[Libvirt-cim] [PATCH] [TEST] #3 Adding cim_state_change() to VirtCIM class of vxml

Deepti B. Kalakeri deeptik at linux.vnet.ibm.com
Thu Nov 20 06:30:34 UTC 2008


# HG changeset patch
# User Deepti B. Kalakeri<deeptik at linux.vnet.ibm.com
# Date 1227162571 28800
# Node ID 340a8219c05fd707857536f04b0c0c4ab7fe1337
# Parent  78b18dc8cbfccff5b50c8c7228ca3a7396facc61
[TEST] #3 Adding cim_state_change() to VirtCIM class of vxml.

Changes:
--------
Updates from 2 to 3:
--------------------
Updated the missing cim VS state transition values to const.py.
Added cim_no_stat_change(), cim_shutdown(), cim_reset() to vxml.py.
Changed the comment in 05_activate_defined_start.py to make it more meaningful.

Updates from Patch 1 to 2:
--------------------------
Removed the get_cs_instance() fn.
Declared VS states and TIME values in const.py.
Added cim_start(), cim_reboot(), cim_pause(), cim_suspend() fn's.


Patch 1:
--------
cim_state_change() fn can be used to start/reboot/suspend the domain.
The function verifies that the state of the domain is changed by calling poll_for_state_change().
Included poll_for_state_change(), .get_cs_instance() fn in the vxml since including it from common_util
was causing a circular chain and was failing.

Right now the cim_state_change() just returns the the status, Can modify to return the domain if req.

Signed-off-by: Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>

diff -r 78b18dc8cbfc -r 340a8219c05f suites/libvirt-cim/cimtest/ComputerSystem/05_activate_defined_start.py
--- a/suites/libvirt-cim/cimtest/ComputerSystem/05_activate_defined_start.py	Thu Nov 13 21:42:27 2008 -0800
+++ b/suites/libvirt-cim/cimtest/ComputerSystem/05_activate_defined_start.py	Wed Nov 19 22:29:31 2008 -0800
@@ -48,7 +48,6 @@ from CimTest.Globals import logger
 from CimTest.Globals import logger
 from XenKvmLib.const import do_main
 from XenKvmLib.classes import get_typed_class
-from XenKvmLib.common_util import call_request_state_change
 from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC
 
 sup_types = ['Xen', 'KVM', 'XenFV', 'LXC']
@@ -57,8 +56,6 @@ bug_no  = "00002"
 bug_no  = "00002"
 START_STATE = 3 
 FINAL_STATE = 2
-REQUESTED_STATE = FINAL_STATE 
-TIME = "00000000000000.000000:000"
 
 @do_main(sup_types)
 def main():
@@ -66,66 +63,64 @@ def main():
     status = FAIL
 
     cxml = vxml.get_class(options.virt)(test_dom, mem) 
+    ret = cxml.cim_define(options.ip)
+    #Define a VS
+    if not ret :
+        logger.error("ERROR: VS '%s' was not defined", test_dom)
+        return status 
 
-#Define a VS
+    cs_class = get_typed_class(options.virt, 'ComputerSystem')
+    keys = { 'Name' : test_dom, 'CreationClassName' : cs_class }
+
     try:
-        ret = cxml.cim_define(options.ip)
-        if not ret :
-            logger.error("ERROR: VS %s was not defined" % test_dom)
-            return status 
-        cs_class = get_typed_class(options.virt, 'ComputerSystem')
-        keys = {
-                'Name' : test_dom,
-                'CreationClassName' : cs_class
-               }
         cs = enumclass.GetInstance(options.ip, cs_class, keys)
-
         if cs.Name == test_dom:
             from_State =  cs.EnabledState
         else:
-            logger.error("ERROR: VS %s is not available" % test_dom)
+            logger.error("VS '%s' is not available", test_dom)
             return status
 
     except Exception, detail:
         logger.error("Exception: %s" % detail)
         cxml.undefine(options.ip)
         return status
