Merge ~mpontillo/maas:fix-ha-rack-dhcp-fabric-creation--bug-1705654 into maas:master

Proposed by Mike Pontillo on 2017-07-21
Status: Merged
Approved by: Mike Pontillo on 2017-07-26
Approved revision: 6a30b4892814133268b596a845f923bf22d2b283
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~mpontillo/maas:fix-ha-rack-dhcp-fabric-creation--bug-1705654
Merge into: maas:master
Diff against target: 156 lines (+74/-7)
4 files modified
src/maasserver/models/node.py (+12/-6)
src/maasserver/models/signals/interfaces.py (+2/-0)
src/maasserver/models/signals/tests/test_interfaces.py (+13/-1)
src/maasserver/models/tests/test_node.py (+47/-0)
Reviewer Review Type Date Requested Status
Blake Rouse 2017-07-21 Approve on 2017-07-21
Review via email: mp+327859@code.launchpad.net

Commit message

Fix fabric creation for rack DHCP IP addresses.

LP: #1705654

To post a comment you must log in.
Blake Rouse (blake-rouse) wrote :

Looks good.

review: Approve
MAAS Lander (maas-lander) wrote :

LANDING
-b fix-ha-rack-dhcp-fabric-creation--bug-1705654 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/126/console

MAAS Lander (maas-lander) wrote :

LANDING
-b fix-ha-rack-dhcp-fabric-creation--bug-1705654 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/127/console

MAAS Lander (maas-lander) wrote :

LANDING
-b fix-ha-rack-dhcp-fabric-creation--bug-1705654 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/128/console

MAAS Lander (maas-lander) wrote :

LANDING
-b fix-ha-rack-dhcp-fabric-creation--bug-1705654 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/137/console

MAAS Lander (maas-lander) wrote :

