[PATCH 0 of 2] [TEST] Added new tc to verify RPCS error values.

# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1252394005 25200 # Node ID fdc0d9aef3427500032bbd35caba0e5977be47f6 # Parent 30196cc506c07d81642c94a01fc65b34421c0714 [TEST] Modified pool.py to support RPCS CreateResourceInPool. Added the following two functions which are used in RPCS/10*py and RPCS/11*py 1) get_stovol_rasd_from_sdc() to get the stovol rasd from sdc 2) get_stovol_default_settings() to get default sto vol settings Also, modified common_util.py to remove the backed up exportfs file. Added RAW_VOL_TYPE which is the FormatType supported by RPCS currently. Once this patch gets accepted we can modify RPCS/10*py to refer to these functions. Tested with KVM and current sources on SLES11. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r 30196cc506c0 -r fdc0d9aef342 suites/libvirt-cim/lib/XenKvmLib/common_util.py --- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Wed Sep 02 05:11:16 2009 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Tue Sep 08 00:13:25 2009 -0700 @@ -531,7 +531,7 @@ # Remove the temp dir created . clean_temp_files(server, src_dir, dst_dir) - + # Restore the original exports file. if os.path.exists(back_exports_file): os.remove(exports_file) @@ -551,6 +551,8 @@ try: # Backup the original exports file. if (os.path.exists(exports_file)): + if os.path.exists(back_exports_file): + os.remove(back_exports_file) move_file(exports_file, back_exports_file) fd = open(exports_file, "w") line = "\n %s %s(rw)" %(src_dir_for_mnt, server) diff -r 30196cc506c0 -r fdc0d9aef342 suites/libvirt-cim/lib/XenKvmLib/pool.py --- a/suites/libvirt-cim/lib/XenKvmLib/pool.py Wed Sep 02 05:11:16 2009 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/pool.py Tue Sep 08 00:13:25 2009 -0700 @@ -34,6 +34,7 @@ from CimTest.CimExt import CIMClassMOF from XenKvmLib.vxml import NetXML, PoolXML from XenKvmLib.xm_virt_util import virsh_version +from XenKvmLib.vsms import RASD_TYPE_STOREVOL cim_errno = pywbem.CIM_ERR_NOT_SUPPORTED cim_mname = "CreateChildResourcePool" @@ -48,6 +49,9 @@ LOGICAL_POOL = 6L SCSI_POOL = 7L +#Volume types +RAW_VOL_TYPE = 1 + def pool_cn_to_rasd_cn(pool_cn, virt): if pool_cn.find('ProcessorPool') >= 0: return get_typed_class(virt, "ProcResourceAllocationSettingData") @@ -297,3 +301,41 @@ status = PASS return status + +def get_stovol_rasd_from_sdc(virt, server, dp_inst_id): + rasd = None + ac_cn = get_typed_class(virt, "AllocationCapabilities") + an_cn = get_typed_class(virt, "SettingsDefineCapabilities") + key_list = {"InstanceID" : dp_inst_id} + + try: + inst = GetInstance(server, ac_cn, key_list) + rasd = Associators(server, an_cn, ac_cn, InstanceID=inst.InstanceID) + except Exception, detail: + logger.error("Exception: %s", detail) + return FAIL, None + + return PASS, rasd + +def get_stovol_default_settings(virt, server, dp_cn, + pool_name, path, vol_name): + + dp_inst_id = "%s/%s" % (dp_cn, pool_name) + status, dp_rasds = get_stovol_rasd_from_sdc(virt, server, dp_inst_id) + if status != PASS: + logger.error("Failed to get the StorageVol RASD's") + return None + + for dpool_rasd in dp_rasds: + if dpool_rasd['ResourceType'] == RASD_TYPE_STOREVOL and \ + 'Default' in dpool_rasd['InstanceID']: + + dpool_rasd['PoolID'] = dp_inst_id + dpool_rasd['Path'] = path + dpool_rasd['VolumeName'] = vol_name + break + + if not pool_name in dpool_rasd['PoolID']: + return None + + return dpool_rasd

