2013-10-28 04:59:46 +08:00
|
|
|
# Copyright (C) 2013 Red Hat, Inc.
|
2013-03-18 05:06:52 +08:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2013-10-28 04:59:47 +08:00
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2013-03-18 05:06:52 +08:00
|
|
|
#
|
|
|
|
# This program 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 program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301 USA.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
import logging
|
|
|
|
|
2013-09-10 05:14:16 +08:00
|
|
|
from virtinst import Interface, InterfaceProtocol
|
2013-04-11 07:48:07 +08:00
|
|
|
from tests import utils
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
conn = utils.open_testdriver()
|
|
|
|
datadir = "tests/interface-xml"
|
|
|
|
|
|
|
|
|
2013-09-10 05:14:16 +08:00
|
|
|
def _m(_n):
|
|
|
|
xml = conn.interfaceLookupByName(_n).XMLDesc(0)
|
|
|
|
return Interface(conn, parsexml=xml)
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-09-10 05:14:16 +08:00
|
|
|
class TestInterfaces(unittest.TestCase):
|
2013-03-18 05:06:52 +08:00
|
|
|
def build_interface(self, interface_type, name):
|
2013-09-10 05:14:16 +08:00
|
|
|
iobj = Interface(conn)
|
|
|
|
iobj.type = interface_type
|
|
|
|
iobj.name = name
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
return iobj
|
|
|
|
|
|
|
|
def set_general_params(self, iface_obj):
|
|
|
|
iface_obj.mtu = 1501
|
|
|
|
iface_obj.macaddr = "AA:AA:AA:AA:AA:AA"
|
2013-09-10 05:14:16 +08:00
|
|
|
iface_obj.start_mode = Interface.INTERFACE_START_MODE_ONBOOT
|
|
|
|
proto = InterfaceProtocol(conn)
|
|
|
|
proto.family = InterfaceProtocol.INTERFACE_PROTOCOL_FAMILY_IPV4
|
|
|
|
iface_obj.add_protocol(proto)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def add_child_interfaces(self, iface_obj):
|
2013-09-10 05:14:16 +08:00
|
|
|
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"))
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def define_xml(self, obj, compare=True):
|
2013-09-10 05:14:16 +08:00
|
|
|
obj.validate()
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
xml = obj.get_xml_config()
|
|
|
|
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"
|
2013-09-10 05:14:16 +08:00
|
|
|
obj = self.build_interface(Interface.INTERFACE_TYPE_BRIDGE,
|
2013-03-18 05:06:52 +08:00
|
|
|
"test-%s" % filename)
|
|
|
|
self.add_child_interfaces(obj)
|
|
|
|
|
|
|
|
obj.stp = False
|
|
|
|
obj.delay = "7"
|
|
|
|
|
|
|
|
self.define_xml(obj)
|
|
|
|
|
|
|
|
def testBridgeInterfaceIP(self):
|
|
|
|
filename = "bridge-ip"
|
2013-09-10 05:14:16 +08:00
|
|
|
obj = self.build_interface(Interface.INTERFACE_TYPE_BRIDGE,
|
2013-03-18 05:06:52 +08:00
|
|
|
"test-%s" % filename)
|
|
|
|
self.add_child_interfaces(obj)
|
|
|
|
|
|
|
|
# IPv4 proto
|
2013-09-10 05:14:16 +08:00
|
|
|
iface_proto1 = InterfaceProtocol(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")
|
2013-03-18 05:06:52 +08:00
|
|
|
iface_proto1.gateway = "1.2.3.4"
|
|
|
|
iface_proto1.dhcp = True
|
|
|
|
iface_proto1.dhcp_peerdns = True
|
|
|
|
|
|
|
|
# IPv6 proto
|
2013-09-10 05:14:16 +08:00
|
|
|
iface_proto2 = InterfaceProtocol(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")
|
2013-03-18 05:06:52 +08:00
|
|
|
iface_proto2.gateway = "1.2.3.4"
|
|
|
|
iface_proto2.dhcp = True
|
|
|
|
iface_proto2.dhcp_peerdns = True
|
|
|
|
iface_proto2.autoconf = True
|
|
|
|
|
2013-09-10 05:14:16 +08:00
|
|
|
obj.add_protocol(iface_proto1)
|
|
|
|
obj.add_protocol(iface_proto2)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
self.define_xml(obj)
|
|
|
|
|
|
|
|
# Bond tests
|
|
|
|
def testBondInterface(self):
|
|
|
|
filename = "bond"
|
2013-09-10 05:14:16 +08:00
|
|
|
obj = self.build_interface(Interface.INTERFACE_TYPE_BOND,
|
2013-03-18 05:06:52 +08:00
|
|
|
"test-%s" % filename)
|
|
|
|
self.add_child_interfaces(obj)
|
|
|
|
self.set_general_params(obj)
|
|
|
|
|
|
|
|
self.define_xml(obj)
|
|
|
|
|
|
|
|
def testBondInterfaceARP(self):
|
|
|
|
filename = "bond-arp"
|
2013-09-10 05:14:16 +08:00
|
|
|
obj = self.build_interface(Interface.INTERFACE_TYPE_BOND,
|
2013-03-18 05:06:52 +08:00
|
|
|
"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"
|
2013-09-10 05:14:16 +08:00
|
|
|
obj = self.build_interface(Interface.INTERFACE_TYPE_BOND,
|
2013-03-18 05:06:52 +08:00
|
|
|
"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"
|
2013-09-10 05:14:16 +08:00
|
|
|
obj = self.build_interface(Interface.INTERFACE_TYPE_ETHERNET,
|
2013-03-18 05:06:52 +08:00
|
|
|
"test-%s" % filename)
|
|
|
|
self.define_xml(obj)
|
|
|
|
|
|
|
|
def testEthernetManyParam(self):
|
|
|
|
filename = "ethernet-params"
|
2013-09-10 05:14:16 +08:00
|
|
|
obj = self.build_interface(Interface.INTERFACE_TYPE_ETHERNET,
|
2013-03-18 05:06:52 +08:00
|
|
|
"test-%s" % filename)
|
|
|
|
|
|
|
|
obj.mtu = 1234
|
|
|
|
obj.mac = "AA:BB:FF:FF:BB:AA"
|
2013-09-10 05:14:16 +08:00
|
|
|
obj.start_mode = Interface.INTERFACE_START_MODE_HOTPLUG
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
self.define_xml(obj)
|
|
|
|
|
|
|
|
# VLAN tests
|
|
|
|
def testVLANInterface(self):
|
|
|
|
filename = "vlan"
|
2013-09-10 05:14:16 +08:00
|
|
|
obj = self.build_interface(Interface.INTERFACE_TYPE_VLAN,
|
2013-03-18 05:06:52 +08:00
|
|
|
"test-%s" % filename)
|
|
|
|
|
|
|
|
obj.tag = "123"
|
2013-09-10 05:14:16 +08:00
|
|
|
obj.parent_interface = "eth2"
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
self.define_xml(obj)
|
|
|
|
|
|
|
|
def testVLANInterfaceBusted(self):
|
2013-09-10 05:14:16 +08:00
|
|
|
obj = self.build_interface(Interface.INTERFACE_TYPE_VLAN,
|
2013-03-18 05:06:52 +08:00
|
|
|
"vlan1")
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.define_xml(obj, compare=False)
|
|
|
|
assert(False)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
except:
|
|
|
|
assert(False)
|
|
|
|
|
|
|
|
# protocol_xml test
|
|
|
|
def testEthernetProtocolInterface(self):
|
|
|
|
filename = "ethernet-copy-proto"
|
2013-09-10 05:14:16 +08:00
|
|
|
obj = self.build_interface(Interface.INTERFACE_TYPE_ETHERNET,
|
2013-03-18 05:06:52 +08:00
|
|
|
"test-%s" % filename)
|
|
|
|
|
|
|
|
protoxml = (" <protocol family='ipv6'>\n"
|
|
|
|
" <dhcp/>\n"
|
|
|
|
" </protocol>\n")
|
2013-09-10 05:14:16 +08:00
|
|
|
proto = InterfaceProtocol(conn, parsexml=protoxml)
|
|
|
|
obj.add_protocol(proto)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
self.define_xml(obj)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|