[WIP] add compute pipeline
Change-Id: Ic1eab1c8e0c043dcbcd8e435abc62d8b205c0d5e
diff --git a/openstack-compute-install.groovy b/openstack-compute-install.groovy
new file mode 100644
index 0000000..91c0f79
--- /dev/null
+++ b/openstack-compute-install.groovy
@@ -0,0 +1,74 @@
+/**
+ * Update packages on given nodes
+ *
+ * Expected parameters:
+ * SALT_MASTER_CREDENTIALS Credentials to the Salt API.
+ * SALT_MASTER_URL Full Salt API address [https://10.10.10.1:8000].
+ * TARGET_SERVERS Salt compound target to match nodes to be updated [*, G@osfamily:debian].
+ *
+**/
+
+def common = new com.mirantis.mk.Common()
+def salt = new com.mirantis.mk.Salt()
+
+def saltMaster
+def targetAll = ['expression': TARGET_SERVERS, 'type': 'compound']
+def minions
+def result
+def command
+def commandKwargs
+
+
+node() {
+ try {
+
+ stage('Connect to Salt master') {
+ saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
+ }
+
+ stage('List target servers') {
+ minions = salt.getMinions(saltMaster, targetAll)
+
+ if (minions.isEmpty()) {
+ throw new Exception("No minion was targeted")
+ }
+
+ targetLiveAll = minions.join(' or ')
+ common.infoMsg("Found nodes: ${targetLiveAll}")
+ common.infoMsg("Selected nodes: ${targetLiveAll}")
+ }
+
+ stage("Setup network for compute") {
+ common.infoMsg("Now all network configuration will be enforced, which caused reboot of nodes: ${targetLiveAll}")
+ try {
+ salt.cmdRun(saltMaster, targetAll, 'salt-call state.sls linux.system.user,openssh,linux.network;reboot')
+ } catch(e) {
+ common.infoMsg("no respond from nodes due reboot")
+ }
+ common.infoMsg("Now pipeline is waiting until node reconnect to salt master")
+ timeout(800) {
+ retry(666) {
+ try {
+ salt.runSaltCommand(saltMaster, 'local', targetAll, 'test.ping', null, null, kwargs)
+ } catch(e) {
+ common.infoMsg("Still waiting for node to come up")
+ sleep(10)
+ }
+ }
+ }
+ }
+
+ stage("Deploy Compute") {
+ common.infoMsg("Lets run rest of the states to finish deployment")
+ salt.enforceState(saltMaster, targetAll, 'linux,openssh,ntp,salt', true)
+ retry(2) {
+ salt.runSaltCommand(saltMaster, 'local', targetAll, 'state.apply', null, null, kwargs)
+ }
+ }
+
+ } catch (Throwable e) {
+ // If there was an error or exception thrown, the build failed
+ currentBuild.result = "FAILURE"
+ throw e
+ }
+}