[PATCH 0 of 2] #2 Fixing 05_RAPF_err.py tc to support verification of exception when an invalid network name is passed.

Fixing 05_RAPF_err.py tc to support verification of exception when an invalid network name is passed.

# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1213780213 25200 # Node ID a4c2aedfe2c9d6a18e069542c17df1b0576ba933 # Parent f4a167c62403c8aaaac5127d0c984c74ea863344 [TEST] #2 Modifying the vxml.py Changes: -------
From patch 1 to 2:
1) Modified the XenXML, XenFVXML, KVMXML to support passing nettype info. Patch 1: -------- 1) Added xml_get_net_network() to get the network name. 2) Fixed the set_nettype(). These changes are needed to support the 05_RAPF_err.py tc. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r f4a167c62403 -r a4c2aedfe2c9 suites/libvirt-cim/lib/XenKvmLib/vxml.py --- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Tue Jun 17 13:20:47 2008 +0800 +++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Wed Jun 18 02:10:13 2008 -0700 @@ -310,8 +310,12 @@ bridge=bridgename) def set_nettype(self, nettype): - self.set_attributes('/domain/devices/interface/type', + self.set_attributes('/domain/devices/interface', type=nettype) + + def set_net_name(self, netname): + self.set_attributes('/domain/devices/interface/source', + network=netname) def set_diskimg(self, diskimg): self.set_attributes('/domain/devices/disk/source', file=diskimg) @@ -403,6 +407,12 @@ bridgeStr = self.get_value_xpath( '/domain/devices/interface/source/@bridge') return bridgeStr + + def xml_get_net_network(self): + networkStr = self.get_value_xpath( + '/domain/devices/interface/source/@network') + return networkStr + def dumpxml(self, ip): cmd = 'virsh -c %s dumpxml %s' % (self.vuri, self.dname) @@ -542,7 +552,8 @@ vcpus=const.default_vcpus, mac=const.Xen_default_mac, disk_file_path=const.Xen_disk_path, - disk=const.Xen_default_disk_dev): + disk=const.Xen_default_disk_dev, + ntype=const.default_net_type): if not (os.path.exists(const.Xen_kernel_path) \ and os.path.exists(const.Xen_init_path)): logger.error('ERROR: Either the kernel image ' @@ -550,10 +561,10 @@ sys.exit(1) VirtXML.__init__(self, 'xen', test_dom, set_uuid(), mem, vcpus) self._os(const.Xen_kernel_path, const.Xen_init_path) - self._devices(disk_file_path, disk, const.default_net_type, mac) + self._devices(disk_file_path, disk, ntype, mac) VirtCIM.__init__(self, 'Xen', test_dom, disk, disk_file_path, - const.default_net_type, mac, vcpus, mem) + ntype, mac, vcpus, mem) def _os(self, os_kernel, os_initrd): os = self.get_node('/domain/os') @@ -595,13 +606,14 @@ vcpus=const.default_vcpus, mac=const.KVM_default_mac, disk_file_path=const.KVM_disk_path, - disk=const.KVM_default_disk_dev): + disk=const.KVM_default_disk_dev, + ntype=const.default_net_type): if not os.path.exists(disk_file_path): logger.error('Error: Disk image does not exist') sys.exit(1) VirtXML.__init__(self, 'kvm', test_dom, set_uuid(), mem, vcpus) self._os() - self._devices(const.KVM_default_emulator, const.default_net_type, + self._devices(const.KVM_default_emulator, ntype, disk_file_path, disk, mac) def _os(self): @@ -636,7 +648,8 @@ vcpus=const.default_vcpus, mac=const.XenFV_default_mac, disk_file_path=const.XenFV_disk_path, - disk=const.XenFV_default_disk_dev): + disk=const.XenFV_default_disk_dev, + ntype=const.default_net_type): if not os.path.exists(disk_file_path): logger.error('Error: Disk image does not exist') sys.exit(1) @@ -644,7 +657,7 @@ self._features() self._os(const.XenFV_default_loader) self._devices(const.XenFV_default_emulator, - const.default_net_type, mac, disk_file_path, disk) + ntype, mac, disk_file_path, disk) def _features(self): features = self.get_node('/domain/features')

# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1213781722 25200 # Node ID bc724a2306e727f9bcabb1ee94d70d2ef551889b # Parent a4c2aedfe2c9d6a18e069542c17df1b0576ba933 [TEST] #2 Fixed the tc 05_RAPF_err.py. Changes: -------
From patch 1 to 2:
1) Removed the use of xml_string.replace used to modify the network info. 2) Modified the tc to use the XML support to pass the nettype info. 3) Moved the code used for newtork information to the modify_net_name() function. 4) Included the missing undefine statement. 5) Removed the support for Xen/XenFV for verification of exception when the network type interface is passed. This is bcs virsh does not support the creation of a guest with invalid networkpool. Patch: ------ 1) Added support for verifying the exception when an invalid network name is passed. 2) Modified get_unique_bridge() to now return non-existing bridgename/networkpoolnmae. 3) Modified the code to occupy 80 columns only. 4) Removed the global declaration of the virt and server and passed them as parameters to fn instead. This tc passed on KVM with latest sources and libvirt-cim rpm on F9. This tc fails for Xen/XenFV when an invalid networkpoolname. The libvirt does not support definining the Xen/XenFV guest with invalid network name. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r a4c2aedfe2c9 -r bc724a2306e7 suites/libvirt-cim/cimtest/ResourceAllocationFromPool/05_RAPF_err.py --- a/suites/libvirt-cim/cimtest/ResourceAllocationFromPool/05_RAPF_err.py Wed Jun 18 02:10:13 2008 -0700 +++ b/suites/libvirt-cim/cimtest/ResourceAllocationFromPool/05_RAPF_err.py Wed Jun 18 02:35:22 2008 -0700 @@ -53,48 +53,68 @@ from CimTest.Globals import logger, CIM_ERROR_ENUMERATE from CimTest.ReturnCodes import PASS, FAIL from CimTest.Globals import do_main, platform_sup -from XenKvmLib.vxml import get_class +from XenKvmLib import vxml from XenKvmLib.classes import get_typed_class test_dom = "RAPF_domain" test_mac = "00:11:22:33:44:aa" test_vcpus = 1 -def get_unique_bridge(): - bridge = "invalid-bridge" - bridge_list = live.available_bridges(server) - while bridge in bridge_list: - bridge = bridge + str(random.randint(1, 100)) +def get_unique_interface(server, virt, nettype='network'): + interface = "wrong-int" + if nettype == 'bridge': + int_list = live.available_bridges(server) + else: + int_list = live.net_list(server, virt) + + while interface in int_list: + interface = interface + str(random.randint(1, 100)) - return bridge + return interface -def setup_env(): +def modify_net_name(server, virt, nettype, vsxml): + if nettype == 'bridge': + int_name = vsxml.xml_get_net_bridge() + else: + int_name = vsxml.xml_get_net_network() + + if int_name == None: + devices = vsxml.get_node('/domain/devices') + vsxml.set_interface_details(devices, test_mac, nettype, virt) + + int_name = get_unique_interface(server, virt, nettype) + + if nettype == 'bridge': + vsxml.set_bridge_name(int_name) + else: + vsxml.set_net_name(int_name) + + return vsxml + +def setup_env(server, virt, nettype='network'): vsxml_info = None if virt == "Xen": test_disk = "xvda" else: test_disk = "hda" - virt_xml = get_class(virt) - vsxml_info = virt_xml(test_dom, vcpus = test_vcpus, mac = test_mac, disk = test_disk) + virt_xml = vxml.get_class(virt) + vsxml_info = virt_xml(test_dom, vcpus = test_vcpus, + mac = test_mac, disk = test_disk, + ntype = nettype) - bridge = vsxml_info.xml_get_net_bridge() - if bridge == None: - bridge = vsxml_info.set_vbridge(server) + vsxml_info = modify_net_name(server, virt, nettype, vsxml_info) -# Get a bridge name that is not used by any of the virtual network pool on the machine. - bridge_name = get_unique_bridge() - -# Assigning the bridge that does not belong to any networkpool. - vsxml_info.set_bridge_name(bridge_name) ret = vsxml_info.define(server) if not ret: - Globals.logger.error("Failed to define the dom: %s", test_dom) + Globals.logger.error("Failed to define the dom '%s' for '%s' type" + " interface", test_dom, nettype) return FAIL, vsxml_info return PASS, vsxml_info -def get_inst_from_list(vsxml, classname, rasd_list, filter_name, exp_val): +def get_inst_from_list(server, vsxml, classname, rasd_list, filter_name, + exp_val): status = PASS ret = FAIL inst = [] @@ -112,14 +132,14 @@ return status, inst -def get_netrasd_instid(vsxml, classname): +def get_netrasd_instid(server, virt, vsxml, classname): rasd_list = [] status = PASS try: rasd_list = enumclass.enumerate_inst(server, classname, virt) if len(rasd_list) < 1: - logger.error("%s returned %i instances, excepted atleast 1 instance", classname, - len(rasd_list)) + logger.error("%s returned %i instances, excepted atleast 1 " + "instance", classname, len(rasd_list)) status = FAIL except Exception, detail: logger.error(CIM_ERROR_ENUMERATE, classname) @@ -132,21 +152,22 @@ # Get the RASD info related to the domain "ONLY". # We should get ONLY one record. rasd_info = [] - status, rasd_info = get_inst_from_list(vsxml, classname, rasd_list, "InstanceID", test_dom) + status, rasd_info = get_inst_from_list(server, vsxml, classname, + rasd_list, "InstanceID", test_dom) return status, rasd_info -def verify_rapf_err(vsxml): +def verify_rapf_err(server, virt, vsxml): status = PASS try: classname = get_typed_class(virt, 'NetResourceAllocationSettingData') - status, net_rasd_list = get_netrasd_instid(vsxml, classname) + status, net_rasd_list = get_netrasd_instid(server, virt, vsxml, classname) if status != PASS or len(net_rasd_list) == 0: return status if len(net_rasd_list) != 1: - logger.error("%s returned %i instances, excepted atleast 1 instance", classname, - len(net_rasd_list)) + logger.error("%s returned %i instances, excepted atleast 1 " + "instance", classname, len(net_rasd_list)) return FAIL @@ -160,12 +181,14 @@ keys = { "InstanceID" : instid } expr_values = { 'rapf_err' : { - 'desc' : "Unable to determine pool of `%s'" %instid, + 'desc' : "Unable to determine pool of " \ + "`%s'" %instid, 'rc' : pywbem.CIM_ERR_FAILED } } - status = try_assoc(conn, classname, assoc_classname, keys, field_name="InstanceID", - expr_values=expr_values['rapf_err'], bug_no="") + status = try_assoc(conn, classname, assoc_classname, keys, + field_name="InstanceID", + expr_values=expr_values['rapf_err'], bug_no="") except Exception, detail: logger.error("Exception: %s", detail) @@ -175,21 +198,29 @@ @do_main(platform_sup) def main(): - global virt, server options = main.options server = options.ip virt = options.virt destroy_and_undefine_all(server) + in_list = [ 'bridge', 'network' ] - status, vsxml = setup_env() - if status != PASS: - logger.error("Failed to setup the domain") - return status + for interface in in_list: + # This is req bcs virsh does not support the defining a guest + # when an invalid network poolname is passed. + if interface == 'network' and virt != 'KVM': + continue - ret = verify_rapf_err(vsxml) - if ret: - logger.error("------FAILED: to verify the RAFP.------") - status = ret + status, vsxml = setup_env(server, virt, interface) + if status != PASS: + logger.error("Failed to setup the domain") + vsxml.undefine(server) + return status + + ret = verify_rapf_err(server, virt, vsxml) + if ret: + logger.error("------FAILED: to verify the RAFP.------") + vsxml.undefine(server) + return ret vsxml.undefine(server) return status
participants (1)
-
Deepti B. Kalakeri