[PATCH 0 of 2] [Test] Patch and test for user defined UUID

Hello everyone, I like to submit patch for setting UUID by the user and a testcase to verify it. Thx Yogi

# HG changeset patch # User anantyog@linux.vnet.ibm.com # Date 1249473758 25200 # Node ID 0fe8417e16fce456f1a7049f196340bcb58a14d1 # Parent cb9ab2702c7b693c334bc6709fd71833e7fa843f [Test] Patch to set UUID in domain Patch enables the user to set the UUID while defining a domain Signed-off-by: Yogananth Subramanian <anantyog@linux.vnet.ibm.com> diff -r cb9ab2702c7b -r 0fe8417e16fc suites/libvirt-cim/lib/XenKvmLib/vsms.py --- a/suites/libvirt-cim/lib/XenKvmLib/vsms.py Tue Aug 04 05:20:41 2009 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/vsms.py Wed Aug 05 05:02:38 2009 -0700 @@ -90,7 +90,7 @@ # classes to define VSSD parameters class CIM_VirtualSystemSettingData(CIMClassMOF): - def __init__(self, name, virt, bldr=None, emulator=None): + def __init__(self, name, virt, uuid=None, bldr=None, emulator=None): type = get_class_type(self.__class__.__name__) self.InstanceID = '%s:%s' % (type, name) self.Caption = self.Description = 'Virtual System' @@ -115,6 +115,9 @@ if bldr is not None: self.Bootloader = bldr + if uuid is not None: + self.UUID = uuid + class Xen_VirtualSystemSettingData(CIM_VirtualSystemSettingData): pass diff -r cb9ab2702c7b -r 0fe8417e16fc suites/libvirt-cim/lib/XenKvmLib/vxml.py --- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Tue Aug 04 05:20:41 2009 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Wed Aug 05 05:02:38 2009 -0700 @@ -555,7 +555,7 @@ class VirtCIM: - def __init__(self, virt, dom_name, disk_dev, disk_source, + def __init__(self, virt, dom_name, uuid, disk_dev, disk_source, net_type, net_name, net_mac, vcpus, mem, mem_allocunits, emu_type, grstype, ip, port_num, kmap, irstype, btype, vnc_passwd): @@ -563,7 +563,7 @@ self.domain_name = dom_name self.err_rc = None self.err_desc = None - self.vssd = vsms.get_vssd_mof(virt, dom_name) + self.vssd = vsms.get_vssd_mof(virt, dom_name, uuid) self.nasd = vsms.get_nasd_class(virt)(type=net_type, mac=net_mac, name=dom_name, @@ -787,6 +787,7 @@ secondary_disk_path = const.Xen_secondary_disk_path def __init__(self, test_dom=const.default_domname, + uuid=None, mem=const.default_memory, mem_allocunits=const.default_mallocunits, vcpus=const.default_vcpus, @@ -807,7 +808,7 @@ self._os(const.Xen_kernel_path, const.Xen_init_path) self._devices(disk_file_path, disk, ntype, mac, net_name) - VirtCIM.__init__(self, 'Xen', test_dom, disk, disk_file_path, + VirtCIM.__init__(self, 'Xen', test_dom, uuid, disk, disk_file_path, ntype, net_name, mac, vcpus, mem, mem_allocunits, emu_type, grstype, address, port_num, keymap, irstype, btype, vnc_passwd) @@ -852,6 +853,7 @@ secondary_disk_path = const.KVM_secondary_disk_path def __init__(self, test_dom=const.default_domname, + uuid=None, mem=const.default_memory, mem_allocunits=const.default_mallocunits, vcpus=const.default_vcpus, @@ -867,7 +869,7 @@ logger.error('Error: Disk image does not exist') sys.exit(1) VirtXML.__init__(self, 'kvm', test_dom, set_uuid(), mem, vcpus) - VirtCIM.__init__(self, 'KVM', test_dom, disk, disk_file_path, + VirtCIM.__init__(self, 'KVM', test_dom, uuid, disk, disk_file_path, ntype, net_name, mac, vcpus, mem, mem_allocunits, emu_type, grstype, address, port_num, keymap, irstype, btype, vnc_passwd) @@ -907,6 +909,7 @@ secondary_disk_path = const.XenFV_secondary_disk_path def __init__(self, test_dom=const.default_domname, + uuid=None, mem=const.default_memory, mem_allocunits=const.default_mallocunits, vcpus=const.default_vcpus, @@ -922,7 +925,7 @@ logger.error('Error: Disk image does not exist') sys.exit(1) VirtXML.__init__(self, 'xenfv', test_dom, set_uuid(), mem, vcpus) - VirtCIM.__init__(self, 'XenFV', test_dom, disk, disk_file_path, + VirtCIM.__init__(self, 'XenFV', test_dom, uuid, disk, disk_file_path, ntype, net_name, mac, vcpus, mem, mem_allocunits, emu_type, grstype, address, port_num, keymap, irstype, btype, vnc_passwd) @@ -967,6 +970,7 @@ class LXCXML(VirtXML, VirtCIM): def __init__(self, test_dom=const.default_domname, + uuid=None, mem=const.default_memory, vcpus=const.default_vcpus, mac=const.LXC_default_mac, @@ -976,7 +980,7 @@ address="127.0.0.1", port_num='-1', keymap="en-us", irstype="mouse", btype="usb", vnc_passwd=None): VirtXML.__init__(self, 'lxc', test_dom, set_uuid(), mem, vcpus) - VirtCIM.__init__(self, 'LXC', test_dom, const.LXC_default_mp, + VirtCIM.__init__(self, 'LXC', test_dom, uuid, const.LXC_default_mp, const.LXC_default_source, ntype, net_name, mac, vcpus, mem, const.default_mallocunits, None, grstype, address, port_num, keymap, irstype, btype, vnc_passwd)

