Add pipeline to deploy random released MCP by schedule
Set 2019.2.7 versions to deploy in the released-* jobs

Change-Id: Id87d58ebedadd8baa62bb5e23a396b7f1106d55f
Related-Prod:#PROD-34546(PROD:34546)
diff --git a/jobs/pipelines/rotation-released-deployment.groovy b/jobs/pipelines/rotation-released-deployment.groovy
new file mode 100644
index 0000000..3dc1fdc
--- /dev/null
+++ b/jobs/pipelines/rotation-released-deployment.groovy
@@ -0,0 +1,81 @@
+/**
+ *
+ * Deploy the product cluster using Jenkins master on CICD cluster
+ *
+ * Expected parameters:
+ *   STACKS                        List of deployments from 'all physical' view in the Jenkins
+                                   They should be separated by newline
+ *   PARENT_NODE_NAME
+ *   OS_AUTH_URL                   OpenStack keystone catalog URL
+ *   OS_PROJECT_NAME               OpenStack project (tenant) name
+ *   OS_CREDENTIALS                OpenStack username and password credentials ID in Jenkins
+
+ *   TCP_QA_REFS                   Reference to the tcp-qa change on Gerrit, like refs/changes/46/418546/41
+ */
+@Library('tcp-qa')_
+
+common = new com.mirantis.mk.Common()
+shared = new com.mirantis.system_qa.SharedPipeline()
+import jenkins.model.*
+
+def stacks = env.STACKS.readLines()
+
+def get_last_build_time(job_name) {
+  def job = Hudson.instance.getJob(job_name)
+  def last_build = Jenkins.instance.getItemByFullName(job.fullName).getLastBuild()
+  if (last_build == null) {
+  	return null
+  }
+  def upStreamBuild = Jenkins.getInstance().getItemByFullName(job.fullName).getBuildByNumber(last_build.getNumber())
+  return upStreamBuild.getTime()
+}
+
+@NonCPS
+def oldest_job(map) {
+  return map.sort({a, b -> a.value <=> b.value})*.key[0]
+}
+
+// ============================================================================
+timeout(time: 15, unit: 'HOURS') {
+  node (env.PARENT_NODE_NAME) {
+    stage("Remove extra stacks") {
+        withCredentials([
+           [$class          : 'UsernamePasswordMultiBinding',
+           credentialsId   : env.OS_CREDENTIALS,
+           passwordVariable: 'OS_PASSWORD',
+           usernameVariable: 'OS_USERNAME']
+        ]) {
+            env.OS_IDENTITY_API_VERSION = 3
+            for (stack_name in stacks) {
+              shared.run_cmd("""
+                # export OS_IDENTITY_API_VERSION=3
+                # export OS_AUTH_URL=${OS_AUTH_URL}
+                # export OS_USERNAME=${OS_USERNAME}
+                # export OS_PASSWORD=${OS_PASSWORD}
+                # export OS_PROJECT_NAME=${OS_PROJECT_NAME}
+                openstack --insecure stack delete -y ${stack_name} || true
+                timeout 20m /bin/bash -c "while openstack --insecure stack show ${stack_name} -f value -c stack_status; do sleep 10; done";
+              """)
+            }
+        }
+    }
+
+    stage("Start deployment") {
+      def jobs_map = [:]
+      for (stack_name in stacks) {
+        jobs_map.put ("${stack_name}", get_last_build_time(stack_name))
+      }
+      stack_to_deploy = oldest_job(jobs_map)
+
+      println "Build ${stack_to_deploy}"
+      currentBuild.description = "${stack_to_deploy}"
+      // Trigger job
+      def deploy = build job: "${stack_to_deploy}",
+      parameters: [
+            string(name: 'PARENT_NODE_NAME', value: env.PARENT_NODE_NAME),
+            string(name: 'OS_CREDENTIALS', value: env.OS_CREDENTIALS),
+            string(name: 'TCP_QA_REFS', value: env.TCP_QA_REFS)
+        ]
+    }
+  }
+}
\ No newline at end of file
diff --git a/jobs/templates/deploy-released.yml b/jobs/templates/deploy-released.yml
new file mode 100644
index 0000000..959962a
--- /dev/null
+++ b/jobs/templates/deploy-released.yml
@@ -0,0 +1,54 @@
+- job-template:
+    project-type: pipeline
+    description: '{job-description}'
+    concurrent: flase
+    disabled: false
+    sandbox: true
+    triggers:
+    - timed: H(20-30) 1 * * 1-5
+    name: deploy_bm
+    parameters:
+    - string:
+        default: sre-qa-ci-eu
+        description: ''
+        name: OS_CREDENTIALS
+        trim: 'false'
+    - text:
+        default: |-
+          released-heat-cicd-pike-contrail41-sl
+          released-heat-cicd-pike-dvr-sl
+          released-heat-cicd-queens-dvr-sl
+        description: List of stacks for deployment. Separated by newline
+        name: STACKS
+        trim: 'false'
+    - string:
+        default: ''
+        description: ''
+        name: TCP_QA_REFS
+        trim: 'false'
+    - string:
+        default: sre-team-infra
+        description: ''
+        name: PARENT_NODE_NAME
+        trim: 'false'
+    - string:
+        default: https://ic-eu.ssl.mirantis.net:5000/v3
+        description: ''
+        name: OS_AUTH_URL
+        trim: 'false'
+    - string:
+        default: sre-team
+        description: ''
+        name: OS_PROJECT_NAME
+        trim: 'false'
+    pipeline-scm:
+      lightweight-checkout: false
+      scm:
+      - git:
+          branches:
+          - FETCH_HEAD
+          refspec: '${{TCP_QA_REFS}}'
+          url: https://gerrit.mcp.mirantis.com/mcp/tcp-qa
+          clean:
+            before: true
+      script-path: jobs/pipelines/rotation-released-deployment.groovy
diff --git a/jobs/templates/released-heat-cicd-pike-contrail41-sl.yml b/jobs/templates/released-heat-cicd-pike-contrail41-sl.yml
index 22ebc40..7e03a30 100644
--- a/jobs/templates/released-heat-cicd-pike-contrail41-sl.yml
+++ b/jobs/templates/released-heat-cicd-pike-contrail41-sl.yml
@@ -33,7 +33,7 @@
         name: PLATFORM_STACK_INSTALL_TIMEOUT
         trim: 'false'
     - string:
