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