# HG changeset patch # User anantyog@linux.vnet.ibm.com # Date 1249473859 25200 # Node ID 9b1015d9ecc67d973be7a95df2bbabf6ba6632bd # Parent 0fe8417e16fce456f1a7049f196340bcb58a14d1 [Test] Test case to test setting UUID by user This test defines a domain with user specified UUID Signed-off-by: Yogananth Subramanian <anantyog@linux.vnet.ibm.com> diff -r 0fe8417e16fc -r 9b1015d9ecc6 suites/libvirt-cim/cimtest/VSSD/05_set_uuid.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/suites/libvirt-cim/cimtest/VSSD/05_set_uuid.py Wed Aug 05 05:04:19 2009 -0700 @@ -0,0 +1,86 @@ +#!/usr/bin/python +# +# Copyright 2009 IBM Corp. +# +# Authors: +# Yogananth Subramanian <anantyog@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 +# + +import sys +from XenKvmLib import vsms +from XenKvmLib import vxml +from CimTest.Globals import logger +from CimTest.ReturnCodes import PASS, FAIL +from XenKvmLib.const import do_main +from XenKvmLib.classes import get_typed_class +from XenKvmLib.enumclass import GetInstance + +sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] +default_dom = 'uuid_domain' +uuid = "05ea345a-4539-57d8-abb4-d4fc858641f3" + +def get_vssd(ip, virt, get_cim_inst): + cn = get_typed_class(virt, "VirtualSystemSettingData") + inst = None + + try: + if virt == "XenFV": + virt = "Xen" + + key_list = {"InstanceID" : "%s:%s" % (virt, default_dom) } + inst = GetInstance(ip, cn, key_list, get_cim_inst) + + except Exception, details: + logger.error(details) + return FAIL, inst + + if inst is None: + return FAIL, inst + + return PASS, inst + +@do_main(sup_types) +def main(): + options = main.options + + service = vsms.get_vsms_class(options.virt)(options.ip) + + cxml = vxml.get_class(options.virt)(default_dom, uuid=uuid) + ret = cxml.cim_define(options.ip) + if not ret: + logger.error("Failed to define the dom: %s", default_dom) + return FAIL + + try: + status, inst = get_vssd(options.ip, options.virt, True) + if status != PASS: + raise Exception("Failed to get the VSSD instance for %s"% + default_dom) + + if inst['UUID'] != uuid: + raise Exception(" UUID is differnet from the one set by the user") + + except Exception, details: + logger.error(details) + status = FAIL + + cxml.undefine(options.ip) + return status + +if __name__ == "__main__": + sys.exit(main()) +

Yogananth Subramanian wrote:
# HG changeset patch # User anantyog@linux.vnet.ibm.com # Date 1249473859 25200 # Node ID 9b1015d9ecc67d973be7a95df2bbabf6ba6632bd # Parent 0fe8417e16fce456f1a7049f196340bcb58a14d1 [Test] Test case to test setting UUID by user
This test defines a domain with user specified UUID
Signed-off-by: Yogananth Subramanian <anantyog@linux.vnet.ibm.com>
diff -r 0fe8417e16fc -r 9b1015d9ecc6 suites/libvirt-cim/cimtest/VSSD/05_set_uuid.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/suites/libvirt-cim/cimtest/VSSD/05_set_uuid.py Wed Aug 05 05:04:19 2009 -0700 @@ -0,0 +1,86 @@ +#!/usr/bin/python +# +# Copyright 2009 IBM Corp. +# +# Authors: +# Yogananth Subramanian <anantyog@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 +#
A small description will be good.
+ +import sys +from XenKvmLib import vsms +from XenKvmLib import vxml +from CimTest.Globals import logger +from CimTest.ReturnCodes import PASS, FAIL +from XenKvmLib.const import do_main +from XenKvmLib.classes import get_typed_class +from XenKvmLib.enumclass import GetInstance + +sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] +default_dom = 'uuid_domain' +uuid = "05ea345a-4539-57d8-abb4-d4fc858641f3"
Instead of hardcoding the uuid can you use randint() and generate some random values in the uuid may be something like "05ea345a-%s-57d8-abb4-d4fc858641f3" % randint(1000, 9999) or something similar.. Like that we hope that we are having a UUID which could be unique otherwise the test might just error out.
+ +def get_vssd(ip, virt, get_cim_inst): + cn = get_typed_class(virt, "VirtualSystemSettingData") + inst = None + + try: + if virt == "XenFV": + virt = "Xen" + + key_list = {"InstanceID" : "%s:%s" % (virt, default_dom) } + inst = GetInstance(ip, cn, key_list, get_cim_inst) + + except Exception, details: + logger.error(details) + return FAIL, inst + + if inst is None:
Error message will be good.
+ return FAIL, inst + + return PASS, inst + +@do_main(sup_types) +def main(): + options = main.options + + service = vsms.get_vsms_class(options.virt)(options.ip) + + cxml = vxml.get_class(options.virt)(default_dom, uuid=uuid) + ret = cxml.cim_define(options.ip) + if not ret: + logger.error("Failed to define the dom: %s", default_dom) + return FAIL
Better if we include the cim_define as well in the try..except block...
+ + try: + status, inst = get_vssd(options.ip, options.virt, True) + if status != PASS: + raise Exception("Failed to get the VSSD instance for %s"% + default_dom) + + if inst['UUID'] != uuid: + raise Exception(" UUID is differnet from the one set by the user")
would be good that we confirm the VVSD.ElementName has the expected domain name.
+ + except Exception, details: + logger.error(details) + status = FAIL + + cxml.undefine(options.ip) + 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

