Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 1 | # 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 Treinish | f077dd2 | 2015-04-23 09:37:41 -0400 | [diff] [blame] | 16 | from six.moves.urllib import parse as urlparse |
Matthew Treinish | c49fcbe | 2015-02-05 23:37:34 -0500 | [diff] [blame] | 17 | from tempest_lib import decorators |
| 18 | |
Victoria Martínez de la Cruz | 1173b6e | 2014-09-22 18:32:13 -0300 | [diff] [blame] | 19 | from tempest.api.messaging import base |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 20 | from tempest.common.utils import data_utils |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 21 | from tempest import config |
| 22 | from tempest import test |
| 23 | |
| 24 | |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 25 | CONF = config.CONF |
| 26 | |
| 27 | |
Victoria Martínez de la Cruz | 1173b6e | 2014-09-22 18:32:13 -0300 | [diff] [blame] | 28 | class TestClaims(base.BaseMessagingTest): |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 29 | |
| 30 | @classmethod |
Andrea Frittoli | 23ee1c6 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 31 | def resource_setup(cls): |
| 32 | super(TestClaims, cls).resource_setup() |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 33 | 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 Cruz | 1173b6e | 2014-09-22 18:32:13 -0300 | [diff] [blame] | 45 | end=CONF.messaging.max_claim_ttl) |
| 46 | claim_grace = data_utils.\ |
| 47 | rand_int_id(start=60, end=CONF.messaging.max_claim_grace) |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 48 | claim_body = {"ttl": claim_ttl, "grace": claim_grace} |
Flavio Percoco | 5ee9f2f | 2015-02-25 08:36:09 +0100 | [diff] [blame] | 49 | resp, body = self.client.post_claims(queue_name=self.queue_name, |
| 50 | rbody=claim_body) |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 51 | |
Flavio Percoco | 5ee9f2f | 2015-02-25 08:36:09 +0100 | [diff] [blame] | 52 | return resp, body |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 53 | |
| 54 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 55 | @test.idempotent_id('936cb1ca-b7af-44dd-a752-805e8c98156f') |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 56 | def test_post_claim(self): |
Flavio Percoco | 5ee9f2f | 2015-02-25 08:36:09 +0100 | [diff] [blame] | 57 | _, body = self._post_and_claim_messages(queue_name=self.queue_name) |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 58 | 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 Treinish | c49fcbe | 2015-02-05 23:37:34 -0500 | [diff] [blame] | 67 | @decorators.skip_because(bug="1331517") |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 68 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 69 | @test.idempotent_id('84e491f4-68c6-451f-9846-b8f868eb27c5') |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 70 | def test_query_claim(self): |
| 71 | # Post a Claim |
Flavio Percoco | 5ee9f2f | 2015-02-25 08:36:09 +0100 | [diff] [blame] | 72 | resp, body = self._post_and_claim_messages(queue_name=self.queue_name) |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 73 | |
| 74 | # Query Claim |
Flavio Percoco | 5ee9f2f | 2015-02-25 08:36:09 +0100 | [diff] [blame] | 75 | claim_uri = resp['location'] |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 76 | 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 Treinish | c49fcbe | 2015-02-05 23:37:34 -0500 | [diff] [blame] | 82 | @decorators.skip_because(bug="1328111") |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 83 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 84 | @test.idempotent_id('420ef0c5-9bd6-4b82-b06d-d9da330fefd3') |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 85 | def test_update_claim(self): |
| 86 | # Post a Claim |
Flavio Percoco | 5ee9f2f | 2015-02-25 08:36:09 +0100 | [diff] [blame] | 87 | resp, body = self._post_and_claim_messages(queue_name=self.queue_name) |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 88 | |
Flavio Percoco | 5ee9f2f | 2015-02-25 08:36:09 +0100 | [diff] [blame] | 89 | claim_uri = resp['location'] |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 90 | 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 Cruz | 1173b6e | 2014-09-22 18:32:13 -0300 | [diff] [blame] | 94 | end=CONF.messaging.max_claim_ttl) |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 95 | 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 Percoco | 5ee9f2f | 2015-02-25 08:36:09 +0100 | [diff] [blame] | 100 | _, body = self.client.query_claim(claim_uri) |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 101 | 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 Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 108 | @test.idempotent_id('fd4c7921-cb3f-4ed8-9ac8-e8f1e74c44aa') |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 109 | def test_release_claim(self): |
| 110 | # Post a Claim |
Flavio Percoco | 5ee9f2f | 2015-02-25 08:36:09 +0100 | [diff] [blame] | 111 | resp, body = self._post_and_claim_messages(queue_name=self.queue_name) |
| 112 | claim_uri = resp['location'] |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 113 | |
| 114 | # Release Claim |
Ken'ichi Ohmichi | b8461cb | 2015-11-20 08:10:51 +0000 | [diff] [blame] | 115 | self.client.delete_claim(claim_uri) |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 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 Frittoli | 23ee1c6 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 123 | def resource_cleanup(cls): |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 124 | cls.delete_queue(cls.queue_name) |
Andrea Frittoli | 23ee1c6 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 125 | super(TestClaims, cls).resource_cleanup() |