Merge lp:~newell-jensen/maas/fix-1602487 into lp:~maas-committers/maas/trunk
- fix-1602487
- Merge into trunk
Proposed by
Newell Jensen
Status: | Merged |
---|---|
Approved by: | Newell Jensen |
Approved revision: | no longer in the source branch. |
Merged at revision: | 5198 |
Proposed branch: | lp:~newell-jensen/maas/fix-1602487 |
Merge into: | lp:~maas-committers/maas/trunk |
Diff against target: |
372 lines (+62/-67) 3 files modified
src/maasserver/models/node.py (+11/-8) src/maasserver/models/tests/test_node.py (+45/-56) src/maasserver/tests/test_node_action.py (+6/-3) |
To merge this branch: | bzr merge lp:~newell-jensen/maas/fix-1602487 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gavin Panella (community) | Approve | ||
Review via email: mp+300387@code.launchpad.net |
Commit message
Factor out the addErrback for resetting the node's status into _start from start_commissio
Description of the change
To post a comment you must log in.
Revision history for this message
Newell Jensen (newell-jensen) wrote : | # |
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-07-15 18:57:25 +0000 | |||
3 | +++ src/maasserver/models/node.py 2016-07-18 20:09:23 +0000 | |||
4 | @@ -1657,7 +1657,7 @@ | |||
5 | 1657 | # Node.start() has synchronous and asynchronous parts, so catch | 1657 | # Node.start() has synchronous and asynchronous parts, so catch |
6 | 1658 | # exceptions arising synchronously, and chain callbacks to the | 1658 | # exceptions arising synchronously, and chain callbacks to the |
7 | 1659 | # Deferred it returns for the asynchronous (post-commit) bits. | 1659 | # Deferred it returns for the asynchronous (post-commit) bits. |
9 | 1660 | starting = self._start(user, commissioning_user_data) | 1660 | starting = self._start(user, commissioning_user_data, old_status) |
10 | 1661 | except Exception as error: | 1661 | except Exception as error: |
11 | 1662 | self.status = old_status | 1662 | self.status = old_status |
12 | 1663 | self.save() | 1663 | self.save() |
13 | @@ -1688,11 +1688,6 @@ | |||
14 | 1688 | callOut, self._start_commissioning_async, is_starting, | 1688 | callOut, self._start_commissioning_async, is_starting, |
15 | 1689 | self.hostname) | 1689 | self.hostname) |
16 | 1690 | 1690 | ||
17 | 1691 | # If there's an error, reset the node's status. | ||
18 | 1692 | starting.addErrback( | ||
19 | 1693 | callOutToDatabase, Node._set_status, self.system_id, | ||
20 | 1694 | status=old_status) | ||
21 | 1695 | |||
22 | 1696 | def eb_start(failure, hostname): | 1691 | def eb_start(failure, hostname): |
23 | 1697 | maaslog.error( | 1692 | maaslog.error( |
24 | 1698 | "%s: Could not start node for commissioning: %s", | 1693 | "%s: Could not start node for commissioning: %s", |
25 | @@ -2135,6 +2130,7 @@ | |||
26 | 2135 | 2130 | ||
27 | 2136 | # Change the status of the node now to avoid races when starting | 2131 | # Change the status of the node now to avoid races when starting |
28 | 2137 | # nodes in bulk. | 2132 | # nodes in bulk. |
29 | 2133 | old_status = self.status | ||
30 | 2138 | self.status = NODE_STATUS.DISK_ERASING | 2134 | self.status = NODE_STATUS.DISK_ERASING |
31 | 2139 | self.save() | 2135 | self.save() |
32 | 2140 | 2136 | ||
33 | @@ -2142,7 +2138,7 @@ | |||
34 | 2142 | # Node.start() has synchronous and asynchronous parts, so catch | 2138 | # Node.start() has synchronous and asynchronous parts, so catch |
35 | 2143 | # exceptions arising synchronously, and chain callbacks to the | 2139 | # exceptions arising synchronously, and chain callbacks to the |
36 | 2144 | # Deferred it returns for the asynchronous (post-commit) bits. | 2140 | # Deferred it returns for the asynchronous (post-commit) bits. |
38 | 2145 | starting = self._start(user, disk_erase_user_data) | 2141 | starting = self._start(user, disk_erase_user_data, old_status) |
39 | 2146 | except Exception as error: | 2142 | except Exception as error: |
40 | 2147 | # We always mark the node as failed here, although we could | 2143 | # We always mark the node as failed here, although we could |
41 | 2148 | # potentially move it back to the state it was in previously. For | 2144 | # potentially move it back to the state it was in previously. For |
42 | @@ -3019,7 +3015,7 @@ | |||
43 | 3019 | return client_idents, fallback_idents | 3015 | return client_idents, fallback_idents |
44 | 3020 | 3016 | ||
45 | 3021 | @transactional | 3017 | @transactional |
47 | 3022 | def _start(self, user, user_data=None): | 3018 | def _start(self, user, user_data=None, old_status=None): |
48 | 3023 | """Request on given user's behalf that the node be started up. | 3019 | """Request on given user's behalf that the node be started up. |
49 | 3024 | 3020 | ||
50 | 3025 | :param user: Requesting user. | 3021 | :param user: Requesting user. |
51 | @@ -3055,6 +3051,7 @@ | |||
52 | 3055 | NodeUserData.objects.set_user_data(self, user_data) | 3051 | NodeUserData.objects.set_user_data(self, user_data) |
53 | 3056 | 3052 | ||
54 | 3057 | if self.status == NODE_STATUS.ALLOCATED: | 3053 | if self.status == NODE_STATUS.ALLOCATED: |
55 | 3054 | old_status = self.status | ||
56 | 3058 | # Claim AUTO IP addresses for the node if it's ALLOCATED. | 3055 | # Claim AUTO IP addresses for the node if it's ALLOCATED. |
57 | 3059 | # The current state being ALLOCATED is our indication that the node | 3056 | # The current state being ALLOCATED is our indication that the node |
58 | 3060 | # is being deployed for the first time. | 3057 | # is being deployed for the first time. |
59 | @@ -3084,6 +3081,12 @@ | |||
60 | 3084 | callOutToDatabase, Node._set_status_expires, | 3081 | callOutToDatabase, Node._set_status_expires, |
61 | 3085 | self.system_id, deployment_timeout) | 3082 | self.system_id, deployment_timeout) |
62 | 3086 | 3083 | ||
63 | 3084 | if old_status is not None: | ||
64 | 3085 | # If there's an error, reset the node's status. | ||
65 | 3086 | d.addErrback( | ||
66 | 3087 | callOutToDatabase, Node._set_status, self.system_id, | ||
67 | 3088 | status=old_status) | ||
68 | 3089 | |||
69 | 3087 | # If any part of this processes fails be sure to release the grabbed | 3090 | # If any part of this processes fails be sure to release the grabbed |
70 | 3088 | # auto IP addresses. | 3091 | # auto IP addresses. |
71 | 3089 | if claimed_ips: | 3092 | if claimed_ips: |
72 | 3090 | 3093 | ||
73 | === modified file 'src/maasserver/models/tests/test_node.py' | |||
74 | --- src/maasserver/models/tests/test_node.py 2016-07-15 18:57:25 +0000 | |||
75 | +++ src/maasserver/models/tests/test_node.py 2016-07-18 20:09:23 +0000 | |||
76 | @@ -1414,7 +1414,8 @@ | |||
77 | 1414 | status=NODE_STATUS.ALLOCATED, owner=owner, agent_name=agent_name) | 1414 | status=NODE_STATUS.ALLOCATED, owner=owner, agent_name=agent_name) |
78 | 1415 | node_start = self.patch(node, '_start') | 1415 | node_start = self.patch(node, '_start') |
79 | 1416 | # Return a post-commit hook from Node.start(). | 1416 | # Return a post-commit hook from Node.start(). |
81 | 1417 | node_start.side_effect = lambda user, user_data: post_commit() | 1417 | node_start.side_effect = ( |
82 | 1418 | lambda user, user_data, old_status: post_commit()) | ||
83 | 1418 | Config.objects.set_config('disk_erase_with_secure_erase', True) | 1419 | Config.objects.set_config('disk_erase_with_secure_erase', True) |
84 | 1419 | Config.objects.set_config('disk_erase_with_quick_erase', True) | 1420 | Config.objects.set_config('disk_erase_with_quick_erase', True) |
85 | 1420 | with post_commit_hooks: | 1421 | with post_commit_hooks: |
86 | @@ -1435,7 +1436,8 @@ | |||
87 | 1435 | status=NODE_STATUS.ALLOCATED, owner=owner, agent_name=agent_name) | 1436 | status=NODE_STATUS.ALLOCATED, owner=owner, agent_name=agent_name) |
88 | 1436 | node_start = self.patch(node, '_start') | 1437 | node_start = self.patch(node, '_start') |
89 | 1437 | # Return a post-commit hook from Node.start(). | 1438 | # Return a post-commit hook from Node.start(). |
91 | 1438 | node_start.side_effect = lambda user, user_data: post_commit() | 1439 | node_start.side_effect = ( |
92 | 1440 | lambda user, user_data, old_status: post_commit()) | ||
93 | 1439 | Config.objects.set_config('disk_erase_with_secure_erase', False) | 1441 | Config.objects.set_config('disk_erase_with_secure_erase', False) |
94 | 1440 | Config.objects.set_config('disk_erase_with_quick_erase', False) | 1442 | Config.objects.set_config('disk_erase_with_quick_erase', False) |
95 | 1441 | with post_commit_hooks: | 1443 | with post_commit_hooks: |
96 | @@ -1456,26 +1458,28 @@ | |||
97 | 1456 | status=NODE_STATUS.ALLOCATED, owner=owner, agent_name=agent_name) | 1458 | status=NODE_STATUS.ALLOCATED, owner=owner, agent_name=agent_name) |
98 | 1457 | node_start = self.patch(node, '_start') | 1459 | node_start = self.patch(node, '_start') |
99 | 1458 | # Return a post-commit hook from Node.start(). | 1460 | # Return a post-commit hook from Node.start(). |
101 | 1459 | node_start.side_effect = lambda user, user_data: post_commit() | 1461 | node_start.side_effect = ( |
102 | 1462 | lambda user, user_data, old_status: post_commit()) | ||
103 | 1460 | with post_commit_hooks: | 1463 | with post_commit_hooks: |
104 | 1461 | node.start_disk_erasing(owner) | 1464 | node.start_disk_erasing(owner) |
105 | 1462 | self.expectThat(node.owner, Equals(owner)) | 1465 | self.expectThat(node.owner, Equals(owner)) |
106 | 1463 | self.expectThat(node.status, Equals(NODE_STATUS.DISK_ERASING)) | 1466 | self.expectThat(node.status, Equals(NODE_STATUS.DISK_ERASING)) |
107 | 1464 | self.expectThat(node.agent_name, Equals(agent_name)) | 1467 | self.expectThat(node.agent_name, Equals(agent_name)) |
108 | 1465 | self.assertThat( | 1468 | self.assertThat( |
110 | 1466 | node_start, MockCalledOnceWith(owner, ANY)) | 1469 | node_start, MockCalledOnceWith(owner, ANY, NODE_STATUS.ALLOCATED)) |
111 | 1467 | 1470 | ||
112 | 1468 | def test_start_disk_erasing_logs_user_request(self): | 1471 | def test_start_disk_erasing_logs_user_request(self): |
113 | 1469 | owner = factory.make_User() | 1472 | owner = factory.make_User() |
114 | 1470 | node = factory.make_Node(status=NODE_STATUS.ALLOCATED, owner=owner) | 1473 | node = factory.make_Node(status=NODE_STATUS.ALLOCATED, owner=owner) |
115 | 1471 | node_start = self.patch(node, '_start') | 1474 | node_start = self.patch(node, '_start') |
116 | 1472 | # Return a post-commit hook from Node.start(). | 1475 | # Return a post-commit hook from Node.start(). |
118 | 1473 | node_start.side_effect = lambda user, user_data: post_commit() | 1476 | node_start.side_effect = ( |
119 | 1477 | lambda user, user_data, old_status: post_commit()) | ||
120 | 1474 | register_event = self.patch(node, '_register_request_event') | 1478 | register_event = self.patch(node, '_register_request_event') |
121 | 1475 | with post_commit_hooks: | 1479 | with post_commit_hooks: |
122 | 1476 | node.start_disk_erasing(owner) | 1480 | node.start_disk_erasing(owner) |
123 | 1477 | self.assertThat( | 1481 | self.assertThat( |
125 | 1478 | node_start, MockCalledOnceWith(owner, ANY)) | 1482 | node_start, MockCalledOnceWith(owner, ANY, NODE_STATUS.ALLOCATED)) |
126 | 1479 | self.assertThat(register_event, MockCalledOnceWith( | 1483 | self.assertThat(register_event, MockCalledOnceWith( |
127 | 1480 | owner, EVENT_TYPES.REQUEST_NODE_ERASE_DISK, | 1484 | owner, EVENT_TYPES.REQUEST_NODE_ERASE_DISK, |
128 | 1481 | action='start disk erasing', comment=None)) | 1485 | action='start disk erasing', comment=None)) |
129 | @@ -1538,7 +1542,7 @@ | |||
130 | 1538 | 1542 | ||
131 | 1539 | self.assertThat( | 1543 | self.assertThat( |
132 | 1540 | node_start, MockCalledOnceWith( | 1544 | node_start, MockCalledOnceWith( |
134 | 1541 | admin, generate_user_data.return_value)) | 1545 | admin, generate_user_data.return_value, NODE_STATUS.ALLOCATED)) |
135 | 1542 | self.assertEqual(NODE_STATUS.FAILED_DISK_ERASING, node.status) | 1546 | self.assertEqual(NODE_STATUS.FAILED_DISK_ERASING, node.status) |
136 | 1543 | 1547 | ||
137 | 1544 | def test_start_disk_erasing_sets_status_on_post_commit_error(self): | 1548 | def test_start_disk_erasing_sets_status_on_post_commit_error(self): |
138 | @@ -2159,7 +2163,8 @@ | |||
139 | 2159 | interface=True, status=NODE_STATUS.NEW, power_type='manual') | 2163 | interface=True, status=NODE_STATUS.NEW, power_type='manual') |
140 | 2160 | node_start = self.patch(node, '_start') | 2164 | node_start = self.patch(node, '_start') |
141 | 2161 | # Return a post-commit hook from Node.start(). | 2165 | # Return a post-commit hook from Node.start(). |
143 | 2162 | node_start.side_effect = lambda user, user_data: post_commit() | 2166 | node_start.side_effect = ( |
144 | 2167 | lambda user, user_data, old_status: post_commit()) | ||
145 | 2163 | admin = factory.make_admin() | 2168 | admin = factory.make_admin() |
146 | 2164 | node.start_commissioning(admin) | 2169 | node.start_commissioning(admin) |
147 | 2165 | post_commit_hooks.reset() # Ignore these for now. | 2170 | post_commit_hooks.reset() # Ignore these for now. |
148 | @@ -2168,7 +2173,8 @@ | |||
149 | 2168 | 'status': NODE_STATUS.COMMISSIONING, | 2173 | 'status': NODE_STATUS.COMMISSIONING, |
150 | 2169 | } | 2174 | } |
151 | 2170 | self.assertAttributes(node, expected_attrs) | 2175 | self.assertAttributes(node, expected_attrs) |
153 | 2171 | self.assertThat(node_start, MockCalledOnceWith(admin, ANY)) | 2176 | self.assertThat(node_start, MockCalledOnceWith( |
154 | 2177 | admin, ANY, NODE_STATUS.NEW)) | ||
155 | 2172 | 2178 | ||
156 | 2173 | def test_start_commissioning_sets_options(self): | 2179 | def test_start_commissioning_sets_options(self): |
157 | 2174 | rack = factory.make_RackController() | 2180 | rack = factory.make_RackController() |
158 | @@ -2177,7 +2183,8 @@ | |||
159 | 2177 | bmc_connected_to=rack) | 2183 | bmc_connected_to=rack) |
160 | 2178 | node_start = self.patch(node, '_start') | 2184 | node_start = self.patch(node, '_start') |
161 | 2179 | # Return a post-commit hook from Node.start(). | 2185 | # Return a post-commit hook from Node.start(). |
163 | 2180 | node_start.side_effect = lambda user, user_data: post_commit() | 2186 | node_start.side_effect = ( |
164 | 2187 | lambda user, user_data, old_status: post_commit()) | ||
165 | 2181 | admin = factory.make_admin() | 2188 | admin = factory.make_admin() |
166 | 2182 | enable_ssh = factory.pick_bool() | 2189 | enable_ssh = factory.pick_bool() |
167 | 2183 | skip_networking = factory.pick_bool() | 2190 | skip_networking = factory.pick_bool() |
168 | @@ -2197,7 +2204,8 @@ | |||
169 | 2197 | def test_start_commissioning_sets_user_data(self): | 2204 | def test_start_commissioning_sets_user_data(self): |
170 | 2198 | node = factory.make_Node(status=NODE_STATUS.NEW) | 2205 | node = factory.make_Node(status=NODE_STATUS.NEW) |
171 | 2199 | node_start = self.patch(node, '_start') | 2206 | node_start = self.patch(node, '_start') |
173 | 2200 | node_start.side_effect = lambda user, user_data: post_commit() | 2207 | node_start.side_effect = ( |
174 | 2208 | lambda user, user_data, old_status: post_commit()) | ||
175 | 2201 | user_data = factory.make_string().encode('ascii') | 2209 | user_data = factory.make_string().encode('ascii') |
176 | 2202 | generate_user_data = self.patch( | 2210 | generate_user_data = self.patch( |
177 | 2203 | commissioning, 'generate_user_data') | 2211 | commissioning, 'generate_user_data') |
178 | @@ -2205,12 +2213,14 @@ | |||
179 | 2205 | admin = factory.make_admin() | 2213 | admin = factory.make_admin() |
180 | 2206 | node.start_commissioning(admin) | 2214 | node.start_commissioning(admin) |
181 | 2207 | post_commit_hooks.reset() # Ignore these for now. | 2215 | post_commit_hooks.reset() # Ignore these for now. |
183 | 2208 | self.assertThat(node_start, MockCalledOnceWith(admin, user_data)) | 2216 | self.assertThat(node_start, MockCalledOnceWith( |
184 | 2217 | admin, user_data, NODE_STATUS.NEW)) | ||
185 | 2209 | 2218 | ||
186 | 2210 | def test_start_commissioning_sets_min_hwe_kernel(self): | 2219 | def test_start_commissioning_sets_min_hwe_kernel(self): |
187 | 2211 | node = factory.make_Node(status=NODE_STATUS.NEW) | 2220 | node = factory.make_Node(status=NODE_STATUS.NEW) |
188 | 2212 | node_start = self.patch(node, '_start') | 2221 | node_start = self.patch(node, '_start') |
190 | 2213 | node_start.side_effect = lambda user, user_data: post_commit() | 2222 | node_start.side_effect = ( |
191 | 2223 | lambda user, user_data, old_status: post_commit()) | ||
192 | 2214 | user_data = factory.make_string().encode('ascii') | 2224 | user_data = factory.make_string().encode('ascii') |
193 | 2215 | generate_user_data = self.patch( | 2225 | generate_user_data = self.patch( |
194 | 2216 | commissioning, 'generate_user_data') | 2226 | commissioning, 'generate_user_data') |
195 | @@ -2224,7 +2234,8 @@ | |||
196 | 2224 | def test_start_commissioning_clears_node_commissioning_results(self): | 2234 | def test_start_commissioning_clears_node_commissioning_results(self): |
197 | 2225 | node = factory.make_Node(status=NODE_STATUS.NEW) | 2235 | node = factory.make_Node(status=NODE_STATUS.NEW) |
198 | 2226 | node_start = self.patch(node, '_start') | 2236 | node_start = self.patch(node, '_start') |
200 | 2227 | node_start.side_effect = lambda user, user_data: post_commit() | 2237 | node_start.side_effect = ( |
201 | 2238 | lambda user, user_data, old_status: post_commit()) | ||
202 | 2228 | NodeResult.objects.store_data( | 2239 | NodeResult.objects.store_data( |
203 | 2229 | node, factory.make_string(), | 2240 | node, factory.make_string(), |
204 | 2230 | random.randint(0, 10), | 2241 | random.randint(0, 10), |
205 | @@ -2237,7 +2248,8 @@ | |||
206 | 2237 | def test_start_commissioning_clears_storage_configuration(self): | 2248 | def test_start_commissioning_clears_storage_configuration(self): |
207 | 2238 | node = factory.make_Node(status=NODE_STATUS.NEW) | 2249 | node = factory.make_Node(status=NODE_STATUS.NEW) |
208 | 2239 | node_start = self.patch(node, '_start') | 2250 | node_start = self.patch(node, '_start') |
210 | 2240 | node_start.side_effect = lambda user, user_data: post_commit() | 2251 | node_start.side_effect = ( |
211 | 2252 | lambda user, user_data, old_status: post_commit()) | ||
212 | 2241 | clear_storage = self.patch_autospec( | 2253 | clear_storage = self.patch_autospec( |
213 | 2242 | node, '_clear_full_storage_configuration') | 2254 | node, '_clear_full_storage_configuration') |
214 | 2243 | admin = factory.make_admin() | 2255 | admin = factory.make_admin() |
215 | @@ -2248,7 +2260,8 @@ | |||
216 | 2248 | def test_start_commissioning_doesnt_clear_storage_configuration(self): | 2260 | def test_start_commissioning_doesnt_clear_storage_configuration(self): |
217 | 2249 | node = factory.make_Node(status=NODE_STATUS.NEW) | 2261 | node = factory.make_Node(status=NODE_STATUS.NEW) |
218 | 2250 | node_start = self.patch(node, '_start') | 2262 | node_start = self.patch(node, '_start') |
220 | 2251 | node_start.side_effect = lambda user, user_data: post_commit() | 2263 | node_start.side_effect = ( |
221 | 2264 | lambda user, user_data, old_status: post_commit()) | ||
222 | 2252 | clear_storage = self.patch_autospec( | 2265 | clear_storage = self.patch_autospec( |
223 | 2253 | node, '_clear_full_storage_configuration') | 2266 | node, '_clear_full_storage_configuration') |
224 | 2254 | admin = factory.make_admin() | 2267 | admin = factory.make_admin() |
225 | @@ -2259,7 +2272,8 @@ | |||
226 | 2259 | def test_start_commissioning_calls__clear_networking_configuration(self): | 2272 | def test_start_commissioning_calls__clear_networking_configuration(self): |
227 | 2260 | node = factory.make_Node(status=NODE_STATUS.NEW) | 2273 | node = factory.make_Node(status=NODE_STATUS.NEW) |
228 | 2261 | node_start = self.patch(node, '_start') | 2274 | node_start = self.patch(node, '_start') |
230 | 2262 | node_start.side_effect = lambda user, user_data: post_commit() | 2275 | node_start.side_effect = ( |
231 | 2276 | lambda user, user_data, old_status: post_commit()) | ||
232 | 2263 | clear_networking = self.patch_autospec( | 2277 | clear_networking = self.patch_autospec( |
233 | 2264 | node, '_clear_networking_configuration') | 2278 | node, '_clear_networking_configuration') |
234 | 2265 | admin = factory.make_admin() | 2279 | admin = factory.make_admin() |
235 | @@ -2270,7 +2284,8 @@ | |||
236 | 2270 | def test_start_commissioning_doesnt_call__clear_networking(self): | 2284 | def test_start_commissioning_doesnt_call__clear_networking(self): |
237 | 2271 | node = factory.make_Node(status=NODE_STATUS.NEW) | 2285 | node = factory.make_Node(status=NODE_STATUS.NEW) |
238 | 2272 | node_start = self.patch(node, '_start') | 2286 | node_start = self.patch(node, '_start') |
240 | 2273 | node_start.side_effect = lambda user, user_data: post_commit() | 2287 | node_start.side_effect = ( |
241 | 2288 | lambda user, user_data, old_status: post_commit()) | ||
242 | 2274 | clear_networking = self.patch_autospec( | 2289 | clear_networking = self.patch_autospec( |
243 | 2275 | node, '_clear_networking_configuration') | 2290 | node, '_clear_networking_configuration') |
244 | 2276 | admin = factory.make_admin() | 2291 | admin = factory.make_admin() |
245 | @@ -2313,41 +2328,10 @@ | |||
246 | 2313 | 2328 | ||
247 | 2314 | self.assertThat( | 2329 | self.assertThat( |
248 | 2315 | node_start, | 2330 | node_start, |
250 | 2316 | MockCalledOnceWith(admin, generate_user_data.return_value)) | 2331 | MockCalledOnceWith( |
251 | 2332 | admin, generate_user_data.return_value, NODE_STATUS.NEW)) | ||
252 | 2317 | self.assertEqual(NODE_STATUS.NEW, node.status) | 2333 | self.assertEqual(NODE_STATUS.NEW, node.status) |
253 | 2318 | 2334 | ||
254 | 2319 | def test_start_commissioning_reverts_status_on_post_commit_error(self): | ||
255 | 2320 | # When start_commissioning encounters an error in its post-commit | ||
256 | 2321 | # hook, it will revert the node to its previous status. | ||
257 | 2322 | admin = factory.make_admin() | ||
258 | 2323 | status = random.choice( | ||
259 | 2324 | (NODE_STATUS.NEW, NODE_STATUS.READY, | ||
260 | 2325 | NODE_STATUS.FAILED_COMMISSIONING)) | ||
261 | 2326 | node = factory.make_Node(status=status) | ||
262 | 2327 | # Patch out some things that we don't want to do right now. | ||
263 | 2328 | self.patch(Node, '_set_status_expires') | ||
264 | 2329 | self.patch(node, '_start').return_value = None | ||
265 | 2330 | # Fake an error during the post-commit hook. | ||
266 | 2331 | error_message = factory.make_name("error") | ||
267 | 2332 | error_type = factory.make_exception_type() | ||
268 | 2333 | _start_async = self.patch_autospec(node, "_start_commissioning_async") | ||
269 | 2334 | _start_async.side_effect = error_type(error_message) | ||
270 | 2335 | # Capture calls to _set_status. | ||
271 | 2336 | self.patch_autospec(Node, "_set_status") | ||
272 | 2337 | |||
273 | 2338 | with LoggerFixture("maas") as logger: | ||
274 | 2339 | with ExpectedException(error_type): | ||
275 | 2340 | with post_commit_hooks: | ||
276 | 2341 | node.start_commissioning(admin) | ||
277 | 2342 | |||
278 | 2343 | # The status is set to be reverted to its initial status. | ||
279 | 2344 | self.assertThat(node._set_status, MockCalledOnceWith( | ||
280 | 2345 | node.system_id, status=status)) | ||
281 | 2346 | # It's logged too. | ||
282 | 2347 | self.assertThat(logger.output, Contains( | ||
283 | 2348 | "%s: Could not start node for commissioning: %s\n" | ||
284 | 2349 | % (node.hostname, error_message))) | ||
285 | 2350 | |||
286 | 2351 | def test_start_commissioning_logs_and_raises_errors_in_starting(self): | 2335 | def test_start_commissioning_logs_and_raises_errors_in_starting(self): |
287 | 2352 | admin = factory.make_admin() | 2336 | admin = factory.make_admin() |
288 | 2353 | node = factory.make_Node(status=NODE_STATUS.NEW) | 2337 | node = factory.make_Node(status=NODE_STATUS.NEW) |
289 | @@ -2368,7 +2352,8 @@ | |||
290 | 2368 | register_event = self.patch(node, '_register_request_event') | 2352 | register_event = self.patch(node, '_register_request_event') |
291 | 2369 | node_start = self.patch(node, '_start') | 2353 | node_start = self.patch(node, '_start') |
292 | 2370 | # Return a post-commit hook from Node.start(). | 2354 | # Return a post-commit hook from Node.start(). |
294 | 2371 | node_start.side_effect = lambda user, user_data: post_commit() | 2355 | node_start.side_effect = ( |
295 | 2356 | lambda user, user_data, old_status: post_commit()) | ||
296 | 2372 | admin = factory.make_admin() | 2357 | admin = factory.make_admin() |
297 | 2373 | node.start_commissioning(admin) | 2358 | node.start_commissioning(admin) |
298 | 2374 | post_commit_hooks.reset() # Ignore these for now. | 2359 | post_commit_hooks.reset() # Ignore these for now. |
299 | @@ -2489,7 +2474,8 @@ | |||
300 | 2489 | enable_ssh=True) | 2474 | enable_ssh=True) |
301 | 2490 | node_start = self.patch(node, 'start') | 2475 | node_start = self.patch(node, 'start') |
302 | 2491 | # Return a post-commit hook from Node.start(). | 2476 | # Return a post-commit hook from Node.start(). |
304 | 2492 | node_start.side_effect = lambda user, user_data: post_commit() | 2477 | node_start.side_effect = ( |
305 | 2478 | lambda user, user_data, old_status: post_commit()) | ||
306 | 2493 | admin = factory.make_admin() | 2479 | admin = factory.make_admin() |
307 | 2494 | node.start_commissioning(admin) | 2480 | node.start_commissioning(admin) |
308 | 2495 | post_commit_hooks.reset() # Ignore these for now. | 2481 | post_commit_hooks.reset() # Ignore these for now. |
309 | @@ -4632,6 +4618,7 @@ | |||
310 | 4632 | def test__adds_callbacks_and_errbacks_to_post_commit(self): | 4618 | def test__adds_callbacks_and_errbacks_to_post_commit(self): |
311 | 4633 | user = factory.make_User() | 4619 | user = factory.make_User() |
312 | 4634 | node = self.make_acquired_node_with_interface(user) | 4620 | node = self.make_acquired_node_with_interface(user) |
313 | 4621 | old_status = node.status | ||
314 | 4635 | 4622 | ||
315 | 4636 | post_commit_defer = self.patch(node_module, "post_commit") | 4623 | post_commit_defer = self.patch(node_module, "post_commit") |
316 | 4637 | mock_power_control = self.patch(Node, "_power_control_node") | 4624 | mock_power_control = self.patch(Node, "_power_control_node") |
317 | @@ -4645,10 +4632,12 @@ | |||
318 | 4645 | callOutToDatabase, Node._set_status_expires, | 4632 | callOutToDatabase, Node._set_status_expires, |
319 | 4646 | node.system_id, node.get_deployment_time())) | 4633 | node.system_id, node.get_deployment_time())) |
320 | 4647 | 4634 | ||
322 | 4648 | # Adds errback to release auto ips. | 4635 | # Adds errback to reset status and release auto ips. |
323 | 4649 | self.assertThat( | 4636 | self.assertThat( |
326 | 4650 | post_commit_defer.addErrback, MockCalledOnceWith( | 4637 | post_commit_defer.addErrback, MockCallsMatch( |
327 | 4651 | callOutToDatabase, node.release_auto_ips)) | 4638 | call(callOutToDatabase, node._set_status, |
328 | 4639 | node.system_id, status=old_status), | ||
329 | 4640 | call(callOutToDatabase, node.release_auto_ips))) | ||
330 | 4652 | 4641 | ||
331 | 4653 | def test_storage_layout_issues_returns_invalid_no_boot_arm64_non_efi(self): | 4642 | def test_storage_layout_issues_returns_invalid_no_boot_arm64_non_efi(self): |
332 | 4654 | node = factory.make_Node( | 4643 | node = factory.make_Node( |
333 | 4655 | 4644 | ||
334 | === modified file 'src/maasserver/tests/test_node_action.py' | |||
335 | --- src/maasserver/tests/test_node_action.py 2016-07-15 00:42:25 +0000 | |||
336 | +++ src/maasserver/tests/test_node_action.py 2016-07-18 20:09:23 +0000 | |||
337 | @@ -292,14 +292,15 @@ | |||
338 | 292 | interface=True, status=self.status, | 292 | interface=True, status=self.status, |
339 | 293 | power_type='manual', power_state=POWER_STATE.OFF) | 293 | power_type='manual', power_state=POWER_STATE.OFF) |
340 | 294 | node_start = self.patch(node, '_start') | 294 | node_start = self.patch(node, '_start') |
342 | 295 | node_start.side_effect = lambda user, user_data: post_commit() | 295 | node_start.side_effect = ( |
343 | 296 | lambda user, user_data, old_status: post_commit()) | ||
344 | 296 | admin = factory.make_admin() | 297 | admin = factory.make_admin() |
345 | 297 | action = Commission(node, admin) | 298 | action = Commission(node, admin) |
346 | 298 | with post_commit_hooks: | 299 | with post_commit_hooks: |
347 | 299 | action.execute() | 300 | action.execute() |
348 | 300 | self.assertEqual(NODE_STATUS.COMMISSIONING, node.status) | 301 | self.assertEqual(NODE_STATUS.COMMISSIONING, node.status) |
349 | 301 | self.assertThat( | 302 | self.assertThat( |
351 | 302 | node_start, MockCalledOnceWith(admin, ANY)) | 303 | node_start, MockCalledOnceWith(admin, ANY, ANY)) |
352 | 303 | 304 | ||
353 | 304 | 305 | ||
354 | 305 | class TestAbortAction(MAASTransactionServerTestCase): | 306 | class TestAbortAction(MAASTransactionServerTestCase): |
355 | @@ -734,6 +735,7 @@ | |||
356 | 734 | interface=True, status=self.actionable_status, | 735 | interface=True, status=self.actionable_status, |
357 | 735 | power_type='ipmi', power_state=POWER_STATE.OFF, | 736 | power_type='ipmi', power_state=POWER_STATE.OFF, |
358 | 736 | owner=user, power_parameters=params) | 737 | owner=user, power_parameters=params) |
359 | 738 | old_status = node.status | ||
360 | 737 | node_start = self.patch_autospec(node, '_start') | 739 | node_start = self.patch_autospec(node, '_start') |
361 | 738 | node_start.return_value = None | 740 | node_start.return_value = None |
362 | 739 | 741 | ||
363 | @@ -742,7 +744,8 @@ | |||
364 | 742 | 744 | ||
365 | 743 | self.expectThat(node.status, Equals(NODE_STATUS.DISK_ERASING)) | 745 | self.expectThat(node.status, Equals(NODE_STATUS.DISK_ERASING)) |
366 | 744 | self.assertThat( | 746 | self.assertThat( |
368 | 745 | node_start, MockCalledOnceWith(user, user_data=ANY)) | 747 | node_start, MockCalledOnceWith( |
369 | 748 | user, user_data=ANY, old_status=old_status)) | ||
370 | 746 | 749 | ||
371 | 747 | def test_Release_passes_secure_erase_and_quick_erase(self): | 750 | def test_Release_passes_secure_erase_and_quick_erase(self): |
372 | 748 | user = factory.make_User() | 751 | user = factory.make_User() |
This was testing on OIL's integration server.