Refactor reclass cloning

SALT_MODELS_REF_CHANGE SALT_MODELS_COMMIT are both exclusive. If
SALT_MODELS_REF_CHANGE is specified then it means we don't need to do a
checkout to special commit. SALT_MODELS_COMMIT is specified but
SALT_MODELS_REF_CHANGE is not, then we need to checkout that commit.

* This change refactor the logic across all templates.
* This change introduce for loop for SALT_MODELS_REF_CHANGE. Several
  commits can be specified using space as separator. Here is an example
  export SALT_MODELS_REF_CHANGE='refs/changes/12/8412/2 refs/changes/58/8458/1'
  All commits should not have any conflicts. In case of conflicts create
  dependant commits and use top one.
* The 'cmd:' for the step "Clone reclass models with submodules" was moved
  to shared-salt.yaml and included to other templates as a jinja2 'macro'.
* SALT_MODELS_SYSTEM_COMMIT now works as expected. If not specified then
  will be used the 'system' commit specified in the cluster model
  submodule.

Doc-Impact

Change-Id: I0d57b1eea79a7c011231dcf7f46fb3599a62c33f
Signed-off-by: Sergii Golovatiuk <sgolovatiuk@mirantis.com>
Reviewed-on: https://review.gerrithub.io/372906
Reviewed-by: Sergii Golovatiuk <holser@gmail.com>
Reviewed-by: Dennis Dmitriev <dis.xcom@gmail.com>
Tested-by: Dennis Dmitriev <dis.xcom@gmail.com>
diff --git a/tcp_tests/templates/physical_mcp11_dvr/salt.yaml b/tcp_tests/templates/physical_mcp11_dvr/salt.yaml
index c8351e7..adebfeb 100644
--- a/tcp_tests/templates/physical_mcp11_dvr/salt.yaml
+++ b/tcp_tests/templates/physical_mcp11_dvr/salt.yaml
@@ -2,18 +2,9 @@
 {% from 'physical_mcp11_dvr/underlay.yaml' import REPOSITORY_SUITE with context %}
 
 {% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/mcp-baremetal-lab') %}
-{% set SALT_MODELS_BRANCH = os_env('SALT_MODELS_BRANCH','master') %}
-{% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %}
+# Other salt model repository parameters see in shared-salt.yaml
 
-# Reference to a patch that should be applied to the model if required, for example: export SALT_MODELS_REF_CHANGE=refs/changes/19/7219/12
-{% set SALT_MODELS_REF_CHANGE = os_env('SALT_MODELS_REF_CHANGE', '') %}
-
-# Address pools for reclass cluster model are taken in the following order:
-# 1. environment variables,
-# 2. config.underlay.address_pools based on fuel-devops address pools
-#    (see generated '.ini' file after underlay is created),
-# 3. defaults
-{% set address_pools = config.underlay.address_pools %}
+{% import 'shared-salt.yaml' as SHARED with context %}
 
 # Install salt to the config node
 
@@ -60,32 +51,7 @@
 
 - description: Clone reclass models with submodules
   cmd: |
-    ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
-    git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
-    pushd /srv/salt/reclass && git checkout {{ SALT_MODELS_COMMIT }} && popd;
-    {%- if SALT_MODELS_REF_CHANGE != '' %}
-    pushd /srv/salt/reclass && git fetch {{ SALT_MODELS_REPOSITORY }} {{ SALT_MODELS_REF_CHANGE }} && git checkout FETCH_HEAD && popd;
-    {%- endif %}
-    mkdir -p /srv/salt/reclass/classes/service;
-
-    # Replace firstly to an intermediate value to avoid intersection between
-    # already replaced and replacing networks.
-    # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
-    # 192.168.10 -> 10.16.0 (generated network for admin)
-    # 10.16.0 -> <external network>
-    # So let's replace constant networks to the keywords, and then keywords to the desired networks.
-
-    find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
-
-    # Disable checkouting the model from remote repository
-    cat << 'EOF' >> /srv/salt/reclass/nodes/control/{{ HOSTNAME_CFG01 }}.yml
-    # local storage
-      reclass:
-        storage:
-          data_source:
-            engine: local
-    EOF
-
+{{  SHARED.MACRO_CLONE_RECLASS_MODELS() }}
     # Show the changes to the console
     cd /srv/salt/reclass/; git diff
   node_name: {{ HOSTNAME_CFG01 }}
@@ -323,22 +289,3 @@
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 1, delay: 10}
   skip_fail: false
-
-
-#- description: Hack gtw node
-#  cmd: salt 'gtw*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4";
-#  node_name: {{ HOSTNAME_CFG01 }}
-#  retry: {count: 1, delay: 10}
-#  skip_fail: false
-
-#- description: Hack cmp01 node
-#  cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
-#  node_name: {{ HOSTNAME_CFG01 }}
-#  retry: {count: 1, delay: 10}
-#  skip_fail: false
-
-#- description: Hack cmp02 node
-#  cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
-#  node_name: {{ HOSTNAME_CFG01 }}
-#  retry: {count: 1, delay: 10}
-#  skip_fail: false