blob: e5da7256858c893d828b3d838de382be222ee1b5 [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 = ""
Ivan Berezovskiy24b0be02019-12-11 15:31:10 +040025def saltMastURL = ''
26def saltMastCreds = ''
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010027
Denis Egorenkoada83882019-06-11 14:03:40 +040028def triggerMirrorJob(String jobName, String reclassSystemBranch) {
Richard Felkl970e0082018-06-12 18:00:51 +020029 params = jenkinsUtils.getJobParameters(jobName)
Denis Egorenkoada83882019-06-11 14:03:40 +040030 try {
31 build job: jobName, parameters: [
32 [$class: 'StringParameterValue', name: 'BRANCHES', value: params.get('BRANCHES')],
33 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')],
34 [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')],
35 [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')]
36 ]
37 } catch (Exception updateErr) {
38 common.warningMsg(updateErr)
39 common.warningMsg('Attempt to update git repo in failsafe manner')
40 build job: jobName, parameters: [
41 [$class: 'StringParameterValue', name: 'BRANCHES', value: reclassSystemBranch.replace('origin/', '')],
42 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')],
43 [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')],
44 [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')]
45 ]
46 }
Richard Felkl970e0082018-06-12 18:00:51 +020047}
48
azvyagintsev6dac3802018-11-09 15:11:30 +020049def updateSaltStack(target, pkgs) {
Denis Egorenko0d0c65f2019-02-26 16:05:03 +040050 salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${target}' --async pkg.install force_yes=True pkgs='$pkgs'")
51 // can't use same function from pipeline lib, as at the moment of running upgrade pipeline Jenkins
52 // still using pipeline lib from current old mcp-version
azvyagintsev6dac3802018-11-09 15:11:30 +020053 common.retry(20, 60) {
Richard Felkl0e80d892018-06-20 13:44:54 +020054 salt.minionsReachable(venvPepper, 'I@salt:master', '*')
55 def running = salt.runSaltProcessStep(venvPepper, target, 'saltutil.running', [], null, true, 5)
azvyagintsev6dac3802018-11-09 15:11:30 +020056 for (value in running.get("return")[0].values()) {
57 if (value != []) {
Richard Felkl0e80d892018-06-20 13:44:54 +020058 throw new Exception("Not all salt-minions are ready for execution")
59 }
60 }
61 }
62
azvyagintsevf3bf77a2018-11-15 19:30:04 +020063 def saltVersion = salt.getPillar(venvPepper, 'I@salt:master', '_param:salt_version').get('return')[0].values()[0]
Richard Felklf23257e2018-08-06 09:24:23 +020064 def saltMinionVersions = salt.cmdRun(venvPepper, target, "apt-cache policy salt-common | awk '/Installed/ && /$saltVersion/'").get("return")
Richard Felkl0e80d892018-06-20 13:44:54 +020065 def saltMinionVersion = ""
66
azvyagintsev6dac3802018-11-09 15:11:30 +020067 for (minion in saltMinionVersions[0].keySet()) {
68 saltMinionVersion = saltMinionVersions[0].get(minion).replace("Salt command execution success", "").trim()
69 if (saltMinionVersion == "") {
Richard Felkl0e80d892018-06-20 13:44:54 +020070 error("Installed version of Salt on $minion doesn't match specified version in the model.")
71 }
72 }
73}
74
Denis Egorenko6f1c8732019-09-24 14:55:50 +040075def getWorkerThreads(saltId) {
76 if (env.getEnvironment().containsKey('SALT_MASTER_OPT_WORKER_THREADS')) {
77 return env['SALT_MASTER_OPT_WORKER_THREADS'].toString()
78 }
79 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)
80 return threads['return'][0].values()[0].replaceAll('Salt command execution success','').trim()
81}
82
Ivan Berezovskiy304705c2019-12-03 18:49:09 +040083def wa29352(String cname) {
Denis Egorenkoada83882019-06-11 14:03:40 +040084 // WA for PROD-29352. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/12/openssh/client/root.yml
85 // Default soft-param has been removed, what now makes not possible to render some old env's.
86 // Like fix, we found copy-paste already generated key from backups, to secrets.yml with correct key name
87 def wa29352ClassName = 'cluster.' + cname + '.infra.secrets_root_wa29352'
88 def wa29352File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_root_wa29352.yml"
89 def wa29352SecretsFile = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets.yml"
90 def _tempFile = '/tmp/wa29352_' + UUID.randomUUID().toString().take(8)
91 try {
92 salt.cmdRun(venvPepper, 'I@salt:master', "grep -qiv root_private_key ${wa29352SecretsFile}", true, null, false)
93 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29352File}", true, null, false)
94 }
95 catch (Exception ex) {
Denis Egorenkoe0c88432019-10-07 12:46:14 +040096 common.infoMsg('Work-around for PROD-29352 already applied, nothing todo')
Denis Egorenkoada83882019-06-11 14:03:40 +040097 return
98 }
99 def rKeysDict = [
100 'parameters': [
101 '_param': [
102 'root_private_key': salt.getPillar(venvPepper, 'I@salt:master', '_param:root_private_key').get('return')[0].values()[0].trim(),
103 'root_public_key' : '',
104 ]
105 ]
106 ]
107 // save root key,and generate public one from it
108 writeFile file: _tempFile, text: rKeysDict['parameters']['_param']['root_private_key'].toString().trim()
109 sh('chmod 0600 ' + _tempFile)
110 rKeysDict['parameters']['_param']['root_public_key'] = sh(script: "ssh-keygen -q -y -f ${_tempFile}", returnStdout: true).trim()
111 sh('rm -fv ' + _tempFile)
112 writeYaml file: _tempFile, data: rKeysDict
113 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
114 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29352File}", false, null, false)
115 common.infoMsg("Add $wa29352ClassName class into secrets.yml")
116
117 // Add 'classes:' directive
118 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
119 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
120
121 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
122 "grep -q '${wa29352ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29352ClassName' infra/secrets.yml")
123 salt.fullRefresh(venvPepper, '*')
124 sh('rm -fv ' + _tempFile)
Denis Egorenkoe0c88432019-10-07 12:46:14 +0400125 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " +
126 "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()}' ")
127 common.infoMsg('Work-around for PROD-29352 successfully applied')
Denis Egorenkoada83882019-06-11 14:03:40 +0400128}
129
130def wa29155(ArrayList saltMinions, String cname) {
131 // WA for PROD-29155. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/
132 // CHeck for existence cmp nodes, and try to render it. Is failed, apply ssh-key wa
133 def ret = ''
134 def patched = false
135 def wa29155ClassName = 'cluster.' + cname + '.infra.secrets_nova_wa29155'
136 def wa29155File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_nova_wa29155.yml"
137
138 try {
139 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29155File}", true, null, false)
140 }
141 catch (Exception ex) {
142 common.infoMsg('Work-around for PROD-29155 already apply, nothing todo')
143 return
144 }
Denis Egorenkoe983d452019-08-23 14:29:34 +0400145 salt.fullRefresh(venvPepper, 'I@salt:master')
Denis Egorenkoada83882019-06-11 14:03:40 +0400146 for (String minion in saltMinions) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400147 // First attempt, second will be performed in next validateReclassModel() stages
148 try {
149 salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
150 } catch (Exception e) {
151 common.errorMsg(e.toString())
152 if (patched) {
153 error("Node: ${minion} failed to render after reclass-system upgrade!WA29155 probably didn't help.")
154 }
155 // check, that failed exactly by our case, by key-length check.
156 def missed_key = salt.getPillar(venvPepper, minion, '_param:nova_compute_ssh_private').get("return")[0].values()[0]
157 if (missed_key != '') {
158 error("Node: ${minion} failed to render after reclass-system upgrade!")
159 }
160 common.warningMsg('Perform: Attempt to apply WA for PROD-29155\n' +
161 'See https://gerrit.mcp.mirantis.com/#/c/37932/ for more info')
162 common.warningMsg('WA-PROD-29155 Generating new ssh key at master node')
163 def _tempFile = "/tmp/nova_wa29155_" + UUID.randomUUID().toString().take(8)
164 common.infoMsg('Perform: generation NEW ssh-private key for nova-compute')
165 salt.cmdRun(venvPepper, 'I@salt:master', "ssh-keygen -f ${_tempFile} -N '' -q")
166 def _pub_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}.pub").get('return')[0].values()[0].trim()
167 def _priv_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}").get('return')[0].values()[0].trim()
168 salt.cmdRun(venvPepper, 'I@salt:master', "rm -fv ${_tempFile}", false, null, false)
169 def novaKeysDict = [
170 "parameters": [
171 "_param": [
172 "nova_compute_ssh_private": _priv_k,
173 "nova_compute_ssh_public" : _pub_k
174 ]
175 ]
176 ]
177 writeYaml file: _tempFile, data: novaKeysDict
178 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
179 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29155File}", false, null, false)
180 common.infoMsg("Add $wa29155ClassName class into secrets.yml")
181
182 // Add 'classes:' directive
183 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
184 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
185
186 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
187 "grep -q '${wa29155ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29155ClassName' infra/secrets.yml")
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400188 salt.fullRefresh(venvPepper, 'I@salt:master')
189 salt.fullRefresh(venvPepper, saltMinions)
Denis Egorenkoada83882019-06-11 14:03:40 +0400190 patched = true
191 }
192 }
193 if (patched) {
194 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " +
195 "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()}' ")
196 common.infoMsg('Work-around for PROD-29155 successfully applied')
197 }
198
199}
200
Denis Egorenkobae9dc72019-07-29 17:44:46 +0400201def wa32284(String clusterName) {
202 def clientGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:enabled").get("return")[0].values()[0]
203 def pkiGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:volumes:salt_pki").get("return")[0].values()[0]
204 def nginxEnabledAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0]
205 if (nginxEnabledAtMaster.toString().toLowerCase() == 'true' && clientGluster.toString().toLowerCase() == 'true' && pkiGluster) {
206 def nginxRequires = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:wait_for_service').get('return')[0].values()[0]
207 if (nginxRequires.isEmpty()) {
208 def nginxRequiresClassName = "cluster.${clusterName}.infra.config.nginx_requires_wa32284"
209 def nginxRequiresClassFile = "/srv/salt/reclass/classes/cluster/${clusterName}/infra/config/nginx_requires_wa32284.yml"
210 def nginxRequiresBlock = ['parameters': ['nginx': ['server': ['wait_for_service': ['srv-salt-pki.mount'] ] ] ] ]
211 def _tempFile = '/tmp/wa32284_' + UUID.randomUUID().toString().take(8)
212 writeYaml file: _tempFile , data: nginxRequiresBlock
213 def nginxRequiresBlockString = sh(script: "cat ${_tempFile}", returnStdout: true).trim()
214 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${clusterName} && " +
215 "sed -i '/^parameters:/i - ${nginxRequiresClassName}' infra/config/init.yml")
216 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${nginxRequiresBlockString}' > ${nginxRequiresClassFile}", false, null, false)
217 }
218 }
219}
220
Denis Egorenkoda117892019-09-02 14:53:02 +0400221def wa32182(String cluster_name) {
Hanna Arhipova644aefd2019-09-06 17:55:40 +0300222 if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) {
Denis Egorenkoda117892019-09-02 14:53:02 +0400223 def clusterModelPath = "/srv/salt/reclass/classes/cluster/${cluster_name}"
224 def fixFile = "${clusterModelPath}/opencontrail/common_wa32182.yml"
225 def usualFile = "${clusterModelPath}/opencontrail/common.yml"
226 def fixFileContent = "classes:\n- system.opencontrail.common\n"
227 salt.cmdRun(venvPepper, 'I@salt:master', "test -f ${fixFile} -o -f ${usualFile} || echo '${fixFileContent}' > ${fixFile}")
228 def contrailFiles = ['opencontrail/analytics.yml', 'opencontrail/control.yml', 'openstack/compute/init.yml']
229 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
230 contrailFiles.add('kubernetes/compute.yml')
231 }
232 for(String contrailFile in contrailFiles) {
233 contrailFile = "${clusterModelPath}/${contrailFile}"
234 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()
235 if (containsFix) {
236 continue
237 } else {
238 salt.cmdRun(venvPepper, 'I@salt:master', "grep -q -E '^parameters:' ${contrailFile} && sed -i '/^parameters:/i - cluster.${cluster_name}.opencontrail.common_wa32182' ${contrailFile} || " +
239 "echo '- cluster.${cluster_name}.opencontrail.common_wa32182' >> ${contrailFile}")
240 }
241 }
242 }
243}
244
Denis Egorenko32461082019-10-25 13:13:39 +0400245def wa33867(String cluster_name) {
246 if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) {
247 def contrailControlFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/opencontrail/control.yml"
248 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()
249 if (line == "- cluster.${cluster_name}.infra") {
250 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra\$/d' ${contrailControlFile}")
251 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra.backup.client_zookeeper\$/i - cluster.${cluster_name}.infra' ${contrailControlFile}")
252 }
253 }
254}
255
Denis Egorenko7e934c22019-10-18 17:06:11 +0400256def wa33771(String cluster_name) {
257 def octaviaEnabled = salt.getMinions(venvPepper, 'I@octavia:api:enabled')
258 def octaviaWSGI = salt.getMinions(venvPepper, 'I@apache:server:site:octavia_api')
259 if (octaviaEnabled && ! octaviaWSGI) {
260 def openstackControl = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/control.yml"
261 def octaviaFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/octavia_wa33771.yml"
262 def octaviaContext = [
263 'classes': [ 'system.apache.server.site.octavia' ],
264 'parameters': [
265 '_param': [ 'apache_octavia_api_address' : '${_param:cluster_local_address}' ],
266 'apache': [ 'server': [ 'site': [ 'apache_proxy_openstack_api_octavia': [ 'enabled': false ] ] ] ]
267 ]
268 ]
269 def _tempFile = '/tmp/wa33771' + UUID.randomUUID().toString().take(8)
270 writeYaml file: _tempFile , data: octaviaContext
271 def octaviaFileContent = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
272 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.octavia_wa33771' ${openstackControl}")
273 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${octaviaFileContent}' | base64 -d > ${octaviaFile}", false, null, false)
274 }
275}
276
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400277def wa33930_33931(String cluster_name) {
278 def openstackControlFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/control.yml"
279 def fixName = 'clients_common_wa33930_33931'
280 def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/${fixName}.yml"
281 def containsFix = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- cluster\\.${cluster_name}\\.openstack\\.${fixName}\$' ${openstackControlFile}", false, null, true).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
282 if (! containsFix) {
283 def fixContext = [
284 'classes': [ 'service.nova.client', 'service.glance.client', 'service.neutron.client' ]
285 ]
286 if (salt.getMinions(venvPepper, 'I@manila:api:enabled')) {
287 fixContext['classes'] << 'service.manila.client'
288 }
289 if (salt.getMinions(venvPepper, 'I@ironic:api:enabled')) {
290 fixContext['classes'] << 'service.ironic.client'
291 }
292 if (salt.getMinions(venvPepper, 'I@gnocchi:server:enabled')) {
293 fixContext['classes'] << 'service.gnocchi.client'
294 }
295 if (salt.getMinions(venvPepper, 'I@barbican:server:enabled')) {
296 fixContext['classes'] << 'service.barbican.client.single'
297 }
298 def _tempFile = '/tmp/wa33930_33931' + UUID.randomUUID().toString().take(8)
299 writeYaml file: _tempFile , data: fixContext
300 def fixFileContent = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
301 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${fixFileContent}' | base64 -d > ${fixFile}", false, null, false)
302 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.${fixName}' ${openstackControlFile}")
303 }
304}
305
azvyagintsev6dac3802018-11-09 15:11:30 +0200306def archiveReclassInventory(filename) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400307 def _tmp_file = '/tmp/' + filename + UUID.randomUUID().toString().take(8)
308 // jenkins may fail at overheap. Compress data with gzip like WA
309 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()
310 def _tmp = sh(script: "echo '$ret' > ${_tmp_file}", returnStdout: false)
311 sh(script: "cat ${_tmp_file} | base64 -d | gzip -d > $filename", returnStdout: false)
312 archiveArtifacts artifacts: filename
313 sh(script: "rm -v ${_tmp_file}|| true")
Richard Felkl0e80d892018-06-20 13:44:54 +0200314}
315
Denis Egorenkod13ad132018-12-17 16:56:02 +0400316def validateReclassModel(ArrayList saltMinions, String suffix) {
317 try {
Denis Egorenkoada83882019-06-11 14:03:40 +0400318 for (String minion in saltMinions) {
319 common.infoMsg("Reclass model validation for minion ${minion}...")
320 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()
321 writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString()
Denis Egorenkod13ad132018-12-17 16:56:02 +0400322 }
323 } catch (Exception e) {
324 common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.')
Denis Egorenkoada83882019-06-11 14:03:40 +0400325 error(e.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400326 }
327}
328
Denis Egorenkoada83882019-06-11 14:03:40 +0400329def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix = 'before', String newSuffix = 'after') {
330 for (String minion in saltMinions) {
331 def fileName = "reclass-model-${minion}-diff.out"
332 sh "diff -u inventory-${minion}-${oldSuffix}.out inventory-${minion}-${newSuffix}.out > ${fileName} || true"
333 archiveArtifacts artifacts: "${fileName}"
Denis Egorenkod13ad132018-12-17 16:56:02 +0400334 }
335}
336
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400337if (common.validInputParam('PIPELINE_TIMEOUT')) {
338 try {
339 pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger()
Denis Egorenkoada83882019-06-11 14:03:40 +0400340 } catch (Exception e) {
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400341 common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger")
342 }
Martin Polreich965c9032018-08-09 16:33:57 +0200343}
344
345timeout(time: pipelineTimeout, unit: 'HOURS') {
Denis Egorenkoada83882019-06-11 14:03:40 +0400346 node("python") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100347 try {
Denis Egorenkoada83882019-06-11 14:03:40 +0400348 def inventoryBeforeFilename = "reclass-inventory-before.out"
349 def inventoryAfterFilename = "reclass-inventory-after.out"
Richard Felkl0e80d892018-06-20 13:44:54 +0200350 workspace = common.getWorkspace()
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200351 targetMcpVersion = null
352 if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) {
353 error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable')
azvyagintsev6dac3802018-11-09 15:11:30 +0200354 }
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200355 // bw comp. for 2018.X => 2018.11 release
Denis Egorenkoada83882019-06-11 14:03:40 +0400356 if (common.validInputParam('MCP_VERSION')) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200357 targetMcpVersion = env.MCP_VERSION
358 common.warningMsg("targetMcpVersion has been changed to:${targetMcpVersion}, which was taken from deprecated pipeline viriable:MCP_VERSION")
Denis Egorenkoada83882019-06-11 14:03:40 +0400359 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200360 targetMcpVersion = env.TARGET_MCP_VERSION
361 }
362 // end bw comp. for 2018.X => 2018.11 release
Denis Egorenkod13ad132018-12-17 16:56:02 +0400363 def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC')
Ivan Berezovskiyd62629c2019-01-16 19:26:18 +0400364 if (targetMcpVersion in ['nightly', 'testing']) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200365 gitTargetMcpVersion = 'master'
Ivan Berezovskiyd62629c2019-01-16 19:26:18 +0400366 } else if (targetMcpVersion == 'proposed') {
367 gitTargetMcpVersion = 'proposed'
Denis Egorenko284690e2018-12-25 15:55:12 +0400368 } else if (!gitTargetMcpVersion) {
369 // backward compatibility for 2018.11.0
370 gitTargetMcpVersion = "release/${targetMcpVersion}"
azvyagintsev6dac3802018-11-09 15:11:30 +0200371 }
Ivan Berezovskiyd62629c2019-01-16 19:26:18 +0400372 common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}")
Denis Egorenko284690e2018-12-25 15:55:12 +0400373 def upgradeSaltStack = ''
374 def updateClusterModel = ''
375 def updatePipelines = ''
376 def updateLocalRepos = ''
377 def reclassSystemBranch = ''
Denis Egorenkob559e542019-03-29 13:24:15 +0400378 def reclassSystemBranchDefault = gitTargetMcpVersion
Denis Egorenko70002bc2019-08-19 19:41:27 +0400379 def batchSize = ''
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400380 if (gitTargetMcpVersion ==~ /^\d\d\d\d\.\d\d?\.\d+$/) {
381 reclassSystemBranchDefault = "tags/${gitTargetMcpVersion}"
382 } else if (gitTargetMcpVersion != 'proposed') {
Denis Egorenkob559e542019-03-29 13:24:15 +0400383 reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}"
384 }
Hanna Arhipova644aefd2019-09-06 17:55:40 +0300385 def driveTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS')
386 if (driveTrainParamsYaml) {
387 def driveTrainParams = readYaml text: driveTrainParamsYaml
388 saltMastURL = driveTrainParams.get('SALT_MASTER_URL')
389 saltMastCreds = driveTrainParams.get('SALT_MASTER_CREDENTIALS')
390 upgradeSaltStack = driveTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean()
391 updateClusterModel = driveTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean()
392 updatePipelines = driveTrainParams.get('UPDATE_PIPELINES', false).toBoolean()
393 updateLocalRepos = driveTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean()
394 reclassSystemBranch = driveTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault)
Denis Egorenko70002bc2019-08-19 19:41:27 +0400395 batchSize = driveTrainParams.get('BATCH_SIZE', '')
Denis Egorenko284690e2018-12-25 15:55:12 +0400396 } else {
397 // backward compatibility for 2018.11.0
398 saltMastURL = env.getProperty('SALT_MASTER_URL')
399 saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS')
Denis Egorenkoe5f39142018-12-28 12:30:48 +0400400 upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean()
401 updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean()
402 updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean()
403 updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean()
Denis Egorenkob559e542019-03-29 13:24:15 +0400404 reclassSystemBranch = reclassSystemBranchDefault
Denis Egorenko284690e2018-12-25 15:55:12 +0400405 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400406 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400407 def minions = salt.getMinions(venvPepper, '*')
Denis Egorenkoc0538ce2019-04-19 15:05:18 +0400408 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
409 if (cluster_name == '' || cluster_name == 'null' || cluster_name == null) {
410 error('Pillar data is broken for Salt master node! Please check it manually and re-run pipeline.')
411 }
Hanna Arhipova644aefd2019-09-06 17:55:40 +0300412 if (!batchSize) {
Denis Egorenko9ef25b92019-12-19 16:45:25 +0400413 // if no batch size provided get current worker threads and set batch size to 2/3 of it to avoid
414 // 'SaltReqTimeoutError: Message timed out' issue on Salt targets for large amount of nodes
415 // do not use toDouble/Double as it requires additional approved method
416 def workerThreads = getWorkerThreads(venvPepper).toInteger()
417 batch_size = (workerThreads * 2 / 3).toString().tokenize('.')[0]
Denis Egorenko70002bc2019-08-19 19:41:27 +0400418 }
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400419 def computeMinions = salt.getMinions(venvPepper, 'I@nova:compute')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400420
Denis Egorenkoada83882019-06-11 14:03:40 +0400421 stage('Update Reclass and Salt-Formulas') {
422 common.infoMsg('Perform: Full salt sync')
423 salt.fullRefresh(venvPepper, '*')
424 common.infoMsg('Perform: Validate reclass medata before processing')
425 validateReclassModel(minions, 'before')
426
427 common.infoMsg('Perform: archiveReclassInventory before upgrade')
Denis Egorenko89a3c572019-03-22 17:03:40 +0400428 archiveReclassInventory(inventoryBeforeFilename)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400429
azvyagintsev6dac3802018-11-09 15:11:30 +0200430 try {
Denis Egorenkoada83882019-06-11 14:03:40 +0400431 salt.cmdRun(venvPepper, 'I@salt:master', 'cd /srv/salt/reclass/ && git status && git diff-index --quiet HEAD --')
Richard Felkl970e0082018-06-12 18:00:51 +0200432 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200433 catch (Exception ex) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400434 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 +0200435 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400436 if (updateClusterModel) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200437 common.infoMsg('Perform: UPDATE_CLUSTER_MODEL')
Sergey382581a2018-10-25 12:22:26 +0400438 def dateTime = common.getDatetime()
Denis Egorenko00897c52019-03-18 15:47:33 +0400439 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/ && git submodule foreach git fetch")
Sergey382581a2018-10-25 12:22:26 +0400440 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400441 "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 +0200442 // Do the same, for deprecated variable-duplicate
443 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400444 "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 +0400445 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400446 "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 +0400447 // Set new k8s param
448 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
449 "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 +0400450 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
451 "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'")
452 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoca871c22019-02-13 13:49:13 +0400453 "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 +0400454 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoca871c22019-02-13 13:49:13 +0400455 "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 +0400456 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoada83882019-06-11 14:03:40 +0400457 "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 +0400458
Denis Egorenko70f4f9a2019-09-16 16:41:26 +0400459 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")
460 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name/infra && sed -i '/maas_region_main_archive/d' maas.yml")
461
Denis Egorenko6ca9f0d2019-07-10 19:47:39 +0400462 // Switch Jenkins/Gerrit to use LDAP SSL/TLS
463 def gerritldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
464 "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()
465 if (gerritldapURI.startsWith('ldap://')) {
466 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
467 "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
468 } else if (! gerritldapURI.startsWith('ldaps://')) {
469 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
470 "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'")
471 }
472 def jenkinsldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
473 "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()
474 if (jenkinsldapURI.startsWith('ldap://')) {
475 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
476 "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
477 } else if (! jenkinsldapURI.startsWith('ldaps://')) {
478 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
479 "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'")
480 }
481
Denis Egorenkobae9dc72019-07-29 17:44:46 +0400482 wa32284(cluster_name)
483
Denis Egorenkod13ad132018-12-17 16:56:02 +0400484 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}")
Sergey Kolekonov6ab15112019-01-23 16:47:43 +0400485 // Add kubernetes-extra repo
486 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
Sergey Kolekonovac9554c2019-04-11 16:33:54 +0400487 // docker-engine conflicts with the recent containerd versions, so it's removed during upgrade. Thus update source engine
488 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
489 "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 +0400490 common.infoMsg("Add kubernetes-extra repo")
491 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
492 "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")
493 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
494 "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")
495 }
Ivan Berezovskiybe630ee2019-04-15 13:23:58 +0400496 // Add all update repositories
497 def repoIncludeBase = '- system.linux.system.repo.mcp.apt_mirantis.'
Denis Egorenko70f4f9a2019-09-16 16:41:26 +0400498 def updateRepoList = ['cassandra', 'ceph', 'contrail', 'docker', 'elastic', 'extra', 'openstack', 'maas', 'percona', 'salt-formulas', 'saltstack', 'ubuntu']
Ivan Berezovskiybe630ee2019-04-15 13:23:58 +0400499 updateRepoList.each { repo ->
500 def repoNameUpdateInclude = "${repoIncludeBase}update.${repo}"
501 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')
502 filesWithInclude.each { file ->
503 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()
504 if (updateRepoIncludeExist == 'not_found') {
505 // Include needs to be added
506 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoada83882019-06-11 14:03:40 +0400507 "sed -i 's/\\( *\\)${repoIncludeBase}${repo}\$/&\\n\\1${repoNameUpdateInclude}/g' ${file}")
Ivan Berezovskiybe630ee2019-04-15 13:23:58 +0400508 common.infoMsg("Update repo for ${repo} is added to ${file}")
509 }
510 }
511 }
Denis Egorenkoda117892019-09-02 14:53:02 +0400512 wa32182(cluster_name)
Denis Egorenko7e934c22019-10-18 17:06:11 +0400513 wa33771(cluster_name)
Denis Egorenko32461082019-10-25 13:13:39 +0400514 wa33867(cluster_name)
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400515 wa33930_33931(cluster_name)
Sergey382581a2018-10-25 12:22:26 +0400516 // Add new defaults
517 common.infoMsg("Add new defaults")
Denis Egorenkod13ad132018-12-17 16:56:02 +0400518 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 +0400519 "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 +0400520 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 +0400521 "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 +0400522 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
523 "grep -r -l 'docker_image_jenkins: .*' cicd | xargs --no-run-if-empty sed -i 's|\\s*docker_image_jenkins: .*||g'")
524 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
525 "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 +0400526 common.infoMsg("The following changes were made to the cluster model and will be commited. " +
azvyagintsev6dac3802018-11-09 15:11:30 +0200527 "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 +0400528 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff")
529 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " +
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200530 "git add -u && git commit --allow-empty -m 'Cluster model update to the release $targetMcpVersion on $dateTime'")
Sergey382581a2018-10-25 12:22:26 +0400531 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400532 try {
533 common.infoMsg('Perform: UPDATE Salt Formulas')
Denis Egorenkoada83882019-06-11 14:03:40 +0400534 salt.fullRefresh(venvPepper, '*')
535 salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400536 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 +0400537 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas", 'salt.master.env'])
538 salt.fullRefresh(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400539 } catch (Exception updateErr) {
540 common.warningMsg(updateErr)
541 common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
542 input message: 'Continue anyway?'
543 }
544
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400545 wa29352(cluster_name)
Denis Egorenkoe983d452019-08-23 14:29:34 +0400546 wa29155(computeMinions, cluster_name)
Denis Egorenkoada83882019-06-11 14:03:40 +0400547
Denis Egorenkod13ad132018-12-17 16:56:02 +0400548 try {
549 common.infoMsg('Perform: UPDATE Reclass package')
550 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"])
551 } catch (Exception updateErr) {
552 common.warningMsg(updateErr)
553 common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
554 input message: 'Continue anyway?'
555 }
556
557 salt.fullRefresh(venvPepper, 'I@salt:master')
Sergey1b81c062018-10-16 17:10:21 +0400558 salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true)
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400559 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && " +
560 "git add -u && git commit --allow-empty -m 'Reclass nodes update to the release ${targetMcpVersion} on ${common.getDatetime()}'")
Denis Egorenkod13ad132018-12-17 16:56:02 +0400561 try {
562 salt.enforceState(venvPepper, "I@salt:master", 'reclass', true)
563 }
564 catch (Exception ex) {
565 error("Reclass fails rendering. Pay attention to your cluster model.")
566 }
567
568 salt.fullRefresh(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400569 try {
570 salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top")
571 }
572 catch (Exception ex) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400573
574 error('Reclass fails rendering. Pay attention to your cluster model.' +
575 'ErrorMessage:' + ex.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400576 }
577
Denis Egorenkoada83882019-06-11 14:03:40 +0400578 common.infoMsg('Perform: archiveReclassInventory AFTER upgrade')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400579 archiveReclassInventory(inventoryAfterFilename)
580
581 sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true"
582 archiveArtifacts artifacts: "reclass-inventory-diff.out"
583
Denis Egorenkoada83882019-06-11 14:03:40 +0400584 validateReclassModel(minions, 'after')
585 archiveReclassModelChanges(minions)
Jakub Josefa63f9862018-01-11 17:58:38 +0100586 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100587
Denis Egorenkod13ad132018-12-17 16:56:02 +0400588 if (updateLocalRepos) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200589 stage("Update local repos") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100590 common.infoMsg("Updating local repositories")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700591
Sergey1b81c062018-10-16 17:10:21 +0400592 def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700593 runningOnDocker = engine.get("return")[0].containsValue("docker")
594
595 if (runningOnDocker) {
596 common.infoMsg("Aptly is running as Docker container")
azvyagintsev6dac3802018-11-09 15:11:30 +0200597 } else {
Sam Stoelingaaab79702018-04-09 18:49:39 -0700598 common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands")
599 }
600
azvyagintsev6dac3802018-11-09 15:11:30 +0200601 if (runningOnDocker) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200602 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 +0200603 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200604 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 +0100605 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100606
Sergey1b81c062018-10-16 17:10:21 +0400607 salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100608
azvyagintsev6dac3802018-11-09 15:11:30 +0200609 if (runningOnDocker) {
Sergey1b81c062018-10-16 17:10:21 +0400610 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true)
611 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 +0200612 } else {
Sergey1b81c062018-10-16 17:10:21 +0400613 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true)
614 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 +0100615 }
Richard Felkl79d7df12018-01-05 16:40:11 +0100616
Sergey1b81c062018-10-16 17:10:21 +0400617 salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100618
Sergey1b81c062018-10-16 17:10:21 +0400619 salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100620
Sergey1b81c062018-10-16 17:10:21 +0400621 salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100622
Sergey1b81c062018-10-16 17:10:21 +0400623 salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100624 }
625 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100626
Denis Egorenkoada83882019-06-11 14:03:40 +0400627 stage('Update Drivetrain') {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400628 if (upgradeSaltStack) {
629 updateSaltStack("I@salt:master", '["salt-master", "salt-common", "salt-api", "salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200630
Denis Egorenko70002bc2019-08-19 19:41:27 +0400631 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.repo', true, true, batchSize)
Richard Felkl0e80d892018-06-20 13:44:54 +0200632 updateSaltStack("I@salt:minion and not I@salt:master", '["salt-minion"]')
633 }
634
Denis Egorenkod13ad132018-12-17 16:56:02 +0400635 if (updatePipelines) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400636 common.infoMsg('Perform: UPDATE git repos')
637 triggerMirrorJob('git-mirror-downstream-mk-pipelines', reclassSystemBranch)
638 triggerMirrorJob('git-mirror-downstream-pipeline-library', reclassSystemBranch)
Richard Felkl970e0082018-06-12 18:00:51 +0200639 }
640
Denis Egorenkod00c17e2019-04-25 20:17:27 +0400641 // update minions certs
Denis Egorenko70002bc2019-08-19 19:41:27 +0400642 salt.enforceState(venvPepper, "I@salt:minion", 'salt.minion.cert', true, true, batchSize)
Denis Egorenkoada83882019-06-11 14:03:40 +0400643
644 // Retry needed only for rare race-condition in user appearance
645 common.infoMsg('Perform: updating users and keys')
Denis Egorenko70002bc2019-08-19 19:41:27 +0400646 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.user', true, true, batchSize)
Denis Egorenkoada83882019-06-11 14:03:40 +0400647 common.infoMsg('Perform: updating openssh')
Denis Egorenko70002bc2019-08-19 19:41:27 +0400648 salt.enforceState(venvPepper, "I@linux:system", 'openssh', true, true, batchSize)
Denis Egorenkoaeaa1de2019-01-15 11:58:12 +0400649
Denis Egorenkoe69920e2019-10-30 13:26:59 +0400650 // Gerrit 2019.2.0 (2.13.6) version has wrong file name for download-commands plugin and was not loaded, let's remove if still there before upgrade
651 def gerritGlusterPath = salt.getPillar(venvPepper, 'I@gerrit:client', 'glusterfs:client:volumes:gerrit:path').get('return')[0].values()[0]
652 def wrongPluginJarName = "${gerritGlusterPath}/plugins/project-download-commands.jar"
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400653 salt.cmdRun(venvPepper, 'I@gerrit:client', "test -f ${wrongPluginJarName} && rm ${wrongPluginJarName} || true")
Denis Egorenkoe69920e2019-10-30 13:26:59 +0400654
Denis Egorenkoada83882019-06-11 14:03:40 +0400655 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")
Ivan Berezovskiy24b0be02019-12-11 15:31:10 +0400656 }
657 }
658 catch (Throwable e) {
659 // If there was an error or exception thrown, the build failed
660 currentBuild.result = "FAILURE"
661 throw e
662 }
663 }
664 // docker.client state may trigger change of jenkins master or jenkins slave services,
665 // so we need wait for slave to reconnect and continue pipeline
666 sleep(180)
667 node('python') {
668 try {
669 stage('Update Drivetrain: Phase 2') {
670 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenkoada83882019-06-11 14:03:40 +0400671 common.infoMsg('Perform: Checking if Docker containers are up')
azvyagintsev6dac3802018-11-09 15:11:30 +0200672 try {
673 common.retry(10, 30) {
Richard Felkl970e0082018-06-12 18:00:51 +0200674 salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'")
675 }
676 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200677 catch (Exception ex) {
Richard Felkl970e0082018-06-12 18:00:51 +0200678 error("Docker containers for CI/CD services are having troubles with starting.")
679 }
Denis Egorenko6ca9f0d2019-07-10 19:47:39 +0400680
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400681 // Apply changes for HaProxy on CI/CD nodes
682 salt.enforceState(venvPepper, 'I@keepalived:cluster:instance:cicd_control_vip and I@haproxy:proxy', 'haproxy.proxy', true)
683
684 salt.enforceState(venvPepper, 'I@jenkins:client and not I@salt:master', 'jenkins.client', true, true, null, false, 60, 2)
Denis Egorenko84a0bc02019-07-23 18:01:21 +0400685
686 // update Nginx proxy settings for Jenkins/Gerrit if needed
687 if (salt.testTarget(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit')) {
688 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)
689 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100690 }
691 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100692 catch (Throwable e) {
693 // If there was an error or exception thrown, the build failed
694 currentBuild.result = "FAILURE"
695 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +0100696 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100697 }
Hanna Arhipova644aefd2019-09-06 17:55:40 +0300698}