Fix list detailed queue without reserved metadata

Now Zaqar lists detailed queue without reserved metadata.
That is inconsistent with response of showing single queue.

Change-Id: Iea3042e294f10a21e5b655f3123f215f09790b17
Closes-Bug: #1680373
This commit is contained in:
wanghao 2017-04-06 19:53:08 +08:00
parent 5b7c69fab9
commit b7141b5270
3 changed files with 24 additions and 16 deletions

View File

@ -0,0 +1,5 @@
---
fixes:
- Zaqar didn't return the reserved metadata when listing detailed queue.
After this fix, Zaqar will return reserved metadata '_default_message_ttl'
and '_max_messages_post_size' in response of listing detailed queue.

View File

@ -425,8 +425,6 @@ class TestQueueLifecycleMongoDB(base.V2Base):
queue = result_doc['queues'][0] queue = result_doc['queues'][0]
result = self.simulate_get(queue['href'], headers=header) result = self.simulate_get(queue['href'], headers=header)
result_doc = jsonutils.loads(result[0]) result_doc = jsonutils.loads(result[0])
queue['metadata']['_default_message_ttl'] = 3600
queue['metadata']['_max_messages_post_size'] = 262144
self.assertEqual(queue['metadata'], result_doc) self.assertEqual(queue['metadata'], result_doc)
self.assertEqual({'node': 31, '_default_message_ttl': 3600, self.assertEqual({'node': 31, '_default_message_ttl': 3600,
'_max_messages_post_size': 262144}, result_doc) '_max_messages_post_size': 262144}, result_doc)

View File

@ -29,6 +29,16 @@ from zaqar.transport.wsgi import utils as wsgi_utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
def _get_reserved_metadata(validate):
_reserved_metadata = ['max_messages_post_size', 'default_message_ttl']
reserved_metadata = {
'_%s' % meta:
validate.get_limit_conf_value(meta)
for meta in _reserved_metadata
}
return reserved_metadata
class ItemResource(object): class ItemResource(object):
__slots__ = ('_validate', '_queue_controller', '_message_controller', __slots__ = ('_validate', '_queue_controller', '_message_controller',
@ -38,16 +48,6 @@ class ItemResource(object):
self._validate = validate self._validate = validate
self._queue_controller = queue_controller self._queue_controller = queue_controller
self._message_controller = message_controller self._message_controller = message_controller
self._reserved_metadata = ['max_messages_post_size',
'default_message_ttl']
def _get_reserved_metadata(self):
reserved_metadata = {
'_%s' % meta:
self._validate.get_limit_conf_value(meta)
for meta in self._reserved_metadata
}
return reserved_metadata
@decorators.TransportLog("Queues item") @decorators.TransportLog("Queues item")
@acl.enforce("queues:get") @acl.enforce("queues:get")
@ -55,7 +55,7 @@ class ItemResource(object):
try: try:
resp_dict = self._queue_controller.get(queue_name, resp_dict = self._queue_controller.get(queue_name,
project=project_id) project=project_id)
for meta, value in self._get_reserved_metadata().items(): for meta, value in _get_reserved_metadata(self._validate).items():
if not resp_dict.get(meta, None): if not resp_dict.get(meta, None):
resp_dict[meta] = value resp_dict[meta] = value
except storage_errors.DoesNotExist as ex: except storage_errors.DoesNotExist as ex:
@ -186,7 +186,7 @@ class ItemResource(object):
# queue. # queue.
metadata = self._queue_controller.get_metadata(queue_name, metadata = self._queue_controller.get_metadata(queue_name,
project=project_id) project=project_id)
reserved_metadata = self._get_reserved_metadata() reserved_metadata = _get_reserved_metadata(self._validate)
for change in changes: for change in changes:
change_method_name = '_do_%s' % change['op'] change_method_name = '_do_%s' % change['op']
change_method = getattr(self, change_method_name) change_method = getattr(self, change_method_name)
@ -209,7 +209,7 @@ class ItemResource(object):
LOG.exception(ex) LOG.exception(ex)
description = _(u'Queue could not be updated.') description = _(u'Queue could not be updated.')
raise wsgi_errors.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
for meta, value in self._get_reserved_metadata().items(): for meta, value in _get_reserved_metadata(self._validate).items():
if not metadata.get(meta, None): if not metadata.get(meta, None):
metadata[meta] = value metadata[meta] = value
resp.body = utils.to_json(metadata) resp.body = utils.to_json(metadata)
@ -242,7 +242,7 @@ class ItemResource(object):
class CollectionResource(object): class CollectionResource(object):
__slots__ = ('_queue_controller', '_validate') __slots__ = ('_queue_controller', '_validate', '_reserved_metadata')
def __init__(self, validate, queue_controller): def __init__(self, validate, queue_controller):
self._queue_controller = queue_controller self._queue_controller = queue_controller
@ -277,8 +277,13 @@ class CollectionResource(object):
# Got some. Prepare the response. # Got some. Prepare the response.
kwargs['marker'] = next(results) or kwargs.get('marker', '') kwargs['marker'] = next(results) or kwargs.get('marker', '')
reserved_metadata = _get_reserved_metadata(self._validate).items()
for each_queue in queues: for each_queue in queues:
each_queue['href'] = req.path + '/' + each_queue['name'] each_queue['href'] = req.path + '/' + each_queue['name']
if kwargs.get('detailed'):
for meta, value in reserved_metadata:
if not each_queue.get('metadata', {}).get(meta):
each_queue['metadata'][meta] = value
links = [] links = []
if queues: if queues: