blob: 32c02a5cda24862253a785e0b39f69c90f15d531 [file] [log] [blame]
Ethan Lynn4d423742016-02-17 16:32:51 +08001# 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
13from heat_integrationtests.functional import functional_base
14
15
16class StackUnicodeTemplateTest(functional_base.FunctionalTestsBase):
17
18 random_template = u'''
19heat_template_version: 2014-10-16
20description: \u8fd9\u662f\u4e00\u4e2a\u63cf\u8ff0
21parameters:
22 \u53c2\u6570:
23 type: number
24 default: 10
25 label: \u6807\u7b7e
26 description: \u8fd9\u662f\u4e00\u4e2a\u63cf\u8ff0
27resources:
28 \u8d44\u6e90:
29 type: OS::Heat::RandomString
30 properties:
31 length: {get_param: \u53c2\u6570}
32outputs:
33 \u8f93\u51fa:
34 description: \u8fd9\u662f\u4e00\u4e2a\u63cf\u8ff0
35 value: {get_attr: [\u8d44\u6e90, value]}
36'''
37
Ethan Lynn4d423742016-02-17 16:32:51 +080038 def _assert_results(self, result):
39 self.assertTrue(result['disable_rollback'])
40 self.assertIsNone(result['parent'])
41 self.assertEqual(u'\u8fd9\u662f\u4e00\u4e2a\u63cf\u8ff0',
42 result['template_description'])
43 self.assertEqual(u'10', result['parameters'][u'\u53c2\u6570'])
44
45 def _assert_preview_results(self, result):
46 self._assert_results(result)
47 res = result['resources'][0]
48 self.assertEqual('/resources/%s' % res['resource_name'],
49 res['resource_identity']['path'])
50
51 def _assert_create_results(self, result):
52 self._assert_results(result)
53 output = result['outputs'][0]
54 self.assertEqual(u'\u8fd9\u662f\u4e00\u4e2a\u63cf\u8ff0',
55 output['description'])
56 self.assertEqual(u'\u8f93\u51fa', output['output_key'])
57 self.assertIsNotNone(output['output_value'])
58
59 def _assert_resource_results(self, result):
60 self.assertEqual(u'\u8d44\u6e90', result['resource_name'])
61 self.assertEqual('OS::Heat::RandomString',
62 result['resource_type'])
63
64 def test_template_validate_basic(self):
65 ret = self.client.stacks.validate(template=self.random_template)
66 expected = {
67 'Description': u'\u8fd9\u662f\u4e00\u4e2a\u63cf\u8ff0',
68 'Parameters': {
69 u'\u53c2\u6570': {
70 'Default': 10,
71 'Description': u'\u8fd9\u662f\u4e00\u4e2a\u63cf\u8ff0',
72 'Label': u'\u6807\u7b7e',
73 'NoEcho': 'false',
74 'Type': 'Number'}
75 }
76 }
77 self.assertEqual(expected, ret)
78
79 def test_template_validate_override_default(self):
80 env = {'parameters': {u'\u53c2\u6570': 5}}
81 ret = self.client.stacks.validate(template=self.random_template,
82 environment=env)
83 expected = {
84 'Description': u'\u8fd9\u662f\u4e00\u4e2a\u63cf\u8ff0',
85 'Parameters': {
86 u'\u53c2\u6570': {
87 'Default': 10,
88 'Value': 5,
89 'Description': u'\u8fd9\u662f\u4e00\u4e2a\u63cf\u8ff0',
90 'Label': u'\u6807\u7b7e',
91 'NoEcho': 'false',
92 'Type': 'Number'}
93 }
94 }
95 self.assertEqual(expected, ret)
96
97 def test_stack_preview(self):
98 result = self.client.stacks.preview(
99 template=self.random_template,
100 stack_name=self._stack_rand_name(),
101 disable_rollback=True).to_dict()
102 self._assert_preview_results(result)
103
104 def test_create_stack(self):
105 stack_identifier = self.stack_create(template=self.random_template)
106 stack = self.client.stacks.get(stack_identifier)
107 self._assert_create_results(stack.to_dict())
108 rl = self.client.resources.list(stack_identifier)
109 self.assertEqual(1, len(rl))
110 self._assert_resource_results(rl[0].to_dict())