Rewrite ceph pipelines for adding and removing nodes

Change-Id: I6d60b01c823d818c2dad9a9883ceaf60f4e2f785
Related-Prod: PROD-35582
diff --git a/ceph-add-osd-upmap.groovy b/ceph-add-osd-upmap.groovy
index 07fc662..0a98f5c 100644
--- a/ceph-add-osd-upmap.groovy
+++ b/ceph-add-osd-upmap.groovy
@@ -1,134 +1,22 @@
 /**
  *
- * Add Ceph OSD node to existing cluster using upmap mechanism
+ * Add Ceph node to existing cluster
  *
  * Requred parameters:
  *  SALT_MASTER_URL             URL of Salt master
  *  SALT_MASTER_CREDENTIALS     Credentials to the Salt API
- *  HOST                        OSD Host (minion id) to be added
+ *  HOST                        Host (minion id) to be added
+ *  CLUSTER_FLAGS               Expected flags on the cluster during job run
  *
  */
 
-common = new com.mirantis.mk.Common()
-salt = new com.mirantis.mk.Salt()
-def python = new com.mirantis.mk.Python()
-def ceph = new com.mirantis.mk.Ceph()
-orchestrate = new com.mirantis.mk.Orchestrate()
-pepperEnv = "pepperEnv"
-def flags = CLUSTER_FLAGS ? CLUSTER_FLAGS.tokenize(',') : []
-
-def runCephCommand(cmd) {
-    return salt.cmdRun(pepperEnv, "I@ceph:mon and I@ceph:common:keyring:admin", cmd, checkResponse = true, batch = null, output = false)
-}
-
-def getpgmap() {
-    return runCephCommand('ceph pg ls remapped --format=json')['return'][0].values()[0]
-}
-
-def generatemapping(master,pgmap,map) {
-    def pg_new
-    def pg_old
-    for (pg in pgmap.get('pg_stats',[])) {
-        pg_new = pg["up"].minus(pg["acting"])
-        pg_old = pg["acting"].minus(pg["up"])
-        for (i = 0; i < pg_new.size(); i++) {
-            def string = "ceph osd pg-upmap-items " + pg["pgid"].toString() + " " + pg_new[i] + " " + pg_old[i] + ";"
-            map.add(string)
-        }
-    }
-}
-
 timeout(time: 12, unit: 'HOURS') {
-    node("python") {
-        try {
-            // create connection to salt master
-            python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
-
-            stage ("verification of supported features") {
-                def checknode = salt.runSaltProcessStep(pepperEnv, HOST, 'test.ping')
-                if (checknode['return'][0].values().isEmpty()) {
-                    common.errorMsg("Host not found")
-                    throw new InterruptedException()
-                }
-                def cmn = salt.getFirstMinion(pepperEnv, "I@ceph:mon")
-                def features = salt.cmdRun(pepperEnv, cmn, "ceph features --format json", checkResponse=true, batch=null, output=false).values()[0]
-
-                features = new groovy.json.JsonSlurperClassic().parseText(features[0][cmn])
-                for ( group in features['client'] ) {
-                    if ( group['release'] != 'luminous' ) {
-                        throw new Exception("Some of installed clients does not support upmap. Update all clients to luminous or newer before using this pipeline")
-                    }
-                }
-            }
-
-            stage("enable luminous compat") {
-                runCephCommand('ceph osd set-require-min-compat-client luminous')['return'][0].values()[0]
-            }
-
-            stage("enable upmap balancer") {
-                runCephCommand('ceph balancer on')['return'][0].values()[0]
-                runCephCommand('ceph balancer mode upmap')['return'][0].values()[0]
-            }
-
-            stage("set norebalance") {
-                runCephCommand('ceph osd set norebalance')['return'][0].values()[0]
-            }
-
-            stage('Install infra') {
-                orchestrate.installFoundationInfraOnTarget(pepperEnv, HOST)
-            }
-
-            stage('Install Ceph OSD') {
-                salt.enforceState(pepperEnv, HOST, 'linux.storage')
-                orchestrate.installCephOsd(pepperEnv, HOST)
-            }
-
-            stage("Update/Install monitoring") {
-                def prometheusNodes = salt.getMinions(pepperEnv, 'I@prometheus:server')
-                if (!prometheusNodes.isEmpty()) {
-                    //Collect Grains
-                    salt.enforceState(pepperEnv, HOST, 'salt.minion.grains')
-                    salt.runSaltProcessStep(pepperEnv, HOST, 'saltutil.refresh_modules')
-                    salt.runSaltProcessStep(pepperEnv, HOST, 'mine.update')
-                    sleep(5)
-                    salt.enforceState(pepperEnv, HOST, ['fluentd', 'telegraf', 'prometheus'])
-                    salt.enforceState(pepperEnv, 'I@prometheus:server', 'prometheus')
-                } else {
-                    common.infoMsg('No Prometheus nodes in cluster. Nothing to do')
-                }
-            }
-
-            stage("Update host files") {
-                salt.enforceState(pepperEnv, '*', 'linux.network.host')
-            }
-
-
-            stage("update mappings") {
-                def pgmap
-                for (int x = 1; x <= 3; x++) {
-                    pgmap = getpgmap()
-                    if (pgmap == '') {
-                        return 1
-                    } else {
-                        def mapping = []
-                        pgmap = new groovy.json.JsonSlurperClassic().parseText(pgmap)
-                        generatemapping(pepperEnv, pgmap, mapping)
-                        mapping.each(this.&runCephCommand)
-                        sleep(30)
-                    }
-                }
-            }
-
-            stage("unset norebalance") {
-                runCephCommand('ceph osd unset norebalance')['return'][0].values()[0]
-            }
-
-            stage("wait for healthy cluster") {
-                ceph.waitForHealthy(pepperEnv, "I@ceph:mon and I@ceph:common:keyring:admin", flags)
-            }
-        }
-        finally {
-            runCephCommand('ceph osd unset norebalance')['return'][0].values()[0]
-        }
-    }
+    build job: 'ceph-add-node', parameters: [
+        [$class: 'BooleanParameterValue', name: 'OSD_ONLY', value: true],
+        [$class: 'BooleanParameterValue', name: 'USE_UPMAP', value: true],
+        [$class: 'StringParameterValue', name: 'HOST', value: HOST],
+        [$class: 'StringParameterValue', name: 'CLUSTER_FLAGS', value: CLUSTER_FLAGS],
+        [$class: 'StringParameterValue', name: 'SALT_MASTER_CREDENTIALS', value: SALT_MASTER_CREDENTIALS],
+        [$class: 'StringParameterValue', name: 'SALT_MASTER_URL', value: SALT_MASTER_URL]
+    ]
 }