huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 1 | # 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 | |
| 13 | from heat_integrationtests.functional import functional_base |
| 14 | |
| 15 | |
| 16 | cfn_template = ''' |
| 17 | AWSTemplateFormatVersion: 2010-09-09 |
| 18 | Parameters: |
| 19 | env_type: |
| 20 | Default: test |
| 21 | Type: String |
| 22 | AllowedValues: [prod, test] |
huangtianhua | 7bdc751 | 2016-06-17 09:25:38 +0800 | [diff] [blame] | 23 | zone: |
| 24 | Type: String |
| 25 | Default: beijing |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 26 | Conditions: |
| 27 | Prod: {"Fn::Equals" : [{Ref: env_type}, "prod"]} |
huangtianhua | bf63fcb | 2016-07-27 13:02:39 +0800 | [diff] [blame] | 28 | Test: |
| 29 | Fn::Not: |
| 30 | - Fn::Equals: |
| 31 | - Ref: env_type |
| 32 | - prod |
huangtianhua | 7bdc751 | 2016-06-17 09:25:38 +0800 | [diff] [blame] | 33 | Beijing_Prod: |
| 34 | Fn::And: |
| 35 | - Fn::Equals: |
| 36 | - Ref: env_type |
| 37 | - prod |
| 38 | - Fn::Equals: |
| 39 | - Ref: zone |
| 40 | - beijing |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 41 | Xian_Zone: |
| 42 | Fn::Equals: |
| 43 | - Ref: zone |
| 44 | - xian |
| 45 | Xianyang_Zone: |
| 46 | Fn::Equals: |
| 47 | - Ref: zone |
| 48 | - xianyang |
huangtianhua | 26da898 | 2016-07-27 18:11:58 +0800 | [diff] [blame] | 49 | Fujian_Zone: |
| 50 | Fn::Or: |
| 51 | - Fn::Equals: |
| 52 | - Ref: zone |
| 53 | - fuzhou |
| 54 | - Fn::Equals: |
| 55 | - Ref: zone |
| 56 | - xiamen |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 57 | Fujian_Prod: |
| 58 | Fn::And: |
| 59 | - Fujian_Zone |
| 60 | - Prod |
| 61 | Shannxi_Provice: |
| 62 | Fn::Or: |
| 63 | - Xian_Zone |
| 64 | - Xianyang_Zone |
| 65 | Not_Shannxi: |
| 66 | Fn::Not: [Shannxi_Provice] |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 67 | Resources: |
| 68 | test_res: |
| 69 | Type: OS::Heat::TestResource |
| 70 | Properties: |
huangtianhua | fb8b51f | 2016-02-23 17:03:10 +0800 | [diff] [blame] | 71 | value: {"Fn::If": ["Prod", "env_is_prod", "env_is_test"]} |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 72 | prod_res: |
| 73 | Type: OS::Heat::TestResource |
| 74 | Properties: |
| 75 | value: prod_res |
| 76 | Condition: Prod |
huangtianhua | bf63fcb | 2016-07-27 13:02:39 +0800 | [diff] [blame] | 77 | test_res1: |
| 78 | Type: OS::Heat::TestResource |
| 79 | Properties: |
| 80 | value: just in test env |
| 81 | Condition: Test |
huangtianhua | 7bdc751 | 2016-06-17 09:25:38 +0800 | [diff] [blame] | 82 | beijing_prod_res: |
| 83 | Type: OS::Heat::TestResource |
| 84 | Properties: |
| 85 | value: beijing_prod_res |
| 86 | Condition: Beijing_Prod |
huangtianhua | 26da898 | 2016-07-27 18:11:58 +0800 | [diff] [blame] | 87 | fujian_res: |
| 88 | Type: OS::Heat::TestResource |
| 89 | Condition: Fujian_Zone |
| 90 | Properties: |
| 91 | value: fujian_res |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 92 | fujian_prod_res: |
| 93 | Type: OS::Heat::TestResource |
| 94 | Condition: Fujian_Prod |
| 95 | Properties: |
| 96 | value: fujian_prod_res |
| 97 | shannxi_res: |
| 98 | Type: OS::Heat::TestResource |
| 99 | Condition: Shannxi_Provice |
| 100 | Properties: |
| 101 | value: shannxi_res |
| 102 | not_shannxi_res: |
| 103 | Type: OS::Heat::TestResource |
| 104 | Condition: Not_Shannxi |
| 105 | Properties: |
| 106 | value: not_shannxi_res |
huangtianhua | 27075a9 | 2016-07-26 14:32:40 +0800 | [diff] [blame] | 107 | Outputs: |
| 108 | res_value: |
| 109 | Value: {"Fn::GetAtt": [prod_res, output]} |
| 110 | Condition: Prod |
huangtianhua | fb8b51f | 2016-02-23 17:03:10 +0800 | [diff] [blame] | 111 | test_res_value: |
| 112 | Value: {"Fn::GetAtt": [test_res, output]} |
| 113 | prod_resource: |
| 114 | Value: {"Fn::If": [Prod, {Ref: prod_res}, 'no_prod_res']} |
huangtianhua | bf63fcb | 2016-07-27 13:02:39 +0800 | [diff] [blame] | 115 | test_res1_value: |
| 116 | Value: {"Fn::If": [Test, {"Fn::GetAtt": [test_res1, output]}, |
| 117 | 'no_test_res1']} |
huangtianhua | 7bdc751 | 2016-06-17 09:25:38 +0800 | [diff] [blame] | 118 | beijing_prod_res: |
| 119 | Value: {"Fn::If": [Beijing_Prod, {Ref: beijing_prod_res}, 'no_prod_res']} |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 120 | ''' |
| 121 | |
| 122 | hot_template = ''' |
| 123 | heat_template_version: 2016-10-14 |
| 124 | parameters: |
| 125 | env_type: |
| 126 | default: test |
| 127 | type: string |
| 128 | constraints: |
| 129 | - allowed_values: [prod, test] |
huangtianhua | 7bdc751 | 2016-06-17 09:25:38 +0800 | [diff] [blame] | 130 | zone: |
| 131 | type: string |
| 132 | default: beijing |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 133 | conditions: |
| 134 | prod: {equals : [{get_param: env_type}, "prod"]} |
huangtianhua | bf63fcb | 2016-07-27 13:02:39 +0800 | [diff] [blame] | 135 | test: |
| 136 | not: |
| 137 | equals: |
| 138 | - get_param: env_type |
| 139 | - prod |
huangtianhua | 7bdc751 | 2016-06-17 09:25:38 +0800 | [diff] [blame] | 140 | beijing_prod: |
| 141 | and: |
| 142 | - equals: |
| 143 | - get_param: zone |
| 144 | - beijing |
| 145 | - equals: |
| 146 | - get_param: env_type |
| 147 | - prod |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 148 | xian_zone: |
| 149 | equals: |
| 150 | - get_param: zone |
| 151 | - xian |
| 152 | xianyang_zone: |
| 153 | equals: |
| 154 | - get_param: zone |
| 155 | - xianyang |
huangtianhua | 26da898 | 2016-07-27 18:11:58 +0800 | [diff] [blame] | 156 | fujian_zone: |
| 157 | or: |
| 158 | - equals: |
| 159 | - get_param: zone |
| 160 | - fuzhou |
| 161 | - equals: |
| 162 | - get_param: zone |
| 163 | - xiamen |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 164 | fujian_prod: |
| 165 | and: |
| 166 | - fujian_zone |
| 167 | - prod |
| 168 | shannxi_provice: |
| 169 | or: |
| 170 | - xian_zone |
| 171 | - xianyang_zone |
| 172 | not_shannxi: |
| 173 | not: shannxi_provice |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 174 | resources: |
| 175 | test_res: |
| 176 | type: OS::Heat::TestResource |
| 177 | properties: |
huangtianhua | fb8b51f | 2016-02-23 17:03:10 +0800 | [diff] [blame] | 178 | value: {if: ["prod", "env_is_prod", "env_is_test"]} |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 179 | prod_res: |
| 180 | type: OS::Heat::TestResource |
| 181 | properties: |
| 182 | value: prod_res |
| 183 | condition: prod |
huangtianhua | bf63fcb | 2016-07-27 13:02:39 +0800 | [diff] [blame] | 184 | test_res1: |
| 185 | type: OS::Heat::TestResource |
| 186 | properties: |
| 187 | value: just in test env |
| 188 | condition: test |
huangtianhua | 7bdc751 | 2016-06-17 09:25:38 +0800 | [diff] [blame] | 189 | beijing_prod_res: |
| 190 | type: OS::Heat::TestResource |
| 191 | properties: |
| 192 | value: beijing_prod_res |
| 193 | condition: beijing_prod |
huangtianhua | 26da898 | 2016-07-27 18:11:58 +0800 | [diff] [blame] | 194 | fujian_res: |
| 195 | type: OS::Heat::TestResource |
| 196 | condition: fujian_zone |
| 197 | properties: |
| 198 | value: fujian_res |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 199 | fujian_prod_res: |
| 200 | type: OS::Heat::TestResource |
| 201 | condition: fujian_prod |
| 202 | properties: |
| 203 | value: fujian_prod_res |
| 204 | shannxi_res: |
| 205 | type: OS::Heat::TestResource |
| 206 | condition: shannxi_provice |
| 207 | properties: |
| 208 | value: shannxi_res |
| 209 | not_shannxi_res: |
| 210 | type: OS::Heat::TestResource |
| 211 | condition: not_shannxi |
| 212 | properties: |
| 213 | value: not_shannxi_res |
huangtianhua | 27075a9 | 2016-07-26 14:32:40 +0800 | [diff] [blame] | 214 | outputs: |
| 215 | res_value: |
| 216 | value: {get_attr: [prod_res, output]} |
| 217 | condition: prod |
huangtianhua | fb8b51f | 2016-02-23 17:03:10 +0800 | [diff] [blame] | 218 | test_res_value: |
| 219 | value: {get_attr: [test_res, output]} |
| 220 | prod_resource: |
| 221 | value: {if: [prod, {get_resource: prod_res}, 'no_prod_res']} |
huangtianhua | bf63fcb | 2016-07-27 13:02:39 +0800 | [diff] [blame] | 222 | test_res1_value: |
| 223 | value: {if: [test, {get_attr: [test_res1, output]}, 'no_test_res1']} |
huangtianhua | 7bdc751 | 2016-06-17 09:25:38 +0800 | [diff] [blame] | 224 | beijing_prod_res: |
| 225 | value: {if: [beijing_prod, {get_resource: beijing_prod_res}, |
| 226 | 'no_prod_res']} |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 227 | ''' |
| 228 | |
Zane Bitter | a9b5aaf | 2016-09-12 20:51:52 -0400 | [diff] [blame] | 229 | before_rename_tmpl = ''' |
| 230 | heat_template_version: 2016-10-14 |
| 231 | parameters: |
| 232 | env_type: |
| 233 | default: test |
| 234 | type: string |
| 235 | conditions: |
| 236 | cd1: {equals : [{get_param: env_type}, "prod"]} |
| 237 | resources: |
| 238 | test: |
| 239 | type: OS::Heat::TestResource |
| 240 | properties: |
| 241 | value: {if: [cd1, 'prod', 'test']} |
| 242 | ''' |
| 243 | |
| 244 | after_rename_tmpl = ''' |
| 245 | heat_template_version: 2016-10-14 |
| 246 | parameters: |
| 247 | env_type: |
| 248 | default: prod |
| 249 | type: string |
| 250 | conditions: |
| 251 | cd2: {equals : [{get_param: env_type}, "prod"]} |
| 252 | resources: |
| 253 | test: |
| 254 | type: OS::Heat::TestResource |
| 255 | properties: |
| 256 | value: {if: [cd2, 'prod', 'test']} |
| 257 | test2: |
| 258 | type: OS::Heat::TestResource |
| 259 | properties: |
| 260 | value: {if: [cd2, 'prod', 'test']} |
| 261 | ''' |
| 262 | |
| 263 | fail_rename_tmpl = ''' |
| 264 | heat_template_version: 2016-10-14 |
| 265 | parameters: |
| 266 | env_type: |
| 267 | default: prod |
| 268 | type: string |
| 269 | conditions: |
| 270 | cd3: {equals : [{get_param: env_type}, "prod"]} |
| 271 | resources: |
| 272 | test: |
| 273 | type: OS::Heat::TestResource |
| 274 | properties: |
| 275 | value: {if: [cd3, 'prod', 'test']} |
| 276 | test2: |
| 277 | type: OS::Heat::TestResource |
| 278 | properties: |
| 279 | value: {if: [cd3, 'prod', 'test']} |
| 280 | test_fail: |
| 281 | type: OS::Heat::TestResource |
| 282 | properties: |
| 283 | fail: True |
| 284 | depends_on: [test, test2] |
| 285 | ''' |
| 286 | |
| 287 | recover_rename_tmpl = ''' |
| 288 | heat_template_version: 2016-10-14 |
| 289 | parameters: |
| 290 | env_type: |
| 291 | default: prod |
| 292 | type: string |
| 293 | conditions: |
| 294 | cd3: {equals : [{get_param: env_type}, "prod"]} |
| 295 | resources: |
| 296 | test2: |
| 297 | type: OS::Heat::TestResource |
| 298 | properties: |
| 299 | value: {if: [cd3, 'prod', 'test']} |
| 300 | test_fail: |
| 301 | type: OS::Heat::TestResource |
| 302 | properties: |
| 303 | fail: False |
| 304 | depends_on: [test2] |
| 305 | ''' |
| 306 | |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 307 | |
| 308 | class CreateUpdateResConditionTest(functional_base.FunctionalTestsBase): |
| 309 | |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 310 | def res_assert_for_prod(self, resources, bj_prod=True, fj_zone=False, |
| 311 | shannxi_provice=False): |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 312 | res_names = [res.resource_name for res in resources] |
huangtianhua | 7bdc751 | 2016-06-17 09:25:38 +0800 | [diff] [blame] | 313 | if bj_prod: |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 314 | self.assertEqual(4, len(resources)) |
huangtianhua | 7bdc751 | 2016-06-17 09:25:38 +0800 | [diff] [blame] | 315 | self.assertIn('beijing_prod_res', res_names) |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 316 | self.assertIn('not_shannxi_res', res_names) |
huangtianhua | 26da898 | 2016-07-27 18:11:58 +0800 | [diff] [blame] | 317 | elif fj_zone: |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 318 | self.assertEqual(5, len(resources)) |
huangtianhua | 26da898 | 2016-07-27 18:11:58 +0800 | [diff] [blame] | 319 | self.assertIn('fujian_res', res_names) |
| 320 | self.assertNotIn('beijing_prod_res', res_names) |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 321 | self.assertIn('not_shannxi_res', res_names) |
| 322 | self.assertIn('fujian_prod_res', res_names) |
| 323 | elif shannxi_provice: |
| 324 | self.assertEqual(3, len(resources)) |
| 325 | self.assertIn('shannxi_res', res_names) |
huangtianhua | 7bdc751 | 2016-06-17 09:25:38 +0800 | [diff] [blame] | 326 | else: |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 327 | self.assertEqual(3, len(resources)) |
| 328 | self.assertIn('not_shannxi_res', res_names) |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 329 | self.assertIn('prod_res', res_names) |
| 330 | self.assertIn('test_res', res_names) |
| 331 | |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 332 | def res_assert_for_test(self, resources, fj_zone=False, |
| 333 | shannxi_provice=False): |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 334 | res_names = [res.resource_name for res in resources] |
huangtianhua | 26da898 | 2016-07-27 18:11:58 +0800 | [diff] [blame] | 335 | |
| 336 | if fj_zone: |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 337 | self.assertEqual(4, len(resources)) |
huangtianhua | 26da898 | 2016-07-27 18:11:58 +0800 | [diff] [blame] | 338 | self.assertIn('fujian_res', res_names) |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 339 | self.assertIn('not_shannxi_res', res_names) |
| 340 | elif shannxi_provice: |
| 341 | self.assertEqual(3, len(resources)) |
Zane Bitter | ee582d9 | 2016-09-08 11:33:46 -0400 | [diff] [blame] | 342 | self.assertNotIn('fujian_res', res_names) |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 343 | self.assertIn('shannxi_res', res_names) |
| 344 | else: |
| 345 | self.assertEqual(3, len(resources)) |
| 346 | self.assertIn('not_shannxi_res', res_names) |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 347 | self.assertIn('test_res', res_names) |
huangtianhua | bf63fcb | 2016-07-27 13:02:39 +0800 | [diff] [blame] | 348 | self.assertIn('test_res1', res_names) |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 349 | self.assertNotIn('prod_res', res_names) |
| 350 | |
huangtianhua | 7bdc751 | 2016-06-17 09:25:38 +0800 | [diff] [blame] | 351 | def output_assert_for_prod(self, stack_id, bj_prod=True): |
huangtianhua | 27075a9 | 2016-07-26 14:32:40 +0800 | [diff] [blame] | 352 | output = self.client.stacks.output_show(stack_id, |
| 353 | 'res_value')['output'] |
| 354 | self.assertEqual('prod_res', output['output_value']) |
| 355 | |
huangtianhua | fb8b51f | 2016-02-23 17:03:10 +0800 | [diff] [blame] | 356 | test_res_value = self.client.stacks.output_show( |
| 357 | stack_id, 'test_res_value')['output'] |
| 358 | self.assertEqual('env_is_prod', test_res_value['output_value']) |
| 359 | |
| 360 | prod_resource = self.client.stacks.output_show( |
| 361 | stack_id, 'prod_resource')['output'] |
| 362 | self.assertNotEqual('no_prod_res', prod_resource['output_value']) |
| 363 | |
huangtianhua | bf63fcb | 2016-07-27 13:02:39 +0800 | [diff] [blame] | 364 | test_res_output = self.client.stacks.output_show( |
| 365 | stack_id, 'test_res1_value')['output'] |
| 366 | self.assertEqual('no_test_res1', test_res_output['output_value']) |
| 367 | |
huangtianhua | 7bdc751 | 2016-06-17 09:25:38 +0800 | [diff] [blame] | 368 | beijing_prod_res = self.client.stacks.output_show( |
| 369 | stack_id, 'beijing_prod_res')['output'] |
| 370 | if bj_prod: |
| 371 | self.assertNotEqual('no_prod_res', |
| 372 | beijing_prod_res['output_value']) |
| 373 | else: |
| 374 | self.assertEqual('no_prod_res', beijing_prod_res['output_value']) |
| 375 | |
huangtianhua | 27075a9 | 2016-07-26 14:32:40 +0800 | [diff] [blame] | 376 | def output_assert_for_test(self, stack_id): |
| 377 | output = self.client.stacks.output_show(stack_id, |
| 378 | 'res_value')['output'] |
| 379 | self.assertIsNone(output['output_value']) |
| 380 | |
huangtianhua | fb8b51f | 2016-02-23 17:03:10 +0800 | [diff] [blame] | 381 | test_res_value = self.client.stacks.output_show( |
| 382 | stack_id, 'test_res_value')['output'] |
| 383 | self.assertEqual('env_is_test', test_res_value['output_value']) |
| 384 | |
| 385 | prod_resource = self.client.stacks.output_show( |
| 386 | stack_id, 'prod_resource')['output'] |
| 387 | self.assertEqual('no_prod_res', prod_resource['output_value']) |
| 388 | |
huangtianhua | bf63fcb | 2016-07-27 13:02:39 +0800 | [diff] [blame] | 389 | test_res_output = self.client.stacks.output_show( |
| 390 | stack_id, 'test_res1_value')['output'] |
| 391 | self.assertEqual('just in test env', |
| 392 | test_res_output['output_value']) |
| 393 | |
huangtianhua | 7bdc751 | 2016-06-17 09:25:38 +0800 | [diff] [blame] | 394 | beijing_prod_res = self.client.stacks.output_show( |
| 395 | stack_id, 'beijing_prod_res')['output'] |
| 396 | self.assertEqual('no_prod_res', beijing_prod_res['output_value']) |
| 397 | |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 398 | def test_stack_create_update_cfn_template_test_to_prod(self): |
| 399 | stack_identifier = self.stack_create(template=cfn_template) |
| 400 | resources = self.client.resources.list(stack_identifier) |
| 401 | self.res_assert_for_test(resources) |
huangtianhua | 27075a9 | 2016-07-26 14:32:40 +0800 | [diff] [blame] | 402 | self.output_assert_for_test(stack_identifier) |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 403 | |
huangtianhua | 26da898 | 2016-07-27 18:11:58 +0800 | [diff] [blame] | 404 | parms = {'zone': 'fuzhou'} |
| 405 | self.update_stack(stack_identifier, |
| 406 | template=cfn_template, |
| 407 | parameters=parms) |
| 408 | |
| 409 | resources = self.client.resources.list(stack_identifier) |
| 410 | self.res_assert_for_test(resources, fj_zone=True) |
| 411 | self.output_assert_for_test(stack_identifier) |
| 412 | |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 413 | parms = {'zone': 'xianyang'} |
| 414 | self.update_stack(stack_identifier, |
| 415 | template=cfn_template, |
| 416 | parameters=parms) |
| 417 | |
| 418 | resources = self.client.resources.list(stack_identifier) |
| 419 | self.res_assert_for_test(resources, shannxi_provice=True) |
| 420 | self.output_assert_for_test(stack_identifier) |
| 421 | |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 422 | parms = {'env_type': 'prod'} |
| 423 | self.update_stack(stack_identifier, |
| 424 | template=cfn_template, |
| 425 | parameters=parms) |
| 426 | |
| 427 | resources = self.client.resources.list(stack_identifier) |
| 428 | self.res_assert_for_prod(resources) |
huangtianhua | 27075a9 | 2016-07-26 14:32:40 +0800 | [diff] [blame] | 429 | self.output_assert_for_prod(stack_identifier) |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 430 | |
huangtianhua | 7bdc751 | 2016-06-17 09:25:38 +0800 | [diff] [blame] | 431 | parms = {'env_type': 'prod', |
| 432 | 'zone': 'shanghai'} |
| 433 | self.update_stack(stack_identifier, |
| 434 | template=cfn_template, |
| 435 | parameters=parms) |
| 436 | |
| 437 | resources = self.client.resources.list(stack_identifier) |
| 438 | self.res_assert_for_prod(resources, False) |
| 439 | self.output_assert_for_prod(stack_identifier, False) |
| 440 | |
huangtianhua | 26da898 | 2016-07-27 18:11:58 +0800 | [diff] [blame] | 441 | parms = {'env_type': 'prod', |
| 442 | 'zone': 'xiamen'} |
| 443 | self.update_stack(stack_identifier, |
| 444 | template=cfn_template, |
| 445 | parameters=parms) |
| 446 | |
| 447 | resources = self.client.resources.list(stack_identifier) |
| 448 | self.res_assert_for_prod(resources, bj_prod=False, fj_zone=True) |
| 449 | self.output_assert_for_prod(stack_identifier, False) |
| 450 | |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 451 | parms = {'env_type': 'prod', |
| 452 | 'zone': 'xianyang'} |
| 453 | self.update_stack(stack_identifier, |
| 454 | template=cfn_template, |
| 455 | parameters=parms) |
| 456 | |
| 457 | resources = self.client.resources.list(stack_identifier) |
| 458 | self.res_assert_for_prod(resources, bj_prod=False, fj_zone=False, |
| 459 | shannxi_provice=True) |
| 460 | self.output_assert_for_prod(stack_identifier, False) |
| 461 | |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 462 | def test_stack_create_update_cfn_template_prod_to_test(self): |
| 463 | parms = {'env_type': 'prod'} |
| 464 | stack_identifier = self.stack_create(template=cfn_template, |
| 465 | parameters=parms) |
| 466 | resources = self.client.resources.list(stack_identifier) |
| 467 | self.res_assert_for_prod(resources) |
huangtianhua | 27075a9 | 2016-07-26 14:32:40 +0800 | [diff] [blame] | 468 | self.output_assert_for_prod(stack_identifier) |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 469 | |
huangtianhua | 26da898 | 2016-07-27 18:11:58 +0800 | [diff] [blame] | 470 | parms = {'zone': 'xiamen', |
| 471 | 'env_type': 'prod'} |
| 472 | self.update_stack(stack_identifier, |
| 473 | template=cfn_template, |
| 474 | parameters=parms) |
| 475 | |
| 476 | resources = self.client.resources.list(stack_identifier) |
| 477 | self.res_assert_for_prod(resources, bj_prod=False, fj_zone=True) |
| 478 | self.output_assert_for_prod(stack_identifier, bj_prod=False) |
| 479 | |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 480 | parms = {'zone': 'xianyang', |
| 481 | 'env_type': 'prod'} |
| 482 | self.update_stack(stack_identifier, |
| 483 | template=cfn_template, |
| 484 | parameters=parms) |
| 485 | |
| 486 | resources = self.client.resources.list(stack_identifier) |
| 487 | self.res_assert_for_prod(resources, bj_prod=False, fj_zone=False, |
| 488 | shannxi_provice=True) |
| 489 | self.output_assert_for_prod(stack_identifier, bj_prod=False) |
| 490 | |
| 491 | parms = {'zone': 'shanghai', |
| 492 | 'env_type': 'prod'} |
| 493 | self.update_stack(stack_identifier, |
| 494 | template=cfn_template, |
| 495 | parameters=parms) |
| 496 | |
| 497 | resources = self.client.resources.list(stack_identifier) |
| 498 | self.res_assert_for_prod(resources, bj_prod=False, fj_zone=False, |
| 499 | shannxi_provice=False) |
| 500 | self.output_assert_for_prod(stack_identifier, bj_prod=False) |
| 501 | |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 502 | parms = {'env_type': 'test'} |
| 503 | self.update_stack(stack_identifier, |
| 504 | template=cfn_template, |
| 505 | parameters=parms) |
| 506 | |
| 507 | resources = self.client.resources.list(stack_identifier) |
| 508 | self.res_assert_for_test(resources) |
huangtianhua | 27075a9 | 2016-07-26 14:32:40 +0800 | [diff] [blame] | 509 | self.output_assert_for_test(stack_identifier) |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 510 | |
huangtianhua | 26da898 | 2016-07-27 18:11:58 +0800 | [diff] [blame] | 511 | parms = {'env_type': 'test', |
| 512 | 'zone': 'fuzhou'} |
| 513 | self.update_stack(stack_identifier, |
| 514 | template=cfn_template, |
| 515 | parameters=parms) |
| 516 | |
| 517 | resources = self.client.resources.list(stack_identifier) |
| 518 | self.res_assert_for_test(resources, fj_zone=True) |
| 519 | self.output_assert_for_test(stack_identifier) |
| 520 | |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 521 | parms = {'env_type': 'test', |
| 522 | 'zone': 'xianyang'} |
| 523 | self.update_stack(stack_identifier, |
| 524 | template=cfn_template, |
| 525 | parameters=parms) |
| 526 | |
| 527 | resources = self.client.resources.list(stack_identifier) |
| 528 | self.res_assert_for_test(resources, fj_zone=False, |
| 529 | shannxi_provice=True) |
| 530 | self.output_assert_for_test(stack_identifier) |
| 531 | |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 532 | def test_stack_create_update_hot_template_test_to_prod(self): |
| 533 | stack_identifier = self.stack_create(template=hot_template) |
| 534 | resources = self.client.resources.list(stack_identifier) |
| 535 | self.res_assert_for_test(resources) |
huangtianhua | 27075a9 | 2016-07-26 14:32:40 +0800 | [diff] [blame] | 536 | self.output_assert_for_test(stack_identifier) |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 537 | |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 538 | parms = {'zone': 'xianyang'} |
| 539 | self.update_stack(stack_identifier, |
| 540 | template=hot_template, |
| 541 | parameters=parms) |
| 542 | |
| 543 | resources = self.client.resources.list(stack_identifier) |
| 544 | self.res_assert_for_test(resources, shannxi_provice=True) |
| 545 | self.output_assert_for_test(stack_identifier) |
| 546 | |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 547 | parms = {'env_type': 'prod'} |
| 548 | self.update_stack(stack_identifier, |
| 549 | template=hot_template, |
| 550 | parameters=parms) |
| 551 | |
| 552 | resources = self.client.resources.list(stack_identifier) |
| 553 | self.res_assert_for_prod(resources) |
huangtianhua | 27075a9 | 2016-07-26 14:32:40 +0800 | [diff] [blame] | 554 | self.output_assert_for_prod(stack_identifier) |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 555 | |
huangtianhua | 7bdc751 | 2016-06-17 09:25:38 +0800 | [diff] [blame] | 556 | parms = {'env_type': 'prod', |
| 557 | 'zone': 'shanghai'} |
| 558 | self.update_stack(stack_identifier, |
| 559 | template=hot_template, |
| 560 | parameters=parms) |
| 561 | |
| 562 | resources = self.client.resources.list(stack_identifier) |
| 563 | self.res_assert_for_prod(resources, False) |
| 564 | self.output_assert_for_prod(stack_identifier, False) |
| 565 | |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 566 | parms = {'env_type': 'prod', |
| 567 | 'zone': 'xianyang'} |
| 568 | self.update_stack(stack_identifier, |
| 569 | template=hot_template, |
| 570 | parameters=parms) |
| 571 | |
| 572 | resources = self.client.resources.list(stack_identifier) |
| 573 | self.res_assert_for_prod(resources, False, shannxi_provice=True) |
| 574 | self.output_assert_for_prod(stack_identifier, False) |
| 575 | |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 576 | def test_stack_create_update_hot_template_prod_to_test(self): |
| 577 | parms = {'env_type': 'prod'} |
| 578 | stack_identifier = self.stack_create(template=hot_template, |
| 579 | parameters=parms) |
| 580 | resources = self.client.resources.list(stack_identifier) |
| 581 | self.res_assert_for_prod(resources) |
huangtianhua | 27075a9 | 2016-07-26 14:32:40 +0800 | [diff] [blame] | 582 | self.output_assert_for_prod(stack_identifier) |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 583 | |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 584 | parms = {'env_type': 'prod', |
| 585 | 'zone': 'xianyang'} |
| 586 | self.update_stack(stack_identifier, |
| 587 | template=hot_template, |
| 588 | parameters=parms) |
| 589 | |
| 590 | resources = self.client.resources.list(stack_identifier) |
| 591 | self.res_assert_for_prod(resources, False, shannxi_provice=True) |
| 592 | self.output_assert_for_prod(stack_identifier, False) |
| 593 | |
huangtianhua | 99a25de | 2016-07-26 10:58:33 +0800 | [diff] [blame] | 594 | parms = {'env_type': 'test'} |
| 595 | self.update_stack(stack_identifier, |
| 596 | template=hot_template, |
| 597 | parameters=parms) |
| 598 | |
| 599 | resources = self.client.resources.list(stack_identifier) |
| 600 | self.res_assert_for_test(resources) |
huangtianhua | 27075a9 | 2016-07-26 14:32:40 +0800 | [diff] [blame] | 601 | self.output_assert_for_test(stack_identifier) |
Zane Bitter | a9b5aaf | 2016-09-12 20:51:52 -0400 | [diff] [blame] | 602 | |
Zane Bitter | 1a977c6 | 2016-09-08 15:37:51 -0400 | [diff] [blame] | 603 | parms = {'env_type': 'test', |
| 604 | 'zone': 'xianyang'} |
| 605 | self.update_stack(stack_identifier, |
| 606 | template=hot_template, |
| 607 | parameters=parms) |
| 608 | |
| 609 | resources = self.client.resources.list(stack_identifier) |
| 610 | self.res_assert_for_test(resources, fj_zone=False, |
| 611 | shannxi_provice=True) |
| 612 | self.output_assert_for_test(stack_identifier) |
| 613 | |
Zane Bitter | a9b5aaf | 2016-09-12 20:51:52 -0400 | [diff] [blame] | 614 | def test_condition_rename(self): |
| 615 | stack_identifier = self.stack_create(template=before_rename_tmpl) |
| 616 | self.update_stack(stack_identifier, template=after_rename_tmpl) |
| 617 | self.update_stack(stack_identifier, template=fail_rename_tmpl, |
| 618 | expected_status='UPDATE_FAILED') |
| 619 | self.update_stack(stack_identifier, template=recover_rename_tmpl) |