Merge ~alexsander-souza/maas:lp2043970_to_33 into maas:3.3

Proposed by Alexsander de Souza
Status: Merged
Approved by: Alexsander de Souza
Approved revision: 2902ca3aff1122a6a9ca9700ce9e28d0e0a64e61
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~alexsander-souza/maas:lp2043970_to_33
Merge into: maas:3.3
Diff against target: 126 lines (+60/-2)
4 files modified
src/maasserver/forms/settings.py (+14/-0)
src/maasserver/models/config.py (+1/-0)
src/metadataserver/builtin_scripts/network.py (+15/-2)
src/metadataserver/builtin_scripts/tests/test_network.py (+30/-0)
Reviewer Review Type Date Requested Status
Alexsander de Souza Approve
MAAS Lander Approve
Review via email: mp+463052@code.launchpad.net

Commit message

fix(metadataserver): leave discovered interfaces disconnected

don't create a default VLAN for interfaces discovered by hardware sync
when MAAS cannot figure out the correct one.

fixes LP#2043970

(cherry picked from commit 253fdfa645f5596ff824f01f5cea6f2f5d316f13)

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

UNIT TESTS
-b lp2043970_to_33 lp:~alexsander-souza/maas/+git/maas into -b 3.3 lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 2902ca3aff1122a6a9ca9700ce9e28d0e0a64e61

review: Approve
Revision history for this message
Alexsander de Souza (alexsander-souza) wrote :

self-approving back-port

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/forms/settings.py b/src/maasserver/forms/settings.py
2index ea3598e..41c33ea 100644
3--- a/src/maasserver/forms/settings.py
4+++ b/src/maasserver/forms/settings.py
5@@ -1054,6 +1054,20 @@ CONFIG_ITEMS = {
6 "max_value": 90,
7 },
8 },
9+ "auto_vlan_creation": {
10+ "default": True,
11+ "form": forms.BooleanField,
12+ "form_kwargs": {
13+ "label": "Automatically create VLANs and Fabrics for interfaces",
14+ "required": False,
15+ "help_text": (
16+ "Enables the creation of a default VLAN and Fabric for "
17+ "discovered network interfaces when MAAS cannot connect it "
18+ "to an existing one. When disabled, the interface is left "
19+ "disconnected in these cases."
20+ ),
21+ },
22+ },
23 }
24
25
26diff --git a/src/maasserver/models/config.py b/src/maasserver/models/config.py
27index 55dc312..bd9d5a6 100644
28--- a/src/maasserver/models/config.py
29+++ b/src/maasserver/models/config.py
30@@ -146,6 +146,7 @@ def get_default_config():
31 "vault_enabled": False,
32 # Windows settings
33 "windows_kms_host": None,
34+ "auto_vlan_creation": True,
35 }
36
37
38diff --git a/src/metadataserver/builtin_scripts/network.py b/src/metadataserver/builtin_scripts/network.py
39index b21b36a..ee222cf 100644
40--- a/src/metadataserver/builtin_scripts/network.py
41+++ b/src/metadataserver/builtin_scripts/network.py
42@@ -1,7 +1,7 @@
43 from django.db.models.expressions import RawSQL
44 from netaddr import IPAddress, IPNetwork
45
46-from maasserver.enum import INTERFACE_TYPE, IPADDRESS_TYPE
47+from maasserver.enum import INTERFACE_TYPE, IPADDRESS_TYPE, NODE_STATUS
48 from maasserver.models.config import Config
49 from maasserver.models.fabric import Fabric
50 from maasserver.models.interface import (
51@@ -506,13 +506,26 @@ def update_parent_vlans(node, interface, parent_nics, update_ip_addresses):
52 parent_nic.save()
53
54
55+def auto_vlan_creation(node) -> bool:
56+ if node.is_controller:
57+ # Always create controller's vlans
58+ return True
59+
60+ if node.status == NODE_STATUS.DEPLOYED:
61+ # don't create empty vlan/fabric for interfaces discovered by HW sync,
62+ # they cannot be used.
63+ return False
64+
65+ return Config.objects.get_config("auto_vlan_creation", True)
66+
67+
68 def guess_vlan_for_interface(node, links):
69 # Make sure that the VLAN on the interface is correct. When
70 # links exists on this interface we place it into the correct
71 # VLAN. If it cannot be determined and its a new interface it
72 # gets placed on its own fabric.
73 new_vlan = get_interface_vlan_from_links(node, links)
74- if new_vlan is None:
75+ if new_vlan is None and auto_vlan_creation(node):
76 # If the default VLAN on the default fabric has no interfaces
77 # associated with it, the first interface will be placed there
78 # (rather than creating a new fabric).
79diff --git a/src/metadataserver/builtin_scripts/tests/test_network.py b/src/metadataserver/builtin_scripts/tests/test_network.py
80index 832e918..a9ef0f0 100644
81--- a/src/metadataserver/builtin_scripts/tests/test_network.py
82+++ b/src/metadataserver/builtin_scripts/tests/test_network.py
83@@ -10,6 +10,7 @@ from maasserver.enum import (
84 NODE_TYPE,
85 )
86 from maasserver.models import Event, EventType
87+from maasserver.models.config import Config
88 from maasserver.models.fabric import Fabric
89 from maasserver.models.interface import (
90 BondInterface,
91@@ -86,6 +87,35 @@ class TestUpdateInterfaces(MAASServerTestCase, UpdateInterfacesMixin):
92 eth0 = node.current_config.interface_set.get(name="eth0")
93 self.assertEqual(eth0.numa_node, node.default_numanode)
94
95+ def test_dont_create_default_vlan_for_deployed_machines(self):
96+ node = factory.make_Machine(status=NODE_STATUS.DEPLOYED)
97+ data = FakeCommissioningData()
98+ data_eth0 = data.create_physical_network(
99+ "eth0",
100+ mac_address="11:11:11:11:11:11",
101+ )
102+ data_eth0.state = "up"
103+ self.update_interfaces(node, data)
104+ eth0 = PhysicalInterface.objects.get(
105+ name="eth0", node_config=node.current_config
106+ )
107+ self.assertIsNone(eth0.vlan)
108+
109+ def test_dont_create_default_vlan_if_disabled(self):
110+ Config.objects.set_config(name="auto_vlan_creation", value=False)
111+ node = factory.make_Machine(status=NODE_STATUS.NEW)
112+ data = FakeCommissioningData()
113+ data_eth0 = data.create_physical_network(
114+ "eth0",
115+ mac_address="11:11:11:11:11:11",
116+ )
117+ data_eth0.state = "up"
118+ self.update_interfaces(node, data)
119+ eth0 = PhysicalInterface.objects.get(
120+ name="eth0", node_config=node.current_config
121+ )
122+ self.assertIsNone(eth0.vlan)
123+
124 def test_all_new_physical_interfaces_no_links(self):
125 controller = self.create_empty_controller()
126 data = FakeCommissioningData()

Subscribers

People subscribed via source and target branches