blob: 780beacc36658b7aab890e4e821658bba6dcb8c4 [file] [log] [blame]
Jakub Pavlik77fe1542017-06-12 13:02:52 +02001/**
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 Egorenkoca6aeca2019-08-19 19:41:27 +04008 * BATCH_SIZE Use batching for large amount of target nodes
Jakub Pavlik77fe1542017-06-12 13:02:52 +02009 *
10**/
11
12def common = new com.mirantis.mk.Common()
13def salt = new com.mirantis.mk.Salt()
chnyda625f4b42017-10-11 14:10:31 +020014def python = new com.mirantis.mk.Python()
Jakub Pavlik77fe1542017-06-12 13:02:52 +020015
chnyda625f4b42017-10-11 14:10:31 +020016def pepperEnv = "pepperEnv"
Jakub Pavlik77fe1542017-06-12 13:02:52 +020017def minions
18def result
19def command
20def commandKwargs
21
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040022def batch_size = ''
23if (common.validInputParam('BATCH_SIZE')) {
24 batch_size = "${BATCH_SIZE}"
25}
26
Jakub Josefa63f9862018-01-11 17:58:38 +010027timeout(time: 12, unit: 'HOURS') {
28 node() {
29 try {
Jakub Pavlik77fe1542017-06-12 13:02:52 +020030
Jakub Josefa63f9862018-01-11 17:58:38 +010031 stage('Setup virtualenv for Pepper') {
32 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020033 }
34
Jakub Josefa63f9862018-01-11 17:58:38 +010035 stage('List target servers') {
36 minions = salt.getMinions(pepperEnv, TARGET_SERVERS)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020037
Jakub Josefa63f9862018-01-11 17:58:38 +010038 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 Stremkouski067d25e2017-09-22 15:00:38 +030045 }
Jakub Josefa63f9862018-01-11 17:58:38 +010046
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 Egorenkoca6aeca2019-08-19 19:41:27 +040052 salt.enforceState(pepperEnv, targetLiveAll, 'linux.network', true, true, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +010053 common.infoMsg("Network iteration #2. Vlan tagging and bridging")
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040054 salt.enforceState(pepperEnv, targetLiveAll, 'linux.network', true, true, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +010055 }
56 }
57
58 stage("Setup repositories") {
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040059 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo', true, true, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +010060 }
61
62 stage("Upgrade packages") {
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040063 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'pkg.upgrade', [], batch_size, true)
Jakub Josefa63f9862018-01-11 17:58:38 +010064 }
65
cdodda2c3f44b2018-11-21 17:12:10 -060066 stage("Update Hosts file") {
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040067 salt.enforceState(pepperEnv, "I@linux:system", 'linux.network.host', true, true, batch_size)
cdodda2c3f44b2018-11-21 17:12:10 -060068 }
69
Jakub Josefa63f9862018-01-11 17:58:38 +010070 stage("Setup networking") {
71 // Sync all of the modules from the salt master.
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040072 salt.syncAll(pepperEnv, targetLiveAll, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +010073
74 // Apply state 'salt' to install python-psutil for network configuration without restarting salt-minion to avoid losing connection.
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040075 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 Josefa63f9862018-01-11 17:58:38 +010076
77 // Restart salt-minion to take effect.
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040078 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['salt-minion'], batch_size, true, 10)
Jakub Josefa63f9862018-01-11 17:58:38 +010079
80 // Configure networking excluding vhost0 interface.
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040081 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.apply', ['linux.network', 'exclude=[{\'id\': \'linux_interface_vhost0\'}]'], batch_size, true)
Jakub Josefa63f9862018-01-11 17:58:38 +010082
83 // Kill unnecessary processes ifup/ifdown which is stuck from previous state linux.network.
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040084 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifup'], batch_size, false)
85 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifdown'], batch_size, false)
Jakub Josefa63f9862018-01-11 17:58:38 +010086
87 // Restart networking to bring UP all interfaces.
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040088 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['networking'], batch_size, true, 300)
Jakub Josefa63f9862018-01-11 17:58:38 +010089 }
90
91 stage("Highstate compute") {
92 // Execute highstate without state opencontrail.client.
Pavel Cizinsky1c435302018-07-31 17:16:13 +020093 common.retry(2){
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040094 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.highstate', ['exclude=opencontrail.client'], batch_size, true)
Pavel Cizinsky1c435302018-07-31 17:16:13 +020095 }
Jakub Josefa63f9862018-01-11 17:58:38 +010096
97 // Apply nova state to remove libvirt default bridge virbr0.
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040098 salt.enforceState(pepperEnv, targetLiveAll, 'nova', true, true, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +010099
100 // Execute highstate.
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400101 salt.enforceHighstate(pepperEnv, targetLiveAll, true, true, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +0100102
103 // Restart supervisor-vrouter.
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400104 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['supervisor-vrouter'], batch_size, true, 300)
Jakub Josefa63f9862018-01-11 17:58:38 +0100105
Jiri Broulik1903cfb2018-02-06 10:07:02 +0100106 // Apply salt and collectd if is present to update information about current network interfaces.
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400107 salt.enforceState(pepperEnv, targetLiveAll, 'salt', true, true, batch_size)
Jiri Broulik1903cfb2018-02-06 10:07:02 +0100108 if(!salt.getPillar(pepperEnv, minions[0], "collectd")['return'][0].values()[0].isEmpty()) {
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400109 salt.enforceState(pepperEnv, targetLiveAll, 'collectd', true, true, batch_size)
Jiri Broulik1903cfb2018-02-06 10:07:02 +0100110 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100111 }
112
Sam Stoelinga87d1f1b2018-04-02 14:10:49 -0700113 stage("Update/Install monitoring") {
114 //Collect Grains
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400115 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 Stoelinga87d1f1b2018-04-02 14:10:49 -0700118 sleep(5)
119
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400120 salt.enforceState(pepperEnv, targetLiveAll, 'prometheus', true, true, batch_size)
121 salt.enforceState(pepperEnv, 'I@prometheus:server', 'prometheus', true, true, batch_size)
Michal Kobusd8874842018-03-13 12:42:07 +0100122 }
123
Jakub Josefa63f9862018-01-11 17:58:38 +0100124 } 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 Stremkouski067d25e2017-09-22 15:00:38 +0300129 }
Jakub Pavlik77fe1542017-06-12 13:02:52 +0200130 }
131}