[PATCH 0 of 8] [TEST] Rework negative tc to not use try_getinstance()

try_getinstance() really isn't needed anymore as the same functionality can be achieved using the functions in enumclass.py. Removing try_getinstance() requires essentially a re-write of these tests - they're old, so updates are needed anyway. More test re-writes will follow in the next set.

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229039337 28800 # Node ID 2870da2286667b1ed71b859facd4d19acdbd3ed4 # Parent 040d16411dd72073f932f2c64d30fe205ebc1647 [TEST] Remove try_getinstance() from VSMC - 02_vsmcap_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@us.ibm.com> diff -r 040d16411dd7 -r 2870da228666 suites/libvirt-cim/cimtest/VirtualSystemManagementCapabilities/02_vsmcap_gi_errs.py --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementCapabilities/02_vsmcap_gi_errs.py Thu Dec 11 15:48:57 2008 -0800 +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementCapabilities/02_vsmcap_gi_errs.py Thu Dec 11 15:48:57 2008 -0800 @@ -22,8 +22,9 @@ # # Test Case Info: # -------------- -# This tc is used to verify if appropriate exceptions are -# returned by Xen_VirtualSystemManagementCapabilities on giving invalid inputs. +# This tc is used to verify if appropriate exceptions are returned by +# VirtualSystemManagementCapabilities' GetInstance call when specifying +# invalid inputs. # # 1) Test by passing Invalid InstanceID Key Value # Input: @@ -36,66 +37,51 @@ # error code : CIM_ERR_NOT_FOUND # error desc : "No such instance (InstanceID)" # -# 2) Test by giving Invalid InstanceID Key Name -# Input: -# ------ -# wbemcli gi http://localhost:5988/root/virt:\ -# Xen_VirtualSystemManagementCapabilities.Wrong="ManagementCapabilities" -nl -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (InstanceID)" -# -Date 22.02.2008 import sys -import pywbem -from VirtLib import utils -from XenKvmLib import assoc -from optparse import OptionParser -from XenKvmLib.common_util import try_getinstance +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 from XenKvmLib.classes import get_typed_class -from CimTest.ReturnCodes import PASS, FAIL -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS from XenKvmLib.const import do_main +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass sup_types=['Xen', 'KVM', 'XenFV', 'LXC'] - -expr_values = { - "invalid_instid_keyname" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : "No such instance (InstanceID)" }, \ - "invalid_instid_keyvalue" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : "No such instance (InstanceID)" } - } - @do_main(sup_types) def main(): options = main.options - status = PASS - classname = get_typed_class(options.virt, 'VirtualSystemManagementCapabilities') + cn = get_typed_class(options.virt, 'VirtualSystemManagementCapabilities') - conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS) + expr_values = { + 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "No such instance (InstanceID)" + } - # 1) Test by passing Invalid InstanceID Key Value - field = 'INVALID_Instid_KeyValue' - keys = { 'InstanceID' : field } - ret_value = try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_instid_keyvalue'], bug_no="") - if ret_value != PASS: + keys = { 'InstanceID' : 'INVALID_Instid_KeyValue' } + + ref = CIMInstanceName(cn, keybindings=keys) + + status = FAIL + 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 and desc %s", err_no, err_desc) + logger.error("Got %s %s", err_desc, err_no) + status = FAIL + + if status != PASS: logger.error("------ FAILED: Invalid InstanceID Key Value.------") - status = ret_value - - # 2) Test by giving Invalid InstanceID Key Name - field = 'INVALID_Instid_KeyName' - inst_id = "ManagementCapabilities" - keys = { field : inst_id } - ret_value = try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_instid_keyname'], bug_no="") - if ret_value != PASS: - logger.error("------ FAILED: Invalid InstanceID Key Name.------") - status = ret_value return status

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229040244 28800 # Node ID 6a9478ad87fac97af5689f6a4a86f165c6c569bf # Parent 2870da2286667b1ed71b859facd4d19acdbd3ed4 [TEST] Remove try_getinstance() from VSSD - 03_vssd_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@us.ibm.com> diff -r 2870da228666 -r 6a9478ad87fa suites/libvirt-cim/cimtest/VSSD/03_vssd_gi_errs.py --- a/suites/libvirt-cim/cimtest/VSSD/03_vssd_gi_errs.py Thu Dec 11 15:48:57 2008 -0800 +++ b/suites/libvirt-cim/cimtest/VSSD/03_vssd_gi_errs.py Thu Dec 11 16:04:04 2008 -0800 @@ -35,79 +35,58 @@ # error code : CIM_ERR_NOT_FOUND # error desc : "No such instance (InstanceID)" -# 2) Test by passing Invalid InstID Keyvalue -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:\ -# Xen_VirtualSystemSettingData.InstanceID="INVALID_InstID_Keyval"' -nl -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (InstanceID)" -# -# Date: 06-03-2008 - import sys -import pywbem +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 from XenKvmLib.const import do_main -from CimTest.Globals import CIM_PASS, CIM_NS, CIM_USER, logger -from XenKvmLib import assoc from XenKvmLib.vxml import get_class -from XenKvmLib.common_util import try_getinstance -from XenKvmLib.test_doms import destroy_and_undefine_all +from XenKvmLib.classes import get_typed_class +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass platform_sup = ['Xen', 'KVM', 'XenFV', 'LXC'] test_dom = "VSSD_domain" -expr_values = { - "INVALID_InstID_Keyname" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance (InstanceID)' }, \ - "INVALID_InstID_Keyval" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance (InstanceID)'} -} - -def try_invalid_gi(VSType, name_val, i, field): - classname = "%s_VirtualSystemSettingData" % VSType - keys = {} - temp = name_val[i] - name_val[i] = field - for j in range(len(name_val)/2): - k = j * 2 - keys[name_val[k]] = name_val[k+1] - ret_val = try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values[field], bug_no="") - if ret_val != PASS: - logger.error("------ FAILED: %s ------", field) - name_val[i] = temp - return ret_val - @do_main(platform_sup) def main(): options = main.options - status = PASS - if options.virt == 'XenFV': - VSType = 'Xen' - else: - VSType = options.virt + vsxml = get_class(options.virt)(test_dom) ret = vsxml.cim_define(options.ip) if not ret : logger.error("error while define of VS") return FAIL - global conn - conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS) + cn = get_typed_class(options.virt, 'VirtualSystemManagementCapabilities') - inst_id = "%s:%s" % (VSType, test_dom) - name_val = ['InstanceID', inst_id] - tc_scen = ['INVALID_InstID_Keyname', 'INVALID_InstID_Keyval'] + expr_values = { + 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "No such instance (InstanceID)" + } - for i in range(len(tc_scen)): - retval = try_invalid_gi(VSType, name_val, i, tc_scen[i]) - if retval != PASS: - status = retval + keys = { 'InstanceID' : 'INVALID_Instid_KeyValue' } + + ref = CIMInstanceName(cn, keybindings=keys) + + status = FAIL + 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 and desc %s", err_no, err_desc) + logger.error("Got %s %s", err_desc, err_no) + status = FAIL + + if status != PASS: + logger.error("------ FAILED: Invalid InstanceID Key Value.------") vsxml.undefine(options.ip) return status

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229040254 28800 # Node ID 4110e478eef820e94aa0fceadad0382b0c66ccf2 # Parent 6a9478ad87fac97af5689f6a4a86f165c6c569bf [TEST] Remove try_getinstance() from VSSSC - 02_vs_sservicecap_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@us.ibm.com> diff -r 6a9478ad87fa -r 4110e478eef8 suites/libvirt-cim/cimtest/VirtualSystemSnapshotServiceCapabilities/02_vs_sservicecap_gi_errs.py --- a/suites/libvirt-cim/cimtest/VirtualSystemSnapshotServiceCapabilities/02_vs_sservicecap_gi_errs.py Thu Dec 11 16:04:04 2008 -0800 +++ b/suites/libvirt-cim/cimtest/VirtualSystemSnapshotServiceCapabilities/02_vs_sservicecap_gi_errs.py Thu Dec 11 16:04:14 2008 -0800 @@ -23,13 +23,8 @@ # -------------- # This tc is used to verify if appropriate exceptions are # returned by VirtualSystemSnapshotServiceCapabilities on giving invalid inputs. -# 1) Test by giving invalid Invalid InstanceID Key Name -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:\ -# KVM_VirtualSystemSnapshotServiceCapabilities.Wrong="SnapshotCapabilities"' -nl # -# 2) Test by passing Invalid InstanceID Key Value +# 1) Test by passing Invalid InstanceID Key Value # Input: # ------ # wbemcli gi 'http://localhost:5988/root/virt:\ @@ -41,50 +36,53 @@ # ------- # error code : CIM_ERR_NOT_FOUND # error desc : "No such instance (InstanceID)" -# -# Date: 25-03-2008 + import sys -import pywbem -from XenKvmLib import assoc -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS -from CimTest.ReturnCodes import PASS -from XenKvmLib.common_util import try_getinstance +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 from XenKvmLib.const import do_main from XenKvmLib.classes import get_typed_class +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] -expr_values = { - "invalid_instid" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance (InstanceID)' } - } -def verify_fields(): - classname = get_typed_class(options.virt, "VirtualSystemSnapshotServiceCapabilities") - return try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_instid'], bug_no="") @do_main(sup_types) def main(): - global options options = main.options - global conn - global keys - global field - conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS) + virt = options.virt - field = 'INVALID_Instid_KeyName' - keys = { field : "SnapshotCapabilities" } - status = verify_fields() + cn = get_typed_class(virt, 'VirtualSystemSnapshotServiceCapabilities') + + expr_values = { + 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "No such instance (InstanceID)" + } + + keys = { 'InstanceID' : 'INVALID_Instid_KeyValue' } + + ref = CIMInstanceName(cn, keybindings=keys) + + status = FAIL + 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 and desc %s", err_no, err_desc) + logger.error("Got %s %s", err_desc, err_no) + status = FAIL + if status != PASS: - logger.error("------ FAILED: to check INVALID_Instid_KeyName.------") - return status + logger.error("------ FAILED: Invalid InstanceID Key Value.------") - field = 'INVALID_Instid_KeyValue' - keys = { 'InstanceID' : field } - status = verify_fields() - if status != PASS: - logger.error("------ FAILED: to check INVALID_Instid_KeyValue.------") - return status - - return PASS + return status if __name__ == "__main__": sys.exit(main())

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229040389 28800 # Node ID 5657d8fc247e73e143e7ce82ee2de5aecd7e6d6d # Parent 4110e478eef820e94aa0fceadad0382b0c66ccf2 [TEST] Remove try_getinstance() from VSSS - 02_vs_sservice_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@us.ibm.com> diff -r 4110e478eef8 -r 5657d8fc247e suites/libvirt-cim/cimtest/VirtualSystemSnapshotService/02_vs_sservice_gi_errs.py --- a/suites/libvirt-cim/cimtest/VirtualSystemSnapshotService/02_vs_sservice_gi_errs.py Thu Dec 11 16:04:14 2008 -0800 +++ b/suites/libvirt-cim/cimtest/VirtualSystemSnapshotService/02_vs_sservice_gi_errs.py Thu Dec 11 16:06:29 2008 -0800 @@ -24,236 +24,113 @@ # This tc is used to verify if appropriate exceptions are # returned by VirtualSystemSnapshotService on giving invalid inputs. # -# Date: 24-03-2008 -import sys -import pywbem -from XenKvmLib import assoc -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS -from CimTest.ReturnCodes import PASS -from XenKvmLib.common_util import try_getinstance -from XenKvmLib.const import do_main -from XenKvmLib.classes import get_typed_class -from XenKvmLib.common_util import get_host_info - -sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] -expr_values = { - "INVALID_CCName" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance (CreationClassName)' }, \ - "INVALID_Name" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance (Name)' }, \ - "INVALID_SCCName" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance (SystemCreationClassName)'}, \ - "INVALID_SName" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance (SystemName)' }, - } - - -def verify_fields(keys): - classname = get_typed_class(options.virt, "VirtualSystemSnapshotService") - return try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values[field], bug_no="") - -def err_invalid_ccname(): -# 1) Test by giving invalid CreationClassName Key Name # Input: # ------ -# wbemcli gi 'http://localhost:5988/root/virt:KVM_VirtualSystemSnapshotService. \ -# Wrong="KVM_VirtualSystemSnapshotService",Name="SnapshotService",\ -# SystemCreationClassName="KVM_HostSystem",SystemName="mx3650a.in.ibm.com"' -nl -# -# 2) Test by passing Invalid CreationClassName Key Value -# Input: -# ------ +# Invalid values for the following: +# CreationClassName +# Name +# SystemCreationClassName +# SystemName +# +# Format: +# -------- # wbemcli gi 'http://localhost:5988/root/virt:KVM_VirtualSystemSnapshotService. \ # CreationClassName="Wrong",Name="SnapshotService",\ # SystemCreationClassName="KVM_HostSystem",SystemName="mx3650a.in.ibm.com"' -nl # -# Inboth the cases the following exception is verified. -# # Output: # ------- # error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (CreationClassName)" - keys = { field : ccn, \ - 'Name' : name, \ - 'SystemCreationClassName' : sccn, \ - 'SystemName' : sys_name - } - status = verify_fields(keys) - if status != PASS: - logger.error("------ FAILED: to check INVALID_CCName_KeyName.------") - return status - keys = { 'CreationClassName' : field, \ - 'Name' : name, \ - 'SystemCreationClassName' : sccn, \ - 'SystemName' : sys_name - } - status = verify_fields(keys) - if status != PASS: - logger.error("------ FAILED: to check INVALID_CCName_KeyValue.------") - return status - return PASS +# error desc : "No such instance (CreationClassName)" (varies by key name) -def err_invalid_name(): -# 1) Test by giving invalid Name Key Name -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:KVM_VirtualSystemSnapshotService. \ -# CreationClassName="KVM_VirtualSystemSnapshotService",Wrong="SnapshotService",\ -# SystemCreationClassName="KVM_HostSystem",SystemName="mx3650a.in.ibm.com"' -nl -# -# 2) Test by passing Invalid CreationClassName Key Value -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:KVM_VirtualSystemSnapshotService. \ -# CreationClassName="KVM_VirtualSystemSnapshotService",Name="Wrong",\ -# SystemCreationClassName="KVM_HostSystem",SystemName="mx3650a.in.ibm.com"' -nl -# -# Inboth the cases the following exception is verified. -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (Name)" -# - keys = { 'CreationClassName' : ccn, \ - field : name, \ - 'SystemCreationClassName' : sccn, \ - 'SystemName' : sys_name - } - status = verify_fields(keys) - if status != PASS: - logger.error("------ FAILED: to check INVALID_Name_KeyName.------") - return status - keys = { 'CreationClassName' : ccn, \ - 'Name' : field, \ - 'SystemCreationClassName' : sccn, \ - 'SystemName' : sys_name - } - status = verify_fields(keys) - if status != PASS: - logger.error("------ FAILED: to check INVALID_Name_KeyValue.------") - return status - return PASS +import sys +import pywbem +from pywbem import CIM_ERR_NOT_FOUND, CIMError +from pywbem.cim_obj import CIMInstanceName +from CimTest.Globals import logger +from CimTest.ReturnCodes import PASS, FAIL +from XenKvmLib.const import do_main +from XenKvmLib.classes import get_typed_class +from XenKvmLib.common_util import get_host_info +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass, EnumInstances -def err_invalid_sccname(): -# 1) Test by giving invalid SystemCreationClassName Key Name -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:KVM_VirtualSystemSnapshotService. \ -# CreationClassName="KVM_VirtualSystemSnapshotService",Name="SnapshotService",\ -# Wrong="KVM_HostSystem",SystemName="mx3650a.in.ibm.com"' -nl -# -# 2) Test by passing Invalid CreationClassName Key Value -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:KVM_VirtualSystemSnapshotService. \ -# CreationClassName="KVM_VirtualSystemSnapshotService",Name="SnapshotService",\ -# SystemCreationClassName="Wrong",SystemName="mx3650a.in.ibm.com"' -nl -# -# Inboth the cases the following exception is verified. -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (SystemCreationClassName)" -# - keys = { 'CreationClassName' : ccn, \ - 'Name' : name, \ - field : sccn, \ - 'SystemName' : sys_name - } - status = verify_fields(keys) - if status != PASS: - logger.error("------ FAILED: to check INVALID_SCCName_KeyName.------") - return status - keys = { 'CreationClassName' : ccn, \ - 'Name' : name, \ - 'SystemCreationClassName' : field, \ - 'SystemName' : sys_name - } - status = verify_fields(keys) - if status != PASS: - logger.error("------ FAILED: to check INVALID_SCCName_KeyValue.------") - return status - return PASS +sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] +expected_values = { + "invalid_ccname" : { 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : 'No such instance (CreationClassName)' }, + "invalid_sccname" : { 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : 'No such instance (SystemCreationClassName)' }, + "invalid_name" : { 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : 'No such instance (Name)'}, + "invalid_sysval" : { 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : 'No such instance (SystemName)' }, + } -def err_invalid_sname(): -# 1) Test by giving invalid SystemName Key Name -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:KVM_VirtualSystemSnapshotService. \ -# CreationClassName="KVM_VirtualSystemSnapshotService",Name="SnapshotService",\ -# SystemCreationClassName="KVM_HostSystem",Wrong="mx3650a.in.ibm.com"' -nl -# -# 2) Test by passing Invalid CreationClassName Key Value -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:KVM_VirtualSystemSnapshotService. \ -# CreationClassName="KVM_VirtualSystemSnapshotService",Name="SnapshotService",\ -# SystemCreationClassName="KVM_HostSystem",SystemName="Wrong"' -nl -# -# Inboth the cases the following exception is verified. -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (SystemName)" -# - keys = { 'CreationClassName' : ccn, \ - 'Name' : name, \ - 'SystemCreationClassName' : sccn, \ - field : sys_name - } - status = verify_fields(keys) - if status != PASS: - logger.error("------ FAILED: to check INVALID_SName_KeyName.------") - return status - keys = { 'CreationClassName' : ccn, \ - 'Name' : name, \ - 'SystemCreationClassName' : sccn, \ - 'SystemName' : field - } - status = verify_fields(keys) - if status != PASS: - logger.error("------ FAILED: to check INVALID_SName_KeyValue.------") - return status - return PASS +def get_vsss_inst(virt, ip, cn): + try: + enum_list = EnumInstances(ip, cn) + + if enum_list < 1: + logger.error("No %s instances returned", cn) + return None, FAIL + + return enum_list[0], PASS + + except Exception, details: + logger.error(details) + + return None, FAIL @do_main(sup_types) def main(): - global options options = main.options - global conn - global field - global ccn - global name, sys_name, sccn - conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS) + ccn = get_typed_class(options.virt, "VirtualSystemSnapshotService") - name = "SnapshotService" - status, host_inst = get_host_info(options.ip, options.virt) + + vsss, status = get_vsss_inst(options.virt, options.ip, ccn) if status != PASS: return status - - sccn = host_inst.CreationClassName - sys_name = host_inst.Name - field = 'INVALID_CCName' - status = err_invalid_ccname() - if status != PASS: - return status - field = 'INVALID_Name' - status = err_invalid_name() - if status != PASS: - return status - field = 'INVALID_SCCName' - status = err_invalid_sccname() - if status != PASS: - return status - field = 'INVALID_SName' - status = err_invalid_sname() - if status != PASS: - return status - return PASS + key_vals = { 'SystemName' : vsss.SystemName, + 'CreationClassName' : vsss.CreationClassName, + 'SystemCreationClassName' : vsss.SystemCreationClassName, + 'Name' : vsss.Name + } + + tc_scen = { + 'invalid_ccname' : 'CreationClassName', + 'invalid_sccname' : 'SystemCreationClassName', + 'invalid_name' : 'Name', + 'invalid_sysval' : 'SystemName', + } + + for tc, field in tc_scen.iteritems(): + status = FAIL + + keys = key_vals.copy() + keys[field] = tc + expr_values = expected_values[tc] + + ref = CIMInstanceName(ccn, 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("Got %s %s", err_desc, err_no) + + if status != PASS: + logger.error("------ FAILED: %s ------", tc) + break + + return status if __name__ == "__main__": sys.exit(main())

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229040425 28800 # Node ID 3bb307b122797cae2b3d3bb7c37f81fb8a50e0f9 # Parent 5657d8fc247e73e143e7ce82ee2de5aecd7e6d6d [TEST] Remove try_getinstance() from VSMSD - 02_vsmsd_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@us.ibm.com> diff -r 5657d8fc247e -r 3bb307b12279 suites/libvirt-cim/cimtest/VirtualSystemMigrationSettingData/02_vsmsd_gi_errs.py --- a/suites/libvirt-cim/cimtest/VirtualSystemMigrationSettingData/02_vsmsd_gi_errs.py Thu Dec 11 16:06:29 2008 -0800 +++ b/suites/libvirt-cim/cimtest/VirtualSystemMigrationSettingData/02_vsmsd_gi_errs.py Thu Dec 11 16:07:05 2008 -0800 @@ -23,69 +23,63 @@ # -------------- # This tc is used to verify if appropriate exceptions are # returned by Xen_VSMSD on giving invalid inputs. -# 1) Test by giving invalid Invalid InstanceID Key Name -# Input: -# ------ -# wbemcli gi http://localhost:5988/root/virt:\ -# Xen_VirtualSystemMigrationSettingData.Wrong="MigrationSettingData" -nl # -# 2) Test by passing Invalid InstanceID Key Value +# 1) Test by passing Invalid InstanceID Key Value # Input: # ------ # wbemcli gi http://localhost:5988/root/virt:\ # Xen_VirtualSystemMigrationSettingData.InstanceID="Wrong" -nl -# -# Inboth the cases the following exception is verified. # # Output: # ------- # error code : CIM_ERR_NOT_FOUND # error desc : "No such instance (InstanceID)" # -# Date: 06-03-2008 + import sys -import pywbem -from XenKvmLib import assoc -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS -from CimTest.ReturnCodes import PASS -from XenKvmLib.common_util import try_getinstance +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 from XenKvmLib.const import do_main from XenKvmLib.classes import get_typed_class +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass platform_sup = ['Xen', 'XenFV', 'KVM', 'LXC'] -expr_values = { - "invalid_instid" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance (InstanceID)' } - } -def verify_fields(): - classname = get_typed_class(options.virt, "VirtualSystemMigrationSettingData") - return try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_instid'], bug_no="") - - @do_main(platform_sup) def main(): - global options options = main.options - global conn - global keys - global field - conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS) - field = 'INVALID_Instid_KeyName' - keys = { field : "MigrationSettingData" } - status = verify_fields() + expr_values = { + 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : 'No such instance (InstanceID)' + } + + cn = get_typed_class(options.virt, 'VirtualSystemMigrationSettingData') + + keys = { 'InstanceID' : 'INVALID_Instid_KeyValue' } + + ref = CIMInstanceName(cn, keybindings=keys) + + status = FAIL + 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 and desc %s", err_no, err_desc) + logger.error("Got %s %s", err_desc, err_no) + status = FAIL + if status != PASS: - logger.error("------ FAILED: to check INVALID_Instid_KeyName.------") - return status - - field = 'INVALID_Instid_KeyValue' - keys = { 'InstanceID' : field } - status = verify_fields() - if status != PASS: - logger.error("------ FAILED: to check INVALID_Instid_KeyValue.------") - return status + logger.error("------ FAILED: Invalid InstanceID Key Value.------") return PASS if __name__ == "__main__":

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229040425 28800 # Node ID 3bb307b122797cae2b3d3bb7c37f81fb8a50e0f9 # Parent 5657d8fc247e73e143e7ce82ee2de5aecd7e6d6d [TEST] Remove try_getinstance() from VSMSD - 02_vsmsd_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
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@us.ibm.com>
diff -r 5657d8fc247e -r 3bb307b12279 suites/libvirt- cim/cimtest/VirtualSystemMigrationSettingData/02_vsmsd_gi_errs.py --- a/suites/libvirt- cim/cimtest/VirtualSystemMigrationSettingData/02_vsmsd_gi_errs.py Thu Dec 11 16:06:29 2008 -0800 +++ b/suites/libvirt- cim/cimtest/VirtualSystemMigrationSettingData/02_vsmsd_gi_errs.py Thu Dec 11 16:07:05 2008 -0800 @@ -23,69 +23,63 @@ # -------------- # This tc is used to verify if appropriate exceptions are # returned by Xen_VSMSD on giving invalid inputs. -# 1) Test by giving invalid Invalid InstanceID Key Name -# Input: -# ------ -# wbemcli gi http://localhost:5988/root/virt:\ -# Xen_VirtualSystemMigrationSettingData.Wrong="MigrationSettingData" -nl # -# 2) Test by passing Invalid InstanceID Key Value +# 1) Test by passing Invalid InstanceID Key Value # Input: # ------ # wbemcli gi http://localhost:5988/root/virt:\ # Xen_VirtualSystemMigrationSettingData.InstanceID="Wrong" -nl -# -# Inboth the cases the following exception is verified. # # Output: # ------- # error code : CIM_ERR_NOT_FOUND # error desc : "No such instance (InstanceID)" # -# Date: 06-03-2008 + import sys -import pywbem -from XenKvmLib import assoc -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS -from CimTest.ReturnCodes import PASS -from XenKvmLib.common_util import try_getinstance +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 from XenKvmLib.const import do_main from XenKvmLib.classes import get_typed_class +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass
platform_sup = ['Xen', 'XenFV', 'KVM', 'LXC']
-expr_values = { - "invalid_instid" : { 'rc' :
libvirt-cim-bounces@redhat.com wrote on 2008-12-12 08:20:49: thefunction, pywbem.CIM_ERR_NOT_FOUND, \
- 'desc' : 'No such instance (InstanceID)' } - } -def verify_fields(): - classname = get_typed_class(options.virt, "VirtualSystemMigrationSettingData") - return try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_instid'], bug_no="") - - @do_main(platform_sup) def main(): - global options options = main.options - global conn - global keys - global field - conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS)
- field = 'INVALID_Instid_KeyName' - keys = { field : "MigrationSettingData" } - status = verify_fields() + expr_values = { + 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : 'No such instance (InstanceID)' + } + + cn = get_typed_class(options.virt, 'VirtualSystemMigrationSettingData') + + keys = { 'InstanceID' : 'INVALID_Instid_KeyValue' } + + ref = CIMInstanceName(cn, keybindings=keys) + + status = FAIL + 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 and desc %s", err_no,err_desc) + logger.error("Got %s %s", err_desc, err_no) + status = FAIL + if status != PASS: - logger.error("------ FAILED: to check INVALID_Instid_KeyName.------") - return status - - field = 'INVALID_Instid_KeyValue' - keys = { 'InstanceID' : field } - status = verify_fields() - if status != PASS: - logger.error("------ FAILED: to check INVALID_Instid_KeyValue.------") - return status + logger.error("------ FAILED: Invalid InstanceID Key Value.------")
It's better to return FAIL after logger.error above, otherwise, we have to return status instead of PASS below. Others looks fine for me.
return PASS if __name__ == "__main__":
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim

