tengqm | c0fffda | 2014-12-11 22:32:27 +0800 | [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 | |
Pavlo Shchelokovskyy | 60e0ecd | 2014-12-14 22:17:21 +0200 | [diff] [blame] | 13 | |
| 14 | from heatclient import exc |
tengqm | c0fffda | 2014-12-11 22:32:27 +0800 | [diff] [blame] | 15 | import six |
| 16 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 17 | from heat_integrationtests.functional import functional_base |
tengqm | c0fffda | 2014-12-11 22:32:27 +0800 | [diff] [blame] | 18 | |
tengqm | c0fffda | 2014-12-11 22:32:27 +0800 | [diff] [blame] | 19 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 20 | class RemoteStackTest(functional_base.FunctionalTestsBase): |
tengqm | c0fffda | 2014-12-11 22:32:27 +0800 | [diff] [blame] | 21 | template = ''' |
| 22 | heat_template_version: 2013-05-23 |
| 23 | resources: |
| 24 | my_stack: |
| 25 | type: OS::Heat::Stack |
| 26 | properties: |
| 27 | context: |
| 28 | region_name: RegionOne |
| 29 | template: |
| 30 | get_file: remote_stack.yaml |
| 31 | outputs: |
| 32 | key: |
| 33 | value: {get_attr: [my_stack, outputs]} |
| 34 | ''' |
| 35 | |
| 36 | remote_template = ''' |
| 37 | heat_template_version: 2013-05-23 |
| 38 | resources: |
| 39 | random1: |
| 40 | type: OS::Heat::RandomString |
| 41 | outputs: |
| 42 | remote_key: |
| 43 | value: {get_attr: [random1, value]} |
| 44 | ''' |
| 45 | |
| 46 | def setUp(self): |
| 47 | super(RemoteStackTest, self).setUp() |
Rabi Mishra | b0759cd | 2016-03-23 10:20:21 +0530 | [diff] [blame] | 48 | # replacing the template region with the one from the config |
| 49 | self.template = self.template.replace('RegionOne', |
| 50 | self.conf.region) |
tengqm | c0fffda | 2014-12-11 22:32:27 +0800 | [diff] [blame] | 51 | |
| 52 | def test_remote_stack_alone(self): |
| 53 | stack_id = self.stack_create(template=self.remote_template) |
| 54 | expected_resources = {'random1': 'OS::Heat::RandomString'} |
| 55 | self.assertEqual(expected_resources, self.list_resources(stack_id)) |
| 56 | stack = self.client.stacks.get(stack_id) |
| 57 | output_value = self._stack_output(stack, 'remote_key') |
| 58 | self.assertEqual(32, len(output_value)) |
| 59 | |
| 60 | def test_stack_create(self): |
| 61 | files = {'remote_stack.yaml': self.remote_template} |
| 62 | stack_id = self.stack_create(files=files) |
| 63 | |
| 64 | expected_resources = {'my_stack': 'OS::Heat::Stack'} |
| 65 | self.assertEqual(expected_resources, self.list_resources(stack_id)) |
| 66 | |
| 67 | stack = self.client.stacks.get(stack_id) |
| 68 | output = self._stack_output(stack, 'key') |
| 69 | parent_output_value = output['remote_key'] |
| 70 | self.assertEqual(32, len(parent_output_value)) |
| 71 | |
| 72 | rsrc = self.client.resources.get(stack_id, 'my_stack') |
| 73 | remote_id = rsrc.physical_resource_id |
| 74 | rstack = self.client.stacks.get(remote_id) |
| 75 | self.assertEqual(remote_id, rstack.id) |
| 76 | remote_output_value = self._stack_output(rstack, 'remote_key') |
| 77 | self.assertEqual(32, len(remote_output_value)) |
| 78 | self.assertEqual(parent_output_value, remote_output_value) |
| 79 | |
| 80 | remote_resources = {'random1': 'OS::Heat::RandomString'} |
| 81 | self.assertEqual(remote_resources, self.list_resources(remote_id)) |
| 82 | |
| 83 | def test_stack_create_bad_region(self): |
Rabi Mishra | b0759cd | 2016-03-23 10:20:21 +0530 | [diff] [blame] | 84 | tmpl_bad_region = self.template.replace(self.conf.region, 'DARKHOLE') |
tengqm | c0fffda | 2014-12-11 22:32:27 +0800 | [diff] [blame] | 85 | files = {'remote_stack.yaml': self.remote_template} |
| 86 | kwargs = { |
tengqm | c0fffda | 2014-12-11 22:32:27 +0800 | [diff] [blame] | 87 | 'template': tmpl_bad_region, |
| 88 | 'files': files |
| 89 | } |
| 90 | ex = self.assertRaises(exc.HTTPBadRequest, self.stack_create, **kwargs) |
| 91 | |
| 92 | error_msg = ('ERROR: Cannot establish connection to Heat endpoint ' |
| 93 | 'at region "DARKHOLE" due to "publicURL endpoint for ' |
| 94 | 'orchestration service in DARKHOLE region not found"') |
| 95 | self.assertEqual(error_msg, six.text_type(ex)) |
| 96 | |
| 97 | def test_stack_resource_validation_fail(self): |
tengqm | c0fffda | 2014-12-11 22:32:27 +0800 | [diff] [blame] | 98 | tmpl_bad_format = self.remote_template.replace('resources', 'resource') |
| 99 | files = {'remote_stack.yaml': tmpl_bad_format} |
Sergey Kraynev | 203f875 | 2016-01-25 04:21:32 -0500 | [diff] [blame] | 100 | kwargs = {'files': files} |
tengqm | c0fffda | 2014-12-11 22:32:27 +0800 | [diff] [blame] | 101 | ex = self.assertRaises(exc.HTTPBadRequest, self.stack_create, **kwargs) |
| 102 | |
| 103 | error_msg = ('ERROR: Failed validating stack template using Heat ' |
Rabi Mishra | b0759cd | 2016-03-23 10:20:21 +0530 | [diff] [blame] | 104 | 'endpoint at region "%s" due to ' |
| 105 | '"ERROR: The template section is ' |
| 106 | 'invalid: resource"') % self.conf.region |
tengqm | c0fffda | 2014-12-11 22:32:27 +0800 | [diff] [blame] | 107 | self.assertEqual(error_msg, six.text_type(ex)) |
| 108 | |
| 109 | def test_stack_update(self): |
| 110 | files = {'remote_stack.yaml': self.remote_template} |
| 111 | stack_id = self.stack_create(files=files) |
| 112 | |
| 113 | expected_resources = {'my_stack': 'OS::Heat::Stack'} |
| 114 | self.assertEqual(expected_resources, self.list_resources(stack_id)) |
| 115 | |
| 116 | rsrc = self.client.resources.get(stack_id, 'my_stack') |
| 117 | physical_resource_id = rsrc.physical_resource_id |
| 118 | rstack = self.client.stacks.get(physical_resource_id) |
| 119 | self.assertEqual(physical_resource_id, rstack.id) |
| 120 | |
| 121 | remote_resources = {'random1': 'OS::Heat::RandomString'} |
| 122 | self.assertEqual(remote_resources, |
| 123 | self.list_resources(rstack.id)) |
| 124 | # do an update |
| 125 | update_template = self.remote_template.replace('random1', 'random2') |
| 126 | files = {'remote_stack.yaml': update_template} |
| 127 | self.update_stack(stack_id, self.template, files=files) |
| 128 | |
| 129 | # check if the remote stack is still there with the same ID |
| 130 | self.assertEqual(expected_resources, self.list_resources(stack_id)) |
| 131 | rsrc = self.client.resources.get(stack_id, 'my_stack') |
| 132 | physical_resource_id = rsrc.physical_resource_id |
| 133 | rstack = self.client.stacks.get(physical_resource_id) |
| 134 | self.assertEqual(physical_resource_id, rstack.id) |
| 135 | |
| 136 | remote_resources = {'random2': 'OS::Heat::RandomString'} |
| 137 | self.assertEqual(remote_resources, |
| 138 | self.list_resources(rstack.id)) |
| 139 | |
| 140 | def test_stack_suspend_resume(self): |
| 141 | files = {'remote_stack.yaml': self.remote_template} |
| 142 | stack_id = self.stack_create(files=files) |
Angus Salkeld | a7500d1 | 2015-04-10 15:44:07 +1000 | [diff] [blame] | 143 | self.stack_suspend(stack_id) |
| 144 | self.stack_resume(stack_id) |