Add pipeline to start long test scenarious

PROD-36050
Change-Id: I7e381385d74bf4e3703d755c343bd2f380f9e253
diff --git a/jobs/pipelines/run-test-scenarios.groovy b/jobs/pipelines/run-test-scenarios.groovy
new file mode 100644
index 0000000..877c0c8
--- /dev/null
+++ b/jobs/pipelines/run-test-scenarios.groovy
@@ -0,0 +1,83 @@
+/**
+ *
+ * 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
+
+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
\ No newline at end of file
diff --git a/jobs/pipelines/self-deploy-jobs.groovy b/jobs/pipelines/self-deploy-jobs.groovy
index 5815cd3..7707a8e 100644
--- a/jobs/pipelines/self-deploy-jobs.groovy
+++ b/jobs/pipelines/self-deploy-jobs.groovy
@@ -8,7 +8,7 @@
             stage('Prepre venv'){
                 sh """
                 if [ ! -d .venv ]; then
-                  echo "Can't find python virtal env, installing"
+                  echo "Can't find python virtual env, installing"
                   virtualenv -p python3 .venv
                 fi
                 if [ -z "\$(./.venv/bin/pip freeze | grep  jenkins-job-builder)" ]; then
diff --git a/jobs/templates/test-scenarios.yml b/jobs/templates/test-scenarios.yml
new file mode 100644
index 0000000..10388e0
--- /dev/null
+++ b/jobs/templates/test-scenarios.yml
@@ -0,0 +1,237 @@
+---
+
+- project:
+    name: test-scenarios
+    views:
+      - Test Backups
+      - Test Ceph
+      - Test MCP updates
+    jobs:
+      - backup-tests
+      - ceph-tests
+      - update-tests
+
+################### VIEWS #######################
+- view:
+    name: Test Backups
+    view-type: list
+    filter-executors: true
+    filter-queue: true
+    regex: 'backup-.*'
+    columns:
+      - status
+      - weather
+      - job
+      - last-success
+      - last-failure
+      - last-duration
+      - build-button
+
+- view:
+    name: Test Ceph
+    view-type: list
+    filter-executors: true
+    filter-queue: true
+    regex: 'ceph_.*'
+    columns:
+      - status
+      - weather
+      - job
+      - last-success
+      - last-failure
+      - last-duration
+      - build-button
+
+- view:
+    name: Test MCP updates
+    view-type: list
+    filter-executors: true
+    filter-queue: true
+    regex: '.*-update-.*'
+    columns:
+      - status
+      - weather
+      - job
+      - last-success
+      - last-failure
+      - last-duration
+      - build-button
+
+######################## JOB GROUP ####################
+- job-group:
+    name: 'backup-tests'
+    test_scenario:
+
+      - backup-saltmaster-queens-dvr-sl:
+          run-test-opts: '-k TestBackupRestoreMaster'
+          deployment: heat-cicd-queens-dvr-sl
+
+      - backup-saltmaster-pike-dvr-sl:
+         run-test-opts: '-k TestBackupRestoreMaster'
+         deployment: heat-cicd-pike-dvr-sl
+
+      - backup-cassandra-queens-contrail-sl:
+         run-test-opts: '-k TestBackupRestoreCassandra'
+         deployment: heat-cicd-queens-contrail-sl
+
+    jobs:
+      - '{test_scenario}'
+
+- job-group:
+    name: 'ceph-tests'
+    test_scenario:
+      - ceph_osd-queens-dvr-sl:
+         run-test-opts: '-k TestCephOsd'
+         deployment: heat-cicd-queens-dvr-sl
+    jobs:
+      - '{test_scenario}'
+
+- job-group:
+    name: 'update-tests'
+    test-opt: |-
+      --keep-duplicates --maxfail=1 \
+      tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_drivetrain \
+      tcp_tests/tests/system/test_mcp_update.py::TestOpenstackUpdate \
+      tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_galera
+      tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_rabbit \
+      tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_stacklight \
+      tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_ceph \
+      \
+      tcp_tests/tests/system/test_3rdparty_suites.py::Test3rdpartySuites::test_run_tempest \
+      tcp_tests/tests/system/test_cvp_pipelines.py::TestCvpPipelines::test_run_cvp_func_sanity \
+      tcp_tests/tests/system/test_cvp_pipelines.py::TestCvpPipelines::test_run_cvp_stacklight
+    test-opt-with-contrail: |-
+      --keep-duplicates --maxfail=1 \
+      tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_drivetrain \
+      tcp_tests/tests/system/test_upgrade_contrail.py::TestUpdateContrail \
+      tcp_tests/tests/system/test_mcp_update.py::TestOpenstackUpdate \
+      tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_galera
+      tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_rabbit \
+      tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_stacklight \
+      tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_ceph \
+      \
+      tcp_tests/tests/system/test_3rdparty_suites.py::Test3rdpartySuites::test_run_tempest \
+      tcp_tests/tests/system/test_cvp_pipelines.py::TestCvpPipelines::test_run_cvp_func_sanity \
+      tcp_tests/tests/system/test_cvp_pipelines.py::TestCvpPipelines::test_run_cvp_stacklight
+
+    test_scenario:
+      - mcp-update-pike-sl:
+          deployment: released-heat-cicd-pike-dvr-sl
+          disabled: true
+          run-test-opts: '{test-opt}'
+
+      - mcp-update-queens-dvr-sl:
+          deployment: released-heat-cicd-queens-dvr-sl
+          disabled: true
+          run-test-opts: '{test-opt}'
+
+      - mcp-update-pike-contrail-sl:
+          deployment: released-heat-cicd-pike-contrail41-sl
+          disabled: true
+          run-test-opts: '{test-opt-with-contrail}'
+
+      - mcp-update-queens-contrail-sl:
+          deployment: released-heat-cicd-queens-contrail41-sl
+          disabled: true
+          run-test-opts: '{test-opt-with-contrail}'
+
+      - os-update-pike-to-queens:
+          deployment: heat-cicd-pike-dvr-sl
+          run-test-opts: '-k TestUpdatePikeToQueens'
+
+      - ceph-update-luminous-to-nautilus:
+          deployment: heat-cicd-pike-dvr-sl
+          disabled: true
+          run-test-opts: '-k TestCephUpdate'
+
+    jobs:
+      - '{test_scenario}'
+
+###################### JOB TEMPLATE ###################
+- job-template:
+    name: '{test_scenario}'
+    project-type: pipeline
+    concurrent: false
+    disabled: '{disabled|false}'
+    quiet-period: 2
+    node: 'openstack_slave_{deployment}'
+    logrotate:
+      daysToKeep: 30
+      numToKeep: 60
+      artifactDaysToKeep: -1
+      artifactNumToKeep: -1
+    # Requires the Jenkins BuildResultTrigger Plugin
+    triggers:
+      - build-result:
+          cron: '* * * * *'
+          combine: true
+          groups:
+            - jobs:
+                - '{deployment}'
+              results:
+                - success
+
+    pipeline-scm:
+      lightweight-checkout: false
+      scm:
+        - git:
+            branches:
+              - FETCH_HEAD
+            refspec: ${{TCP_QA_REFS}}
+            url: https://gerrit.mcp.mirantis.com/mcp/tcp-qa.git
+      script-path: jobs/pipelines/run-test-scenarios.groovy
+
+    parameters:
+    - node:
+        name: NODE
+        allowed-slaves:
+          - 'openstack_slave_{deployment}'
+    - string:
+        default: '{deployment}'
+        description: 'Required: Fuel-devops environment name'
+        name: ENV_NAME
+        trim: 'false'
+    - string:
+        default: ''
+        description: 'Example: refs/changes/89/411189/36
+                       (for now - only one reference allowed)'
+        name: TCP_QA_REFS
+        trim: 'false'
+    - string:
+        default: 'openstack_slave_{deployment}'
+        description: 'Required: Name of the jenkins slave to create the environment
+                      To be set by the parent deployment job.'
+        name: PARENT_NODE_NAME
+        trim: 'false'
+    - string:
+        default: '/home/jenkins/workspace/workspace/{deployment}'
+        description: 'Required: Workspace on the jenkins slave to reuse for
+                      the job To be set by the parent deployment job'
+        name: PARENT_WORKSPACE
+        trim: 'false'
+    - string:
+        default: ''
+        description: 'Completed steps to install components on the environment.
+                      If tests require some additional components, it may be installed in
+                      appropriate fixtures, so set the PASSED_STEPS correctly for the
+                      testing environment.'
+        name: PASSED_STEPS
+        trim: 'false'
+    - string:
+        default: ''
+        description: 'Example: refs/changes/89/411189/36
+                       (for now - only one reference allowed)'
+        name: TCP_QA_REFS
+        trim: 'false'
+    - text:
+        default: '{run-test-opts}'
+        description: |-
+          Pytest option -k or -m, with expression to select necessary tests.
+          Additional pytest options are allowed.
+        name: RUN_TEST_OPTS
+        trim: 'false'
+    - bool:
+        default: true
+        name: REPORT_TO_TESTRAIL
+
+