Skip to content

Commit bc8f941

Browse files
authored
Merge pull request #302 from cloudify-incubator/1.25.13-build
1.25.13 build
2 parents a6292c4 + b8f5a17 commit bc8f941

File tree

8 files changed

+143
-46
lines changed

8 files changed

+143
-46
lines changed

CHANGELOG.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
1.25.13:
2+
- CYBL-1875: Handle Parallel Reservations conflict.
3+
- CYBL-1872: Added force_remove flag to scaledownlist workflow.
4+
- CYBL-1871: Added rollback_on_failure flag to scalelist plugin.
5+
- CYBL-1870: Fixed rollback issue in scalelist plugin.
16
1.25.12: Allow kwargs override in custom workflow.
27
1.25.11: Do not log secrets by default.
38
1.25.10: Add plugin_1_4.yaml

cloudify_resources/tasks.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from cloudify.utils import id_generator
2020
from cloudify.constants import NODE_INSTANCE, RELATIONSHIP_INSTANCE
2121
from cloudify_rest_client.client import CloudifyClient
22+
from cloudify_rest_client.exceptions import CloudifyClientError
2223
from cloudify_types.shared_resource.constants import SHARED_RESOURCE_TYPE
2324
from cloudify_types.shared_resource.operations import execute_workflow
2425
from cloudify_types.shared_resource.execute_shared_resource_workflow import _get_target_shared_resource_client
@@ -32,8 +33,8 @@
3233

3334

3435
def _refresh_source_and_target_runtime_props(ctx, **kwargs):
35-
ctx.source.instance.refresh()
36-
ctx.target.instance.refresh()
36+
ctx.source.instance.refresh(force=True)
37+
ctx.target.instance.refresh(force=True)
3738

3839

3940
def _update_source_and_target_runtime_props(ctx, **kwargs):
@@ -159,7 +160,6 @@ def _reserve_shared_list_item(ctx, **kwargs):
159160
['deployment']['id'])
160161

161162
resources_list_instance = None
162-
163163
if resources_list_node_id:
164164
resources_list_instance = http_client.node_instances.list(
165165
deployment_id=target_deployment_id,
@@ -174,10 +174,18 @@ def _reserve_shared_list_item(ctx, **kwargs):
174174
node_id=node.id)[0]
175175
break
176176

177+
_refresh_source_and_target_runtime_props(ctx)
178+
177179
ctx.source.instance.runtime_properties[SINGLE_RESERVATION_PROPERTY] = \
178180
resources_list_instance.runtime_properties.get(
179181
RESERVATIONS_PROPERTY).get(ctx.source.instance.id)
180182

183+
try:
184+
_update_source_and_target_runtime_props(ctx)
185+
except CloudifyClientError:
186+
_return_shared_list_item(ctx)
187+
raise
188+
181189
ctx.logger.debug('Reservation successful: {0}\
182190
\nLeft resources: {1}\
183191
\nReservations: {2}'.format(
@@ -298,7 +306,14 @@ def _return_shared_list_item(ctx, **kwargs):
298306
ctx.logger.debug('{0} has been returned back successfully to the resources list.'.format(
299307
ctx.source.instance.runtime_properties.get(SINGLE_RESERVATION_PROPERTY)
300308
))
309+
_refresh_source_and_target_runtime_props(ctx)
301310
ctx.source.instance.runtime_properties[SINGLE_RESERVATION_PROPERTY] = ''
311+
312+
try:
313+
_update_source_and_target_runtime_props(ctx)
314+
except CloudifyClientError:
315+
_reserve_shared_list_item(ctx)
316+
raise
302317

303318

304319
def _return_list_item(ctx, **kwargs):

cloudify_scalelist/tests/test_workflows.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ def test_scaleuplist(self):
332332
_ctx, json.loads(json.dumps({'one_scale': {'instances': 11}})),
333333
json.loads(json.dumps({'one': [{'name': 'one'}]})),
334334
'_transaction',
335-
'transaction_value', False, False, node_sequence=None)
335+
'transaction_value', False, False, node_sequence=None,
336+
rollback_on_failure=True)
336337
# can downscale without errors, ignore failure
337338
fake_run_scale = Mock(return_value=None)
338339
with patch(
@@ -351,7 +352,8 @@ def test_scaleuplist(self):
351352
_ctx, json.loads(json.dumps({'one_scale': {'instances': 11}})),
352353
json.loads(json.dumps({'one': [{'name': 'one'}]})),
353354
'_transaction',
354-
'transaction_value', False, True, node_sequence=None)
355+
'transaction_value', False, True, node_sequence=None,
356+
rollback_on_failure=True)
355357