+def get_stovol_rasd_from_sdc(virt, server, dp_inst_id): + rasd = None + ac_cn = get_typed_class(virt, "AllocationCapabilities") + an_cn = get_typed_class(virt, "SettingsDefineCapabilities") + key_list = {"InstanceID" : dp_inst_id} + + try: + inst = GetInstance(server, ac_cn, key_list)
What if inst is None - should return an error here.
+ rasd = Associators(server, an_cn, ac_cn, InstanceID=inst.InstanceID)
Should also check to make sure rasd is of some length - otherwise, return an error.
+ except Exception, detail: + logger.error("Exception: %s", detail) + return FAIL, None + + return PASS, rasd +
-- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1252394401 25200 # Node ID 465cfe3802c691e2315dc47eb07790df6c96fb77 # Parent fdc0d9aef3427500032bbd35caba0e5977be47f6 [TEST] Added new tc to verify the RPCS error values. This test case verifies the creation of the StorageVol using the CreateResourceInPool method of RPCS returns an error when invalid values are passed. The test case checks for the errors when: 1) FormatType field in the StoragePoolRASD set to value other than RAW_TYPE 2) Trying to create a Vol in a netfs storage pool 3) Trying to create 2 Vol in the same Path Tested with KVM and current sources on SLES11. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r fdc0d9aef342 -r 465cfe3802c6 suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/11_create_storagevolume_errs.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/11_create_storagevolume_errs.py Tue Sep 08 00:20:01 2009 -0700 @@ -0,0 +1,226 @@ +#!/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 creation of the StorageVol using the +# CreateResourceInPool method of RPCS returns an error when invalid values +# are passed. +# The test case checks for the errors when: +# 1) FormatType field in the StoragePoolRASD set to value other than RAW_TYPE +# 2) Trying to create a Vol in a netfs storage pool +# 3) Trying to create 2 Vol in the same Path +# +# -Date: 04-09-2009 + +import sys +import os +from VirtLib import utils +from random import randint +from pywbem.cim_types import Uint64 +from pywbem import CIM_ERR_FAILED, CIMError +from CimTest.Globals import logger +from CimTest.ReturnCodes import FAIL, PASS, SKIP +from XenKvmLib.const import do_main, platform_sup, default_pool_name, \ + get_provider_version +from XenKvmLib.rasd import libvirt_rasd_storagepool_changes +from XenKvmLib import rpcs_service +from XenKvmLib.assoc import Associators +from XenKvmLib.enumclass import GetInstance, EnumNames +from XenKvmLib.xm_virt_util import virsh_version +from XenKvmLib.classes import get_typed_class, inst_to_mof +from XenKvmLib.common_util import destroy_diskpool, nfs_netfs_setup, \ + netfs_cleanup +from XenKvmLib.pool import create_pool, undefine_diskpool, RAW_VOL_TYPE, \ + DIR_POOL, NETFS_POOL, \ + get_stovol_rasd_from_sdc, get_stovol_default_settings + +dir_pool_attr = { "Path" : "/tmp" } +vol_name = "cimtest-vol.img" + +INVALID_FTYPE = RAW_VOL_TYPE + randint(20,100) +exp_err_no = CIM_ERR_FAILED +exp_err_values = { 'INVALID_FTYPE': { 'msg' : "Unable to generate XML "\ + "for new resource" }, + 'NETFS_POOL' : { 'msg' : "This function does not "\ + "support this resource type"}, + 'DUP_VOL_PATH' : { 'msg' : "Unable to create storage volume"} + } + +def get_pool_attr(server, pool_type, dp_types): + pool_attr = dir_pool_attr + + if pool_type == dp_types['NETFS_POOL']: + status , src_mnt_dir, dir_mnt_dir = nfs_netfs_setup(server) + if status != PASS: + logger.error("Failed to get pool_attr for NETFS diskpool type") + return FAIL, pool_attr + + pool_attr['SourceDirectory'] = src_mnt_dir + pool_attr['Host'] = server + pool_attr['Path'] = dir_mnt_dir + + return PASS, pool_attr + +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 + +def verify_vol_err(server, virt, sv_settings, dp_inst, key): + status = FAIL + res = [FAIL] + try: + rpcs = get_typed_class(virt, "ResourcePoolConfigurationService") + rpcs_conn = eval("rpcs_service." + rpcs)(server) + res = rpcs_conn.CreateResourceInPool(Settings=sv_settings, + Pool=dp_inst) + + # For duplicate vol path verfication we should have been able to + # create the first dir pool successfully before attempting the next + if key == 'DUP_VOL_PATH' and res[0] == PASS: + # Trying to create the vol in the same vol path should return + # an error + res = rpcs_conn.CreateResourceInPool(Settings=sv_settings, + Pool=dp_inst) + + except CIMError, (err_no, err_desc): + if exp_err_values[key]['msg'] in err_desc and exp_err_no == err_no: + logger.error("Got the expected error message: '%s' with '%s'", + err_desc, key) + status=PASS + else: + logger.error("Failed to get the error message '%s'", + exp_err_values[key]['msg']) + + if status != PASS: + logger.error("Should not have been able to create Vol %s", vol_name) + + return status + +def cleanup_pool_vol(server, virt, pool_name, clean_pool, exp_vol_path): + try: + if clean_pool == 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) + except Exception, details: + logger.error("Exception details: %s", details) + return FAIL + + if os.path.exists(exp_vol_path): + cmd = "rm -rf %s" % exp_vol_path + ret, out = utils.run_remote(server, cmd) + if ret != 0: + logger.info("'%s' was not removed, please remove it manually", + exp_vol_path) + 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_storagepool_changes: + logger.info("Storage Volume creation support is available with Libvirt" + "version >= 0.4.1 and Libvirt-CIM rev '%s'", + libvirt_rasd_storagepool_changes) + return SKIP + + dp_types = { "NETFS_POOL" : NETFS_POOL } + dp_types['DUP_VOL_PATH'] = dp_types['INVALID_FTYPE'] = DIR_POOL + dp_cn = "DiskPool" + exp_vol_path = "%s/%s" % (dir_pool_attr['Path'], vol_name) + + for pool_name, pool_type in dp_types.iteritems(): + status = FAIL + clean_pool=True + try: + status, pool_attr = get_pool_attr(server, pool_type, dp_types) + if status != PASS: + return status + + # err_key will contain either INVALID_FTYPE/DUP_VOL_PATH/NETFS_POOL + # to be able access the err mesg + err_key = pool_name + + if pool_type == DIR_POOL: + pool_name = default_pool_name + clean_pool=False + else: + # Creating NETFS pool to verify RPCS error + 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") + + if err_key == "INVALID_FTYPE": + sv_rasd['FormatType'] = Uint64(INVALID_FTYPE) + + 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) + + status = verify_vol_err(server, virt, sv_settings, dp_inst, err_key) + if status != PASS : + raise Exception("Failed to verify the Invlaid '%s' ", err_key) + + if err_key == 'NETFS_POOL': + netfs_cleanup(server, pool_attr) + + except Exception, details: + logger.error("Exception details: %s", details) + status = FAIL + if err_key == 'NETFS_POOL': + netfs_cleanup(server, pool_attr) + break + + cleanup_pool_vol(server, virt, pool_name, clean_pool, exp_vol_path) + + return status +if __name__ == "__main__": + sys.exit(main())

