blob: b3ed94182bd4112f83b1ea66f045037c809be52c [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
38 @classmethod
Rohan Kanade06129fa2015-02-07 10:16:50 +053039 def skip_checks(cls):
40 super(BaseMessagingTest, cls).skip_checks()
Malini Kamalambal8681e922014-08-18 10:10:45 -040041 if not CONF.service_available.zaqar:
42 raise cls.skipException("Zaqar support is required")
Rohan Kanade06129fa2015-02-07 10:16:50 +053043
44 @classmethod
45 def setup_credentials(cls):
46 super(BaseMessagingTest, cls).setup_credentials()
47 cls.os = cls.get_client_manager()
48
49 @classmethod
50 def setup_clients(cls):
51 super(BaseMessagingTest, cls).setup_clients()
52 cls.client = cls.os.messaging_client
53
54 @classmethod
55 def resource_setup(cls):
56 super(BaseMessagingTest, cls).resource_setup()
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030057 cls.messaging_cfg = CONF.messaging
Malini Kamalambal6e7b3b82014-02-06 06:49:04 -050058
59 @classmethod
60 def create_queue(cls, queue_name):
61 """Wrapper utility that returns a test queue."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010062 resp, body = cls.client.create_queue(queue_name)
63 return resp, body
Jorge Chai4f5896e2014-02-17 14:34:54 -050064
65 @classmethod
66 def delete_queue(cls, queue_name):
Jorge Chai83ba4ee2014-04-15 18:58:08 +000067 """Wrapper utility that deletes a test queue."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010068 resp, body = cls.client.delete_queue(queue_name)
69 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000070
71 @classmethod
72 def check_queue_exists(cls, queue_name):
73 """Wrapper utility that checks the existence of a test queue."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010074 resp, body = cls.client.get_queue(queue_name)
75 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000076
77 @classmethod
78 def check_queue_exists_head(cls, queue_name):
79 """Wrapper utility checks the head of a queue via http HEAD."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010080 resp, body = cls.client.head_queue(queue_name)
81 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000082
83 @classmethod
84 def list_queues(cls):
85 """Wrapper utility that lists queues."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010086 resp, body = cls.client.list_queues()
87 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000088
89 @classmethod
90 def get_queue_stats(cls, queue_name):
91 """Wrapper utility that returns the queue stats."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010092 resp, body = cls.client.get_queue_stats(queue_name)
93 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000094
95 @classmethod
96 def get_queue_metadata(cls, queue_name):
97 """Wrapper utility that gets a queue metadata."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010098 resp, body = cls.client.get_queue_metadata(queue_name)
99 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +0000100
101 @classmethod
102 def set_queue_metadata(cls, queue_name, rbody):
103 """Wrapper utility that sets the metadata of a queue."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100104 resp, body = cls.client.set_queue_metadata(queue_name, rbody)
105 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400106
107 @classmethod
108 def post_messages(cls, queue_name, rbody):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300109 """Wrapper utility that posts messages to a queue."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100110 resp, body = cls.client.post_messages(queue_name, rbody)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400111
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100112 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400113
114 @classmethod
115 def list_messages(cls, queue_name):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300116 """Wrapper utility that lists the messages in a queue."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100117 resp, body = cls.client.list_messages(queue_name)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400118
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100119 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400120
121 @classmethod
122 def get_single_message(cls, message_uri):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300123 """Wrapper utility that gets a single message."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100124 resp, body = cls.client.get_single_message(message_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400125
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100126 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400127
128 @classmethod
129 def get_multiple_messages(cls, message_uri):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300130 """Wrapper utility that gets multiple messages."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100131 resp, body = cls.client.get_multiple_messages(message_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400132
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100133 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400134
135 @classmethod
136 def delete_messages(cls, message_uri):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300137 """Wrapper utility that deletes messages."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100138 resp, body = cls.client.delete_messages(message_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400139
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100140 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400141
142 @classmethod
143 def post_claims(cls, queue_name, rbody, url_params=False):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300144 """Wrapper utility that claims messages."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100145 resp, body = cls.client.post_claims(
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400146 queue_name, rbody, url_params=False)
147
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100148 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400149
150 @classmethod
151 def query_claim(cls, claim_uri):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300152 """Wrapper utility that gets a claim."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100153 resp, body = cls.client.query_claim(claim_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400154
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100155 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400156
157 @classmethod
158 def update_claim(cls, claim_uri, rbody):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300159 """Wrapper utility that updates a claim."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100160 resp, body = cls.client.update_claim(claim_uri, rbody)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400161
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100162 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400163
164 @classmethod
165 def release_claim(cls, claim_uri):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300166 """Wrapper utility that deletes a claim."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100167 resp, body = cls.client.release_claim(claim_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400168
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100169 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400170
171 @classmethod
172 def generate_message_body(cls, repeat=1):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300173 """Wrapper utility that sets the metadata of a queue."""
174 message_ttl = data_utils.\
175 rand_int_id(start=60, end=CONF.messaging.max_message_ttl)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400176
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300177 key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
178 value = data_utils.arbitrary_string(size=20,
179 base_text='MessagingValue')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400180 message_body = {key: value}
181
182 rbody = ([{'body': message_body, 'ttl': message_ttl}] * repeat)
183 return rbody