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