blob: 1aab8d2acde568317541e0eb5be26a6efef9bc80 [file] [log] [blame]
Malini Kamalambal7458b4b2014-05-29 11:47:28 -04001# 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
16import logging
17import urlparse
18
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050019from tempest_lib import decorators
20
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030021from tempest.api.messaging import base
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040022from tempest.common.utils import data_utils
23from tempest import config
24from tempest import test
25
26
27LOG = logging.getLogger(__name__)
28CONF = config.CONF
29
30
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030031class TestClaims(base.BaseMessagingTest):
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040032 _interface = 'json'
33
34 @classmethod
Andrea Frittoli23ee1c62014-09-15 13:14:54 +010035 def resource_setup(cls):
36 super(TestClaims, cls).resource_setup()
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040037 cls.queue_name = data_utils.rand_name('Queues-Test')
38 # Create Queue
39 cls.create_queue(cls.queue_name)
40
41 def _post_and_claim_messages(self, queue_name, repeat=1):
42 # Post Messages
43 message_body = self.generate_message_body(repeat=repeat)
44 self.client.post_messages(queue_name=self.queue_name,
45 rbody=message_body)
46
47 # Post Claim
48 claim_ttl = data_utils.rand_int_id(start=60,
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030049 end=CONF.messaging.max_claim_ttl)
50 claim_grace = data_utils.\
51 rand_int_id(start=60, end=CONF.messaging.max_claim_grace)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040052 claim_body = {"ttl": claim_ttl, "grace": claim_grace}
53 resp, body = self.client.post_claims(queue_name=self.queue_name,
54 rbody=claim_body)
55
56 return resp, body
57
58 @test.attr(type='smoke')
59 def test_post_claim(self):
60 _, body = self._post_and_claim_messages(queue_name=self.queue_name)
61 claimed_message_uri = body[0]['href']
62
63 # Skipping this step till bug-1331517 is fixed
64 # Get posted claim
65 # self.client.query_claim(claimed_message_uri)
66
67 # Delete Claimed message
68 self.client.delete_messages(claimed_message_uri)
69
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050070 @decorators.skip_because(bug="1331517")
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040071 @test.attr(type='smoke')
72 def test_query_claim(self):
73 # Post a Claim
74 resp, body = self._post_and_claim_messages(queue_name=self.queue_name)
75
76 # Query Claim
77 claim_uri = resp['location']
78 self.client.query_claim(claim_uri)
79
80 # Delete Claimed message
81 claimed_message_uri = body[0]['href']
82 self.delete_messages(claimed_message_uri)
83
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050084 @decorators.skip_because(bug="1328111")
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040085 @test.attr(type='smoke')
86 def test_update_claim(self):
87 # Post a Claim
88 resp, body = self._post_and_claim_messages(queue_name=self.queue_name)
89
90 claim_uri = resp['location']
91 claimed_message_uri = body[0]['href']
92
93 # Update Claim
94 claim_ttl = data_utils.rand_int_id(start=60,
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030095 end=CONF.messaging.max_claim_ttl)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040096 update_rbody = {"ttl": claim_ttl}
97
98 self.client.update_claim(claim_uri, rbody=update_rbody)
99
100 # Verify claim ttl >= updated ttl value
101 _, body = self.client.query_claim(claim_uri)
102 updated_claim_ttl = body["ttl"]
103 self.assertTrue(updated_claim_ttl >= claim_ttl)
104
105 # Delete Claimed message
106 self.client.delete_messages(claimed_message_uri)
107
108 @test.attr(type='smoke')
109 def test_release_claim(self):
110 # Post a Claim
111 resp, body = self._post_and_claim_messages(queue_name=self.queue_name)
112 claim_uri = resp['location']
113
114 # Release Claim
115 self.client.release_claim(claim_uri)
116
117 # Delete Claimed message
118 # This will implicitly verify that the claim is deleted.
119 message_uri = urlparse.urlparse(claim_uri).path
120 self.client.delete_messages(message_uri)
121
122 @classmethod
Andrea Frittoli23ee1c62014-09-15 13:14:54 +0100123 def resource_cleanup(cls):
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400124 cls.delete_queue(cls.queue_name)
Andrea Frittoli23ee1c62014-09-15 13:14:54 +0100125 super(TestClaims, cls).resource_cleanup()