|
23 | 23 | from marvin.cloudstackAPI import * |
24 | 24 | from marvin.codes import (FAILED, FAIL, PASS, RUNNING, STOPPED, |
25 | 25 | STARTING, DESTROYED, EXPUNGING, |
26 | | - STOPPING, BACKED_UP, BACKING_UP) |
| 26 | + STOPPING, BACKED_UP, BACKING_UP, |
| 27 | + HOST_RS_MAINTENANCE) |
27 | 28 | from marvin.cloudstackException import GetDetailExceptionInfo, CloudstackAPIException |
28 | | -from marvin.lib.utils import validateList, is_server_ssh_ready, random_gen |
| 29 | +from marvin.lib.utils import validateList, is_server_ssh_ready, random_gen, wait_until |
29 | 30 | # Import System modules |
30 | 31 | import time |
31 | 32 | import hashlib |
@@ -2459,13 +2460,40 @@ def create(cls, apiclient, cluster, services, zoneid=None, podid=None, hyperviso |
2459 | 2460 | GetDetailExceptionInfo(e) |
2460 | 2461 | return FAILED |
2461 | 2462 |
|
| 2463 | + @staticmethod |
| 2464 | + def _check_resource_state(apiclient, hostid, resourcestate): |
| 2465 | + hosts = Host.list(apiclient, id=hostid, listall=True) |
| 2466 | + |
| 2467 | + validationresult = validateList(hosts) |
| 2468 | + |
| 2469 | + assert validationresult is not None, "'validationresult' should not be equal to 'None'." |
| 2470 | + |
| 2471 | + assert isinstance(validationresult, list), "'validationresult' should be a 'list'." |
| 2472 | + |
| 2473 | + assert len(validationresult) == 3, "'validationresult' should be a list with three items in it." |
| 2474 | + |
| 2475 | + if validationresult[0] == FAIL: |
| 2476 | + raise Exception("Host list validation failed: %s" % validationresult[2]) |
| 2477 | + |
| 2478 | + if str(hosts[0].resourcestate).lower().decode("string_escape") == str(resourcestate).lower(): |
| 2479 | + return True, None |
| 2480 | + |
| 2481 | + return False, "Host is not in the following state: " + str(resourcestate) |
| 2482 | + |
2462 | 2483 | def delete(self, apiclient): |
2463 | 2484 | """Delete Host""" |
2464 | 2485 | # Host must be in maintenance mode before deletion |
2465 | 2486 | cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd() |
2466 | 2487 | cmd.id = self.id |
2467 | 2488 | apiclient.prepareHostForMaintenance(cmd) |
2468 | | - time.sleep(30) |
| 2489 | + |
| 2490 | + retry_interval = 10 |
| 2491 | + num_tries = 10 |
| 2492 | + |
| 2493 | + wait_result, return_val = wait_until(retry_interval, num_tries, Host._check_resource_state, apiclient, self.id, HOST_RS_MAINTENANCE) |
| 2494 | + |
| 2495 | + if not wait_result: |
| 2496 | + raise Exception(return_val) |
2469 | 2497 |
|
2470 | 2498 | cmd = deleteHost.deleteHostCmd() |
2471 | 2499 | cmd.id = self.id |
@@ -2711,7 +2739,7 @@ def getState(cls, apiclient, poolid, state, timeout=600): |
2711 | 2739 | id=poolid, listAll=True) |
2712 | 2740 | validationresult = validateList(pools) |
2713 | 2741 | if validationresult[0] == FAIL: |
2714 | | - raise Exception("Host list validation failed: %s" % validationresult[2]) |
| 2742 | + raise Exception("Pool list validation failed: %s" % validationresult[2]) |
2715 | 2743 | elif str(pools[0].state).lower().decode("string_escape") == str(state).lower(): |
2716 | 2744 | returnValue = [PASS, None] |
2717 | 2745 | break |
|
0 commit comments