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

Deepti B. Kalakeri deeptik at linux.vnet.ibm.com
Tue Nov 18 12:42:15 UTC 2008


# HG changeset patch
# User Deepti B. Kalakeri<deeptik at linux.vnet.ibm.com
# Date 1227012098 28800
# Node ID 588efe005eaaf7f56218e844b84bd63e347d0dc0
# Parent  ac693577d27b1b5f24fdc6c50272b11d02c91c7f
[TEST] Adding cim_state_change() to VirtCIM class of vxml.

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 ac693577d27b -r 588efe005eaa suites/libvirt-cim/cimtest/ComputerSystem/05_activate_defined_start.py
--- a/suites/libvirt-cim/cimtest/ComputerSystem/05_activate_defined_start.py	Fri Nov 14 12:48:36 2008 -0800
+++ b/suites/libvirt-cim/cimtest/ComputerSystem/05_activate_defined_start.py	Tue Nov 18 04:41:38 2008 -0800
@@ -65,25 +65,25 @@ def main():
     options = main.options
     status = FAIL
 
-    cxml = vxml.get_class(options.virt)(test_dom, mem) 
 
-#Define a VS
+    cs_class = get_typed_class(options.virt, 'ComputerSystem')
+    keys = { 'Name' : test_dom, 'CreationClassName' : cs_class }
+
     try:
+        #Define a VS
+        cxml = vxml.get_class(options.virt)(test_dom, mem) 
         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)
+            cxml.undefine(options.ip)
             return status
 
     except Exception, detail:
@@ -91,16 +91,17 @@ def main():
         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_state_change(options.ip, options.virt, test_dom, 
+                                       REQUESTED_STATE, TIME)
+        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
@@ -108,11 +109,11 @@ def main():
         else: 
             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 == 3
+        # To state == 2
+        # Enabled_state == RequestedState
 
         if from_State == START_STATE and \
            to_RequestedState == FINAL_STATE and \
@@ -125,7 +126,7 @@ def main():
     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 ac693577d27b -r 588efe005eaa suites/libvirt-cim/lib/XenKvmLib/vxml.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py	Fri Nov 14 12:48:36 2008 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py	Tue Nov 18 04:41:38 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,10 @@ 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 +527,81 @@ class VirtCIM:
             return False
         return ret[0] == 0
 
+    def get_cs_instance(self, server, virt, domain_name, cs_class, keys):
+        cs = None
+        try:
+            cs = GetInstance(server, cs_class, keys)
+
+            if cs.Name != domain_name:
+                logger.error("VS %s is not found", domain_name)
+                return FAIL, cs
+
+        except Exception, detail:
+            logger.error("In fn get_cs_instance()")
+            logger.error("Exception: %s", detail)
+            return  FAIL, cs
+
+        return PASS, cs
+
+    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, rs, time,
+                         poll_timeout=30):
+
+        cs_class = get_typed_class(virt, 'ComputerSystem')
+        keys = { 'Name' : domain_name, 'CreationClassName' : cs_class }
+
+        status, cs = self.get_cs_instance(server, virt, domain_name, 
+                                          cs_class, keys)
+        if status != PASS:
+            return status
+
+        try:
+            req_state   = pywbem.cim_types.Uint16(rs)
+            time_period = pywbem.cim_types.CIMDateTime(time)
+            cs.RequestStateChange(RequestedState=req_state,
+                                  TimeoutPeriod=time_period)
+
+        except Exception, detail:
+            logger.error("In fn cim_state_change()")
+            logger.error("Failed to change the state of the domain '%s'",  
+                          domain_name)
+            logger.error("Exception: %s", detail)
+            return FAIL 
+        status = self.poll_for_state_change(server, domain_name, cs_class, keys, 
+                                            req_state, poll_timeout)
+        return status
+        
+
 class XenXML(VirtXML, VirtCIM):
 
     secondary_disk_path = const.Xen_secondary_disk_path




More information about the Libvirt-cim mailing list