-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix getting device attribute through udev on py3
On Python 3 pyudev Attribute object provides its own getter and missing the __getitem__. Switch to use the "get" method which will work for both py2 and py3.
- Loading branch information
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
repos/system_upgrade/common/libraries/tests/test_persistentnetnames_library.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from leapp.libraries.common import persistentnetnames | ||
from leapp.libraries.stdlib import api | ||
from leapp.libraries.common.testutils import produce_mocked | ||
|
||
|
||
class AttributesTest(object): | ||
def __init__(self): | ||
self.attributes = { | ||
'address': b'fa:16:3e:cd:26:5a' | ||
} | ||
|
||
def get(self, attribute): | ||
if attribute in self.attributes: | ||
return self.attributes[attribute] | ||
raise KeyError | ||
|
||
|
||
class DeviceTest(object): | ||
def __init__(self): | ||
self.dict_data = { | ||
'ID_NET_DRIVER': 'virtio_net', | ||
'ID_VENDOR_ID': '0x1af4', | ||
'ID_PATH': 'pci-0000:00:03.0', | ||
} | ||
|
||
def __getitem__(self, key): | ||
if key in self.dict_data: | ||
return self.dict_data[key] | ||
raise KeyError | ||
|
||
@property | ||
def sys_name(self): | ||
return 'eth' | ||
|
||
@property | ||
def device_path(self): | ||
return '/devices/pci0000:00/0000:00:03.0/virtio0/net/eth0' | ||
|
||
@property | ||
def attributes(self): | ||
return AttributesTest() | ||
|
||
|
||
def provide_test_interfaces(): | ||
return [DeviceTest()] | ||
|
||
|
||
def test_getting_interfaces(monkeypatch): | ||
monkeypatch.setattr(persistentnetnames, 'physical_interfaces', provide_test_interfaces) | ||
monkeypatch.setattr(api, 'produce', produce_mocked()) | ||
interface = next(persistentnetnames.interfaces()) | ||
assert interface.name | ||
assert interface.devpath | ||
assert interface.driver | ||
assert interface.vendor | ||
assert interface.pci_info | ||
assert interface.mac |