blob: 41a02f25ae7f9c396f4fd714b376763795cd5051 [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
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040016from tempest.common.utils import data_utils
Malini Kamalambal6e7b3b82014-02-06 06:49:04 -050017from tempest import config
18from tempest.openstack.common import log as logging
19from tempest import test
20
21CONF = config.CONF
22
23LOG = logging.getLogger(__name__)
24
25
26class BaseQueuingTest(test.BaseTestCase):
27
28 """
Malini Kamalambal8681e922014-08-18 10:10:45 -040029 Base class for the Queuing tests that use the Tempest Zaqar REST client
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
34 queuing as True
35 """
36
37 @classmethod
38 def setUpClass(cls):
39 super(BaseQueuingTest, cls).setUpClass()
Malini Kamalambal8681e922014-08-18 10:10:45 -040040 if not CONF.service_available.zaqar:
41 raise cls.skipException("Zaqar support is required")
Malini Kamalambal6e7b3b82014-02-06 06:49:04 -050042 os = cls.get_client_manager()
43 cls.queuing_cfg = CONF.queuing
44 cls.client = os.queuing_client
45
46 @classmethod
47 def create_queue(cls, queue_name):
48 """Wrapper utility that returns a test queue."""
49 resp, body = cls.client.create_queue(queue_name)
50 return resp, body
Jorge Chai4f5896e2014-02-17 14:34:54 -050051
52 @classmethod
53 def delete_queue(cls, queue_name):
Jorge Chai83ba4ee2014-04-15 18:58:08 +000054 """Wrapper utility that deletes a test queue."""
Jorge Chai4f5896e2014-02-17 14:34:54 -050055 resp, body = cls.client.delete_queue(queue_name)
56 return resp, body
Jorge Chai83ba4ee2014-04-15 18:58:08 +000057
58 @classmethod
59 def check_queue_exists(cls, queue_name):
60 """Wrapper utility that checks the existence of a test queue."""
61 resp, body = cls.client.get_queue(queue_name)
62 return resp, body
63
64 @classmethod
65 def check_queue_exists_head(cls, queue_name):
66 """Wrapper utility checks the head of a queue via http HEAD."""
67 resp, body = cls.client.head_queue(queue_name)
68 return resp, body
69
70 @classmethod
71 def list_queues(cls):
72 """Wrapper utility that lists queues."""
73 resp, body = cls.client.list_queues()
74 return resp, body
75
76 @classmethod
77 def get_queue_stats(cls, queue_name):
78 """Wrapper utility that returns the queue stats."""
79 resp, body = cls.client.get_queue_stats(queue_name)
80 return resp, body
81
82 @classmethod
83 def get_queue_metadata(cls, queue_name):
84 """Wrapper utility that gets a queue metadata."""
85 resp, body = cls.client.get_queue_metadata(queue_name)
86 return resp, body
87
88 @classmethod
89 def set_queue_metadata(cls, queue_name, rbody):
90 """Wrapper utility that sets the metadata of a queue."""
91 resp, body = cls.client.set_queue_metadata(queue_name, rbody)
92 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040093
94 @classmethod
95 def post_messages(cls, queue_name, rbody):
96 '''Wrapper utility that posts messages to a queue.'''
97 resp, body = cls.client.post_messages(queue_name, rbody)
98
99 return resp, body
100
101 @classmethod
102 def list_messages(cls, queue_name):
103 '''Wrapper utility that lists the messages in a queue.'''
104 resp, body = cls.client.list_messages(queue_name)
105
106 return resp, body
107
108 @classmethod
109 def get_single_message(cls, message_uri):
110 '''Wrapper utility that gets a single message.'''
111 resp, body = cls.client.get_single_message(message_uri)
112
113 return resp, body
114
115 @classmethod
116 def get_multiple_messages(cls, message_uri):
117 '''Wrapper utility that gets multiple messages.'''
118 resp, body = cls.client.get_multiple_messages(message_uri)
119
120 return resp, body
121
122 @classmethod
123 def delete_messages(cls, message_uri):
124 '''Wrapper utility that deletes messages.'''
125 resp, body = cls.client.delete_messages(message_uri)
126
127 return resp, body
128
129 @classmethod
130 def post_claims(cls, queue_name, rbody, url_params=False):
131 '''Wrapper utility that claims messages.'''
132 resp, body = cls.client.post_claims(
133 queue_name, rbody, url_params=False)
134
135 return resp, body
136
137 @classmethod
138 def query_claim(cls, claim_uri):
139 '''Wrapper utility that gets a claim.'''
140 resp, body = cls.client.query_claim(claim_uri)
141
142 return resp, body
143
144 @classmethod
145 def update_claim(cls, claim_uri, rbody):
146 '''Wrapper utility that updates a claim.'''
147 resp, body = cls.client.update_claim(claim_uri, rbody)
148
149 return resp, body
150
151 @classmethod
152 def release_claim(cls, claim_uri):
153 '''Wrapper utility that deletes a claim.'''
154 resp, body = cls.client.release_claim(claim_uri)
155
156 return resp, body
157
158 @classmethod
159 def generate_message_body(cls, repeat=1):
160 '''Wrapper utility that sets the metadata of a queue.'''
161 message_ttl = data_utils.rand_int_id(start=60,
162 end=CONF.queuing.max_message_ttl)
163
164 key = data_utils.arbitrary_string(size=20, base_text='QueuingKey')
165 value = data_utils.arbitrary_string(size=20, base_text='QueuingValue')
166 message_body = {key: value}
167
168 rbody = ([{'body': message_body, 'ttl': message_ttl}] * repeat)
169 return rbody