Merge ~bjornt/maas:bug-1929086-vlan-interface-name into maas:master

Proposed by Björn Tillenius
Status: Merged
Approved by: Björn Tillenius
Approved revision: 8a050ea617ca275ceb79a2d523086677c4b095a6
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~bjornt/maas:bug-1929086-vlan-interface-name
Merge into: maas:master
Diff against target: 79 lines (+27/-16)
2 files modified
src/maasserver/models/interface.py (+9/-16)
src/metadataserver/builtin_scripts/tests/test_network.py (+18/-0)
Reviewer Review Type Date Requested Status
Alberto Donato (community) Approve
MAAS Lander Approve
Review via email: mp+403121@code.launchpad.net

Commit message

LP #1929086: LXD VM hosts can't be refreshed if VLANs interfaces aren't named $parent.$vid

This is a small fix that can be backported to 3.0.

We should remove the automatic generation of of VLAN interface name
completly, since the callsites should be responsible for giving the
right name. That's a bit too risky of a change for 3.0, though, since it
breaks a lot of tests.

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

UNIT TESTS
-b bug-1929086-vlan-interface-name lp:~bjornt/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 8a050ea617ca275ceb79a2d523086677c4b095a6

review: Approve
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/maasserver/models/interface.py b/src/maasserver/models/interface.py
2index 2a0b85a..3127746 100644
3--- a/src/maasserver/models/interface.py
4+++ b/src/maasserver/models/interface.py
5@@ -1912,7 +1912,7 @@ class VLANInterface(ChildInterface):
6 :raises: AssertionError if the VLAN is not defined, or if the related
7 VLAN is not tagged with a valid 802.1Q VLAN tag (between 1-4094).
8 """
9- if self._is_related_node_a_controller() and self.name is not None:
10+ if self._should_preserve_name():
11 # Controllers must preserve original VLAN interface names, since
12 # having an accurate name is important for MAAS (in order to
13 # perform actions such as providing DHCP or monitoring interfaces).
14@@ -1970,9 +1970,13 @@ class VLANInterface(ChildInterface):
15 {"vlan": ["VLAN interface requires connection to a VLAN."]}
16 )
17
18- def _is_related_node_a_controller(self):
19- """Returns True if the related Node is a Controller."""
20- return self.get_node().is_controller
21+ # XXX: We should always trust the name that is passed when creating
22+ # the VLANInterface. This should be removed when 3.0 is
23+ # released.
24+ def _should_preserve_name(self):
25+ """Returns True if the VLAN interface name shouldn't be generated"""
26+ node = self.get_node()
27+ return (node.is_controller or node.is_pod) and self.name is not None
28
29 def save(self, *args, **kwargs):
30 # Set the node of this VLAN to the same as its parents.
31@@ -1984,18 +1988,7 @@ class VLANInterface(ChildInterface):
32 parent = self.parents.first()
33 if parent is not None:
34 self.mac_address = parent.mac_address
35- # There are two cases where we want to automatically generate a
36- # VLAN interface's name:
37- # (1) The interface is not attached to a Controller. Controllers
38- # always inform MAAS what their interface name is, so MAAS
39- # must trust what they say. On controllers, we allow
40- # non-standard naming conventions, such as 'vlan100',
41- # 'vlan0100', or 'eth0.0100'. On deployed nodes, we always
42- # coerce the name to '<parent>.<vid-no-pad>' format.
43- # (2) The interface is on a controller, but no name was specified.
44- # (This is useful more for the test suite than anything else.)
45- is_controller = self._is_related_node_a_controller()
46- if not is_controller or (is_controller and self.name is None):
47+ if not self._should_preserve_name():
48 new_name = self.get_name()
49 if self.name != new_name:
50 self.name = new_name
51diff --git a/src/metadataserver/builtin_scripts/tests/test_network.py b/src/metadataserver/builtin_scripts/tests/test_network.py
52index 4b6d0b4..c8667d5 100644
53--- a/src/metadataserver/builtin_scripts/tests/test_network.py
54+++ b/src/metadataserver/builtin_scripts/tests/test_network.py
55@@ -545,6 +545,24 @@ class TestUpdateInterfaces(MAASServerTestCase, UpdateInterfacesMixin):
56 self.assertTrue(eth0_0102.enabled)
57 self.assertEqual([eth0], list(eth0_0102.parents.all()))
58
59+ def test_vlans_with_alternate_naming_conventions_vm_host(self):
60+ host = factory.make_Machine()
61+ factory.make_Pod(host=host)
62+ data = FakeCommissioningData()
63+ eth0_network = data.create_physical_network("eth0")
64+ data.create_vlan_network("vlan0100", parent=eth0_network, vid=1)
65+ data.create_vlan_network("vlan101", parent=eth0_network, vid=2)
66+ data.create_vlan_network("eth0.0102", parent=eth0_network, vid=3)
67+
68+ self.update_interfaces(host, data)
69+
70+ interface_names = VLANInterface.objects.filter(node=host).values_list(
71+ "name", flat=True
72+ )
73+ self.assertEqual(
74+ ["eth0.0102", "vlan0100", "vlan101"], sorted(interface_names)
75+ )
76+
77 def test_sets_discovery_parameters(self):
78 controller = self.create_empty_controller()
79 eth0_mac = factory.make_mac_address()

Subscribers

People subscribed via source and target branches