/**
 *
 * 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
def 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.printMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green")
                    }
                } catch (e) {
                    common.printMsg("Tests are failed: " + e.message, "purple")
                }
            } // stage("Run tests")

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

            stage("report results to testrail from jenkins master") {
                if ("${env.REPORT_TO_TESTRAIL}" != "false") {
                    common.printMsg("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.printMsg("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.printMsg("REPORT_TO_TESTRAIL is set to FALSE. Skipped this step ")
                }
            } // stage("Store TestRail reports to job description")
        } // dir
    } // node
} // timeout