[PATCH] [TEST][Resubmitting: Addition] : Adding 02_reverse.py tc to verify ReferencedProfile

# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1207117559 -19800 # Node ID f3e2ef4edbb4ec299aaba8a9a6307e5b777a8712 # Parent 57b84aa20438fe7f8b7f2fa5e0098e30e2198745 [TEST][Resubmitting: Addition] : Adding 02_reverse.py tc to verify ReferencedProfile. Removed the check_len() function and included the logic to check the len of assoc, list in the same file. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r 57b84aa20438 -r f3e2ef4edbb4 suites/libvirt-cim/cimtest/ReferencedProfile/02_reverse.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/suites/libvirt-cim/cimtest/ReferencedProfile/02_reverse.py Wed Apr 02 11:55:59 2008 +0530 @@ -0,0 +1,172 @@ +#!/usr/bin/python +# +# Copyright 2008 IBM Corp. +# +# Authors: +# Deepti B. Kalakeri <deeptik@linux.vnet.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 +# +# The following test case is used to verify the ReferencedProfile supported +# by the VSM providers. +# +# Command: +# ------- +# +# wbemcli ai -ac Xen_ReferencedProfile 'http://localhost:5988/root/interop: +# Xen_RegisteredProfile.InstanceID="CIM:DSP1042-SystemVirtualization-1.0.0"' +# +# Output: +# ------- +# localhost:5988/root/interop:Xen_RegisteredProfile.InstanceID="CIM:DSP1057-VirtualSystem-1.0.0a" +# -InstanceID="CIM:DSP1057-VirtualSystem-1.0.0a" +# -RegisteredOrganization=2 +# -RegisteredName="Virtual System Profile" +# -RegisteredVersion="1.0.0a" +# +# localhost:5988/root/interop:Xen_RegisteredProfile. +# InstanceID="CIM:DSP1059-GenericDeviceResourceVirtualization-1.0.0" +# ..... +# localhost:5988/root/interop:Xen_RegisteredProfile. +# InstanceID="CIM:DSP1045-MemoryResourceVirtualization-1.0.0" +# ...... +# localhost:5988/root/interop:Xen_RegisteredProfile. +# InstanceID="CIM:DSP1081-VirtualSystemMigration-1.0" +# ...... +# Date : 31-03-2008 +import sys +from XenKvmLib.assoc import Associators +from CimTest import Globals +from CimTest.Globals import log_param, logger, CIM_ERROR_ASSOCIATORS +from CimTest.Globals import do_main +from XenKvmLib.classes import get_typed_class +from CimTest.ReturnCodes import FAIL, PASS + +sup_types = ['Xen', 'KVM', 'XenFV'] + + +def init_list(): + vs_prof = { + "InstanceID" : "CIM:DSP1057-VirtualSystem-1.0.0a", + "RegisteredOrganization" : 2, + "RegisteredName" : "Virtual System Profile", + "RegisteredVersion" : "1.0.0a" + } + gen_dev_prof = { + "InstanceID" : + "CIM:DSP1059-GenericDeviceResourceVirtualization-1.0.0", + "RegisteredOrganization" : 2, + "RegisteredName" : "Generic Device Resource Virtualization", + "RegisteredVersion" : "1.0.0" + } + mem_res_prof = { + "InstanceID" : "CIM:DSP1045-MemoryResourceVirtualization-1.0.0", + "RegisteredOrganization" : 2, + "RegisteredName" : "Memory Resource Virtualization", + "RegisteredVersion" : "1.0.0" + } + vs_mig_prof = { + "InstanceID" : "CIM:DSP1081-VirtualSystemMigration-1.0", + "RegisteredOrganization" : 2, + "RegisteredName" : "Virtual System Migration", + "RegisteredVersion" : "1.0" + } + + return vs_prof, gen_dev_prof, mem_res_prof, vs_mig_prof + +def print_field_error(fieldname, ret_value, exp_value): + logger.error("%s Mismatch", fieldname) + logger.error("Returned '%s' instead of '%s'", ret_value, exp_value) + + +def verify_fields(assoc_info, prof_info): + if assoc_info['InstanceID'] != prof_info['InstanceID']: + print_field_error('InstanceID', assoc_info['InstanceID'], prof_info['InstanceID']) + return FAIL + if assoc_info['RegisteredOrganization'] != prof_info['RegisteredOrganization']: + print_field_error('RegisteredOrganization', assoc_info['RegisteredOrganization'], \ + prof_info['RegisteredOrganization']) + return FAIL + if assoc_info['RegisteredName'] != prof_info['RegisteredName']: + print_field_error('RegisteredName', assoc_info['RegisteredName'], \ + prof_info['RegisteredName']) + return FAIL + if assoc_info['RegisteredVersion'] != prof_info['RegisteredVersion']: + print_field_error('RegisteredVersion', assoc_info['RegisteredVersion'], \ + prof_info['RegisteredVersion']) + return FAIL + return PASS + + +def verify_ref_assoc_info(assoc_info): + status = PASS + vs_prof, gen_dev_prof, mem_res_prof, vs_mig_prof = init_list() + for i in range(len(assoc_info)): + instid = assoc_info[i]['InstanceID'] + if instid.find("DSP1045") >=0 : + status = verify_fields(assoc_info[i], mem_res_prof) + elif instid.find("DSP1057") >=0 : + status = verify_fields(assoc_info[i], vs_prof) + elif instid.find("DSP1059") >=0 : + status = verify_fields(assoc_info[i], gen_dev_prof) + elif instid.find("DSP1081") >=0 : + status = verify_fields(assoc_info[i], vs_mig_prof) + else: + status = FAIL + if status != PASS: + break + return status + +def get_refprof_verify_info(): + assoc_info = [] + status = PASS + assoc_name = get_typed_class(virt, 'ReferencedProfile') + instid = "CIM:DSP1042-SystemVirtualization-1.0.0" + try: + assoc_info = Associators(server, assoc_name, reg_classname, virt, InstanceID = instid, + CreationClassName = reg_classname) + if len(assoc_info) < 4: + logger.error("%s returned %i %s objects, expected atleast 4", + assoc_name, len(assoc_info), 'Profile') + status = FAIL + + if status != PASS: + return status + status = verify_ref_assoc_info(assoc_info) + except Exception, detail: + logger.error(CIM_ERROR_ASSOCIATORS, assoc_name) + logger.error("Exception: %s", detail) + status = FAIL + return status + +@do_main(sup_types) +def main(): + log_param() + options = main.options + global virt, server, reg_classname + virt = options.virt + server = options.ip + status = PASS + prev_namespace = Globals.CIM_NS + Globals.CIM_NS = 'root/interop' + + reg_classname = get_typed_class(virt, 'RegisteredProfile') + status = get_refprof_verify_info() + + Globals.CIM_NS = prev_namespace + return status + +if __name__ == "__main__": + sys.exit(main())

