Add Support for subscription list v2
Change-Id: I1ce38e6875034f31fa105b656f74a3ce8a32b4ed
This commit is contained in:
parent
f933dc8131
commit
8962837f88
@ -88,6 +88,7 @@ openstack.messaging.v2 =
|
|||||||
subscription_update = zaqarclient.queues.v2.cli:UpdateSubscription
|
subscription_update = zaqarclient.queues.v2.cli:UpdateSubscription
|
||||||
subscription_delete = zaqarclient.queues.v2.cli:DeleteSubscription
|
subscription_delete = zaqarclient.queues.v2.cli:DeleteSubscription
|
||||||
subscription_show = zaqarclient.queues.v2.cli:ShowSubscription
|
subscription_show = zaqarclient.queues.v2.cli:ShowSubscription
|
||||||
|
subscription_list = zaqarclient.queues.v2.cli:ListSubscriptions
|
||||||
|
|
||||||
openstack.cli.extension =
|
openstack.cli.extension =
|
||||||
messaging = zaqarclient.queues.cli
|
messaging = zaqarclient.queues.cli
|
||||||
|
@ -16,6 +16,7 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from cliff import command
|
from cliff import command
|
||||||
|
from cliff import lister
|
||||||
from cliff import show
|
from cliff import show
|
||||||
|
|
||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
@ -264,3 +265,49 @@ class ShowSubscription(show.ShowOne):
|
|||||||
**kwargs)
|
**kwargs)
|
||||||
columns = ('ID', 'Subscriber', 'TTL', 'Options')
|
columns = ('ID', 'Subscriber', 'TTL', 'Options')
|
||||||
return columns, utils.get_dict_properties(pool_data.__dict__, columns)
|
return columns, utils.get_dict_properties(pool_data.__dict__, columns)
|
||||||
|
|
||||||
|
|
||||||
|
class ListSubscriptions(lister.Lister):
|
||||||
|
"""List available subscriptions"""
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__ + ".ListSubscriptions")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(ListSubscriptions, self).get_parser(prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
"queue_name",
|
||||||
|
metavar="<queue_name>",
|
||||||
|
help="Name of the queue to subscribe to")
|
||||||
|
parser.add_argument(
|
||||||
|
"--marker",
|
||||||
|
metavar="<subscription_id>",
|
||||||
|
help="Subscription's paging marker, "
|
||||||
|
"the ID of the last subscription of the previous page")
|
||||||
|
parser.add_argument(
|
||||||
|
"--limit",
|
||||||
|
metavar="<limit>",
|
||||||
|
help="Page size limit, default value is 20")
|
||||||
|
parser.add_argument(
|
||||||
|
"--detailed",
|
||||||
|
type=bool,
|
||||||
|
default=False,
|
||||||
|
metavar="<detailed>",
|
||||||
|
help="Whether to show subscription metadata")
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
self.log.debug("take_action(%s)" % parsed_args)
|
||||||
|
|
||||||
|
client = self.app.client_manager.messaging
|
||||||
|
|
||||||
|
kwargs = {'queue_name': parsed_args.queue_name,
|
||||||
|
'detailed': parsed_args.detailed}
|
||||||
|
if parsed_args.marker is not None:
|
||||||
|
kwargs["marker"] = parsed_args.marker
|
||||||
|
if parsed_args.limit is not None:
|
||||||
|
kwargs["limit"] = parsed_args.limit
|
||||||
|
|
||||||
|
data = client.subscriptions(**kwargs)
|
||||||
|
columns = ('ID', 'Subscriber', 'TTL', 'Options')
|
||||||
|
return (columns,
|
||||||
|
(utils.get_item_properties(s, columns) for s in data))
|
||||||
|
@ -60,7 +60,7 @@ class Client(client.Client):
|
|||||||
return subscription.Subscription(self, queue_name, **kwargs)
|
return subscription.Subscription(self, queue_name, **kwargs)
|
||||||
|
|
||||||
@decorators.version(min_version=2)
|
@decorators.version(min_version=2)
|
||||||
def subscriptions(self, **params):
|
def subscriptions(self, queue_name, **params):
|
||||||
"""Gets a list of subscriptions from the server
|
"""Gets a list of subscriptions from the server
|
||||||
|
|
||||||
:param params: Filters to use for getting subscriptions
|
:param params: Filters to use for getting subscriptions
|
||||||
@ -71,7 +71,10 @@ class Client(client.Client):
|
|||||||
"""
|
"""
|
||||||
req, trans = self._request_and_transport()
|
req, trans = self._request_and_transport()
|
||||||
|
|
||||||
subscription_list = core.subscription_list(trans, req, **params)
|
subscription_list = core.subscription_list(trans, req, queue_name,
|
||||||
|
**params)
|
||||||
|
for s in subscription_list['subscriptions']:
|
||||||
|
s['queue_name'] = queue_name
|
||||||
|
|
||||||
return iterator._Iterator(self,
|
return iterator._Iterator(self,
|
||||||
subscription_list,
|
subscription_list,
|
||||||
|
@ -199,24 +199,27 @@ def subscription_delete(transport, request, queue_name, subscription_id):
|
|||||||
transport.send(request)
|
transport.send(request)
|
||||||
|
|
||||||
|
|
||||||
def subscription_list(transport, request, **kwargs):
|
def subscription_list(transport, request, queue_name, **kwargs):
|
||||||
"""Gets a list of subscriptions
|
"""Gets a list of subscriptions
|
||||||
|
|
||||||
:param transport: Transport instance to use
|
:param transport: Transport instance to use
|
||||||
:type transport: `transport.base.Transport`
|
:type transport: `transport.base.Transport`
|
||||||
:param request: Request instance ready to be sent.
|
:param request: Request instance ready to be sent.
|
||||||
:type request: `transport.request.Request`
|
:type request: `transport.request.Request`
|
||||||
|
:param queue_name: Queue reference name.
|
||||||
|
:type queue_name: `six.text_type`
|
||||||
:param kwargs: Optional arguments for this operation.
|
:param kwargs: Optional arguments for this operation.
|
||||||
- marker: Where to start getting subscriptions from.
|
- marker: Where to start getting subscriptions from.
|
||||||
- limit: Maximum number of subscriptions to get.
|
- limit: Maximum number of subscriptions to get.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request.operation = 'subscription_list'
|
request.operation = 'subscription_list'
|
||||||
|
request.params['queue_name'] = queue_name
|
||||||
request.params.update(kwargs)
|
request.params.update(kwargs)
|
||||||
|
|
||||||
resp = transport.send(request)
|
resp = transport.send(request)
|
||||||
|
|
||||||
if not resp.content:
|
if not resp.content:
|
||||||
return {'links': [], 'pools': []}
|
return {'links': [], 'subscriptions': []}
|
||||||
|
|
||||||
return resp.deserialized_content
|
return resp.deserialized_content
|
||||||
|
@ -76,9 +76,9 @@ class Subscription(object):
|
|||||||
|
|
||||||
|
|
||||||
def create_object(parent):
|
def create_object(parent):
|
||||||
return lambda kwargs: Subscription(parent, kwargs["queue_name"],
|
return lambda kwargs: Subscription(parent, kwargs.pop("queue_name"),
|
||||||
subscriber=kwargs['subscriber'],
|
subscriber=kwargs.pop('subscriber'),
|
||||||
ttl=kwargs['ttl'],
|
ttl=kwargs.pop('ttl'),
|
||||||
id=kwargs['id'],
|
id=kwargs.pop('id'),
|
||||||
auto_create=False,
|
auto_create=False,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
@ -119,6 +119,30 @@ class QueuesV2SubscriptionUnitTest(base.QueuesTestBase):
|
|||||||
self.assertEqual('http://trigger.me', subscription.subscriber)
|
self.assertEqual('http://trigger.me', subscription.subscriber)
|
||||||
self.assertEqual(3600, subscription.ttl)
|
self.assertEqual(3600, subscription.ttl)
|
||||||
|
|
||||||
|
def test_subscription_list(self):
|
||||||
|
subscription_data = {'subscriptions':
|
||||||
|
[{'id': '568afabb508f153573f6a56f',
|
||||||
|
'subscriber': 'http://trigger.me',
|
||||||
|
'ttl': 3600,
|
||||||
|
'options': {}},
|
||||||
|
{'id': '568afabb508f153573f6a56x',
|
||||||
|
'subscriber': 'http://trigger.you',
|
||||||
|
'ttl': 7200,
|
||||||
|
'options': {}}]}
|
||||||
|
|
||||||
|
with mock.patch.object(self.transport, 'send',
|
||||||
|
autospec=True) as send_method:
|
||||||
|
|
||||||
|
list_resp = response.Response(None,
|
||||||
|
json.dumps(subscription_data))
|
||||||
|
send_method.side_effect = iter([list_resp])
|
||||||
|
|
||||||
|
# NOTE(flwang): This will call
|
||||||
|
# ensure exists in the client instance
|
||||||
|
# since auto_create's default is True
|
||||||
|
subscriptions = self.client.subscriptions('beijing')
|
||||||
|
self.assertEqual(2, len(list(subscriptions)))
|
||||||
|
|
||||||
|
|
||||||
class QueuesV2SubscriptionFunctionalTest(base.QueuesTestBase):
|
class QueuesV2SubscriptionFunctionalTest(base.QueuesTestBase):
|
||||||
|
|
||||||
@ -169,3 +193,12 @@ class QueuesV2SubscriptionFunctionalTest(base.QueuesTestBase):
|
|||||||
|
|
||||||
self.assertEqual('http://trigger.me', subscription_get.subscriber)
|
self.assertEqual('http://trigger.me', subscription_get.subscriber)
|
||||||
self.assertEqual(3600, subscription_get.ttl)
|
self.assertEqual(3600, subscription_get.ttl)
|
||||||
|
|
||||||
|
def test_subscription_list(self):
|
||||||
|
subscriptions = self.client.subscriptions(self.queue_name)
|
||||||
|
subscriptions = list(subscriptions)
|
||||||
|
self.assertEqual(2, len(subscriptions))
|
||||||
|
|
||||||
|
subscriber_list = [s.subscriber for s in subscriptions]
|
||||||
|
self.assertIn('http://trigger.me', subscriber_list)
|
||||||
|
self.assertIn('http://trigger.he', subscriber_list)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user