Additional exception type check for ceilo-client

This adds additional exception type checking for ceilometer client.
In addition to previous HTTPNotFound exception, ceilometer client lib
may throw an apiclient.NotFound exception directly.  Both cases should
be treated as 'valid' results from HTTP 404, so that the
ignore-not-found logic in Heat can work using either version of
ceilometer client.

Change-Id: Iedd061afe0cf039d5070257caf0d5a726213a8af
Closes-Bug: 1361128
This commit is contained in:
tengqm 2014-08-26 09:32:13 +08:00
parent 6e3488be15
commit f620834132
3 changed files with 19 additions and 4 deletions

@ -62,7 +62,12 @@ class ClientPlugin():
def is_client_exception(self, ex):
'''Returns True if the current exception comes from the client.'''
if self.exceptions_module:
return type(ex) in self.exceptions_module.__dict__.values()
if isinstance(self.exceptions_module, list):
for m in self.exceptions_module:
if type(ex) in m.__dict__.values():
return True
else:
return type(ex) in self.exceptions_module.__dict__.values()
return False
def is_not_found(self, ex):

@ -13,13 +13,14 @@
from ceilometerclient import client as cc
from ceilometerclient import exc
from ceilometerclient.openstack.common.apiclient import exceptions as api_exc
from heat.engine.clients import client_plugin
class CeilometerClientPlugin(client_plugin.ClientPlugin):
exceptions_module = exc
exceptions_module = [exc, api_exc]
def _create(self):
@ -42,7 +43,7 @@ class CeilometerClientPlugin(client_plugin.ClientPlugin):
return cc.Client('2', endpoint, **args)
def is_not_found(self, ex):
return isinstance(ex, exc.HTTPNotFound)
return isinstance(ex, (exc.HTTPNotFound, api_exc.NotFound))
def is_over_limit(self, ex):
return isinstance(ex, exc.HTTPOverLimit)

@ -12,6 +12,7 @@
# under the License.
from ceilometerclient import exc as ceil_exc
from ceilometerclient.openstack.common.apiclient import exceptions as c_a_exc
from cinderclient import exceptions as cinder_exc
from glanceclient import exc as glance_exc
from heatclient import exc as heat_exc
@ -236,6 +237,13 @@ class TestIsNotFound(HeatTestCase):
plugin='ceilometer',
exception=lambda: ceil_exc.HTTPNotFound(details='gone'),
)),
('ceilometer_not_found_apiclient', dict(
is_not_found=True,
is_over_limit=False,
is_client_exception=True,
plugin='ceilometer',
exception=lambda: c_a_exc.NotFound(details='gone'),
)),
('ceilometer_exception', dict(
is_not_found=False,
is_over_limit=False,
@ -491,5 +499,6 @@ class TestIsNotFound(HeatTestCase):
raise self.exception()
except Exception as e:
ice = self.is_client_exception
if ice != client_plugin.is_client_exception(e):
actual = client_plugin.is_client_exception(e)
if ice != actual:
raise