DK> +def verify_fields(assoc_info, prof_info): DK> + if assoc_info['InstanceID'] != prof_info['InstanceID']: DK> + print_field_error('InstanceID', assoc_info['InstanceID'], prof_info['InstanceID']) DK> + return FAIL DK> + if assoc_info['RegisteredOrganization'] != prof_info['RegisteredOrganization']: DK> + print_field_error('RegisteredOrganization', assoc_info['RegisteredOrganization'], \ DK> + prof_info['RegisteredOrganization']) DK> + return FAIL DK> + if assoc_info['RegisteredName'] != prof_info['RegisteredName']: DK> + print_field_error('RegisteredName', assoc_info['RegisteredName'], \ DK> + prof_info['RegisteredName']) DK> + return FAIL DK> + if assoc_info['RegisteredVersion'] != prof_info['RegisteredVersion']: DK> + print_field_error('RegisteredVersion', assoc_info['RegisteredVersion'], \ DK> + prof_info['RegisteredVersion']) DK> + return FAIL DK> + return PASS Same comment as before for this as well. DK> +def verify_ref_assoc_info(assoc_info): DK> + status = PASS DK> + vs_prof, gen_dev_prof, mem_res_prof, vs_mig_prof = init_list() DK> + for i in range(len(assoc_info)): Please use the following syntax for for loops (unless you really need the index): for i in assoc_info: DK> + instid = assoc_info[i]['InstanceID'] DK> + if instid.find("DSP1045") >=0 : DK> + status = verify_fields(assoc_info[i], mem_res_prof) DK> + elif instid.find("DSP1057") >=0 : DK> + status = verify_fields(assoc_info[i], vs_prof) DK> + elif instid.find("DSP1059") >=0 : DK> + status = verify_fields(assoc_info[i], gen_dev_prof) DK> + elif instid.find("DSP1081") >=0 : DK> + status = verify_fields(assoc_info[i], vs_mig_prof) DK> + else: DK> + status = FAIL DK> + if status != PASS: DK> + break DK> + return status In the interest of making this more extensible in the future, why not embed the information you need in the profile information dictionary in some way to avoid this sort of static structure? Assuming the dict has a "profnum" field: profiles = init_list() for i in assoc_info: status = None for profile in profiles: if profile["profnum"] in i['InstanceID']: status = verify_fields(i, profile) break if status == FAIL: break You may need to rearrange your profile dict a little to make the key properties distinct from other bits, but the result will be that when we add a new supported profile, you can just add an entry to the top-level list of profiles and not have to modify lots of other bits in the code. Most of your other tests can probably be modified in this way as well, which leads me to ask: Why not define a single set of profiles in a common file and import them? That way, all of the profile tests will work against a single set of profiles, which I think makes a lot more sense. DK> +def get_refprof_verify_info(): DK> + assoc_info = [] DK> + status = PASS DK> + assoc_name = get_typed_class(virt, 'ReferencedProfile') DK> + instid = "CIM:DSP1042-SystemVirtualization-1.0.0" DK> + try: DK> + assoc_info = Associators(server, assoc_name, reg_classname, virt, InstanceID = instid, DK> + CreationClassName = reg_classname) DK> + if len(assoc_info) < 4: DK> + logger.error("%s returned %i %s objects, expected atleast 4", DK> + assoc_name, len(assoc_info), 'Profile') DK> + status = FAIL DK> + DK> + if status != PASS: DK> + return status DK> + status = verify_ref_assoc_info(assoc_info) DK> + except Exception, detail: DK> + logger.error(CIM_ERROR_ASSOCIATORS, assoc_name) DK> + logger.error("Exception: %s", detail) DK> + status = FAIL DK> + return status Perhaps you can explain the need for the repeated special case distinction for this profile? -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

