blob: 99edde179cde74c6e190fb552c312b85c9a52239 [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
Matthew Treinishf077dd22015-04-23 09:37:41 -040016from six.moves.urllib import parse as urlparse
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050017from tempest_lib import decorators
18
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030019from tempest.api.messaging import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120020from tempest.common.utils import data_utils
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040021from tempest import config
22from tempest import test
23
24
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040025CONF = config.CONF
26
27
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030028class TestClaims(base.BaseMessagingTest):
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040029
30 @classmethod
Andrea Frittoli23ee1c62014-09-15 13:14:54 +010031 def resource_setup(cls):
32 super(TestClaims, cls).resource_setup()
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040033 cls.queue_name = data_utils.rand_name('Queues-Test')
34 # Create Queue
35 cls.create_queue(cls.queue_name)
36
37 def _post_and_claim_messages(self, queue_name, repeat=1):
38 # Post Messages
39 message_body = self.generate_message_body(repeat=repeat)
40 self.client.post_messages(queue_name=self.queue_name,
41 rbody=message_body)
42
43 # Post Claim
44 claim_ttl = data_utils.rand_int_id(start=60,
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030045 end=CONF.messaging.max_claim_ttl)
46 claim_grace = data_utils.\
47 rand_int_id(start=60, end=CONF.messaging.max_claim_grace)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040048 claim_body = {"ttl": claim_ttl, "grace": claim_grace}
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010049 resp, body = self.client.post_claims(queue_name=self.queue_name,
50 rbody=claim_body)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040051
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010052 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040053
54 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080055 @test.idempotent_id('936cb1ca-b7af-44dd-a752-805e8c98156f')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040056 def test_post_claim(self):
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010057 _, body = self._post_and_claim_messages(queue_name=self.queue_name)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040058 claimed_message_uri = body[0]['href']
59
60 # Skipping this step till bug-1331517 is fixed
61 # Get posted claim
62 # self.client.query_claim(claimed_message_uri)
63
64 # Delete Claimed message
65 self.client.delete_messages(claimed_message_uri)
66
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050067 @decorators.skip_because(bug="1331517")
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040068 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080069 @test.idempotent_id('84e491f4-68c6-451f-9846-b8f868eb27c5')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040070 def test_query_claim(self):
71 # Post a Claim
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010072 resp, body = self._post_and_claim_messages(queue_name=self.queue_name)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040073
74 # Query Claim
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010075 claim_uri = resp['location']
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040076 self.client.query_claim(claim_uri)
77
78 # Delete Claimed message
79 claimed_message_uri = body[0]['href']
80 self.delete_messages(claimed_message_uri)
81
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050082 @decorators.skip_because(bug="1328111")
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040083 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080084 @test.idempotent_id('420ef0c5-9bd6-4b82-b06d-d9da330fefd3')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040085 def test_update_claim(self):
86 # Post a Claim
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010087 resp, body = self._post_and_claim_messages(queue_name=self.queue_name)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040088
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010089 claim_uri = resp['location']
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040090 claimed_message_uri = body[0]['href']
91
92 # Update Claim
93 claim_ttl = data_utils.rand_int_id(start=60,
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030094 end=CONF.messaging.max_claim_ttl)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040095 update_rbody = {"ttl": claim_ttl}
96
97 self.client.update_claim(claim_uri, rbody=update_rbody)
98
99 # Verify claim ttl >= updated ttl value
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100100 _, body = self.client.query_claim(claim_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400101 updated_claim_ttl = body["ttl"]
102 self.assertTrue(updated_claim_ttl >= claim_ttl)
103
104 # Delete Claimed message
105 self.client.delete_messages(claimed_message_uri)
106
107 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800108 @test.idempotent_id('fd4c7921-cb3f-4ed8-9ac8-e8f1e74c44aa')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400109 def test_release_claim(self):
110 # Post a Claim
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100111 resp, body = self._post_and_claim_messages(queue_name=self.queue_name)
112 claim_uri = resp['location']
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400113
114 # Release Claim
Ken'ichi Ohmichib8461cb2015-11-20 08:10:51 +0000115 self.client.delete_claim(claim_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400116
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()