Merge lp:~danilo/maas/bug-1699479-dhcp-test-stability into lp:~maas-committers/maas/trunk

Proposed by Данило Шеган
Status: Merged
Approved by: Mike Pontillo
Approved revision: no longer in the source branch.
Merged at revision: 6100
Proposed branch: lp:~danilo/maas/bug-1699479-dhcp-test-stability
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 73 lines (+25/-3)
2 files modified
src/maasserver/testing/factory.py (+5/-1)
src/maasserver/tests/test_preseed_network.py (+20/-2)
To merge this branch: bzr merge lp:~danilo/maas/bug-1699479-dhcp-test-stability
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Approve
Review via email: mp+326069@code.launchpad.net

Commit message

Make TestDHCPNetworkLayout.test__dhcp_configurations_rendered always run in both IPv4 and IPv6 network configurations to ensure it stably either passes or fails.

To avoid resolve_hostname() on the MAAS configured URL only return an IP address that it resolves to on the local system (which could be only IPv4 or only IPv6 address) which can't be used for a DNS server, we patch resolve_hostname() in the test to return the appropriate localhost address.

Description of the change

This is a fix for a test that fails on LXD containers occasionally (when subnet ends up being an IPv6 network).

To post a comment you must log in.
Revision history for this message
Mike Pontillo (mpontillo) wrote :

I much prefer the v4 and v6 scenario approach to pure randomness. Thanks for the fix.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/testing/factory.py'
--- src/maasserver/testing/factory.py 2017-04-26 23:46:21 +0000
+++ src/maasserver/testing/factory.py 2017-06-21 12:05:32 +0000
@@ -767,6 +767,10 @@
767 if 'iftype' in kwargs:767 if 'iftype' in kwargs:
768 iftype = kwargs['iftype']768 iftype = kwargs['iftype']
769 del kwargs['iftype']769 del kwargs['iftype']
770 if 'ip_version' in kwargs and cidr is None:
771 ip_version = kwargs.pop('ip_version')
772 else:
773 ip_version = None
770 node = self.make_Node(fabric=fabric, **kwargs)774 node = self.make_Node(fabric=fabric, **kwargs)
771 if vlan is None and subnet is not None:775 if vlan is None and subnet is not None:
772 vlan = subnet.vlan776 vlan = subnet.vlan
@@ -778,7 +782,7 @@
778 vlan.dhcp_on = dhcp_on782 vlan.dhcp_on = dhcp_on
779 vlan.save()783 vlan.save()
780 if subnet is None:784 if subnet is None:
781 subnet = self.make_Subnet(vlan=vlan, cidr=cidr)785 subnet = self.make_Subnet(vlan=vlan, cidr=cidr, version=ip_version)
782 boot_interface = self.make_Interface(786 boot_interface = self.make_Interface(
783 iftype, name=ifname, node=node, vlan=vlan,787 iftype, name=ifname, node=node, vlan=vlan,
784 mac_address=mac_address)788 mac_address=mac_address)
785789
=== modified file 'src/maasserver/tests/test_preseed_network.py'
--- src/maasserver/tests/test_preseed_network.py 2017-03-09 16:32:52 +0000
+++ src/maasserver/tests/test_preseed_network.py 2017-06-21 12:05:32 +0000
@@ -20,9 +20,13 @@
20 compose_curtin_network_config,20 compose_curtin_network_config,
21 NodeNetworkConfiguration,21 NodeNetworkConfiguration,
22)22)
23import maasserver.server_address
23from maasserver.testing.factory import factory24from maasserver.testing.factory import factory
24from maasserver.testing.testcase import MAASServerTestCase25from maasserver.testing.testcase import MAASServerTestCase
25from netaddr import IPNetwork26from netaddr import (
27 IPAddress,
28 IPNetwork,
29)
26from testtools.matchers import (30from testtools.matchers import (
27 ContainsDict,31 ContainsDict,
28 Equals,32 Equals,
@@ -406,8 +410,14 @@
406class TestDHCPNetworkLayout(MAASServerTestCase,410class TestDHCPNetworkLayout(MAASServerTestCase,
407 AssertNetworkConfigMixin):411 AssertNetworkConfigMixin):
408412
413 scenarios = (
414 ('ipv4', {'ip_version': 4}),
415 ('ipv6', {'ip_version': 6}),
416 )
417
409 def test__dhcp_configurations_rendered(self):418 def test__dhcp_configurations_rendered(self):
410 node = factory.make_Node_with_Interface_on_Subnet()419 node = factory.make_Node_with_Interface_on_Subnet(
420 ip_version=self.ip_version)
411 iface = node.interface_set.first()421 iface = node.interface_set.first()
412 subnet = iface.vlan.subnet_set.first()422 subnet = iface.vlan.subnet_set.first()
413 factory.make_StaticIPAddress(423 factory.make_StaticIPAddress(
@@ -415,6 +425,14 @@
415 alloc_type=IPADDRESS_TYPE.DHCP,425 alloc_type=IPADDRESS_TYPE.DHCP,
416 interface=iface,426 interface=iface,
417 subnet=subnet)427 subnet=subnet)
428 # Patch resolve_hostname() to return the appropriate network version
429 # IP address for MAAS hostname.
430 resolve_hostname = self.patch(
431 maasserver.server_address, "resolve_hostname")
432 if self.ip_version == 4:
433 resolve_hostname.return_value = {IPAddress("127.0.0.1")}
434 else:
435 resolve_hostname.return_value = {IPAddress("::1")}
418 config = compose_curtin_network_config(node)436 config = compose_curtin_network_config(node)
419 config_yaml = yaml.safe_load(config[0])437 config_yaml = yaml.safe_load(config[0])
420 self.assertThat(438 self.assertThat(