Merge "Catch missing 404 exceptions in client"
This commit is contained in:
@@ -21,6 +21,7 @@ import copy
|
||||
|
||||
from ceilometerclient import exc
|
||||
from ceilometerclient.openstack.common.apiclient import base
|
||||
from ceilometerclient.openstack.common.apiclient import exceptions
|
||||
|
||||
# Python 2.4 compat
|
||||
try:
|
||||
@@ -65,7 +66,10 @@ class Manager(object):
|
||||
|
||||
def _list(self, url, response_key=None, obj_class=None, body=None,
|
||||
expect_single=False):
|
||||
resp = self.api.get(url)
|
||||
try:
|
||||
resp = self.api.get(url)
|
||||
except exceptions.NotFound:
|
||||
raise exc.HTTPNotFound
|
||||
if not resp.content:
|
||||
raise exc.HTTPNotFound
|
||||
body = resp.json()
|
||||
|
||||
@@ -511,7 +511,7 @@ class ShellSampleShowCommandTest(utils.BaseTestCase):
|
||||
|
||||
@mock.patch('sys.stdout', new=six.StringIO())
|
||||
def test_sample_show_raises_command_err(self):
|
||||
self.cc.new_samples.get.return_value = None
|
||||
self.cc.new_samples.get.side_effect = exc.HTTPNotFound
|
||||
|
||||
self.assertRaises(exc.CommandError, ceilometer_shell.do_sample_show,
|
||||
self.cc, self.args)
|
||||
|
||||
@@ -170,9 +170,9 @@ def _do_sample_list(cc, args):
|
||||
help='ID (aka message ID) of the sample to show.')
|
||||
def do_sample_show(cc, args):
|
||||
'''Show an sample.'''
|
||||
sample = cc.new_samples.get(args.sample_id)
|
||||
|
||||
if sample is None:
|
||||
try:
|
||||
sample = cc.new_samples.get(args.sample_id)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError('Sample not found: %s' % args.sample_id)
|
||||
|
||||
fields = ['id', 'meter', 'volume', 'type', 'unit', 'source',
|
||||
@@ -405,6 +405,8 @@ def _display_alarm(alarm):
|
||||
def do_alarm_show(cc, args={}):
|
||||
"""Show an alarm."""
|
||||
alarm = cc.alarms.get(args.alarm_id)
|
||||
# alarm.get actually catches the HTTPNotFound exception and turns the
|
||||
# result into None if the alarm wasn't found.
|
||||
if alarm is None:
|
||||
raise exc.CommandError('Alarm not found: %s' % args.alarm_id)
|
||||
else:
|
||||
@@ -1046,7 +1048,11 @@ def do_event_list(cc, args={}):
|
||||
help='The ID of the event. Should be a UUID.')
|
||||
def do_event_show(cc, args={}):
|
||||
"""Show a particular event."""
|
||||
event = cc.events.get(args.message_id)
|
||||
try:
|
||||
event = cc.events.get(args.message_id)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError('Event not found: %s' % args.message_id)
|
||||
|
||||
fields = ['event_type', 'generated', 'traits', 'raw']
|
||||
data = dict([(f, getattr(event, f, '')) for f in fields])
|
||||
utils.print_dict(data, wrap=72)
|
||||
|
||||
Reference in New Issue
Block a user