Merge "Change message when no nodes found during update"

This commit is contained in:
Zuul 2019-07-31 16:26:29 +00:00 committed by Gerrit Code Review
commit fa55f5697e
1 changed files with 38 additions and 18 deletions

View File

@ -23,37 +23,57 @@ except ImportError:
DrydockBaseOperator DrydockBaseOperator
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
safeguard_message_header = (
"No nodes were found by Drydock. Safeguard triggered to prevent "
"continued deployment of nodes.")
safeguard_message_body = (
"This condition can occur if update_site is invoked before a deploy_site "
"has previously deployed nodes in this site. If nodes are expected to be "
"present (previously deployed), this is a serious condition and should "
"be investigated. This behavior can be bypassed by setting "
"continue-on-fail to true.")
safeguard_bypassed_message = (
"Nodes do not exist, but continue-on-fail is True. Safeguard bypassed by "
"invocation options.")
class DrydockVerifyNodesExistOperator(DrydockBaseOperator): class DrydockVerifyNodesExistOperator(DrydockBaseOperator):
"""Drydock Verify nodes exist Operator """Drydock Verify nodes exist Operator
This operator will trigger drydock to verify node for Check that ANY nodes exist.
site update One use of this is to prevent an update_site from redeploying servers if
the underlying datastores have lost their data. Doing this prevents
destruction of potentially running workloads.
""" """
def do_execute(self): def do_execute(self):
LOG.info("Verifying that nodes exist before proceeding.")
LOG.info('verify_nodes_exit was invoked.')
node_list = self.get_nodes() node_list = self.get_nodes()
continue_on_fail = self.action_info['parameters'].get( if not node_list:
'continue-on-fail', 'false') if self.continue_on_fail():
LOG.debug('node list is : {}'.format(node_list)) LOG.info(safeguard_bypassed_message)
LOG.debug('continue on fail is: {}'.format(continue_on_fail)) else:
LOG.error(safeguard_message_header)
LOG.error(safeguard_message_body)
raise AirflowException(safeguard_message_header)
else:
LOG.info("Drydock reports nodes: %s", node_list)
if not node_list and str(continue_on_fail).lower() != 'true': def continue_on_fail(self):
msg = 'No nodes were found in MaaS, ' \ """Retrieve the continue_on_fail boolean value
'and continue_on_fail is {} ' \
'-> Fail Drydock prepare and ' \ Fetch the continue-on-fail value from the action_info parameters and
'deply nodes.'.format(continue_on_fail) translate it into a boolean value.
LOG.error(msg) """
raise AirflowException(msg) continue_on_fail_str = str(self.action_info['parameters'].get(
'continue-on-fail', 'false'))
continue_on_fail = continue_on_fail_str.lower() == 'true'
LOG.debug("continue-on-fail value is: %s, evaluates to: %s",
continue_on_fail_str, continue_on_fail)
return continue_on_fail
class DrydockVerifyNodesExistOperatorPlugin(AirflowPlugin): class DrydockVerifyNodesExistOperatorPlugin(AirflowPlugin):
"""Creates DrydockVerifyNodesExistOperatorPlugin in Airflow.""" """Creates DrydockVerifyNodesExistOperatorPlugin in Airflow."""
name = 'drydock_verify_nodes_exist_operator' name = 'drydock_verify_nodes_exist_operator'