Add support for subscription delete v2
Change-Id: I235bdf8a220f097cd43a8c2be250ddcd62e30644
This commit is contained in:
parent
5a7fdc637c
commit
4d48c7e9d9
|
@ -84,6 +84,7 @@ openstack.messaging.v2 =
|
|||
messaging_flavor_create = zaqarclient.queues.v2.cli:CreateFlavor
|
||||
subscription_create = zaqarclient.queues.v2.cli:CreateSubscription
|
||||
subscription_update = zaqarclient.queues.v2.cli:UpdateSubscription
|
||||
subscription_delete = zaqarclient.queues.v2.cli:DeleteSubscription
|
||||
|
||||
openstack.cli.extension =
|
||||
messaging = zaqarclient.queues.cli
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
import json
|
||||
import logging
|
||||
|
||||
from cliff import command
|
||||
from cliff import show
|
||||
|
||||
from openstackclient.common import utils
|
||||
|
@ -210,3 +211,28 @@ class UpdateSubscription(show.ShowOne):
|
|||
|
||||
columns = ('ID', 'Subscriber', 'TTL', 'Options')
|
||||
return columns, utils.get_item_properties(data, columns)
|
||||
|
||||
|
||||
class DeleteSubscription(command.Command):
|
||||
"""Delete a subscription"""
|
||||
|
||||
log = logging.getLogger(__name__ + ".DeleteSubscription")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(DeleteSubscription, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"queue_name",
|
||||
metavar="<queue_name>",
|
||||
help="Name of the queue for the subscription")
|
||||
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)
|
||||
client.subscription(parsed_args.queue_name,
|
||||
id=parsed_args.subscription_id,
|
||||
auto_create=False).delete()
|
||||
|
|
|
@ -17,6 +17,7 @@ import json
|
|||
import mock
|
||||
|
||||
from zaqarclient.tests.queues import base
|
||||
from zaqarclient.transport import errors
|
||||
from zaqarclient.transport import response
|
||||
|
||||
|
||||
|
@ -71,6 +72,35 @@ class QueuesV2SubscriptionUnitTest(base.QueuesTestBase):
|
|||
subscription.update({'subscriber': 'fake_subscriber'})
|
||||
self.assertEqual('fake_subscriber', subscription.subscriber)
|
||||
|
||||
def test_subscription_delete(self):
|
||||
subscription_data = {'subscriber': 'http://trigger.me',
|
||||
'ttl': 3600}
|
||||
|
||||
with mock.patch.object(self.transport, 'send',
|
||||
autospec=True) as send_method:
|
||||
|
||||
create_resp = response.Response(None,
|
||||
'{"subscription_id": "fake_id"}')
|
||||
get_content = ('{"subscriber": "http://trigger.me","ttl": 3600, '
|
||||
'"id": "fake_id"}')
|
||||
get_resp = response.Response(None, get_content)
|
||||
send_method.side_effect = iter([create_resp, get_resp, None,
|
||||
errors.ResourceNotFound])
|
||||
|
||||
# NOTE(flwang): This will call
|
||||
# ensure exists in the client instance
|
||||
# since auto_create's default is True
|
||||
subscription = self.client.subscription('beijing',
|
||||
**subscription_data)
|
||||
self.assertEqual('http://trigger.me', subscription.subscriber)
|
||||
self.assertEqual(3600, subscription.ttl)
|
||||
self.assertEqual('fake_id', subscription.id)
|
||||
|
||||
subscription.delete()
|
||||
self.assertRaises(errors.ResourceNotFound,
|
||||
self.client.subscription,
|
||||
'beijing', **{'id': 'fake_id'})
|
||||
|
||||
|
||||
class QueuesV2SubscriptionFunctionalTest(base.QueuesTestBase):
|
||||
|
||||
|
@ -107,3 +137,10 @@ class QueuesV2SubscriptionFunctionalTest(base.QueuesTestBase):
|
|||
sub.update(data)
|
||||
self.assertEqual('http://trigger.ok', sub.subscriber)
|
||||
self.assertEqual(1000, sub.ttl)
|
||||
|
||||
def test_subscription_delete(self):
|
||||
self.subscription_1.delete()
|
||||
|
||||
subscription_data = {'id': self.subscription_1.id}
|
||||
self.assertRaises(errors.ResourceNotFound, self.client.subscription,
|
||||
self.queue_name, **subscription_data)
|
||||
|
|
Loading…
Reference in New Issue