Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Update packages on given nodes |
| 3 | * |
| 4 | * Expected parameters: |
| 5 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API. |
| 6 | * SALT_MASTER_URL Full Salt API address [https://10.10.10.1:8000]. |
| 7 | * TARGET_SERVERS Salt compound target to match nodes to be updated [*, G@osfamily:debian]. |
| 8 | * |
| 9 | **/ |
| 10 | |
| 11 | def common = new com.mirantis.mk.Common() |
| 12 | def salt = new com.mirantis.mk.Salt() |
| 13 | |
| 14 | def saltMaster |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 15 | def minions |
| 16 | def result |
| 17 | def command |
| 18 | def commandKwargs |
| 19 | |
| 20 | |
| 21 | node() { |
| 22 | try { |
| 23 | |
| 24 | stage('Connect to Salt master') { |
| 25 | saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 26 | } |
| 27 | |
| 28 | stage('List target servers') { |
Tomáš Kukrál | c86c8b4 | 2017-07-13 10:26:51 +0200 | [diff] [blame] | 29 | minions = salt.getMinions(saltMaster, TARGET_SERVERS) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 30 | |
| 31 | if (minions.isEmpty()) { |
| 32 | throw new Exception("No minion was targeted") |
| 33 | } |
| 34 | |
| 35 | targetLiveAll = minions.join(' or ') |
| 36 | common.infoMsg("Found nodes: ${targetLiveAll}") |
| 37 | common.infoMsg("Selected nodes: ${targetLiveAll}") |
| 38 | } |
| 39 | |
| 40 | stage("Setup network for compute") { |
| 41 | common.infoMsg("Now all network configuration will be enforced, which caused reboot of nodes: ${targetLiveAll}") |
| 42 | try { |
Jakub Pavlik | e7a399a | 2017-06-12 21:45:44 +0200 | [diff] [blame] | 43 | salt.cmdRun(saltMaster, targetLiveAll, 'salt-call state.sls linux.system.user,openssh,linux.network;reboot') |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 44 | } catch(e) { |
| 45 | common.infoMsg("no respond from nodes due reboot") |
| 46 | } |
| 47 | common.infoMsg("Now pipeline is waiting until node reconnect to salt master") |
| 48 | timeout(800) { |
| 49 | retry(666) { |
| 50 | try { |
Jakub Pavlik | d7fb22d | 2017-06-12 22:44:19 +0200 | [diff] [blame] | 51 | salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], 'test.ping') |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 52 | } catch(e) { |
| 53 | common.infoMsg("Still waiting for node to come up") |
| 54 | sleep(10) |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | stage("Deploy Compute") { |
| 61 | common.infoMsg("Lets run rest of the states to finish deployment") |
Jakub Pavlik | e7a399a | 2017-06-12 21:45:44 +0200 | [diff] [blame] | 62 | salt.enforceState(saltMaster, targetLiveAll, 'linux,openssh,ntp,salt', true) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 63 | retry(2) { |
Jakub Pavlik | d7fb22d | 2017-06-12 22:44:19 +0200 | [diff] [blame] | 64 | salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], 'state.apply') |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | |
| 68 | } catch (Throwable e) { |
| 69 | // If there was an error or exception thrown, the build failed |
| 70 | currentBuild.result = "FAILURE" |
| 71 | throw e |
| 72 | } |
| 73 | } |