blob: ea66b7db3328264db0cb309e598c4b5490daf2a9 [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
15from zaqarclient.queues.v1 import client as zaqarclient
16
17from heat_integrationtests.functional import functional_base
18
19
20class ZaqarEventSinkTest(functional_base.FunctionalTestsBase):
21 template = '''
22heat_template_version: "2013-05-23"
23resources:
24 test_resource:
25 type: OS::Heat::TestResource
26 properties:
27 value: ok
28'''
29
30 def test_events(self):
31 queue_id = str(uuid.uuid4())
32 environment = {'event_sinks': [{'type': 'zaqar-queue',
33 'target': queue_id,
34 'ttl': 120}]}
35 stack_identifier = self.stack_create(
36 template=self.template,
37 environment=environment)
38 stack_name, stack_id = stack_identifier.split('/')
39 conf = {
40 'auth_opts': {
41 'backend': 'keystone',
42 'options': {
43 'os_username': self.conf.username,
44 'os_password': self.conf.password,
45 'os_project_name': self.conf.tenant_name,
rabi133ee5f2016-12-01 09:54:37 +053046 'os_auth_url': self.conf.auth_url,
47 'os_user_domain_id': self.conf.user_domain_id,
48 'os_project_domain_id': self.conf.project_domain_id,
49 'os_user_domain_name': self.conf.user_domain_name,
50 'os_project_domain_name': self.conf.project_domain_name
Thomas Herved60ebed2016-01-25 13:21:17 +010051 }
52 }
53 }
54
55 zaqar = zaqarclient.Client(conf=conf, version=1.1)
56 queue = zaqar.queue(queue_id)
57 messages = list(queue.messages())
58 self.assertEqual(4, len(messages))
59 types = [m.body['type'] for m in messages]
60 self.assertEqual(['os.heat.event'] * 4, types)
61 resources = set([m.body['payload']['resource_name'] for m in messages])
62 self.assertEqual(set([stack_name, 'test_resource']), resources)
63 stack_ids = [m.body['payload']['stack_id'] for m in messages]
64 self.assertEqual([stack_id] * 4, stack_ids)
65 statuses = [m.body['payload']['resource_status'] for m in messages]
Thomas Herve9480c0e2016-02-24 13:08:06 +010066 statuses.sort()
Thomas Herved60ebed2016-01-25 13:21:17 +010067 self.assertEqual(
Thomas Herve9480c0e2016-02-24 13:08:06 +010068 ['COMPLETE', 'COMPLETE', 'IN_PROGRESS', 'IN_PROGRESS'], statuses)
Thomas Herved60ebed2016-01-25 13:21:17 +010069 actions = [m.body['payload']['resource_action'] for m in messages]
70 self.assertEqual(['CREATE'] * 4, actions)