Merge lp:~allenap/maas/subnet-attribute-error--bug-1671048 into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 5829
Proposed branch: lp:~allenap/maas/subnet-attribute-error--bug-1671048
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 140 lines (+43/-20)
2 files modified
src/maasserver/models/node.py (+4/-4)
src/maasserver/models/tests/test_node.py (+39/-16)
To merge this branch: bzr merge lp:~allenap/maas/subnet-attribute-error--bug-1671048
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+320512@code.launchpad.net

Commit message

Node.get_default_gateways now always returns a DefaultGateways instance which contains two GatewayDefinition instances.

Previously plain tuples were sometimes returned instead of GatewayDefinition named tuples.

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

Looks good. Thanks for the quick fix.

review: Approve
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Don't forget the backport.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/models/node.py'
2--- src/maasserver/models/node.py 2017-03-10 18:38:46 +0000
3+++ src/maasserver/models/node.py 2017-03-21 15:48:45 +0000
4@@ -3129,7 +3129,7 @@
5 interface.id
6 """, (self.id,))
7 return [
8- GatewayDefinition._make((found[0], found[1], found[2]))
9+ GatewayDefinition(found[0], found[1], found[2])
10 for found in cursor.fetchall()
11 ]
12
13@@ -3141,7 +3141,7 @@
14 def _get_gateway_tuple(self, gateway_link):
15 """Return a tuple for the interface id, subnet id, and gateway IP for
16 the `gateway_link`."""
17- return (
18+ return GatewayDefinition(
19 self._get_best_interface_from_gateway_link(
20 gateway_link),
21 gateway_link.subnet.id,
22@@ -3181,7 +3181,7 @@
23
24 # Early out if we already have both gateways.
25 if gateway_ipv4 and gateway_ipv6:
26- return DefaultGateways._make((gateway_ipv4, gateway_ipv6))
27+ return DefaultGateways(gateway_ipv4, gateway_ipv6)
28
29 # Get the best guesses for the missing IP families.
30 found_gateways = self.get_best_guess_for_default_gateways()
31@@ -3191,7 +3191,7 @@
32 if not gateway_ipv6:
33 gateway_ipv6 = self._get_gateway_tuple_by_family(
34 found_gateways, IPADDRESS_FAMILY.IPv6)
35- return DefaultGateways._make((gateway_ipv4, gateway_ipv6))
36+ return DefaultGateways(gateway_ipv4, gateway_ipv6)
37
38 def get_default_dns_servers(self, ipv4=True, ipv6=True):
39 """Return the default DNS servers for this node."""
40
41=== modified file 'src/maasserver/models/tests/test_node.py'
42--- src/maasserver/models/tests/test_node.py 2017-03-10 18:38:46 +0000
43+++ src/maasserver/models/tests/test_node.py 2017-03-21 15:48:45 +0000
44@@ -197,6 +197,7 @@
45 HasLength,
46 Is,
47 IsInstance,
48+ MatchesAll,
49 MatchesSetwise,
50 MatchesStructure,
51 Not,
52@@ -5209,6 +5210,24 @@
53 node.get_best_guess_for_default_gateways())
54
55
56+def MatchesDefaultGateways(ipv4, ipv6):
57+ # Matches a `DefaultGateways` instance, which must contain
58+ # `GatewayDefinition` instances, not just plain tuples.
59+ return MatchesAll(
60+ IsInstance(DefaultGateways),
61+ MatchesStructure(
62+ ipv4=MatchesAll(
63+ IsInstance(GatewayDefinition),
64+ Equals(ipv4),
65+ ),
66+ ipv6=MatchesAll(
67+ IsInstance(GatewayDefinition),
68+ Equals(ipv6),
69+ ),
70+ ),
71+ )
72+
73+
74 class TestGetDefaultGateways(MAASServerTestCase):
75 """Tests for `Node.get_default_gateways`."""
76
77@@ -5244,10 +5263,11 @@
78 node.gateway_link_ipv4 = link_v4
79 node.gateway_link_ipv6 = link_v6
80 node.save()
81- self.assertEqual((
82- (interface.id, subnet_v4_2.id, subnet_v4_2.gateway_ip),
83- (interface.id, subnet_v6_2.id, subnet_v6_2.gateway_ip),
84- ), node.get_default_gateways())
85+ self.assertThat(
86+ node.get_default_gateways(), MatchesDefaultGateways(
87+ (interface.id, subnet_v4_2.id, subnet_v4_2.gateway_ip),
88+ (interface.id, subnet_v6_2.id, subnet_v6_2.gateway_ip),
89+ ))
90
91 def test__return_set_ipv4_and_guess_ipv6(self):
92 node = factory.make_Node(status=NODE_STATUS.READY)
93@@ -5273,10 +5293,11 @@
94 subnet=subnet_v6, interface=interface)
95 node.gateway_link_ipv4 = link_v4
96 node.save()
97- self.assertEqual((
98- (interface.id, subnet_v4_2.id, subnet_v4_2.gateway_ip),
99- (interface.id, subnet_v6.id, subnet_v6.gateway_ip),
100- ), node.get_default_gateways())
101+ self.assertThat(
102+ node.get_default_gateways(), MatchesDefaultGateways(
103+ (interface.id, subnet_v4_2.id, subnet_v4_2.gateway_ip),
104+ (interface.id, subnet_v6.id, subnet_v6.gateway_ip),
105+ ))
106
107 def test__return_set_ipv6_and_guess_ipv4(self):
108 node = factory.make_Node(status=NODE_STATUS.READY)
109@@ -5302,10 +5323,11 @@
110 subnet=subnet_v6_2, interface=interface)
111 node.gateway_link_ipv6 = link_v6
112 node.save()
113- self.assertEqual((
114- (interface.id, subnet_v4.id, subnet_v4.gateway_ip),
115- (interface.id, subnet_v6_2.id, subnet_v6_2.gateway_ip),
116- ), node.get_default_gateways())
117+ self.assertThat(
118+ node.get_default_gateways(), MatchesDefaultGateways(
119+ (interface.id, subnet_v4.id, subnet_v4.gateway_ip),
120+ (interface.id, subnet_v6_2.id, subnet_v6_2.gateway_ip),
121+ ))
122
123 def test__return_guess_ipv4_and_ipv6(self):
124 node = factory.make_Node(status=NODE_STATUS.READY)
125@@ -5322,10 +5344,11 @@
126 alloc_type=IPADDRESS_TYPE.STICKY,
127 ip=factory.pick_ip_in_network(network_v6),
128 subnet=subnet_v6, interface=interface)
129- self.assertEqual((
130- (interface.id, subnet_v4.id, subnet_v4.gateway_ip),
131- (interface.id, subnet_v6.id, subnet_v6.gateway_ip),
132- ), node.get_default_gateways())
133+ self.assertThat(
134+ node.get_default_gateways(), MatchesDefaultGateways(
135+ (interface.id, subnet_v4.id, subnet_v4.gateway_ip),
136+ (interface.id, subnet_v6.id, subnet_v6.gateway_ip),
137+ ))
138
139
140 class TestGetDefaultDNSServers(MAASServerTestCase):