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

Proposed by Sylvain Pineau
Status: Merged
Approved by: Sylvain Pineau
Approved revision: bcaeafabb606811f98a8219ae48d8336d42553f6
Merged at revision: 04059ec405fdb1c4ebc1ae5beb5c61f280e370aa
Proposed branch: ~sylvain-pineau/checkbox-support:add_bt_hci_interface
Merge into: checkbox-support:master
Diff against target: 103 lines (+37/-15)
1 file modified
checkbox_support/parsers/udevadm.py (+37/-15)
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+356251@code.launchpad.net

Description of the change

Ensure all BLUETOOTH devices get an hci interface property.

e.g:

path: /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0
bus: usb
category: BLUETOOTH
driver: btusb
product_id: 2603
vendor_id: 32903
vendor: Intel Corp.
interface: hci0
vendor_slug: Intel_Corp.

To post a comment you must log in.
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

self-approved, tested using the udevadm parser test data files.

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 4c0590e..38b5882 100644
3--- a/checkbox_support/parsers/udevadm.py
4+++ b/checkbox_support/parsers/udevadm.py
5@@ -534,6 +534,14 @@ class UdevadmDevice(object):
6 if self._environment["SUBSYSTEM"] == "video4linux":
7 return "CAPTURE"
8
9+ if (
10+ 'RFKILL_TYPE' in self._environment and
11+ 'RFKILL_NAME' in self._environment
12+ ):
13+ if self._environment["RFKILL_TYPE"] == 'bluetooth':
14+ if self._environment["RFKILL_NAME"].startswith('hci'):
15+ return 'BLUETOOTH'
16+
17 # Any devices that have a product name and proper vendor and product
18 # IDs, but had no other category, are lumped together in OTHER.
19 # A few devices may have no self.product but carry PRODUCT data in
20@@ -645,11 +653,11 @@ class UdevadmDevice(object):
21 if "ID_MODEL_ID" in self._environment:
22 return decode_id(self._environment["ID_MODEL_ID"])
23 if "SUBSYSTEM" in self._environment:
24- # hidraw
25+ # hidraw
26 if self._environment["SUBSYSTEM"] == "hidraw" and self._stack:
27 parent = self._stack[-1]
28 return parent.product_id
29- # video4linux
30+ # video4linux
31 if self._environment["SUBSYSTEM"] == "video4linux":
32 if "ID_MODEL_ID" in self._environment:
33 return decode_id(self._environment["ID_MODEL_ID"])
34@@ -699,11 +707,11 @@ class UdevadmDevice(object):
35 if "ID_VENDOR_ID" in self._environment:
36 return decode_id(self._environment["ID_VENDOR_ID"])
37 if "SUBSYSTEM" in self._environment:
38- # hidraw
39+ # hidraw
40 if self._environment["SUBSYSTEM"] == "hidraw" and self._stack:
41 parent = self._stack[-1]
42 return parent.vendor_id
43- # video4linux
44+ # video4linux
45 if self._environment["SUBSYSTEM"] == "video4linux":
46 if "ID_VENDOR_ID" in self._environment:
47 return decode_id(self._environment["ID_VENDOR_ID"])
48@@ -975,6 +983,8 @@ class UdevadmDevice(object):
49 return self._environment["INTERFACE"]
50 else:
51 return 'UNKNOWN'
52+ if "RFKILL_NAME" in self._environment:
53+ return self._environment["RFKILL_NAME"]
54 return None
55
56 @property
57@@ -1224,7 +1234,7 @@ class UdevadmParser(object):
58 for parent in (device._stack[-1], device._stack[-2]):
59 if parent._raw_path in HID_devices_path_list:
60 self.devices.pop(device._raw_path, None)
61- if device.category in ("INFINIBAND", "NETWORK", "SOCKETCAN",
62+ elif device.category in ("INFINIBAND", "NETWORK", "SOCKETCAN",
63 "WIRELESS", "WWAN", "OTHER"):
64 dev_interface = [
65 d for d in self.devices.values()
66@@ -1243,16 +1253,28 @@ class UdevadmParser(object):
67 dev_interface.subproduct_id = device.subproduct_id
68 dev_interface.subvendor_id = device.subvendor_id
69 self.devices.pop(device._raw_path, None)
70- # If dev/mapper list devices then they take precedence over the
71- # other block devices
72- if dev_mapper_devices and device.category == 'DISK':
73- if device not in dev_mapper_devices:
74- self.devices.pop(device._raw_path, None)
75- # Remove DISK devices participating in RAID arrays created by
76- # mdstat
77- if md_devices and device.category == 'DISK':
78- if device.name in md_devices:
79- self.devices.pop(device._raw_path, None)
80+ elif device.category == 'BLUETOOTH':
81+ dev_interface = [
82+ d for d in self.devices.values()
83+ if d.category == 'BLUETOOTH' and
84+ device._raw_path != d._raw_path and
85+ device._raw_path + '/' in d._raw_path
86+ ]
87+ if dev_interface:
88+ dev_interface = dev_interface.pop()
89+ device.interface = dev_interface.interface
90+ self.devices.pop(dev_interface._raw_path, None)
91+ elif device.category == 'DISK':
92+ # If dev/mapper list devices then they take precedence over the
93+ # other block devices
94+ if dev_mapper_devices:
95+ if device not in dev_mapper_devices:
96+ self.devices.pop(device._raw_path, None)
97+ # Remove DISK devices participating in RAID arrays created by
98+ # mdstat
99+ if md_devices:
100+ if device.name in md_devices:
101+ self.devices.pop(device._raw_path, None)
102
103 [result.addDevice(device) for device in self.devices.values()]
104

Subscribers

People subscribed via source and target branches