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