blob: 877a4bc8bf92ebaa22ddc89641ce767350969f4d [file] [log] [blame]
Richard Felkl26cae4d2017-12-19 00:19:16 +01001/**
2 *
3 * Update Salt environment pipeline
4 *
5 * Expected parameters:
azvyagintsev6dac3802018-11-09 15:11:30 +02006 * TARGET_MCP_VERSION Version of MCP to upgrade to
Denis Egorenkod13ad132018-12-17 16:56:02 +04007 * GIT_REFSPEC Git repo ref to be used
8 * DRIVE_TRAIN_PARAMS Yaml, DriveTrain releated params:
9 * SALT_MASTER_URL Salt API server location
10 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040011 * BATCH_SIZE Use batch sizing during upgrade for large envs
Denis Egorenkod13ad132018-12-17 16:56:02 +040012 * UPGRADE_SALTSTACK Upgrade SaltStack packages to new version.
13 * UPDATE_CLUSTER_MODEL Update MCP version parameter in cluster model
14 * UPDATE_PIPELINES Update pipeline repositories on Gerrit
15 * UPDATE_LOCAL_REPOS Update local repositories
Richard Felkl26cae4d2017-12-19 00:19:16 +010016 */
17
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010018salt = new com.mirantis.mk.Salt()
19common = new com.mirantis.mk.Common()
20python = new com.mirantis.mk.Python()
Richard Felkl970e0082018-06-12 18:00:51 +020021jenkinsUtils = new com.mirantis.mk.JenkinsUtils()
azvyagintsevf3bf77a2018-11-15 19:30:04 +020022def pipelineTimeout = 12
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010023venvPepper = "venvPepper"
Richard Felkl0e80d892018-06-20 13:44:54 +020024workspace = ""
Ivan Berezovskiya766d432019-12-11 15:31:10 +040025def saltMastURL = ''
26def saltMastCreds = ''
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010027
azvyagintsevbc359d42019-04-10 19:53:22 +030028def triggerMirrorJob(String jobName, String reclassSystemBranch) {
Richard Felkl970e0082018-06-12 18:00:51 +020029 params = jenkinsUtils.getJobParameters(jobName)
azvyagintsevbc359d42019-04-10 19:53:22 +030030 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) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +030050 salt.cmdRun(venvPepper, 'I@salt:master', "salt -C '${target}' --async pkg.install force_yes=True pkgs='$pkgs'")
Denis Egorenko4b54e7f2019-02-26 16:05:03 +040051 // 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 Egorenko20a43462019-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 Berezovskiyf5c911b2019-12-03 18:49:09 +040083def wa29352(String cname) {
azvyagintsev745a6e52019-04-18 13:19:39 +030084 // 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 Egorenkodfa35422019-10-07 12:46:14 +040096 common.infoMsg('Work-around for PROD-29352 already applied, nothing todo')
azvyagintsev745a6e52019-04-18 13:19:39 +030097 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 Egorenkodfa35422019-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')
azvyagintsev745a6e52019-04-18 13:19:39 +0300128}
129
azvyagintsevbc359d42019-04-10 19:53:22 +0300130def 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 Egorenko14fa6e12019-08-23 14:29:34 +0400145 salt.fullRefresh(venvPepper, 'I@salt:master')
azvyagintsevbc359d42019-04-10 19:53:22 +0300146 for (String minion in saltMinions) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300147 // First attempt, second will be performed in next validateReclassModel() stages
148 try {
azvyagintsev745a6e52019-04-18 13:19:39 +0300149 salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
azvyagintsevbc359d42019-04-10 19:53:22 +0300150 } 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 }
azvyagintsev745a6e52019-04-18 13:19:39 +0300160 common.warningMsg('Perform: Attempt to apply WA for PROD-29155\n' +
161 'See https://gerrit.mcp.mirantis.com/#/c/37932/ for more info')
azvyagintsevbc359d42019-04-10 19:53:22 +0300162 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 ]
azvyagintsev745a6e52019-04-18 13:19:39 +0300177 writeYaml file: _tempFile, data: novaKeysDict
azvyagintsevbc359d42019-04-10 19:53:22 +0300178 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 Berezovskiyf5c911b2019-12-03 18:49:09 +0400188 salt.fullRefresh(venvPepper, 'I@salt:master')
189 salt.fullRefresh(venvPepper, saltMinions)
azvyagintsevbc359d42019-04-10 19:53:22 +0300190 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 Egorenko1b11d232019-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 Egorenkoaf18b252019-09-02 14:53:02 +0400221def wa32182(String cluster_name) {
Hanna Arhipovad5eec4c2019-09-06 17:55:40 +0300222 if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) {
Denis Egorenkoaf18b252019-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 Egorenkoba631332019-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 Egorenkoe312cc92019-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 Egorenkoe9fc0592019-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) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300307 def _tmp_file = '/tmp/' + filename + UUID.randomUUID().toString().take(8)
308 // jenkins may fail at overheap. Compress data with gzip like WA
azvyagintsev745a6e52019-04-18 13:19:39 +0300309 def ret = salt.cmdRun(venvPepper, 'I@salt:master', 'reclass -i 2>/dev/null | gzip -9 -c | base64', true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
azvyagintsevbc359d42019-04-10 19:53:22 +0300310 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 {
azvyagintsevbc359d42019-04-10 19:53:22 +0300318 for (String minion in saltMinions) {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400319 common.infoMsg("Reclass model validation for minion ${minion}...")
azvyagintsev745a6e52019-04-18 13:19:39 +0300320 def reclassInv = salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
Denis Egorenkod13ad132018-12-17 16:56:02 +0400321 writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString()
322 }
323 } catch (Exception e) {
324 common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.')
azvyagintsevbc359d42019-04-10 19:53:22 +0300325 error(e.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400326 }
327}
328
azvyagintsevbc359d42019-04-10 19:53:22 +0300329def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix = 'before', String newSuffix = 'after') {
330 for (String minion in saltMinions) {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400331 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}"
334 }
335}
336
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300337def checkDebsums() {
338 // check for salt-formulas consistency
339 try {
340 try {
341 salt.cmdRun(venvPepper, 'I@salt:master', "salt -C 'I@salt:master' pkg.install force_yes=True pkgs=[debsums]")
342 }
343 catch (Exception ex) {
344 common.warningMsg('Unable to install package "debsums" at cfg01. Salt-formulas integrity check skipped')
345 }
346 salt.cmdRun(venvPepper, 'I@salt:master', '> /root/debdsums_report; for i in $(dpkg-query -W -f=\'${Package}\\n\' | sed "s/ //g" |grep \'salt-formula-\'); do debsums -s ${i} 2>> /root/debdsums_report; done')
347 salt.cmdRun(venvPepper, 'I@salt:master', 'if [ -s "/root/debdsums_report" ]; then exit 1 ; fi')
348 }
349 catch (Exception ex) {
350 common.errorMsg(salt.cmdRun(venvPepper, 'I@salt:master', 'cat /root/debdsums_report ', true, null, false).get('return')[0].values()[0].trim())
351 common.errorMsg(ex.toString())
352 error('You have unexpected changes in formulas. All of them will be overwrited by update. Unable to continue in automatic way')
353 }
354}
355
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400356if (common.validInputParam('PIPELINE_TIMEOUT')) {
357 try {
358 pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger()
azvyagintsevbc359d42019-04-10 19:53:22 +0300359 } catch (Exception e) {
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400360 common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger")
361 }
Martin Polreich965c9032018-08-09 16:33:57 +0200362}
363
364timeout(time: pipelineTimeout, unit: 'HOURS') {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300365 node('python') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100366 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300367 def inventoryBeforeFilename = "reclass-inventory-before.out"
368 def inventoryAfterFilename = "reclass-inventory-after.out"
Richard Felkl0e80d892018-06-20 13:44:54 +0200369 workspace = common.getWorkspace()
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200370 targetMcpVersion = null
371 if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) {
372 error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable')
azvyagintsev6dac3802018-11-09 15:11:30 +0200373 }
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200374 // bw comp. for 2018.X => 2018.11 release
azvyagintsevbc359d42019-04-10 19:53:22 +0300375 if (common.validInputParam('MCP_VERSION')) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200376 targetMcpVersion = env.MCP_VERSION
377 common.warningMsg("targetMcpVersion has been changed to:${targetMcpVersion}, which was taken from deprecated pipeline viriable:MCP_VERSION")
azvyagintsevbc359d42019-04-10 19:53:22 +0300378 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200379 targetMcpVersion = env.TARGET_MCP_VERSION
380 }
381 // end bw comp. for 2018.X => 2018.11 release
Denis Egorenkod13ad132018-12-17 16:56:02 +0400382 def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC')
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400383 if (targetMcpVersion in ['nightly', 'testing']) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200384 gitTargetMcpVersion = 'master'
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400385 } else if (targetMcpVersion == 'proposed') {
386 gitTargetMcpVersion = 'proposed'
Denis Egorenko284690e2018-12-25 15:55:12 +0400387 } else if (!gitTargetMcpVersion) {
388 // backward compatibility for 2018.11.0
389 gitTargetMcpVersion = "release/${targetMcpVersion}"
azvyagintsev6dac3802018-11-09 15:11:30 +0200390 }
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400391 common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}")
Denis Egorenko284690e2018-12-25 15:55:12 +0400392 def upgradeSaltStack = ''
393 def updateClusterModel = ''
394 def updatePipelines = ''
395 def updateLocalRepos = ''
396 def reclassSystemBranch = ''
Denis Egorenko517e06c2019-03-29 13:24:15 +0400397 def reclassSystemBranchDefault = gitTargetMcpVersion
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400398 def batchSize = ''
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400399 if (gitTargetMcpVersion ==~ /^\d\d\d\d\.\d\d?\.\d+$/) {
400 reclassSystemBranchDefault = "tags/${gitTargetMcpVersion}"
401 } else if (gitTargetMcpVersion != 'proposed') {
Denis Egorenko517e06c2019-03-29 13:24:15 +0400402 reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}"
403 }
Hanna Arhipovad5eec4c2019-09-06 17:55:40 +0300404 def driveTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS')
405 if (driveTrainParamsYaml) {
406 def driveTrainParams = readYaml text: driveTrainParamsYaml
407 saltMastURL = driveTrainParams.get('SALT_MASTER_URL')
408 saltMastCreds = driveTrainParams.get('SALT_MASTER_CREDENTIALS')
409 upgradeSaltStack = driveTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean()
410 updateClusterModel = driveTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean()
411 updatePipelines = driveTrainParams.get('UPDATE_PIPELINES', false).toBoolean()
412 updateLocalRepos = driveTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean()
413 reclassSystemBranch = driveTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault)
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400414 batchSize = driveTrainParams.get('BATCH_SIZE', '')
Denis Egorenko284690e2018-12-25 15:55:12 +0400415 } else {
416 // backward compatibility for 2018.11.0
417 saltMastURL = env.getProperty('SALT_MASTER_URL')
418 saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS')
Denis Egorenkoe5f39142018-12-28 12:30:48 +0400419 upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean()
420 updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean()
421 updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean()
422 updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean()
Denis Egorenko517e06c2019-03-29 13:24:15 +0400423 reclassSystemBranch = reclassSystemBranchDefault
Denis Egorenko284690e2018-12-25 15:55:12 +0400424 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400425 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400426 def minions = salt.getMinions(venvPepper, '*')
Denis Egorenkofbcee412019-04-19 15:05:18 +0400427 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
428 if (cluster_name == '' || cluster_name == 'null' || cluster_name == null) {
429 error('Pillar data is broken for Salt master node! Please check it manually and re-run pipeline.')
430 }
Hanna Arhipovad5eec4c2019-09-06 17:55:40 +0300431 if (!batchSize) {
Denis Egorenko7b098c32019-12-19 16:45:25 +0400432 // if no batch size provided get current worker threads and set batch size to 2/3 of it to avoid
433 // 'SaltReqTimeoutError: Message timed out' issue on Salt targets for large amount of nodes
434 // do not use toDouble/Double as it requires additional approved method
435 def workerThreads = getWorkerThreads(venvPepper).toInteger()
436 batch_size = (workerThreads * 2 / 3).toString().tokenize('.')[0]
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400437 }
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400438 def computeMinions = salt.getMinions(venvPepper, 'I@nova:compute')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400439
azvyagintsevbc359d42019-04-10 19:53:22 +0300440 stage('Update Reclass and Salt-Formulas') {
441 common.infoMsg('Perform: Full salt sync')
442 salt.fullRefresh(venvPepper, '*')
443 common.infoMsg('Perform: Validate reclass medata before processing')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400444 validateReclassModel(minions, 'before')
445
azvyagintsev745a6e52019-04-18 13:19:39 +0300446 common.infoMsg('Perform: archiveReclassInventory before upgrade')
447 archiveReclassInventory(inventoryBeforeFilename)
448
azvyagintsev6dac3802018-11-09 15:11:30 +0200449 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300450 salt.cmdRun(venvPepper, 'I@salt:master', 'cd /srv/salt/reclass/ && git status && git diff-index --quiet HEAD --')
Richard Felkl970e0082018-06-12 18:00:51 +0200451 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200452 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300453 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 +0200454 }
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300455 checkDebsums()
Denis Egorenkod13ad132018-12-17 16:56:02 +0400456 if (updateClusterModel) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200457 common.infoMsg('Perform: UPDATE_CLUSTER_MODEL')
Sergey382581a2018-10-25 12:22:26 +0400458 def dateTime = common.getDatetime()
Denis Egorenko20254e72019-03-18 15:47:33 +0400459 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/ && git submodule foreach git fetch")
Sergey382581a2018-10-25 12:22:26 +0400460 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400461 "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 +0200462 // Do the same, for deprecated variable-duplicate
463 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400464 "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 +0400465 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400466 "grep -r --exclude-dir=aptly -l 'jenkins_pipelines_branch: .*' * | xargs --no-run-if-empty sed -i 's|jenkins_pipelines_branch: .*|jenkins_pipelines_branch: \"$gitTargetMcpVersion\"|g'")
Victor Ryzhenkinabbefe62019-01-15 19:58:03 +0400467 // Set new k8s param
468 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
469 "grep -r --exclude-dir=aptly -l 'kubernetes_containerd_enabled: .*' * | xargs --no-run-if-empty sed -i 's|kubernetes_containerd_enabled: .*|kubernetes_containerd_enabled: True|g'")
Denis Egorenkoe5b49512019-01-16 19:18:31 +0400470 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
471 "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'")
472 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko301cc8a2019-02-13 13:49:13 +0400473 "grep -r --exclude-dir=aptly -l 'system.linux.system.repo.mcp.contrail' * | xargs --no-run-if-empty sed -i 's/system.linux.system.repo.mcp.contrail/system.linux.system.repo.mcp.apt_mirantis.contrail/g'")
Denis Egorenkoe5b49512019-01-16 19:18:31 +0400474 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko301cc8a2019-02-13 13:49:13 +0400475 "grep -r --exclude-dir=aptly -l 'system.linux.system.repo.mcp.updates' * | xargs --no-run-if-empty sed -i 's/system.linux.system.repo.mcp.updates/system.linux.system.repo.mcp.apt_mirantis.update/g'")
Anton Samoylov308c7ca2019-02-13 15:57:13 +0400476 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsevbc359d42019-04-10 19:53:22 +0300477 "grep -r --exclude-dir=aptly -l 'system.linux.system.repo.mcp.extra' * | xargs --no-run-if-empty sed -i 's/system.linux.system.repo.mcp.extra/system.linux.system.repo.mcp.apt_mirantis.extra/g'")
Denis Egorenko21c78be2019-07-10 19:47:39 +0400478
Denis Egorenko6f07b592019-09-16 16:41:26 +0400479 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")
480 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name/infra && sed -i '/maas_region_main_archive/d' maas.yml")
481
Denis Egorenko21c78be2019-07-10 19:47:39 +0400482 // Switch Jenkins/Gerrit to use LDAP SSL/TLS
483 def gerritldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
484 "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()
485 if (gerritldapURI.startsWith('ldap://')) {
486 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
487 "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
488 } else if (! gerritldapURI.startsWith('ldaps://')) {
489 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
490 "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'")
491 }
492 def jenkinsldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
493 "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()
494 if (jenkinsldapURI.startsWith('ldap://')) {
495 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
496 "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
497 } else if (! jenkinsldapURI.startsWith('ldaps://')) {
498 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
499 "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'")
500 }
501
Denis Egorenko1b11d232019-07-29 17:44:46 +0400502 wa32284(cluster_name)
503
Denis Egorenkod13ad132018-12-17 16:56:02 +0400504 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}")
Sergey Kolekonov5dfbf7a2019-01-23 16:47:43 +0400505 // Add kubernetes-extra repo
506 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
Sergey Kolekonov3fde8b12019-04-11 16:33:54 +0400507 // docker-engine conflicts with the recent containerd versions, so it's removed during upgrade. Thus update source engine
508 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
509 "grep -r -l 'engine: docker_hybrid' kubernetes | xargs --no-run-if-empty sed -i 's/engine: docker_hybrid/engine: archive/g'")
Sergey Kolekonov5dfbf7a2019-01-23 16:47:43 +0400510 common.infoMsg("Add kubernetes-extra repo")
511 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
512 "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")
513 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
514 "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")
515 }
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400516 // Add all update repositories
517 def repoIncludeBase = '- system.linux.system.repo.mcp.apt_mirantis.'
Denis Egorenko6f07b592019-09-16 16:41:26 +0400518 def updateRepoList = ['cassandra', 'ceph', 'contrail', 'docker', 'elastic', 'extra', 'openstack', 'maas', 'percona', 'salt-formulas', 'saltstack', 'ubuntu']
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400519 updateRepoList.each { repo ->
520 def repoNameUpdateInclude = "${repoIncludeBase}update.${repo}"
521 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')
522 filesWithInclude.each { file ->
523 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()
524 if (updateRepoIncludeExist == 'not_found') {
525 // Include needs to be added
526 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsevbc359d42019-04-10 19:53:22 +0300527 "sed -i 's/\\( *\\)${repoIncludeBase}${repo}\$/&\\n\\1${repoNameUpdateInclude}/g' ${file}")
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400528 common.infoMsg("Update repo for ${repo} is added to ${file}")
529 }
530 }
531 }
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400532 wa32182(cluster_name)
Denis Egorenkoe312cc92019-10-18 17:06:11 +0400533 wa33771(cluster_name)
Denis Egorenkoba631332019-10-25 13:13:39 +0400534 wa33867(cluster_name)
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400535 wa33930_33931(cluster_name)
Sergey382581a2018-10-25 12:22:26 +0400536 // Add new defaults
537 common.infoMsg("Add new defaults")
Denis Egorenkod13ad132018-12-17 16:56:02 +0400538 salt.cmdRun(venvPepper, 'I@salt:master', "grep '^ mcp_version: ' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400539 "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 +0400540 salt.cmdRun(venvPepper, 'I@salt:master', "grep '^- system.defaults\$' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400541 "sed -i 's|^classes:|classes:\\n- system.defaults|' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml")
Ivan Berezovskiy5113c7c2019-04-23 14:32:02 +0400542 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300543 "grep -r -l 'docker_image_jenkins: .*' cicd | xargs --no-run-if-empty sed -i 's|\\s*docker_image_jenkins: .*||g'")
Ivan Berezovskiy5113c7c2019-04-23 14:32:02 +0400544 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300545 "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 +0400546 common.infoMsg("The following changes were made to the cluster model and will be commited. " +
azvyagintsev6dac3802018-11-09 15:11:30 +0200547 "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 +0400548 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff")
549 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " +
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200550 "git add -u && git commit --allow-empty -m 'Cluster model update to the release $targetMcpVersion on $dateTime'")
Sergey382581a2018-10-25 12:22:26 +0400551 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400552 try {
553 common.infoMsg('Perform: UPDATE Salt Formulas')
azvyagintsevca97a112019-04-22 17:53:40 +0300554 salt.fullRefresh(venvPepper, '*')
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400555 salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400556 def saltEnv = salt.getPillar(venvPepper, 'I@salt:master', "_param:salt_master_base_environment").get("return")[0].values()[0]
azvyagintsevbc359d42019-04-10 19:53:22 +0300557 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas", 'salt.master.env'])
azvyagintsevca97a112019-04-22 17:53:40 +0300558 salt.fullRefresh(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400559 } catch (Exception updateErr) {
560 common.warningMsg(updateErr)
561 common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
562 input message: 'Continue anyway?'
563 }
564
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400565 wa29352(cluster_name)
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400566 wa29155(computeMinions, cluster_name)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400567
568 try {
569 common.infoMsg('Perform: UPDATE Reclass package')
570 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"])
571 } catch (Exception updateErr) {
572 common.warningMsg(updateErr)
573 common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
574 input message: 'Continue anyway?'
575 }
576
577 salt.fullRefresh(venvPepper, 'I@salt:master')
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400578 salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true, true, null, false, 60, 2)
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400579 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && " +
580 "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 +0400581 try {
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400582 salt.enforceState(venvPepper, 'I@salt:master', 'reclass', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400583 }
584 catch (Exception ex) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300585 common.errorMsg(ex.toString())
586 error('Reclass fails rendering. Pay attention to your cluster model.')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400587 }
588
589 salt.fullRefresh(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400590 try {
591 salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top")
592 }
593 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300594
595 error('Reclass fails rendering. Pay attention to your cluster model.' +
596 'ErrorMessage:' + ex.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400597 }
598
azvyagintsevbc359d42019-04-10 19:53:22 +0300599 common.infoMsg('Perform: archiveReclassInventory AFTER upgrade')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400600 archiveReclassInventory(inventoryAfterFilename)
601
602 sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true"
603 archiveArtifacts artifacts: "reclass-inventory-diff.out"
604
605 validateReclassModel(minions, 'after')
606 archiveReclassModelChanges(minions)
Jakub Josefa63f9862018-01-11 17:58:38 +0100607 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100608
Denis Egorenkod13ad132018-12-17 16:56:02 +0400609 if (updateLocalRepos) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200610 stage("Update local repos") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100611 common.infoMsg("Updating local repositories")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700612
Sergey1b81c062018-10-16 17:10:21 +0400613 def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700614 runningOnDocker = engine.get("return")[0].containsValue("docker")
615
616 if (runningOnDocker) {
617 common.infoMsg("Aptly is running as Docker container")
azvyagintsev6dac3802018-11-09 15:11:30 +0200618 } else {
Sam Stoelingaaab79702018-04-09 18:49:39 -0700619 common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands")
620 }
621
azvyagintsev6dac3802018-11-09 15:11:30 +0200622 if (runningOnDocker) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200623 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 +0200624 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200625 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 +0100626 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100627
Sergey1b81c062018-10-16 17:10:21 +0400628 salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100629
azvyagintsev6dac3802018-11-09 15:11:30 +0200630 if (runningOnDocker) {
Sergey1b81c062018-10-16 17:10:21 +0400631 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true)
632 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 +0200633 } else {
Sergey1b81c062018-10-16 17:10:21 +0400634 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true)
635 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 +0100636 }
Richard Felkl79d7df12018-01-05 16:40:11 +0100637
Sergey1b81c062018-10-16 17:10:21 +0400638 salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100639
Sergey1b81c062018-10-16 17:10:21 +0400640 salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100641
Sergey1b81c062018-10-16 17:10:21 +0400642 salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100643
Sergey1b81c062018-10-16 17:10:21 +0400644 salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100645 }
646 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100647
azvyagintsevbc359d42019-04-10 19:53:22 +0300648 stage('Update Drivetrain') {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400649 if (upgradeSaltStack) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300650 updateSaltStack('I@salt:master', '["salt-master", "salt-common", "salt-api", "salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200651
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400652 salt.enforceState(venvPepper, 'I@linux:system', 'linux.system.repo', true, true, batchSize, false, 60, 2)
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300653 updateSaltStack('I@salt:minion and not I@salt:master', '["salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200654 }
655
Denis Egorenkod13ad132018-12-17 16:56:02 +0400656 if (updatePipelines) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300657 common.infoMsg('Perform: UPDATE git repos')
658 triggerMirrorJob('git-mirror-downstream-mk-pipelines', reclassSystemBranch)
659 triggerMirrorJob('git-mirror-downstream-pipeline-library', reclassSystemBranch)
Richard Felkl970e0082018-06-12 18:00:51 +0200660 }
661
Denis Egorenko7a4cf032019-04-25 20:48:26 +0400662 // update minions certs
Denis Egorenkoaf3a2202019-04-26 15:13:16 +0400663 // call for `salt.minion.ca` state on related nodes to make sure
664 // mine was updated with required data after salt-minion/salt-master restart salt:minion:ca
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400665 salt.enforceState(venvPepper, 'I@salt:minion:ca', 'salt.minion.ca', true, true, batchSize, false, 60, 2)
666 salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion.cert', true, true, batchSize, false, 60, 2)
Denis Egorenko7a4cf032019-04-25 20:48:26 +0400667
Ann Kamyshnikovae8910112019-05-06 12:56:38 +0400668 // run `salt.minion` to refresh all minion configs (for example _keystone.conf)
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400669 salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion', true, true, null, false, 60, 2)
azvyagintsevbc359d42019-04-10 19:53:22 +0300670 // Retry needed only for rare race-condition in user appearance
671 common.infoMsg('Perform: updating users and keys')
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400672 salt.enforceState(venvPepper, 'I@linux:system', 'linux.system.user', true, true, batchSize, false, 60, 2)
azvyagintsevbc359d42019-04-10 19:53:22 +0300673 common.infoMsg('Perform: updating openssh')
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400674 salt.enforceState(venvPepper, 'I@linux:system', 'openssh', true, true, batchSize, false, 60, 2)
Denis Egorenko65cf2a42019-01-15 11:58:12 +0400675
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300676 // apply salt API TLS if needed
677 def nginxAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0]
678 if (nginxAtMaster.toString().toLowerCase() == 'true') {
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400679 salt.enforceState(venvPepper, 'I@salt:master', 'nginx', true, true, null, false, 60, 2)
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300680 }
681
Denis Egorenko579f1842019-10-30 13:26:59 +0400682 // 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
683 def gerritGlusterPath = salt.getPillar(venvPepper, 'I@gerrit:client', 'glusterfs:client:volumes:gerrit:path').get('return')[0].values()[0]
684 def wrongPluginJarName = "${gerritGlusterPath}/plugins/project-download-commands.jar"
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400685 salt.cmdRun(venvPepper, 'I@gerrit:client', "test -f ${wrongPluginJarName} && rm ${wrongPluginJarName} || true")
Denis Egorenko579f1842019-10-30 13:26:59 +0400686
Denis Egorenko21c78be2019-07-10 19:47:39 +0400687 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 Berezovskiya766d432019-12-11 15:31:10 +0400688 }
689 }
690 catch (Throwable e) {
691 // If there was an error or exception thrown, the build failed
692 currentBuild.result = "FAILURE"
693 throw e
694 }
695 }
696 // docker.client state may trigger change of jenkins master or jenkins slave services,
697 // so we need wait for slave to reconnect and continue pipeline
698 sleep(180)
699 node('python') {
700 try {
701 stage('Update Drivetrain: Phase 2') {
702 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
azvyagintsevbc359d42019-04-10 19:53:22 +0300703 common.infoMsg('Perform: Checking if Docker containers are up')
azvyagintsev6dac3802018-11-09 15:11:30 +0200704 try {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300705 common.retry(20, 30) {
Richard Felkl970e0082018-06-12 18:00:51 +0200706 salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'")
707 }
708 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200709 catch (Exception ex) {
Richard Felkl970e0082018-06-12 18:00:51 +0200710 error("Docker containers for CI/CD services are having troubles with starting.")
711 }
Denis Egorenko21c78be2019-07-10 19:47:39 +0400712
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400713 // Apply changes for HaProxy on CI/CD nodes
714 salt.enforceState(venvPepper, 'I@keepalived:cluster:instance:cicd_control_vip and I@haproxy:proxy', 'haproxy.proxy', true)
715
Denis Egorenko21c78be2019-07-10 19:47:39 +0400716 salt.enforceState(venvPepper, 'I@jenkins:client and not I@salt:master', 'jenkins.client', true, true, null, false, 60, 2)
Denis Egorenko312bcd42019-07-23 17:59:13 +0400717
718 // update Nginx proxy settings for Jenkins/Gerrit if needed
719 if (salt.testTarget(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit')) {
720 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)
721 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100722 }
723 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100724 catch (Throwable e) {
725 // If there was an error or exception thrown, the build failed
726 currentBuild.result = "FAILURE"
727 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +0100728 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100729 }
Jakub Josef2c21c6c2018-02-08 18:51:42 +0100730}