Merge ~bjornt/maas:update-node-interfaces-non-physical into maas:master

Proposed by Björn Tillenius
Status: Merged
Approved by: Björn Tillenius
Approved revision: 4a10c9de2eca3f44d48e436e3f2814d432ae12e0
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~bjornt/maas:update-node-interfaces-non-physical
Merge into: maas:master
Diff against target: 157 lines (+24/-50)
1 file modified
src/metadataserver/builtin_scripts/network.py (+24/-50)
Reviewer Review Type Date Requested Status
Alberto Donato (community) Approve
MAAS Lander Needs Fixing
Review via email: mp+401676@code.launchpad.net

Commit message

Don't use controller-specific data for non-physical interfaces.

Now update_interface() uses only commissioning data for for all vital
interface data.

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

UNIT TESTS
-b update-node-interfaces-non-physical lp:~bjornt/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/9842/console
COMMIT: 4a10c9de2eca3f44d48e436e3f2814d432ae12e0

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

+1

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/network.py b/src/metadataserver/builtin_scripts/network.py
2index 4b425b4..daf2130 100644
3--- a/src/metadataserver/builtin_scripts/network.py
4+++ b/src/metadataserver/builtin_scripts/network.py
5@@ -86,19 +86,18 @@ def update_node_interfaces(node, data):
6 discovery_mode = Config.objects.get_network_discovery_config()
7 interfaces_details = parse_interfaces(node, data)
8 for name in flatten(process_order):
9- settings = interfaces[name]
10 # Note: the interface that comes back from this call may be None,
11 # if we decided not to model an interface based on what the rack
12 # sent.
13 interface = update_interface(
14 node,
15 name,
16- settings,
17 data,
18 address_extra,
19 hints=topology_hints,
20 )
21 if interface is not None:
22+ settings = interfaces[name]
23 interface.update_discovery_state(discovery_mode, settings)
24 if interface.type == INTERFACE_TYPE.PHYSICAL:
25 update_interface_details(interface, interfaces_details)
26@@ -124,12 +123,10 @@ def update_node_interfaces(node, data):
27 node.save()
28
29
30-def update_interface(node, name, config, data, address_extra, hints=None):
31+def update_interface(node, name, data, address_extra, hints=None):
32 """Update a interface.
33
34 :param name: Name of the interface.
35- :param config: Interface dictionary that was parsed from
36- /etc/network/interfaces on the rack controller.
37 :param data: Commissioning data as a dict.
38 :param address_extra: Extra data about IP addresses that controller
39 collects.
40@@ -144,21 +141,15 @@ def update_interface(node, name, config, data, address_extra, hints=None):
41 ]
42 for link in links:
43 link.update(address_extra.get(link["address"], {}))
44- if config["type"] == "physical":
45+ if network["vlan"]:
46+ return update_vlan_interface(node, name, network, links)
47+ elif network["bond"] or network["bridge"]:
48+ return update_child_interface(node, name, network, links)
49+ else:
50 card, port = get_card_port(name, data)
51 return update_physical_interface(
52 node, name, network, links, card=card, port=port, hints=hints
53 )
54- elif config["type"] == "vlan":
55- return update_vlan_interface(node, name, config, links)
56- elif config["type"] == "bond":
57- return update_bond_interface(node, name, config, links)
58- elif config["type"] == "bridge":
59- return update_bridge_interface(node, name, config, links)
60- else:
61- raise ValueError(
62- "Unkwown interface type '%s' for '%s'." % (config["type"], name)
63- )
64
65
66 def get_card_port(name, data):
67@@ -291,17 +282,14 @@ def guess_vlan_from_hints(node, ifname, hints):
68 return existing_vlan
69
70
71-def update_vlan_interface(node, name, config, links):
72+def update_vlan_interface(node, name, network, links):
73 """Update a VLAN interface.
74
75 :param name: Name of the interface.
76- :param config: Interface dictionary that was parsed from
77- /etc/network/interfaces on the rack controller.
78+ :param network: Network settings from commissioning data.
79 """
80- vid = config["vid"]
81- # VLAN only ever has one parent, and the parent should always
82- # exists because of the order the links are processed.
83- parent_name = config["parents"][0]
84+ vid = network["vlan"]["vid"]
85+ parent_name = network["vlan"]["lower_device"]
86 parent_nic = Interface.objects.get(node=node, name=parent_name)
87 links_vlan = get_interface_vlan_from_links(node, links)
88 if links_vlan:
89@@ -342,28 +330,34 @@ def update_vlan_interface(node, name, config, links):
90 return interface
91
92
93-def update_child_interface(node, name, config, links, child_type):
94+def update_child_interface(node, name, network, links):
95 """Update a child interface.
96
97 :param name: Name of the interface.
98- :param config: Interface dictionary that was parsed from
99- /etc/network/interfaces on the rack controller.
100+ :param network: Network settings from commissioning data.
101 """
102+ if network["bridge"]:
103+ parents = network["bridge"]["upper_devices"]
104+ child_type = BridgeInterface
105+ elif network["bond"]:
106+ parents = network["bond"]["lower_devices"]
107+ child_type = BondInterface
108+ else:
109+ raise RuntimeError(f"Unknown child interface: {network}")
110 # Get all the parent interfaces for this interface. All the parents
111 # should exists because of the order the links are processed.
112- ifnames = config["parents"]
113 parent_nics = Interface.objects.get_interfaces_on_node_by_name(
114- node, ifnames
115+ node, parents
116 )
117
118 # Ignore most child interfaces that don't have parents. MAAS won't know
119 # what to do with them since they can't be connected to a fabric.
120 # Bridges are an exception since some MAAS demo/test environments
121 # contain virtual bridges.
122- if len(parent_nics) == 0 and child_type is not BridgeInterface:
123+ if len(parent_nics) == 0 and not network["bridge"]:
124 return None
125
126- mac_address = config["mac_address"]
127+ mac_address = network["hwaddr"]
128 interface = child_type.objects.get_or_create_on_node(
129 node,
130 name,
131@@ -384,26 +378,6 @@ def update_child_interface(node, name, config, links, child_type):
132 return interface
133
134
135-def update_bond_interface(node, name, config, links):
136- """Update a bond interface.
137-
138- :param name: Name of the interface.
139- :param config: Interface dictionary that was parsed from
140- /etc/network/interfaces on the rack controller.
141- """
142- return update_child_interface(node, name, config, links, BondInterface)
143-
144-
145-def update_bridge_interface(node, name, config, links):
146- """Update a bridge interface.
147-
148- :param name: Name of the interface.
149- :param config: Interface dictionary that was parsed from
150- /etc/network/interfaces on the rack controller.
151- """
152- return update_child_interface(node, name, config, links, BridgeInterface)
153-
154-
155 def update_parent_vlans(node, interface, parent_nics, update_ip_addresses):
156 """Given the specified interface model object, the specified list of
157 parent interfaces, and the specified list of static IP addresses,

Subscribers

People subscribed via source and target branches