blob: 7602dcf2cc6f18be315205cc844780fe0a6792c7 [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
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.
83 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.highstate', ['exclude=opencontrail.client'], null, true)
84
85 // Apply nova state to remove libvirt default bridge virbr0.
86 salt.enforceState(pepperEnv, targetLiveAll, 'nova', true)
87
88 // Execute highstate.
89 salt.enforceHighstate(pepperEnv, targetLiveAll, true)
90
91 // Restart supervisor-vrouter.
92 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['supervisor-vrouter'], null, true, 300)
93
Jiri Broulik1903cfb2018-02-06 10:07:02 +010094 // Apply salt and collectd if is present to update information about current network interfaces.
95 salt.enforceState(pepperEnv, targetLiveAll, 'salt', true)
96 if(!salt.getPillar(pepperEnv, minions[0], "collectd")['return'][0].values()[0].isEmpty()) {
97 salt.enforceState(pepperEnv, targetLiveAll, 'collectd', true)
98 }
Jakub Josefa63f9862018-01-11 17:58:38 +010099 }
100
Sam Stoelinga87d1f1b2018-04-02 14:10:49 -0700101 stage("Update/Install monitoring") {
102 //Collect Grains
103 salt.enforceState(pepperEnv, targetLiveAll, 'salt.minion.grains')
104 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_modules')
105 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'mine.update')
106 sleep(5)
107
Michal Kobusd8874842018-03-13 12:42:07 +0100108 salt.enforceState(pepperEnv, targetLiveAll, 'prometheus')
Sam Stoelinga87d1f1b2018-04-02 14:10:49 -0700109 salt.enforceState(pepperEnv, 'I@prometheus:server', 'prometheus')
Michal Kobusd8874842018-03-13 12:42:07 +0100110 }
111
Jakub Josefa63f9862018-01-11 17:58:38 +0100112 } catch (Throwable e) {
113 // If there was an error or exception thrown, the build failed
114 currentBuild.result = "FAILURE"
115 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
116 throw e
Dmitry Stremkouski067d25e2017-09-22 15:00:38 +0300117 }
Jakub Pavlik77fe1542017-06-12 13:02:52 +0200118 }
119}