blob: 8eebc46e715f4f68f231dd9e969bfbd22c22c886 [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 Egorenko70002bc2019-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
Denis Egorenkoada83882019-06-11 14:03:40 +040026def triggerMirrorJob(String jobName, String reclassSystemBranch) {
Richard Felkl970e0082018-06-12 18:00:51 +020027 params = jenkinsUtils.getJobParameters(jobName)
Denis Egorenkoada83882019-06-11 14:03:40 +040028 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) {
Denis Egorenko0d0c65f2019-02-26 16:05:03 +040048 salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${target}' --async pkg.install force_yes=True pkgs='$pkgs'")
49 // 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
Denis Egorenko6f1c8732019-09-24 14:55:50 +040073def getWorkerThreads(saltId) {
74 if (env.getEnvironment().containsKey('SALT_MASTER_OPT_WORKER_THREADS')) {
75 return env['SALT_MASTER_OPT_WORKER_THREADS'].toString()
76 }
77 def threads = salt.cmdRun(saltId, "I@salt:master", "cat /etc/salt/master.d/master.conf | grep worker_threads | cut -f 2 -d ':'", true, null, true)
78 return threads['return'][0].values()[0].replaceAll('Salt command execution success','').trim()
79}
80
Denis Egorenkoada83882019-06-11 14:03:40 +040081def wa29352(ArrayList saltMinions, String cname) {
82 // WA for PROD-29352. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/12/openssh/client/root.yml
83 // Default soft-param has been removed, what now makes not possible to render some old env's.
84 // Like fix, we found copy-paste already generated key from backups, to secrets.yml with correct key name
85 def wa29352ClassName = 'cluster.' + cname + '.infra.secrets_root_wa29352'
86 def wa29352File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_root_wa29352.yml"
87 def wa29352SecretsFile = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets.yml"
88 def _tempFile = '/tmp/wa29352_' + UUID.randomUUID().toString().take(8)
89 try {
90 salt.cmdRun(venvPepper, 'I@salt:master', "grep -qiv root_private_key ${wa29352SecretsFile}", true, null, false)
91 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29352File}", true, null, false)
92 }
93 catch (Exception ex) {
Denis Egorenkoe0c88432019-10-07 12:46:14 +040094 common.infoMsg('Work-around for PROD-29352 already applied, nothing todo')
Denis Egorenkoada83882019-06-11 14:03:40 +040095 return
96 }
97 def rKeysDict = [
98 'parameters': [
99 '_param': [
100 'root_private_key': salt.getPillar(venvPepper, 'I@salt:master', '_param:root_private_key').get('return')[0].values()[0].trim(),
101 'root_public_key' : '',
102 ]
103 ]
104 ]
105 // save root key,and generate public one from it
106 writeFile file: _tempFile, text: rKeysDict['parameters']['_param']['root_private_key'].toString().trim()
107 sh('chmod 0600 ' + _tempFile)
108 rKeysDict['parameters']['_param']['root_public_key'] = sh(script: "ssh-keygen -q -y -f ${_tempFile}", returnStdout: true).trim()
109 sh('rm -fv ' + _tempFile)
110 writeYaml file: _tempFile, data: rKeysDict
111 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
112 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29352File}", false, null, false)
113 common.infoMsg("Add $wa29352ClassName class into secrets.yml")
114
115 // Add 'classes:' directive
116 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
117 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
118
119 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
120 "grep -q '${wa29352ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29352ClassName' infra/secrets.yml")
121 salt.fullRefresh(venvPepper, '*')
122 sh('rm -fv ' + _tempFile)
Denis Egorenkoe0c88432019-10-07 12:46:14 +0400123 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " +
124 "git add ${wa29352File} && git add -u && git commit --allow-empty -m 'Cluster model updated with WA for PROD-29352. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/ at ${common.getDatetime()}' ")
125 common.infoMsg('Work-around for PROD-29352 successfully applied')
Denis Egorenkoada83882019-06-11 14:03:40 +0400126}
127
128def wa29155(ArrayList saltMinions, String cname) {
129 // WA for PROD-29155. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/
130 // CHeck for existence cmp nodes, and try to render it. Is failed, apply ssh-key wa
131 def ret = ''
132 def patched = false
133 def wa29155ClassName = 'cluster.' + cname + '.infra.secrets_nova_wa29155'
134 def wa29155File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_nova_wa29155.yml"
135
136 try {
137 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29155File}", true, null, false)
138 }
139 catch (Exception ex) {
140 common.infoMsg('Work-around for PROD-29155 already apply, nothing todo')
141 return
142 }
Denis Egorenkoe983d452019-08-23 14:29:34 +0400143 salt.fullRefresh(venvPepper, 'I@salt:master')
144 salt.fullRefresh(venvPepper, 'I@nova:compute')
Denis Egorenkoada83882019-06-11 14:03:40 +0400145 for (String minion in saltMinions) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400146 // First attempt, second will be performed in next validateReclassModel() stages
147 try {
148 salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
149 } catch (Exception e) {
150 common.errorMsg(e.toString())
151 if (patched) {
152 error("Node: ${minion} failed to render after reclass-system upgrade!WA29155 probably didn't help.")
153 }
154 // check, that failed exactly by our case, by key-length check.
155 def missed_key = salt.getPillar(venvPepper, minion, '_param:nova_compute_ssh_private').get("return")[0].values()[0]
156 if (missed_key != '') {
157 error("Node: ${minion} failed to render after reclass-system upgrade!")
158 }
159 common.warningMsg('Perform: Attempt to apply WA for PROD-29155\n' +
160 'See https://gerrit.mcp.mirantis.com/#/c/37932/ for more info')
161 common.warningMsg('WA-PROD-29155 Generating new ssh key at master node')
162 def _tempFile = "/tmp/nova_wa29155_" + UUID.randomUUID().toString().take(8)
163 common.infoMsg('Perform: generation NEW ssh-private key for nova-compute')
164 salt.cmdRun(venvPepper, 'I@salt:master', "ssh-keygen -f ${_tempFile} -N '' -q")
165 def _pub_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}.pub").get('return')[0].values()[0].trim()
166 def _priv_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}").get('return')[0].values()[0].trim()
167 salt.cmdRun(venvPepper, 'I@salt:master', "rm -fv ${_tempFile}", false, null, false)
168 def novaKeysDict = [
169 "parameters": [
170 "_param": [
171 "nova_compute_ssh_private": _priv_k,
172 "nova_compute_ssh_public" : _pub_k
173 ]
174 ]
175 ]
176 writeYaml file: _tempFile, data: novaKeysDict
177 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
178 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29155File}", false, null, false)
179 common.infoMsg("Add $wa29155ClassName class into secrets.yml")
180
181 // Add 'classes:' directive
182 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
183 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
184
185 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
186 "grep -q '${wa29155ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29155ClassName' infra/secrets.yml")
187 salt.fullRefresh(venvPepper, 'cfg*')
188 salt.fullRefresh(venvPepper, 'cmp*')
189 patched = true
190 }
191 }
192 if (patched) {
193 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " +
194 "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()}' ")
195 common.infoMsg('Work-around for PROD-29155 successfully applied')
196 }
197
198}
199
Denis Egorenkobae9dc72019-07-29 17:44:46 +0400200def wa32284(String clusterName) {
201 def clientGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:enabled").get("return")[0].values()[0]
202 def pkiGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:volumes:salt_pki").get("return")[0].values()[0]
203 def nginxEnabledAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0]
204 if (nginxEnabledAtMaster.toString().toLowerCase() == 'true' && clientGluster.toString().toLowerCase() == 'true' && pkiGluster) {
205 def nginxRequires = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:wait_for_service').get('return')[0].values()[0]
206 if (nginxRequires.isEmpty()) {
207 def nginxRequiresClassName = "cluster.${clusterName}.infra.config.nginx_requires_wa32284"
208 def nginxRequiresClassFile = "/srv/salt/reclass/classes/cluster/${clusterName}/infra/config/nginx_requires_wa32284.yml"
209 def nginxRequiresBlock = ['parameters': ['nginx': ['server': ['wait_for_service': ['srv-salt-pki.mount'] ] ] ] ]
210 def _tempFile = '/tmp/wa32284_' + UUID.randomUUID().toString().take(8)
211 writeYaml file: _tempFile , data: nginxRequiresBlock
212 def nginxRequiresBlockString = sh(script: "cat ${_tempFile}", returnStdout: true).trim()
213 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${clusterName} && " +
214 "sed -i '/^parameters:/i - ${nginxRequiresClassName}' infra/config/init.yml")
215 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${nginxRequiresBlockString}' > ${nginxRequiresClassFile}", false, null, false)
216 }
217 }
218}
219
Denis Egorenkoda117892019-09-02 14:53:02 +0400220def wa32182(String cluster_name) {
Hanna Arhipova644aefd2019-09-06 17:55:40 +0300221 if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) {
Denis Egorenkoda117892019-09-02 14:53:02 +0400222 def clusterModelPath = "/srv/salt/reclass/classes/cluster/${cluster_name}"
223 def fixFile = "${clusterModelPath}/opencontrail/common_wa32182.yml"
224 def usualFile = "${clusterModelPath}/opencontrail/common.yml"
225 def fixFileContent = "classes:\n- system.opencontrail.common\n"
226 salt.cmdRun(venvPepper, 'I@salt:master', "test -f ${fixFile} -o -f ${usualFile} || echo '${fixFileContent}' > ${fixFile}")
227 def contrailFiles = ['opencontrail/analytics.yml', 'opencontrail/control.yml', 'openstack/compute/init.yml']
228 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
229 contrailFiles.add('kubernetes/compute.yml')
230 }
231 for(String contrailFile in contrailFiles) {
232 contrailFile = "${clusterModelPath}/${contrailFile}"
233 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()
234 if (containsFix) {
235 continue
236 } else {
237 salt.cmdRun(venvPepper, 'I@salt:master', "grep -q -E '^parameters:' ${contrailFile} && sed -i '/^parameters:/i - cluster.${cluster_name}.opencontrail.common_wa32182' ${contrailFile} || " +
238 "echo '- cluster.${cluster_name}.opencontrail.common_wa32182' >> ${contrailFile}")
239 }
240 }
241 }
242}
243
Denis Egorenko32461082019-10-25 13:13:39 +0400244def wa33867(String cluster_name) {
245 if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) {
246 def contrailControlFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/opencontrail/control.yml"
247 def line = salt.cmdRun(venvPepper, 'I@salt:master', "awk '/^- cluster.${cluster_name}.infra.backup.client_zookeeper/ {getline; print \$0}' ${contrailControlFile}", false, null, true).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
248 if (line == "- cluster.${cluster_name}.infra") {
249 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra\$/d' ${contrailControlFile}")
250 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra.backup.client_zookeeper\$/i - cluster.${cluster_name}.infra' ${contrailControlFile}")
251 }
252 }
253}
254
Denis Egorenko7e934c22019-10-18 17:06:11 +0400255def wa33771(String cluster_name) {
256 def octaviaEnabled = salt.getMinions(venvPepper, 'I@octavia:api:enabled')
257 def octaviaWSGI = salt.getMinions(venvPepper, 'I@apache:server:site:octavia_api')
258 if (octaviaEnabled && ! octaviaWSGI) {
259 def openstackControl = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/control.yml"
260 def octaviaFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/octavia_wa33771.yml"
261 def octaviaContext = [
262 'classes': [ 'system.apache.server.site.octavia' ],
263 'parameters': [
264 '_param': [ 'apache_octavia_api_address' : '${_param:cluster_local_address}' ],
265 'apache': [ 'server': [ 'site': [ 'apache_proxy_openstack_api_octavia': [ 'enabled': false ] ] ] ]
266 ]
267 ]
268 def _tempFile = '/tmp/wa33771' + UUID.randomUUID().toString().take(8)
269 writeYaml file: _tempFile , data: octaviaContext
270 def octaviaFileContent = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
271 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.octavia_wa33771' ${openstackControl}")
272 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${octaviaFileContent}' | base64 -d > ${octaviaFile}", false, null, false)
273 }
274}
275
azvyagintsev6dac3802018-11-09 15:11:30 +0200276def archiveReclassInventory(filename) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400277 def _tmp_file = '/tmp/' + filename + UUID.randomUUID().toString().take(8)
278 // jenkins may fail at overheap. Compress data with gzip like WA
279 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()
280 def _tmp = sh(script: "echo '$ret' > ${_tmp_file}", returnStdout: false)
281 sh(script: "cat ${_tmp_file} | base64 -d | gzip -d > $filename", returnStdout: false)
282 archiveArtifacts artifacts: filename
283 sh(script: "rm -v ${_tmp_file}|| true")
Richard Felkl0e80d892018-06-20 13:44:54 +0200284}
285
Denis Egorenkod13ad132018-12-17 16:56:02 +0400286def validateReclassModel(ArrayList saltMinions, String suffix) {
287 try {
Denis Egorenkoada83882019-06-11 14:03:40 +0400288 for (String minion in saltMinions) {
289 common.infoMsg("Reclass model validation for minion ${minion}...")
290 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()
291 writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString()
Denis Egorenkod13ad132018-12-17 16:56:02 +0400292 }
293 } catch (Exception e) {
294 common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.')
Denis Egorenkoada83882019-06-11 14:03:40 +0400295 error(e.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400296 }
297}
298
Denis Egorenkoada83882019-06-11 14:03:40 +0400299def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix = 'before', String newSuffix = 'after') {
300 for (String minion in saltMinions) {
301 def fileName = "reclass-model-${minion}-diff.out"
302 sh "diff -u inventory-${minion}-${oldSuffix}.out inventory-${minion}-${newSuffix}.out > ${fileName} || true"
303 archiveArtifacts artifacts: "${fileName}"
Denis Egorenkod13ad132018-12-17 16:56:02 +0400304 }
305}
306
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400307if (common.validInputParam('PIPELINE_TIMEOUT')) {
308 try {
309 pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger()
Denis Egorenkoada83882019-06-11 14:03:40 +0400310 } catch (Exception e) {
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400311 common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger")
312 }
Martin Polreich965c9032018-08-09 16:33:57 +0200313}
314
315timeout(time: pipelineTimeout, unit: 'HOURS') {
Denis Egorenkoada83882019-06-11 14:03:40 +0400316 node("python") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100317 try {
Denis Egorenkoada83882019-06-11 14:03:40 +0400318 def inventoryBeforeFilename = "reclass-inventory-before.out"
319 def inventoryAfterFilename = "reclass-inventory-after.out"
Richard Felkl0e80d892018-06-20 13:44:54 +0200320 workspace = common.getWorkspace()
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200321 targetMcpVersion = null
322 if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) {
323 error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable')
azvyagintsev6dac3802018-11-09 15:11:30 +0200324 }
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200325 // bw comp. for 2018.X => 2018.11 release
Denis Egorenkoada83882019-06-11 14:03:40 +0400326 if (common.validInputParam('MCP_VERSION')) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200327 targetMcpVersion = env.MCP_VERSION
328 common.warningMsg("targetMcpVersion has been changed to:${targetMcpVersion}, which was taken from deprecated pipeline viriable:MCP_VERSION")
Denis Egorenkoada83882019-06-11 14:03:40 +0400329 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200330 targetMcpVersion = env.TARGET_MCP_VERSION
331 }
332 // end bw comp. for 2018.X => 2018.11 release
Denis Egorenkod13ad132018-12-17 16:56:02 +0400333 def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC')
Ivan Berezovskiyd62629c2019-01-16 19:26:18 +0400334 if (targetMcpVersion in ['nightly', 'testing']) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200335 gitTargetMcpVersion = 'master'
Ivan Berezovskiyd62629c2019-01-16 19:26:18 +0400336 } else if (targetMcpVersion == 'proposed') {
337 gitTargetMcpVersion = 'proposed'
Denis Egorenko284690e2018-12-25 15:55:12 +0400338 } else if (!gitTargetMcpVersion) {
339 // backward compatibility for 2018.11.0
340 gitTargetMcpVersion = "release/${targetMcpVersion}"
azvyagintsev6dac3802018-11-09 15:11:30 +0200341 }
Ivan Berezovskiyd62629c2019-01-16 19:26:18 +0400342 common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}")
Denis Egorenko284690e2018-12-25 15:55:12 +0400343 def saltMastURL = ''
344 def saltMastCreds = ''
345 def upgradeSaltStack = ''
346 def updateClusterModel = ''
347 def updatePipelines = ''
348 def updateLocalRepos = ''
349 def reclassSystemBranch = ''
Denis Egorenkob559e542019-03-29 13:24:15 +0400350 def reclassSystemBranchDefault = gitTargetMcpVersion
Denis Egorenko70002bc2019-08-19 19:41:27 +0400351 def batchSize = ''
Denis Egorenkob559e542019-03-29 13:24:15 +0400352 if (gitTargetMcpVersion != 'proposed') {
353 reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}"
354 }
Hanna Arhipova644aefd2019-09-06 17:55:40 +0300355 def driveTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS')
356 if (driveTrainParamsYaml) {
357 def driveTrainParams = readYaml text: driveTrainParamsYaml
358 saltMastURL = driveTrainParams.get('SALT_MASTER_URL')
359 saltMastCreds = driveTrainParams.get('SALT_MASTER_CREDENTIALS')
360 upgradeSaltStack = driveTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean()
361 updateClusterModel = driveTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean()
362 updatePipelines = driveTrainParams.get('UPDATE_PIPELINES', false).toBoolean()
363 updateLocalRepos = driveTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean()
364 reclassSystemBranch = driveTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault)
Denis Egorenko70002bc2019-08-19 19:41:27 +0400365 batchSize = driveTrainParams.get('BATCH_SIZE', '')
Denis Egorenko284690e2018-12-25 15:55:12 +0400366 } else {
367 // backward compatibility for 2018.11.0
368 saltMastURL = env.getProperty('SALT_MASTER_URL')
369 saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS')
Denis Egorenkoe5f39142018-12-28 12:30:48 +0400370 upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean()
371 updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean()
372 updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean()
373 updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean()
Denis Egorenkob559e542019-03-29 13:24:15 +0400374 reclassSystemBranch = reclassSystemBranchDefault
Denis Egorenko284690e2018-12-25 15:55:12 +0400375 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400376 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400377 def minions = salt.getMinions(venvPepper, '*')
Denis Egorenkoc0538ce2019-04-19 15:05:18 +0400378 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
379 if (cluster_name == '' || cluster_name == 'null' || cluster_name == null) {
380 error('Pillar data is broken for Salt master node! Please check it manually and re-run pipeline.')
381 }
Hanna Arhipova644aefd2019-09-06 17:55:40 +0300382 if (!batchSize) {
Denis Egorenko6f1c8732019-09-24 14:55:50 +0400383 batchSize = getWorkerThreads(venvPepper)
Denis Egorenko70002bc2019-08-19 19:41:27 +0400384 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400385
Denis Egorenkoada83882019-06-11 14:03:40 +0400386 stage('Update Reclass and Salt-Formulas') {
387 common.infoMsg('Perform: Full salt sync')
388 salt.fullRefresh(venvPepper, '*')
389 common.infoMsg('Perform: Validate reclass medata before processing')
390 validateReclassModel(minions, 'before')
391
392 common.infoMsg('Perform: archiveReclassInventory before upgrade')
Denis Egorenko89a3c572019-03-22 17:03:40 +0400393 archiveReclassInventory(inventoryBeforeFilename)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400394
azvyagintsev6dac3802018-11-09 15:11:30 +0200395 try {
Denis Egorenkoada83882019-06-11 14:03:40 +0400396 salt.cmdRun(venvPepper, 'I@salt:master', 'cd /srv/salt/reclass/ && git status && git diff-index --quiet HEAD --')
Richard Felkl970e0082018-06-12 18:00:51 +0200397 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200398 catch (Exception ex) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400399 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 +0200400 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400401 if (updateClusterModel) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200402 common.infoMsg('Perform: UPDATE_CLUSTER_MODEL')
Sergey382581a2018-10-25 12:22:26 +0400403 def dateTime = common.getDatetime()
Denis Egorenko00897c52019-03-18 15:47:33 +0400404 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/ && git submodule foreach git fetch")
Sergey382581a2018-10-25 12:22:26 +0400405 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400406 "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 +0200407 // Do the same, for deprecated variable-duplicate
408 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400409 "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 +0400410 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400411 "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 Ryzhenkin202c5062019-01-15 19:58:03 +0400412 // Set new k8s param
413 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
414 "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 Egorenko2a39d2c2019-01-16 19:18:31 +0400415 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
416 "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'")
417 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoca871c22019-02-13 13:49:13 +0400418 "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 Egorenko2a39d2c2019-01-16 19:18:31 +0400419 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoca871c22019-02-13 13:49:13 +0400420 "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 Samoylov72c2ccf2019-02-13 15:57:13 +0400421 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoada83882019-06-11 14:03:40 +0400422 "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 Egorenko6ca9f0d2019-07-10 19:47:39 +0400423
Denis Egorenko70f4f9a2019-09-16 16:41:26 +0400424 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name/infra && sed -i '/linux_system_repo_mcp_maas_url/d' maas.yml")
425 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name/infra && sed -i '/maas_region_main_archive/d' maas.yml")
426
Denis Egorenko6ca9f0d2019-07-10 19:47:39 +0400427 // Switch Jenkins/Gerrit to use LDAP SSL/TLS
428 def gerritldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
429 "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()
430 if (gerritldapURI.startsWith('ldap://')) {
431 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
432 "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
433 } else if (! gerritldapURI.startsWith('ldaps://')) {
434 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
435 "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'")
436 }
437 def jenkinsldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
438 "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()
439 if (jenkinsldapURI.startsWith('ldap://')) {
440 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
441 "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
442 } else if (! jenkinsldapURI.startsWith('ldaps://')) {
443 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
444 "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'")
445 }
446
Denis Egorenkobae9dc72019-07-29 17:44:46 +0400447 wa32284(cluster_name)
448
Denis Egorenkod13ad132018-12-17 16:56:02 +0400449 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}")
Sergey Kolekonov6ab15112019-01-23 16:47:43 +0400450 // Add kubernetes-extra repo
451 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
Sergey Kolekonovac9554c2019-04-11 16:33:54 +0400452 // docker-engine conflicts with the recent containerd versions, so it's removed during upgrade. Thus update source engine
453 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
454 "grep -r -l 'engine: docker_hybrid' kubernetes | xargs --no-run-if-empty sed -i 's/engine: docker_hybrid/engine: archive/g'")
Sergey Kolekonov6ab15112019-01-23 16:47:43 +0400455 common.infoMsg("Add kubernetes-extra repo")
456 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
457 "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")
458 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
459 "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")
460 }
Ivan Berezovskiybe630ee2019-04-15 13:23:58 +0400461 // Add all update repositories
462 def repoIncludeBase = '- system.linux.system.repo.mcp.apt_mirantis.'
Denis Egorenko70f4f9a2019-09-16 16:41:26 +0400463 def updateRepoList = ['cassandra', 'ceph', 'contrail', 'docker', 'elastic', 'extra', 'openstack', 'maas', 'percona', 'salt-formulas', 'saltstack', 'ubuntu']
Ivan Berezovskiybe630ee2019-04-15 13:23:58 +0400464 updateRepoList.each { repo ->
465 def repoNameUpdateInclude = "${repoIncludeBase}update.${repo}"
466 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')
467 filesWithInclude.each { file ->
468 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()
469 if (updateRepoIncludeExist == 'not_found') {
470 // Include needs to be added
471 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoada83882019-06-11 14:03:40 +0400472 "sed -i 's/\\( *\\)${repoIncludeBase}${repo}\$/&\\n\\1${repoNameUpdateInclude}/g' ${file}")
Ivan Berezovskiybe630ee2019-04-15 13:23:58 +0400473 common.infoMsg("Update repo for ${repo} is added to ${file}")
474 }
475 }
476 }
Denis Egorenkoda117892019-09-02 14:53:02 +0400477 wa32182(cluster_name)
Denis Egorenko7e934c22019-10-18 17:06:11 +0400478 wa33771(cluster_name)
Denis Egorenko32461082019-10-25 13:13:39 +0400479 wa33867(cluster_name)
Sergey382581a2018-10-25 12:22:26 +0400480 // Add new defaults
481 common.infoMsg("Add new defaults")
Denis Egorenkod13ad132018-12-17 16:56:02 +0400482 salt.cmdRun(venvPepper, 'I@salt:master', "grep '^ mcp_version: ' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400483 "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 +0400484 salt.cmdRun(venvPepper, 'I@salt:master', "grep '^- system.defaults\$' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400485 "sed -i 's|^classes:|classes:\\n- system.defaults|' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml")
Ivan Berezovskiyadb7d832019-04-23 14:32:02 +0400486 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
487 "grep -r -l 'docker_image_jenkins: .*' cicd | xargs --no-run-if-empty sed -i 's|\\s*docker_image_jenkins: .*||g'")
488 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
489 "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 +0400490 common.infoMsg("The following changes were made to the cluster model and will be commited. " +
azvyagintsev6dac3802018-11-09 15:11:30 +0200491 "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 +0400492 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff")
493 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " +
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200494 "git add -u && git commit --allow-empty -m 'Cluster model update to the release $targetMcpVersion on $dateTime'")
Sergey382581a2018-10-25 12:22:26 +0400495 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400496 try {
497 common.infoMsg('Perform: UPDATE Salt Formulas')
Denis Egorenkoada83882019-06-11 14:03:40 +0400498 salt.fullRefresh(venvPepper, '*')
499 salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400500 def saltEnv = salt.getPillar(venvPepper, 'I@salt:master', "_param:salt_master_base_environment").get("return")[0].values()[0]
Denis Egorenkoada83882019-06-11 14:03:40 +0400501 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas", 'salt.master.env'])
502 salt.fullRefresh(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400503 } catch (Exception updateErr) {
504 common.warningMsg(updateErr)
505 common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
506 input message: 'Continue anyway?'
507 }
508
Denis Egorenkoada83882019-06-11 14:03:40 +0400509 wa29352(minions, cluster_name)
Denis Egorenkoe983d452019-08-23 14:29:34 +0400510 def computeMinions = salt.getMinions(venvPepper, 'I@nova:compute')
511 wa29155(computeMinions, cluster_name)
Denis Egorenkoada83882019-06-11 14:03:40 +0400512
Denis Egorenkod13ad132018-12-17 16:56:02 +0400513 try {
514 common.infoMsg('Perform: UPDATE Reclass package')
515 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"])
516 } catch (Exception updateErr) {
517 common.warningMsg(updateErr)
518 common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
519 input message: 'Continue anyway?'
520 }
521
522 salt.fullRefresh(venvPepper, 'I@salt:master')
Sergey1b81c062018-10-16 17:10:21 +0400523 salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400524 try {
525 salt.enforceState(venvPepper, "I@salt:master", 'reclass', true)
526 }
527 catch (Exception ex) {
528 error("Reclass fails rendering. Pay attention to your cluster model.")
529 }
530
531 salt.fullRefresh(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400532 try {
533 salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top")
534 }
535 catch (Exception ex) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400536
537 error('Reclass fails rendering. Pay attention to your cluster model.' +
538 'ErrorMessage:' + ex.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400539 }
540
Denis Egorenkoada83882019-06-11 14:03:40 +0400541 common.infoMsg('Perform: archiveReclassInventory AFTER upgrade')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400542 archiveReclassInventory(inventoryAfterFilename)
543
544 sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true"
545 archiveArtifacts artifacts: "reclass-inventory-diff.out"
546
Denis Egorenkoada83882019-06-11 14:03:40 +0400547 validateReclassModel(minions, 'after')
548 archiveReclassModelChanges(minions)
Jakub Josefa63f9862018-01-11 17:58:38 +0100549 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100550
Denis Egorenkod13ad132018-12-17 16:56:02 +0400551 if (updateLocalRepos) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200552 stage("Update local repos") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100553 common.infoMsg("Updating local repositories")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700554
Sergey1b81c062018-10-16 17:10:21 +0400555 def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700556 runningOnDocker = engine.get("return")[0].containsValue("docker")
557
558 if (runningOnDocker) {
559 common.infoMsg("Aptly is running as Docker container")
azvyagintsev6dac3802018-11-09 15:11:30 +0200560 } else {
Sam Stoelingaaab79702018-04-09 18:49:39 -0700561 common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands")
562 }
563
azvyagintsev6dac3802018-11-09 15:11:30 +0200564 if (runningOnDocker) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200565 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 +0200566 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200567 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 +0100568 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100569
Sergey1b81c062018-10-16 17:10:21 +0400570 salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100571
azvyagintsev6dac3802018-11-09 15:11:30 +0200572 if (runningOnDocker) {
Sergey1b81c062018-10-16 17:10:21 +0400573 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true)
574 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 +0200575 } else {
Sergey1b81c062018-10-16 17:10:21 +0400576 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true)
577 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 +0100578 }
Richard Felkl79d7df12018-01-05 16:40:11 +0100579
Sergey1b81c062018-10-16 17:10:21 +0400580 salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100581
Sergey1b81c062018-10-16 17:10:21 +0400582 salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100583
Sergey1b81c062018-10-16 17:10:21 +0400584 salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100585
Sergey1b81c062018-10-16 17:10:21 +0400586 salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100587 }
588 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100589
Denis Egorenkoada83882019-06-11 14:03:40 +0400590 stage('Update Drivetrain') {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400591 if (upgradeSaltStack) {
592 updateSaltStack("I@salt:master", '["salt-master", "salt-common", "salt-api", "salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200593
Denis Egorenko70002bc2019-08-19 19:41:27 +0400594 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.repo', true, true, batchSize)
Richard Felkl0e80d892018-06-20 13:44:54 +0200595 updateSaltStack("I@salt:minion and not I@salt:master", '["salt-minion"]')
596 }
597
Denis Egorenkod13ad132018-12-17 16:56:02 +0400598 if (updatePipelines) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400599 common.infoMsg('Perform: UPDATE git repos')
600 triggerMirrorJob('git-mirror-downstream-mk-pipelines', reclassSystemBranch)
601 triggerMirrorJob('git-mirror-downstream-pipeline-library', reclassSystemBranch)
Richard Felkl970e0082018-06-12 18:00:51 +0200602 }
603
Denis Egorenkod00c17e2019-04-25 20:17:27 +0400604 // update minions certs
Denis Egorenko70002bc2019-08-19 19:41:27 +0400605 salt.enforceState(venvPepper, "I@salt:minion", 'salt.minion.cert', true, true, batchSize)
Denis Egorenkoada83882019-06-11 14:03:40 +0400606
607 // Retry needed only for rare race-condition in user appearance
608 common.infoMsg('Perform: updating users and keys')
Denis Egorenko70002bc2019-08-19 19:41:27 +0400609 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.user', true, true, batchSize)
Denis Egorenkoada83882019-06-11 14:03:40 +0400610 common.infoMsg('Perform: updating openssh')
Denis Egorenko70002bc2019-08-19 19:41:27 +0400611 salt.enforceState(venvPepper, "I@linux:system", 'openssh', true, true, batchSize)
Denis Egorenkoaeaa1de2019-01-15 11:58:12 +0400612
Denis Egorenko242f9bd2019-07-09 18:55:35 +0400613 // Apply changes for HaProxy on CI/CD nodes
614 salt.enforceState(venvPepper, 'I@keepalived:cluster:instance:cicd_control_vip and I@haproxy:proxy', 'haproxy.proxy', true)
615
Denis Egorenkoada83882019-06-11 14:03:40 +0400616 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 +0200617
618 sleep(180)
619
Denis Egorenkoada83882019-06-11 14:03:40 +0400620 common.infoMsg('Perform: Checking if Docker containers are up')
Richard Felkl970e0082018-06-12 18:00:51 +0200621
azvyagintsev6dac3802018-11-09 15:11:30 +0200622 try {
623 common.retry(10, 30) {
Richard Felkl970e0082018-06-12 18:00:51 +0200624 salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'")
625 }
626 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200627 catch (Exception ex) {
Richard Felkl970e0082018-06-12 18:00:51 +0200628 error("Docker containers for CI/CD services are having troubles with starting.")
629 }
Denis Egorenko6ca9f0d2019-07-10 19:47:39 +0400630
631 salt.enforceState(venvPepper, 'I@jenkins:client and not I@salt:master', 'jenkins.client', true)
Denis Egorenko84a0bc02019-07-23 18:01:21 +0400632
633 // update Nginx proxy settings for Jenkins/Gerrit if needed
634 if (salt.testTarget(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit')) {
635 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)
636 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100637 }
638 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100639 catch (Throwable e) {
640 // If there was an error or exception thrown, the build failed
641 currentBuild.result = "FAILURE"
642 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +0100643 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100644 }
Hanna Arhipova644aefd2019-09-06 17:55:40 +0300645}