blob: 8d8cc89be0687580dfc24eef9917ccd3d7f6bc45 [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 test_resource_group_zero_novalidate(self):
46 # Nested resources should be validated only when size > 0
47 # This allows features to be disabled via size=0 without
gecong1973f6df13b2016-06-23 12:39:48 +080048 # triggering validation of nested resource custom constraints
Steven Hardy6f0bda82014-12-12 17:49:10 +000049 # e.g images etc in the nested schema.
50 nested_template_fail = '''
51heat_template_version: 2013-05-23
Angus Salkeld665d86c2015-01-19 22:15:48 +100052parameters:
53 length:
54 type: string
55 default: 50
Angus Salkeldb61f8f12015-01-19 23:00:45 +100056 salt:
57 type: string
58 default: initial
Steven Hardy6f0bda82014-12-12 17:49:10 +000059resources:
60 random:
61 type: OS::Heat::RandomString
62 properties:
Angus Salkeld665d86c2015-01-19 22:15:48 +100063 length: BAD
Steven Hardy6f0bda82014-12-12 17:49:10 +000064'''
65
66 files = {'provider.yaml': nested_template_fail}
67 env = {'resource_registry':
68 {'My::RandomString': 'provider.yaml'}}
69 stack_identifier = self.stack_create(
Angus Salkeld665d86c2015-01-19 22:15:48 +100070 template=self.template,
Steven Hardy6f0bda82014-12-12 17:49:10 +000071 files=files,
72 environment=env
73 )
74
75 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
76 self.list_resources(stack_identifier))
77
78 # Check we created an empty nested stack
Rabi Mishra8bcff8a2015-09-21 18:15:04 +053079 nested_identifier = self.group_nested_identifier(stack_identifier,
80 'random_group')
Steven Hardy6f0bda82014-12-12 17:49:10 +000081 self.assertEqual({}, self.list_resources(nested_identifier))
82
83 # Prove validation works for non-zero create/update
Angus Salkeld665d86c2015-01-19 22:15:48 +100084 template_two_nested = self.template.replace("count: 0", "count: 2")
Peter Razumovskyd7500792014-10-08 19:19:13 +040085 expected_err = "Value 'BAD' is not an integer"
Steven Hardy6f0bda82014-12-12 17:49:10 +000086 ex = self.assertRaises(exc.HTTPBadRequest, self.update_stack,
87 stack_identifier, template_two_nested,
88 environment=env, files=files)
89 self.assertIn(expected_err, six.text_type(ex))
90
91 ex = self.assertRaises(exc.HTTPBadRequest, self.stack_create,
92 template=template_two_nested,
93 environment=env, files=files)
94 self.assertIn(expected_err, six.text_type(ex))
Unmesh Gurjar0a25a732014-12-23 17:28:33 +053095
Steven Hardy0145b8d2015-04-23 14:14:26 +100096 def _validate_resources(self, stack_identifier, expected_count):
Rabi Mishra8bcff8a2015-09-21 18:15:04 +053097 resources = self.list_group_resources(stack_identifier,
98 'random_group')
Unmesh Gurjar0a25a732014-12-23 17:28:33 +053099 self.assertEqual(expected_count, len(resources))
100 expected_resources = dict(
Angus Salkeld665d86c2015-01-19 22:15:48 +1000101 (str(idx), 'My::RandomString')
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530102 for idx in range(expected_count))
103
104 self.assertEqual(expected_resources, resources)
105
106 def test_create(self):
107 def validate_output(stack, output_key, length):
108 output_value = self._stack_output(stack, output_key)
109 self.assertEqual(length, len(output_value))
110 return output_value
111 # verify that the resources in resource group are identically
112 # configured, resource names and outputs are appropriate.
Angus Salkeld665d86c2015-01-19 22:15:48 +1000113 env = {'resource_registry':
114 {'My::RandomString': 'OS::Heat::RandomString'}}
115 create_template = self.template.replace("count: 0", "count: 2")
116 stack_identifier = self.stack_create(template=create_template,
117 environment=env)
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530118 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
119 self.list_resources(stack_identifier))
120
121 # validate count, type and name of resources in a resource group.
122 self._validate_resources(stack_identifier, 2)
123
124 # validate outputs
125 stack = self.client.stacks.get(stack_identifier)
126 outputs = []
127 outputs.append(validate_output(stack, 'random1', 30))
128 outputs.append(validate_output(stack, 'random2', 30))
129 self.assertEqual(outputs, self._stack_output(stack, 'all_values'))
130
131 def test_update_increase_decrease_count(self):
132 # create stack with resource group count 2
Angus Salkeld665d86c2015-01-19 22:15:48 +1000133 env = {'resource_registry':
134 {'My::RandomString': 'OS::Heat::RandomString'}}
135 create_template = self.template.replace("count: 0", "count: 2")
136 stack_identifier = self.stack_create(template=create_template,
137 environment=env)
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530138 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
139 self.list_resources(stack_identifier))
140 # verify that the resource group has 2 resources
141 self._validate_resources(stack_identifier, 2)
142
143 # increase the resource group count to 5
Angus Salkeld665d86c2015-01-19 22:15:48 +1000144 update_template = self.template.replace("count: 0", "count: 5")
145 self.update_stack(stack_identifier, update_template, environment=env)
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530146 # verify that the resource group has 5 resources
147 self._validate_resources(stack_identifier, 5)
148
149 # decrease the resource group count to 3
Angus Salkeld665d86c2015-01-19 22:15:48 +1000150 update_template = self.template.replace("count: 0", "count: 3")
151 self.update_stack(stack_identifier, update_template, environment=env)
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530152 # verify that the resource group has 3 resources
153 self._validate_resources(stack_identifier, 3)
Angus Salkeld011acc72015-01-16 20:26:34 +1000154
Steven Hardy0145b8d2015-04-23 14:14:26 +1000155 def test_update_removal_policies(self):
156 rp_template = '''
157heat_template_version: 2014-10-16
158resources:
159 random_group:
160 type: OS::Heat::ResourceGroup
161 properties:
162 count: 5
163 removal_policies: []
164 resource_def:
165 type: OS::Heat::RandomString
166'''
167
168 # create stack with resource group, initial count 5
169 stack_identifier = self.stack_create(template=rp_template)
170 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
171 self.list_resources(stack_identifier))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530172 group_resources = self.list_group_resources(stack_identifier,
173 'random_group')
Steven Hardy0145b8d2015-04-23 14:14:26 +1000174 expected_resources = {u'0': u'OS::Heat::RandomString',
175 u'1': u'OS::Heat::RandomString',
176 u'2': u'OS::Heat::RandomString',
177 u'3': u'OS::Heat::RandomString',
178 u'4': u'OS::Heat::RandomString'}
179 self.assertEqual(expected_resources, group_resources)
180
181 # Remove three, specifying the middle resources to be removed
182 update_template = rp_template.replace(
183 'removal_policies: []',
184 'removal_policies: [{resource_list: [\'1\', \'2\', \'3\']}]')
185 self.update_stack(stack_identifier, update_template)
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530186 group_resources = self.list_group_resources(stack_identifier,
187 'random_group')
Steven Hardy0145b8d2015-04-23 14:14:26 +1000188 expected_resources = {u'0': u'OS::Heat::RandomString',
189 u'4': u'OS::Heat::RandomString',
190 u'5': u'OS::Heat::RandomString',
191 u'6': u'OS::Heat::RandomString',
192 u'7': u'OS::Heat::RandomString'}
193 self.assertEqual(expected_resources, group_resources)
194
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000195 def test_props_update(self):
196 """Test update of resource_def properties behaves as expected."""
197
198 env = {'resource_registry':
199 {'My::RandomString': 'OS::Heat::RandomString'}}
200 template_one = self.template.replace("count: 0", "count: 1")
201 stack_identifier = self.stack_create(template=template_one,
202 environment=env)
203 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
204 self.list_resources(stack_identifier))
205
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530206 initial_nested_ident = self.group_nested_identifier(stack_identifier,
207 'random_group')
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000208 self.assertEqual({'0': 'My::RandomString'},
209 self.list_resources(initial_nested_ident))
210 # get the resource id
211 res = self.client.resources.get(initial_nested_ident, '0')
212 initial_res_id = res.physical_resource_id
213
214 # change the salt (this should replace the RandomString but
215 # not the nested stack or resource group.
216 template_salt = template_one.replace("salt: initial", "salt: more")
217 self.update_stack(stack_identifier, template_salt, environment=env)
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530218 updated_nested_ident = self.group_nested_identifier(stack_identifier,
219 'random_group')
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000220 self.assertEqual(initial_nested_ident, updated_nested_ident)
221
222 # compare the resource id, we expect a change.
223 res = self.client.resources.get(updated_nested_ident, '0')
224 updated_res_id = res.physical_resource_id
225 self.assertNotEqual(initial_res_id, updated_res_id)
226
227 def test_update_nochange(self):
228 """Test update with no properties change."""
229
230 env = {'resource_registry':
231 {'My::RandomString': 'OS::Heat::RandomString'}}
Angus Salkelda89a0282015-07-24 15:47:38 +1000232 template_one = self.template.replace("count: 0", "count: 2")
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000233 stack_identifier = self.stack_create(template=template_one,
234 environment=env)
235 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
236 self.list_resources(stack_identifier))
237
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530238 initial_nested_ident = self.group_nested_identifier(stack_identifier,
239 'random_group')
Angus Salkelda89a0282015-07-24 15:47:38 +1000240 self.assertEqual({'0': 'My::RandomString', '1': 'My::RandomString'},
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000241 self.list_resources(initial_nested_ident))
242 # get the output
243 stack0 = self.client.stacks.get(stack_identifier)
244 initial_rand = self._stack_output(stack0, 'random1')
245
246 template_copy = copy.deepcopy(template_one)
247 self.update_stack(stack_identifier, template_copy, environment=env)
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530248 updated_nested_ident = self.group_nested_identifier(stack_identifier,
249 'random_group')
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000250 self.assertEqual(initial_nested_ident, updated_nested_ident)
251
252 # compare the random number, we expect no change.
253 stack1 = self.client.stacks.get(stack_identifier)
254 updated_rand = self._stack_output(stack1, 'random1')
255 self.assertEqual(initial_rand, updated_rand)
256
257 def test_update_nochange_resource_needs_update(self):
Peter Razumovskyf0ac9582015-09-24 16:49:03 +0300258 """Test update when the resource definition has changed.
259
260 Test the scenario when the ResourceGroup update happens without
261 any changed properties, this can happen if the definition of
262 a contained provider resource changes (files map changes), then
263 the group and underlying nested stack should end up updated.
264 """
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000265
266 random_templ1 = '''
267heat_template_version: 2013-05-23
268parameters:
269 length:
270 type: string
271 default: not-used
272 salt:
273 type: string
274 default: not-used
275resources:
276 random1:
277 type: OS::Heat::RandomString
278 properties:
279 salt: initial
280outputs:
281 value:
282 value: {get_attr: [random1, value]}
283'''
284 files1 = {'my_random.yaml': random_templ1}
285
286 random_templ2 = random_templ1.replace('salt: initial',
287 'salt: more')
288 files2 = {'my_random.yaml': random_templ2}
289
290 env = {'resource_registry':
291 {'My::RandomString': 'my_random.yaml'}}
292
Angus Salkelda89a0282015-07-24 15:47:38 +1000293 template_one = self.template.replace("count: 0", "count: 2")
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000294 stack_identifier = self.stack_create(template=template_one,
295 environment=env,
296 files=files1)
297 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
298 self.list_resources(stack_identifier))
Steven Hardy78d09932016-07-12 14:04:06 +0100299 self.assertEqual(files1, self.client.stacks.files(stack_identifier))
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000300
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530301 initial_nested_ident = self.group_nested_identifier(stack_identifier,
302 'random_group')
Angus Salkelda89a0282015-07-24 15:47:38 +1000303 self.assertEqual({'0': 'My::RandomString', '1': 'My::RandomString'},
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000304 self.list_resources(initial_nested_ident))
305 # get the output
306 stack0 = self.client.stacks.get(stack_identifier)
307 initial_rand = self._stack_output(stack0, 'random1')
308
309 # change the environment so we use a different TemplateResource.
310 # note "files2".
311 self.update_stack(stack_identifier, template_one,
312 environment=env, files=files2)
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530313 updated_nested_ident = self.group_nested_identifier(stack_identifier,
314 'random_group')
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000315 self.assertEqual(initial_nested_ident, updated_nested_ident)
Steven Hardy78d09932016-07-12 14:04:06 +0100316 self.assertEqual(files2, self.client.stacks.files(stack_identifier))
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000317
318 # compare the output, we expect a change.
319 stack1 = self.client.stacks.get(stack_identifier)
320 updated_rand = self._stack_output(stack1, 'random1')
321 self.assertNotEqual(initial_rand, updated_rand)
322
Angus Salkeld011acc72015-01-16 20:26:34 +1000323
Rabi Mishra477efc92015-07-31 13:01:45 +0530324class ResourceGroupTestNullParams(functional_base.FunctionalTestsBase):
Angus Salkeld59b8f412015-02-25 21:01:12 +1000325 template = '''
326heat_template_version: 2013-05-23
327parameters:
328 param:
329 type: empty
330resources:
331 random_group:
332 type: OS::Heat::ResourceGroup
333 properties:
334 count: 1
335 resource_def:
336 type: My::RandomString
337 properties:
338 param: {get_param: param}
339outputs:
340 val:
341 value: {get_attr: [random_group, val]}
342'''
343
344 nested_template_file = '''
345heat_template_version: 2013-05-23
346parameters:
347 param:
348 type: empty
349outputs:
350 val:
351 value: {get_param: param}
352'''
353
354 scenarios = [
355 ('string_empty', dict(
356 param='',
357 p_type='string',
358 )),
359 ('boolean_false', dict(
360 param=False,
361 p_type='boolean',
362 )),
363 ('number_zero', dict(
364 param=0,
365 p_type='number',
366 )),
367 ('comma_delimited_list', dict(
368 param=[],
369 p_type='comma_delimited_list',
370 )),
371 ('json_empty', dict(
372 param={},
373 p_type='json',
374 )),
375 ]
376
Angus Salkeld59b8f412015-02-25 21:01:12 +1000377 def test_create_pass_zero_parameter(self):
378 templ = self.template.replace('type: empty',
379 'type: %s' % self.p_type)
380 n_t_f = self.nested_template_file.replace('type: empty',
381 'type: %s' % self.p_type)
382 files = {'provider.yaml': n_t_f}
383 env = {'resource_registry':
384 {'My::RandomString': 'provider.yaml'}}
385 stack_identifier = self.stack_create(
386 template=templ,
387 files=files,
388 environment=env,
389 parameters={'param': self.param}
390 )
391 stack = self.client.stacks.get(stack_identifier)
392 self.assertEqual(self.param, self._stack_output(stack, 'val')[0])
393
394
Rabi Mishra477efc92015-07-31 13:01:45 +0530395class ResourceGroupAdoptTest(functional_base.FunctionalTestsBase):
Angus Salkeld011acc72015-01-16 20:26:34 +1000396 """Prove that we can do resource group adopt."""
397
398 main_template = '''
399heat_template_version: "2013-05-23"
400resources:
401 group1:
402 type: OS::Heat::ResourceGroup
403 properties:
404 count: 2
405 resource_def:
406 type: OS::Heat::RandomString
407outputs:
408 test0:
409 value: {get_attr: [group1, resource.0.value]}
410 test1:
411 value: {get_attr: [group1, resource.1.value]}
412'''
413
Angus Salkeld011acc72015-01-16 20:26:34 +1000414 def _yaml_to_json(self, yaml_templ):
Bo Wangd8df4dd2016-02-16 21:23:53 +0800415 return yaml.safe_load(yaml_templ)
Angus Salkeld011acc72015-01-16 20:26:34 +1000416
417 def test_adopt(self):
418 data = {
419 "resources": {
420 "group1": {
421 "status": "COMPLETE",
422 "name": "group1",
423 "resource_data": {},
424 "metadata": {},
425 "resource_id": "test-group1-id",
426 "action": "CREATE",
427 "type": "OS::Heat::ResourceGroup",
428 "resources": {
429 "0": {
430 "status": "COMPLETE",
431 "name": "0",
432 "resource_data": {"value": "goopie"},
433 "resource_id": "ID-0",
434 "action": "CREATE",
435 "type": "OS::Heat::RandomString",
436 "metadata": {}
437 },
438 "1": {
439 "status": "COMPLETE",
440 "name": "1",
441 "resource_data": {"value": "different"},
442 "resource_id": "ID-1",
443 "action": "CREATE",
444 "type": "OS::Heat::RandomString",
445 "metadata": {}
446 }
447 }
448 }
449 },
450 "environment": {"parameters": {}},
Bo Wangd8df4dd2016-02-16 21:23:53 +0800451 "template": yaml.safe_load(self.main_template)
Angus Salkeld011acc72015-01-16 20:26:34 +1000452 }
453 stack_identifier = self.stack_adopt(
454 adopt_data=json.dumps(data))
455
456 self.assert_resource_is_a_stack(stack_identifier, 'group1')
457 stack = self.client.stacks.get(stack_identifier)
458 self.assertEqual('goopie', self._stack_output(stack, 'test0'))
459 self.assertEqual('different', self._stack_output(stack, 'test1'))
Steve Baker75ee9d12015-07-22 10:56:55 +1200460
461
Rabi Mishra477efc92015-07-31 13:01:45 +0530462class ResourceGroupErrorResourceTest(functional_base.FunctionalTestsBase):
Steve Baker75ee9d12015-07-22 10:56:55 +1200463 template = '''
464heat_template_version: "2013-05-23"
465resources:
466 group1:
467 type: OS::Heat::ResourceGroup
468 properties:
469 count: 2
470 resource_def:
471 type: fail.yaml
472'''
473 nested_templ = '''
474heat_template_version: "2013-05-23"
475resources:
476 oops:
477 type: OS::Heat::TestResource
478 properties:
479 fail: true
480 wait_secs: 2
481'''
482
Steve Baker75ee9d12015-07-22 10:56:55 +1200483 def test_fail(self):
484 stack_identifier = self.stack_create(
485 template=self.template,
486 files={'fail.yaml': self.nested_templ},
487 expected_status='CREATE_FAILED',
488 enable_cleanup=False)
489 stack = self.client.stacks.get(stack_identifier)
490
491 self.assertEqual('CREATE_FAILED', stack.stack_status)
492 self.client.stacks.delete(stack_identifier)
493 self._wait_for_stack_status(
494 stack_identifier, 'DELETE_COMPLETE',
495 success_on_not_found=True)
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530496
497
498class ResourceGroupUpdatePolicyTest(functional_base.FunctionalTestsBase):
499
500 template = '''
501heat_template_version: '2015-04-30'
502resources:
503 random_group:
504 type: OS::Heat::ResourceGroup
505 update_policy:
506 rolling_update:
507 min_in_service: 1
508 max_batch_size: 2
509 pause_time: 1
510 properties:
511 count: 10
512 resource_def:
513 type: OS::Heat::TestResource
514 properties:
515 value: initial
516 update_replace: False
517'''
518
519 def update_resource_group(self, update_template,
520 updated, created, deleted):
521 stack_identifier = self.stack_create(template=self.template)
522 group_resources = self.list_group_resources(stack_identifier,
523 'random_group',
524 minimal=False)
525
526 init_names = [res.physical_resource_id for res in group_resources]
527
528 self.update_stack(stack_identifier, update_template)
529 group_resources = self.list_group_resources(stack_identifier,
530 'random_group',
531 minimal=False)
532
533 updt_names = [res.physical_resource_id for res in group_resources]
534
535 matched_names = set(updt_names) & set(init_names)
536
537 self.assertEqual(updated, len(matched_names))
538
539 self.assertEqual(created, len(set(updt_names) - set(init_names)))
540
541 self.assertEqual(deleted, len(set(init_names) - set(updt_names)))
542
543 def test_resource_group_update(self):
544 """Test rolling update with no conflict.
545
546 Simple rolling update with no conflict in batch size
547 and minimum instances in service.
548 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800549 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530550 grp = updt_template['resources']['random_group']
551 policy = grp['update_policy']['rolling_update']
552 policy['min_in_service'] = '1'
553 policy['max_batch_size'] = '3'
554 res_def = grp['properties']['resource_def']
555 res_def['properties']['value'] = 'updated'
556
557 self.update_resource_group(updt_template,
558 updated=10,
559 created=0,
560 deleted=0)
561
562 def test_resource_group_update_replace(self):
563 """Test rolling update(replace)with no conflict.
564
565 Simple rolling update replace with no conflict in batch size
566 and minimum instances in service.
567 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800568 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530569 grp = updt_template['resources']['random_group']
570 policy = grp['update_policy']['rolling_update']
571 policy['min_in_service'] = '1'
572 policy['max_batch_size'] = '3'
573 res_def = grp['properties']['resource_def']
574 res_def['properties']['value'] = 'updated'
575 res_def['properties']['update_replace'] = True
576
577 self.update_resource_group(updt_template,
578 updated=0,
579 created=10,
580 deleted=10)
581
582 def test_resource_group_update_scaledown(self):
583 """Test rolling update with scaledown.
584
585 Simple rolling update with reduced size.
586 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800587 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530588 grp = updt_template['resources']['random_group']
589 policy = grp['update_policy']['rolling_update']
590 policy['min_in_service'] = '1'
591 policy['max_batch_size'] = '3'
592 grp['properties']['count'] = 6
593 res_def = grp['properties']['resource_def']
594 res_def['properties']['value'] = 'updated'
595
596 self.update_resource_group(updt_template,
597 updated=6,
598 created=0,
599 deleted=4)
600
601 def test_resource_group_update_scaleup(self):
602 """Test rolling update with scaleup.
603
604 Simple rolling update with increased size.
605 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800606 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530607 grp = updt_template['resources']['random_group']
608 policy = grp['update_policy']['rolling_update']
609 policy['min_in_service'] = '1'
610 policy['max_batch_size'] = '3'
611 grp['properties']['count'] = 12
612 res_def = grp['properties']['resource_def']
613 res_def['properties']['value'] = 'updated'
614
615 self.update_resource_group(updt_template,
616 updated=10,
617 created=2,
618 deleted=0)
619
620 def test_resource_group_update_adjusted(self):
621 """Test rolling update with enough available resources
622
623 Update with capacity adjustment with enough resources.
624 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800625 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530626 grp = updt_template['resources']['random_group']
627 policy = grp['update_policy']['rolling_update']
628 policy['min_in_service'] = '8'
629 policy['max_batch_size'] = '4'
630 grp['properties']['count'] = 6
631 res_def = grp['properties']['resource_def']
632 res_def['properties']['value'] = 'updated'
633
634 self.update_resource_group(updt_template,
635 updated=6,
636 created=0,
637 deleted=4)
638
639 def test_resource_group_update_with_adjusted_capacity(self):
640 """Test rolling update with capacity adjustment.
641
642 Rolling update with capacity adjustment due to conflict in
643 batch size and minimum instances in service.
644 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800645 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530646 grp = updt_template['resources']['random_group']
647 policy = grp['update_policy']['rolling_update']
648 policy['min_in_service'] = '8'
649 policy['max_batch_size'] = '4'
650 res_def = grp['properties']['resource_def']
651 res_def['properties']['value'] = 'updated'
652
653 self.update_resource_group(updt_template,
654 updated=10,
655 created=0,
656 deleted=0)
657
658 def test_resource_group_update_huge_batch_size(self):
659 """Test rolling update with huge batch size.
660
661 Rolling Update with a huge batch size(more than
662 current size).
663 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800664 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530665 grp = updt_template['resources']['random_group']
666 policy = grp['update_policy']['rolling_update']
667 policy['min_in_service'] = '0'
668 policy['max_batch_size'] = '20'
669 res_def = grp['properties']['resource_def']
670 res_def['properties']['value'] = 'updated'
671 self.update_resource_group(updt_template,
672 updated=10,
673 created=0,
674 deleted=0)
675
676 def test_resource_group_update_huge_min_in_service(self):
677 """Test rolling update with huge minimum capacity.
678
679 Rolling Update with a huge number of minimum instances
680 in service.
681 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800682 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530683 grp = updt_template['resources']['random_group']
684 policy = grp['update_policy']['rolling_update']
685 policy['min_in_service'] = '20'
686 policy['max_batch_size'] = '1'
687 res_def = grp['properties']['resource_def']
688 res_def['properties']['value'] = 'updated'
689
690 self.update_resource_group(updt_template,
691 updated=10,
692 created=0,
693 deleted=0)