zaqar-tempest-plugin/zaqar_tempest_plugin/tests/v2/test_queues.py
Andreas Jaeger 4195ae11b2 Cleanup py27 support
This repo is now testing only with Python 3, so let's make
a few cleanups:
- Remove py2 stanza from setup.py
- Remove obsolete sections from setup.cfg
- Update classifiers
- Switch to using sphinx-build
- Remove install_command from tox.ini, the default is fine
- Remove Babel from requirements, it's not needed for running.
- Remove obsolete babel.cfg
- Use TOX_CONSTRAINTS_FILE instead of obsolete UPPER_CONSTRAINTS_FILE.
- Update hacking to current 3.1.0 version
- Remove use of six library

Change-Id: I233dfc7a06cbd2e098499629f63d0b8f2db5258e
2020-06-09 14:37:58 +02:00

158 lines
6.4 KiB
Python

# Copyright (c) 2016 HuaWei, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from tempest import config
from tempest.lib.common.utils import data_utils
from tempest.lib import decorators
from zaqar_tempest_plugin.tests import base
CONF = config.CONF
class TestQueues(base.BaseV2MessagingTest):
@decorators.idempotent_id('f2db96f3-fa02-426a-9b42-5806e12f14d4')
def test_create_delete_queue(self):
# Create & Delete Queue
queue_name = data_utils.rand_name('test')
_, body = self.create_queue(queue_name)
self.addCleanup(self.client.delete_queue, queue_name)
# NOTE(gmann): create_queue returns response status code as 201
# so specifically checking the expected empty response body as
# this is not going to be checked in response_checker().
self.assertEqual(b'', body)
self.delete_queue(queue_name)
# lazy queue
self.client.show_queue(queue_name)
class TestManageQueue(base.BaseV2MessagingTest):
@classmethod
def resource_setup(cls):
super(TestManageQueue, cls).resource_setup()
cls.queues = list()
for _ in range(5):
queue_name = data_utils.rand_name('Queues-Test')
cls.queues.append(queue_name)
# 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
_, body = self.list_queues()
self.assertEqual(len(body['queues']), len(self.queues))
for item in body['queues']:
self.assertIn(item['name'], self.queues)
@decorators.idempotent_id('9a2e9a09-5cbd-416f-a75f-fe827462aa9a')
def test_list_queues_with_count(self):
# Listing queues with count
_, body = self.client.list_queues(url_params={"with_count": True})
self.assertEqual(len(body['queues']), len(self.queues))
for item in body['queues']:
self.assertIn(item['name'], self.queues)
@decorators.idempotent_id('e96466e7-d43f-48f9-bfe8-59e3d40f6868')
def test_get_queue_stats(self):
# Retrieve random queue
queue_name = self.queues[data_utils.rand_int_id(0,
len(self.queues) - 1)]
# Get Queue Stats for a newly created Queue
_, body = self.get_queue_stats(queue_name)
msgs = body['messages']
for element in ('free', 'claimed', 'total'):
self.assertEqual(0, msgs[element])
for element in ('oldest', 'newest'):
self.assertNotIn(element, msgs)
@decorators.idempotent_id('dfb1e0b0-b481-4e2a-91ae-2c28b65e9c28')
def test_set_and_get_queue_metadata(self):
QueueName = "QueueWithMeta"
self.client.create_queue(QueueName)
_, body = self.get_queue_metadata(QueueName)
self.assertEqual(262144, body['_max_messages_post_size'])
self.assertEqual(3600, body['_default_message_ttl'])
self.assertEqual(0, body.get('_default_message_delay', 0))
# Create metadata
op1 = {"op": "add",
"path": "/metadata/_max_claim_count", "value": 2}
op2 = {"op": "add",
"path": "/metadata/_dead_letter_queue_messages_ttl",
"value": 7799}
metadata = [op1, op2]
# Set Queue Metadata
self.set_queue_metadata(QueueName, metadata)
# Get Queue Metadata
_, body = self.get_queue_metadata(QueueName)
self.assertEqual(262144, body['_max_messages_post_size'])
self.assertEqual(7799, body['_dead_letter_queue_messages_ttl'])
self.assertEqual(2, body['_max_claim_count'])
self.assertEqual(3600, body['_default_message_ttl'])
self.assertEqual(0, body.get('_default_message_delay', 0))
self.client.delete_queue(QueueName)
@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:
cls.client.delete_queue(queue_name)
super(TestManageQueue, cls).resource_cleanup()