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_network_ovs_bridge_with_dhcp(self): interface = self._default_interface() 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, self.provider.bridges['br0'])
def test_vlan_ovs_bridge_int_port(self): vlan = objects.Vlan('eth0', 5) bridge = objects.OvsBridge('br0', use_dhcp=True, members=[vlan]) self.provider.add_bridge(bridge) self.provider.add_vlan(vlan) self.assertEqual(_VLAN_OVS_PORT, self.get_interface_config('vlan5'))
def test_add_ovs_bridge_with_vlan(self): vlan = objects.Vlan('em1', 5) bridge = objects.OvsBridge('br-ctlplane', use_dhcp=True, members=[vlan]) self.provider.add_vlan(vlan) self.provider.add_bridge(bridge) self.assertEqual(_VLAN_OVS_BRIDGE, self.get_vlan_config('vlan5'))
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_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_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_ovs_bridge_with_standalone_fail_mode(self): interface = self._default_interface() bridge = objects.OvsBridge('br0', use_dhcp=True, members=[interface], fail_mode='standalone') self.provider.add_bridge(bridge) self.provider.add_interface(interface) self.assertEqual(_OVS_PORT_IFACE, self.get_interface_config()) self.assertEqual(_OVS_BRIDGE_DHCP_STANDALONE, self.provider.bridges['br0'])
def test_network_ovs_bridge_static(self): v4_addr = objects.Address('192.168.1.2/24') interface = objects.Interface('em1') bridge = objects.OvsBridge('br-ctlplane', members=[interface], addresses=[v4_addr]) self.provider.add_interface(interface) self.provider.add_bridge(bridge) self.assertEqual(_OVS_INTERFACE, self.get_interface_config()) self.assertEqual(_OVS_BRIDGE_STATIC, self.provider.bridge_data['br-ctlplane'])
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_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_ovs_bridge_with_dhcp_primary_interface(self): def test_interface_mac(name): return "a1:b2:c3:d4:e5" self.stubs.Set(utils, 'interface_mac', test_interface_mac) interface = objects.Interface('em1', primary=True) 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_PRIMARY_INTERFACE, self.provider.bridge_data['br-ctlplane'])
def test_network_ovs_bridge_with_tunnel(self): interface = objects.OvsTunnel('tun0') interface.type = 'ovs_tunnel' interface.tunnel_type = 'gre' interface.ovs_options = ['options:remote_ip=192.168.1.1'] interface.bridge_name = 'br-ctlplane' self.provider.add_interface(interface) v4_addr = objects.Address('192.168.1.2/24') bridge = objects.OvsBridge('br-ctlplane', members=[interface], addresses=[v4_addr]) self.provider.add_bridge(bridge) self.provider.add_interface(interface) self.assertEqual(_OVS_IFCFG_TUNNEL, self.get_interface_config('tun0')) self.assertEqual(_OVS_BRIDGE_STATIC, self.provider.bridge_data['br-ctlplane'])
def test_network_ovs_bridge_with_dhcp_and_primary_with_ovs_format(self): def test_interface_mac(name): return "a1:b2:c3:d4:e5" self.stub_out('os_net_config.utils.interface_mac', test_interface_mac) interface = objects.Interface(self.if_name, primary=True) ovs_extra = "br-set-external-id {name} bridge-id {name}" bridge = objects.OvsBridge('br0', use_dhcp=True, members=[interface], ovs_extra=[ovs_extra]) self.provider.add_bridge(bridge) self.provider.add_interface(interface) self.assertEqual(_OVS_PORT_IFACE, self.get_interface_config()) self.assertEqual(_OVS_BRIDGE_DHCP_OVS_EXTRA, self.provider.bridges['br0'])
def test_network_ovs_bridge_with_dhcp_primary_interface_with_format(self): def test_interface_mac(name): return "a1:b2:c3:d4:e5" self.stubs.Set(utils, 'interface_mac', test_interface_mac) interface = objects.Interface('em1', primary=True) ovs_extra = "br-set-external-id {name} bridge-id {name}" bridge = objects.OvsBridge('br-ctlplane', use_dhcp=True, members=[interface], ovs_extra=[ovs_extra]) self.provider.add_interface(interface) self.provider.add_bridge(bridge) self.assertEqual(_OVS_INTERFACE, self.get_interface_config()) self.assertEqual(_OVS_BRIDGE_DHCP_OVS_EXTRA, self.provider.bridge_data['br-ctlplane'])