Merge "Add tempest test for purge queue"
This commit is contained in:
commit
ee1d244a28
@ -358,6 +358,16 @@ class V2MessagingClient(MessagingClient):
|
||||
self.expected_success(204, resp.status)
|
||||
return resp, body
|
||||
|
||||
def purge_queue(self, queue_name, resource=None):
|
||||
uri = '{0}/queues/{1}/purge'.format(self.uri_prefix, queue_name)
|
||||
rbody = {"resource_types": ["messages", "subscriptions"]}
|
||||
if resource:
|
||||
rbody = {"resource_types": resource}
|
||||
resp, body = self.post(uri, body=json.dumps(rbody),
|
||||
headers=self.headers)
|
||||
self.expected_success(204, resp.status)
|
||||
return resp, body
|
||||
|
||||
def show_queue_stats(self, queue_name):
|
||||
uri = '{0}/queues/{1}/stats'.format(self.uri_prefix, queue_name)
|
||||
resp, body = self.get(uri, headers=self.headers)
|
||||
|
@ -211,6 +211,12 @@ class BaseV2MessagingTest(BaseMessagingTest):
|
||||
build_interval=CONF.compute.build_interval,
|
||||
build_timeout=CONF.compute.build_timeout)
|
||||
|
||||
@classmethod
|
||||
def purge_queue(cls, queue_name, resource=None):
|
||||
resp, body = cls.client.purge_queue(
|
||||
queue_name, resource)
|
||||
return resp, body
|
||||
|
||||
@classmethod
|
||||
def create_subscription(cls, queue_name, rbody):
|
||||
resp, body = cls.client.create_subscription(
|
||||
|
@ -16,11 +16,14 @@
|
||||
|
||||
from six import moves
|
||||
from tempest.common.utils import data_utils
|
||||
from tempest import config
|
||||
from tempest.lib import decorators
|
||||
from testtools import matchers
|
||||
|
||||
from zaqar.tests.tempest_plugin.tests import base
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
class TestQueues(base.BaseV2MessagingTest):
|
||||
|
||||
@ -53,6 +56,22 @@ class TestManageQueue(base.BaseV2MessagingTest):
|
||||
# Create Queue
|
||||
cls.client.create_queue(queue_name)
|
||||
|
||||
def _post_messages(self, repeat=CONF.messaging.max_messages_per_page,
|
||||
queue_name=None):
|
||||
message_body = self.generate_message_body(repeat=repeat)
|
||||
resp, body = self.post_messages(queue_name=queue_name,
|
||||
rbody=message_body)
|
||||
return resp, body
|
||||
|
||||
def _create_subscriptions(self, queue_name):
|
||||
bodys = self.generate_subscription_body()
|
||||
results = []
|
||||
for body in bodys:
|
||||
resp, body = self.create_subscription(queue_name=queue_name,
|
||||
rbody=body)
|
||||
results.append((resp, body))
|
||||
return results
|
||||
|
||||
@decorators.idempotent_id('8f1fec00-54fc-48b9-aa67-c10a824b768d')
|
||||
def test_list_queues(self):
|
||||
# Listing queues
|
||||
@ -98,6 +117,31 @@ class TestManageQueue(base.BaseV2MessagingTest):
|
||||
_, body = self.get_queue_metadata(queue_name)
|
||||
self.assertThat(body, matchers.Equals(req_body))
|
||||
|
||||
@decorators.idempotent_id('2fb6e5a8-c18f-4407-9ee7-7a13c8e09f69')
|
||||
def test_purge_queue(self):
|
||||
queue_name = self.queues[0]
|
||||
# The queue contains no messages and subscriptions by default.
|
||||
resp, body = self.list_messages(queue_name=queue_name)
|
||||
self.assertEqual([], body['messages'])
|
||||
resp, body = self.list_subscription(queue_name)
|
||||
self.assertEqual([], body['subscriptions'])
|
||||
# Post some messages and create some subscriptions for the queue.
|
||||
self._post_messages(queue_name=queue_name)
|
||||
self._create_subscriptions(queue_name=queue_name)
|
||||
# The queue contains messages and subscriptions now.
|
||||
resp, body = self.list_messages(queue_name=queue_name)
|
||||
self.assertIsNotNone(len(body['messages']))
|
||||
resp, body = self.list_subscription(queue_name)
|
||||
self.assertIsNotNone(len(body['subscriptions']))
|
||||
# Purge the queue
|
||||
resp, body = self.purge_queue(queue_name)
|
||||
self.assertEqual(204, resp.status)
|
||||
# The queue contains nothing.
|
||||
resp, body = self.list_messages(queue_name=queue_name)
|
||||
self.assertEqual([], body['messages'])
|
||||
resp, body = self.list_subscription(queue_name)
|
||||
self.assertEqual([], body['subscriptions'])
|
||||
|
||||
@classmethod
|
||||
def resource_cleanup(cls):
|
||||
for queue_name in cls.queues:
|
||||
|
Loading…
x
Reference in New Issue
Block a user