blob: 2ddc3fc4e9a90d1336b865ba1fec8a78d2d16d6b [file] [log] [blame]
Malini Kamalambal6e7b3b82014-02-06 06:49:04 -05001# Copyright (c) 2014 Rackspace, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12# implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
Doug Hellmann583ce2c2015-03-11 14:55:46 +000016from oslo_log import log as logging
Matthew Treinish01472ff2015-02-20 17:26:52 -050017from tempest_lib.common.utils import data_utils
18
Malini Kamalambal6e7b3b82014-02-06 06:49:04 -050019from tempest import config
Malini Kamalambal6e7b3b82014-02-06 06:49:04 -050020from tempest import test
21
22CONF = config.CONF
23
24LOG = logging.getLogger(__name__)
25
26
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030027class BaseMessagingTest(test.BaseTestCase):
Malini Kamalambal6e7b3b82014-02-06 06:49:04 -050028
29 """
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030030 Base class for the Messaging tests that use the Tempest Zaqar REST client
Malini Kamalambal6e7b3b82014-02-06 06:49:04 -050031
32 It is assumed that the following option is defined in the
33 [service_available] section of etc/tempest.conf
34
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030035 messaging as True
Malini Kamalambal6e7b3b82014-02-06 06:49:04 -050036 """
37
Andrea Frittolib21de6c2015-02-06 20:12:38 +000038 credentials = ['primary']
39
Malini Kamalambal6e7b3b82014-02-06 06:49:04 -050040 @classmethod
Rohan Kanade06129fa2015-02-07 10:16:50 +053041 def skip_checks(cls):
42 super(BaseMessagingTest, cls).skip_checks()
Malini Kamalambal8681e922014-08-18 10:10:45 -040043 if not CONF.service_available.zaqar:
44 raise cls.skipException("Zaqar support is required")
Rohan Kanade06129fa2015-02-07 10:16:50 +053045
46 @classmethod
Rohan Kanade06129fa2015-02-07 10:16:50 +053047 def setup_clients(cls):
48 super(BaseMessagingTest, cls).setup_clients()
49 cls.client = cls.os.messaging_client
50
51 @classmethod
52 def resource_setup(cls):
53 super(BaseMessagingTest, cls).resource_setup()
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030054 cls.messaging_cfg = CONF.messaging
Malini Kamalambal6e7b3b82014-02-06 06:49:04 -050055
56 @classmethod
57 def create_queue(cls, queue_name):
58 """Wrapper utility that returns a test queue."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010059 resp, body = cls.client.create_queue(queue_name)
60 return resp, body
Jorge Chai4f5896e2014-02-17 14:34:54 -050061
62 @classmethod
63 def delete_queue(cls, queue_name):
Jorge Chai83ba4ee2014-04-15 18:58:08 +000064 """Wrapper utility that deletes a test queue."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010065 resp, body = cls.client.delete_queue(queue_name)
66 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000067
68 @classmethod
69 def check_queue_exists(cls, queue_name):
70 """Wrapper utility that checks the existence of a test queue."""
Ken'ichi Ohmichi7e3ccd52015-04-06 23:55:46 +000071 resp, body = cls.client.show_queue(queue_name)
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010072 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000073
74 @classmethod
75 def check_queue_exists_head(cls, queue_name):
76 """Wrapper utility checks the head of a queue via http HEAD."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010077 resp, body = cls.client.head_queue(queue_name)
78 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000079
80 @classmethod
81 def list_queues(cls):
82 """Wrapper utility that lists queues."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010083 resp, body = cls.client.list_queues()
84 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000085
86 @classmethod
87 def get_queue_stats(cls, queue_name):
88 """Wrapper utility that returns the queue stats."""
Ken'ichi Ohmichi7e3ccd52015-04-06 23:55:46 +000089 resp, body = cls.client.show_queue_stats(queue_name)
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010090 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000091
92 @classmethod
93 def get_queue_metadata(cls, queue_name):
94 """Wrapper utility that gets a queue metadata."""
Ken'ichi Ohmichi7e3ccd52015-04-06 23:55:46 +000095 resp, body = cls.client.show_queue_metadata(queue_name)
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010096 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000097
98 @classmethod
99 def set_queue_metadata(cls, queue_name, rbody):
100 """Wrapper utility that sets the metadata of a queue."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100101 resp, body = cls.client.set_queue_metadata(queue_name, rbody)
102 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400103
104 @classmethod
105 def post_messages(cls, queue_name, rbody):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300106 """Wrapper utility that posts messages to a queue."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100107 resp, body = cls.client.post_messages(queue_name, rbody)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400108
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100109 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400110
111 @classmethod
112 def list_messages(cls, queue_name):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300113 """Wrapper utility that lists the messages in a queue."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100114 resp, body = cls.client.list_messages(queue_name)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400115
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100116 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400117
118 @classmethod
119 def get_single_message(cls, message_uri):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300120 """Wrapper utility that gets a single message."""
Ken'ichi Ohmichi7e3ccd52015-04-06 23:55:46 +0000121 resp, body = cls.client.show_single_message(message_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400122
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100123 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400124
125 @classmethod
126 def get_multiple_messages(cls, message_uri):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300127 """Wrapper utility that gets multiple messages."""
Ken'ichi Ohmichi7e3ccd52015-04-06 23:55:46 +0000128 resp, body = cls.client.show_multiple_messages(message_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400129
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100130 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400131
132 @classmethod
133 def delete_messages(cls, message_uri):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300134 """Wrapper utility that deletes messages."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100135 resp, body = cls.client.delete_messages(message_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400136
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100137 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400138
139 @classmethod
140 def post_claims(cls, queue_name, rbody, url_params=False):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300141 """Wrapper utility that claims messages."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100142 resp, body = cls.client.post_claims(
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400143 queue_name, rbody, url_params=False)
144
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100145 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400146
147 @classmethod
148 def query_claim(cls, claim_uri):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300149 """Wrapper utility that gets a claim."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100150 resp, body = cls.client.query_claim(claim_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400151
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100152 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400153
154 @classmethod
155 def update_claim(cls, claim_uri, rbody):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300156 """Wrapper utility that updates a claim."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100157 resp, body = cls.client.update_claim(claim_uri, rbody)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400158
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100159 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400160
161 @classmethod
162 def release_claim(cls, claim_uri):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300163 """Wrapper utility that deletes a claim."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100164 resp, body = cls.client.release_claim(claim_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400165
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100166 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400167
168 @classmethod
169 def generate_message_body(cls, repeat=1):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300170 """Wrapper utility that sets the metadata of a queue."""
171 message_ttl = data_utils.\
172 rand_int_id(start=60, end=CONF.messaging.max_message_ttl)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400173
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300174 key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
175 value = data_utils.arbitrary_string(size=20,
176 base_text='MessagingValue')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400177 message_body = {key: value}
178
179 rbody = ([{'body': message_body, 'ttl': message_ttl}] * repeat)
180 return rbody