Merge "Catch Unauthorized in delete_trust()"

This commit is contained in:
Jenkins
2017-03-20 04:45:34 +00:00
committed by Gerrit Code Review
3 changed files with 19 additions and 23 deletions

View File

@@ -236,7 +236,7 @@ class KsClientWrapper(object):
"""Delete the specified trust."""
try:
self.client.trusts.delete(trust_id)
except ks_exception.NotFound:
except (ks_exception.NotFound, ks_exception.Unauthorized):
pass
def _get_username(self, username):

View File

@@ -20,7 +20,6 @@ import itertools
import re
import warnings
from keystoneauth1 import exceptions as ks_exceptions
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import encodeutils
@@ -1704,11 +1703,6 @@ class Stack(collections.Mapping):
else:
self.clients.client('keystone').delete_trust(
trust_id)
except ks_exceptions.Unauthorized:
# ignore if unauthorized, don't to set FAILED
LOG.warning(_LW("Unauthorized, including the cases: "
"the trustor is deleted or the trust "
"is expired."))
except Exception as ex:
LOG.exception(_LE("Error deleting trust"))
stack_status = self.FAILED

View File

@@ -707,36 +707,38 @@ class KeystoneClientTest(common.HeatTestCase):
heat_ks_client = heat_keystoneclient.KeystoneClient(ctx)
self.assertIsNotNone(heat_ks_client._client)
def test_delete_trust(self):
"""Test delete_trust when deleting trust."""
def _test_delete_trust(self, raise_ext=None):
self._stubs_auth()
cfg.CONF.set_override('deferred_auth_method', 'trusts',
enforce_type=True)
self.mock_ks_v3_client.trusts = self.m.CreateMockAnything()
self.mock_ks_v3_client.trusts.delete('atrust123').AndReturn(None)
if raise_ext is None:
self.mock_ks_v3_client.trusts.delete('atrust123').AndReturn(None)
else:
self.mock_ks_v3_client.trusts.delete('atrust123').AndRaise(
raise_ext)
self.m.ReplayAll()
ctx = utils.dummy_context()
heat_ks_client = heat_keystoneclient.KeystoneClient(ctx)
self.assertIsNone(heat_ks_client.delete_trust(trust_id='atrust123'))
def test_delete_trust(self):
"""Test delete_trust when deleting trust."""
self._test_delete_trust()
def test_delete_trust_not_found(self):
"""Test delete_trust when trust already deleted."""
self._stubs_auth()
cfg.CONF.set_override('deferred_auth_method', 'trusts',
enforce_type=True)
self.mock_ks_v3_client.trusts = self.m.CreateMockAnything()
self.mock_ks_v3_client.trusts.delete('atrust123').AndRaise(
kc_exception.NotFound)
self._test_delete_trust(raise_ext=kc_exception.NotFound)
self.m.ReplayAll()
ctx = utils.dummy_context()
heat_ks_client = heat_keystoneclient.KeystoneClient(ctx)
self.assertIsNone(heat_ks_client.delete_trust(trust_id='atrust123'))
def test_delete_trust_unauthorized(self):
"""Test delete_trust when trustor is deleted or trust is expired."""
self._test_delete_trust(raise_ext=kc_exception.Unauthorized)
def test_disable_stack_user(self):