Deepti B Kalakeri wrote:
Yogananth Subramanian wrote:
# HG changeset patch # User anantyog@linux.vnet.ibm.com # Date 1249473859 25200 # Node ID 9b1015d9ecc67d973be7a95df2bbabf6ba6632bd # Parent 0fe8417e16fce456f1a7049f196340bcb58a14d1 [Test] Test case to test setting UUID by user
This test defines a domain with user specified UUID
Signed-off-by: Yogananth Subramanian <anantyog@linux.vnet.ibm.com>
diff -r 0fe8417e16fc -r 9b1015d9ecc6 suites/libvirt-cim/cimtest/VSSD/05_set_uuid.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/suites/libvirt-cim/cimtest/VSSD/05_set_uuid.py Wed Aug 05 05:04:19 2009 -0700 @@ -0,0 +1,86 @@ +#!/usr/bin/python +# +# Copyright 2009 IBM Corp. +# +# Authors: +# Yogananth Subramanian <anantyog@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 +#
A small description will be good.
+ +import sys +from XenKvmLib import vsms +from XenKvmLib import vxml +from CimTest.Globals import logger +from CimTest.ReturnCodes import PASS, FAIL +from XenKvmLib.const import do_main +from XenKvmLib.classes import get_typed_class +from XenKvmLib.enumclass import GetInstance + +sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] +default_dom = 'uuid_domain' +uuid = "05ea345a-4539-57d8-abb4-d4fc858641f3"
Instead of hardcoding the uuid can you use randint() and generate some random values in the uuid may be something like
"05ea345a-%s-57d8-abb4-d4fc858641f3" % randint(1000, 9999) or something similar.. Like that we hope that we are having a UUID which could be unique otherwise the test might just error out.
+ +def get_vssd(ip, virt, get_cim_inst): + cn = get_typed_class(virt, "VirtualSystemSettingData") + inst = None + + try: + if virt == "XenFV": + virt = "Xen" + + key_list = {"InstanceID" : "%s:%s" % (virt, default_dom) } + inst = GetInstance(ip, cn, key_list, get_cim_inst) + + except Exception, details: + logger.error(details) + return FAIL, inst + + if inst is None:
Error message will be good.
You can ignore this comment I did not see that you are checking for the error message below in the main function.
+ return FAIL, inst + + return PASS, inst + +@do_main(sup_types) +def main(): + options = main.options + + service = vsms.get_vsms_class(options.virt)(options.ip) + + cxml = vxml.get_class(options.virt)(default_dom, uuid=uuid) + ret = cxml.cim_define(options.ip) + if not ret: + logger.error("Failed to define the dom: %s", default_dom) + return FAIL
Better if we include the cim_define as well in the try..except block...
+ + try: + status, inst = get_vssd(options.ip, options.virt, True) + if status != PASS: + raise Exception("Failed to get the VSSD instance for %s"% + default_dom) + + if inst['UUID'] != uuid: + raise Exception(" UUID is differnet from the one set by the user")
would be good that we confirm the VVSD.ElementName has the expected domain name.
+ + except Exception, details: + logger.error(details) + status = FAIL + + cxml.undefine(options.ip) + return status + +if __name__ == "__main__": + sys.exit(main()) + _______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
Also, do you have enough time to come up with a test case to test if libvirt-cim throws an error when two domain uses the same UUID? -- Thanks and Regards, Deepti B. Kalakeri IBM Linux Technology Center deeptik@linux.vnet.ibm.com
participants (2)
-
Deepti B Kalakeri
-
Yogananth Subramanian