[PATCH] [TEST][Resubmitting: Addition] : Adding 01_forward.py tc to verify ReferencedProfile

# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1207117030 -19800 # Node ID 57b84aa20438fe7f8b7f2fa5e0098e30e2198745 # Parent e2cd9e869996152255adcf54e4c4e38331fcf760 [TEST][Resubmitting: Addition] : Adding 01_forward.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 e2cd9e869996 -r 57b84aa20438 suites/libvirt-cim/cimtest/ReferencedProfile/01_forward.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/suites/libvirt-cim/cimtest/ReferencedProfile/01_forward.py Wed Apr 02 11:47:10 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 provider. +# +#Ex Command: +#----------- +# wbemcli ain -ac Xen_ReferencedProfile 'http://localhost:5988/root/interop: +# Xen_RegisteredProfile.InstanceID="CIM:DSP1057-VirtualSystem-1.0.0a"' +# +# wbemcli ain -ac Xen_ReferencedProfile 'http://localhost:5988/root/interop: +# Xen_RegisteredProfile.InstanceID="CIM:DSP1059-GenericDeviceResourceVirtualization-1.0.0"' +# +# wbemcli ain -ac Xen_ReferencedProfile 'http://localhost:5988/root/interop: +# Xen_RegisteredProfile.InstanceID="CIM:DSP1045-MemoryResourceVirtualization-1.0.0"' +# +# wbemcli ain -ac Xen_ReferencedProfile 'http://localhost:5988/root/interop: +# Xen_RegisteredProfile.InstanceID="CIM:DSP1081-VirtualSystemMigration-1.0"' +# +# Output: +# ------- +# All the above examples have the following as result. +# +# localhost:5988/root/interop:Xen_RegisteredProfile. +# InstanceID="CIM:DSP1042-SystemVirtualization-1.0.0" +# ...... +# InstanceID="CIM:DSP1042-SystemVirtualization-1.0.0" +# RegisteredOrganization=2 +# RegisteredName="System Virtualization" +# RegisteredVersion="1.0.0" +# .... +# +# Date : 31-03-2008 +import sys +from XenKvmLib import enumclass +from XenKvmLib.assoc import Associators +from CimTest import Globals +from CimTest.Globals import log_param, logger, CIM_ERROR_ENUMERATE, 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(): + sys_prof_info = { + "InstanceID" : "CIM:DSP1042-SystemVirtualization-1.0.0", + "RegisteredOrganization" : 2, + "RegisteredName" : "System Virtualization", + "RegisteredVersion" : "1.0.0" + } + return sys_prof_info + +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 get_proflist(): + proflist = [] + status = PASS + try: + key_list = ["InstanceID"] + proflist = enumclass.enumerate(server, eval('enumclass.' + reg_classname), key_list, virt) + if len(proflist) < 5 : + logger.error("%s returned %i %s objects, expected atleast 5", + reg_classname, len(proflist), 'Profile') + status = FAIL + + except Exception, detail: + logger.error(CIM_ERROR_ENUMERATE, reg_classname) + logger.error("Exception: %s", detail) + status = FAIL + + if status != PASS: + return status, proflist + + profiles_instid_list = [] + for profile in proflist: + if not ("DSP1042" in profile.InstanceID): + profiles_instid_list.append(profile.InstanceID) + + return status, profiles_instid_list + +def verify_ref_assoc_info(assoc_info, sys_prof_info): + if assoc_info['InstanceID'] != sys_prof_info['InstanceID']: + print_field_error('InstanceID', assoc_info['InstanceID'], sys_prof_info['InstanceID']) + return FAIL + if assoc_info['RegisteredOrganization'] != sys_prof_info['RegisteredOrganization']: + print_field_error('RegisteredOrganization', assoc_info['RegisteredOrganization'], + sys_prof_info['RegisteredOrganization']) + return FAIL + if assoc_info['RegisteredName'] != sys_prof_info['RegisteredName']: + print_field_error('RegisteredName', assoc_info['RegisteredName'], + sys_prof_info['RegisteredName']) + return FAIL + if assoc_info['RegisteredVersion'] != sys_prof_info['RegisteredVersion']: + print_field_error('RegisteredVersion', assoc_info['RegisteredVersion'], + sys_prof_info['RegisteredVersion']) + return FAIL + return PASS + + + +def get_refprof_verify_info(proflist): + assoc_info = [] + status = PASS + assoc_name = get_typed_class(virt, 'ReferencedProfile') + sys_prof_info = init_list() + for instid in proflist: + try: + assoc_info = Associators(server, assoc_name, reg_classname, virt, InstanceID = instid, + CreationClassName = reg_classname) + if len(assoc_info) != 1: + logger.error("%s returned %i %s objects, expected only 1", + assoc_name, len(assoc_info), 'SystemVirtualization') + status = FAIL + if status != PASS: + break + + status = verify_ref_assoc_info(assoc_info[0], sys_prof_info) + if status != PASS: + break + + 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, proflist = get_proflist() + if status != PASS : + Globals.CIM_NS = prev_namespace + return status + + status = get_refprof_verify_info(proflist) + Globals.CIM_NS = prev_namespace + return status + +if __name__ == "__main__": + sys.exit(main())

