blob: 3638fab758fdb7026101a370cad5f6a4c34dea5a [file] [log] [blame]
James Combs775a1382015-08-31 20:50:51 +00001# 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
13from heat_integrationtests.functional import functional_base
14
15
16class StackEventsTest(functional_base.FunctionalTestsBase):
17
18 template = '''
19heat_template_version: 2014-10-16
20parameters:
21resources:
22 test_resource:
23 type: OS::Heat::TestResource
24 properties:
25 value: 'test1'
26 fail: False
27 update_replace: False
28 wait_secs: 0
29outputs:
30 resource_id:
31 description: 'ID of resource'
32 value: { get_resource: test_resource }
33'''
34
James Combs775a1382015-08-31 20:50:51 +000035 def _verify_event_fields(self, event, event_characteristics):
36 self.assertIsNotNone(event_characteristics)
37 self.assertIsNotNone(event.event_time)
38 self.assertIsNotNone(event.links)
39 self.assertIsNotNone(event.logical_resource_id)
40 self.assertIsNotNone(event.resource_status)
41 self.assertIn(event.resource_status, event_characteristics[1])
42 self.assertIsNotNone(event.resource_status_reason)
43 self.assertIsNotNone(event.id)
44
45 def test_event(self):
46 parameters = {}
47
48 test_stack_name = self._stack_rand_name()
49 stack_identifier = self.stack_create(
50 stack_name=test_stack_name,
51 template=self.template,
52 parameters=parameters
53 )
54
55 expected_status = ['CREATE_IN_PROGRESS', 'CREATE_COMPLETE']
56 event_characteristics = {
57 test_stack_name: ('OS::Heat::Stack', expected_status),
58 'test_resource': ('OS::Heat::TestResource', expected_status)}
59
60 # List stack events
61 # API: GET /v1/{tenant_id}/stacks/{stack_name}/{stack_id}/events
62 stack_events = self.client.events.list(stack_identifier)
63
64 for stack_event in stack_events:
65 # Key on an expected/valid resource name
66 self._verify_event_fields(
67 stack_event,
68 event_characteristics[stack_event.resource_name])
69
70 # Test the event filtering API based on this resource_name
71 # /v1/{tenant_id}/stacks/{stack_name}/{stack_id}/resources/{resource_name}/events
72 resource_events = self.client.events.list(
73 stack_identifier,
74 stack_event.resource_name)
75
76 # Resource events are a subset of the original stack event list
77 self.assertTrue(len(resource_events) < len(stack_events))
78
79 # Get the event details for each resource event
80 for resource_event in resource_events:
81 # A resource_event should be in the original stack event list
82 self.assertIn(resource_event, stack_events)
83 # Given a filtered list, the resource names should be identical
84 self.assertEqual(
85 resource_event.resource_name,
86 stack_event.resource_name)
87 # Verify all fields, keying off the resource_name
88 self._verify_event_fields(
89 resource_event,
90 event_characteristics[resource_event.resource_name])
91
92 # Exercise the event details API
93 # /v1/{tenant_id}/stacks/{stack_name}/{stack_id}/resources/{resource_name}/events/{event_id}
94 event_details = self.client.events.get(
95 stack_identifier,
96 resource_event.resource_name,
97 resource_event.id)
98 self._verify_event_fields(
99 event_details,
100 event_characteristics[event_details.resource_name])
101 # The names should be identical to the non-detailed event
102 self.assertEqual(
103 resource_event.resource_name,
104 event_details.resource_name)
105 # Verify the extra field in the detail results
106 self.assertIsNotNone(event_details.resource_type)
107 self.assertEqual(
108 event_characteristics[event_details.resource_name][0],
109 event_details.resource_type)