[PATCH 0/4] cimtest - VLAN extension

These patches would add basic testcases about modifying host networks. Additional usecases such as association was not included. With this user could understand the usecase easier and also reduce the testing burden when libvirt-cim code was modified. It works with libvirt-cim V2 patch, and it should also work with later changes, if the test cases were confirmed to be correct scenior according to DSP profiles. Wayne Xia (4): cimtest - VLAN extension - add basic functions cimtest - VLAN extension - bridge testing cimtest - VLAN extension - 802.1.q port testing cimtest - VLAN extension - connecting of bridge and port .../cimtest/HostNetwork/01_VESSMS_Bridge.py | 78 ++++ .../cimtest/HostNetwork/02_VESSMS_EASD_EA.py | 84 ++++ .../cimtest/HostNetwork/03_VESSMS_EASD_EC.py | 101 +++++ suites/libvirt-cim/lib/XenKvmLib/host_network.py | 410 ++++++++++++++++++++ 4 files changed, 673 insertions(+), 0 deletions(-) create mode 100644 suites/libvirt-cim/cimtest/HostNetwork/01_VESSMS_Bridge.py create mode 100644 suites/libvirt-cim/cimtest/HostNetwork/02_VESSMS_EASD_EA.py create mode 100644 suites/libvirt-cim/cimtest/HostNetwork/03_VESSMS_EASD_EC.py create mode 100644 suites/libvirt-cim/lib/XenKvmLib/host_network.py -- 1.7.6

