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 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
1diff --git a/checkbox_support/parsers/udevadm.py b/checkbox_support/parsers/udevadm.py
2index db81070..b90b807 100644
3--- a/checkbox_support/parsers/udevadm.py
4+++ b/checkbox_support/parsers/udevadm.py
5@@ -125,6 +125,7 @@ class UdevadmDevice(object):
6 "_stack",
7 "_bus",
8 "_interface",
9+ "_mac",
10 "_product",
11 "_product_id",
12 "_subproduct_id",
13@@ -142,6 +143,7 @@ class UdevadmDevice(object):
14 self._stack = stack
15 self._bus = None
16 self._interface = None
17+ self._mac = None
18 self._product = None
19 self._product_id = None
20 self._subproduct_id = None
21@@ -790,6 +792,22 @@ class UdevadmDevice(object):
22 return 'UNKNOWN'
23 return None
24
25+ @property
26+ def mac(self):
27+ if self._mac is not None:
28+ return self._mac
29+ if self.category in ("NETWORK", "WIRELESS"):
30+ if "ID_NET_NAME_MAC" in self._environment:
31+ mac = self._environment["ID_NET_NAME_MAC"][3:]
32+ return ':'.join([mac[i:i+2] for i in range(0, len(mac), 2)])
33+ else:
34+ return 'UNKNOWN'
35+ return None
36+
37+ @mac.setter
38+ def mac(self, value):
39+ self._mac = value
40+
41 @interface.setter
42 def interface(self, value):
43 self._interface = value
44@@ -797,7 +815,8 @@ class UdevadmDevice(object):
45 def as_json(self):
46 attributes = ("path", "bus", "category", "driver", "product_id",
47 "vendor_id", "subproduct_id", "subvendor_id", "product",
48- "vendor", "interface", "name", "product_slug", "vendor_slug")
49+ "vendor", "interface", "mac", "name", "product_slug",
50+ "vendor_slug")
51
52 return {a: getattr(self, a) for a in attributes if getattr(self, a)}
53
54@@ -1050,7 +1069,8 @@ def parse_udevadm_output(output, lsblk=None, bits=None):
55 if lsblk is None:
56 try:
57 lsblk = check_output(
58- ['lsblk', '-i', '-n', '-P', '-o', 'KNAME,TYPE,MOUNTPOINT'])
59+ ['lsblk', '-i', '-n', '-P', '-o', 'KNAME,TYPE,MOUNTPOINT'],
60+ universal_newlines=True)
61 except CalledProcessError as exc:
62 lsblk = ''
63 udev = UdevadmParser(output, lsblk, bits)

Subscribers

People subscribed via source and target branches