blob: c0c7de71a2fe89e1321150384c21ffdbd9b1b1ba [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
gecong1973f6df13b2016-06-23 12:39:48 +080051 # triggering validation of nested resource custom constraints
Steven Hardy6f0bda82014-12-12 17:49:10 +000052 # 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))
Steven Hardy78d09932016-07-12 14:04:06 +0100302 self.assertEqual(files1, self.client.stacks.files(stack_identifier))
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000303
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530304 initial_nested_ident = self.group_nested_identifier(stack_identifier,
305 'random_group')
Angus Salkelda89a0282015-07-24 15:47:38 +1000306 self.assertEqual({'0': 'My::RandomString', '1': 'My::RandomString'},
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000307 self.list_resources(initial_nested_ident))
308 # get the output
309 stack0 = self.client.stacks.get(stack_identifier)
310 initial_rand = self._stack_output(stack0, 'random1')
311
312 # change the environment so we use a different TemplateResource.
313 # note "files2".
314 self.update_stack(stack_identifier, template_one,
315 environment=env, files=files2)
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530316 updated_nested_ident = self.group_nested_identifier(stack_identifier,
317 'random_group')
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000318 self.assertEqual(initial_nested_ident, updated_nested_ident)
Steven Hardy78d09932016-07-12 14:04:06 +0100319 self.assertEqual(files2, self.client.stacks.files(stack_identifier))
Angus Salkeldb61f8f12015-01-19 23:00:45 +1000320
321 # compare the output, we expect a change.
322 stack1 = self.client.stacks.get(stack_identifier)
323 updated_rand = self._stack_output(stack1, 'random1')
324 self.assertNotEqual(initial_rand, updated_rand)
325
Angus Salkeld011acc72015-01-16 20:26:34 +1000326
Rabi Mishra477efc92015-07-31 13:01:45 +0530327class ResourceGroupTestNullParams(functional_base.FunctionalTestsBase):
Angus Salkeld59b8f412015-02-25 21:01:12 +1000328 template = '''
329heat_template_version: 2013-05-23
330parameters:
331 param:
332 type: empty
333resources:
334 random_group:
335 type: OS::Heat::ResourceGroup
336 properties:
337 count: 1
338 resource_def:
339 type: My::RandomString
340 properties:
341 param: {get_param: param}
342outputs:
343 val:
344 value: {get_attr: [random_group, val]}
345'''
346
347 nested_template_file = '''
348heat_template_version: 2013-05-23
349parameters:
350 param:
351 type: empty
352outputs:
353 val:
354 value: {get_param: param}
355'''
356
357 scenarios = [
358 ('string_empty', dict(
359 param='',
360 p_type='string',
361 )),
362 ('boolean_false', dict(
363 param=False,
364 p_type='boolean',
365 )),
366 ('number_zero', dict(
367 param=0,
368 p_type='number',
369 )),
370 ('comma_delimited_list', dict(
371 param=[],
372 p_type='comma_delimited_list',
373 )),
374 ('json_empty', dict(
375 param={},
376 p_type='json',
377 )),
378 ]
379
380 def setUp(self):
381 super(ResourceGroupTestNullParams, self).setUp()
Angus Salkeld59b8f412015-02-25 21:01:12 +1000382
383 def test_create_pass_zero_parameter(self):
384 templ = self.template.replace('type: empty',
385 'type: %s' % self.p_type)
386 n_t_f = self.nested_template_file.replace('type: empty',
387 'type: %s' % self.p_type)
388 files = {'provider.yaml': n_t_f}
389 env = {'resource_registry':
390 {'My::RandomString': 'provider.yaml'}}
391 stack_identifier = self.stack_create(
392 template=templ,
393 files=files,
394 environment=env,
395 parameters={'param': self.param}
396 )
397 stack = self.client.stacks.get(stack_identifier)
398 self.assertEqual(self.param, self._stack_output(stack, 'val')[0])
399
400
Rabi Mishra477efc92015-07-31 13:01:45 +0530401class ResourceGroupAdoptTest(functional_base.FunctionalTestsBase):
Angus Salkeld011acc72015-01-16 20:26:34 +1000402 """Prove that we can do resource group adopt."""
403
404 main_template = '''
405heat_template_version: "2013-05-23"
406resources:
407 group1:
408 type: OS::Heat::ResourceGroup
409 properties:
410 count: 2
411 resource_def:
412 type: OS::Heat::RandomString
413outputs:
414 test0:
415 value: {get_attr: [group1, resource.0.value]}
416 test1:
417 value: {get_attr: [group1, resource.1.value]}
418'''
419
420 def setUp(self):
421 super(ResourceGroupAdoptTest, self).setUp()
Angus Salkeld011acc72015-01-16 20:26:34 +1000422
423 def _yaml_to_json(self, yaml_templ):
Bo Wangd8df4dd2016-02-16 21:23:53 +0800424 return yaml.safe_load(yaml_templ)
Angus Salkeld011acc72015-01-16 20:26:34 +1000425
426 def test_adopt(self):
427 data = {
428 "resources": {
429 "group1": {
430 "status": "COMPLETE",
431 "name": "group1",
432 "resource_data": {},
433 "metadata": {},
434 "resource_id": "test-group1-id",
435 "action": "CREATE",
436 "type": "OS::Heat::ResourceGroup",
437 "resources": {
438 "0": {
439 "status": "COMPLETE",
440 "name": "0",
441 "resource_data": {"value": "goopie"},
442 "resource_id": "ID-0",
443 "action": "CREATE",
444 "type": "OS::Heat::RandomString",
445 "metadata": {}
446 },
447 "1": {
448 "status": "COMPLETE",
449 "name": "1",
450 "resource_data": {"value": "different"},
451 "resource_id": "ID-1",
452 "action": "CREATE",
453 "type": "OS::Heat::RandomString",
454 "metadata": {}
455 }
456 }
457 }
458 },
459 "environment": {"parameters": {}},
Bo Wangd8df4dd2016-02-16 21:23:53 +0800460 "template": yaml.safe_load(self.main_template)
Angus Salkeld011acc72015-01-16 20:26:34 +1000461 }
462 stack_identifier = self.stack_adopt(
463 adopt_data=json.dumps(data))
464
465 self.assert_resource_is_a_stack(stack_identifier, 'group1')
466 stack = self.client.stacks.get(stack_identifier)
467 self.assertEqual('goopie', self._stack_output(stack, 'test0'))
468 self.assertEqual('different', self._stack_output(stack, 'test1'))
Steve Baker75ee9d12015-07-22 10:56:55 +1200469
470
Rabi Mishra477efc92015-07-31 13:01:45 +0530471class ResourceGroupErrorResourceTest(functional_base.FunctionalTestsBase):
Steve Baker75ee9d12015-07-22 10:56:55 +1200472 template = '''
473heat_template_version: "2013-05-23"
474resources:
475 group1:
476 type: OS::Heat::ResourceGroup
477 properties:
478 count: 2
479 resource_def:
480 type: fail.yaml
481'''
482 nested_templ = '''
483heat_template_version: "2013-05-23"
484resources:
485 oops:
486 type: OS::Heat::TestResource
487 properties:
488 fail: true
489 wait_secs: 2
490'''
491
492 def setUp(self):
493 super(ResourceGroupErrorResourceTest, self).setUp()
Steve Baker75ee9d12015-07-22 10:56:55 +1200494
495 def test_fail(self):
496 stack_identifier = self.stack_create(
497 template=self.template,
498 files={'fail.yaml': self.nested_templ},
499 expected_status='CREATE_FAILED',
500 enable_cleanup=False)
501 stack = self.client.stacks.get(stack_identifier)
502
503 self.assertEqual('CREATE_FAILED', stack.stack_status)
504 self.client.stacks.delete(stack_identifier)
505 self._wait_for_stack_status(
506 stack_identifier, 'DELETE_COMPLETE',
507 success_on_not_found=True)
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530508
509
510class ResourceGroupUpdatePolicyTest(functional_base.FunctionalTestsBase):
511
512 template = '''
513heat_template_version: '2015-04-30'
514resources:
515 random_group:
516 type: OS::Heat::ResourceGroup
517 update_policy:
518 rolling_update:
519 min_in_service: 1
520 max_batch_size: 2
521 pause_time: 1
522 properties:
523 count: 10
524 resource_def:
525 type: OS::Heat::TestResource
526 properties:
527 value: initial
528 update_replace: False
529'''
530
531 def update_resource_group(self, update_template,
532 updated, created, deleted):
533 stack_identifier = self.stack_create(template=self.template)
534 group_resources = self.list_group_resources(stack_identifier,
535 'random_group',
536 minimal=False)
537
538 init_names = [res.physical_resource_id for res in group_resources]
539
540 self.update_stack(stack_identifier, update_template)
541 group_resources = self.list_group_resources(stack_identifier,
542 'random_group',
543 minimal=False)
544
545 updt_names = [res.physical_resource_id for res in group_resources]
546
547 matched_names = set(updt_names) & set(init_names)
548
549 self.assertEqual(updated, len(matched_names))
550
551 self.assertEqual(created, len(set(updt_names) - set(init_names)))
552
553 self.assertEqual(deleted, len(set(init_names) - set(updt_names)))
554
555 def test_resource_group_update(self):
556 """Test rolling update with no conflict.
557
558 Simple rolling update with no conflict in batch size
559 and minimum instances in service.
560 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800561 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530562 grp = updt_template['resources']['random_group']
563 policy = grp['update_policy']['rolling_update']
564 policy['min_in_service'] = '1'
565 policy['max_batch_size'] = '3'
566 res_def = grp['properties']['resource_def']
567 res_def['properties']['value'] = 'updated'
568
569 self.update_resource_group(updt_template,
570 updated=10,
571 created=0,
572 deleted=0)
573
574 def test_resource_group_update_replace(self):
575 """Test rolling update(replace)with no conflict.
576
577 Simple rolling update replace with no conflict in batch size
578 and minimum instances in service.
579 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800580 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530581 grp = updt_template['resources']['random_group']
582 policy = grp['update_policy']['rolling_update']
583 policy['min_in_service'] = '1'
584 policy['max_batch_size'] = '3'
585 res_def = grp['properties']['resource_def']
586 res_def['properties']['value'] = 'updated'
587 res_def['properties']['update_replace'] = True
588
589 self.update_resource_group(updt_template,
590 updated=0,
591 created=10,
592 deleted=10)
593
594 def test_resource_group_update_scaledown(self):
595 """Test rolling update with scaledown.
596
597 Simple rolling update with reduced size.
598 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800599 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530600 grp = updt_template['resources']['random_group']
601 policy = grp['update_policy']['rolling_update']
602 policy['min_in_service'] = '1'
603 policy['max_batch_size'] = '3'
604 grp['properties']['count'] = 6
605 res_def = grp['properties']['resource_def']
606 res_def['properties']['value'] = 'updated'
607
608 self.update_resource_group(updt_template,
609 updated=6,
610 created=0,
611 deleted=4)
612
613 def test_resource_group_update_scaleup(self):
614 """Test rolling update with scaleup.
615
616 Simple rolling update with increased size.
617 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800618 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530619 grp = updt_template['resources']['random_group']
620 policy = grp['update_policy']['rolling_update']
621 policy['min_in_service'] = '1'
622 policy['max_batch_size'] = '3'
623 grp['properties']['count'] = 12
624 res_def = grp['properties']['resource_def']
625 res_def['properties']['value'] = 'updated'
626
627 self.update_resource_group(updt_template,
628 updated=10,
629 created=2,
630 deleted=0)
631
632 def test_resource_group_update_adjusted(self):
633 """Test rolling update with enough available resources
634
635 Update with capacity adjustment with enough resources.
636 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800637 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530638 grp = updt_template['resources']['random_group']
639 policy = grp['update_policy']['rolling_update']
640 policy['min_in_service'] = '8'
641 policy['max_batch_size'] = '4'
642 grp['properties']['count'] = 6
643 res_def = grp['properties']['resource_def']
644 res_def['properties']['value'] = 'updated'
645
646 self.update_resource_group(updt_template,
647 updated=6,
648 created=0,
649 deleted=4)
650
651 def test_resource_group_update_with_adjusted_capacity(self):
652 """Test rolling update with capacity adjustment.
653
654 Rolling update with capacity adjustment due to conflict in
655 batch size and minimum instances in service.
656 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800657 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530658 grp = updt_template['resources']['random_group']
659 policy = grp['update_policy']['rolling_update']
660 policy['min_in_service'] = '8'
661 policy['max_batch_size'] = '4'
662 res_def = grp['properties']['resource_def']
663 res_def['properties']['value'] = 'updated'
664
665 self.update_resource_group(updt_template,
666 updated=10,
667 created=0,
668 deleted=0)
669
670 def test_resource_group_update_huge_batch_size(self):
671 """Test rolling update with huge batch size.
672
673 Rolling Update with a huge batch size(more than
674 current size).
675 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800676 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530677 grp = updt_template['resources']['random_group']
678 policy = grp['update_policy']['rolling_update']
679 policy['min_in_service'] = '0'
680 policy['max_batch_size'] = '20'
681 res_def = grp['properties']['resource_def']
682 res_def['properties']['value'] = 'updated'
683 self.update_resource_group(updt_template,
684 updated=10,
685 created=0,
686 deleted=0)
687
688 def test_resource_group_update_huge_min_in_service(self):
689 """Test rolling update with huge minimum capacity.
690
691 Rolling Update with a huge number of minimum instances
692 in service.
693 """
Bo Wangd8df4dd2016-02-16 21:23:53 +0800694 updt_template = yaml.safe_load(copy.deepcopy(self.template))
Rabi Mishra8bcff8a2015-09-21 18:15:04 +0530695 grp = updt_template['resources']['random_group']
696 policy = grp['update_policy']['rolling_update']
697 policy['min_in_service'] = '20'
698 policy['max_batch_size'] = '1'
699 res_def = grp['properties']['resource_def']
700 res_def['properties']['value'] = 'updated'
701
702 self.update_resource_group(updt_template,
703 updated=10,
704 created=0,
705 deleted=0)