blob: 3cf6aaa3b50ff2fe7176b17a1354f6a92ebe0956 [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') {
Dmitrii Kabanovf31c8962017-10-12 21:00:30 -070026 python.setupPepperVirtualenv(pepperEnv, 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
Dmitry Stremkouski067d25e2017-09-22 15:00:38 +030041 stage("Trusty workaround") {
chnydabf77c212017-11-15 11:17:00 +010042 if(salt.getGrain(pepperEnv, minions[0], "oscodename")['return'][0].values()[0]["oscodename"] == "trusty") {
Dmitry Stremkouski067d25e2017-09-22 15:00:38 +030043 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")
chnydabf77c212017-11-15 11:17:00 +010046 salt.enforceState(pepperEnv, targetLiveAll, 'linux.network', true)
Dmitry Stremkouski067d25e2017-09-22 15:00:38 +030047 common.infoMsg("Network iteration #2. Vlan tagging and bridging")
chnydabf77c212017-11-15 11:17:00 +010048 salt.enforceState(pepperEnv, targetLiveAll, 'linux.network', true)
Dmitry Stremkouski067d25e2017-09-22 15:00:38 +030049 }
50 }
51
Alexander Noskov227ea932017-07-13 17:17:15 +040052 stage("Setup repositories") {
chnyda625f4b42017-10-11 14:10:31 +020053 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo', true)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020054 }
55
Alexander Noskov227ea932017-07-13 17:17:15 +040056 stage("Upgrade packages") {
chnyda625f4b42017-10-11 14:10:31 +020057 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'pkg.upgrade', [], null, true)
Alexander Noskov227ea932017-07-13 17:17:15 +040058 }
59
60 stage("Setup networking") {
61 // Sync all of the modules from the salt master.
chnyda625f4b42017-10-11 14:10:31 +020062 salt.syncAll(pepperEnv, targetLiveAll)
Alexander Noskov227ea932017-07-13 17:17:15 +040063
64 // Apply state 'salt' to install python-psutil for network configuration without restarting salt-minion to avoid losing connection.
chnyda625f4b42017-10-11 14:10:31 +020065 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 +040066
67 // Restart salt-minion to take effect.
chnyda625f4b42017-10-11 14:10:31 +020068 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['salt-minion'], null, true, 10)
Alexander Noskov227ea932017-07-13 17:17:15 +040069
70 // Configure networking excluding vhost0 interface.
chnyda625f4b42017-10-11 14:10:31 +020071 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.apply', ['linux.network', 'exclude=[{\'id\': \'linux_interface_vhost0\'}]'], null, true)
Alexander Noskov227ea932017-07-13 17:17:15 +040072
73 // Kill unnecessary processes ifup/ifdown which is stuck from previous state linux.network.
chnyda625f4b42017-10-11 14:10:31 +020074 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifup'], null, false)
75 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifdown'], null, false)
Alexander Noskov227ea932017-07-13 17:17:15 +040076
77 // Restart networking to bring UP all interfaces.
chnyda625f4b42017-10-11 14:10:31 +020078 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['networking'], null, true, 300)
Alexander Noskov227ea932017-07-13 17:17:15 +040079 }
80
81 stage("Highstate compute") {
82 // Execute highstate without state opencontrail.client.
chnyda625f4b42017-10-11 14:10:31 +020083 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.highstate', ['exclude=opencontrail.client'], null, true)
Alexander Noskov227ea932017-07-13 17:17:15 +040084
85 // Apply nova state to remove libvirt default bridge virbr0.
chnyda625f4b42017-10-11 14:10:31 +020086 salt.enforceState(pepperEnv, targetLiveAll, 'nova', true)
Alexander Noskov227ea932017-07-13 17:17:15 +040087
88 // Execute highstate.
chnyda625f4b42017-10-11 14:10:31 +020089 salt.enforceHighstate(pepperEnv, targetLiveAll, true)
Alexander Noskov227ea932017-07-13 17:17:15 +040090
91 // Restart supervisor-vrouter.
chnyda625f4b42017-10-11 14:10:31 +020092 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['supervisor-vrouter'], null, true, 300)
Alexander Noskov227ea932017-07-13 17:17:15 +040093
94 // Apply salt,collectd to update information about current network interfaces.
chnyda625f4b42017-10-11 14:10:31 +020095 salt.enforceState(pepperEnv, targetLiveAll, 'salt,collectd', true)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020096 }
97
98 } catch (Throwable e) {
99 // If there was an error or exception thrown, the build failed
100 currentBuild.result = "FAILURE"
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200101 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Jakub Pavlik77fe1542017-06-12 13:02:52 +0200102 throw e
103 }
104}