Steven Hardy | 00de758 | 2014-05-07 15:18:52 +0100 | [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 | |
Steven Hardy | 00de758 | 2014-05-07 15:18:52 +0100 | [diff] [blame] | 13 | from tempest.api.orchestration import base |
Ken'ichi Ohmichi | 60680a8 | 2017-03-10 11:03:16 -0800 | [diff] [blame] | 14 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | 835a945 | 2017-01-27 18:17:07 -0800 | [diff] [blame] | 15 | from tempest.lib import decorators |
Steven Hardy | 00de758 | 2014-05-07 15:18:52 +0100 | [diff] [blame] | 16 | |
| 17 | |
Steven Hardy | 00de758 | 2014-05-07 15:18:52 +0100 | [diff] [blame] | 18 | class StackEnvironmentTest(base.BaseOrchestrationTest): |
| 19 | |
Ken'ichi Ohmichi | 835a945 | 2017-01-27 18:17:07 -0800 | [diff] [blame] | 20 | @decorators.idempotent_id('37d4346b-1abd-4442-b7b1-2a4e5749a1e3') |
Steven Hardy | 00de758 | 2014-05-07 15:18:52 +0100 | [diff] [blame] | 21 | def test_environment_parameter(self): |
| 22 | """Test passing a stack parameter via the environment.""" |
| 23 | stack_name = data_utils.rand_name('heat') |
Ghanshyam | 961ea1a | 2014-06-09 10:56:00 +0900 | [diff] [blame] | 24 | template = self.read_template('random_string') |
Steven Hardy | 00de758 | 2014-05-07 15:18:52 +0100 | [diff] [blame] | 25 | environment = {'parameters': {'random_length': 20}} |
| 26 | |
| 27 | stack_identifier = self.create_stack(stack_name, template, |
| 28 | environment=environment) |
| 29 | self.client.wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE') |
| 30 | |
| 31 | random_len = self.get_stack_output(stack_identifier, 'random_length') |
| 32 | self.assertEqual(20, random_len) |
| 33 | |
| 34 | random_value = self.get_stack_output(stack_identifier, 'random_value') |
| 35 | self.assertEqual(20, len(random_value)) |
Steven Hardy | 1b25fe0 | 2014-05-07 16:21:28 +0100 | [diff] [blame] | 36 | |
Ken'ichi Ohmichi | 835a945 | 2017-01-27 18:17:07 -0800 | [diff] [blame] | 37 | @decorators.idempotent_id('73bce717-ad22-4853-bbef-6ed89b632701') |
Steven Hardy | 1b25fe0 | 2014-05-07 16:21:28 +0100 | [diff] [blame] | 38 | def test_environment_provider_resource(self): |
| 39 | """Test passing resource_registry defining a provider resource.""" |
| 40 | stack_name = data_utils.rand_name('heat') |
| 41 | template = ''' |
| 42 | heat_template_version: 2013-05-23 |
| 43 | resources: |
| 44 | random: |
| 45 | type: My:Random::String |
| 46 | outputs: |
| 47 | random_value: |
| 48 | value: {get_attr: [random, random_value]} |
| 49 | ''' |
| 50 | environment = {'resource_registry': |
| 51 | {'My:Random::String': 'my_random.yaml'}} |
Ghanshyam | 961ea1a | 2014-06-09 10:56:00 +0900 | [diff] [blame] | 52 | files = {'my_random.yaml': self.read_template('random_string')} |
Steven Hardy | 1b25fe0 | 2014-05-07 16:21:28 +0100 | [diff] [blame] | 53 | |
| 54 | stack_identifier = self.create_stack(stack_name, template, |
| 55 | environment=environment, |
| 56 | files=files) |
| 57 | self.client.wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE') |
| 58 | |
| 59 | # random_string.yaml specifies a length of 10 |
| 60 | random_value = self.get_stack_output(stack_identifier, 'random_value') |
Ghanshyam | f36b0d4 | 2014-07-10 10:24:29 +0900 | [diff] [blame] | 61 | random_string_template = self.load_template('random_string') |
| 62 | expected_length = random_string_template['parameters'][ |
| 63 | 'random_length']['default'] |
| 64 | self.assertEqual(expected_length, len(random_value)) |
Steven Hardy | 77c51ec | 2014-05-07 16:34:05 +0100 | [diff] [blame] | 65 | |
Ken'ichi Ohmichi | 835a945 | 2017-01-27 18:17:07 -0800 | [diff] [blame] | 66 | @decorators.idempotent_id('9d682e5a-f4bb-47d5-8472-9d3cacb855df') |
Steven Hardy | 77c51ec | 2014-05-07 16:34:05 +0100 | [diff] [blame] | 67 | def test_files_provider_resource(self): |
| 68 | """Test untyped defining of a provider resource via "files".""" |
| 69 | # It's also possible to specify the filename directly in the template. |
| 70 | # without adding the type alias to resource_registry |
| 71 | stack_name = data_utils.rand_name('heat') |
| 72 | template = ''' |
| 73 | heat_template_version: 2013-05-23 |
| 74 | resources: |
| 75 | random: |
| 76 | type: my_random.yaml |
| 77 | outputs: |
| 78 | random_value: |
| 79 | value: {get_attr: [random, random_value]} |
| 80 | ''' |
Ghanshyam | 961ea1a | 2014-06-09 10:56:00 +0900 | [diff] [blame] | 81 | files = {'my_random.yaml': self.read_template('random_string')} |
Steven Hardy | 77c51ec | 2014-05-07 16:34:05 +0100 | [diff] [blame] | 82 | |
| 83 | stack_identifier = self.create_stack(stack_name, template, |
| 84 | files=files) |
| 85 | self.client.wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE') |
| 86 | |
| 87 | # random_string.yaml specifies a length of 10 |
| 88 | random_value = self.get_stack_output(stack_identifier, 'random_value') |
Ghanshyam | f36b0d4 | 2014-07-10 10:24:29 +0900 | [diff] [blame] | 89 | random_string_template = self.load_template('random_string') |
| 90 | expected_length = random_string_template['parameters'][ |
| 91 | 'random_length']['default'] |
| 92 | self.assertEqual(expected_length, len(random_value)) |