You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by gi...@apache.org on 2014/05/06 13:31:56 UTC

git commit: updated refs/heads/4.4-forward to 6598167

Repository: cloudstack
Updated Branches:
  refs/heads/4.4-forward 8546f76b7 -> 6598167be


CLOUDSTACK-6257: Adding function to check the VM state


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6598167b
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6598167b
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6598167b

Branch: refs/heads/4.4-forward
Commit: 6598167bedb1f00e9d1efc12b82999f8e822d5d6
Parents: 8546f76
Author: Gaurav Aradhye <ga...@clogeny.com>
Authored: Fri May 2 13:54:50 2014 +0530
Committer: Gaurav Aradhye <ga...@clogeny.com>
Committed: Tue May 6 00:43:42 2014 -0400

----------------------------------------------------------------------
 tools/marvin/marvin/codes.py    |  5 ++++
 tools/marvin/marvin/lib/base.py | 45 +++++++++++++++++++++++++++++++++++-
 2 files changed, 49 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6598167b/tools/marvin/marvin/codes.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/codes.py b/tools/marvin/marvin/codes.py
index 660193a..ef49c0c 100644
--- a/tools/marvin/marvin/codes.py
+++ b/tools/marvin/marvin/codes.py
@@ -31,6 +31,11 @@
 """
 
 RUNNING = "Running"
+STOPPED = "Stopped"
+STOPPING = "Stopping"
+STARTING = "Starting"
+DESTROYED = "Destroyed"
+EXPUNGING = "Expunging"
 RECURRING = "RECURRING"
 ENABLED = "Enabled"
 NETWORK_OFFERING = "network_offering"

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6598167b/tools/marvin/marvin/lib/base.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/lib/base.py b/tools/marvin/marvin/lib/base.py
index f49323e..cd113f8 100644
--- a/tools/marvin/marvin/lib/base.py
+++ b/tools/marvin/marvin/lib/base.py
@@ -21,7 +21,9 @@
 
 import marvin
 from marvin.cloudstackAPI import *
-from marvin.codes import FAILED, PASS
+from marvin.codes import (FAILED, FAIL, PASS, RUNNING, STOPPED,
+                          STARTING, DESTROYED, EXPUNGING,
+                          STOPPING)
 from marvin.cloudstackException import GetDetailExceptionInfo
 from marvin.lib.utils import validateList, is_server_ssh_ready, random_gen
 # Import System modules
@@ -234,6 +236,16 @@ class VirtualMachine:
 
     """Manage virtual machine lifecycle"""
 
+    '''Class level variables'''
+    # Variables denoting VM state - start
+    STOPPED = STOPPED
+    RUNNING = RUNNING
+    DESTROYED = DESTROYED
+    EXPUNGING = EXPUNGING
+    STOPPING = STOPPING
+    STARTING = STARTING
+    # Varibles denoting VM state - end
+
     def __init__(self, items, services):
         self.__dict__.update(items)
         if "username" in services:
@@ -495,6 +507,10 @@ class VirtualMachine:
         if forced:
             cmd.forced = forced
         apiclient.stopVirtualMachine(cmd)
+        response = self.getState(apiclient, VirtualMachine.STOPPED)
+        if response[0] == FAIL:
+            raise Exception(response[1])
+        return
 
     def reboot(self, apiclient):
         """Reboot the instance"""
@@ -548,6 +564,33 @@ class VirtualMachine:
         )
         return self.ssh_client
 
+    def getState(self, apiclient, state, timeout=600):
+        """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
+                       2) Reason - Reason for failure"""
+
+        returnValue = [FAIL, "VM state not trasited to %s,\
+                        operation timed out" % state]
+
+        while timeout>0:
+            try:
+                vms = VirtualMachine.list(apiclient, id=self.id, listAll=True)
+                validationresult = validateList(vms)
+                if validationresult[0] == FAIL:
+                    raise Exception("VM list validation failed: %s" % validationresult[2])
+                elif str(vms[0].state).lower() == str(state).lower():
+                    returnValue = [PASS, None]
+                    break
+            except Exception as e:
+                returnValue = [FAIL, e]
+                break
+            time.sleep(60)
+            timeout -= 60
+        return returnValue
+
     def resetSshKey(self, apiclient, **kwargs):
         """Resets SSH key"""