this file adding basic functions for configuration of host network Signed-off-by: Wayne Xia <xiawenc@linux.vnet.ibm.com> --- suites/libvirt-cim/lib/XenKvmLib/host_network.py | 410 ++++++++++++++++++++++ 1 files changed, 410 insertions(+), 0 deletions(-) create mode 100644 suites/libvirt-cim/lib/XenKvmLib/host_network.py diff --git a/suites/libvirt-cim/lib/XenKvmLib/host_network.py b/suites/libvirt-cim/lib/XenKvmLib/host_network.py new file mode 100644 index 0000000..d74b711 --- /dev/null +++ b/suites/libvirt-cim/lib/XenKvmLib/host_network.py @@ -0,0 +1,410 @@ +#!/usr/bin/env python + +# +# Copyright 2011 IBM Corp. +# +# Authors: +# Wenchao Xia (Wayne) <xiawenc@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 file have basic functions for testing of host network in libvirt-cim + + +import sys +import os +import pywbem + +from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS +from XenKvmLib.classes import get_typed_class +from XenKvmLib.vxml import get_class + +network_clas_prefix = "Net" +vesssd_parent = "Virt" +vs_prefix = "VS_" +ea_prefix = "EA_" +ec_prefix = "EC_" +delimiter_System = """:""" +delimiter_Device = """/""" + +vess_cls_name = "Net_VirtualEthernetSwitchSystem" +vessms_cls_name = "VirtualEthernetSwitchSystemManagementService" +vesssd_cls_name = "Net_VirtualEthernetSwitchSystemSettingData" +easd_cls_name = "Net_EthernetPortAllocationSettingData" + +vlan_8021q_type = 1 + +bridge_pNIC = "test_br1" +bridge_name = """%s%s""" % (vs_prefix, bridge_pNIC) +bridge_stp = 0 +bridge_stp_modify = 1 + + +def set_vs_define(inst): + return """ +instance of %s { + VirtualSystemIdentifier="%s"; + STP=%d; +};""" % (vesssd_cls_name, + inst["VirtualSystemIdentifier"], + inst["STP"],) + +def set_vs_modify(inst): + return """ +instance of %s { + VirtualSystemIdentifier="%s"; + STP=%d; +};""" % (vesssd_cls_name, + inst["VirtualSystemIdentifier"], + inst["STP"],) + + +def set_vs_destroy(inst): + inst = pywbem.CIMInstanceName(classname=vess_cls_name, keybindings=pywbem.NocaseDict({'CreationClassName': vess_cls_name, 'Name': inst["Name"]})) + return inst + +def get_vessms(cim): + virt = network_clas_prefix + _class = get_typed_class(virt, vessms_cls_name) + sys_mgmt_service = cim.EnumerateInstanceNames(_class)[0] + #it is not supposed to fail here, the enum of VESSMS is very simple + logger.info("got vessms as: %s.", sys_mgmt_service) + return sys_mgmt_service + +def check_vesssd(cim, targetInst, compareAll = False): + #check the result + _class = vesssd_cls_name + vesssd = cim.EnumerateInstances(_class) + targetID = targetInst["Name"] + instanceList = "" + found = 0 + for inst in vesssd: + items = inst.items() + instanceList += str(items)+ "\n" + (prefix, ID) = inst["InstanceID"].split(":",1) + cmp_ret = cmp(ID, targetID) or cmp(prefix, vesssd_parent) + if cmp_ret == 0: + logger.info("found the device., it is :\n %s", str(items)) + if compareAll == False : + found = 1 + else : + if inst["STP"] == targetInst["STP"]: + found = 1 + #logger.info("search for %s, found is %d, list is: \n%s", _class, found, instanceList) + logger.info("target vesssd searching result is %d.", found) + return found + +def try_delete_vs(cim, sys_mgmt_service, inst): + #delete the bridge + val = set_vs_destroy(inst) + method = "DestroySystem" + par_name = "AffectedSystem" + param = {par_name: val} + logger.info("trying method %s of %s with parameter:\n %s", method, sys_mgmt_service, param) + ret = cim.InvokeMethod(method, sys_mgmt_service, **param) + found = check_vesssd(cim, inst) + if found == 1 : + return 0 + else : + return 1 + +def try_create_vs(cim, sys_mgmt_service, inst): + #Check the Env + found = check_vesssd(cim, inst) + if found == 1: + logger.info("device exist, trying delete it"); + ret = try_delete_vs(cim, sys_mgmt_service, inst) + if ret != 1: + return 0 + + #add the bridge + val = set_vs_define(inst) + method = "DefineSystem" + logger.info("try method %s of %s with parameter %s", method, sys_mgmt_service, val) + ret = cim.InvokeMethod(method, sys_mgmt_service, **{"SystemSettings": val}) + found = check_vesssd(cim, inst) + if found == 1 : + return 1 + else : + return 0 + +def try_modify_vs(cim, sys_mgmt_service, inst): + #modify the bridge + val = set_vs_modify(inst) + method = "ModifySystemSettings" + par_name = "SystemSettings" + param = {par_name: val} + logger.info("trying method %s of %s with parameter:\n %s", method, sys_mgmt_service, param) + ret = cim.InvokeMethod(method, sys_mgmt_service, **param) + found = check_vesssd(cim, inst, True) + if found == 1 : + return 1 + else : + return 0 + + +#inst should be: +#{'Parent': "eth0", 'VLanID':10, 'ReorderHdr':1, 'Ingress':"1:2 2:3", 'Egress':'2:4'} +def set_ea_add_8021q(inst): + ParentSystem = """%s%s""" % (vs_prefix, inst['Parent']) + AffectedID = """%s%s%s""" % (vesssd_parent, delimiter_System, ParentSystem) + AffectedConfiguration = pywbem.CIMInstanceName(classname= vesssd_cls_name, keybindings=pywbem.NocaseDict({'InstanceID': AffectedID})) + EA_ID = """%s%s.%d""" % (ea_prefix, inst['Parent'], inst['VLanID']) + InstanceID_EA = """%s%s%s""" % (ParentSystem, delimiter_Device, EA_ID) + ea1 = """ +instance of %s { + InstanceID ="%s"; + VLANType = %d; + Connection = {"VLAN%d"}; + ReorderHdr = %d; + VLANQosIngress = "%s"; + VLANQosEgress = "%s"; +};""" % (easd_cls_name, + InstanceID_EA, + vlan_8021q_type, + inst["VLanID"], + inst["ReorderHdr"], + inst["Ingress"], + inst["Egress"]) + final_param = {"AffectedConfiguration" : AffectedConfiguration, "ResourceSettings" : [ea1,]} + return final_param + +def set_ea_mod_8021q(inst): + ParentSystem = """%s%s""" % (vs_prefix, inst['Parent']) + EA_ID = """%s%s.%d""" % (ea_prefix, inst['Parent'], inst['VLanID']) + InstanceID_EA = """%s%s%s""" % (ParentSystem, delimiter_Device, EA_ID) + ea1 = """ +instance of %s { + InstanceID ="%s"; + VLANType = %d; + Connection = {"VLAN%d"}; + ReorderHdr = %d; + VLANQosIngress = "%s"; + VLANQosEgress = "%s"; +};""" % (easd_cls_name, + InstanceID_EA, + vlan_8021q_type, + inst["VLanID"], + inst["ReorderHdr"], + inst["Ingress"], + inst["Egress"]) + final_param = {"ResourceSettings" : [ea1,]} + return final_param + +def set_ea_del_8021q(inst): + ParentSystem = """%s%s""" % (vs_prefix, inst['Parent']) + EA_ID = """%s%s.%d""" % (ea_prefix, inst['Parent'], inst['VLanID']) + InstanceID_EA = """%s%s%s""" % (ParentSystem, delimiter_Device, EA_ID) + del_ref = pywbem.CIMInstanceName(classname= easd_cls_name, keybindings=pywbem.NocaseDict({'InstanceID': InstanceID_EA})) + final_param = {"ResourceSettings" : [del_ref,],} + return final_param + + +def check_easd_ea(cim, targetInst, compareAll = False): + #check the result + _class = easd_cls_name + easds = cim.EnumerateInstances(_class) + + inst = targetInst + ParentSystem = """%s%s""" % (vs_prefix, inst['Parent']) + EA_ID = """%s%s.%d""" % (ea_prefix, inst['Parent'], inst['VLanID']) + InstanceID_EA = """%s%s%s""" % (ParentSystem, delimiter_Device, EA_ID) + vlanstr = """VLAN%d""" % (inst['VLanID']) + + instanceList = "" + found = 0 + for inst in easds: + items = inst.items() + instanceList += str(items)+ "\n" + cmp_ret = cmp(inst["InstanceID"], InstanceID_EA) + if cmp_ret == 0: + logger.info("found the device., it is :\n %s", str(items)) + if compareAll == False : + cmp_ret = cmp(inst["Connection"][0], vlanstr) + if cmp_ret == 0: + found = 1 + else : + found = 1 + if inst["ReorderHdr"] != targetInst["ReorderHdr"]: + found = 0 + cmp_ret = cmp(inst["VLANQosIngress"], targetInst["Ingress"]) + if cmp_ret != 0 : + found = 0 + cmp_ret = cmp(inst["VLANQosEgress"], targetInst["Egress"]) + if cmp_ret != 0 : + found = 0 + #logger.info("search for %s, found is %d, list is: \n%s", _class, found, instanceList) + logger.info("target easd searching result is %d.", found) + return found + +def try_del_ea(cim, sys_mgmt_service, inst): + param = set_ea_del_8021q(inst) + method = "RemoveResourceSettings" + logger.info("trying method %s of %s with parameter:\n %s", method, sys_mgmt_service, param) + ret = cim.InvokeMethod(method, sys_mgmt_service, **param) + found = check_easd_ea(cim, inst) + if found == 1 : + return 0 + else : + return 1 + +def try_mod_ea(cim, sys_mgmt_service, inst): + param = set_ea_mod_8021q(inst) + method = "ModifyResourceSettings" + logger.info("trying method %s of %s with parameter:\n %s", method, sys_mgmt_service, param) + ret = cim.InvokeMethod(method, sys_mgmt_service, **param) + found = check_easd_ea(cim, inst, True) + if found == 1 : + return 1 + else : + return 0 + + +def try_add_ea(cim, sys_mgmt_service, inst): + #Check the Env + found = check_easd_ea(cim, inst) + if found == 1: + logger.info("device exist, trying delete it"); + ret = try_del_ea(cim, sys_mgmt_service, inst) + if ret != 1: + return 0 + + param = set_ea_add_8021q(inst) + method = "AddResourceSettings" + logger.info("trying method %s of %s with parameter:\n %s", method, sys_mgmt_service, param) + ret = cim.InvokeMethod(method, sys_mgmt_service, **param) + found = check_easd_ea(cim, inst) + if found == 1 : + return 1 + else : + return 0 + + +#inst should be: +#{'ParentBridge': "eth0", 'EthPort':eth0.10, 'TargetBridge': "test_br"} +def set_ec_add(inst): + ParentSystem = """%s%s""" % (vs_prefix, inst['ParentBridge']) + TargetSystem = """%s%s""" % (vs_prefix, inst['TargetBridge']) + AffectedID = """%s%s%s""" % (vesssd_parent, delimiter_System, ParentSystem) + AffectedConfiguration = pywbem.CIMInstanceName(classname= vesssd_cls_name, keybindings=pywbem.NocaseDict({'InstanceID': AffectedID})) + EA_ID = """%s%s""" % (ea_prefix, inst['EthPort']) + EC_ID = """%s%s""" % (ec_prefix, inst['EthPort']) + InstanceID_EA = """%s%s%s""" % (ParentSystem, delimiter_Device, EA_ID) + InstanceID_EC = """%s%s%s""" % (ParentSystem, delimiter_Device, EC_ID) + ea1 = """ +instance of %s { + InstanceID ="%s"; + HostResource = {"%s"}; + Parent = "%s"; +};""" % (easd_cls_name, + InstanceID_EC, + TargetSystem, + InstanceID_EA) + final_param = {"AffectedConfiguration" : AffectedConfiguration, "ResourceSettings" : [ea1,]} + return final_param + +def set_ec_del(inst): + ParentSystem = """%s%s""" % (vs_prefix, inst['ParentBridge']) + EC_ID = """%s%s""" % (ec_prefix, inst['EthPort']) + InstanceID_EC = """%s%s%s""" % (ParentSystem, delimiter_Device, EC_ID) + del_ref = pywbem.CIMInstanceName(classname= easd_cls_name, keybindings=pywbem.NocaseDict({'InstanceID': InstanceID_EC})) + final_param = {"ResourceSettings" : [del_ref,],} + return final_param + +def check_easd_ec(cim, targetInst, compareAll = False): + #check the result + _class = easd_cls_name + easds = cim.EnumerateInstances(_class) + + inst = targetInst + ParentSystem = """%s%s""" % (vs_prefix, inst['ParentBridge']) + TargetSystem = """%s%s""" % (vs_prefix, inst['TargetBridge']) + EC_ID = """%s%s""" % (ec_prefix, inst['EthPort']) + InstanceID_EC0 = """%s%s%s""" % (ParentSystem, delimiter_Device, EC_ID) + InstanceID_EC1 = """%s%s%s""" % (TargetSystem, delimiter_Device, EC_ID) + + instanceList = "" + EC0_found = 0 + EC1_found = 0 + for inst in easds: + items = inst.items() + instanceList += str(items)+ "\n" + cmp_ret = cmp(inst["InstanceID"], InstanceID_EC0) + if cmp_ret == 0: + logger.info("found the ec0., it is :\n %s", str(items)) + EC0_found = 1 + else : + cmp_ret = cmp(inst["InstanceID"], InstanceID_EC1) + if cmp_ret == 0: + logger.info("found the ec1., it is :\n %s", str(items)) + EC1_found = 1 + #logger.info("search for %s, list is: \n%s", _class, instanceList) + found = EC0_found and EC1_found + logger.info("target easd_ec searching result is %d and %d.", EC0_found, EC1_found) + if EC0_found != EC1_found : + logger.info("not all ec found as expected.") + found = -1 + return found + +def try_del_ec(cim, sys_mgmt_service, inst): + param = set_ec_del(inst) + method = "RemoveResourceSettings" + logger.info("trying method %s of %s with parameter:\n %s", method, sys_mgmt_service, param) + ret = cim.InvokeMethod(method, sys_mgmt_service, **param) + found = check_easd_ec(cim, inst) + if found == 0 : + return 1 + else : + return 0 + +def try_add_ec(cim, sys_mgmt_service, inst): + #Check the Env + found = check_easd_ec(cim, inst) + if found != 0: + logger.info("device exist, trying delete it"); + ret = try_del_ec(cim, sys_mgmt_service, inst) + if ret != 1: + return 0 + + param = set_ec_add(inst) + method = "AddResourceSettings" + logger.info("trying method %s of %s with parameter:\n %s", method, sys_mgmt_service, param) + ret = cim.InvokeMethod(method, sys_mgmt_service, **param) + found = check_easd_ec(cim, inst) + if found == 1 : + return 1 + else : + return 0 + +def FoundOnePNIC(cim): + #check the result + _class = vesssd_cls_name + vesssd = cim.EnumerateInstances(_class) + EthList = [] + found = 0 + for inst in vesssd: + (prefix, ID) = inst["InstanceID"].split(":",1) + if ID.find(vs_prefix) == 0 : + realname = ID[len(vs_prefix):] + if realname.find("eth") == 0 and realname.find(".") == -1 : + found = 1 + EthList.append(realname) + #logger.info("search for %s, found is %d, list is: \n%s", _class, found, instanceList) + ret_name = None + if found == 1 : + ret_name = EthList[0] + logger.info("pNIC searching result is %d, list %s, ret is %s.", found, EthList, ret_name) + return ret_name -- 1.7.6

