From c6df105245cac2e694a2dc53ae1ec32be7c8ce43 Mon Sep 17 00:00:00 2001 From: Thomas Herve Date: Wed, 8 Jun 2016 16:06:28 +0200 Subject: [PATCH] Add a trust notifier task This adds the ability to send keystone authentified notifications using trusts. To do so, you specify the posted URL with the "trust+" prefix, and Zaqar will create and store a trust when subscribing to a queue, if the trust not provided in the subscription options It also add a capability to the webhook task to be able to send more structured data in the notification, allowing to include the Zaqar message in the data. blueprint mistral-notifications DocImpact Change-Id: I12b9c1b34cdd220fcf1bdc2720043d4a8f75dc85 --- .../api_schema/response/v2/queues.py | 4 +-- .../tests/v2/test_subscriptions.py | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/zaqar/tests/tempest_plugin/api_schema/response/v2/queues.py b/zaqar/tests/tempest_plugin/api_schema/response/v2/queues.py index 4a10efe..e22ffaa 100644 --- a/zaqar/tests/tempest_plugin/api_schema/response/v2/queues.py +++ b/zaqar/tests/tempest_plugin/api_schema/response/v2/queues.py @@ -130,7 +130,7 @@ message_ttl = { list_messages_links = { 'type': 'array', 'maxItems': 1, - 'minItems': 1, + 'minItems': 0, 'items': { 'type': 'object', 'properties': { @@ -143,7 +143,7 @@ list_messages_links = { list_messages_response = { 'type': 'array', - 'minItems': 1, + 'minItems': 0, 'items': { 'type': 'object', 'properties': { diff --git a/zaqar/tests/tempest_plugin/tests/v2/test_subscriptions.py b/zaqar/tests/tempest_plugin/tests/v2/test_subscriptions.py index 47c6f34..303af38 100644 --- a/zaqar/tests/tempest_plugin/tests/v2/test_subscriptions.py +++ b/zaqar/tests/tempest_plugin/tests/v2/test_subscriptions.py @@ -13,9 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +import json +import uuid from tempest.common.utils import data_utils from tempest.lib import decorators +from tempest import test from zaqar.tests.tempest_plugin.tests import base @@ -91,6 +94,32 @@ class TestSubscriptions(base.BaseV2MessagingTest): subscription_id = result[1]["subscription_id"] self.delete_subscription(self.queue_name, subscription_id) + @decorators.idempotent_id('ff4344b4-ba78-44c5-9ffc-44e53e484f76') + def test_trust_subscription(self): + sub_queue = data_utils.rand_name('Queues-Test') + self.addCleanup(self.client.delete_queue, sub_queue) + subscriber = 'trust+{0}/{1}/queues/{2}/messages'.format( + self.client.base_url, self.client.uri_prefix, sub_queue) + post_body = json.dumps( + {'messages': [{'body': '$zaqar_message$', 'ttl': 60}]}) + post_headers = {'X-Project-ID': self.client.tenant_id, + 'Client-ID': str(uuid.uuid4())} + sub_body = {'ttl': 1200, 'subscriber': subscriber, + 'options': {'post_data': post_body, + 'post_headers': post_headers}} + + self.create_subscription(queue_name=self.queue_name, rbody=sub_body) + message_body = self.generate_message_body() + self.post_messages(queue_name=self.queue_name, rbody=message_body) + + if not test.call_until_true( + lambda: self.list_messages(sub_queue)[1]['messages'], 10, 1): + self.fail("Couldn't get messages") + messages = self.list_messages(sub_queue) + expected = message_body['messages'][0] + expected['queue_name'] = self.queue_name + self.assertEqual(expected, messages[1]['messages'][0]['body']) + @classmethod def resource_cleanup(cls): cls.delete_queue(cls.queue_name)