Reconfigure updates.mirantis versioning setting

- Use stable updates repo for released jobs
- Add UPDATES_MIRANTIS_VERSION jenkins param
- Add ability to overwrite repo version in context (upgrade
  pre-deployment)
- Set repo version to 'staging' during MCP drivetrain upgrade

Change-Id: I99d70b6802a0215acf8533909f71b7d9f0784621
diff --git a/jobs/templates/bm-cicd-pike-ovs-maas.yml b/jobs/templates/bm-cicd-pike-ovs-maas.yml
index a3b6e4a..45b4aa7 100644
--- a/jobs/templates/bm-cicd-pike-ovs-maas.yml
+++ b/jobs/templates/bm-cicd-pike-ovs-maas.yml
@@ -181,6 +181,12 @@
         name: UPDATE_VERSION
         trim: 'false'
     - string:
+        name: UPDATES_MIRANTIS_VERSION
+        default: 'staging'
+        description: |
+            Overwrite subsection of updates.mirantis.com repository.
+            Effective only if enabled in cookiecutter context!
+    - string:
         name: IPMI_CREDS
         default: 'lab_engineer'
     - string:
diff --git a/jobs/templates/swarm-cookied-model-generator.yml b/jobs/templates/swarm-cookied-model-generator.yml
index b804fa0..4ea8a03 100644
--- a/jobs/templates/swarm-cookied-model-generator.yml
+++ b/jobs/templates/swarm-cookied-model-generator.yml
@@ -117,6 +117,12 @@
           name: UPDATE_VERSION
           trim: 'false'
       - string:
+          name: UPDATES_MIRANTIS_VERSION
+          default: ''
+          description: |
+            Overwrite subsection of updates.mirantis.com repository.
+            Effective only if enabled in cookiecutter context!
+      - string:
           default: ''
           description: ''
           name: DEPLOY_NETWORK_NETMASK
diff --git a/src/com/mirantis/system_qa/SharedPipeline.groovy b/src/com/mirantis/system_qa/SharedPipeline.groovy
index 0f839c6..e5f1de3 100644
--- a/src/com/mirantis/system_qa/SharedPipeline.groovy
+++ b/src/com/mirantis/system_qa/SharedPipeline.groovy
@@ -220,6 +220,7 @@
         def env_lab_ctl_iface = env.LAB_CONTROL_IFACE ?: ''
         def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
         def update_version = env.UPDATE_VERSION ?: ''
+        def updates_mirantis_version = env.UPDATES_MIRANTIS_VERSION ?: ''
         def parameters = [
                 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
                 string(name: 'PARENT_WORKSPACE', value: pwd()),
@@ -248,6 +249,7 @@
                 string(name: 'JENKINS_PIPELINE_BRANCH', value: "${jenkins_pipelines_branch}"),
                 string(name: 'MCP_COMMON_SCRIPTS_REFS', value: "${mcp_common_scripts_refs}"),
                 string(name: 'UPDATE_VERSION', value: "${update_version}"),
+                string(name: 'UPDATES_MIRANTIS_VERSION', value: "${updates_mirantis_version}"),
                 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
             ]
 
@@ -275,6 +277,7 @@
         def env_lab_ctl_iface = env.LAB_CONTROL_IFACE ?: ''
         def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
         def update_version = env.UPDATE_VERSION ?: ''
