Merge ~sylvain-pineau/checkbox-support:mac_property into checkbox-support:master

Proposed by Sylvain Pineau
Status: Merged
Approved by: Sylvain Pineau
Approved revision: 0a42f4fedf09a6047fb6b510ca479945539283e2
Merged at revision: cede25c675ace9360a0f2663a06fd2376a635c2a
Proposed branch: ~sylvain-pineau/checkbox-support:mac_property
Merge into: checkbox-support:master
Diff against target: 63 lines (+22/-2)
1 file modified
checkbox_support/parsers/udevadm.py (+22/-2)
Reviewer Review Type Date Requested Status
Maciej Kisielewski (community) Approve
Sylvain Pineau (community) Needs Resubmitting
Review via email: mp+311697@code.launchpad.net

Description of the change

add mac property for network devices. This will help writing WOl tests where we need to wake a system using its mac address.

+ a small fix to ensure lsblk output is always a string.

To post a comment you must log in.
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

Comment/Question in line.

Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

setters are not always needed, but for consistency let's add one for mac. Other setters are used when we parse the tree of parents for a given device and overwrite a property of a child if the parent's one is preferred.

review: Needs Resubmitting
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

> setters are not always needed, but for consistency let's add one for mac.
> Other setters are used when we parse the tree of parents for a given device
> and overwrite a property of a child if the parent's one is preferred.

TYVM for the explanation!

Revision history for this message
Maciej Kisielewski (kissiel) wrote :

Looks good! +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/checkbox_support/parsers/udevadm.py b/checkbox_support/parsers/udevadm.py
index db81070..b90b807 100644
--- a/checkbox_support/parsers/udevadm.py
+++ b/checkbox_support/parsers/udevadm.py
@@ -125,6 +125,7 @@ class UdevadmDevice(object):
125 "_stack",125 "_stack",
126 "_bus",126 "_bus",
127 "_interface",127 "_interface",
128 "_mac",
128 "_product",129 "_product",
129 "_product_id",130 "_product_id",
130 "_subproduct_id",131 "_subproduct_id",
@@ -142,6 +143,7 @@ class UdevadmDevice(object):
142 self._stack = stack143 self._stack = stack
143 self._bus = None144 self._bus = None
144 self._interface = None145 self._interface = None
146 self._mac = None
145 self._product = None147 self._product = None
146 self._product_id = None148 self._product_id = None
147 self._subproduct_id = None149 self._subproduct_id = None
@@ -790,6 +792,22 @@ class UdevadmDevice(object):
790 return 'UNKNOWN'792 return 'UNKNOWN'
791 return None793 return None
792794
795 @property
796 def mac(self):
797 if self._mac is not None:
798 return self._mac
799 if self.category in ("NETWORK", "WIRELESS"):
800 if "ID_NET_NAME_MAC" in self._environment:
801 mac = self._environment["ID_NET_NAME_MAC"][3:]
802 return ':'.join([mac[i:i+2] for i in range(0, len(mac), 2)])
803 else:
804 return 'UNKNOWN'
805 return None
806
807 @mac.setter
808 def mac(self, value):
809 self._mac = value
810
793 @interface.setter811 @interface.setter
794 def interface(self, value):812 def interface(self, value):
795 self._interface = value813 self._interface = value
@@ -797,7 +815,8 @@ class UdevadmDevice(object):
797 def as_json(self):815 def as_json(self):
798 attributes = ("path", "bus", "category", "driver", "product_id",816 attributes = ("path", "bus", "category", "driver", "product_id",
799 "vendor_id", "subproduct_id", "subvendor_id", "product",817 "vendor_id", "subproduct_id", "subvendor_id", "product",
800 "vendor", "interface", "name", "product_slug", "vendor_slug")818 "vendor", "interface", "mac", "name", "product_slug",
819 "vendor_slug")
801820
802 return {a: getattr(self, a) for a in attributes if getattr(self, a)}821 return {a: getattr(self, a) for a in attributes if getattr(self, a)}
803822
@@ -1050,7 +1069,8 @@ def parse_udevadm_output(output, lsblk=None, bits=None):
1050 if lsblk is None:1069 if lsblk is None:
1051 try:1070 try:
1052 lsblk = check_output(1071 lsblk = check_output(
1053 ['lsblk', '-i', '-n', '-P', '-o', 'KNAME,TYPE,MOUNTPOINT'])1072 ['lsblk', '-i', '-n', '-P', '-o', 'KNAME,TYPE,MOUNTPOINT'],
1073 universal_newlines=True)
1054 except CalledProcessError as exc:1074 except CalledProcessError as exc:
1055 lsblk = ''1075 lsblk = ''
1056 udev = UdevadmParser(output, lsblk, bits)1076 udev = UdevadmParser(output, lsblk, bits)

Subscribers

People subscribed via source and target branches