def test_cleaner_users_all_services(self, mock_del_cinder, mock_del_glance, mock_del_nova, mock_clients): context = { "task": mock.MagicMock(), "users": [{ "endpoint": mock.MagicMock() }, { "endpoint": mock.MagicMock() }], "config": { "cleanup": ["cinder", "nova", "glance"] }, "tenants": [mock.MagicMock()] } res_cleaner = cleanup_ctx.ResourceCleaner(context) with res_cleaner: res_cleaner.setup() expected = [ mock.call(context["users"][0]["endpoint"]), mock.call(context["users"][1]["endpoint"]) ] mock_clients.assert_has_calls(expected, any_order=True) self.assertEqual(mock_del_nova.call_count, 2) self.assertEqual(mock_del_glance.call_count, 2) self.assertEqual(mock_del_cinder.call_count, 2)
def test_with_statement_no_user_no_admin(self): context = { "task": mock.MagicMock(), "admin": None, "users": [], "tenants": [], } resource_cleaner = cleanup_ctx.ResourceCleaner(context) with resource_cleaner: resource_cleaner.setup()
def test_with_statement(self): fake_user_ctx = fakes.FakeUserContext({}).context fake_user_ctx["config"] = {"cleanup": ["nova"]} res_cleaner = cleanup_ctx.ResourceCleaner(fake_user_ctx) res_cleaner.setup() res_cleaner._cleanup_users_resources = mock.MagicMock() res_cleaner._cleanup_admin_resources = mock.MagicMock() with res_cleaner as cleaner: self.assertEqual(res_cleaner, cleaner) res_cleaner._cleanup_users_resources.assert_called_once_with() res_cleaner._cleanup_admin_resources.assert_called_once_with()
def test_cleaner_users_default_behavior(self, mock_cleanup): context = { "task": mock.MagicMock(), "users": [{ "endpoint": mock.MagicMock() }, { "endpoint": mock.MagicMock() }], } res_cleaner = cleanup_ctx.ResourceCleaner(context) with res_cleaner: res_cleaner.setup() self.assertEqual(mock_cleanup.call_count, 0)
def test_cleaner_admin(self, mock_del_keystone, mock_clients): context = { "task": mock.MagicMock(), "config": { "cleanup": ["cinder", "nova"] }, "admin": { "endpoint": mock.MagicMock() }, } res_cleaner = cleanup_ctx.ResourceCleaner(context) mock_clients.return_value.keystone.return_value = 'keystone' with res_cleaner: res_cleaner.setup() mock_clients.assert_called_once_with(context["admin"]["endpoint"]) mock_clients.return_value.keystone.assert_called_once_with() mock_del_keystone.assert_called_once_with('keystone')