Merge lp:~mpontillo/maas/ip-allocation-from-incorrect-range--bug-1677507--2.1 into lp:maas/2.1
- ip-allocation-from-incorrect-range--bug-1677507--2.1
- Merge into 2.1
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Mike Pontillo | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 5598 | ||||
Proposed branch: | lp:~mpontillo/maas/ip-allocation-from-incorrect-range--bug-1677507--2.1 | ||||
Merge into: | lp:maas/2.1 | ||||
Diff against target: |
71 lines (+37/-2) 3 files modified
docs/changelog.rst (+9/-0) src/maasserver/models/subnet.py (+11/-2) src/maasserver/models/tests/test_subnet.py (+17/-0) |
||||
To merge this branch: | bzr merge lp:~mpontillo/maas/ip-allocation-from-incorrect-range--bug-1677507--2.1 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mike Pontillo (community) | Approve | ||
Review via email: mp+321472@code.launchpad.net |
Commit message
Don't allow allocation of least-recently-used discoveries if they occur in a reserved range.
* Merges revision 5887 from trunk to fix bug #1677507.
Description of the change
Mike Pontillo (mpontillo) wrote : | # |
Mike Pontillo (mpontillo) wrote : | # |
Self-approve backport.
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~mpontillo/maas/ip-allocation-from-incorrect-range--bug-1677507--2.1 into lp:maas/2.1 failed. Below is the output from the failed tests.
Get:1 http://
Hit:2 http://
Get:3 http://
Get:4 http://
Fetched 306 kB in 0s (780 kB/s)
Reading package lists...
sudo DEBIAN_
--no-
Reading package lists...
Building dependency tree...
Reading state information...
distro-info is already the newest version (0.14build1).
distro-info set to manually installed.
git is already the newest version (1:2.7.4-0ubuntu1).
libjs-jquery is already the newest version (1.11.3+dfsg-4).
libjs-jquery set to manually installed.
make is already the newest version (4.1-6).
python-simplejson is already the newest version (3.8.1-1ubuntu2).
python-simplejson set to manually installed.
python-yaml is already the newest version (3.11-3build1).
python3-apt is already the newest version (1.1.0~
python3-jinja2 is already the newest version (2.8-1).
python3-oauthlib is already the newest version (1.0.3-1).
python3-requests is already the newest version (2.9.1-3).
python3-yaml is already the newest version (3.11-3build1).
ubuntu-
bash is already the newest version (4.3-14ubuntu1.1).
bzr is already the newest version (2.7.0-2ubuntu3).
curl is already the newest version (7.47.0-
dnsutils is alr...
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~mpontillo/maas/ip-allocation-from-incorrect-range--bug-1677507--2.1 into lp:maas/2.1 failed. Below is the output from the failed tests.
Hit:1 http://
Get:2 http://
Get:3 http://
Get:4 http://
Fetched 306 kB in 0s (684 kB/s)
Reading package lists...
sudo DEBIAN_
--no-
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~
build-essential is already the newest version (12.1ubuntu2).
debhelper is already the newest version (9.20160115ubun
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).
pxelinux is already the newest version (3:6.03+
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.18-1).
python-netifaces is already the newest version (0.10....
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~mpontillo/maas/ip-allocation-from-incorrect-range--bug-1677507--2.1 into lp:maas/2.1 failed. Below is the output from the failed tests.
Get:1 http://
Hit:2 http://
Get:3 http://
Get:4 http://
Fetched 306 kB in 0s (697 kB/s)
Reading package lists...
sudo DEBIAN_
--no-
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~
build-essential is already the newest version (12.1ubuntu2).
debhelper is already the newest version (9.20160115ubun
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).
pxelinux is already the newest version (3:6.03+
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.18-1).
python-netifaces is already the newest version (0.10....
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~mpontillo/maas/ip-allocation-from-incorrect-range--bug-1677507--2.1 into lp:maas/2.1 failed. Below is the output from the failed tests.
Hit:1 http://
Get:2 http://
Get:3 http://
Get:4 http://
Fetched 306 kB in 0s (695 kB/s)
Reading package lists...
sudo DEBIAN_
--no-
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~
build-essential is already the newest version (12.1ubuntu2).
debhelper is already the newest version (9.20160115ubun
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).
pxelinux is already the newest version (3:6.03+
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.18-1).
python-netifaces is already the newest version (0.10....
Preview Diff
1 | === modified file 'docs/changelog.rst' | |||
2 | --- docs/changelog.rst 2017-03-23 12:20:26 +0000 | |||
3 | +++ docs/changelog.rst 2017-03-30 17:25:45 +0000 | |||
4 | @@ -2,6 +2,15 @@ | |||
5 | 2 | Changelog | 2 | Changelog |
6 | 3 | ========= | 3 | ========= |
7 | 4 | 4 | ||
8 | 5 | 2.1.6 | ||
9 | 6 | ===== | ||
10 | 7 | |||
11 | 8 | Bugs fixed in this release | ||
12 | 9 | -------------------------- | ||
13 | 10 | |||
14 | 11 | LP: ##1677507 Fix potential IP allocation from incorrect range. | ||
15 | 12 | |||
16 | 13 | |||
17 | 5 | 2.1.5 | 14 | 2.1.5 |
18 | 6 | ===== | 15 | ===== |
19 | 7 | 16 | ||
20 | 8 | 17 | ||
21 | === modified file 'src/maasserver/models/subnet.py' | |||
22 | --- src/maasserver/models/subnet.py 2017-02-17 05:34:56 +0000 | |||
23 | +++ src/maasserver/models/subnet.py 2017-03-30 17:25:45 +0000 | |||
24 | @@ -593,8 +593,17 @@ | |||
25 | 593 | """ | 593 | """ |
26 | 594 | # Circular imports. | 594 | # Circular imports. |
27 | 595 | from maasserver.models import Discovery | 595 | from maasserver.models import Discovery |
30 | 596 | return Discovery.objects.filter( | 596 | # Note: for the purposes of this function, being in part of a "used" |
31 | 597 | subnet=self).by_unknown_ip().order_by('last_seen').first() | 597 | # range (such as a router IP address or reserved range) makes it |
32 | 598 | # "known". So we need to avoid those here in order to avoid stepping | ||
33 | 599 | # on network infrastructure, reserved ranges, etc. | ||
34 | 600 | unused = self.get_ipranges_not_in_use(ignore_discovered_ips=True) | ||
35 | 601 | least_recent_neighbours = Discovery.objects.filter( | ||
36 | 602 | subnet=self).by_unknown_ip().order_by('last_seen') | ||
37 | 603 | for neighbor in least_recent_neighbours: | ||
38 | 604 | if neighbor.ip in unused: | ||
39 | 605 | return neighbor | ||
40 | 606 | return None | ||
41 | 598 | 607 | ||
42 | 599 | def get_iprange_usage(self, with_neighbours=False) -> MAASIPSet: | 608 | def get_iprange_usage(self, with_neighbours=False) -> MAASIPSet: |
43 | 600 | """Returns both the reserved and unreserved IP ranges in this Subnet. | 609 | """Returns both the reserved and unreserved IP ranges in this Subnet. |
44 | 601 | 610 | ||
45 | === modified file 'src/maasserver/models/tests/test_subnet.py' | |||
46 | --- src/maasserver/models/tests/test_subnet.py 2017-02-17 05:34:56 +0000 | |||
47 | +++ src/maasserver/models/tests/test_subnet.py 2017-03-30 17:25:45 +0000 | |||
48 | @@ -919,6 +919,23 @@ | |||
49 | 919 | discovery = subnet.get_least_recently_seen_unknown_neighbour() | 919 | discovery = subnet.get_least_recently_seen_unknown_neighbour() |
50 | 920 | self.assertThat(discovery.ip, Equals("10.0.0.2")) | 920 | self.assertThat(discovery.ip, Equals("10.0.0.2")) |
51 | 921 | 921 | ||
52 | 922 | def test__returns_least_recently_seen_neighbour_excludes_in_use(self): | ||
53 | 923 | # Note: 10.0.0.0/30 --> 10.0.0.1 and 10.0.0.0.2 are usable. | ||
54 | 924 | subnet = factory.make_Subnet( | ||
55 | 925 | cidr="10.0.0.0/30", gateway_ip=None, dns_servers=None) | ||
56 | 926 | rackif = factory.make_Interface(vlan=subnet.vlan) | ||
57 | 927 | now = datetime.now() | ||
58 | 928 | yesterday = now - timedelta(days=1) | ||
59 | 929 | factory.make_Discovery( | ||
60 | 930 | ip="10.0.0.1", interface=rackif, updated=now) | ||
61 | 931 | factory.make_Discovery( | ||
62 | 932 | ip="10.0.0.2", interface=rackif, updated=yesterday) | ||
63 | 933 | factory.make_IPRange( | ||
64 | 934 | subnet, start_ip="10.0.0.2", end_ip="10.0.0.2", | ||
65 | 935 | type=IPRANGE_TYPE.RESERVED) | ||
66 | 936 | discovery = subnet.get_least_recently_seen_unknown_neighbour() | ||
67 | 937 | self.assertThat(discovery.ip, Equals("10.0.0.1")) | ||
68 | 938 | |||
69 | 922 | def test__returns_none_if_no_neighbours(self): | 939 | def test__returns_none_if_no_neighbours(self): |
70 | 923 | # Note: 10.0.0.0/30 --> 10.0.0.1 and 10.0.0.0.2 are usable. | 940 | # Note: 10.0.0.0/30 --> 10.0.0.1 and 10.0.0.0.2 are usable. |
71 | 924 | subnet = factory.make_Subnet( | 941 | subnet = factory.make_Subnet( |
Rejecting temporarily to remove test case for feature that didn't exist in MAAS 2.1.