Thomas Herve | d60ebed | 2016-01-25 13:21:17 +0100 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | # not use this file except in compliance with the License. You may obtain |
| 3 | # a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | # License for the specific language governing permissions and limitations |
| 11 | # under the License. |
| 12 | |
| 13 | import uuid |
| 14 | |
rabi | 5200ac7 | 2017-08-11 09:49:49 +0530 | [diff] [blame] | 15 | from zaqarclient.queues.v2 import client as zaqarclient |
Thomas Herve | d60ebed | 2016-01-25 13:21:17 +0100 | [diff] [blame] | 16 | |
rabi | e7872e7 | 2017-08-11 16:37:48 +0530 | [diff] [blame] | 17 | from heat_integrationtests.common import test |
Thomas Herve | d60ebed | 2016-01-25 13:21:17 +0100 | [diff] [blame] | 18 | from heat_integrationtests.functional import functional_base |
| 19 | |
| 20 | |
| 21 | class ZaqarEventSinkTest(functional_base.FunctionalTestsBase): |
| 22 | template = ''' |
| 23 | heat_template_version: "2013-05-23" |
| 24 | resources: |
| 25 | test_resource: |
| 26 | type: OS::Heat::TestResource |
| 27 | properties: |
| 28 | value: ok |
| 29 | ''' |
| 30 | |
| 31 | def test_events(self): |
| 32 | queue_id = str(uuid.uuid4()) |
| 33 | environment = {'event_sinks': [{'type': 'zaqar-queue', |
| 34 | 'target': queue_id, |
| 35 | 'ttl': 120}]} |
| 36 | stack_identifier = self.stack_create( |
| 37 | template=self.template, |
| 38 | environment=environment) |
| 39 | stack_name, stack_id = stack_identifier.split('/') |
| 40 | conf = { |
| 41 | 'auth_opts': { |
| 42 | 'backend': 'keystone', |
| 43 | 'options': { |
| 44 | 'os_username': self.conf.username, |
| 45 | 'os_password': self.conf.password, |
rabi | be38c30 | 2017-04-11 09:54:07 +0530 | [diff] [blame] | 46 | 'os_project_name': self.conf.project_name, |
rabi | 133ee5f | 2016-12-01 09:54:37 +0530 | [diff] [blame] | 47 | 'os_auth_url': self.conf.auth_url, |
| 48 | 'os_user_domain_id': self.conf.user_domain_id, |
| 49 | 'os_project_domain_id': self.conf.project_domain_id, |
| 50 | 'os_user_domain_name': self.conf.user_domain_name, |
| 51 | 'os_project_domain_name': self.conf.project_domain_name |
Thomas Herve | d60ebed | 2016-01-25 13:21:17 +0100 | [diff] [blame] | 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
rabi | 5200ac7 | 2017-08-11 09:49:49 +0530 | [diff] [blame] | 56 | zaqar = zaqarclient.Client(conf=conf) |
Thomas Herve | d60ebed | 2016-01-25 13:21:17 +0100 | [diff] [blame] | 57 | queue = zaqar.queue(queue_id) |
rabi | e7872e7 | 2017-08-11 16:37:48 +0530 | [diff] [blame] | 58 | |
| 59 | def validate_messages(): |
| 60 | messages = list(queue.messages()) |
| 61 | if len(messages) < 4: |
| 62 | return False |
| 63 | |
| 64 | types = [m.body['type'] for m in messages] |
| 65 | self.assertEqual(['os.heat.event'] * 4, types) |
| 66 | resources = set([m.body['payload'][ |
| 67 | 'resource_name'] for m in messages]) |
| 68 | self.assertEqual(set([stack_name, 'test_resource']), resources) |
| 69 | stack_ids = [m.body['payload']['stack_id'] for m in messages] |
| 70 | self.assertEqual([stack_id] * 4, stack_ids) |
| 71 | statuses = [m.body['payload']['resource_status'] for m in messages] |
| 72 | statuses.sort() |
| 73 | self.assertEqual(['COMPLETE', 'COMPLETE', |
| 74 | 'IN_PROGRESS', 'IN_PROGRESS'], statuses) |
| 75 | actions = [m.body['payload']['resource_action'] for m in messages] |
| 76 | self.assertEqual(['CREATE'] * 4, actions) |
| 77 | return True |
| 78 | |
| 79 | self.assertTrue(test.call_until_true(20, 0, validate_messages)) |