blob: 1e9edd50ac735ce36d81f9334d0e7b1e5caafea3 [file] [log] [blame]
Steven Hardy6f0bda82014-12-12 17:49:10 +00001# 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
Angus Salkeldb61f8f12015-01-19 23:00:45 +100013import copy
Angus Salkeld011acc72015-01-16 20:26:34 +100014import json
15
Steven Hardy6f0bda82014-12-12 17:49:10 +000016from heatclient import exc
Pavlo Shchelokovskyy60e0ecd2014-12-14 22:17:21 +020017import six
Angus Salkeld011acc72015-01-16 20:26:34 +100018import yaml
Steven Hardy6f0bda82014-12-12 17:49:10 +000019
Rabi Mishra477efc92015-07-31 13:01:45 +053020from heat_integrationtests.functional import functional_base
Steven Hardy6f0bda82014-12-12 17:49:10 +000021
22
Rabi Mishra477efc92015-07-31 13:01:45 +053023class ResourceGroupTest(functional_base.FunctionalTestsBase):
Angus Salkeld665d86c2015-01-19 22:15:48 +100024 template = '''
Unmesh Gurjar0a25a732014-12-23 17:28:33 +053025heat_template_version: 2013-05-23
26resources:
27 random_group:
28 type: OS::Heat::ResourceGroup
29 properties:
Angus Salkeld665d86c2015-01-19 22:15:48 +100030 count: 0
Unmesh Gurjar0a25a732014-12-23 17:28:33 +053031 resource_def:
Angus Salkeld665d86c2015-01-19 22:15:48 +100032 type: My::RandomString
Unmesh Gurjar0a25a732014-12-23 17:28:33 +053033 properties:
34 length: 30
Angus Salkeldb61f8f12015-01-19 23:00:45 +100035 salt: initial
Unmesh Gurjar0a25a732014-12-23 17:28:33 +053036outputs:
37 random1:
38 value: {get_attr: [random_group, resource.0.value]}
39 random2:
40 value: {get_attr: [random_group, resource.1.value]}
41 all_values:
42 value: {get_attr: [random_group, value]}
43'''
44
Steven Hardy6f0bda82014-12-12 17:49:10 +000045 def setUp(self):
46 super(ResourceGroupTest, self).setUp()
Steven Hardy6f0bda82014-12-12 17:49:10 +000047
Steven Hardy6f0bda82014-12-12 17:49:10 +000048 def test_resource_group_zero_novalidate(self):
49 # Nested resources should be validated only when size > 0
50 # This allows features to be disabled via size=0 without
51 # triggering validation of nested resource custom contraints
52 # e.g images etc in the nested schema.
53 nested_template_fail = '''
54heat_template_version: 2013-05-23
Angus Salkeld665d86c2015-01-19 22:15:48 +100055parameters:
56 length:
57 type: string
58 default: 50
Angus Salkeldb61f8f12015-01-19 23:00:45 +100059 salt:
60 type: string
61 default: initial
Steven Hardy6f0bda82014-12-12 17:49:10 +000062resources:
63 random:
64 type: OS::Heat::RandomString
65 properties:
Angus Salkeld665d86c2015-01-19 22:15:48 +100066 length: BAD
Steven Hardy6f0bda82014-12-12 17:49:10 +000067'''
68
69 files = {'provider.yaml': nested_template_fail}
70 env = {'resource_registry':
71 {'My::RandomString': 'provider.yaml'}}
72 stack_identifier = self.stack_create(
Angus Salkeld665d86c2015-01-19 22:15:48 +100073 template=self.template,
Steven Hardy6f0bda82014-12-12 17:49:10 +000074 files=files,
75 environment=env
76 )
77
78 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
79 self.list_resources(stack_identifier))
80
81 # Check we created an empty nested stack
Rabi Mishra8bcff8a2015-09-21 18:15:04 +053082 nested_identifier = self.group_nested_identifier(stack_identifier,
83 'random_group')
Steven Hardy6f0bda82014-12-12 17:49:10 +000084 self.assertEqual({}, self.list_resources(nested_identifier))
85
86 # Prove validation works for non-zero create/update
Angus Salkeld665d86c2015-01-19 22:15:48 +100087 template_two_nested = self.template.replace("count: 0", "count: 2")
Peter Razumovskyd7500792014-10-08 19:19:13 +040088 expected_err = "Value 'BAD' is not an integer"
Steven Hardy6f0bda82014-12-12 17:49:10 +000089 ex = self.assertRaises(exc.HTTPBadRequest, self.update_stack,
90 stack_identifier, template_two_nested,
91 environment=env, files=files)
92 self.assertIn(expected_err, six.text_type(ex))
93
94 ex = self.assertRaises(exc.HTTPBadRequest, self.stack_create,
95 template=template_two_nested,
96 environment=env, files=files)
97 self.assertIn(expected_err, six.text_type(ex))
Unmesh Gurjar0a25a732014-12-23 17:28:33 +053098
Steven Hardy0145b8d2015-04-23 14:14:26 +100099 def _validate_resources(self, stack_identifier, expected_count):
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530100 resources = self.list_group_resources(stack_identifier,
101 'random_group')
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530102 self.assertEqual(expected_count, len(resources))
103 expected_resources = dict(
Angus Salkeld665d86c2015-01-19 22:15:48 +1000104 (str(idx), 'My::RandomString')
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530105 for idx in range(expected_count))
106
107 self.assertEqual(expected_resources, resources)
108
109 def test_create(self):
110 def validate_output(stack, output_key, length):
111 output_value = self._stack_output(stack, output_key)
112 self.assertEqual(length, len(output_value))
113 return output_value
114 # verify that the resources in resource group are identically
115 # configured, resource names and outputs are appropriate.
Angus Salkeld665d86c2015-01-19 22:15:48 +1000116 env = {'resource_registry':
117 {'My::RandomString': 'OS::Heat::RandomString'}}
118 create_template = self.template.replace("count: 0", "count: 2")
119 stack_identifier = self.stack_create(template=create_template,
120 environment=env)
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530121 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
122 self.list_resources(stack_identifier))
123
124 # validate count, type and name of resources in a resource group.
125 self._validate_resources(stack_identifier, 2)
126
127 # validate outputs
128 stack = self.client.stacks.get(stack_identifier)
129 outputs = []
130 outputs.append(validate_output(stack, 'random1', 30))
131 outputs.append(validate_output(stack, 'random2', 30))
132 self.assertEqual(outputs, self._stack_output(stack, 'all_values'))
133
134 def test_update_increase_decrease_count(self):
135 # create stack with resource group count 2
Angus Salkeld665d86c2015-01-19 22:15:48 +1000136 env = {'resource_registry':
137 {'My::RandomString': 'OS::Heat::RandomString'}}
138 create_template = self.template.replace("count: 0", "count: 2")
139 stack_identifier = self.stack_create(template=create_template,
140 environment=env)
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530141 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
142 self.list_resources(stack_identifier))
143 # verify that the resource group has 2 resources
144 self._validate_resources(stack_identifier, 2)
145
146 # increase the resource group count to 5
Angus Salkeld665d86c2015-01-19 22:15:48 +1000147 update_template = self.template.replace("count: 0", "count: 5")
148 self.update_stack(stack_identifier, update_template, environment=env)
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530149 # verify that the resource group has 5 resources
150 self._validate_resources(stack_identifier, 5)
151
152 # decrease the resource group count to 3
Angus Salkeld665d86c2015-01-19 22:15:48 +1000153 update_template = self.template.replace("count: 0", "count: 3")
154 self.update_stack(stack_identifier, update_template, environment=env)
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530155 # verify that the resource group has 3 resources
156 self._validate_resources(stack_identifier, 3)
Angus Salkeld011acc72015-01-16 20:26:34 +1000157
Steven Hardy0145b8d2015-04-23 14:14:26 +1000158 def test_update_removal_policies(self):
159 rp_template = '''
160heat_template_version: 2014-10-16
161resources:
162 random_group:
163 type: OS::Heat::ResourceGroup
164 properties:
165 count: 5
166 removal_policies: []
167 resource_def:
168 type: OS::Heat::RandomString
169'''
170
171 # create stack with resource group, initial count 5
172 stack_identifier = self.stack_create(template=rp_template)
173 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
174 self.list_resources(stack_identifier))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530175 group_resources = self.list_group_resources(stack_identifier,
176 'random_group')
Steven Hardy0145b8d2015-04-23 14:14:26 +1000177 expected_resources = {u'0': u'OS::Heat::RandomString',
178 u'1': u'OS::Heat::RandomString',
179 u'2': u'OS::Heat::RandomString',
180 u'3': u'OS::Heat::RandomString',
181 u'4': u'OS::Heat::RandomString'}
182 self.assertEqual(expected_resources, group_resources)
183
184 # Remove three, specifying the middle resources to be removed
185 update_template = rp_template.replace(
186 'removal_policies: []',
187 'removal_policies: [{resource_list: [\'1\', \'2\', \'3\']}]')
188 self.update_stack(stack_identifier, update_template)
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530189 group_resources = self.list_group_resources(stack_identifier,
190 'random_group')
Steven Hardy0145b8d2015-04-23 14:14:26 +1000191 expected_resources = {u'0': u'OS::Heat::RandomString',
192 u'4': u'OS::Heat::RandomString',
193 u'5': u'OS::Heat::RandomString',
194 u'6': u'OS::Heat::RandomString',
195 u'7': u'OS::Heat::RandomString'}
196 self.assertEqual(expected_resources, group_resources)
197
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000198 def test_props_update(self):
199 """Test update of resource_def properties behaves as expected."""
200
201 env = {'resource_registry':
202 {'My::RandomString': 'OS::Heat::RandomString'}}
203 template_one = self.template.replace("count: 0", "count: 1")
204 stack_identifier = self.stack_create(template=template_one,
205 environment=env)
206 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
207 self.list_resources(stack_identifier))
208
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530209 initial_nested_ident = self.group_nested_identifier(stack_identifier,
210 'random_group')
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000211 self.assertEqual({'0': 'My::RandomString'},
212 self.list_resources(initial_nested_ident))
213 # get the resource id
214 res = self.client.resources.get(initial_nested_ident, '0')
215 initial_res_id = res.physical_resource_id
216
217 # change the salt (this should replace the RandomString but
218 # not the nested stack or resource group.
219 template_salt = template_one.replace("salt: initial", "salt: more")
220 self.update_stack(stack_identifier, template_salt, environment=env)
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530221 updated_nested_ident = self.group_nested_identifier(stack_identifier,
222 'random_group')
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000223 self.assertEqual(initial_nested_ident, updated_nested_ident)
224
225 # compare the resource id, we expect a change.
226 res = self.client.resources.get(updated_nested_ident, '0')
227 updated_res_id = res.physical_resource_id
228 self.assertNotEqual(initial_res_id, updated_res_id)
229
230 def test_update_nochange(self):
231 """Test update with no properties change."""
232
233 env = {'resource_registry':
234 {'My::RandomString': 'OS::Heat::RandomString'}}
Angus Salkelda89a0282015-07-24 15:47:38 +1000235 template_one = self.template.replace("count: 0", "count: 2")
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000236 stack_identifier = self.stack_create(template=template_one,
237 environment=env)
238 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
239 self.list_resources(stack_identifier))
240
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530241 initial_nested_ident = self.group_nested_identifier(stack_identifier,
242 'random_group')
Angus Salkelda89a0282015-07-24 15:47:38 +1000243 self.assertEqual({'0': 'My::RandomString', '1': 'My::RandomString'},
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000244 self.list_resources(initial_nested_ident))
245 # get the output
246 stack0 = self.client.stacks.get(stack_identifier)
247 initial_rand = self._stack_output(stack0, 'random1')
248
249 template_copy = copy.deepcopy(template_one)
250 self.update_stack(stack_identifier, template_copy, environment=env)
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530251 updated_nested_ident = self.group_nested_identifier(stack_identifier,
252 'random_group')
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000253 self.assertEqual(initial_nested_ident, updated_nested_ident)
254
255 # compare the random number, we expect no change.
256 stack1 = self.client.stacks.get(stack_identifier)
257 updated_rand = self._stack_output(stack1, 'random1')
258 self.assertEqual(initial_rand, updated_rand)
259
260 def test_update_nochange_resource_needs_update(self):
Peter Razumovskyf0ac9582015-09-24 16:49:03 +0300261 """Test update when the resource definition has changed.
262
263 Test the scenario when the ResourceGroup update happens without
264 any changed properties, this can happen if the definition of
265 a contained provider resource changes (files map changes), then
266 the group and underlying nested stack should end up updated.
267 """
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000268
269 random_templ1 = '''
270heat_template_version: 2013-05-23
271parameters:
272 length:
273 type: string
274 default: not-used
275 salt:
276 type: string
277 default: not-used
278resources:
279 random1:
280 type: OS::Heat::RandomString
281 properties:
282 salt: initial
283outputs:
284 value:
285 value: {get_attr: [random1, value]}
286'''
287 files1 = {'my_random.yaml': random_templ1}
288
289 random_templ2 = random_templ1.replace('salt: initial',
290 'salt: more')
291 files2 = {'my_random.yaml': random_templ2}
292
293 env = {'resource_registry':
294 {'My::RandomString': 'my_random.yaml'}}
295
Angus Salkelda89a0282015-07-24 15:47:38 +1000296 template_one = self.template.replace("count: 0", "count: 2")
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000297 stack_identifier = self.stack_create(template=template_one,
298 environment=env,
299 files=files1)
300 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
301 self.list_resources(stack_identifier))
302
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530303 initial_nested_ident = self.group_nested_identifier(stack_identifier,
304 'random_group')
Angus Salkelda89a0282015-07-24 15:47:38 +1000305 self.assertEqual({'0': 'My::RandomString', '1': 'My::RandomString'},
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000306 self.list_resources(initial_nested_ident))
307 # get the output
308 stack0 = self.client.stacks.get(stack_identifier)
309 initial_rand = self._stack_output(stack0, 'random1')
310
311 # change the environment so we use a different TemplateResource.
312 # note "files2".
313 self.update_stack(stack_identifier, template_one,
314 environment=env, files=files2)
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530315 updated_nested_ident = self.group_nested_identifier(stack_identifier,
316 'random_group')
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000317 self.assertEqual(initial_nested_ident, updated_nested_ident)
318
319 # compare the output, we expect a change.
320 stack1 = self.client.stacks.get(stack_identifier)
321 updated_rand = self._stack_output(stack1, 'random1')
322 self.assertNotEqual(initial_rand, updated_rand)
323
Angus Salkeld011acc72015-01-16 20:26:34 +1000324
Rabi Mishra477efc92015-07-31 13:01:45 +0530325class ResourceGroupTestNullParams(functional_base.FunctionalTestsBase):
Angus Salkeld59b8f412015-02-25 21:01:12 +1000326 template = '''
327heat_template_version: 2013-05-23
328parameters:
329 param:
330 type: empty
331resources:
332 random_group:
333 type: OS::Heat::ResourceGroup
334 properties:
335 count: 1
336 resource_def:
337 type: My::RandomString
338 properties:
339 param: {get_param: param}
340outputs:
341 val:
342 value: {get_attr: [random_group, val]}
343'''
344
345 nested_template_file = '''
346heat_template_version: 2013-05-23
347parameters:
348 param:
349 type: empty
350outputs:
351 val:
352 value: {get_param: param}
353'''
354
355 scenarios = [
356 ('string_empty', dict(
357 param='',
358 p_type='string',
359 )),
360 ('boolean_false', dict(
361 param=False,
362 p_type='boolean',
363 )),
364 ('number_zero', dict(
365 param=0,
366 p_type='number',
367 )),
368 ('comma_delimited_list', dict(
369 param=[],
370 p_type='comma_delimited_list',
371 )),
372 ('json_empty', dict(
373 param={},
374 p_type='json',
375 )),
376 ]
377
378 def setUp(self):
379 super(ResourceGroupTestNullParams, self).setUp()
Angus Salkeld59b8f412015-02-25 21:01:12 +1000380
381 def test_create_pass_zero_parameter(self):
382 templ = self.template.replace('type: empty',
383 'type: %s' % self.p_type)
384 n_t_f = self.nested_template_file.replace('type: empty',
385 'type: %s' % self.p_type)
386 files = {'provider.yaml': n_t_f}
387 env = {'resource_registry':
388 {'My::RandomString': 'provider.yaml'}}
389 stack_identifier = self.stack_create(
390 template=templ,
391 files=files,
392 environment=env,
393 parameters={'param': self.param}
394 )
395 stack = self.client.stacks.get(stack_identifier)
396 self.assertEqual(self.param, self._stack_output(stack, 'val')[0])
397
398
Rabi Mishra477efc92015-07-31 13:01:45 +0530399class ResourceGroupAdoptTest(functional_base.FunctionalTestsBase):
Angus Salkeld011acc72015-01-16 20:26:34 +1000400 """Prove that we can do resource group adopt."""
401
402 main_template = '''
403heat_template_version: "2013-05-23"
404resources:
405 group1:
406 type: OS::Heat::ResourceGroup
407 properties:
408 count: 2
409 resource_def:
410 type: OS::Heat::RandomString
411outputs:
412 test0:
413 value: {get_attr: [group1, resource.0.value]}
414 test1:
415 value: {get_attr: [group1, resource.1.value]}
416'''
417
418 def setUp(self):
419 super(ResourceGroupAdoptTest, self).setUp()
Angus Salkeld011acc72015-01-16 20:26:34 +1000420
421 def _yaml_to_json(self, yaml_templ):
Bo Wangd8df4dd2016-02-16 21:23:53 +0800422 return yaml.safe_load(yaml_templ)
Angus Salkeld011acc72015-01-16 20:26:34 +1000423
424 def test_adopt(self):
425 data = {
426 "resources": {
427 "group1": {
428 "status": "COMPLETE",
429 "name": "group1",
430 "resource_data": {},
431 "metadata": {},
432 "resource_id": "test-group1-id",
433 "action": "CREATE",
434 "type": "OS::Heat::ResourceGroup",
435 "resources": {
436 "0": {
437 "status": "COMPLETE",
438 "name": "0",
439 "resource_data": {"value": "goopie"},
440 "resource_id": "ID-0",
441 "action": "CREATE",
442 "type": "OS::Heat::RandomString",
443 "metadata": {}
444 },
445 "1": {
446 "status": "COMPLETE",
447 "name": "1",
448 "resource_data": {"value": "different"},
449 "resource_id": "ID-1",
450 "action": "CREATE",
451 "type": "OS::Heat::RandomString",
452 "metadata": {}
453 }
454 }
455 }
456 },
457 "environment": {"parameters": {}},
Bo Wangd8df4dd2016-02-16 21:23:53 +0800458 "template": yaml.safe_load(self.main_template)
Angus Salkeld011acc72015-01-16 20:26:34 +1000459 }
460 stack_identifier = self.stack_adopt(
461 adopt_data=json.dumps(data))
462
463 self.assert_resource_is_a_stack(stack_identifier, 'group1')
464 stack = self.client.stacks.get(stack_identifier)
465 self.assertEqual('goopie', self._stack_output(stack, 'test0'))
466 self.assertEqual('different', self._stack_output(stack, 'test1'))
Steve Baker75ee9d12015-07-22 10:56:55 +1200467
468
Rabi Mishra477efc92015-07-31 13:01:45 +0530469class ResourceGroupErrorResourceTest(functional_base.FunctionalTestsBase):
Steve Baker75ee9d12015-07-22 10:56:55 +1200470 template = '''
471heat_template_version: "2013-05-23"
472resources:
473 group1:
474 type: OS::Heat::ResourceGroup
475 properties:
476 count: 2
477 resource_def:
478 type: fail.yaml
479'''
480 nested_templ = '''
481heat_template_version: "2013-05-23"
482resources:
483 oops:
484 type: OS::Heat::TestResource
485 properties:
486 fail: true
487 wait_secs: 2
488'''
489
490 def setUp(self):
491 super(ResourceGroupErrorResourceTest, self).setUp()
Steve Baker75ee9d12015-07-22 10:56:55 +1200492
493 def test_fail(self):
494 stack_identifier = self.stack_create(
495 template=self.template,
496 files={'fail.yaml': self.nested_templ},
497 expected_status='CREATE_FAILED',
498 enable_cleanup=False)
499 stack = self.client.stacks.get(stack_identifier)
500
501 self.assertEqual('CREATE_FAILED', stack.stack_status)
502 self.client.stacks.delete(stack_identifier)
503 self._wait_for_stack_status(
504 stack_identifier, 'DELETE_COMPLETE',
505 success_on_not_found=True)
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530506
507
508class ResourceGroupUpdatePolicyTest(functional_base.FunctionalTestsBase):
509
510 template = '''
511heat_template_version: '2015-04-30'
512resources:
513 random_group:
514 type: OS::Heat::ResourceGroup
515 update_policy:
516 rolling_update:
517 min_in_service: 1
518 max_batch_size: 2
519 pause_time: 1
520 properties:
521 count: 10
522 resource_def:
523 type: OS::Heat::TestResource
524 properties:
525 value: initial
526 update_replace: False
527'''
528
529 def update_resource_group(self, update_template,
530 updated, created, deleted):
531 stack_identifier = self.stack_create(template=self.template)
532 group_resources = self.list_group_resources(stack_identifier,
533 'random_group',
534 minimal=False)
535
536 init_names = [res.physical_resource_id for res in group_resources]
537
538 self.update_stack(stack_identifier, update_template)
539 group_resources = self.list_group_resources(stack_identifier,
540 'random_group',
541 minimal=False)
542
543 updt_names = [res.physical_resource_id for res in group_resources]
544
545 matched_names = set(updt_names) & set(init_names)
546
547 self.assertEqual(updated, len(matched_names))
548
549 self.assertEqual(created, len(set(updt_names) - set(init_names)))
550
551 self.assertEqual(deleted, len(set(init_names) - set(updt_names)))
552
553 def test_resource_group_update(self):
554 """Test rolling update with no conflict.
555
556 Simple rolling update with no conflict in batch size
557 and minimum instances in service.
558 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800559 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530560 grp = updt_template['resources']['random_group']
561 policy = grp['update_policy']['rolling_update']
562 policy['min_in_service'] = '1'
563 policy['max_batch_size'] = '3'
564 res_def = grp['properties']['resource_def']
565 res_def['properties']['value'] = 'updated'
566
567 self.update_resource_group(updt_template,
568 updated=10,
569 created=0,
570 deleted=0)
571
572 def test_resource_group_update_replace(self):
573 """Test rolling update(replace)with no conflict.
574
575 Simple rolling update replace with no conflict in batch size
576 and minimum instances in service.
577 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800578 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530579 grp = updt_template['resources']['random_group']
580 policy = grp['update_policy']['rolling_update']
581 policy['min_in_service'] = '1'
582 policy['max_batch_size'] = '3'
583 res_def = grp['properties']['resource_def']
584 res_def['properties']['value'] = 'updated'
585 res_def['properties']['update_replace'] = True
586
587 self.update_resource_group(updt_template,
588 updated=0,
589 created=10,
590 deleted=10)
591
592 def test_resource_group_update_scaledown(self):
593 """Test rolling update with scaledown.
594
595 Simple rolling update with reduced size.
596 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800597 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530598 grp = updt_template['resources']['random_group']
599 policy = grp['update_policy']['rolling_update']
600 policy['min_in_service'] = '1'
601 policy['max_batch_size'] = '3'
602 grp['properties']['count'] = 6
603 res_def = grp['properties']['resource_def']
604 res_def['properties']['value'] = 'updated'
605
606 self.update_resource_group(updt_template,
607 updated=6,
608 created=0,
609 deleted=4)
610
611 def test_resource_group_update_scaleup(self):
612 """Test rolling update with scaleup.
613
614 Simple rolling update with increased size.
615 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800616 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530617 grp = updt_template['resources']['random_group']
618 policy = grp['update_policy']['rolling_update']
619 policy['min_in_service'] = '1'
620 policy['max_batch_size'] = '3'
621 grp['properties']['count'] = 12
622 res_def = grp['properties']['resource_def']
623 res_def['properties']['value'] = 'updated'
624
625 self.update_resource_group(updt_template,
626 updated=10,
627 created=2,
628 deleted=0)
629
630 def test_resource_group_update_adjusted(self):
631 """Test rolling update with enough available resources
632
633 Update with capacity adjustment with enough resources.
634 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800635 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530636 grp = updt_template['resources']['random_group']
637 policy = grp['update_policy']['rolling_update']
638 policy['min_in_service'] = '8'
639 policy['max_batch_size'] = '4'
640 grp['properties']['count'] = 6
641 res_def = grp['properties']['resource_def']
642 res_def['properties']['value'] = 'updated'
643
644 self.update_resource_group(updt_template,
645 updated=6,
646 created=0,
647 deleted=4)
648
649 def test_resource_group_update_with_adjusted_capacity(self):
650 """Test rolling update with capacity adjustment.
651
652 Rolling update with capacity adjustment due to conflict in
653 batch size and minimum instances in service.
654 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800655 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530656 grp = updt_template['resources']['random_group']
657 policy = grp['update_policy']['rolling_update']
658 policy['min_in_service'] = '8'
659 policy['max_batch_size'] = '4'
660 res_def = grp['properties']['resource_def']
661 res_def['properties']['value'] = 'updated'
662
663 self.update_resource_group(updt_template,
664 updated=10,
665 created=0,
666 deleted=0)
667
668 def test_resource_group_update_huge_batch_size(self):
669 """Test rolling update with huge batch size.
670
671 Rolling Update with a huge batch size(more than
672 current size).
673 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800674 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530675 grp = updt_template['resources']['random_group']
676 policy = grp['update_policy']['rolling_update']
677 policy['min_in_service'] = '0'
678 policy['max_batch_size'] = '20'
679 res_def = grp['properties']['resource_def']
680 res_def['properties']['value'] = 'updated'
681 self.update_resource_group(updt_template,
682 updated=10,
683 created=0,
684 deleted=0)
685
686 def test_resource_group_update_huge_min_in_service(self):
687 """Test rolling update with huge minimum capacity.
688
689 Rolling Update with a huge number of minimum instances
690 in service.
691 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800692 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530693 grp = updt_template['resources']['random_group']
694 policy = grp['update_policy']['rolling_update']
695 policy['min_in_service'] = '20'
696 policy['max_batch_size'] = '1'
697 res_def = grp['properties']['resource_def']
698 res_def['properties']['value'] = 'updated'
699
700 self.update_resource_group(updt_template,
701 updated=10,
702 created=0,
703 deleted=0)