# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1229639710 28800
# Node ID a77720f03c87b82c2357f621f962bebc7c00327d
# Parent bac8c62509fa9e94ba8983826ed300b4f946b65f
[TEST] Remove try_getinstance() from Memory - 03_mem_gi_errs.py
try_getinstance() is no longer needed - this function can be implemented using
functions from enumclass.py. Plus, a conn needs to be passed to the function,
which is poor function design.
Removed the "invalid_instid_keyname" case - passing an invalid keyname only
tests the CIMOM, it does not test the providers.
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r bac8c62509fa -r a77720f03c87 suites/libvirt-cim/cimtest/Memory/03_mem_gi_errs.py
--- a/suites/libvirt-cim/cimtest/Memory/03_mem_gi_errs.py Thu Dec 18 00:51:43 2008 -0800
+++ b/suites/libvirt-cim/cimtest/Memory/03_mem_gi_errs.py Thu Dec 18 14:35:10 2008 -0800
@@ -20,196 +20,118 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-# Test Case Info:
-# --------------
-# This tc is used to verify if appropriate exceptions are
-# returned by Xen_Memory on giving invalid inputs.
#
-# 1) Test by passing Invalid CCName Keyname
# Input:
# ------
-# wbemcli gi 'http://localhost:5988/root/virt:Xen_Memory.\
-#
wrong="Xen_Memory",DeviceID="Domain-0/mem",SystemCreationClassName=\
-# "Xen_ComputerSystem",SystemName="Domain-0"' -nl
+# DeviceID
+# SystemCreationClassName
+# SystemName
+# CreationClassName
+#
+# Format:
+# ------
+# wbemcli gi 'http://localhost:5988/root/virt:KVM_Memory.DeviceID="wrong",
+# SystemCreationClassName="KVM_ComputerSystem", SystemName="guest",
+# CreationClassName="KVM_Memory"'
#
# Output:
# -------
# error code : CIM_ERR_NOT_FOUND
-# error desc : "No such instance (CreationClassName)"
-
-# 2) Test by passing Invalid CCName Keyvalue
-# Input:
-# ------
-# wbemcli gi 'http://localhost:5988/root/virt:Xen_Memory.\
-#
CreationClassName="wrong",DeviceID="Domain-0/mem",SystemCreationClassName=\
-# "Xen_ComputerSystem",SystemName="Domain-0"' -nl
+# error desc : "No such instance (DeviceID)" (this varies by key)
#
-# Output:
-# -------
-# error code : CIM_ERR_NOT_FOUND
-# error desc : "No such instance (CreationClassName)"
-
-# 3) Test by passing Invalid DevId Keyname
-# Input:
-# ------
-# wbemcli gi 'http://localhost:5988/root/virt:Xen_Memory.\
-#
CreationClassName="Xen_Memory",wrong="Domain-0/mem",SystemCreationClassName=\
-# "Xen_ComputerSystem",SystemName="Domain-0"' -nl
-#
-# Output:
-# -------
-# error code : CIM_ERR_FAILED
-# error desc : "No DeviceID specified"
-
-# 4) Test by passing Invalid DevId Keyvalue
-# ------
-# wbemcli gi 'http://localhost:5988/root/virt:Xen_Memory.\
-#
CreationClassName="Xen_Memory",DeviceID="wrong",SystemCreationClassName=\
-# "Xen_ComputerSystem",SystemName="Domain-0"' -nl
-#
-# Output:
-# -------
-# error code : CIM_ERR_NOT_FOUND
-# error desc : "No such instance (wrong)"
-
-# 5) Test by passing Invalid SCCName Keyname
-# Input:
-# ------
-# wbemcli gi 'http://localhost:5988/root/virt:Xen_Memory.\
-# CreationClassName="Xen_Memory",DeviceID="Domain-0/mem",wrong=\
-# "Xen_ComputerSystem",SystemName="Domain-0"' -nl
-#
-# Output:
-# -------
-# error code : CIM_ERR_NOT_FOUND
-# error desc : "No such instance (SystemCreationClassName)"
-
-# 6) Test by passing Invalid SCCName Keyvalue
-# Input:
-# ------
-# wbemcli gi 'http://localhost:5988/root/virt:Xen_Memory.\
-#
CreationClassName="Xen_Memory",DeviceID="Domain-0/mem",SystemCreationClassName=\
-# "wrong",SystemName="Domain-0"' -nl
-#
-# Output:
-# -------
-# error code : CIM_ERR_NOT_FOUND
-# error desc : "No such instance (SystemCreationClassName)"
-
-# 7) Test by passing Invalid SysName Keyname
-# Input:
-# ------
-# wbemcli gi 'http://localhost:5988/root/virt:Xen_Memory.\
-#
CreationClassName="Xen_Memory",DeviceID="Domain-0/mem",SystemCreationClassName=\
-# "Xen_ComputerSystem",wrong="Domain-0"' -nl
-#
-# Output:
-# -------
-# error code : CIM_ERR_NOT_FOUND
-# error desc : "No such instance (SystemName)"
-
-# 8) Test by passing Invalid SysName Keyvalue# Input:
-# Input:
-# ------
-# wbemcli gi 'http://localhost:5988/root/virt:Xen_Memory.\
-#
CreationClassName="Xen_Memory",DeviceID="Domain-0/mem",SystemCreationClassName=\
-# "Xen_ComputerSystem",SystemName="wrong"' -nl
-#
-# Output:
-# -------
-# error code : CIM_ERR_NOT_FOUND
-# error desc : "No such instance (SystemName)"
-# -Date 26.02.2008
import sys
-import pywbem
-from VirtLib import utils
-from XenKvmLib import assoc
-from XenKvmLib.common_util import try_getinstance
-from XenKvmLib.test_doms import destroy_and_undefine_all
-from XenKvmLib.vxml import XenXML, KVMXML, get_class
-from XenKvmLib.classes import get_typed_class
+from pywbem import CIM_ERR_NOT_FOUND, CIMError
+from pywbem.cim_obj import CIMInstanceName
from CimTest.ReturnCodes import PASS, FAIL
from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS
+from XenKvmLib.vxml import get_class
+from XenKvmLib.classes import get_typed_class
from XenKvmLib.const import do_main
+from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass, EnumInstances
sup_types = ['Xen', 'KVM', 'XenFV', 'LXC']
-expr_values = {
- "invalid_ccname" : {'rc' : pywbem.CIM_ERR_NOT_FOUND, \
- 'desc' : "No such instance" }, \
- "invalid_devid_keyname" : {'rc' : pywbem.CIM_ERR_FAILED, \
- 'desc' : "No DeviceID specified" }, \
- "invalid_devid_keyvalue" : {'rc' : pywbem.CIM_ERR_NOT_FOUND, \
- 'desc' : "No such instance" }, \
- "invalid_sccname" : {'rc' : pywbem.CIM_ERR_NOT_FOUND, \
- 'desc' : "No such instance" }, \
- "invalid_sysname" : {'rc' : pywbem.CIM_ERR_NOT_FOUND, \
- 'desc' : "No such instance" }
- }
+def get_mem_inst(virt, ip, cn, guest_name):
+ try:
+ enum_list = EnumInstances(ip, cn)
-test_dom = "domU"
-test_mem = 256 #MB
+ if enum_list < 1:
+ logger.error("No %s instances returned", cn)
+ return None, FAIL
-def try_invalid_gi(i, field1, field2):
- j = 0
- keys = {}
- temp = name_val[i]
- name_val[i] = field1
- for j in range(len(name_val)/2):
- k = j * 2
- keys[name_val[k]] = name_val[k+1]
+ for inst in enum_list:
+ if inst.SystemName == guest_name:
+ return inst, PASS
- ret_value = try_getinstance(conn, classname, keys, field_name=field1, \
- expr_values=expr_values[field2], bug_no="")
- if ret_value != PASS:
- logger.error("------ FAILED: %s------" % field1)
- name_val[i] = temp
- return ret_value
+ except Exception, details:
+ logger.error(details)
+
+ return None, FAIL
@do_main(sup_types)
def main():
options = main.options
- devid = "%s/%s" % (test_dom, test_mem)
- status = PASS
+ test_dom = "domU"
+ test_mem = 256 #MB
- # Getting the VS list and deleting the test_dom if it already exists.
- destroy_and_undefine_all(options.ip)
vsxml = get_class(options.virt)(test_dom, test_mem)
ret = vsxml.cim_define(options.ip)
if not ret:
logger.error("Failed to Create the dom: %s", test_dom)
return FAIL
- global conn
- conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS),
CIM_NS)
- global classname
- global name_val
- classname = get_typed_class(options.virt, "Memory")
- name_val = [
- 'CreationClassName', classname, \
- 'DeviceID', devid, \
- 'SystemCreationClassName', get_typed_class(options.virt,
'ComputerSystem'), \
- 'SystemName', test_dom
- ]
+ expr_values = {
+ 'rc' : CIM_ERR_NOT_FOUND,
+ 'desc' : 'No such instance'
+ }
- tc_scen = { 'INVALID_CCName_Keyname' : 'invalid_ccname', \
- 'INVALID_CCName_Keyvalue' : 'invalid_ccname', \
- 'INVALID_DevID_Keyname' : 'invalid_devid_keyname', \
- 'INVALID_DevID_Keyvalue' : 'invalid_devid_keyvalue', \
- 'INVALID_SCCName_Keyname' : 'invalid_sccname', \
- 'INVALID_SCCName_Keyvalue' : 'invalid_sccname', \
- 'INVALID_SysName_Keyname' : 'invalid_sysname', \
- 'INVALID_SysName_Keyvalue' : 'invalid_sysname'
+ cn = get_typed_class(options.virt, "Memory")
+
+ mem, status = get_mem_inst(options.virt, options.ip, cn, test_dom)
+ if status != PASS:
+ vsxml.undefine(options.ip)
+ return status
+
+ key_vals = { 'SystemName' : mem.SystemName,
+ 'CreationClassName' : mem.CreationClassName,
+ 'SystemCreationClassName' : mem.SystemCreationClassName,
+ 'DeviceID' : mem.DeviceID
+ }
+
+ tc_scen = {
+ 'invalid_sysval' : 'SystemName',
+ 'invalid_ccname' : 'CreationClassName',
+ 'invalid_sccname' : 'SystemCreationClassName',
+ 'invalid_devid' : 'DeviceID',
}
- i = 0
- for field1, field2 in sorted(tc_scen.items()):
- retval = try_invalid_gi(i, field1, field2)
- if retval != PASS:
- status = retval
- i = i + 1
+ for tc, field in tc_scen.iteritems():
+ status = FAIL
+
+ keys = key_vals.copy()
+ keys[field] = tc
+
+ ref = CIMInstanceName(cn, keybindings=keys)
+
+ try:
+ inst = CIM_CimtestClass(options.ip, ref)
+
+ except CIMError, (err_no, err_desc):
+ exp_rc = expr_values['rc']
+ exp_desc = expr_values['desc']
+
+ if err_no == exp_rc and err_desc.find(exp_desc) >= 0:
+ logger.info("Got expected exception: %s %s", exp_desc, exp_rc)
+ status = PASS
+ else:
+ logger.error("Unexpected errno %s, desc %s", err_no, err_desc)
+ logger.error("Expected %s %s", exp_desc, exp_rc)
+
+ if status != PASS:
+ logger.error("------ FAILED: %s ------", tc)
+ break
vsxml.undefine(options.ip)
return status