blob: 924c1100be601c2a339a942eae466940944be4cb [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
38 def setUp(self):
39 super(StackUnicodeTemplateTest, self).setUp()
40
41 def _assert_results(self, result):
42 self.assertTrue(result['disable_rollback'])
43 self.assertIsNone(result['parent'])
44 self.assertEqual(u'\u8fd9\u662f\u4e00\u4e2a\u63cf\u8ff0',
45 result['template_description'])
46 self.assertEqual(u'10', result['parameters'][u'\u53c2\u6570'])
47
48 def _assert_preview_results(self, result):
49 self._assert_results(result)
50 res = result['resources'][0]
51 self.assertEqual('/resources/%s' % res['resource_name'],
52 res['resource_identity']['path'])
53
54 def _assert_create_results(self, result):
55 self._assert_results(result)
56 output = result['outputs'][0]
57 self.assertEqual(u'\u8fd9\u662f\u4e00\u4e2a\u63cf\u8ff0',
58 output['description'])
59 self.assertEqual(u'\u8f93\u51fa', output['output_key'])
60 self.assertIsNotNone(output['output_value'])
61
62 def _assert_resource_results(self, result):
63 self.assertEqual(u'\u8d44\u6e90', result['resource_name'])
64 self.assertEqual('OS::Heat::RandomString',
65 result['resource_type'])
66
67 def test_template_validate_basic(self):
68 ret = self.client.stacks.validate(template=self.random_template)
69 expected = {
70 'Description': u'\u8fd9\u662f\u4e00\u4e2a\u63cf\u8ff0',
71 'Parameters': {
72 u'\u53c2\u6570': {
73 'Default': 10,
74 'Description': u'\u8fd9\u662f\u4e00\u4e2a\u63cf\u8ff0',
75 'Label': u'\u6807\u7b7e',
76 'NoEcho': 'false',
77 'Type': 'Number'}
78 }
79 }
80 self.assertEqual(expected, ret)
81
82 def test_template_validate_override_default(self):
83 env = {'parameters': {u'\u53c2\u6570': 5}}
84 ret = self.client.stacks.validate(template=self.random_template,
85 environment=env)
86 expected = {
87 'Description': u'\u8fd9\u662f\u4e00\u4e2a\u63cf\u8ff0',
88 'Parameters': {
89 u'\u53c2\u6570': {
90 'Default': 10,
91 'Value': 5,
92 'Description': u'\u8fd9\u662f\u4e00\u4e2a\u63cf\u8ff0',
93 'Label': u'\u6807\u7b7e',
94 'NoEcho': 'false',
95 'Type': 'Number'}
96 }
97 }
98 self.assertEqual(expected, ret)
99
100 def test_stack_preview(self):
101 result = self.client.stacks.preview(
102 template=self.random_template,
103 stack_name=self._stack_rand_name(),
104 disable_rollback=True).to_dict()
105 self._assert_preview_results(result)
106
107 def test_create_stack(self):
108 stack_identifier = self.stack_create(template=self.random_template)
109 stack = self.client.stacks.get(stack_identifier)
110 self._assert_create_results(stack.to_dict())
111 rl = self.client.resources.list(stack_identifier)
112 self.assertEqual(1, len(rl))
113 self._assert_resource_results(rl[0].to_dict())