Merge lp:~mpontillo/maas/auto-assigned-gateway-ip--1.9--bug-1690231 into lp:maas/1.9

Proposed by Mike Pontillo
Status: Merged
Approved by: Mike Pontillo
Approved revision: no longer in the source branch.
Merged at revision: 4600
Proposed branch: lp:~mpontillo/maas/auto-assigned-gateway-ip--1.9--bug-1690231
Merge into: lp:maas/1.9
Diff against target: 99 lines (+32/-3)
3 files modified
src/maasserver/models/interface.py (+14/-2)
src/maasserver/models/staticipaddress.py (+7/-1)
src/maasserver/models/tests/test_interface.py (+11/-0)
To merge this branch: bzr merge lp:~mpontillo/maas/auto-assigned-gateway-ip--1.9--bug-1690231
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+324080@code.launchpad.net

Commit message

Ensure the default gateway for a subnet is excluded from automatic static IP address allocation.

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

Looks good.

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (1.2 MiB)

The attempt to merge lp:~mpontillo/maas/auto-assigned-gateway-ip--1.9--bug-1690231 into lp:maas/1.9 failed. Below is the output from the failed tests.

Ign http://prodstack-zone-2.clouds.archive.ubuntu.com trusty InRelease
Get:1 http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-updates InRelease [65.9 kB]
Get:2 http://security.ubuntu.com trusty-security InRelease [65.9 kB]
Hit http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-backports InRelease
Hit http://prodstack-zone-2.clouds.archive.ubuntu.com trusty Release.gpg
Hit http://prodstack-zone-2.clouds.archive.ubuntu.com trusty Release
Get:3 http://security.ubuntu.com trusty-security/main Sources [131 kB]
Get:4 http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-updates/main Sources [398 kB]
Get:5 http://security.ubuntu.com trusty-security/universe Sources [52.5 kB]
Get:6 http://security.ubuntu.com trusty-security/main amd64 Packages [614 kB]
Get:7 http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-updates/restricted Sources [6,327 B]
Get:8 http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-updates/universe Sources [178 kB]
Get:9 http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-updates/multiverse Sources [7,767 B]
Get:10 http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages [981 kB]
Get:11 http://security.ubuntu.com trusty-security/universe amd64 Packages [157 kB]
Get:12 http://security.ubuntu.com trusty-security/main Translation-en [334 kB]
Get:13 http://security.ubuntu.com trusty-security/universe Translation-en [91.4 kB]
Get:14 http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-updates/restricted amd64 Packages [17.1 kB]
Get:15 http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages [405 kB]
Get:16 http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-updates/multiverse amd64 Packages [14.3 kB]
Get:17 http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-updates/main Translation-en [485 kB]
Get:18 http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-updates/multiverse Translation-en [7,430 B]
Get:19 http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-updates/restricted Translation-en [3,975 B]
Get:20 http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-updates/universe Translation-en [215 kB]
Hit http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-backports/main Sources
Hit http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-backports/restricted Sources
Hit http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-backports/universe Sources
Hit http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-backports/multiverse Sources
Hit http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-backports/main amd64 Packages
Hit http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-backports/restricted amd64 Packages
Hit http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-backports/universe amd64 Packages
Hit http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-backports/multiverse amd64 Packages
Hit http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-backports/main Translation-en
Hit http://prodstack-zone-2.clouds.archive.ubuntu.com trusty-backp...

Revision history for this message
Mike Pontillo (mpontillo) wrote :

