From a82b3e861b1046f8976d727caa37a46532745192 Mon Sep 17 00:00:00 2001 From: Mykyta Karpin Date: Mon, 6 Aug 2018 15:52:07 +0300 Subject: [PATCH] Add ability to get confirmation on event Currently salt doesn't allow to get confirmation on minion upon successfull reactor execution on event. However there can be issues with reactor in salt 2017.7 [1] or reactor register state can fail if pillar failed to render, so node registration confirmation maybe needed. In order to enable this functionality add node_confirm_registration parameter to event data with value true. [1] https://github.com/saltstack/salt/issues/47539 Change-Id: I1abc4fdf172e018dcdb48abcf61532fb51ad3660 Related-Prod: https://mirantis.jira.com/browse/PROD-21463 --- README.rst | 16 ++++++++++++++++ reclass/orchestrate/reactor/node_register.sls | 14 ++++++++++++++ reclass/orchestrate/reactor/node_unregister.sls | 12 ++++++++++++ 3 files changed, 42 insertions(+) diff --git a/README.rst b/README.rst index 29690d5..26e7723 100644 --- a/README.rst +++ b/README.rst @@ -108,6 +108,22 @@ Event to trigger the node classification Both actions will use the minion ID as the node_name to be updated. +Confirmation of node classification + + Currently salt doesn't allow to get confirmation on minion upon successfull reactor execution on event. However there can be issues + with reactor in salt 2017.7 (https://github.com/saltstack/salt/issues/47539) or reactor register state can fail if pillar failed + to render, so node registration confirmation maybe needed. In order to enable this functionality add node_confirm_registration parameter to + event data with value true: + +.. code-block:: bash + + salt-call event.send 'reclass/minion/classify' "{'node_master_ip': '$config_host', 'node_ip': '${node_ip}', 'node_domain': '$node_domain', 'node_cluster': '$node_cluster', 'node_hostname': '$node_hostname', 'node_os': '$node_os', node_confirm_registration: true}" + + Then on minion side execute: + salt-call mine.get 'salt:master' ${minion_id}_classified pillar + + If true is returned than registration has passed successfully + Event to trigger the node declassification .. code-block:: bash diff --git a/reclass/orchestrate/reactor/node_register.sls b/reclass/orchestrate/reactor/node_register.sls index 6cc2f0e..1db8057 100644 --- a/reclass/orchestrate/reactor/node_register.sls +++ b/reclass/orchestrate/reactor/node_register.sls @@ -19,3 +19,17 @@ regenerate_all_nodes: - queue: True - require: - salt: classify_node_{{ node_name }} + +{% if node_data.get('node_confirm_registration', False) | to_bool %} +confirm_node_classification_{{ node_name }}: + salt.function: + - tgt: 'salt:master' + - tgt_type: pillar + - name: mine.send + - arg: + - '{{ node_name }}_classified' + - 'mine_function=cmd.shell' + - 'echo true' + - require: + - salt: regenerate_all_nodes +{% endif %} diff --git a/reclass/orchestrate/reactor/node_unregister.sls b/reclass/orchestrate/reactor/node_unregister.sls index ec6fd91..5fb7725 100644 --- a/reclass/orchestrate/reactor/node_unregister.sls +++ b/reclass/orchestrate/reactor/node_unregister.sls @@ -8,3 +8,15 @@ unregister_node_{{ node_name }}: - queue: True - pillar: node_name: {{ node_name }} + +{% if salt['mine.get']('salt:master', node_name + '_classified', 'pillar') %} +confirm_node_unregistration_{{ node_name }}: + salt.function: + - tgt: 'salt:master' + - tgt_type: pillar + - name: mine.delete + - arg: + - '{{ node_name }}_classified' + - require: + - salt: unregister_node_{{ node_name }} +{% endif %}