def test_network_ovs_dpdk_bond(self): nic_mapping = {'nic1': 'eth0', 'nic2': 'eth1', 'nic3': 'eth2'} self.stubbed_mapped_nics = nic_mapping iface0 = objects.Interface(name='nic2') dpdk0 = objects.OvsDpdkPort(name='dpdk0', members=[iface0]) iface1 = objects.Interface(name='nic3') dpdk1 = objects.OvsDpdkPort(name='dpdk1', members=[iface1]) bond = objects.OvsDpdkBond('dpdkbond0', members=[dpdk0, dpdk1]) bridge = objects.OvsUserBridge('br-link', members=[bond]) def test_bind_dpdk_interfaces(ifname, driver, noop): self.assertIn(ifname, ['eth1', 'eth2']) self.assertEqual(driver, 'vfio-pci') self.stubs.Set(utils, 'bind_dpdk_interfaces', test_bind_dpdk_interfaces) self.provider.add_ovs_dpdk_bond(bond) self.provider.add_ovs_user_bridge(bridge) dpdk_bond_config = """# This file is autogenerated by os-net-config DEVICE=dpdkbond0 ONBOOT=yes HOTPLUG=no NM_CONTROLLED=no PEERDNS=no DEVICETYPE=ovs TYPE=OVSDPDKBond OVS_BRIDGE=br-link BOND_IFACES="dpdk0 dpdk1" """ self.assertEqual(dpdk_bond_config, self.get_interface_config('dpdkbond0'))
def test_restart_interface_counts(self): interface = objects.Interface('em1') self.provider.add_interface(interface) interface2 = objects.Interface('em2') self.provider.add_interface(interface2) self.provider.apply() self.assertEqual(1, self.ifup_interface_names.count("em1")) self.assertEqual(1, self.ifup_interface_names.count("em2"))
def test_linux_team(self): interface1 = objects.Interface('em1') interface2 = objects.Interface('em2') team = objects.LinuxTeam('team0', use_dhcp=True, members=[interface1, interface2]) self.provider.add_linux_team(team) self.provider.add_interface(interface1) self.provider.add_interface(interface2) self.assertEqual(_LINUX_TEAM_DHCP, self.get_linux_team_config('team0')) self.assertEqual(_LINUX_TEAM_INTERFACE, self.get_interface_config('em1'))
def test_linux_bond(self): interface1 = objects.Interface('em1') interface2 = objects.Interface('em2') bond = objects.LinuxBond('bond0', use_dhcp=True, members=[interface1, interface2]) self.provider.add_linux_bond(bond) self.provider.add_interface(interface1) self.provider.add_interface(interface2) self.assertEqual(_LINUX_BOND_DHCP, self.get_linux_bond_config('bond0')) self.assertEqual(_LINUX_BOND_INTERFACE, self.get_interface_config('em1'))
def test_interface_failure_multiple(self): self.stubs.Set(processutils, 'execute', self._failed_execute) v4_addr = objects.Address('192.168.1.2/24') interface = objects.Interface('em1', addresses=[v4_addr]) v4_addr2 = objects.Address('192.168.2.2/24') interface2 = objects.Interface('em2', addresses=[v4_addr2]) self.provider.add_interface(interface) self.provider.add_interface(interface2) self.assertRaises(os_net_config.ConfigurationError, self.provider.apply) # Even though the first one failed, we should have attempted both self.assertEqual(2, len(self.provider.errors))
def test_bond_active_ordering(self): # setup and apply a bond interface1 = objects.Interface('em1') interface2 = objects.Interface('em2') bond = objects.OvsBond('bond1', use_dhcp=True, members=[interface1, interface2]) self.provider.add_interface(interface1) self.provider.add_interface(interface2) self.provider.add_bond(bond) self.provider.apply() ovs_appctl_cmds = '/bin/ovs-appctl bond/set-active-slave bond1 em1' self.assertIn(ovs_appctl_cmds, self.ovs_appctl_cmds)
def test_dhclient_stop_on_iface_activate(self): self.stop_dhclient_interfaces = [] v4_addr = objects.Address('192.168.1.2/24') interface = objects.Interface('em1', addresses=[v4_addr]) interface2 = objects.Interface('em2', use_dhcp=True) interface3 = objects.Interface('em3', use_dhcp=False) self.provider.add_interface(interface) self.provider.add_interface(interface2) self.provider.add_interface(interface3) self.provider.apply() # stop dhclient on em1 due to static IP and em3 due to no IP self.assertIn('em1', self.stop_dhclient_interfaces) self.assertIn('em3', self.stop_dhclient_interfaces) self.assertNotIn('em2', self.stop_dhclient_interfaces)
def test_nm_controlled(self): interface1 = objects.Interface('em1', nm_controlled=True) interface2 = objects.Interface('em2', nm_controlled=True) bond = objects.LinuxBond('bond1', nm_controlled=True, members=[interface1, interface2]) self.provider.add_linux_bond(bond) self.provider.add_interface(interface1) self.provider.add_interface(interface2) ifcfg_data = self.get_interface_config('em1') self.assertEqual(_NM_CONTROLLED_INTERFACE, ifcfg_data) bond_data = self.get_linux_bond_config('bond1') self.assertEqual(_NM_CONTROLLED_BOND, bond_data)
def test_restart_children_on_change(self): # setup and apply a bridge interface = objects.Interface('em1') bridge = objects.OvsBridge('br-ctlplane', use_dhcp=True, members=[interface]) self.provider.add_interface(interface) self.provider.add_bridge(bridge) self.provider.apply() self.assertIn('em1', self.ifup_interface_names) self.assertIn('br-ctlplane', self.ifup_interface_names) # changing the bridge should restart the interface too self.ifup_interface_names = [] bridge = objects.OvsBridge('br-ctlplane', use_dhcp=False, members=[interface]) self.provider.add_interface(interface) self.provider.add_bridge(bridge) self.provider.apply() # setup and apply a bond on a bridge self.ifup_interface_names = [] interface1 = objects.Interface('em1') interface2 = objects.Interface('em2') bond = objects.OvsBond('bond0', members=[interface1, interface2]) bridge = objects.OvsBridge('br-ctlplane', use_dhcp=True, members=[bond]) self.provider.add_interface(interface1) self.provider.add_interface(interface2) self.provider.add_bond(bond) self.provider.add_bridge(bridge) self.provider.apply() # changing the bridge should restart everything self.ifup_interface_names = [] bridge = objects.OvsBridge('br-ctlplane', use_dhcp=False, members=[bond]) self.provider.add_interface(interface1) self.provider.add_interface(interface2) self.provider.add_bond(bond) self.provider.add_bridge(bridge) self.provider.apply() self.assertIn('br-ctlplane', self.ifup_interface_names) self.assertIn('bond0', self.ifup_interface_names) self.assertIn('em1', self.ifup_interface_names) self.assertIn('em2', self.ifup_interface_names)
def test_dhcp_ovs_bridge_network_apply(self): interface = objects.Interface('eth0') bridge = objects.OvsBridge('br0', use_dhcp=True, members=[interface]) self.provider.addInterface(interface) self.provider.addBridge(bridge) self.provider.apply() iface_data = utils.get_file_data(self.temp_config_file.name) self.assertEqual((_OVS_BRIDGE_DHCP + _OVS_PORT_IFACE), iface_data)
def test_ovs_bond(self): interface1 = objects.Interface('em1') interface2 = objects.Interface('em2') bond = objects.OvsBond('bond0', use_dhcp=True, members=[interface1, interface2]) self.provider.addInterface(interface1) self.provider.addInterface(interface2) self.provider.addBond(bond) self.assertEqual(_NO_IP, self.get_interface_config('em1')) em2_config = """DEVICE=em2 ONBOOT=yes HOTPLUG=no BOOTPROTO=none """ self.assertEqual(em2_config, self.get_interface_config('em2')) self.assertEqual(_OVS_BOND_DHCP, self.get_interface_config('bond0'))
def test_interface_failure(self): self.stubs.Set(processutils, 'execute', self._failed_execute) v4_addr = objects.Address('192.168.1.2/24') interface = objects.Interface('em1', addresses=[v4_addr]) self.provider.add_interface(interface) self.assertRaises(os_net_config.ConfigurationError, self.provider.apply) self.assertEqual(1, len(self.provider.errors))
def test_apply_noactivate(self): interface = objects.Interface('em1') bridge = objects.OvsBridge('br-ctlplane', use_dhcp=True, members=[interface]) self.provider.add_interface(interface) self.provider.add_bridge(bridge) self.provider.apply(activate=False) self.assertEqual([], self.ifup_interface_names)
def test_add_interface_with_v6_multiple(self): addresses = [ objects.Address('2001:abc:a::/64'), objects.Address('2001:abc:b::1/64'), objects.Address('2001:abc:c::2/96') ] interface = objects.Interface('em1', addresses=addresses) self.provider.add_interface(interface) self.assertEqual(_V6_IFCFG_MULTIPLE, self.get_interface_config())
def test_add_interface_with_v4_multiple(self): addresses = [ objects.Address('192.168.1.2/24'), objects.Address('192.168.1.3/32'), objects.Address('10.0.0.2/8') ] interface = objects.Interface('em1', addresses=addresses) self.provider.add_interface(interface) self.assertEqual(_V4_IFCFG_MULTIPLE, self.get_interface_config()) self.assertEqual('', self.get_route_config())
def test_network_linux_bridge_with_dhcp(self): interface = objects.Interface('em1') bridge = objects.LinuxBridge('br-ctlplane', use_dhcp=True, members=[interface]) self.provider.add_linux_bridge(bridge) self.provider.add_interface(interface) self.assertEqual(_LINUX_BRIDGE_IFCFG, self.get_interface_config()) self.assertEqual(_LINUX_BRIDGE_DHCP, self.provider.linuxbridge_data['br-ctlplane'])
def test_network_ovs_bridge_with_dhcp(self): interface = objects.Interface('em1') bridge = objects.OvsBridge('br-ctlplane', use_dhcp=True, members=[interface]) self.provider.add_interface(interface) self.provider.add_bridge(bridge) self.assertEqual(_OVS_INTERFACE, self.get_interface_config()) self.assertEqual(_OVS_BRIDGE_DHCP, self.provider.bridge_data['br-ctlplane'])
def test_network_with_routes(self): route1 = objects.Route('192.168.1.1', default=True) route2 = objects.Route('192.168.1.1', '172.19.0.0/24') v4_addr = objects.Address('192.168.1.2/24') interface = objects.Interface('em1', addresses=[v4_addr], routes=[route1, route2]) self.provider.add_interface(interface) self.assertEqual(_V4_IFCFG, self.get_interface_config()) self.assertEqual(_ROUTES, self.get_route_config())
def test_network_linux_bridge_static(self): v4_addr = objects.Address('192.168.1.2/24') interface = objects.Interface('em1') bridge = objects.LinuxBridge('br-ctlplane', members=[interface], addresses=[v4_addr]) self.provider.add_interface(interface) self.provider.add_bridge(bridge) self.assertEqual(_LINUX_BRIDGE_IFCFG, self.get_interface_config()) self.assertEqual(_LINUX_BRIDGE_STATIC, self.provider.bridge_data['br-ctlplane'])
def test_network_apply(self): route = objects.Route('192.168.1.1', '172.19.0.0/24') v4_addr = objects.Address('192.168.1.2/24') interface = objects.Interface('eth0', addresses=[v4_addr], routes=[route]) self.provider.addInterface(interface) self.provider.apply() iface_data = utils.get_file_data(self.temp_config_file.name) self.assertEqual((_V4_IFACE_STATIC_IP + _RTS), iface_data)
def test_ovs_bond(self): interface1 = objects.Interface('em1') interface2 = objects.Interface('em2') bond = objects.OvsBond('bond0', use_dhcp=True, members=[interface1, interface2]) self.provider.add_interface(interface1) self.provider.add_interface(interface2) self.provider.add_bond(bond) self.assertEqual(_NO_IP, self.get_interface_config('em1')) em2_config = """# This file is autogenerated by os-net-config DEVICE=em2 ONBOOT=yes HOTPLUG=no NM_CONTROLLED=no PEERDNS=no BOOTPROTO=none """ self.assertEqual(em2_config, self.get_interface_config('em2')) self.assertEqual(_OVS_BOND_DHCP, self.get_interface_config('bond0'))
def test_interface_single_dns_server(self): interface1 = objects.Interface('em1', dns_servers=['1.2.3.4']) self.provider.add_interface(interface1) em1_config = """# This file is autogenerated by os-net-config DEVICE=em1 ONBOOT=yes HOTPLUG=no NM_CONTROLLED=no BOOTPROTO=none DNS1=1.2.3.4 """ self.assertEqual(em1_config, self.get_interface_config('em1'))
def test_interface_dhclient_opts(self): interface1 = objects.Interface('em1', dhclient_args='--foobar') self.provider.add_interface(interface1) em1_config = """# This file is autogenerated by os-net-config DEVICE=em1 ONBOOT=yes HOTPLUG=no NM_CONTROLLED=no PEERDNS=no BOOTPROTO=none DHCLIENTARGS=--foobar """ self.assertEqual(em1_config, self.get_interface_config('em1'))
def test_network_ovs_bridge_with_dhcp_and_primary_interface(self): def test_interface_mac(name): return "a1:b2:c3:d4:e5" self.stub_out('os_net_config.common.interface_mac', test_interface_mac) interface = objects.Interface(self.if_name, primary=True) bridge = objects.OvsBridge('br0', use_dhcp=True, members=[interface]) self.provider.add_bridge(bridge) self.provider.add_interface(interface) self.assertEqual(_OVS_PORT_IFACE, self.get_interface_config()) self.assertEqual(_OVS_BRIDGE_DHCP_PRIMARY_INTERFACE, self.provider.bridges['br0'])
def test_apply_noactivate(self): route1 = objects.Route('192.168.1.1', '172.19.0.0/24') route2 = objects.Route('192.168.1.5', '172.20.0.0/24', route_options="metric 100") v4_addr = objects.Address('192.168.1.2/24') interface = objects.Interface('eth0', addresses=[v4_addr], routes=[route1, route2]) self.provider.add_interface(interface) self.provider.apply(activate=False) iface_data = utils.get_file_data(self.temp_config_file.name) self.assertEqual((_V4_IFACE_STATIC_IP + _RTS), iface_data) self.assertEqual([], self.ifup_interface_names)
def test_interface_ethtool_opts(self): interface1 = objects.Interface('em1', ethtool_opts='speed 1000 duplex full') self.provider.add_interface(interface1) em1_config = """# This file is autogenerated by os-net-config DEVICE=em1 ONBOOT=yes HOTPLUG=no NM_CONTROLLED=no PEERDNS=no BOOTPROTO=none ETHTOOL_OPTS=\"speed 1000 duplex full\" """ self.assertEqual(em1_config, self.get_interface_config('em1'))
def test_ovs_restart_not_called(self): interface = objects.Interface('em1') execute_strings = [] def test_execute(*args, **kwargs): execute_strings.append(args[1]) pass self.stubs.Set(NetConfig, 'execute', test_execute) self.provider.noop = True self.provider.add_interface(interface) self.provider.apply() self.assertNotIn('Restart openvswitch', execute_strings)
def test_network_with_ipv6_routes(self): route1 = objects.Route('192.168.1.1', default=True) route2 = objects.Route('192.168.1.1', '172.19.0.0/24') route3 = objects.Route('2001:db8::1', default=True) route4 = objects.Route('fd00:fd00:2000::1', '2001:db8:dead:beef:cafe::/56') v4_addr = objects.Address('192.168.1.2/24') v6_addr = objects.Address('2001:abc:a::/64') interface = objects.Interface('em1', addresses=[v4_addr, v6_addr], routes=[route1, route2, route3, route4]) self.provider.add_interface(interface) self.assertEqual(_V4_V6_IFCFG, self.get_interface_config()) self.assertEqual(_ROUTES_V6, self.get_route6_config())
def test_dhcp_ovs_bridge_network_apply(self): interface = objects.Interface('em1') bridge = objects.OvsBridge('br-ctlplane', use_dhcp=True, members=[interface]) self.provider.add_interface(interface) self.provider.add_bridge(bridge) self.provider.apply() ifcfg_data = utils.get_file_data(self.temp_ifcfg_file.name) self.assertEqual(_OVS_INTERFACE, ifcfg_data) bridge_data = utils.get_file_data(self.temp_bridge_file.name) self.assertEqual(_OVS_BRIDGE_DHCP, bridge_data) route_data = utils.get_file_data(self.temp_route_file.name) self.assertEqual("", route_data)
def test_network_apply(self): route1 = objects.Route('192.168.1.1', default=True) route2 = objects.Route('192.168.1.1', '172.19.0.0/24') v4_addr = objects.Address('192.168.1.2/24') interface = objects.Interface('em1', addresses=[v4_addr], routes=[route1, route2]) self.provider.add_interface(interface) self.provider.apply() ifcfg_data = utils.get_file_data(self.temp_ifcfg_file.name) self.assertEqual(_V4_IFCFG, ifcfg_data) route_data = utils.get_file_data(self.temp_route_file.name) self.assertEqual(_ROUTES, route_data)