Merge ~ack/maas:1927667-update-interface-numanode-2.9 into maas:2.9

Proposed by Alberto Donato
Status: Merged
Approved by: Alberto Donato
Approved revision: ef20a3be0d2663f3aacee153e3f286afafb9d874
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ack/maas:1927667-update-interface-numanode-2.9
Merge into: maas:2.9
Diff against target: 120 lines (+40/-7)
3 files modified
src/maasserver/models/node.py (+5/-2)
src/metadataserver/builtin_scripts/hooks.py (+21/-5)
src/metadataserver/builtin_scripts/tests/test_hooks.py (+14/-0)
Reviewer Review Type Date Requested Status
Lee Trager (community) Approve
MAAS Lander Approve
Review via email: mp+402810@code.launchpad.net

Commit message

LP: #1927667 - update network interfaces numa node from resource data

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b 1927667-update-interface-numanode-2.9 lp:~ack/maas/+git/maas into -b 2.9 lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10085/console
COMMIT: 38ffe485e11d5365c86c18bde919b0ead6b73571

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b 1927667-update-interface-numanode-2.9 lp:~ack/maas/+git/maas into -b 2.9 lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: d58f534dd9cf98e2191941478b3ff26111d07a05

review: Approve
Revision history for this message
Lee Trager (ltrager) wrote :

The initial caller, update_node_network_information, already has the NUMA nodes loaded in memory. I think that should be passed to update_node_interfaces which passes it to update_interface_details so MAAS doesn't have to do additional database lookups.

review: Needs Fixing
Revision history for this message
Alberto Donato (ack) wrote :

@Lee thanks for the review.

Passing in the NUMANode objects through those functions is quite a big change, since update_node_interfaces is used in a bunch of places.

To keep the change minimal, since this fix is only needed in 2.9 (3.0 reworks the logic and already updates the numanode elsewhere) I've made a change to pass the mapping between indexes and IDs to update_interface_details, so a single extra query is made to get those.

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b 1927667-update-interface-numanode-2.9 lp:~ack/maas/+git/maas into -b 2.9 lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10094/console
COMMIT: ef20a3be0d2663f3aacee153e3f286afafb9d874

review: Needs Fixing
Revision history for this message
Alberto Donato (ack) wrote :

jenkins: !test

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b 1927667-update-interface-numanode-2.9 lp:~ack/maas/+git/maas into -b 2.9 lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: ef20a3be0d2663f3aacee153e3f286afafb9d874

review: Approve
Revision history for this message
Lee Trager (ltrager) :
review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

LANDING
-b 1927667-update-interface-numanode-2.9 lp:~ack/maas/+git/maas into -b 2.9 lp:~maas-committers/maas

STATUS: FAILED BUILD
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10105/consoleText

Revision history for this message
MAAS Lander (maas-lander) wrote :

LANDING
-b 1927667-update-interface-numanode-2.9 lp:~ack/maas/+git/maas into -b 2.9 lp:~maas-committers/maas

STATUS: FAILED BUILD
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10107/consoleText

Revision history for this message
MAAS Lander (maas-lander) wrote :

LANDING
-b 1927667-update-interface-numanode-2.9 lp:~ack/maas/+git/maas into -b 2.9 lp:~maas-committers/maas

