From 40fcbcb8852cad03eec345106772292fa08b25dc Mon Sep 17 00:00:00 2001 From: Édouard Thuleau Date: Tue, 27 Nov 2012 17:15:34 +0100 Subject: Remove unused bridge interfaces If a network gateway of multi hosted network is unsed by any VM on the host, we tear down it. It is implemented only with the VLAN manager. Fixes LP bug #1084651 Change-Id: Ia7e399de5b8ddf6ec252d38dfbb8762c4f14e3a5 --- nova/tests/network/test_linux_net.py | 27 +++++++++++++++++++++++++++ nova/tests/test_db_api.py | 17 +++++++++++++++++ 2 files changed, 44 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/network/test_linux_net.py b/nova/tests/network/test_linux_net.py index 55a9c7777..68aaa6251 100644 --- a/nova/tests/network/test_linux_net.py +++ b/nova/tests/network/test_linux_net.py @@ -494,6 +494,33 @@ class LinuxNetworkTestCase(test.TestCase): for inp in expected_inputs: self.assertTrue(inp in inputs[0]) + executes = [] + inputs = [] + + @classmethod + def fake_remove(_self, bridge, gateway): + return + + self.stubs.Set(linux_net.LinuxBridgeInterfaceDriver, + 'remove_bridge', fake_remove) + + driver.unplug(network) + expected = [ + ('ebtables', '-D', 'INPUT', '-p', 'ARP', '-i', iface, + '--arp-ip-dst', dhcp, '-j', 'DROP'), + ('ebtables', '-D', 'OUTPUT', '-p', 'ARP', '-o', iface, + '--arp-ip-src', dhcp, '-j', 'DROP'), + ('iptables-save', '-c', '-t', 'filter'), + ('iptables-restore', '-c'), + ('iptables-save', '-c', '-t', 'nat'), + ('iptables-restore', '-c'), + ('ip6tables-save', '-c', '-t', 'filter'), + ('ip6tables-restore', '-c'), + ] + self.assertEqual(executes, expected) + for inp in expected_inputs: + self.assertFalse(inp in inputs[0]) + def _test_initialize_gateway(self, existing, expected, routes=''): self.flags(fake_network=False) executes = [] diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index f2124c021..29bce8bf5 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -582,6 +582,23 @@ class DbApiTestCase(test.TestCase): data = db.network_get_all_by_host(ctxt, 'foo') self.assertEqual(len(data), 3) + def test_network_in_use_on_host(self): + ctxt = context.get_admin_context() + + values = {'host': 'foo', 'hostname': 'myname'} + instance = db.instance_create(ctxt, values) + values = {'address': 'bar', 'instance_uuid': instance['uuid']} + vif = db.virtual_interface_create(ctxt, values) + values = {'address': 'baz', + 'network_id': 1, + 'allocated': True, + 'instance_uuid': instance['uuid'], + 'virtual_interface_id': vif['id']} + db.fixed_ip_create(ctxt, values) + + self.assertEqual(db.network_in_use_on_host(ctxt, 1, 'foo'), True) + self.assertEqual(db.network_in_use_on_host(ctxt, 1, 'bar'), False) + def _timeout_test(self, ctxt, timeout, multi_host): values = {'host': 'foo'} instance = db.instance_create(ctxt, values) -- cgit