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() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 13 | def python = new com.mirantis.mk.Python() |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 14 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 15 | def pepperEnv = "pepperEnv" |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 16 | def minions |
| 17 | def result |
| 18 | def command |
| 19 | def commandKwargs |
| 20 | |
| 21 | |
| 22 | node() { |
| 23 | try { |
| 24 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 25 | stage('Setup virtualenv for Pepper') { |
| 26 | python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | stage('List target servers') { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 30 | minions = salt.getMinions(pepperEnv, TARGET_SERVERS) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 31 | |
| 32 | if (minions.isEmpty()) { |
| 33 | throw new Exception("No minion was targeted") |
| 34 | } |
| 35 | |
| 36 | targetLiveAll = minions.join(' or ') |
| 37 | common.infoMsg("Found nodes: ${targetLiveAll}") |
| 38 | common.infoMsg("Selected nodes: ${targetLiveAll}") |
| 39 | } |
| 40 | |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 41 | stage("Setup repositories") { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 42 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo', true) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 43 | } |
| 44 | |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 45 | stage("Upgrade packages") { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 46 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'pkg.upgrade', [], null, true) |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | stage("Setup networking") { |
| 50 | // Sync all of the modules from the salt master. |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 51 | salt.syncAll(pepperEnv, targetLiveAll) |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 52 | |
| 53 | // Apply state 'salt' to install python-psutil for network configuration without restarting salt-minion to avoid losing connection. |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 54 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.apply', ['salt', 'exclude=[{\'id\': \'salt_minion_service\'}, {\'id\': \'salt_minion_service_restart\'}, {\'id\': \'salt_minion_sync_all\'}]'], null, true) |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 55 | |
| 56 | // Restart salt-minion to take effect. |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 57 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['salt-minion'], null, true, 10) |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 58 | |
| 59 | // Configure networking excluding vhost0 interface. |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 60 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.apply', ['linux.network', 'exclude=[{\'id\': \'linux_interface_vhost0\'}]'], null, true) |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 61 | |
| 62 | // Kill unnecessary processes ifup/ifdown which is stuck from previous state linux.network. |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 63 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifup'], null, false) |
| 64 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifdown'], null, false) |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 65 | |
| 66 | // Restart networking to bring UP all interfaces. |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 67 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['networking'], null, true, 300) |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | stage("Highstate compute") { |
| 71 | // Execute highstate without state opencontrail.client. |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 72 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.highstate', ['exclude=opencontrail.client'], null, true) |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 73 | |
| 74 | // Apply nova state to remove libvirt default bridge virbr0. |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 75 | salt.enforceState(pepperEnv, targetLiveAll, 'nova', true) |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 76 | |
| 77 | // Execute highstate. |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 78 | salt.enforceHighstate(pepperEnv, targetLiveAll, true) |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 79 | |
| 80 | // Restart supervisor-vrouter. |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 81 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['supervisor-vrouter'], null, true, 300) |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 82 | |
| 83 | // Apply salt,collectd to update information about current network interfaces. |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 84 | salt.enforceState(pepperEnv, targetLiveAll, 'salt,collectd', true) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | } catch (Throwable e) { |
| 88 | // If there was an error or exception thrown, the build failed |
| 89 | currentBuild.result = "FAILURE" |
Jakub Josef | d2efd7d | 2017-08-22 17:49:57 +0200 | [diff] [blame] | 90 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 91 | throw e |
| 92 | } |
| 93 | } |