blob: d8bca4375122b466a88ddff09a1a35ad98eaae59 [file] [log] [blame]
Richard Felkl26cae4d2017-12-19 00:19:16 +01001/**
2 *
3 * Update Salt environment pipeline
4 *
5 * Expected parameters:
azvyagintsev6dac3802018-11-09 15:11:30 +02006 * TARGET_MCP_VERSION Version of MCP to upgrade to
Denis Egorenkod13ad132018-12-17 16:56:02 +04007 * GIT_REFSPEC Git repo ref to be used
8 * DRIVE_TRAIN_PARAMS Yaml, DriveTrain releated params:
9 * SALT_MASTER_URL Salt API server location
10 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040011 * BATCH_SIZE Use batch sizing during upgrade for large envs
Denis Egorenkod13ad132018-12-17 16:56:02 +040012 * UPGRADE_SALTSTACK Upgrade SaltStack packages to new version.
13 * UPDATE_CLUSTER_MODEL Update MCP version parameter in cluster model
14 * UPDATE_PIPELINES Update pipeline repositories on Gerrit
15 * UPDATE_LOCAL_REPOS Update local repositories
Richard Felkl26cae4d2017-12-19 00:19:16 +010016 */
17
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010018salt = new com.mirantis.mk.Salt()
19common = new com.mirantis.mk.Common()
20python = new com.mirantis.mk.Python()
Richard Felkl970e0082018-06-12 18:00:51 +020021jenkinsUtils = new com.mirantis.mk.JenkinsUtils()
azvyagintsevf3bf77a2018-11-15 19:30:04 +020022def pipelineTimeout = 12
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010023venvPepper = "venvPepper"
Richard Felkl0e80d892018-06-20 13:44:54 +020024workspace = ""
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010025
azvyagintsevbc359d42019-04-10 19:53:22 +030026def triggerMirrorJob(String jobName, String reclassSystemBranch) {
Richard Felkl970e0082018-06-12 18:00:51 +020027 params = jenkinsUtils.getJobParameters(jobName)
azvyagintsevbc359d42019-04-10 19:53:22 +030028 try {
29 build job: jobName, parameters: [
30 [$class: 'StringParameterValue', name: 'BRANCHES', value: params.get('BRANCHES')],
31 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')],
32 [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')],
33 [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')]
34 ]
35 } catch (Exception updateErr) {
36 common.warningMsg(updateErr)
37 common.warningMsg('Attempt to update git repo in failsafe manner')
38 build job: jobName, parameters: [
39 [$class: 'StringParameterValue', name: 'BRANCHES', value: reclassSystemBranch.replace('origin/', '')],
40 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')],
41 [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')],
42 [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')]
43 ]
44 }
Richard Felkl970e0082018-06-12 18:00:51 +020045}
46
azvyagintsev6dac3802018-11-09 15:11:30 +020047def updateSaltStack(target, pkgs) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +030048 salt.cmdRun(venvPepper, 'I@salt:master', "salt -C '${target}' --async pkg.install force_yes=True pkgs='$pkgs'")
Denis Egorenko4b54e7f2019-02-26 16:05:03 +040049 // can't use same function from pipeline lib, as at the moment of running upgrade pipeline Jenkins
50 // still using pipeline lib from current old mcp-version
azvyagintsev6dac3802018-11-09 15:11:30 +020051 common.retry(20, 60) {
Richard Felkl0e80d892018-06-20 13:44:54 +020052 salt.minionsReachable(venvPepper, 'I@salt:master', '*')
53 def running = salt.runSaltProcessStep(venvPepper, target, 'saltutil.running', [], null, true, 5)
azvyagintsev6dac3802018-11-09 15:11:30 +020054 for (value in running.get("return")[0].values()) {
55 if (value != []) {
Richard Felkl0e80d892018-06-20 13:44:54 +020056 throw new Exception("Not all salt-minions are ready for execution")
57 }
58 }
59 }
60
azvyagintsevf3bf77a2018-11-15 19:30:04 +020061 def saltVersion = salt.getPillar(venvPepper, 'I@salt:master', '_param:salt_version').get('return')[0].values()[0]
Richard Felklf23257e2018-08-06 09:24:23 +020062 def saltMinionVersions = salt.cmdRun(venvPepper, target, "apt-cache policy salt-common | awk '/Installed/ && /$saltVersion/'").get("return")
Richard Felkl0e80d892018-06-20 13:44:54 +020063 def saltMinionVersion = ""
64
azvyagintsev6dac3802018-11-09 15:11:30 +020065 for (minion in saltMinionVersions[0].keySet()) {
66 saltMinionVersion = saltMinionVersions[0].get(minion).replace("Salt command execution success", "").trim()
67 if (saltMinionVersion == "") {
Richard Felkl0e80d892018-06-20 13:44:54 +020068 error("Installed version of Salt on $minion doesn't match specified version in the model.")
69 }
70 }
71}
72
azvyagintsev745a6e52019-04-18 13:19:39 +030073def wa29352(ArrayList saltMinions, String cname) {
74 // WA for PROD-29352. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/12/openssh/client/root.yml
75 // Default soft-param has been removed, what now makes not possible to render some old env's.
76 // Like fix, we found copy-paste already generated key from backups, to secrets.yml with correct key name
77 def wa29352ClassName = 'cluster.' + cname + '.infra.secrets_root_wa29352'
78 def wa29352File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_root_wa29352.yml"
79 def wa29352SecretsFile = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets.yml"
80 def _tempFile = '/tmp/wa29352_' + UUID.randomUUID().toString().take(8)
81 try {
82 salt.cmdRun(venvPepper, 'I@salt:master', "grep -qiv root_private_key ${wa29352SecretsFile}", true, null, false)
83 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29352File}", true, null, false)
84 }
85 catch (Exception ex) {
86 common.infoMsg('Work-around for PROD-29352 already apply, nothing todo')
87 return
88 }
89 def rKeysDict = [
90 'parameters': [
91 '_param': [
92 'root_private_key': salt.getPillar(venvPepper, 'I@salt:master', '_param:root_private_key').get('return')[0].values()[0].trim(),
93 'root_public_key' : '',
94 ]
95 ]
96 ]
97 // save root key,and generate public one from it
98 writeFile file: _tempFile, text: rKeysDict['parameters']['_param']['root_private_key'].toString().trim()
99 sh('chmod 0600 ' + _tempFile)
100 rKeysDict['parameters']['_param']['root_public_key'] = sh(script: "ssh-keygen -q -y -f ${_tempFile}", returnStdout: true).trim()
101 sh('rm -fv ' + _tempFile)
102 writeYaml file: _tempFile, data: rKeysDict
103 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
104 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29352File}", false, null, false)
105 common.infoMsg("Add $wa29352ClassName class into secrets.yml")
106
107 // Add 'classes:' directive
108 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
109 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
110
111 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
112 "grep -q '${wa29352ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29352ClassName' infra/secrets.yml")
113 salt.fullRefresh(venvPepper, '*')
114 sh('rm -fv ' + _tempFile)
115}
116
azvyagintsevbc359d42019-04-10 19:53:22 +0300117def wa29155(ArrayList saltMinions, String cname) {
118 // WA for PROD-29155. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/
119 // CHeck for existence cmp nodes, and try to render it. Is failed, apply ssh-key wa
120 def ret = ''
121 def patched = false
122 def wa29155ClassName = 'cluster.' + cname + '.infra.secrets_nova_wa29155'
123 def wa29155File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_nova_wa29155.yml"
124
125 try {
126 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29155File}", true, null, false)
127 }
128 catch (Exception ex) {
129 common.infoMsg('Work-around for PROD-29155 already apply, nothing todo')
130 return
131 }
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400132 salt.fullRefresh(venvPepper, 'I@salt:master')
133 salt.fullRefresh(venvPepper, 'I@nova:compute')
azvyagintsevbc359d42019-04-10 19:53:22 +0300134 for (String minion in saltMinions) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300135 // First attempt, second will be performed in next validateReclassModel() stages
136 try {
azvyagintsev745a6e52019-04-18 13:19:39 +0300137 salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
azvyagintsevbc359d42019-04-10 19:53:22 +0300138 } catch (Exception e) {
139 common.errorMsg(e.toString())
140 if (patched) {
141 error("Node: ${minion} failed to render after reclass-system upgrade!WA29155 probably didn't help.")
142 }
143 // check, that failed exactly by our case, by key-length check.
144 def missed_key = salt.getPillar(venvPepper, minion, '_param:nova_compute_ssh_private').get("return")[0].values()[0]
145 if (missed_key != '') {
146 error("Node: ${minion} failed to render after reclass-system upgrade!")
147 }
azvyagintsev745a6e52019-04-18 13:19:39 +0300148 common.warningMsg('Perform: Attempt to apply WA for PROD-29155\n' +
149 'See https://gerrit.mcp.mirantis.com/#/c/37932/ for more info')
azvyagintsevbc359d42019-04-10 19:53:22 +0300150 common.warningMsg('WA-PROD-29155 Generating new ssh key at master node')
151 def _tempFile = "/tmp/nova_wa29155_" + UUID.randomUUID().toString().take(8)
152 common.infoMsg('Perform: generation NEW ssh-private key for nova-compute')
153 salt.cmdRun(venvPepper, 'I@salt:master', "ssh-keygen -f ${_tempFile} -N '' -q")
154 def _pub_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}.pub").get('return')[0].values()[0].trim()
155 def _priv_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}").get('return')[0].values()[0].trim()
156 salt.cmdRun(venvPepper, 'I@salt:master', "rm -fv ${_tempFile}", false, null, false)
157 def novaKeysDict = [
158 "parameters": [
159 "_param": [
160 "nova_compute_ssh_private": _priv_k,
161 "nova_compute_ssh_public" : _pub_k
162 ]
163 ]
164 ]
azvyagintsev745a6e52019-04-18 13:19:39 +0300165 writeYaml file: _tempFile, data: novaKeysDict
azvyagintsevbc359d42019-04-10 19:53:22 +0300166 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
167 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29155File}", false, null, false)
168 common.infoMsg("Add $wa29155ClassName class into secrets.yml")
169
170 // Add 'classes:' directive
171 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
172 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
173
174 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
175 "grep -q '${wa29155ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29155ClassName' infra/secrets.yml")
176 salt.fullRefresh(venvPepper, 'cfg*')
177 salt.fullRefresh(venvPepper, 'cmp*')
178 patched = true
179 }
180 }
181 if (patched) {
182 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " +
183 "git add ${wa29155File} && git add -u && git commit --allow-empty -m 'Cluster model updated with WA for PROD-29155. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/ at ${common.getDatetime()}' ")
184 common.infoMsg('Work-around for PROD-29155 successfully applied')
185 }
186
187}
188
Denis Egorenko1b11d232019-07-29 17:44:46 +0400189def wa32284(String clusterName) {
190 def clientGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:enabled").get("return")[0].values()[0]
191 def pkiGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:volumes:salt_pki").get("return")[0].values()[0]
192 def nginxEnabledAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0]
193 if (nginxEnabledAtMaster.toString().toLowerCase() == 'true' && clientGluster.toString().toLowerCase() == 'true' && pkiGluster) {
194 def nginxRequires = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:wait_for_service').get('return')[0].values()[0]
195 if (nginxRequires.isEmpty()) {
196 def nginxRequiresClassName = "cluster.${clusterName}.infra.config.nginx_requires_wa32284"
197 def nginxRequiresClassFile = "/srv/salt/reclass/classes/cluster/${clusterName}/infra/config/nginx_requires_wa32284.yml"
198 def nginxRequiresBlock = ['parameters': ['nginx': ['server': ['wait_for_service': ['srv-salt-pki.mount'] ] ] ] ]
199 def _tempFile = '/tmp/wa32284_' + UUID.randomUUID().toString().take(8)
200 writeYaml file: _tempFile , data: nginxRequiresBlock
201 def nginxRequiresBlockString = sh(script: "cat ${_tempFile}", returnStdout: true).trim()
202 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${clusterName} && " +
203 "sed -i '/^parameters:/i - ${nginxRequiresClassName}' infra/config/init.yml")
204 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${nginxRequiresBlockString}' > ${nginxRequiresClassFile}", false, null, false)
205 }
206 }
207}
208
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400209def wa32182(String cluster_name) {
210 if (salt.testTarget('I@opencontrail:control or I@opencontrail:collector')) {
211 def clusterModelPath = "/srv/salt/reclass/classes/cluster/${cluster_name}"
212 def fixFile = "${clusterModelPath}/opencontrail/common_wa32182.yml"
213 def usualFile = "${clusterModelPath}/opencontrail/common.yml"
214 def fixFileContent = "classes:\n- system.opencontrail.common\n"
215 salt.cmdRun(venvPepper, 'I@salt:master', "test -f ${fixFile} -o -f ${usualFile} || echo '${fixFileContent}' > ${fixFile}")
216 def contrailFiles = ['opencontrail/analytics.yml', 'opencontrail/control.yml', 'openstack/compute/init.yml']
217 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
218 contrailFiles.add('kubernetes/compute.yml')
219 }
220 for(String contrailFile in contrailFiles) {
221 contrailFile = "${clusterModelPath}/${contrailFile}"
222 def containsFix = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- cluster\\.${cluster_name}\\.opencontrail\\.common(_wa32182)?\$' ${contrailFile}", false, null, true).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
223 if (containsFix) {
224 continue
225 } else {
226 salt.cmdRun(venvPepper, 'I@salt:master', "grep -q -E '^parameters:' ${contrailFile} && sed -i '/^parameters:/i - cluster.${cluster_name}.opencontrail.common_wa32182' ${contrailFile} || " +
227 "echo '- cluster.${cluster_name}.opencontrail.common_wa32182' >> ${contrailFile}")
228 }
229 }
230 }
231}
232
azvyagintsev6dac3802018-11-09 15:11:30 +0200233def archiveReclassInventory(filename) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300234 def _tmp_file = '/tmp/' + filename + UUID.randomUUID().toString().take(8)
235 // jenkins may fail at overheap. Compress data with gzip like WA
azvyagintsev745a6e52019-04-18 13:19:39 +0300236 def ret = salt.cmdRun(venvPepper, 'I@salt:master', 'reclass -i 2>/dev/null | gzip -9 -c | base64', true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
azvyagintsevbc359d42019-04-10 19:53:22 +0300237 def _tmp = sh(script: "echo '$ret' > ${_tmp_file}", returnStdout: false)
238 sh(script: "cat ${_tmp_file} | base64 -d | gzip -d > $filename", returnStdout: false)
239 archiveArtifacts artifacts: filename
240 sh(script: "rm -v ${_tmp_file}|| true")
Richard Felkl0e80d892018-06-20 13:44:54 +0200241}
242
Denis Egorenkod13ad132018-12-17 16:56:02 +0400243def validateReclassModel(ArrayList saltMinions, String suffix) {
244 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300245 for (String minion in saltMinions) {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400246 common.infoMsg("Reclass model validation for minion ${minion}...")
azvyagintsev745a6e52019-04-18 13:19:39 +0300247 def reclassInv = salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
Denis Egorenkod13ad132018-12-17 16:56:02 +0400248 writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString()
249 }
250 } catch (Exception e) {
251 common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.')
azvyagintsevbc359d42019-04-10 19:53:22 +0300252 error(e.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400253 }
254}
255
azvyagintsevbc359d42019-04-10 19:53:22 +0300256def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix = 'before', String newSuffix = 'after') {
257 for (String minion in saltMinions) {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400258 def fileName = "reclass-model-${minion}-diff.out"
259 sh "diff -u inventory-${minion}-${oldSuffix}.out inventory-${minion}-${newSuffix}.out > ${fileName} || true"
260 archiveArtifacts artifacts: "${fileName}"
261 }
262}
263
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300264def checkDebsums() {
265 // check for salt-formulas consistency
266 try {
267 try {
268 salt.cmdRun(venvPepper, 'I@salt:master', "salt -C 'I@salt:master' pkg.install force_yes=True pkgs=[debsums]")
269 }
270 catch (Exception ex) {
271 common.warningMsg('Unable to install package "debsums" at cfg01. Salt-formulas integrity check skipped')
272 }
273 salt.cmdRun(venvPepper, 'I@salt:master', '> /root/debdsums_report; for i in $(dpkg-query -W -f=\'${Package}\\n\' | sed "s/ //g" |grep \'salt-formula-\'); do debsums -s ${i} 2>> /root/debdsums_report; done')
274 salt.cmdRun(venvPepper, 'I@salt:master', 'if [ -s "/root/debdsums_report" ]; then exit 1 ; fi')
275 }
276 catch (Exception ex) {
277 common.errorMsg(salt.cmdRun(venvPepper, 'I@salt:master', 'cat /root/debdsums_report ', true, null, false).get('return')[0].values()[0].trim())
278 common.errorMsg(ex.toString())
279 error('You have unexpected changes in formulas. All of them will be overwrited by update. Unable to continue in automatic way')
280 }
281}
282
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400283if (common.validInputParam('PIPELINE_TIMEOUT')) {
284 try {
285 pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger()
azvyagintsevbc359d42019-04-10 19:53:22 +0300286 } catch (Exception e) {
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400287 common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger")
288 }
Martin Polreich965c9032018-08-09 16:33:57 +0200289}
290
291timeout(time: pipelineTimeout, unit: 'HOURS') {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300292 node('python') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100293 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300294 def inventoryBeforeFilename = "reclass-inventory-before.out"
295 def inventoryAfterFilename = "reclass-inventory-after.out"
Richard Felkl0e80d892018-06-20 13:44:54 +0200296 workspace = common.getWorkspace()
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200297 targetMcpVersion = null
298 if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) {
299 error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable')
azvyagintsev6dac3802018-11-09 15:11:30 +0200300 }
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200301 // bw comp. for 2018.X => 2018.11 release
azvyagintsevbc359d42019-04-10 19:53:22 +0300302 if (common.validInputParam('MCP_VERSION')) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200303 targetMcpVersion = env.MCP_VERSION
304 common.warningMsg("targetMcpVersion has been changed to:${targetMcpVersion}, which was taken from deprecated pipeline viriable:MCP_VERSION")
azvyagintsevbc359d42019-04-10 19:53:22 +0300305 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200306 targetMcpVersion = env.TARGET_MCP_VERSION
307 }
308 // end bw comp. for 2018.X => 2018.11 release
Denis Egorenkod13ad132018-12-17 16:56:02 +0400309 def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC')
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400310 if (targetMcpVersion in ['nightly', 'testing']) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200311 gitTargetMcpVersion = 'master'
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400312 } else if (targetMcpVersion == 'proposed') {
313 gitTargetMcpVersion = 'proposed'
Denis Egorenko284690e2018-12-25 15:55:12 +0400314 } else if (!gitTargetMcpVersion) {
315 // backward compatibility for 2018.11.0
316 gitTargetMcpVersion = "release/${targetMcpVersion}"
azvyagintsev6dac3802018-11-09 15:11:30 +0200317 }
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400318 common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}")
Denis Egorenko284690e2018-12-25 15:55:12 +0400319 def saltMastURL = ''
320 def saltMastCreds = ''
321 def upgradeSaltStack = ''
322 def updateClusterModel = ''
323 def updatePipelines = ''
324 def updateLocalRepos = ''
325 def reclassSystemBranch = ''
Denis Egorenko517e06c2019-03-29 13:24:15 +0400326 def reclassSystemBranchDefault = gitTargetMcpVersion
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400327 def batchSize = ''
Denis Egorenko517e06c2019-03-29 13:24:15 +0400328 if (gitTargetMcpVersion != 'proposed') {
329 reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}"
330 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400331 def driteTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS')
Denis Egorenko284690e2018-12-25 15:55:12 +0400332 if (driteTrainParamsYaml) {
333 def driteTrainParams = readYaml text: driteTrainParamsYaml
334 saltMastURL = driteTrainParams.get('SALT_MASTER_URL')
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400335 saltMastCreds = driteTrainParams.get('SALT_MASTER_CREDENTIALS')
Denis Egorenko284690e2018-12-25 15:55:12 +0400336 upgradeSaltStack = driteTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean()
337 updateClusterModel = driteTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean()
338 updatePipelines = driteTrainParams.get('UPDATE_PIPELINES', false).toBoolean()
339 updateLocalRepos = driteTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean()
Denis Egorenko517e06c2019-03-29 13:24:15 +0400340 reclassSystemBranch = driteTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault)
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400341 batchSize = driveTrainParams.get('BATCH_SIZE', '')
Denis Egorenko284690e2018-12-25 15:55:12 +0400342 } else {
343 // backward compatibility for 2018.11.0
344 saltMastURL = env.getProperty('SALT_MASTER_URL')
345 saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS')
Denis Egorenkoe5f39142018-12-28 12:30:48 +0400346 upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean()
347 updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean()
348 updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean()
349 updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean()
Denis Egorenko517e06c2019-03-29 13:24:15 +0400350 reclassSystemBranch = reclassSystemBranchDefault
Denis Egorenko284690e2018-12-25 15:55:12 +0400351 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400352 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400353 def minions = salt.getMinions(venvPepper, '*')
Denis Egorenkofbcee412019-04-19 15:05:18 +0400354 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
355 if (cluster_name == '' || cluster_name == 'null' || cluster_name == null) {
356 error('Pillar data is broken for Salt master node! Please check it manually and re-run pipeline.')
357 }
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400358 if (!batch_size) {
359 def workerThreads = salt.getReturnValues(salt.getPillar(venvPepper, "I@salt:master", "salt:master:worker_threads", null))
360 if (workerThreads.isInteger() && workerThreads.toInteger() > 0) {
361 batch_size = workerThreads
362 }
363 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400364
azvyagintsevbc359d42019-04-10 19:53:22 +0300365 stage('Update Reclass and Salt-Formulas') {
366 common.infoMsg('Perform: Full salt sync')
367 salt.fullRefresh(venvPepper, '*')
368 common.infoMsg('Perform: Validate reclass medata before processing')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400369 validateReclassModel(minions, 'before')
370
azvyagintsev745a6e52019-04-18 13:19:39 +0300371 common.infoMsg('Perform: archiveReclassInventory before upgrade')
372 archiveReclassInventory(inventoryBeforeFilename)
373
azvyagintsev6dac3802018-11-09 15:11:30 +0200374 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300375 salt.cmdRun(venvPepper, 'I@salt:master', 'cd /srv/salt/reclass/ && git status && git diff-index --quiet HEAD --')
Richard Felkl970e0082018-06-12 18:00:51 +0200376 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200377 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300378 error('You have uncommitted changes in your Reclass cluster model repository. Please commit or reset them and rerun the pipeline.')
Richard Felkl970e0082018-06-12 18:00:51 +0200379 }
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300380 checkDebsums()
Denis Egorenkod13ad132018-12-17 16:56:02 +0400381 if (updateClusterModel) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200382 common.infoMsg('Perform: UPDATE_CLUSTER_MODEL')
Sergey382581a2018-10-25 12:22:26 +0400383 def dateTime = common.getDatetime()
Denis Egorenko20254e72019-03-18 15:47:33 +0400384 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/ && git submodule foreach git fetch")
Sergey382581a2018-10-25 12:22:26 +0400385 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400386 "grep -r --exclude-dir=aptly -l 'mcp_version: .*' * | xargs --no-run-if-empty sed -i 's|mcp_version: .*|mcp_version: \"$targetMcpVersion\"|g'")
azvyagintsev6dac3802018-11-09 15:11:30 +0200387 // Do the same, for deprecated variable-duplicate
388 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400389 "grep -r --exclude-dir=aptly -l 'apt_mk_version: .*' * | xargs --no-run-if-empty sed -i 's|apt_mk_version: .*|apt_mk_version: \"$targetMcpVersion\"|g'")
Denis Egorenko284690e2018-12-25 15:55:12 +0400390 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400391 "grep -r --exclude-dir=aptly -l 'jenkins_pipelines_branch: .*' * | xargs --no-run-if-empty sed -i 's|jenkins_pipelines_branch: .*|jenkins_pipelines_branch: \"$gitTargetMcpVersion\"|g'")
Victor Ryzhenkinabbefe62019-01-15 19:58:03 +0400392 // Set new k8s param
393 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
394 "grep -r --exclude-dir=aptly -l 'kubernetes_containerd_enabled: .*' * | xargs --no-run-if-empty sed -i 's|kubernetes_containerd_enabled: .*|kubernetes_containerd_enabled: True|g'")
Denis Egorenkoe5b49512019-01-16 19:18:31 +0400395 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
396 "grep -r --exclude-dir=aptly -l 'system.linux.system.repo.mcp.salt' * | xargs --no-run-if-empty sed -i 's/system.linux.system.repo.mcp.salt/system.linux.system.repo.mcp.apt_mirantis.salt-formulas/g'")
397 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko301cc8a2019-02-13 13:49:13 +0400398 "grep -r --exclude-dir=aptly -l 'system.linux.system.repo.mcp.contrail' * | xargs --no-run-if-empty sed -i 's/system.linux.system.repo.mcp.contrail/system.linux.system.repo.mcp.apt_mirantis.contrail/g'")
Denis Egorenkoe5b49512019-01-16 19:18:31 +0400399 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko301cc8a2019-02-13 13:49:13 +0400400 "grep -r --exclude-dir=aptly -l 'system.linux.system.repo.mcp.updates' * | xargs --no-run-if-empty sed -i 's/system.linux.system.repo.mcp.updates/system.linux.system.repo.mcp.apt_mirantis.update/g'")
Anton Samoylov308c7ca2019-02-13 15:57:13 +0400401 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsevbc359d42019-04-10 19:53:22 +0300402 "grep -r --exclude-dir=aptly -l 'system.linux.system.repo.mcp.extra' * | xargs --no-run-if-empty sed -i 's/system.linux.system.repo.mcp.extra/system.linux.system.repo.mcp.apt_mirantis.extra/g'")
Denis Egorenko21c78be2019-07-10 19:47:39 +0400403
404 // Switch Jenkins/Gerrit to use LDAP SSL/TLS
405 def gerritldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
406 "grep -r --exclude-dir=aptly 'gerrit_ldap_server: .*' * | grep -Po 'gerrit_ldap_server: \\K.*' | tr -d '\"'", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
407 if (gerritldapURI.startsWith('ldap://')) {
408 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
409 "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
410 } else if (! gerritldapURI.startsWith('ldaps://')) {
411 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
412 "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|gerrit_ldap_server: .*|gerrit_ldap_server: \"ldaps://${gerritldapURI}\"|g'")
413 }
414 def jenkinsldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
415 "grep -r --exclude-dir=aptly 'jenkins_security_ldap_server: .*' * | grep -Po 'jenkins_security_ldap_server: \\K.*' | tr -d '\"'", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
416 if (jenkinsldapURI.startsWith('ldap://')) {
417 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
418 "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
419 } else if (! jenkinsldapURI.startsWith('ldaps://')) {
420 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
421 "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|jenkins_security_ldap_server: .*|jenkins_security_ldap_server: \"ldaps://${jenkinsldapURI}\"|g'")
422 }
423
Denis Egorenko1b11d232019-07-29 17:44:46 +0400424 wa32284(cluster_name)
425
Denis Egorenkod13ad132018-12-17 16:56:02 +0400426 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}")
Sergey Kolekonov5dfbf7a2019-01-23 16:47:43 +0400427 // Add kubernetes-extra repo
428 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
Sergey Kolekonov3fde8b12019-04-11 16:33:54 +0400429 // docker-engine conflicts with the recent containerd versions, so it's removed during upgrade. Thus update source engine
430 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
431 "grep -r -l 'engine: docker_hybrid' kubernetes | xargs --no-run-if-empty sed -i 's/engine: docker_hybrid/engine: archive/g'")
Sergey Kolekonov5dfbf7a2019-01-23 16:47:43 +0400432 common.infoMsg("Add kubernetes-extra repo")
433 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
434 "grep -q system.linux.system.repo.mcp.apt_mirantis.update.kubernetes_extra kubernetes/common.yml || sed -i '/classes:/ a - system.linux.system.repo.mcp.apt_mirantis.update.kubernetes_extra' kubernetes/common.yml")
435 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
436 "grep -q system.linux.system.repo.mcp.apt_mirantis.kubernetes_extra kubernetes/common.yml || sed -i '/classes:/ a - system.linux.system.repo.mcp.apt_mirantis.kubernetes_extra' kubernetes/common.yml")
437 }
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400438 // Add all update repositories
439 def repoIncludeBase = '- system.linux.system.repo.mcp.apt_mirantis.'
azvyagintsevbc359d42019-04-10 19:53:22 +0300440 def updateRepoList = ['cassandra', 'ceph', 'contrail', 'docker', 'elastic', 'extra', 'openstack', 'percona', 'salt-formulas', 'saltstack', 'ubuntu']
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400441 updateRepoList.each { repo ->
442 def repoNameUpdateInclude = "${repoIncludeBase}update.${repo}"
443 def filesWithInclude = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && grep -Plr '\\${repoIncludeBase}${repo}\$' . || true", false).get('return')[0].values()[0].trim().tokenize('\n')
444 filesWithInclude.each { file ->
445 def updateRepoIncludeExist = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && grep -P '\\${repoNameUpdateInclude}\$' ${file} || echo not_found", false, null, true).get('return')[0].values()[0].trim()
446 if (updateRepoIncludeExist == 'not_found') {
447 // Include needs to be added
448 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsevbc359d42019-04-10 19:53:22 +0300449 "sed -i 's/\\( *\\)${repoIncludeBase}${repo}\$/&\\n\\1${repoNameUpdateInclude}/g' ${file}")
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400450 common.infoMsg("Update repo for ${repo} is added to ${file}")
451 }
452 }
453 }
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400454 wa32182(cluster_name)
Sergey382581a2018-10-25 12:22:26 +0400455 // Add new defaults
456 common.infoMsg("Add new defaults")
Denis Egorenkod13ad132018-12-17 16:56:02 +0400457 salt.cmdRun(venvPepper, 'I@salt:master', "grep '^ mcp_version: ' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400458 "sed -i 's|^ _param:| _param:\\n mcp_version: \"$targetMcpVersion\"|' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml")
Sergey382581a2018-10-25 12:22:26 +0400459 salt.cmdRun(venvPepper, 'I@salt:master', "grep '^- system.defaults\$' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400460 "sed -i 's|^classes:|classes:\\n- system.defaults|' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml")
Ivan Berezovskiy5113c7c2019-04-23 14:32:02 +0400461 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300462 "grep -r -l 'docker_image_jenkins: .*' cicd | xargs --no-run-if-empty sed -i 's|\\s*docker_image_jenkins: .*||g'")
Ivan Berezovskiy5113c7c2019-04-23 14:32:02 +0400463 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300464 "grep -r -l 'docker_image_jenkins_slave: .*' cicd | xargs --no-run-if-empty sed -i 's|\\s*docker_image_jenkins_slave: .*||g'")
Sergey382581a2018-10-25 12:22:26 +0400465 common.infoMsg("The following changes were made to the cluster model and will be commited. " +
azvyagintsev6dac3802018-11-09 15:11:30 +0200466 "Please consider if you want to push them to the remote repository or not. You have to do this manually when the run is finished.")
Sergey382581a2018-10-25 12:22:26 +0400467 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff")
468 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " +
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200469 "git add -u && git commit --allow-empty -m 'Cluster model update to the release $targetMcpVersion on $dateTime'")
Sergey382581a2018-10-25 12:22:26 +0400470 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400471 try {
472 common.infoMsg('Perform: UPDATE Salt Formulas')
azvyagintsevca97a112019-04-22 17:53:40 +0300473 salt.fullRefresh(venvPepper, '*')
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400474 salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400475 def saltEnv = salt.getPillar(venvPepper, 'I@salt:master', "_param:salt_master_base_environment").get("return")[0].values()[0]
azvyagintsevbc359d42019-04-10 19:53:22 +0300476 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas", 'salt.master.env'])
azvyagintsevca97a112019-04-22 17:53:40 +0300477 salt.fullRefresh(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400478 } catch (Exception updateErr) {
479 common.warningMsg(updateErr)
480 common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
481 input message: 'Continue anyway?'
482 }
483
azvyagintsev745a6e52019-04-18 13:19:39 +0300484 wa29352(minions, cluster_name)
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400485 def computeMinions = salt.getMinions(venvPepper, 'I@nova:compute')
486 wa29155(computeMinions, cluster_name)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400487
488 try {
489 common.infoMsg('Perform: UPDATE Reclass package')
490 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"])
491 } catch (Exception updateErr) {
492 common.warningMsg(updateErr)
493 common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
494 input message: 'Continue anyway?'
495 }
496
497 salt.fullRefresh(venvPepper, 'I@salt:master')
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400498 salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400499 try {
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400500 salt.enforceState(venvPepper, 'I@salt:master', 'reclass', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400501 }
502 catch (Exception ex) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300503 common.errorMsg(ex.toString())
504 error('Reclass fails rendering. Pay attention to your cluster model.')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400505 }
506
507 salt.fullRefresh(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400508 try {
509 salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top")
510 }
511 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300512
513 error('Reclass fails rendering. Pay attention to your cluster model.' +
514 'ErrorMessage:' + ex.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400515 }
516
azvyagintsevbc359d42019-04-10 19:53:22 +0300517 common.infoMsg('Perform: archiveReclassInventory AFTER upgrade')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400518 archiveReclassInventory(inventoryAfterFilename)
519
520 sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true"
521 archiveArtifacts artifacts: "reclass-inventory-diff.out"
522
523 validateReclassModel(minions, 'after')
524 archiveReclassModelChanges(minions)
Jakub Josefa63f9862018-01-11 17:58:38 +0100525 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100526
Denis Egorenkod13ad132018-12-17 16:56:02 +0400527 if (updateLocalRepos) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200528 stage("Update local repos") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100529 common.infoMsg("Updating local repositories")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700530
Sergey1b81c062018-10-16 17:10:21 +0400531 def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700532 runningOnDocker = engine.get("return")[0].containsValue("docker")
533
534 if (runningOnDocker) {
535 common.infoMsg("Aptly is running as Docker container")
azvyagintsev6dac3802018-11-09 15:11:30 +0200536 } else {
Sam Stoelingaaab79702018-04-09 18:49:39 -0700537 common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands")
538 }
539
azvyagintsev6dac3802018-11-09 15:11:30 +0200540 if (runningOnDocker) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200541 salt.cmdRun(venvPepper, 'I@aptly:publisher', "aptly mirror list --raw | grep -E '*' | xargs --no-run-if-empty -n 1 aptly mirror drop -force", true, null, true)
azvyagintsev6dac3802018-11-09 15:11:30 +0200542 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200543 salt.cmdRun(venvPepper, 'I@aptly:publisher', "aptly mirror list --raw | grep -E '*' | xargs --no-run-if-empty -n 1 aptly mirror drop -force", true, null, true, ['runas=aptly'])
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100544 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100545
Sergey1b81c062018-10-16 17:10:21 +0400546 salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100547
azvyagintsev6dac3802018-11-09 15:11:30 +0200548 if (runningOnDocker) {
Sergey1b81c062018-10-16 17:10:21 +0400549 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true)
550 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=-frv -u http://10.99.0.1:8080"], null, true)
azvyagintsev6dac3802018-11-09 15:11:30 +0200551 } else {
Sergey1b81c062018-10-16 17:10:21 +0400552 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true)
553 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=-afrv", 'runas=aptly'], null, true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100554 }
Richard Felkl79d7df12018-01-05 16:40:11 +0100555
Sergey1b81c062018-10-16 17:10:21 +0400556 salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100557
Sergey1b81c062018-10-16 17:10:21 +0400558 salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100559
Sergey1b81c062018-10-16 17:10:21 +0400560 salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100561
Sergey1b81c062018-10-16 17:10:21 +0400562 salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100563 }
564 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100565
azvyagintsevbc359d42019-04-10 19:53:22 +0300566 stage('Update Drivetrain') {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400567 if (upgradeSaltStack) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300568 updateSaltStack('I@salt:master', '["salt-master", "salt-common", "salt-api", "salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200569
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400570 salt.enforceState(venvPepper, 'I@linux:system', 'linux.system.repo', true, true, batchSize, false, 60, 2)
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300571 updateSaltStack('I@salt:minion and not I@salt:master', '["salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200572 }
573
Denis Egorenkod13ad132018-12-17 16:56:02 +0400574 if (updatePipelines) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300575 common.infoMsg('Perform: UPDATE git repos')
576 triggerMirrorJob('git-mirror-downstream-mk-pipelines', reclassSystemBranch)
577 triggerMirrorJob('git-mirror-downstream-pipeline-library', reclassSystemBranch)
Richard Felkl970e0082018-06-12 18:00:51 +0200578 }
579
Denis Egorenko7a4cf032019-04-25 20:48:26 +0400580 // update minions certs
Denis Egorenkoaf3a2202019-04-26 15:13:16 +0400581 // call for `salt.minion.ca` state on related nodes to make sure
582 // mine was updated with required data after salt-minion/salt-master restart salt:minion:ca
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400583 salt.enforceState(venvPepper, 'I@salt:minion:ca', 'salt.minion.ca', true, true, batchSize, false, 60, 2)
584 salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion.cert', true, true, batchSize, false, 60, 2)
Denis Egorenko7a4cf032019-04-25 20:48:26 +0400585
Ann Kamyshnikovae8910112019-05-06 12:56:38 +0400586 // run `salt.minion` to refresh all minion configs (for example _keystone.conf)
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400587 salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion', true, true, null, false, 60, 2)
azvyagintsevbc359d42019-04-10 19:53:22 +0300588 // Retry needed only for rare race-condition in user appearance
589 common.infoMsg('Perform: updating users and keys')
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400590 salt.enforceState(venvPepper, 'I@linux:system', 'linux.system.user', true, true, batchSize, false, 60, 2)
azvyagintsevbc359d42019-04-10 19:53:22 +0300591 common.infoMsg('Perform: updating openssh')
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400592 salt.enforceState(venvPepper, 'I@linux:system', 'openssh', true, true, batchSize, false, 60, 2)
Denis Egorenko65cf2a42019-01-15 11:58:12 +0400593
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300594 // apply salt API TLS if needed
595 def nginxAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0]
596 if (nginxAtMaster.toString().toLowerCase() == 'true') {
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400597 salt.enforceState(venvPepper, 'I@salt:master', 'nginx', true, true, null, false, 60, 2)
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300598 }
599
Denis Egorenkobc440322019-07-09 18:55:35 +0400600 // Apply changes for HaProxy on CI/CD nodes
601 salt.enforceState(venvPepper, 'I@keepalived:cluster:instance:cicd_control_vip and I@haproxy:proxy', 'haproxy.proxy', true)
602
Denis Egorenko21c78be2019-07-10 19:47:39 +0400603 salt.cmdRun(venvPepper, "I@salt:master", "salt -C 'I@jenkins:client and I@docker:client and not I@salt:master' state.sls docker.client --async")
Richard Felkl970e0082018-06-12 18:00:51 +0200604
605 sleep(180)
606
azvyagintsevbc359d42019-04-10 19:53:22 +0300607 common.infoMsg('Perform: Checking if Docker containers are up')
Richard Felkl970e0082018-06-12 18:00:51 +0200608
azvyagintsev6dac3802018-11-09 15:11:30 +0200609 try {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300610 common.retry(20, 30) {
Richard Felkl970e0082018-06-12 18:00:51 +0200611 salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'")
612 }
613 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200614 catch (Exception ex) {
Richard Felkl970e0082018-06-12 18:00:51 +0200615 error("Docker containers for CI/CD services are having troubles with starting.")
616 }
Denis Egorenko21c78be2019-07-10 19:47:39 +0400617
618 salt.enforceState(venvPepper, 'I@jenkins:client and not I@salt:master', 'jenkins.client', true, true, null, false, 60, 2)
Denis Egorenko312bcd42019-07-23 17:59:13 +0400619
620 // update Nginx proxy settings for Jenkins/Gerrit if needed
621 if (salt.testTarget(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit')) {
622 salt.enforceState(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit', 'nginx.server', true, true, null, false, 60, 2)
623 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100624 }
625 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100626 catch (Throwable e) {
627 // If there was an error or exception thrown, the build failed
628 currentBuild.result = "FAILURE"
629 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +0100630 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100631 }
Jakub Josef2c21c6c2018-02-08 18:51:42 +0100632}