Not sure why this one failed. I don't see any errors in the output from the lander. Manually re-checking.

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 2016-04-05 15:38:30 +0000
+++ src/maasserver/models/interface.py 2017-05-15 22:56:53 +0000
@@ -1116,7 +1116,7 @@
1116 alloc_type=IPADDRESS_TYPE.DISCOVERED):1116 alloc_type=IPADDRESS_TYPE.DISCOVERED):
1117 self.unlink_ip_address(ip_address, clearing_config=clearing_config)1117 self.unlink_ip_address(ip_address, clearing_config=clearing_config)
11181118
1119 def claim_auto_ips(self, exclude_addresses=[]):1119 def claim_auto_ips(self, exclude_addresses=None):
1120 """Claim IP addresses for this interfaces AUTO IP addresses.1120 """Claim IP addresses for this interfaces AUTO IP addresses.
11211121
1122 :param exclude_addresses: Exclude the following IP addresses in the1122 :param exclude_addresses: Exclude the following IP addresses in the
@@ -1124,6 +1124,8 @@
1124 runs to identify available IP address does not include the already1124 runs to identify available IP address does not include the already
1125 allocated IP addresses.1125 allocated IP addresses.
1126 """1126 """
1127 if exclude_addresses is None:
1128 exclude_addresses = set()
1127 exclude_addresses = set(exclude_addresses)1129 exclude_addresses = set(exclude_addresses)
1128 affected_nodegroups = set()1130 affected_nodegroups = set()
1129 assigned_addresses = []1131 assigned_addresses = []
@@ -1140,11 +1142,16 @@
1140 self._update_dns_zones(affected_nodegroups)1142 self._update_dns_zones(affected_nodegroups)
1141 return assigned_addresses1143 return assigned_addresses
11421144
1143 def _claim_auto_ip(self, auto_ip, exclude_addresses=[]):1145 def _claim_auto_ip(self, auto_ip, exclude_addresses=None):
1144 """Claim an IP address for the `auto_ip`.1146 """Claim an IP address for the `auto_ip`.
11451147
1146 :returns:NodeGroupInterface, new_ip_address1148 :returns:NodeGroupInterface, new_ip_address
1147 """1149 """
1150 if exclude_addresses is None:
1151 exclude_addresses = set()
1152 else:
1153 exclude_addresses = set(exclude_addresses)
1154
1148 # Check if already has a hostmap allocated for this MAC address.1155 # Check if already has a hostmap allocated for this MAC address.
1149 subnet = auto_ip.subnet1156 subnet = auto_ip.subnet
1150 if subnet is None:1157 if subnet is None:
@@ -1203,6 +1210,11 @@
1203 static_ip_range_low, static_ip_range_high = (1210 static_ip_range_low, static_ip_range_high = (
1204 get_first_and_last_usable_host_in_network(network))1211 get_first_and_last_usable_host_in_network(network))
1205 in_use_ipset = subnet.get_ipranges_in_use()1212 in_use_ipset = subnet.get_ipranges_in_use()
1213
1214 # Make sure we don't step on the gateway IP on the subnet.
1215 if subnet is not None and subnet.gateway_ip is not None:
1216 exclude_addresses.add(unicode(subnet.gateway_ip))
1217
1206 new_ip = StaticIPAddress.objects.allocate_new(1218 new_ip = StaticIPAddress.objects.allocate_new(
1207 network, static_ip_range_low, static_ip_range_high,1219 network, static_ip_range_low, static_ip_range_high,
1208 None, None, alloc_type=IPADDRESS_TYPE.AUTO,1220 None, None, alloc_type=IPADDRESS_TYPE.AUTO,
12091221
=== modified file 'src/maasserver/models/staticipaddress.py'
--- src/maasserver/models/staticipaddress.py 2016-05-26 17:51:44 +0000
+++ src/maasserver/models/staticipaddress.py 2017-05-15 22:56:53 +0000
@@ -166,7 +166,7 @@
166 dynamic_range_low, dynamic_range_high,166 dynamic_range_low, dynamic_range_high,
167 alloc_type=IPADDRESS_TYPE.AUTO, user=None,167 alloc_type=IPADDRESS_TYPE.AUTO, user=None,
168 requested_address=None, hostname=None, subnet=None,168 requested_address=None, hostname=None, subnet=None,
169 exclude_addresses=[], in_use_ipset=set()):169 exclude_addresses=None, in_use_ipset=None):
170 """Return a new StaticIPAddress.170 """Return a new StaticIPAddress.
171171
172 :param network: The network the address should be allocated in.172 :param network: The network the address should be allocated in.
@@ -194,6 +194,12 @@
194 Note that this method has been designed to work even when the database194 Note that this method has been designed to work even when the database
195 is running with READ COMMITTED isolation. Try to keep it that way.195 is running with READ COMMITTED isolation. Try to keep it that way.
196 """196 """
197 # Set multable default parameters.
198 if exclude_addresses is None:
199 exclude_addresses = set()
200 if in_use_ipset is None:
201 in_use_ipset = set()
202
197 # This check for `alloc_type` is important for later on. We rely on203 # This check for `alloc_type` is important for later on. We rely on
198 # detecting IntegrityError as a sign than an IP address is already204 # detecting IntegrityError as a sign than an IP address is already
199 # taken, and so we must first eliminate all other possible causes.205 # taken, and so we must first eliminate all other possible causes.
200206
=== modified file 'src/maasserver/models/tests/test_interface.py'
--- src/maasserver/models/tests/test_interface.py 2016-04-05 15:38:30 +0000
+++ src/maasserver/models/tests/test_interface.py 2017-05-15 22:56:53 +0000
@@ -2469,6 +2469,17 @@
2469 auto_ip = interface.ip_addresses.get(alloc_type=IPADDRESS_TYPE.AUTO)2469 auto_ip = interface.ip_addresses.get(alloc_type=IPADDRESS_TYPE.AUTO)
2470 self.assertEquals(IPAddress(exclude) + 1, IPAddress(auto_ip.ip))2470 self.assertEquals(IPAddress(exclude) + 1, IPAddress(auto_ip.ip))
24712471
2472 def test__excludes_default_gateway(self):
2473 interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
2474 subnet = factory.make_Subnet(
2475 vlan=interface.vlan, cidr='10.0.0.0/24', gateway_ip='10.0.0.1')
2476 factory.make_StaticIPAddress(
2477 alloc_type=IPADDRESS_TYPE.AUTO, ip="",
2478 subnet=subnet, interface=interface)
2479 interface.claim_auto_ips()
2480 auto_ip = interface.ip_addresses.get(alloc_type=IPADDRESS_TYPE.AUTO)
2481 self.assertEquals(IPAddress('10.0.0.1') + 1, IPAddress(auto_ip.ip))
2482
2472 def test__can_acquire_multiple_address_from_the_same_subnet(self):2483 def test__can_acquire_multiple_address_from_the_same_subnet(self):
2473 interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)2484 interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
2474 subnet = factory.make_Subnet(vlan=interface.vlan)2485 subnet = factory.make_Subnet(vlan=interface.vlan)

Subscribers

People subscribed via source and target branches