diff options
| author | Eric Pendergrass <eap@hp.com> | 2014-07-29 08:52:20 -0700 |
|---|---|---|
| committer | Eric Pendergrass <eap@hp.com> | 2014-08-29 14:04:30 +0000 |
| commit | 8a01731d4e68152e9f575bea78b2baa085986726 (patch) | |
| tree | d0a3b72014f68a11ec9ca4415034bbc715a59f1b /ceilometerclient/common/base.py | |
| parent | 11134c56752a0224c4458e0827a318ba8c6e2642 (diff) | |
| download | python-ceilometerclient-8a01731d4e68152e9f575bea78b2baa085986726.tar.gz | |
Verify alarm found before modifying
Current behavior is to retrieve alarm by id and conduct operations on the
object. If the tenant doesn't own the alarm or isn't admin, the user will
receive the message: 'NoneType' object has no attribute 'to_dict'
Above message doesn't provide any useful diagnostic information and indicates a
programming error since an unexpected None-type is encountered and not handled.
This change verifies the alarm is found before using the object. If alarm not
found it prints the same message for a not found Alarm as other PUT operations
like alarm-state-set: Alarm not found: <alarm_id>.
This message is more useful for diagnosis and gets rid of the uncaught
None-type error.
Change-Id: I66abcd4498b24ac7cadcf29fe3ced3fcda08458c
Closes-Bug: #1348387
Diffstat (limited to 'ceilometerclient/common/base.py')
| -rw-r--r-- | ceilometerclient/common/base.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/ceilometerclient/common/base.py b/ceilometerclient/common/base.py index 7d4be24..4129176 100644 --- a/ceilometerclient/common/base.py +++ b/ceilometerclient/common/base.py @@ -19,6 +19,7 @@ Base utilities to build API operation managers and objects on top of. import copy +from ceilometerclient import exc from ceilometerclient.openstack.common.apiclient import base # Python 2.4 compat @@ -55,7 +56,10 @@ class Manager(object): def _list(self, url, response_key=None, obj_class=None, body=None, expect_single=False): - body = self.api.get(url).json() + resp = self.api.get(url) + if not resp.content: + raise exc.HTTPNotFound + body = resp.json() if obj_class is None: obj_class = self.resource_class |
