[PATCH 0 of 3] [TEST] Added new tc to verify RPCS DeleteResourceInPool()

This patchset is dependent on the "Added new tc to verify RPCS error values." changes The patches should be applied on top of "Added new tc to verify RPCS error values" pathces

# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1252412311 25200 # Node ID 4c9b50a928295e90904b2f560334cd2c398808af # Parent 465cfe3802c691e2315dc47eb07790df6c96fb77 [TEST] Adding get_diskpool() to pool.py Added get_diskpool() definition to pool.py as this will be referenced by RPCS/10*py, RPCS/11*py and RPCS/12*py. Tested with KVM and current sources on SLES11. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r 465cfe3802c6 -r 4c9b50a92829 suites/libvirt-cim/lib/XenKvmLib/pool.py --- a/suites/libvirt-cim/lib/XenKvmLib/pool.py Tue Sep 08 00:20:01 2009 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/pool.py Tue Sep 08 05:18:31 2009 -0700 @@ -25,7 +25,7 @@ from CimTest.ReturnCodes import PASS, FAIL, SKIP from XenKvmLib.classes import get_typed_class, inst_to_mof from XenKvmLib.const import get_provider_version, default_pool_name -from XenKvmLib.enumclass import EnumInstances, GetInstance +from XenKvmLib.enumclass import EnumInstances, GetInstance, EnumNames from XenKvmLib.assoc import Associators from VirtLib.utils import run_remote from XenKvmLib.xm_virt_util import virt2uri, net_list @@ -40,6 +40,7 @@ cim_mname = "CreateChildResourcePool" input_graphics_pool_rev = 757 libvirt_cim_child_pool_rev = 837 +libvirt_rasd_spool_del_changes = 971 DIR_POOL = 1L FS_POOL = 2L @@ -339,3 +340,16 @@ return None return dpool_rasd + +def get_diskpool(server, virt, dp_cn, pool_name): + dp_inst = None + dpool_cn = get_typed_class(virt, dp_cn) + pools = EnumNames(server, dpool_cn) + + dp_inst_id = "%s/%s" % (dp_cn, pool_name) + for pool in pools: + if pool['InstanceID'] == dp_inst_id: + dp_inst = pool + break + + return dp_inst

# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1252413103 25200 # Node ID c127b5047569b1a7fbb7e2a266e8e8fea71e762e # Parent 4c9b50a928295e90904b2f560334cd2c398808af [TEST] Add new tc to verify the DeleteResourceInPool(). Tested with KVM and current sources on SLES11. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r 4c9b50a92829 -r c127b5047569 suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/12_delete_storagevolume.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/12_delete_storagevolume.py Tue Sep 08 05:31:43 2009 -0700 @@ -0,0 +1,177 @@ +#!/usr/bin/python +# +# Copyright 2009 IBM Corp. +# +# Authors: +# Deepti B. Kalakeri<dkalaker@in.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 +# +# +# This test case verifies the deletion of the StorageVol using the +# DeleteResourceInPool method of RPCS. +# +# -Date: 08-09-2009 + +import sys +import os +from VirtLib import utils +from CimTest.Globals import logger +from CimTest.ReturnCodes import FAIL, PASS, SKIP +from XenKvmLib.xm_virt_util import virsh_version +from XenKvmLib.const import do_main, platform_sup, default_pool_name, \ + get_provider_version +from XenKvmLib import rpcs_service +from XenKvmLib.assoc import Associators +from XenKvmLib.enumclass import GetInstance, EnumNames +from XenKvmLib.classes import get_typed_class, inst_to_mof +from XenKvmLib.common_util import destroy_diskpool +from XenKvmLib.pool import create_pool, undefine_diskpool, DIR_POOL, \ + libvirt_rasd_spool_del_changes, get_diskpool, \ + get_stovol_default_settings, \ + get_stovol_rasd_from_sdc + +pool_attr = { 'Path' : "/tmp" } +vol_name = "cimtest-vol.img" + +def get_sto_vol_rasd(virt, server, dp_cn, pool_name, exp_vol_path): + dv_rasds = None + dp_inst_id = "%s/%s" % (dp_cn, pool_name) + status, rasds = get_stovol_rasd_from_sdc(virt, server, dp_inst_id) + if status != PASS: + logger.error("Failed to get the StorageVol for '%s' vol", exp_vol_path) + return FAIL + + for item in rasds: + if item['Address'] == exp_vol_path and item['PoolID'] == dp_inst_id: + dv_rasds = item + break + + return dv_rasds + +def cleanup_pool_vol(server, virt, pool_name, clean_vol, exp_vol_path): + try: + if clean_vol == True: + status = destroy_diskpool(server, virt, pool_name) + if status != PASS: + raise Exception("Unable to destroy diskpool '%s'" % pool_name) + else: + status = undefine_diskpool(server, virt, pool_name) + if status != PASS: + raise Exception("Unable to undefine diskpool '%s'" \ + % pool_name) + if os.path.exists(exp_vol_path): + cmd = "rm -rf %s" % exp_vol_path + ret, out = utils.run_remote(server, cmd) + if ret != 0: + raise Exception("'%s' was not removed, please remove it " \ + "manually" % exp_vol_path) + except Exception, details: + logger.error("Exception details: %s", details) + return FAIL + + return PASS + + +@do_main(platform_sup) +def main(): + options = main.options + server = options.ip + virt = options.virt + + libvirt_ver = virsh_version(server, virt) + cim_rev, changeset = get_provider_version(virt, server) + if libvirt_ver < "0.4.1" and cim_rev < libvirt_rasd_spool_del_changes: + logger.info("Storage Volume deletion support is available with Libvirt" + "version >= 0.4.1 and Libvirt-CIM rev '%s'", + libvirt_rasd_spool_del_changes) + return SKIP + + dp_cn = "DiskPool" + exp_vol_path = "%s/%s" % (pool_attr['Path'], vol_name) + + # For now the test case support only the deletion of dir type based + # vol, we can extend dp_types to include netfs etc ..... + dp_types = { "DISK_POOL_DIR" : DIR_POOL } + + for pool_name, pool_type in dp_types.iteritems(): + status = FAIL + res = del_res = [FAIL] + clean_pool=True + try: + if pool_type == DIR_POOL: + pool_name = default_pool_name + clean_pool=False + else: + status = create_pool(server, virt, pool_name, pool_attr, + mode_type=pool_type, pool_type=dp_cn) + + if status != PASS: + logger.error("Failed to create pool '%s'", pool_name) + return status + + sv_rasd = get_stovol_default_settings(virt, server, dp_cn, pool_name, + exp_vol_path, vol_name) + if sv_rasd == None: + raise Exception("Failed to get the defualt StorageVolRASD info") + + sv_settings = inst_to_mof(sv_rasd) + + dp_inst = get_diskpool(server, virt, dp_cn, pool_name) + if dp_inst == None: + raise Exception("DiskPool instance for '%s' not found!" \ + % pool_name) + + rpcs = get_typed_class(virt, "ResourcePoolConfigurationService") + rpcs_conn = eval("rpcs_service." + rpcs)(server) + res = rpcs_conn.CreateResourceInPool(Settings=sv_settings, + Pool=dp_inst) + if res[0] != PASS: + raise Exception("Failed to create the Vol %s" % vol_name) + + res_settings = get_sto_vol_rasd(virt, server, dp_cn, + pool_name, exp_vol_path) + if res_settings == None: + raise Exception("Failed to get the resource settings for '%s'" \ + " Vol" % vol_name) + + resource_setting = inst_to_mof(res_settings) + del_res = rpcs_conn.DeleteResourceInPool(Resource=resource_setting, + Pool=dp_inst) + + res_settings = get_sto_vol_rasd(virt, server, dp_cn, + pool_name, exp_vol_path) + if res_settings != None: + raise Exception("'%s' vol of '%s' pool was not deleted" \ + % (vol_name, pool_name)) + else: + logger.info("Vol '%s' of '%s' pool deleted successfully by " + "DeleteResourceInPool()", vol_name, pool_name) + + except Exception, details: + logger.error("Exception details: %s", details) + status = FAIL + + ret = cleanup_pool_vol(server, virt, pool_name, + clean_pool, exp_vol_path) + if del_res[0] == PASS and ret == PASS : + status = PASS + else: + return FAIL + + return status +if __name__ == "__main__": + sys.exit(main())