- return status + logger.error("------ FAILED: Invalid InstanceID Key Value.------")
It's better to return FAIL after logger.error above, otherwise, we have to return status instead of PASS below. Others looks fine for me.
Oops! Yes, this should be a "return status" not a "return FAIL". Thanks for catching this! I'll resubmit =) -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229040450 28800 # Node ID c141460650d74a4f5d34ae7193c357c301c0896e # Parent 3bb307b122797cae2b3d3bb7c37f81fb8a50e0f9 [TEST] Remove try_getinstance() from VSMigC - 02_vsmc_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@us.ibm.com> diff -r 3bb307b12279 -r c141460650d7 suites/libvirt-cim/cimtest/VirtualSystemMigrationCapabilities/02_vsmc_gi_errs.py --- a/suites/libvirt-cim/cimtest/VirtualSystemMigrationCapabilities/02_vsmc_gi_errs.py Thu Dec 11 16:07:05 2008 -0800 +++ b/suites/libvirt-cim/cimtest/VirtualSystemMigrationCapabilities/02_vsmc_gi_errs.py Thu Dec 11 16:07:30 2008 -0800 @@ -23,67 +23,63 @@ # Test Case Info: # -------------- # This tc is used to verify if appropriate exceptions are -# returned by Xen_VSMC on giving invalid inputs. -# 1) Test by giving invalid Invalid InstanceID Key Name -# Input: -# ------ -# wbemcli gi http://localhost:5988/root/virt:\ -# Xen_VirtualSystemMigrationCapabilities.Wrong="RPCC" -nl +# returned by VirtualSystemMigrationCapabilities on giving invalid inputs. # -# 2) Test by passing Invalid InstanceID Key Value +# 1) Test by passing Invalid InstanceID Key Value # Input: # ------ # wbemcli gi http://localhost:5988/root/virt:\ # Xen_VirtualSystemMigrationCapabilities.InstanceID="Wrong" -nl # -# Inboth the cases the following exception is verified. -# # Output: # ------- # error code : CIM_ERR_NOT_FOUND # error desc : "No such instance (InstanceID)" -# -# -Date 20.02.2008 import sys -import pywbem -from XenKvmLib import assoc -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS +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 from XenKvmLib.const import do_main -from CimTest.ReturnCodes import PASS, FAIL -from XenKvmLib.common_util import try_getinstance from XenKvmLib.classes import get_typed_class +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass sup_types = ['Xen', 'XenFV', 'KVM', 'LXC'] - -expr_values = { - "invalid_instid" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance (InstanceID)' } - } @do_main(sup_types) def main(): options = main.options - status = PASS - conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS) - classname = get_typed_class(options.virt, 'VirtualSystemMigrationCapabilities') + cn = get_typed_class(options.virt, 'VirtualSystemMigrationCapabilities') - field = 'INVALID_Instid_KeyName' - keys = { field : "RPCC" } - ret_value = try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_instid'], bug_no="") - if ret_value != PASS: - logger.error("------ FAILED: Invalid InstanceID Key Name.------") - status = ret_value + expr_values = { + 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "No such instance (InstanceID)" + } - field = 'INVALID_Instid_KeyValue' - keys = { 'InstanceID' : field } - ret_value = try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_instid'], bug_no="") - if ret_value != PASS: + keys = { 'InstanceID' : 'INVALID_Instid_KeyValue' } + + ref = CIMInstanceName(cn, keybindings=keys) + + status = FAIL + 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 and desc %s", err_no, err_desc) + logger.error("Got %s %s", err_desc, err_no) + status = FAIL + + if status != PASS: logger.error("------ FAILED: Invalid InstanceID Key Value.------") - status = ret_value return status if __name__ == "__main__":

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229041204 28800 # Node ID c6c43892a8b9dd0fa801406b5fac2eed45e5c246 # Parent c141460650d74a4f5d34ae7193c357c301c0896e [TEST] Remove try_getinstance() from RPCS - 02_rcps_gi_errors.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@us.ibm.com> diff -r c141460650d7 -r c6c43892a8b9 suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/02_rcps_gi_errors.py --- a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/02_rcps_gi_errors.py Thu Dec 11 16:07:30 2008 -0800 +++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/02_rcps_gi_errors.py Thu Dec 11 16:20:04 2008 -0800 @@ -20,272 +20,117 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # This tc is used to verify if appropriate exceptions are -# returned by Xen_RCPS on giving invalid inputs. +# returned by ResourcePoolConfigurationService on giving invalid inputs. # -# -# Date : 17-02-2008 - -import sys -import pywbem -from CimTest.ReturnCodes import PASS -from XenKvmLib import assoc -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS -from XenKvmLib.common_util import get_host_info, try_getinstance -from XenKvmLib.const import do_main -from XenKvmLib.classes import get_typed_class - -platform_sup = ['Xen', 'KVM', 'XenFV', 'LXC'] -expr_values = { - "invalid_sysname" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance (SystemName)' }, \ - "invalid_sccname" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance \ -(SystemCreationClassName)' }, \ - "invalid_name" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance (Name)' }, \ - "invalid_ccname" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance (CreationClassName)'} - } - - - -def err_invalid_ccname_keyname(conn, classname, hostname, sccname, field): -# Input: +# Input values for the following keys: +# ------------------------------------ +# CreationClassName +# Name +# SystemCreationClassName +# SystemName +# +# Format # ------ # wbemcli gi 'http://localhost:5988/root/virt:\ -# Xen_ResourcePoolConfigurationService.Wrong="Xen_ResourcePoolConfigurationService"\ -# ,Name="RPCS",SystemCreationClassName="Xen_HostSystem",SystemName="mx3650a.in.ibm.com"' -# +# Xen_ResourcePoolConfigurationService.CreationClassName="Wrong",\ +# Name="RPCS",SystemCreationClassName="Xen_HostSystem",\ +# SystemName="mx3650a.in.ibm.com"' +# # Output: # ------- # error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (CreationClassName)" +# error desc : "No such instance (CreationClassName)" (varies by key name) # - keys = { - field : classname, \ - 'Name' : 'RPCS', \ - 'SystemCreationClassName' : sccname, \ - 'SystemName' : hostname - } - return try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_ccname'], bug_no="") -def err_invalid_ccname_keyvalue(conn, classname, hostname, sccname, field): -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:\ -# Xen_ResourcePoolConfigurationService.CreationClassName="Wrong",\ -# Name="RPCS",SystemCreationClassName="Xen_HostSystem",SystemName="mx3650a.in.ibm.com"' -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (CreationClassName)" -# - keys = { - 'CreationClassName' : field, \ - 'Name' : 'RPCS', \ - 'SystemCreationClassName' : sccname, \ - 'SystemName' : hostname - } - return try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_ccname'], bug_no="") +import sys +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 +from XenKvmLib.const import do_main +from XenKvmLib.classes import get_typed_class +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass, EnumInstances -def err_invalid_name_keyname(conn, classname, hostname, sccname, field): -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:\ -# Xen_ResourcePoolConfigurationService.CreationClassName=\ -# "Xen_ResourcePoolConfigurationService",Wrong="RCPS",\ -# SystemCreationClassName="Xen_HostSystem",SystemName="mx3650a.in.ibm.com"' -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (Name)" -# - keys = { - 'CreationClassName' : classname, \ - field : 'RPCS', \ - 'SystemCreationClassName' : sccname, \ - 'SystemName' : hostname - } - return try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_name'], bug_no="") +platform_sup = ['Xen', 'KVM', 'XenFV', 'LXC'] +expected_values = { + "invalid_ccname" : { 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : 'No such instance (CreationClassName)' }, + "invalid_sccname" : { 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : 'No such instance (SystemCreationClassName)' }, + "invalid_name" : { 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : 'No such instance (Name)'}, + "invalid_sysval" : { 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : 'No such instance (SystemName)' }, + } -def err_invalid_name_keyvalue(conn, classname, hostname, sccname, field): -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:\ -# Xen_ResourcePoolConfigurationService.CreationClassName=\ -# "Xen_ResourcePoolConfigurationService",Name="Wrong",\ -# SystemCreationClassName="Xen_HostSystem",SystemName="mx3650a.in.ibm.com"' -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (Name)" -# - keys = { - 'CreationClassName' : classname, \ - 'Name' : field, \ - 'SystemCreationClassName' : sccname, \ - 'SystemName' : hostname - } - return try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_name'], bug_no="") +def get_rpcs_inst(virt, ip, cn): + try: + enum_list = EnumInstances(ip, cn) + if len(enum_list) != 1: + logger.error("No %s instances returned", cn) + return None, FAIL -def err_invalid_sccname_keyname(conn, classname, hostname, sccname, field): -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:\ -# Xen_ResourcePoolConfigurationService.CreationClassName=\ -# "Xen_ResourcePoolConfigurationService",Name="RPCS",\ -# Wrong="Xen_HostSystem",SystemName="mx3650a.in.ibm.com"' -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (SystemCreationClassName)" -# - keys = { - 'CreationClassName' : classname, \ - 'Name' : 'RPCS', \ - field : sccname, \ - 'SystemName' : hostname - } - return try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_sccname'], - bug_no="") + return enum_list[0], PASS -def err_invalid_sccname_keyvalue(conn, classname, hostname, field): -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:\ -# Xen_ResourcePoolConfigurationService.CreationClassName=\ -# "Xen_ResourcePoolConfigurationService",Name="RPCS",\ -# SystemCreationClassName="Wrong",SystemName="mx3650a.in.ibm.com"' -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (SystemCreationClassName)" -# - keys = { - 'CreationClassName' : classname, \ - 'Name' : 'RPCS', \ - 'SystemCreationClassName' : field, \ - 'SystemName' : hostname - } - return try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_sccname'], - bug_no="") + except Exception, details: + logger.error(details) -def err_invalid_sysname_keyname(conn, classname, hostname, sccname, field): -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:\ -# Xen_ResourcePoolConfigurationService.CreationClassName=\ -# "Xen_ResourcePoolConfigurationService",Name="RPCS",\ -# SystemCreationClassName="Xen_HostSystem",Wrong="mx3650a.in.ibm.com"' -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (SystemName)" -# - keys = { - 'CreationClassName' : classname, \ - 'Name' : 'RPCS', \ - 'SystemCreationClassName' : sccname, \ - field : hostname - } - return try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_sysname'], - bug_no="") - -def err_invalid_sysname_keyvalue(conn, classname, sccname, field): -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:\ -# Xen_ResourcePoolConfigurationService.CreationClassName=\ -# "Xen_ResourcePoolConfigurationService",Name="RPCS",\ -# SystemCreationClassName="Xen_HostSystem",SystemName="Wrong"' -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (SystemName)" -# - keys = { - 'CreationClassName' : classname, \ - 'Name' : 'RPCS', \ - 'SystemCreationClassName' : sccname, \ - 'SystemName' : field - } - return try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_sysname'], - bug_no="") - + return None, FAIL @do_main(platform_sup) def main(): options = main.options - status = PASS server = options.ip - conn = assoc.myWBEMConnection('http://%s' % options.ip, - (CIM_USER, CIM_PASS), CIM_NS) virt = options.virt - status, host_inst = get_host_info(server, virt) + + cn = get_typed_class(virt, 'ResourcePoolConfigurationService') + + rpcs, status = get_rpcs_inst(options.virt, options.ip, cn) if status != PASS: - logger.error("Problem getting host information") return status - sccname = host_inst.CreationClassName - hostname = host_inst.Name + key_vals = { 'SystemName' : rpcs.SystemName, + 'CreationClassName' : rpcs.CreationClassName, + 'SystemCreationClassName' : rpcs.SystemCreationClassName, + 'Name' : rpcs.Name + } - classname = get_typed_class(virt, 'ResourcePoolConfigurationService') - ret_value = err_invalid_ccname_keyname(conn, classname, hostname, sccname, \ - field='INVALID_CCName_KeyName') - if ret_value != PASS: - logger.error("------ FAILED: Invalid CCName Key Name.------") - status = ret_value - ret_value = err_invalid_ccname_keyvalue(conn, classname, hostname, sccname, \ - field='INVALID_CCName_KeyValue') - if ret_value != PASS: - logger.error("------ FAILED: Invalid CCName Key Value.------") - status = ret_value - ret_value = err_invalid_name_keyname(conn, classname, hostname, sccname, \ - field='INVALID_Name_KeyName') - if ret_value != PASS: - logger.error("------ FAILED: Invalid Name Key Name.------") - status = ret_value - ret_value = err_invalid_name_keyvalue(conn, classname, hostname, sccname, \ - field='INVALID_CCName_KeyValue') - if ret_value != PASS: - logger.error("------ FAILED: Invalid Name Key Value.------") - status = ret_value - ret_value = err_invalid_sccname_keyname(conn, classname, hostname, sccname, - field='INVALID_Sys_CCName_KeyName') - if ret_value != PASS: - logger.error("------ FAILED: Invalid System CreationClassName Key Name.------") - status = ret_value - ret_value = err_invalid_sccname_keyvalue(conn, classname, hostname, \ - field='INVALID_Sys_CCName_KeyValue') - if ret_value != PASS: - logger.error("------ FAILED: Invalid System CreationClassName Key Value.------") - status = ret_value - ret_value = err_invalid_sysname_keyname(conn, classname, hostname, sccname, - field='INVALID_SysName_KeyName') - if ret_value != PASS: - logger.error("------ FAILED: Invalid SystemName Key Name.------") - status = ret_value - ret_value = err_invalid_sysname_keyvalue(conn, classname, sccname, \ - field='INVALID_SysName_KeyValue') - if ret_value != PASS: - logger.error("------ FAILED: Invalid SystemName Key Value.------") - status = ret_value + tc_scen = { + 'invalid_ccname' : 'CreationClassName', + 'invalid_sccname' : 'SystemCreationClassName', + 'invalid_name' : 'Name', + 'invalid_sysval' : 'SystemName', + } + + for tc, field in tc_scen.iteritems(): + status = FAIL + + keys = key_vals.copy() + keys[field] = tc + expr_values = expected_values[tc] + + ref = CIMInstanceName(cn, keybindings=keys) + + try: + inst = CIM_CimtestClass(server, 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("Got %s %s", err_desc, err_no) + + if status != PASS: + logger.error("------ FAILED: %s ------", tc) + break + return status if __name__ == "__main__": sys.exit(main())

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229041208 28800 # Node ID 8ade254f085ce279c4d3c14f9c419350f10b0a23 # Parent c6c43892a8b9dd0fa801406b5fac2eed45e5c246 [TEST] Remove try_getinstance() from RPCC - 02_rpcc_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@us.ibm.com> diff -r c6c43892a8b9 -r 8ade254f085c suites/libvirt-cim/cimtest/ResourcePoolConfigurationCapabilities/02_rpcc_gi_errs.py --- a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationCapabilities/02_rpcc_gi_errs.py Thu Dec 11 16:20:04 2008 -0800 +++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationCapabilities/02_rpcc_gi_errs.py Thu Dec 11 16:20:08 2008 -0800 @@ -24,19 +24,12 @@ # -------------- # This tc is used to verify if appropriate exceptions are # returned by Xen_RPCC on giving invalid inputs. -# 1) Test by giving invalid Invalid InstanceID Key Name -# Input: -# ------ -# wbemcli gi http://localhost:5988/root/virt:\ -# Xen_ResourcePoolConfigurationCapabilities.Wrong="RPCC" -nl # -# 2) Test by passing Invalid InstanceID Key Value +# 1) Test by passing Invalid InstanceID Key Value # Input: # ------ # wbemcli gi http://localhost:5988/root/virt:\ # Xen_ResourcePoolConfigurationCapabilities.InstanceID="Wrong" -nl -# -# Inboth the cases the following exception is verified. # # Output: # ------- @@ -46,43 +39,49 @@ # -Date 20.02.2008 import sys -import pywbem -from XenKvmLib import assoc +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 from XenKvmLib.classes import get_typed_class -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS from XenKvmLib.const import do_main -from CimTest.ReturnCodes import PASS, FAIL -from XenKvmLib.common_util import try_getinstance +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass sup_types = ['Xen', 'XenFV', 'KVM', 'LXC'] - -expr_values = { - "invalid_instid" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance (InstanceID)' } - } @do_main(sup_types) def main(): options = main.options - status = PASS - conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS) - classname = get_typed_class(options.virt, 'ResourcePoolConfigurationCapabilities') - field = 'INVALID_Instid_KeyName' - keys = { field : "RPCC" } - ret_value = try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_instid'], bug_no="") - if ret_value != PASS: - logger.error("------ FAILED: Invalid InstanceID Key Name.------") - status = ret_value + cn = get_typed_class(options.virt, 'ResourcePoolConfigurationCapabilities') - field = 'INVALID_Instid_KeyValue' - keys = { 'InstanceID' : field } - ret_value = try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_instid'], bug_no="") - if ret_value != PASS: + expr_values = { + 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "No such instance (InstanceID)" + } + + keys = { 'InstanceID' : 'INVALID_Instid_KeyValue' } + + ref = CIMInstanceName(cn, keybindings=keys) + + status = FAIL + 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 and desc %s", err_no, err_desc) + logger.error("Got %s %s", err_desc, err_no) + status = FAIL + + if status != PASS: logger.error("------ FAILED: Invalid InstanceID Key Value.------") - status = ret_value return status if __name__ == "__main__":
participants (2)
-
Guo Lian Yun
-
Kaitlin Rupert