Merge lp:~newell-jensen/maas/2.0-fix-1614659 into lp:maas/2.0

Proposed by Newell Jensen on 2016-10-05
Status: Merged
Approved by: Newell Jensen on 2016-10-05
Approved revision: 5195
Merged at revision: 5195
Proposed branch: lp:~newell-jensen/maas/2.0-fix-1614659
Merge into: lp:maas/2.0
Diff against target: 135 lines (+31/-9)
4 files modified
src/maasserver/api/tests/test_machines.py (+2/-1)
src/maasserver/models/node.py (+8/-1)
src/maasserver/models/tests/test_node.py (+15/-7)
src/maasserver/node_status.py (+6/-0)
To merge this branch: bzr merge lp:~newell-jensen/maas/2.0-fix-1614659
Reviewer Review Type Date Requested Status
Newell Jensen Approve on 2016-10-05
Review via email: mp+307752@code.launchpad.net

Commit message

Backport trunk r5447: Revert to previous status when error during 'Releasing'

To post a comment you must log in.
Newell Jensen (newell-jensen) wrote :

Self approve backport.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/api/tests/test_machines.py'
2--- src/maasserver/api/tests/test_machines.py 2016-06-09 23:39:53 +0000
3+++ src/maasserver/api/tests/test_machines.py 2016-10-05 19:12:06 +0000
4@@ -1391,7 +1391,8 @@
5
6 def test_POST_release_returns_modified_machines(self):
7 owner = self.user
8- self.patch(Machine, "_stop").return_value = None
9+ self.patch(Machine, '_stop')
10+ self.patch(Machine, '_set_status')
11 acceptable_states = [NODE_STATUS.READY] + RELEASABLE_STATUSES
12 machines = [
13 factory.make_Node_with_Interface_on_Subnet(
14
15=== modified file 'src/maasserver/models/node.py'
16--- src/maasserver/models/node.py 2016-07-25 23:25:53 +0000
17+++ src/maasserver/models/node.py 2016-10-05 19:12:06 +0000
18@@ -2187,7 +2187,14 @@
19 # the issue this will cause.
20 if self.power_state != POWER_STATE.OFF:
21 try:
22- self._stop(self.owner)
23+ # Node.stop() has synchronous and asynchronous parts, so catch
24+ # exceptions arising synchronously, and chain callbacks to the
25+ # Deferred it returns for the asynchronous (post-commit) bits.
26+ stopping = self._stop(self.owner)
27+ # If there's an error, reset the node's status.
28+ stopping.addErrback(
29+ callOutToDatabase, Node._set_status, self.system_id,
30+ status=self.status)
31 except Exception as ex:
32 maaslog.error(
33 "%s: Unable to shut node down: %s", self.hostname,
34
35=== modified file 'src/maasserver/models/tests/test_node.py'
36--- src/maasserver/models/tests/test_node.py 2016-07-25 23:25:53 +0000
37+++ src/maasserver/models/tests/test_node.py 2016-10-05 19:12:06 +0000
38@@ -1536,7 +1536,8 @@
39 node = factory.make_Node(
40 status=NODE_STATUS.ALLOCATED, owner=owner, agent_name=agent_name)
41 self.patch(Node, '_set_status_expires')
42- self.patch(node, '_stop').return_value = None
43+ self.patch(node, '_stop')
44+ self.patch(node, '_set_status')
45 node_result = factory.make_NodeResult_for_installation(node=node)
46 self.assertEqual(
47 [node_result], list(NodeResult.objects.filter(
48@@ -1704,7 +1705,8 @@
49 def test_release_turns_on_netboot(self):
50 node = factory.make_Node(
51 status=NODE_STATUS.ALLOCATED, owner=factory.make_User())
52- self.patch(node, '_stop').return_value = None
53+ self.patch(node, '_stop')
54+ self.patch(node, '_set_status')
55 node.set_netboot(on=False)
56 with post_commit_hooks:
57 node.release()
58@@ -1713,7 +1715,8 @@
59 def test_release_logs_user_request(self):
60 owner = factory.make_User()
61 node = factory.make_Node(status=NODE_STATUS.ALLOCATED, owner=owner)
62- self.patch(node, "_stop").return_value = None
63+ self.patch(node, '_stop')
64+ self.patch(node, '_set_status')
65 register_event = self.patch(node, '_register_request_event')
66 with post_commit_hooks:
67 node.release(owner)
68@@ -1726,7 +1729,8 @@
69 status=NODE_STATUS.ALLOCATED, owner=factory.make_User())
70 node.osystem = factory.make_name('os')
71 node.distro_series = factory.make_name('series')
72- self.patch(node, "_stop").return_value = None
73+ self.patch(node, '_stop')
74+ self.patch(node, '_set_status')
75 with post_commit_hooks:
76 node.release()
77 self.assertEqual("", node.osystem)
78@@ -1777,6 +1781,8 @@
79 release_auto_ips = self.patch_autospec(
80 node, "release_auto_ips")
81 self.patch(Node, '_set_status_expires')
82+ self.patch(node, '_stop')
83+ self.patch(node, '_set_status')
84 with post_commit_hooks:
85 node.release()
86 self.assertThat(release_auto_ips, MockCalledOnceWith())
87@@ -1818,7 +1824,7 @@
88 node_stop.side_effect = factory.make_exception()
89
90 try:
91- with transaction.atomic():
92+ with post_commit_hooks:
93 node.release()
94 except node_stop.side_effect.__class__:
95 # We don't care about the error here, so suppress it. It
96@@ -1832,7 +1838,8 @@
97 node = factory.make_Node(
98 status=NODE_STATUS.ALLOCATED, owner=factory.make_User())
99 mock_clear = self.patch(node, "_clear_acquired_filesystems")
100- self.patch(node, "_stop").return_value = None
101+ self.patch(node, '_stop')
102+ self.patch(node, '_set_status')
103 with post_commit_hooks:
104 node.release()
105 self.assertThat(mock_clear, MockCalledOnceWith())
106@@ -3611,7 +3618,8 @@
107 self.assertItemsEqual(other_nodes, Node.objects.all())
108
109 def test_children_get_deleted_when_parent_is_released(self):
110- self.patch(Node, "_stop").return_value = None
111+ self.patch(Node, '_stop')
112+ self.patch(Node, '_set_status')
113 owner = factory.make_User()
114 # Create children.
115 parent = factory.make_Node(status=NODE_STATUS.ALLOCATED, owner=owner)
116
117=== modified file 'src/maasserver/node_status.py'
118--- src/maasserver/node_status.py 2016-07-22 16:11:04 +0000
119+++ src/maasserver/node_status.py 2016-10-05 19:12:06 +0000
120@@ -80,9 +80,15 @@
121 NODE_STATUS.RELEASING,
122 ],
123 NODE_STATUS.RELEASING: [
124+ NODE_STATUS.ALLOCATED,
125+ NODE_STATUS.RESERVED,
126+ NODE_STATUS.DEPLOYING,
127+ NODE_STATUS.DEPLOYED,
128 NODE_STATUS.READY,
129 NODE_STATUS.BROKEN,
130 NODE_STATUS.MISSING,
131+ NODE_STATUS.FAILED_DEPLOYMENT,
132+ NODE_STATUS.FAILED_DISK_ERASING,
133 NODE_STATUS.FAILED_RELEASING,
134 ],
135 NODE_STATUS.DEPLOYING: [

Subscribers

People subscribed via source and target branches

to all changes: