Merge lp:~mpontillo/maas/gateway-with-auto-ip--bug-1671891 into lp:maas/2.1

Proposed by Mike Pontillo
Status: Merged
Approved by: Mike Pontillo
Approved revision: no longer in the source branch.
Merged at revision: 5592
Proposed branch: lp:~mpontillo/maas/gateway-with-auto-ip--bug-1671891
Merge into: lp:maas/2.1
Diff against target: 78 lines (+39/-5)
3 files modified
docs/changelog.rst (+2/-0)
src/maasserver/models/interface.py (+7/-5)
src/maasserver/models/tests/test_interface.py (+30/-0)
To merge this branch: bzr merge lp:~mpontillo/maas/gateway-with-auto-ip--bug-1671891
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Approve
Review via email: mp+320267@code.launchpad.net

Commit message

Fix deployment with AUTO IPs set as the gateway link. (Merge revision 5820 from trunk.)

 * Previously the gateway link would be thrown away and replaced.
   Now the existing link will be updated with the allocated
   IP address.

Description of the change

-

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

Self-approve backport, just in case we need to release 2.1.x again.

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 2017-03-01 15:54:17 +0000
3+++ docs/changelog.rst 2017-03-17 23:26:59 +0000
4@@ -36,6 +36,8 @@
5
6 LP: #1665143 Select the shortest by-id path when discovering block devices to address issues when discovering nvme devices.
7
8+LP: #1671891 Fix deployment with AUTO IPs set as the gateway link.
9+
10
11 Other notable changes
12 ---------------------
13
14=== modified file 'src/maasserver/models/interface.py'
15--- src/maasserver/models/interface.py 2016-12-07 12:59:10 +0000
16+++ src/maasserver/models/interface.py 2017-03-17 23:26:59 +0000
17@@ -1055,13 +1055,15 @@
18 new_ip = StaticIPAddress.objects.allocate_new(
19 subnet=subnet, alloc_type=IPADDRESS_TYPE.AUTO,
20 exclude_addresses=exclude_addresses)
21- self.ip_addresses.add(new_ip)
22+ auto_ip.ip = new_ip.ip
23+ # Throw away the newly-allocated address and assign it to the old AUTO
24+ # address, so that the interface link IDs remain consistent.
25+ new_ip.delete()
26+ auto_ip.save()
27 maaslog.info("Allocated automatic IP address %s for %s." % (
28- new_ip.ip,
29+ auto_ip.ip,
30 self.get_log_string()))
31-
32- auto_ip.delete()
33- return new_ip
34+ return auto_ip
35
36 def release_auto_ips(self):
37 """Release all AUTO IP address for this interface that have an IP
38
39=== modified file 'src/maasserver/models/tests/test_interface.py'
40--- src/maasserver/models/tests/test_interface.py 2016-12-07 12:59:10 +0000
41+++ src/maasserver/models/tests/test_interface.py 2017-03-17 23:26:59 +0000
42@@ -2661,6 +2661,36 @@
43 "Should have 3 AUTO IP addresses with an IP address assigned.")
44 self.assertItemsEqual(assigned_addresses, observed)
45
46+ def test__keeps_ip_address_ids_consistent(self):
47+ auto_ip_ids = []
48+ with transaction.atomic():
49+ interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
50+ for _ in range(3):
51+ subnet = factory.make_ipv4_Subnet_with_IPRanges(
52+ vlan=interface.vlan)
53+ auto_ip = factory.make_StaticIPAddress(
54+ alloc_type=IPADDRESS_TYPE.AUTO, ip="",
55+ subnet=subnet, interface=interface)
56+ auto_ip_ids.append(auto_ip.id)
57+ with transaction.atomic():
58+ observed = interface.claim_auto_ips()
59+ # Should now have 3 AUTO with IP addresses assigned.
60+ interface = reload_object(interface)
61+ assigned_addresses = interface.ip_addresses.filter(
62+ alloc_type=IPADDRESS_TYPE.AUTO)
63+ assigned_addresses = [
64+ ip
65+ for ip in assigned_addresses
66+ if ip.ip
67+ ]
68+ self.assertEqual(
69+ 3, len(assigned_addresses),
70+ "Should have 3 AUTO IP addresses with an IP address assigned.")
71+ self.assertItemsEqual(assigned_addresses, observed)
72+ # Make sure the IDs didn't change upon allocation.
73+ self.assertItemsEqual(
74+ auto_ip_ids, (ip.id for ip in assigned_addresses))
75+
76 def test__claims_all_missing_assigned_auto_ip_addresses(self):
77 with transaction.atomic():
78 interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)

Subscribers

People subscribed via source and target branches

to all changes: