Merge "Use DISTRIB_REVISION for formulas in test-cookiecutter-reclass"
diff --git a/aptly-promote-pipeline.groovy b/aptly-promote-pipeline.groovy
index 461abcf..0f51a90 100644
--- a/aptly-promote-pipeline.groovy
+++ b/aptly-promote-pipeline.groovy
@@ -22,9 +22,12 @@
 } catch (MissingPropertyException e) {
     storages = ['local']
 }
+
+def insufficientPermissions = false
+
 timeout(time: 12, unit: 'HOURS') {
   node() {
-    try{
+    try {
       stage("promote") {
         // promote is restricted to users in aptly-promote-users LDAP group
         if(jenkinsUtils.currentUserInGroups(["mcp-cicd-admins", "aptly-promote-users"])){
@@ -37,18 +40,26 @@
             }
           }
         }else{
+            insufficientPermissions = true
             throw new Exception(String.format("You don't have permissions to make aptly promote from source:%s to target:%s! Only CI/CD and QA team can perform aptly promote.", SOURCE, TARGET))
         }
       }
     } catch (Throwable e) {
        // If there was an error or exception thrown, the build failed
-       currentBuild.result = "FAILURE"
-       currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
+       if (insufficientPermissions) {
+         currentBuild.result = "ABORTED"
+         currentBuild.description = "Promote aborted due to insufficient permissions"
+       } else {
+         currentBuild.result = "FAILURE"
+         currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
+       }
        throw e
     } finally {
-       common.sendNotification(currentBuild.result,"",["slack"])
-       def _extra_descr = "${SOURCE}=>${TARGET}:\n${COMPONENTS} ${packages}"
-       currentBuild.description = currentBuild.description ? _extra_descr + " " + currentBuild.description : _extra_descr
+       if (!insufficientPermissions) {
+         common.sendNotification(currentBuild.result,"",["slack"])
+         def _extra_descr = "${SOURCE}=>${TARGET}:\n${COMPONENTS} ${packages}"
+         currentBuild.description = currentBuild.description ? _extra_descr + " " + currentBuild.description : _extra_descr
+       }
     }
   }
 }
diff --git a/build-mirror-image.groovy b/build-mirror-image.groovy
index 0700d60..4c42b3e 100644
--- a/build-mirror-image.groovy
+++ b/build-mirror-image.groovy
@@ -25,13 +25,13 @@
 def git = new com.mirantis.mk.Git()
 def date = new Date()
 def dateTime = date.format("ddMMyyyy-HHmmss")
-def openstackServer = ""
 def rcFile = ""
 def openstackEnv = ""
 def uploadImageStatus = ""
 def uploadMd5Status = ""
-ArrayList extra_vars = job_env.get('EXTRA_VARIABLES', '').readLines()
-def IMAGE_NAME = job_env.get('IMAGE_NAME', "packer-image") + "-" + dateTime
+def creds
+ArrayList extra_vars = EXTRA_VARIABLES.readLines()
+IMAGE_NAME = IMAGE_NAME + "-" + dateTime
 
 timeout(time: 8, unit: 'HOURS') {
   node("python&&disk-xl") {
@@ -40,7 +40,6 @@
       openstackEnv = "${workspace}/venv"
 
       stage("Prepare env") {
-        checkout scm
         if (!fileExists("${workspace}/tmp")) {
           sh "mkdir -p ${workspace}/tmp"
         }
@@ -64,27 +63,28 @@
 
         openstack.setupOpenstackVirtualenv(openstackEnv, OS_VERSION)
         git.checkoutGitRepository(PACKER_TEMPLATES_REPO_NAME, PACKER_TEMPLATES_REPO_URL, PACKER_TEMPLATES_BRANCH)
+        creds = common.getPasswordCredentials(OS_CREDENTIALS_ID)
       }
 
       stage("Build Instance") {
-        rcFile = openstack.createOpenstackEnv(OS_URL, OS_CREDENTIALS_ID, OS_PROJECT, "default", "", "default", "2", "")
         dir("${workspace}/${PACKER_TEMPLATES_REPO_NAME}/${BUILD_OS}/") {
           withEnv(extra_vars + ["PATH=${env.PATH}:${workspace}/bin",
                                 "PACKER_LOG_PATH=${workspace}/packer.log",
                                 "PACKER_LOG=1",
-                                "TMPDIR=${workspace}/tmp"]) {
+                                "TMPDIR=${workspace}/tmp",
+                                "IMAGE_NAME=${IMAGE_NAME}",
+                                "OS_USERNAME=${creds.username}",
+                                "OS_PASSWORD=${creds.password.toString()}"]) {
             if (PACKER_DEBUG.toBoolean()) {
               PACKER_ARGS = "${PACKER_ARGS} -debug"
             }
 
-            sh "source extra.vars ; packer build -only=${BUILD_ONLY} ${PACKER_ARGS} -parallel=false template.json"
+            sh "packer build -only=${BUILD_ONLY} ${PACKER_ARGS} -parallel=false template.json"
 
             def packerStatus = sh(script: "grep \"Some builds didn't complete successfully and had errors\" ${PACKER_LOG_PATH}", returnStatus: true)
             // grep returns 0 if find something
             if (packerStatus != 0) {
-              if (buildTypes.contains("openstack")) {
-                common.infoMsg("Openstack instance complete")
-              }
+              common.infoMsg("Openstack instance complete")
             } else {
               throw new Exception("Packer build failed")
             }
@@ -94,6 +94,8 @@
 
       stage("Publish image") {
         common.infoMsg("Saving image ${IMAGE_NAME}")
+        rcFile = openstack.createOpenstackEnv(workspace, OS_URL, OS_CREDENTIALS_ID, OS_PROJECT, "default", "", "default", "2", "")
+
         common.retry(3, 5) {
           openstack.runOpenstackCommand("openstack image save --file ${IMAGE_NAME}.qcow2 ${IMAGE_NAME}", rcFile, openstackEnv)
         }
@@ -122,25 +124,16 @@
       throw e
     } finally {
       if (CLEANUP_AFTER) {
-        stage("Cleanup") {
-          if (openstackServer != "") {
-            openstack.runOpenstackCommand("openstack server delete ${IMAGE_NAME}", rcFile, openstackEnv)
-            openstack.runOpenstackCommand("openstack image delete ${IMAGE_NAME}", rcFile, openstackEnv)
-          }
           dir(workspace) {
             sh "rm -rf ./*"
           }
-        }
-
       } else {
         common.infoMsg("Env has not been cleanup!")
         common.infoMsg("Packer private key:")
         dir("${workspace}/${PACKER_TEMPLATES_REPO_NAME}/${BUILD_OS}/") {
           sh "cat os_${BUILD_OS}.pem"
         }
-
       }
     }
-
   }
 }
diff --git a/ceph-add-node.groovy b/ceph-add-node.groovy
index f2af894..92d61e0 100644
--- a/ceph-add-node.groovy
+++ b/ceph-add-node.groovy
@@ -73,5 +73,8 @@
                 salt.enforceState(pepperEnv, 'I@ceph:radosgw', ['keepalived', 'haproxy', 'ceph.radosgw'], true)
             }
         }
+
+        salt.enforceState(pepperEnv, HOST, 'prometheus')
+        salt.enforceState(pepperEnv, 'I@prometheus', 'prometheus')
     }
 }
diff --git a/cloud-deploy-pipeline.groovy b/cloud-deploy-pipeline.groovy
index ad46e2f..a37a655 100644
--- a/cloud-deploy-pipeline.groovy
+++ b/cloud-deploy-pipeline.groovy
@@ -18,6 +18,7 @@
  *   STACK_CLEANUP_JOB          Name of job for deleting stack
  *
  *   STACK_COMPUTE_COUNT        Number of compute nodes to launch
+ *   STACK_CLUSTER_NAME         The name of cluster model to use
  *   STATIC_MGMT_NETWORK        Check if model contains static IP address definitions for all nodes
  *
  *   AWS_STACK_REGION           CloudFormation AWS region
