예제 #1
0
    def test_list(self):
        self.cloud.list_ports.return_value = []

        self.assertIsInstance(
            neutron.RouterInterfaces(self.creds_manager).list(), list)

        self.cloud.list_ports.assert_has_calls([
            mock.call(
                filters={
                    'device_owner': 'network:router_interface',
                    'tenant_id': self.creds_manager.project_id
                }),
            mock.call(
                filters={
                    'device_owner': 'network:router_interface_distributed',
                    'tenant_id': self.creds_manager.project_id
                }),
            mock.call(
                filters={
                    'device_owner': 'network:ha_router_replicated_interface',
                    'tenant_id': self.creds_manager.project_id
                }),
            mock.call(
                filters={
                    'device_owner': 'network:router_gateway',
                    'tenant_id': self.creds_manager.project_id
                }),
        ])
예제 #2
0
    def test_should_delete(self):
        creds_manager = mock.Mock()
        resource_manager = base.ServiceResource(creds_manager)

        resource = mock.Mock(get=mock.Mock(side_effect=[None, None]))
        self.assertEqual(True, resource_manager.should_delete(resource))
        resource.get.call_args = [mock.call('project_id'),
                                  mock.call('tenant_id')]

        resource.get.side_effect = ["Foo", "Bar"]
        self.assertEqual(False, resource_manager.should_delete(resource))

        resource.get.side_effect = [42, resource_manager.cleanup_project_id]
        self.assertEqual(True, resource_manager.should_delete(resource))
예제 #3
0
    def test_runner_disable(self):
        resources = [mock.Mock(), mock.Mock(), mock.Mock()]
        resource_manager = mock.Mock(list=mock.Mock(return_value=resources))
        options = mock.Mock(dry_run=False, resource=False, disable_only=True)
        exit = mock.Mock(is_set=mock.Mock(side_effect=[False, False, True]))

        main.runner(resource_manager, options, exit)

        resource_manager.list.assert_called_once_with()
        resource_manager.wait_for_check_prerequisite.assert_not_called()
        resource_manager.should_delete.assert_not_called()
        resource_manager.delete.assert_not_called()
        self.assertEqual(2, resource_manager.disable.call_count)
        self.assertEqual([mock.call(resources[0]),
                          mock.call(resources[1])],
                         resource_manager.disable.call_args_list)
예제 #4
0
    def test_call_and_ignore_notfound(self):
        def raiser():
            raise os_exceptions.OpenStackCloudException("")

        self.assertIsNone(
            utils.call_and_ignore_exc(os_exceptions.OpenStackCloudException,
                                      raiser))

        m = mock.Mock()
        utils.call_and_ignore_exc(os_exceptions.OpenStackCloudException, m, 42)
        self.assertEqual([mock.call(42)], m.call_args_list)
예제 #5
0
    def test_call_and_ignore_notfound(self):
        def raiser():
            raise shade.exc.OpenStackCloudResourceNotFound("")

        self.assertIsNone(
            utils.call_and_ignore_exc(shade.exc.OpenStackCloudResourceNotFound,
                                      raiser))

        m = mock.Mock()
        utils.call_and_ignore_exc(shade.exc.OpenStackCloudResourceNotFound, m,
                                  42)
        self.assertEqual([mock.call(42)], m.call_args_list)
예제 #6
0
    def test_wait_for_check_prerequisite_runtimeerror(self,
                                                      mock_check_prerequisite,
                                                      mock_sleep):
        resource_manager = base.ServiceResource(mock.Mock())
        mock_exit = mock.Mock(is_set=mock.Mock(return_value=False))

        with mock.patch('time.time') as mock_time:
            mock_time.side_effect = generate_timeout_series(675)
            self.assertRaisesRegex(
                exceptions.TimeoutError, "^Timeout exceeded .*",
                resource_manager.wait_for_check_prerequisite, mock_exit)
        self.assertEqual(mock_check_prerequisite.call_args_list,
                         [mock.call()] * (2700 // 675 - 1))
        self.assertEqual(mock_sleep.call_args_list,
                         [mock.call(i) for i in (2, 4, 8)])

        mock_sleep.reset_mock()
        mock_check_prerequisite.reset_mock()
        mock_exit.is_set.return_value = True
        self.assertRaisesRegex(RuntimeError,
                               ".* exited because it was interrupted .*",
                               resource_manager.wait_for_check_prerequisite,
                               mock_exit)
예제 #7
0
    def test_wait_for_check_prerequisite_runtimeerror(
            self, mock_check_prerequisite, mock_sleep):
        resource_manager = base.ServiceResource(mock.Mock())
        mock_exit = mock.Mock(is_set=mock.Mock(return_value=False))

        with mock.patch('time.time') as mock_time:
            mock_time.side_effect = generate_timeout_series(30)
            self.assertRaisesRegex(
                exceptions.TimeoutError, "^Timeout exceeded .*",
                resource_manager.wait_for_check_prerequisite, mock_exit
            )

        self.assertEqual(mock_check_prerequisite.call_args_list,
                         [mock.call()] * (120 // 30 - 1))
        self.assertEqual(mock_sleep.call_args_list,
                         [mock.call(i) for i in (2, 4, 8)])

        mock_sleep.reset_mock()
        mock_check_prerequisite.reset_mock()
        mock_exit.is_set.return_value = True
        self.assertRaisesRegex(
            RuntimeError, ".* exited because it was interrupted .*",
            resource_manager.wait_for_check_prerequisite, mock_exit
        )