-        default: 2019.2.0
+        default: 2019.2.7
         description: ''
         name: MCP_VERSION
         trim: 'false'
@@ -70,32 +70,50 @@
         name: TCP_QA_REFS
         trim: 'false'
     - string:
-        default: refs/tags/2019.2.6
+        default: refs/tags/2019.2.7
         description: reference to patchset in pipeline-library
         name: PIPELINE_LIBRARY_REF
         trim: 'false'
     - string:
-        default: refs/tags/2019.2.6
+        default: refs/tags/2019.2.7
         description: reference to patchset in mk-pipelines
         name: MK_PIPELINES_REF
         trim: 'false'
     - string:
-        default: 380f83f44ecca210825f3d3070a9c202e00adc58
+        default: refs/tags/2019.2.7
         description: Can be 'master' or 'proposed'. If empty, then takes ${{MCP_VERSION}}
           value
         name: COOKIECUTTER_TEMPLATE_COMMIT
         trim: 'false'
     - string:
-        default: c2458cb04793900195ee68a1e80edaf5c2cff7dc
+        default: refs/tags/2019.2.7
         description: Can be 'master' or 'proposed'. If empty, then takes ${{MCP_VERSION}}
           value
         name: SALT_MODELS_SYSTEM_COMMIT
         trim: 'false'
-    - string:
-        default: -m "run_cvp_func_sanity|run_tempest|run_stacklight"
+    - text:
+        default: |-
+          --keep-duplicates --maxfail=2
+            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
+
+            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
+
         description: |-
           Pytest option -k or -m, with expression to select necessary tests.
           Additional pytest options are allowed.
+          Procedure according to https://docs.mirantis.com/mcp/q4-18/mcp-release-notes/mu/mu-7/mu-7-apply-updates.html
         name: RUN_TEST_OPTS
         trim: 'false'
     - bool:
@@ -173,18 +191,18 @@
         name: LAB_PARAM_DEFAULTS
         trim: 'false'
     - string:
-        default: refs/tags/2019.2.6
+        default: refs/tags/2019.2.7
         description: ''
         name: JENKINS_PIPELINE_BRANCH
         trim: 'false'
     - string:
-        default: refs/tags/2019.2.6
+        default: refs/tags/2019.2.7
         description: ''
         name: MCP_COMMON_SCRIPTS_REFS
         trim: 'false'
     - string:
-        default: 2019.2.0
-        description: ''
+        default: 2019.2.7
+        description: 'for formula repo http://mirror.mirantis.com/update/${UPDATE_VERSION}/salt-formulas/xenial'
         name: UPDATE_VERSION
         trim: 'false'
     - string:
diff --git a/jobs/templates/released-heat-cicd-pike-dvr-sl.yml b/jobs/templates/released-heat-cicd-pike-dvr-sl.yml
index b297eda..c82f7da 100644
--- a/jobs/templates/released-heat-cicd-pike-dvr-sl.yml
+++ b/jobs/templates/released-heat-cicd-pike-dvr-sl.yml
@@ -33,7 +33,7 @@
         name: PLATFORM_STACK_INSTALL_TIMEOUT
         trim: 'false'
     - string:
-        default: 2019.2.0
+        default: 2019.2.7
         description: ''
         name: MCP_VERSION
         trim: 'false'
@@ -70,32 +70,49 @@
         name: TCP_QA_REFS
         trim: 'false'
     - string:
-        default: refs/tags/2019.2.6
+        default: refs/tags/2019.2.7
         description: reference to patchset in pipeline-library
         name: PIPELINE_LIBRARY_REF
         trim: 'false'
     - string:
-        default: refs/tags/2019.2.6
+        default: refs/tags/2019.2.7
         description: reference to patchset in mk-pipelines
         name: MK_PIPELINES_REF
         trim: 'false'
     - string:
