tests: Drop most interface XML testing
No part of the app requires the <interface> details any more, so drop testing
This commit is contained in:
parent
85a7b2cd61
commit
58d0d43db1
|
@ -3,199 +3,30 @@
|
|||
# This work is licensed under the GNU GPLv2 or later.
|
||||
# See the COPYING file in the top-level directory.
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import logging
|
||||
|
||||
from virtinst import Interface, InterfaceProtocol
|
||||
from virtinst import Interface
|
||||
from tests import utils
|
||||
|
||||
datadir = "tests/interface-xml"
|
||||
|
||||
|
||||
|
||||
|
||||
class TestInterfaces(unittest.TestCase):
|
||||
@property
|
||||
def conn(self):
|
||||
return utils.URIs.open_testdriver_cached()
|
||||
def testInterfaceBridgeIP(self):
|
||||
conn = utils.URIs.open_testdriver_cached()
|
||||
|
||||
def build_interface(self, interface_type, name):
|
||||
iobj = Interface(self.conn)
|
||||
iobj.type = interface_type
|
||||
iobj.name = name
|
||||
def _check_iface(name, typ, child_names):
|
||||
libvirtobj = conn.interfaceLookupByName(name)
|
||||
xmlobj = Interface(conn, parsexml=libvirtobj.XMLDesc(0))
|
||||
|
||||
return iobj
|
||||
self.assertEqual(xmlobj.name, name)
|
||||
self.assertEqual(xmlobj.type, typ)
|
||||
self.assertEqual(
|
||||
{i.name for i in xmlobj.interfaces},
|
||||
set(child_names))
|
||||
|
||||
def set_general_params(self, iface_obj):
|
||||
iface_obj.mtu = 1501
|
||||
iface_obj.macaddr = "AA:AA:AA:AA:AA:AA"
|
||||
iface_obj.start_mode = Interface.INTERFACE_START_MODE_ONBOOT
|
||||
proto = InterfaceProtocol(self.conn)
|
||||
proto.family = InterfaceProtocol.INTERFACE_PROTOCOL_FAMILY_IPV4
|
||||
iface_obj.add_protocol(proto)
|
||||
|
||||
def add_child_interfaces(self, iface_obj):
|
||||
def _m(_n):
|
||||
xml = self.conn.interfaceLookupByName(_n).XMLDesc(0)
|
||||
return Interface(self.conn, parsexml=xml)
|
||||
if iface_obj.type == Interface.INTERFACE_TYPE_BRIDGE:
|
||||
iface_obj.add_interface(_m("vlaneth1"))
|
||||
iface_obj.add_interface(_m("bond-brbond"))
|
||||
iface_obj.add_interface(_m("eth0"))
|
||||
elif iface_obj.type == Interface.INTERFACE_TYPE_BOND:
|
||||
iface_obj.add_interface(_m("eth0"))
|
||||
iface_obj.add_interface(_m("eth1"))
|
||||
iface_obj.add_interface(_m("eth2"))
|
||||
|
||||
def define_xml(self, obj, compare=True):
|
||||
obj.validate()
|
||||
|
||||
xml = obj.get_xml()
|
||||
logging.debug("Defining interface XML:\n%s", xml)
|
||||
|
||||
if compare:
|
||||
filename = os.path.join(datadir, obj.name + ".xml")
|
||||
utils.diff_compare(xml, filename)
|
||||
|
||||
iface = obj.install()
|
||||
|
||||
newxml = iface.XMLDesc(0)
|
||||
logging.debug("Defined XML:\n%s", newxml)
|
||||
|
||||
iface.undefine()
|
||||
|
||||
# Bridge tests
|
||||
def testBridgeInterface(self):
|
||||
filename = "bridge"
|
||||
obj = self.build_interface(Interface.INTERFACE_TYPE_BRIDGE,
|
||||
"test-%s" % filename)
|
||||
self.add_child_interfaces(obj)
|
||||
|
||||
obj.stp = False
|
||||
obj.delay = "7"
|
||||
|
||||
self.define_xml(obj)
|
||||
|
||||
def testBridgeInterfaceIP(self):
|
||||
filename = "bridge-ip"
|
||||
obj = self.build_interface(Interface.INTERFACE_TYPE_BRIDGE,
|
||||
"test-%s" % filename)
|
||||
self.add_child_interfaces(obj)
|
||||
|
||||
# IPv4 proto
|
||||
iface_proto1 = InterfaceProtocol(self.conn)
|
||||
iface_proto1.family = InterfaceProtocol.INTERFACE_PROTOCOL_FAMILY_IPV4
|
||||
iface_proto1.add_ip("129.63.1.2")
|
||||
iface_proto1.add_ip("255.255.255.0")
|
||||
iface_proto1.gateway = "1.2.3.4"
|
||||
iface_proto1.dhcp = True
|
||||
iface_proto1.dhcp_peerdns = True
|
||||
|
||||
# IPv6 proto
|
||||
iface_proto2 = InterfaceProtocol(self.conn)
|
||||
iface_proto2.family = InterfaceProtocol.INTERFACE_PROTOCOL_FAMILY_IPV6
|
||||
|
||||
iface_proto2.add_ip("fe99::215:58ff:fe6e:5", prefix="32")
|
||||
iface_proto2.add_ip("fe80::215:58ff:fe6e:5", prefix="64")
|
||||
iface_proto2.gateway = "1.2.3.4"
|
||||
iface_proto2.dhcp = True
|
||||
iface_proto2.dhcp_peerdns = True
|
||||
iface_proto2.autoconf = True
|
||||
|
||||
obj.add_protocol(iface_proto1)
|
||||
obj.add_protocol(iface_proto2)
|
||||
|
||||
self.define_xml(obj)
|
||||
|
||||
# Bond tests
|
||||
def testBondInterface(self):
|
||||
filename = "bond"
|
||||
obj = self.build_interface(Interface.INTERFACE_TYPE_BOND,
|
||||
"test-%s" % filename)
|
||||
self.add_child_interfaces(obj)
|
||||
self.set_general_params(obj)
|
||||
|
||||
self.define_xml(obj)
|
||||
|
||||
def testBondInterfaceARP(self):
|
||||
filename = "bond-arp"
|
||||
obj = self.build_interface(Interface.INTERFACE_TYPE_BOND,
|
||||
"test-%s" % filename)
|
||||
self.add_child_interfaces(obj)
|
||||
self.set_general_params(obj)
|
||||
|
||||
obj.arp_interval = 100
|
||||
obj.arp_target = "192.168.100.200"
|
||||
obj.arp_validate_mode = "backup"
|
||||
|
||||
self.define_xml(obj)
|
||||
|
||||
def testBondInterfaceMII(self):
|
||||
filename = "bond-mii"
|
||||
obj = self.build_interface(Interface.INTERFACE_TYPE_BOND,
|
||||
"test-%s" % filename)
|
||||
self.add_child_interfaces(obj)
|
||||
self.set_general_params(obj)
|
||||
|
||||
obj.mii_frequency = "123"
|
||||
obj.mii_updelay = "12"
|
||||
obj.mii_downdelay = "34"
|
||||
obj.mii_carrier_mode = "netif"
|
||||
|
||||
self.define_xml(obj)
|
||||
|
||||
# Ethernet tests
|
||||
def testEthernetInterface(self):
|
||||
filename = "ethernet"
|
||||
obj = self.build_interface(Interface.INTERFACE_TYPE_ETHERNET,
|
||||
"test-%s" % filename)
|
||||
self.define_xml(obj)
|
||||
|
||||
def testEthernetManyParam(self):
|
||||
filename = "ethernet-params"
|
||||
obj = self.build_interface(Interface.INTERFACE_TYPE_ETHERNET,
|
||||
"test-%s" % filename)
|
||||
|
||||
obj.mtu = 1234
|
||||
obj.mac = "AA:BB:FF:FF:BB:AA"
|
||||
obj.start_mode = Interface.INTERFACE_START_MODE_HOTPLUG
|
||||
|
||||
self.define_xml(obj)
|
||||
|
||||
# VLAN tests
|
||||
def testVLANInterface(self):
|
||||
filename = "vlan"
|
||||
obj = self.build_interface(Interface.INTERFACE_TYPE_VLAN,
|
||||
"test-%s" % filename)
|
||||
|
||||
obj.tag = "123"
|
||||
obj.parent_interface = "eth2"
|
||||
|
||||
self.define_xml(obj)
|
||||
|
||||
def testVLANInterfaceBusted(self):
|
||||
obj = self.build_interface(Interface.INTERFACE_TYPE_VLAN,
|
||||
"vlan1")
|
||||
|
||||
try:
|
||||
self.define_xml(obj, compare=False)
|
||||
assert(False)
|
||||
except ValueError:
|
||||
pass
|
||||
except Exception:
|
||||
assert(False)
|
||||
|
||||
# protocol_xml test
|
||||
def testEthernetProtocolInterface(self):
|
||||
filename = "ethernet-copy-proto"
|
||||
obj = self.build_interface(Interface.INTERFACE_TYPE_ETHERNET,
|
||||
"test-%s" % filename)
|
||||
|
||||
protoxml = (" <protocol family='ipv6'>\n"
|
||||
" <dhcp/>\n"
|
||||
" </protocol>\n")
|
||||
proto = InterfaceProtocol(self.conn, parsexml=protoxml)
|
||||
obj.add_protocol(proto)
|
||||
|
||||
self.define_xml(obj)
|
||||
_check_iface("eth0", "ethernet", [])
|
||||
_check_iface("bond0", "bond", ["eth-bond0-1", "eth-bond0-2"])
|
||||
_check_iface("brplain", "bridge", ["eth-brplain0", "eth-brplain1"])
|
||||
_check_iface("brempty", "bridge", [])
|
||||
_check_iface("vlaneth1.3", "vlan", ["vlaneth1"])
|
||||
|
|
|
@ -3491,25 +3491,15 @@ ba</description>
|
|||
<interface type='ethernet' name='eth1'>
|
||||
<mac address='00:FF:EE:FF:EE:AB'/>
|
||||
</interface>
|
||||
<interface type='ethernet' name='eth2'>
|
||||
<start mode='hotplug'/>
|
||||
<mac address='00:FF:EE:FF:EE:CD'/>
|
||||
</interface>
|
||||
|
||||
<interface type='ethernet' name='lo'>
|
||||
<start mode='onboot'/>
|
||||
<protocol family='ipv4'>
|
||||
<ip address='127.0.0.1' prefix='8'/>
|
||||
</protocol>
|
||||
</interface>
|
||||
|
||||
<interface type='ethernet' name='wlan0'>
|
||||
<start mode='none'/>
|
||||
<mac address='00:AA:CC:BB:AA:BB'/>
|
||||
</interface>
|
||||
|
||||
|
||||
<!-- backup bond -->
|
||||
<!-- bond example -->
|
||||
<interface type="ethernet" name="eth-bond0-1"/>
|
||||
<interface type="ethernet" name="eth-bond0-2"/>
|
||||
<interface type="bond" name="bond0">
|
||||
<start mode="none"/>
|
||||
<protocol family="ipv4">
|
||||
|
@ -3522,11 +3512,11 @@ ba</description>
|
|||
<interface type="ethernet" name="eth-bond0-2"/>
|
||||
</bond>
|
||||
</interface>
|
||||
<interface type="ethernet" name="eth-bond0-1"/>
|
||||
<interface type="ethernet" name="eth-bond0-2"/>
|
||||
|
||||
|
||||
<!-- Plain bridge -->
|
||||
<interface type="ethernet" name="eth-brplain0"/>
|
||||
<interface type="ethernet" name="eth-brplain1"/>
|
||||
<interface type="bridge" name="brplain">
|
||||
<start mode="onboot"/>
|
||||
<mtu size="1500"/>
|
||||
|
@ -3536,9 +3526,6 @@ ba</description>
|
|||
</bridge>
|
||||
</interface>
|
||||
|
||||
<interface type="ethernet" name="eth-brplain0"/>
|
||||
<interface type="ethernet" name="eth-brplain1"/>
|
||||
|
||||
|
||||
<!-- Empty bridge -->
|
||||
<interface type="bridge" name="brempty">
|
||||
|
@ -3555,82 +3542,13 @@ ba</description>
|
|||
</interface>
|
||||
|
||||
|
||||
<!-- Bridge using vlan -->
|
||||
<interface type="bridge" name="brvlan">
|
||||
<start mode="onboot"/>
|
||||
<protocol family="ipv4">
|
||||
<dhcp/>
|
||||
</protocol>
|
||||
<bridge stp="off">
|
||||
<interface type="vlan" name="eth0.42">
|
||||
<vlan tag="42">
|
||||
<interface name="eth0"/>
|
||||
</vlan>
|
||||
</interface>
|
||||
</bridge>
|
||||
</interface>
|
||||
|
||||
<interface type="vlan" name="eth0.42">
|
||||
<start mode="onboot"/>
|
||||
<protocol family="ipv4">
|
||||
<dhcp peerdns="no"/>
|
||||
<ip address='192.168.1.2'/>
|
||||
</protocol>
|
||||
<vlan tag="42">
|
||||
<interface name="eth0"/>
|
||||
</vlan>
|
||||
</interface>
|
||||
|
||||
|
||||
<!-- Bridge using bond -->
|
||||
<interface type="bond" name="bond-brbond">
|
||||
<start mode="none"/>
|
||||
<bond mode="active-backup">
|
||||
<miimon freq="100" updelay="10" carrier="ioctl"/>
|
||||
<interface type="ethernet" name="brbond-eth0"/>
|
||||
<interface type="ethernet" name="brbond-eth1"/>
|
||||
</bond>
|
||||
<protocol family='ipv6'>
|
||||
<ip address='3ffe:ffff:0:5::1' prefix='128'/>
|
||||
<ip address='3ffe:ffff:0:5::3' prefix='128'/>
|
||||
<ip address='3ffe:ffff:0:5::5' prefix='128'/>
|
||||
</protocol>
|
||||
</interface>
|
||||
<interface type="ethernet" name="eth-bond-brbond0"/>
|
||||
<interface type="ethernet" name="eth-bond-brbond1"/>
|
||||
|
||||
|
||||
<!-- Multi interface bridge -->
|
||||
<interface type="bridge" name="brbond">
|
||||
<start mode="onboot"/>
|
||||
<mtu size="1500"/>
|
||||
<bridge stp="off">
|
||||
<interface type="bond" name="bond-brbond">
|
||||
<start mode="none"/>
|
||||
<bond mode="active-backup">
|
||||
<miimon freq="100" updelay="10" carrier="ioctl"/>
|
||||
<interface type="ethernet" name="brbond-eth0"/>
|
||||
<interface type="ethernet" name="brbond-eth1"/>
|
||||
</bond>
|
||||
</interface>
|
||||
</bridge>
|
||||
<protocol family='ipv4'>
|
||||
<ip address='192.168.0.5' prefix='24'/>
|
||||
<route gateway='192.168.0.1'/>
|
||||
</protocol>
|
||||
</interface>
|
||||
|
||||
|
||||
<!-- Unused vlan -->
|
||||
<!-- vlan example -->
|
||||
<interface type="ethernet" name="vlaneth1"/>
|
||||
<interface type="vlan" name="vlaneth1.3">
|
||||
<start mode="onboot"/>
|
||||
<vlan tag="43">
|
||||
<interface name="vlaneth1"/>
|
||||
</vlan>
|
||||
</interface>
|
||||
<interface type="ethernet" name="vlaneth1"/>
|
||||
|
||||
<!-- Unused interface -->
|
||||
<interface type="ethernet" name="unusedeth0"/>
|
||||
|
||||
</node>
|
||||
|
|
|
@ -1163,98 +1163,6 @@ class XMLParseTest(unittest.TestCase):
|
|||
utils.diff_compare(snap.get_xml(), outfile)
|
||||
|
||||
|
||||
###################
|
||||
# Interface tests #
|
||||
###################
|
||||
|
||||
def testInterfaceBridgeIP(self):
|
||||
basename = "test-bridge-ip"
|
||||
infile = "tests/interface-xml/%s.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/interface-%s-out.xml" % basename
|
||||
iface = virtinst.Interface(self.conn, parsexml=open(infile).read())
|
||||
|
||||
self.assertEqual(len(iface.protocols), 2)
|
||||
self.assertEqual(len(iface.interfaces), 3)
|
||||
|
||||
check = self._make_checker(iface)
|
||||
check("type", "bridge", "foo", "bridge")
|
||||
check("name", "test-bridge-ip", "foo-new")
|
||||
check("stp", None, True)
|
||||
check("delay", None, 2)
|
||||
|
||||
check = self._make_checker(iface.protocols[0])
|
||||
check("family", "ipv4", "foo", "ipv4")
|
||||
check("dhcp_peerdns", True, False)
|
||||
check("gateway", "1.2.3.4", "5.5.5.5")
|
||||
self.assertEqual(iface.protocols[0].ips[1].address, "255.255.255.0")
|
||||
|
||||
check = self._make_checker(iface.protocols[1])
|
||||
check("dhcp", True, False)
|
||||
check("autoconf", True, False)
|
||||
|
||||
check = self._make_checker(iface.protocols[1].ips[1])
|
||||
check("address", "fe80::215:58ff:fe6e:5", "2002::")
|
||||
check("prefix", 64, 38)
|
||||
|
||||
# Remove a child interface, verify it's data remains intact
|
||||
child_iface = iface.interfaces[1]
|
||||
iface.remove_interface(child_iface)
|
||||
|
||||
check = self._make_checker(child_iface)
|
||||
check("name", "bond-brbond")
|
||||
self.assertEqual(len(child_iface.interfaces), 2)
|
||||
|
||||
utils.diff_compare(iface.get_xml(), outfile)
|
||||
utils.test_create(self.conn, iface.get_xml(), "interfaceDefineXML")
|
||||
|
||||
def testInterfaceBondArp(self):
|
||||
basename = "test-bond-arp"
|
||||
infile = "tests/interface-xml/%s.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/interface-%s-out.xml" % basename
|
||||
iface = virtinst.Interface(self.conn, parsexml=open(infile).read())
|
||||
|
||||
check = self._make_checker(iface)
|
||||
check("start_mode", "onboot", "hotplug")
|
||||
check("macaddr", "AA:AA:AA:AA:AA:AA", "AA:AA:AA:11:AA:AA")
|
||||
check("mtu", 1501, 1234)
|
||||
|
||||
check("bond_mode", None, "active-backup")
|
||||
check("arp_interval", 100, 234)
|
||||
check("arp_target", "192.168.100.200", "1.2.3.4")
|
||||
check("arp_validate_mode", "backup", "active")
|
||||
|
||||
utils.diff_compare(iface.get_xml(), outfile)
|
||||
utils.test_create(self.conn, iface.get_xml(), "interfaceDefineXML")
|
||||
|
||||
def testInterfaceBondMii(self):
|
||||
basename = "test-bond-mii"
|
||||
infile = "tests/interface-xml/%s.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/interface-%s-out.xml" % basename
|
||||
iface = virtinst.Interface(self.conn, parsexml=open(infile).read())
|
||||
|
||||
check = self._make_checker(iface)
|
||||
check("mii_frequency", 123, 111)
|
||||
check("mii_downdelay", 34, 22)
|
||||
check("mii_updelay", 12, 33)
|
||||
check("mii_carrier_mode", "netif", "ioctl")
|
||||
|
||||
utils.diff_compare(iface.get_xml(), outfile)
|
||||
utils.test_create(self.conn, iface.get_xml(), "interfaceDefineXML")
|
||||
|
||||
def testInterfaceVLAN(self):
|
||||
basename = "test-vlan"
|
||||
infile = "tests/interface-xml/%s.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/interface-%s-out.xml" % basename
|
||||
iface = virtinst.Interface(self.conn, parsexml=open(infile).read())
|
||||
|
||||
check = self._make_checker(iface)
|
||||
check("tag", 123, 456)
|
||||
check("parent_interface", "eth2", "foonew")
|
||||
|
||||
utils.diff_compare(iface.get_xml(), outfile)
|
||||
utils.test_create(self.conn, iface.get_xml(), "interfaceDefineXML")
|
||||
|
||||
|
||||
#################
|
||||
# Storage tests #
|
||||
#################
|
||||
|
|
Loading…
Reference in New Issue