test case about creating, modifying, deleting bridges Signed-off-by: Wayne Xia <xiawenc@linux.vnet.ibm.com> --- .../cimtest/HostNetwork/01_VESSMS_Bridge.py | 78 ++++++++++++++++++++ 1 files changed, 78 insertions(+), 0 deletions(-) create mode 100644 suites/libvirt-cim/cimtest/HostNetwork/01_VESSMS_Bridge.py diff --git a/suites/libvirt-cim/cimtest/HostNetwork/01_VESSMS_Bridge.py b/suites/libvirt-cim/cimtest/HostNetwork/01_VESSMS_Bridge.py new file mode 100644 index 0000000..2c03d0c --- /dev/null +++ b/suites/libvirt-cim/cimtest/HostNetwork/01_VESSMS_Bridge.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python + +# +# Copyright 2011 IBM Corp. +# +# Authors: +# Wenchao Xia (Wayne) <xiawenc@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 +# + +# +# Create ,modify, delete a soft virtual switch system +# +# + +import sys +import os +import pywbem + +from CimTest.ReturnCodes import PASS, FAIL, XFAIL, SKIP +from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS +from XenKvmLib.const import do_main +from XenKvmLib.classes import get_typed_class +from XenKvmLib.vxml import get_class +from XenKvmLib import host_network + +cim = None +sys_mgmt_service = None +supported = ['KVM',] + +@do_main(supported) +def main(): + options = main.options + server = options.ip + server_url = "http://%s" % server + #global cim + cim = pywbem.WBEMConnection(server_url, (CIM_USER, CIM_PASS), CIM_NS) + + sys_mgmt_service = host_network.get_vessms(cim) + + #add the bridge + inst = {'VirtualSystemIdentifier':host_network.bridge_name, 'STP': host_network.bridge_stp, 'Name': host_network.bridge_name} + + ret = host_network.try_create_vs(cim, sys_mgmt_service, inst) + if ret != 1: + logger.error("Failed to add cim bridge") + return FAIL + + inst["STP"] = host_network.bridge_stp_modify + ret = host_network.try_modify_vs(cim, sys_mgmt_service, inst) + if ret != 1: + logger.error("Failed to modify cim bridge") + return FAIL + + ret = host_network.try_delete_vs(cim, sys_mgmt_service, inst) + if ret != 1: + logger.error("Failed to delete cim bridge") + return FAIL + return PASS + +# main() + +if __name__ == "__main__": + ret = main() + sys.exit(ret) -- 1.7.6

