def test_main_no_candidates(self): namespaces = ['ns1', 'ns2'] with mock.patch('quantum.agent.linux.ip_lib.IPWrapper') as ip_wrap: ip_wrap.get_namespaces.return_value = namespaces with mock.patch('eventlet.sleep') as eventlet_sleep: conf = mock.Mock() conf.force = False methods_to_mock = dict( eligible_for_deletion=mock.DEFAULT, destroy_namespace=mock.DEFAULT, setup_conf=mock.DEFAULT) with mock.patch.multiple(util, **methods_to_mock) as mocks: mocks['eligible_for_deletion'].return_value = False mocks['setup_conf'].return_value = conf with mock.patch('quantum.common.config.setup_logging'): util.main() 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)]) self.assertFalse(mocks['destroy_namespace'].called) self.assertFalse(eventlet_sleep.called)
def test_main_no_candidates(self): namespaces = ['ns1', 'ns2'] with mock.patch('quantum.agent.linux.ip_lib.IPWrapper') as ip_wrap: ip_wrap.get_namespaces.return_value = namespaces with mock.patch('eventlet.sleep') as eventlet_sleep: conf = mock.Mock() conf.root_helper = 'sudo' conf.force = False methods_to_mock = dict(eligible_for_deletion=mock.DEFAULT, destroy_namespace=mock.DEFAULT, setup_conf=mock.DEFAULT) 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() ip_wrap.assert_has_calls( [mock.call.get_namespaces('sudo')]) 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(eventlet_sleep.called)
def test_main(self): namespaces = ["ns1", "ns2"] with mock.patch("quantum.agent.linux.ip_lib.IPWrapper") as ip_wrap: ip_wrap.get_namespaces.return_value = namespaces with mock.patch("eventlet.sleep") as eventlet_sleep: conf = mock.Mock() conf.force = False methods_to_mock = dict( eligible_for_deletion=mock.DEFAULT, destroy_namespace=mock.DEFAULT, setup_conf=mock.DEFAULT ) with mock.patch.multiple(util, **methods_to_mock) as mocks: mocks["eligible_for_deletion"].return_value = True mocks["setup_conf"].return_value = conf 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["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)]) eventlet_sleep.assert_called_once_with(2)
def test_main(self): namespaces = ['ns1', 'ns2'] with mock.patch('quantum.agent.linux.ip_lib.IPWrapper') as ip_wrap: ip_wrap.get_namespaces.return_value = namespaces with mock.patch('eventlet.sleep') as eventlet_sleep: conf = mock.Mock() conf.root_helper = 'sudo' conf.force = False methods_to_mock = dict( eligible_for_deletion=mock.DEFAULT, destroy_namespace=mock.DEFAULT, setup_conf=mock.DEFAULT) 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() 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)]) ip_wrap.assert_has_calls( [mock.call.get_namespaces('sudo')]) eventlet_sleep.assert_called_once_with(2)
def test_main(self): namespaces = ['ns1', 'ns2'] with mock.patch('quantum.agent.linux.ip_lib.IPWrapper') as ip_wrap: ip_wrap.get_namespaces.return_value = namespaces with mock.patch('eventlet.sleep') as eventlet_sleep: conf = mock.Mock() conf.force = False methods_to_mock = dict(eligible_for_deletion=mock.DEFAULT, destroy_namespace=mock.DEFAULT, setup_conf=mock.DEFAULT) with mock.patch.multiple(util, **methods_to_mock) as mocks: mocks['eligible_for_deletion'].return_value = True mocks['setup_conf'].return_value = conf 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['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)]) eventlet_sleep.assert_called_once_with(2)