# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1232135486 28800
# Node ID 57f3bc7c3105bb779b41e19b1c03a1e5f214cec1
# Parent 32645e444b323b137d0c0a2a323be574b370d75a
[TEST] #3 Update VSMS 04_definesystem_ers.py to use cim_define()
Add a err_rc and err_desc elements to the VirtCIM class. This will allow
us to check the error code and error description in case of failed CIM
method calls.
Add two functions: set_sys_settings() and set_res_settings(). These allow the
caller to set the VSSD and RASDs after the initial init() of the VirtCIM class.
Some of the logic in cim_define() was changed to allow the passing of just
a single RASD to DefineSystem() (instead of passing all the RASDs).
Updates from 2 to 3:
-Rebased on current tree
Updates from 1 to 2:
-Create function to verify return code and error description if define fails
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 32645e444b32 -r 57f3bc7c3105
suites/libvirt-cim/cimtest/VirtualSystemManagementService/04_definesystem_ers.py
--- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/04_definesystem_ers.py Wed
Jan 14 21:29:48 2009 -0800
+++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/04_definesystem_ers.py Fri
Jan 16 11:51:26 2009 -0800
@@ -23,17 +23,14 @@
#
import sys
-import pywbem
-from VirtLib import utils
-from XenKvmLib import vsms
-from XenKvmLib.test_doms import undefine_test_domain
-from XenKvmLib.common_util import create_using_definesystem
+from pywbem import CIM_ERR_FAILED
from CimTest.Globals import logger
from XenKvmLib.const import do_main
from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC
+from XenKvmLib.vxml import get_class
sup_types = ['Xen', 'KVM', 'XenFV', 'LXC']
-exp_rc = 1 #CMPI_RC_ERR_FAILED
+exp_rc = CIM_ERR_FAILED
exp_desc = 'Unable to parse embedded object'
@do_main(sup_types)
@@ -41,26 +38,28 @@
options = main.options
dname = 'test_domain'
- vssd, rasd = vsms.default_vssd_rasd_str(dom_name=dname, virt=options.virt)
- params = {'vssd' : vssd,
- 'rasd' : ['wrong']
- }
+ cxml = get_class(options.virt)(dname)
- exp_err = {'exp_rc' : exp_rc,
- 'exp_desc' : exp_desc
- }
+ rasd_list = { "MemResourceAllocationSettingData" : "wrong" }
+ cxml.set_res_settings(rasd_list)
+ try:
+ ret = cxml.cim_define(options.ip)
+ if ret:
+ raise Exception('DefineSystem returned OK with invalid params')
- rc = create_using_definesystem(dname, options.ip, params, ref_config=' ',
- exp_err=exp_err, virt=options.virt)
+ status = cxml.verify_error_msg(exp_rc, exp_desc)
+ if status != PASS:
+ raise Exception('DefineSystem failed for an unexpected reason')
- if rc != PASS:
- logger.error('DefineSystem should NOT return OK with a wrong ss input')
+ except Exception, details:
+ logger.error(details)
+ status = FAIL
- undefine_test_domain(dname, options.ip, virt=options.virt)
+ cxml.undefine(options.ip)
- return rc
+ return status
if __name__ == "__main__":
sys.exit(main())
diff -r 32645e444b32 -r 57f3bc7c3105 suites/libvirt-cim/lib/XenKvmLib/vxml.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Wed Jan 14 21:29:48 2009 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Fri Jan 16 11:51:26 2009 -0800
@@ -470,6 +470,8 @@
mem_allocunits, emu_type):
self.virt = virt
self.domain_name = dom_name
+ self.err_rc = None
+ self.err_desc = None
self.vssd = vsms.get_vssd_mof(virt, dom_name)
self.nasd = vsms.get_nasd_class(virt)(type=net_type,
mac=net_mac,
@@ -491,11 +493,17 @@
def cim_define(self, ip, ref_conf=None):
service = vsms.get_vsms_class(self.virt)(ip)
sys_settings = str(self.vssd)
- if self.virt == 'LXC' and const.LXC_netns_support is False:
- res_settings = [str(self.dasd), str(self.pasd), str(self.masd)]
- else:
- res_settings = [str(self.dasd), str(self.nasd),
- str(self.pasd), str(self.masd)]
+
+ res_settings = []
+ if self.dasd is not None:
+ res_settings.append(str(self.dasd))
+ if self.pasd is not None:
+ res_settings.append(str(self.pasd))
+ if self.masd is not None:
+ res_settings.append(str(self.masd))
+ if self.nasd is not None or \
+ (self.virt == 'LXC' and const.LXC_netns_support is False):
+ res_settings.append(str(self.nasd))
if ref_conf is None:
ref_conf = ' '
@@ -506,6 +514,8 @@
ReferenceConfiguration=ref_conf)
except pywbem.CIMError, (rc, desc):
logger.error('Got CIM error %s with return code %s' % (desc, rc))
+ self.err_rc = rc
+ self.err_desc = desc
return False
except Exception, details:
@@ -523,6 +533,12 @@
target = pywbem.cim_obj.CIMInstanceName(cs_cn, keybindings = keys)
try:
ret = service.DestroySystem(AffectedSystem=target)
+ except pywbem.CIMError, (rc, desc):
+ logger.error('Got CIM error %s with return code %s' % (desc, rc))
+ self.err_rc = rc
+ self.err_desc = desc
+ return False
+
except Exception, details:
logger.error('Error invoking DestroySystem')
logger.error('Got error %s with exception %s' \
@@ -575,6 +591,12 @@
cs.RequestStateChange(RequestedState=req_state_change,
TimeoutPeriod=time_period)
+ except pywbem.CIMError, (rc, desc):
+ logger.error('Got CIM error %s with return code %s' % (desc, rc))
+ self.err_rc = rc
+ self.err_desc = desc
+ return FAIL
+
except Exception, detail:
logger.error("In fn cim_state_change()")
logger.error("Failed to change state of the domain '%s'",
cs.Name)
@@ -620,6 +642,36 @@
return self.cim_state_change(server, const.CIM_RESET,
req_time, poll_time, const.CIM_ENABLE)
+ def set_sys_settings(self, vssd):
+ self.vssd = vssd
+
+ def set_res_settings(self, rasd_list):
+ for cn, rasd in rasd_list.iteritems():
+ if cn.find("MemResourceAllocationSettingData") >= 0:
+ self.masd = rasd
+ elif cn.find("ProcResourceAllocationSettingData") >= 0:
+ self.pasd = rasd
+ elif cn.find("DiskResourceAllocationSettingData") >= 0:
+ self.dasd = rasd
+ elif cn.find("NetResourceAllocationSettingData") >= 0:
+ self.nasd = rasd
+
+ def verify_error_msg(self, exp_rc, exp_desc):
+ try:
+ rc = int(self.err_rc)
+
+ if rc != exp_rc:
+ raise Exception("Got rc: %d, exp %d." % (rc, exp_rc))
+
+ if self.err_desc.find(exp_desc) < 0:
+ raise Exception("Got desc: '%s', exp '%s'" %
(self.err_desc,
+ exp_desc))
+
+ except Exception, details:
+ logger.error(details)
+ return FAIL
+
+ return PASS
class XenXML(VirtXML, VirtCIM):