Introduce metadata for app behavior control

Keep existing behavior when evaluating app reapplies.

Story: 2007960
Task: 41755
Signed-off-by: Dan Voiculeasa <dan.voiculeasa@windriver.com>
Change-Id: Ie02743cdf056dda3feb66911c74f9dabe69d98dd
This commit is contained in:
Dan Voiculeasa 2021-02-03 16:00:47 +02:00
parent eab750b7ff
commit b5c1f62088
2 changed files with 70 additions and 0 deletions

View File

@ -73,6 +73,12 @@ class OpenstackAppLifecycleOperator(base.AppLifecycleOperator):
hook_info.relative_timing == constants.APP_LIFECYCLE_TIMING_POST: hook_info.relative_timing == constants.APP_LIFECYCLE_TIMING_POST:
return lifecycle_utils.delete_rbd_provisioner_secrets(app_op, app, hook_info) return lifecycle_utils.delete_rbd_provisioner_secrets(app_op, app, hook_info)
# Semantic checks
elif hook_info.lifecycle_type == constants.APP_LIFECYCLE_TYPE_SEMANTIC_CHECK:
if hook_info.mode == constants.APP_LIFECYCLE_MODE_AUTO and \
hook_info.operation == constants.APP_EVALUATE_REAPPLY_OP:
return self._semantic_check_evaluate_app_reapply(app_op, app, hook_info)
# Default behavior # Default behavior
super(OpenstackAppLifecycleOperator, self).app_lifecycle_actions(context, conductor_obj, app_op, app, super(OpenstackAppLifecycleOperator, self).app_lifecycle_actions(context, conductor_obj, app_op, app,
hook_info) hook_info)
@ -225,3 +231,52 @@ class OpenstackAppLifecycleOperator(base.AppLifecycleOperator):
except Exception as e: except Exception as e:
LOG.error(e) LOG.error(e)
raise raise
def _semantic_check_evaluate_app_reapply(self, app_op, app, hook_info):
"""Semantic check for evaluating app reapply
This is an example of how to use the evaluate reapply semantic check.
The same behavior could have been achieved by placing a filter in the metadata
based on LifecycleConstants.TRIGGER_CONFIGURE_REQUIRED
Example of equivalent behavior by adding filters to triggers in metadata:
---
behavior:
evaluate_reapply:
triggers:
- type: unlock
filters: # This line was added
- configure_required: True # This line was added
- type: force-unlock
filters: # This line was added
- configure_required: True # This line was added
:param app_op: AppOperator object
:param app: AppOperator.Application object
:param hook_info: LifecycleHookInfo object
"""
if LifecycleConstants.EVALUATE_REAPPLY_TRIGGER not in hook_info[LifecycleConstants.EXTRA]:
raise exception.LifecycleMissingInfo(
"Missing {}".format(LifecycleConstants.EVALUATE_REAPPLY_TRIGGER))
trigger = hook_info[LifecycleConstants.EXTRA][LifecycleConstants.EVALUATE_REAPPLY_TRIGGER]
if LifecycleConstants.TRIGGER_TYPE not in trigger:
raise exception.LifecycleMissingInfo(
"Missing {} {}".format(LifecycleConstants.EVALUATE_REAPPLY_TRIGGER,
LifecycleConstants.TRIGGER_TYPE))
# At the moment of writing this focus is on keeping backwards compatibility
# The logic was extracted and kept as it was
if trigger[LifecycleConstants.TRIGGER_TYPE] in [constants.UNLOCK_ACTION, constants.FORCE_UNLOCK_ACTION]:
if LifecycleConstants.TRIGGER_CONFIGURE_REQUIRED not in trigger:
raise exception.LifecycleMissingInfo(
"Missing {} {}".format(LifecycleConstants.EVALUATE_REAPPLY_TRIGGER,
LifecycleConstants.TRIGGER_CONFIGURE_REQUIRED))
# For an unlock, the logic had 'configure_required' set to True
if not trigger[LifecycleConstants.TRIGGER_CONFIGURE_REQUIRED]:
raise exception.LifecycleSemanticCheckException(
"Trigger type {} expects {} to be true".format(
trigger[LifecycleConstants.TRIGGER_TYPE],
LifecycleConstants.TRIGGER_CONFIGURE_REQUIRED))

View File

@ -6,3 +6,18 @@ disabled_charts:
- gnocchi - gnocchi
- ironic - ironic
- panko - panko
behavior:
platform_managed_app: yes
evaluate_reapply:
after:
- platform-integ-apps
triggers:
- type: unlock
- type: force-unlock
- type: runtime-apply-puppet
- type: host-availability-updated
filters:
- availability: services-enabled
- type: host-delete
filters:
- openstack_worker: True