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 | |
| 16 | import logging |
| 17 | import urlparse |
| 18 | |
Matthew Treinish | c49fcbe | 2015-02-05 23:37:34 -0500 | [diff] [blame] | 19 | from tempest_lib import decorators |
| 20 | |
Victoria Martínez de la Cruz | 1173b6e | 2014-09-22 18:32:13 -0300 | [diff] [blame] | 21 | from tempest.api.messaging import base |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 22 | from tempest.common.utils import data_utils |
| 23 | from tempest import config |
| 24 | from tempest import test |
| 25 | |
| 26 | |
| 27 | LOG = logging.getLogger(__name__) |
| 28 | CONF = config.CONF |
| 29 | |
| 30 | |
Victoria Martínez de la Cruz | 1173b6e | 2014-09-22 18:32:13 -0300 | [diff] [blame] | 31 | class TestClaims(base.BaseMessagingTest): |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 32 | _interface = 'json' |
| 33 | |
| 34 | @classmethod |
Andrea Frittoli | 23ee1c6 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 35 | def resource_setup(cls): |
| 36 | super(TestClaims, cls).resource_setup() |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 37 | 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 Cruz | 1173b6e | 2014-09-22 18:32:13 -0300 | [diff] [blame] | 49 | end=CONF.messaging.max_claim_ttl) |
| 50 | claim_grace = data_utils.\ |
| 51 | rand_int_id(start=60, end=CONF.messaging.max_claim_grace) |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 52 | 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 Treinish | c49fcbe | 2015-02-05 23:37:34 -0500 | [diff] [blame] | 70 | @decorators.skip_because(bug="1331517") |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 71 | @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 Treinish | c49fcbe | 2015-02-05 23:37:34 -0500 | [diff] [blame] | 84 | @decorators.skip_because(bug="1328111") |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 85 | @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 Cruz | 1173b6e | 2014-09-22 18:32:13 -0300 | [diff] [blame] | 95 | end=CONF.messaging.max_claim_ttl) |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 96 | 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 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() |