blob: b8f48a99885b6f22f76a10e5dfbf83e3f0afb82c [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 = ''
Denis Egorenko96cc57d2020-01-24 19:47:05 +040027def packageUpgradeMode = ''
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010028
azvyagintsevbc359d42019-04-10 19:53:22 +030029def triggerMirrorJob(String jobName, String reclassSystemBranch) {
Richard Felkl970e0082018-06-12 18:00:51 +020030 params = jenkinsUtils.getJobParameters(jobName)
azvyagintsevbc359d42019-04-10 19:53:22 +030031 try {
32 build job: jobName, parameters: [
33 [$class: 'StringParameterValue', name: 'BRANCHES', value: params.get('BRANCHES')],
34 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')],
35 [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')],
36 [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')]
37 ]
38 } catch (Exception updateErr) {
39 common.warningMsg(updateErr)
40 common.warningMsg('Attempt to update git repo in failsafe manner')
41 build job: jobName, parameters: [
42 [$class: 'StringParameterValue', name: 'BRANCHES', value: reclassSystemBranch.replace('origin/', '')],
43 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')],
44 [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')],
45 [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')]
46 ]
47 }
Richard Felkl970e0082018-06-12 18:00:51 +020048}
49
azvyagintsev6dac3802018-11-09 15:11:30 +020050def updateSaltStack(target, pkgs) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +030051 salt.cmdRun(venvPepper, 'I@salt:master', "salt -C '${target}' --async pkg.install force_yes=True pkgs='$pkgs'")
Denis Egorenko4b54e7f2019-02-26 16:05:03 +040052 // can't use same function from pipeline lib, as at the moment of running upgrade pipeline Jenkins
53 // still using pipeline lib from current old mcp-version
azvyagintsev6dac3802018-11-09 15:11:30 +020054 common.retry(20, 60) {
Richard Felkl0e80d892018-06-20 13:44:54 +020055 salt.minionsReachable(venvPepper, 'I@salt:master', '*')
56 def running = salt.runSaltProcessStep(venvPepper, target, 'saltutil.running', [], null, true, 5)
azvyagintsev6dac3802018-11-09 15:11:30 +020057 for (value in running.get("return")[0].values()) {
58 if (value != []) {
Richard Felkl0e80d892018-06-20 13:44:54 +020059 throw new Exception("Not all salt-minions are ready for execution")
60 }
61 }
62 }
63
azvyagintsevf3bf77a2018-11-15 19:30:04 +020064 def saltVersion = salt.getPillar(venvPepper, 'I@salt:master', '_param:salt_version').get('return')[0].values()[0]
Richard Felklf23257e2018-08-06 09:24:23 +020065 def saltMinionVersions = salt.cmdRun(venvPepper, target, "apt-cache policy salt-common | awk '/Installed/ && /$saltVersion/'").get("return")
Richard Felkl0e80d892018-06-20 13:44:54 +020066 def saltMinionVersion = ""
67
azvyagintsev6dac3802018-11-09 15:11:30 +020068 for (minion in saltMinionVersions[0].keySet()) {
69 saltMinionVersion = saltMinionVersions[0].get(minion).replace("Salt command execution success", "").trim()
70 if (saltMinionVersion == "") {
Richard Felkl0e80d892018-06-20 13:44:54 +020071 error("Installed version of Salt on $minion doesn't match specified version in the model.")
72 }
73 }
74}
75
Denis Egorenko20a43462019-09-24 14:55:50 +040076def getWorkerThreads(saltId) {
77 if (env.getEnvironment().containsKey('SALT_MASTER_OPT_WORKER_THREADS')) {
78 return env['SALT_MASTER_OPT_WORKER_THREADS'].toString()
79 }
80 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)
81 return threads['return'][0].values()[0].replaceAll('Salt command execution success','').trim()
82}
83
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +040084def wa29352(String cname) {
azvyagintsev745a6e52019-04-18 13:19:39 +030085 // WA for PROD-29352. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/12/openssh/client/root.yml
86 // Default soft-param has been removed, what now makes not possible to render some old env's.
87 // Like fix, we found copy-paste already generated key from backups, to secrets.yml with correct key name
88 def wa29352ClassName = 'cluster.' + cname + '.infra.secrets_root_wa29352'
89 def wa29352File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_root_wa29352.yml"
90 def wa29352SecretsFile = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets.yml"
91 def _tempFile = '/tmp/wa29352_' + UUID.randomUUID().toString().take(8)
92 try {
93 salt.cmdRun(venvPepper, 'I@salt:master', "grep -qiv root_private_key ${wa29352SecretsFile}", true, null, false)
94 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29352File}", true, null, false)
95 }
96 catch (Exception ex) {
Denis Egorenkodfa35422019-10-07 12:46:14 +040097 common.infoMsg('Work-around for PROD-29352 already applied, nothing todo')
azvyagintsev745a6e52019-04-18 13:19:39 +030098 return
99 }
100 def rKeysDict = [
101 'parameters': [
102 '_param': [
103 'root_private_key': salt.getPillar(venvPepper, 'I@salt:master', '_param:root_private_key').get('return')[0].values()[0].trim(),
104 'root_public_key' : '',
105 ]
106 ]
107 ]
108 // save root key,and generate public one from it
109 writeFile file: _tempFile, text: rKeysDict['parameters']['_param']['root_private_key'].toString().trim()
110 sh('chmod 0600 ' + _tempFile)
111 rKeysDict['parameters']['_param']['root_public_key'] = sh(script: "ssh-keygen -q -y -f ${_tempFile}", returnStdout: true).trim()
112 sh('rm -fv ' + _tempFile)
113 writeYaml file: _tempFile, data: rKeysDict
114 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
115 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29352File}", false, null, false)
116 common.infoMsg("Add $wa29352ClassName class into secrets.yml")
117
118 // Add 'classes:' directive
119 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
120 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
121
122 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
123 "grep -q '${wa29352ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29352ClassName' infra/secrets.yml")
124 salt.fullRefresh(venvPepper, '*')
125 sh('rm -fv ' + _tempFile)
Denis Egorenkodfa35422019-10-07 12:46:14 +0400126 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " +
127 "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()}' ")
128 common.infoMsg('Work-around for PROD-29352 successfully applied')
azvyagintsev745a6e52019-04-18 13:19:39 +0300129}
130
azvyagintsevbc359d42019-04-10 19:53:22 +0300131def wa29155(ArrayList saltMinions, String cname) {
132 // WA for PROD-29155. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/
133 // CHeck for existence cmp nodes, and try to render it. Is failed, apply ssh-key wa
134 def ret = ''
135 def patched = false
136 def wa29155ClassName = 'cluster.' + cname + '.infra.secrets_nova_wa29155'
137 def wa29155File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_nova_wa29155.yml"
138
139 try {
140 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29155File}", true, null, false)
141 }
142 catch (Exception ex) {
143 common.infoMsg('Work-around for PROD-29155 already apply, nothing todo')
144 return
145 }
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400146 salt.fullRefresh(venvPepper, 'I@salt:master')
azvyagintsevbc359d42019-04-10 19:53:22 +0300147 for (String minion in saltMinions) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300148 // First attempt, second will be performed in next validateReclassModel() stages
149 try {
azvyagintsev745a6e52019-04-18 13:19:39 +0300150 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 +0300151 } catch (Exception e) {
152 common.errorMsg(e.toString())
153 if (patched) {
154 error("Node: ${minion} failed to render after reclass-system upgrade!WA29155 probably didn't help.")
155 }
156 // check, that failed exactly by our case, by key-length check.
157 def missed_key = salt.getPillar(venvPepper, minion, '_param:nova_compute_ssh_private').get("return")[0].values()[0]
158 if (missed_key != '') {
159 error("Node: ${minion} failed to render after reclass-system upgrade!")
160 }
azvyagintsev745a6e52019-04-18 13:19:39 +0300161 common.warningMsg('Perform: Attempt to apply WA for PROD-29155\n' +
162 'See https://gerrit.mcp.mirantis.com/#/c/37932/ for more info')
azvyagintsevbc359d42019-04-10 19:53:22 +0300163 common.warningMsg('WA-PROD-29155 Generating new ssh key at master node')
164 def _tempFile = "/tmp/nova_wa29155_" + UUID.randomUUID().toString().take(8)
165 common.infoMsg('Perform: generation NEW ssh-private key for nova-compute')
166 salt.cmdRun(venvPepper, 'I@salt:master', "ssh-keygen -f ${_tempFile} -N '' -q")
167 def _pub_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}.pub").get('return')[0].values()[0].trim()
168 def _priv_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}").get('return')[0].values()[0].trim()
169 salt.cmdRun(venvPepper, 'I@salt:master', "rm -fv ${_tempFile}", false, null, false)
170 def novaKeysDict = [
171 "parameters": [
172 "_param": [
173 "nova_compute_ssh_private": _priv_k,
174 "nova_compute_ssh_public" : _pub_k
175 ]
176 ]
177 ]
azvyagintsev745a6e52019-04-18 13:19:39 +0300178 writeYaml file: _tempFile, data: novaKeysDict
azvyagintsevbc359d42019-04-10 19:53:22 +0300179 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
180 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29155File}", false, null, false)
181 common.infoMsg("Add $wa29155ClassName class into secrets.yml")
182
183 // Add 'classes:' directive
184 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
185 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
186
187 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
188 "grep -q '${wa29155ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29155ClassName' infra/secrets.yml")
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400189 salt.fullRefresh(venvPepper, 'I@salt:master')
190 salt.fullRefresh(venvPepper, saltMinions)
azvyagintsevbc359d42019-04-10 19:53:22 +0300191 patched = true
192 }
193 }
194 if (patched) {
195 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " +
196 "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()}' ")
197 common.infoMsg('Work-around for PROD-29155 successfully applied')
198 }
199
200}
201
Denis Egorenko1b11d232019-07-29 17:44:46 +0400202def wa32284(String clusterName) {
203 def clientGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:enabled").get("return")[0].values()[0]
204 def pkiGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:volumes:salt_pki").get("return")[0].values()[0]
205 def nginxEnabledAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0]
206 if (nginxEnabledAtMaster.toString().toLowerCase() == 'true' && clientGluster.toString().toLowerCase() == 'true' && pkiGluster) {
207 def nginxRequires = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:wait_for_service').get('return')[0].values()[0]
208 if (nginxRequires.isEmpty()) {
209 def nginxRequiresClassName = "cluster.${clusterName}.infra.config.nginx_requires_wa32284"
210 def nginxRequiresClassFile = "/srv/salt/reclass/classes/cluster/${clusterName}/infra/config/nginx_requires_wa32284.yml"
211 def nginxRequiresBlock = ['parameters': ['nginx': ['server': ['wait_for_service': ['srv-salt-pki.mount'] ] ] ] ]
212 def _tempFile = '/tmp/wa32284_' + UUID.randomUUID().toString().take(8)
213 writeYaml file: _tempFile , data: nginxRequiresBlock
214 def nginxRequiresBlockString = sh(script: "cat ${_tempFile}", returnStdout: true).trim()
215 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${clusterName} && " +
216 "sed -i '/^parameters:/i - ${nginxRequiresClassName}' infra/config/init.yml")
217 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${nginxRequiresBlockString}' > ${nginxRequiresClassFile}", false, null, false)
218 }
219 }
220}
221
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400222def wa32182(String cluster_name) {
Hanna Arhipovad5eec4c2019-09-06 17:55:40 +0300223 if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) {
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400224 def clusterModelPath = "/srv/salt/reclass/classes/cluster/${cluster_name}"
225 def fixFile = "${clusterModelPath}/opencontrail/common_wa32182.yml"
226 def usualFile = "${clusterModelPath}/opencontrail/common.yml"
227 def fixFileContent = "classes:\n- system.opencontrail.common\n"
228 salt.cmdRun(venvPepper, 'I@salt:master', "test -f ${fixFile} -o -f ${usualFile} || echo '${fixFileContent}' > ${fixFile}")
229 def contrailFiles = ['opencontrail/analytics.yml', 'opencontrail/control.yml', 'openstack/compute/init.yml']
230 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
231 contrailFiles.add('kubernetes/compute.yml')
232 }
233 for(String contrailFile in contrailFiles) {
234 contrailFile = "${clusterModelPath}/${contrailFile}"
235 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()
236 if (containsFix) {
237 continue
238 } else {
239 salt.cmdRun(venvPepper, 'I@salt:master', "grep -q -E '^parameters:' ${contrailFile} && sed -i '/^parameters:/i - cluster.${cluster_name}.opencontrail.common_wa32182' ${contrailFile} || " +
240 "echo '- cluster.${cluster_name}.opencontrail.common_wa32182' >> ${contrailFile}")
241 }
242 }
243 }
244}
245
Denis Egorenkoba631332019-10-25 13:13:39 +0400246def wa33867(String cluster_name) {
247 if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) {
248 def contrailControlFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/opencontrail/control.yml"
249 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()
250 if (line == "- cluster.${cluster_name}.infra") {
251 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra\$/d' ${contrailControlFile}")
252 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra.backup.client_zookeeper\$/i - cluster.${cluster_name}.infra' ${contrailControlFile}")
253 }
254 }
255}
256
Denis Egorenkoe312cc92019-10-18 17:06:11 +0400257def wa33771(String cluster_name) {
258 def octaviaEnabled = salt.getMinions(venvPepper, 'I@octavia:api:enabled')
259 def octaviaWSGI = salt.getMinions(venvPepper, 'I@apache:server:site:octavia_api')
260 if (octaviaEnabled && ! octaviaWSGI) {
261 def openstackControl = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/control.yml"
262 def octaviaFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/octavia_wa33771.yml"
263 def octaviaContext = [
264 'classes': [ 'system.apache.server.site.octavia' ],
265 'parameters': [
266 '_param': [ 'apache_octavia_api_address' : '${_param:cluster_local_address}' ],
267 'apache': [ 'server': [ 'site': [ 'apache_proxy_openstack_api_octavia': [ 'enabled': false ] ] ] ]
268 ]
269 ]
270 def _tempFile = '/tmp/wa33771' + UUID.randomUUID().toString().take(8)
271 writeYaml file: _tempFile , data: octaviaContext
272 def octaviaFileContent = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
273 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.octavia_wa33771' ${openstackControl}")
274 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${octaviaFileContent}' | base64 -d > ${octaviaFile}", false, null, false)
275 }
276}
277
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400278def wa33930_33931(String cluster_name) {
279 def openstackControlFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/control.yml"
280 def fixName = 'clients_common_wa33930_33931'
281 def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/${fixName}.yml"
282 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()
283 if (! containsFix) {
284 def fixContext = [
285 'classes': [ 'service.nova.client', 'service.glance.client', 'service.neutron.client' ]
286 ]
287 if (salt.getMinions(venvPepper, 'I@manila:api:enabled')) {
288 fixContext['classes'] << 'service.manila.client'
289 }
290 if (salt.getMinions(venvPepper, 'I@ironic:api:enabled')) {
291 fixContext['classes'] << 'service.ironic.client'
292 }
293 if (salt.getMinions(venvPepper, 'I@gnocchi:server:enabled')) {
294 fixContext['classes'] << 'service.gnocchi.client'
295 }
296 if (salt.getMinions(venvPepper, 'I@barbican:server:enabled')) {
297 fixContext['classes'] << 'service.barbican.client.single'
298 }
299 def _tempFile = '/tmp/wa33930_33931' + UUID.randomUUID().toString().take(8)
300 writeYaml file: _tempFile , data: fixContext
301 def fixFileContent = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
302 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${fixFileContent}' | base64 -d > ${fixFile}", false, null, false)
303 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.${fixName}' ${openstackControlFile}")
304 }
305}
306
azvyagintsev6dac3802018-11-09 15:11:30 +0200307def archiveReclassInventory(filename) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300308 def _tmp_file = '/tmp/' + filename + UUID.randomUUID().toString().take(8)
309 // jenkins may fail at overheap. Compress data with gzip like WA
azvyagintsev745a6e52019-04-18 13:19:39 +0300310 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 +0300311 def _tmp = sh(script: "echo '$ret' > ${_tmp_file}", returnStdout: false)
312 sh(script: "cat ${_tmp_file} | base64 -d | gzip -d > $filename", returnStdout: false)
313 archiveArtifacts artifacts: filename
314 sh(script: "rm -v ${_tmp_file}|| true")
Richard Felkl0e80d892018-06-20 13:44:54 +0200315}
316
Denis Egorenkod13ad132018-12-17 16:56:02 +0400317def validateReclassModel(ArrayList saltMinions, String suffix) {
318 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300319 for (String minion in saltMinions) {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400320 common.infoMsg("Reclass model validation for minion ${minion}...")
azvyagintsev745a6e52019-04-18 13:19:39 +0300321 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 +0400322 writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString()
323 }
324 } catch (Exception e) {
325 common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.')
azvyagintsevbc359d42019-04-10 19:53:22 +0300326 error(e.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400327 }
328}
329
azvyagintsevbc359d42019-04-10 19:53:22 +0300330def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix = 'before', String newSuffix = 'after') {
331 for (String minion in saltMinions) {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400332 def fileName = "reclass-model-${minion}-diff.out"
333 sh "diff -u inventory-${minion}-${oldSuffix}.out inventory-${minion}-${newSuffix}.out > ${fileName} || true"
334 archiveArtifacts artifacts: "${fileName}"
335 }
336}
337
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300338def checkDebsums() {
339 // check for salt-formulas consistency
340 try {
341 try {
342 salt.cmdRun(venvPepper, 'I@salt:master', "salt -C 'I@salt:master' pkg.install force_yes=True pkgs=[debsums]")
343 }
344 catch (Exception ex) {
345 common.warningMsg('Unable to install package "debsums" at cfg01. Salt-formulas integrity check skipped')
346 }
347 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')
348 salt.cmdRun(venvPepper, 'I@salt:master', 'if [ -s "/root/debdsums_report" ]; then exit 1 ; fi')
349 }
350 catch (Exception ex) {
351 common.errorMsg(salt.cmdRun(venvPepper, 'I@salt:master', 'cat /root/debdsums_report ', true, null, false).get('return')[0].values()[0].trim())
352 common.errorMsg(ex.toString())
353 error('You have unexpected changes in formulas. All of them will be overwrited by update. Unable to continue in automatic way')
354 }
355}
356
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400357def checkCICDDocker() {
358 common.infoMsg('Perform: Checking if Docker containers are up')
359 try {
360 common.retry(10, 30) {
361 salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'")
362 }
363 }
364 catch (Exception ex) {
365 error("Docker containers for CI/CD services are having troubles with starting.")
366 }
367}
368
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400369if (common.validInputParam('PIPELINE_TIMEOUT')) {
370 try {
371 pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger()
azvyagintsevbc359d42019-04-10 19:53:22 +0300372 } catch (Exception e) {
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400373 common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger")
374 }
Martin Polreich965c9032018-08-09 16:33:57 +0200375}
376
377timeout(time: pipelineTimeout, unit: 'HOURS') {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300378 node('python') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100379 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300380 def inventoryBeforeFilename = "reclass-inventory-before.out"
381 def inventoryAfterFilename = "reclass-inventory-after.out"
Richard Felkl0e80d892018-06-20 13:44:54 +0200382 workspace = common.getWorkspace()
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200383 targetMcpVersion = null
384 if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) {
385 error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable')
azvyagintsev6dac3802018-11-09 15:11:30 +0200386 }
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200387 // bw comp. for 2018.X => 2018.11 release
azvyagintsevbc359d42019-04-10 19:53:22 +0300388 if (common.validInputParam('MCP_VERSION')) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200389 targetMcpVersion = env.MCP_VERSION
390 common.warningMsg("targetMcpVersion has been changed to:${targetMcpVersion}, which was taken from deprecated pipeline viriable:MCP_VERSION")
azvyagintsevbc359d42019-04-10 19:53:22 +0300391 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200392 targetMcpVersion = env.TARGET_MCP_VERSION
393 }
394 // end bw comp. for 2018.X => 2018.11 release
Denis Egorenkod13ad132018-12-17 16:56:02 +0400395 def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC')
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400396 if (targetMcpVersion in ['nightly', 'testing']) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200397 gitTargetMcpVersion = 'master'
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400398 } else if (targetMcpVersion == 'proposed') {
399 gitTargetMcpVersion = 'proposed'
Denis Egorenko284690e2018-12-25 15:55:12 +0400400 } else if (!gitTargetMcpVersion) {
401 // backward compatibility for 2018.11.0
402 gitTargetMcpVersion = "release/${targetMcpVersion}"
azvyagintsev6dac3802018-11-09 15:11:30 +0200403 }
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400404 common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}")
Denis Egorenko284690e2018-12-25 15:55:12 +0400405 def upgradeSaltStack = ''
406 def updateClusterModel = ''
407 def updatePipelines = ''
408 def updateLocalRepos = ''
409 def reclassSystemBranch = ''
Denis Egorenko517e06c2019-03-29 13:24:15 +0400410 def reclassSystemBranchDefault = gitTargetMcpVersion
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400411 def batchSize = ''
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400412 if (gitTargetMcpVersion ==~ /^\d\d\d\d\.\d\d?\.\d+$/) {
413 reclassSystemBranchDefault = "tags/${gitTargetMcpVersion}"
414 } else if (gitTargetMcpVersion != 'proposed') {
Denis Egorenko517e06c2019-03-29 13:24:15 +0400415 reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}"
416 }
Hanna Arhipovad5eec4c2019-09-06 17:55:40 +0300417 def driveTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS')
418 if (driveTrainParamsYaml) {
419 def driveTrainParams = readYaml text: driveTrainParamsYaml
420 saltMastURL = driveTrainParams.get('SALT_MASTER_URL')
421 saltMastCreds = driveTrainParams.get('SALT_MASTER_CREDENTIALS')
422 upgradeSaltStack = driveTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean()
423 updateClusterModel = driveTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean()
424 updatePipelines = driveTrainParams.get('UPDATE_PIPELINES', false).toBoolean()
425 updateLocalRepos = driveTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean()
426 reclassSystemBranch = driveTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault)
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400427 batchSize = driveTrainParams.get('BATCH_SIZE', '')
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400428 if (driveTrainParams.get('OS_DIST_UPGRADE', false).toBoolean() == true) {
429 packageUpgradeMode = 'dist-upgrade'
430 } else if (driveTrainParams.get('OS_UPGRADE', false).toBoolean() == true) {
431 packageUpgradeMode = 'upgrade'
432 }
Denis Egorenko284690e2018-12-25 15:55:12 +0400433 } else {
434 // backward compatibility for 2018.11.0
435 saltMastURL = env.getProperty('SALT_MASTER_URL')
436 saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS')
Denis Egorenkoe5f39142018-12-28 12:30:48 +0400437 upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean()
438 updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean()
439 updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean()
440 updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean()
Denis Egorenko517e06c2019-03-29 13:24:15 +0400441 reclassSystemBranch = reclassSystemBranchDefault
Denis Egorenko284690e2018-12-25 15:55:12 +0400442 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400443 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400444 def minions = salt.getMinions(venvPepper, '*')
Denis Egorenkofbcee412019-04-19 15:05:18 +0400445 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
446 if (cluster_name == '' || cluster_name == 'null' || cluster_name == null) {
447 error('Pillar data is broken for Salt master node! Please check it manually and re-run pipeline.')
448 }
Hanna Arhipovad5eec4c2019-09-06 17:55:40 +0300449 if (!batchSize) {
Denis Egorenko7b098c32019-12-19 16:45:25 +0400450 // if no batch size provided get current worker threads and set batch size to 2/3 of it to avoid
451 // 'SaltReqTimeoutError: Message timed out' issue on Salt targets for large amount of nodes
452 // do not use toDouble/Double as it requires additional approved method
453 def workerThreads = getWorkerThreads(venvPepper).toInteger()
454 batch_size = (workerThreads * 2 / 3).toString().tokenize('.')[0]
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400455 }
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400456 def computeMinions = salt.getMinions(venvPepper, 'I@nova:compute')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400457
azvyagintsevbc359d42019-04-10 19:53:22 +0300458 stage('Update Reclass and Salt-Formulas') {
459 common.infoMsg('Perform: Full salt sync')
460 salt.fullRefresh(venvPepper, '*')
461 common.infoMsg('Perform: Validate reclass medata before processing')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400462 validateReclassModel(minions, 'before')
463
azvyagintsev745a6e52019-04-18 13:19:39 +0300464 common.infoMsg('Perform: archiveReclassInventory before upgrade')
465 archiveReclassInventory(inventoryBeforeFilename)
466
azvyagintsev6dac3802018-11-09 15:11:30 +0200467 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300468 salt.cmdRun(venvPepper, 'I@salt:master', 'cd /srv/salt/reclass/ && git status && git diff-index --quiet HEAD --')
Richard Felkl970e0082018-06-12 18:00:51 +0200469 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200470 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300471 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 +0200472 }
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300473 checkDebsums()
Denis Egorenkod13ad132018-12-17 16:56:02 +0400474 if (updateClusterModel) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200475 common.infoMsg('Perform: UPDATE_CLUSTER_MODEL')
Sergey382581a2018-10-25 12:22:26 +0400476 def dateTime = common.getDatetime()
Ivan Berezovskiycfa1b2f2020-01-17 13:55:18 +0400477 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git fetch")
Sergey382581a2018-10-25 12:22:26 +0400478 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400479 "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 +0200480 // Do the same, for deprecated variable-duplicate
481 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400482 "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 +0400483 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400484 "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 +0400485 // Set new k8s param
486 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
487 "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 +0400488 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
489 "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'")
490 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko301cc8a2019-02-13 13:49:13 +0400491 "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 +0400492 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko301cc8a2019-02-13 13:49:13 +0400493 "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 +0400494 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsevbc359d42019-04-10 19:53:22 +0300495 "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 +0400496
Denis Egorenko6f07b592019-09-16 16:41:26 +0400497 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")
498 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name/infra && sed -i '/maas_region_main_archive/d' maas.yml")
499
Denis Egorenko21c78be2019-07-10 19:47:39 +0400500 // Switch Jenkins/Gerrit to use LDAP SSL/TLS
501 def gerritldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
502 "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()
503 if (gerritldapURI.startsWith('ldap://')) {
504 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
505 "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
506 } else if (! gerritldapURI.startsWith('ldaps://')) {
507 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
508 "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'")
509 }
510 def jenkinsldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
511 "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()
512 if (jenkinsldapURI.startsWith('ldap://')) {
513 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
514 "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
515 } else if (! jenkinsldapURI.startsWith('ldaps://')) {
516 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
517 "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'")
518 }
519
Denis Egorenko1b11d232019-07-29 17:44:46 +0400520 wa32284(cluster_name)
521
Denis Egorenkod13ad132018-12-17 16:56:02 +0400522 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}")
Sergey Kolekonov5dfbf7a2019-01-23 16:47:43 +0400523 // Add kubernetes-extra repo
524 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
Sergey Kolekonov3fde8b12019-04-11 16:33:54 +0400525 // docker-engine conflicts with the recent containerd versions, so it's removed during upgrade. Thus update source engine
526 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
527 "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 +0400528 common.infoMsg("Add kubernetes-extra repo")
529 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
530 "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")
531 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
532 "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")
533 }
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400534 // Add all update repositories
535 def repoIncludeBase = '- system.linux.system.repo.mcp.apt_mirantis.'
Denis Egorenko6f07b592019-09-16 16:41:26 +0400536 def updateRepoList = ['cassandra', 'ceph', 'contrail', 'docker', 'elastic', 'extra', 'openstack', 'maas', 'percona', 'salt-formulas', 'saltstack', 'ubuntu']
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400537 updateRepoList.each { repo ->
538 def repoNameUpdateInclude = "${repoIncludeBase}update.${repo}"
539 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')
540 filesWithInclude.each { file ->
541 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()
542 if (updateRepoIncludeExist == 'not_found') {
543 // Include needs to be added
544 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsevbc359d42019-04-10 19:53:22 +0300545 "sed -i 's/\\( *\\)${repoIncludeBase}${repo}\$/&\\n\\1${repoNameUpdateInclude}/g' ${file}")
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400546 common.infoMsg("Update repo for ${repo} is added to ${file}")
547 }
548 }
549 }
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400550 wa32182(cluster_name)
Denis Egorenkoe312cc92019-10-18 17:06:11 +0400551 wa33771(cluster_name)
Denis Egorenkoba631332019-10-25 13:13:39 +0400552 wa33867(cluster_name)
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400553 wa33930_33931(cluster_name)
Sergey382581a2018-10-25 12:22:26 +0400554 // Add new defaults
555 common.infoMsg("Add new defaults")
Denis Egorenkod13ad132018-12-17 16:56:02 +0400556 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 +0400557 "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 +0400558 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 +0400559 "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 +0400560 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300561 "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 +0400562 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300563 "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 +0400564 common.infoMsg("The following changes were made to the cluster model and will be commited. " +
azvyagintsev6dac3802018-11-09 15:11:30 +0200565 "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 +0400566 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff")
567 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " +
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200568 "git add -u && git commit --allow-empty -m 'Cluster model update to the release $targetMcpVersion on $dateTime'")
Sergey382581a2018-10-25 12:22:26 +0400569 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400570 try {
571 common.infoMsg('Perform: UPDATE Salt Formulas')
azvyagintsevca97a112019-04-22 17:53:40 +0300572 salt.fullRefresh(venvPepper, '*')
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400573 salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400574 def saltEnv = salt.getPillar(venvPepper, 'I@salt:master', "_param:salt_master_base_environment").get("return")[0].values()[0]
azvyagintsevbc359d42019-04-10 19:53:22 +0300575 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas", 'salt.master.env'])
azvyagintsevca97a112019-04-22 17:53:40 +0300576 salt.fullRefresh(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400577 } catch (Exception updateErr) {
578 common.warningMsg(updateErr)
579 common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
580 input message: 'Continue anyway?'
581 }
582
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400583 wa29352(cluster_name)
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400584 wa29155(computeMinions, cluster_name)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400585
586 try {
587 common.infoMsg('Perform: UPDATE Reclass package')
588 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"])
589 } catch (Exception updateErr) {
590 common.warningMsg(updateErr)
591 common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
592 input message: 'Continue anyway?'
593 }
594
595 salt.fullRefresh(venvPepper, 'I@salt:master')
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400596 salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true, true, null, false, 60, 2)
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400597 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && " +
598 "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 +0400599 try {
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400600 salt.enforceState(venvPepper, 'I@salt:master', 'reclass', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400601 }
602 catch (Exception ex) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300603 common.errorMsg(ex.toString())
604 error('Reclass fails rendering. Pay attention to your cluster model.')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400605 }
606
607 salt.fullRefresh(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400608 try {
609 salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top")
610 }
611 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300612
613 error('Reclass fails rendering. Pay attention to your cluster model.' +
614 'ErrorMessage:' + ex.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400615 }
616
azvyagintsevbc359d42019-04-10 19:53:22 +0300617 common.infoMsg('Perform: archiveReclassInventory AFTER upgrade')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400618 archiveReclassInventory(inventoryAfterFilename)
619
620 sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true"
621 archiveArtifacts artifacts: "reclass-inventory-diff.out"
622
623 validateReclassModel(minions, 'after')
624 archiveReclassModelChanges(minions)
Jakub Josefa63f9862018-01-11 17:58:38 +0100625 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100626
Denis Egorenkod13ad132018-12-17 16:56:02 +0400627 if (updateLocalRepos) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200628 stage("Update local repos") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100629 common.infoMsg("Updating local repositories")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700630
Sergey1b81c062018-10-16 17:10:21 +0400631 def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700632 runningOnDocker = engine.get("return")[0].containsValue("docker")
633
634 if (runningOnDocker) {
635 common.infoMsg("Aptly is running as Docker container")
azvyagintsev6dac3802018-11-09 15:11:30 +0200636 } else {
Sam Stoelingaaab79702018-04-09 18:49:39 -0700637 common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands")
638 }
639
azvyagintsev6dac3802018-11-09 15:11:30 +0200640 if (runningOnDocker) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200641 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 +0200642 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200643 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 +0100644 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100645
Sergey1b81c062018-10-16 17:10:21 +0400646 salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100647
azvyagintsev6dac3802018-11-09 15:11:30 +0200648 if (runningOnDocker) {
Sergey1b81c062018-10-16 17:10:21 +0400649 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true)
650 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 +0200651 } else {
Sergey1b81c062018-10-16 17:10:21 +0400652 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true)
653 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 +0100654 }
Richard Felkl79d7df12018-01-05 16:40:11 +0100655
Sergey1b81c062018-10-16 17:10:21 +0400656 salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100657
Sergey1b81c062018-10-16 17:10:21 +0400658 salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100659
Sergey1b81c062018-10-16 17:10:21 +0400660 salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100661
Sergey1b81c062018-10-16 17:10:21 +0400662 salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100663 }
664 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100665
azvyagintsevbc359d42019-04-10 19:53:22 +0300666 stage('Update Drivetrain') {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400667 if (upgradeSaltStack) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300668 updateSaltStack('I@salt:master', '["salt-master", "salt-common", "salt-api", "salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200669
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400670 salt.enforceState(venvPepper, 'I@linux:system', 'linux.system.repo', true, true, batchSize, false, 60, 2)
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300671 updateSaltStack('I@salt:minion and not I@salt:master', '["salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200672 }
673
Denis Egorenkod13ad132018-12-17 16:56:02 +0400674 if (updatePipelines) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300675 common.infoMsg('Perform: UPDATE git repos')
676 triggerMirrorJob('git-mirror-downstream-mk-pipelines', reclassSystemBranch)
677 triggerMirrorJob('git-mirror-downstream-pipeline-library', reclassSystemBranch)
Richard Felkl970e0082018-06-12 18:00:51 +0200678 }
679
Denis Egorenko7a4cf032019-04-25 20:48:26 +0400680 // update minions certs
Denis Egorenkoaf3a2202019-04-26 15:13:16 +0400681 // call for `salt.minion.ca` state on related nodes to make sure
682 // mine was updated with required data after salt-minion/salt-master restart salt:minion:ca
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400683 salt.enforceState(venvPepper, 'I@salt:minion:ca', 'salt.minion.ca', true, true, batchSize, false, 60, 2)
684 salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion.cert', true, true, batchSize, false, 60, 2)
Denis Egorenko7a4cf032019-04-25 20:48:26 +0400685
Ann Kamyshnikovae8910112019-05-06 12:56:38 +0400686 // run `salt.minion` to refresh all minion configs (for example _keystone.conf)
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400687 salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion', true, true, null, false, 60, 2)
azvyagintsevbc359d42019-04-10 19:53:22 +0300688 // Retry needed only for rare race-condition in user appearance
689 common.infoMsg('Perform: updating users and keys')
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400690 salt.enforceState(venvPepper, 'I@linux:system', 'linux.system.user', true, true, batchSize, false, 60, 2)
azvyagintsevbc359d42019-04-10 19:53:22 +0300691 common.infoMsg('Perform: updating openssh')
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400692 salt.enforceState(venvPepper, 'I@linux:system', 'openssh', true, true, batchSize, false, 60, 2)
Denis Egorenko65cf2a42019-01-15 11:58:12 +0400693
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300694 // apply salt API TLS if needed
695 def nginxAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0]
696 if (nginxAtMaster.toString().toLowerCase() == 'true') {
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400697 salt.enforceState(venvPepper, 'I@salt:master', 'nginx', true, true, null, false, 60, 2)
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300698 }
699
Denis Egorenko579f1842019-10-30 13:26:59 +0400700 // 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
701 def gerritGlusterPath = salt.getPillar(venvPepper, 'I@gerrit:client', 'glusterfs:client:volumes:gerrit:path').get('return')[0].values()[0]
702 def wrongPluginJarName = "${gerritGlusterPath}/plugins/project-download-commands.jar"
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400703 salt.cmdRun(venvPepper, 'I@gerrit:client', "test -f ${wrongPluginJarName} && rm ${wrongPluginJarName} || true")
Denis Egorenko579f1842019-10-30 13:26:59 +0400704
Denis Egorenko21c78be2019-07-10 19:47:39 +0400705 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 +0400706 }
707 }
708 catch (Throwable e) {
709 // If there was an error or exception thrown, the build failed
710 currentBuild.result = "FAILURE"
711 throw e
712 }
713 }
714 // docker.client state may trigger change of jenkins master or jenkins slave services,
715 // so we need wait for slave to reconnect and continue pipeline
716 sleep(180)
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400717 def cidNodes = []
Ivan Berezovskiya766d432019-12-11 15:31:10 +0400718 node('python') {
719 try {
720 stage('Update Drivetrain: Phase 2') {
721 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400722 checkCICDDocker()
Denis Egorenko21c78be2019-07-10 19:47:39 +0400723
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400724 // Apply changes for HaProxy on CI/CD nodes
725 salt.enforceState(venvPepper, 'I@keepalived:cluster:instance:cicd_control_vip and I@haproxy:proxy', 'haproxy.proxy', true)
726
Denis Egorenko21c78be2019-07-10 19:47:39 +0400727 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 +0400728
729 // update Nginx proxy settings for Jenkins/Gerrit if needed
730 if (salt.testTarget(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit')) {
731 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)
732 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100733 }
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400734 if (packageUpgradeMode) {
735 cidNodes = salt.getMinions(venvPepper, 'I@_param:drivetrain_role:cicd')
736 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100737 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100738 catch (Throwable e) {
739 // If there was an error or exception thrown, the build failed
740 currentBuild.result = "FAILURE"
741 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +0100742 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100743 }
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400744
745 stage('Upgrade OS') {
746 if (packageUpgradeMode) {
747 def debian = new com.mirantis.mk.Debian()
748 def statusFile = '/tmp/rebooted_during_upgrade'
749 for(cidNode in cidNodes) {
750 node('python') {
751 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
752 // cmd.run async to prevent connection close in case of slave shutdown, give 5 seconds to handle request response
753 salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${cidNode}' cmd.run 'sleep 5; touch ${statusFile}; salt-call service.stop docker' --async")
754 }
755 sleep(30)
756 node('python') {
757 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
758 debian.osUpgradeNode(venvPepper, cidNode, packageUpgradeMode, false, 60)
759 salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': cidNode, wait: 60, timeout: 10])
760 if (salt.runSaltProcessStep(venvPepper, cidNode, 'file.file_exists', [statusFile], null, true, 5)['return'][0].values()[0].toBoolean()) {
761 salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${cidNode}' cmd.run 'rm ${statusFile} && salt-call service.start docker'") // in case if node was not rebooted
762 sleep(10)
763 }
764 checkCICDDocker()
765 }
766 }
767 } else {
768 common.infoMsg('Upgrade OS skipped...')
769 }
770 }
Jakub Josef2c21c6c2018-02-08 18:51:42 +0100771}