blob: 3f47ca5a389b9ee8eb2f38eb189fa99e0b931bfb [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")
rabi2a5bfcd2017-05-22 15:06:57 +053085 expected_err = ("resources.random_group<nested_stack>.resources."
86 "0<provider.yaml>.resources.random: : "
87 "Value 'BAD' is not an integer")
Steven Hardy6f0bda82014-12-12 17:49:10 +000088 ex = self.assertRaises(exc.HTTPBadRequest, self.update_stack,
89 stack_identifier, template_two_nested,
90 environment=env, files=files)
91 self.assertIn(expected_err, six.text_type(ex))
92
93 ex = self.assertRaises(exc.HTTPBadRequest, self.stack_create,
94 template=template_two_nested,
95 environment=env, files=files)
96 self.assertIn(expected_err, six.text_type(ex))
Unmesh Gurjar0a25a732014-12-23 17:28:33 +053097
Steven Hardy0145b8d2015-04-23 14:14:26 +100098 def _validate_resources(self, stack_identifier, expected_count):
Rabi Mishra8bcff8a2015-09-21 18:15:04 +053099 resources = self.list_group_resources(stack_identifier,
100 'random_group')
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530101 self.assertEqual(expected_count, len(resources))
102 expected_resources = dict(
Angus Salkeld665d86c2015-01-19 22:15:48 +1000103 (str(idx), 'My::RandomString')
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530104 for idx in range(expected_count))
105
106 self.assertEqual(expected_resources, resources)
107
108 def test_create(self):
109 def validate_output(stack, output_key, length):
110 output_value = self._stack_output(stack, output_key)
111 self.assertEqual(length, len(output_value))
112 return output_value
113 # verify that the resources in resource group are identically
114 # configured, resource names and outputs are appropriate.
Angus Salkeld665d86c2015-01-19 22:15:48 +1000115 env = {'resource_registry':
116 {'My::RandomString': 'OS::Heat::RandomString'}}
117 create_template = self.template.replace("count: 0", "count: 2")
118 stack_identifier = self.stack_create(template=create_template,
119 environment=env)
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530120 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
121 self.list_resources(stack_identifier))
122
123 # validate count, type and name of resources in a resource group.
124 self._validate_resources(stack_identifier, 2)
125
126 # validate outputs
127 stack = self.client.stacks.get(stack_identifier)
128 outputs = []
129 outputs.append(validate_output(stack, 'random1', 30))
130 outputs.append(validate_output(stack, 'random2', 30))
131 self.assertEqual(outputs, self._stack_output(stack, 'all_values'))
132
133 def test_update_increase_decrease_count(self):
134 # create stack with resource group count 2
Angus Salkeld665d86c2015-01-19 22:15:48 +1000135 env = {'resource_registry':
136 {'My::RandomString': 'OS::Heat::RandomString'}}
137 create_template = self.template.replace("count: 0", "count: 2")
138 stack_identifier = self.stack_create(template=create_template,
139 environment=env)
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530140 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
141 self.list_resources(stack_identifier))
142 # verify that the resource group has 2 resources
143 self._validate_resources(stack_identifier, 2)
144
145 # increase the resource group count to 5
Angus Salkeld665d86c2015-01-19 22:15:48 +1000146 update_template = self.template.replace("count: 0", "count: 5")
147 self.update_stack(stack_identifier, update_template, environment=env)
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530148 # verify that the resource group has 5 resources
149 self._validate_resources(stack_identifier, 5)
150
151 # decrease the resource group count to 3
Angus Salkeld665d86c2015-01-19 22:15:48 +1000152 update_template = self.template.replace("count: 0", "count: 3")
153 self.update_stack(stack_identifier, update_template, environment=env)
Unmesh Gurjar0a25a732014-12-23 17:28:33 +0530154 # verify that the resource group has 3 resources
155 self._validate_resources(stack_identifier, 3)
Angus Salkeld011acc72015-01-16 20:26:34 +1000156
Steven Hardy0145b8d2015-04-23 14:14:26 +1000157 def test_update_removal_policies(self):
158 rp_template = '''
159heat_template_version: 2014-10-16
160resources:
161 random_group:
162 type: OS::Heat::ResourceGroup
163 properties:
164 count: 5
165 removal_policies: []
166 resource_def:
167 type: OS::Heat::RandomString
168'''
169
170 # create stack with resource group, initial count 5
171 stack_identifier = self.stack_create(template=rp_template)
172 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
173 self.list_resources(stack_identifier))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530174 group_resources = self.list_group_resources(stack_identifier,
175 'random_group')
Steven Hardy0145b8d2015-04-23 14:14:26 +1000176 expected_resources = {u'0': u'OS::Heat::RandomString',
177 u'1': u'OS::Heat::RandomString',
178 u'2': u'OS::Heat::RandomString',
179 u'3': u'OS::Heat::RandomString',
180 u'4': u'OS::Heat::RandomString'}
181 self.assertEqual(expected_resources, group_resources)
182
183 # Remove three, specifying the middle resources to be removed
184 update_template = rp_template.replace(
185 'removal_policies: []',
186 'removal_policies: [{resource_list: [\'1\', \'2\', \'3\']}]')
187 self.update_stack(stack_identifier, update_template)
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530188 group_resources = self.list_group_resources(stack_identifier,
189 'random_group')
Steven Hardy0145b8d2015-04-23 14:14:26 +1000190 expected_resources = {u'0': u'OS::Heat::RandomString',
191 u'4': u'OS::Heat::RandomString',
192 u'5': u'OS::Heat::RandomString',
193 u'6': u'OS::Heat::RandomString',
194 u'7': u'OS::Heat::RandomString'}
195 self.assertEqual(expected_resources, group_resources)
196
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000197 def test_props_update(self):
198 """Test update of resource_def properties behaves as expected."""
199
200 env = {'resource_registry':
201 {'My::RandomString': 'OS::Heat::RandomString'}}
202 template_one = self.template.replace("count: 0", "count: 1")
203 stack_identifier = self.stack_create(template=template_one,
204 environment=env)
205 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
206 self.list_resources(stack_identifier))
207
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530208 initial_nested_ident = self.group_nested_identifier(stack_identifier,
209 'random_group')
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000210 self.assertEqual({'0': 'My::RandomString'},
211 self.list_resources(initial_nested_ident))
212 # get the resource id
213 res = self.client.resources.get(initial_nested_ident, '0')
214 initial_res_id = res.physical_resource_id
215
216 # change the salt (this should replace the RandomString but
217 # not the nested stack or resource group.
218 template_salt = template_one.replace("salt: initial", "salt: more")
219 self.update_stack(stack_identifier, template_salt, environment=env)
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530220 updated_nested_ident = self.group_nested_identifier(stack_identifier,
221 'random_group')
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000222 self.assertEqual(initial_nested_ident, updated_nested_ident)
223
224 # compare the resource id, we expect a change.
225 res = self.client.resources.get(updated_nested_ident, '0')
226 updated_res_id = res.physical_resource_id
227 self.assertNotEqual(initial_res_id, updated_res_id)
228
229 def test_update_nochange(self):
230 """Test update with no properties change."""
231
232 env = {'resource_registry':
233 {'My::RandomString': 'OS::Heat::RandomString'}}
Angus Salkelda89a0282015-07-24 15:47:38 +1000234 template_one = self.template.replace("count: 0", "count: 2")
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000235 stack_identifier = self.stack_create(template=template_one,
236 environment=env)
237 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
238 self.list_resources(stack_identifier))
239
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530240 initial_nested_ident = self.group_nested_identifier(stack_identifier,
241 'random_group')
Angus Salkelda89a0282015-07-24 15:47:38 +1000242 self.assertEqual({'0': 'My::RandomString', '1': 'My::RandomString'},
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000243 self.list_resources(initial_nested_ident))
244 # get the output
245 stack0 = self.client.stacks.get(stack_identifier)
246 initial_rand = self._stack_output(stack0, 'random1')
247
248 template_copy = copy.deepcopy(template_one)
249 self.update_stack(stack_identifier, template_copy, environment=env)
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530250 updated_nested_ident = self.group_nested_identifier(stack_identifier,
251 'random_group')
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000252 self.assertEqual(initial_nested_ident, updated_nested_ident)
253
254 # compare the random number, we expect no change.
255 stack1 = self.client.stacks.get(stack_identifier)
256 updated_rand = self._stack_output(stack1, 'random1')
257 self.assertEqual(initial_rand, updated_rand)
258
259 def test_update_nochange_resource_needs_update(self):
Peter Razumovskyf0ac9582015-09-24 16:49:03 +0300260 """Test update when the resource definition has changed.
261
262 Test the scenario when the ResourceGroup update happens without
263 any changed properties, this can happen if the definition of
264 a contained provider resource changes (files map changes), then
265 the group and underlying nested stack should end up updated.
266 """
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000267
268 random_templ1 = '''
269heat_template_version: 2013-05-23
270parameters:
271 length:
272 type: string
273 default: not-used
274 salt:
275 type: string
276 default: not-used
277resources:
278 random1:
279 type: OS::Heat::RandomString
280 properties:
281 salt: initial
282outputs:
283 value:
284 value: {get_attr: [random1, value]}
285'''
286 files1 = {'my_random.yaml': random_templ1}
287
288 random_templ2 = random_templ1.replace('salt: initial',
289 'salt: more')
290 files2 = {'my_random.yaml': random_templ2}
291
292 env = {'resource_registry':
293 {'My::RandomString': 'my_random.yaml'}}
294
Angus Salkelda89a0282015-07-24 15:47:38 +1000295 template_one = self.template.replace("count: 0", "count: 2")
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000296 stack_identifier = self.stack_create(template=template_one,
297 environment=env,
298 files=files1)
299 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
300 self.list_resources(stack_identifier))
Steven Hardy78d09932016-07-12 14:04:06 +0100301 self.assertEqual(files1, self.client.stacks.files(stack_identifier))
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000302
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)
Steven Hardy78d09932016-07-12 14:04:06 +0100318 self.assertEqual(files2, self.client.stacks.files(stack_identifier))
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000319
320 # compare the output, we expect a change.
321 stack1 = self.client.stacks.get(stack_identifier)
322 updated_rand = self._stack_output(stack1, 'random1')
323 self.assertNotEqual(initial_rand, updated_rand)
324
Angus Salkeld011acc72015-01-16 20:26:34 +1000325
Rabi Mishra477efc92015-07-31 13:01:45 +0530326class ResourceGroupTestNullParams(functional_base.FunctionalTestsBase):
Angus Salkeld59b8f412015-02-25 21:01:12 +1000327 template = '''
328heat_template_version: 2013-05-23
329parameters:
330 param:
331 type: empty
332resources:
333 random_group:
334 type: OS::Heat::ResourceGroup
335 properties:
336 count: 1
337 resource_def:
338 type: My::RandomString
339 properties:
340 param: {get_param: param}
341outputs:
342 val:
343 value: {get_attr: [random_group, val]}
344'''
345
346 nested_template_file = '''
347heat_template_version: 2013-05-23
348parameters:
349 param:
350 type: empty
351outputs:
352 val:
353 value: {get_param: param}
354'''
355
356 scenarios = [
357 ('string_empty', dict(
358 param='',
359 p_type='string',
360 )),
361 ('boolean_false', dict(
362 param=False,
363 p_type='boolean',
364 )),
365 ('number_zero', dict(
366 param=0,
367 p_type='number',
368 )),
369 ('comma_delimited_list', dict(
370 param=[],
371 p_type='comma_delimited_list',
372 )),
373 ('json_empty', dict(
374 param={},
375 p_type='json',
376 )),
377 ]
378
Angus Salkeld59b8f412015-02-25 21:01:12 +1000379 def test_create_pass_zero_parameter(self):
380 templ = self.template.replace('type: empty',
381 'type: %s' % self.p_type)
382 n_t_f = self.nested_template_file.replace('type: empty',
383 'type: %s' % self.p_type)
384 files = {'provider.yaml': n_t_f}
385 env = {'resource_registry':
386 {'My::RandomString': 'provider.yaml'}}
387 stack_identifier = self.stack_create(
388 template=templ,
389 files=files,
390 environment=env,
391 parameters={'param': self.param}
392 )
393 stack = self.client.stacks.get(stack_identifier)
394 self.assertEqual(self.param, self._stack_output(stack, 'val')[0])
395
396
Rabi Mishra477efc92015-07-31 13:01:45 +0530397class ResourceGroupAdoptTest(functional_base.FunctionalTestsBase):
Angus Salkeld011acc72015-01-16 20:26:34 +1000398 """Prove that we can do resource group adopt."""
399
400 main_template = '''
401heat_template_version: "2013-05-23"
402resources:
403 group1:
404 type: OS::Heat::ResourceGroup
405 properties:
406 count: 2
407 resource_def:
408 type: OS::Heat::RandomString
409outputs:
410 test0:
411 value: {get_attr: [group1, resource.0.value]}
412 test1:
413 value: {get_attr: [group1, resource.1.value]}
414'''
415
Angus Salkeld011acc72015-01-16 20:26:34 +1000416 def _yaml_to_json(self, yaml_templ):
Bo Wangd8df4dd2016-02-16 21:23:53 +0800417 return yaml.safe_load(yaml_templ)
Angus Salkeld011acc72015-01-16 20:26:34 +1000418
419 def test_adopt(self):
420 data = {
421 "resources": {
422 "group1": {
423 "status": "COMPLETE",
424 "name": "group1",
425 "resource_data": {},
426 "metadata": {},
427 "resource_id": "test-group1-id",
428 "action": "CREATE",
429 "type": "OS::Heat::ResourceGroup",
430 "resources": {
431 "0": {
432 "status": "COMPLETE",
433 "name": "0",
434 "resource_data": {"value": "goopie"},
435 "resource_id": "ID-0",
436 "action": "CREATE",
437 "type": "OS::Heat::RandomString",
438 "metadata": {}
439 },
440 "1": {
441 "status": "COMPLETE",
442 "name": "1",
443 "resource_data": {"value": "different"},
444 "resource_id": "ID-1",
445 "action": "CREATE",
446 "type": "OS::Heat::RandomString",
447 "metadata": {}
448 }
449 }
450 }
451 },
452 "environment": {"parameters": {}},
Bo Wangd8df4dd2016-02-16 21:23:53 +0800453 "template": yaml.safe_load(self.main_template)
Angus Salkeld011acc72015-01-16 20:26:34 +1000454 }
455 stack_identifier = self.stack_adopt(
456 adopt_data=json.dumps(data))
457
458 self.assert_resource_is_a_stack(stack_identifier, 'group1')
459 stack = self.client.stacks.get(stack_identifier)
460 self.assertEqual('goopie', self._stack_output(stack, 'test0'))
461 self.assertEqual('different', self._stack_output(stack, 'test1'))
Steve Baker75ee9d12015-07-22 10:56:55 +1200462
463
Rabi Mishra477efc92015-07-31 13:01:45 +0530464class ResourceGroupErrorResourceTest(functional_base.FunctionalTestsBase):
Steve Baker75ee9d12015-07-22 10:56:55 +1200465 template = '''
466heat_template_version: "2013-05-23"
467resources:
468 group1:
469 type: OS::Heat::ResourceGroup
470 properties:
471 count: 2
472 resource_def:
473 type: fail.yaml
474'''
475 nested_templ = '''
476heat_template_version: "2013-05-23"
477resources:
478 oops:
479 type: OS::Heat::TestResource
480 properties:
481 fail: true
482 wait_secs: 2
483'''
484
Steve Baker75ee9d12015-07-22 10:56:55 +1200485 def test_fail(self):
486 stack_identifier = self.stack_create(
487 template=self.template,
488 files={'fail.yaml': self.nested_templ},
489 expected_status='CREATE_FAILED',
490 enable_cleanup=False)
491 stack = self.client.stacks.get(stack_identifier)
492
493 self.assertEqual('CREATE_FAILED', stack.stack_status)
494 self.client.stacks.delete(stack_identifier)
495 self._wait_for_stack_status(
496 stack_identifier, 'DELETE_COMPLETE',
497 success_on_not_found=True)
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530498
499
500class ResourceGroupUpdatePolicyTest(functional_base.FunctionalTestsBase):
501
502 template = '''
503heat_template_version: '2015-04-30'
504resources:
505 random_group:
506 type: OS::Heat::ResourceGroup
507 update_policy:
508 rolling_update:
509 min_in_service: 1
510 max_batch_size: 2
511 pause_time: 1
512 properties:
513 count: 10
514 resource_def:
515 type: OS::Heat::TestResource
516 properties:
517 value: initial
518 update_replace: False
519'''
520
521 def update_resource_group(self, update_template,
522 updated, created, deleted):
523 stack_identifier = self.stack_create(template=self.template)
524 group_resources = self.list_group_resources(stack_identifier,
525 'random_group',
526 minimal=False)
527
528 init_names = [res.physical_resource_id for res in group_resources]
529
530 self.update_stack(stack_identifier, update_template)
531 group_resources = self.list_group_resources(stack_identifier,
532 'random_group',
533 minimal=False)
534
535 updt_names = [res.physical_resource_id for res in group_resources]
536
537 matched_names = set(updt_names) & set(init_names)
538
539 self.assertEqual(updated, len(matched_names))
540
541 self.assertEqual(created, len(set(updt_names) - set(init_names)))
542
543 self.assertEqual(deleted, len(set(init_names) - set(updt_names)))
544
545 def test_resource_group_update(self):
546 """Test rolling update with no conflict.
547
548 Simple rolling update with no conflict in batch size
549 and minimum instances in service.
550 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800551 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530552 grp = updt_template['resources']['random_group']
553 policy = grp['update_policy']['rolling_update']
554 policy['min_in_service'] = '1'
555 policy['max_batch_size'] = '3'
556 res_def = grp['properties']['resource_def']
557 res_def['properties']['value'] = 'updated'
558
559 self.update_resource_group(updt_template,
560 updated=10,
561 created=0,
562 deleted=0)
563
564 def test_resource_group_update_replace(self):
565 """Test rolling update(replace)with no conflict.
566
567 Simple rolling update replace with no conflict in batch size
568 and minimum instances in service.
569 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800570 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530571 grp = updt_template['resources']['random_group']
572 policy = grp['update_policy']['rolling_update']
573 policy['min_in_service'] = '1'
574 policy['max_batch_size'] = '3'
575 res_def = grp['properties']['resource_def']
576 res_def['properties']['value'] = 'updated'
577 res_def['properties']['update_replace'] = True
578
579 self.update_resource_group(updt_template,
580 updated=0,
581 created=10,
582 deleted=10)
583
584 def test_resource_group_update_scaledown(self):
585 """Test rolling update with scaledown.
586
587 Simple rolling update with reduced size.
588 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800589 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530590 grp = updt_template['resources']['random_group']
591 policy = grp['update_policy']['rolling_update']
592 policy['min_in_service'] = '1'
593 policy['max_batch_size'] = '3'
594 grp['properties']['count'] = 6
595 res_def = grp['properties']['resource_def']
596 res_def['properties']['value'] = 'updated'
597
598 self.update_resource_group(updt_template,
599 updated=6,
600 created=0,
601 deleted=4)
602
603 def test_resource_group_update_scaleup(self):
604 """Test rolling update with scaleup.
605
606 Simple rolling update with increased size.
607 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800608 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530609 grp = updt_template['resources']['random_group']
610 policy = grp['update_policy']['rolling_update']
611 policy['min_in_service'] = '1'
612 policy['max_batch_size'] = '3'
613 grp['properties']['count'] = 12
614 res_def = grp['properties']['resource_def']
615 res_def['properties']['value'] = 'updated'
616
617 self.update_resource_group(updt_template,
618 updated=10,
619 created=2,
620 deleted=0)
621
622 def test_resource_group_update_adjusted(self):
623 """Test rolling update with enough available resources
624
625 Update with capacity adjustment with enough resources.
626 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800627 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530628 grp = updt_template['resources']['random_group']
629 policy = grp['update_policy']['rolling_update']
630 policy['min_in_service'] = '8'
631 policy['max_batch_size'] = '4'
632 grp['properties']['count'] = 6
633 res_def = grp['properties']['resource_def']
634 res_def['properties']['value'] = 'updated'
635
636 self.update_resource_group(updt_template,
637 updated=6,
638 created=0,
639 deleted=4)
640
641 def test_resource_group_update_with_adjusted_capacity(self):
642 """Test rolling update with capacity adjustment.
643
644 Rolling update with capacity adjustment due to conflict in
645 batch size and minimum instances in service.
646 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800647 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530648 grp = updt_template['resources']['random_group']
649 policy = grp['update_policy']['rolling_update']
650 policy['min_in_service'] = '8'
651 policy['max_batch_size'] = '4'
652 res_def = grp['properties']['resource_def']
653 res_def['properties']['value'] = 'updated'
654
655 self.update_resource_group(updt_template,
656 updated=10,
657 created=0,
658 deleted=0)
659
660 def test_resource_group_update_huge_batch_size(self):
661 """Test rolling update with huge batch size.
662
663 Rolling Update with a huge batch size(more than
664 current size).
665 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800666 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530667 grp = updt_template['resources']['random_group']
668 policy = grp['update_policy']['rolling_update']
669 policy['min_in_service'] = '0'
670 policy['max_batch_size'] = '20'
671 res_def = grp['properties']['resource_def']
672 res_def['properties']['value'] = 'updated'
673 self.update_resource_group(updt_template,
674 updated=10,
675 created=0,
676 deleted=0)
677
678 def test_resource_group_update_huge_min_in_service(self):
679 """Test rolling update with huge minimum capacity.
680
681 Rolling Update with a huge number of minimum instances
682 in service.
683 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800684 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530685 grp = updt_template['resources']['random_group']
686 policy = grp['update_policy']['rolling_update']
687 policy['min_in_service'] = '20'
688 policy['max_batch_size'] = '1'
689 res_def = grp['properties']['resource_def']
690 res_def['properties']['value'] = 'updated'
691
692 self.update_resource_group(updt_template,
693 updated=10,
694 created=0,
695 deleted=0)