Deepti B. Kalakeri wrote:
# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1252394401 25200 # Node ID 465cfe3802c691e2315dc47eb07790df6c96fb77 # Parent fdc0d9aef3427500032bbd35caba0e5977be47f6 [TEST] Added new tc to verify the RPCS error values.
This test case verifies the creation of the StorageVol using the CreateResourceInPool method of RPCS returns an error when invalid values are passed. The test case checks for the errors when: 1) FormatType field in the StoragePoolRASD set to value other than RAW_TYPE 2) Trying to create a Vol in a netfs storage pool 3) Trying to create 2 Vol in the same Path
Tested with KVM and current sources on SLES11. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com>
diff -r fdc0d9aef342 -r 465cfe3802c6 suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/11_create_storagevolume_errs.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/11_create_storagevolume_errs.py Tue Sep 08 00:20:01 2009 -0700 @@ -0,0 +1,226 @@ +#!/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 creation of the StorageVol using the +# CreateResourceInPool method of RPCS returns an error when invalid values +# are passed. +# The test case checks for the errors when: +# 1) FormatType field in the StoragePoolRASD set to value other than RAW_TYPE +# 2) Trying to create a Vol in a netfs storage pool +# 3) Trying to create 2 Vol in the same Path +# +# -Date: 04-09-2009 + +import sys +import os +from VirtLib import utils +from random import randint +from pywbem.cim_types import Uint64 +from pywbem import CIM_ERR_FAILED, CIMError +from CimTest.Globals import logger +from CimTest.ReturnCodes import FAIL, PASS, SKIP +from XenKvmLib.const import do_main, platform_sup, default_pool_name, \ + get_provider_version +from XenKvmLib.rasd import libvirt_rasd_storagepool_changes +from XenKvmLib import rpcs_service +from XenKvmLib.assoc import Associators +from XenKvmLib.enumclass import GetInstance, EnumNames +from XenKvmLib.xm_virt_util import virsh_version +from XenKvmLib.classes import get_typed_class, inst_to_mof +from XenKvmLib.common_util import destroy_diskpool, nfs_netfs_setup, \ + netfs_cleanup +from XenKvmLib.pool import create_pool, undefine_diskpool, RAW_VOL_TYPE, \ + DIR_POOL, NETFS_POOL, \ + get_stovol_rasd_from_sdc, get_stovol_default_settings + +dir_pool_attr = { "Path" : "/tmp" } +vol_name = "cimtest-vol.img" + +INVALID_FTYPE = RAW_VOL_TYPE + randint(20,100) +exp_err_no = CIM_ERR_FAILED +exp_err_values = { 'INVALID_FTYPE': { 'msg' : "Unable to generate XML "\ + "for new resource" }, + 'NETFS_POOL' : { 'msg' : "This function does not "\ + "support this resource type"}, + 'DUP_VOL_PATH' : { 'msg' : "Unable to create storage volume"}
Can you line up the third entry with the other two?
+ } +
+ +@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_storagepool_changes: + logger.info("Storage Volume creation support is available with Libvirt" + "version >= 0.4.1 and Libvirt-CIM rev '%s'", + libvirt_rasd_storagepool_changes) + return SKIP + + dp_types = { "NETFS_POOL" : NETFS_POOL } + dp_types['DUP_VOL_PATH'] = dp_types['INVALID_FTYPE'] = DIR_POOL + dp_cn = "DiskPool" + exp_vol_path = "%s/%s" % (dir_pool_attr['Path'], vol_name) + + for pool_name, pool_type in dp_types.iteritems(): + status = FAIL + clean_pool=True + try: + status, pool_attr = get_pool_attr(server, pool_type, dp_types) + if status != PASS: + return status + + # err_key will contain either INVALID_FTYPE/DUP_VOL_PATH/NETFS_POOL + # to be able access the err mesg + err_key = pool_name + + if pool_type == DIR_POOL: + pool_name = default_pool_name + clean_pool=False + else: + # Creating NETFS pool to verify RPCS error + status = create_pool(server, virt, pool_name, pool_attr, + mode_type=pool_type, pool_type=dp_cn)
A netfs pool requires a nfsserver running on the system, and not all systems have nfs installed. So I wouldn't use the netfs type pool in this test.
+ + 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") + + if err_key == "INVALID_FTYPE": + sv_rasd['FormatType'] = Uint64(INVALID_FTYPE) + + sv_settings = inst_to_mof(sv_rasd)
Looks like you don't use sv_settings elsewhere in the test, so include this line in verify_vol_err().
+ + dp_inst = get_diskpool(server, virt, dp_cn, pool_name) + if dp_inst == None: + raise Exception("DiskPool instance for '%s' not found!" \ + % pool_name) + + status = verify_vol_err(server, virt, sv_settings, dp_inst, err_key) + if status != PASS : + raise Exception("Failed to verify the Invlaid '%s' ", err_key) + + if err_key == 'NETFS_POOL': + netfs_cleanup(server, pool_attr) + + except Exception, details: + logger.error("Exception details: %s", details) + status = FAIL + if err_key == 'NETFS_POOL': + netfs_cleanup(server, pool_attr) + break
I would have the try / except block outside of the for loop so you don't need to break from the look. Raising the exception should be enough to break you out of the loop.
+ + cleanup_pool_vol(server, virt, pool_name, clean_pool, exp_vol_path) + + return status +if __name__ == "__main__": + sys.exit(main())
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
-- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
Deepti B. Kalakeri wrote:
# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1252394401 25200 # Node ID 465cfe3802c691e2315dc47eb07790df6c96fb77 # Parent fdc0d9aef3427500032bbd35caba0e5977be47f6 [TEST] Added new tc to verify the RPCS error values.
This test case verifies the creation of the StorageVol using the CreateResourceInPool method of RPCS returns an error when invalid values are passed. The test case checks for the errors when: 1) FormatType field in the StoragePoolRASD set to value other than RAW_TYPE 2) Trying to create a Vol in a netfs storage pool 3) Trying to create 2 Vol in the same Path
Tested with KVM and current sources on SLES11. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com>
diff -r fdc0d9aef342 -r 465cfe3802c6 suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/11_create_storagevolume_errs.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/11_create_storagevolume_errs.py Tue Sep 08 00:20:01 2009 -0700 @@ -0,0 +1,226 @@ +#!/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 creation of the StorageVol using the +# CreateResourceInPool method of RPCS returns an error when invalid values +# are passed. +# The test case checks for the errors when: +# 1) FormatType field in the StoragePoolRASD set to value other than RAW_TYPE +# 2) Trying to create a Vol in a netfs storage pool +# 3) Trying to create 2 Vol in the same Path +# +# -Date: 04-09-2009 + +import sys +import os +from VirtLib import utils +from random import randint +from pywbem.cim_types import Uint64 +from pywbem import CIM_ERR_FAILED, CIMError +from CimTest.Globals import logger +from CimTest.ReturnCodes import FAIL, PASS, SKIP +from XenKvmLib.const import do_main, platform_sup, default_pool_name, \ + get_provider_version +from XenKvmLib.rasd import libvirt_rasd_storagepool_changes +from XenKvmLib import rpcs_service +from XenKvmLib.assoc import Associators +from XenKvmLib.enumclass import GetInstance, EnumNames +from XenKvmLib.xm_virt_util import virsh_version +from XenKvmLib.classes import get_typed_class, inst_to_mof +from XenKvmLib.common_util import destroy_diskpool, nfs_netfs_setup, \ + netfs_cleanup +from XenKvmLib.pool import create_pool, undefine_diskpool, RAW_VOL_TYPE, \ + DIR_POOL, NETFS_POOL, \ + get_stovol_rasd_from_sdc, get_stovol_default_settings + +dir_pool_attr = { "Path" : "/tmp" } +vol_name = "cimtest-vol.img" + +INVALID_FTYPE = RAW_VOL_TYPE + randint(20,100) +exp_err_no = CIM_ERR_FAILED +exp_err_values = { 'INVALID_FTYPE': { 'msg' : "Unable to generate XML "\ + "for new resource" }, + 'NETFS_POOL' : { 'msg' : "This function does not "\ + "support this resource type"}, + 'DUP_VOL_PATH' : { 'msg' : "Unable to create storage volume"}
Can you line up the third entry with the other two?
+ } +
+ +@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_storagepool_changes: + logger.info("Storage Volume creation support is available with Libvirt" + "version >= 0.4.1 and Libvirt-CIM rev '%s'", + libvirt_rasd_storagepool_changes) + return SKIP + + dp_types = { "NETFS_POOL" : NETFS_POOL } + dp_types['DUP_VOL_PATH'] = dp_types['INVALID_FTYPE'] = DIR_POOL + dp_cn = "DiskPool" + exp_vol_path = "%s/%s" % (dir_pool_attr['Path'], vol_name) + + for pool_name, pool_type in dp_types.iteritems(): + status = FAIL + clean_pool=True + try: + status, pool_attr = get_pool_attr(server, pool_type, dp_types) + if status != PASS: + return status + + # err_key will contain either INVALID_FTYPE/DUP_VOL_PATH/NETFS_POOL + # to be able access the err mesg + err_key = pool_name + + if pool_type == DIR_POOL: + pool_name = default_pool_name + clean_pool=False + else: + # Creating NETFS pool to verify RPCS error + status = create_pool(server, virt, pool_name, pool_attr, + mode_type=pool_type, pool_type=dp_cn)
A netfs pool requires a nfsserver running on the system, and not all systems have nfs installed. So I wouldn't use the netfs type pool in this test.
Other pool types would require user to give inputs. So I found netfs the only option to verify the error. Any suggestion for the pool types ?
+ + 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") + + if err_key == "INVALID_FTYPE": + sv_rasd['FormatType'] = Uint64(INVALID_FTYPE) + + sv_settings = inst_to_mof(sv_rasd)
Looks like you don't use sv_settings elsewhere in the test, so include this line in verify_vol_err().
+ + dp_inst = get_diskpool(server, virt, dp_cn, pool_name) + if dp_inst == None: + raise Exception("DiskPool instance for '%s' not found!" \ + % pool_name) + + status = verify_vol_err(server, virt, sv_settings, dp_inst, err_key) + if status != PASS : + raise Exception("Failed to verify the Invlaid '%s' ", err_key) + + if err_key == 'NETFS_POOL': + netfs_cleanup(server, pool_attr) + + except Exception, details: + logger.error("Exception details: %s", details) + status = FAIL + if err_key == 'NETFS_POOL': + netfs_cleanup(server, pool_attr) + break
I would have the try / except block outside of the for loop so you don't need to break from the look. Raising the exception should be enough to break you out of the loop.
+ + cleanup_pool_vol(server, virt, pool_name, clean_pool, exp_vol_path) + + return status +if __name__ == "__main__": + sys.exit(main())
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
-- Thanks and Regards, Deepti B. Kalakeri IBM Linux Technology Center deeptik@linux.vnet.ibm.com