@@ -194,6 +195,12 @@
                             envParams.put('cfg_extra_formulas', EXTRA_FORMULAS)
                         }
 
+                        // add cluster name if specified
+                        if (common.validInputParam('STACK_CLUSTER_NAME')) {
+                            common.infoMsg("Setting cluster_name to ${STACK_CLUSTER_NAME}")
+                            envParams.put('cluster_name', STACK_CLUSTER_NAME)
+                        }
+
                         openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
                     }
 
diff --git a/openstack-compute-install.groovy b/openstack-compute-install.groovy
index 7d6cf6d..7b9054a 100644
--- a/openstack-compute-install.groovy
+++ b/openstack-compute-install.groovy
@@ -98,6 +98,11 @@
                 }
             }
 
+        stage("Install monitoring") {
+            salt.enforceState(pepperEnv, targetLiveAll, 'prometheus')
+            salt.enforceState(pepperEnv, 'I@prometheus', 'prometheus')
+        }
+
         } catch (Throwable e) {
             // If there was an error or exception thrown, the build failed
             currentBuild.result = "FAILURE"
diff --git a/test-customers-salt-models.groovy b/test-customers-salt-models.groovy
new file mode 100644
index 0000000..3c0ccaf
--- /dev/null
+++ b/test-customers-salt-models.groovy
@@ -0,0 +1,47 @@
+/**
+ * Parent pipeline for running customer's models
+ *
+ * Params:
+ * CUSTOMERS - Comma-separated list of customer's names
+ */
+def common = new com.mirantis.mk.Common()
+
+timeout(time: 12, unit: 'HOURS') {
+  node() {
+    try {
+      stage("Run customer's salt models tests") {
+        if(common.validInputParam("CUSTOMERS")){
+           def customerList = CUSTOMERS.tokenize(",").collect{it.trim()}
+           for(int i=0; i<customerList.size(); i++){
+             def modelName = customerList[i]
+             common.infoMsg("Test of ${modelName} starts")
+             build job: "test-salt-model-customer-${modelName}"
+            // build job: "test-salt-model-customer-${customerList[i]}", parameters: [
+            //   [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: defaultGitUrl],
+            //   [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: defaultGitRef],
+            //   [$class: 'StringParameterValue', name: 'CLUSTER_NAME', value: modelName],
+            //   [$class: 'StringParameterValue', name: 'NODE_TARGET', value: testTarget],
+            //   [$class: 'StringParameterValue', name: 'FORMULAS_SOURCE', value: formulasSource]
+            //   [$class: 'StringParameterValue', name: 'EXTRA_FORMULAS', value: EXTRA_FORMULAS],
+            //   [$class: 'StringParameterValue', name: 'FORMULAS_REVISION', value: FORMULAS_REVISION],
+            //   [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: CREDENTIALS_ID],
+            //   [$class: 'StringParameterValue', name: 'SYSTEM_GIT_URL', value: SYSTEM_GIT_URL],
+            //   [$class: 'StringParameterValue', name: 'MAX_CPU_PER_JOB', value: MAX_CPU_PER_JOB],
+            //   [$class: 'StringParameterValue', name: 'SYSTEM_GIT_REF', value: SYSTEM_GIT_REF],
+            //   [$class: 'BooleanParameterValue', name: 'LEGACY_TEST_MODE', value: LEGACY_TEST_MODE.toBoolean()],
+            //   [$class: 'BooleanParameterValue', name: 'RECLASS_IGNORE_CLASS_NOTFOUND', value: RECLASS_IGNORE_CLASS_NOTFOUND.toBoolean()]
+            // ]
+           }
+        }
+      }
+    } catch (Throwable e) {
+       // If there was an error or exception thrown, the build failed
+       currentBuild.result = "FAILURE"
+       currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
+       throw e
+    } finally {
+       common.sendNotification(currentBuild.result, "", ["slack"])
+    }
+  }
+}
+