blob: 581168a6468864db086ea55916f48828f539dc65 [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].
8 *
9**/
10
11def common = new com.mirantis.mk.Common()
12def salt = new com.mirantis.mk.Salt()
chnyda625f4b42017-10-11 14:10:31 +020013def python = new com.mirantis.mk.Python()
Jakub Pavlik77fe1542017-06-12 13:02:52 +020014
chnyda625f4b42017-10-11 14:10:31 +020015def pepperEnv = "pepperEnv"
Jakub Pavlik77fe1542017-06-12 13:02:52 +020016def minions
17def result
18def command
19def commandKwargs
20
Jakub Josefa63f9862018-01-11 17:58:38 +010021timeout(time: 12, unit: 'HOURS') {
22 node() {
23 try {
Jakub Pavlik77fe1542017-06-12 13:02:52 +020024
Jakub Josefa63f9862018-01-11 17:58:38 +010025 stage('Setup virtualenv for Pepper') {
26 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020027 }
28
Jakub Josefa63f9862018-01-11 17:58:38 +010029 stage('List target servers') {
30 minions = salt.getMinions(pepperEnv, TARGET_SERVERS)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020031
Jakub Josefa63f9862018-01-11 17:58:38 +010032 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 Stremkouski067d25e2017-09-22 15:00:38 +030039 }
Jakub Josefa63f9862018-01-11 17:58:38 +010040
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
cdodda2c3f44b2018-11-21 17:12:10 -060060 stage("Update Hosts file") {
61 salt.enforceState(pepperEnv, "I@linux:system", 'linux.network.host', true)
62 }
63
Jakub Josefa63f9862018-01-11 17:58:38 +010064 stage("Setup networking") {
65 // Sync all of the modules from the salt master.
66 salt.syncAll(pepperEnv, targetLiveAll)
67
68 // Apply state 'salt' to install python-psutil for network configuration without restarting salt-minion to avoid losing connection.
69 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.apply', ['salt', 'exclude=[{\'id\': \'salt_minion_service\'}, {\'id\': \'salt_minion_service_restart\'}, {\'id\': \'salt_minion_sync_all\'}]'], null, true)
70
71 // Restart salt-minion to take effect.
72 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['salt-minion'], null, true, 10)
73
74 // Configure networking excluding vhost0 interface.
75 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.apply', ['linux.network', 'exclude=[{\'id\': \'linux_interface_vhost0\'}]'], null, true)
76
77 // Kill unnecessary processes ifup/ifdown which is stuck from previous state linux.network.
78 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifup'], null, false)
79 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifdown'], null, false)
80
81 // Restart networking to bring UP all interfaces.
82 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['networking'], null, true, 300)
83 }
84
85 stage("Highstate compute") {
86 // Execute highstate without state opencontrail.client.
Pavel Cizinsky1c435302018-07-31 17:16:13 +020087 common.retry(2){
88 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.highstate', ['exclude=opencontrail.client'], null, true)
89 }
Jakub Josefa63f9862018-01-11 17:58:38 +010090
91 // Apply nova state to remove libvirt default bridge virbr0.
92 salt.enforceState(pepperEnv, targetLiveAll, 'nova', true)
93
94 // Execute highstate.
95 salt.enforceHighstate(pepperEnv, targetLiveAll, true)
96
97 // Restart supervisor-vrouter.
98 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['supervisor-vrouter'], null, true, 300)
99
Jiri Broulik1903cfb2018-02-06 10:07:02 +0100100 // Apply salt and collectd if is present to update information about current network interfaces.
101 salt.enforceState(pepperEnv, targetLiveAll, 'salt', true)
102 if(!salt.getPillar(pepperEnv, minions[0], "collectd")['return'][0].values()[0].isEmpty()) {
103 salt.enforceState(pepperEnv, targetLiveAll, 'collectd', true)
104 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100105 }
106
Sam Stoelinga87d1f1b2018-04-02 14:10:49 -0700107 stage("Update/Install monitoring") {
108 //Collect Grains
109 salt.enforceState(pepperEnv, targetLiveAll, 'salt.minion.grains')
110 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_modules')
111 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'mine.update')
112 sleep(5)
113
Michal Kobusd8874842018-03-13 12:42:07 +0100114 salt.enforceState(pepperEnv, targetLiveAll, 'prometheus')
Sam Stoelinga87d1f1b2018-04-02 14:10:49 -0700115 salt.enforceState(pepperEnv, 'I@prometheus:server', 'prometheus')
Michal Kobusd8874842018-03-13 12:42:07 +0100116 }
117
Jakub Josefa63f9862018-01-11 17:58:38 +0100118 } catch (Throwable e) {
119 // If there was an error or exception thrown, the build failed
120 currentBuild.result = "FAILURE"
121 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
122 throw e
Dmitry Stremkouski067d25e2017-09-22 15:00:38 +0300123 }
Jakub Pavlik77fe1542017-06-12 13:02:52 +0200124 }
125}