blob: c8a9aa734306be998d12506c8911ef751187e85d [file] [log] [blame]
Steven Hardy00de7582014-05-07 15:18:52 +01001# 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 Hardy00de7582014-05-07 15:18:52 +010013from tempest.api.orchestration import base
Ken'ichi Ohmichi60680a82017-03-10 11:03:16 -080014from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi835a9452017-01-27 18:17:07 -080015from tempest.lib import decorators
Steven Hardy00de7582014-05-07 15:18:52 +010016
17
Steven Hardy00de7582014-05-07 15:18:52 +010018class StackEnvironmentTest(base.BaseOrchestrationTest):
19
Ken'ichi Ohmichi835a9452017-01-27 18:17:07 -080020 @decorators.idempotent_id('37d4346b-1abd-4442-b7b1-2a4e5749a1e3')
Steven Hardy00de7582014-05-07 15:18:52 +010021 def test_environment_parameter(self):
22 """Test passing a stack parameter via the environment."""
23 stack_name = data_utils.rand_name('heat')
Ghanshyam961ea1a2014-06-09 10:56:00 +090024 template = self.read_template('random_string')
Steven Hardy00de7582014-05-07 15:18:52 +010025 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 Hardy1b25fe02014-05-07 16:21:28 +010036
Ken'ichi Ohmichi835a9452017-01-27 18:17:07 -080037 @decorators.idempotent_id('73bce717-ad22-4853-bbef-6ed89b632701')
Steven Hardy1b25fe02014-05-07 16:21:28 +010038 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 = '''
42heat_template_version: 2013-05-23
43resources:
44 random:
45 type: My:Random::String
46outputs:
47 random_value:
48 value: {get_attr: [random, random_value]}
49'''
50 environment = {'resource_registry':
51 {'My:Random::String': 'my_random.yaml'}}
Ghanshyam961ea1a2014-06-09 10:56:00 +090052 files = {'my_random.yaml': self.read_template('random_string')}
Steven Hardy1b25fe02014-05-07 16:21:28 +010053
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')
Ghanshyamf36b0d42014-07-10 10:24:29 +090061 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 Hardy77c51ec2014-05-07 16:34:05 +010065
Ken'ichi Ohmichi835a9452017-01-27 18:17:07 -080066 @decorators.idempotent_id('9d682e5a-f4bb-47d5-8472-9d3cacb855df')
Steven Hardy77c51ec2014-05-07 16:34:05 +010067 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 = '''
73heat_template_version: 2013-05-23
74resources:
75 random:
76 type: my_random.yaml
77outputs:
78 random_value:
79 value: {get_attr: [random, random_value]}
80'''
Ghanshyam961ea1a2014-06-09 10:56:00 +090081 files = {'my_random.yaml': self.read_template('random_string')}
Steven Hardy77c51ec2014-05-07 16:34:05 +010082
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')
Ghanshyamf36b0d42014-07-10 10:24:29 +090089 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))