Mark testresults automatically for each deployment

PROD-35718

Change-Id: I0289d9db8316d4ffcfd984b42be22e02b1abab1d
diff --git a/jobs/pipelines/swarm-bootstrap-salt-cluster-heat.groovy b/jobs/pipelines/swarm-bootstrap-salt-cluster-heat.groovy
index 10ea257..dd866a3 100644
--- a/jobs/pipelines/swarm-bootstrap-salt-cluster-heat.groovy
+++ b/jobs/pipelines/swarm-bootstrap-salt-cluster-heat.groovy
@@ -263,18 +263,27 @@
 
                 stage("Clean the environment and clone tcp-qa") {
                     deleteDir()
+                    // Install  TestRail reporter to upload test results to TestRail
                     shared.verbose_sh("""\
                         [ -d /home/jenkins/venv_testrail_reporter ] || virtualenv /home/jenkins/venv_testrail_reporter
                     """, true, false, true)
                     shared.run_cmd("""\
                         . /home/jenkins/venv_testrail_reporter/bin/activate; pip install git+https://github.com/dis-xcom/testrail_reporter -U
                     """)
+                    // Install DEVOPS tools
                     shared.verbose_sh("""\
                         [ -d /home/jenkins/fuel-devops30 ] || virtualenv /home/jenkins/fuel-devops30
                     """, true, false, true)
                     shared.run_cmd("""\
                         git clone https://gerrit.mcp.mirantis.com/mcp/tcp-qa ${PARENT_WORKSPACE}
                     """)
+                    // Install  TestRail reporter to mark known failures test results to TestRail
+                    shared.verbose_sh("""\
+                        [ -d /home/jenkins/venv_testrail_analyzer ] || virtualenv --python=python3 /home/jenkins/venv_testrail_analyzer
+                    """, true, false, true)
+                    shared.run_cmd("""\
+                        . /home/jenkins/venv_testrail_analyzer/bin/activate; pip install git+https://github.com/ibumarskov/testrail-reporter
+                    """)
                     shared.update_working_dir()
                 }
 
@@ -289,7 +298,7 @@
                     stage("Run the 'underlay' and 'salt-deployed' fixtures to bootstrap salt cluster") {
                         def xml_report_name = "deploy_salt.xml"
                         try {
-                            // deploy_salt.xml
+                            // deploy_salt.xmli
                             shared.run_sh("""\
                                 export ENV_NAME=${ENV_NAME}
                                 export LAB_CONFIG_NAME=${LAB_CONFIG_NAME}
diff --git a/jobs/pipelines/swarm-testrail-report.groovy b/jobs/pipelines/swarm-testrail-report.groovy
index 17b770f..4af60af 100644
--- a/jobs/pipelines/swarm-testrail-report.groovy
+++ b/jobs/pipelines/swarm-testrail-report.groovy
@@ -19,6 +19,8 @@
 def common = new com.mirantis.mk.Common()
 def shared = new com.mirantis.system_qa.SharedPipeline()
 def stacks = shared.get_steps_list(PASSED_STEPS)
+def testPlanNamePrefix = env.TEST_PLAN_NAME_PREFIX ?: "[2019.2.0-update]System"
+def testPlanName = env.TEST_PLAN_NAME ?: "${testPlanNamePrefix}-${MCP_VERSION}-${new Date().format('yyyy-MM-dd')}"
 
 if (! env.PARENT_NODE_NAME) {
     error "'PARENT_NODE_NAME' must be set from the parent deployment job!"
@@ -85,7 +87,7 @@
                     reporter_extra_options = [
                       "--testrail-add-missing-cases",
                     ]
-                    ret = shared.upload_results_to_testrail(deployment_report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
+                    ret = shared.upload_results_to_testrail(deployment_report_name, testPlanName, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
                     common.printMsg(ret.stdout, "blue")
                     report_url = ret.stdout.split("\n").each {
                         if (it.contains("[TestRun URL]")) {
@@ -106,7 +108,7 @@
                       "--testrail-add-missing-cases",
 //                       "--testrail_configuration_name tcp-qa",
                     ]
-                    ret = shared.upload_results_to_testrail(tcpqa_report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
+                    ret = shared.upload_results_to_testrail(tcpqa_report_name, testPlanName, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
                     common.printMsg(ret.stdout, "blue")
                     report_url = ret.stdout.split("\n").each {
                         if (it.contains("[TestRun URL]")) {
@@ -129,11 +131,15 @@
 //                       "--testrail_configuration_name tcp-qa",
                     ]
                     ret = shared.upload_results_to_testrail(tempest_report_name,
+                                                            testPlanName,
                                                             testSuiteName,
                                                             methodname,
                                                             testrail_name_template,
                                                             reporter_extra_options)
                     common.printMsg(ret.stdout, "blue")
+                    marked = shared.mark_test_results(testPlanName, testSuiteName)
+                    common.printMsg(marked.stdout, "blue")
+
                     report_url = ret.stdout.split("\n").each {
                         if (it.contains("[TestRun URL]")) {
                             common.printMsg("Found report URL: " + it.trim().split().last(), "blue")
@@ -153,8 +159,11 @@
                       "--testrail-add-missing-cases",
                       "--testrail-case-custom-fields {\\\"custom_qa_team\\\":\\\"9\\\"}",
                     ]
-                    ret = shared.upload_results_to_testrail(stacklight_report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
+                    ret = shared.upload_results_to_testrail(stacklight_report_name, testPlanName, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
                     common.printMsg(ret.stdout, "blue")
+                    marked = shared.mark_test_results(testPlanName, testSuiteName)
+                    common.printMsg(marked.stdout, "blue")
+
                     report_url = ret.stdout.split("\n").each {
                         if (it.contains("[TestRun URL]")) {
                             common.printMsg("Found report URL: " + it.trim().split().last(), "blue")
@@ -175,9 +184,12 @@
                       "--testrail-add-missing-cases",
 //                       "--testrail_configuration_name tcp-qa",
                     ]
-                    ret = shared.upload_results_to_testrail(cvp_sanity_report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
-                    common.printMsg(ret.stdout, "blue")
-                    report_url = ret.stdout.split("\n").each {
+                    uploaded = shared.upload_results_to_testrail(cvp_sanity_report_name, testPlanName, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
+                    common.printMsg(uploaded.stdout, "blue")
+                    marked = shared.mark_test_results(testPlanName, testSuiteName)
+                    common.printMsg(marked.stdout, "blue")
+
+                    report_url = uploaded.stdout.split("\n").each {
                         if (it.contains("[TestRun URL]")) {
                             common.printMsg("Found report URL: " + it.trim().split().last(), "blue")
                             description += "<a href=" + it.trim().split().last() + ">${testSuiteName}</a><br>"
@@ -187,6 +199,7 @@
                 }
             }
 
+
             // Check if there were any exceptions during reporting
             if (exception_message) {
                 throw new Exception(exception_message)