blob: bbf07a478c43a1729bfcb6f84e1b180c3937906e [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
21
22node() {
23 try {
24
chnyda625f4b42017-10-11 14:10:31 +020025 stage('Setup virtualenv for Pepper') {
26 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020027 }
28
29 stage('List target servers') {
chnyda625f4b42017-10-11 14:10:31 +020030 minions = salt.getMinions(pepperEnv, TARGET_SERVERS)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020031
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}")
39 }
40
Alexander Noskov227ea932017-07-13 17:17:15 +040041 stage("Setup repositories") {
chnyda625f4b42017-10-11 14:10:31 +020042 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo', true)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020043 }
44
Alexander Noskov227ea932017-07-13 17:17:15 +040045 stage("Upgrade packages") {
chnyda625f4b42017-10-11 14:10:31 +020046 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'pkg.upgrade', [], null, true)
Alexander Noskov227ea932017-07-13 17:17:15 +040047 }
48
49 stage("Setup networking") {
50 // Sync all of the modules from the salt master.
chnyda625f4b42017-10-11 14:10:31 +020051 salt.syncAll(pepperEnv, targetLiveAll)
Alexander Noskov227ea932017-07-13 17:17:15 +040052
53 // Apply state 'salt' to install python-psutil for network configuration without restarting salt-minion to avoid losing connection.
chnyda625f4b42017-10-11 14:10:31 +020054 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.apply', ['salt', 'exclude=[{\'id\': \'salt_minion_service\'}, {\'id\': \'salt_minion_service_restart\'}, {\'id\': \'salt_minion_sync_all\'}]'], null, true)
Alexander Noskov227ea932017-07-13 17:17:15 +040055
56 // Restart salt-minion to take effect.
chnyda625f4b42017-10-11 14:10:31 +020057 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['salt-minion'], null, true, 10)
Alexander Noskov227ea932017-07-13 17:17:15 +040058
59 // Configure networking excluding vhost0 interface.
chnyda625f4b42017-10-11 14:10:31 +020060 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.apply', ['linux.network', 'exclude=[{\'id\': \'linux_interface_vhost0\'}]'], null, true)
Alexander Noskov227ea932017-07-13 17:17:15 +040061
62 // Kill unnecessary processes ifup/ifdown which is stuck from previous state linux.network.
chnyda625f4b42017-10-11 14:10:31 +020063 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifup'], null, false)
64 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifdown'], null, false)
Alexander Noskov227ea932017-07-13 17:17:15 +040065
66 // Restart networking to bring UP all interfaces.
chnyda625f4b42017-10-11 14:10:31 +020067 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['networking'], null, true, 300)
Alexander Noskov227ea932017-07-13 17:17:15 +040068 }
69
70 stage("Highstate compute") {
71 // Execute highstate without state opencontrail.client.
chnyda625f4b42017-10-11 14:10:31 +020072 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.highstate', ['exclude=opencontrail.client'], null, true)
Alexander Noskov227ea932017-07-13 17:17:15 +040073
74 // Apply nova state to remove libvirt default bridge virbr0.
chnyda625f4b42017-10-11 14:10:31 +020075 salt.enforceState(pepperEnv, targetLiveAll, 'nova', true)
Alexander Noskov227ea932017-07-13 17:17:15 +040076
77 // Execute highstate.
chnyda625f4b42017-10-11 14:10:31 +020078 salt.enforceHighstate(pepperEnv, targetLiveAll, true)
Alexander Noskov227ea932017-07-13 17:17:15 +040079
80 // Restart supervisor-vrouter.
chnyda625f4b42017-10-11 14:10:31 +020081 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['supervisor-vrouter'], null, true, 300)
Alexander Noskov227ea932017-07-13 17:17:15 +040082
83 // Apply salt,collectd to update information about current network interfaces.
chnyda625f4b42017-10-11 14:10:31 +020084 salt.enforceState(pepperEnv, targetLiveAll, 'salt,collectd', true)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020085 }
86
87 } catch (Throwable e) {
88 // If there was an error or exception thrown, the build failed
89 currentBuild.result = "FAILURE"
Jakub Josefd2efd7d2017-08-22 17:49:57 +020090 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Jakub Pavlik77fe1542017-06-12 13:02:52 +020091 throw e
92 }
93}