+@do_main(platform_sup) +def main(): + options = main.options + server = options.ip + virt = options.virt + + libvirt_ver = virsh_version(server, virt) + cim_rev, changeset = get_provider_version(virt, server) + if libvirt_ver < "0.4.1" and cim_rev < libvirt_rasd_spool_del_changes: + logger.info("Storage Volume deletion support is available with Libvirt" + "version >= 0.4.1 and Libvirt-CIM rev '%s'", + libvirt_rasd_spool_del_changes) + return SKIP + + dp_cn = "DiskPool" + exp_vol_path = "%s/%s" % (pool_attr['Path'], vol_name) + + # For now the test case support only the deletion of dir type based + # vol, we can extend dp_types to include netfs etc ..... + dp_types = { "DISK_POOL_DIR" : DIR_POOL } + + for pool_name, pool_type in dp_types.iteritems(): + status = FAIL + res = del_res = [FAIL] + clean_pool=True + try: + if pool_type == DIR_POOL: + pool_name = default_pool_name + clean_pool=False
Need spaces here around the = sign. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1252437748 25200 # Node ID 616c8e4217a138a001a9223363c3fdd2bb448f13 # Parent c127b5047569b1a7fbb7e2a266e8e8fea71e762e [TEST] Add new tc to verify the err values for RPCS DeleteResourceInPool() Tested with KVM and current sources on SLES11. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r c127b5047569 -r 616c8e4217a1 suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/13_delete_storagevolume_errs.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/13_delete_storagevolume_errs.py Tue Sep 08 12:22:28 2009 -0700 @@ -0,0 +1,191 @@ +#!/usr/bin/python +# +# Copyright 2009 IBM Corp. +# +# Authors: +# Deepti B. Kalakeri<dkalaker@in.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 +# +# +# This test case verifies the deletion of the StorageVol using the +# DeleteResourceInPool method of RPCS returns error when invalid values are +# passed. +# +# -Date: 08-09-2009 + +import sys +import os +from VirtLib import utils +from CimTest.Globals import logger +from pywbem import CIM_ERR_FAILED, CIM_ERR_INVALID_PARAMETER, CIMError +from CimTest.ReturnCodes import FAIL, PASS, SKIP +from XenKvmLib.xm_virt_util import virsh_version +from XenKvmLib.const import do_main, platform_sup, default_pool_name, \ + get_provider_version +from XenKvmLib import rpcs_service +from XenKvmLib.assoc import Associators +from XenKvmLib.enumclass import GetInstance, EnumNames +from XenKvmLib.classes import get_typed_class, inst_to_mof +from XenKvmLib.common_util import destroy_diskpool +from XenKvmLib.pool import create_pool, undefine_diskpool, DIR_POOL, \ + libvirt_rasd_spool_del_changes, get_diskpool, \ + get_stovol_default_settings, \ + get_stovol_rasd_from_sdc + +pool_attr = { 'Path' : "/tmp" } +vol_name = "cimtest-vol.img" +invalid_scen = { "INVALID_ADDRESS" : { 'val' : 'Junkvol_path', + 'msg' : 'no storage vol with '\ + 'matching path' }, + "NO_ADDRESS" : { 'msg' :'Missing Address in '\ + 'resource RASD' }, + "MISSING_RESOURCE" : { 'msg' :"Missing argument `Resource'"}, + "MISSING_POOL" : { 'msg' :"Missing argument `Pool'"} + } + + +def get_sto_vol_rasd(virt, server, dp_cn, pool_name, exp_vol_path): + dv_rasds = None + dp_inst_id = "%s/%s" % (dp_cn, pool_name) + status, rasds = get_stovol_rasd_from_sdc(virt, server, dp_inst_id) + if status != PASS: + logger.error("Failed to get the StorageVol for '%s' vol", exp_vol_path) + return FAIL + + for item in rasds: + if item['Address'] == exp_vol_path and item['PoolID'] == dp_inst_id: + dv_rasds = item + break + + return dv_rasds + + +def verify_rpcs_err_val(virt, server, rpcs_conn, dp_cn, pool_name, + exp_vol_path, dp_inst): + for err_scen in invalid_scen.keys(): + logger.info("Verifying errors for '%s'....", err_scen) + status = FAIL + del_res = [FAIL] + try: + res_settings = get_sto_vol_rasd(virt, server, dp_cn, + pool_name, exp_vol_path) + if res_settings == None: + raise Exception("Failed to get the resource settings for '%s'" \ + " Vol" % vol_name) + if not "MISSING" in err_scen: + exp_err_no = CIM_ERR_FAILED + if "NO_ADDRESS" in err_scen: + del res_settings['Address'] + elif "INVALID_ADDRESS" in err_scen: + res_settings['Address'] = invalid_scen[err_scen]['val'] + + resource = inst_to_mof(res_settings) + del_res = rpcs_conn.DeleteResourceInPool(Resource=resource, + Pool=dp_inst) + else: + exp_err_no = CIM_ERR_INVALID_PARAMETER + if err_scen == "MISSING_RESOURCE": + del_res = rpcs_conn.DeleteResourceInPool(Pool=dp_inst) + elif err_scen == "MISSING_POOL": + del_res = rpcs_conn.DeleteResourceInPool(Resource=resource) + + except CIMError, (err_no, err_desc): + if invalid_scen[err_scen]['msg'] in err_desc \ + and exp_err_no == err_no: + logger.error("Got the expected error message: '%s' for '%s'", + err_desc, err_scen) + status=PASS + else: + logger.error("Failed to get the error message '%s'", + invalid_scen[err_scen]['msg']) + + if del_res[0] == PASS: + logger.error("Should not have been able to delete Vol %s", vol_name) + return FAIL + + return status + +def cleanup_pool_vol(server, exp_vol_path): + try: + if os.path.exists(exp_vol_path): + cmd = "rm -rf %s" % exp_vol_path + ret, out = utils.run_remote(server, cmd) + if ret != 0: + raise Exception("'%s' was not removed, please remove it " \ + "manually" % exp_vol_path) + except Exception, details: + logger.error("Exception details: %s", details) + return FAIL + + return PASS + + +@do_main(platform_sup) +def main(): + options = main.options + server = options.ip + virt = options.virt + + libvirt_ver = virsh_version(server, virt) + cim_rev, changeset = get_provider_version(virt, server) + if libvirt_ver < "0.4.1" and cim_rev < libvirt_rasd_spool_del_changes: + logger.info("Storage Volume deletion support is available with Libvirt" + "version >= 0.4.1 and Libvirt-CIM rev '%s'", + libvirt_rasd_spool_del_changes) + return SKIP + + dp_cn = "DiskPool" + exp_vol_path = "%s/%s" % (pool_attr['Path'], vol_name) + + pool_name = default_pool_name + pool_type = DIR_POOL + status = FAIL + res = del_res = [FAIL] + try: + sv_rasd = get_stovol_default_settings(virt, server, dp_cn, pool_name, + exp_vol_path, vol_name) + if sv_rasd == None: + raise Exception("Failed to get the defualt StorageVolRASD info") + + sv_settings = inst_to_mof(sv_rasd) + + dp_inst = get_diskpool(server, virt, dp_cn, pool_name) + if dp_inst == None: + raise Exception("DiskPool instance for '%s' not found!" \ + % pool_name) + + rpcs = get_typed_class(virt, "ResourcePoolConfigurationService") + rpcs_conn = eval("rpcs_service." + rpcs)(server) + res = rpcs_conn.CreateResourceInPool(Settings=sv_settings, + Pool=dp_inst) + if res[0] != PASS: + raise Exception("Failed to create the Vol %s" % vol_name) + + status = verify_rpcs_err_val(virt, server, rpcs_conn, dp_cn, + pool_name, exp_vol_path, dp_inst) + if status != PASS : + raise Exception("Failed to verify the error") + + except Exception, details: + logger.error("Exception details: %s", details) + status = FAIL + + ret = cleanup_pool_vol(server, exp_vol_path) + + return status +if __name__ == "__main__": + sys.exit(main())

