Add support for subscription show v2
Change-Id: Ic2a3b2979fea71a536678e8ad3e5e6323c9d0f41
This commit is contained in:
@@ -85,6 +85,7 @@ openstack.messaging.v2 =
|
||||
subscription_create = zaqarclient.queues.v2.cli:CreateSubscription
|
||||
subscription_update = zaqarclient.queues.v2.cli:UpdateSubscription
|
||||
subscription_delete = zaqarclient.queues.v2.cli:DeleteSubscription
|
||||
subscription_show = zaqarclient.queues.v2.cli:ShowSubscription
|
||||
|
||||
openstack.cli.extension =
|
||||
messaging = zaqarclient.queues.cli
|
||||
|
@@ -236,3 +236,31 @@ class DeleteSubscription(command.Command):
|
||||
client.subscription(parsed_args.queue_name,
|
||||
id=parsed_args.subscription_id,
|
||||
auto_create=False).delete()
|
||||
|
||||
|
||||
class ShowSubscription(show.ShowOne):
|
||||
"""Display subscription details"""
|
||||
|
||||
log = logging.getLogger(__name__ + ".ShowSubscription")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ShowSubscription, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"queue_name",
|
||||
metavar="<queue_name>",
|
||||
help="Name of the queue to subscribe to"
|
||||
)
|
||||
parser.add_argument(
|
||||
"subscription_id",
|
||||
metavar="<subscription_id>",
|
||||
help="ID of the subscription"
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = _get_client(self, parsed_args)
|
||||
kwargs = {'id': parsed_args.subscription_id}
|
||||
pool_data = client.subscription(parsed_args.queue_name,
|
||||
**kwargs)
|
||||
columns = ('ID', 'Subscriber', 'TTL', 'Options')
|
||||
return columns, utils.get_dict_properties(pool_data.__dict__, columns)
|
||||
|
@@ -101,6 +101,24 @@ class QueuesV2SubscriptionUnitTest(base.QueuesTestBase):
|
||||
self.client.subscription,
|
||||
'beijing', **{'id': 'fake_id'})
|
||||
|
||||
def test_subscription_get(self):
|
||||
subscription_data = {'subscriber': 'http://trigger.me',
|
||||
'ttl': 3600}
|
||||
|
||||
with mock.patch.object(self.transport, 'send',
|
||||
autospec=True) as send_method:
|
||||
|
||||
resp = response.Response(None, json.dumps(subscription_data))
|
||||
send_method.return_value = resp
|
||||
|
||||
# NOTE(flaper87): This will call
|
||||
# ensure exists in the client instance
|
||||
# since auto_create's default is True
|
||||
kwargs = {'id': 'fake_id'}
|
||||
subscription = self.client.subscription('test', **kwargs)
|
||||
self.assertEqual('http://trigger.me', subscription.subscriber)
|
||||
self.assertEqual(3600, subscription.ttl)
|
||||
|
||||
|
||||
class QueuesV2SubscriptionFunctionalTest(base.QueuesTestBase):
|
||||
|
||||
@@ -144,3 +162,10 @@ class QueuesV2SubscriptionFunctionalTest(base.QueuesTestBase):
|
||||
subscription_data = {'id': self.subscription_1.id}
|
||||
self.assertRaises(errors.ResourceNotFound, self.client.subscription,
|
||||
self.queue_name, **subscription_data)
|
||||
|
||||
def test_subscription_get(self):
|
||||
kwargs = {'id': self.subscription_1.id}
|
||||
subscription_get = self.client.subscription(self.queue_name, **kwargs)
|
||||
|
||||
self.assertEqual('http://trigger.me', subscription_get.subscriber)
|
||||
self.assertEqual(3600, subscription_get.ttl)
|
||||
|
Reference in New Issue
Block a user