Return the error message of API request failure
For now, the error message from Aodh API can not be return when a request failure occur(e.g. BadRequest, Conflict). That is because the fualtstring from the response isn't extracted correctly. Change-Id: I5e0048f969d2e852042c4aa2c7e6e0bff254d15b
This commit is contained in:
parent
f84a2b27b4
commit
3377106557
@ -161,7 +161,7 @@ def from_response(response, url, method=None):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
desc = body.get('description')
|
desc = body.get('error_message', {}).get('faultstring')
|
||||||
for enhanced_cls in enhanced_classes:
|
for enhanced_cls in enhanced_classes:
|
||||||
if enhanced_cls.match.match(desc):
|
if enhanced_cls.match.match(desc):
|
||||||
cls = enhanced_cls
|
cls = enhanced_cls
|
||||||
|
@ -46,8 +46,9 @@ class AodhClientTest(base.ClientTestBase):
|
|||||||
params=(u"create --type event --name ev_alarm1 "
|
params=(u"create --type event --name ev_alarm1 "
|
||||||
"--project-id %s" % PROJECT_ID),
|
"--project-id %s" % PROJECT_ID),
|
||||||
fail_ok=True, merge_stderr=True)
|
fail_ok=True, merge_stderr=True)
|
||||||
self.assertFirstLineStartsWith(result.split('\n'),
|
self.assertFirstLineStartsWith(
|
||||||
'Conflict (HTTP 409)')
|
result.split('\n'),
|
||||||
|
"Alarm with name='ev_alarm1' exists (HTTP 409)")
|
||||||
|
|
||||||
# UPDATE IGNORE INVALID
|
# UPDATE IGNORE INVALID
|
||||||
result = self.aodh(
|
result = self.aodh(
|
||||||
@ -105,14 +106,13 @@ class AodhClientTest(base.ClientTestBase):
|
|||||||
# GET FAIL
|
# GET FAIL
|
||||||
result = self.aodh('alarm', params="show %s" % ALARM_ID,
|
result = self.aodh('alarm', params="show %s" % ALARM_ID,
|
||||||
fail_ok=True, merge_stderr=True)
|
fail_ok=True, merge_stderr=True)
|
||||||
self.assertFirstLineStartsWith(result.split('\n'),
|
expected = "Alarm %s not found (HTTP 404)" % ALARM_ID
|
||||||
"Not found (HTTP 404)")
|
self.assertFirstLineStartsWith(result.split('\n'), expected)
|
||||||
|
|
||||||
# DELETE FAIL
|
# DELETE FAIL
|
||||||
result = self.aodh('alarm', params="delete %s" % ALARM_ID,
|
result = self.aodh('alarm', params="delete %s" % ALARM_ID,
|
||||||
fail_ok=True, merge_stderr=True)
|
fail_ok=True, merge_stderr=True)
|
||||||
self.assertFirstLineStartsWith(result.split('\n'),
|
self.assertFirstLineStartsWith(result.split('\n'), expected)
|
||||||
"Not found (HTTP 404)")
|
|
||||||
|
|
||||||
# LIST DOES NOT HAVE ALARM
|
# LIST DOES NOT HAVE ALARM
|
||||||
result = self.aodh('alarm', params="list --type event")
|
result = self.aodh('alarm', params="list --type event")
|
||||||
@ -140,8 +140,8 @@ class AodhClientTest(base.ClientTestBase):
|
|||||||
"-m meter_name --threshold 5 "
|
"-m meter_name --threshold 5 "
|
||||||
"--project-id %s" % PROJECT_ID),
|
"--project-id %s" % PROJECT_ID),
|
||||||
fail_ok=True, merge_stderr=True)
|
fail_ok=True, merge_stderr=True)
|
||||||
self.assertFirstLineStartsWith(result.split('\n'),
|
self.assertFirstLineStartsWith(
|
||||||
'Conflict (HTTP 409)')
|
result.split('\n'), "Alarm with name='alarm1' exists (HTTP 409)")
|
||||||
|
|
||||||
# CREATE FAIL MISSING PARAM
|
# CREATE FAIL MISSING PARAM
|
||||||
self.assertRaises(exceptions.CommandFailed,
|
self.assertRaises(exceptions.CommandFailed,
|
||||||
@ -200,14 +200,13 @@ class AodhClientTest(base.ClientTestBase):
|
|||||||
# GET FAIL
|
# GET FAIL
|
||||||
result = self.aodh('alarm', params="show %s" % ALARM_ID,
|
result = self.aodh('alarm', params="show %s" % ALARM_ID,
|
||||||
fail_ok=True, merge_stderr=True)
|
fail_ok=True, merge_stderr=True)
|
||||||
self.assertFirstLineStartsWith(result.split('\n'),
|
expected = "Alarm %s not found (HTTP 404)" % ALARM_ID
|
||||||
"Not found (HTTP 404)")
|
self.assertFirstLineStartsWith(result.split('\n'), expected)
|
||||||
|
|
||||||
# DELETE FAIL
|
# DELETE FAIL
|
||||||
result = self.aodh('alarm', params="delete %s" % ALARM_ID,
|
result = self.aodh('alarm', params="delete %s" % ALARM_ID,
|
||||||
fail_ok=True, merge_stderr=True)
|
fail_ok=True, merge_stderr=True)
|
||||||
self.assertFirstLineStartsWith(result.split('\n'),
|
self.assertFirstLineStartsWith(result.split('\n'), expected)
|
||||||
"Not found (HTTP 404)")
|
|
||||||
|
|
||||||
# LIST DOES NOT HAVE ALARM
|
# LIST DOES NOT HAVE ALARM
|
||||||
result = self.aodh('alarm', params="list --type threshold")
|
result = self.aodh('alarm', params="list --type threshold")
|
||||||
@ -254,8 +253,8 @@ class AodhClientGnocchiRulesTest(base.ClientTestBase):
|
|||||||
"--project-id %s"
|
"--project-id %s"
|
||||||
% (RESOURCE_ID, PROJECT_ID)),
|
% (RESOURCE_ID, PROJECT_ID)),
|
||||||
fail_ok=True, merge_stderr=True)
|
fail_ok=True, merge_stderr=True)
|
||||||
self.assertFirstLineStartsWith(result.split('\n'),
|
self.assertFirstLineStartsWith(
|
||||||
'Conflict (HTTP 409)')
|
result.split('\n'), "Alarm with name='alarm1' exists (HTTP 409)")
|
||||||
|
|
||||||
# CREATE FAIL MISSING PARAM
|
# CREATE FAIL MISSING PARAM
|
||||||
self.assertRaises(exceptions.CommandFailed,
|
self.assertRaises(exceptions.CommandFailed,
|
||||||
@ -325,14 +324,13 @@ class AodhClientGnocchiRulesTest(base.ClientTestBase):
|
|||||||
# GET FAIL
|
# GET FAIL
|
||||||
result = self.aodh('alarm', params="show %s" % ALARM_ID,
|
result = self.aodh('alarm', params="show %s" % ALARM_ID,
|
||||||
fail_ok=True, merge_stderr=True)
|
fail_ok=True, merge_stderr=True)
|
||||||
self.assertFirstLineStartsWith(result.split('\n'),
|
expected = "Alarm %s not found (HTTP 404)" % ALARM_ID
|
||||||
"Not found (HTTP 404)")
|
self.assertFirstLineStartsWith(result.split('\n'), expected)
|
||||||
|
|
||||||
# DELETE FAIL
|
# DELETE FAIL
|
||||||
result = self.aodh('alarm', params="delete %s" % ALARM_ID,
|
result = self.aodh('alarm', params="delete %s" % ALARM_ID,
|
||||||
fail_ok=True, merge_stderr=True)
|
fail_ok=True, merge_stderr=True)
|
||||||
self.assertFirstLineStartsWith(result.split('\n'),
|
self.assertFirstLineStartsWith(result.split('\n'), expected)
|
||||||
"Not found (HTTP 404)")
|
|
||||||
|
|
||||||
# LIST DOES NOT HAVE ALARM
|
# LIST DOES NOT HAVE ALARM
|
||||||
result = self.aodh('alarm',
|
result = self.aodh('alarm',
|
||||||
@ -379,8 +377,8 @@ class AodhClientGnocchiRulesTest(base.ClientTestBase):
|
|||||||
"--aggregation-method last "
|
"--aggregation-method last "
|
||||||
"--project-id %s" % PROJECT_ID),
|
"--project-id %s" % PROJECT_ID),
|
||||||
fail_ok=True, merge_stderr=True)
|
fail_ok=True, merge_stderr=True)
|
||||||
self.assertFirstLineStartsWith(result.split('\n'),
|
self.assertFirstLineStartsWith(
|
||||||
'Conflict (HTTP 409)')
|
result.split('\n'), "Alarm with name='alarm1' exists (HTTP 409)")
|
||||||
|
|
||||||
# CREATE FAIL MISSING PARAM
|
# CREATE FAIL MISSING PARAM
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
@ -455,14 +453,13 @@ class AodhClientGnocchiRulesTest(base.ClientTestBase):
|
|||||||
# GET FAIL
|
# GET FAIL
|
||||||
result = self.aodh('alarm', params="show %s" % ALARM_ID,
|
result = self.aodh('alarm', params="show %s" % ALARM_ID,
|
||||||
fail_ok=True, merge_stderr=True)
|
fail_ok=True, merge_stderr=True)
|
||||||
self.assertFirstLineStartsWith(result.split('\n'),
|
expected = "Alarm %s not found (HTTP 404)" % ALARM_ID
|
||||||
"Not found (HTTP 404)")
|
self.assertFirstLineStartsWith(result.split('\n'), expected)
|
||||||
|
|
||||||
# DELETE FAIL
|
# DELETE FAIL
|
||||||
result = self.aodh('alarm', params="delete %s" % ALARM_ID,
|
result = self.aodh('alarm', params="delete %s" % ALARM_ID,
|
||||||
fail_ok=True, merge_stderr=True)
|
fail_ok=True, merge_stderr=True)
|
||||||
self.assertFirstLineStartsWith(result.split('\n'),
|
self.assertFirstLineStartsWith(result.split('\n'), expected)
|
||||||
"Not found (HTTP 404)")
|
|
||||||
|
|
||||||
# LIST DOES NOT HAVE ALARM
|
# LIST DOES NOT HAVE ALARM
|
||||||
result = self.aodh('alarm', params="list --type "
|
result = self.aodh('alarm', params="list --type "
|
||||||
@ -509,8 +506,8 @@ class AodhClientGnocchiRulesTest(base.ClientTestBase):
|
|||||||
"--project-id %s"
|
"--project-id %s"
|
||||||
% (METRIC1, METRIC2, PROJECT_ID)),
|
% (METRIC1, METRIC2, PROJECT_ID)),
|
||||||
fail_ok=True, merge_stderr=True)
|
fail_ok=True, merge_stderr=True)
|
||||||
self.assertFirstLineStartsWith(result.split('\n'),
|
self.assertFirstLineStartsWith(
|
||||||
'Conflict (HTTP 409)')
|
result.split('\n'), "Alarm with name='alarm1' exists (HTTP 409)")
|
||||||
|
|
||||||
# CREATE FAIL MISSING PARAM
|
# CREATE FAIL MISSING PARAM
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
@ -584,14 +581,14 @@ class AodhClientGnocchiRulesTest(base.ClientTestBase):
|
|||||||
# GET FAIL
|
# GET FAIL
|
||||||
result = self.aodh('alarm', params="show %s" % ALARM_ID,
|
result = self.aodh('alarm', params="show %s" % ALARM_ID,
|
||||||
fail_ok=True, merge_stderr=True)
|
fail_ok=True, merge_stderr=True)
|
||||||
self.assertFirstLineStartsWith(result.split('\n'),
|
expected = "Alarm %s not found (HTTP 404)" % ALARM_ID
|
||||||
"Not found (HTTP 404)")
|
self.assertFirstLineStartsWith(result.split('\n'), expected)
|
||||||
|
|
||||||
# DELETE FAIL
|
# DELETE FAIL
|
||||||
result = self.aodh('alarm', params="delete %s" % ALARM_ID,
|
result = self.aodh('alarm', params="delete %s" % ALARM_ID,
|
||||||
fail_ok=True, merge_stderr=True)
|
fail_ok=True, merge_stderr=True)
|
||||||
self.assertFirstLineStartsWith(result.split('\n'),
|
|
||||||
"Not found (HTTP 404)")
|
self.assertFirstLineStartsWith(result.split('\n'), expected)
|
||||||
|
|
||||||
# LIST DOES NOT HAVE ALARM
|
# LIST DOES NOT HAVE ALARM
|
||||||
result = self.aodh(
|
result = self.aodh(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user