Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [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 | import json |
Pavlo Shchelokovskyy | 60e0ecd | 2014-12-14 22:17:21 +0200 | [diff] [blame] | 14 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 15 | import yaml |
| 16 | |
| 17 | from heat_integrationtests.common import test |
| 18 | |
| 19 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 20 | class TemplateResourceTest(test.HeatIntegrationTest): |
| 21 | """Prove that we can use the registry in a nested provider.""" |
Angus Salkeld | 95403d8 | 2015-02-12 14:06:01 +1000 | [diff] [blame] | 22 | |
| 23 | template = ''' |
| 24 | heat_template_version: 2013-05-23 |
| 25 | resources: |
| 26 | secret1: |
| 27 | type: OS::Heat::RandomString |
| 28 | outputs: |
| 29 | secret-out: |
| 30 | value: { get_attr: [secret1, value] } |
| 31 | ''' |
| 32 | nested_templ = ''' |
| 33 | heat_template_version: 2013-05-23 |
| 34 | resources: |
| 35 | secret2: |
| 36 | type: OS::Heat::RandomString |
| 37 | outputs: |
| 38 | value: |
| 39 | value: { get_attr: [secret2, value] } |
| 40 | ''' |
| 41 | |
| 42 | env_templ = ''' |
| 43 | resource_registry: |
| 44 | "OS::Heat::RandomString": nested.yaml |
| 45 | ''' |
| 46 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 47 | def setUp(self): |
| 48 | super(TemplateResourceTest, self).setUp() |
| 49 | self.client = self.orchestration_client |
| 50 | |
| 51 | def test_nested_env(self): |
| 52 | main_templ = ''' |
| 53 | heat_template_version: 2013-05-23 |
| 54 | resources: |
| 55 | secret1: |
| 56 | type: My::NestedSecret |
| 57 | outputs: |
| 58 | secret-out: |
| 59 | value: { get_attr: [secret1, value] } |
| 60 | ''' |
| 61 | |
| 62 | nested_templ = ''' |
| 63 | heat_template_version: 2013-05-23 |
| 64 | resources: |
| 65 | secret2: |
| 66 | type: My::Secret |
| 67 | outputs: |
| 68 | value: |
| 69 | value: { get_attr: [secret2, value] } |
| 70 | ''' |
| 71 | |
| 72 | env_templ = ''' |
| 73 | resource_registry: |
| 74 | "My::Secret": "OS::Heat::RandomString" |
| 75 | "My::NestedSecret": nested.yaml |
| 76 | ''' |
| 77 | |
| 78 | stack_identifier = self.stack_create( |
| 79 | template=main_templ, |
| 80 | files={'nested.yaml': nested_templ}, |
| 81 | environment=env_templ) |
Angus Salkeld | 2e61f9f | 2015-04-07 09:25:50 +1000 | [diff] [blame] | 82 | nested_ident = self.assert_resource_is_a_stack(stack_identifier, |
| 83 | 'secret1') |
| 84 | # prove that resource.parent_resource is populated. |
| 85 | sec2 = self.client.resources.get(nested_ident, 'secret2') |
| 86 | self.assertEqual('secret1', sec2.parent_resource) |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 87 | |
| 88 | def test_no_infinite_recursion(self): |
| 89 | """Prove that we can override a python resource. |
| 90 | |
| 91 | And use that resource within the template resource. |
| 92 | """ |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 93 | stack_identifier = self.stack_create( |
Angus Salkeld | 95403d8 | 2015-02-12 14:06:01 +1000 | [diff] [blame] | 94 | template=self.template, |
| 95 | files={'nested.yaml': self.nested_templ}, |
| 96 | environment=self.env_templ) |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 97 | self.assert_resource_is_a_stack(stack_identifier, 'secret1') |
| 98 | |
Angus Salkeld | 95403d8 | 2015-02-12 14:06:01 +1000 | [diff] [blame] | 99 | def test_nested_stack_delete_then_delete_parent_stack(self): |
| 100 | """Check the robustness of stack deletion. |
| 101 | |
| 102 | This tests that if you manually delete a nested |
| 103 | stack, the parent stack is still deletable. |
| 104 | """ |
Sergey Kraynev | bf67ce3 | 2015-04-17 10:54:20 -0400 | [diff] [blame] | 105 | # disable cleanup so we can call _stack_delete() directly. |
| 106 | stack_identifier = self.stack_create( |
Angus Salkeld | 95403d8 | 2015-02-12 14:06:01 +1000 | [diff] [blame] | 107 | template=self.template, |
| 108 | files={'nested.yaml': self.nested_templ}, |
| 109 | environment=self.env_templ, |
Sergey Kraynev | bf67ce3 | 2015-04-17 10:54:20 -0400 | [diff] [blame] | 110 | enable_cleanup=False) |
Angus Salkeld | 95403d8 | 2015-02-12 14:06:01 +1000 | [diff] [blame] | 111 | |
| 112 | nested_ident = self.assert_resource_is_a_stack(stack_identifier, |
| 113 | 'secret1') |
| 114 | |
| 115 | self._stack_delete(nested_ident) |
| 116 | self._stack_delete(stack_identifier) |
| 117 | |
Angus Salkeld | 19b9e1d | 2015-05-08 11:02:38 +1000 | [diff] [blame] | 118 | def test_change_in_file_path(self): |
| 119 | stack_identifier = self.stack_create( |
| 120 | template=self.template, |
| 121 | files={'nested.yaml': self.nested_templ}, |
| 122 | environment=self.env_templ) |
| 123 | stack = self.client.stacks.get(stack_identifier) |
| 124 | secret_out1 = self._stack_output(stack, 'secret-out') |
| 125 | |
| 126 | nested_templ_2 = ''' |
| 127 | heat_template_version: 2013-05-23 |
| 128 | resources: |
| 129 | secret2: |
| 130 | type: OS::Heat::RandomString |
| 131 | outputs: |
| 132 | value: |
| 133 | value: freddy |
| 134 | ''' |
| 135 | env_templ_2 = ''' |
| 136 | resource_registry: |
| 137 | "OS::Heat::RandomString": new/nested.yaml |
| 138 | ''' |
| 139 | self.update_stack(stack_identifier, |
| 140 | template=self.template, |
| 141 | files={'new/nested.yaml': nested_templ_2}, |
| 142 | environment=env_templ_2) |
| 143 | stack = self.client.stacks.get(stack_identifier) |
| 144 | secret_out2 = self._stack_output(stack, 'secret-out') |
| 145 | self.assertNotEqual(secret_out1, secret_out2) |
| 146 | self.assertEqual('freddy', secret_out2) |
| 147 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 148 | |
| 149 | class NestedAttributesTest(test.HeatIntegrationTest): |
| 150 | """Prove that we can use the template resource references.""" |
| 151 | |
| 152 | main_templ = ''' |
| 153 | heat_template_version: 2014-10-16 |
| 154 | resources: |
| 155 | secret2: |
| 156 | type: My::NestedSecret |
| 157 | outputs: |
| 158 | old_way: |
| 159 | value: { get_attr: [secret2, nested_str]} |
| 160 | test_attr1: |
| 161 | value: { get_attr: [secret2, resource.secret1, value]} |
| 162 | test_attr2: |
| 163 | value: { get_attr: [secret2, resource.secret1.value]} |
| 164 | test_ref: |
| 165 | value: { get_resource: secret2 } |
| 166 | ''' |
| 167 | |
| 168 | env_templ = ''' |
| 169 | resource_registry: |
| 170 | "My::NestedSecret": nested.yaml |
| 171 | ''' |
| 172 | |
| 173 | def setUp(self): |
| 174 | super(NestedAttributesTest, self).setUp() |
| 175 | self.client = self.orchestration_client |
| 176 | |
| 177 | def test_stack_ref(self): |
| 178 | nested_templ = ''' |
| 179 | heat_template_version: 2014-10-16 |
| 180 | resources: |
| 181 | secret1: |
| 182 | type: OS::Heat::RandomString |
Angus Salkeld | a89a028 | 2015-07-24 15:47:38 +1000 | [diff] [blame] | 183 | outputs: |
| 184 | nested_str: |
| 185 | value: {get_attr: [secret1, value]} |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 186 | ''' |
| 187 | stack_identifier = self.stack_create( |
| 188 | template=self.main_templ, |
| 189 | files={'nested.yaml': nested_templ}, |
| 190 | environment=self.env_templ) |
| 191 | self.assert_resource_is_a_stack(stack_identifier, 'secret2') |
| 192 | stack = self.client.stacks.get(stack_identifier) |
| 193 | test_ref = self._stack_output(stack, 'test_ref') |
| 194 | self.assertIn('arn:openstack:heat:', test_ref) |
| 195 | |
| 196 | def test_transparent_ref(self): |
| 197 | """With the addition of OS::stack_id we can now use the nested resource |
| 198 | more transparently. |
| 199 | """ |
| 200 | nested_templ = ''' |
| 201 | heat_template_version: 2014-10-16 |
| 202 | resources: |
| 203 | secret1: |
| 204 | type: OS::Heat::RandomString |
| 205 | outputs: |
| 206 | OS::stack_id: |
| 207 | value: {get_resource: secret1} |
| 208 | nested_str: |
| 209 | value: {get_attr: [secret1, value]} |
| 210 | ''' |
| 211 | stack_identifier = self.stack_create( |
| 212 | template=self.main_templ, |
| 213 | files={'nested.yaml': nested_templ}, |
| 214 | environment=self.env_templ) |
| 215 | self.assert_resource_is_a_stack(stack_identifier, 'secret2') |
| 216 | stack = self.client.stacks.get(stack_identifier) |
| 217 | test_ref = self._stack_output(stack, 'test_ref') |
| 218 | test_attr = self._stack_output(stack, 'old_way') |
| 219 | |
| 220 | self.assertNotIn('arn:openstack:heat', test_ref) |
| 221 | self.assertEqual(test_attr, test_ref) |
| 222 | |
| 223 | def test_nested_attributes(self): |
| 224 | nested_templ = ''' |
| 225 | heat_template_version: 2014-10-16 |
| 226 | resources: |
| 227 | secret1: |
| 228 | type: OS::Heat::RandomString |
| 229 | outputs: |
| 230 | nested_str: |
| 231 | value: {get_attr: [secret1, value]} |
| 232 | ''' |
| 233 | stack_identifier = self.stack_create( |
| 234 | template=self.main_templ, |
| 235 | files={'nested.yaml': nested_templ}, |
| 236 | environment=self.env_templ) |
| 237 | self.assert_resource_is_a_stack(stack_identifier, 'secret2') |
| 238 | stack = self.client.stacks.get(stack_identifier) |
| 239 | old_way = self._stack_output(stack, 'old_way') |
| 240 | test_attr1 = self._stack_output(stack, 'test_attr1') |
| 241 | test_attr2 = self._stack_output(stack, 'test_attr2') |
| 242 | |
| 243 | self.assertEqual(old_way, test_attr1) |
| 244 | self.assertEqual(old_way, test_attr2) |
| 245 | |
| 246 | |
| 247 | class TemplateResourceUpdateTest(test.HeatIntegrationTest): |
| 248 | """Prove that we can do template resource updates.""" |
| 249 | |
| 250 | main_template = ''' |
| 251 | HeatTemplateFormatVersion: '2012-12-12' |
| 252 | Resources: |
| 253 | the_nested: |
| 254 | Type: the.yaml |
| 255 | Properties: |
| 256 | one: my_name |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 257 | two: your_name |
| 258 | Outputs: |
| 259 | identifier: |
| 260 | Value: {Ref: the_nested} |
| 261 | value: |
| 262 | Value: {'Fn::GetAtt': [the_nested, the_str]} |
| 263 | ''' |
| 264 | |
| 265 | main_template_change_prop = ''' |
| 266 | HeatTemplateFormatVersion: '2012-12-12' |
| 267 | Resources: |
| 268 | the_nested: |
| 269 | Type: the.yaml |
| 270 | Properties: |
| 271 | one: updated_name |
| 272 | two: your_name |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 273 | |
| 274 | Outputs: |
| 275 | identifier: |
| 276 | Value: {Ref: the_nested} |
| 277 | value: |
| 278 | Value: {'Fn::GetAtt': [the_nested, the_str]} |
| 279 | ''' |
| 280 | |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 281 | main_template_add_prop = ''' |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 282 | HeatTemplateFormatVersion: '2012-12-12' |
| 283 | Resources: |
| 284 | the_nested: |
| 285 | Type: the.yaml |
| 286 | Properties: |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 287 | one: my_name |
| 288 | two: your_name |
| 289 | three: third_name |
| 290 | |
| 291 | Outputs: |
| 292 | identifier: |
| 293 | Value: {Ref: the_nested} |
| 294 | value: |
| 295 | Value: {'Fn::GetAtt': [the_nested, the_str]} |
| 296 | ''' |
| 297 | |
| 298 | main_template_remove_prop = ''' |
| 299 | HeatTemplateFormatVersion: '2012-12-12' |
| 300 | Resources: |
| 301 | the_nested: |
| 302 | Type: the.yaml |
| 303 | Properties: |
| 304 | one: my_name |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 305 | |
| 306 | Outputs: |
| 307 | identifier: |
| 308 | Value: {Ref: the_nested} |
| 309 | value: |
| 310 | Value: {'Fn::GetAtt': [the_nested, the_str]} |
| 311 | ''' |
| 312 | |
| 313 | initial_tmpl = ''' |
| 314 | HeatTemplateFormatVersion: '2012-12-12' |
| 315 | Parameters: |
| 316 | one: |
| 317 | Default: foo |
| 318 | Type: String |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 319 | two: |
| 320 | Default: bar |
| 321 | Type: String |
| 322 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 323 | Resources: |
| 324 | NestedResource: |
| 325 | Type: OS::Heat::RandomString |
| 326 | Properties: |
| 327 | salt: {Ref: one} |
| 328 | Outputs: |
| 329 | the_str: |
| 330 | Value: {'Fn::GetAtt': [NestedResource, value]} |
| 331 | ''' |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 332 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 333 | prop_change_tmpl = ''' |
| 334 | HeatTemplateFormatVersion: '2012-12-12' |
| 335 | Parameters: |
| 336 | one: |
| 337 | Default: yikes |
| 338 | Type: String |
| 339 | two: |
| 340 | Default: foo |
| 341 | Type: String |
| 342 | Resources: |
| 343 | NestedResource: |
| 344 | Type: OS::Heat::RandomString |
| 345 | Properties: |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 346 | salt: {Ref: two} |
| 347 | Outputs: |
| 348 | the_str: |
| 349 | Value: {'Fn::GetAtt': [NestedResource, value]} |
| 350 | ''' |
| 351 | |
| 352 | prop_add_tmpl = ''' |
| 353 | HeatTemplateFormatVersion: '2012-12-12' |
| 354 | Parameters: |
| 355 | one: |
| 356 | Default: yikes |
| 357 | Type: String |
| 358 | two: |
| 359 | Default: foo |
| 360 | Type: String |
| 361 | three: |
| 362 | Default: bar |
| 363 | Type: String |
| 364 | |
| 365 | Resources: |
| 366 | NestedResource: |
| 367 | Type: OS::Heat::RandomString |
| 368 | Properties: |
| 369 | salt: {Ref: three} |
| 370 | Outputs: |
| 371 | the_str: |
| 372 | Value: {'Fn::GetAtt': [NestedResource, value]} |
| 373 | ''' |
| 374 | |
| 375 | prop_remove_tmpl = ''' |
| 376 | HeatTemplateFormatVersion: '2012-12-12' |
| 377 | Parameters: |
| 378 | one: |
| 379 | Default: yikes |
| 380 | Type: String |
| 381 | |
| 382 | Resources: |
| 383 | NestedResource: |
| 384 | Type: OS::Heat::RandomString |
| 385 | Properties: |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 386 | salt: {Ref: one} |
| 387 | Outputs: |
| 388 | the_str: |
| 389 | Value: {'Fn::GetAtt': [NestedResource, value]} |
| 390 | ''' |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 391 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 392 | attr_change_tmpl = ''' |
| 393 | HeatTemplateFormatVersion: '2012-12-12' |
| 394 | Parameters: |
| 395 | one: |
| 396 | Default: foo |
| 397 | Type: String |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 398 | two: |
| 399 | Default: bar |
| 400 | Type: String |
| 401 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 402 | Resources: |
| 403 | NestedResource: |
| 404 | Type: OS::Heat::RandomString |
| 405 | Properties: |
| 406 | salt: {Ref: one} |
| 407 | Outputs: |
| 408 | the_str: |
| 409 | Value: {'Fn::GetAtt': [NestedResource, value]} |
| 410 | something_else: |
| 411 | Value: just_a_string |
| 412 | ''' |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 413 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 414 | content_change_tmpl = ''' |
| 415 | HeatTemplateFormatVersion: '2012-12-12' |
| 416 | Parameters: |
| 417 | one: |
| 418 | Default: foo |
| 419 | Type: String |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 420 | two: |
| 421 | Default: bar |
| 422 | Type: String |
| 423 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 424 | Resources: |
| 425 | NestedResource: |
| 426 | Type: OS::Heat::RandomString |
| 427 | Properties: |
| 428 | salt: yum |
| 429 | Outputs: |
| 430 | the_str: |
| 431 | Value: {'Fn::GetAtt': [NestedResource, value]} |
| 432 | ''' |
| 433 | |
| 434 | EXPECTED = (UPDATE, NOCHANGE) = ('update', 'nochange') |
| 435 | scenarios = [ |
| 436 | ('no_changes', dict(template=main_template, |
| 437 | provider=initial_tmpl, |
| 438 | expect=NOCHANGE)), |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 439 | ('main_tmpl_change', dict(template=main_template_change_prop, |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 440 | provider=initial_tmpl, |
| 441 | expect=UPDATE)), |
| 442 | ('provider_change', dict(template=main_template, |
| 443 | provider=content_change_tmpl, |
| 444 | expect=UPDATE)), |
| 445 | ('provider_props_change', dict(template=main_template, |
| 446 | provider=prop_change_tmpl, |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 447 | expect=UPDATE)), |
| 448 | ('provider_props_add', dict(template=main_template_add_prop, |
| 449 | provider=prop_add_tmpl, |
| 450 | expect=UPDATE)), |
| 451 | ('provider_props_remove', dict(template=main_template_remove_prop, |
| 452 | provider=prop_remove_tmpl, |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 453 | expect=NOCHANGE)), |
| 454 | ('provider_attr_change', dict(template=main_template, |
| 455 | provider=attr_change_tmpl, |
| 456 | expect=NOCHANGE)), |
| 457 | ] |
| 458 | |
| 459 | def setUp(self): |
| 460 | super(TemplateResourceUpdateTest, self).setUp() |
| 461 | self.client = self.orchestration_client |
| 462 | |
| 463 | def test_template_resource_update_template_schema(self): |
| 464 | stack_identifier = self.stack_create( |
| 465 | template=self.main_template, |
| 466 | files={'the.yaml': self.initial_tmpl}) |
| 467 | stack = self.client.stacks.get(stack_identifier) |
| 468 | initial_id = self._stack_output(stack, 'identifier') |
| 469 | initial_val = self._stack_output(stack, 'value') |
| 470 | |
| 471 | self.update_stack(stack_identifier, |
| 472 | self.template, |
| 473 | files={'the.yaml': self.provider}) |
| 474 | stack = self.client.stacks.get(stack_identifier) |
| 475 | self.assertEqual(initial_id, |
| 476 | self._stack_output(stack, 'identifier')) |
| 477 | if self.expect == self.NOCHANGE: |
| 478 | self.assertEqual(initial_val, |
| 479 | self._stack_output(stack, 'value')) |
| 480 | else: |
| 481 | self.assertNotEqual(initial_val, |
| 482 | self._stack_output(stack, 'value')) |
| 483 | |
| 484 | |
Angus Salkeld | 5a3e1dd | 2015-02-03 15:31:47 +1000 | [diff] [blame] | 485 | class TemplateResourceUpdateFailedTest(test.HeatIntegrationTest): |
| 486 | """Prove that we can do updates on a nested stack to fix a stack.""" |
| 487 | main_template = ''' |
| 488 | HeatTemplateFormatVersion: '2012-12-12' |
| 489 | Resources: |
| 490 | keypair: |
| 491 | Type: OS::Nova::KeyPair |
| 492 | Properties: |
| 493 | name: replace-this |
| 494 | save_private_key: false |
| 495 | server: |
| 496 | Type: server_fail.yaml |
| 497 | DependsOn: keypair |
| 498 | ''' |
| 499 | nested_templ = ''' |
| 500 | HeatTemplateFormatVersion: '2012-12-12' |
| 501 | Resources: |
| 502 | RealRandom: |
| 503 | Type: OS::Heat::RandomString |
| 504 | ''' |
| 505 | |
| 506 | def setUp(self): |
| 507 | super(TemplateResourceUpdateFailedTest, self).setUp() |
| 508 | self.client = self.orchestration_client |
Sergey Kraynev | a265c13 | 2015-02-13 03:51:03 -0500 | [diff] [blame] | 509 | self.assign_keypair() |
Angus Salkeld | 5a3e1dd | 2015-02-03 15:31:47 +1000 | [diff] [blame] | 510 | |
| 511 | def test_update_on_failed_create(self): |
Vikas Jain | ac6b02f | 2015-02-11 11:31:46 -0800 | [diff] [blame] | 512 | # create a stack with "server" dependent on "keypair", but |
Angus Salkeld | 5a3e1dd | 2015-02-03 15:31:47 +1000 | [diff] [blame] | 513 | # keypair fails, so "server" is not created properly. |
| 514 | # We then fix the template and it should succeed. |
| 515 | broken_templ = self.main_template.replace('replace-this', |
| 516 | self.keypair_name) |
| 517 | stack_identifier = self.stack_create( |
| 518 | template=broken_templ, |
| 519 | files={'server_fail.yaml': self.nested_templ}, |
| 520 | expected_status='CREATE_FAILED') |
| 521 | |
| 522 | fixed_templ = self.main_template.replace('replace-this', |
| 523 | test.rand_name()) |
| 524 | self.update_stack(stack_identifier, |
| 525 | fixed_templ, |
| 526 | files={'server_fail.yaml': self.nested_templ}) |
| 527 | |
| 528 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 529 | class TemplateResourceAdoptTest(test.HeatIntegrationTest): |
| 530 | """Prove that we can do template resource adopt/abandon.""" |
| 531 | |
| 532 | main_template = ''' |
| 533 | HeatTemplateFormatVersion: '2012-12-12' |
| 534 | Resources: |
| 535 | the_nested: |
| 536 | Type: the.yaml |
| 537 | Properties: |
| 538 | one: my_name |
| 539 | Outputs: |
| 540 | identifier: |
| 541 | Value: {Ref: the_nested} |
| 542 | value: |
| 543 | Value: {'Fn::GetAtt': [the_nested, the_str]} |
| 544 | ''' |
| 545 | |
| 546 | nested_templ = ''' |
| 547 | HeatTemplateFormatVersion: '2012-12-12' |
| 548 | Parameters: |
| 549 | one: |
| 550 | Default: foo |
| 551 | Type: String |
| 552 | Resources: |
| 553 | RealRandom: |
| 554 | Type: OS::Heat::RandomString |
| 555 | Properties: |
| 556 | salt: {Ref: one} |
| 557 | Outputs: |
| 558 | the_str: |
| 559 | Value: {'Fn::GetAtt': [RealRandom, value]} |
| 560 | ''' |
| 561 | |
| 562 | def setUp(self): |
| 563 | super(TemplateResourceAdoptTest, self).setUp() |
| 564 | self.client = self.orchestration_client |
| 565 | |
| 566 | def _yaml_to_json(self, yaml_templ): |
| 567 | return yaml.load(yaml_templ) |
| 568 | |
| 569 | def test_abandon(self): |
Sergey Kraynev | bf67ce3 | 2015-04-17 10:54:20 -0400 | [diff] [blame] | 570 | stack_identifier = self.stack_create( |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 571 | template=self.main_template, |
| 572 | files={'the.yaml': self.nested_templ}, |
Sergey Kraynev | bf67ce3 | 2015-04-17 10:54:20 -0400 | [diff] [blame] | 573 | enable_cleanup=False |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 574 | ) |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 575 | |
Sirushti Murugesan | 04ee802 | 2015-02-02 23:00:23 +0530 | [diff] [blame] | 576 | info = self.stack_abandon(stack_id=stack_identifier) |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 577 | self.assertEqual(self._yaml_to_json(self.main_template), |
| 578 | info['template']) |
| 579 | self.assertEqual(self._yaml_to_json(self.nested_templ), |
| 580 | info['resources']['the_nested']['template']) |
| 581 | |
| 582 | def test_adopt(self): |
| 583 | data = { |
| 584 | 'resources': { |
| 585 | 'the_nested': { |
| 586 | "type": "the.yaml", |
| 587 | "resources": { |
| 588 | "RealRandom": { |
| 589 | "type": "OS::Heat::RandomString", |
| 590 | 'resource_data': {'value': 'goopie'}, |
| 591 | 'resource_id': 'froggy' |
| 592 | } |
| 593 | } |
| 594 | } |
| 595 | }, |
| 596 | "environment": {"parameters": {}}, |
| 597 | "template": yaml.load(self.main_template) |
| 598 | } |
| 599 | |
| 600 | stack_identifier = self.stack_adopt( |
| 601 | adopt_data=json.dumps(data), |
| 602 | files={'the.yaml': self.nested_templ}) |
| 603 | |
| 604 | self.assert_resource_is_a_stack(stack_identifier, 'the_nested') |
| 605 | stack = self.client.stacks.get(stack_identifier) |
| 606 | self.assertEqual('goopie', self._stack_output(stack, 'value')) |
Angus Salkeld | 8760172 | 2015-01-05 14:57:27 +1000 | [diff] [blame] | 607 | |
| 608 | |
| 609 | class TemplateResourceCheckTest(test.HeatIntegrationTest): |
| 610 | """Prove that we can do template resource check.""" |
| 611 | |
| 612 | main_template = ''' |
| 613 | HeatTemplateFormatVersion: '2012-12-12' |
| 614 | Resources: |
| 615 | the_nested: |
| 616 | Type: the.yaml |
| 617 | Properties: |
| 618 | one: my_name |
| 619 | Outputs: |
| 620 | identifier: |
| 621 | Value: {Ref: the_nested} |
| 622 | value: |
| 623 | Value: {'Fn::GetAtt': [the_nested, the_str]} |
| 624 | ''' |
| 625 | |
| 626 | nested_templ = ''' |
| 627 | HeatTemplateFormatVersion: '2012-12-12' |
| 628 | Parameters: |
| 629 | one: |
| 630 | Default: foo |
| 631 | Type: String |
| 632 | Resources: |
| 633 | RealRandom: |
| 634 | Type: OS::Heat::RandomString |
| 635 | Properties: |
| 636 | salt: {Ref: one} |
| 637 | Outputs: |
| 638 | the_str: |
| 639 | Value: {'Fn::GetAtt': [RealRandom, value]} |
| 640 | ''' |
| 641 | |
| 642 | def setUp(self): |
| 643 | super(TemplateResourceCheckTest, self).setUp() |
| 644 | self.client = self.orchestration_client |
| 645 | |
| 646 | def test_check(self): |
Sergey Kraynev | bf67ce3 | 2015-04-17 10:54:20 -0400 | [diff] [blame] | 647 | stack_identifier = self.stack_create( |
Angus Salkeld | 8760172 | 2015-01-05 14:57:27 +1000 | [diff] [blame] | 648 | template=self.main_template, |
Sergey Kraynev | bf67ce3 | 2015-04-17 10:54:20 -0400 | [diff] [blame] | 649 | files={'the.yaml': self.nested_templ} |
Angus Salkeld | 8760172 | 2015-01-05 14:57:27 +1000 | [diff] [blame] | 650 | ) |
Angus Salkeld | 8760172 | 2015-01-05 14:57:27 +1000 | [diff] [blame] | 651 | |
| 652 | self.client.actions.check(stack_id=stack_identifier) |
| 653 | self._wait_for_stack_status(stack_identifier, 'CHECK_COMPLETE') |
Angus Salkeld | 793b0fc | 2015-06-24 08:52:08 +1000 | [diff] [blame] | 654 | |
| 655 | |
| 656 | class TemplateResourceErrorMessageTest(test.HeatIntegrationTest): |
| 657 | """Prove that nested stack errors don't suck.""" |
| 658 | template = ''' |
| 659 | HeatTemplateFormatVersion: '2012-12-12' |
| 660 | Resources: |
| 661 | victim: |
| 662 | Type: fail.yaml |
| 663 | ''' |
| 664 | nested_templ = ''' |
| 665 | HeatTemplateFormatVersion: '2012-12-12' |
| 666 | Resources: |
| 667 | oops: |
| 668 | Type: OS::Heat::TestResource |
| 669 | Properties: |
| 670 | fail: true |
| 671 | wait_secs: 2 |
| 672 | ''' |
| 673 | |
| 674 | def setUp(self): |
| 675 | super(TemplateResourceErrorMessageTest, self).setUp() |
| 676 | self.client = self.orchestration_client |
| 677 | |
| 678 | def test_fail(self): |
| 679 | stack_identifier = self.stack_create( |
| 680 | template=self.template, |
| 681 | files={'fail.yaml': self.nested_templ}, |
| 682 | expected_status='CREATE_FAILED') |
| 683 | stack = self.client.stacks.get(stack_identifier) |
| 684 | |
| 685 | exp_path = 'resources.victim.resources.oops' |
| 686 | exp_msg = 'Test Resource failed oops' |
| 687 | exp = 'Resource CREATE failed: ValueError: %s: %s' % (exp_path, |
| 688 | exp_msg) |
| 689 | self.assertEqual(exp, stack.stack_status_reason) |
kairat_kushaev | 61a99e1 | 2015-07-31 16:22:45 +0300 | [diff] [blame] | 690 | |
| 691 | |
| 692 | class TemplateResourceSuspendResumeTest(test.HeatIntegrationTest): |
| 693 | """Prove that we can do template resource suspend/resume.""" |
| 694 | |
| 695 | main_template = ''' |
| 696 | heat_template_version: 2014-10-16 |
| 697 | parameters: |
| 698 | resources: |
| 699 | the_nested: |
| 700 | type: the.yaml |
| 701 | ''' |
| 702 | |
| 703 | nested_templ = ''' |
| 704 | heat_template_version: 2014-10-16 |
| 705 | resources: |
| 706 | test_random_string: |
| 707 | type: OS::Heat::RandomString |
| 708 | ''' |
| 709 | |
| 710 | def setUp(self): |
| 711 | super(TemplateResourceSuspendResumeTest, self).setUp() |
| 712 | self.client = self.orchestration_client |
| 713 | |
| 714 | def test_suspend_resume(self): |
| 715 | """Basic test for template resource suspend resume""" |
| 716 | stack_identifier = self.stack_create( |
| 717 | template=self.main_template, |
| 718 | files={'the.yaml': self.nested_templ} |
| 719 | ) |
| 720 | |
| 721 | self.stack_suspend(stack_identifier=stack_identifier) |
| 722 | self.stack_resume(stack_identifier=stack_identifier) |