Merge ~ack/maas:1939340-3.0 into maas:3.0

Proposed by Alberto Donato
Status: Merged
Approved by: Alberto Donato
Approved revision: a387a87279db2ea57958a3c9da5532a3513b1547
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ack/maas:1939340-3.0
Merge into: maas:3.0
Diff against target: 55 lines (+26/-1)
2 files modified
src/metadataserver/builtin_scripts/hooks.py (+3/-1)
src/metadataserver/builtin_scripts/tests/test_hooks.py (+23/-0)
Reviewer Review Type Date Requested Status
Alberto Donato Approve
Review via email: mp+411264@code.launchpad.net

Commit message

LP:1939340 handle "interfaces" field for reported USB devices being null

To post a comment you must log in.
Revision history for this message
Alberto Donato (ack) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/metadataserver/builtin_scripts/hooks.py b/src/metadataserver/builtin_scripts/hooks.py
2index fd52cdd..9ea7b89 100644
3--- a/src/metadataserver/builtin_scripts/hooks.py
4+++ b/src/metadataserver/builtin_scripts/hooks.py
5@@ -465,13 +465,15 @@ def _process_usb_devices(add_func, data):
6 device["device_address"],
7 )
8 key = (device["vendor_id"], device["product_id"], usb_address)
9+ # the "interfaces" field can be present but None
10+ interfaces = device.get("interfaces") or []
11 # USB devices can have different drivers for each
12 # functionality. e.g a webcam has a video and audio driver.
13 commissioning_driver = ", ".join(
14 set(
15 [
16 interface["driver"]
17- for interface in device.get("interfaces", [])
18+ for interface in interfaces
19 if "driver" in interface
20 ]
21 )
22diff --git a/src/metadataserver/builtin_scripts/tests/test_hooks.py b/src/metadataserver/builtin_scripts/tests/test_hooks.py
23index 4e36ffa..f7563fc 100644
24--- a/src/metadataserver/builtin_scripts/tests/test_hooks.py
25+++ b/src/metadataserver/builtin_scripts/tests/test_hooks.py
26@@ -1556,6 +1556,29 @@ class TestProcessLXDResults(MAASServerTestCase):
27 pcie_node_device.pci_address, pcie_device["pci_address"]
28 )
29
30+ def test_usb_device_null_interfaces(self):
31+ node = factory.make_Node()
32+ lxd_output = make_lxd_output()
33+ usb_device = make_lxd_usb_device()
34+ usb_device["interfaces"] = None
35+ lxd_output["resources"]["usb"] = {
36+ "devices": [usb_device],
37+ "total": 1,
38+ }
39+ process_lxd_results(node, json.dumps(lxd_output).encode(), 0)
40+ usb_node_device = node.node_devices.get(bus=NODE_DEVICE_BUS.USB)
41+ self.assertEqual(usb_node_device.hardware_type, HARDWARE_TYPE.NODE)
42+ self.assertEqual(usb_node_device.vendor_id, usb_device["vendor_id"])
43+ self.assertEqual(usb_node_device.product_id, usb_device["product_id"])
44+ self.assertEqual(usb_node_device.vendor_name, usb_device["vendor"])
45+ self.assertEqual(usb_node_device.product_name, usb_device["product"])
46+ self.assertEqual(usb_node_device.bus_number, usb_device["bus_address"])
47+ self.assertEqual(usb_node_device.commissioning_driver, "")
48+ self.assertEqual(
49+ usb_node_device.device_number, usb_device["device_address"]
50+ )
51+ self.assertIsNone(usb_node_device.pci_address)
52+
53 def test_updates_node_device(self):
54 node = factory.make_Node()
55 pcie_device = factory.make_NodeDevice(

Subscribers

People subscribed via source and target branches