-        
-#Change the state of the  VS to Start
-    rc = call_request_state_change(test_dom, options.ip, REQUESTED_STATE,
-                                   TIME, options.virt)
-    if rc != 0:
-        logger.error("Unable start dom %s using RequestedStateChange()", test_dom)
-        cxml.undefine(options.ip)
-        return status
 
-#Get the value of the EnabledState property and RequestedState property.
     try:
+        #Change the state of the  VS to Start
+        status = cxml.cim_start(options.ip, options.virt, test_dom)
+        if status != PASS:      
+            logger.error("Unable start dom '%s' using "
+                         "RequestedStateChange()", test_dom)
+            cxml.undefine(options.ip)
+            return status
+
+        #Get the value of the EnabledState property and RequestedState property.
         cs= enumclass.GetInstance(options.ip, cs_class, keys)
         if cs.Name == test_dom:
             to_RequestedState = cs.RequestedState
             enabledState = cs.EnabledState
         else: 
-            logger.error("VS %s is not found" % test_dom)
+            logger.error("VS '%s' is not found", test_dom)
             return status 
-# Success: 
-# if  
-# From state == 3
-# To state == 2
-# Enabled_state == RequestedState
+
+        # Success: 
+        # if  
+        # From state == defined
+        # To state == running
+        # Enabled_state == RequestedState
 
         if from_State == START_STATE and \
            to_RequestedState == FINAL_STATE and \
            enabledState == to_RequestedState:
             status = PASS
         else:
-            logger.error("ERROR: VS %s transition from Defined State to Activate state\
- was not Successful" % test_dom)
+            logger.error("VS '%s' transition from Defined State to "
+                         "Activate state was not Successful", test_dom)
             status = XFAIL_RC(bug_no)
     except Exception, detail:
         logger.error("Exception: %s" % detail)
 
-    cxml.destroy(options.ip)
+    cxml.cim_destroy(options.ip)
     cxml.undefine(options.ip)
     return status
 if __name__ == "__main__":
diff -r 78b18dc8cbfc -r 340a8219c05f suites/libvirt-cim/lib/XenKvmLib/const.py
--- a/suites/libvirt-cim/lib/XenKvmLib/const.py	Thu Nov 13 21:42:27 2008 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/const.py	Wed Nov 19 22:29:31 2008 -0800
@@ -30,6 +30,19 @@ platform_sup = ["Xen", "KVM", "XenFV"]
 platform_sup = ["Xen", "KVM", "XenFV"]
 
 VIRSH_ERROR_DEFINE = "Failed to define a domain with the name %s from virsh"
+
+#CIM values for VS State transitions
+CIM_START      = 2
+CIM_DEFINE     = 3
+CIM_SHUTDOWN   = 4
+CIM_NOCHANGE   = 5
+CIM_SUSPEND    = 6
+CIM_PAUSE      = 9
+CIM_REBOOT     = 10
+CIM_RESET      = 11
+
+# Default TimeoutPeriod param for CS.RequestedStateChange()
+TIME           = "00000000000000.000000:000"
 
 # vxml.NetXML
 default_bridge_name = 'testbridge'
diff -r 78b18dc8cbfc -r 340a8219c05f suites/libvirt-cim/lib/XenKvmLib/vxml.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py	Thu Nov 13 21:42:27 2008 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py	Wed Nov 19 22:29:31 2008 -0800
@@ -34,6 +34,7 @@ import sys
 import sys
 import platform
 import tempfile
+from time import sleep
 import pywbem
 from xml.dom import minidom, Node
 from xml import xpath
@@ -43,8 +44,9 @@ from XenKvmLib import vsms
 from XenKvmLib import vsms
 from XenKvmLib import const
 from CimTest.Globals import logger, CIM_IP, CIM_PORT, CIM_NS, CIM_USER, CIM_PASS
-from CimTest.ReturnCodes import SKIP
+from CimTest.ReturnCodes import SKIP, PASS, FAIL
 from XenKvmLib.classes import virt_types, get_typed_class
+from XenKvmLib.enumclass  import GetInstance
 
 class XMLClass:
     xml_string = ""