LANDING
-b fix-ha-rack-dhcp-fabric-creation--bug-1705654 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/138/console

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/maasserver/models/node.py b/src/maasserver/models/node.py
index d27a111..7ff13c5 100644
--- a/src/maasserver/models/node.py
+++ b/src/maasserver/models/node.py
@@ -4184,7 +4184,7 @@ class Controller(Node):
4184 def _update_physical_links(self, interface, config, new_vlan,4184 def _update_physical_links(self, interface, config, new_vlan,
4185 update_fields):4185 update_fields):
4186 update_ip_addresses = self._update_links(interface, config["links"])4186 update_ip_addresses = self._update_links(interface, config["links"])
4187 linked_vlan = self._get_first_sticky_vlan_from_ip_addresses(4187 linked_vlan = self._guess_best_vlan_from_ip_addresses(
4188 update_ip_addresses)4188 update_ip_addresses)
4189 if linked_vlan is not None:4189 if linked_vlan is not None:
4190 interface.vlan = linked_vlan4190 interface.vlan = linked_vlan
@@ -4381,7 +4381,7 @@ class Controller(Node):
4381 If a static IP address is allocated, give preferential treatment to4381 If a static IP address is allocated, give preferential treatment to
4382 the VLAN that IP address resides on.4382 the VLAN that IP address resides on.
4383 """4383 """
4384 linked_vlan = self._get_first_sticky_vlan_from_ip_addresses(4384 linked_vlan = self._guess_best_vlan_from_ip_addresses(
4385 update_ip_addresses)4385 update_ip_addresses)
4386 if linked_vlan is not None:4386 if linked_vlan is not None:
4387 interface.vlan = linked_vlan4387 interface.vlan = linked_vlan
@@ -4417,8 +4417,11 @@ class Controller(Node):
4417 """Return a set of subnets that `links` belongs to."""4417 """Return a set of subnets that `links` belongs to."""
4418 subnets = set()4418 subnets = set()
4419 for link in links:4419 for link in links:
4420 if link["mode"] == "static":4420 if link["mode"] == "static" or link["mode"] == "dhcp":
4421 ip_addr = IPNetwork(link["address"])4421 address = link.get("address", None)
4422 if address is None:
4423 continue
4424 ip_addr = IPNetwork(address)
4422 subnet = get_one(Subnet.objects.filter(cidr=str(ip_addr.cidr)))4425 subnet = get_one(Subnet.objects.filter(cidr=str(ip_addr.cidr)))
4423 if subnet is not None:4426 if subnet is not None:
4424 subnets.add(subnet)4427 subnets.add(subnet)
@@ -4439,12 +4442,15 @@ class Controller(Node):
4439 return ip_address4442 return ip_address
4440 return None4443 return None
44414444
4442 def _get_first_sticky_vlan_from_ip_addresses(self, ip_addresses):4445 def _guess_best_vlan_from_ip_addresses(self, ip_addresses):
4443 """Return the first VLAN for a STICKY IP address in `ip_addresses`."""4446 """Return the first VLAN for a STICKY IP address in `ip_addresses`."""
4447 second_best = None
4444 for ip_address in ip_addresses:4448 for ip_address in ip_addresses:
4445 if ip_address.alloc_type == IPADDRESS_TYPE.STICKY:4449 if ip_address.alloc_type == IPADDRESS_TYPE.STICKY:
4446 return ip_address.subnet.vlan4450 return ip_address.subnet.vlan
4447 return None4451 elif ip_address.alloc_type == IPADDRESS_TYPE.DISCOVERED:
4452 second_best = ip_address.subnet.vlan
4453 return second_best
44484454
4449 def _update_links(4455 def _update_links(
4450 self, interface, links, force_vlan=False, use_interface_vlan=True):4456 self, interface, links, force_vlan=False, use_interface_vlan=True):
diff --git a/src/maasserver/models/signals/interfaces.py b/src/maasserver/models/signals/interfaces.py
index 5c6e75a..baac5eb 100644
--- a/src/maasserver/models/signals/interfaces.py
+++ b/src/maasserver/models/signals/interfaces.py
@@ -214,6 +214,8 @@ def interface_vlan_update(instance, old_values, **kwargs):
214 NODE_TYPE.REGION_CONTROLLER,214 NODE_TYPE.REGION_CONTROLLER,
215 NODE_TYPE.RACK_CONTROLLER,215 NODE_TYPE.RACK_CONTROLLER,
216 NODE_TYPE.REGION_AND_RACK_CONTROLLER):216 NODE_TYPE.REGION_AND_RACK_CONTROLLER):
217 if old_vlan_id is None:
218 return
217 # Interface VLAN was changed on a controller. Move all linked subnets219 # Interface VLAN was changed on a controller. Move all linked subnets
218 # to that new VLAN, unless the new VLAN is None. When the VLAN is220 # to that new VLAN, unless the new VLAN is None. When the VLAN is
219 # None then the administrator is say that the interface is now221 # None then the administrator is say that the interface is now
diff --git a/src/maasserver/models/signals/tests/test_interfaces.py b/src/maasserver/models/signals/tests/test_interfaces.py
index 6af1fa9..d15235b 100644
--- a/src/maasserver/models/signals/tests/test_interfaces.py
+++ b/src/maasserver/models/signals/tests/test_interfaces.py
@@ -240,7 +240,7 @@ class TestInterfaceVLANUpdateController(MAASServerTestCase):
240 interface.save()240 interface.save()
241 self.assertEquals(new_vlan, reload_object(subnet).vlan)241 self.assertEquals(new_vlan, reload_object(subnet).vlan)
242242
243 def test__doesnt_move_link_subnets_when_vlan_is_None(self):243 def test__doesnt_move_link_subnets_when_target_vlan_is_None(self):
244 node = self.maker()244 node = self.maker()
245 interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL, node=node)245 interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL, node=node)
246 old_vlan = interface.vlan246 old_vlan = interface.vlan
@@ -251,6 +251,18 @@ class TestInterfaceVLANUpdateController(MAASServerTestCase):
251 interface.save()251 interface.save()
252 self.assertEquals(old_vlan, reload_object(subnet).vlan)252 self.assertEquals(old_vlan, reload_object(subnet).vlan)
253253
254 def test__doesnt_move_link_subnets_when_source_vlan_is_None(self):
255 node = self.maker()
256 interface = factory.make_Interface(
257 INTERFACE_TYPE.PHYSICAL, node=node, vlan=None)
258 old_vlan = interface.vlan
259 subnet = factory.make_Subnet(vlan=old_vlan)
260 factory.make_StaticIPAddress(
261 subnet=subnet, interface=interface)
262 interface.vlan = factory.make_VLAN()
263 interface.save()
264 self.assertEquals(interface.vlan, reload_object(subnet).vlan)
265
254 def test__moves_children_vlans_to_same_fabric(self):266 def test__moves_children_vlans_to_same_fabric(self):
255 node = self.maker()267 node = self.maker()
256 parent = factory.make_Interface(INTERFACE_TYPE.PHYSICAL, node=node)268 parent = factory.make_Interface(INTERFACE_TYPE.PHYSICAL, node=node)
diff --git a/src/maasserver/models/tests/test_node.py b/src/maasserver/models/tests/test_node.py
index 88ad200..42fa230 100644
--- a/src/maasserver/models/tests/test_node.py
+++ b/src/maasserver/models/tests/test_node.py
@@ -9241,6 +9241,53 @@ class TestUpdateInterfaces(MAASServerTestCase):
9241 self.assertIsNotNone(eth0.vlan)9241 self.assertIsNotNone(eth0.vlan)
9242 self.assertIsNone(eth1.vlan)9242 self.assertIsNone(eth1.vlan)
92439243
9244 def test_subnet_seen_on_second_controller_does_not_create_fabric(self):
9245 alice = self.create_empty_controller()
9246 bob = self.create_empty_controller()
9247 alice_interfaces = {
9248 'eth0': {
9249 'enabled': True,
9250 'links': [{'address': '192.168.0.1/24', 'mode': 'dhcp'}],
9251 'mac_address': '52:54:00:77:15:e3',
9252 'parents': [],
9253 'source': 'ipaddr',
9254 'type': 'physical'
9255 },
9256 'eth1': {
9257 'enabled': False,
9258 'links': [],
9259 'mac_address': '52:54:00:77:15:e4',
9260 'parents': [],
9261 'source': 'ipaddr',
9262 'type': 'physical'
9263 },
9264 }
9265 bob_interfaces = {
9266 'eth0': {
9267 'enabled': True,
9268 'links': [{'address': '192.168.0.2/24', 'mode': 'dhcp'}],
9269 'mac_address': '52:54:00:87:25:f3',
9270 'parents': [],
9271 'source': 'ipaddr',
9272 'type': 'physical'
9273 },
9274 'eth1': {
9275 'enabled': False,
9276 'links': [],
9277 'mac_address': '52:54:00:87:25:f4',
9278 'parents': [],
9279 'source': 'ipaddr',
9280 'type': 'physical'
9281 },
9282 }
9283 self.update_interfaces(alice, alice_interfaces)
9284 self.update_interfaces(bob, bob_interfaces)
9285 alice_eth0 = get_one(
9286 PhysicalInterface.objects.filter(node=alice, name='eth0'))
9287 bob_eth0 = get_one(
9288 PhysicalInterface.objects.filter(node=bob, name='eth0'))
9289 self.assertThat(alice_eth0.vlan, Equals(bob_eth0.vlan))
9290
92449291
9245class TestRackControllerRefresh(MAASTransactionServerTestCase):9292class TestRackControllerRefresh(MAASTransactionServerTestCase):
92469293

Subscribers

People subscribed via source and target branches

to all changes: