Merge "Extend description for workflow jobs"
diff --git a/src/com/mirantis/mcp/Validate.groovy b/src/com/mirantis/mcp/Validate.groovy
index 9c7a5b6..308ff14 100644
--- a/src/com/mirantis/mcp/Validate.groovy
+++ b/src/com/mirantis/mcp/Validate.groovy
@@ -57,7 +57,6 @@
     default_mounts = ["/etc/ssl/certs/": "/etc/ssl/certs/",
                       "/srv/salt/pki/${cluster_name}/": "/etc/certs",
                       "/root/test/": "/root/tempest/",
-                      "/tmp/": "/tmp/",
                       "/etc/hosts": "/etc/hosts"]
     params.mounts = default_mounts + params.mounts
     if ( salt.cmdRun(params.master, params.target, "docker ps -f name=^${params.name}\$ -q", false, null, false)['return'][0].values()[0] ) {
diff --git a/src/com/mirantis/mk/KaasUtils.groovy b/src/com/mirantis/mk/KaasUtils.groovy
index cc58774..e558131 100644
--- a/src/com/mirantis/mk/KaasUtils.groovy
+++ b/src/com/mirantis/mk/KaasUtils.groovy
@@ -16,24 +16,25 @@
  * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and combine test-suite -> trigger deployment jobs from kaas/core
  * manage test-suite through Jenkins Job Parameters
  *
- * @return (map)[*                    deployChildEnabled: (bool) True if need to deploy child cluster during demo-run
- *                    runUie2eEnabled: (bool) True if need to run ui-e2e cluster during demo-run
+ * @return      (map)[
+ *                    deployChildEnabled: (bool) True if need to deploy child cluster during demo-run
+ *                    runUie2eEnabled:    (bool) True if need to run ui-e2e cluster during demo-run
  *                   ]
  */
 def checkDeploymentTestSuite() {
     def common = new com.mirantis.mk.Common()
 
     // Available triggers and its sane defaults
-    def deployChild = (env.DEPLOY_CHILD_CLUSTER != null) ? env.DEPLOY_CHILD_CLUSTER.toBoolean() : false
-    def upgradeChild = (env.UPGRADE_CHILD_CLUSTER != null) ? env.UPGRADE_CHILD_CLUSTER.toBoolean() : false
-    def upgradeMgmt = (env.UPGRADE_MGMT_CLUSTER != null) ? env.UPGRADE_MGMT_CLUSTER.toBoolean() : false
-    def runUie2e = (env.RUN_UI_E2E != null) ? env.RUN_UI_E2E.toBoolean() : false
-    def runMgmtConformance = (env.RUN_MGMT_CFM != null) ? env.RUN_MGMT_CFM.toBoolean() : false
-    def runChildConformance = (env.RUN_CHILD_CFM != null) ? env.RUN_CHILD_CFM.toBoolean() : false
-    def fetchServiceBinaries = (env.FETCH_BINARIES_FROM_UPSTREAM != null) ? env.FETCH_BINARIES_FROM_UPSTREAM.toBoolean() : false
-    def awsOnDemandDemo = (env.RUN_AWS_ON_DEMAND_DEMO != null) ? env.RUN_AWS_ON_DEMAND_DEMO.toBoolean() : false
+    def deployChild = env.DEPLOY_CHILD_CLUSTER ? env.DEPLOY_CHILD_CLUSTER.toBoolean() : false
+    def upgradeChild = env.UPGRADE_CHILD_CLUSTER ? env.UPGRADE_CHILD_CLUSTER.toBoolean() : false
+    def upgradeMgmt = env.UPGRADE_MGMT_CLUSTER ? env.UPGRADE_MGMT_CLUSTER.toBoolean() : false
+    def runUie2e = env.RUN_UI_E2E ? env.RUN_UI_E2E.toBoolean() : false
+    def runMgmtConformance = env.RUN_MGMT_CFM ? env.RUN_MGMT_CFM.toBoolean() : false
+    def runChildConformance = env.RUN_CHILD_CFM ? env.RUN_CHILD_CFM.toBoolean() : false
+    def fetchServiceBinaries = env.FETCH_BINARIES_FROM_UPSTREAM ? env.FETCH_BINARIES_FROM_UPSTREAM.toBoolean() : false
+    def awsOnDemandDemo = env.ALLOW_AWS_ON_DEMAND ? env.ALLOW_AWS_ON_DEMAND.toBoolean() : false
 
-    def commitMsg = (env.GERRIT_CHANGE_COMMIT_MESSAGE != null) ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
+    def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
     if (commitMsg ==~ /(?s).*\[child-deploy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-deploy.*/ || upgradeChild || runChildConformance) {
         deployChild = true
     }
@@ -111,10 +112,10 @@
     def common = new com.mirantis.mk.Common()
 
     // Available triggers and its sane defaults
-    def siTestsRefspec = (env.SI_TESTS_REFSPEC != null) ? env.SI_TESTS_REFSPEC : 'master'
-    def siPipelinesRefspec = (env.SI_PIPELINES_REFSPEC != null) ? env.SI_PIPELINES_REFSPEC : 'master'
-    def siTestsDockerImage = (env.SI_TESTS_DOCKER_IMAGE != null) ? env.SI_TESTS_DOCKER_IMAGE : 'docker-dev-kaas-local.docker.mirantis.net/mirantis/kaas/si-test:master'
-    def commitMsg = (env.GERRIT_CHANGE_COMMIT_MESSAGE != null) ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
+    def siTestsRefspec = env.SI_TESTS_REFSPEC ?: 'master'
+    def siPipelinesRefspec = env.SI_PIPELINES_REFSPEC ?: 'master'
+    def siTestsDockerImage = env.SI_TESTS_DOCKER_IMAGE ?: 'docker-dev-kaas-local.docker.mirantis.net/mirantis/kaas/si-test:master'
+    def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
 
     def siTestMatches = (commitMsg =~ /(\[si-tests-ref\s*refs\/changes\/.*?\])/)
     def siPipelinesMatches = (commitMsg =~ /(\[si-pipelines-ref\s*refs\/changes\/.*?\])/)
@@ -135,3 +136,120 @@
         Keywords: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/.git-message-template#59""")
     return [siTests: siTestsRefspec, siPipelines: siPipelinesRefspec, siTestsDockerImage: siTestsDockerImage]
 }
+
+/**
+ * Determine if custom kaas core/pipelines refspec forwarded from gerrit change request
+
+ * Keyword list: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/.git-message-template#59
+ * Used for components team to test component changes w/ custom Core refspecs using kaas/core deployment jobs
+ * Example scheme:
+ * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
+ * manage refspecs through Jenkins Job Parameters
+ *
+ * @return          (map)[     core: (string) final refspec for kaas/core
+ *                             corePipelines: (string) final refspec for pipelines in kaas/core
+ *                       ]
+ */
+def checkCustomCoreRefspec() {
+    def common = new com.mirantis.mk.Common()
+
+    // Available triggers and its sane defaults
+    def coreRefspec = env.KAAS_CORE_REFSPEC ?: 'master'
+    // by default using value of GERRIT_REFSPEC parameter in *kaas/core jobs*
+    def corePipelinesRefspec = env.KAAS_PIPELINE_REFSPEC ?: '\$GERRIT_REFSPEC'
+    def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
+
+    def coreMatches = (commitMsg =~ /(\[core-ref\s*refs\/changes\/.*?\])/)
+    def corePipelinesMatches = (commitMsg =~ /(\[core-pipelines-ref\s*refs\/changes\/.*?\])/)
+
+    if (coreMatches.size() > 0) {
+        coreRefspec = coreMatches[0][0].split('core-ref')[1].replaceAll('[\\[\\]]', '').trim()
+    }
+    if (corePipelinesMatches.size() > 0) {
+        corePipelinesRefspec = corePipelinesMatches[0][0].split('core-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
+    }
+
+    common.infoMsg("""
+        kaas/core will be fetched from: ${coreRefspec}
+        kaas/core pipelines will be fetched from: ${corePipelinesRefspec}
+        Keywords: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/.git-message-template#59""")
+    return [core: coreRefspec, corePipelines: corePipelinesRefspec]
+}
+
+
+/**
+ * Trigger KaaS demo jobs based on AWS/OS providers with customized test suite, parsed from external sources (gerrit commit/jj vars)
+ * Keyword list: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/.git-message-template
+ * Used for components team to test component changes w/ customized SI tests/refspecs using kaas/core deployment jobs
+ *
+ * @param:        (string) component name [iam, lcm, stacklight]
+ * @param:        (string) Patch for kaas/cluster releases in json format
+ */
+def triggerPatchedComponentDemo(component, patchSpec) {
+    def common = new com.mirantis.mk.Common()
+    // Determine if custom trigger keywords forwarded from gerrit
+    def triggers = checkDeploymentTestSuite()
+    // Determine SI refspecs
+    def siRefspec = checkCustomSIRefspec()
+    // Determine Core refspecs
+    def coreRefspec = checkCustomCoreRefspec()
+
+    def jobs = [:]
+    // TODO manage SI_TESTS_FEATURE_FLAGS through checkCustomSIRefspec()
+    //string(name: "SI_TESTS_FEATURE_FLAGS", value: env.SI_TESTS_FEATURE_FLAGS),
+    def parameters = [
+        string(name: 'GERRIT_REFSPEC', value: coreRefspec.core),
+        string(name: 'KAAS_PIPELINE_REFSPEC', value: coreRefspec.corePipelines),
+        string(name: 'SI_TESTS_REFSPEC', value: siRefspec.siTests),
+        string(name: 'SI_PIPELINES_REFSPEC', value: siRefspec.siPipelines),
+        string(name: 'CUSTOM_RELEASE_PATCH_SPEC', value: patchSpec),
+        booleanParam(name: 'UPGRADE_MGMT', value: triggers.upgradeMgmtEnabled),
+        booleanParam(name: 'RUN_UI_E2E', value: triggers.runUie2eEnabled),
+        booleanParam(name: 'RUN_MGMT_CONFORMANCE', value: triggers.runMgmtConformanceEnabled),
+        booleanParam(name: 'DEPLOY_CHILD', value: triggers.deployChildEnabled),
+        booleanParam(name: 'UPGRADE_CHILD', value: triggers.upgradeChildEnabled),
+        booleanParam(name: 'RUN_CHILD_CONFORMANCE', value: triggers.runChildConformanceEnabled),
+        booleanParam(name: 'ALLOW_AWS_ON_DEMAND', value: triggers.awsOnDemandDemoEnabled),
+    ]
+
+    def jobResults = []
+    jobs["kaas-core-openstack-patched-${component}"] = {
+        try {
+            common.infoMsg('Deploy: patched KaaS demo with Openstack provider')
+            def job_info = build job: "kaas-testing-core-openstack-workflow-${component}", parameters: parameters, wait: true
+            def build_description = job_info.getDescription()
+            if (build_description) {
+                currentBuild.description += build_description
+            }
+        } finally {
+            def build_result = job_info.getResult()
+            common.infoMsg("Patched KaaS demo with Openstack provider finished with status: ${build_result}")
+            jobResults.add(build_result)
+        }
+    }
+    if (triggers.awsOnDemandDemoEnabled) {
+        jobs["kaas-core-aws-patched-${component}"] = {
+            try {
+                common.infoMsg('Deploy: patched KaaS demo with AWS provider')
+                def job_info = build job: "kaas-testing-core-aws-workflow-${component}", parameters: parameters, wait: true
+                def build_description = job_info.getDescription()
+                if (build_description) {
+                    currentBuild.description += build_description
+                }
+            } finally {
+                def build_result = job_info.getResult()
+                common.infoMsg("Patched KaaS demo with AWS provider finished with status: ${build_result}")
+                jobResults.add(build_result)
+            }
+        }
+    }
+
+    common.infoMsg('Trigger KaaS demo deployments according to defined provider set')
+    // Limit build concurency workaround examples: https://issues.jenkins-ci.org/browse/JENKINS-44085
+    parallel jobs
+
+    if (jobResults.contains('FAILURE')) {
+        common.infoMsg('One of parallel downstream jobs is failed, mark executor job as failed')
+        currentBuild.result = 'FAILURE'
+    }
+}