# HG changeset patch
# User Deepti B. Kalakeri<deeptik(a)linux.vnet.ibm.com
# Date 1227103041 28800
# Node ID 6b81367e87d574d3352f2752a4d303ff155367fd
# Parent 78b18dc8cbfccff5b50c8c7228ca3a7396facc61
[TEST] #2 Adding cim_state_change() to VirtCIM class of vxml.
Changes:
--------
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(a)linux.vnet.ibm.com>
diff -r 78b18dc8cbfc -r 6b81367e87d5
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
05:57:21 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,41 +63,38 @@ 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
@@ -108,24 +102,24 @@ 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 \
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 6b81367e87d5 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 05:57:21 2008 -0800
@@ -30,6 +30,16 @@ 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_SUSPEND = 6
+CIM_PAUSE = 9
+CIM_REBOOT = 10
+
+# Default TimeoutPeriod param for CS.RequestedStateChange()
+TIME = "00000000000000.000000:000"
# vxml.NetXML
default_bridge_name = 'testbridge'
diff -r 78b18dc8cbfc -r 6b81367e87d5 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 05:57:21 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,83 @@ 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_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_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)
+
+
class XenXML(VirtXML, VirtCIM):
secondary_disk_path = const.Xen_secondary_disk_path