1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
#
# 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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
import virtinst.Interface
from virtinst.Interface import (Interface, InterfaceProtocol,
InterfaceProtocolIPAddress)
import tests
conn = tests.open_testdriver()
datadir = "tests/interface-xml"
vlan_iface = conn.interfaceLookupByName("vlaneth1")
bond_iface = conn.interfaceLookupByName("bond-brbond")
eth_iface1 = conn.interfaceLookupByName("eth0")
eth_iface2 = conn.interfaceLookupByName("eth1")
eth_iface3 = conn.interfaceLookupByName("eth2")
br_iface = conn.interfaceLookupByName("brempty")
class TestInterfaces(unittest.TestCase):
def setUp(self):
pass
def build_interface(self, interface_type, name):
iclass = Interface.interface_class_for_type(interface_type)
iobj = iclass(name, conn)
return iobj
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
iface_obj.protocols = [virtinst.Interface.InterfaceProtocolIPv4()]
def add_child_interfaces(self, iface_obj):
if iface_obj.object_type == Interface.INTERFACE_TYPE_BRIDGE:
iface_obj.interfaces.append(vlan_iface)
iface_obj.interfaces.append(bond_iface)
iface_obj.interfaces.append(eth_iface1)
elif iface_obj.object_type == Interface.INTERFACE_TYPE_BOND:
iface_obj.interfaces.append(eth_iface1)
iface_obj.interfaces.append(eth_iface2)
iface_obj.interfaces.append(eth_iface3)
def define_xml(self, obj, compare=True):
xml = obj.get_xml_config()
logging.debug("Defining interface XML:\n%s", xml)
if compare:
filename = os.path.join(datadir, obj.name + ".xml")
tests.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_ip1 = InterfaceProtocolIPAddress("129.63.1.2")
iface_ip2 = InterfaceProtocolIPAddress("255.255.255.0")
iface_proto1 = InterfaceProtocol.protocol_class_for_family(
InterfaceProtocol.INTERFACE_PROTOCOL_FAMILY_IPV4)()
iface_proto1.ips = [iface_ip1, iface_ip2]
iface_proto1.gateway = "1.2.3.4"
iface_proto1.dhcp = True
iface_proto1.dhcp_peerdns = True
# IPv6 proto
iface_ip3 = InterfaceProtocolIPAddress("fe99::215:58ff:fe6e:5",
prefix="32")
iface_ip4 = InterfaceProtocolIPAddress("fe80::215:58ff:fe6e:5",
prefix="64")
iface_proto2 = InterfaceProtocol.protocol_class_for_family(
InterfaceProtocol.INTERFACE_PROTOCOL_FAMILY_IPV6)()
iface_proto2.ips = [iface_ip3, iface_ip4]
iface_proto2.gateway = "1.2.3.4"
iface_proto2.dhcp = True
iface_proto2.dhcp_peerdns = True
iface_proto2.autoconf = True
obj.protocols = [iface_proto1, 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.monitor_mode = "arpmon"
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.monitor_mode = "miimon"
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 = eth_iface3
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:
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")
obj.protocol_xml = protoxml
self.define_xml(obj)
if __name__ == "__main__":
unittest.main()
|