[Libvirt-cim] [PATCH] [TEST] Update VSMS 04_definesystem_ers.py to use cim_define()
Deepti B Kalakeri
deeptik at linux.vnet.ibm.com
Thu Jan 8 07:54:00 UTC 2009
Kaitlin Rupert wrote:
> # HG changeset patch
> # User Kaitlin Rupert <karupert at us.ibm.com>
> # Date 1231351832 28800
> # Node ID a320568c9308dc0d42c8fe46a7aad0f3ff699260
> # Parent 64672f2644fb26a6788f171685269e59b9029142
> [TEST] 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).
>
> Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>
>
> diff -r 64672f2644fb -r a320568c9308 suites/libvirt-cim/cimtest/VirtualSystemManagementService/04_definesystem_ers.py
> --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/04_definesystem_ers.py Wed Jan 07 10:10:00 2009 -0800
> +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/04_definesystem_ers.py Wed Jan 07 10:10:32 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,34 @@
> 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)
>
> + ret = cxml.cim_define(options.ip)
> + if ret:
> + logger.error('DefineSystem should NOT return OK with a wrong ss input')
> + status = FAIL
>
> - rc = create_using_definesystem(dname, options.ip, params, ref_config=' ',
> - exp_err=exp_err, virt=options.virt)
> + try:
> + if int(cxml.err_rc) != exp_rc:
> + raise Exception("Got rc: %d, exp %d." % (int(cxml.err_rc), exp_rc))
>
> - if rc != PASS:
> - logger.error('DefineSystem should NOT return OK with a wrong ss input')
> + if cxml.err_desc.find(exp_desc) < 0:
> + raise Exception("Got desc: '%s', exp '%s'" % (cxml.err_desc,
> + exp_desc))
>
>
How about including the above checks for err_rc and err_desc in the
cim_define() like the way we have in create_using_definesystem().
This would avoid repeating this check in every test which verifies the
error conditions.
> - undefine_test_domain(dname, options.ip, virt=options.virt)
> + status = PASS
>
> - return rc
> + except Exception, details:
> + logger.error(details)
> + status = FAIL
> +
> + cxml.undefine(options.ip)
> +
> + return status
>
> if __name__ == "__main__":
> sys.exit(main())
> diff -r 64672f2644fb -r a320568c9308 suites/libvirt-cim/lib/XenKvmLib/vxml.py
> --- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Wed Jan 07 10:10:00 2009 -0800
> +++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Wed Jan 07 10:10:32 2009 -0800
> @@ -469,6 +469,8 @@
> net_type, net_name, net_mac, vcpus, mem, mem_allocunits):
> 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.dasd = vsms.get_dasd_class(virt)(disk_dev, disk_source, dom_name)
> self.nasd = vsms.get_nasd_class(virt)(type=net_type,
> @@ -487,11 +489,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 = ' '
> @@ -502,6 +510,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:
> @@ -519,6 +529,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' \
> @@ -570,6 +586,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)
> @@ -615,6 +637,19 @@
> 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
>
> class XenXML(VirtXML, VirtCIM):
>
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim
>
--
Thanks and Regards,
Deepti B. Kalakeri
IBM Linux Technology Center
deeptik at linux.vnet.ibm.com
More information about the Libvirt-cim
mailing list