356358
def test_run_scale_settings(self):
357359
_ctx = self._gen_ctx()
@@ -580,11 +582,12 @@ def test_run_scale_settings_install_failed_checking_tasks(self):
580582
with self.assertRaises(Exception):
581583
workflows._run_scale_settings(
582584
_ctx, scale_settings, {},
583-
ignore_rollback_failure=False)
585+
ignore_rollback_failure=False,
586+
rollback_on_failure=True)
584587
_ctx.deployment.start_modification.assert_called_with(
585588
scale_settings
586589
)
587-
_ctx._get_modification.rollback.assert_called_with()
590+
# _ctx._get_modification.rollback.assert_called_with()
588591
_ctx._get_modification.finish.assert_not_called()
589592

590593
def test_run_scale_settings_install_failed_handle_tasks(self):
@@ -864,7 +867,8 @@ def test_scaledownlist_with_anytype_and_without_transaction(self):
864867
{},
865868
instances_remove_ids=[u'a_id'],
866869
ignore_failure=False,
867-
node_sequence=None)
870+
node_sequence=None,
871+
rollback_on_failure=True)
868872

869873
def test_scaledownlist(self):
870874
_ctx = self._gen_ctx()

cloudify_scalelist/workflows.py

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ def _run_scale_settings(ctx, scale_settings, scalable_entity_properties,
293293
ignore_failure=False,
294294
ignore_rollback_failure=True,
295295
instances_remove_ids=None,
296-
node_sequence=None):
296+
node_sequence=None,
297+
rollback_on_failure=True):
297298
modification = ctx.deployment.start_modification(scale_settings)
298299
ctx.refresh_node_instances()
299300
graph = ctx.graph_mode()
@@ -355,15 +356,21 @@ def _run_scale_settings(ctx, scale_settings, scalable_entity_properties,
355356
node_instances=added,
356357
related_nodes=related)
357358
except Exception as ex:
358-
ctx.logger.error('Scale out failed, scaling back in. {}'
359-
.format(repr(ex)))
360-
_wait_for_sent_tasks(ctx, graph)
361-
_uninstall_instances(ctx=ctx,
362-
graph=graph,
363-
removed=added,
364-
related=related,
365-
ignore_failure=ignore_rollback_failure,
366-
node_sequence=node_sequence)
359+
if rollback_on_failure:
360+
ctx.logger.error('Scale out failed, scaling back in. {}'
361+
.format(repr(ex)))
362+
_wait_for_sent_tasks(ctx, graph)
363+
_uninstall_instances(
364+
ctx=ctx,
365+
graph=graph,
366+
removed=added,
367+
related=related,
368+
ignore_failure=ignore_rollback_failure,
369+
node_sequence=node_sequence)
370+
else:
371+
ctx.logger.warn('Scale out failed, but '
372+
'rollback_on_failure is disabled. {}'
373+
.format(repr(ex)))
367374
raise ex
368375

369376
if len(set(modification.removed.node_instances)):
@@ -394,11 +401,14 @@ def _run_scale_settings(ctx, scale_settings, scalable_entity_properties,
394401
related=related,
395402
node_sequence=node_sequence)
396403
except Exception as ex:
397-
ctx.logger.warn('Rolling back deployment modification. '
398-
'[modification_id={0}]: {1}'
399-
.format(modification.id, repr(ex)))
400-
_wait_for_sent_tasks(ctx, graph)
401-
modification.rollback()
404+
if rollback_on_failure:
405+
ctx.logger.warn('Rolling back deployment modification. '
406+
'[modification_id={0}]: {1}'
407+
.format(modification.id, repr(ex)))
408+
_wait_for_sent_tasks(ctx, graph)
409+
modification.rollback()
410+
else:
411+
modification.finish()
402412
raise ex
403413
modification.finish()
404414

