blob: e4a23ff6fc23d135db5f33c5d9f2c4c2dbf8b007 [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,
46 'os_auth_url': self.conf.auth_url
47 }
48 }
49 }
50
51 zaqar = zaqarclient.Client(conf=conf, version=1.1)
52 queue = zaqar.queue(queue_id)
53 messages = list(queue.messages())
54 self.assertEqual(4, len(messages))
55 types = [m.body['type'] for m in messages]
56 self.assertEqual(['os.heat.event'] * 4, types)
57 resources = set([m.body['payload']['resource_name'] for m in messages])
58 self.assertEqual(set([stack_name, 'test_resource']), resources)
59 stack_ids = [m.body['payload']['stack_id'] for m in messages]
60 self.assertEqual([stack_id] * 4, stack_ids)
61 statuses = [m.body['payload']['resource_status'] for m in messages]
Thomas Herve9480c0e2016-02-24 13:08:06 +010062 statuses.sort()
Thomas Herved60ebed2016-01-25 13:21:17 +010063 self.assertEqual(
Thomas Herve9480c0e2016-02-24 13:08:06 +010064 ['COMPLETE', 'COMPLETE', 'IN_PROGRESS', 'IN_PROGRESS'], statuses)
Thomas Herved60ebed2016-01-25 13:21:17 +010065 actions = [m.body['payload']['resource_action'] for m in messages]
66 self.assertEqual(['CREATE'] * 4, actions)