test case for 802.1.q virtual vlan child port on host Signed-off-by: Wayne Xia <xiawenc@linux.vnet.ibm.com> --- .../cimtest/HostNetwork/02_VESSMS_EASD_EA.py | 84 ++++++++++++++++++++ 1 files changed, 84 insertions(+), 0 deletions(-) create mode 100644 suites/libvirt-cim/cimtest/HostNetwork/02_VESSMS_EASD_EA.py diff --git a/suites/libvirt-cim/cimtest/HostNetwork/02_VESSMS_EASD_EA.py b/suites/libvirt-cim/cimtest/HostNetwork/02_VESSMS_EASD_EA.py new file mode 100644 index 0000000..2963afc --- /dev/null +++ b/suites/libvirt-cim/cimtest/HostNetwork/02_VESSMS_EASD_EA.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python + +# +# Copyright 2011 IBM Corp. +# +# Authors: +# Wenchao Xia (Wayne) <xiawenc@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 +# + +# +# Create, Modify, Delete IEEE802.1.q child port +# +# + +import sys +import os +import pywbem + +from CimTest.ReturnCodes import PASS, FAIL, XFAIL, SKIP +from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS +from XenKvmLib.const import do_main +from XenKvmLib.classes import get_typed_class +from XenKvmLib.vxml import get_class +from XenKvmLib import host_network + +cim = None +sys_mgmt_service = None +supported = ['KVM',] + + +@do_main(supported) +def main(): + options = main.options + server = options.ip + server_url = "http://%s" % server + #global cim + cim = pywbem.WBEMConnection(server_url, (CIM_USER, CIM_PASS), CIM_NS) + + sys_mgmt_service = host_network.get_vessms(cim) + pNIC = host_network.FoundOnePNIC(cim) + if pNIC == None : + logger.error("Failed to find any pNIC on the host.") + return FAIL + + inst = {'Parent': pNIC, 'VLanID':10, 'ReorderHdr':1, 'Ingress':"1:2 2:3", 'Egress':'2:4'} + ret = host_network.try_add_ea(cim, sys_mgmt_service, inst) + if ret != 1: + logger.error("Failed to add 802.1.q ea") + return FAIL + + inst['ReorderHdr'] = 0 + inst['Ingress'] = "0:1 1:2 2:3 3:4 4:5 5:6 6:7 7:0" + inst['Egress'] = "0:0 1:0 2:4 3:0 4:0 5:0 6:0 7:0" + ret = host_network.try_mod_ea(cim, sys_mgmt_service, inst) + if ret != 1: + logger.error("Failed to mod 802.1.q ea") + return FAIL + + ret = host_network.try_del_ea(cim, sys_mgmt_service, inst) + if ret != 1: + logger.error("Failed to remove 802.1.q ea") + return FAIL + + return PASS + +# main() + +if __name__ == "__main__": + ret = main() + sys.exit(ret) -- 1.7.6

