import unittest2 as unittest
from quantum.agent import netns_cleanup_util as util
+from quantum.openstack.common import cfg
class TestNullDelegate(unittest.TestCase):
class TestNetnsCleanup(unittest.TestCase):
- def test_setup_conf(self):
- with mock.patch('quantum.common.config.setup_logging'):
- conf = util.setup_conf()
- self.assertFalse(conf.force)
+ def tearDown(self):
+ cfg.CONF.reset()
def test_kill_dhcp(self, dhcp_active=True):
conf = mock.Mock()
with mock.patch.multiple(util, **methods_to_mock) as mocks:
mocks['eligible_for_deletion'].return_value = True
mocks['setup_conf'].return_value = conf
- util.main()
+ with mock.patch('quantum.common.config.setup_logging'):
+ util.main()
- mocks['eligible_for_deletion'].assert_has_calls(
- [mock.call(conf, 'ns1', False),
- mock.call(conf, 'ns2', False)])
+ mocks['eligible_for_deletion'].assert_has_calls(
+ [mock.call(conf, 'ns1', False),
+ mock.call(conf, 'ns2', False)])
- mocks['destroy_namespace'].assert_has_calls(
- [mock.call(conf, 'ns1', False),
- mock.call(conf, 'ns2', False)])
+ mocks['destroy_namespace'].assert_has_calls(
+ [mock.call(conf, 'ns1', False),
+ mock.call(conf, 'ns2', False)])
- ip_wrap.assert_has_calls(
- [mock.call.get_namespaces(conf.AGENT.root_helper)])
+ ip_wrap.assert_has_calls(
+ [mock.call.get_namespaces(conf.AGENT.root_helper)])
- eventlet_sleep.assert_called_once_with(2)
+ eventlet_sleep.assert_called_once_with(2)
def test_main_no_candidates(self):
namespaces = ['ns1', 'ns2']
with mock.patch.multiple(util, **methods_to_mock) as mocks:
mocks['eligible_for_deletion'].return_value = False
mocks['setup_conf'].return_value = conf
- util.main()
+ with mock.patch('quantum.common.config.setup_logging'):
+ util.main()
- ip_wrap.assert_has_calls(
- [mock.call.get_namespaces(conf.AGENT.root_helper)])
+ ip_wrap.assert_has_calls(
+ [mock.call.get_namespaces(conf.AGENT.root_helper)])
- mocks['eligible_for_deletion'].assert_has_calls(
- [mock.call(conf, 'ns1', False),
- mock.call(conf, 'ns2', False)])
+ mocks['eligible_for_deletion'].assert_has_calls(
+ [mock.call(conf, 'ns1', False),
+ mock.call(conf, 'ns2', False)])
- self.assertFalse(mocks['destroy_namespace'].called)
+ self.assertFalse(mocks['destroy_namespace'].called)
- self.assertFalse(eventlet_sleep.called)
+ self.assertFalse(eventlet_sleep.called)
from quantum.agent.linux import ip_lib
from quantum.agent.linux import ovs_lib
from quantum.agent import ovs_cleanup_util as util
+from quantum.openstack.common import cfg
from quantum.openstack.common import uuidutils
class TestOVSCleanup(unittest.TestCase):
+ def tearDown(self):
+ cfg.CONF.reset()
+
def test_setup_conf(self):
- with mock.patch('quantum.common.config.setup_logging'):
- conf = util.setup_conf()
- self.assertEqual(conf.external_network_bridge, 'br-ex')
- self.assertEqual(conf.ovs_integration_bridge, 'br-int')
- self.assertFalse(conf.ovs_all_ports)
- self.assertEqual(conf.AGENT.root_helper, 'sudo')
+ conf = util.setup_conf()
+ self.assertEqual(conf.external_network_bridge, 'br-ex')
+ self.assertEqual(conf.ovs_integration_bridge, 'br-int')
+ self.assertFalse(conf.ovs_all_ports)
+ self.assertEqual(conf.AGENT.root_helper, 'sudo')
def test_main(self):
bridges = ['br-int', 'br-ex']
return_value=ports),
mock.patch.object(util, 'delete_quantum_ports')
) as (_log, _conf, _get, ovs, collect, delete):
- util.main()
- ovs.assert_has_calls([mock.call().delete_ports(all_ports=False)])
- collect.assert_called_once_with(set(bridges), 'dummy_sudo')
- delete.assert_called_once_with(ports, 'dummy_sudo')
+ with mock.patch('quantum.common.config.setup_logging'):
+ util.main()
+ ovs.assert_has_calls([mock.call().delete_ports(
+ all_ports=False)])
+ collect.assert_called_once_with(set(bridges), 'dummy_sudo')
+ delete.assert_called_once_with(ports, 'dummy_sudo')
def test_collect_quantum_ports(self):
port1 = ovs_lib.VifPort('tap1234', 1, uuidutils.generate_uuid(),