blob: 8d131c8778fb8857f6aa11d147dbf08ed00ed2c9 [file] [log] [blame]
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +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 * TARGET_SUBSET_TEST Number of nodes to list package updates, empty string means all targetted nodes.
9 * TARGET_SUBSET_LIVE Number of selected nodes to live apply selected package update.
10 *
11**/
12
13def common = new com.mirantis.mk.Common()
14def salt = new com.mirantis.mk.Salt()
chnyda625f4b42017-10-11 14:10:31 +020015def python = new com.mirantis.mk.Python()
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020016
chnyda625f4b42017-10-11 14:10:31 +020017def pepperEnv = "pepperEnv"
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020018def targetTestSubset
19def targetLiveSubset
20def targetLiveAll
21def minions
22def result
23def args
24def command
25def commandKwargs
26def probe = 1
Jakub Josefa63f9862018-01-11 17:58:38 +010027timeout(time: 12, unit: 'HOURS') {
28 node() {
29 try {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020030
Jakub Josefa63f9862018-01-11 17:58:38 +010031 stage('Setup virtualenv for Pepper') {
32 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020033 }
34
Jakub Josefa63f9862018-01-11 17:58:38 +010035 stage('List target servers') {
36 minions = salt.getMinions(pepperEnv, TARGET_SERVERS)
37
38 if (minions.isEmpty()) {
39 throw new Exception("No minion was targeted")
40 }
41
42 if (TARGET_SUBSET_TEST != "") {
43 targetTestSubset = minions.subList(0, Integer.valueOf(TARGET_SUBSET_TEST)).join(' or ')
44 } else {
45 targetTestSubset = minions.join(' or ')
46 }
47 targetLiveSubset = minions.subList(0, Integer.valueOf(TARGET_SUBSET_LIVE)).join(' or ')
48 targetTestSubsetProbe = minions.subList(0, probe).join(' or ')
49 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
50
51 targetLiveAll = minions.join(' or ')
52 common.infoMsg("Found nodes: ${targetLiveAll}")
53 common.infoMsg("Selected test nodes: ${targetTestSubset}")
54 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020055 }
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020056
57
Jakub Josefa63f9862018-01-11 17:58:38 +010058 stage("Add new repos on test nodes") {
59 salt.enforceState(pepperEnv, targetTestSubset, 'linux.system.repo')
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020060 }
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020061
Jakub Josefa63f9862018-01-11 17:58:38 +010062 stage("List package upgrades") {
63 salt.runSaltProcessStep(pepperEnv, targetTestSubset, 'pkg.list_upgrades', [], null, true)
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020064 }
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020065
Jakub Josefa63f9862018-01-11 17:58:38 +010066 stage('Confirm upgrade on sample nodes') {
67 input message: "Please verify the list of packages that you want to be upgraded. Do you want to continue with upgrade?"
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020068 }
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020069
Jakub Josefa63f9862018-01-11 17:58:38 +010070 stage("Add new repos on sample nodes") {
71 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020072 }
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020073
Jakub Josefa63f9862018-01-11 17:58:38 +010074 args = "apt-get -y -s -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade"
75
76 stage('Test upgrade on sample') {
77 try {
78 salt.cmdRun(pepperEnv, targetLiveSubset, args)
79 } catch (Exception er) {
80 print(er)
81 }
82 }
83
84 stage('Confirm upgrade on sample') {
85 input message: "Please verify if there are packages that it wants to downgrade. If so, execute apt-cache policy on them and verify if everything is fine. Do you want to continue with upgrade?"
86 }
87
88 command = "cmd.run"
89 args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;'
90
91 stage('Apply package upgrades on sample') {
92 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, commandKwargs)
93 salt.printSaltCommandResult(out)
94 }
95
96 args = "sudo /usr/share/openvswitch/scripts/ovs-ctl start"
97
98 stage('Start ovs on sample nodes') {
99 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, commandKwargs)
100 salt.printSaltCommandResult(out)
101 }
102 stage("Run Neutron state on sample nodes") {
103 salt.enforceState(pepperEnv, targetLiveSubset, ['neutron'])
104 }
105
106 stage("Run Highstate on sample nodes") {
107 try {
108 salt.enforceHighstate(pepperEnv, targetLiveSubset)
109 } catch (Exception er) {
110 common.errorMsg("Highstate was executed on ${targetLiveSubset} but something failed. Please check it and fix it accordingly.")
111 }
112 }
113
114 stage('Confirm upgrade on all targeted nodes') {
115 timeout(time: 2, unit: 'HOURS') {
116 input message: "Verify that the upgraded sample nodes are working correctly. If so, do you want to approve live upgrade on ${targetLiveAll} nodes?"
117 }
118 }
119
120 stage("Add new repos on all targeted nodes") {
121 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
122 }
123
124 args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;'
125
126 stage('Apply package upgrades on all targeted nodes') {
127 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, commandKwargs)
128 salt.printSaltCommandResult(out)
129 }
130
131 args = "sudo /usr/share/openvswitch/scripts/ovs-ctl start"
132
133 stage('Start ovs on all targeted nodes') {
134 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, commandKwargs)
135 salt.printSaltCommandResult(out)
136 }
137 stage("Run Neutron state on all targeted nodes") {
138 salt.enforceState(pepperEnv, targetLiveAll, ['neutron'])
139 }
140
141 stage("Run Highstate on all targeted nodes") {
142 try {
143 salt.enforceHighstate(pepperEnv, targetLiveAll)
144 } catch (Exception er) {
145 common.errorMsg("Highstate was executed ${targetLiveAll} but something failed. Please check it and fix it accordingly.")
146 }
147 }
148
149 } catch (Throwable e) {
150 // If there was an error or exception thrown, the build failed
151 currentBuild.result = "FAILURE"
152 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
153 throw e
154 }
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200155 }
156}