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
This commit is contained in:
rabi 2017-09-03 10:11:38 +05:30
parent 4cd3c2c790
commit b93e3c637e
2 changed files with 36 additions and 6 deletions

View File

@ -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:

View File

@ -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):