Merge lp:~lamont/maas/bug-1603590-1.9 into lp:maas/1.9

Proposed by LaMont Jones on 2016-07-16
Status: Merged
Approved by: LaMont Jones on 2016-07-19
Approved revision: 4598
Merged at revision: 4594
Proposed branch: lp:~lamont/maas/bug-1603590-1.9
Merge into: lp:maas/1.9
Diff against target: 66 lines (+33/-1)
3 files modified
docs/changelog.rst (+5/-0)
src/maasserver/models/subnet.py (+11/-1)
src/maasserver/models/tests/test_subnet.py (+17/-0)
To merge this branch: bzr merge lp:~lamont/maas/bug-1603590-1.9
Reviewer Review Type Date Requested Status
Mike Pontillo (community) 2016-07-16 Approve on 2016-07-18
Review via email: mp+300259@code.launchpad.net

Commit message

Allow link-local addresses (fe80::/64) for the default gateway for a subnet.

Description of the change

Allow link-local addresses (fe80::/64) for the default gateway for a subnet.

To post a comment you must log in.
lp:~lamont/maas/bug-1603590-1.9 updated on 2016-07-18
4596. By LaMont Jones on 2016-07-17

fix test failures

4597. By LaMont Jones on 2016-07-17

update changelog

4598. By LaMont Jones on 2016-07-17

IPAddress.is_link_local arrived in precise or ealier

Mike Pontillo (mpontillo) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'docs/changelog.rst'
2--- docs/changelog.rst 2016-07-13 01:23:13 +0000
3+++ docs/changelog.rst 2016-07-18 17:26:29 +0000
4@@ -2,6 +2,11 @@
5 Changelog
6 =========
7
8+1.9.5
9+=====
10+
11+LP: #1603590 [1.9] MAAS does not allow link-local address for default gateway on ipv6 subnet.
12+
13 1.9.4
14 =====
15
16
17=== modified file 'src/maasserver/models/subnet.py'
18--- src/maasserver/models/subnet.py 2015-12-03 10:41:08 +0000
19+++ src/maasserver/models/subnet.py 2016-07-18 17:26:29 +0000
20@@ -383,7 +383,17 @@
21 if self.gateway_ip is None or self.gateway_ip == '':
22 return
23 gateway_addr = IPAddress(self.gateway_ip)
24- if gateway_addr not in self.get_ipnetwork():
25+ network = self.get_ipnetwork()
26+ if gateway_addr in network:
27+ # If the gateway is in the network, it is fine.
28+ return
29+ elif network.version == 6 and gateway_addr.is_link_local():
30+ # If this is an IPv6 network and the gateway is in the link-local
31+ # network (fe80::/64 -- required to be configured by the spec),
32+ # then it is also valid.
33+ return
34+ else:
35+ # The gateway is not valid for the network.
36 message = "Gateway IP must be within CIDR range."
37 raise ValidationError({'gateway_ip': [message]})
38
39
40=== modified file 'src/maasserver/models/tests/test_subnet.py'
41--- src/maasserver/models/tests/test_subnet.py 2015-11-06 01:55:30 +0000
42+++ src/maasserver/models/tests/test_subnet.py 2016-07-18 17:26:29 +0000
43@@ -445,6 +445,23 @@
44 {'gateway_ip': ["Gateway IP must be within CIDR range."]},
45 error.message_dict)
46
47+ def test_allows_fe80_gateway(self):
48+ network = factory.make_ipv6_network(slash=64)
49+ gateway_ip = factory.pick_ip_in_network(IPNetwork('fe80::/64'))
50+ subnet = factory.make_Subnet(
51+ cidr=unicode(network), gateway_ip=gateway_ip)
52+ self.assertEqual(subnet.gateway_ip, gateway_ip)
53+
54+ def test_denies_fe80_gateway_for_ipv4(self):
55+ network = factory.make_ipv4_network(slash=22)
56+ gateway_ip = factory.pick_ip_in_network(IPNetwork('fe80::/64'))
57+ error = self.assertRaises(
58+ ValidationError, factory.make_Subnet,
59+ cidr=unicode(network), gateway_ip=gateway_ip)
60+ self.assertEqual(
61+ {'gateway_ip': ["Gateway IP must be within CIDR range."]},
62+ error.message_dict)
63+
64 def test_create_from_cidr_creates_subnet(self):
65 vlan = factory.make_VLAN()
66 cidr = unicode(factory.make_ip4_or_6_network().cidr)

Subscribers

People subscribed via source and target branches