diff --git a/devstack/gate/gate_hook.sh b/devstack/gate/gate_hook.sh index 82d50f67b..c134c3144 100755 --- a/devstack/gate/gate_hook.sh +++ b/devstack/gate/gate_hook.sh @@ -46,7 +46,7 @@ function run_tempest_tests() { cd $BASE/new/tempest/ sudo -E testr init - sudo -E tox -eall-plugin zaqar + sudo -E tox -evenv-tempest -- tempest run -r zaqar_tempest_plugin } function run_zaqarclient_tests() { diff --git a/devstack/settings b/devstack/settings index fd5f98f6b..3186c4e92 100644 --- a/devstack/settings +++ b/devstack/settings @@ -45,4 +45,8 @@ ZAQAR_TRUSTEE_DOMAIN=${ZAQAR_TRUSTEE_DOMAIN:-default} # Tell Tempest this project is present TEMPEST_SERVICES+=,zaqar +GITREPO["zaqar-tempest-plugin"]=${ZAQARTEMPEST_REPO:-${GIT_BASE}/openstack/zaqar-tempest-plugin.git} +GITBRANCH["zaqar-tempest-plugin"]=${ZAQARTEMPEST_BRANCH:-master} +GITDIR["zaqar-tempest-plugin"]=$DEST/zaqar-tempest-plugin + enable_service zaqar-websocket zaqar-wsgi diff --git a/setup.cfg b/setup.cfg index 02b25924f..fb4101e48 100644 --- a/setup.cfg +++ b/setup.cfg @@ -84,9 +84,6 @@ zaqar.notification.tasks = trust+http = zaqar.notification.tasks.trust:TrustTask trust+https = zaqar.notification.tasks.trust:TrustTask -tempest.test_plugins = - zaqar_tests = zaqar.tests.tempest_plugin.plugin:ZaqarTempestPlugin - oslo.policy.policies = zaqar = zaqar.common.policies:list_rules diff --git a/test-requirements.txt b/test-requirements.txt index 5f78d58ca..9679aacea 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -34,8 +34,5 @@ oslotest>=1.10.0 # Apache-2.0 reno>=2.5.0 # Apache-2.0 os-api-ref>=1.4.0 # Apache-2.0 -# Tempest -tempest>=16.1.0 # Apache-2.0 - #OSprofiler osprofiler>=1.4.0 # Apache-2.0 diff --git a/zaqar/tests/tempest_plugin/__init__.py b/zaqar/tests/tempest_plugin/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/zaqar/tests/tempest_plugin/api_schema/__init__.py b/zaqar/tests/tempest_plugin/api_schema/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/zaqar/tests/tempest_plugin/api_schema/response/__init__.py b/zaqar/tests/tempest_plugin/api_schema/response/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/zaqar/tests/tempest_plugin/api_schema/response/v1/__init__.py b/zaqar/tests/tempest_plugin/api_schema/response/v1/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/zaqar/tests/tempest_plugin/api_schema/response/v1/queues.py b/zaqar/tests/tempest_plugin/api_schema/response/v1/queues.py deleted file mode 100644 index bf645f1a1..000000000 --- a/zaqar/tests/tempest_plugin/api_schema/response/v1/queues.py +++ /dev/null @@ -1,238 +0,0 @@ -# Copyright (c) 2014 Rackspace, 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. - - -list_link = { - 'type': 'object', - 'properties': { - 'rel': {'type': 'string'}, - 'href': { - 'type': 'string', - 'format': 'uri' - } - }, - 'required': ['href', 'rel'] -} - -list_queue = { - 'type': 'object', - 'properties': { - 'name': {'type': 'string'}, - 'href': { - 'type': 'string', - 'format': 'uri' - }, - 'metadata': {'type': 'object'} - }, - 'required': ['name', 'href'] -} - -list_queues = { - 'status_code': [200, 204], - 'response_body': { - 'type': 'object', - 'properties': { - 'links': { - 'type': 'array', - 'items': list_link, - 'maxItems': 1 - }, - 'queues': { - 'type': 'array', - 'items': list_queue - } - }, - 'required': ['links', 'queues'] - } -} - -age = { - 'type': 'number', - 'minimum': 0 -} - -message_link = { - 'type': 'object', - 'properties': { - 'href': { - 'type': 'string', - 'format': 'uri' - }, - 'age': age, - 'created': { - 'type': 'string', - 'format': 'date-time' - } - }, - 'required': ['href', 'age', 'created'] -} - -messages = { - 'type': 'object', - 'properties': { - 'free': {'type': 'number'}, - 'claimed': {'type': 'number'}, - 'total': {'type': 'number'}, - 'oldest': message_link, - 'newest': message_link - }, - 'required': ['free', 'claimed', 'total'] -} - -queue_stats = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'messages': messages - }, - 'required': ['messages'] - } -} - -resource_schema = { - 'type': 'array', - 'items': { - 'type': 'string' - }, - 'minItems': 1 -} - -post_messages = { - 'status_code': [201], - 'response_body': { - 'type': 'object', - 'properties': { - 'resources': resource_schema, - 'partial': {'type': 'boolean'} - } - }, - 'required': ['resources', 'partial'] -} - -message_ttl = { - 'type': 'number', - 'minimum': 1 -} - -list_messages_links = { - 'type': 'array', - 'maxItems': 1, - 'minItems': 1, - 'items': { - 'type': 'object', - 'properties': { - 'rel': {'type': 'string'}, - 'href': {'type': 'string'} - }, - 'required': ['rel', 'href'] - } -} - -list_messages_response = { - 'type': 'array', - 'minItems': 1, - 'items': { - 'type': 'object', - 'properties': { - 'href': {'type': 'string'}, - 'ttl': message_ttl, - 'age': age, - 'body': {'type': 'object'} - }, - 'required': ['href', 'ttl', 'age', 'body'] - } -} - -list_messages = { - 'status_code': [200, 204], - 'response_body': { - 'type': 'object', - 'properties': { - 'links': list_messages_links, - 'messages': list_messages_response - } - }, - 'required': ['links', 'messages'] -} - -single_message = { - 'type': 'object', - 'properties': { - 'href': {'type': 'string'}, - 'ttl': message_ttl, - 'age': age, - 'body': {'type': 'object'} - }, - 'required': ['href', 'ttl', 'age', 'body'] -} - -get_single_message = { - 'status_code': [200], - 'response_body': single_message -} - -get_multiple_messages = { - 'status_code': [200], - 'response_body': { - 'type': 'array', - 'items': single_message, - 'minItems': 1 - } -} - -messages_claimed = { - 'type': 'object', - 'properties': { - 'href': { - 'type': 'string', - 'format': 'uri' - }, - 'ttl': message_ttl, - 'age': {'type': 'number'}, - 'body': {'type': 'object'} - }, - 'required': ['href', 'ttl', 'age', 'body'] -} - -claim_messages = { - 'status_code': [201, 204], - 'response_body': { - 'type': 'array', - 'items': messages_claimed, - 'minItems': 1 - } -} - -claim_ttl = { - 'type': 'number', - 'minimum': 1 -} - -query_claim = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'age': {'type': 'number'}, - 'ttl': claim_ttl, - 'messages': { - 'type': 'array', - 'minItems': 1 - } - }, - 'required': ['ttl', 'age', 'messages'] - } -} diff --git a/zaqar/tests/tempest_plugin/api_schema/response/v1_1/__init__.py b/zaqar/tests/tempest_plugin/api_schema/response/v1_1/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/zaqar/tests/tempest_plugin/api_schema/response/v1_1/queues.py b/zaqar/tests/tempest_plugin/api_schema/response/v1_1/queues.py deleted file mode 100644 index 92b5b6b89..000000000 --- a/zaqar/tests/tempest_plugin/api_schema/response/v1_1/queues.py +++ /dev/null @@ -1,250 +0,0 @@ -# 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. - - -list_link = { - 'type': 'object', - 'properties': { - 'rel': {'type': 'string'}, - 'href': { - 'type': 'string', - 'format': 'uri' - } - }, - 'required': ['href', 'rel'] -} - -list_queue = { - 'type': 'object', - 'properties': { - 'name': {'type': 'string'}, - 'href': { - 'type': 'string', - 'format': 'uri' - }, - 'metadata': {'type': 'object'} - }, - 'required': ['name', 'href'] -} - -list_queues = { - 'status_code': [200, 204], - 'response_body': { - 'type': 'object', - 'properties': { - 'links': { - 'type': 'array', - 'items': list_link, - 'maxItems': 1 - }, - 'queues': { - 'type': 'array', - 'items': list_queue - } - }, - 'required': ['links', 'queues'] - } -} - -age = { - 'type': 'number', - 'minimum': 0 -} - -message_link = { - 'type': 'object', - 'properties': { - 'href': { - 'type': 'string', - 'format': 'uri' - }, - 'age': age, - 'created': { - 'type': 'string', - 'format': 'date-time' - } - }, - 'required': ['href', 'age', 'created'] -} - -messages = { - 'type': 'object', - 'properties': { - 'free': {'type': 'number'}, - 'claimed': {'type': 'number'}, - 'total': {'type': 'number'}, - 'oldest': message_link, - 'newest': message_link - }, - 'required': ['free', 'claimed', 'total'] -} - -queue_stats = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'messages': messages - }, - 'required': ['messages'] - } -} - -resource_schema = { - 'type': 'array', - 'items': { - 'type': 'string' - }, - 'minItems': 1 -} - -post_messages = { - 'status_code': [201], - 'response_body': { - 'type': 'object', - 'properties': { - 'resources': resource_schema, - 'partial': {'type': 'boolean'} - } - }, - 'required': ['resources', 'partial'] -} - -message_ttl = { - 'type': 'number', - 'minimum': 1 -} - -list_messages_links = { - 'type': 'array', - 'maxItems': 1, - 'minItems': 1, - 'items': { - 'type': 'object', - 'properties': { - 'rel': {'type': 'string'}, - 'href': {'type': 'string'} - }, - 'required': ['rel', 'href'] - } -} - -list_messages_response = { - 'type': 'array', - 'minItems': 1, - 'items': { - 'type': 'object', - 'properties': { - 'href': {'type': 'string'}, - 'ttl': message_ttl, - 'age': age, - 'body': {'type': 'object'} - }, - 'required': ['href', 'ttl', 'age', 'body'] - } -} - -list_messages = { - 'status_code': [200, 204], - 'response_body': { - 'type': 'object', - 'properties': { - 'links': list_messages_links, - 'messages': list_messages_response - } - }, - 'required': ['links', 'messages'] -} - -single_message = { - 'type': 'object', - 'properties': { - 'href': {'type': 'string'}, - 'ttl': message_ttl, - 'age': age, - 'body': {'type': 'object'}, - 'id': {'type': 'string'} - }, - 'required': ['href', 'ttl', 'age', 'body', 'id'] -} - -get_single_message = { - 'status_code': [200], - 'response_body': single_message -} - -get_multiple_messages = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'messages': { - "type": "array", - "items": single_message, - "minItems": 1, - } - } - } -} - -messages_claimed = { - 'type': 'object', - 'properties': { - 'href': { - 'type': 'string', - 'format': 'uri' - }, - 'ttl': message_ttl, - 'age': {'type': 'number'}, - 'body': {'type': 'object'}, - 'id': {'type': 'string'} - }, - 'required': ['href', 'ttl', 'age', 'body', 'id'] -} - -claim_messages = { - 'status_code': [201, 204], - 'response_body': { - 'type': 'object', - 'properties': { - 'messages': { - "type": "array", - "items": single_message, - "minItems": 1, - } - } - } -} - -claim_ttl = { - 'type': 'number', - 'minimum': 1 -} - -query_claim = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'age': {'type': 'number'}, - 'ttl': claim_ttl, - 'messages': { - 'type': 'array', - 'minItems': 1 - } - }, - 'required': ['ttl', 'age', 'messages'] - } -} diff --git a/zaqar/tests/tempest_plugin/api_schema/response/v2/__init__.py b/zaqar/tests/tempest_plugin/api_schema/response/v2/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/zaqar/tests/tempest_plugin/api_schema/response/v2/queues.py b/zaqar/tests/tempest_plugin/api_schema/response/v2/queues.py deleted file mode 100644 index e22ffaac7..000000000 --- a/zaqar/tests/tempest_plugin/api_schema/response/v2/queues.py +++ /dev/null @@ -1,297 +0,0 @@ -# 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. - - -list_link = { - 'type': 'object', - 'properties': { - 'rel': {'type': 'string'}, - 'href': { - 'type': 'string', - 'format': 'uri' - } - }, - 'required': ['href', 'rel'] -} - -list_queue = { - 'type': 'object', - 'properties': { - 'name': {'type': 'string'}, - 'href': { - 'type': 'string', - 'format': 'uri' - }, - 'metadata': {'type': 'object'} - }, - 'required': ['name', 'href'] -} - -list_queues = { - 'status_code': [200, 204], - 'response_body': { - 'type': 'object', - 'properties': { - 'links': { - 'type': 'array', - 'items': list_link, - 'maxItems': 1 - }, - 'queues': { - 'type': 'array', - 'items': list_queue - } - }, - 'required': ['links', 'queues'] - } -} - -age = { - 'type': 'number', - 'minimum': 0 -} - -message_link = { - 'type': 'object', - 'properties': { - 'href': { - 'type': 'string', - 'format': 'uri' - }, - 'age': age, - 'created': { - 'type': 'string', - 'format': 'date-time' - } - }, - 'required': ['href', 'age', 'created'] -} - -messages = { - 'type': 'object', - 'properties': { - 'free': {'type': 'number'}, - 'claimed': {'type': 'number'}, - 'total': {'type': 'number'}, - 'oldest': message_link, - 'newest': message_link - }, - 'required': ['free', 'claimed', 'total'] -} - -queue_stats = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'messages': messages - }, - 'required': ['messages'] - } -} - -resource_schema = { - 'type': 'array', - 'items': { - 'type': 'string' - }, - 'minItems': 1 -} - -post_messages = { - 'status_code': [201], - 'response_body': { - 'type': 'object', - 'properties': { - 'resources': resource_schema, - 'partial': {'type': 'boolean'} - } - }, - 'required': ['resources', 'partial'] -} - -message_ttl = { - 'type': 'number', - 'minimum': 1 -} - -list_messages_links = { - 'type': 'array', - 'maxItems': 1, - 'minItems': 0, - 'items': { - 'type': 'object', - 'properties': { - 'rel': {'type': 'string'}, - 'href': {'type': 'string'} - }, - 'required': ['rel', 'href'] - } -} - -list_messages_response = { - 'type': 'array', - 'minItems': 0, - 'items': { - 'type': 'object', - 'properties': { - 'href': {'type': 'string'}, - 'ttl': message_ttl, - 'age': age, - 'body': {'type': 'object'} - }, - 'required': ['href', 'ttl', 'age', 'body'] - } -} - -list_messages = { - 'status_code': [200, 204], - 'response_body': { - 'type': 'object', - 'properties': { - 'links': list_messages_links, - 'messages': list_messages_response - } - }, - 'required': ['links', 'messages'] -} - -single_message = { - 'type': 'object', - 'properties': { - 'href': {'type': 'string'}, - 'ttl': message_ttl, - 'age': age, - 'body': {'type': 'object'}, - 'id': {'type': 'string'} - }, - 'required': ['href', 'ttl', 'age', 'body', 'id'] -} - -get_single_message = { - 'status_code': [200], - 'response_body': single_message -} - -get_multiple_messages = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'messages': { - "type": "array", - "items": single_message, - "minItems": 1, - } - } - } -} - -messages_claimed = { - 'type': 'object', - 'properties': { - 'href': { - 'type': 'string', - 'format': 'uri' - }, - 'ttl': message_ttl, - 'age': {'type': 'number'}, - 'body': {'type': 'object'}, - 'id': {'type': 'string'} - }, - 'required': ['href', 'ttl', 'age', 'body', 'id'] -} - -claim_messages = { - 'status_code': [201, 204], - 'response_body': { - 'type': 'object', - 'properties': { - 'messages': { - "type": "array", - "items": single_message, - "minItems": 1, - } - } - } -} - -claim_ttl = { - 'type': 'number', - 'minimum': 1 -} - -query_claim = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'age': {'type': 'number'}, - 'ttl': claim_ttl, - 'messages': { - 'type': 'array', - 'minItems': 1 - } - }, - 'required': ['ttl', 'age', 'messages'] - } -} - -create_subscription = { - 'status_code': [201], - 'response_body': { - 'type': 'object', - 'properties': { - 'subscription_id': {'type': 'string'}, - }, - 'required': ['subscription_id'] - } -} - -single_subscription = { - 'type': 'object', - 'properties': { - 'subscriber': {'type': 'string'}, - 'source': {'type': 'string'}, - 'options': {'type': 'object'}, - 'id': {'type': 'string'}, - 'ttl': message_ttl, - }, - 'required': ['subscriber', 'source', 'options', 'id', 'ttl'] -} - -show_single_subscription = { - 'status_code': [200], - 'response_body': single_subscription -} - -list_subscriptions = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'subscriptions': { - "type": "array", - "items": single_subscription, - }, - 'links': { - 'type': 'array', - 'items': list_link, - 'maxItems': 1 - }, - }, - 'required': ['subscriptions', 'links'] - } -} diff --git a/zaqar/tests/tempest_plugin/config.py b/zaqar/tests/tempest_plugin/config.py deleted file mode 100644 index eb7c5b664..000000000 --- a/zaqar/tests/tempest_plugin/config.py +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright (c) 2016 Hewlett-Packard Development Company, L.P. -# -# 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 oslo_config import cfg - -service_option = cfg.BoolOpt('zaqar', - default=True, - help="Whether or not Zaqar is expected to be " - "available") - -messaging_group = cfg.OptGroup(name='messaging', - title='Messaging Service') - -MessagingGroup = [ - cfg.StrOpt('catalog_type', - default='messaging', - help='Catalog type of the Messaging service.'), - cfg.IntOpt('max_queues_per_page', - default=20, - help='The maximum number of queue records per page when ' - 'listing queues'), - cfg.IntOpt('max_queue_metadata', - default=65536, - help='The maximum metadata size for a queue'), - cfg.IntOpt('max_messages_per_page', - default=20, - help='The maximum number of queue message per page when ' - 'listing (or) posting messages'), - cfg.IntOpt('max_message_size', - default=262144, - help='The maximum size of a message body'), - cfg.IntOpt('max_messages_per_claim', - default=20, - help='The maximum number of messages per claim'), - cfg.IntOpt('max_message_ttl', - default=1209600, - help='The maximum ttl for a message'), - cfg.IntOpt('max_claim_ttl', - default=43200, - help='The maximum ttl for a claim'), - cfg.IntOpt('max_claim_grace', - default=43200, - help='The maximum grace period for a claim'), -] diff --git a/zaqar/tests/tempest_plugin/plugin.py b/zaqar/tests/tempest_plugin/plugin.py deleted file mode 100644 index 70ffad4b6..000000000 --- a/zaqar/tests/tempest_plugin/plugin.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (c) 2016 Hewlett-Packard Development Company, L.P. -# All Rights Reserved. -# -# 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. - - -import os - -from tempest.test_discover import plugins - -from zaqar.tests.tempest_plugin import config as zaqar_config - - -class ZaqarTempestPlugin(plugins.TempestPlugin): - def load_tests(self): - base_path = os.path.split(os.path.dirname( - os.path.abspath(__file__)))[0] - # Note: base_path should be set to the top directory - # of zaqar. - base_path += '/../..' - test_dir = "zaqar/tests/tempest_plugin/tests" - full_test_dir = os.path.join(base_path, test_dir) - return full_test_dir, base_path - - def register_opts(self, conf): - conf.register_group(zaqar_config.messaging_group) - conf.register_opts(zaqar_config.MessagingGroup, group='messaging') - conf.register_opt(zaqar_config.service_option, - group='service_available') - - def get_opt_lists(self): - return [('messaging', zaqar_config.MessagingGroup), - ('service_available', [zaqar_config.service_option])] diff --git a/zaqar/tests/tempest_plugin/services/__init__.py b/zaqar/tests/tempest_plugin/services/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/zaqar/tests/tempest_plugin/services/messaging/__init__.py b/zaqar/tests/tempest_plugin/services/messaging/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/zaqar/tests/tempest_plugin/services/messaging/json/__init__.py b/zaqar/tests/tempest_plugin/services/messaging/json/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/zaqar/tests/tempest_plugin/services/messaging/json/messaging_client.py b/zaqar/tests/tempest_plugin/services/messaging/json/messaging_client.py deleted file mode 100644 index 9f3a44b9c..000000000 --- a/zaqar/tests/tempest_plugin/services/messaging/json/messaging_client.py +++ /dev/null @@ -1,510 +0,0 @@ -# Copyright (c) 2014 Rackspace, 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 oslo_utils import uuidutils - -from oslo_serialization import jsonutils as json -from six.moves.urllib import parse as urllib -from tempest.lib.common import rest_client - -from zaqar.tests.tempest_plugin.api_schema.response.v1 \ - import queues as v1schema -from zaqar.tests.tempest_plugin.api_schema.response.v1_1 \ - import queues as v11schema -from zaqar.tests.tempest_plugin.api_schema.response.v2 \ - import queues as v2schema - - -class MessagingClient(rest_client.RestClient): - - def __init__(self, auth_provider, service, region, **kwargs): - super(MessagingClient, self).__init__( - auth_provider, service, region, **kwargs) - - self.version = '1' - self.uri_prefix = 'v{0}'.format(self.version) - - client_id = uuidutils.generate_uuid(dashed=False) - self.headers = {'Client-ID': client_id} - - -class V1MessagingClient(MessagingClient): - def __init__(self, auth_provider, service, region, **kwargs): - super(V1MessagingClient, self).__init__( - auth_provider, service, region, **kwargs) - - self.version = '1' - - def list_queues(self): - uri = '{0}/queues'.format(self.uri_prefix) - resp, body = self.get(uri) - - if resp['status'] != '204': - body = json.loads(body) - self.validate_response(v1schema.list_queues, resp, body) - return resp, body - - def create_queue(self, queue_name): - uri = '{0}/queues/{1}'.format(self.uri_prefix, queue_name) - resp, body = self.put(uri, body=None) - self.expected_success(201, resp.status) - return resp, body - - def show_queue(self, queue_name): - uri = '{0}/queues/{1}'.format(self.uri_prefix, queue_name) - resp, body = self.get(uri) - self.expected_success(204, resp.status) - return resp, body - - def head_queue(self, queue_name): - uri = '{0}/queues/{1}'.format(self.uri_prefix, queue_name) - resp, body = self.head(uri) - self.expected_success(204, resp.status) - return resp, body - - def delete_queue(self, queue_name): - uri = '{0}/queues/{1}'.format(self.uri_prefix, queue_name) - resp, body = self.delete(uri) - 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) - body = json.loads(body) - self.validate_response(v1schema.queue_stats, resp, body) - return resp, body - - def show_queue_metadata(self, queue_name): - uri = '{0}/queues/{1}/metadata'.format(self.uri_prefix, queue_name) - resp, body = self.get(uri) - self.expected_success(200, resp.status) - body = json.loads(body) - return resp, body - - def set_queue_metadata(self, queue_name, rbody): - uri = '{0}/queues/{1}/metadata'.format(self.uri_prefix, queue_name) - resp, body = self.put(uri, body=json.dumps(rbody)) - self.expected_success(204, resp.status) - return resp, body - - def post_messages(self, queue_name, rbody): - uri = '{0}/queues/{1}/messages'.format(self.uri_prefix, queue_name) - resp, body = self.post(uri, body=json.dumps(rbody), - extra_headers=True, - headers=self.headers) - - body = json.loads(body) - self.validate_response(v1schema.post_messages, resp, body) - return resp, body - - def list_messages(self, queue_name): - uri = '{0}/queues/{1}/messages?echo=True'.format(self.uri_prefix, - queue_name) - resp, body = self.get(uri, extra_headers=True, headers=self.headers) - - if resp['status'] != '204': - body = json.loads(body) - self.validate_response(v1schema.list_messages, resp, body) - - return resp, body - - def show_single_message(self, message_uri): - resp, body = self.get(message_uri, extra_headers=True, - headers=self.headers) - if resp['status'] != '204': - body = json.loads(body) - self.validate_response(v1schema.get_single_message, resp, - body) - return resp, body - - def show_multiple_messages(self, message_uri): - resp, body = self.get(message_uri, extra_headers=True, - headers=self.headers) - - if resp['status'] != '204': - body = json.loads(body) - self.validate_response(v1schema.get_multiple_messages, - resp, - body) - - return resp, body - - def delete_messages(self, message_uri): - resp, body = self.delete(message_uri) - self.expected_success(204, resp.status) - return resp, body - - def post_claims(self, queue_name, rbody, url_params=False): - uri = '{0}/queues/{1}/claims'.format(self.uri_prefix, queue_name) - if url_params: - uri += '?%s' % urllib.urlencode(url_params) - - resp, body = self.post(uri, body=json.dumps(rbody), - extra_headers=True, - headers=self.headers) - - body = json.loads(body) - self.validate_response(v1schema.claim_messages, resp, body) - return resp, body - - def query_claim(self, claim_uri): - resp, body = self.get(claim_uri) - - if resp['status'] != '204': - body = json.loads(body) - self.validate_response(v1schema.query_claim, resp, body) - return resp, body - - def update_claim(self, claim_uri, rbody): - resp, body = self.patch(claim_uri, body=json.dumps(rbody)) - self.expected_success(204, resp.status) - return resp, body - - def delete_claim(self, claim_uri): - resp, body = self.delete(claim_uri) - self.expected_success(204, resp.status) - return resp, body - - -class V11MessagingClient(MessagingClient): - def __init__(self, auth_provider, service, region, **kwargs): - super(V11MessagingClient, self).__init__( - auth_provider, service, region, **kwargs) - - self.version = '1.1' - self.uri_prefix = 'v{0}'.format(self.version) - - def list_queues(self): - uri = '{0}/queues'.format(self.uri_prefix) - resp, body = self.get(uri, headers=self.headers) - - if resp['status'] != '204': - body = json.loads(body) - self.validate_response(v11schema.list_queues, resp, body) - return resp, body - - def create_queue(self, queue_name): - uri = '{0}/queues/{1}'.format(self.uri_prefix, queue_name) - resp, body = self.put(uri, body=None, headers=self.headers) - self.expected_success(201, resp.status) - return resp, body - - def show_queue(self, queue_name): - uri = '{0}/queues/{1}'.format(self.uri_prefix, queue_name) - resp, body = self.get(uri, headers=self.headers) - self.expected_success(200, resp.status) - return resp, body - - def delete_queue(self, queue_name): - uri = '{0}/queues/{1}'.format(self.uri_prefix, queue_name) - resp, body = self.delete(uri, 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) - body = json.loads(body) - self.validate_response(v11schema.queue_stats, resp, body) - return resp, body - - def show_queue_metadata(self, queue_name): - uri = '{0}/queues/{1}/metadata'.format(self.uri_prefix, queue_name) - resp, body = self.get(uri, headers=self.headers) - self.expected_success(200, resp.status) - body = json.loads(body) - return resp, body - - def set_queue_metadata(self, queue_name, rbody): - uri = '{0}/queues/{1}/metadata'.format(self.uri_prefix, queue_name) - resp, body = self.put(uri, body=json.dumps(rbody), - headers=self.headers) - self.expected_success(204, resp.status) - return resp, body - - def post_messages(self, queue_name, rbody): - uri = '{0}/queues/{1}/messages'.format(self.uri_prefix, queue_name) - resp, body = self.post(uri, body=json.dumps(rbody), - extra_headers=True, - headers=self.headers) - - body = json.loads(body) - self.validate_response(v11schema.post_messages, resp, body) - return resp, body - - def list_messages(self, queue_name): - uri = '{0}/queues/{1}/messages?echo=True'.format(self.uri_prefix, - queue_name) - resp, body = self.get(uri, extra_headers=True, headers=self.headers) - - if resp['status'] != '204': - body = json.loads(body) - self.validate_response(v11schema.list_messages, resp, body) - - return resp, body - - def show_single_message(self, message_uri): - resp, body = self.get(message_uri, extra_headers=True, - headers=self.headers) - if resp['status'] != '204': - body = json.loads(body) - self.validate_response(v11schema.get_single_message, resp, - body) - return resp, body - - def show_multiple_messages(self, message_uri): - resp, body = self.get(message_uri, extra_headers=True, - headers=self.headers) - - if resp['status'] != '404': - body = json.loads(body) - self.validate_response(v11schema.get_multiple_messages, - resp, - body) - - return resp, body - - def delete_messages(self, message_uri): - resp, body = self.delete(message_uri, headers=self.headers) - self.expected_success(204, resp.status) - return resp, body - - def post_claims(self, queue_name, rbody, url_params=False): - uri = '{0}/queues/{1}/claims'.format(self.uri_prefix, queue_name) - if url_params: - uri += '?%s' % urllib.urlencode(url_params) - - resp, body = self.post(uri, body=json.dumps(rbody), - extra_headers=True, - headers=self.headers) - - body = json.loads(body) - self.validate_response(v11schema.claim_messages, resp, body) - return resp, body - - def query_claim(self, claim_uri): - resp, body = self.get(claim_uri, headers=self.headers) - - if resp['status'] != '204': - body = json.loads(body) - self.validate_response(v11schema.query_claim, resp, body) - return resp, body - - def update_claim(self, claim_uri, rbody): - resp, body = self.patch(claim_uri, body=json.dumps(rbody), - headers=self.headers) - self.expected_success(204, resp.status) - return resp, body - - def delete_claim(self, claim_uri): - resp, body = self.delete(claim_uri, headers=self.headers) - self.expected_success(204, resp.status) - return resp, body - - -class V2MessagingClient(MessagingClient): - def __init__(self, auth_provider, service, region, **kwargs): - super(V2MessagingClient, self).__init__( - auth_provider, service, region, **kwargs) - - self.version = '2' - self.uri_prefix = 'v{0}'.format(self.version) - - def list_queues(self, url_params=False): - uri = '{0}/queues'.format(self.uri_prefix) - if url_params: - uri += '?%s' % urllib.urlencode(url_params) - - resp, body = self.get(uri, headers=self.headers) - if resp['status'] != '204': - body = json.loads(body) - self.validate_response(v2schema.list_queues, resp, body) - return resp, body - - def create_queue(self, queue_name): - uri = '{0}/queues/{1}'.format(self.uri_prefix, queue_name) - resp, body = self.put(uri, body=None, headers=self.headers) - self.expected_success(201, resp.status) - return resp, body - - def show_queue(self, queue_name): - uri = '{0}/queues/{1}'.format(self.uri_prefix, queue_name) - resp, body = self.get(uri, headers=self.headers) - self.expected_success(200, resp.status) - return resp, body - - def delete_queue(self, queue_name): - uri = '{0}/queues/{1}'.format(self.uri_prefix, queue_name) - resp, body = self.delete(uri, headers=self.headers) - 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) - body = json.loads(body) - self.validate_response(v2schema.queue_stats, resp, body) - return resp, body - - def show_queue_metadata(self, queue_name): - uri = '{0}/queues/{1}'.format(self.uri_prefix, queue_name) - resp, body = self.get(uri, headers=self.headers) - self.expected_success(200, resp.status) - body = json.loads(body) - return resp, body - - def set_queue_metadata(self, queue_name, rbody): - uri = '{0}/queues/{1}'.format(self.uri_prefix, queue_name) - headers = self.headers.copy() - headers['Content-Type'] =\ - 'application/openstack-messaging-v2.0-json-patch' - resp, body = self.patch(uri, body=json.dumps(rbody), - headers=headers) - self.expected_success(200, resp.status) - return resp, body - - def post_messages(self, queue_name, rbody): - uri = '{0}/queues/{1}/messages'.format(self.uri_prefix, queue_name) - resp, body = self.post(uri, body=json.dumps(rbody), - extra_headers=True, - headers=self.headers) - - body = json.loads(body) - self.validate_response(v2schema.post_messages, resp, body) - return resp, body - - def list_messages(self, queue_name): - uri = '{0}/queues/{1}/messages?echo=True'.format(self.uri_prefix, - queue_name) - resp, body = self.get(uri, extra_headers=True, headers=self.headers) - - if resp['status'] != '204': - body = json.loads(body) - self.validate_response(v2schema.list_messages, resp, body) - - return resp, body - - def show_single_message(self, message_uri): - resp, body = self.get(message_uri, extra_headers=True, - headers=self.headers) - if resp['status'] != '204': - body = json.loads(body) - self.validate_response(v2schema.get_single_message, resp, - body) - return resp, body - - def show_multiple_messages(self, message_uri): - resp, body = self.get(message_uri, extra_headers=True, - headers=self.headers) - - if resp['status'] != '404': - body = json.loads(body) - self.validate_response(v2schema.get_multiple_messages, - resp, - body) - - return resp, body - - def delete_messages(self, message_uri): - resp, body = self.delete(message_uri, headers=self.headers) - self.expected_success(204, resp.status) - return resp, body - - def post_claims(self, queue_name, rbody, url_params=False): - uri = '{0}/queues/{1}/claims'.format(self.uri_prefix, queue_name) - if url_params: - uri += '?%s' % urllib.urlencode(url_params) - - resp, body = self.post(uri, body=json.dumps(rbody), - extra_headers=True, - headers=self.headers) - - if resp['status'] != '204': - body = json.loads(body) - self.validate_response(v2schema.claim_messages, resp, body) - return resp, body - - def query_claim(self, claim_uri): - resp, body = self.get(claim_uri, headers=self.headers) - - if resp['status'] != '204': - body = json.loads(body) - self.validate_response(v2schema.query_claim, resp, body) - return resp, body - - def update_claim(self, claim_uri, rbody): - resp, body = self.patch(claim_uri, body=json.dumps(rbody), - headers=self.headers) - self.expected_success(204, resp.status) - return resp, body - - def delete_claim(self, claim_uri): - resp, body = self.delete(claim_uri, headers=self.headers) - self.expected_success(204, resp.status) - return resp, body - - def create_subscription(self, queue_name, rbody): - uri = '{0}/queues/{1}/subscriptions'.format(self.uri_prefix, - queue_name) - - resp, body = self.post(uri, body=json.dumps(rbody), - extra_headers=True, - headers=self.headers) - body = json.loads(body) - self.validate_response(v2schema.create_subscription, resp, body) - return resp, body - - def delete_subscription(self, queue_name, subscription_id): - uri = '{0}/queues/{1}/subscriptions/{2}'.format(self.uri_prefix, - queue_name, - subscription_id) - resp, body = self.delete(uri, headers=self.headers) - return resp, body - - def list_subscription(self, queue_name): - uri = '{0}/queues/{1}/subscriptions/'.format(self.uri_prefix, - queue_name) - resp, body = self.get(uri, headers=self.headers) - body = json.loads(body) - self.validate_response(v2schema.list_subscriptions, resp, body) - return resp, body - - def show_subscription(self, queue_name, subscription_id): - uri = '{0}/queues/{1}/subscriptions/{2}'.format(self.uri_prefix, - queue_name, - subscription_id) - resp, body = self.get(uri, headers=self.headers) - body = json.loads(body) - self.validate_response(v2schema.show_single_subscription, resp, body) - return resp, body - - def update_subscription(self, queue_name, subscription_id, rbody): - uri = '{0}/queues/{1}/subscriptions/{2}'.format(self.uri_prefix, - queue_name, - subscription_id) - resp, body = self.patch(uri, body=json.dumps(rbody), - headers=self.headers) - return resp, body diff --git a/zaqar/tests/tempest_plugin/tests/__init__.py b/zaqar/tests/tempest_plugin/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/zaqar/tests/tempest_plugin/tests/base.py b/zaqar/tests/tempest_plugin/tests/base.py deleted file mode 100644 index b174ff0de..000000000 --- a/zaqar/tests/tempest_plugin/tests/base.py +++ /dev/null @@ -1,277 +0,0 @@ -# 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 import test - -from zaqar.tests.tempest_plugin.services.messaging.json import messaging_client - -CONF = config.CONF - - -class BaseMessagingTest(test.BaseTestCase): - - """Base class for the Messaging (Zaqar) tests - - It is assumed that the following option is defined in the - [service_available] section of etc/tempest.conf - - messaging as True - """ - - credentials = ['primary'] - - @classmethod - def skip_checks(cls): - super(BaseMessagingTest, cls).skip_checks() - if not CONF.service_available.zaqar: - raise cls.skipException("Zaqar support is required") - - @classmethod - def resource_setup(cls): - super(BaseMessagingTest, cls).resource_setup() - cls.messaging_cfg = CONF.messaging - - @classmethod - def create_queue(cls, queue_name): - """Wrapper utility that returns a test queue.""" - resp, body = cls.client.create_queue(queue_name) - return resp, body - - @classmethod - def delete_queue(cls, queue_name): - """Wrapper utility that deletes a test queue.""" - resp, body = cls.client.delete_queue(queue_name) - return resp, body - - @classmethod - def list_queues(cls): - """Wrapper utility that lists queues.""" - resp, body = cls.client.list_queues() - return resp, body - - @classmethod - def get_queue_stats(cls, queue_name): - """Wrapper utility that returns the queue stats.""" - resp, body = cls.client.show_queue_stats(queue_name) - return resp, body - - @classmethod - def get_queue_metadata(cls, queue_name): - """Wrapper utility that gets a queue metadata.""" - resp, body = cls.client.show_queue_metadata(queue_name) - return resp, body - - @classmethod - def set_queue_metadata(cls, queue_name, rbody): - """Wrapper utility that sets the metadata of a queue.""" - resp, body = cls.client.set_queue_metadata(queue_name, rbody) - return resp, body - - @classmethod - def post_messages(cls, queue_name, rbody): - """Wrapper utility that posts messages to a queue.""" - resp, body = cls.client.post_messages(queue_name, rbody) - - return resp, body - - @classmethod - def list_messages(cls, queue_name): - """Wrapper utility that lists the messages in a queue.""" - resp, body = cls.client.list_messages(queue_name) - - return resp, body - - @classmethod - def delete_messages(cls, message_uri): - """Wrapper utility that deletes messages.""" - resp, body = cls.client.delete_messages(message_uri) - - return resp, body - - @classmethod - def post_claims(cls, queue_name, rbody, url_params=False): - """Wrapper utility that claims messages.""" - resp, body = cls.client.post_claims( - queue_name, rbody, url_params=False) - - return resp, body - - @classmethod - def query_claim(cls, claim_uri): - """Wrapper utility that gets a claim.""" - resp, body = cls.client.query_claim(claim_uri) - - return resp, body - - @classmethod - def update_claim(cls, claim_uri, rbody): - """Wrapper utility that updates a claim.""" - resp, body = cls.client.update_claim(claim_uri, rbody) - - return resp, body - - @classmethod - def release_claim(cls, claim_uri): - """Wrapper utility that deletes a claim.""" - resp, body = cls.client.delete_claim(claim_uri) - - return resp, body - - @classmethod - def generate_message_body(cls, repeat=1): - """Wrapper utility that sets the metadata of a queue.""" - message_ttl = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_message_ttl) - - key = data_utils.arbitrary_string(size=20, base_text='MessagingKey') - value = data_utils.arbitrary_string(size=20, - base_text='MessagingValue') - message_body = {key: value} - - rbody = ([{'body': message_body, 'ttl': message_ttl}] * repeat) - return rbody - - -class BaseV1MessagingTest(BaseMessagingTest): - """Base class for the Messaging (Zaqar) v1.0 tests.""" - @classmethod - def setup_clients(cls): - super(BaseV1MessagingTest, cls).setup_clients() - cls.client = messaging_client.V1MessagingClient( - cls.os_primary.auth_provider, - CONF.messaging.catalog_type, - CONF.identity.region, - build_interval=CONF.compute.build_interval, - build_timeout=CONF.compute.build_timeout) - - @classmethod - def check_queue_exists(cls, queue_name): - """Wrapper utility that checks the existence of a test queue.""" - resp, body = cls.client.show_queue(queue_name) - return resp, body - - @classmethod - def check_queue_exists_head(cls, queue_name): - """Wrapper utility checks the head of a queue via http HEAD.""" - resp, body = cls.client.head_queue(queue_name) - return resp, body - - -class BaseV11MessagingTest(BaseMessagingTest): - """Base class for the Messaging (Zaqar) v1.1 tests.""" - @classmethod - def setup_clients(cls): - super(BaseV11MessagingTest, cls).setup_clients() - cls.client = messaging_client.V11MessagingClient( - cls.os_primary.auth_provider, - CONF.messaging.catalog_type, - CONF.identity.region, - build_interval=CONF.compute.build_interval, - build_timeout=CONF.compute.build_timeout) - - @classmethod - def generate_message_body(cls, repeat=1): - """Wrapper utility that sets the metadata of a queue.""" - message_ttl = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_message_ttl) - - key = data_utils.arbitrary_string(size=20, base_text='MessagingKey') - value = data_utils.arbitrary_string(size=20, - base_text='MessagingValue') - message_body = {key: value} - - body = ([{'body': message_body, 'ttl': message_ttl}] * repeat) - rbody = {'messages': body} - return rbody - - -class BaseV2MessagingTest(BaseMessagingTest): - """Base class for the Messaging (Zaqar) v2 tests.""" - @classmethod - def setup_clients(cls): - super(BaseV2MessagingTest, cls).setup_clients() - cls.client = messaging_client.V2MessagingClient( - cls.os_primary.auth_provider, - CONF.messaging.catalog_type, - CONF.identity.region, - 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( - queue_name, rbody) - return resp, body - - @classmethod - def delete_subscription(cls, queue_name, subscription_id): - resp, body = cls.client.delete_subscription(queue_name, - subscription_id) - return resp, body - - @classmethod - def list_subscription(cls, queue_name): - resp, body = cls.client.list_subscription(queue_name) - return resp, body - - @classmethod - def show_subscription(cls, queue_name, subscription_id): - resp, body = cls.client.show_subscription(queue_name, subscription_id) - return resp, body - - @classmethod - def update_subscription(cls, queue_name, subscription_id, rbody): - resp, body = cls.client.update_subscription(queue_name, - subscription_id, - rbody) - return resp, body - - @classmethod - def generate_subscription_body(cls): - message_ttl = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_message_ttl) - - key = data_utils.arbitrary_string(size=20, base_text='MessagingKey') - value = data_utils.arbitrary_string(size=20, - base_text='MessagingValue') - option_body = {key: value} - subscribers = ['http://fake:8080', 'https://fake:8080', - 'mailto:fake@123.com'] - rbody = [{'options': option_body, 'ttl': message_ttl, - 'subscriber': subscriber} for subscriber in subscribers] - return rbody - - @classmethod - def generate_message_body(cls, repeat=1): - """Wrapper utility that sets the metadata of a queue.""" - message_ttl = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_message_ttl) - - key = data_utils.arbitrary_string(size=20, base_text='MessagingKey') - value = data_utils.arbitrary_string(size=20, - base_text='MessagingValue') - message_body = {key: value} - - body = ([{'body': message_body, 'ttl': message_ttl}] * repeat) - rbody = {'messages': body} - return rbody diff --git a/zaqar/tests/tempest_plugin/tests/v1/__init__.py b/zaqar/tests/tempest_plugin/tests/v1/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/zaqar/tests/tempest_plugin/tests/v1/test_claims.py b/zaqar/tests/tempest_plugin/tests/v1/test_claims.py deleted file mode 100644 index 6a3499b6a..000000000 --- a/zaqar/tests/tempest_plugin/tests/v1/test_claims.py +++ /dev/null @@ -1,114 +0,0 @@ -# Copyright (c) 2014 Rackspace, 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 six.moves.urllib import parse as urlparse -from tempest import config -from tempest.lib.common.utils import data_utils -from tempest.lib import decorators - -from zaqar.tests.tempest_plugin.tests import base - - -CONF = config.CONF - - -class TestClaims(base.BaseV1MessagingTest): - - @classmethod - def resource_setup(cls): - super(TestClaims, cls).resource_setup() - cls.queue_name = data_utils.rand_name('Queues-Test') - # Create Queue - cls.create_queue(cls.queue_name) - - def _post_and_claim_messages(self, queue_name, repeat=1): - # Post Messages - message_body = self.generate_message_body(repeat=repeat) - self.client.post_messages(queue_name=self.queue_name, - rbody=message_body) - - # Post Claim - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - claim_grace = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_claim_grace) - claim_body = {"ttl": claim_ttl, "grace": claim_grace} - resp, body = self.client.post_claims(queue_name=self.queue_name, - rbody=claim_body) - - return resp, body - - @decorators.idempotent_id('936cb1ca-b7af-44dd-a752-805e8c98156f') - def test_post_claim(self): - _, body = self._post_and_claim_messages(queue_name=self.queue_name) - claimed_message_uri = body[0]['href'] - - # Delete Claimed message - self.client.delete_messages(claimed_message_uri) - - @decorators.idempotent_id('84e491f4-68c6-451f-9846-b8f868eb27c5') - def test_query_claim(self): - # Post a Claim - resp, body = self._post_and_claim_messages(queue_name=self.queue_name) - - # Query Claim - claim_uri = resp['location'][resp['location'].find('/v1'):] - self.client.query_claim(claim_uri) - - # Delete Claimed message - claimed_message_uri = body[0]['href'] - self.delete_messages(claimed_message_uri) - - @decorators.idempotent_id('420ef0c5-9bd6-4b82-b06d-d9da330fefd3') - def test_update_claim(self): - # Post a Claim - resp, body = self._post_and_claim_messages(queue_name=self.queue_name) - - claim_uri = resp['location'][resp['location'].find('/v1'):] - claimed_message_uri = body[0]['href'] - - # Update Claim - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - update_rbody = {"ttl": claim_ttl} - - self.client.update_claim(claim_uri, rbody=update_rbody) - - # Verify claim ttl >= updated ttl value - _, body = self.client.query_claim(claim_uri) - updated_claim_ttl = body["ttl"] - self.assertGreaterEqual(claim_ttl, updated_claim_ttl) - - # Delete Claimed message - self.client.delete_messages(claimed_message_uri) - - @decorators.idempotent_id('fd4c7921-cb3f-4ed8-9ac8-e8f1e74c44aa') - def test_release_claim(self): - # Post a Claim - resp, body = self._post_and_claim_messages(queue_name=self.queue_name) - claim_uri = resp['location'][resp['location'].find('/v1'):] - - # Release Claim - self.client.delete_claim(claim_uri) - - # Delete Claimed message - # This will implicitly verify that the claim is deleted. - message_uri = urlparse.urlparse(claim_uri).path - self.client.delete_messages(message_uri) - - @classmethod - def resource_cleanup(cls): - cls.delete_queue(cls.queue_name) - super(TestClaims, cls).resource_cleanup() diff --git a/zaqar/tests/tempest_plugin/tests/v1/test_messages.py b/zaqar/tests/tempest_plugin/tests/v1/test_messages.py deleted file mode 100644 index 27e6def4a..000000000 --- a/zaqar/tests/tempest_plugin/tests/v1/test_messages.py +++ /dev/null @@ -1,118 +0,0 @@ -# Copyright (c) 2014 Rackspace, 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.tests.tempest_plugin.tests import base - -CONF = config.CONF - - -class TestMessages(base.BaseV1MessagingTest): - - @classmethod - def resource_setup(cls): - super(TestMessages, cls).resource_setup() - cls.queue_name = data_utils.rand_name('Queues-Test') - # Create Queue - cls.client.create_queue(cls.queue_name) - - def _post_messages(self, repeat=CONF.messaging.max_messages_per_page): - message_body = self.generate_message_body(repeat=repeat) - resp, body = self.post_messages(queue_name=self.queue_name, - rbody=message_body) - return resp, body - - @decorators.idempotent_id('93867172-a414-4eb3-a639-96e943c516b4') - def test_post_messages(self): - # Post Messages - resp, _ = self._post_messages() - - # Get on the posted messages - message_uri = resp['location'][resp['location'].find('/v1'):] - resp, _ = self.client.show_multiple_messages(message_uri) - # The test has an assertion here, because the response cannot be 204 - # in this case (the client allows 200 or 204 for this API call). - self.assertEqual('200', resp['status']) - - @decorators.idempotent_id('c967d59a-e919-41cb-994b-1c4300452c80') - def test_list_messages(self): - # Post Messages - self._post_messages() - - # List Messages - resp, _ = self.list_messages(queue_name=self.queue_name) - # The test has an assertion here, because the response cannot be 204 - # in this case (the client allows 200 or 204 for this API call). - self.assertEqual('200', resp['status']) - - @decorators.idempotent_id('2a68e3de-24df-47c3-9039-ec4156656bf8') - def test_get_message(self): - # Post Messages - _, body = self._post_messages() - message_uri = body['resources'][0] - - # Get posted message - resp, _ = self.client.show_single_message(message_uri) - # The test has an assertion here, because the response cannot be 204 - # in this case (the client allows 200 or 204 for this API call). - self.assertEqual('200', resp['status']) - - @decorators.idempotent_id('c4b0a30b-efda-4b87-a395-0c43140df74d') - def test_get_multiple_messages(self): - # Post Messages - resp, _ = self._post_messages() - message_uri = resp['location'][resp['location'].find('/v1'):] - - # Get posted messages - resp, _ = self.client.show_multiple_messages(message_uri) - # The test has an assertion here, because the response cannot be 204 - # in this case (the client allows 200 or 204 for this API call). - self.assertEqual('200', resp['status']) - - @decorators.idempotent_id('fc0fca47-dd8b-4ecc-8522-d9c191f9bc9f') - def test_delete_single_message(self): - # Post Messages - _, body = self._post_messages() - message_uri = body['resources'][0] - - # Delete posted message & verify the delete operration - self.client.delete_messages(message_uri) - - message_uri = message_uri.replace('/messages/', '/messages?ids=') - resp, _ = self.client.show_multiple_messages(message_uri) - # The test has an assertion here, because the response has to be 204 - # in this case (the client allows 200 or 204 for this API call). - self.assertEqual('204', resp['status']) - - @decorators.idempotent_id('00cca069-5c8f-4b42-bff1-c577da2a4546') - def test_delete_multiple_messages(self): - # Post Messages - resp, _ = self._post_messages() - message_uri = resp['location'][resp['location'].find('/v1'):] - - # Delete multiple messages - self.client.delete_messages(message_uri) - resp, _ = self.client.show_multiple_messages(message_uri) - # The test has an assertion here, because the response has to be 204 - # in this case (the client allows 200 or 204 for this API call). - self.assertEqual('204', resp['status']) - - @classmethod - def resource_cleanup(cls): - cls.delete_queue(cls.queue_name) - super(TestMessages, cls).resource_cleanup() diff --git a/zaqar/tests/tempest_plugin/tests/v1/test_queues.py b/zaqar/tests/tempest_plugin/tests/v1/test_queues.py deleted file mode 100644 index afda1b35f..000000000 --- a/zaqar/tests/tempest_plugin/tests/v1/test_queues.py +++ /dev/null @@ -1,118 +0,0 @@ -# Copyright (c) 2014 Rackspace, 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 six import moves -from tempest.lib.common.utils import data_utils -from tempest.lib import decorators -from tempest.lib import exceptions as lib_exc -from testtools import matchers - -from zaqar.tests.tempest_plugin.tests import base - - -class TestQueues(base.BaseV1MessagingTest): - - @decorators.idempotent_id('9f1c4c72-80c5-4dac-acf3-188cef42e36c') - 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('', body) - - self.delete_queue(queue_name) - self.assertRaises(lib_exc.NotFound, - self.client.show_queue, - queue_name) - - -class TestManageQueue(base.BaseV1MessagingTest): - - @classmethod - def resource_setup(cls): - super(TestManageQueue, cls).resource_setup() - cls.queues = list() - for _ in moves.xrange(5): - queue_name = data_utils.rand_name('Queues-Test') - cls.queues.append(queue_name) - # Create Queue - cls.client.create_queue(queue_name) - - @decorators.idempotent_id('ccd3d69e-f156-4c5f-8a12-b4f24bee44e1') - def test_check_queue_existence(self): - # Checking Queue Existence - for queue_name in self.queues: - self.check_queue_exists(queue_name) - - @decorators.idempotent_id('e27634d8-9c8f-47d8-a677-655c47658d3e') - def test_check_queue_head(self): - # Checking Queue Existence by calling HEAD - for queue_name in self.queues: - self.check_queue_exists_head(queue_name) - - @decorators.idempotent_id('0a0feeca-7768-4303-806d-82bbbb796ad3') - 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('8fb66602-077d-49d6-ae1a-5f2091739178') - 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('0e2441e6-6593-4bdb-a3c0-20e66eeb3fff') - def test_set_and_get_queue_metadata(self): - # Retrieve random queue - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - # Check the Queue has no metadata - _, body = self.get_queue_metadata(queue_name) - self.assertThat(body, matchers.HasLength(0)) - # Create metadata - key3 = [0, 1, 2, 3, 4] - key2 = data_utils.rand_name('value') - req_body1 = dict() - req_body1[data_utils.rand_name('key3')] = key3 - req_body1[data_utils.rand_name('key2')] = key2 - req_body = dict() - req_body[data_utils.rand_name('key1')] = req_body1 - # Set Queue Metadata - self.set_queue_metadata(queue_name, req_body) - - # Get Queue Metadata - _, body = self.get_queue_metadata(queue_name) - self.assertThat(body, matchers.Equals(req_body)) - - @classmethod - def resource_cleanup(cls): - for queue_name in cls.queues: - cls.client.delete_queue(queue_name) - super(TestManageQueue, cls).resource_cleanup() diff --git a/zaqar/tests/tempest_plugin/tests/v1_1/__init__.py b/zaqar/tests/tempest_plugin/tests/v1_1/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/zaqar/tests/tempest_plugin/tests/v1_1/test_claims.py b/zaqar/tests/tempest_plugin/tests/v1_1/test_claims.py deleted file mode 100644 index fde4fbc9f..000000000 --- a/zaqar/tests/tempest_plugin/tests/v1_1/test_claims.py +++ /dev/null @@ -1,114 +0,0 @@ -# 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 six.moves.urllib import parse as urlparse -from tempest import config -from tempest.lib.common.utils import data_utils -from tempest.lib import decorators - -from zaqar.tests.tempest_plugin.tests import base - - -CONF = config.CONF - - -class TestClaims(base.BaseV11MessagingTest): - - @classmethod - def resource_setup(cls): - super(TestClaims, cls).resource_setup() - cls.queue_name = data_utils.rand_name('Queues-Test') - # Create Queue - cls.create_queue(cls.queue_name) - - def _post_and_claim_messages(self, queue_name, repeat=1): - # Post Messages - message_body = self.generate_message_body(repeat=repeat) - self.client.post_messages(queue_name=self.queue_name, - rbody=message_body) - - # Post Claim - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - claim_grace = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_claim_grace) - claim_body = {"ttl": claim_ttl, "grace": claim_grace} - resp, body = self.client.post_claims(queue_name=self.queue_name, - rbody=claim_body) - - return resp, body - - @decorators.idempotent_id('6fc4b79d-2366-4911-b0be-6446a1f02aea') - def test_post_claim(self): - _, body = self._post_and_claim_messages(queue_name=self.queue_name) - claimed_message_uri = body['messages'][0]['href'] - - # Delete Claimed message - self.client.delete_messages(claimed_message_uri) - - @decorators.idempotent_id('c61829f9-104a-4860-a136-6af2a89f3eef') - def test_query_claim(self): - # Post a Claim - resp, body = self._post_and_claim_messages(queue_name=self.queue_name) - - # Query Claim - claim_uri = resp['location'][resp['location'].find('/v1.1'):] - self.client.query_claim(claim_uri) - - # Delete Claimed message - claimed_message_uri = body['messages'][0]['href'] - self.delete_messages(claimed_message_uri) - - @decorators.idempotent_id('57b9d065-1995-420f-9173-4d716339e3b9') - def test_update_claim(self): - # Post a Claim - resp, body = self._post_and_claim_messages(queue_name=self.queue_name) - - claim_uri = resp['location'][resp['location'].find('/v1.1'):] - claimed_message_uri = body['messages'][0]['href'] - - # Update Claim - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - update_rbody = {"ttl": claim_ttl} - - self.client.update_claim(claim_uri, rbody=update_rbody) - - # Verify claim ttl >= updated ttl value - _, body = self.client.query_claim(claim_uri) - updated_claim_ttl = body["ttl"] - self.assertGreaterEqual(claim_ttl, updated_claim_ttl) - - # Delete Claimed message - self.client.delete_messages(claimed_message_uri) - - @decorators.idempotent_id('71081c25-3eb4-427a-b2f3-891d0c5f7d32') - def test_release_claim(self): - # Post a Claim - resp, body = self._post_and_claim_messages(queue_name=self.queue_name) - claim_uri = resp['location'][resp['location'].find('/v1.1'):] - - # Release Claim - self.client.delete_claim(claim_uri) - - # Delete Claimed message - # This will implicitly verify that the claim is deleted. - message_uri = urlparse.urlparse(claim_uri).path - self.client.delete_messages(message_uri) - - @classmethod - def resource_cleanup(cls): - cls.delete_queue(cls.queue_name) - super(TestClaims, cls).resource_cleanup() diff --git a/zaqar/tests/tempest_plugin/tests/v1_1/test_messages.py b/zaqar/tests/tempest_plugin/tests/v1_1/test_messages.py deleted file mode 100644 index 8d039d58a..000000000 --- a/zaqar/tests/tempest_plugin/tests/v1_1/test_messages.py +++ /dev/null @@ -1,121 +0,0 @@ -# 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 tempest.lib import exceptions as lib_exc - -from zaqar.tests.tempest_plugin.tests import base - -CONF = config.CONF - - -class TestMessages(base.BaseV11MessagingTest): - - @classmethod - def resource_setup(cls): - super(TestMessages, cls).resource_setup() - cls.queue_name = data_utils.rand_name('Queues-Test') - # Create Queue - cls.client.create_queue(cls.queue_name) - - def _post_messages(self, repeat=CONF.messaging.max_messages_per_page): - message_body = self.generate_message_body(repeat=repeat) - resp, body = self.post_messages(queue_name=self.queue_name, - rbody=message_body) - return resp, body - - @decorators.idempotent_id('7e506151-6870-404b-b746-801a72599418') - def test_post_messages(self): - # Post Messages - resp, _ = self._post_messages() - - # Get on the posted messages - message_uri = resp['location'][resp['location'].find('/v1.1'):] - resp, _ = self.client.show_multiple_messages(message_uri) - # The test has an assertion here, because the response cannot be 204 - # in this case (the client allows 200 or 204 for this API call). - self.assertEqual('200', resp['status']) - - @decorators.idempotent_id('d50ae94e-5f84-4e2d-bda4-48d8ab3ee3af') - def test_list_messages(self): - # Post Messages - self._post_messages() - - # List Messages - resp, _ = self.list_messages(queue_name=self.queue_name) - # The test has an assertion here, because the response cannot be 204 - # in this case (the client allows 200 or 204 for this API call). - self.assertEqual('200', resp['status']) - - @decorators.idempotent_id('a679d6be-f2ef-4649-b03c-710c72126b2f') - def test_get_message(self): - # Post Messages - _, body = self._post_messages() - message_uri = body['resources'][0] - - # Get posted message - resp, _ = self.client.show_single_message(message_uri) - # The test has an assertion here, because the response cannot be 204 - # in this case (the client allows 200 or 204 for this API call). - self.assertEqual('200', resp['status']) - - @decorators.idempotent_id('889e7263-2d0c-4de1-aebd-d192157e347d') - def test_get_multiple_messages(self): - # Post Messages - resp, _ = self._post_messages() - message_uri = resp['location'][resp['location'].find('/v1.1'):] - - # Get posted messages - resp, _ = self.client.show_multiple_messages(message_uri) - # The test has an assertion here, because the response cannot be 204 - # in this case (the client allows 200 or 204 for this API call). - self.assertEqual('200', resp['status']) - - @decorators.idempotent_id('9a932955-933e-4283-86d0-85dd121c2edf') - def test_delete_single_message(self): - # Post Messages - _, body = self._post_messages() - message_uri = body['resources'][0] - - # Delete posted message & verify the delete operration - self.client.delete_messages(message_uri) - - message_uri = message_uri.replace('/messages/', '/messages?ids=') - # The test has an assertion here, because the response has to be 404 - # in this case(different from v1). - self.assertRaises(lib_exc.NotFound, - self.client.show_multiple_messages, - message_uri) - - @decorators.idempotent_id('ad1949a7-36c0-45be-8020-df91467d0bbb') - def test_delete_multiple_messages(self): - # Post Messages - resp, _ = self._post_messages() - message_uri = resp['location'][resp['location'].find('/v1.1'):] - - # Delete multiple messages - self.client.delete_messages(message_uri) - # The test has an assertion here, because the response has to be 404 - # in this case(different from v1). - self.assertRaises(lib_exc.NotFound, - self.client.show_multiple_messages, - message_uri) - - @classmethod - def resource_cleanup(cls): - cls.delete_queue(cls.queue_name) - super(TestMessages, cls).resource_cleanup() diff --git a/zaqar/tests/tempest_plugin/tests/v1_1/test_queues.py b/zaqar/tests/tempest_plugin/tests/v1_1/test_queues.py deleted file mode 100644 index 27f715230..000000000 --- a/zaqar/tests/tempest_plugin/tests/v1_1/test_queues.py +++ /dev/null @@ -1,80 +0,0 @@ -# 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 six import moves -from tempest.lib.common.utils import data_utils -from tempest.lib import decorators - -from zaqar.tests.tempest_plugin.tests import base - - -class TestQueues(base.BaseV11MessagingTest): - - @decorators.idempotent_id('16a8a53e-e9f0-4c84-bc74-4e4e89abae75') - 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('', body) - - self.delete_queue(queue_name) - # lazy queue - self.client.show_queue(queue_name) - - -class TestManageQueue(base.BaseV11MessagingTest): - - @classmethod - def resource_setup(cls): - super(TestManageQueue, cls).resource_setup() - cls.queues = list() - for _ in moves.xrange(5): - queue_name = data_utils.rand_name('Queues-Test') - cls.queues.append(queue_name) - # Create Queue - cls.client.create_queue(queue_name) - - @decorators.idempotent_id('a27e9c2f-66ba-400e-b175-7b2e3f0f2ef9') - 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('fe1a0655-08f9-4366-b1c6-b4bc4d30396b') - 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) - - @classmethod - def resource_cleanup(cls): - for queue_name in cls.queues: - cls.client.delete_queue(queue_name) - super(TestManageQueue, cls).resource_cleanup() diff --git a/zaqar/tests/tempest_plugin/tests/v2/__init__.py b/zaqar/tests/tempest_plugin/tests/v2/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/zaqar/tests/tempest_plugin/tests/v2/test_claims.py b/zaqar/tests/tempest_plugin/tests/v2/test_claims.py deleted file mode 100644 index 422b94fa1..000000000 --- a/zaqar/tests/tempest_plugin/tests/v2/test_claims.py +++ /dev/null @@ -1,154 +0,0 @@ -# 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. - -import time - -from six.moves.urllib import parse as urlparse -from tempest import config -from tempest.lib.common.utils import data_utils -from tempest.lib import decorators - -from zaqar.tests.tempest_plugin.tests import base - - -CONF = config.CONF - - -class TestClaims(base.BaseV2MessagingTest): - - @classmethod - def resource_setup(cls): - super(TestClaims, cls).resource_setup() - cls.queue_name = data_utils.rand_name('Queues-Test') - # Create Queue - cls.create_queue(cls.queue_name) - - def _post_and_claim_messages(self, queue_name, repeat=1): - # Post Messages - message_body = self.generate_message_body(repeat=repeat) - self.client.post_messages(queue_name=self.queue_name, - rbody=message_body) - - # Post Claim - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - claim_grace = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_claim_grace) - claim_body = {"ttl": claim_ttl, "grace": claim_grace} - resp, body = self.client.post_claims(queue_name=self.queue_name, - rbody=claim_body) - - return resp, body - - @decorators.idempotent_id('3b839cac-d214-4fca-8c03-b8edbdcecb20') - def test_post_claim(self): - _, body = self._post_and_claim_messages(queue_name=self.queue_name) - claimed_message_uri = body['messages'][0]['href'] - - # Delete Claimed message - self.client.delete_messages(claimed_message_uri) - - @decorators.idempotent_id('e69d047c-b3f4-4216-990e-7953407084b7') - def test_query_claim(self): - # Post a Claim - resp, body = self._post_and_claim_messages(queue_name=self.queue_name) - - # Query Claim - claim_uri = resp['location'][resp['location'].find('/v2'):] - self.client.query_claim(claim_uri) - - # Delete Claimed message - claimed_message_uri = body['messages'][0]['href'] - self.delete_messages(claimed_message_uri) - - @decorators.idempotent_id('5e1e7559-77fc-4ea8-a817-cd43be23d692') - def test_update_claim(self): - # Post a Claim - resp, body = self._post_and_claim_messages(queue_name=self.queue_name) - - claim_uri = resp['location'][resp['location'].find('/v2'):] - claimed_message_uri = body['messages'][0]['href'] - - # Update Claim - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - update_rbody = {"ttl": claim_ttl} - - self.client.update_claim(claim_uri, rbody=update_rbody) - - # Verify claim ttl >= updated ttl value - _, body = self.client.query_claim(claim_uri) - updated_claim_ttl = body["ttl"] - self.assertGreaterEqual(claim_ttl, updated_claim_ttl) - - # Delete Claimed message - self.client.delete_messages(claimed_message_uri) - - @decorators.idempotent_id('97c1ebcc-9d1e-463a-8673-6ec989ba3be7') - def test_release_claim(self): - # Post a Claim - resp, body = self._post_and_claim_messages(queue_name=self.queue_name) - claim_uri = resp['location'][resp['location'].find('/v2'):] - - # Release Claim - self.client.delete_claim(claim_uri) - - # Delete Claimed message - # This will implicitly verify that the claim is deleted. - message_uri = urlparse.urlparse(claim_uri).path - self.client.delete_messages(message_uri) - - @decorators.idempotent_id('c1975970-66e7-11e7-a771-fa163e40e1ff') - def test_dead_letter_queue(self): - # Post Messages - QueueName = "QueueWithDLQ" - DLQ_name = "DLQ" - meta = {'ttl': 60, 'grace': 60} - # Set dead letter queeu metadata - op1 = {"op": "add", - "path": "/metadata/_max_claim_count", "value": 2} - op2 = {"op": "add", - "path": "/metadata/_dead_letter_queue", "value": DLQ_name} - op3 = {"op": "add", - "path": "/metadata/_dead_letter_queue_messages_ttl", - "value": 7799} - metadata = [op1, op2, op3] - self.client.create_queue(QueueName) - self.client.create_queue(DLQ_name) - self.set_queue_metadata(QueueName, metadata) - message_body = self.generate_message_body(repeat=1) - self.client.post_messages(queue_name=QueueName, - rbody=message_body) - - for i in range(3): - resp, body = self.client.post_claims( - queue_name=QueueName, - rbody=meta) - if(i == 2): - self.assertEqual('204', resp['status']) - else: - self.assertEqual('201', resp['status']) - self.assertEqual(1, len(body["messages"])) - time.sleep(70) - - resp, body = self.client.list_messages(DLQ_name) - self.assertEqual('200', resp['status']) - self.client.delete_queue(DLQ_name) - self.client.delete_queue(QueueName) - - @classmethod - def resource_cleanup(cls): - cls.delete_queue(cls.queue_name) - super(TestClaims, cls).resource_cleanup() diff --git a/zaqar/tests/tempest_plugin/tests/v2/test_claims_negative.py b/zaqar/tests/tempest_plugin/tests/v2/test_claims_negative.py deleted file mode 100644 index 6f51f6a44..000000000 --- a/zaqar/tests/tempest_plugin/tests/v2/test_claims_negative.py +++ /dev/null @@ -1,416 +0,0 @@ -# Copyright (c) 2016 LARSEN & TOUBRO LIMITED. All rights reserved. -# -# 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 oslo_utils import uuidutils - -from tempest import config -from tempest.lib.common.utils import data_utils -from tempest.lib import decorators -from tempest.lib import exceptions as lib_exc - -from zaqar.tests.tempest_plugin.tests import base - -CONF = config.CONF - - -class TestClaimsNegative(base.BaseV2MessagingTest): - - @classmethod - def resource_setup(cls): - super(TestClaimsNegative, cls).resource_setup() - cls.queue_name = data_utils.rand_name('Queues-Test') - # Create Queue - cls.create_queue(cls.queue_name) - - def _post_and_claim_messages(self, queue_name, repeat=1): - # Post Messages - message_body = self.generate_message_body(repeat=repeat) - self.client.post_messages(queue_name=self.queue_name, - rbody=message_body) - - # Post Claim - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - claim_grace = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_claim_grace) - claim_body = {"ttl": claim_ttl, "grace": claim_grace} - resp, body = self.client.post_claims(queue_name=self.queue_name, - rbody=claim_body) - return resp, body - - # Claim Messages - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('bd524990-7dff-4950-a82b-554ef1d644b6') - def test_request_claim_message_with_no_request_body(self): - # Claim a message with no request body - body = self.generate_message_body() - self.client.post_messages(self.queue_name, body) - - claim_body = {} - resp, _ = self.client.post_claims(self.queue_name, - claim_body) - self.assertEqual('201', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('21de9b01-00a7-406a-a2e7-86ecfea2f21a') - def test_request_claim_message_with_invalid_character_request_body(self): - # Claim a message with invalid characters as request body - body = self.generate_message_body() - self.client.post_messages(self.queue_name, body) - - claim_body = '[' - self.assertRaises(lib_exc.BadRequest, - self.client.post_claims, self.queue_name, - claim_body) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('5149cf66-0273-438c-b9de-f8c4af56f382') - def test_request_claim_message_with_invalid_request_body(self): - # Claim a message with invalid request body - body = self.generate_message_body() - self.client.post_messages(self.queue_name, body) - - claim_body = '"Try"' - self.assertRaises(lib_exc.BadRequest, - self.client.post_claims, self.queue_name, - claim_body) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('9537b022-659e-4220-a05d-eabc10661772') - def test_request_claim_message_with_greater_value_for_limit(self): - # Claim messages with a greater limit value - message_body = self.generate_message_body(repeat=1) - self.client.post_messages(queue_name=self.queue_name, - rbody=message_body) - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - claim_grace = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_claim_grace) - claim_body = {"ttl": claim_ttl, "grace": claim_grace} - params = {'limit': 200} - self.assertRaises(lib_exc.BadRequest, - self.client.post_claims, self.queue_name, - claim_body, url_params=params) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('b9160f04-31f0-4246-b879-329b806a0d8a') - def test_request_claim_message_with_lesser_value_for_limit(self): - # Claim messages with an invalid lesser value - message_body = self.generate_message_body(repeat=1) - _, body = self.client.post_messages(queue_name=self.queue_name, - rbody=message_body) - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - claim_grace = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_claim_grace) - claim_body = {"ttl": claim_ttl, "grace": claim_grace} - params = {'limit': 0} - self.assertRaises(lib_exc.BadRequest, - self.client.post_claims, self.queue_name, - claim_body, url_params=params) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('5dfa2fa4-ca17-46f3-9a28-8e70fbbd7f9e') - def test_request_claim_message_with_negative_value_for_limit(self): - # Claim messages with a negative value of limit - message_body = self.generate_message_body(repeat=1) - _, body = self.client.post_messages(queue_name=self.queue_name, - rbody=message_body) - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - claim_grace = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_claim_grace) - claim_body = {"ttl": claim_ttl, "grace": claim_grace} - - params = {'limit': -1} - self.assertRaises(lib_exc.BadRequest, - self.client.post_claims, self.queue_name, - claim_body, url_params=params) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('eb8025bb-0f42-42fd-9905-6376bdc74cf4') - def test_request_claim_message_with_no_TTL_field(self): - # Claim a message with no TTL field - body = self.generate_message_body() - self.client.post_messages(self.queue_name, body) - - claim_grace = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_claim_grace) - claim_body = {"grace": claim_grace} - resp, _ = self.client.post_claims(self.queue_name, - claim_body) - self.assertEqual('201', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('6b99cab8-17f0-4ec5-bb6a-9ad490a0eb7a') - def test_request_claim_message_with_greater_invalid_TTL_value(self): - # TTL for a claim may not exceed 1209600 seconds, - # and must be at least 60 seconds long , configurable - body = self.generate_message_body() - self.client.post_messages(self.queue_name, body) - claim_ttl = data_utils.rand_int_id(start=43201, - end=43500) - claim_grace = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_claim_grace) - claim_body = {"ttl": claim_ttl, "grace": claim_grace} - self.assertRaises(lib_exc.BadRequest, - self.client.post_claims, self.queue_name, claim_body) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('3d65af6e-b104-40a6-a15c-1cf65358e687') - def test_request_claim_message_with_lesser_invalid_TTL_value(self): - # TTL for a claim may not exceed 1209600 seconds, - # and must be at least 60 seconds long , configurable - body = self.generate_message_body() - self.client.post_messages(self.queue_name, body) - claim_ttl = data_utils.rand_int_id(start=-43500, - end=0) - claim_grace = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_claim_grace) - claim_body = {"ttl": claim_ttl, "grace": claim_grace} - self.assertRaises(lib_exc.BadRequest, - self.client.post_claims, self.queue_name, claim_body) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('86978d35-65be-44bb-aba4-0610728b5399') - def test_request_claim_message_with_no_grace_field(self): - # Grace for a claim may not exceed 1209600 seconds, - # and must be at least 60 seconds long , configurable - body = self.generate_message_body() - self.client.post_messages(self.queue_name, body) - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - claim_body = {"ttl": claim_ttl} - resp, _ = self.client.post_claims(self.queue_name, - claim_body) - self.assertEqual('201', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('812d9092-2d59-4dae-b67d-ce00da3f74f9') - def test_request_claim_message_with_invalid_greater_grace_value(self): - # Grace for a claim may not exceed 1209600 seconds, - # and must be at least 60 seconds long , configurable - body = self.generate_message_body() - self.client.post_messages(self.queue_name, body) - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - claim_grace = data_utils.\ - rand_int_id(start=43201, end=43501) - claim_body = {"ttl": claim_ttl, "grace": claim_grace} - self.assertRaises(lib_exc.BadRequest, - self.client.post_claims, self.queue_name, claim_body) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('bf10b08c-e254-49e4-a751-a0e128dce618') - def test_request_claim_message_with_invalid_lesser_grace_value(self): - # Grace for a claim may not exceed 1209600 seconds, - # and must be at least 60 seconds long , configurable - body = self.generate_message_body() - self.client.post_messages(self.queue_name, body) - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - claim_grace = data_utils.\ - rand_int_id(start=-43201, end=0) - claim_body = {"ttl": claim_ttl, "grace": claim_grace} - self.assertRaises(lib_exc.BadRequest, - self.client.post_claims, self.queue_name, claim_body) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('69b0d11a-40f5-4f35-847f-05f92ffadeb3') - def test_request_claim_message_with_non_JSON_request_body(self): - # Claim a messsage with an invalid JSON - body = self.generate_message_body() - self.client.post_messages(self.queue_name, body) - claim_body = "123" - self.assertRaises(lib_exc.BadRequest, - self.client.post_claims, self.queue_name, claim_body) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('d145ea04-203d-41f9-a893-f6e5716005b6') - def test_request_claim_message_with_invalid_url_params(self): - # Post Messages - message_body = self.generate_message_body(repeat=1) - _, body = self.client.post_messages(queue_name=self.queue_name, - rbody=message_body) - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - claim_grace = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_claim_grace) - claim_body = {"ttl": claim_ttl, "grace": claim_grace} - params = {'Invalid': 'ImAnInvalidParam'} - resp, _ = self.client.post_claims(self.queue_name, - claim_body, url_params=params) - self.assertEqual('201', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('dbdf17ce-879f-4688-b71c-260cb9e4c4ab') - def test_claim_message_with_invalid_token(self): - # Claim a message without a valid token - body = self.generate_message_body() - self.client.post_messages(self.queue_name, body) - - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - claim_grace = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_claim_grace) - claim_body = {"ttl": claim_ttl, "grace": claim_grace} - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None - ) - self.assertRaises(lib_exc.Unauthorized, - self.client.post_claims, self.queue_name, claim_body) - - # Query Claim - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('a1844a12-62d6-435e-906b-6b6ae538834f') - def test_query_from_a_nonexistent_queue(self): - # Query claim a non existent queue - non_existent_queue = data_utils.rand_name('rand_queuename') - non_existent_id = uuidutils.generate_uuid() - uri = "/v2/queues/{0}/claims/{1}".format(non_existent_queue, - non_existent_id) - self.assertRaises(lib_exc.NotFound, - self.client.query_claim, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('a2af8e9b-08fb-4079-a77a-28c0390a614a') - def test_query_claim_with_non_existing_claim_id(self): - # Query claim using a non existing claim id - non_existent_id = uuidutils.generate_uuid() - uri = "/v2/queues/{0}/claims/{1}".format(self.queue_name, - non_existent_id) - self.assertRaises(lib_exc.NotFound, - self.client.query_claim, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('a58c5214-68b9-47d6-a036-de73e7b2cdad') - def test_query_claim_with_invalid_token(self): - # Query claim with an invalid token - resp, body = self._post_and_claim_messages(queue_name=self.queue_name) - claim_uri = resp['location'][resp['location'].find('/v2'):] - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None - ) - self.assertRaises(lib_exc.Unauthorized, - self.client.query_claim, claim_uri) - - # Update Claim - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('28915079-8b20-487d-ab01-64218572c543') - def test_update_claim_on_non_existing_queue(self): - # Update claim on a non existing queue - resp, body = self._post_and_claim_messages(queue_name=self.queue_name) - self.client.delete_queue(self.queue_name) - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - update_rbody = {"ttl": claim_ttl} - claim_uri = resp['location'][resp['location'].find('/v2'):] - self.assertRaises(lib_exc.NotFound, - self.client.update_claim, claim_uri, update_rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('732e9ca6-6e4f-4d66-9e78-200c3d6aca88') - def test_update_a_non_existing_claim(self): - # Update a non existing claim - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - update_rbody = {"ttl": claim_ttl} - claim_id = uuidutils.generate_uuid() - claim_uri = "/v2/queues/{0}/claims/{1}".format(self.queue_name, - claim_id) - self.assertRaises(lib_exc.NotFound, - self.client.update_claim, claim_uri, update_rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('925514e9-57f0-4209-a64e-8b0a72bb8f0f') - def test_update_claim_with_no_request_body(self): - # Update claim with no request body - resp, body = self._post_and_claim_messages(self.queue_name) - update_rbody = {} - claim_uri = resp['location'][resp['location'].find('/v2'):] - resp, body = self.client.update_claim(claim_uri, update_rbody) - self.assertEqual('204', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('c17793da-112a-4e90-b2fd-a5acbfdcddc5') - def test_update_claim_with_invalid_json_in_request_body(self): - # Update claim with an invalid JSON - resp, body = self._post_and_claim_messages(self.queue_name) - update_rbody = {"123"} - claim_uri = resp['location'][resp['location'].find('/v2'):] - self.assertRaises(lib_exc.BadRequest, - self.client.update_claim, claim_uri, update_rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('1cd2fed7-6840-49cd-9b7a-1d80c01300fb') - def test_update_claim_with_invalid_token(self): - # Update claim without a valid token - resp, body = self._post_and_claim_messages(self.queue_name) - claim_uri = resp['location'][resp['location'].find('/v2'):] - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - update_rbody = {"ttl": claim_ttl} - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None - ) - self.assertRaises(lib_exc.Unauthorized, - self.client.update_claim, claim_uri, update_rbody) - - # Release Claim - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('b61a0d09-bc47-4b33-aa6d-7f20cbbe9bd2') - def test_release_claim_from_a_non_existing_queue(self): - # Release claim from a non existing queue - non_existent_queue = data_utils.rand_name('rand_queuename') - non_existent_id = uuidutils.generate_uuid() - uri = "/v2/queues/{0}/claims/{1}".format(non_existent_queue, - non_existent_id) - resp, body = self.client.delete_claim(uri) - self.assertEqual('204', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('20a6e6ed-0f53-484d-aa78-717cdaa25e50') - def test_release_a_nonexisting_claim_id(self): - # Release a non existing claim - non_existent_id = uuidutils.generate_uuid() - uri = "/v2/queues/{0}/claims/{1}".format(self.queue_name, - non_existent_id) - resp, body = self.client.delete_claim(uri) - self.assertEqual('204', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('082d50ca-bd3e-4d66-a92b-6ff917ab3b21') - def test_release_claim_with_invalid_token(self): - # Release claim without a valid token - resp, body = self._post_and_claim_messages(queue_name=self.queue_name) - claim_uri = resp['location'][resp['location'].find('/v2'):] - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None - ) - self.assertRaises(lib_exc.Unauthorized, - self.client.delete_claim, claim_uri) - - @classmethod - def resource_cleanup(cls): - cls.delete_queue(cls.queue_name) - super(TestClaimsNegative, cls).resource_cleanup() diff --git a/zaqar/tests/tempest_plugin/tests/v2/test_messages.py b/zaqar/tests/tempest_plugin/tests/v2/test_messages.py deleted file mode 100644 index fe322e323..000000000 --- a/zaqar/tests/tempest_plugin/tests/v2/test_messages.py +++ /dev/null @@ -1,121 +0,0 @@ -# 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 tempest.lib import exceptions as lib_exc - -from zaqar.tests.tempest_plugin.tests import base - -CONF = config.CONF - - -class TestMessages(base.BaseV2MessagingTest): - - @classmethod - def resource_setup(cls): - super(TestMessages, cls).resource_setup() - cls.queue_name = data_utils.rand_name('Queues-Test') - # Create Queue - cls.client.create_queue(cls.queue_name) - - def _post_messages(self, repeat=CONF.messaging.max_messages_per_page): - message_body = self.generate_message_body(repeat=repeat) - resp, body = self.post_messages(queue_name=self.queue_name, - rbody=message_body) - return resp, body - - @decorators.idempotent_id('2e1a26c1-6d7b-4ae7-b510-d8e2abe9d831') - def test_post_messages(self): - # Post Messages - resp, _ = self._post_messages() - - # Get on the posted messages - message_uri = resp['location'][resp['location'].find('/v2'):] - resp, _ = self.client.show_multiple_messages(message_uri) - # The test has an assertion here, because the response cannot be 204 - # in this case (the client allows 200 or 204 for this API call). - self.assertEqual('200', resp['status']) - - @decorators.idempotent_id('f38cca63-55d7-41e7-8ff9-7254e9859aa7') - def test_list_messages(self): - # Post Messages - self._post_messages() - - # List Messages - resp, _ = self.list_messages(queue_name=self.queue_name) - # The test has an assertion here, because the response cannot be 204 - # in this case (the client allows 200 or 204 for this API call). - self.assertEqual('200', resp['status']) - - @decorators.idempotent_id('f9719398-8bb7-4660-acb6-ef87c47d726c') - def test_get_message(self): - # Post Messages - _, body = self._post_messages() - message_uri = body['resources'][0] - - # Get posted message - resp, _ = self.client.show_single_message(message_uri) - # The test has an assertion here, because the response cannot be 204 - # in this case (the client allows 200 or 204 for this API call). - self.assertEqual('200', resp['status']) - - @decorators.idempotent_id('a8fe2c0f-c3f2-4278-8bd9-2fca94356f2e') - def test_get_multiple_messages(self): - # Post Messages - resp, _ = self._post_messages() - message_uri = resp['location'][resp['location'].find('/v2'):] - - # Get posted messages - resp, _ = self.client.show_multiple_messages(message_uri) - # The test has an assertion here, because the response cannot be 204 - # in this case (the client allows 200 or 204 for this API call). - self.assertEqual('200', resp['status']) - - @decorators.idempotent_id('9654fb55-8cbd-4997-8c3e-8d388276a8d9') - def test_delete_single_message(self): - # Post Messages - _, body = self._post_messages() - message_uri = body['resources'][0] - - # Delete posted message & verify the delete operration - self.client.delete_messages(message_uri) - - message_uri = message_uri.replace('/messages/', '/messages?ids=') - # The test has an assertion here, because the response has to be 404 - # in this case(different from v1). - self.assertRaises(lib_exc.NotFound, - self.client.show_multiple_messages, - message_uri) - - @decorators.idempotent_id('e025555a-fa3f-4558-859a-42d69ccf66a6') - def test_delete_multiple_messages(self): - # Post Messages - resp, _ = self._post_messages() - message_uri = resp['location'][resp['location'].find('/v2'):] - - # Delete multiple messages - self.client.delete_messages(message_uri) - # The test has an assertion here, because the response has to be 404 - # in this case(different from v1). - self.assertRaises(lib_exc.NotFound, - self.client.show_multiple_messages, - message_uri) - - @classmethod - def resource_cleanup(cls): - cls.delete_queue(cls.queue_name) - super(TestMessages, cls).resource_cleanup() diff --git a/zaqar/tests/tempest_plugin/tests/v2/test_messages_negative.py b/zaqar/tests/tempest_plugin/tests/v2/test_messages_negative.py deleted file mode 100644 index a40aa01cb..000000000 --- a/zaqar/tests/tempest_plugin/tests/v2/test_messages_negative.py +++ /dev/null @@ -1,646 +0,0 @@ -# Copyright (c) 2016 LARSEN & TOUBRO LIMITED. All rights reserved. -# -# 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. - -import random - -from oslo_utils import uuidutils -from six import moves -from tempest import config -from tempest.lib.common.utils import data_utils -from tempest.lib import decorators -from tempest.lib import exceptions as lib_exc - -from zaqar.tests.tempest_plugin.tests import base - -CONF = config.CONF - - -class TestMessagesNegative(base.BaseV2MessagingTest): - - @classmethod - def resource_setup(cls): - super(TestMessagesNegative, cls).resource_setup() - cls.queues = list() - for _ in moves.xrange(1): - queue_name = data_utils.rand_name('Queues-Test') - cls.queues.append(queue_name) - # Create Queue - cls.client.create_queue(queue_name) - - # Get specific Message - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('8246ee51-651c-4e2a-9a07-91848ca5e1e4') - def test_request_single_message_from_a_nonexistent_queue(self): - # List a message from a nonexistent queue - id = uuidutils.generate_uuid() - non_existent_queue = data_utils.rand_name('rand_queuename') - uri = "/v2/queues/{0}/messages/{1}".format(non_existent_queue, id) - self.assertRaises(lib_exc.NotFound, - self.client.show_single_message, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('767fdad1-37df-485a-8063-5036e8d16a12') - def test_request_a_non_existing_message(self): - # List a message with an invalid id - invalid_id = uuidutils.generate_uuid() - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - uri = "/v2/queues/{0}/messages/{1}".format(queue_name, invalid_id) - self.assertRaises(lib_exc.NotFound, - self.client.show_single_message, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('ac2d1a88-5721-4bef-8dfa-53d936630e84') - def test_request_a_message_with_negative_message_id(self): - # List a message with an invalid id, negative - negative_id = '-1' - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - uri = "/v2/queues/{0}/messages?ids={1}".format(queue_name, - negative_id) - self.assertRaises(lib_exc.NotFound, - self.client.show_single_message, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('ac083d78-67bb-4515-b553-2fc76499e2bd') - def test_request_a_message_without_a_token(self): - # List a message without a valid token - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - id = uuidutils.generate_uuid() - uri = "/v2/queues/{0}/messages/{1}".format(queue_name, id) - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None - ) - self.assertRaises(lib_exc.Unauthorized, - self.client.show_single_message, uri) - - # Get a Set of Messages by ID - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('f544e745-f3da-451d-8621-c3711cd37453') - def test_request_multiple_messages_from_a_nonexistent_queue(self): - # List multiple messages from a non existent queue - id1 = uuidutils.generate_uuid() - id2 = uuidutils.generate_uuid() - queue = data_utils.rand_name('nonexistent_queue') - uri = "/v2/queues/{0}/messages?ids={1},{2}".format(queue, - id1, id2) - self.assertRaises(lib_exc.NotFound, - self.client.show_multiple_messages, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('654e64f8-01df-40a0-a09e-d5ec17a3e187') - def test_request_multiple_messages_with_invalid_message_id(self): - # List multiple messages by passing invalid id - invalid_id = uuidutils.generate_uuid() - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - uri = "/v2/queues/{0}/messages?ids={1},{2}".format(queue_name, - invalid_id, - invalid_id) - self.assertRaises(lib_exc.NotFound, - self.client.show_multiple_messages, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('295a37a6-5c93-43e3-a316-3f3dffd4b242') - def test_request_multiple_messages_by_exceeding_the_default_limit(self): - # Default limit value is 20 , configurable - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - ids = str.join(',', (uuidutils.generate_uuid()) * 21) - uri = "/v2/queues/{0}/messages?ids={1}".format(queue_name, ids) - self.assertRaises(lib_exc.BadRequest, - self.client.show_multiple_messages, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('f96eb4a0-8930-4d5e-b8bf-11080628c761') - def test_request_message_by_passing_invalid_echo_param(self): - # Value of the echo parameter must be either true or false - echo = None - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - uri = "/v2/queues/{0}/messages?echo={1}".format(queue_name, echo) - self.assertRaises(lib_exc.BadRequest, - self.client.show_multiple_messages, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('6f668242-6a45-48bc-8ef2-fb581e57d471') - def test_request_messages_by_passing_invalid_include_claimed_param(self): - # Value of include_claimed param must be either true or false - value = None - queue = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - uri = "/v2/queues/{0}/messages?include_claimed={1}".format(queue, - value) - self.assertRaises(lib_exc.BadRequest, - self.client.show_multiple_messages, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('dd267387-76f6-47bd-849b-b1640051aff4') - def test_request_messages_limit_greater_than_configured_value(self): - # Default limit value is 20 , configurable - invalid_limit = data_utils.rand_int_id(21, 10000) - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - uri = "/v2/queues/{0}/messages?limit={1}".format(queue_name, - invalid_limit) - self.assertRaises(lib_exc.BadRequest, - self.client.show_multiple_messages, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('d199f64e-0f22-4129-9bc4-ff709c01592b') - def test_request_messages_with_limit_less_than_configured_value(self): - # Default limit value is 20 , configurable - invalid_limit = data_utils.rand_int_id(-1000, 0) - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - uri = "/v2/queues/{0}/messages?limit={1}".format(queue_name, - invalid_limit) - self.assertRaises(lib_exc.BadRequest, - self.client.show_multiple_messages, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('0b2e803c-7cb9-4c11-bed6-f976f5247b27') - def test_request_multiple_messages_request_without_a_token(self): - # List messages without a valid token - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - id1 = uuidutils.generate_uuid() - id2 = uuidutils.generate_uuid() - uri = "/v2/queues/{0}/messages/{1},{2}".format(queue_name, id1, id2) - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None - ) - self.assertRaises(lib_exc.Unauthorized, - self.client.show_multiple_messages, uri) - - # Get Messages - - @decorators.idempotent_id('125632c4-c7ce-47fb-93fe-c446d14396f9') - def test_list_messages_with_invalid_token(self): - # List messages without a valid token - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None - ) - self.assertRaises(lib_exc.Unauthorized, - self.client.list_messages, queue_name) - - # Post Messages - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('5a0ba3e6-e6ca-4952-be50-fb6be7834ab7') - def test_post_messages_with_no_request_body(self): - # Post message with empty body - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - body = {} - self.assertRaises(lib_exc.BadRequest, - self.client.post_messages, queue_name, body) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('af5ffb4d-c0b4-41db-aea3-bcfc8a232bd6') - def test_post_messages_with_a_bad_message(self): - # Post message with invalid message format - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - body = {'[]', '.'} - self.assertRaises(lib_exc.BadRequest, - self.client.post_messages, queue_name, body) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('10bc153c-97d2-4a19-9795-e0f6993bad4f') - def test_post_messages_to_a_nonexistent_queue(self): - # Post message to a non existent queue - non_existent_queue = data_utils.rand_name('rand_queuename') - body = self.generate_message_body() - resp, _ = self.client.post_messages(non_existent_queue, body) - self.assertEqual('201', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('263d6361-4759-4f2c-be9c-12559f064135') - def test_post_messages_to_a_non_ascii_queue(self): - # Post message to a queue with non ascii queue name - queue_name = data_utils.rand_name('\u6c49\u5b57\u6f22\u5b57') - body = self.generate_message_body() - self.assertRaises(lib_exc.BadRequest, - self.client.post_messages, queue_name, body) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('04c1b220-1e22-4e38-9db2-a76e8b5e2f3f') - def test_post_messages_to_a_queue_with_invalid_name(self): - # Post messages to a queue with invalid characters for queue name - queue_name = '@$@^qw@' - body = self.generate_message_body() - self.assertRaises(lib_exc.BadRequest, - self.client.post_messages, queue_name, body) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('72290766-cb01-425e-856b-a57877015336') - def test_post_messages_to_a_queue_with_invalid_length_for_queue_name(self): - # Post messages to a queue with a long queue name - queue_name = 'q' * 65 - body = self.generate_message_body() - self.assertRaises(lib_exc.BadRequest, - self.client.post_messages, queue_name, body) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('774e8bc8-9b20-40fb-9eed-c5368de368c5') - def test_post_messages_with_invalid_json_request_body(self): - # Post messages to a queue with non-JSON request body - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - body = "123" - self.assertRaises(lib_exc.BadRequest, - self.client.post_messages, queue_name, body) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('ebbe257a-9f1e-498a-bba8-f5c71230365a') - def test_post_messages_with_TTL_less_than_60(self): - # TTL for a message may not exceed 1209600 seconds, - # and must be at least 60 seconds long. - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - message_ttl = data_utils.\ - rand_int_id(start=0, end=60) - - key = data_utils.arbitrary_string(size=20, base_text='MessagingKey') - value = data_utils.arbitrary_string(size=20, - base_text='MessagingValue') - message_body = {key: value} - - rbody = ([{'body': message_body, 'ttl': message_ttl}] * 1) - - self.assertRaises(lib_exc.BadRequest, - self.client.post_messages, queue_name, rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('6d64de03-fd57-4f07-b6f1-8563200a4b4d') - def test_post_messages_with_TTL_greater_than_1209600(self): - # TTL for a message may not exceed 1209600 seconds, and - # must be at least 60 seconds long. - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - message_ttl = data_utils.\ - rand_int_id(start=1209601, end=1309600) - - key = data_utils.arbitrary_string(size=20, base_text='MessagingKey') - value = data_utils.arbitrary_string(size=20, - base_text='MessagingValue') - message_body = {key: value} - - rbody = ([{'body': message_body, 'ttl': message_ttl}] * 1) - - self.assertRaises(lib_exc.BadRequest, - self.client.post_messages, queue_name, rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('c48802d7-7e91-4d5f-9c23-32cd4edc41ff') - def test_post_messages_with_non_int_value_of_TTL(self): - # TTL for a message may not exceed 1209600 seconds, and - # must be at least 60 seconds long. - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - message_ttl = random.uniform(0.0, 0.120960) - - key = data_utils.arbitrary_string(size=20, base_text='MessagingKey') - value = data_utils.arbitrary_string(size=20, - base_text='MessagingValue') - message_body = {key: value} - - rbody = ([{'body': message_body, 'ttl': message_ttl}] * 1) - - self.assertRaises(lib_exc.BadRequest, - self.client.post_messages, queue_name, rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('203fed96-0df3-43c0-9956-723b34b8a23b') - def test_post_messages_with_negative_value_of_TTL(self): - # TTL for a message may not exceed 1209600 seconds, and - # must be at least 60 seconds long. - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - message_ttl = data_utils.\ - rand_int_id(start=-9999, end=-1) - - key = data_utils.arbitrary_string(size=20, base_text='MessagingKey') - value = data_utils.arbitrary_string(size=20, - base_text='MessagingValue') - message_body = {key: value} - - rbody = ([{'body': message_body, 'ttl': message_ttl}] * 1) - - self.assertRaises(lib_exc.BadRequest, - self.client.post_messages, queue_name, rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('d3ad28e7-0c84-43cf-bb87-1574da28a10d') - def test_post_messages_without_TTL(self): - # TTL for a message may not exceed 1209600 seconds, and - # must be at least 60 seconds long. - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - key = data_utils.arbitrary_string(size=20, base_text='MessagingKey') - value = data_utils.arbitrary_string(size=20, - base_text='MessagingValue') - message_body = {key: value} - - rbody = ([{'body': message_body}] * 1) - - self.assertRaises(lib_exc.BadRequest, - self.client.post_messages, queue_name, rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('662428d4-302f-4000-8ac6-1a53fb8818b8') - def test_post_messages_exceeding_message_post_size(self): - # Post messages with greater message size - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - key = data_utils.arbitrary_string(size=20, base_text='MessagingKey') - value = 'a' * 1024 - message_ttl = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_message_ttl) - - message_body = {key: value} - - rbody = ([{'body': message_body, 'ttl': message_ttl}] * 1) - - self.assertRaises(lib_exc.BadRequest, - self.client.post_messages, queue_name, rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('ba4f7334-1a4d-4bc8-acd3-040a1310fe62') - def test_post_messages_with_invalid_body_size(self): - # Maximum number of queue message per page - # while posting messages is 20 - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - key = data_utils.arbitrary_string(size=20, base_text='MessagingKey') - value = data_utils.arbitrary_string(size=20, - base_text='MessagingValue') - message_ttl = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_message_ttl) - - message_body = {key: value} - rbody = ([{'body': message_body, 'ttl': message_ttl}] * 21) - self.assertRaises(lib_exc.BadRequest, - self.client.post_messages, queue_name, rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('855d36a2-e583-4355-af33-fcec0f71842c') - def test_post_messages_without_body_in_request_body(self): - # TTL for a message may not exceed 1209600 seconds, and - # must be at least 60 seconds long. - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - message_ttl = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_message_ttl) - - rbody = ([{'ttl': message_ttl}] * 1) - - self.assertRaises(lib_exc.BadRequest, - self.client.post_messages, queue_name, rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('074fe312-0077-41ba-8aa9-e6d6a586a685') - def test_post_messages_with_invalid_auth_token(self): - # X-Auth-Token is not provided - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - body = self.generate_message_body() - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None) - self.assertRaises(lib_exc.Unauthorized, - self.client.post_messages, - queue_name, body) - - # Delete Messages - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('8552d5b3-7c16-4eaf-a8de-a7b178823458') - def test_delete_message_from_a_nonexistent_queue(self): - # Delete is an idempotent operation - non_existent_queue = data_utils.rand_name('rand_queuename') - message_id = uuidutils.generate_uuid() - uri = "/v2/queues/{0}/messages?ids={1}".format(non_existent_queue, - message_id) - resp, _ = self.client.delete_messages(uri) - self.assertEqual('204', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('a5d581f0-0403-4c2d-9ea4-048cc6cc85f0') - def test_delete_a_non_existing_message(self): - # Delete is an idempotent operation - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - message_id = uuidutils.generate_uuid() - uri = "/v2/queues/{0}/messages?ids={1}".format(queue_name, - message_id) - resp, _ = self.client.delete_messages(uri) - self.assertEqual('204', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('f792f462-0ad9-41b1-9bae-636957364ca0') - def test_delete_message_with_non_existent_message_id(self): - # Delete is an idempotent operation - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - message_id = uuidutils.generate_uuid() - uri = "/v2/queues/{0}/messages/{1}".format(queue_name, - message_id) - resp, _ = self.client.delete_messages(uri) - self.assertEqual('204', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('6b8f14b3-2307-49e2-aa53-75d4d4b82754') - def test_delete_multiple_non_existing_messages(self): - # Delete is an idempotent operation - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - id1 = uuidutils.generate_uuid() - id2 = uuidutils.generate_uuid() - id3 = uuidutils.generate_uuid() - uri = "/v2/queues/{0}/messages?ids={1}{2}{3}".format(queue_name, - id1, id2, id3) - resp, _ = self.client.delete_messages(uri) - self.assertEqual('204', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('805f75fd-6447-4c8a-860c-2659d8a5b0b5') - def test_delete_message_without_id(self): - # Delete all the message from a queue - # without passing any id - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - message_body = self.generate_message_body(repeat=1) - self.post_messages(queue_name, message_body) - uri = "/v2/queues/{0}/messages".format(queue_name) - self.assertRaises(lib_exc.BadRequest, - self.client.delete_messages, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('85eed2fb-fa72-4886-8cfc-44c7fb58ffea') - def test_delete_message_with_invalid_message_id(self): - # Delete is an idempotent operation - # Delete a message with negative id - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - message_id = uuidutils.generate_uuid() - uri = "/v2/queues/{0}/messages?ids=-{1}".format(queue_name, - message_id) - resp, _ = self.client.delete_messages(uri) - self.assertEqual('204', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('374265e7-1146-4da4-a265-38c8698e4144') - def test_delete_the_deleted_message(self): - # Delete is an idempotent operation - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - message_id = uuidutils.generate_uuid() - uri = "/v2/queues/{0}/messages?ids={1}".format(queue_name, - message_id) - resp, _ = self.client.delete_messages(uri) - # Delete the message again - resp, _ = self.client.delete_messages(uri) - self.assertEqual('204', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('a130d499-cd41-42dd-b1f0-e859f73b00e0') - def test_delete_multiple_messages_by_exceeding_the_default_limit(self): - # Default limit value is 20 - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - ids = str.join(',', (uuidutils.generate_uuid()) * 21) - uri = "/v2/queues/{0}/messages?ids={1}".format(queue_name, ids) - self.assertRaises(lib_exc.BadRequest, - self.client.delete_messages, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('51a2f5ca-e358-4ef6-9f33-73d3e01f07b9') - def test_delete_message_without_providing_claim_id(self): - # When message is claimed; - # it cannot be deleted without a valid claim ID. - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - # Post Messages - message_body = self.generate_message_body(repeat=1) - self.client.post_messages(queue_name=queue_name, - rbody=message_body) - # Post Claim - claim_ttl = data_utils.rand_int_id(start=60, - end=CONF.messaging.max_claim_ttl) - claim_grace = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_claim_grace) - claim_body = {"ttl": claim_ttl, "grace": claim_grace} - resp, body = self.client.post_claims(queue_name=queue_name, - rbody=claim_body) - message_uri = body['messages'][0]['href'] - sep = "?claim_id" - uri = message_uri.split(sep, 1)[0] - self.assertRaises(lib_exc.Forbidden, - self.client.delete_messages, - uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('18fa5f43-20e6-47bd-a751-ef33e62a4315') - def test_delete_message_with_invalid_claim_id(self): - # Delete with a non existent claim id - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - message_body = self.generate_message_body(repeat=1) - resp, body = self.post_messages(queue_name, message_body) - message_uri = body['resources'][0] - claim_id = "?claim_id=123" - uri = message_uri + str(claim_id) - self.assertRaises(lib_exc.BadRequest, - self.client.delete_messages, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('b82e5dee-5470-4408-9dca-d4a7536ff25f') - def test_delete_message_with_no_pop_value(self): - # Pop value must be at least 1 and may not be greater than 20 - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - value = ' ' - uri = "/v2/queues/{0}/messages?pop={1}".format(queue_name, value) - self.assertRaises(lib_exc.BadRequest, - self.client.delete_messages, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('6454103d-9cfd-48da-bd8c-061e61a7e634') - def test_delete_message_with_invalid_pop_value(self): - # Pop value must be at least 1 and may not be greater than 20 - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - value = 1000000000 - uri = "/v2/queues/{0}/messages?pop={1}".format(queue_name, value) - self.assertRaises(lib_exc.BadRequest, - self.client.delete_messages, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('9874b696-352b-47d7-a338-d149d4096c28') - def test_delete_message_with_negative_pop_value(self): - # Pop value must be at least 1 and may not be greater than 20 - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - value = '-1' - uri = "/v2/queues/{0}/messages?pop={1}".format(queue_name, value) - self.assertRaises(lib_exc.BadRequest, - self.client.delete_messages, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('4044f38a-0a70-4c86-ab1b-ca369e5b443a') - def test_delete_message_with_invalid_params_with_pop(self): - # Pop & ids parameters are mutually exclusive - # Anyone of which needs to be used with delete - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - pop_value = 5 - ids_value = uuidutils.generate_uuid() - uri = "/v2/queues/{0}/messages?pop={1}&ids={2}".format(queue_name, - pop_value, - ids_value) - self.assertRaises(lib_exc.BadRequest, - self.client.delete_messages, uri) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('ea609ee5-a7a2-41a0-a9fb-73e8c7ed8c59') - def test_delete_messages_with_invalid_auth_token(self): - # Delete message with an invalid token - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - message_body = self.generate_message_body(repeat=1) - resp, body = self.post_messages(queue_name, message_body) - message_uri = body['resources'][0] - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None) - self.assertRaises(lib_exc.Unauthorized, - self.client.delete_messages, - message_uri) - - @classmethod - def resource_cleanup(cls): - for queue_name in cls.queues: - cls.client.delete_queue(queue_name) - super(TestMessagesNegative, cls).resource_cleanup() diff --git a/zaqar/tests/tempest_plugin/tests/v2/test_queues.py b/zaqar/tests/tempest_plugin/tests/v2/test_queues.py deleted file mode 100644 index 71dca371c..000000000 --- a/zaqar/tests/tempest_plugin/tests/v2/test_queues.py +++ /dev/null @@ -1,151 +0,0 @@ -# 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 six import moves -from tempest import config -from tempest.lib.common.utils import data_utils -from tempest.lib import decorators -from testtools import matchers - -from zaqar.tests.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('', 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 moves.xrange(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('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.assertThat(body, matchers.HasLength(2)) - self.assertEqual(262144, body['_max_messages_post_size']) - self.assertEqual(3600, body['_default_message_ttl']) - # 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.assertThat(body, matchers.HasLength(4)) - 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.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() diff --git a/zaqar/tests/tempest_plugin/tests/v2/test_queues_negative.py b/zaqar/tests/tempest_plugin/tests/v2/test_queues_negative.py deleted file mode 100644 index 65a43e21d..000000000 --- a/zaqar/tests/tempest_plugin/tests/v2/test_queues_negative.py +++ /dev/null @@ -1,239 +0,0 @@ -# Copyright (c) 2016 LARSEN & TOUBRO LIMITED. All rights reserved. -# -# 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 six import moves -from tempest.lib.common.utils import data_utils -from tempest.lib import decorators -from tempest.lib import exceptions as lib_exc - -from zaqar.tests.tempest_plugin.tests import base - - -class QueueNegativeTestJSON(base.BaseV2MessagingTest): - - @classmethod - def resource_setup(cls): - super(QueueNegativeTestJSON, cls).resource_setup() - cls.queues = list() - for _ in moves.xrange(1): - queue_name = data_utils.rand_name('Queues-Test') - cls.queues.append(queue_name) - cls.client.create_queue(queue_name) - - # Create Queues - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('77634fd0-0a25-4cc7-a01c-b6d16304f907') - def test_queue_has_a_long_name(self): - # Length of queue name should >= 1 and <=64 bytes - queue_name = 'q' * 65 - self.assertRaises(lib_exc.BadRequest, - self.client.create_queue, - queue_name) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('639206ad-d74c-4f51-895d-76e2c7dff60b') - def test_queue_name_is_not_specified(self): - # Length of queue name should >= 1 and <=64 bytes - queue_name = ' ' - self.assertRaises(lib_exc.UnexpectedResponseCode, - self.client.create_queue, - queue_name) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('3ca0e180-c770-4922-8a48-9563c484aaed') - def test_queue_name_has_a_invalid_character_set(self): - # Invalid name with characters - queue_name = '@$@^qw@' - self.assertRaises(lib_exc.BadRequest, - self.client.create_queue, - queue_name) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('533c5a65-fcc9-4e07-84bc-82ac0c007dbc') - def test_queue_name_with_non_ASCII_characters(self): - # Invalid name with non-ASCII characters - queue_name = data_utils.rand_name('\u6c49\u5b57\u6f22\u5b57') - self.assertRaises(lib_exc.BadRequest, - self.client.create_queue, - queue_name) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('44775212-2b79-40c7-8604-fcf01eddba79') - def test_queue_name_with_numeric_values(self): - # Numeric values for queue name - queue_name = data_utils.rand_int_id() - resp, _ = self.client.create_queue(queue_name) - self.assertEqual('201', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('2ce4f4c1-cbaa-4c2d-b28a-f562aec037aa') - def test_create_queue_with_invalid_auth_token(self): - # Create queue with empty headers - # X-Auth-Token is not provided - queue_name = data_utils.rand_name(name='queue') - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None - ) - self.assertRaises(lib_exc.Unauthorized, - self.client.create_queue, - queue_name) - - # List Queues - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('d4d33596-0f06-4911-aecc-17512c00a301') - def test_request_a_nonexistent_queue(self): - # List a non-existent queue - nonexistent_queuename = data_utils.rand_name('rand_queuename') - resp, _ = self.client.show_queue(nonexistent_queuename) - self.assertEqual('200', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('0c8122a8-e28b-4320-8f1f-af97a0bfa26b') - def test_request_after_deleting_queue(self): - # Request queue after deleting the queue - # DELETE is an idempotent operation - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - self.client.delete_queue(queue_name) - resp, _ = self.client.show_queue(queue_name) - self.assertEqual('200', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('b7c4521a-d0f1-4fc6-b99d-ece2131ac082') - def test_request_with_a_greater_limit_value(self): - # Limit for listing queues is 20 , configurable - params = {'limit': '200'} - self.assertRaises(lib_exc.BadRequest, - self.client.list_queues, - url_params=params) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('121e5171-e189-4be5-8ccf-d0b2009b3bbe') - def test_request_with_zero_limit_value(self): - # Limit for listing queues is 20 , configurable - params = {'limit': '0'} - self.assertRaises(lib_exc.BadRequest, - self.client.list_queues, - url_params=params) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('6c710fa6-9447-4c2c-b8c0-7581a56b4ab5') - def test_request_with_negative_limit_value(self): - # Limit for listing queues is 20 , configurable - params = {'limit': '-1'} - self.assertRaises(lib_exc.BadRequest, - self.client.list_queues, - url_params=params) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('4a54b60c-0a6a-4662-9ba1-fe0b9dd4f399') - def test_with_non_boolean_value_for_detailed(self): - # Value for detailed parameter should be true or false - params = {'detailed': 'None'} - self.assertRaises(lib_exc.BadRequest, - self.client.list_queues, url_params=params) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('f66f1225-bfe8-4fe0-b8c9-35e4342e0f0e') - def test_list_queues_with_invalid_auth_token(self): - # List queue with empty headers - # X-Auth-Token is not provided - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None - ) - self.assertRaises(lib_exc.Unauthorized, - self.client.list_queues) - - # Get Queue Stats - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('16cec0df-b58a-44e8-9132-f99f0c1da29a') - def test_request_stats_for_a_non_existing_queue(self): - # Show stats for a non-existent queue - nonexistent_queuename = data_utils.rand_name('rand_queuename') - resp, _ = self.client.show_queue_stats(nonexistent_queuename) - self.assertEqual('200', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('1cad4984-3f66-48f6-82c9-9a544be78ca6') - def test_request_queue_stats_after_deleting_queue(self): - # List queue stats after deleting the queue - # DELETE is an idempotent operation - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - self.client.delete_queue(queue_name) - resp, _ = self.client.show_queue_stats(queue_name) - self.assertEqual('200', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('2b1aeba8-a314-495b-8d45-84692354a013') - def test_request_queue_stats_with_invalid_auth_token(self): - # Get queue stats with empty headers - # X-Auth-Token is not provided - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None - ) - self.assertRaises(lib_exc.Unauthorized, - self.client.show_queue_stats, - queue_name) - - # Delete Queues - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('cf7d5cff-0e4f-4d2c-82eb-59f450ca1b7d') - def test_delete_a_non_existing_queue(self): - # Delete is an idempotent operation - non_existent_queue = data_utils.rand_name('Queue_name') - resp, _ = self.client.delete_queue(non_existent_queue) - self.assertEqual('204', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('c5973d87-5b59-446c-8e81-a8e28de9e61d') - def test_delete_the_deleted_queue(self): - # Delete is an idempotent operation - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - self.client.delete_queue(queue_name) - # Delete again - resp, _ = self.client.delete_queue(queue_name) - self.assertEqual('204', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('a54e2715-478a-4701-9080-a06b9364dc74') - def test_delete_queue_with_invalid_auth_token(self): - # Delete queue with empty headers - # X-Auth-Token is not provided - queue_name = self.queues[data_utils.rand_int_id(0, - len(self.queues) - 1)] - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None - ) - self.assertRaises(lib_exc.Unauthorized, - self.client.delete_queue, - queue_name) - - @classmethod - def resource_cleanup(cls): - for queue_name in cls.queues: - cls.client.delete_queue(queue_name) - super(QueueNegativeTestJSON, cls).resource_cleanup() diff --git a/zaqar/tests/tempest_plugin/tests/v2/test_subscriptions.py b/zaqar/tests/tempest_plugin/tests/v2/test_subscriptions.py deleted file mode 100644 index 4d6f4f7e6..000000000 --- a/zaqar/tests/tempest_plugin/tests/v2/test_subscriptions.py +++ /dev/null @@ -1,153 +0,0 @@ -# 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. - -import json - -from oslo_utils import uuidutils -from tempest.lib.common.utils import data_utils -from tempest.lib.common.utils import test_utils -from tempest.lib import decorators - -from zaqar.tests.tempest_plugin.tests import base - - -class TestSubscriptions(base.BaseV2MessagingTest): - - @classmethod - def resource_setup(cls): - super(TestSubscriptions, cls).resource_setup() - cls.queue_name = data_utils.rand_name('Queues-Test') - # Create Queue - cls.client.create_queue(cls.queue_name) - - def _create_subscriptions(self): - bodys = self.generate_subscription_body() - results = [] - for body in bodys: - resp, body = self.create_subscription(queue_name=self.queue_name, - rbody=body) - results.append((resp, body)) - return results - - @decorators.idempotent_id('425d5afb-31d8-40ea-a23a-ef3f5554f7cc') - def test_create_delete_subscriptions(self): - # create all kinds of subscriptions - results = self._create_subscriptions() - # delete them - for result in results: - subscription_id = result[1]["subscription_id"] - self.delete_subscription(self.queue_name, subscription_id) - - @decorators.idempotent_id('a8776d93-895f-4947-a6b0-d0da50bfd5e8') - def test_list_subscriptions(self): - # create all kinds of subscriptions - results = self._create_subscriptions() - # list them - resp, body = self.list_subscription(self.queue_name) - self.assertEqual('200', resp['status']) - self.assertEqual(3, len(body['subscriptions'])) - # delete them - for result in results: - subscription_id = result[1]["subscription_id"] - self.delete_subscription(self.queue_name, subscription_id) - - @decorators.idempotent_id('de3d4a35-c5de-4f40-b6ad-7df187bf3831') - def test_show_subscriptions(self): - # create all kinds of subscriptions - results = self._create_subscriptions() - # get the first one - subscription_id = results[0][1]["subscription_id"] - resp, body = self.show_subscription(self.queue_name, subscription_id) - self.assertEqual('200', resp['status']) - self.assertEqual('http://fake:8080', body['subscriber']) - # delete them - for result in results: - subscription_id = result[1]["subscription_id"] - self.delete_subscription(self.queue_name, subscription_id) - - @decorators.idempotent_id('90489fa2-893d-4062-b2bd-29bdd06f54f3') - def test_update_subscriptions(self): - # create all kinds of subscriptions - results = self._create_subscriptions() - # update the first one - subscription_id = results[0][1]["subscription_id"] - rbody = {'options': {'test': 'updated'}} - self.update_subscription(self.queue_name, subscription_id, rbody) - # get the new one - resp, body = self.show_subscription(self.queue_name, subscription_id) - self.assertEqual('200', resp['status']) - self.assertEqual(rbody['options'], body['options']) - # delete them - for result in results: - subscription_id = result[1]["subscription_id"] - self.delete_subscription(self.queue_name, subscription_id) - - @decorators.idempotent_id('fe0d8ec1-1a64-4490-8869-e821b2252e74') - def test_create_subscriptions_with_duplicate_subscriber(self): - # Adding subscriptions to the queue - results = self._create_subscriptions() - s_id1 = results[0][1]['subscription_id'] - - # Adding a subscription with duplicate subscriber, it will reconfirm - # the subscription and run well. - rbody = {'subscriber': 'http://fake:8080', - 'options': {'MessagingKeyMsg': 'MessagingValueMsg'}, - 'ttl': 293305} - resp, body = self.create_subscription(self.queue_name, rbody) - s_id2 = body['subscription_id'] - - self.assertEqual('201', resp['status']) - self.assertEqual(s_id2, s_id1) - - # Delete the subscriptions created - for result in results: - subscription_id = result[1]["subscription_id"] - self.delete_subscription(self.queue_name, subscription_id) - - @decorators.idempotent_id('ff4344b4-ba78-44c5-9ffc-44e53e484f76') - def test_trust_subscription(self): - sub_queue = data_utils.rand_name('Queues-Test') - self.addCleanup(self.client.delete_queue, sub_queue) - subscriber = 'trust+{0}/{1}/queues/{2}/messages'.format( - self.client.base_url, self.client.uri_prefix, sub_queue) - post_body = json.dumps( - {'messages': [{'body': '$zaqar_message$', 'ttl': 60}]}) - post_headers = {'X-Project-ID': self.client.tenant_id, - 'Client-ID': uuidutils.generate_uuid()} - sub_body = {'ttl': 1200, 'subscriber': subscriber, - 'options': {'post_data': post_body, - 'post_headers': post_headers}} - - self.create_subscription(queue_name=self.queue_name, rbody=sub_body) - message_body = self.generate_message_body() - self.post_messages(queue_name=self.queue_name, rbody=message_body) - - if not test_utils.call_until_true( - lambda: self.list_messages(sub_queue)[1]['messages'], 10, 1): - self.fail("Couldn't get messages") - _, body = self.list_messages(sub_queue) - expected = message_body['messages'][0] - expected['queue_name'] = self.queue_name - expected['Message_Type'] = 'Notification' - for message in body['messages']: - # There are two message in the queue. One is the confirm message, - # the other one is the notification. - if message['body']['Message_Type'] == 'Notification': - self.assertEqual(expected, message['body']) - - @classmethod - def resource_cleanup(cls): - cls.delete_queue(cls.queue_name) - super(TestSubscriptions, cls).resource_cleanup() diff --git a/zaqar/tests/tempest_plugin/tests/v2/test_subscriptions_negative.py b/zaqar/tests/tempest_plugin/tests/v2/test_subscriptions_negative.py deleted file mode 100644 index a836752c1..000000000 --- a/zaqar/tests/tempest_plugin/tests/v2/test_subscriptions_negative.py +++ /dev/null @@ -1,372 +0,0 @@ -# Copyright (c) 2016 LARSEN & TOUBRO LIMITED. All rights reserved. -# -# 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 oslo_utils import uuidutils - -from tempest import config -from tempest.lib.common.utils import data_utils -from tempest.lib import decorators -from tempest.lib import exceptions as lib_exc - -from zaqar.tests.tempest_plugin.tests import base - -CONF = config.CONF - - -class TestSubscriptionsNegative(base.BaseV2MessagingTest): - - @classmethod - def resource_setup(cls): - super(TestSubscriptionsNegative, cls).resource_setup() - cls.queue_name = data_utils.rand_name('Queues-Test') - # Create Queue - cls.client.create_queue(cls.queue_name) - - def _create_subscriptions(self): - bodys = self.generate_subscription_body() - results = [] - for body in bodys: - resp, body = self.create_subscription(queue_name=self.queue_name, - rbody=body) - results.append((resp, body)) - return results - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('0bda2907-a783-4614-af16-23d7a7d53b72') - def test_create_subscriptions_with_invalid_body(self): - # Missing subscriber parameter in body - message_ttl = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_message_ttl) - key = data_utils.arbitrary_string(size=20, base_text='MessagingKey') - value = data_utils.arbitrary_string(size=20, - base_text='MessagingValue') - option_body = {key: value} - rbody = {'options': option_body, 'ttl': message_ttl} - self.assertRaises(lib_exc.BadRequest, - self.create_subscription, self.queue_name, rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('36601d23-77d5-42b1-b234-6789acdda7ba') - def test_create_subscriptions_with_no_body(self): - # Missing parameters in body - rbody = {} - self.assertRaises(lib_exc.BadRequest, - self.create_subscription, self.queue_name, rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('1d510d93-635f-4161-b071-91f838d6907e') - def test_create_subscriptions_with_invalid_subscriber(self): - # The subscriber type of subscription must be supported in the list - # ['http', 'https', 'mailto'] - message_ttl = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_message_ttl) - key = data_utils.arbitrary_string(size=20, base_text='MessagingKey') - value = data_utils.arbitrary_string(size=20, - base_text='MessagingValue') - option_body = {key: value} - subscriber = 'fake' - rbody = {'options': option_body, 'ttl': message_ttl, - 'subscriber': subscriber} - self.assertRaises(lib_exc.BadRequest, - self.create_subscription, self.queue_name, rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('65be33a4-a063-47e1-b56b-9d7aa979bbcb') - def test_create_subscriptions_with_unsupported_subscriber(self): - # The subscriber type of subscription must be supported in the list - # ['http', 'https', 'mailto'] - message_ttl = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_message_ttl) - key = data_utils.arbitrary_string(size=20, base_text='MessagingKey') - value = data_utils.arbitrary_string(size=20, - base_text='MessagingValue') - option_body = {key: value} - subscriber = 'email://fake' - rbody = {'options': option_body, 'ttl': message_ttl, - 'subscriber': subscriber} - self.assertRaises(lib_exc.BadRequest, - self.create_subscription, self.queue_name, rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('cada6c25-0f59-4021-a4c3-961945913998') - def test_create_subscriptions_with_invalid_options(self): - # Options must be a dict - message_ttl = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_message_ttl) - option_body = '123' - subscriber = 'http://fake:8080' - rbody = {'options': option_body, 'ttl': message_ttl, - 'subscriber': subscriber} - self.assertRaises(lib_exc.BadRequest, - self.create_subscription, self.queue_name, rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('84c1e298-c632-4ccb-859f-afe9a390081c') - def test_create_subscriptions_with_non_integer_value_for_ttl(self): - # The subscriber type of subscription must be supported in the list - # ['http', 'https', 'mailto'] - message_ttl = "123" - key = data_utils.arbitrary_string(size=20, base_text='MessagingKey') - value = data_utils.arbitrary_string(size=20, - base_text='MessagingValue') - option_body = {key: value} - subscriber = 'http://fake:8080' - rbody = {'options': option_body, 'ttl': message_ttl, - 'subscriber': subscriber} - self.assertRaises(lib_exc.BadRequest, - self.create_subscription, self.queue_name, rbody) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('1302e137-4db6-48ad-b779-ef2095198bc2') - def test_create_a_subscription_without_a_token(self): - # X-Auth-Token is not provided - message_ttl = data_utils.\ - rand_int_id(start=60, end=CONF.messaging.max_message_ttl) - key = data_utils.arbitrary_string(size=20, base_text='MessagingKey') - value = data_utils.arbitrary_string(size=20, - base_text='MessagingValue') - option_body = {key: value} - subscriber = 'http://fake:8080' - rbody = {'options': option_body, 'ttl': message_ttl, - 'subscriber': subscriber} - - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None - ) - self.assertRaises(lib_exc.Unauthorized, - self.create_subscription, self.queue_name, rbody) - - # List Subscriptions - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('e2109835-34ad-4f0a-8bbb-43d475d1315d') - def test_list_subscriptions_from_non_existing_queue(self): - # Request for listing subscriptions from a non existent queue - non_existent_queue = data_utils.rand_name('rand_queuename') - resp, _ = self.client.list_subscription(non_existent_queue) - self.assertEqual('200', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('95d7c77f-4912-49ce-9f38-cfcc6d5cd65b') - def test_list_subscriptions_from_queue_with_no_subsciptions(self): - # Request to list subscription - resp, _ = self.client.list_subscription(self.queue_name) - self.assertEqual('200', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('72f8c0b7-23d8-40ef-ae7c-212cc0751946') - def test_list_subscription_without_a_token(self): - # X-Auth-Token is not provided - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None - ) - self.assertRaises(lib_exc.Unauthorized, - self.list_subscription, self.queue_name) - - # Show Subscriptions - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('7ecc2cb9-a0f4-4d03-b903-ecf2917fda13') - def test_show_subscriptions_from_non_existing_queue(self): - # Show subscription details from a non existent queue - non_existent_queue = data_utils.rand_name('rand_queuename') - invalid_id = '123' - self.assertRaises(lib_exc.NotFound, - self.show_subscription, non_existent_queue, - invalid_id) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('bb46d838-e9f9-4851-a788-c30bff41c484') - def test_show_subscriptions_with_invalid_id(self): - # Show subscription details with invaild id - invalid_id = '123' - self.assertRaises(lib_exc.NotFound, - self.show_subscription, self.queue_name, invalid_id) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('1120f006-397a-4e8b-9e79-e2dc96b37d46') - def test_show_subscriptions_after_deleting_subscription(self): - # Create subscription - results = self._create_subscriptions() - subscription_id = results[0][1]["subscription_id"] - # Delete subscription - for result in results: - subscription_id = result[1]["subscription_id"] - self.delete_subscription(self.queue_name, subscription_id) - # Show the details of the subscription - self.assertRaises(lib_exc.NotFound, - self.show_subscription, self.queue_name, - subscription_id) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('47a3f29f-6ddb-4cf2-87ed-a2b97733f386') - def test_show_subscription_without_a_token(self): - # X-Auth-Token is not provided - results = self._create_subscriptions() - subscription_id = results[0][1]["subscription_id"] - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None - ) - self.assertRaises(lib_exc.Unauthorized, - self.show_subscription, self.queue_name, - subscription_id) - for result in results: - subscription_id = result[1]["subscription_id"] - self.delete_subscription(self.queue_name, subscription_id) - - # Update Subscriptions - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('5c93b468-cb84-424f-af35-d4f5febc7c56') - def test_update_subscription_on_non_existing_queue(self): - # Update subscription on a non existing queue - results = self._create_subscriptions() - subscription_id = results[0][1]["subscription_id"] - non_existent_queue = data_utils.rand_name('rand_queuename') - update_rbody = {'ttl': 1000} - self.assertRaises(lib_exc.NotFound, self.client.update_subscription, - non_existent_queue, subscription_id, update_rbody) - - for result in results: - subscription_id = result[1]["subscription_id"] - self.delete_subscription(self.queue_name, subscription_id) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('b383a29a-08f1-418f-8adb-c29ef080358c') - def test_update_subscription_with_invalid_id(self): - # Update subscription using invalid id - results = self._create_subscriptions() - subscription_id = uuidutils.generate_uuid() - update_rbody = {'ttl': 100} - self.assertRaises(lib_exc.NotFound, - self.client.update_subscription, self.queue_name, - subscription_id, update_rbody) - for result in results: - subscription_id = result[1]["subscription_id"] - self.delete_subscription(self.queue_name, subscription_id) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('4e446118-fa90-4f67-9a91-e157fbaa5a4c') - def test_update_subscription_with_empty_body(self): - # Update subscription with no body - results = self._create_subscriptions() - subscription_id = results[0][1]["subscription_id"] - update_rbody = {' '} - self.assertRaises(lib_exc.BadRequest, - self.client.update_subscription, self.queue_name, - subscription_id, update_rbody) - for result in results: - subscription_id = result[1]["subscription_id"] - self.delete_subscription(self.queue_name, subscription_id) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('966f5356-9d0b-46c6-9d57-26bcd9d8e699') - def test_update_subscription_with_invalid_TTL(self): - # Update subscription using invalid TTL - results = self._create_subscriptions() - subscription_id = results[0][1]["subscription_id"] - update_rbody = {'ttl': 50} - self.assertRaises(lib_exc.BadRequest, - self.client.update_subscription, self.queue_name, - subscription_id, update_rbody) - for result in results: - subscription_id = result[1]["subscription_id"] - self.delete_subscription(self.queue_name, subscription_id) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('8838f3b2-d4c3-42e2-840c-4314e334a2f0') - def test_update_subscription_with_invalid_json_in_request_body(self): - # Update subscription with invalid json - results = self._create_subscriptions() - subscription_id = results[0][1]["subscription_id"] - update_rbody = {"123"} - self.assertRaises(lib_exc.BadRequest, - self.client.update_subscription, self.queue_name, - subscription_id, update_rbody) - for result in results: - subscription_id = result[1]["subscription_id"] - self.delete_subscription(self.queue_name, subscription_id) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('8bfe5638-0126-483e-b88a-2767fa6564e6') - def test_update_subscription_with_invalid_token(self): - # X-Auth-Token is not provided - results = self._create_subscriptions() - subscription_id = results[0][1]["subscription_id"] - update_rbody = {"ttl": "1000"} - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None - ) - self.assertRaises(lib_exc.Unauthorized, - self.client.update_subscription, self.queue_name, - subscription_id, update_rbody) - for result in results: - subscription_id = result[1]["subscription_id"] - self.delete_subscription(self.queue_name, subscription_id) - - # Delete Subscriptions - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('bb885255-ccac-47e1-a491-2630f205df58') - def test_delete_subscription_from_a_non_existing_queue(self): - # Delete subscription from a non existing queue - rbody = {'subscriber': 'http://fake123:8080', - 'options': {'MessagingKey': 'MessagingValue'}, - 'ttl': 2935} - results = self.create_subscription(self.queue_name, rbody) - subscription_id = results[1]["subscription_id"] - non_existent_queue = data_utils.rand_name('rand_queuename') - resp, _ = self.client.delete_subscription(non_existent_queue, - subscription_id) - self.assertEqual('204', resp['status']) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('a7007b4b-1ab1-4121-9d59-afe5eb82d31c') - def test_delete_subscription_using_a_nonexisting_id(self): - # Delete subscription with non existent id - results = self._create_subscriptions() - subscription_id = uuidutils.generate_uuid() - resp, _ = self.client.delete_subscription(self.queue_name, - subscription_id) - self.assertEqual('204', resp['status']) - for result in results: - subscription_id = result[1]["subscription_id"] - self.delete_subscription(self.queue_name, subscription_id) - - @decorators.attr(type=['negative']) - @decorators.idempotent_id('8faf37ee-4abe-4586-9e4b-ed896129a3e8') - def test_delete_subscription_with_invalid_token(self): - # X-Auth-Token is not provided - results = self._create_subscriptions() - subscription_id = results[0][1]["subscription_id"] - self.client.auth_provider.set_alt_auth_data( - request_part='headers', - auth_data=None - ) - self.assertRaises(lib_exc.Unauthorized, - self.client.delete_subscription, self.queue_name, - subscription_id) - for result in results: - subscription_id = result[1]["subscription_id"] - self.delete_subscription(self.queue_name, subscription_id) - - @classmethod - def resource_cleanup(cls): - cls.delete_queue(cls.queue_name) - super(TestSubscriptionsNegative, cls).resource_cleanup()