Пример #1
0
    def test_main_no_candidates(self):
        namespaces = ['ns1', 'ns2']
        with mock.patch('neutron.agent.linux.ip_lib.IPWrapper') as ip_wrap:
            ip_wrap.get_namespaces.return_value = namespaces

            with mock.patch('time.sleep') as time_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('neutron.common.config.setup_logging'):
                        util.main()

                        ip_wrap.assert_has_calls(
                            [mock.call.get_namespaces()])

                        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(time_sleep.called)
Пример #2
0
    def test_main_no_candidates(self):
        namespaces = ['ns1', 'ns2']
        with mock.patch('neutron.agent.linux.ip_lib.IPWrapper') as ip_wrap:
            ip_wrap.get_namespaces.return_value = namespaces

            with mock.patch('time.sleep') as time_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('neutron.common.config.setup_logging'):
                        util.main()

                        ip_wrap.assert_has_calls([mock.call.get_namespaces()])

                        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(time_sleep.called)
Пример #3
0
    def test_main(self):
        namespaces = ['ns1', 'ns2']
        with mock.patch('neutron.agent.linux.ip_lib.'
                        'list_network_namespaces') as listnetns:
            listnetns.return_value = namespaces

            with mock.patch('time.sleep') as time_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('neutron.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)
                        ])

                        self.assertEqual(1, listnetns.call_count)

                        time_sleep.assert_called_once_with(2)
Пример #4
0
    def test_main(self):
        namespaces = ['ns1', 'ns2']
        with mock.patch('neutron.agent.linux.ip_lib.'
                        'list_network_namespaces') as listnetns:
            listnetns.return_value = namespaces

            with mock.patch('time.sleep') as time_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('neutron.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)])

                        self.assertEqual(1, listnetns.call_count)

                        time_sleep.assert_called_once_with(2)
Пример #5
0
    def test_main(self):
        namespaces = ['ns1', 'ns2']
        with mock.patch('neutron.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('neutron.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)
Пример #6
0
    def test_main(self):
        namespaces = ["ns1", "ns2"]
        with mock.patch("neutron.agent.linux.ip_lib.IPWrapper") as ip_wrap:
            ip_wrap.get_namespaces.return_value = namespaces

            with mock.patch("time.sleep") as time_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("neutron.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()])

                        time_sleep.assert_called_once_with(2)
Пример #7
0
    def test_main(self):
        namespaces = ['ns1', 'ns2']
        with mock.patch('neutron.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('neutron.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)