Merge ~troyanov/maas:fix-2015411 into maas:master

Proposed by Anton Troyanov
Status: Merged
Approved by: Anton Troyanov
Approved revision: bde8669ad5a140752be6f04d54c69aa8ee0b1407
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~troyanov/maas:fix-2015411
Merge into: maas:master
Diff against target: 113 lines (+66/-2)
2 files modified
src/maasserver/api/tests/test_machine.py (+64/-2)
src/maasserver/models/node.py (+2/-0)
Reviewer Review Type Date Requested Status
Jack-Skye Owen-Lloyd-Walters Approve
MAAS Lander Approve
Review via email: mp+453596@code.launchpad.net

Commit message

fix: force save model object changes

Resolved LP:2015411 StaticIPAddress matching query does not exist

Description of the change

Before this change, result of the next two calls was never stored in the database:
- machine.restore_network_interfaces()
- machine.set_initial_networking_configuration()

And the following call failed to properly reload FK related data:
- return reload_object(machine)

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b fix-2015411 lp:~troyanov/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/3758/console
COMMIT: 4bbdbaf75f169a07e868142b30b8c4d966026dcf

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b fix-2015411 lp:~troyanov/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/3759/console
COMMIT: 7c7a56465d1446208e866594877f29397a05a0a1

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b fix-2015411 lp:~troyanov/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: bde8669ad5a140752be6f04d54c69aa8ee0b1407

review: Approve
Revision history for this message
Jack-Skye Owen-Lloyd-Walters (lloydwaltersj) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/api/tests/test_machine.py b/src/maasserver/api/tests/test_machine.py
2index 948032f..d9996d5 100644
3--- a/src/maasserver/api/tests/test_machine.py
4+++ b/src/maasserver/api/tests/test_machine.py
5@@ -42,7 +42,7 @@ from maasserver.enum import (
6 from maasserver.exceptions import StaticIPAddressExhaustion
7 from maasserver.models import Config, Domain, Filesystem, Machine, Node
8 from maasserver.models import node as node_module
9-from maasserver.models import NodeKey, NodeUserData, StaticIPAddress
10+from maasserver.models import NodeKey, NodeUserData, ScriptSet, StaticIPAddress
11 from maasserver.models.bmc import Pod
12 from maasserver.models.node import RELEASABLE_STATUSES
13 from maasserver.models.signals.testing import SignalsDisabled
14@@ -73,9 +73,13 @@ from maastesting.matchers import (
15 MockNotCalled,
16 )
17 from metadataserver.builtin_scripts import load_builtin_scripts
18+from metadataserver.builtin_scripts.tests import test_hooks
19 from metadataserver.enum import SCRIPT_TYPE
20 from metadataserver.nodeinituser import get_node_init_user
21-from provisioningserver.refresh.node_info_scripts import NODE_INFO_SCRIPTS
22+from provisioningserver.refresh.node_info_scripts import (
23+ COMMISSIONING_OUTPUT_NAME,
24+ NODE_INFO_SCRIPTS,
25+)
26 from provisioningserver.utils.enum import map_enum
27
28
29@@ -3606,6 +3610,64 @@ class TestRestoreNetworkingConfiguration(APITestCase.ForUser):
30 self.assertThat(mock_set_initial_networking_config, MockCalledOnce())
31 self.assertThat(mock_restore_network_interfaces, MockCalledOnce())
32
33+ def test_restore_networking_configuration_no_gateway_link_ipv4_conflict(
34+ self,
35+ ):
36+ # See also LP#2015411
37+ self.become_admin()
38+ machine = factory.make_Machine_with_Interface_on_Subnet(
39+ status=NODE_STATUS.READY
40+ )
41+
42+ lxd_script = factory.make_Script(
43+ name=COMMISSIONING_OUTPUT_NAME,
44+ script_type=SCRIPT_TYPE.COMMISSIONING,
45+ )
46+ commissioning_script_set = (
47+ ScriptSet.objects.create_commissioning_script_set(
48+ machine, scripts=[lxd_script.name]
49+ )
50+ )
51+ machine.current_commissioning_script_set = commissioning_script_set
52+ output = test_hooks.make_lxd_output_json()
53+ factory.make_ScriptResult(
54+ script_set=commissioning_script_set,
55+ script=lxd_script,
56+ exit_status=0,
57+ output=output,
58+ stdout=output,
59+ )
60+ # Create NUMA nodes.
61+ test_hooks.create_numa_nodes(machine)
62+
63+ interface = factory.make_Interface(
64+ INTERFACE_TYPE.PHYSICAL, node=machine
65+ )
66+ network = factory.make_ipv4_network()
67+ subnet = factory.make_Subnet(cidr=str(network.cidr))
68+
69+ link_v4 = factory.make_StaticIPAddress(
70+ alloc_type=IPADDRESS_TYPE.STICKY,
71+ ip=factory.pick_ip_in_network(network),
72+ subnet=subnet,
73+ interface=interface,
74+ )
75+ machine.gateway_link_ipv4 = link_v4
76+ machine.save()
77+
78+ machine.restore_network_interfaces()
79+ machine.set_initial_networking_configuration()
80+
81+ response = self.client.post(
82+ self.get_machine_uri(machine),
83+ {"op": "restore_networking_configuration"},
84+ )
85+
86+ self.assertEqual(http.client.OK, response.status_code)
87+ self.assertEqual(
88+ machine.system_id, json_load_bytes(response.content)["system_id"]
89+ )
90+
91 def test_restore_networking_configuration_requires_admin(self):
92 machine = factory.make_Machine()
93 response = self.client.post(
94diff --git a/src/maasserver/models/node.py b/src/maasserver/models/node.py
95index 822e071..542de31 100644
96--- a/src/maasserver/models/node.py
97+++ b/src/maasserver/models/node.py
98@@ -4753,6 +4753,7 @@ class Node(CleanSave, TimestampedModel):
99 update_node_network_information(
100 self, data, NUMANode.objects.filter(node=self)
101 )
102+ self.save()
103
104 def get_commissioning_resources(self):
105 script = self.current_commissioning_script_set.find_script_result(
106@@ -4813,6 +4814,7 @@ class Node(CleanSave, TimestampedModel):
107 continue
108 if interface.enabled:
109 interface.ensure_link_up()
110+ self.save()
111
112 def set_networking_configuration_from_node(self, source_node):
113 """Set the networking configuration for this node from the source

Subscribers

People subscribed via source and target branches