blob: 61f1bfabb31c1de9403bacdd85a9ba4b251a8b99 [file] [log] [blame]
Thomas Herved60ebed2016-01-25 13:21:17 +01001# 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
13import uuid
14
rabi5200ac72017-08-11 09:49:49 +053015from zaqarclient.queues.v2 import client as zaqarclient
Thomas Herved60ebed2016-01-25 13:21:17 +010016
rabie7872e72017-08-11 16:37:48 +053017from heat_integrationtests.common import test
Thomas Herved60ebed2016-01-25 13:21:17 +010018from heat_integrationtests.functional import functional_base
19
20
21class ZaqarEventSinkTest(functional_base.FunctionalTestsBase):
22 template = '''
23heat_template_version: "2013-05-23"
24resources:
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,
rabibe38c302017-04-11 09:54:07 +053046 'os_project_name': self.conf.project_name,
rabi133ee5f2016-12-01 09:54:37 +053047 '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 Herved60ebed2016-01-25 13:21:17 +010052 }
53 }
54 }
55
rabi5200ac72017-08-11 09:49:49 +053056 zaqar = zaqarclient.Client(conf=conf)
Thomas Herved60ebed2016-01-25 13:21:17 +010057 queue = zaqar.queue(queue_id)
rabie7872e72017-08-11 16:37:48 +053058
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))