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 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 21 | timeout(time: 12, unit: 'HOURS') { |
| 22 | node() { |
| 23 | try { |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 24 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 25 | stage('Setup virtualenv for Pepper') { |
| 26 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 27 | } |
| 28 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 29 | stage('List target servers') { |
| 30 | minions = salt.getMinions(pepperEnv, TARGET_SERVERS) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 31 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 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}") |
Dmitry Stremkouski | 067d25e | 2017-09-22 15:00:38 +0300 | [diff] [blame] | 39 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 40 | |
| 41 | stage("Trusty workaround") { |
| 42 | if(salt.getGrain(pepperEnv, minions[0], "oscodename")['return'][0].values()[0]["oscodename"] == "trusty") { |
| 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") |
| 46 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.network', true) |
| 47 | common.infoMsg("Network iteration #2. Vlan tagging and bridging") |
| 48 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.network', true) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | stage("Setup repositories") { |
| 53 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo', true) |
| 54 | } |
| 55 | |
| 56 | stage("Upgrade packages") { |
| 57 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'pkg.upgrade', [], null, true) |
| 58 | } |
| 59 | |
| 60 | stage("Setup networking") { |
| 61 | // Sync all of the modules from the salt master. |
| 62 | salt.syncAll(pepperEnv, targetLiveAll) |
| 63 | |
| 64 | // Apply state 'salt' to install python-psutil for network configuration without restarting salt-minion to avoid losing connection. |
| 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) |
| 66 | |
| 67 | // Restart salt-minion to take effect. |
| 68 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['salt-minion'], null, true, 10) |
| 69 | |
| 70 | // Configure networking excluding vhost0 interface. |
| 71 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.apply', ['linux.network', 'exclude=[{\'id\': \'linux_interface_vhost0\'}]'], null, true) |
| 72 | |
| 73 | // Kill unnecessary processes ifup/ifdown which is stuck from previous state linux.network. |
| 74 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifup'], null, false) |
| 75 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifdown'], null, false) |
| 76 | |
| 77 | // Restart networking to bring UP all interfaces. |
| 78 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['networking'], null, true, 300) |
| 79 | } |
| 80 | |
| 81 | stage("Highstate compute") { |
| 82 | // Execute highstate without state opencontrail.client. |
Pavel Cizinsky | 1c43530 | 2018-07-31 17:16:13 +0200 | [diff] [blame^] | 83 | common.retry(2){ |
| 84 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.highstate', ['exclude=opencontrail.client'], null, true) |
| 85 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 86 | |
| 87 | // Apply nova state to remove libvirt default bridge virbr0. |
| 88 | salt.enforceState(pepperEnv, targetLiveAll, 'nova', true) |
| 89 | |
| 90 | // Execute highstate. |
| 91 | salt.enforceHighstate(pepperEnv, targetLiveAll, true) |
| 92 | |
| 93 | // Restart supervisor-vrouter. |
| 94 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['supervisor-vrouter'], null, true, 300) |
| 95 | |
Jiri Broulik | 1903cfb | 2018-02-06 10:07:02 +0100 | [diff] [blame] | 96 | // Apply salt and collectd if is present to update information about current network interfaces. |
| 97 | salt.enforceState(pepperEnv, targetLiveAll, 'salt', true) |
| 98 | if(!salt.getPillar(pepperEnv, minions[0], "collectd")['return'][0].values()[0].isEmpty()) { |
| 99 | salt.enforceState(pepperEnv, targetLiveAll, 'collectd', true) |
| 100 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Sam Stoelinga | 87d1f1b | 2018-04-02 14:10:49 -0700 | [diff] [blame] | 103 | stage("Update/Install monitoring") { |
| 104 | //Collect Grains |
| 105 | salt.enforceState(pepperEnv, targetLiveAll, 'salt.minion.grains') |
| 106 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_modules') |
| 107 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'mine.update') |
| 108 | sleep(5) |
| 109 | |
Michal Kobus | d887484 | 2018-03-13 12:42:07 +0100 | [diff] [blame] | 110 | salt.enforceState(pepperEnv, targetLiveAll, 'prometheus') |
Sam Stoelinga | 87d1f1b | 2018-04-02 14:10:49 -0700 | [diff] [blame] | 111 | salt.enforceState(pepperEnv, 'I@prometheus:server', 'prometheus') |
Michal Kobus | d887484 | 2018-03-13 12:42:07 +0100 | [diff] [blame] | 112 | } |
| 113 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 114 | } catch (Throwable e) { |
| 115 | // If there was an error or exception thrown, the build failed |
| 116 | currentBuild.result = "FAILURE" |
| 117 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 118 | throw e |
Dmitry Stremkouski | 067d25e | 2017-09-22 15:00:38 +0300 | [diff] [blame] | 119 | } |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 120 | } |
| 121 | } |