Browse Source

Merge "Using trustor's session to delete the trust"

Zuul 3 months ago
parent
commit
a6130e423f
3 changed files with 20 additions and 12 deletions
  1. 4
    3
      murano/common/auth_utils.py
  2. 1
    1
      murano/common/engine.py
  3. 15
    8
      murano/tests/unit/common/test_auth_utils.py

+ 4
- 3
murano/common/auth_utils.py View File

@@ -118,9 +118,10 @@ def create_trust(trustee_token=None, trustee_project_id=None):
118 118
     return trust.id
119 119
 
120 120
 
121
-def delete_trust(trust):
122
-    user_client = _create_keystone_admin_client()
123
-    user_client.trusts.delete(trust)
121
+def delete_trust(session):
122
+    user_client = create_keystone_client(
123
+        token=session.token, project_id=session.project_id)
124
+    user_client.trusts.delete(session.trust_id)
124 125
 
125 126
 
126 127
 def _get_config_option(conf_section, option_name, default=None):

+ 1
- 1
murano/common/engine.py View File

@@ -323,7 +323,7 @@ class TaskExecutor(object):
323 323
     def _delete_trust(self):
324 324
         trust_id = self._session.trust_id
325 325
         if trust_id:
326
-            auth_utils.delete_trust(self._session.trust_id)
326
+            auth_utils.delete_trust(self._session)
327 327
             self._session.system_attributes['TrustId'] = None
328 328
             self._session.trust_id = None
329 329
 

+ 15
- 8
murano/tests/unit/common/test_auth_utils.py View File

@@ -238,16 +238,23 @@ class TestAuthUtils(base.MuranoTestCase):
238 238
             role_names=mock.sentinel.role_names,
239 239
             project=mock.sentinel.project_id)
240 240
 
241
-    @mock.patch.object(
242
-        auth_utils, '_create_keystone_admin_client', autospec=True)
243
-    def test_delete_trust(self, mock_create_ks_admin_client):
244
-        mock_admin_client = mock.Mock()
245
-        mock_create_ks_admin_client.return_value = mock_admin_client
241
+    @mock.patch.object(auth_utils, 'create_keystone_client', autospec=True)
242
+    def test_delete_trust(self, mock_ks_client):
243
+        mock_auth_ref = mock.Mock(trust_id=mock.sentinel.trust_id,
244
+                                  token=mock.sentinel.token,
245
+                                  project_id=mock.sentinel.project_id)
246
+        mock_user_session = mock.Mock(**{
247
+            'auth.get_access.return_value': mock_auth_ref
248
+        })
249
+        mock_user_client = mock.Mock(
250
+            session=mock_user_session)
251
+
252
+        mock_ks_client.return_value = mock_user_client
246 253
 
247
-        auth_utils.delete_trust(mock.sentinel.trust)
254
+        auth_utils.delete_trust(mock_auth_ref)
248 255
 
249
-        mock_admin_client.trusts.delete.assert_called_once_with(
250
-            mock.sentinel.trust)
256
+        mock_user_client.trusts.delete.assert_called_once_with(
257
+            mock_auth_ref.trust_id)
251 258
 
252 259
     def test_get_config_option(self):
253 260
         cfg.CONF.set_override('url', 'foourl', 'murano')

Loading…
Cancel
Save