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