Merge "Raise an error when metric name doesn't exists"
This commit is contained in:
commit
babaa03a01
|
@ -18,7 +18,7 @@ class ClientException(Exception):
|
|||
"""The base exception class for all exceptions this library raises."""
|
||||
message = 'Unknown Error'
|
||||
|
||||
def __init__(self, code, message=None, request_id=None,
|
||||
def __init__(self, code=None, message=None, request_id=None,
|
||||
url=None, method=None):
|
||||
self.code = code
|
||||
self.message = message or self.__class__.message
|
||||
|
@ -27,10 +27,11 @@ class ClientException(Exception):
|
|||
self.method = method
|
||||
|
||||
def __str__(self):
|
||||
formatted_string = "%s (HTTP %s)" % (self.message, self.code)
|
||||
formatted_string = "%s" % self.message
|
||||
if self.code:
|
||||
formatted_string += " (HTTP %s)" % self.code
|
||||
if self.request_id:
|
||||
formatted_string += " (Request-ID: %s)" % self.request_id
|
||||
|
||||
return formatted_string
|
||||
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ class ResourceClientTest(base.ClientTestBase):
|
|||
self.assertEqual(self.RESOURCE_ID, resource_got["id"])
|
||||
self.assertEqual(self.PROJECT_ID, resource_got["project_id"])
|
||||
self.assertEqual(resource["started_at"], resource_got["started_at"])
|
||||
self.assertIn("temperature", resource_updated["metrics"])
|
||||
self.assertIn("temperature", resource_got["metrics"])
|
||||
|
||||
# HISTORY
|
||||
result = self.gnocchi(
|
||||
|
@ -111,6 +111,13 @@ class ResourceClientTest(base.ClientTestBase):
|
|||
resource_updated = self.details_multiple(result)[0]
|
||||
self.assertNotIn("temperature", resource_updated["metrics"])
|
||||
|
||||
result = self.gnocchi(
|
||||
'resource', params=("update %s -d temperature" % self.RESOURCE_ID),
|
||||
fail_ok=True, merge_stderr=True)
|
||||
self.assertFirstLineStartsWith(
|
||||
result.split('\n'),
|
||||
"Metric name temperature not found")
|
||||
|
||||
# CREATE 2
|
||||
result = self.gnocchi(
|
||||
'resource', params=("create %s -t generic "
|
||||
|
|
|
@ -14,6 +14,7 @@ from cliff import command
|
|||
from cliff import lister
|
||||
from cliff import show
|
||||
|
||||
from gnocchiclient import exceptions
|
||||
from gnocchiclient import utils
|
||||
|
||||
|
||||
|
@ -161,7 +162,11 @@ class CliResourceCreate(show.ShowOne):
|
|||
parsed_args.resource_id)
|
||||
default = r['metrics']
|
||||
for metric_name in parsed_args.delete_metric:
|
||||
default.pop(metric_name, None)
|
||||
try:
|
||||
del default[metric_name]
|
||||
except KeyError:
|
||||
raise exceptions.MetricNotFound(
|
||||
message="Metric name %s not found" % metric_name)
|
||||
else:
|
||||
default = {}
|
||||
resource['metrics'] = default
|
||||
|
|
Loading…
Reference in New Issue