+ # Creating NETFS pool to verify RPCS error + status = create_pool(server, virt, pool_name, pool_attr, + mode_type=pool_type, pool_type=dp_cn)
A netfs pool requires a nfsserver running on the system, and not all systems have nfs installed. So I wouldn't use the netfs type pool in this test.
Other pool types would require user to give inputs. So I found netfs the only option to verify the error. Any suggestion for the pool types ?
Why not use a directory pool? The case you're trying to test is whether libvirt-cim returns an error if a pool with that name has already been specified. For this case, the pool type doesn't matter. The provider does a look up in libvirt based on the pool name - it doesn't even consider the pool type. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
+ # Creating NETFS pool to verify RPCS error + status = create_pool(server, virt, pool_name, pool_attr, + mode_type=pool_type, pool_type=dp_cn)
A netfs pool requires a nfsserver running on the system, and not all systems have nfs installed. So I wouldn't use the netfs type pool in this test.
Other pool types would require user to give inputs. So I found netfs the only option to verify the error. Any suggestion for the pool types ?
Why not use a directory pool? The case you're trying to test is whether libvirt-cim returns an error if a pool with that name has already been specified.
For this case, the pool type doesn't matter. The provider does a look up in libvirt based on the pool name - it doesn't even consider the pool type.
yes we can use the dir pool for the duplicate path verification but for verifying the unsupported error we would require a pool other than dir pool. -- Thanks and Regards, Deepti B. Kalakeri IBM Linux Technology Center deeptik@linux.vnet.ibm.com

Deepti B Kalakeri wrote:
Kaitlin Rupert wrote:
+ # Creating NETFS pool to verify RPCS error + status = create_pool(server, virt, pool_name, pool_attr, + mode_type=pool_type, pool_type=dp_cn)
A netfs pool requires a nfsserver running on the system, and not all systems have nfs installed. So I wouldn't use the netfs type pool in this test.
Other pool types would require user to give inputs. So I found netfs the only option to verify the error. Any suggestion for the pool types ?
Why not use a directory pool? The case you're trying to test is whether libvirt-cim returns an error if a pool with that name has already been specified.
For this case, the pool type doesn't matter. The provider does a look up in libvirt based on the pool name - it doesn't even consider the pool type.
yes we can use the dir pool for the duplicate path verification but for verifying the unsupported error we would require a pool other than dir pool.
Ah, right - good point. I'm wondering if the unsupported error should be a different test. I'll need to give this some thought.. ordinarily, I would suggest having the test skip if there isn't a nfsserver.. but in this case, I would like to see the test report pass/failure status on the other conditions of the test. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (3)
-
Deepti B Kalakeri
-
Deepti B. Kalakeri
-
Kaitlin Rupert