blob: 87cf8289c473c63970bf8f79e0165ac8dbaf28a1 [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.
Vasyl Saienko1a034dd2018-06-22 15:33:37 +030010 * INTERACTIVE Ask interactive questions during pipeline run (bool).
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020011 *
12**/
13
14def common = new com.mirantis.mk.Common()
15def salt = new com.mirantis.mk.Salt()
chnyda625f4b42017-10-11 14:10:31 +020016def python = new com.mirantis.mk.Python()
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020017
chnyda625f4b42017-10-11 14:10:31 +020018def pepperEnv = "pepperEnv"
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020019def targetTestSubset
20def targetLiveSubset
21def targetLiveAll
22def minions
23def result
24def args
25def command
26def commandKwargs
27def probe = 1
Jakub Josefa63f9862018-01-11 17:58:38 +010028timeout(time: 12, unit: 'HOURS') {
29 node() {
30 try {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020031
Jakub Josefa63f9862018-01-11 17:58:38 +010032 stage('Setup virtualenv for Pepper') {
33 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020034 }
35
Jakub Josefa63f9862018-01-11 17:58:38 +010036 stage('List target servers') {
37 minions = salt.getMinions(pepperEnv, TARGET_SERVERS)
38
39 if (minions.isEmpty()) {
40 throw new Exception("No minion was targeted")
41 }
42
43 if (TARGET_SUBSET_TEST != "") {
44 targetTestSubset = minions.subList(0, Integer.valueOf(TARGET_SUBSET_TEST)).join(' or ')
45 } else {
46 targetTestSubset = minions.join(' or ')
47 }
48 targetLiveSubset = minions.subList(0, Integer.valueOf(TARGET_SUBSET_LIVE)).join(' or ')
49 targetTestSubsetProbe = minions.subList(0, probe).join(' or ')
50 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
51
52 targetLiveAll = minions.join(' or ')
53 common.infoMsg("Found nodes: ${targetLiveAll}")
54 common.infoMsg("Selected test nodes: ${targetTestSubset}")
55 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020056 }
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020057
58
Jakub Josefa63f9862018-01-11 17:58:38 +010059 stage("Add new repos on test nodes") {
60 salt.enforceState(pepperEnv, targetTestSubset, 'linux.system.repo')
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020061 }
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020062
Jakub Josefa63f9862018-01-11 17:58:38 +010063 stage("List package upgrades") {
64 salt.runSaltProcessStep(pepperEnv, targetTestSubset, 'pkg.list_upgrades', [], null, true)
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020065 }
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020066
Vasyl Saienko1a034dd2018-06-22 15:33:37 +030067 if (INTERACTIVE.toBoolean()){
68 stage('Confirm upgrade on sample nodes') {
Jakub Josefa63f9862018-01-11 17:58:38 +010069 input message: "Please verify the list of packages that you want to be upgraded. Do you want to continue with upgrade?"
Vasyl Saienko1a034dd2018-06-22 15:33:37 +030070 }
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020071 }
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020072
Jakub Josefa63f9862018-01-11 17:58:38 +010073 stage("Add new repos on sample nodes") {
74 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020075 }
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020076
Jakub Josefa63f9862018-01-11 17:58:38 +010077 args = "apt-get -y -s -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade"
78
79 stage('Test upgrade on sample') {
80 try {
81 salt.cmdRun(pepperEnv, targetLiveSubset, args)
82 } catch (Exception er) {
83 print(er)
84 }
85 }
86
Vasyl Saienko1a034dd2018-06-22 15:33:37 +030087 if (INTERACTIVE.toBoolean()){
88 stage('Confirm upgrade on sample') {
Jakub Josefa63f9862018-01-11 17:58:38 +010089 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?"
Vasyl Saienko1a034dd2018-06-22 15:33:37 +030090 }
Jakub Josefa63f9862018-01-11 17:58:38 +010091 }
92
93 command = "cmd.run"
94 args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;'
95
96 stage('Apply package upgrades on sample') {
97 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, commandKwargs)
98 salt.printSaltCommandResult(out)
99 }
100
101 args = "sudo /usr/share/openvswitch/scripts/ovs-ctl start"
102
103 stage('Start ovs on sample nodes') {
104 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, commandKwargs)
105 salt.printSaltCommandResult(out)
106 }
107 stage("Run Neutron state on sample nodes") {
108 salt.enforceState(pepperEnv, targetLiveSubset, ['neutron'])
109 }
110
111 stage("Run Highstate on sample nodes") {
112 try {
113 salt.enforceHighstate(pepperEnv, targetLiveSubset)
114 } catch (Exception er) {
115 common.errorMsg("Highstate was executed on ${targetLiveSubset} but something failed. Please check it and fix it accordingly.")
116 }
117 }
118
Vasyl Saienko1a034dd2018-06-22 15:33:37 +0300119 if (INTERACTIVE.toBoolean()){
120 stage('Confirm upgrade on all targeted nodes') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100121 timeout(time: 2, unit: 'HOURS') {
Vasyl Saienko1a034dd2018-06-22 15:33:37 +0300122 input message: "Verify that the upgraded sample nodes are working correctly. If so, do you want to approve live upgrade on ${targetLiveAll} nodes?"
Jakub Josefa63f9862018-01-11 17:58:38 +0100123 }
Vasyl Saienko1a034dd2018-06-22 15:33:37 +0300124 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100125 }
126
127 stage("Add new repos on all targeted nodes") {
128 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
129 }
130
131 args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;'
132
133 stage('Apply package upgrades on all targeted nodes') {
134 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, commandKwargs)
135 salt.printSaltCommandResult(out)
136 }
137
138 args = "sudo /usr/share/openvswitch/scripts/ovs-ctl start"
139
140 stage('Start ovs on all targeted nodes') {
141 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, commandKwargs)
142 salt.printSaltCommandResult(out)
143 }
144 stage("Run Neutron state on all targeted nodes") {
145 salt.enforceState(pepperEnv, targetLiveAll, ['neutron'])
146 }
147
148 stage("Run Highstate on all targeted nodes") {
149 try {
150 salt.enforceHighstate(pepperEnv, targetLiveAll)
151 } catch (Exception er) {
152 common.errorMsg("Highstate was executed ${targetLiveAll} but something failed. Please check it and fix it accordingly.")
153 }
154 }
155
156 } catch (Throwable e) {
157 // If there was an error or exception thrown, the build failed
158 currentBuild.result = "FAILURE"
159 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
160 throw e
161 }
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200162 }
163}