From b93e3c637e9a272f54804e52ededa708af78d83b Mon Sep 17 00:00:00 2001 From: rabi Date: Sun, 3 Sep 2017 10:11:38 +0530 Subject: [PATCH] Check for keystoneauth exceptions in mistral client plugin We started to use keyston esession with mistal client plugin since pike, but it seems the patch to translate keystoneauth exceptions to mistal api exceptions did not get to python-mistalclient==3.1.2. Change-Id: I198cdbb8ee02623f2f5fb03a784135ce6f94a046 Closes-Bug: #1714679 --- heat/engine/clients/os/mistral.py | 25 +++++++++++++++++++------ heat/tests/clients/test_clients.py | 17 +++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/heat/engine/clients/os/mistral.py b/heat/engine/clients/os/mistral.py index 87e8a3cb18..0b33792b5d 100644 --- a/heat/engine/clients/os/mistral.py +++ b/heat/engine/clients/os/mistral.py @@ -11,6 +11,7 @@ # License for the specific language governing permissions and limitations # under the License. +from keystoneauth1.exceptions import http as ka_exceptions from mistralclient.api import base as mistral_base from mistralclient.api import client as mistral_client @@ -39,16 +40,28 @@ class MistralClientPlugin(client_plugin.ClientPlugin): return client def is_not_found(self, ex): - return (isinstance(ex, mistral_base.APIException) and - ex.error_code == 404) + # check for keystoneauth exceptions till requirements change + # to python-mistralclient > 3.1.2 + ka_not_found = isinstance(ex, ka_exceptions.NotFound) + mistral_not_found = (isinstance(ex, mistral_base.APIException) and + ex.error_code == 404) + return ka_not_found or mistral_not_found def is_over_limit(self, ex): - return (isinstance(ex, mistral_base.APIException) and - ex.error_code == 413) + # check for keystoneauth exceptions till requirements change + # to python-mistralclient > 3.1.2 + ka_overlimit = isinstance(ex, ka_exceptions.RequestEntityTooLarge) + mistral_overlimit = (isinstance(ex, mistral_base.APIException) and + ex.error_code == 413) + return ka_overlimit or mistral_overlimit def is_conflict(self, ex): - return (isinstance(ex, mistral_base.APIException) and - ex.error_code == 409) + # check for keystoneauth exceptions till requirements change + # to python-mistralclient > 3.1.2 + ka_conflict = isinstance(ex, ka_exceptions.Conflict) + mistral_conflict = (isinstance(ex, mistral_base.APIException) and + ex.error_code == 409) + return ka_conflict or mistral_conflict def get_workflow_by_identifier(self, workflow_identifier): try: diff --git a/heat/tests/clients/test_clients.py b/heat/tests/clients/test_clients.py index 8a6c0c936f..c15591d6d2 100644 --- a/heat/tests/clients/test_clients.py +++ b/heat/tests/clients/test_clients.py @@ -20,6 +20,7 @@ from heatclient import exc as heat_exc from keystoneauth1 import exceptions as keystone_exc from keystoneauth1.identity import generic from manilaclient import exceptions as manila_exc +from mistralclient.api import base as mistral_base import mock from neutronclient.common import exceptions as neutron_exc from openstack import exceptions @@ -792,6 +793,22 @@ class TestIsNotFound(common.HeatTestCase): plugin='manila', exception=lambda: manila_exc.Conflict(), )), + ('mistral_not_found1', dict( + is_not_found=True, + is_over_limit=False, + is_client_exception=False, + is_conflict=False, + plugin='mistral', + exception=lambda: mistral_base.APIException(404), + )), + ('mistral_not_found2', dict( + is_not_found=True, + is_over_limit=False, + is_client_exception=False, + is_conflict=False, + plugin='mistral', + exception=lambda: keystone_exc.NotFound(), + )), ] def test_is_not_found(self):