Merge lp:~mpontillo/maas/fix-commissioning-with-default-gateway--bug-1603466 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: 5477
Proposed branch: lp:~mpontillo/maas/fix-commissioning-with-default-gateway--bug-1603466
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 64 lines (+36/-0)
2 files modified
src/maasserver/models/node.py (+2/-0)
src/maasserver/models/tests/test_node.py (+34/-0)
To merge this branch: bzr merge lp:~mpontillo/maas/fix-commissioning-with-default-gateway--bug-1603466
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Review via email: mp+308306@code.launchpad.net

Commit message

Fix commissioning to properly clear default gateways when clearing network configuration.

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/models/node.py'
2--- src/maasserver/models/node.py 2016-10-05 16:41:26 +0000
3+++ src/maasserver/models/node.py 2016-10-12 21:10:26 +0000
4@@ -2673,6 +2673,8 @@
5 commissioned. This allows the new commissioning data to create a new
6 networking configuration.
7 """
8+ self.gateway_link_ipv4 = None
9+ self.gateway_link_ipv6 = None
10 interfaces = self.interface_set.all()
11 for interface in interfaces:
12 interface.clear_all_links(clearing_config=True)
13
14=== modified file 'src/maasserver/models/tests/test_node.py'
15--- src/maasserver/models/tests/test_node.py 2016-10-05 16:41:26 +0000
16+++ src/maasserver/models/tests/test_node.py 2016-10-12 21:10:26 +0000
17@@ -86,6 +86,8 @@
18 from maasserver.models.event import Event
19 import maasserver.models.interface as interface_module
20 from maasserver.models.node import (
21+ DefaultGateways,
22+ GatewayDefinition,
23 generate_node_system_id,
24 PowerInfo,
25 typecast_node,
26@@ -4291,6 +4293,38 @@
27 [dhcp_ip, static_ip, auto_ip], observed_ip_address)
28 self.assertEqual(set([True]), clearing_config)
29
30+ def test__clear_networking_configuration_clears_gateways(self):
31+ node = factory.make_Node()
32+ nic0 = factory.make_Interface(INTERFACE_TYPE.PHYSICAL, node=node)
33+ nic1 = factory.make_Interface(INTERFACE_TYPE.PHYSICAL, node=node)
34+ ipv4_subnet = factory.make_Subnet(
35+ cidr="192.168.0.0/24", gateway_ip="192.168.0.1")
36+ ipv6_subnet = factory.make_Subnet(
37+ cidr="2001:db8::/64", gateway_ip="2001:db8::1")
38+ static_ipv4 = factory.make_StaticIPAddress(
39+ alloc_type=IPADDRESS_TYPE.STICKY, interface=nic0,
40+ subnet=ipv4_subnet)
41+ static_ipv6 = factory.make_StaticIPAddress(
42+ alloc_type=IPADDRESS_TYPE.STICKY, interface=nic1,
43+ subnet=ipv6_subnet)
44+ node.gateway_link_ipv4 = static_ipv4
45+ node.gateway_link_ipv6 = static_ipv6
46+ node.save()
47+ node = reload_object(node)
48+ expected_gateways = DefaultGateways(
49+ GatewayDefinition(
50+ interface_id=nic0.id, subnet_id=ipv4_subnet.id,
51+ gateway_ip=ipv4_subnet.gateway_ip),
52+ GatewayDefinition(
53+ interface_id=nic1.id, subnet_id=ipv6_subnet.id,
54+ gateway_ip=ipv6_subnet.gateway_ip)
55+ )
56+ self.assertThat(
57+ node.get_default_gateways(), Equals(expected_gateways))
58+ node._clear_networking_configuration()
59+ self.assertThat(node.gateway_link_ipv4, Equals(None))
60+ self.assertThat(node.gateway_link_ipv6, Equals(None))
61+
62 def test_set_initial_net_config_does_nothing_if_skip_networking(self):
63 node = factory.make_Node_with_Interface_on_Subnet(skip_networking=True)
64 boot_interface = node.get_boot_interface()