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 | |
Dmitry Stremkouski | 067d25e | 2017-09-22 15:00:38 +0300 | [diff] [blame^] | 40 | stage("Trusty workaround") { |
| 41 | if(salt.getGrain(saltMaster, minions[0], "oscodename")['return'][0].values()[0]["oscodename"] == "trusty") { |
| 42 | common.infoMsg("First node %nodename% has trusty") |
| 43 | common.infoMsg("Assuming trusty on all cluster, running extra network states...") |
| 44 | common.infoMsg("Network iteration #1. Bonding") |
| 45 | salt.enforceState(saltMaster, targetLiveAll, 'linux.network', true) |
| 46 | common.infoMsg("Network iteration #2. Vlan tagging and bridging") |
| 47 | salt.enforceState(saltMaster, targetLiveAll, 'linux.network', true) |
| 48 | } |
| 49 | } |
| 50 | |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 51 | stage("Setup repositories") { |
| 52 | salt.enforceState(saltMaster, targetLiveAll, 'linux.system.repo', true) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 53 | } |
| 54 | |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 55 | stage("Upgrade packages") { |
| 56 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'pkg.upgrade', [], null, true) |
| 57 | } |
| 58 | |
| 59 | stage("Setup networking") { |
| 60 | // Sync all of the modules from the salt master. |
| 61 | salt.syncAll(saltMaster, targetLiveAll) |
| 62 | |
| 63 | // Apply state 'salt' to install python-psutil for network configuration without restarting salt-minion to avoid losing connection. |
| 64 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'state.apply', ['salt', 'exclude=[{\'id\': \'salt_minion_service\'}, {\'id\': \'salt_minion_service_restart\'}, {\'id\': \'salt_minion_sync_all\'}]'], null, true) |
| 65 | |
| 66 | // Restart salt-minion to take effect. |
| 67 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'service.restart', ['salt-minion'], null, true, 10) |
| 68 | |
| 69 | // Configure networking excluding vhost0 interface. |
| 70 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'state.apply', ['linux.network', 'exclude=[{\'id\': \'linux_interface_vhost0\'}]'], null, true) |
| 71 | |
| 72 | // Kill unnecessary processes ifup/ifdown which is stuck from previous state linux.network. |
| 73 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'ps.pkill', ['ifup'], null, false) |
| 74 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'ps.pkill', ['ifdown'], null, false) |
| 75 | |
| 76 | // Restart networking to bring UP all interfaces. |
| 77 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'service.restart', ['networking'], null, true, 300) |
| 78 | } |
| 79 | |
| 80 | stage("Highstate compute") { |
| 81 | // Execute highstate without state opencontrail.client. |
| 82 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'state.highstate', ['exclude=opencontrail.client'], null, true) |
| 83 | |
| 84 | // Apply nova state to remove libvirt default bridge virbr0. |
| 85 | salt.enforceState(saltMaster, targetLiveAll, 'nova', true) |
| 86 | |
| 87 | // Execute highstate. |
| 88 | salt.enforceHighstate(saltMaster, targetLiveAll, true) |
| 89 | |
| 90 | // Restart supervisor-vrouter. |
| 91 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'service.restart', ['supervisor-vrouter'], null, true, 300) |
| 92 | |
| 93 | // Apply salt,collectd to update information about current network interfaces. |
| 94 | salt.enforceState(saltMaster, targetLiveAll, 'salt,collectd', true) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | } catch (Throwable e) { |
| 98 | // If there was an error or exception thrown, the build failed |
| 99 | currentBuild.result = "FAILURE" |
Jakub Josef | d2efd7d | 2017-08-22 17:49:57 +0200 | [diff] [blame] | 100 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 101 | throw e |
| 102 | } |
| 103 | } |