blob: 218aafefaf657273a9c295788a4dfa8acbeca8d6 [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
11 * UPGRADE_SALTSTACK Upgrade SaltStack packages to new version.
12 * UPDATE_CLUSTER_MODEL Update MCP version parameter in cluster model
13 * UPDATE_PIPELINES Update pipeline repositories on Gerrit
14 * UPDATE_LOCAL_REPOS Update local repositories
Richard Felkl26cae4d2017-12-19 00:19:16 +010015 */
16
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010017salt = new com.mirantis.mk.Salt()
18common = new com.mirantis.mk.Common()
19python = new com.mirantis.mk.Python()
Richard Felkl970e0082018-06-12 18:00:51 +020020jenkinsUtils = new com.mirantis.mk.JenkinsUtils()
azvyagintsevf3bf77a2018-11-15 19:30:04 +020021def pipelineTimeout = 12
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010022venvPepper = "venvPepper"
Richard Felkl0e80d892018-06-20 13:44:54 +020023workspace = ""
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010024
azvyagintsevbc359d42019-04-10 19:53:22 +030025def triggerMirrorJob(String jobName, String reclassSystemBranch) {
Richard Felkl970e0082018-06-12 18:00:51 +020026 params = jenkinsUtils.getJobParameters(jobName)
azvyagintsevbc359d42019-04-10 19:53:22 +030027 try {
28 build job: jobName, parameters: [
29 [$class: 'StringParameterValue', name: 'BRANCHES', value: params.get('BRANCHES')],
30 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')],
31 [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')],
32 [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')]
33 ]
34 } catch (Exception updateErr) {
35 common.warningMsg(updateErr)
36 common.warningMsg('Attempt to update git repo in failsafe manner')
37 build job: jobName, parameters: [
38 [$class: 'StringParameterValue', name: 'BRANCHES', value: reclassSystemBranch.replace('origin/', '')],
39 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')],
40 [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')],
41 [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')]
42 ]
43 }
Richard Felkl970e0082018-06-12 18:00:51 +020044}
45
azvyagintsev6dac3802018-11-09 15:11:30 +020046def updateSaltStack(target, pkgs) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +030047 salt.cmdRun(venvPepper, 'I@salt:master', "salt -C '${target}' --async pkg.install force_yes=True pkgs='$pkgs'")
Denis Egorenko4b54e7f2019-02-26 16:05:03 +040048 // can't use same function from pipeline lib, as at the moment of running upgrade pipeline Jenkins
49 // still using pipeline lib from current old mcp-version
azvyagintsev6dac3802018-11-09 15:11:30 +020050 common.retry(20, 60) {
Richard Felkl0e80d892018-06-20 13:44:54 +020051 salt.minionsReachable(venvPepper, 'I@salt:master', '*')
52 def running = salt.runSaltProcessStep(venvPepper, target, 'saltutil.running', [], null, true, 5)
azvyagintsev6dac3802018-11-09 15:11:30 +020053 for (value in running.get("return")[0].values()) {
54 if (value != []) {
Richard Felkl0e80d892018-06-20 13:44:54 +020055 throw new Exception("Not all salt-minions are ready for execution")
56 }
57 }
58 }
59
azvyagintsevf3bf77a2018-11-15 19:30:04 +020060 def saltVersion = salt.getPillar(venvPepper, 'I@salt:master', '_param:salt_version').get('return')[0].values()[0]
Richard Felklf23257e2018-08-06 09:24:23 +020061 def saltMinionVersions = salt.cmdRun(venvPepper, target, "apt-cache policy salt-common | awk '/Installed/ && /$saltVersion/'").get("return")
Richard Felkl0e80d892018-06-20 13:44:54 +020062 def saltMinionVersion = ""
63
azvyagintsev6dac3802018-11-09 15:11:30 +020064 for (minion in saltMinionVersions[0].keySet()) {
65 saltMinionVersion = saltMinionVersions[0].get(minion).replace("Salt command execution success", "").trim()
66 if (saltMinionVersion == "") {
Richard Felkl0e80d892018-06-20 13:44:54 +020067 error("Installed version of Salt on $minion doesn't match specified version in the model.")
68 }
69 }
70}
71
azvyagintsev745a6e52019-04-18 13:19:39 +030072def wa29352(ArrayList saltMinions, String cname) {
73 // WA for PROD-29352. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/12/openssh/client/root.yml
74 // Default soft-param has been removed, what now makes not possible to render some old env's.
75 // Like fix, we found copy-paste already generated key from backups, to secrets.yml with correct key name
76 def wa29352ClassName = 'cluster.' + cname + '.infra.secrets_root_wa29352'
77 def wa29352File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_root_wa29352.yml"
78 def wa29352SecretsFile = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets.yml"
79 def _tempFile = '/tmp/wa29352_' + UUID.randomUUID().toString().take(8)
80 try {
81 salt.cmdRun(venvPepper, 'I@salt:master', "grep -qiv root_private_key ${wa29352SecretsFile}", true, null, false)
82 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29352File}", true, null, false)
83 }
84 catch (Exception ex) {
85 common.infoMsg('Work-around for PROD-29352 already apply, nothing todo')
86 return
87 }
88 def rKeysDict = [
89 'parameters': [
90 '_param': [
91 'root_private_key': salt.getPillar(venvPepper, 'I@salt:master', '_param:root_private_key').get('return')[0].values()[0].trim(),
92 'root_public_key' : '',
93 ]
94 ]
95 ]
96 // save root key,and generate public one from it
97 writeFile file: _tempFile, text: rKeysDict['parameters']['_param']['root_private_key'].toString().trim()
98 sh('chmod 0600 ' + _tempFile)
99 rKeysDict['parameters']['_param']['root_public_key'] = sh(script: "ssh-keygen -q -y -f ${_tempFile}", returnStdout: true).trim()
100 sh('rm -fv ' + _tempFile)
101 writeYaml file: _tempFile, data: rKeysDict
102 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
103 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29352File}", false, null, false)
104 common.infoMsg("Add $wa29352ClassName class into secrets.yml")
105
106 // Add 'classes:' directive
107 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
108 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
109
110 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
111 "grep -q '${wa29352ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29352ClassName' infra/secrets.yml")
112 salt.fullRefresh(venvPepper, '*')
113 sh('rm -fv ' + _tempFile)
114}
115
azvyagintsevbc359d42019-04-10 19:53:22 +0300116def wa29155(ArrayList saltMinions, String cname) {
117 // WA for PROD-29155. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/
118 // CHeck for existence cmp nodes, and try to render it. Is failed, apply ssh-key wa
119 def ret = ''
120 def patched = false
121 def wa29155ClassName = 'cluster.' + cname + '.infra.secrets_nova_wa29155'
122 def wa29155File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_nova_wa29155.yml"
123
124 try {
125 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29155File}", true, null, false)
126 }
127 catch (Exception ex) {
128 common.infoMsg('Work-around for PROD-29155 already apply, nothing todo')
129 return
130 }
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400131 salt.fullRefresh(venvPepper, 'I@salt:master')
132 salt.fullRefresh(venvPepper, 'I@nova:compute')
azvyagintsevbc359d42019-04-10 19:53:22 +0300133 for (String minion in saltMinions) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300134 // First attempt, second will be performed in next validateReclassModel() stages
135 try {
azvyagintsev745a6e52019-04-18 13:19:39 +0300136 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 +0300137 } catch (Exception e) {
138 common.errorMsg(e.toString())
139 if (patched) {
140 error("Node: ${minion} failed to render after reclass-system upgrade!WA29155 probably didn't help.")
141 }
142 // check, that failed exactly by our case, by key-length check.
143 def missed_key = salt.getPillar(venvPepper, minion, '_param:nova_compute_ssh_private').get("return")[0].values()[0]
144 if (missed_key != '') {
145 error("Node: ${minion} failed to render after reclass-system upgrade!")
146 }
azvyagintsev745a6e52019-04-18 13:19:39 +0300147 common.warningMsg('Perform: Attempt to apply WA for PROD-29155\n' +
148 'See https://gerrit.mcp.mirantis.com/#/c/37932/ for more info')
azvyagintsevbc359d42019-04-10 19:53:22 +0300149 common.warningMsg('WA-PROD-29155 Generating new ssh key at master node')
150 def _tempFile = "/tmp/nova_wa29155_" + UUID.randomUUID().toString().take(8)
151 common.infoMsg('Perform: generation NEW ssh-private key for nova-compute')
152 salt.cmdRun(venvPepper, 'I@salt:master', "ssh-keygen -f ${_tempFile} -N '' -q")
153 def _pub_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}.pub").get('return')[0].values()[0].trim()
154 def _priv_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}").get('return')[0].values()[0].trim()
155 salt.cmdRun(venvPepper, 'I@salt:master', "rm -fv ${_tempFile}", false, null, false)
156 def novaKeysDict = [
157 "parameters": [
158 "_param": [
159 "nova_compute_ssh_private": _priv_k,
160 "nova_compute_ssh_public" : _pub_k
161 ]
162 ]
163 ]
azvyagintsev745a6e52019-04-18 13:19:39 +0300164 writeYaml file: _tempFile, data: novaKeysDict
azvyagintsevbc359d42019-04-10 19:53:22 +0300165 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
166 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29155File}", false, null, false)
167 common.infoMsg("Add $wa29155ClassName class into secrets.yml")
168
169 // Add 'classes:' directive
170 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
171 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
172
173 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
174 "grep -q '${wa29155ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29155ClassName' infra/secrets.yml")
175 salt.fullRefresh(venvPepper, 'cfg*')
176 salt.fullRefresh(venvPepper, 'cmp*')
177 patched = true
178 }
179 }
180 if (patched) {
181 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " +
182 "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()}' ")
183 common.infoMsg('Work-around for PROD-29155 successfully applied')
184 }
185
186}
187
Denis Egorenko1b11d232019-07-29 17:44:46 +0400188def wa32284(String clusterName) {
189 def clientGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:enabled").get("return")[0].values()[0]
190 def pkiGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:volumes:salt_pki").get("return")[0].values()[0]
191 def nginxEnabledAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0]
192 if (nginxEnabledAtMaster.toString().toLowerCase() == 'true' && clientGluster.toString().toLowerCase() == 'true' && pkiGluster) {
193 def nginxRequires = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:wait_for_service').get('return')[0].values()[0]
194 if (nginxRequires.isEmpty()) {
195 def nginxRequiresClassName = "cluster.${clusterName}.infra.config.nginx_requires_wa32284"
196 def nginxRequiresClassFile = "/srv/salt/reclass/classes/cluster/${clusterName}/infra/config/nginx_requires_wa32284.yml"
197 def nginxRequiresBlock = ['parameters': ['nginx': ['server': ['wait_for_service': ['srv-salt-pki.mount'] ] ] ] ]
198 def _tempFile = '/tmp/wa32284_' + UUID.randomUUID().toString().take(8)
199 writeYaml file: _tempFile , data: nginxRequiresBlock
200 def nginxRequiresBlockString = sh(script: "cat ${_tempFile}", returnStdout: true).trim()
201 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${clusterName} && " +
202 "sed -i '/^parameters:/i - ${nginxRequiresClassName}' infra/config/init.yml")
203 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${nginxRequiresBlockString}' > ${nginxRequiresClassFile}", false, null, false)
204 }
205 }
206}
207
azvyagintsev6dac3802018-11-09 15:11:30 +0200208def archiveReclassInventory(filename) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300209 def _tmp_file = '/tmp/' + filename + UUID.randomUUID().toString().take(8)
210 // jenkins may fail at overheap. Compress data with gzip like WA
azvyagintsev745a6e52019-04-18 13:19:39 +0300211 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 +0300212 def _tmp = sh(script: "echo '$ret' > ${_tmp_file}", returnStdout: false)
213 sh(script: "cat ${_tmp_file} | base64 -d | gzip -d > $filename", returnStdout: false)
214 archiveArtifacts artifacts: filename
215 sh(script: "rm -v ${_tmp_file}|| true")
Richard Felkl0e80d892018-06-20 13:44:54 +0200216}
217
Denis Egorenkod13ad132018-12-17 16:56:02 +0400218def validateReclassModel(ArrayList saltMinions, String suffix) {
219 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300220 for (String minion in saltMinions) {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400221 common.infoMsg("Reclass model validation for minion ${minion}...")
azvyagintsev745a6e52019-04-18 13:19:39 +0300222 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 +0400223 writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString()
224 }
225 } catch (Exception e) {
226 common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.')
azvyagintsevbc359d42019-04-10 19:53:22 +0300227 error(e.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400228 }
229}
230
azvyagintsevbc359d42019-04-10 19:53:22 +0300231def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix = 'before', String newSuffix = 'after') {
232 for (String minion in saltMinions) {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400233 def fileName = "reclass-model-${minion}-diff.out"
234 sh "diff -u inventory-${minion}-${oldSuffix}.out inventory-${minion}-${newSuffix}.out > ${fileName} || true"
235 archiveArtifacts artifacts: "${fileName}"
236 }
237}
238
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300239def checkDebsums() {
240 // check for salt-formulas consistency
241 try {
242 try {
243 salt.cmdRun(venvPepper, 'I@salt:master', "salt -C 'I@salt:master' pkg.install force_yes=True pkgs=[debsums]")
244 }
245 catch (Exception ex) {
246 common.warningMsg('Unable to install package "debsums" at cfg01. Salt-formulas integrity check skipped')
247 }
248 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')
249 salt.cmdRun(venvPepper, 'I@salt:master', 'if [ -s "/root/debdsums_report" ]; then exit 1 ; fi')
250 }
251 catch (Exception ex) {
252 common.errorMsg(salt.cmdRun(venvPepper, 'I@salt:master', 'cat /root/debdsums_report ', true, null, false).get('return')[0].values()[0].trim())
253 common.errorMsg(ex.toString())
254 error('You have unexpected changes in formulas. All of them will be overwrited by update. Unable to continue in automatic way')
255 }
256}
257
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400258if (common.validInputParam('PIPELINE_TIMEOUT')) {
259 try {
260 pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger()
azvyagintsevbc359d42019-04-10 19:53:22 +0300261 } catch (Exception e) {
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400262 common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger")
263 }
Martin Polreich965c9032018-08-09 16:33:57 +0200264}
265
266timeout(time: pipelineTimeout, unit: 'HOURS') {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300267 node('python') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100268 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300269 def inventoryBeforeFilename = "reclass-inventory-before.out"
270 def inventoryAfterFilename = "reclass-inventory-after.out"
Richard Felkl0e80d892018-06-20 13:44:54 +0200271 workspace = common.getWorkspace()
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200272 targetMcpVersion = null
273 if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) {
274 error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable')
azvyagintsev6dac3802018-11-09 15:11:30 +0200275 }
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200276 // bw comp. for 2018.X => 2018.11 release
azvyagintsevbc359d42019-04-10 19:53:22 +0300277 if (common.validInputParam('MCP_VERSION')) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200278 targetMcpVersion = env.MCP_VERSION
279 common.warningMsg("targetMcpVersion has been changed to:${targetMcpVersion}, which was taken from deprecated pipeline viriable:MCP_VERSION")
azvyagintsevbc359d42019-04-10 19:53:22 +0300280 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200281 targetMcpVersion = env.TARGET_MCP_VERSION
282 }
283 // end bw comp. for 2018.X => 2018.11 release
Denis Egorenkod13ad132018-12-17 16:56:02 +0400284 def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC')
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400285 if (targetMcpVersion in ['nightly', 'testing']) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200286 gitTargetMcpVersion = 'master'
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400287 } else if (targetMcpVersion == 'proposed') {
288 gitTargetMcpVersion = 'proposed'
Denis Egorenko284690e2018-12-25 15:55:12 +0400289 } else if (!gitTargetMcpVersion) {
290 // backward compatibility for 2018.11.0
291 gitTargetMcpVersion = "release/${targetMcpVersion}"
azvyagintsev6dac3802018-11-09 15:11:30 +0200292 }
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400293 common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}")
Denis Egorenko284690e2018-12-25 15:55:12 +0400294 def saltMastURL = ''
295 def saltMastCreds = ''
296 def upgradeSaltStack = ''
297 def updateClusterModel = ''
298 def updatePipelines = ''
299 def updateLocalRepos = ''
300 def reclassSystemBranch = ''
Denis Egorenko517e06c2019-03-29 13:24:15 +0400301 def reclassSystemBranchDefault = gitTargetMcpVersion
302 if (gitTargetMcpVersion != 'proposed') {
303 reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}"
304 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400305 def driteTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS')
Denis Egorenko284690e2018-12-25 15:55:12 +0400306 if (driteTrainParamsYaml) {
307 def driteTrainParams = readYaml text: driteTrainParamsYaml
308 saltMastURL = driteTrainParams.get('SALT_MASTER_URL')
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400309 saltMastCreds = driteTrainParams.get('SALT_MASTER_CREDENTIALS')
Denis Egorenko284690e2018-12-25 15:55:12 +0400310 upgradeSaltStack = driteTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean()
311 updateClusterModel = driteTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean()
312 updatePipelines = driteTrainParams.get('UPDATE_PIPELINES', false).toBoolean()
313 updateLocalRepos = driteTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean()
Denis Egorenko517e06c2019-03-29 13:24:15 +0400314 reclassSystemBranch = driteTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault)
Denis Egorenko284690e2018-12-25 15:55:12 +0400315 } else {
316 // backward compatibility for 2018.11.0
317 saltMastURL = env.getProperty('SALT_MASTER_URL')
318 saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS')
Denis Egorenkoe5f39142018-12-28 12:30:48 +0400319 upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean()
320 updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean()
321 updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean()
322 updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean()
Denis Egorenko517e06c2019-03-29 13:24:15 +0400323 reclassSystemBranch = reclassSystemBranchDefault
Denis Egorenko284690e2018-12-25 15:55:12 +0400324 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400325 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400326 def minions = salt.getMinions(venvPepper, '*')
Denis Egorenkofbcee412019-04-19 15:05:18 +0400327 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
328 if (cluster_name == '' || cluster_name == 'null' || cluster_name == null) {
329 error('Pillar data is broken for Salt master node! Please check it manually and re-run pipeline.')
330 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400331
azvyagintsevbc359d42019-04-10 19:53:22 +0300332 stage('Update Reclass and Salt-Formulas') {
333 common.infoMsg('Perform: Full salt sync')
334 salt.fullRefresh(venvPepper, '*')
335 common.infoMsg('Perform: Validate reclass medata before processing')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400336 validateReclassModel(minions, 'before')
337
azvyagintsev745a6e52019-04-18 13:19:39 +0300338 common.infoMsg('Perform: archiveReclassInventory before upgrade')
339 archiveReclassInventory(inventoryBeforeFilename)
340
azvyagintsev6dac3802018-11-09 15:11:30 +0200341 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300342 salt.cmdRun(venvPepper, 'I@salt:master', 'cd /srv/salt/reclass/ && git status && git diff-index --quiet HEAD --')
Richard Felkl970e0082018-06-12 18:00:51 +0200343 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200344 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300345 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 +0200346 }
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300347 checkDebsums()
Denis Egorenkod13ad132018-12-17 16:56:02 +0400348 if (updateClusterModel) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200349 common.infoMsg('Perform: UPDATE_CLUSTER_MODEL')
Sergey382581a2018-10-25 12:22:26 +0400350 def dateTime = common.getDatetime()
Denis Egorenko20254e72019-03-18 15:47:33 +0400351 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/ && git submodule foreach git fetch")
Sergey382581a2018-10-25 12:22:26 +0400352 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400353 "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 +0200354 // Do the same, for deprecated variable-duplicate
355 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400356 "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 +0400357 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400358 "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 +0400359 // Set new k8s param
360 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
361 "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 +0400362 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
363 "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'")
364 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko301cc8a2019-02-13 13:49:13 +0400365 "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 +0400366 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko301cc8a2019-02-13 13:49:13 +0400367 "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 +0400368 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsevbc359d42019-04-10 19:53:22 +0300369 "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 +0400370
371 // Switch Jenkins/Gerrit to use LDAP SSL/TLS
372 def gerritldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
373 "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()
374 if (gerritldapURI.startsWith('ldap://')) {
375 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
376 "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
377 } else if (! gerritldapURI.startsWith('ldaps://')) {
378 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
379 "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'")
380 }
381 def jenkinsldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
382 "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()
383 if (jenkinsldapURI.startsWith('ldap://')) {
384 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
385 "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
386 } else if (! jenkinsldapURI.startsWith('ldaps://')) {
387 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
388 "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'")
389 }
390
Denis Egorenko1b11d232019-07-29 17:44:46 +0400391 wa32284(cluster_name)
392
Denis Egorenkod13ad132018-12-17 16:56:02 +0400393 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}")
Sergey Kolekonov5dfbf7a2019-01-23 16:47:43 +0400394 // Add kubernetes-extra repo
395 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
Sergey Kolekonov3fde8b12019-04-11 16:33:54 +0400396 // docker-engine conflicts with the recent containerd versions, so it's removed during upgrade. Thus update source engine
397 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
398 "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 +0400399 common.infoMsg("Add kubernetes-extra repo")
400 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
401 "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")
402 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
403 "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")
404 }
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400405 // Add all update repositories
406 def repoIncludeBase = '- system.linux.system.repo.mcp.apt_mirantis.'
azvyagintsevbc359d42019-04-10 19:53:22 +0300407 def updateRepoList = ['cassandra', 'ceph', 'contrail', 'docker', 'elastic', 'extra', 'openstack', 'percona', 'salt-formulas', 'saltstack', 'ubuntu']
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400408 updateRepoList.each { repo ->
409 def repoNameUpdateInclude = "${repoIncludeBase}update.${repo}"
410 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')
411 filesWithInclude.each { file ->
412 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()
413 if (updateRepoIncludeExist == 'not_found') {
414 // Include needs to be added
415 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsevbc359d42019-04-10 19:53:22 +0300416 "sed -i 's/\\( *\\)${repoIncludeBase}${repo}\$/&\\n\\1${repoNameUpdateInclude}/g' ${file}")
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400417 common.infoMsg("Update repo for ${repo} is added to ${file}")
418 }
419 }
420 }
Sergey382581a2018-10-25 12:22:26 +0400421 // Add new defaults
422 common.infoMsg("Add new defaults")
Denis Egorenkod13ad132018-12-17 16:56:02 +0400423 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 +0400424 "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 +0400425 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 +0400426 "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 +0400427 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300428 "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 +0400429 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300430 "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 +0400431 common.infoMsg("The following changes were made to the cluster model and will be commited. " +
azvyagintsev6dac3802018-11-09 15:11:30 +0200432 "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 +0400433 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff")
434 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " +
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200435 "git add -u && git commit --allow-empty -m 'Cluster model update to the release $targetMcpVersion on $dateTime'")
Sergey382581a2018-10-25 12:22:26 +0400436 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400437 try {
438 common.infoMsg('Perform: UPDATE Salt Formulas')
azvyagintsevca97a112019-04-22 17:53:40 +0300439 salt.fullRefresh(venvPepper, '*')
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400440 salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400441 def saltEnv = salt.getPillar(venvPepper, 'I@salt:master', "_param:salt_master_base_environment").get("return")[0].values()[0]
azvyagintsevbc359d42019-04-10 19:53:22 +0300442 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas", 'salt.master.env'])
azvyagintsevca97a112019-04-22 17:53:40 +0300443 salt.fullRefresh(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400444 } catch (Exception updateErr) {
445 common.warningMsg(updateErr)
446 common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
447 input message: 'Continue anyway?'
448 }
449
azvyagintsev745a6e52019-04-18 13:19:39 +0300450 wa29352(minions, cluster_name)
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400451 def computeMinions = salt.getMinions(venvPepper, 'I@nova:compute')
452 wa29155(computeMinions, cluster_name)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400453
454 try {
455 common.infoMsg('Perform: UPDATE Reclass package')
456 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"])
457 } catch (Exception updateErr) {
458 common.warningMsg(updateErr)
459 common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
460 input message: 'Continue anyway?'
461 }
462
463 salt.fullRefresh(venvPepper, 'I@salt:master')
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400464 salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400465 try {
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400466 salt.enforceState(venvPepper, 'I@salt:master', 'reclass', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400467 }
468 catch (Exception ex) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300469 common.errorMsg(ex.toString())
470 error('Reclass fails rendering. Pay attention to your cluster model.')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400471 }
472
473 salt.fullRefresh(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400474 try {
475 salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top")
476 }
477 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300478
479 error('Reclass fails rendering. Pay attention to your cluster model.' +
480 'ErrorMessage:' + ex.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400481 }
482
azvyagintsevbc359d42019-04-10 19:53:22 +0300483 common.infoMsg('Perform: archiveReclassInventory AFTER upgrade')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400484 archiveReclassInventory(inventoryAfterFilename)
485
486 sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true"
487 archiveArtifacts artifacts: "reclass-inventory-diff.out"
488
489 validateReclassModel(minions, 'after')
490 archiveReclassModelChanges(minions)
Jakub Josefa63f9862018-01-11 17:58:38 +0100491 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100492
Denis Egorenkod13ad132018-12-17 16:56:02 +0400493 if (updateLocalRepos) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200494 stage("Update local repos") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100495 common.infoMsg("Updating local repositories")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700496
Sergey1b81c062018-10-16 17:10:21 +0400497 def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700498 runningOnDocker = engine.get("return")[0].containsValue("docker")
499
500 if (runningOnDocker) {
501 common.infoMsg("Aptly is running as Docker container")
azvyagintsev6dac3802018-11-09 15:11:30 +0200502 } else {
Sam Stoelingaaab79702018-04-09 18:49:39 -0700503 common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands")
504 }
505
azvyagintsev6dac3802018-11-09 15:11:30 +0200506 if (runningOnDocker) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200507 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 +0200508 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200509 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 +0100510 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100511
Sergey1b81c062018-10-16 17:10:21 +0400512 salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100513
azvyagintsev6dac3802018-11-09 15:11:30 +0200514 if (runningOnDocker) {
Sergey1b81c062018-10-16 17:10:21 +0400515 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true)
516 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 +0200517 } else {
Sergey1b81c062018-10-16 17:10:21 +0400518 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true)
519 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 +0100520 }
Richard Felkl79d7df12018-01-05 16:40:11 +0100521
Sergey1b81c062018-10-16 17:10:21 +0400522 salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100523
Sergey1b81c062018-10-16 17:10:21 +0400524 salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100525
Sergey1b81c062018-10-16 17:10:21 +0400526 salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100527
Sergey1b81c062018-10-16 17:10:21 +0400528 salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100529 }
530 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100531
azvyagintsevbc359d42019-04-10 19:53:22 +0300532 stage('Update Drivetrain') {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400533 if (upgradeSaltStack) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300534 updateSaltStack('I@salt:master', '["salt-master", "salt-common", "salt-api", "salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200535
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400536 salt.enforceState(venvPepper, 'I@linux:system', 'linux.system.repo', true, true, null, false, 60, 2)
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300537 updateSaltStack('I@salt:minion and not I@salt:master', '["salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200538 }
539
Denis Egorenkod13ad132018-12-17 16:56:02 +0400540 if (updatePipelines) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300541 common.infoMsg('Perform: UPDATE git repos')
542 triggerMirrorJob('git-mirror-downstream-mk-pipelines', reclassSystemBranch)
543 triggerMirrorJob('git-mirror-downstream-pipeline-library', reclassSystemBranch)
Richard Felkl970e0082018-06-12 18:00:51 +0200544 }
545
Denis Egorenko7a4cf032019-04-25 20:48:26 +0400546 // update minions certs
Denis Egorenkoaf3a2202019-04-26 15:13:16 +0400547 // call for `salt.minion.ca` state on related nodes to make sure
548 // mine was updated with required data after salt-minion/salt-master restart salt:minion:ca
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400549 salt.enforceState(venvPepper, 'I@salt:minion:ca', 'salt.minion.ca', true, true, null, false, 60, 2)
550 salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion.cert', true, true, null, false, 60, 2)
Denis Egorenko7a4cf032019-04-25 20:48:26 +0400551
Ann Kamyshnikovae8910112019-05-06 12:56:38 +0400552 // run `salt.minion` to refresh all minion configs (for example _keystone.conf)
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400553 salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion', true, true, null, false, 60, 2)
azvyagintsevbc359d42019-04-10 19:53:22 +0300554 // Retry needed only for rare race-condition in user appearance
555 common.infoMsg('Perform: updating users and keys')
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400556 salt.enforceState(venvPepper, 'I@linux:system', 'linux.system.user', true, true, null, false, 60, 2)
azvyagintsevbc359d42019-04-10 19:53:22 +0300557 common.infoMsg('Perform: updating openssh')
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400558 salt.enforceState(venvPepper, 'I@linux:system', 'openssh', true, true, null, false, 60, 2)
Denis Egorenko65cf2a42019-01-15 11:58:12 +0400559
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300560 // apply salt API TLS if needed
561 def nginxAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0]
562 if (nginxAtMaster.toString().toLowerCase() == 'true') {
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400563 salt.enforceState(venvPepper, 'I@salt:master', 'nginx', true, true, null, false, 60, 2)
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300564 }
565
Denis Egorenkobc440322019-07-09 18:55:35 +0400566 // Apply changes for HaProxy on CI/CD nodes
567 salt.enforceState(venvPepper, 'I@keepalived:cluster:instance:cicd_control_vip and I@haproxy:proxy', 'haproxy.proxy', true)
568
Denis Egorenko21c78be2019-07-10 19:47:39 +0400569 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 +0200570
571 sleep(180)
572
azvyagintsevbc359d42019-04-10 19:53:22 +0300573 common.infoMsg('Perform: Checking if Docker containers are up')
Richard Felkl970e0082018-06-12 18:00:51 +0200574
azvyagintsev6dac3802018-11-09 15:11:30 +0200575 try {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300576 common.retry(20, 30) {
Richard Felkl970e0082018-06-12 18:00:51 +0200577 salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'")
578 }
579 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200580 catch (Exception ex) {
Richard Felkl970e0082018-06-12 18:00:51 +0200581 error("Docker containers for CI/CD services are having troubles with starting.")
582 }
Denis Egorenko21c78be2019-07-10 19:47:39 +0400583
584 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 +0400585
586 // update Nginx proxy settings for Jenkins/Gerrit if needed
587 if (salt.testTarget(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit')) {
588 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)
589 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100590 }
591 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100592 catch (Throwable e) {
593 // If there was an error or exception thrown, the build failed
594 currentBuild.result = "FAILURE"
595 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +0100596 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100597 }
Jakub Josef2c21c6c2018-02-08 18:51:42 +0100598}