+def verify_rpcs_err_val(virt, server, rpcs_conn, dp_cn, pool_name, + exp_vol_path, dp_inst): + for err_scen in invalid_scen.keys(): + logger.info("Verifying errors for '%s'....", err_scen) + status = FAIL + del_res = [FAIL] + try:
I would put the try / execpt outside of the for loop. This will save you some indentation.
+ res_settings = get_sto_vol_rasd(virt, server, dp_cn, + pool_name, exp_vol_path) + if res_settings == None: + raise Exception("Failed to get the resource settings for '%s'" \ + " Vol" % vol_name) + if not "MISSING" in err_scen: + exp_err_no = CIM_ERR_FAILED + if "NO_ADDRESS" in err_scen: + del res_settings['Address'] + elif "INVALID_ADDRESS" in err_scen: + res_settings['Address'] = invalid_scen[err_scen]['val']
+ + resource = inst_to_mof(res_settings) + del_res = rpcs_conn.DeleteResourceInPool(Resource=resource, + Pool=dp_inst) + else: + exp_err_no = CIM_ERR_INVALID_PARAMETER + if err_scen == "MISSING_RESOURCE": + del_res = rpcs_conn.DeleteResourceInPool(Pool=dp_inst) + elif err_scen == "MISSING_POOL": + del_res = rpcs_conn.DeleteResourceInPool(Resource=resource)
Will invalid_scen.keys() already return the keys in the same order? I'm wondering if it is possible for resource to be undefined here since it only gets defined if "if not "MISSING" in err_scen:" has passed in a prior iteration of the loop. If "if not "MISSING" in err_scen:" fails the first time through the loop, resource will be undefined.
+ + except CIMError, (err_no, err_desc): + if invalid_scen[err_scen]['msg'] in err_desc \ + and exp_err_no == err_no: + logger.error("Got the expected error message: '%s' for '%s'", + err_desc, err_scen) + status=PASS
Spaces between the = here. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
+def verify_rpcs_err_val(virt, server, rpcs_conn, dp_cn, pool_name, + exp_vol_path, dp_inst): + for err_scen in invalid_scen.keys(): + logger.info("Verifying errors for '%s'....", err_scen) + status = FAIL + del_res = [FAIL] + try:
I would put the try / execpt outside of the for loop. This will save you some indentation.
I would need the try: except block .. so that I can catch the errors for each of the invalid delete() scenarios.
+ res_settings = get_sto_vol_rasd(virt, server, dp_cn, + pool_name, exp_vol_path) + if res_settings == None: + raise Exception("Failed to get the resource settings for '%s'" \ + " Vol" % vol_name) + if not "MISSING" in err_scen: + exp_err_no = CIM_ERR_FAILED + if "NO_ADDRESS" in err_scen: + del res_settings['Address'] + elif "INVALID_ADDRESS" in err_scen: + res_settings['Address'] = invalid_scen[err_scen]['val']
+ + resource = inst_to_mof(res_settings) + del_res = rpcs_conn.DeleteResourceInPool(Resource=resource, + Pool=dp_inst) + else: + exp_err_no = CIM_ERR_INVALID_PARAMETER + if err_scen == "MISSING_RESOURCE": + del_res = rpcs_conn.DeleteResourceInPool(Pool=dp_inst) + elif err_scen == "MISSING_POOL": + del_res = rpcs_conn.DeleteResourceInPool(Resource=resource)
Will invalid_scen.keys() already return the keys in the same order? I'm wondering if it is possible for resource to be undefined here since it only gets defined if "if not "MISSING" in err_scen:" has passed in a prior iteration of the loop.
If "if not "MISSING" in err_scen:" fails the first time through the loop, resource will be undefined.
I am not sure I understand the comment here.
+ + except CIMError, (err_no, err_desc): + if invalid_scen[err_scen]['msg'] in err_desc \ + and exp_err_no == err_no: + logger.error("Got the expected error message: '%s' for '%s'", + err_desc, err_scen) + status=PASS
Spaces between the = here. Oh! yeah , Thanks !! done.
-- Thanks and Regards, Deepti B. Kalakeri IBM Linux Technology Center deeptik@linux.vnet.ibm.com

