blob: e54bed112cc01ed96d6bc1cfe4775289ca067590 [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
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040017
Matthew Treinishf077dd22015-04-23 09:37:41 -040018from six.moves.urllib import parse as urlparse
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
Fei Long Wangd39431f2015-05-14 11:30:48 +120022from tempest.common.utils import data_utils
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040023from 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
33 @classmethod
Andrea Frittoli23ee1c62014-09-15 13:14:54 +010034 def resource_setup(cls):
35 super(TestClaims, cls).resource_setup()
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040036 cls.queue_name = data_utils.rand_name('Queues-Test')
37 # Create Queue
38 cls.create_queue(cls.queue_name)
39
40 def _post_and_claim_messages(self, queue_name, repeat=1):
41 # Post Messages
42 message_body = self.generate_message_body(repeat=repeat)
43 self.client.post_messages(queue_name=self.queue_name,
44 rbody=message_body)
45
46 # Post Claim
47 claim_ttl = data_utils.rand_int_id(start=60,
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030048 end=CONF.messaging.max_claim_ttl)
49 claim_grace = data_utils.\
50 rand_int_id(start=60, end=CONF.messaging.max_claim_grace)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040051 claim_body = {"ttl": claim_ttl, "grace": claim_grace}
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010052 resp, body = self.client.post_claims(queue_name=self.queue_name,
53 rbody=claim_body)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040054
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010055 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040056
57 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080058 @test.idempotent_id('936cb1ca-b7af-44dd-a752-805e8c98156f')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040059 def test_post_claim(self):
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010060 _, body = self._post_and_claim_messages(queue_name=self.queue_name)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040061 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')
Chris Hoge7579c1a2015-02-26 14:12:15 -080072 @test.idempotent_id('84e491f4-68c6-451f-9846-b8f868eb27c5')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040073 def test_query_claim(self):
74 # Post a Claim
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010075 resp, body = self._post_and_claim_messages(queue_name=self.queue_name)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040076
77 # Query Claim
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010078 claim_uri = resp['location']
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040079 self.client.query_claim(claim_uri)
80
81 # Delete Claimed message
82 claimed_message_uri = body[0]['href']
83 self.delete_messages(claimed_message_uri)
84
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050085 @decorators.skip_because(bug="1328111")
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040086 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080087 @test.idempotent_id('420ef0c5-9bd6-4b82-b06d-d9da330fefd3')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040088 def test_update_claim(self):
89 # Post a Claim
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010090 resp, body = self._post_and_claim_messages(queue_name=self.queue_name)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040091
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010092 claim_uri = resp['location']
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040093 claimed_message_uri = body[0]['href']
94
95 # Update Claim
96 claim_ttl = data_utils.rand_int_id(start=60,
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030097 end=CONF.messaging.max_claim_ttl)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040098 update_rbody = {"ttl": claim_ttl}
99
100 self.client.update_claim(claim_uri, rbody=update_rbody)
101
102 # Verify claim ttl >= updated ttl value
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100103 _, body = self.client.query_claim(claim_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400104 updated_claim_ttl = body["ttl"]
105 self.assertTrue(updated_claim_ttl >= claim_ttl)
106
107 # Delete Claimed message
108 self.client.delete_messages(claimed_message_uri)
109
110 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800111 @test.idempotent_id('fd4c7921-cb3f-4ed8-9ac8-e8f1e74c44aa')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400112 def test_release_claim(self):
113 # Post a Claim
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100114 resp, body = self._post_and_claim_messages(queue_name=self.queue_name)
115 claim_uri = resp['location']
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400116
117 # Release Claim
118 self.client.release_claim(claim_uri)
119
120 # Delete Claimed message
121 # This will implicitly verify that the claim is deleted.
122 message_uri = urlparse.urlparse(claim_uri).path
123 self.client.delete_messages(message_uri)
124
125 @classmethod
Andrea Frittoli23ee1c62014-09-15 13:14:54 +0100126 def resource_cleanup(cls):
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400127 cls.delete_queue(cls.queue_name)
Andrea Frittoli23ee1c62014-09-15 13:14:54 +0100128 super(TestClaims, cls).resource_cleanup()