blob: c9064b0628605a008ac59c6fdd78b73826f509d8 [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
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')
58 def test_post_claim(self):
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010059 _, body = self._post_and_claim_messages(queue_name=self.queue_name)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040060 claimed_message_uri = body[0]['href']
61
62 # Skipping this step till bug-1331517 is fixed
63 # Get posted claim
64 # self.client.query_claim(claimed_message_uri)
65
66 # Delete Claimed message
67 self.client.delete_messages(claimed_message_uri)
68
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050069 @decorators.skip_because(bug="1331517")
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040070 @test.attr(type='smoke')
71 def test_query_claim(self):
72 # Post a Claim
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010073 resp, body = self._post_and_claim_messages(queue_name=self.queue_name)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040074
75 # Query Claim
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010076 claim_uri = resp['location']
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040077 self.client.query_claim(claim_uri)
78
79 # Delete Claimed message
80 claimed_message_uri = body[0]['href']
81 self.delete_messages(claimed_message_uri)
82
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050083 @decorators.skip_because(bug="1328111")
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040084 @test.attr(type='smoke')
85 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')
108 def test_release_claim(self):
109 # Post a Claim
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100110 resp, body = self._post_and_claim_messages(queue_name=self.queue_name)
111 claim_uri = resp['location']
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400112
113 # Release Claim
114 self.client.release_claim(claim_uri)
115
116 # Delete Claimed message
117 # This will implicitly verify that the claim is deleted.
118 message_uri = urlparse.urlparse(claim_uri).path
119 self.client.delete_messages(message_uri)
120
121 @classmethod
Andrea Frittoli23ee1c62014-09-15 13:14:54 +0100122 def resource_cleanup(cls):
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400123 cls.delete_queue(cls.queue_name)
Andrea Frittoli23ee1c62014-09-15 13:14:54 +0100124 super(TestClaims, cls).resource_cleanup()