Merge lp:~mpontillo/maas/commissioning-fixes-trunk into lp:~maas-committers/maas/trunk

Proposed by Mike Pontillo
Status: Merged
Approved by: Mike Pontillo
Approved revision: no longer in the source branch.
Merged at revision: 4553
Proposed branch: lp:~mpontillo/maas/commissioning-fixes-trunk
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 188 lines (+68/-25)
4 files modified
src/maasserver/models/interface.py (+13/-1)
src/maasserver/models/tests/test_interface.py (+32/-0)
src/maasserver/testing/factory.py (+12/-6)
src/metadataserver/models/commissioningscript.py (+11/-18)
To merge this branch: bzr merge lp:~mpontillo/maas/commissioning-fixes-trunk
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+280228@code.launchpad.net

Commit message

Merge fix for bug 1524924 from MAAS 1.9 at revsion 4530. Fixes node interfaces being configured in an incorrect subnet after commissioning.

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

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/models/interface.py'
--- src/maasserver/models/interface.py 2015-12-09 02:02:23 +0000
+++ src/maasserver/models/interface.py 2015-12-11 03:55:02 +0000
@@ -455,8 +455,20 @@
455 # to create or update the Subnet)455 # to create or update the Subnet)
456 try:456 try:
457 subnet = Subnet.objects.get(cidr=cidr)457 subnet = Subnet.objects.get(cidr=cidr)
458 # Update VLAN based on the VLAN this Subnet belongs to.
459 if subnet.vlan != self.vlan:
460 vlan = subnet.vlan
461 maaslog.info("%s: Observed connected to %s via %s." % (
462 self.get_log_string(), vlan.fabric.get_name(), cidr))
463 self.vlan = vlan
464 self.save()
458 except Subnet.DoesNotExist:465 except Subnet.DoesNotExist:
459 # XXX mpontillo 2015-11-01 configuration != state466 # XXX mpontillo 2015-11-01 Configuration != state. That is,
467 # this means we have just a subnet on an unknown Fabric/VLAN,
468 # and this fact should be recorded somewhere, so that the user
469 # gets a chance to configure it. Note, however, that if this
470 # is already a managed cluster interface, a Fabric/VLAN will
471 # already have been created.
460 subnet = Subnet.objects.create_from_cidr(cidr)472 subnet = Subnet.objects.create_from_cidr(cidr)
461 maaslog.info(473 maaslog.info(
462 "Creating subnet %s connected to interface %s "474 "Creating subnet %s connected to interface %s "
463475
=== modified file 'src/maasserver/models/tests/test_interface.py'
--- src/maasserver/models/tests/test_interface.py 2015-12-09 02:02:23 +0000
+++ src/maasserver/models/tests/test_interface.py 2015-12-11 03:55:02 +0000
@@ -1038,6 +1038,38 @@
1038 alloc_type=IPADDRESS_TYPE.DISCOVERED, subnet=subnet_list[i],1038 alloc_type=IPADDRESS_TYPE.DISCOVERED, subnet=subnet_list[i],
1039 ip=str(IPNetwork(cidr_list[i]).ip)))1039 ip=str(IPNetwork(cidr_list[i]).ip)))
10401040
1041 def test__links_interface_to_vlan_on_existing_subnet_with_logging(self):
1042 ng = factory.make_NodeGroup()
1043 fabric2 = factory.make_Fabric()
1044 fabric3 = factory.make_Fabric()
1045 ngi1 = factory.make_NodeGroupInterface(ng)
1046 ngi2 = factory.make_NodeGroupInterface(ng, fabric=fabric2)
1047 ngi3 = factory.make_NodeGroupInterface(ng, fabric=fabric3)
1048 interface1 = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
1049 interface2 = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
1050 interface3 = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
1051 vlan1 = ngi1.subnet.vlan
1052 vlan2 = ngi2.subnet.vlan
1053 vlan3 = ngi3.subnet.vlan
1054 maaslog = self.patch_autospec(interface_module, "maaslog")
1055 interface1.update_ip_addresses([ngi1.subnet.cidr])
1056 interface2.update_ip_addresses([ngi2.subnet.cidr])
1057 interface3.update_ip_addresses([ngi3.subnet.cidr])
1058 self.assertThat(interface1.vlan, Equals(vlan1))
1059 self.assertThat(interface2.vlan, Equals(vlan2))
1060 self.assertThat(interface3.vlan, Equals(vlan3))
1061 self.assertThat(maaslog.info, MockCallsMatch(
1062 call(("%s: Observed connected to %s via %s." % (
1063 interface1.get_log_string(), interface1.vlan.fabric.get_name(),
1064 ngi1.subnet.cidr))),
1065 call(("%s: Observed connected to %s via %s." % (
1066 interface2.get_log_string(), interface2.vlan.fabric.get_name(),
1067 ngi2.subnet.cidr))),
1068 call(("%s: Observed connected to %s via %s." % (
1069 interface3.get_log_string(), interface3.vlan.fabric.get_name(),
1070 ngi3.subnet.cidr))),
1071 ))
1072
1041 def test__deletes_old_discovered_ip_addresses_on_interface(self):1073 def test__deletes_old_discovered_ip_addresses_on_interface(self):
1042 interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)1074 interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
1043 # Create existing DISCOVERED IP address on the interface. These should1075 # Create existing DISCOVERED IP address on the interface. These should
10441076
=== modified file 'src/maasserver/testing/factory.py'
--- src/maasserver/testing/factory.py 2015-12-09 01:24:24 +0000
+++ src/maasserver/testing/factory.py 2015-12-11 03:55:02 +0000
@@ -482,7 +482,8 @@
482 ip_range_low=None, ip_range_high=None,482 ip_range_low=None, ip_range_high=None,
483 interface=None, management=None,483 interface=None, management=None,
484 static_ip_range_low=None,484 static_ip_range_low=None,
485 static_ip_range_high=None, **kwargs):485 static_ip_range_high=None, fabric=None,
486 **kwargs):
486 interface_settings = self.get_interface_fields(487 interface_settings = self.get_interface_fields(
487 name=name, ip=ip, router_ip=router_ip,488 name=name, ip=ip, router_ip=router_ip,
488 network=network, subnet=subnet, subnet_mask=subnet_mask,489 network=network, subnet=subnet, subnet_mask=subnet_mask,
@@ -498,12 +499,17 @@
498 cidr = create_cidr(499 cidr = create_cidr(
499 interface_settings['ip'], interface_settings['subnet_mask'])500 interface_settings['ip'], interface_settings['subnet_mask'])
500501
502 defaults = {
503 'name': cidr,
504 'cidr': cidr,
505 'space': Space.objects.get_default_space(),
506 }
507
508 if fabric is not None:
509 defaults['vlan'] = fabric.get_default_vlan()
510
501 subnet, _ = Subnet.objects.get_or_create(511 subnet, _ = Subnet.objects.get_or_create(
502 cidr=cidr, defaults={512 cidr=cidr, defaults=defaults)
503 'name': cidr,
504 'cidr': cidr,
505 'space': Space.objects.get_default_space(),
506 })
507 elif interface_settings['subnet']:513 elif interface_settings['subnet']:
508 subnet = interface_settings.pop('subnet')514 subnet = interface_settings.pop('subnet')
509 interface_settings['subnet_mask'] = subnet.get_ipnetwork().netmask515 interface_settings['subnet_mask'] = subnet.get_ipnetwork().netmask
510516
=== modified file 'src/metadataserver/models/commissioningscript.py'
--- src/metadataserver/models/commissioningscript.py 2015-12-01 18:12:59 +0000
+++ src/metadataserver/models/commissioningscript.py 2015-12-11 03:55:02 +0000
@@ -130,8 +130,7 @@
130"""130"""
131131
132132
133def _create_default_physical_interface(133def _create_default_physical_interface(node, ifname, mac):
134 node, ifname, mac, fabric=None, vlan=None):
135 """Assigns the specified interface to the specified Node.134 """Assigns the specified interface to the specified Node.
136135
137 Creates or updates a PhysicalInterface that corresponds to the given MAC.136 Creates or updates a PhysicalInterface that corresponds to the given MAC.
@@ -140,18 +139,15 @@
140 :param ifname: the interface name (for example, 'eth0')139 :param ifname: the interface name (for example, 'eth0')
141 :param mac: the Interface to update and associate140 :param mac: the Interface to update and associate
142 """141 """
143 if fabric is None:142 # We don't yet have enough information to put this newly-created Interface
144 fabric = Fabric.objects.get_default_fabric()143 # into the proper Fabric/VLAN. (We'll do this on a "best effort" basis
145144 # later, if we are able to determine that the interface is on a particular
146 if vlan is None:145 # subnet due to a DHCP reply during commissioning.)
147 vlan = fabric.get_default_vlan()146 fabric = Fabric.objects.get_default_fabric()
148147 vlan = fabric.get_default_vlan()
149 interface = PhysicalInterface.objects.create(148 interface = PhysicalInterface.objects.create(
150 mac_address=mac, name=ifname, node=node, vlan=vlan)149 mac_address=mac, name=ifname, node=node, vlan=vlan)
151150
152 # XXX:fabric - for now we use the default fabric, but we need to be smarter
153 # about determining which fabric the node is in. (perhaps the cluster
154 # interface the node is linked to has an associated fabric, for example)
155 return interface151 return interface
156152
157153
@@ -185,7 +181,6 @@
185 else:181 else:
186 ifname = link['name']182 ifname = link['name']
187 try:183 try:
188 # XXX:fabric - this MAC might exist on a different Fabric
189 interface = PhysicalInterface.objects.get(184 interface = PhysicalInterface.objects.get(
190 mac_address=link_mac)185 mac_address=link_mac)
191 if interface.node is not None and interface.node != node:186 if interface.node is not None and interface.node != node:
@@ -195,7 +190,6 @@
195 (interface.mac_address, interface.node.fqdn,190 (interface.mac_address, interface.node.fqdn,
196 node.fqdn))191 node.fqdn))
197 interface.delete()192 interface.delete()
198 # XXX: mpontillo 2015-08-27 how do we get Fabric/VLAN here?
199 interface = _create_default_physical_interface(193 interface = _create_default_physical_interface(
200 node, ifname, link_mac)194 node, ifname, link_mac)
201 else:195 else:
@@ -204,7 +198,6 @@
204 interface.name = ifname198 interface.name = ifname
205 interface.save()199 interface.save()
206 except PhysicalInterface.DoesNotExist:200 except PhysicalInterface.DoesNotExist:
207 # XXX: mpontillo 2015-08-27 how do we get Fabric/VLAN here?
208 interface = _create_default_physical_interface(201 interface = _create_default_physical_interface(
209 node, ifname, link_mac)202 node, ifname, link_mac)
210203
@@ -681,10 +674,6 @@
681 'content': LIST_MODALIASES_SCRIPT.encode('ascii'),674 'content': LIST_MODALIASES_SCRIPT.encode('ascii'),
682 'hook': null_hook,675 'hook': null_hook,
683 },676 },
684 '00-maas-05-network-interfaces.out': {
685 'content': IPADDR_SCRIPT.encode('ascii'),
686 'hook': update_node_network_information,
687 },
688 '00-maas-06-dhcp-unconfigured-ifaces': {677 '00-maas-06-dhcp-unconfigured-ifaces': {
689 'content': make_function_call_script(dhcp_explore),678 'content': make_function_call_script(dhcp_explore),
690 'hook': null_hook,679 'hook': null_hook,
@@ -702,6 +691,10 @@
702 'content': make_function_call_script(lldpd_capture),691 'content': make_function_call_script(lldpd_capture),
703 'hook': set_node_routers,692 'hook': set_node_routers,
704 },693 },
694 '99-maas-03-network-interfaces.out': {
695 'content': IPADDR_SCRIPT.encode('ascii'),
696 'hook': update_node_network_information,
697 },
705}698}
706699
707700