[PATCH 0 of 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 1213711149 25200 # Node ID 9700e5130a511e8a5457ba3033eb57d7b0b6a656 # Parent 6652ca49942c0314ec1b2b1da504810325097250 [TEST] Modifying the vxml.py 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 6652ca49942c -r 9700e5130a51 suites/libvirt-cim/lib/XenKvmLib/vxml.py --- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Thu Jun 12 17:13:23 2008 +0800 +++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Tue Jun 17 06:59:09 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)

# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1213711825 25200 # Node ID 73d199833bce1a21f374a1c8c95885a749e955cc # Parent 9700e5130a511e8a5457ba3033eb57d7b0b6a656 [TEST] Fixed the tc 05_RAPF_err.py. 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 9700e5130a51 -r 73d199833bce suites/libvirt-cim/cimtest/ResourceAllocationFromPool/05_RAPF_err.py --- a/suites/libvirt-cim/cimtest/ResourceAllocationFromPool/05_RAPF_err.py Tue Jun 17 06:59:09 2008 -0700 +++ b/suites/libvirt-cim/cimtest/ResourceAllocationFromPool/05_RAPF_err.py Tue Jun 17 07:10:25 2008 -0700 @@ -53,48 +53,65 @@ 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 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) - bridge = vsxml_info.xml_get_net_bridge() - if bridge == None: - bridge = vsxml_info.set_vbridge(server) + int_name = vsxml_info.xml_get_net_network() + if int_name == None: + devices = vsxml_info.get_node('/domain/devices') + vsxml_info.set_interface_details(devices, test_mac, nettype, virt) -# Get a bridge name that is not used by any of the virtual network pool on the machine. - bridge_name = get_unique_bridge() + int_name = get_unique_interface(server, virt, nettype) + vsxml_net_type = vsxml_info.xml_get_net_type() + if vsxml_net_type == 'bridge': + vsxml_info.set_bridge_name(int_name) + else: + vsxml_info.set_net_name(int_name) -# Assigning the bridge that does not belong to any networkpool. - vsxml_info.set_bridge_name(bridge_name) + if vsxml_net_type != 'bridge' and nettype == 'bridge': + vsxml_info.set_nettype(nettype) + in_string = 'network="%s"' %int_name + out_string = 'bridge="%s"' %int_name + vsxml_replace = (vsxml_info.xml_string.replace(in_string, out_string)) + vsxml_info.xml_string = vsxml_replace + 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 +129,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 +149,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 +178,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 +195,23 @@ @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: + status, vsxml = setup_env(server, virt, interface) + if status != PASS: + logger.error("Failed to setup the domain") + return status - ret = verify_rapf_err(vsxml) - if ret: - logger.error("------FAILED: to verify the RAFP.------") - status = ret + 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

Deepti B. Kalakeri wrote:
# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1213711825 25200 # Node ID 73d199833bce1a21f374a1c8c95885a749e955cc # Parent 9700e5130a511e8a5457ba3033eb57d7b0b6a656 [TEST] Fixed the tc 05_RAPF_err.py.
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.
This test is creating invalid guests - you won't be able to start the KVM guest, even though the define succeeds. It's good to have a test to make sure we handle broken guests properly. Since this isn't supported for Xen/XenFV - this test should skip instead of failine. It'd also be good to have a test where we create a valid guest with a network device that isn't part of a pool. For Xen/XenFV guests, this can be done using an ethernet interface. It should be possible to do something similar with KVM and the user interface type, but I've not tried this. I'll add this test case idea to the wiki to keep track of it.
Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com>
diff -r 9700e5130a51 -r 73d199833bce suites/libvirt-cim/cimtest/ResourceAllocationFromPool/05_RAPF_err.py
vsxml_info.set_net_name(int_name)
-# Assigning the bridge that does not belong to any networkpool. - vsxml_info.set_bridge_name(bridge_name) + if vsxml_net_type != 'bridge' and nettype == 'bridge': + vsxml_info.set_nettype(nettype) + in_string = 'network="%s"' %int_name + out_string = 'bridge="%s"' %int_name + vsxml_replace = (vsxml_info.xml_string.replace(in_string, out_string)) + vsxml_info.xml_string = vsxml_replace
Instead of hacking the xml_string directly, could something like set_interface_details() be modified to change the existing interface? Or maybe a new function for this? Another option would be to allow the KVMXML (etc) init call to take a network type. That way, you could create an XML of whatever interface type you'd like (instead of modifying it afterwards).
@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: + status, vsxml = setup_env(server, virt, interface) + if status != PASS:
You'll need to undefine the guest here. Even though virsh is returning an error, the guest is being defined.
+ logger.error("Failed to setup the domain") + return status
-- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Deepti B. Kalakeri
-
Kaitlin Rupert