blob: 54577180e08e9917b5d1da76ad41e3a3ae585f86 [file] [log] [blame]
Ales Komarek1fe5b8f2017-03-06 11:07:54 +01001/**
Ales Komarek374cc382017-03-16 08:49:01 +01002 * Update packages on given nodes
Ales Komarek1fe5b8f2017-03-06 11:07:54 +01003 *
4 * Expected parameters:
Ales Komarek374cc382017-03-16 08:49:01 +01005 * 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 * TARGET_PACKAGES Space delimited list of packages to be updates [package1=version package2=version], empty string means all updating all packages to the latest version.
9 * TARGET_SIZE_TEST Number of nodes to list package updates, empty string means all targetted nodes.
10 * TARGET_SIZE_SAMPLE Number of selected noded to live apply selected package update.
11 * TARGET_SIZE_BATCH Batch size for the complete live package update on all nodes, empty string means apply to all targetted nodes.
Ales Komarek1fe5b8f2017-03-06 11:07:54 +010012 *
13**/
14
Ales Komarek1fe5b8f2017-03-06 11:07:54 +010015def common = new com.mirantis.mk.Common()
16def salt = new com.mirantis.mk.Salt()
Ales Komarek1fe5b8f2017-03-06 11:07:54 +010017
Ales Komarek374cc382017-03-16 08:49:01 +010018def saltMaster
19def targetAll = ['expression': TARGET_SERVERS, 'type': 'compound']
20def targetTestSubset
21def targetLiveSubset
22def targetLiveAll
23def minions
24def result
25def packages
26
27node() {
28 try {
29
30 if (TARGET_PACKAGES != "") {
31 packages = TARGET_PACKAGES.split(' ')
32 }
33 else {
34 packages = []
Ales Komarek1fe5b8f2017-03-06 11:07:54 +010035 }
36
Ales Komarek374cc382017-03-16 08:49:01 +010037 stage('Connect to Salt master') {
38 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Ales Komarek1fe5b8f2017-03-06 11:07:54 +010039 }
40
Ales Komarek374cc382017-03-16 08:49:01 +010041 stage('List target servers') {
42 minions = salt.getMinions(saltMaster, targetAll)
43 if (TARGET_SUBSET_TEST != "") {
44 targetTestSubset = minions.subList(0, Integer.valueOf(TARGET_SUBSET_TEST)).join(' or ')
Ales Komarek1fe5b8f2017-03-06 11:07:54 +010045 }
Ales Komarek374cc382017-03-16 08:49:01 +010046 else {
47 targetTestSubset = minions.join(' or ')
48 }
49 targetLiveSubset = minions.subList(0, Integer.valueOf(TARGET_SUBSET_LIVE)).join(' or ')
50 targetLiveAll = minions.join(' or ')
51 common.infoMsg("Found nodes: ${targetLiveAll}")
52 common.infoMsg("Selected test nodes: ${targetTestSubset}")
53 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
Ales Komarek1fe5b8f2017-03-06 11:07:54 +010054 }
55
Ales Komarek374cc382017-03-16 08:49:01 +010056 stage("List package upgrades") {
57 salt.runSaltProcessStep(saltMaster, targetTestSubset, 'pkg.list_upgrades', [], null, true)
58 }
59
60 stage('Confirm live package upgrades on sample') {
61 timeout(time: 2, unit: 'HOURS') {
62 input message: "Approve live package upgrades on ${targetLiveSubset} nodes?"
63 }
64 }
65
66 stage('Apply package upgrades on sample') {
67 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'pkg.install', packages, null, true)
68
69 }
70
71 stage('Confirm package upgrades on all nodes') {
72 timeout(time: 2, unit: 'HOURS') {
73 input message: "Approve live package upgrades on ${targetLiveAll} nodes?"
74 }
75 }
76
77 stage('Apply package upgrades on all nodes') {
78 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'pkg.install', packages, null, true)
79 }
80
81 } catch (Throwable e) {
82 // If there was an error or exception thrown, the build failed
83 currentBuild.result = "FAILURE"
84 throw e
85 } finally {
86 // common.sendNotification(currentBuild.result,"",["slack"])
Ales Komarek1fe5b8f2017-03-06 11:07:54 +010087 }
88}