Merge "Fix return error when resource can't be found"
This commit is contained in:
commit
132c85e075
@ -692,9 +692,15 @@ class ResourcesController(rest.RestController):
|
||||
:param resource_id: The UUID of the resource.
|
||||
"""
|
||||
authorized_project = acl.get_limited_to_project(pecan.request.headers)
|
||||
r = list(pecan.request.storage_conn.get_resources(
|
||||
resource=resource_id, project=authorized_project))[0]
|
||||
return Resource.from_db_and_links(r,
|
||||
resources = list(pecan.request.storage_conn.get_resources(
|
||||
resource=resource_id, project=authorized_project))
|
||||
# FIXME (flwang): Need to change this to return a 404 error code when
|
||||
# we get a release of WSME that supports it.
|
||||
if not resources:
|
||||
raise wsme.exc.InvalidInput("resource_id",
|
||||
resource_id,
|
||||
_("Unknown resource"))
|
||||
return Resource.from_db_and_links(resources[0],
|
||||
self._resource_links(resource_id))
|
||||
|
||||
@wsme_pecan.wsexpose([Resource], [Query])
|
||||
@ -876,6 +882,8 @@ class AlarmsController(rest.RestController):
|
||||
auth_project = acl.get_limited_to_project(pecan.request.headers)
|
||||
alarms = list(conn.get_alarms(alarm_id=alarm_id,
|
||||
project=auth_project))
|
||||
# FIXME (flwang): Need to change this to return a 404 error code when
|
||||
# we get a release of WSME that supports it.
|
||||
if len(alarms) < 1:
|
||||
raise wsme.exc.ClientSideError(_("Unknown alarm"))
|
||||
|
||||
|
@ -196,6 +196,56 @@ class TestListResources(FunctionalTest):
|
||||
ids = [r['resource_id'] for r in data]
|
||||
self.assertEquals(['resource-id'], ids)
|
||||
|
||||
def test_with_invalid_resource_id(self):
|
||||
counter1 = counter.Counter(
|
||||
'instance',
|
||||
'cumulative',
|
||||
'',
|
||||
1,
|
||||
'user-id',
|
||||
'project-id',
|
||||
'resource-id-1',
|
||||
timestamp=datetime.datetime(2012, 7, 2, 10, 40),
|
||||
resource_metadata={'display_name': 'test-server',
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
msg = rpc.meter_message_from_counter(
|
||||
counter1,
|
||||
cfg.CONF.publisher_rpc.metering_secret,
|
||||
'test_list_resources',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
counter2 = counter.Counter(
|
||||
'instance',
|
||||
'cumulative',
|
||||
'',
|
||||
1,
|
||||
'user-id2',
|
||||
'project-id',
|
||||
'resource-id-2',
|
||||
timestamp=datetime.datetime(2012, 7, 2, 10, 41),
|
||||
resource_metadata={'display_name': 'test-server',
|
||||
'tag': 'self.counter2',
|
||||
}
|
||||
)
|
||||
msg2 = rpc.meter_message_from_counter(
|
||||
counter2,
|
||||
cfg.CONF.publisher_rpc.metering_secret,
|
||||
'test_list_resources',
|
||||
)
|
||||
self.conn.record_metering_data(msg2)
|
||||
|
||||
resp1 = self.get_json('/resources/resource-id-1')
|
||||
self.assertEquals(resp1["resource_id"], "resource-id-1")
|
||||
|
||||
resp2 = self.get_json('/resources/resource-id-2')
|
||||
self.assertEquals(resp2["resource_id"], "resource-id-2")
|
||||
|
||||
resp3 = self.get_json('/resources/resource-id-3', expect_errors=True)
|
||||
self.assertEquals(resp3.status_code, 400)
|
||||
|
||||
def test_with_user(self):
|
||||
counter1 = counter.Counter(
|
||||
'instance',
|
||||
|
Loading…
Reference in New Issue
Block a user