[PATCH 0 of 2] [TEST] Add RASD template functions, VSMS 14_define_sys_disk.py

This patchset adds functions to get the template RASDs from SDC. These functions should be used to construct the RASDs passed to define system (instead of using the classes defined in vsms.py). This patchset is dependent on a recent version of pywbem.

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1223515128 25200 # Node ID 25b12a8b5257cd983e4926875dc619812fc1ce88 # Parent c2c64b0ee95d55ac09375f0a3518d60fd569ee7d [TEST] Add get_default_rasds() and get_rasd_templates() to rasd.py NOTE: This patch only works with recent versions of pywbem (svn checkout of 09/04/2008 or later). These functions can be used to get the template RASD instances. Instead of building instances by hand (see default_vssd_rasd_str()), the test cases should be using the template RASDs provided by the SettingsDefineCapabilities association. get_rasd_templates() - returns the min, max, increment, and default template RASD instances for a given AllocationCapabilities instance. get_default_rasds() - returns just the default template RASD instances for the resource pools. Add inst_to_mof() to convert instances to mof format. This is only needed for libcmpiutil version 0.4 and older. Add get_default_rasd_mofs() - returns default template RASDs in mof format. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r c2c64b0ee95d -r 25b12a8b5257 suites/libvirt-cim/lib/XenKvmLib/classes.py --- a/suites/libvirt-cim/lib/XenKvmLib/classes.py Wed Oct 08 12:59:17 2008 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/classes.py Wed Oct 08 18:18:48 2008 -0700 @@ -44,3 +44,18 @@ return cn[dash_index+1:] +#FIXME This function is only needed for libcmpiutil versions 0.4 and later. +#Once version 0.4 is obsolete, this function should be removed. +def inst_to_mof(inst): + mof_str = inst.tomof() + + mof_inst = "" + + for str in mof_str.splitlines(): + if str.endswith('{') or not str.endswith('NULL;'): + mof_inst += "%s\n" % str + elif str.endswith('};'): + mof_inst += "%s\n" % str + + return mof_inst + diff -r c2c64b0ee95d -r 25b12a8b5257 suites/libvirt-cim/lib/XenKvmLib/rasd.py --- a/suites/libvirt-cim/lib/XenKvmLib/rasd.py Wed Oct 08 12:59:17 2008 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/rasd.py Wed Oct 08 18:18:48 2008 -0700 @@ -24,8 +24,11 @@ from CimTest.Globals import logger from CimTest.ReturnCodes import FAIL, PASS from XenKvmLib import vxml -from XenKvmLib.classes import get_typed_class - +from XenKvmLib import const +from XenKvmLib.classes import get_typed_class, get_class_type +from XenKvmLib.enumclass import GetInstance +from XenKvmLib.assoc import Associators +from XenKvmLib.const import default_pool_name, default_network_name pasd_cn = 'ProcResourceAllocationSettingData' nasd_cn = 'NetResourceAllocationSettingData' @@ -165,3 +168,63 @@ memrasd_list['VirtualQuantity']) status = FAIL return status + +def get_rasd_templates(host_ip, type, pool_id): + ac_cn = get_typed_class(type, "AllocationCapabilities") + an_cn = get_typed_class(type, "SettingsDefineCapabilities") + + templates = [] + + try: + key_list = {"InstanceID" : pool_id } + + inst = GetInstance(host_ip, ac_cn, key_list) + + temps = Associators(host_ip, an_cn, ac_cn, InstanceID=inst.InstanceID) + + for temp in temps: + templates.append(temp) + + except Exception, detail: + logger.error("Exception: %s", detail) + + return templates + +def get_default_rasds(host_ip, type): + ac_id_list = [ "MemoryPool/0", + "DiskPool/%s" % default_pool_name, + ] + + if type == "LXC": + if const.LXC_netns_support is True: + ac_id_list.append("NetworkPool/%s" % default_network_name) + else: + ac_id_list.append("NetworkPool/%s" % default_network_name) + ac_id_list.append("ProcessorPool/0") + + templates = [] + + for id in ac_id_list: + rasd_list = get_rasd_templates(host_ip, type, id) + if len(rasd_list) < 1: + logger.info("No RASD templates returned for %s", id) + return [] + + for rasd in rasd_list: + if rasd['InstanceID'] == "Default": + templates.append(rasd) + + return templates + +def get_default_rasd_mofs(host_ip, type): + rasds = get_default_rasds(ip, virt) + + rasd_mofs = [] + + #FIXME for libcmpiutil versions 0.4 and later, inst_to_mof() is needed. + #This should be changed to rasd.tomof() once version 0.4 is obsolete. + for rasd in rasds: + rasd_mofs.append(inst_to_mof(rasd)) + + return rasd_mofs +