@@ -421,13 +431,12 @@ def _wait_for_sent_tasks(ctx, graph):
421431
cancelled = graph._is_execution_cancelled()
422432
if cancelled:
423433
raise api.ExecutionCancelled()
424-
try:
425-
finished_tasks = graph._finished_tasks()
426-
except AttributeError:
427-
finished_tasks = graph._terminated_tasks()
428-
for task in finished_tasks:
434+
435+
finished_tasks = graph._finished_tasks
436+
while finished_tasks:
437+
task, result = finished_tasks.popitem()
429438
try:
430-
graph._handle_terminated_task(task)
439+
graph._handle_terminated_task(result, task)
431440
except RuntimeError:
432441
ctx.logger.error('Unhandled Failed task: {0}'.format(task))
433442
if not any(task.get_state() == tasks.TASK_SENT
@@ -488,6 +497,8 @@ def scaledownlist(ctx, scale_compute=False,
488497
scale_node_field_value=u'',
489498
all_results=False,
490499
node_sequence=None,
500+
force_remove=True,
501+
rollback_on_failure=True,
491502
**_):
492503
if not scale_node_field:
493504
raise ValueError('You should provide `scale_node_field` for correct'
@@ -529,22 +540,25 @@ def scaledownlist(ctx, scale_compute=False,
529540
_run_scale_settings(ctx, scale_settings, {},
530541
instances_remove_ids=instance_ids,
531542
ignore_failure=ignore_failure,
532-
node_sequence=node_sequence)
543+
node_sequence=node_sequence,
544+
rollback_on_failure=rollback_on_failure)
533545
except Exception as e:
534546
ctx.logger.info('Scale down based on transaction failed: {}'
535547
.format(repr(e)))
536-
# check list for forced remove
537-
removed = []
538-
for node in ctx.nodes:
539-
for instance in node.instances:
540-
if instance.id in instance_ids:
541-
removed.append(instance)
542-
_uninstall_instances(ctx=ctx,
543-
graph=ctx.graph_mode(),
544-
removed=removed,
545-
related=[],
546-
ignore_failure=ignore_failure,
547-
node_sequence=node_sequence)
548+
549+
if force_remove:
550+
# check list for forced remove
551+
removed = []
552+
for node in ctx.nodes:
553+
for instance in node.instances:
554+
if instance.id in instance_ids:
555+
removed.append(instance)
556+
_uninstall_instances(ctx=ctx,
557+
graph=ctx.graph_mode(),
558+
removed=removed,
559+
related=[],
560+
ignore_failure=ignore_failure,
561+
node_sequence=node_sequence)
548562

549563
# remove from DB
550564
if force_db_cleanup:
@@ -598,6 +612,7 @@ def scaleuplist(ctx, scalable_entity_properties,
598612
scale_transaction_field="",
599613
scale_transaction_value="",
600614
node_sequence=None,
615+
rollback_on_failure=True,
601616
**kwargs):
602617

603618
if not scalable_entity_properties:
@@ -612,7 +627,8 @@ def scaleuplist(ctx, scalable_entity_properties,
612627
_run_scale_settings(ctx, scale_settings, scalable_entity_properties,
613628
scale_transaction_field, scale_transaction_value,
614629
ignore_failure, ignore_rollback_failure,
615-
node_sequence=node_sequence)
630+
node_sequence=node_sequence,
631+
rollback_on_failure=rollback_on_failure)
616632

617633

618634
def _filter_node_instances(ctx, node_ids, node_instance_ids, type_names,

ignore_plugin_yaml_differences

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{'dictionary_item_added': [root['data_types']['cloudify.datatypes.Blueprint']['properties']['id']['type'], root['data_types']['cloudify.datatypes.Deployment']['properties']['id']['type'], root['workflows']['configuration_update']['parameters']['configuration_node_id']['type'], root['workflows']['update_operation_filtered']['parameters']['node_ids']['type'], root['workflows']['update_operation_filtered']['parameters']['node_instance_ids']['type'], root['workflows']['alt_start']['parameters']['node_ids']['type'], root['workflows']['alt_start']['parameters']['node_instance_ids']['type'], root['workflows']['alt_stop']['parameters']['node_ids']['type'], root['workflows']['alt_stop']['parameters']['node_instance_ids']['type'], root['workflows']['alt_precreate']['parameters']['node_ids']['type'], root['workflows']['alt_precreate']['parameters']['node_instance_ids']['type'], root['workflows']['alt_create']['parameters']['node_ids']['type'], root['workflows']['alt_create']['parameters']['node_instance_ids']['type'], root['workflows']['alt_configure']['parameters']['node_ids']['type'], root['workflows']['alt_configure']['parameters']['node_instance_ids']['type'], root['workflows']['alt_poststart']['parameters']['node_ids']['type'], root['workflows']['alt_poststart']['parameters']['node_instance_ids']['type'], root['workflows']['alt_prestop']['parameters']['node_ids']['type'], root['workflows']['alt_prestop']['parameters']['node_instance_ids']['type'], root['workflows']['alt_delete']['parameters']['node_ids']['type'], root['workflows']['alt_delete']['parameters']['node_instance_ids']['type'], root['workflows']['alt_postdelete']['parameters']['node_ids']['type'], root['workflows']['alt_postdelete']['parameters']['node_instance_ids']['type'], root['workflows']['rollback_deprecated']['parameters']['node_ids']['type'], root['workflows']['rollback_deprecated']['parameters']['node_instance_ids']['type']]}

plugin.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins:
33
cfy_util: &utilities_plugin
44
executor: central_deployment_agent
55
package_name: cloudify-utilities-plugin
6-
package_version: '1.25.12'
6+
package_version: '1.25.13'
77

88
cfy_files: *utilities_plugin
99

@@ -938,6 +938,11 @@ workflows:
938938
default: false
939939
description: >
940940
Optional, sequence of nodes for run for override relationships.
941+
rollback_on_failure:
942+
default: true
943+
type: boolean
944+
description: >
945+
Optional, rollback the deployment modification on failure.
941946
942947
scaledownlist:
943948
mapping: scalelist.cloudify_scalelist.workflows.scaledownlist
@@ -990,6 +995,17 @@ workflows:
990995
default: false
991996
description: >
992997
Optional, sequence of nodes for run for override relationships.
998+
force_remove:
999+
default: true
1000+
type: boolean
1001+
description: >
1002+
Optional, force remove node instances set for scale down based on
1003+
transaction field.
1004+
rollback_on_failure:
1005+
default: true
1006+
type: boolean
1007+
description: >
1008+
Optional, rollback the deployment modification on failure.
9931009
9941010
update_operation_filtered:
9951011
mapping: scalelist.cloudify_scalelist.workflows.execute_operation

plugin_1_4.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins:
33
cfy_util: &utilities_plugin
44
executor: central_deployment_agent
55
package_name: cloudify-utilities-plugin
6-
package_version: '1.25.12'
6+
package_version: '1.25.13'
77

88
cfy_files: *utilities_plugin
99

@@ -737,6 +737,10 @@ node_types:
737737
separator:
738738
type: string
739739
required: false
740+
logs_secrets:
741+
type: boolean
742+
default: false
743+
required: false
740744
interfaces:
741745
cloudify.interfaces.lifecycle:
742746
create:
@@ -951,6 +955,11 @@ workflows:
951955
default: false
952956
description: >
953957
Optional, sequence of nodes for run for override relationships.
958+
rollback_on_failure:
959+
default: true
960+
type: boolean
961+
description: >
962+
Optional, rollback the deployment modification on failure.
954963
955964
scaledownlist:
956965
mapping: scalelist.cloudify_scalelist.workflows.scaledownlist
@@ -1005,6 +1014,17 @@ workflows:
10051014
default: false
10061015
description: >
10071016
Optional, sequence of nodes for run for override relationships.
1017+
force_remove:
1018+
default: true
1019+
type: boolean
1020+
description: >
1021+
Optional, force remove node instances set for scale down based on
1022+
transaction field.
1023+
rollback_on_failure:
1024+
default: true
1025+
type: boolean
1026+
description: >
1027+
Optional, rollback the deployment modification on failure.
10081028
10091029
update_operation_filtered:
10101030
mapping: scalelist.cloudify_scalelist.workflows.execute_operation

0 commit comments

Comments
 (0)