Merge lp:~blake-rouse/maas/fix-15270528 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Andres Rodriguez
Approved revision: no longer in the source branch.
Merged at revision: 4719
Proposed branch: lp:~blake-rouse/maas/fix-15270528
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 80 lines (+54/-2)
2 files modified
src/maasserver/dhcp.py (+6/-2)
src/maasserver/tests/test_dhcp.py (+48/-0)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-15270528
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Review via email: mp+287869@code.launchpad.net

Commit message

Fix get_interfaces_with_ip_on_vlan to actually check the VLAN.

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

lgtm!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/dhcp.py'
2--- src/maasserver/dhcp.py 2016-03-02 05:03:06 +0000
3+++ src/maasserver/dhcp.py 2016-03-03 02:36:07 +0000
4@@ -112,11 +112,15 @@
5 for ip_address in interface.ip_addresses.all():
6 if ip_address.alloc_type in [
7 IPADDRESS_TYPE.AUTO, IPADDRESS_TYPE.STICKY]:
8- if ip_is_version(ip_address, ip_version):
9+ if (ip_is_version(ip_address, ip_version) and
10+ ip_address.subnet is not None and
11+ ip_address.subnet.vlan == vlan):
12 interfaces_with_static.append(interface)
13 break
14 elif ip_address.alloc_type == IPADDRESS_TYPE.DISCOVERED:
15- if ip_is_version(ip_address, ip_version):
16+ if (ip_is_version(ip_address, ip_version) and
17+ ip_address.subnet is not None and
18+ ip_address.subnet.vlan == vlan):
19 interfaces_with_discovered.append(interface)
20 break
21 if len(interfaces_with_static) > 0:
22
23=== modified file 'src/maasserver/tests/test_dhcp.py'
24--- src/maasserver/tests/test_dhcp.py 2016-03-02 04:31:19 +0000
25+++ src/maasserver/tests/test_dhcp.py 2016-03-03 02:36:07 +0000
26@@ -254,6 +254,54 @@
27 dhcp.get_interfaces_with_ip_on_vlan(
28 rack_controller, vlan, subnet.get_ipnetwork().version))
29
30+ def test__returns_only_interfaces_on_vlan_ipv4(self):
31+ rack_controller = factory.make_RackController()
32+ vlan = factory.make_VLAN()
33+ network = factory.make_ipv4_network()
34+ subnet = factory.make_Subnet(cidr=str(network.cidr), vlan=vlan)
35+ interface = factory.make_Interface(
36+ INTERFACE_TYPE.PHYSICAL, node=rack_controller, vlan=vlan)
37+ factory.make_StaticIPAddress(
38+ alloc_type=IPADDRESS_TYPE.STICKY,
39+ subnet=subnet, interface=interface)
40+ other_vlan = factory.make_VLAN()
41+ other_network = factory.make_ipv4_network()
42+ other_subnet = factory.make_Subnet(
43+ cidr=str(other_network.cidr), vlan=other_vlan)
44+ other_interface = factory.make_Interface(
45+ INTERFACE_TYPE.PHYSICAL, node=rack_controller, vlan=other_vlan)
46+ factory.make_StaticIPAddress(
47+ alloc_type=IPADDRESS_TYPE.STICKY,
48+ subnet=other_subnet, interface=other_interface)
49+ self.assertEquals(
50+ [interface],
51+ dhcp.get_interfaces_with_ip_on_vlan(
52+ rack_controller, vlan, subnet.get_ipnetwork().version))
53+
54+ def test__returns_only_interfaces_on_vlan_ipv6(self):
55+ rack_controller = factory.make_RackController()
56+ vlan = factory.make_VLAN()
57+ network = factory.make_ipv6_network()
58+ subnet = factory.make_Subnet(cidr=str(network.cidr), vlan=vlan)
59+ interface = factory.make_Interface(
60+ INTERFACE_TYPE.PHYSICAL, node=rack_controller, vlan=vlan)
61+ factory.make_StaticIPAddress(
62+ alloc_type=IPADDRESS_TYPE.STICKY,
63+ subnet=subnet, interface=interface)
64+ other_vlan = factory.make_VLAN()
65+ other_network = factory.make_ipv6_network()
66+ other_subnet = factory.make_Subnet(
67+ cidr=str(other_network.cidr), vlan=other_vlan)
68+ other_interface = factory.make_Interface(
69+ INTERFACE_TYPE.PHYSICAL, node=rack_controller, vlan=other_vlan)
70+ factory.make_StaticIPAddress(
71+ alloc_type=IPADDRESS_TYPE.STICKY,
72+ subnet=other_subnet, interface=other_interface)
73+ self.assertEquals(
74+ [interface],
75+ dhcp.get_interfaces_with_ip_on_vlan(
76+ rack_controller, vlan, subnet.get_ipnetwork().version))
77+
78
79 class TestGetManagedVLANsFor(MAASServerTestCase):
80 """Tests for `get_managed_vlans_for`."""