apply limit constraint on storage base interface
Currently we have implemented limit constraint on get_meters, get_resources, get_samples and query_samples on most of major databases, but haven't applied such change on storage interface of get_meters and get_resources, this patch adds parameter limit to those two methods. Change-Id: I10e43e082ec9fd87dcd491299a57c0116009220e Closes-Bug: #1496677
This commit is contained in:
parent
67b55c01c8
commit
5c17ff6470
@ -491,11 +491,8 @@ class MetersController(rest.RestController):
|
||||
# Timestamp field is not supported for Meter queries
|
||||
limit = v2_utils.enforce_limit(limit)
|
||||
kwargs = v2_utils.query_to_kwargs(
|
||||
q, pecan.request.storage_conn.get_meters, allow_timestamps=False)
|
||||
if 'limit' in kwargs:
|
||||
raise base.ClientSideError(_(
|
||||
"Limit is not a valid field for queries, "
|
||||
"use 'limit' parameter."))
|
||||
q, pecan.request.storage_conn.get_meters,
|
||||
['limit'], allow_timestamps=False)
|
||||
return [Meter.from_db_model(m)
|
||||
for m in pecan.request.storage_conn.get_meters(limit=limit,
|
||||
**kwargs)]
|
||||
|
@ -142,11 +142,7 @@ class ResourcesController(rest.RestController):
|
||||
q = q or []
|
||||
limit = utils.enforce_limit(limit)
|
||||
kwargs = utils.query_to_kwargs(
|
||||
q, pecan.request.storage_conn.get_resources)
|
||||
if 'limit' in kwargs:
|
||||
raise base.ClientSideError(_(
|
||||
"Limit is not a valid field for queries, "
|
||||
"use 'limit' parameter."))
|
||||
q, pecan.request.storage_conn.get_resources, ['limit'])
|
||||
resources = [
|
||||
Resource.from_db_and_links(r,
|
||||
self._resource_links(r.resource_id,
|
||||
|
@ -176,7 +176,7 @@ class Connection(object):
|
||||
def get_resources(user=None, project=None, source=None,
|
||||
start_timestamp=None, start_timestamp_op=None,
|
||||
end_timestamp=None, end_timestamp_op=None,
|
||||
metaquery=None, resource=None):
|
||||
metaquery=None, resource=None, limit=None):
|
||||
"""Return an iterable of models.Resource instances.
|
||||
|
||||
Iterable items containing resource information.
|
||||
@ -189,12 +189,13 @@ class Connection(object):
|
||||
:param end_timestamp_op: Optional timestamp end range operation.
|
||||
:param metaquery: Optional dict with metadata to match on.
|
||||
:param resource: Optional resource filter.
|
||||
:param limit: Maximum number of results to return.
|
||||
"""
|
||||
raise ceilometer.NotImplementedError('Resources not implemented')
|
||||
|
||||
@staticmethod
|
||||
def get_meters(user=None, project=None, resource=None, source=None,
|
||||
metaquery=None):
|
||||
metaquery=None, limit=None):
|
||||
"""Return an iterable of model.Meter instances.
|
||||
|
||||
Iterable items containing meter information.
|
||||
@ -203,6 +204,7 @@ class Connection(object):
|
||||
:param resource: Optional resource filter.
|
||||
:param source: Optional source filter.
|
||||
:param metaquery: Optional dict with metadata to match on.
|
||||
:param limit: Maximum number of results to return.
|
||||
"""
|
||||
raise ceilometer.NotImplementedError('Meters not implemented')
|
||||
|
||||
|
@ -55,7 +55,7 @@ class Connection(base.Connection):
|
||||
def get_resources(self, user=None, project=None, source=None,
|
||||
start_timestamp=None, start_timestamp_op=None,
|
||||
end_timestamp=None, end_timestamp_op=None,
|
||||
metaquery=None, resource=None):
|
||||
metaquery=None, resource=None, limit=None):
|
||||
"""Return an iterable of dictionaries containing resource information.
|
||||
|
||||
{ 'resource_id': UUID of the resource,
|
||||
@ -75,6 +75,7 @@ class Connection(base.Connection):
|
||||
:param end_timestamp_op: Optional end time operator, like lt, le.
|
||||
:param metaquery: Optional dict with metadata to match on.
|
||||
:param resource: Optional resource filter.
|
||||
:param limit: Maximum number of results to return.
|
||||
"""
|
||||
return []
|
||||
|
||||
@ -98,7 +99,7 @@ class Connection(base.Connection):
|
||||
"""
|
||||
return []
|
||||
|
||||
def get_samples(self, sample_filter):
|
||||
def get_samples(self, sample_filter, limit=None):
|
||||
"""Return an iterable of samples.
|
||||
|
||||
Items are created by
|
||||
|
@ -374,10 +374,10 @@ tests:
|
||||
url: /v2/meters?q.field=limit&q.op=eq&q.type=&q.value=1
|
||||
status: 400
|
||||
response_strings:
|
||||
- Limit is not a valid field for queries,
|
||||
- 'Unknown argument: \"limit\": unrecognized field in query'
|
||||
|
||||
- name: get meters filter limit and limit
|
||||
url: /v2/meters?q.field=limit&q.op=eq&q.type=&q.value=1&limit=1
|
||||
status: 400
|
||||
response_strings:
|
||||
- Limit is not a valid field for queries,
|
||||
- 'Unknown argument: \"limit\": unrecognized field in query'
|
||||
|
@ -77,10 +77,10 @@ tests:
|
||||
url: /v2/resources?q.field=limit&q.op=eq&q.type=&q.value=1
|
||||
status: 400
|
||||
response_strings:
|
||||
- Limit is not a valid field for queries,
|
||||
- 'Unknown argument: \"limit\": unrecognized field in query'
|
||||
|
||||
- name: get resources filter limit and limit
|
||||
url: /v2/resources?q.field=limit&q.op=eq&q.type=&q.value=1&limit=1
|
||||
status: 400
|
||||
response_strings:
|
||||
- Limit is not a valid field for queries,
|
||||
- 'Unknown argument: \"limit\": unrecognized field in query'
|
||||
|
@ -380,7 +380,8 @@ class TestQueryToKwArgs(tests_base.BaseTestCase):
|
||||
value='abc')]
|
||||
exc = self.assertRaises(
|
||||
wsme.exc.UnknownArgument,
|
||||
utils.query_to_kwargs, q, storage_base.Connection.get_meters)
|
||||
utils.query_to_kwargs,
|
||||
q, storage_base.Connection.get_meters, ['limit'])
|
||||
valid_keys = ['project', 'resource', 'source', 'user']
|
||||
msg = ("unrecognized field in query: %s, "
|
||||
"valid keys: %s") % (q, valid_keys)
|
||||
@ -393,7 +394,8 @@ class TestQueryToKwArgs(tests_base.BaseTestCase):
|
||||
value='abc')]
|
||||
exc = self.assertRaises(
|
||||
wsme.exc.UnknownArgument,
|
||||
utils.query_to_kwargs, q, storage_base.Connection.get_resources)
|
||||
utils.query_to_kwargs,
|
||||
q, storage_base.Connection.get_resources, ['limit'])
|
||||
valid_keys = ['project', 'resource',
|
||||
'search_offset', 'source', 'timestamp', 'user']
|
||||
msg = ("unrecognized field in query: %s, "
|
||||
|
Loading…
Reference in New Issue
Block a user