Merge lp:~mpontillo/maas/claim-auto-ip-keep-link-id--bug-1671891 into lp:~maas-committers/maas/trunk

Proposed by Mike Pontillo
Status: Merged
Approved by: Mike Pontillo
Approved revision: no longer in the source branch.
Merged at revision: 5820
Proposed branch: lp:~mpontillo/maas/claim-auto-ip-keep-link-id--bug-1671891
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 65 lines (+37/-5)
2 files modified
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/claim-auto-ip-keep-link-id--bug-1671891
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Review via email: mp+320126@code.launchpad.net

Commit message

Fix deployment with AUTO IPs set as the gateway link.

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

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

lgtm!

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

The attempt to merge lp:~mpontillo/maas/claim-auto-ip-keep-link-id--bug-1671891 into lp:maas failed. Below is the output from the failed tests.

Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Hit:2 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial InRelease
Get:3 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:4 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Fetched 306 kB in 0s (580 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
    --no-install-recommends install apache2 archdetect-deb authbind avahi-utils bash bind9 bind9utils build-essential bzr bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools git gjs ipython isc-dhcp-common isc-dhcp-server libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libnss-wrapper libpq-dev make nodejs-legacy npm postgresql psmisc pxelinux python3-all python3-apt python3-attr python3-bson python3-convoy python3-crochet python3-cssselect python3-curtin python3-dev python3-distro-info python3-django python3-django-nose python3-django-piston3 python3-dnspython python3-docutils python3-formencode python3-hivex python3-httplib2 python3-jinja2 python3-jsonschema python3-lxml python3-netaddr python3-netifaces python3-novaclient python3-oauth python3-oauthlib python3-openssl python3-paramiko python3-petname python3-pexpect python3-psycopg2 python3-pyinotify python3-pyparsing python3-pyvmomi python3-requests python3-seamicroclient python3-setuptools python3-simplestreams python3-sphinx python3-tempita python3-twisted python3-txtftp python3-tz python3-yaml python3-zope.interface python-bson python-crochet python-django python-django-piston python-djorm-ext-pgarray python-formencode python-lxml python-netaddr python-netifaces python-pocket-lint python-psycopg2 python-simplejson python-tempita python-twisted python-yaml socat syslinux-common tgt ubuntu-cloudimage-keyring wget xvfb
Reading package lists...
Building dependency tree...
Reading state information...
authbind is already the newest version (2.1.1+nmu1).
avahi-utils is already the newest version (0.6.32~rc+dfsg-1ubuntu2).
build-essential is already the newest version (12.1ubuntu2).
debhelper is already the newest version (9.20160115ubuntu3).
distro-info is already the newest version (0.14build1).
git is already the newest version (1:2.7.4-0ubuntu1).
libjs-angularjs is already the newest version (1.2.28-1ubuntu2).
libjs-jquery is already the newest version (1.11.3+dfsg-4).
libjs-yui3-full is already the newest version (3.5.1-1ubuntu3).
libjs-yui3-min is already the newest version (3.5.1-1ubuntu3).
make is already the newest version (4.1-6).
postgresql is already the newest version (9.5+173).
psmisc is already the newest version (22.21-2.1build1).
pxelinux is already the newest version (3:6.03+dfsg-11ubuntu1).
python-formencode is already the newest version (1.3.0-0ubuntu5).
python-lxml is already the newest version (3.5.0-1build1).
python-netaddr is already the newest version (0.7...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/models/interface.py'
2--- src/maasserver/models/interface.py 2017-03-10 18:11:01 +0000
3+++ src/maasserver/models/interface.py 2017-03-16 22:17:14 +0000
4@@ -1138,13 +1138,15 @@
5 new_ip = StaticIPAddress.objects.allocate_new(
6 subnet=subnet, alloc_type=IPADDRESS_TYPE.AUTO,
7 exclude_addresses=exclude_addresses)
8- self.ip_addresses.add(new_ip)
9+ auto_ip.ip = new_ip.ip
10+ # Throw away the newly-allocated address and assign it to the old AUTO
11+ # address, so that the interface link IDs remain consistent.
12+ new_ip.delete()
13+ auto_ip.save()
14 maaslog.info("Allocated automatic IP address %s for %s." % (
15- new_ip.ip,
16+ auto_ip.ip,
17 self.get_log_string()))
18-
19- auto_ip.delete()
20- return new_ip
21+ return auto_ip
22
23 def release_auto_ips(self):
24 """Release all AUTO IP address for this interface that have an IP
25
26=== modified file 'src/maasserver/models/tests/test_interface.py'
27--- src/maasserver/models/tests/test_interface.py 2017-03-10 15:37:21 +0000
28+++ src/maasserver/models/tests/test_interface.py 2017-03-16 22:17:14 +0000
29@@ -2751,6 +2751,36 @@
30 "Should have 3 AUTO IP addresses with an IP address assigned.")
31 self.assertItemsEqual(assigned_addresses, observed)
32
33+ def test__keeps_ip_address_ids_consistent(self):
34+ auto_ip_ids = []
35+ with transaction.atomic():
36+ interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
37+ for _ in range(3):
38+ subnet = factory.make_ipv4_Subnet_with_IPRanges(
39+ vlan=interface.vlan)
40+ auto_ip = factory.make_StaticIPAddress(
41+ alloc_type=IPADDRESS_TYPE.AUTO, ip="",
42+ subnet=subnet, interface=interface)
43+ auto_ip_ids.append(auto_ip.id)
44+ with transaction.atomic():
45+ observed = interface.claim_auto_ips()
46+ # Should now have 3 AUTO with IP addresses assigned.
47+ interface = reload_object(interface)
48+ assigned_addresses = interface.ip_addresses.filter(
49+ alloc_type=IPADDRESS_TYPE.AUTO)
50+ assigned_addresses = [
51+ ip
52+ for ip in assigned_addresses
53+ if ip.ip
54+ ]
55+ self.assertEqual(
56+ 3, len(assigned_addresses),
57+ "Should have 3 AUTO IP addresses with an IP address assigned.")
58+ self.assertItemsEqual(assigned_addresses, observed)
59+ # Make sure the IDs didn't change upon allocation.
60+ self.assertItemsEqual(
61+ auto_ip_ids, (ip.id for ip in assigned_addresses))
62+
63 def test__claims_all_missing_assigned_auto_ip_addresses(self):
64 with transaction.atomic():
65 interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)