/**
 *
 * Deploy the product cluster using Jenkins master on CICD cluster
 *
 * Expected parameters:

 *   ENV_NAME                      Fuel-devops environment name
 *   PASSED_STEPS                  Steps passed to install components using Jenkins on CICD cluster: "salt,core,cicd,openstack:3200,stacklight:2400",
                                   where 3200 and 2400 might be timeouts (not used in the testing pipeline)
 *   RUN_TEST_OPTS                 Pytest option -k or -m, with expression to select necessary tests. Additional pytest options are allowed.
 *   PARENT_NODE_NAME              Name of the jenkins slave to create the environment
 *   PARENT_WORKSPACE              Path to the workspace of the parent job to use tcp-qa repo
 *   TCP_QA_REFS                   Reference to the tcp-qa change on Gerrit, like refs/changes/46/418546/41
 *   SHUTDOWN_ENV_ON_TEARDOWN      optional, shutdown fuel-devops environment at the end of the job
 *   TEMPEST_IMAGE_VERSION         Tempest image version: pike by default, can be queens.
 *   TEMPEST_TARGET                Node where tempest will be run
 *   MAKE_SNAPSHOT_STAGES          optional, use "dos.py snapshot" to snapshot stages
 */

@Library('tcp-qa')_

def common = new com.mirantis.mk.Common()
def shared = new com.mirantis.system_qa.SharedPipeline()

def steps = env.PASSED_STEPS
def make_snapshot_stages = false
env.LAB_CONFIG_NAME = env.LAB_CONFIG_NAME ?: env.ENV_NAME

timeout(time: 23, unit: 'HOURS') {
    node ("${PARENT_NODE_NAME}") {
            if (! fileExists("${PARENT_WORKSPACE}")) {
            error "'PARENT_WORKSPACE' contains path to non-existing directory ${PARENT_WORKSPACE} on the node '${PARENT_NODE_NAME}'."
        }
        dir("${PARENT_WORKSPACE}") {
            env.slave_workdir = pwd()
            if (env.TCP_QA_REFS) {
                stage("Update working dir to patch ${TCP_QA_REFS}") {
                    shared.update_working_dir()
                }
            }

            stage("Run tests") {
                try {
                    if (env.RUN_TEST_OPTS) {
                        shared.swarm_run_pytest(steps, "${PARENT_NODE_NAME}", make_snapshot_stages)
                    } else {
                        common.infoMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green")
                    }
                } catch (e) {
                    common.infoMsg("Tests are failed: " + e.message, "purple")
                    currentBuild.result = 'FAILURE'
                }
            } // stage("Run tests")

            stage("Archive all xml reports") {
                dir("${env.slave_workdir }") {
                    archiveArtifacts artifacts: "**/*.xml,**/*.log"
                    }
            }

            stage("report results to testrail from jenkins master") {
                if ("${env.REPORT_TO_TESTRAIL}" != "false") {
                    common.infoMsg("Running on: " + env.PARENT_NODE_NAME, "blue")
                    shared.verbose_sh("""\
                           [ -d /home/jenkins/venv_testrail_reporter ] || virtualenv --python=python3.7 /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""")
                    shared.swarm_testrail_report(steps, env.PARENT_NODE_NAME)
                } else {
                    common.infoMsg("REPORT_TO_TESTRAIL is set to FALSE. Skipped this step ")
                }
            } // stage("report results to testrail from jenkins master")
            stage("Store TestRail reports to job description") {
                if ("${env.REPORT_TO_TESTRAIL}" != "false") {
                    if (fileExists("description.txt")) {
                        def String description  = readFile("description.txt")
                        currentBuild.description += "${description}"
                    }
                } else {
                    common.infoMsg("REPORT_TO_TESTRAIL is set to FALSE. Skipped this step ")
                }
            } // stage("Store TestRail reports to job description")
        } // dir
    } // node
} // timeout