blob: 39dc7c31a13cf4d4eb9b596d077f532b9b80c7f2 [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 -050017
Fei Long Wangd39431f2015-05-14 11:30:48 +120018from tempest.common.utils import data_utils
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
Ken'ichi Ohmichi9e3dac02015-11-19 07:01:07 +000029 """Base class for the Messaging (Zaqar) tests
Malini Kamalambal6e7b3b82014-02-06 06:49:04 -050030
31 It is assumed that the following option is defined in the
32 [service_available] section of etc/tempest.conf
33
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030034 messaging as True
Malini Kamalambal6e7b3b82014-02-06 06:49:04 -050035 """
36
Andrea Frittolib21de6c2015-02-06 20:12:38 +000037 credentials = ['primary']
38
Malini Kamalambal6e7b3b82014-02-06 06:49:04 -050039 @classmethod
Rohan Kanade06129fa2015-02-07 10:16:50 +053040 def skip_checks(cls):
41 super(BaseMessagingTest, cls).skip_checks()
Malini Kamalambal8681e922014-08-18 10:10:45 -040042 if not CONF.service_available.zaqar:
43 raise cls.skipException("Zaqar support is required")
Rohan Kanade06129fa2015-02-07 10:16:50 +053044
45 @classmethod
Rohan Kanade06129fa2015-02-07 10:16:50 +053046 def setup_clients(cls):
47 super(BaseMessagingTest, cls).setup_clients()
48 cls.client = cls.os.messaging_client
49
50 @classmethod
51 def resource_setup(cls):
52 super(BaseMessagingTest, cls).resource_setup()
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030053 cls.messaging_cfg = CONF.messaging
Malini Kamalambal6e7b3b82014-02-06 06:49:04 -050054
55 @classmethod
56 def create_queue(cls, queue_name):
57 """Wrapper utility that returns a test queue."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010058 resp, body = cls.client.create_queue(queue_name)
59 return resp, body
Jorge Chai4f5896e2014-02-17 14:34:54 -050060
61 @classmethod
62 def delete_queue(cls, queue_name):
Jorge Chai83ba4ee2014-04-15 18:58:08 +000063 """Wrapper utility that deletes a test queue."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010064 resp, body = cls.client.delete_queue(queue_name)
65 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000066
67 @classmethod
68 def check_queue_exists(cls, queue_name):
69 """Wrapper utility that checks the existence of a test queue."""
Ken'ichi Ohmichi7e3ccd52015-04-06 23:55:46 +000070 resp, body = cls.client.show_queue(queue_name)
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010071 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000072
73 @classmethod
74 def check_queue_exists_head(cls, queue_name):
75 """Wrapper utility checks the head of a queue via http HEAD."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010076 resp, body = cls.client.head_queue(queue_name)
77 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000078
79 @classmethod
80 def list_queues(cls):
81 """Wrapper utility that lists queues."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010082 resp, body = cls.client.list_queues()
83 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000084
85 @classmethod
86 def get_queue_stats(cls, queue_name):
87 """Wrapper utility that returns the queue stats."""
Ken'ichi Ohmichi7e3ccd52015-04-06 23:55:46 +000088 resp, body = cls.client.show_queue_stats(queue_name)
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010089 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000090
91 @classmethod
92 def get_queue_metadata(cls, queue_name):
93 """Wrapper utility that gets a queue metadata."""
Ken'ichi Ohmichi7e3ccd52015-04-06 23:55:46 +000094 resp, body = cls.client.show_queue_metadata(queue_name)
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010095 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000096
97 @classmethod
98 def set_queue_metadata(cls, queue_name, rbody):
99 """Wrapper utility that sets the metadata of a queue."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100100 resp, body = cls.client.set_queue_metadata(queue_name, rbody)
101 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400102
103 @classmethod
104 def post_messages(cls, queue_name, rbody):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300105 """Wrapper utility that posts messages to a queue."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100106 resp, body = cls.client.post_messages(queue_name, rbody)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400107
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100108 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400109
110 @classmethod
111 def list_messages(cls, queue_name):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300112 """Wrapper utility that lists the messages in a queue."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100113 resp, body = cls.client.list_messages(queue_name)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400114
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100115 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400116
117 @classmethod
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400118 def delete_messages(cls, message_uri):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300119 """Wrapper utility that deletes messages."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100120 resp, body = cls.client.delete_messages(message_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400121
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100122 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400123
124 @classmethod
125 def post_claims(cls, queue_name, rbody, url_params=False):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300126 """Wrapper utility that claims messages."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100127 resp, body = cls.client.post_claims(
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400128 queue_name, rbody, url_params=False)
129
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100130 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400131
132 @classmethod
133 def query_claim(cls, claim_uri):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300134 """Wrapper utility that gets a claim."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100135 resp, body = cls.client.query_claim(claim_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 update_claim(cls, claim_uri, rbody):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300141 """Wrapper utility that updates a claim."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100142 resp, body = cls.client.update_claim(claim_uri, rbody)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400143
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100144 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400145
146 @classmethod
147 def release_claim(cls, claim_uri):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300148 """Wrapper utility that deletes a claim."""
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100149 resp, body = cls.client.release_claim(claim_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400150
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100151 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400152
153 @classmethod
154 def generate_message_body(cls, repeat=1):
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300155 """Wrapper utility that sets the metadata of a queue."""
156 message_ttl = data_utils.\
157 rand_int_id(start=60, end=CONF.messaging.max_message_ttl)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400158
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -0300159 key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
160 value = data_utils.arbitrary_string(size=20,
161 base_text='MessagingValue')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400162 message_body = {key: value}
163
164 rbody = ([{'body': message_body, 'ttl': message_ttl}] * repeat)
165 return rbody