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
1=== modified file 'src/maasserver/testing/factory.py'
2--- src/maasserver/testing/factory.py 2017-04-26 23:46:21 +0000
3+++ src/maasserver/testing/factory.py 2017-06-21 12:05:32 +0000
4@@ -767,6 +767,10 @@
5 if 'iftype' in kwargs:
6 iftype = kwargs['iftype']
7 del kwargs['iftype']
8+ if 'ip_version' in kwargs and cidr is None:
9+ ip_version = kwargs.pop('ip_version')
10+ else:
11+ ip_version = None
12 node = self.make_Node(fabric=fabric, **kwargs)
13 if vlan is None and subnet is not None:
14 vlan = subnet.vlan
15@@ -778,7 +782,7 @@
16 vlan.dhcp_on = dhcp_on
17 vlan.save()
18 if subnet is None:
19- subnet = self.make_Subnet(vlan=vlan, cidr=cidr)
20+ subnet = self.make_Subnet(vlan=vlan, cidr=cidr, version=ip_version)
21 boot_interface = self.make_Interface(
22 iftype, name=ifname, node=node, vlan=vlan,
23 mac_address=mac_address)
24
25=== modified file 'src/maasserver/tests/test_preseed_network.py'
26--- src/maasserver/tests/test_preseed_network.py 2017-03-09 16:32:52 +0000
27+++ src/maasserver/tests/test_preseed_network.py 2017-06-21 12:05:32 +0000
28@@ -20,9 +20,13 @@
29 compose_curtin_network_config,
30 NodeNetworkConfiguration,
31 )
32+import maasserver.server_address
33 from maasserver.testing.factory import factory
34 from maasserver.testing.testcase import MAASServerTestCase
35-from netaddr import IPNetwork
36+from netaddr import (
37+ IPAddress,
38+ IPNetwork,
39+)
40 from testtools.matchers import (
41 ContainsDict,
42 Equals,
43@@ -406,8 +410,14 @@
44 class TestDHCPNetworkLayout(MAASServerTestCase,
45 AssertNetworkConfigMixin):
46
47+ scenarios = (
48+ ('ipv4', {'ip_version': 4}),
49+ ('ipv6', {'ip_version': 6}),
50+ )
51+
52 def test__dhcp_configurations_rendered(self):
53- node = factory.make_Node_with_Interface_on_Subnet()
54+ node = factory.make_Node_with_Interface_on_Subnet(
55+ ip_version=self.ip_version)
56 iface = node.interface_set.first()
57 subnet = iface.vlan.subnet_set.first()
58 factory.make_StaticIPAddress(
59@@ -415,6 +425,14 @@
60 alloc_type=IPADDRESS_TYPE.DHCP,
61 interface=iface,
62 subnet=subnet)
63+ # Patch resolve_hostname() to return the appropriate network version
64+ # IP address for MAAS hostname.
65+ resolve_hostname = self.patch(
66+ maasserver.server_address, "resolve_hostname")
67+ if self.ip_version == 4:
68+ resolve_hostname.return_value = {IPAddress("127.0.0.1")}
69+ else:
70+ resolve_hostname.return_value = {IPAddress("::1")}
71 config = compose_curtin_network_config(node)
72 config_yaml = yaml.safe_load(config[0])
73 self.assertThat(