+        def updates_mirantis_version = env.UPDATES_MIRANTIS_VERSION ?: ''
         def deploy_empty_node = env.DEPLOY_EMPTY_NODE ?: false
         def parameters = [
                 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
@@ -298,6 +301,7 @@
                 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
                 string(name: 'MCP_COMMON_SCRIPTS_REFS', value: "${mcp_common_scripts_refs}"),
                 string(name: 'UPDATE_VERSION', value: "${update_version}"),
+                string(name: 'UPDATES_MIRANTIS_VERSION', value: "${updates_mirantis_version}"),
                 string(name: 'IPMI_USER', value: env_ipmi_user),
                 string(name: 'IPMI_PASS', value: env_ipmi_pass),
                 string(name: 'CISCO_PASS', value: env_cisco_pass),
@@ -440,6 +444,7 @@
         def jenkins_pipelines_branch=env.JENKINS_PIPELINE_BRANCH ?: ''
         def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
         def update_version = env.UPDATE_VERSION ?: ''
+        def updates_mirantis_version = env.UPDATES_MIRANTIS_VERSION ?: ''
 
         def parameters = [
                 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
@@ -463,6 +468,7 @@
                 string(name: 'JENKINS_PIPELINE_BRANCH', value: "${jenkins_pipelines_branch}"),
                 string(name: 'IMAGE_PATH_CFG01_DAY01', value: env.IMAGE_PATH_CFG01_DAY01),
                 string(name: 'UPDATE_VERSION', value: "${update_version}"),
+                string(name: 'UPDATES_MIRANTIS_VERSION', value: "${updates_mirantis_version}"),
 
             ]
 
diff --git a/tcp_tests/templates/released-heat-cicd-pike-contrail41-sl/salt-context-cookiecutter-contrail.yaml b/tcp_tests/templates/released-heat-cicd-pike-contrail41-sl/salt-context-cookiecutter-contrail.yaml
index a8d05b3..207c298 100644
--- a/tcp_tests/templates/released-heat-cicd-pike-contrail41-sl/salt-context-cookiecutter-contrail.yaml
+++ b/tcp_tests/templates/released-heat-cicd-pike-contrail41-sl/salt-context-cookiecutter-contrail.yaml
@@ -319,4 +319,4 @@
   # Enable Mirantis repo with CVE fixes for xenial
   updates_mirantis_login: "%LOGIN%"
   updates_mirantis_password: "%PASS%"
-  updates_mirantis_version: "staging"
\ No newline at end of file
+  updates_mirantis_version: "stable"
\ No newline at end of file
diff --git a/tcp_tests/templates/released-heat-cicd-queens-dvr-sl/salt-context-cookiecutter.yaml b/tcp_tests/templates/released-heat-cicd-queens-dvr-sl/salt-context-cookiecutter.yaml
index 6e575b1..1b4ffe0 100644
--- a/tcp_tests/templates/released-heat-cicd-queens-dvr-sl/salt-context-cookiecutter.yaml
+++ b/tcp_tests/templates/released-heat-cicd-queens-dvr-sl/salt-context-cookiecutter.yaml
@@ -382,4 +382,4 @@
   # Enable Mirantis repo with CVE fixes for xenial
   updates_mirantis_login: "%LOGIN%"
   updates_mirantis_password: "%PASS%"
-  updates_mirantis_version: "staging"
\ No newline at end of file
+  updates_mirantis_version: "stable"
\ No newline at end of file
diff --git a/tcp_tests/templates/shared-salt.yaml b/tcp_tests/templates/shared-salt.yaml
index 200ae8d..354d59e 100644
--- a/tcp_tests/templates/shared-salt.yaml
+++ b/tcp_tests/templates/shared-salt.yaml
@@ -66,6 +66,8 @@
 # Needed for using different models in different templates
 {% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
 
+# Ubuntu-postEOL updates by cloudlinux
+{% set UPDATES_MIRANTIS_VERSION = os_env('UPDATES_MIRANTIS_VERSION', '') %}
 
 {%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
 {#####################################################}
@@ -426,6 +428,10 @@
       {%- if JENKINS_PIPELINE_BRANCH != '' %}
         echo "JENKINS_PIPELINE_BRANCH={{ JENKINS_PIPELINE_BRANCH }}"
       {%- endif %}
+      {%- if UPDATES_MIRANTIS_VERSION != '' %}
+        echo "UPDATES_MIRANTIS_VERSION={{ UPDATES_MIRANTIS_VERSION }}"
+      {%- endif %}
+
       echo "======================================="
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 1, delay: 1}
@@ -517,6 +523,10 @@
     find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
     find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {} +
 
+    {%- if UPDATES_MIRANTIS_VERSION != '' %}
+    sed -i "s/updates_mirantis_version:.*/updates_mirantis_version: '{{ UPDATES_MIRANTIS_VERSION }}'/g" {{ CLUSTER_CONTEXT_PATH }}
+    {%- endif %}
+
     {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /root/cookiecutter-templates/cluster_product/)' %}
     mkdir -p /tmp/output /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/
     # Allow to use encryption keys
diff --git a/tcp_tests/tests/system/test_mcp_update.py b/tcp_tests/tests/system/test_mcp_update.py
index c01c80f..5ec2627 100644
--- a/tcp_tests/tests/system/test_mcp_update.py
+++ b/tcp_tests/tests/system/test_mcp_update.py
@@ -226,11 +226,32 @@
     salt_actions.run_state("*", "saltutil.refresh_pillar")
 
 
+@pytest.fixture(scope='class')
+def switch_to_staging_updates_mirantis_repo(reclass_actions, salt_actions):
+    version_param = "parameters._param.updates_mirantis_version"
+    infra_yml = "cluster/*/infra/init.yml"
+
+    current_version = reclass_actions.get_key(version_param, infra_yml)
+    if current_version == 'staging':
+        LOG.info("updates.mirantis.com already set to 'staging', skipping")
+        return
+    if current_version is None:
+        LOG.info("updates.mirantis.com is not enabled, "
+                 "skipping /staging repo pillar")
+        return
+
+    LOG.info("Switch to updates.mirantis.com/staging repo")
+    reclass_actions.add_key(version_param, 'staging', infra_yml)
+
+    salt_actions.run_state("*", "saltutil.refresh_pillar")
+
+
 @pytest.mark.usefixtures("switch_to_proposed_pipelines",
                          "update_to_tag",
                          "wa_for_galera_clustercheck_password_prod35705",
                          "wa_for_alerta_password_prod35958",
-                         "wa_redis_server_version_3_prod36960")
+                         "wa_redis_server_version_3_prod36960",
+                         "switch_to_staging_updates_mirantis_repo")
 class TestUpdateMcpCluster(object):
     """
     Following the steps in