-        default: 380f83f44ecca210825f3d3070a9c202e00adc58
+        default: refs/tags/2019.2.7
         description: Can be 'master' or 'proposed'. If empty, then takes ${{MCP_VERSION}}
           value
         name: COOKIECUTTER_TEMPLATE_COMMIT
         trim: 'false'
     - string:
-        default: c2458cb04793900195ee68a1e80edaf5c2cff7dc
+        default: refs/tags/2019.2.7
         description: Can be 'master' or 'proposed'. If empty, then takes ${{MCP_VERSION}}
           value
         name: SALT_MODELS_SYSTEM_COMMIT
         trim: 'false'
-    - string:
-        default: -m "run_cvp_func_sanity|run_tempest|run_stacklight"
+    - text:
+        default: |-
+          --keep-duplicates --maxfail=2
+            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
+
+            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
+
         description: |-
           Pytest option -k or -m, with expression to select necessary tests.
           Additional pytest options are allowed.
+          Procedure according to https://docs.mirantis.com/mcp/q4-18/mcp-release-notes/mu/mu-7/mu-7-apply-updates.html
         name: RUN_TEST_OPTS
         trim: 'false'
     - bool:
@@ -173,7 +190,7 @@
         name: LAB_PARAM_DEFAULTS
         trim: 'false'
     - string:
-        default: refs/tags/2019.2.6
+        default: refs/tags/2019.2.7
         description: ''
         name: JENKINS_PIPELINE_BRANCH
         trim: 'false'
@@ -183,12 +200,12 @@
         name: TEMPEST_PATTERN
         trim: 'false'
     - string:
-        default: refs/tags/2019.2.6
+        default: refs/tags/2019.2.7
         description: ''
         name: MCP_COMMON_SCRIPTS_REFS
         trim: 'false'
     - string:
-        default: 2019.2.0
+        default: 2019.2.7
         description: ''
         name: UPDATE_VERSION
         trim: 'false'
diff --git a/jobs/templates/released-heat-cicd-queens-dvr-sl.yml b/jobs/templates/released-heat-cicd-queens-dvr-sl.yml
index 01cf37f..55d8142 100644
--- a/jobs/templates/released-heat-cicd-queens-dvr-sl.yml
+++ b/jobs/templates/released-heat-cicd-queens-dvr-sl.yml
@@ -33,7 +33,7 @@
         name: PLATFORM_STACK_INSTALL_TIMEOUT
         trim: 'false'
     - string:
-        default: 2019.2.0
+        default: 2019.2.7
         description: ''
         name: MCP_VERSION
         trim: 'false'
@@ -70,32 +70,49 @@
         name: TCP_QA_REFS
         trim: 'false'
     - string:
-        default: refs/tags/2019.2.6
+        default: refs/tags/2019.2.7
         description: reference to patchset in pipeline-library
         name: PIPELINE_LIBRARY_REF
         trim: 'false'
     - string:
-        default: refs/tags/2019.2.6
+        default: refs/tags/2019.2.7
         description: reference to patchset in mk-pipelines
         name: MK_PIPELINES_REF
         trim: 'false'
     - string:
-        default: 380f83f44ecca210825f3d3070a9c202e00adc58
+        default: refs/tags/2019.2.7
         description: Can be 'master' or 'proposed'. If empty, then takes ${{MCP_VERSION}}
           value
         name: COOKIECUTTER_TEMPLATE_COMMIT
         trim: 'false'
     - string:
-        default: c2458cb04793900195ee68a1e80edaf5c2cff7dc
+        default: refs/tags/2019.2.7
         description: Can be 'master' or 'proposed'. If empty, then takes ${{MCP_VERSION}}
           value
         name: SALT_MODELS_SYSTEM_COMMIT
         trim: 'false'
     - text:
-        default: -m "run_cvp_func_sanity|run_tempest|run_stacklight"
+        default: |-
+          --keep-duplicates --maxfail=2
+            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
+
+            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
+
         description: |-
           Pytest option -k or -m, with expression to select necessary tests.
           Additional pytest options are allowed.
+          Procedure according to https://docs.mirantis.com/mcp/q4-18/mcp-release-notes/mu/mu-7/mu-7-apply-updates.html
         name: RUN_TEST_OPTS
         trim: 'false'
     - bool:
@@ -173,7 +190,7 @@
         name: LAB_PARAM_DEFAULTS
         trim: 'false'
     - string:
-        default: refs/tags/2019.2.6
+        default: refs/tags/2019.2.7
         description: ''
         name: JENKINS_PIPELINE_BRANCH
         trim: 'false'
@@ -183,12 +200,12 @@
         name: TEMPEST_PATTERN
         trim: 'false'
     - string:
-        default: refs/tags/2019.2.6
+        default: refs/tags/2019.2.7
         description: ''
         name: MCP_COMMON_SCRIPTS_REFS
         trim: 'false'
     - string:
-        default: 2019.2.0
+        default: 2019.2.7
         description: ''
         name: UPDATE_VERSION
         trim: 'false'