Fix upgrade test for PROD-37068

-microfix mcp_update with rule flake8
-change pipline lib before upgrade

Related-Prod: PROD-36426
Change-Id: Iebfa1cf671fe873d6bcb4fbbb058494f9bf09274
diff --git a/tcp_tests/tests/system/test_mcp_update.py b/tcp_tests/tests/system/test_mcp_update.py
index 51d29d0..e4c84ac 100644
--- a/tcp_tests/tests/system/test_mcp_update.py
+++ b/tcp_tests/tests/system/test_mcp_update.py
@@ -109,6 +109,34 @@
     salt_actions.enforce_state("I@jenkins:client", "jenkins.client")
 
 
+@pytest.mark.parametrize("_", [settings.ENV_NAME])
+@pytest.fixture
+def wa_for_stacklight_monitor_hostname_prod37068(reclass_actions,
+                                                 salt_actions):
+    stacklight_monitor_hostname = salt_actions.cmd_run(
+        "I@salt:master",
+        ". /root/venv-reclass-tools/bin/activate; "
+        "reclass-tools get-key "
+        "parameters.dogtag.server.stacklight_monitor_hostname "
+        "/srv/salt/reclass/classes/cluster/{env_name}"
+        "/openstack/barbican.yml".format(
+            env_name=settings.ENV_NAME))
+
+    if stacklight_monitor_hostname != '':
+        reclass_actions.add_key(
+            "parameters.dogtag.server.stacklight_monitor_hostname",
+            "mon",
+            "cluster/*/openstack/barbican.yml"
+        )
+        salt_actions.cmd_run("cfg01*",
+                             "cd /srv/salt/reclass; git add -u && "
+                             "git commit --allow-empty "
+                             "-m 'fix stacklight_monitor_hostname "
+                             "for dogtag'")
+    else:
+        LOG.info("Skipping WA stacklight_monitor_hostname fix prod37068")
+
+
 @pytest.fixture
 def wa_for_galera_clustercheck_password_prod35705(reclass_actions,
                                                   salt_actions):
@@ -117,13 +145,13 @@
                                    "_param:galera_clustercheck_password")[0]:
         reclass_actions.add_key(
             "parameters._param.galera_clustercheck_password",
-            "a"*32,
+            "a" * 32,
             "cluster/*/infra/secrets.yml")
         salt_actions.run_state(tgt, "saltutil.refresh_pillar")
         salt_actions.enforce_state(tgt, "galera")
         salt_actions.enforce_state(tgt, "haproxy")
         reclass_actions.commit(
-          "[from TCP-QA] Add galera_clustercheck_password")
+            "[from TCP-QA] Add galera_clustercheck_password")
     else:
 
         LOG.info("Skipping WA for Galera Clustercheck Password")
@@ -154,12 +182,11 @@
 @pytest.fixture
 def wa_for_alerta_password_prod35958(reclass_actions,
                                      salt_actions):
-
     if not salt_actions.get_pillar("I@prometheus:alerta",
                                    "_param:alerta_admin_api_key_generated")[0]:
         reclass_actions.add_key(
             "parameters._param.alerta_admin_api_key_generated",
-            "a"*32,
+            "a" * 32,
             "cluster/*/infra/secrets.yml")
         reclass_actions.add_key(
             "parameters._param.alerta_admin_key",
@@ -259,6 +286,7 @@
                          "wa_for_galera_clustercheck_password_prod35705",
                          "wa_for_alerta_password_prod35958",
                          "wa_redis_server_version_3_prod36960",
+                         "wa_for_stacklight_monitor_hostname_prod37068",
                          "switch_to_staging_updates_mirantis_repo")
 class TestUpdateMcpCluster(object):
     """
@@ -270,16 +298,17 @@
     @pytest.mark.parametrize("_", [settings.ENV_NAME])
     @pytest.mark.run_mcp_update
     def test_update_drivetrain(self, salt_actions, drivetrain_actions,
-                               show_step, update_to_tag, _):
+                               show_step, update_to_tag, reclass_actions, _):
         """Updating DriveTrain component to release/proposed/2019.2.0 version
 
         Scenario:
             1. Add workaround for PROD-32751
             2. Run job git-mirror-downstream-mk-pipelines
             3. Run job git-mirror-downstream-pipeline-library
