From d6b777e12616d33a932bc4ca1035e8f7c9bea5f1 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Mon, 13 Jan 2014 16:57:14 +0000 Subject: [PATCH] Convert heat_keystoneclient user enable/disable logic to v3 API Migrate the enable_stack_user and disable_stack_user functions to use the v3 API. Change-Id: Ieebc94cf09ba952d0ec0499091ba52906d6fe9cb blueprint: keystone-v3-only --- heat/common/heat_keystoneclient.py | 6 ++---- heat/tests/test_heatclient.py | 34 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/heat/common/heat_keystoneclient.py b/heat/common/heat_keystoneclient.py index ebf593d817..aa63043679 100644 --- a/heat/common/heat_keystoneclient.py +++ b/heat/common/heat_keystoneclient.py @@ -283,12 +283,10 @@ class KeystoneClient(object): return self.client_v2.ec2.create(uid, self.context.tenant_id) def disable_stack_user(self, user_id): - # FIXME : This won't work with the v3 keystone API - self.client_v2.users.update_enabled(user_id, False) + self.client_v3.users.update(user=user_id, enabled=False) def enable_stack_user(self, user_id): - # FIXME : This won't work with the v3 keystone API - self.client_v2.users.update_enabled(user_id, True) + self.client_v3.users.update(user=user_id, enabled=True) def url_for(self, **kwargs): return self.client_v2.service_catalog.url_for(**kwargs) diff --git a/heat/tests/test_heatclient.py b/heat/tests/test_heatclient.py index ff02c31d05..1d0f79e324 100644 --- a/heat/tests/test_heatclient.py +++ b/heat/tests/test_heatclient.py @@ -415,3 +415,37 @@ class KeystoneClientTest(HeatTestCase): ctx = utils.dummy_context() heat_ks_client = heat_keystoneclient.KeystoneClient(ctx) self.assertIsNone(heat_ks_client.delete_trust(trust_id='atrust123')) + + def test_disable_stack_user(self): + + """Test disabling a stack user.""" + + self._stubs_v3() + + ctx = utils.dummy_context() + ctx.trust_id = None + + # mock keystone client update function + self.mock_ks_v3_client.users = self.m.CreateMockAnything() + self.mock_ks_v3_client.users.update(user='atestuser', enabled=False + ).AndReturn(None) + self.m.ReplayAll() + heat_ks_client = heat_keystoneclient.KeystoneClient(ctx) + heat_ks_client.disable_stack_user('atestuser') + + def test_enable_stack_user(self): + + """Test enabling a stack user.""" + + self._stubs_v3() + + ctx = utils.dummy_context() + ctx.trust_id = None + + # mock keystone client update function + self.mock_ks_v3_client.users = self.m.CreateMockAnything() + self.mock_ks_v3_client.users.update(user='atestuser', enabled=True + ).AndReturn(None) + self.m.ReplayAll() + heat_ks_client = heat_keystoneclient.KeystoneClient(ctx) + heat_ks_client.enable_stack_user('atestuser')