blob: d0f49a8d8ccf1fe8ac2a647d3a0eb45d3e8060b1 [file] [log] [blame]
huangtianhua99a25de2016-07-26 10:58:33 +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
16cfn_template = '''
17AWSTemplateFormatVersion: 2010-09-09
18Parameters:
19 env_type:
20 Default: test
21 Type: String
22 AllowedValues: [prod, test]
23Conditions:
24 Prod: {"Fn::Equals" : [{Ref: env_type}, "prod"]}
25Resources:
26 test_res:
27 Type: OS::Heat::TestResource
28 Properties:
29 value: test_res
30 prod_res:
31 Type: OS::Heat::TestResource
32 Properties:
33 value: prod_res
34 Condition: Prod
35'''
36
37hot_template = '''
38heat_template_version: 2016-10-14
39parameters:
40 env_type:
41 default: test
42 type: string
43 constraints:
44 - allowed_values: [prod, test]
45conditions:
46 prod: {equals : [{get_param: env_type}, "prod"]}
47resources:
48 test_res:
49 type: OS::Heat::TestResource
50 properties:
51 value: test_res
52 prod_res:
53 type: OS::Heat::TestResource
54 properties:
55 value: prod_res
56 condition: prod
57'''
58
59
60class CreateUpdateResConditionTest(functional_base.FunctionalTestsBase):
61
62 def setUp(self):
63 super(CreateUpdateResConditionTest, self).setUp()
64
65 def res_assert_for_prod(self, resources):
66 self.assertEqual(2, len(resources))
67 res_names = [res.resource_name for res in resources]
68 self.assertIn('prod_res', res_names)
69 self.assertIn('test_res', res_names)
70
71 def res_assert_for_test(self, resources):
72 self.assertEqual(1, len(resources))
73 res_names = [res.resource_name for res in resources]
74 self.assertIn('test_res', res_names)
75 self.assertNotIn('prod_res', res_names)
76
77 def test_stack_create_update_cfn_template_test_to_prod(self):
78 stack_identifier = self.stack_create(template=cfn_template)
79 resources = self.client.resources.list(stack_identifier)
80 self.res_assert_for_test(resources)
81
82 parms = {'env_type': 'prod'}
83 self.update_stack(stack_identifier,
84 template=cfn_template,
85 parameters=parms)
86
87 resources = self.client.resources.list(stack_identifier)
88 self.res_assert_for_prod(resources)
89
90 def test_stack_create_update_cfn_template_prod_to_test(self):
91 parms = {'env_type': 'prod'}
92 stack_identifier = self.stack_create(template=cfn_template,
93 parameters=parms)
94 resources = self.client.resources.list(stack_identifier)
95 self.res_assert_for_prod(resources)
96
97 parms = {'env_type': 'test'}
98 self.update_stack(stack_identifier,
99 template=cfn_template,
100 parameters=parms)
101
102 resources = self.client.resources.list(stack_identifier)
103 self.res_assert_for_test(resources)
104
105 def test_stack_create_update_hot_template_test_to_prod(self):
106 stack_identifier = self.stack_create(template=hot_template)
107 resources = self.client.resources.list(stack_identifier)
108 self.res_assert_for_test(resources)
109
110 parms = {'env_type': 'prod'}
111 self.update_stack(stack_identifier,
112 template=hot_template,
113 parameters=parms)
114
115 resources = self.client.resources.list(stack_identifier)
116 self.res_assert_for_prod(resources)
117
118 def test_stack_create_update_hot_template_prod_to_test(self):
119 parms = {'env_type': 'prod'}
120 stack_identifier = self.stack_create(template=hot_template,
121 parameters=parms)
122 resources = self.client.resources.list(stack_identifier)
123 self.res_assert_for_prod(resources)
124
125 parms = {'env_type': 'test'}
126 self.update_stack(stack_identifier,
127 template=hot_template,
128 parameters=parms)
129
130 resources = self.client.resources.list(stack_identifier)
131 self.res_assert_for_test(resources)