Make the error message of alarm-not-found clear
When creating a alarm combination with invalid project, ceilometer will raise alarm-Not-Found error, even though the specified alarm ids are existent. The error message is easily misleading. This change gives a explicit presentation of this case. Change-Id: Id189209ed4ccf27543f8dc628ca5f82eeeeeaa44 Closes-bug: #1320433
This commit is contained in:
parent
a4fd88c283
commit
7498db6f8f
|
@ -88,6 +88,17 @@ class EntityNotFound(ClientSideError):
|
|||
status_code=404)
|
||||
|
||||
|
||||
class AlarmNotFound(ClientSideError):
|
||||
def __init__(self, alarm, auth_project):
|
||||
if not auth_project:
|
||||
msg = _('Alarm %s not found') % alarm
|
||||
else:
|
||||
msg = _('Alarm %(alarm_id)s not found in project %'
|
||||
'(project)s') % {
|
||||
'alarm_id': alarm, 'project': auth_project}
|
||||
super(AlarmNotFound, self).__init__(msg, status_code=404)
|
||||
|
||||
|
||||
class AdvEnum(wtypes.wsproperty):
|
||||
"""Handle default and mandatory for wtypes.Enum."""
|
||||
def __init__(self, name, *args, **kwargs):
|
||||
|
@ -1767,7 +1778,7 @@ class Alarm(_Base):
|
|||
alarms = list(pecan.request.storage_conn.get_alarms(
|
||||
alarm_id=id, project=project))
|
||||
if not alarms:
|
||||
raise EntityNotFound(_('Alarm'), id)
|
||||
raise AlarmNotFound(id, project)
|
||||
|
||||
tc_names = [tc.name for tc in alarm.time_constraints]
|
||||
if len(tc_names) > len(set(tc_names)):
|
||||
|
@ -1881,7 +1892,7 @@ class AlarmController(rest.RestController):
|
|||
alarms = list(self.conn.get_alarms(alarm_id=self._id,
|
||||
project=auth_project))
|
||||
if not alarms:
|
||||
raise EntityNotFound(_('Alarm'), self._id)
|
||||
raise AlarmNotFound(alarm=self._id, auth_project=auth_project)
|
||||
return alarms[0]
|
||||
|
||||
def _record_change(self, data, now, on_behalf_of=None, type=None):
|
||||
|
|
|
@ -234,7 +234,7 @@ class TestAlarms(v2.FunctionalTest,
|
|||
def test_get_not_existing_alarm(self):
|
||||
resp = self.get_json('/alarms/alarm-id-3', expect_errors=True)
|
||||
self.assertEqual(404, resp.status_code)
|
||||
self.assertEqual("Alarm alarm-id-3 Not Found",
|
||||
self.assertEqual('Alarm alarm-id-3 not found',
|
||||
jsonutils.loads(resp.body)['error_message']
|
||||
['faultstring'])
|
||||
|
||||
|
@ -1088,7 +1088,9 @@ class TestAlarms(v2.FunctionalTest,
|
|||
'X-Project-Id': str(uuid.uuid4())}
|
||||
resp = self.post_json('/alarms', params=json, status=404,
|
||||
headers=an_other_user_auth)
|
||||
self.assertEqual("Alarm a Not Found",
|
||||
self.assertEqual("Alarm a not found in project "
|
||||
"%s" %
|
||||
an_other_user_auth['X-Project-Id'],
|
||||
jsonutils.loads(resp.body)['error_message']
|
||||
['faultstring'])
|
||||
|
||||
|
@ -1121,7 +1123,8 @@ class TestAlarms(v2.FunctionalTest,
|
|||
headers['X-Roles'] = 'admin'
|
||||
resp = self.post_json('/alarms', params=json, status=404,
|
||||
headers=headers)
|
||||
self.assertEqual("Alarm a Not Found",
|
||||
self.assertEqual("Alarm a not found in project "
|
||||
"aprojectidthatisnotmine",
|
||||
jsonutils.loads(resp.body)['error_message']
|
||||
['faultstring'])
|
||||
|
||||
|
|
|
@ -213,12 +213,12 @@ class TestApiMiddleware(v2.FunctionalTest):
|
|||
def test_translated_then_untranslated_error(self):
|
||||
resp = self.get_json('/alarms/alarm-id-3', expect_errors=True)
|
||||
self.assertEqual(404, resp.status_code)
|
||||
self.assertEqual("Alarm alarm-id-3 Not Found",
|
||||
self.assertEqual("Alarm alarm-id-3 not found",
|
||||
json.loads(resp.body)['error_message']
|
||||
['faultstring'])
|
||||
|
||||
with mock.patch('ceilometer.api.controllers.'
|
||||
'v2.EntityNotFound') as CustomErrorClass:
|
||||
'v2.AlarmNotFound') as CustomErrorClass:
|
||||
CustomErrorClass.return_value = wsme.exc.ClientSideError(
|
||||
"untranslated_error", status_code=404)
|
||||
resp = self.get_json('/alarms/alarm-id-5', expect_errors=True)
|
||||
|
|
Loading…
Reference in New Issue