Kaitlin Rupert wrote:
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1223515128 25200 # Node ID 25b12a8b5257cd983e4926875dc619812fc1ce88 # Parent c2c64b0ee95d55ac09375f0a3518d60fd569ee7d [TEST] Add get_default_rasds() and get_rasd_templates() to rasd.py
NOTE: This patch only works with recent versions of pywbem (svn checkout of 09/04/2008 or later).
These functions can be used to get the template RASD instances. Instead of building instances by hand (see default_vssd_rasd_str()), the test cases should be using the template RASDs provided by the SettingsDefineCapabilities association.
get_rasd_templates() - returns the min, max, increment, and default template RASD instances for a given AllocationCapabilities instance.
get_default_rasds() - returns just the default template RASD instances for the resource pools.
Add inst_to_mof() to convert instances to mof format. This is only needed for libcmpiutil version 0.4 and older.
Add get_default_rasd_mofs() - returns default template RASDs in mof format.
Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com>
diff -r c2c64b0ee95d -r 25b12a8b5257 suites/libvirt-cim/lib/XenKvmLib/classes.py --- a/suites/libvirt-cim/lib/XenKvmLib/classes.py Wed Oct 08 12:59:17 2008 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/classes.py Wed Oct 08 18:18:48 2008 -0700 @@ -44,3 +44,18 @@
return cn[dash_index+1:]
+#FIXME This function is only needed for libcmpiutil versions 0.4 and later. +#Once version 0.4 is obsolete, this function should be removed. +def inst_to_mof(inst): + mof_str = inst.tomof() + + mof_inst = "" + + for str in mof_str.splitlines(): + if str.endswith('{') or not str.endswith('NULL;'): + mof_inst += "%s\n" % str + elif str.endswith('};'): + mof_inst += "%s\n" % str
The above two conditions can be combined as follows: if str.endswith('{') or str.endswith('};') or not str.endswith('NULL;'): Because all of them are mutually exclusive and will not occur on the same line at any given time. Any one of them is true we need to store the line. Any specific reason for having separate conditions instead of it having it in one.
+ + return mof_inst + diff -r c2c64b0ee95d -r 25b12a8b5257 suites/libvirt-cim/lib/XenKvmLib/rasd.py --- a/suites/libvirt-cim/lib/XenKvmLib/rasd.py Wed Oct 08 12:59:17 2008 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/rasd.py Wed Oct 08 18:18:48 2008 -0700 @@ -24,8 +24,11 @@ from CimTest.Globals import logger from CimTest.ReturnCodes import FAIL, PASS from XenKvmLib import vxml -from XenKvmLib.classes import get_typed_class - +from XenKvmLib import const +from XenKvmLib.classes import get_typed_class, get_class_type +from XenKvmLib.enumclass import GetInstance +from XenKvmLib.assoc import Associators +from XenKvmLib.const import default_pool_name, default_network_name
pasd_cn = 'ProcResourceAllocationSettingData' nasd_cn = 'NetResourceAllocationSettingData' @@ -165,3 +168,63 @@ memrasd_list['VirtualQuantity']) status = FAIL return status + +def get_rasd_templates(host_ip, type, pool_id): + ac_cn = get_typed_class(type, "AllocationCapabilities") + an_cn = get_typed_class(type, "SettingsDefineCapabilities") + + templates = [] + + try: + key_list = {"InstanceID" : pool_id } + + inst = GetInstance(host_ip, ac_cn, key_list) + + temps = Associators(host_ip, an_cn, ac_cn, InstanceID=inst.InstanceID) + + for temp in temps: + templates.append(temp) + + except Exception, detail: + logger.error("Exception: %s", detail) + + return templates + +def get_default_rasds(host_ip, type): + ac_id_list = [ "MemoryPool/0", + "DiskPool/%s" % default_pool_name, + ] + + if type == "LXC": + if const.LXC_netns_support is True: + ac_id_list.append("NetworkPool/%s" % default_network_name) + else: + ac_id_list.append("NetworkPool/%s" % default_network_name) + ac_id_list.append("ProcessorPool/0") + + templates = [] + + for id in ac_id_list: + rasd_list = get_rasd_templates(host_ip, type, id) + if len(rasd_list) < 1: + logger.info("No RASD templates returned for %s", id) + return [] + + for rasd in rasd_list: + if rasd['InstanceID'] == "Default": + templates.append(rasd) + + return templates + +def get_default_rasd_mofs(host_ip, type): + rasds = get_default_rasds(ip, virt) + + rasd_mofs = [] + + #FIXME for libcmpiutil versions 0.4 and later, inst_to_mof() is needed. + #This should be changed to rasd.tomof() once version 0.4 is obsolete. + for rasd in rasds: + rasd_mofs.append(inst_to_mof(rasd)) + + return rasd_mofs +
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1223567675 25200 # Node ID 1b152e5e9a47ec932b5c18bb26f226d5896b5432 # Parent 25b12a8b5257cd983e4926875dc619812fc1ce88 [TEST] Add VirtualSystemManagementService - 14_define_sys_disk.py This test defines a guest with a very large disk image. This test can be updated in the future to include other disk specific DefineSystem() tests. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 25b12a8b5257 -r 1b152e5e9a47 suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py Thu Oct 09 08:54:35 2008 -0700 @@ -0,0 +1,103 @@ +#!/usr/bin/python +# +# Copyright 2008 IBM Corp. +# +# Authors: +# Kaitlin Rupert <karupert@us.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 +# + +import sys +import os +from VirtLib.utils import run_remote +from CimTest.Globals import logger +from CimTest.ReturnCodes import FAIL, PASS +from XenKvmLib.const import do_main, _image_dir +from XenKvmLib.common_util import create_using_definesystem +from XenKvmLib.test_doms import destroy_and_undefine_domain +from XenKvmLib.classes import get_typed_class, inst_to_mof +from XenKvmLib.rasd import get_default_rasds +from XenKvmLib.vsms import get_vssd_class, default_vssd_rasd_str + +sup_types = ['Xen', 'XenFV', 'KVM', 'LXC'] +test_dom = 'rstest_disk_domain' + +def make_long_disk_path(ip): + path = os.path.join(_image_dir, 'cimtest_large_image') + + cmd = "dd if=/dev/zero of=%s bs=1M count=1 seek=8192" % path + + rc, out = run_remote(ip, cmd) + if rc != 0: + logger.error("Unable to create large disk image") + logger.error(out) + return None + + return path + +def get_vssd_rasd(ip, virt, addr): + class_vssd = get_vssd_class(virt) + vssd = class_vssd(test_dom, virt) + + vssd, rasd = default_vssd_rasd_str( + dom_name=test_dom, virt=virt) + + rasds = get_default_rasds(ip, virt) + + for i in range(0, len(rasds)): + if rasds[i]['PoolID'].find('DiskPool') >= 0: + rasds[i]['Address'] = addr + rasds[i] = inst_to_mof(rasds[i]) + + params = { 'vssd' : vssd, + 'rasd' : rasds + } + + return params + +@do_main(sup_types) +def main(): + options = main.options + + try: + addr = make_long_disk_path(options.ip) + if addr is None: + raise Exception("Unable to create large disk image") + + define_params = get_vssd_rasd(options.ip, options.virt, addr) + if len(define_params) != 2: + raise Exception("Unable to get VSSD and RASDs for %s" % test_dom) + + status = create_using_definesystem(test_dom, options.ip, + params=define_params, ref_config="", + virt=options.virt) + if status != PASS: + raise Exception("Unable to define %s" % test_dom) + + except Exception, details: + logger.error(details) + status = FAIL + + if os.path.exists(addr): + os.remove(addr) + + destroy_and_undefine_domain(test_dom, options.ip, options.virt) + + return status + +if __name__ == "__main__": + sys.exit(main()) +

