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]. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 8 | * BATCH_SIZE Use batching for large amount of target nodes |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 9 | * |
| 10 | **/ |
| 11 | |
| 12 | def common = new com.mirantis.mk.Common() |
| 13 | def salt = new com.mirantis.mk.Salt() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 14 | def python = new com.mirantis.mk.Python() |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 15 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 16 | def pepperEnv = "pepperEnv" |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 17 | def minions |
| 18 | def result |
| 19 | def command |
| 20 | def commandKwargs |
| 21 | |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 22 | def batch_size = '' |
| 23 | if (common.validInputParam('BATCH_SIZE')) { |
| 24 | batch_size = "${BATCH_SIZE}" |
| 25 | } |
| 26 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 27 | timeout(time: 12, unit: 'HOURS') { |
| 28 | node() { |
| 29 | try { |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 30 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 31 | stage('Setup virtualenv for Pepper') { |
| 32 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 33 | } |
| 34 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 35 | stage('List target servers') { |
| 36 | minions = salt.getMinions(pepperEnv, TARGET_SERVERS) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 37 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 38 | if (minions.isEmpty()) { |
| 39 | throw new Exception("No minion was targeted") |
| 40 | } |
| 41 | |
| 42 | targetLiveAll = minions.join(' or ') |
| 43 | common.infoMsg("Found nodes: ${targetLiveAll}") |
| 44 | common.infoMsg("Selected nodes: ${targetLiveAll}") |
Dmitry Stremkouski | 067d25e | 2017-09-22 15:00:38 +0300 | [diff] [blame] | 45 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 46 | |
| 47 | stage("Trusty workaround") { |
| 48 | if(salt.getGrain(pepperEnv, minions[0], "oscodename")['return'][0].values()[0]["oscodename"] == "trusty") { |
| 49 | common.infoMsg("First node %nodename% has trusty") |
| 50 | common.infoMsg("Assuming trusty on all cluster, running extra network states...") |
| 51 | common.infoMsg("Network iteration #1. Bonding") |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 52 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.network', true, true, batch_size) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 53 | common.infoMsg("Network iteration #2. Vlan tagging and bridging") |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 54 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.network', true, true, batch_size) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
| 58 | stage("Setup repositories") { |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 59 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo', true, true, batch_size) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | stage("Upgrade packages") { |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 63 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'pkg.upgrade', [], batch_size, true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 64 | } |
| 65 | |
cdodda | 2c3f44b | 2018-11-21 17:12:10 -0600 | [diff] [blame] | 66 | stage("Update Hosts file") { |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 67 | salt.enforceState(pepperEnv, "I@linux:system", 'linux.network.host', true, true, batch_size) |
cdodda | 2c3f44b | 2018-11-21 17:12:10 -0600 | [diff] [blame] | 68 | } |
| 69 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 70 | stage("Setup networking") { |
| 71 | // Sync all of the modules from the salt master. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 72 | salt.syncAll(pepperEnv, targetLiveAll, batch_size) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 73 | |
| 74 | // Apply state 'salt' to install python-psutil for network configuration without restarting salt-minion to avoid losing connection. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 75 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.apply', ['salt', 'exclude=[{\'id\': \'salt_minion_service\'}, {\'id\': \'salt_minion_service_restart\'}, {\'id\': \'salt_minion_sync_all\'}]'], batch_size, true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 76 | |
| 77 | // Restart salt-minion to take effect. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 78 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['salt-minion'], batch_size, true, 10) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 79 | |
| 80 | // Configure networking excluding vhost0 interface. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 81 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.apply', ['linux.network', 'exclude=[{\'id\': \'linux_interface_vhost0\'}]'], batch_size, true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 82 | |
| 83 | // Kill unnecessary processes ifup/ifdown which is stuck from previous state linux.network. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 84 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifup'], batch_size, false) |
| 85 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifdown'], batch_size, false) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 86 | |
| 87 | // Restart networking to bring UP all interfaces. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 88 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['networking'], batch_size, true, 300) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | stage("Highstate compute") { |
| 92 | // Execute highstate without state opencontrail.client. |
Pavel Cizinsky | 1c43530 | 2018-07-31 17:16:13 +0200 | [diff] [blame] | 93 | common.retry(2){ |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 94 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.highstate', ['exclude=opencontrail.client'], batch_size, true) |
Pavel Cizinsky | 1c43530 | 2018-07-31 17:16:13 +0200 | [diff] [blame] | 95 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 96 | |
| 97 | // Apply nova state to remove libvirt default bridge virbr0. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 98 | salt.enforceState(pepperEnv, targetLiveAll, 'nova', true, true, batch_size) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 99 | |
| 100 | // Execute highstate. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 101 | salt.enforceHighstate(pepperEnv, targetLiveAll, true, true, batch_size) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 102 | |
| 103 | // Restart supervisor-vrouter. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 104 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['supervisor-vrouter'], batch_size, true, 300) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 105 | |
Jiri Broulik | 1903cfb | 2018-02-06 10:07:02 +0100 | [diff] [blame] | 106 | // Apply salt and collectd if is present to update information about current network interfaces. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 107 | salt.enforceState(pepperEnv, targetLiveAll, 'salt', true, true, batch_size) |
Jiri Broulik | 1903cfb | 2018-02-06 10:07:02 +0100 | [diff] [blame] | 108 | if(!salt.getPillar(pepperEnv, minions[0], "collectd")['return'][0].values()[0].isEmpty()) { |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 109 | salt.enforceState(pepperEnv, targetLiveAll, 'collectd', true, true, batch_size) |
Jiri Broulik | 1903cfb | 2018-02-06 10:07:02 +0100 | [diff] [blame] | 110 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Sam Stoelinga | 87d1f1b | 2018-04-02 14:10:49 -0700 | [diff] [blame] | 113 | stage("Update/Install monitoring") { |
| 114 | //Collect Grains |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 115 | salt.enforceState(pepperEnv, targetLiveAll, 'salt.minion.grains', true, true, batch_size) |
| 116 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_modules', [], batch_size) |
| 117 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'mine.update', [], batch_size) |
Sam Stoelinga | 87d1f1b | 2018-04-02 14:10:49 -0700 | [diff] [blame] | 118 | sleep(5) |
| 119 | |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 120 | salt.enforceState(pepperEnv, targetLiveAll, 'prometheus', true, true, batch_size) |
| 121 | salt.enforceState(pepperEnv, 'I@prometheus:server', 'prometheus', true, true, batch_size) |
Michal Kobus | d887484 | 2018-03-13 12:42:07 +0100 | [diff] [blame] | 122 | } |
| 123 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 124 | } catch (Throwable e) { |
| 125 | // If there was an error or exception thrown, the build failed |
| 126 | currentBuild.result = "FAILURE" |
| 127 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 128 | throw e |
Dmitry Stremkouski | 067d25e | 2017-09-22 15:00:38 +0300 | [diff] [blame] | 129 | } |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 130 | } |
| 131 | } |