List VM and check if its state is as expected @returnValue - List[Result, Reason] 1) Result - FAIL if there is any exception in the operation or VM state does not change to expected state in given time else PASS
(self, apiclient, state, timeout=600)
| 859 | return self.ssh_client |
| 860 | |
| 861 | def getState(self, apiclient, state, timeout=600): |
| 862 | """List VM and check if its state is as expected |
| 863 | @returnValue - List[Result, Reason] |
| 864 | 1) Result - FAIL if there is any exception |
| 865 | in the operation or VM state does not change |
| 866 | to expected state in given time else PASS |
| 867 | 2) Reason - Reason for failure""" |
| 868 | |
| 869 | returnValue = [FAIL, Exception(f"VM state not transitioned to {state},\ |
| 870 | operation timed out")] |
| 871 | |
| 872 | while timeout > 0: |
| 873 | try: |
| 874 | projectid = None |
| 875 | if hasattr(self, "projectid"): |
| 876 | projectid = self.projectid |
| 877 | vms = VirtualMachine.list(apiclient, projectid=projectid, |
| 878 | id=self.id, listAll=True) |
| 879 | validationresult = validateList(vms) |
| 880 | if validationresult[0] == FAIL: |
| 881 | raise Exception("VM list validation failed: %s" % validationresult[2]) |
| 882 | elif str(vms[0].state).lower() == str(state).lower(): |
| 883 | returnValue = [PASS, None] |
| 884 | break |
| 885 | except Exception as e: |
| 886 | returnValue = [FAIL, e] |
| 887 | break |
| 888 | time.sleep(60) |
| 889 | timeout -= 60 |
| 890 | return returnValue |
| 891 | |
| 892 | def resetSshKey(self, apiclient, **kwargs): |
| 893 | """Resets SSH key""" |
no test coverage detected