-            4. Run job pre-upgrade-verify
-            5. If jobs are passed then start 'Deploy - upgrade MCP Drivetrain'
-            6. Wait till salt-master completes all async jobs
+            4. Switch mcp-ci/pipeline-library to new version
+            5. Run job pre-upgrade-verify
+            6. If jobs are passed then start 'Deploy - upgrade MCP Drivetrain'
+            7. Wait till salt-master completes all async jobs
 
         Duration: ~70 min
         """
@@ -321,8 +350,34 @@
 
         assert job_result == 'SUCCESS', job_description
 
-        # ############### Start 'Pre-upgrade verify' job (since 2019.2.17)#####
+        # ############### Switch mcp-ci/pipeline-library to new version########
         show_step(4)
+
+        # https://docs.mirantis.com/mcp/q4-18/mcp-operations-guide/
+        # update-upgrade/minor-update/preupdate-drivetrain-verify.html
+        actual_piplines_version = salt.get_single_pillar(
+            "I@salt:master",
+            "_param:jenkins_pipelines_branch")
+        LOG.info(actual_piplines_version)
+        if actual_piplines_version != "refs/tags/{}".format(
+                update_to_tag):
+            reclass_actions.add_key(
+                'parameters._param.jenkins_pipelines_branch',
+                "refs/tags/{}".format(
+                    update_to_tag),
+                'cluster/*/infra/init.yml')
+            salt.run_state("I@jenkins:client and not I@salt:master",
+                           "saltutil.refresh_pillar")
+            salt_actions.enforce_state("I@jenkins:client:lib",
+                                       "jenkins.client.lib")
+            salt_actions.cmd_run("cfg01*",
+                                 "cd /srv/salt/reclass; git add -u && "
+                                 "git commit --allow-empty "
+                                 "-m 'use workaround for PROD-37068 "
+                                 "missing'")
+
+        # ############### Start 'Pre-upgrade verify' job (since 2019.2.17)#####
+        show_step(5)
         job_name = 'pre-upgrade-verify'
         job_parameters = {}
 
@@ -337,7 +392,7 @@
             assert job_result == 'SUCCESS', job_description
 
         # ################### Start 'Deploy - upgrade MCP Drivetrain' job #####
-        show_step(5)
+        show_step(6)
 
         job_name = 'upgrade-mcp-release'
         job_parameters = {
@@ -346,10 +401,10 @@
                 update_to_tag or 'release/proposed/2019.2.0',
             'TARGET_MCP_VERSION': update_to_tag or '2019.2.0',
             "DRIVE_TRAIN_PARAMS": {
-                        "OS_DIST_UPGRADE": True,
-                        "OS_UPGRADE": True,
-                        "BATCH_SIZE": 10
-                        }
+                "OS_DIST_UPGRADE": True,
+                "OS_UPGRADE": True,
+                "BATCH_SIZE": 10
+            }
         }
         job_result, job_description = dt.start_job_on_jenkins(
             job_name=job_name,
@@ -359,8 +414,8 @@
 
         assert job_result == 'SUCCESS', job_description
         # ############### Wait till salt-master completes all async jobs #####
-        show_step(5)
-        salt.wait_jobs_completed(timeout=20*60)
+        show_step(7)
+        salt.wait_jobs_completed(timeout=20 * 60)
 
     @pytest.mark.grab_versions
     @pytest.mark.parametrize("_", [settings.ENV_NAME])
@@ -450,7 +505,7 @@
         show_step(2)
         if (update_mysql_to_version == '5.7'):
             mysql_class = "cluster.{env_name}.openstack." \
-                          "database.mysql_version"\
+                          "database.mysql_version" \
                 .format(env_name=settings.ENV_NAME)
             reclass.add_class(
                 mysql_class,
@@ -459,17 +514,17 @@
                 mysql_class,
                 "cluster/*/openstack/database/slave.yml")
             mysql_path = "cluster/{env_name}" \
-                         "/openstack/database/mysql_version.yml"\
+                         "/openstack/database/mysql_version.yml" \
                 .format(env_name=settings.ENV_NAME)
             galera_mysql_version = '5.7'
             if update_mysql_to_version != '5.7':
                 galera_mysql_version = update_mysql_to_version
             mysql_version = "parameters:\n" \
                             "  _param:\n" \
-                            "    galera_mysql_version: {}"\
+                            "    galera_mysql_version: {}" \
                 .format(galera_mysql_version)
             if not os.path.isfile("/srv/salt/reclass/classes/{path}".format(
-                                      path=mysql_path)):
+                    path=mysql_path)):
                 reclass.create_yaml_with_context(mysql_version,
                                                  mysql_path)
             else:
@@ -701,7 +756,7 @@
 
         ceph_version = salt_actions.get_single_pillar(
             "I@salt:master",
-            "_param:_param:ceph_version")
+            "_param:ceph_version")
         if ceph_version == "nautilus":
             wa_cve_2021_20288_global_id_reclaim(reclass, salt)
         else: