blob: 9d2b42570ee19c7fd491468676c0d77e42de3c4c [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
Fei Long Wangd39431f2015-05-14 11:30:48 +120014from tempest.common.utils import data_utils
Steven Hardy00de7582014-05-07 15:18:52 +010015from tempest import config
16from tempest import test
17
18
19CONF = config.CONF
Steven Hardy00de7582014-05-07 15:18:52 +010020
21
22class StackEnvironmentTest(base.BaseOrchestrationTest):
23
Chris Hoge7579c1a2015-02-26 14:12:15 -080024 @test.idempotent_id('37d4346b-1abd-4442-b7b1-2a4e5749a1e3')
Steven Hardy00de7582014-05-07 15:18:52 +010025 def test_environment_parameter(self):
26 """Test passing a stack parameter via the environment."""
27 stack_name = data_utils.rand_name('heat')
Ghanshyam961ea1a2014-06-09 10:56:00 +090028 template = self.read_template('random_string')
Steven Hardy00de7582014-05-07 15:18:52 +010029 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 Hardy1b25fe02014-05-07 16:21:28 +010040
Chris Hoge7579c1a2015-02-26 14:12:15 -080041 @test.idempotent_id('73bce717-ad22-4853-bbef-6ed89b632701')
Steven Hardy1b25fe02014-05-07 16:21:28 +010042 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 = '''
46heat_template_version: 2013-05-23
47resources:
48 random:
49 type: My:Random::String
50outputs:
51 random_value:
52 value: {get_attr: [random, random_value]}
53'''
54 environment = {'resource_registry':
55 {'My:Random::String': 'my_random.yaml'}}
Ghanshyam961ea1a2014-06-09 10:56:00 +090056 files = {'my_random.yaml': self.read_template('random_string')}
Steven Hardy1b25fe02014-05-07 16:21:28 +010057
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')
Ghanshyamf36b0d42014-07-10 10:24:29 +090065 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 Hardy77c51ec2014-05-07 16:34:05 +010069
Chris Hoge7579c1a2015-02-26 14:12:15 -080070 @test.idempotent_id('9d682e5a-f4bb-47d5-8472-9d3cacb855df')
Steven Hardy77c51ec2014-05-07 16:34:05 +010071 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 = '''
77heat_template_version: 2013-05-23
78resources:
79 random:
80 type: my_random.yaml
81outputs:
82 random_value:
83 value: {get_attr: [random, random_value]}
84'''
Ghanshyam961ea1a2014-06-09 10:56:00 +090085 files = {'my_random.yaml': self.read_template('random_string')}
Steven Hardy77c51ec2014-05-07 16:34:05 +010086
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')
Ghanshyamf36b0d42014-07-10 10:24:29 +090093 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))