test case of attaching one 802.1.q child port to a bridge Signed-off-by: Wayne Xia <xiawenc@linux.vnet.ibm.com> --- .../cimtest/HostNetwork/03_VESSMS_EASD_EC.py | 101 ++++++++++++++++++++ 1 files changed, 101 insertions(+), 0 deletions(-) create mode 100644 suites/libvirt-cim/cimtest/HostNetwork/03_VESSMS_EASD_EC.py diff --git a/suites/libvirt-cim/cimtest/HostNetwork/03_VESSMS_EASD_EC.py b/suites/libvirt-cim/cimtest/HostNetwork/03_VESSMS_EASD_EC.py new file mode 100644 index 0000000..6ece7fa --- /dev/null +++ b/suites/libvirt-cim/cimtest/HostNetwork/03_VESSMS_EASD_EC.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python + +# +# Copyright 2011 IBM Corp. +# +# Authors: +# Wenchao Xia (Wayne) <xiawenc@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 +# + +# +# try connect two CIM switch by attaching one eth to another bridge +# +# + +import sys +import os +import pywbem + +from CimTest.ReturnCodes import PASS, FAIL, XFAIL, SKIP +from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS +from XenKvmLib.const import do_main +from XenKvmLib.classes import get_typed_class +from XenKvmLib.vxml import get_class +from XenKvmLib import host_network + +cim = None +sys_mgmt_service = None +supported = ['KVM',] + + +@do_main(supported) +def main(): + options = main.options + server = options.ip + server_url = "http://%s" % server + #global cim + cim = pywbem.WBEMConnection(server_url, (CIM_USER, CIM_PASS), CIM_NS) + + sys_mgmt_service = host_network.get_vessms(cim) + pNIC = host_network.FoundOnePNIC(cim) + if pNIC == None : + logger.error("Failed to find any pNIC on the host.") + return FAIL + + #add the bridge + inst_br = {'VirtualSystemIdentifier':host_network.bridge_name, 'STP': host_network.bridge_stp, 'Name': host_network.bridge_name} + + ret = host_network.try_create_vs(cim, sys_mgmt_service, inst_br) + if ret != 1: + logger.error("Failed to add cim bridge") + return FAIL + + inst_ea = {'Parent': pNIC, 'VLanID':10, 'ReorderHdr':1, 'Ingress':"1:2 2:3", 'Egress':'2:4'} + ret = host_network.try_add_ea(cim, sys_mgmt_service, inst_ea) + if ret != 1: + logger.error("Failed to add 802.1.q ea") + return FAIL + + EthPort = """%s.%d""" % (inst_ea["Parent"], inst_ea["VLanID"]) + inst_ec = {'ParentBridge': pNIC, 'EthPort':EthPort, 'TargetBridge': host_network.bridge_pNIC} + ret = host_network.try_add_ec(cim, sys_mgmt_service, inst_ec) + if ret != 1: + logger.error("Failed to add connection") + return FAIL + + ret = host_network.try_del_ec(cim, sys_mgmt_service, inst_ec) + if ret != 1: + logger.error("Failed to add connection") + return FAIL + + ret = host_network.try_del_ea(cim, sys_mgmt_service, inst_ea) + if ret != 1: + logger.error("Failed to remove 802.1.q ea") + return FAIL + + ret = host_network.try_delete_vs(cim, sys_mgmt_service, inst_br) + if ret != 1: + logger.error("Failed to delete cim bridge") + return FAIL + + return PASS + +# main() + +if __name__ == "__main__": + ret = main() + sys.exit(ret) -- 1.7.6
participants (1)
-
Wayne Xia