Deepti B Kalakeri wrote:
Kaitlin Rupert wrote:
+def verify_rpcs_err_val(virt, server, rpcs_conn, dp_cn, pool_name, + exp_vol_path, dp_inst): + for err_scen in invalid_scen.keys(): + logger.info("Verifying errors for '%s'....", err_scen) + status = FAIL + del_res = [FAIL] + try:
I would put the try / execpt outside of the for loop. This will save you some indentation.
I would need the try: except block .. so that I can catch the errors for each of the invalid delete() scenarios.
Agreed. Your code does something like: + for err_scen in invalid_scen.keys(): <snip> + try: <snip> + + except CIMError, (err_no, err_desc): Why not do: try: for except CIMError, (err_no, err_desc): except Exception, details: This would save you some indentation, and allow you to catch any unexpected errors in addition to the errors thrown by the delete call.
+ resource = inst_to_mof(res_settings) + del_res = rpcs_conn.DeleteResourceInPool(Resource=resource, + Pool=dp_inst) + else: + exp_err_no = CIM_ERR_INVALID_PARAMETER + if err_scen == "MISSING_RESOURCE": + del_res = rpcs_conn.DeleteResourceInPool(Pool=dp_inst) + elif err_scen == "MISSING_POOL": + del_res = rpcs_conn.DeleteResourceInPool(Resource=resource)
Will invalid_scen.keys() already return the keys in the same order? I'm wondering if it is possible for resource to be undefined here since it only gets defined if "if not "MISSING" in err_scen:" has passed in a prior iteration of the loop.
If "if not "MISSING" in err_scen:" fails the first time through the loop, resource will be undefined.
I am not sure I understand the comment here.
If you look at the Python documentation, the keys are returned an arbitrary order (http://docs.python.org/library/stdtypes.html#dict.items). So taking a look at your code, let's say keys() returns err_scen == MISSING_POOL the first time through the loop... if not "MISSING" in err_scen: This check fails else: exp_err_no = CIM_ERR_INVALID_PARAMETER if err_scen == "MISSING_RESOURCE": del_res = rpcs_conn.DeleteResourceInPool(Pool=dp_inst) elif err_scen == "MISSING_POOL": del_res = rpcs_conn.DeleteResourceInPool(Resource=resource) This code is executed, but resource hasn't been set yet. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Deepti B Kalakeri wrote:
Kaitlin Rupert wrote:
+def verify_rpcs_err_val(virt, server, rpcs_conn, dp_cn, pool_name, + exp_vol_path, dp_inst): + for err_scen in invalid_scen.keys(): + logger.info("Verifying errors for '%s'....", err_scen) + status = FAIL + del_res = [FAIL] + try:
I would put the try / execpt outside of the for loop. This will save you some indentation.
I would need the try: except block .. so that I can catch the errors for each of the invalid delete() scenarios.
Agreed. Your code does something like:
+ for err_scen in invalid_scen.keys():
<snip>
+ try:
<snip>
+ + except CIMError, (err_no, err_desc):
Why not do:
try:
for
except CIMError, (err_no, err_desc):
except Exception, details: If I change the existing code to
Kaitlin Rupert wrote: try: for except CIMError, (err_no, err_desc): except Exception, details: Then, I will be able to execute the for loop only one time and the execution will come out with suitable message from verify_error*().
This would save you some indentation, and allow you to catch any unexpected errors in addition to the errors thrown by the delete call.
Good Point!! to include the exception for the other cases apart from the DeleteResourceInPool().
+ resource = inst_to_mof(res_settings) + del_res = rpcs_conn.DeleteResourceInPool(Resource=resource, + Pool=dp_inst) + else: + exp_err_no = CIM_ERR_INVALID_PARAMETER + if err_scen == "MISSING_RESOURCE": + del_res = rpcs_conn.DeleteResourceInPool(Pool=dp_inst) + elif err_scen == "MISSING_POOL": + del_res = rpcs_conn.DeleteResourceInPool(Resource=resource)
Will invalid_scen.keys() already return the keys in the same order? I'm wondering if it is possible for resource to be undefined here since it only gets defined if "if not "MISSING" in err_scen:" has passed in a prior iteration of the loop.
If "if not "MISSING" in err_scen:" fails the first time through the loop, resource will be undefined.
I am not sure I understand the comment here.
If you look at the Python documentation, the keys are returned an arbitrary order (http://docs.python.org/library/stdtypes.html#dict.items).
Yeah thats correct the keys() would not come in a particular oder unless sorted.
So taking a look at your code, let's say keys() returns err_scen == MISSING_POOL the first time through the loop...
if not "MISSING" in err_scen: This check fails
else: exp_err_no = CIM_ERR_INVALID_PARAMETER if err_scen == "MISSING_RESOURCE": del_res = rpcs_conn.DeleteResourceInPool(Pool=dp_inst) elif err_scen == "MISSING_POOL": del_res = rpcs_conn.DeleteResourceInPool(Resource=resource)
This code is executed, but resource hasn't been set yet.
yeah!! the old patch did not set the resource for the MISSING_POOL case and that was a mistake. This has been included in the new patch that was sent yesterday. -- Thanks and Regards, Deepti B. Kalakeri IBM Linux Technology Center deeptik@linux.vnet.ibm.com

Why not do:
try:
for
except CIMError, (err_no, err_desc):
except Exception, details:
If I change the existing code to try:
for except CIMError, (err_no, err_desc):
except Exception, details:
Then, I will be able to execute the for loop only one time and the execution will come out with suitable message from verify_error*().
This would save you some indentation, and allow you to catch any unexpected errors in addition to the errors thrown by the delete call.
Ah, yes - that's a fair point. That's my mistake here. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (3)
-
Deepti B Kalakeri
-
Deepti B. Kalakeri
-
Kaitlin Rupert