Kaitlin Rupert wrote:
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1223567675 25200 # Node ID 1b152e5e9a47ec932b5c18bb26f226d5896b5432 # Parent 25b12a8b5257cd983e4926875dc619812fc1ce88 [TEST] Add VirtualSystemManagementService - 14_define_sys_disk.py
This test defines a guest with a very large disk image. This test can be updated in the future to include other disk specific DefineSystem() tests.
Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com>
diff -r 25b12a8b5257 -r 1b152e5e9a47 suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py Thu Oct 09 08:54:35 2008 -0700 @@ -0,0 +1,103 @@ +#!/usr/bin/python +# +# Copyright 2008 IBM Corp. +# +# Authors: +# Kaitlin Rupert <karupert@us.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 +# + +import sys +import os +from VirtLib.utils import run_remote +from CimTest.Globals import logger +from CimTest.ReturnCodes import FAIL, PASS +from XenKvmLib.const import do_main, _image_dir +from XenKvmLib.common_util import create_using_definesystem +from XenKvmLib.test_doms import destroy_and_undefine_domain +from XenKvmLib.classes import get_typed_class, inst_to_mof +from XenKvmLib.rasd import get_default_rasds +from XenKvmLib.vsms import get_vssd_class, default_vssd_rasd_str + +sup_types = ['Xen', 'XenFV', 'KVM', 'LXC'] +test_dom = 'rstest_disk_domain' + +def make_long_disk_path(ip): + path = os.path.join(_image_dir, 'cimtest_large_image') + + cmd = "dd if=/dev/zero of=%s bs=1M count=1 seek=8192" % path + + rc, out = run_remote(ip, cmd) + if rc != 0: + logger.error("Unable to create large disk image") + logger.error(out) + return None + + return path + +def get_vssd_rasd(ip, virt, addr): + class_vssd = get_vssd_class(virt) + vssd = class_vssd(test_dom, virt) + + vssd, rasd = default_vssd_rasd_str( + dom_name=test_dom, virt=virt)
The above line can be wrapped in a single 80 column line. We do not require default_vssd_rasd_str().
+ + rasds = get_default_rasds(ip, virt) + + for i in range(0, len(rasds)):
just range(len(rasds)) will work.
+ if rasds[i]['PoolID'].find('DiskPool') >= 0: + rasds[i]['Address'] = addr + rasds[i] = inst_to_mof(rasds[i]) + + params = { 'vssd' : vssd, + 'rasd' : rasds + } + + return params + +@do_main(sup_types) +def main(): + options = main.options + + try: + addr = make_long_disk_path(options.ip) + if addr is None: + raise Exception("Unable to create large disk image") + + define_params = get_vssd_rasd(options.ip, options.virt, addr) + if len(define_params) != 2: + raise Exception("Unable to get VSSD and RASDs for %s" % test_dom) + + status = create_using_definesystem(test_dom, options.ip, + params=define_params, ref_config="", + virt=options.virt) + if status != PASS: + raise Exception("Unable to define %s" % test_dom) + + except Exception, details: + logger.error(details) + status = FAIL + + if os.path.exists(addr): + os.remove(addr) + + destroy_and_undefine_domain(test_dom, options.ip, options.virt) + + return status + +if __name__ == "__main__": + sys.exit(main()) +
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim

+def get_vssd_rasd(ip, virt, addr): + class_vssd = get_vssd_class(virt) + vssd = class_vssd(test_dom, virt) + + vssd, rasd = default_vssd_rasd_str( + dom_name=test_dom, virt=virt)
The above line can be wrapped in a single 80 column line. We do not require default_vssd_rasd_str().
Yes, I meant to put a comment here that get_vssd_class() should be replaced by a function that returns a mof. Currently, get_vssd_class() returns an object that is prefixed by XenKvmLib.vsms.<>, which doesn't work properly when passed to the DefineSystem() call. default_vssd_rasd_str() strips this piece away when it calls .mof() on the class. I'll include a patch to fix this when I resend.
+ + rasds = get_default_rasds(ip, virt) + + for i in range(0, len(rasds)):
just range(len(rasds)) will work.
Good call =) -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Deepti B Kalakeri
-
Kaitlin Rupert