yunguol(a)cn.ibm.com wrote:
# HG changeset patch
# User Guolian Yun <yunguol(a)cn.ibm.com>
# Date 1240479451 25200
# Node ID e1be3bd47b8005fad25dcfd80672870009d5c111
# Parent e8dc06eefada41252ba8d27b08fcef8ef6604251
[TEST] Add new tc to validate that the Disk child pool can be created through the
providers
Tested for KVM with current sources
Signed-off-by: Guolian Yun<yunguol(a)cn.ibm.com>
diff -r e8dc06eefada -r e1be3bd47b80
suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/08_CreateChildResourcePool_Disk.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++
b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/08_CreateChildResourcePool_Disk.py Thu
Apr 23 02:37:31 2009 -0700
@@ -0,0 +1,144 @@
+#!/usr/bin/python
+#
+# Copyright 2009 IBM Corp.
+#
+# Authors:
+# Guolian Yun <yunguol(a)cn.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 should test the CreateChildResourcePool service
+# supplied by the RPCS provider.
+# Input
+# -----
+# IN -- ElementName -- String -- The desired name of the resource pool
+# IN -- Settings -- String -- A string representation of a
+# CIM_ResourceAllocationSettingData
+# instance that represents the allocation
+# assigned to this child pool
+# IN -- ParentPool -- CIM_ResourcePool REF -- The parent pool from which
+# to create this pool
+#
+# Output
+# ------
+# OUT -- Pool -- CIM_ResourcePool REF -- The resulting resource pool
+# OUT -- Job -- CIM_ConcreteJob REF -- Returned job if started
+# OUT -- Error -- String -- Encoded error instance if the operation
+# failed and did not return a job
+#
+# Exception details before Revision 837
+# -----
+# Error code: CIM_ERR_NOT_SUPPORTED
+#
+# After revision 837, the service is implemented
+#
+# -Date: 23.04.2009
+
+import sys
+import pywbem
+from XenKvmLib import rpcs_service
+from CimTest.Globals import logger
+from CimTest.ReturnCodes import FAIL, PASS
+from CimTest.Globals import CIM_NS
combine CIM_NS and logger
+from XenKvmLib.const import do_main, platform_sup,
get_provider_version
+from XenKvmLib.classes import get_typed_class
+from pywbem.cim_obj import CIMInstanceName, CIMInstance
+from XenKvmLib.enumclass import EnumInstances
+from XenKvmLib.xm_virt_util import diskpool_destroy, diskpool_undefine
+from pywbem.cim_types import Uint16
+
+cim_errno = pywbem.CIM_ERR_NOT_SUPPORTED
+cim_mname = "CreateChildResourcePool"
+libvirt_cim_child_pool_rev = 837
+test_pool = ["dir_pool"]
+
+def verify_pool(pool_list, poolname):
+ status = FAIL
+ if len(pool_list) < 1:
+ logger.error("Return %i instances, expected at least one instance",
+ len(pool_list))
+ return FAIL
+
+ for i in range(0, len(pool_list)):
+ ret_pool = pool_list[i].InstanceID
+ if ret_pool == poolname:
+ status = PASS
+ break
+ elif ret_pool != poolname and i == len(pool_list)-1:
+ logger.error("Can not find expected pool")
Can we move this function to a library since it is used in other tc as
well ?
When you move the function, you can as well move the
EnumInstances(options.ip, dp) to the library function.
+
+ return status
+
+@do_main(platform_sup)
+def main():
+ options = main.options
+ rpcs_conn = eval("rpcs_service." + get_typed_class(options.virt, \
+ "ResourcePoolConfigurationService"))(options.ip)
+
+ curr_cim_rev, changeset = get_provider_version(options.virt, options.ip)
+ if curr_cim_rev < libvirt_cim_child_pool_rev:
+ try:
+ rpcs_conn.CreateChildResourcePool()
+ except pywbem.CIMError, (err_no, desc):
+ if err_no == cim_errno :
+ logger.info("Got expected exception for '%s'service",
cim_mname)
+ logger.info("Errno is '%s' ", err_no)
+ logger.info("Error string is '%s'", desc)
+ return PASS
+ else:
+ logger.error("Unexpected rc code %s and description %s\n",
+ err_no, desc)
+ return FAIL
+ elif curr_cim_rev >= libvirt_cim_child_pool_rev:
+ dprasd = get_typed_class(options.virt,
+ 'DiskPoolResourceAllocationSettingData')
+ dp_prop = {"Path" : "/tmp"}
+
+ for i in range(0, len(test_pool)):
+ dp_id = 'DiskPool/%s' % test_pool[i]
+ iname = CIMInstanceName(dprasd,
+ namespace = CIM_NS,
+ keybindings = {'InstanceID':dp_id})
+ if test_pool[i] == "dir_pool":
+ dp_prop["Type"] = Uint16(1)
+
+ drasd = CIMInstance(dprasd, path = iname, properties = dp_prop)
+ try:
+ rpcs_conn.CreateChildResourcePool(ElementName=test_pool[i],
+ Settings=[drasd.tomof()])
+ dp = get_typed_class(options.virt, 'DiskPool')
+ diskpool = EnumInstances(options.ip, dp)
+ status = verify_pool(diskpool, dp_id)
+ if status != PASS:
+ raise Exception("Error in diskpool verification")
+ status = diskpool_destroy(test_pool[i], options.ip, options.virt)
+ if status != PASS:
+ raise Exception("Unable to destroy diskpool %s"
+ % test_pool[i])
+ status = diskpool_undefine(test_pool[i], options.ip, options.virt)
+ if status != PASS:
+ raise Exception("Unable to undefine diskpool %s"
+ % test_pool[i])
+ except Exception, details:
+ logger.error("Invoke CreateChildResourcePool() error when "
+ "create %s", dp_id)
+ logger.error(details)
Make this log msg more generic.
+ return FAIL
+
+ return status
+
+if __name__ == "__main__":
+ sys.exit(main())
diff -r e8dc06eefada -r e1be3bd47b80 suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py Tue Apr 21 17:08:06 2009 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py Thu Apr 23 02:37:31 2009 -0700
@@ -190,7 +190,23 @@
cmd = "virsh -c %s net-destroy %s" % (virt2uri(virt), network)
ret, out = utils.run_remote(server, cmd)
- return ret
+ return ret
+
+def diskpool_destroy(diskpool, server, virt="Xen"):
+ """Function destroys a given virtual diskpool"""
+
+ cmd = "virsh -c %s pool-destroy %s" % (virt2uri(virt), diskpool)
+ ret, out = utils.run_remote(server, cmd)
+
+ return ret
+
+def diskpool_undefine(diskpool, server, virt="Xen"):
+ """Function undefines a given virtual diskpool"""
+
+ cmd = "virsh -c %s pool-undefine %s" % (virt2uri(virt), diskpool)
+ ret, out = utils.run_remote(server, cmd)
+
+ return ret
def network_by_bridge(bridge, server, virt="Xen"):
"""Function returns virtual network for a given
bridge"""
_______________________________________________
Libvirt-cim mailing list
Libvirt-cim(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvirt-cim
--
Thanks and Regards,
Deepti B. Kalakeri
IBM Linux Technology Center
deeptik(a)linux.vnet.ibm.com