Merge lp:~gmb/maas/enlist-uscm-to-RPC into lp:~maas-committers/maas/trunk
- enlist-uscm-to-RPC
- Merge into trunk
Proposed by
Graham Binns
Status: | Superseded |
---|---|
Proposed branch: | lp:~gmb/maas/enlist-uscm-to-RPC |
Merge into: | lp:~maas-committers/maas/trunk |
Diff against target: |
354 lines (+234/-30) 6 files modified
src/maasserver/models/nodegroup.py (+30/-8) src/maasserver/models/tests/test_nodegroup.py (+100/-0) src/provisioningserver/rpc/cluster.py (+28/-0) src/provisioningserver/rpc/clusterservice.py (+22/-0) src/provisioningserver/rpc/tests/test_clusterservice.py (+54/-0) src/provisioningserver/tasks.py (+0/-22) |
To merge this branch: | bzr merge lp:~gmb/maas/enlist-uscm-to-RPC |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
MAAS Maintainers | Pending | ||
Review via email: mp+234284@code.launchpad.net |
This proposal has been superseded by a proposal from 2014-09-11.
Commit message
Convert the enlist_
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/maasserver/models/nodegroup.py' | |||
2 | --- src/maasserver/models/nodegroup.py 2014-09-10 16:01:38 +0000 | |||
3 | +++ src/maasserver/models/nodegroup.py 2014-09-11 10:17:45 +0000 | |||
4 | @@ -41,13 +41,11 @@ | |||
5 | 41 | from provisioningserver.rpc.cluster import ( | 41 | from provisioningserver.rpc.cluster import ( |
6 | 42 | AddSeaMicro15k, | 42 | AddSeaMicro15k, |
7 | 43 | AddVirsh, | 43 | AddVirsh, |
8 | 44 | EnlistNodesFromMSCM, | ||
9 | 45 | EnlistNodesFromUCSM, | ||
10 | 44 | ImportBootImages, | 46 | ImportBootImages, |
11 | 45 | ) | 47 | ) |
12 | 46 | from provisioningserver.rpc.exceptions import NoConnectionsAvailable | 48 | from provisioningserver.rpc.exceptions import NoConnectionsAvailable |
13 | 47 | from provisioningserver.tasks import ( | ||
14 | 48 | enlist_nodes_from_mscm, | ||
15 | 49 | enlist_nodes_from_ucsm, | ||
16 | 50 | ) | ||
17 | 51 | 49 | ||
18 | 52 | 50 | ||
19 | 53 | class NodeGroupManager(Manager): | 51 | class NodeGroupManager(Manager): |
20 | @@ -304,9 +302,21 @@ | |||
21 | 304 | :param URL: URL of the Cisco UCS Manager HTTP-XML API. | 302 | :param URL: URL of the Cisco UCS Manager HTTP-XML API. |
22 | 305 | :param username: username for UCS Manager. | 303 | :param username: username for UCS Manager. |
23 | 306 | :param password: password for UCS Manager. | 304 | :param password: password for UCS Manager. |
24 | 305 | |||
25 | 306 | :raises NoConnectionsAvailable: If no connections to the cluster | ||
26 | 307 | are available. | ||
27 | 307 | """ | 308 | """ |
30 | 308 | args = (url, username, password) | 309 | try: |
31 | 309 | enlist_nodes_from_ucsm.apply_async(queue=self.uuid, args=args) | 310 | client = getClientFor(self.uuid, timeout=1) |
32 | 311 | except NoConnectionsAvailable: | ||
33 | 312 | # No connection to the cluster so we can't do anything. We | ||
34 | 313 | # let the caller handle the error, since we don't want to | ||
35 | 314 | # just drop it. | ||
36 | 315 | raise | ||
37 | 316 | else: | ||
38 | 317 | return client( | ||
39 | 318 | EnlistNodesFromUCSM, url=url, username=username, | ||
40 | 319 | password=password) | ||
41 | 310 | 320 | ||
42 | 311 | def enlist_nodes_from_mscm(self, host, username, password): | 321 | def enlist_nodes_from_mscm(self, host, username, password): |
43 | 312 | """ Add the servers from a Moonshot HP iLO Chassis Manager. | 322 | """ Add the servers from a Moonshot HP iLO Chassis Manager. |
44 | @@ -314,6 +324,18 @@ | |||
45 | 314 | :param host: IP address for the MSCM. | 324 | :param host: IP address for the MSCM. |
46 | 315 | :param username: username for MSCM. | 325 | :param username: username for MSCM. |
47 | 316 | :param password: password for MSCM. | 326 | :param password: password for MSCM. |
48 | 327 | |||
49 | 328 | :raises NoConnectionsAvailable: If no connections to the cluster | ||
50 | 329 | are available. | ||
51 | 317 | """ | 330 | """ |
54 | 318 | args = (host, username, password) | 331 | try: |
55 | 319 | enlist_nodes_from_mscm.apply_async(queue=self.uuid, args=args) | 332 | client = getClientFor(self.uuid, timeout=1) |
56 | 333 | except NoConnectionsAvailable: | ||
57 | 334 | # No connection to the cluster so we can't do anything. We | ||
58 | 335 | # let the caller handle the error, since we don't want to | ||
59 | 336 | # just drop it. | ||
60 | 337 | raise | ||
61 | 338 | else: | ||
62 | 339 | return client( | ||
63 | 340 | EnlistNodesFromMSCM, host=host, username=username, | ||
64 | 341 | password=password) | ||
65 | 320 | 342 | ||
66 | === modified file 'src/maasserver/models/tests/test_nodegroup.py' | |||
67 | --- src/maasserver/models/tests/test_nodegroup.py 2014-09-10 16:01:38 +0000 | |||
68 | +++ src/maasserver/models/tests/test_nodegroup.py 2014-09-11 10:17:45 +0000 | |||
69 | @@ -49,6 +49,8 @@ | |||
70 | 49 | from provisioningserver.rpc.cluster import ( | 49 | from provisioningserver.rpc.cluster import ( |
71 | 50 | AddSeaMicro15k, | 50 | AddSeaMicro15k, |
72 | 51 | AddVirsh, | 51 | AddVirsh, |
73 | 52 | EnlistNodesFromMSCM, | ||
74 | 53 | EnlistNodesFromUCSM, | ||
75 | 52 | ImportBootImages, | 54 | ImportBootImages, |
76 | 53 | ) | 55 | ) |
77 | 54 | from provisioningserver.rpc.exceptions import NoConnectionsAvailable | 56 | from provisioningserver.rpc.exceptions import NoConnectionsAvailable |
78 | @@ -513,3 +515,101 @@ | |||
79 | 513 | self.assertRaises( | 515 | self.assertRaises( |
80 | 514 | NoConnectionsAvailable, nodegroup.add_seamicro15k, | 516 | NoConnectionsAvailable, nodegroup.add_seamicro15k, |
81 | 515 | mac, username, password, power_control) | 517 | mac, username, password, power_control) |
82 | 518 | |||
83 | 519 | def test_enlist_nodes_from_mscm_end_to_end(self): | ||
84 | 520 | nodegroup = factory.make_NodeGroup(status=NODEGROUP_STATUS.ACCEPTED) | ||
85 | 521 | |||
86 | 522 | self.useFixture(RegionEventLoopFixture("rpc")) | ||
87 | 523 | self.useFixture(RunningEventLoopFixture()) | ||
88 | 524 | fixture = self.useFixture(MockLiveRegionToClusterRPCFixture()) | ||
89 | 525 | protocol = fixture.makeCluster(nodegroup, EnlistNodesFromMSCM) | ||
90 | 526 | protocol.EnlistNodesFromMSCM.return_value = defer.succeed({}) | ||
91 | 527 | |||
92 | 528 | host = factory.make_name('host') | ||
93 | 529 | username = factory.make_name('user') | ||
94 | 530 | password = factory.make_name('password') | ||
95 | 531 | nodegroup.enlist_nodes_from_mscm( | ||
96 | 532 | host, username, password).wait(10) | ||
97 | 533 | |||
98 | 534 | self.expectThat( | ||
99 | 535 | protocol.EnlistNodesFromMSCM, | ||
100 | 536 | MockCalledOnceWith( | ||
101 | 537 | ANY, host=host, username=username, password=password)) | ||
102 | 538 | |||
103 | 539 | def test_enlist_nodes_from_mscm_calls_client_with_resource_endpoint(self): | ||
104 | 540 | getClientFor = self.patch(nodegroup_module, 'getClientFor') | ||
105 | 541 | client = getClientFor.return_value | ||
106 | 542 | nodegroup = factory.make_NodeGroup() | ||
107 | 543 | |||
108 | 544 | host = factory.make_name('host') | ||
109 | 545 | username = factory.make_name('user') | ||
110 | 546 | password = factory.make_name('password') | ||
111 | 547 | nodegroup.enlist_nodes_from_mscm( | ||
112 | 548 | host, username, password).wait(10) | ||
113 | 549 | |||
114 | 550 | self.expectThat( | ||
115 | 551 | client, | ||
116 | 552 | MockCalledOnceWith( | ||
117 | 553 | EnlistNodesFromMSCM, host=host, username=username, | ||
118 | 554 | password=password)) | ||
119 | 555 | |||
120 | 556 | def test_enlist_nodes_from_mscm_raises_if_no_connection_to_cluster(self): | ||
121 | 557 | getClientFor = self.patch(nodegroup_module, 'getClientFor') | ||
122 | 558 | getClientFor.side_effect = NoConnectionsAvailable() | ||
123 | 559 | nodegroup = factory.make_NodeGroup() | ||
124 | 560 | |||
125 | 561 | host = factory.make_name('host') | ||
126 | 562 | username = factory.make_name('user') | ||
127 | 563 | password = factory.make_name('password') | ||
128 | 564 | self.assertRaises( | ||
129 | 565 | NoConnectionsAvailable, nodegroup.enlist_nodes_from_mscm, | ||
130 | 566 | host, username, password) | ||
131 | 567 | |||
132 | 568 | def test_enlist_nodes_from_ucsm_end_to_end(self): | ||
133 | 569 | nodegroup = factory.make_NodeGroup(status=NODEGROUP_STATUS.ACCEPTED) | ||
134 | 570 | |||
135 | 571 | self.useFixture(RegionEventLoopFixture("rpc")) | ||
136 | 572 | self.useFixture(RunningEventLoopFixture()) | ||
137 | 573 | fixture = self.useFixture(MockLiveRegionToClusterRPCFixture()) | ||
138 | 574 | protocol = fixture.makeCluster(nodegroup, EnlistNodesFromUCSM) | ||
139 | 575 | protocol.EnlistNodesFromUCSM.return_value = defer.succeed({}) | ||
140 | 576 | |||
141 | 577 | url = factory.make_url() | ||
142 | 578 | username = factory.make_name('user') | ||
143 | 579 | password = factory.make_name('password') | ||
144 | 580 | nodegroup.enlist_nodes_from_ucsm( | ||
145 | 581 | url, username, password).wait(10) | ||
146 | 582 | |||
147 | 583 | self.expectThat( | ||
148 | 584 | protocol.EnlistNodesFromUCSM, | ||
149 | 585 | MockCalledOnceWith( | ||
150 | 586 | ANY, url=url, username=username, password=password)) | ||
151 | 587 | |||
152 | 588 | def test_enlist_nodes_from_ucsm_calls_client_with_resource_endpoint(self): | ||
153 | 589 | getClientFor = self.patch(nodegroup_module, 'getClientFor') | ||
154 | 590 | client = getClientFor.return_value | ||
155 | 591 | nodegroup = factory.make_NodeGroup() | ||
156 | 592 | |||
157 | 593 | url = factory.make_url() | ||
158 | 594 | username = factory.make_name('user') | ||
159 | 595 | password = factory.make_name('password') | ||
160 | 596 | nodegroup.enlist_nodes_from_ucsm( | ||
161 | 597 | url, username, password).wait(10) | ||
162 | 598 | |||
163 | 599 | self.expectThat( | ||
164 | 600 | client, | ||
165 | 601 | MockCalledOnceWith( | ||
166 | 602 | EnlistNodesFromUCSM, url=url, username=username, | ||
167 | 603 | password=password)) | ||
168 | 604 | |||
169 | 605 | def test_enlist_nodes_from_ucsm_raises_if_no_connection_to_cluster(self): | ||
170 | 606 | getClientFor = self.patch(nodegroup_module, 'getClientFor') | ||
171 | 607 | getClientFor.side_effect = NoConnectionsAvailable() | ||
172 | 608 | nodegroup = factory.make_NodeGroup() | ||
173 | 609 | |||
174 | 610 | url = factory.make_url() | ||
175 | 611 | username = factory.make_name('user') | ||
176 | 612 | password = factory.make_name('password') | ||
177 | 613 | self.assertRaises( | ||
178 | 614 | NoConnectionsAvailable, nodegroup.enlist_nodes_from_ucsm, | ||
179 | 615 | url, username, password) | ||
180 | 516 | 616 | ||
181 | === modified file 'src/provisioningserver/rpc/cluster.py' | |||
182 | --- src/provisioningserver/rpc/cluster.py 2014-09-10 16:44:28 +0000 | |||
183 | +++ src/provisioningserver/rpc/cluster.py 2014-09-11 10:17:45 +0000 | |||
184 | @@ -377,3 +377,31 @@ | |||
185 | 377 | errors = { | 377 | errors = { |
186 | 378 | exceptions.NoIPFoundForMACAddress: b"NoIPFoundForMACAddress", | 378 | exceptions.NoIPFoundForMACAddress: b"NoIPFoundForMACAddress", |
187 | 379 | } | 379 | } |
188 | 380 | |||
189 | 381 | |||
190 | 382 | class EnlistNodesFromMSCM(amp.Command): | ||
191 | 383 | """Probe for and enlist mscm machines attached to the cluster. | ||
192 | 384 | |||
193 | 385 | :since 1.7: | ||
194 | 386 | """ | ||
195 | 387 | arguments = [ | ||
196 | 388 | (b"host", amp.Unicode()), | ||
197 | 389 | (b"username", amp.Unicode()), | ||
198 | 390 | (b"password", amp.Unicode()), | ||
199 | 391 | ] | ||
200 | 392 | response = [] | ||
201 | 393 | errors = {} | ||
202 | 394 | |||
203 | 395 | |||
204 | 396 | class EnlistNodesFromUCSM(amp.Command): | ||
205 | 397 | """Probe for and enlist ucsm machines attached to the cluster. | ||
206 | 398 | |||
207 | 399 | :since 1.7: | ||
208 | 400 | """ | ||
209 | 401 | arguments = [ | ||
210 | 402 | (b"url", amp.Unicode()), | ||
211 | 403 | (b"username", amp.Unicode()), | ||
212 | 404 | (b"password", amp.Unicode()), | ||
213 | 405 | ] | ||
214 | 406 | response = [] | ||
215 | 407 | errors = {} | ||
216 | 380 | 408 | ||
217 | === modified file 'src/provisioningserver/rpc/clusterservice.py' | |||
218 | --- src/provisioningserver/rpc/clusterservice.py 2014-09-10 23:00:52 +0000 | |||
219 | +++ src/provisioningserver/rpc/clusterservice.py 2014-09-11 10:17:45 +0000 | |||
220 | @@ -29,6 +29,8 @@ | |||
221 | 29 | ArchitectureRegistry, | 29 | ArchitectureRegistry, |
222 | 30 | PowerTypeRegistry, | 30 | PowerTypeRegistry, |
223 | 31 | ) | 31 | ) |
224 | 32 | from provisioningserver.drivers.hardware.mscm import probe_and_enlist_mscm | ||
225 | 33 | from provisioningserver.drivers.hardware.ucsm import probe_and_enlist_ucsm | ||
226 | 32 | from provisioningserver.drivers.hardware.seamicro import ( | 34 | from provisioningserver.drivers.hardware.seamicro import ( |
227 | 33 | probe_seamicro15k_and_enlist, | 35 | probe_seamicro15k_and_enlist, |
228 | 34 | ) | 36 | ) |
229 | @@ -266,6 +268,26 @@ | |||
230 | 266 | raise exceptions.NoIPFoundForMACAddress(message) | 268 | raise exceptions.NoIPFoundForMACAddress(message) |
231 | 267 | return {} | 269 | return {} |
232 | 268 | 270 | ||
233 | 271 | @cluster.EnlistNodesFromMSCM.responder | ||
234 | 272 | def enlist_nodes_from_mscm(self, host, username, password): | ||
235 | 273 | """enlist_nodes_from_mscm() | ||
236 | 274 | |||
237 | 275 | Implemention of | ||
238 | 276 | :py:class:`~provisioningserver.rpc.cluster.EnlistNodesFromMSCM`. | ||
239 | 277 | """ | ||
240 | 278 | probe_and_enlist_mscm(host, username, password) | ||
241 | 279 | return {} | ||
242 | 280 | |||
243 | 281 | @cluster.EnlistNodesFromUCSM.responder | ||
244 | 282 | def enlist_nodes_from_ucsm(self, url, username, password): | ||
245 | 283 | """enlist_nodes_from_ucsm() | ||
246 | 284 | |||
247 | 285 | Implemention of | ||
248 | 286 | :py:class:`~provisioningserver.rpc.cluster.EnlistNodesFromUCSM`. | ||
249 | 287 | """ | ||
250 | 288 | probe_and_enlist_ucsm(url, username, password) | ||
251 | 289 | return {} | ||
252 | 290 | |||
253 | 269 | 291 | ||
254 | 270 | @implementer(IConnection) | 292 | @implementer(IConnection) |
255 | 271 | class ClusterClient(Cluster): | 293 | class ClusterClient(Cluster): |
256 | 272 | 294 | ||
257 | === modified file 'src/provisioningserver/rpc/tests/test_clusterservice.py' | |||
258 | --- src/provisioningserver/rpc/tests/test_clusterservice.py 2014-09-10 23:00:52 +0000 | |||
259 | +++ src/provisioningserver/rpc/tests/test_clusterservice.py 2014-09-11 10:17:45 +0000 | |||
260 | @@ -1256,3 +1256,57 @@ | |||
261 | 1256 | probe_seamicro15k_and_enlist, MockCalledOnceWith( | 1256 | probe_seamicro15k_and_enlist, MockCalledOnceWith( |
262 | 1257 | find_ip_via_arp.return_value, username, password, | 1257 | find_ip_via_arp.return_value, username, password, |
263 | 1258 | power_control=power_control)) | 1258 | power_control=power_control)) |
264 | 1259 | |||
265 | 1260 | |||
266 | 1261 | class TestClusterProtocol_EnlistNodesFromMSCM(MAASTestCase): | ||
267 | 1262 | |||
268 | 1263 | def test__is_registered(self): | ||
269 | 1264 | protocol = Cluster() | ||
270 | 1265 | responder = protocol.locateResponder( | ||
271 | 1266 | cluster.EnlistNodesFromMSCM.commandName) | ||
272 | 1267 | self.assertIsNot(responder, None) | ||
273 | 1268 | |||
274 | 1269 | def test__calls_probe_and_enlist_mscm(self): | ||
275 | 1270 | probe_and_enlist_mscm = self.patch_autospec( | ||
276 | 1271 | clusterservice, 'probe_and_enlist_mscm') | ||
277 | 1272 | |||
278 | 1273 | host = factory.make_name('host') | ||
279 | 1274 | username = factory.make_name('user') | ||
280 | 1275 | password = factory.make_name('password') | ||
281 | 1276 | |||
282 | 1277 | call_responder(Cluster(), cluster.EnlistNodesFromMSCM, { | ||
283 | 1278 | 'host': host, | ||
284 | 1279 | 'username': username, | ||
285 | 1280 | 'password': password, | ||
286 | 1281 | }) | ||
287 | 1282 | |||
288 | 1283 | self.assertThat( | ||
289 | 1284 | probe_and_enlist_mscm, MockCalledOnceWith( | ||
290 | 1285 | host, username, password)) | ||
291 | 1286 | |||
292 | 1287 | |||
293 | 1288 | class TestClusterProtocol_EnlistNodesFromUCSM(MAASTestCase): | ||
294 | 1289 | |||
295 | 1290 | def test__is_registered(self): | ||
296 | 1291 | protocol = Cluster() | ||
297 | 1292 | responder = protocol.locateResponder( | ||
298 | 1293 | cluster.EnlistNodesFromUCSM.commandName) | ||
299 | 1294 | self.assertIsNot(responder, None) | ||
300 | 1295 | |||
301 | 1296 | def test__calls_probe_and_enlist_ucsm(self): | ||
302 | 1297 | probe_and_enlist_ucsm = self.patch_autospec( | ||
303 | 1298 | clusterservice, 'probe_and_enlist_ucsm') | ||
304 | 1299 | |||
305 | 1300 | url = factory.make_url() | ||
306 | 1301 | username = factory.make_name('user') | ||
307 | 1302 | password = factory.make_name('password') | ||
308 | 1303 | |||
309 | 1304 | call_responder(Cluster(), cluster.EnlistNodesFromUCSM, { | ||
310 | 1305 | 'url': url, | ||
311 | 1306 | 'username': username, | ||
312 | 1307 | 'password': password, | ||
313 | 1308 | }) | ||
314 | 1309 | |||
315 | 1310 | self.assertThat( | ||
316 | 1311 | probe_and_enlist_ucsm, MockCalledOnceWith( | ||
317 | 1312 | url, username, password)) | ||
318 | 1259 | 1313 | ||
319 | === modified file 'src/provisioningserver/tasks.py' | |||
320 | --- src/provisioningserver/tasks.py 2014-09-10 17:00:43 +0000 | |||
321 | +++ src/provisioningserver/tasks.py 2014-09-11 10:17:45 +0000 | |||
322 | @@ -42,8 +42,6 @@ | |||
323 | 42 | set_up_options_conf, | 42 | set_up_options_conf, |
324 | 43 | setup_rndc, | 43 | setup_rndc, |
325 | 44 | ) | 44 | ) |
326 | 45 | from provisioningserver.drivers.hardware.mscm import probe_and_enlist_mscm | ||
327 | 46 | from provisioningserver.drivers.hardware.ucsm import probe_and_enlist_ucsm | ||
328 | 47 | from provisioningserver.logger import get_maas_logger | 45 | from provisioningserver.logger import get_maas_logger |
329 | 48 | 46 | ||
330 | 49 | # For each item passed to refresh_secrets, a refresh function to give it to. | 47 | # For each item passed to refresh_secrets, a refresh function to give it to. |
331 | @@ -297,23 +295,3 @@ | |||
332 | 297 | exc=exc, countdown=UPDATE_NODE_TAGS_RETRY_DELAY) | 295 | exc=exc, countdown=UPDATE_NODE_TAGS_RETRY_DELAY) |
333 | 298 | else: | 296 | else: |
334 | 299 | raise | 297 | raise |
335 | 300 | |||
336 | 301 | |||
337 | 302 | # ===================================================================== | ||
338 | 303 | # Custom hardware tasks | ||
339 | 304 | # ===================================================================== | ||
340 | 305 | |||
341 | 306 | @task | ||
342 | 307 | @log_task_events() | ||
343 | 308 | @log_exception_text | ||
344 | 309 | def enlist_nodes_from_ucsm(url, username, password): | ||
345 | 310 | """ See `maasserver.api.NodeGroupHandler.enlist_nodes_from_ucsm`. """ | ||
346 | 311 | probe_and_enlist_ucsm(url, username, password) | ||
347 | 312 | |||
348 | 313 | |||
349 | 314 | @task | ||
350 | 315 | @log_task_events() | ||
351 | 316 | @log_exception_text | ||
352 | 317 | def enlist_nodes_from_mscm(host, username, password): | ||
353 | 318 | """ See `maasserver.api.NodeGroupHandler.enlist_nodes_from_mscm`. """ | ||
354 | 319 | probe_and_enlist_mscm(host, username, password) |