Merge ~mpontillo/maas:dont-create-fabrics-for-disabled-interfaces into maas:master

Proposed by Mike Pontillo
Status: Merged
Approved by: Mike Pontillo
Approved revision: 811966c16533b7290f4d7db5dd39ec6f2cb215cc
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~mpontillo/maas:dont-create-fabrics-for-disabled-interfaces
Merge into: maas:master
Diff against target: 94 lines (+46/-7)
2 files modified
src/maasserver/models/node.py (+18/-7)
src/maasserver/models/tests/test_node.py (+28/-0)
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+327688@code.launchpad.net

Commit message

Ensure that disabled interfaces do not create new fabrics.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good.

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

LANDING
-b dont-create-fabrics-for-disabled-interfaces lp:~mpontillo/maas into -b master lp:~maas-committers/maas

STATUS: FAILED BUILD
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/118/console

Revision history for this message
Mike Pontillo (mpontillo) wrote :

Looks like some type of random failure with postgresql.

http://paste.ubuntu.com/25124643/

Revision history for this message
Andres Rodriguez (andreserl) wrote :

Let's file a bug for that :)

On Wed, Jul 19, 2017 at 12:10 PM Mike Pontillo <email address hidden>
wrote:

> Looks like some type of random failure with postgresql.
>
> http://paste.ubuntu.com/25124643/
> --
> https://code.launchpad.net/~mpontillo/maas/+git/maas/+merge/327688
> Your team MAAS Committers is subscribed to branch maas:master.
>
--
Andres Rodriguez
Engineering Manager, MAAS
Canonical USA, Inc.

Revision history for this message
Mike Pontillo (mpontillo) wrote :

I would file a bug, but it would be Incomplete. =(

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 0b92fb1..d27a111 100644
3--- a/src/maasserver/models/node.py
4+++ b/src/maasserver/models/node.py
5@@ -4148,9 +4148,16 @@ class Controller(Node):
6 "name": name,
7 "enabled": is_enabled,
8 })
9- if create_fabrics and interface.vlan is None:
10- new_vlan = self._update_vlan_for_interface(
11- interface, config, new_vlan)
12+ # Don't update the VLAN unless:
13+ # (1) We're at the phase where we're creating fabrics.
14+ # (that is, beaconing has already completed)
15+ # (2) The interface's VLAN wasn't previously known.
16+ # (3) The interface is administratively enabled.
17+ if create_fabrics and interface.vlan is None and is_enabled:
18+ new_vlan = self._guess_vlan_for_interface(interface, config)
19+ if new_vlan is not None:
20+ interface.vlan = new_vlan
21+ update_fields.add('vlan')
22 if not created:
23 if interface.node.id != self.id:
24 # MAC address was on a different node. We need to move
25@@ -4187,14 +4194,20 @@ class Controller(Node):
26 # a link re-assigned the VLAN this interface is connected to.
27 new_vlan.fabric.delete()
28
29- def _update_vlan_for_interface(self, interface, config, new_vlan):
30+ def _guess_vlan_for_interface(self, interface, config):
31 # Make sure that the VLAN on the interface is correct. When
32 # links exists on this interface we place it into the correct
33 # VLAN. If it cannot be determined and its a new interface it
34 # gets placed on its own fabric.
35+ new_vlan = None
36 connected_to_subnets = self._get_connected_subnets(
37 config["links"])
38- if len(connected_to_subnets) == 0:
39+ if len(connected_to_subnets) > 0:
40+ for subnet in connected_to_subnets:
41+ new_vlan = subnet.vlan
42+ if new_vlan is not None:
43+ break
44+ if new_vlan is None:
45 # If the default VLAN on the default fabric has no interfaces
46 # associated with it, the first interface will be placed there
47 # (rather than creating a new fabric).
48@@ -4206,8 +4219,6 @@ class Controller(Node):
49 else:
50 new_fabric = Fabric.objects.create()
51 new_vlan = new_fabric.get_default_vlan()
52- interface.vlan = new_vlan
53- interface.save()
54 return new_vlan
55
56 def _get_or_create_vlan_interface(self, name, vlan, parent):
57diff --git a/src/maasserver/models/tests/test_node.py b/src/maasserver/models/tests/test_node.py
58index 60d82db..88ad200 100644
59--- a/src/maasserver/models/tests/test_node.py
60+++ b/src/maasserver/models/tests/test_node.py
61@@ -9213,6 +9213,34 @@ class TestUpdateInterfaces(MAASServerTestCase):
62 self.assertIsNotNone(eth0)
63 self.assertIsNotNone(br0)
64
65+ def test_disabled_interfaces_do_not_create_fabrics(self):
66+ controller = self.create_empty_controller()
67+ interfaces = {
68+ 'eth0': {
69+ 'enabled': True,
70+ 'links': [],
71+ 'mac_address': '52:54:00:77:15:e3',
72+ 'parents': [],
73+ 'source': 'ipaddr',
74+ 'type': 'physical'
75+ },
76+ 'eth1': {
77+ 'enabled': False,
78+ 'links': [],
79+ 'mac_address': '52:54:00:77:15:e4',
80+ 'parents': [],
81+ 'source': 'ipaddr',
82+ 'type': 'physical'
83+ },
84+ }
85+ self.update_interfaces(controller, interfaces)
86+ eth0 = get_one(
87+ PhysicalInterface.objects.filter(node=controller, name='eth0'))
88+ eth1 = get_one(
89+ PhysicalInterface.objects.filter(node=controller, name='eth1'))
90+ self.assertIsNotNone(eth0.vlan)
91+ self.assertIsNone(eth1.vlan)
92+
93
94 class TestRackControllerRefresh(MAASTransactionServerTestCase):
95

Subscribers

People subscribed via source and target branches