blob: a43c2b9b78895a887ace70c7437c397522567f8b [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
Dmitry Stremkouski067d25e2017-09-22 15:00:38 +030040 stage("Trusty workaround") {
41 if(salt.getGrain(saltMaster, minions[0], "oscodename")['return'][0].values()[0]["oscodename"] == "trusty") {
42 common.infoMsg("First node %nodename% has trusty")
43 common.infoMsg("Assuming trusty on all cluster, running extra network states...")
44 common.infoMsg("Network iteration #1. Bonding")
45 salt.enforceState(saltMaster, targetLiveAll, 'linux.network', true)
46 common.infoMsg("Network iteration #2. Vlan tagging and bridging")
47 salt.enforceState(saltMaster, targetLiveAll, 'linux.network', true)
48 }
49 }
50
Alexander Noskov227ea932017-07-13 17:17:15 +040051 stage("Setup repositories") {
52 salt.enforceState(saltMaster, targetLiveAll, 'linux.system.repo', true)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020053 }
54
Alexander Noskov227ea932017-07-13 17:17:15 +040055 stage("Upgrade packages") {
56 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'pkg.upgrade', [], null, true)
57 }
58
59 stage("Setup networking") {
60 // Sync all of the modules from the salt master.
61 salt.syncAll(saltMaster, targetLiveAll)
62
63 // Apply state 'salt' to install python-psutil for network configuration without restarting salt-minion to avoid losing connection.
64 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'state.apply', ['salt', 'exclude=[{\'id\': \'salt_minion_service\'}, {\'id\': \'salt_minion_service_restart\'}, {\'id\': \'salt_minion_sync_all\'}]'], null, true)
65
66 // Restart salt-minion to take effect.
67 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'service.restart', ['salt-minion'], null, true, 10)
68
69 // Configure networking excluding vhost0 interface.
70 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'state.apply', ['linux.network', 'exclude=[{\'id\': \'linux_interface_vhost0\'}]'], null, true)
71
72 // Kill unnecessary processes ifup/ifdown which is stuck from previous state linux.network.
73 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'ps.pkill', ['ifup'], null, false)
74 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'ps.pkill', ['ifdown'], null, false)
75
76 // Restart networking to bring UP all interfaces.
77 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'service.restart', ['networking'], null, true, 300)
78 }
79
80 stage("Highstate compute") {
81 // Execute highstate without state opencontrail.client.
82 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'state.highstate', ['exclude=opencontrail.client'], null, true)
83
84 // Apply nova state to remove libvirt default bridge virbr0.
85 salt.enforceState(saltMaster, targetLiveAll, 'nova', true)
86
87 // Execute highstate.
88 salt.enforceHighstate(saltMaster, targetLiveAll, true)
89
90 // Restart supervisor-vrouter.
91 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'service.restart', ['supervisor-vrouter'], null, true, 300)
92
93 // Apply salt,collectd to update information about current network interfaces.
94 salt.enforceState(saltMaster, targetLiveAll, 'salt,collectd', true)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020095 }
96
97 } catch (Throwable e) {
98 // If there was an error or exception thrown, the build failed
99 currentBuild.result = "FAILURE"
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200100 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Jakub Pavlik77fe1542017-06-12 13:02:52 +0200101 throw e
102 }
103}