Hi Dan, Please see my replies inline. Thanks and Regards, Deepti. Dan Smith wrote:
DK> +def verify_fields(assoc_info, prof_info): DK> + if assoc_info['InstanceID'] != prof_info['InstanceID']: DK> + print_field_error('InstanceID', assoc_info['InstanceID'], prof_info['InstanceID']) DK> + return FAIL DK> + if assoc_info['RegisteredOrganization'] != prof_info['RegisteredOrganization']: DK> + print_field_error('RegisteredOrganization', assoc_info['RegisteredOrganization'], \ DK> + prof_info['RegisteredOrganization']) DK> + return FAIL DK> + if assoc_info['RegisteredName'] != prof_info['RegisteredName']: DK> + print_field_error('RegisteredName', assoc_info['RegisteredName'], \ DK> + prof_info['RegisteredName']) DK> + return FAIL DK> + if assoc_info['RegisteredVersion'] != prof_info['RegisteredVersion']: DK> + print_field_error('RegisteredVersion', assoc_info['RegisteredVersion'], \ DK> + prof_info['RegisteredVersion']) DK> + return FAIL DK> + return PASS
Same comment as before for this as well.
Changed this.
DK> +def verify_ref_assoc_info(assoc_info): DK> + status = PASS DK> + vs_prof, gen_dev_prof, mem_res_prof, vs_mig_prof = init_list() DK> + for i in range(len(assoc_info)):
Please use the following syntax for for loops (unless you really need the index):
for i in assoc_info:
Done.
DK> + instid = assoc_info[i]['InstanceID'] DK> + if instid.find("DSP1045") >=0 : DK> + status = verify_fields(assoc_info[i], mem_res_prof) DK> + elif instid.find("DSP1057") >=0 : DK> + status = verify_fields(assoc_info[i], vs_prof) DK> + elif instid.find("DSP1059") >=0 : DK> + status = verify_fields(assoc_info[i], gen_dev_prof) DK> + elif instid.find("DSP1081") >=0 : DK> + status = verify_fields(assoc_info[i], vs_mig_prof) DK> + else: DK> + status = FAIL DK> + if status != PASS: DK> + break DK> + return status
In the interest of making this more extensible in the future, why not embed the information you need in the profile information dictionary in some way to avoid this sort of static structure? Assuming the dict has a "profnum" field:
Done.
profiles = init_list() for i in assoc_info: status = None for profile in profiles: if profile["profnum"] in i['InstanceID']: status = verify_fields(i, profile) break if status == FAIL: break
You may need to rearrange your profile dict a little to make the key properties distinct from other bits, but the result will be that when we add a new supported profile, you can just add an entry to the top-level list of profiles and not have to modify lots of other bits in the code.
Most of your other tests can probably be modified in this way as well, which leads me to ask: Why not define a single set of profiles in a common file and import them? That way, all of the profile tests will work against a single set of profiles, which I think makes a lot more sense.
Done.
DK> +def get_refprof_verify_info(): DK> + assoc_info = [] DK> + status = PASS DK> + assoc_name = get_typed_class(virt, 'ReferencedProfile') DK> + instid = "CIM:DSP1042-SystemVirtualization-1.0.0" DK> + try: DK> + assoc_info = Associators(server, assoc_name, reg_classname, virt, InstanceID = instid, DK> + CreationClassName = reg_classname) DK> + if len(assoc_info) < 4: DK> + logger.error("%s returned %i %s objects, expected atleast 4", DK> + assoc_name, len(assoc_info), 'Profile') DK> + status = FAIL DK> + DK> + if status != PASS: DK> + return status DK> + status = verify_ref_assoc_info(assoc_info) DK> + except Exception, detail: DK> + logger.error(CIM_ERROR_ASSOCIATORS, assoc_name) DK> + logger.error("Exception: %s", detail) DK> + status = FAIL DK> + return status
Perhaps you can explain the need for the repeated special case distinction for this profile?
Merged in this with the other tc.
------------------------------------------------------------------------
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
participants (3)
-
Dan Smith
-
Deepti B Kalakeri
-
Deepti B. Kalakeri