def test_ensure_bridge_concurrent_add(self, mock_dev_exists, mock_exec): mock_exec.side_effect = [ValueError(), 0, 0, 0] linux_net.ensure_bridge("br0", None, filtering=False) calls = [mock.call('brctl', 'addbr', 'br0'), mock.call('brctl', 'setfd', 'br0', 0), mock.call('brctl', 'stp', 'br0', "off"), mock.call('ip', 'link', 'set', 'br0', "up")] self.assertEqual(calls, mock_exec.mock_calls) mock_dev_exists.assert_has_calls([mock.call("br0"), mock.call("br0")])
def test_ensure_bridge_new_ipv4(self, mock_dev_exists, mock_exec, mock_path_exists): linux_net.ensure_bridge("br0", None, filtering=False) calls = [mock.call('brctl', 'addbr', 'br0'), mock.call('brctl', 'setfd', 'br0', 0), mock.call('brctl', 'stp', 'br0', "off"), mock.call('ip', 'link', 'set', 'br0', "up")] self.assertEqual(calls, mock_exec.mock_calls) mock_dev_exists.assert_called_once_with("br0")
def test_ensure_bridge_new_ipv4(self, mock_dev_exists, mock_exec, mock_path_exists): linux_net.ensure_bridge("br0", None, filtering=False) calls = [mock.call('brctl', 'addbr', 'br0'), mock.call('brctl', 'setfd', 'br0', 0), mock.call('brctl', 'stp', 'br0', "off"), mock.call('ip', 'link', 'set', 'br0', "up")] mock_exec.assert_has_calls(calls) mock_dev_exists.assert_called_once_with("br0")
def test_ensure_bridge_concurrent_add(self, mock_dev_exists, mock_exec): mock_exec.side_effect = [ValueError(), 0, 0, 0] linux_net.ensure_bridge("br0", None, filtering=False) calls = [mock.call('brctl', 'addbr', 'br0'), mock.call('brctl', 'setfd', 'br0', 0), mock.call('brctl', 'stp', 'br0', "off"), mock.call('ip', 'link', 'set', 'br0', "up")] mock_exec.assert_has_calls(calls) mock_dev_exists.assert_has_calls([mock.call("br0"), mock.call("br0")])
def test_ensure_bridge_new_ipv6(self, mock_dev_exists, mock_exec, mock_path_exists): linux_net.ensure_bridge("br0", None, filtering=False) calls = [mock.call('brctl', 'addbr', 'br0'), mock.call('brctl', 'setfd', 'br0', 0), mock.call('brctl', 'stp', 'br0', "off"), mock.call('tee', '/proc/sys/net/ipv6/conf/br0/disable_ipv6', check_exit_code=[0, 1], process_input='1'), mock.call('ip', 'link', 'set', 'br0', "up")] self.assertEqual(calls, mock_exec.mock_calls) mock_dev_exists.assert_called_once_with("br0")
def test_ensure_bridge_new_ipv6(self, mock_dev_exists, mock_exec, mock_path_exists): linux_net.ensure_bridge("br0", None, filtering=False) calls = [mock.call('brctl', 'addbr', 'br0'), mock.call('brctl', 'setfd', 'br0', 0), mock.call('brctl', 'stp', 'br0', "off"), mock.call('tee', '/proc/sys/net/ipv6/conf/br0/disable_ipv6', check_exit_code=[0, 1], process_input='1'), mock.call('ip', 'link', 'set', 'br0', "up")] mock_exec.assert_has_calls(calls) mock_dev_exists.assert_called_once_with("br0")
def plug(self, vif, instance_info): """Ensure that the bridge exists, and add VIF to it.""" network = vif.network bridge_name = vif.bridge_name if not network.multi_host and network.should_provide_bridge: if network.should_provide_vlan: iface = self.config.vlan_interface or network.bridge_interface mtu = self.config.network_device_mtu linux_net.ensure_vlan_bridge(network.vlan, bridge_name, iface, mtu=mtu) else: iface = self.config.flat_interface or network.bridge_interface linux_net.ensure_bridge(bridge_name, iface)
def test_ensure_bridge(self, mock_filtering, mock_priv): linux_net.ensure_bridge("br0", None, filtering=False) mock_priv.assert_called_once_with("br0", None, None, True, filtering=False, mtu=None) mock_filtering.assert_not_called() linux_net.ensure_bridge("br0", None, filtering=True) mock_filtering.assert_called_once_with("br0", True)
def plug(self, vif, instance_info): """Ensure that the bridge exists, and add VIF to it.""" network = vif.network bridge_name = vif.bridge_name if not network.multi_host and network.should_provide_bridge: mtu = network.mtu or self.config.network_device_mtu if network.should_provide_vlan: iface = self.config.vlan_interface or network.bridge_interface linux_net.ensure_vlan_bridge(network.vlan, bridge_name, iface, mtu=mtu) else: iface = self.config.flat_interface or network.bridge_interface # only put in iptables rules if Neutron not filtering install_filters = not vif.has_traffic_filtering linux_net.ensure_bridge(bridge_name, iface, filtering=install_filters, mtu=mtu)
def test_ensure_bridge_addbr_exception(self, mock_dev_exists, mock_exec): mock_exec.side_effect = ValueError() with testtools.ExpectedException(ValueError): linux_net.ensure_bridge("br0", None, filtering=False)
def test_ensure_bridge_exists(self, mock_dev_exists, mock_exec): linux_net.ensure_bridge("br0", None, filtering=False) self.assertEqual([], mock_exec.mock_calls) mock_dev_exists.assert_called_once_with("br0")
def test_ensure_bridge_exists(self, mock_dev_exists, mock_exec): linux_net.ensure_bridge("br0", None, filtering=False) mock_exec.assert_not_called() mock_dev_exists.assert_called_once_with("br0")