blob: 8e53396c0e244bed77946409f42f5a350b07630f [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()
13
14def saltMaster
Jakub Pavlik77fe1542017-06-12 13:02:52 +020015def minions
16def result
17def command
18def commandKwargs
19
20
21node() {
22 try {
23
24 stage('Connect to Salt master') {
25 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
26 }
27
28 stage('List target servers') {
Tomáš Kukrálc86c8b42017-07-13 10:26:51 +020029 minions = salt.getMinions(saltMaster, TARGET_SERVERS)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020030
31 if (minions.isEmpty()) {
32 throw new Exception("No minion was targeted")
33 }
34
35 targetLiveAll = minions.join(' or ')
36 common.infoMsg("Found nodes: ${targetLiveAll}")
37 common.infoMsg("Selected nodes: ${targetLiveAll}")
38 }
39
Alexander Noskov227ea932017-07-13 17:17:15 +040040 stage("Setup repositories") {
41 salt.enforceState(saltMaster, targetLiveAll, 'linux.system.repo', true)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020042 }
43
Alexander Noskov227ea932017-07-13 17:17:15 +040044 stage("Upgrade packages") {
45 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'pkg.upgrade', [], null, true)
46 }
47
48 stage("Setup networking") {
49 // Sync all of the modules from the salt master.
50 salt.syncAll(saltMaster, targetLiveAll)
51
52 // Apply state 'salt' to install python-psutil for network configuration without restarting salt-minion to avoid losing connection.
53 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'state.apply', ['salt', 'exclude=[{\'id\': \'salt_minion_service\'}, {\'id\': \'salt_minion_service_restart\'}, {\'id\': \'salt_minion_sync_all\'}]'], null, true)
54
55 // Restart salt-minion to take effect.
56 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'service.restart', ['salt-minion'], null, true, 10)
57
58 // Configure networking excluding vhost0 interface.
59 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'state.apply', ['linux.network', 'exclude=[{\'id\': \'linux_interface_vhost0\'}]'], null, true)
60
61 // Kill unnecessary processes ifup/ifdown which is stuck from previous state linux.network.
62 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'ps.pkill', ['ifup'], null, false)
63 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'ps.pkill', ['ifdown'], null, false)
64
65 // Restart networking to bring UP all interfaces.
66 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'service.restart', ['networking'], null, true, 300)
67 }
68
69 stage("Highstate compute") {
70 // Execute highstate without state opencontrail.client.
71 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'state.highstate', ['exclude=opencontrail.client'], null, true)
72
73 // Apply nova state to remove libvirt default bridge virbr0.
74 salt.enforceState(saltMaster, targetLiveAll, 'nova', true)
75
76 // Execute highstate.
77 salt.enforceHighstate(saltMaster, targetLiveAll, true)
78
79 // Restart supervisor-vrouter.
80 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'service.restart', ['supervisor-vrouter'], null, true, 300)
81
82 // Apply salt,collectd to update information about current network interfaces.
83 salt.enforceState(saltMaster, targetLiveAll, 'salt,collectd', true)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020084 }
85
86 } catch (Throwable e) {
87 // If there was an error or exception thrown, the build failed
88 currentBuild.result = "FAILURE"
89 throw e
90 }
91}