DK> # HG changeset patch DK> # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> DK> # Date 1207117030 -19800 DK> # Node ID 57b84aa20438fe7f8b7f2fa5e0098e30e2198745 DK> # Parent e2cd9e869996152255adcf54e4c4e38331fcf760 DK> [TEST][Resubmitting: Addition] : Adding 01_forward.py tc to verify ReferencedProfile. This one ran fine when I tried it, but I have some comments. DK> + try: DK> + key_list = ["InstanceID"] DK> + proflist = enumclass.enumerate(server, eval('enumclass.' + reg_classname), key_list, virt) Doesn't enumclass.enumerate take a classname? We should avoid eval()'ing all over the place for no reason. DK> + if len(proflist) < 5 : This will break when we add one more profile. Please make sure this is >0 and then check that the proper profiles are returned somewhere else. DK> + profiles_instid_list = [] DK> + for profile in proflist: DK> + if not ("DSP1042" in profile.InstanceID): DK> + profiles_instid_list.append(profile.InstanceID) This is randomly filtering out DSP1042? Why? DK> +def verify_ref_assoc_info(assoc_info, sys_prof_info): DK> + if assoc_info['InstanceID'] != sys_prof_info['InstanceID']: DK> + print_field_error('InstanceID', assoc_info['InstanceID'], sys_prof_info['InstanceID']) DK> + return FAIL DK> + if assoc_info['RegisteredOrganization'] != sys_prof_info['RegisteredOrganization']: DK> + print_field_error('RegisteredOrganization', assoc_info['RegisteredOrganization'], DK> + sys_prof_info['RegisteredOrganization']) DK> + return FAIL DK> + if assoc_info['RegisteredName'] != sys_prof_info['RegisteredName']: DK> + print_field_error('RegisteredName', assoc_info['RegisteredName'], DK> + sys_prof_info['RegisteredName']) DK> + return FAIL DK> + if assoc_info['RegisteredVersion'] != sys_prof_info['RegisteredVersion']: DK> + print_field_error('RegisteredVersion', assoc_info['RegisteredVersion'], DK> + sys_prof_info['RegisteredVersion']) DK> + return FAIL DK> + return PASS The entire blob above can be replaced with this: for f in ["RegisteredOrganization", "RegisteredName", "RegisteredVersion"]: if assoc_info[f] != sys_prof_info[f]: print_field_error(f, assoc_info[f], sys_prof_info[f]) return FAIL return PASS Thanks! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

Hi Dan, Please see my comments inline. Thanks and Regards, Deepti. Dan Smith wrote:
DK> # HG changeset patch DK> # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> DK> # Date 1207117030 -19800 DK> # Node ID 57b84aa20438fe7f8b7f2fa5e0098e30e2198745 DK> # Parent e2cd9e869996152255adcf54e4c4e38331fcf760 DK> [TEST][Resubmitting: Addition] : Adding 01_forward.py tc to verify ReferencedProfile.
This one ran fine when I tried it, but I have some comments.
DK> + try: DK> + key_list = ["InstanceID"] DK> + proflist = enumclass.enumerate(server, eval('enumclass.' + reg_classname), key_list, virt)
Doesn't enumclass.enumerate take a classname? We should avoid eval()'ing all over the place for no reason.
DK> + if len(proflist) < 5 :
This will break when we add one more profile. Please make sure this is >0 and then check that the proper profiles are returned somewhere else. Well, if we add a new profile later then the len(proflist) will be 6 and
yes it does, I have changed this. the condition (6<5) will still hold good. Also, by explicitly verifying the len to be 5 makes sure that we dont get anything less than the previously implemented profiles.
DK> + profiles_instid_list = [] DK> + for profile in proflist: DK> + if not ("DSP1042" in profile.InstanceID): DK> + profiles_instid_list.append(profile.InstanceID)
This is randomly filtering out DSP1042? Why? Changed this. DK> +def verify_ref_assoc_info(assoc_info, sys_prof_info): DK> + if assoc_info['InstanceID'] != sys_prof_info['InstanceID']: DK> + print_field_error('InstanceID', assoc_info['InstanceID'], sys_prof_info['InstanceID']) DK> + return FAIL DK> + if assoc_info['RegisteredOrganization'] != sys_prof_info['RegisteredOrganization']: DK> + print_field_error('RegisteredOrganization', assoc_info['RegisteredOrganization'], DK> + sys_prof_info['RegisteredOrganization']) DK> + return FAIL DK> + if assoc_info['RegisteredName'] != sys_prof_info['RegisteredName']: DK> + print_field_error('RegisteredName', assoc_info['RegisteredName'], DK> + sys_prof_info['RegisteredName']) DK> + return FAIL DK> + if assoc_info['RegisteredVersion'] != sys_prof_info['RegisteredVersion']: DK> + print_field_error('RegisteredVersion', assoc_info['RegisteredVersion'], DK> + sys_prof_info['RegisteredVersion']) DK> + return FAIL DK> + return PASS
The entire blob above can be replaced with this:
for f in ["RegisteredOrganization", "RegisteredName", "RegisteredVersion"]: if assoc_info[f] != sys_prof_info[f]: print_field_error(f, assoc_info[f], sys_prof_info[f]) return FAIL return PASS
This is better way, thanks I used this :).
Thanks!
------------------------------------------------------------------------
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim

DK> Well, if we add a new profile later then the len(proflist) will be DK> 6 and the condition (6<5) will still hold good. Also, by DK> explicitly verifying the len to be 5 makes sure that we dont get DK> anything less than the previously implemented profiles. Okay, that's fair :) DK> This is better way, thanks I used this :). Cool, thanks! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com
participants (3)
-
Dan Smith
-
Deepti B Kalakeri
-
Deepti B. Kalakeri