@@ -524,6 +526,98 @@ class VirtCIM:
             return False
         return ret[0] == 0
 
+    def poll_for_state_change(self, server, domain_name, cs_class, keys, 
+                              req_state, timeout):
+        dom_cs = None
+        try:
+
+            for i in range(1, (timeout + 1)):
+                dom_cs = GetInstance(server, cs_class, keys)
+                if dom_cs is None or dom_cs.Name != domain_name:
+                    continue
+
+                sleep(1)
+                if dom_cs.EnabledState == req_state:
+                    break
+        
+        except Exception, detail:
+            logger.error("In fn poll_for_state_change()")
+            logger.error("Exception: %s" % detail)
+            return FAIL
+
+        if dom_cs is None or dom_cs.Name != domain_name:
+            logger.error("CS instance not returned for %s." % domain_name)
+            return FAIL
+
+        if dom_cs.EnabledState != req_state:
+            logger.error("EnabledState is %i instead of %i.", 
+                         dom_cs.EnabledState, req_state)
+            logger.error("Try to increase the timeout and run the test again")
+            return FAIL
+
+        return PASS
+
+    def cim_state_change(self, server, virt, domain_name,
+                         req_state, req_timeout, poll_time):
+        cs = None
+        cs_class = get_typed_class(virt, 'ComputerSystem')
+        keys = { 'Name' : domain_name, 'CreationClassName' : cs_class }
+        cs = GetInstance(server, cs_class, keys)
+        if cs is None or cs.Name != domain_name:
+            return status
+
+        try:
+            req_state_change   = pywbem.cim_types.Uint16(req_state)
+            time_period = pywbem.cim_types.CIMDateTime(req_timeout)
+            cs.RequestStateChange(RequestedState=req_state_change,
+                                  TimeoutPeriod=time_period)
+
+        except Exception, detail:
+            logger.error("In fn cim_state_change()")
+            logger.error("Failed to change state of the domain '%s'", cs.Name)
+            logger.error("Exception: %s", detail)
+            return FAIL 
+
+        status = self.poll_for_state_change(server, domain_name, cs_class, keys, 
+                                            req_state, poll_time)
+        return status
+
+    def cim_start(self, server, virt, domain_name, 
+                  req_time=const.TIME, poll_time=30):
+        return self.cim_state_change(server, virt, domain_name, 
+                                     const.CIM_START, req_time, poll_time)
+
+    def cim_shutdown(self, server, virt, domain_name, 
+                     req_time=const.TIME, poll_time=30):
+        return self.cim_state_change(server, virt, domain_name, 
+                                     const.CIM_SHUTDOWN, req_time, poll_time)
+
+    def cim_no_state_change(self, server, virt, domain_name, 
+                            req_time=const.TIME, poll_time=30):
+        return self.cim_state_change(server, virt, domain_name, 
+                                     const.CIM_NOCHANGE, req_time, poll_time)
+
+    def cim_suspend(self, server, virt, domain_name, 
+                    req_time=const.TIME, poll_time=30):
+        return self.cim_state_change(server, virt, domain_name, 
+                                     const.CIM_SUSPEND, req_time, poll_time)
+
+    def cim_pause(self, server, virt, domain_name, 
+                    req_time=const.TIME, poll_time=30):
+        return self.cim_state_change(server, virt, domain_name,
+                                     const.CIM_PAUSE, req_time, poll_time)
+        
+    def cim_reboot(self, server, virt, domain_name, 
+                   req_time=const.TIME, poll_time=30):
+        return self.cim_state_change(server, virt, domain_name, 
+                                     const.CIM_REBOOT, req_time, poll_time)
+
+    def cim_reset(self, server, virt, domain_name, 
+                  req_time=const.TIME, poll_time=30):
+        return self.cim_state_change(server, virt, domain_name, 
+                                     const.CIM_RESET, req_time, poll_time)
+
+
 class XenXML(VirtXML, VirtCIM):
 
     secondary_disk_path = const.Xen_secondary_disk_path




More information about the Libvirt-cim mailing list