# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1217427140 25200
# Node ID be869ee37ebd8cd304751dd67b7ac47ce6c642ce
# Parent 753ddf4191cff036c917376039299a4e525db1c9
[TEST] #3 Check that the DefineSystem() result can be passed to GetInstance()
Changes:
- Check that ResultingSystem is a REF instead of an instance too
- Handle case where results does not include a ResultingSystem
- Undefine test domain before exit
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r 753ddf4191cf -r be869ee37ebd
suites/libvirt-cim/cimtest/VirtualSystemManagementService/12_define_result.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/12_define_result.py Wed
Jul 30 07:12:20 2008 -0700
@@ -0,0 +1,106 @@
+#!/usr/bin/python
+#
+# Copyright 2008 IBM Corp.
+#
+# Authors:
+# Dan Smith <danms(a)us.ibm.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+sup_types = ['Xen', 'XenFV', 'KVM']
+default_dom = "define_test"
+
+import sys
+import pywbem
+from CimTest.ReturnCodes import FAIL, PASS
+from CimTest.Globals import do_main
+from CimTest.Globals import logger
+from CimTest import Globals
+from XenKvmLib import vsms
+from XenKvmLib.classes import get_typed_class
+from XenKvmLib.test_doms import undefine_test_domain
+
+def define_system(host, virt, name, vssd, rasds):
+ vsms_class = eval("vsms." + \
+ get_typed_class(virt,
+ "VirtualSystemManagementService"))
+
+ service = vsms_class(host)
+
+ rc, results = service.DefineSystem(SystemSettings=vssd,
+ ResourceSettings=rasds,
+ ReferenceConfiguration=' ')
+
+ try:
+ system = results["ResultingSystem"]
+ except KeyError:
+ logger.error("DefineSystem() did not return a ResultingSystem")
+ return FAIL, None
+
+ return rc, system
+
+def get_instance_by_ref(host, ref):
+ conn = pywbem.WBEMConnection('http://%s' % host,
+ (Globals.CIM_USER, Globals.CIM_PASS),
+ ref.namespace)
+ return conn.GetInstance(ref)
+
+def define_test_system(options):
+ vssd_class = vsms.get_vssd_class(options.virt)
+ vssd = vssd_class(name=default_dom, virt=options.virt)
+
+ mrasd_class = vsms.get_masd_class(options.virt)
+ mrasd = mrasd_class(32, default_dom)
+
+ rc, system = define_system(options.ip,
+ options.virt,
+ default_dom,
+ vssd.mof(),
+ [mrasd.mof()])
+
+ return rc, system
+
+@do_main(sup_types)
+def main():
+ options = main.options
+
+ rc, systemref = define_test_system(options)
+ if systemref is None:
+ return rc
+
+ if not isinstance(systemref, pywbem.CIMInstanceName):
+ logger.error("ResultingSystem is not a Reference!")
+ return FAIL
+
+ if systemref.namespace is None:
+ logger.error("Returned reference had no namespace!")
+ return FAIL
+
+ logger.info("GetInstance(%s)" % systemref)
+ system = get_instance_by_ref(options.ip, systemref)
+
+ undefine_test_domain(default_dom, options.ip, virt=options.virt)
+
+ if system["Name"] == default_dom:
+ logger.info("Validated resulting system instance")
+ return PASS
+ else:
+ logger.error("Result system was: %s instead of %s" %
(system["Name"],
+ default_dom))
+ return FAIL
+
+if __name__ == "__main__":
+ sys.exit(main())
Show replies by date
+@do_main(sup_types)
+def main():
+ options = main.options
+
+ rc, systemref = define_test_system(options)
+ if systemref is None:
+ return rc
+
+ if not isinstance(systemref, pywbem.CIMInstanceName):
+ logger.error("ResultingSystem is not a Reference!")
+ return FAIL
+
You'll need to undefine the guest before the return
+ if systemref.namespace is None:
+ logger.error("Returned reference had no namespace!")
+ return FAIL
Same here.
+
+ logger.info("GetInstance(%s)" % systemref)
+ system = get_instance_by_ref(options.ip, systemref)
+
+ undefine_test_domain(default_dom, options.ip, virt=options.virt)
+
--
Kaitlin Rupert
IBM Linux Technology Center
kaitlin(a)linux.vnet.ibm.com
KR> You'll need to undefine the guest before the return
Whoops, I was thinking I handled all the cases by putting the undefine
where I did. Sorry about that (again). I'll send a replacement :)
--
Dan Smith
IBM Linux Technology Center
Open Hypervisor Team
email: danms(a)us.ibm.com