STATUS: FAILED BUILD
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10108/consoleText

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/models/node.py b/src/maasserver/models/node.py
2index 1d5b74f..14c3119 100644
3--- a/src/maasserver/models/node.py
4+++ b/src/maasserver/models/node.py
5@@ -6783,12 +6783,13 @@ class Controller(Node):
6 VLAN. Otherwise, creates the interfaces but does not create any
7 links or VLANs.
8 """
9- # Avoid circular imports
10 from metadataserver.builtin_scripts.hooks import (
11 parse_interfaces_details,
12 update_interface_details,
13 )
14
15+ numa_ids_map = dict(self.numanode_set.values_list("index", "id"))
16+
17 # Get all of the current interfaces on this node.
18 current_interfaces = {
19 interface.id: interface
20@@ -6825,7 +6826,9 @@ class Controller(Node):
21 if interface is not None:
22 interface.update_discovery_state(discovery_mode, settings)
23 if interface.type == INTERFACE_TYPE.PHYSICAL:
24- update_interface_details(interface, interfaces_details)
25+ update_interface_details(
26+ interface, interfaces_details, numa_ids_map
27+ )
28 if interface.id in current_interfaces:
29 del current_interfaces[interface.id]
30
31diff --git a/src/metadataserver/builtin_scripts/hooks.py b/src/metadataserver/builtin_scripts/hooks.py
32index 96d7d12..d89dc75 100644
33--- a/src/metadataserver/builtin_scripts/hooks.py
34+++ b/src/metadataserver/builtin_scripts/hooks.py
35@@ -199,11 +199,12 @@ def parse_interfaces_details(node):
36 return _parse_interfaces(node, details)
37
38
39-def update_interface_details(interface, details):
40+def update_interface_details(interface, details, numa_ids_map):
41 """Update details for an existing interface from commissioning data.
42
43- This should be passed details from the _parse_interfaces call.
44-
45+ :params details: details from the _parse_interfaces call
46+ :params numa_ids_map: dict mapping numa node indexes to their IDs for the
47+ node the interface belongs to
48 """
49 iface_details = details.get(interface.mac_address)
50 if not iface_details:
51@@ -223,10 +224,19 @@ def update_interface_details(interface, details):
52 setattr(interface, field, value)
53 update_fields.append(field)
54
55+ numa_node_idx = iface_details["numa_node"]
56+ if (
57+ interface.numa_node is None
58+ or interface.numa_node.index != numa_node_idx
59+ ):
60+ interface.numa_node_id = numa_ids_map[numa_node_idx]
61+ update_fields.append("numa_node")
62+
63 sriov_max_vf = iface_details.get("sriov_max_vf")
64 if interface.sriov_max_vf != sriov_max_vf:
65 interface.sriov_max_vf = sriov_max_vf
66 update_fields.append("sriov_max_vf")
67+
68 if update_fields:
69 interface.save(update_fields=["updated", *update_fields])
70
71@@ -295,8 +305,12 @@ def update_node_network_information(node, data, numa_nodes):
72 # Duplicate MACs are not expected on machines, raise the
73 # exception so this can be handled.
74 raise
75- current_interfaces = set()
76
77+ numa_ids_map = dict(
78+ NUMANode.objects.filter(node=node).values_list("index", "id")
79+ )
80+
81+ current_interfaces = set()
82 for mac, iface in interfaces_info.items():
83 ifname = iface.get("name")
84 link_connected = iface.get("link_connected")
85@@ -313,7 +327,9 @@ def update_node_network_information(node, data, numa_nodes):
86 if interface.node == node:
87 # Interface already exists on this node, so just update the NIC
88 # info
89- update_interface_details(interface, interfaces_info)
90+ update_interface_details(
91+ interface, interfaces_info, numa_ids_map
92+ )
93 else:
94 logger.warning(
95 "Interface with MAC %s moved from node %s to %s. "
96diff --git a/src/metadataserver/builtin_scripts/tests/test_hooks.py b/src/metadataserver/builtin_scripts/tests/test_hooks.py
97index bac7d2a..bb11f5f 100644
98--- a/src/metadataserver/builtin_scripts/tests/test_hooks.py
99+++ b/src/metadataserver/builtin_scripts/tests/test_hooks.py
100@@ -1675,6 +1675,20 @@ class TestProcessLXDResults(MAASServerTestCase):
101 self.assertEqual(0, iface3.link_speed)
102 self.assertEqual(0, iface3.interface_speed)
103
104+ def test_updates_interface_numa_node(self):
105+ node = factory.make_Node()
106+ iface = factory.make_Interface(
107+ node=node,
108+ mac_address="00:00:00:00:00:01",
109+ )
110+ create_IPADDR_OUTPUT_NAME_script(node, IP_ADDR_OUTPUT)
111+
112+ lxd_output = make_lxd_output()
113+ lxd_output["resources"]["network"]["cards"][0]["numa_node"] = 1
114+ process_lxd_results(node, json.dumps(lxd_output).encode(), 0)
115+ iface1 = reload_object(iface)
116+ self.assertEqual(iface1.numa_node.index, 1)
117+
118 def test_ipaddr_script_before(self):
119 self.assertLess(
120 IPADDR_OUTPUT_NAME,

Subscribers

People subscribed via source and target branches