blob: eb53100b521b324e76b26a990df242bc2581f199 [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
Ivan Berezovskiy22390f62020-02-17 17:08:47 +040016 * OS_UPGRADE Run apt-get upgrade on Drivetrain nodes
17 * OS_DIST_UPGRADE Run apt-get dist-upgrade on Drivetrain nodes and reboot to apply changes
18 * APPLY_MODEL_WORKAROUNDS Whether to apply cluster model workarounds from the pipeline
Richard Felkl26cae4d2017-12-19 00:19:16 +010019 */
20
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010021salt = new com.mirantis.mk.Salt()
22common = new com.mirantis.mk.Common()
23python = new com.mirantis.mk.Python()
Richard Felkl970e0082018-06-12 18:00:51 +020024jenkinsUtils = new com.mirantis.mk.JenkinsUtils()
azvyagintsevf3bf77a2018-11-15 19:30:04 +020025def pipelineTimeout = 12
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010026venvPepper = "venvPepper"
Richard Felkl0e80d892018-06-20 13:44:54 +020027workspace = ""
Ivan Berezovskiya766d432019-12-11 15:31:10 +040028def saltMastURL = ''
29def saltMastCreds = ''
Denis Egorenko96cc57d2020-01-24 19:47:05 +040030def packageUpgradeMode = ''
Ivan Berezovskiy22390f62020-02-17 17:08:47 +040031batchSize = ''
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010032
Ivan Berezovskiyc4dc5012020-03-19 14:03:43 +040033def fullRefreshOneByOne(venvPepper, minions) {
34 for (minion in minions) {
35 salt.runSaltProcessStep(venvPepper, minion, 'saltutil.refresh_pillar', [], null, true, 60)
36 salt.runSaltProcessStep(venvPepper, minion, 'saltutil.refresh_grains', [], null, true, 60)
37 salt.runSaltProcessStep(venvPepper, minion, 'saltutil.sync_all', [], null, true, 180)
38 }
39}
40
azvyagintsevbc359d42019-04-10 19:53:22 +030041def triggerMirrorJob(String jobName, String reclassSystemBranch) {
Richard Felkl970e0082018-06-12 18:00:51 +020042 params = jenkinsUtils.getJobParameters(jobName)
azvyagintsevbc359d42019-04-10 19:53:22 +030043 try {
44 build job: jobName, parameters: [
45 [$class: 'StringParameterValue', name: 'BRANCHES', value: params.get('BRANCHES')],
46 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')],
47 [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')],
48 [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')]
49 ]
50 } catch (Exception updateErr) {
51 common.warningMsg(updateErr)
52 common.warningMsg('Attempt to update git repo in failsafe manner')
53 build job: jobName, parameters: [
54 [$class: 'StringParameterValue', name: 'BRANCHES', value: reclassSystemBranch.replace('origin/', '')],
55 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')],
56 [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')],
57 [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')]
58 ]
59 }
Richard Felkl970e0082018-06-12 18:00:51 +020060}
61
azvyagintsev6dac3802018-11-09 15:11:30 +020062def updateSaltStack(target, pkgs) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +030063 salt.cmdRun(venvPepper, 'I@salt:master', "salt -C '${target}' --async pkg.install force_yes=True pkgs='$pkgs'")
Denis Egorenko4b54e7f2019-02-26 16:05:03 +040064 // can't use same function from pipeline lib, as at the moment of running upgrade pipeline Jenkins
65 // still using pipeline lib from current old mcp-version
Denis V. Meltsaykinfd7586b2020-06-02 11:23:18 +020066
67 // sleep to make sure package update started, otherwise checks will pass on still running old instance
68 sleep(120)
69
azvyagintsev6dac3802018-11-09 15:11:30 +020070 common.retry(20, 60) {
Richard Felkl0e80d892018-06-20 13:44:54 +020071 salt.minionsReachable(venvPepper, 'I@salt:master', '*')
72 def running = salt.runSaltProcessStep(venvPepper, target, 'saltutil.running', [], null, true, 5)
azvyagintsev6dac3802018-11-09 15:11:30 +020073 for (value in running.get("return")[0].values()) {
74 if (value != []) {
Richard Felkl0e80d892018-06-20 13:44:54 +020075 throw new Exception("Not all salt-minions are ready for execution")
76 }
77 }
78 }
79
azvyagintsevf3bf77a2018-11-15 19:30:04 +020080 def saltVersion = salt.getPillar(venvPepper, 'I@salt:master', '_param:salt_version').get('return')[0].values()[0]
Richard Felklf23257e2018-08-06 09:24:23 +020081 def saltMinionVersions = salt.cmdRun(venvPepper, target, "apt-cache policy salt-common | awk '/Installed/ && /$saltVersion/'").get("return")
Richard Felkl0e80d892018-06-20 13:44:54 +020082 def saltMinionVersion = ""
83
azvyagintsev6dac3802018-11-09 15:11:30 +020084 for (minion in saltMinionVersions[0].keySet()) {
85 saltMinionVersion = saltMinionVersions[0].get(minion).replace("Salt command execution success", "").trim()
86 if (saltMinionVersion == "") {
Richard Felkl0e80d892018-06-20 13:44:54 +020087 error("Installed version of Salt on $minion doesn't match specified version in the model.")
88 }
89 }
90}
91
Denis Egorenko20a43462019-09-24 14:55:50 +040092def getWorkerThreads(saltId) {
93 if (env.getEnvironment().containsKey('SALT_MASTER_OPT_WORKER_THREADS')) {
94 return env['SALT_MASTER_OPT_WORKER_THREADS'].toString()
95 }
96 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)
97 return threads['return'][0].values()[0].replaceAll('Salt command execution success','').trim()
98}
99
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400100def wa29352(String cname) {
azvyagintsev745a6e52019-04-18 13:19:39 +0300101 // WA for PROD-29352. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/12/openssh/client/root.yml
102 // Default soft-param has been removed, what now makes not possible to render some old env's.
103 // Like fix, we found copy-paste already generated key from backups, to secrets.yml with correct key name
104 def wa29352ClassName = 'cluster.' + cname + '.infra.secrets_root_wa29352'
105 def wa29352File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_root_wa29352.yml"
106 def wa29352SecretsFile = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets.yml"
107 def _tempFile = '/tmp/wa29352_' + UUID.randomUUID().toString().take(8)
108 try {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400109 salt.cmdRun(venvPepper, 'I@salt:master', "! grep -qi root_private_key: ${wa29352SecretsFile}", true, null, false)
azvyagintsev745a6e52019-04-18 13:19:39 +0300110 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29352File}", true, null, false)
111 }
112 catch (Exception ex) {
Denis Egorenkodfa35422019-10-07 12:46:14 +0400113 common.infoMsg('Work-around for PROD-29352 already applied, nothing todo')
azvyagintsev745a6e52019-04-18 13:19:39 +0300114 return
115 }
116 def rKeysDict = [
117 'parameters': [
118 '_param': [
119 'root_private_key': salt.getPillar(venvPepper, 'I@salt:master', '_param:root_private_key').get('return')[0].values()[0].trim(),
120 'root_public_key' : '',
121 ]
122 ]
123 ]
124 // save root key,and generate public one from it
125 writeFile file: _tempFile, text: rKeysDict['parameters']['_param']['root_private_key'].toString().trim()
126 sh('chmod 0600 ' + _tempFile)
127 rKeysDict['parameters']['_param']['root_public_key'] = sh(script: "ssh-keygen -q -y -f ${_tempFile}", returnStdout: true).trim()
128 sh('rm -fv ' + _tempFile)
129 writeYaml file: _tempFile, data: rKeysDict
130 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
131 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29352File}", false, null, false)
132 common.infoMsg("Add $wa29352ClassName class into secrets.yml")
133
134 // Add 'classes:' directive
135 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
136 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
137
138 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
139 "grep -q '${wa29352ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29352ClassName' infra/secrets.yml")
azvyagintsev745a6e52019-04-18 13:19:39 +0300140 sh('rm -fv ' + _tempFile)
Denis Egorenkodfa35422019-10-07 12:46:14 +0400141 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " +
142 "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()}' ")
143 common.infoMsg('Work-around for PROD-29352 successfully applied')
azvyagintsev745a6e52019-04-18 13:19:39 +0300144}
145
azvyagintsevbc359d42019-04-10 19:53:22 +0300146def wa29155(ArrayList saltMinions, String cname) {
147 // WA for PROD-29155. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/
148 // CHeck for existence cmp nodes, and try to render it. Is failed, apply ssh-key wa
azvyagintsevbc359d42019-04-10 19:53:22 +0300149 def patched = false
150 def wa29155ClassName = 'cluster.' + cname + '.infra.secrets_nova_wa29155'
151 def wa29155File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_nova_wa29155.yml"
152
153 try {
154 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29155File}", true, null, false)
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400155 def patch_required = false
156 for (String minion in saltMinions) {
157 def nova_key = salt.getPillar(venvPepper, minion, '_param:nova_compute_ssh_private').get("return")[0].values()[0]
158 if (nova_key == '' || nova_key == 'null' || nova_key == null) {
159 patch_required = true
160 break // no exception, proceeding to apply the patch
161 }
162 }
163 if (!patch_required) {
164 error('No need to apply work-around for PROD-29155')
165 }
azvyagintsevbc359d42019-04-10 19:53:22 +0300166 }
167 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300168 return
169 }
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400170 salt.fullRefresh(venvPepper, 'I@salt:master')
azvyagintsevbc359d42019-04-10 19:53:22 +0300171 for (String minion in saltMinions) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300172 // First attempt, second will be performed in next validateReclassModel() stages
173 try {
azvyagintsev745a6e52019-04-18 13:19:39 +0300174 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 +0300175 } catch (Exception e) {
176 common.errorMsg(e.toString())
177 if (patched) {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400178 error("Node: ${minion} failed to render after reclass-system upgrade! WA29155 probably didn't help.")
azvyagintsevbc359d42019-04-10 19:53:22 +0300179 }
azvyagintsev745a6e52019-04-18 13:19:39 +0300180 common.warningMsg('Perform: Attempt to apply WA for PROD-29155\n' +
181 'See https://gerrit.mcp.mirantis.com/#/c/37932/ for more info')
azvyagintsevbc359d42019-04-10 19:53:22 +0300182 common.warningMsg('WA-PROD-29155 Generating new ssh key at master node')
183 def _tempFile = "/tmp/nova_wa29155_" + UUID.randomUUID().toString().take(8)
184 common.infoMsg('Perform: generation NEW ssh-private key for nova-compute')
185 salt.cmdRun(venvPepper, 'I@salt:master', "ssh-keygen -f ${_tempFile} -N '' -q")
186 def _pub_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}.pub").get('return')[0].values()[0].trim()
187 def _priv_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}").get('return')[0].values()[0].trim()
188 salt.cmdRun(venvPepper, 'I@salt:master', "rm -fv ${_tempFile}", false, null, false)
189 def novaKeysDict = [
190 "parameters": [
191 "_param": [
192 "nova_compute_ssh_private": _priv_k,
193 "nova_compute_ssh_public" : _pub_k
194 ]
195 ]
196 ]
azvyagintsev745a6e52019-04-18 13:19:39 +0300197 writeYaml file: _tempFile, data: novaKeysDict
azvyagintsevbc359d42019-04-10 19:53:22 +0300198 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
199 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29155File}", false, null, false)
200 common.infoMsg("Add $wa29155ClassName class into secrets.yml")
201
202 // Add 'classes:' directive
203 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
204 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
205
206 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
207 "grep -q '${wa29155ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29155ClassName' infra/secrets.yml")
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400208 salt.fullRefresh(venvPepper, 'I@salt:master')
Ivan Berezovskiyc4dc5012020-03-19 14:03:43 +0400209 salt.runSaltProcessStep(venvPepper, saltMinions, 'saltutil.refresh_pillar', [], null, true, 60)
azvyagintsevbc359d42019-04-10 19:53:22 +0300210 patched = true
211 }
212 }
213 if (patched) {
214 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " +
215 "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()}' ")
216 common.infoMsg('Work-around for PROD-29155 successfully applied')
217 }
218
219}
220
Ivan Berezovskiy5b62e9c2020-01-24 17:52:26 +0400221def wa32284(String cluster_name) {
Denis Egorenko1b11d232019-07-29 17:44:46 +0400222 def clientGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:enabled").get("return")[0].values()[0]
223 def pkiGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:volumes:salt_pki").get("return")[0].values()[0]
224 def nginxEnabledAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0]
225 if (nginxEnabledAtMaster.toString().toLowerCase() == 'true' && clientGluster.toString().toLowerCase() == 'true' && pkiGluster) {
226 def nginxRequires = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:wait_for_service').get('return')[0].values()[0]
227 if (nginxRequires.isEmpty()) {
Ivan Berezovskiy5b62e9c2020-01-24 17:52:26 +0400228 def nginxRequiresClassName = "cluster.${cluster_name}.infra.config.nginx_requires_wa32284"
229 def nginxRequiresClassFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/infra/config/nginx_requires_wa32284.yml"
Denis Egorenko1b11d232019-07-29 17:44:46 +0400230 def nginxRequiresBlock = ['parameters': ['nginx': ['server': ['wait_for_service': ['srv-salt-pki.mount'] ] ] ] ]
231 def _tempFile = '/tmp/wa32284_' + UUID.randomUUID().toString().take(8)
232 writeYaml file: _tempFile , data: nginxRequiresBlock
233 def nginxRequiresBlockString = sh(script: "cat ${_tempFile}", returnStdout: true).trim()
Ivan Berezovskiy5b62e9c2020-01-24 17:52:26 +0400234 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && " +
Denis Egorenko1b11d232019-07-29 17:44:46 +0400235 "sed -i '/^parameters:/i - ${nginxRequiresClassName}' infra/config/init.yml")
236 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${nginxRequiresBlockString}' > ${nginxRequiresClassFile}", false, null, false)
Ivan Berezovskiy5b62e9c2020-01-24 17:52:26 +0400237 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${nginxRequiresClassFile}")
Denis Egorenko1b11d232019-07-29 17:44:46 +0400238 }
239 }
240}
241
Oleksii Molchanov5b7fceb2020-03-13 13:28:10 +0200242def check_34406(String cluster_name) {
243 def sphinxpasswordPillar = salt.getPillar(venvPepper, 'I@salt:master', '_param:sphinx_proxy_password_generated').get("return")[0].values()[0]
244 if (sphinxpasswordPillar == '' || sphinxpasswordPillar == 'null' || sphinxpasswordPillar == null) {
245 error('Sphinx password is not defined.\n' +
246 'See https://docs.mirantis.com/mcp/q4-18/mcp-release-notes/mu/mu-9/mu-9-addressed/mu-9-dtrain/mu-9-dt-manual.html#i-34406 for more info')
247 }
248}
249
Oleksii Molchanov05c49832020-09-28 19:28:06 +0300250def check_35705(String cluster_name) {
251 def galeracheckpasswordPillar = salt.getPillar(venvPepper, 'I@salt:master', '_param:galera_clustercheck_password').get("return")[0].values()[0]
252 if (galeracheckpasswordPillar == '' || galeracheckpasswordPillar == 'null' || galeracheckpasswordPillar == null) {
253 error('Galera clustercheck password is not defined.\n' +
254 'See https://docs.mirantis.com/mcp/q4-18/mcp-release-notes/mu/mu-12/mu-12-addressed/mu-12-dtrain/mu-12-dt-manual.html#improper-operation-of-galera-ha for more info')
255 }
256}
257
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400258def wa32182(String cluster_name) {
Hanna Arhipovad5eec4c2019-09-06 17:55:40 +0300259 if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) {
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400260 def clusterModelPath = "/srv/salt/reclass/classes/cluster/${cluster_name}"
261 def fixFile = "${clusterModelPath}/opencontrail/common_wa32182.yml"
262 def usualFile = "${clusterModelPath}/opencontrail/common.yml"
263 def fixFileContent = "classes:\n- system.opencontrail.common\n"
264 salt.cmdRun(venvPepper, 'I@salt:master', "test -f ${fixFile} -o -f ${usualFile} || echo '${fixFileContent}' > ${fixFile}")
265 def contrailFiles = ['opencontrail/analytics.yml', 'opencontrail/control.yml', 'openstack/compute/init.yml']
266 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
267 contrailFiles.add('kubernetes/compute.yml')
268 }
Ivan Berezovskiy9f6330b2020-02-05 21:18:17 +0400269 for (String contrailFile in contrailFiles) {
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400270 contrailFile = "${clusterModelPath}/${contrailFile}"
271 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()
272 if (containsFix) {
273 continue
274 } else {
275 salt.cmdRun(venvPepper, 'I@salt:master', "grep -q -E '^parameters:' ${contrailFile} && sed -i '/^parameters:/i - cluster.${cluster_name}.opencontrail.common_wa32182' ${contrailFile} || " +
Ivan Berezovskiy9f6330b2020-02-05 21:18:17 +0400276 "echo '- cluster.${cluster_name}.opencontrail.common_wa32182' >> ${contrailFile}")
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400277 }
278 }
Ivan Berezovskiy9f6330b2020-02-05 21:18:17 +0400279 salt.cmdRun(venvPepper, 'I@salt:master', "test -f ${fixFile} && cd ${clusterModelPath} && git status && git add ${fixFile} || true")
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400280 }
281}
282
Denis Egorenkoba631332019-10-25 13:13:39 +0400283def wa33867(String cluster_name) {
284 if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) {
285 def contrailControlFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/opencontrail/control.yml"
286 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()
287 if (line == "- cluster.${cluster_name}.infra") {
288 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra\$/d' ${contrailControlFile}")
289 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra.backup.client_zookeeper\$/i - cluster.${cluster_name}.infra' ${contrailControlFile}")
290 }
291 }
292}
293
Denis Egorenkoe312cc92019-10-18 17:06:11 +0400294def wa33771(String cluster_name) {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400295 if (salt.getMinions(venvPepper, 'I@_param:openstack_node_role and I@apache:server')) {
296 def octaviaEnabled = salt.getMinions(venvPepper, 'I@octavia:api:enabled')
297 def octaviaWSGI = salt.getMinions(venvPepper, 'I@apache:server:site:octavia_api')
298 if (octaviaEnabled && !octaviaWSGI) {
299 def openstackControl = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/control.yml"
300 def octaviaFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/octavia_wa33771.yml"
301 def octaviaContext = [
302 'classes' : ['system.apache.server.site.octavia'],
303 'parameters': [
304 '_param': ['apache_octavia_api_address': '${_param:cluster_local_address}'],
305 ]
Denis Egorenkoe312cc92019-10-18 17:06:11 +0400306 ]
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400307 def openstackHTTPSEnabled = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_internal_protocol").get("return")[0].values()[0]
308 if (openstackHTTPSEnabled == 'https') {
309 octaviaContext['parameters'] << ['apache': ['server': ['site': ['apache_proxy_openstack_api_octavia': ['enabled': false]]]]]
310 }
311 def _tempFile = '/tmp/wa33771' + UUID.randomUUID().toString().take(8)
312 writeYaml file: _tempFile, data: octaviaContext
313 def octaviaFileContent = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
314 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.octavia_wa33771' ${openstackControl}")
315 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${octaviaFileContent}' | base64 -d > ${octaviaFile}", false, null, false)
316 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${octaviaFile}")
Denis Egorenko59f82a52020-01-30 17:17:25 +0400317 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400318 } else {
319 common.warningMsg("Apache server is not defined on controller nodes. Skipping Octavia WSGI workaround");
Denis Egorenkoe312cc92019-10-18 17:06:11 +0400320 }
321}
322
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400323def wa33930_33931(String cluster_name) {
324 def openstackControlFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/control.yml"
325 def fixName = 'clients_common_wa33930_33931'
326 def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/${fixName}.yml"
327 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()
328 if (! containsFix) {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400329 def fixContext = [ 'classes': [ ] ]
330 def novaControllerNodes = salt.getMinions(venvPepper, 'I@nova:controller')
331 for (novaController in novaControllerNodes) {
332 def novaClientPillar = salt.getPillar(venvPepper, novaController, "nova:client").get("return")[0].values()[0]
333 if (novaClientPillar == '' || novaClientPillar == 'null' || novaClientPillar == null) {
334 fixContext['classes'] << 'service.nova.client'
335 break
336 }
337 }
338 def glanceServerNodes = salt.getMinions(venvPepper, 'I@glance:server')
339 for (glanceServer in glanceServerNodes) {
340 def glanceClientPillar = salt.getPillar(venvPepper, glanceServer, "glance:client").get("return")[0].values()[0]
341 if (glanceClientPillar == '' || glanceClientPillar == 'null' || glanceClientPillar == null) {
342 fixContext['classes'] << 'service.glance.client'
343 break
344 }
345 }
346 def neutronServerNodes = salt.getMinions(venvPepper, 'I@neutron:server')
347 for (neutronServer in neutronServerNodes) {
348 def neutronServerPillar = salt.getPillar(venvPepper, neutronServer, "neutron:client").get("return")[0].values()[0]
349 if (neutronServerPillar == '' || neutronServerPillar == 'null' || neutronServerPillar == null) {
350 fixContext['classes'] << 'service.neutron.client'
351 break
352 }
353 }
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400354 if (salt.getMinions(venvPepper, 'I@manila:api:enabled')) {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400355 def manilaApiNodes = salt.getMinions(venvPepper, 'I@manila:api')
356 for (manilaNode in manilaApiNodes) {
357 def manilaNodePillar = salt.getPillar(venvPepper, manilaNode, "manila:client").get("return")[0].values()[0]
358 if (manilaNodePillar == '' || manilaNodePillar == 'null' || manilaNodePillar == null) {
359 fixContext['classes'] << 'service.manila.client'
360 break
361 }
362 }
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400363 }
364 if (salt.getMinions(venvPepper, 'I@ironic:api:enabled')) {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400365 def ironicApiNodes = salt.getMinions(venvPepper, 'I@ironic:api')
366 for (ironicNode in ironicApiNodes) {
367 def ironicNodePillar = salt.getPillar(venvPepper, ironicNode, "ironic:client").get("return")[0].values()[0]
368 if (ironicNodePillar == '' || ironicNodePillar == 'null' || ironicNodePillar == null) {
369 fixContext['classes'] << 'service.ironic.client'
370 break
371 }
372 }
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400373 }
374 if (salt.getMinions(venvPepper, 'I@gnocchi:server:enabled')) {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400375 def gnocchiServerNodes = salt.getMinions(venvPepper, 'I@gnocchi:server')
376 for (gnocchiNode in gnocchiServerNodes) {
377 def gnocchiNodePillar = salt.getPillar(venvPepper, gnocchiNode, "gnocchi:client").get("return")[0].values()[0]
378 if (gnocchiNodePillar == '' || gnocchiNodePillar == 'null' || gnocchiNodePillar == null) {
379 fixContext['classes'] << 'service.gnocchi.client'
380 break
381 }
382 }
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400383 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400384
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400385 if (salt.getMinions(venvPepper, 'I@barbican:server:enabled')) {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400386 def barbicanServerNodes = salt.getMinions(venvPepper, 'I@barbican:server')
387 for (barbicanNode in barbicanServerNodes) {
388 def barbicanNodePillar = salt.getPillar(venvPepper, barbicanNode, "barbican:client").get("return")[0].values()[0]
389 if (barbicanNodePillar == '' || barbicanNodePillar == 'null' || barbicanNodePillar == null) {
390 fixContext['classes'] << 'service.barbican.client.single'
391 break
392 }
393 }
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400394 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400395 if (fixContext['classes'] != []) {
396 def _tempFile = '/tmp/wa33930_33931' + UUID.randomUUID().toString().take(8)
397 writeYaml file: _tempFile, data: fixContext
398 def fixFileContent = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
399 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${fixFileContent}' | base64 -d > ${fixFile}", false, null, false)
400 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.${fixName}' ${openstackControlFile}")
401 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${fixFile}")
402 }
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400403 }
404}
405
Denis Egorenko215acda2020-01-28 16:41:44 +0400406def wa34245(cluster_name) {
407 def infraInitFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/infra/init.yml"
408 def fixName = 'hosts_wa34245'
409 def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/infra/${fixName}.yml"
410 if (salt.testTarget(venvPepper, 'I@keystone:server')) {
411 def fixApplied = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- cluster.${cluster_name}.infra.${fixName}\$' ${infraInitFile}", false, null, true).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
412 if (!fixApplied) {
413 def fixFileContent = []
414 def containsFix = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- system\\.linux\\.network\\.hosts\\.openstack\$' ${infraInitFile}", false, null, true).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
415 if (!containsFix) {
416 fixFileContent << '- system.linux.network.hosts.openstack'
417 }
418 if (salt.testTarget(venvPepper, 'I@gnocchi:server')) {
419 containsFix = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- system\\.linux\\.network\\.hosts\\.openstack\\.telemetry\$' ${infraInitFile}", false, null, true).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
420 if (!containsFix) {
421 fixFileContent << '- system.linux.network.hosts.openstack.telemetry'
422 }
423 }
424 if (salt.testTarget(venvPepper, 'I@manila:api')) {
425 containsFix = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- system\\.linux\\.network\\.hosts\\.openstack\\.share\$' ${infraInitFile}", false, null, true).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
426 if (!containsFix) {
427 fixFileContent << '- system.linux.network.hosts.openstack.share'
428 }
429 }
430 if (salt.testTarget(venvPepper, 'I@barbican:server')) {
431 containsFix = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- system\\.linux\\.network\\.hosts\\.openstack\\.kmn\$' ${infraInitFile}", false, null, true).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
432 if (!containsFix) {
433 fixFileContent << '- system.linux.network.hosts.openstack.kmn'
434 }
435 }
436 if (fixFileContent) {
437 salt.cmdRun(venvPepper, 'I@salt:master', "echo 'classes:\n${fixFileContent.join('\n')}' > ${fixFile}")
438 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.infra.${fixName}' ${infraInitFile}")
Ivan Berezovskiy5b62e9c2020-01-24 17:52:26 +0400439 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${fixFile}")
Denis Egorenko215acda2020-01-28 16:41:44 +0400440 }
441 }
442 }
443}
444
Ivan Berezovskiy5b62e9c2020-01-24 17:52:26 +0400445def wa34528(String cluster_name) {
446 // Mysql users have to be defined on each Galera node
447 if(salt.getMinions(venvPepper, 'I@galera:master').isEmpty()) {
448 common.errorMsg('No Galera master found in cluster. Skipping')
449 return
450 }
451 def mysqlUsersMasterPillar = salt.getPillar(venvPepper, 'I@galera:master', 'mysql:server:database').get("return")[0].values()[0]
452 if (mysqlUsersMasterPillar == '' || mysqlUsersMasterPillar == 'null' || mysqlUsersMasterPillar == null) {
453 common.errorMsg('Pillar data is broken for Galera master node!')
454 input message: 'Do you want to ignore and continue without Galera pillar patch?'
455 return
456 }
457 def fileToPatch = salt.cmdRun(venvPepper, 'I@salt:master', "ls /srv/salt/reclass/classes/cluster/${cluster_name}/openstack/database/init.yml || " +
458 "ls /srv/salt/reclass/classes/cluster/${cluster_name}/openstack/database/slave.yml || echo 'File not found'", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
459 if (fileToPatch == 'File not found') {
460 common.errorMsg('Cluster model is old and cannot be patched for PROD-34528. Patching is possible for 2019.2.x cluster models only')
461 return
462 }
463 def patchRequired = false
464 def mysqlUsersSlavePillar = ''
465 def galeraSlaveNodes = salt.getMinions(venvPepper, 'I@galera:slave')
466 if (!galeraSlaveNodes.isEmpty()) {
467 for (galeraSlave in galeraSlaveNodes) {
468 mysqlUsersSlavePillar = salt.getPillar(venvPepper, galeraSlave, 'mysql:server:database').get("return")[0].values()[0]
469 if (mysqlUsersSlavePillar == '' || mysqlUsersSlavePillar == 'null' || mysqlUsersSlavePillar == null) {
470 common.errorMsg('Mysql users data is not defined for Galera slave nodes. Fixing...')
471 patchRequired = true
472 break
473 }
474 }
475 if (patchRequired) {
476 def fixFileContent = []
477 def fixName = 'db_wa34528'
478 def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/database/${fixName}.yml"
479 for (dbName in mysqlUsersMasterPillar.keySet()) {
480 def classIncluded = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- system\\.galera\\.server\\.database\\.${dbName}\$'" +
481 " /srv/salt/reclass/classes/cluster/${cluster_name}/openstack/database/master.yml", false, null, true).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
482 if(classIncluded) {
483 fixFileContent << "- system.galera.server.database.${dbName}"
484 }
485 def sslClassIncluded = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- system\\.galera\\.server\\.database\\.x509\\.${dbName}\$'" +
486 " /srv/salt/reclass/classes/cluster/${cluster_name}/openstack/database/master.yml", false, null, true).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
487 if(sslClassIncluded) {
488 fixFileContent << "- system.galera.server.database.x509.${dbName}"
489 }
490 }
491 if (fixFileContent) {
492 salt.cmdRun(venvPepper, 'I@salt:master', "echo 'classes:\n${fixFileContent.join('\n')}' > ${fixFile}")
493 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.database.${fixName}' ${fileToPatch}")
494 }
495 salt.fullRefresh(venvPepper, 'I@galera:slave')
496 // Verify
497 for (galeraSlave in galeraSlaveNodes) {
498 mysqlUsersSlavePillar = salt.getPillar(venvPepper, galeraSlave, 'mysql:server:database').get("return")[0].values()[0]
499 if (mysqlUsersSlavePillar == '' || mysqlUsersSlavePillar == 'null' || mysqlUsersSlavePillar == null || mysqlUsersSlavePillar.keySet() != mysqlUsersMasterPillar.keySet()) {
500 common.errorMsg("Mysql user data is different on master and slave node ${galeraSlave}.")
501 input message: 'Do you want to ignore and continue?'
502 }
503 }
504 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${fixFile}")
505 common.infoMsg('Galera slaves patching is done')
506 } else {
507 common.infoMsg('Galera slaves patching is not required')
508 }
509 }
510}
511
azvyagintsev6dac3802018-11-09 15:11:30 +0200512def archiveReclassInventory(filename) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300513 def _tmp_file = '/tmp/' + filename + UUID.randomUUID().toString().take(8)
514 // jenkins may fail at overheap. Compress data with gzip like WA
azvyagintsev745a6e52019-04-18 13:19:39 +0300515 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 +0300516 def _tmp = sh(script: "echo '$ret' > ${_tmp_file}", returnStdout: false)
517 sh(script: "cat ${_tmp_file} | base64 -d | gzip -d > $filename", returnStdout: false)
518 archiveArtifacts artifacts: filename
519 sh(script: "rm -v ${_tmp_file}|| true")
Richard Felkl0e80d892018-06-20 13:44:54 +0200520}
521
Denis Egorenkod13ad132018-12-17 16:56:02 +0400522def validateReclassModel(ArrayList saltMinions, String suffix) {
523 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300524 for (String minion in saltMinions) {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400525 common.infoMsg("Reclass model validation for minion ${minion}...")
azvyagintsev745a6e52019-04-18 13:19:39 +0300526 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 +0400527 writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString()
528 }
529 } catch (Exception e) {
530 common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.')
azvyagintsevbc359d42019-04-10 19:53:22 +0300531 error(e.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400532 }
533}
534
azvyagintsevbc359d42019-04-10 19:53:22 +0300535def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix = 'before', String newSuffix = 'after') {
536 for (String minion in saltMinions) {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400537 def fileName = "reclass-model-${minion}-diff.out"
538 sh "diff -u inventory-${minion}-${oldSuffix}.out inventory-${minion}-${newSuffix}.out > ${fileName} || true"
539 archiveArtifacts artifacts: "${fileName}"
540 }
541}
542
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300543def checkDebsums() {
544 // check for salt-formulas consistency
545 try {
546 try {
547 salt.cmdRun(venvPepper, 'I@salt:master', "salt -C 'I@salt:master' pkg.install force_yes=True pkgs=[debsums]")
548 }
549 catch (Exception ex) {
550 common.warningMsg('Unable to install package "debsums" at cfg01. Salt-formulas integrity check skipped')
551 }
552 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')
553 salt.cmdRun(venvPepper, 'I@salt:master', 'if [ -s "/root/debdsums_report" ]; then exit 1 ; fi')
554 }
555 catch (Exception ex) {
556 common.errorMsg(salt.cmdRun(venvPepper, 'I@salt:master', 'cat /root/debdsums_report ', true, null, false).get('return')[0].values()[0].trim())
557 common.errorMsg(ex.toString())
558 error('You have unexpected changes in formulas. All of them will be overwrited by update. Unable to continue in automatic way')
559 }
560}
561
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400562def checkCICDDocker() {
563 common.infoMsg('Perform: Checking if Docker containers are up')
564 try {
565 common.retry(10, 30) {
566 salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'")
567 }
568 }
569 catch (Exception ex) {
570 error("Docker containers for CI/CD services are having troubles with starting.")
571 }
572}
573
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400574if (common.validInputParam('PIPELINE_TIMEOUT')) {
575 try {
576 pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger()
azvyagintsevbc359d42019-04-10 19:53:22 +0300577 } catch (Exception e) {
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400578 common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger")
579 }
Martin Polreich965c9032018-08-09 16:33:57 +0200580}
581
582timeout(time: pipelineTimeout, unit: 'HOURS') {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300583 node('python') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100584 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300585 def inventoryBeforeFilename = "reclass-inventory-before.out"
586 def inventoryAfterFilename = "reclass-inventory-after.out"
Richard Felkl0e80d892018-06-20 13:44:54 +0200587 workspace = common.getWorkspace()
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200588 targetMcpVersion = null
589 if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) {
590 error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable')
azvyagintsev6dac3802018-11-09 15:11:30 +0200591 }
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200592 // bw comp. for 2018.X => 2018.11 release
azvyagintsevbc359d42019-04-10 19:53:22 +0300593 if (common.validInputParam('MCP_VERSION')) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200594 targetMcpVersion = env.MCP_VERSION
595 common.warningMsg("targetMcpVersion has been changed to:${targetMcpVersion}, which was taken from deprecated pipeline viriable:MCP_VERSION")
azvyagintsevbc359d42019-04-10 19:53:22 +0300596 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200597 targetMcpVersion = env.TARGET_MCP_VERSION
598 }
599 // end bw comp. for 2018.X => 2018.11 release
Denis Egorenkod13ad132018-12-17 16:56:02 +0400600 def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC')
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400601 if (targetMcpVersion in ['nightly', 'testing']) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200602 gitTargetMcpVersion = 'master'
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400603 } else if (targetMcpVersion == 'proposed') {
604 gitTargetMcpVersion = 'proposed'
Denis Egorenko284690e2018-12-25 15:55:12 +0400605 } else if (!gitTargetMcpVersion) {
606 // backward compatibility for 2018.11.0
607 gitTargetMcpVersion = "release/${targetMcpVersion}"
azvyagintsev6dac3802018-11-09 15:11:30 +0200608 }
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400609 common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}")
Denis Egorenko284690e2018-12-25 15:55:12 +0400610 def upgradeSaltStack = ''
611 def updateClusterModel = ''
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400612 def applyWorkarounds = true
Denis Egorenko284690e2018-12-25 15:55:12 +0400613 def updatePipelines = ''
614 def updateLocalRepos = ''
615 def reclassSystemBranch = ''
Denis Egorenko517e06c2019-03-29 13:24:15 +0400616 def reclassSystemBranchDefault = gitTargetMcpVersion
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400617 if (gitTargetMcpVersion ==~ /^\d\d\d\d\.\d\d?\.\d+$/) {
618 reclassSystemBranchDefault = "tags/${gitTargetMcpVersion}"
619 } else if (gitTargetMcpVersion != 'proposed') {
Denis Egorenko517e06c2019-03-29 13:24:15 +0400620 reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}"
621 }
Hanna Arhipovad5eec4c2019-09-06 17:55:40 +0300622 def driveTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS')
623 if (driveTrainParamsYaml) {
624 def driveTrainParams = readYaml text: driveTrainParamsYaml
625 saltMastURL = driveTrainParams.get('SALT_MASTER_URL')
626 saltMastCreds = driveTrainParams.get('SALT_MASTER_CREDENTIALS')
627 upgradeSaltStack = driveTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean()
628 updateClusterModel = driveTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean()
629 updatePipelines = driveTrainParams.get('UPDATE_PIPELINES', false).toBoolean()
630 updateLocalRepos = driveTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean()
631 reclassSystemBranch = driveTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault)
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400632 batchSize = driveTrainParams.get('BATCH_SIZE', '')
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400633 if (driveTrainParams.get('OS_DIST_UPGRADE', false).toBoolean() == true) {
634 packageUpgradeMode = 'dist-upgrade'
635 } else if (driveTrainParams.get('OS_UPGRADE', false).toBoolean() == true) {
636 packageUpgradeMode = 'upgrade'
637 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400638 applyWorkarounds = driveTrainParams.get('APPLY_MODEL_WORKAROUNDS', true).toBoolean()
Denis Egorenko284690e2018-12-25 15:55:12 +0400639 } else {
640 // backward compatibility for 2018.11.0
641 saltMastURL = env.getProperty('SALT_MASTER_URL')
642 saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS')
Denis Egorenkoe5f39142018-12-28 12:30:48 +0400643 upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean()
644 updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean()
645 updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean()
646 updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean()
Denis Egorenko517e06c2019-03-29 13:24:15 +0400647 reclassSystemBranch = reclassSystemBranchDefault
Denis Egorenko284690e2018-12-25 15:55:12 +0400648 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400649 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400650 def minions = salt.getMinions(venvPepper, '*')
Denis Egorenkofbcee412019-04-19 15:05:18 +0400651 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
652 if (cluster_name == '' || cluster_name == 'null' || cluster_name == null) {
653 error('Pillar data is broken for Salt master node! Please check it manually and re-run pipeline.')
654 }
Hanna Arhipovad5eec4c2019-09-06 17:55:40 +0300655 if (!batchSize) {
Denis Egorenko7b098c32019-12-19 16:45:25 +0400656 // if no batch size provided get current worker threads and set batch size to 2/3 of it to avoid
657 // 'SaltReqTimeoutError: Message timed out' issue on Salt targets for large amount of nodes
658 // do not use toDouble/Double as it requires additional approved method
659 def workerThreads = getWorkerThreads(venvPepper).toInteger()
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400660 batchSize = (workerThreads * 2 / 3).toString().tokenize('.')[0]
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400661 }
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400662 def computeMinions = salt.getMinions(venvPepper, 'I@nova:compute')
Ivan Berezovskiyc4dc5012020-03-19 14:03:43 +0400663 def allMinions = salt.getMinions(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400664
azvyagintsevbc359d42019-04-10 19:53:22 +0300665 stage('Update Reclass and Salt-Formulas') {
666 common.infoMsg('Perform: Full salt sync')
Ivan Berezovskiyc4dc5012020-03-19 14:03:43 +0400667 fullRefreshOneByOne(venvPepper, allMinions)
Oleksii Molchanov5b7fceb2020-03-13 13:28:10 +0200668
669 check_34406(cluster_name)
Oleksii Molchanov05c49832020-09-28 19:28:06 +0300670 check_35705(cluster_name)
Oleksii Molchanov5b7fceb2020-03-13 13:28:10 +0200671
azvyagintsevbc359d42019-04-10 19:53:22 +0300672 common.infoMsg('Perform: Validate reclass medata before processing')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400673 validateReclassModel(minions, 'before')
674
azvyagintsev745a6e52019-04-18 13:19:39 +0300675 common.infoMsg('Perform: archiveReclassInventory before upgrade')
676 archiveReclassInventory(inventoryBeforeFilename)
677
azvyagintsev6dac3802018-11-09 15:11:30 +0200678 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300679 salt.cmdRun(venvPepper, 'I@salt:master', 'cd /srv/salt/reclass/ && git status && git diff-index --quiet HEAD --')
Richard Felkl970e0082018-06-12 18:00:51 +0200680 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200681 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300682 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 +0200683 }
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300684 checkDebsums()
Denis Egorenkod13ad132018-12-17 16:56:02 +0400685 if (updateClusterModel) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200686 common.infoMsg('Perform: UPDATE_CLUSTER_MODEL')
Sergey382581a2018-10-25 12:22:26 +0400687 def dateTime = common.getDatetime()
Ivan Berezovskiycfa1b2f2020-01-17 13:55:18 +0400688 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git fetch")
Sergey382581a2018-10-25 12:22:26 +0400689 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400690 "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 +0200691 // Do the same, for deprecated variable-duplicate
692 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400693 "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 +0400694 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400695 "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 +0400696 // Set new k8s param
697 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
698 "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 +0400699 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
700 "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'")
701 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko301cc8a2019-02-13 13:49:13 +0400702 "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 +0400703 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko301cc8a2019-02-13 13:49:13 +0400704 "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 +0400705 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsevbc359d42019-04-10 19:53:22 +0300706 "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 +0400707
Denis Egorenko6f07b592019-09-16 16:41:26 +0400708 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")
709 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name/infra && sed -i '/maas_region_main_archive/d' maas.yml")
710
Denis Egorenko21c78be2019-07-10 19:47:39 +0400711 // Switch Jenkins/Gerrit to use LDAP SSL/TLS
712 def gerritldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
713 "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()
714 if (gerritldapURI.startsWith('ldap://')) {
715 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
716 "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
717 } else if (! gerritldapURI.startsWith('ldaps://')) {
718 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
719 "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'")
720 }
721 def jenkinsldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
722 "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()
723 if (jenkinsldapURI.startsWith('ldap://')) {
724 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
725 "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
726 } else if (! jenkinsldapURI.startsWith('ldaps://')) {
727 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
728 "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'")
729 }
730
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400731 if (applyWorkarounds) {
732 wa32284(cluster_name)
733 wa34245(cluster_name)
734 }
Denis Egorenko1b11d232019-07-29 17:44:46 +0400735
Denis Egorenkod13ad132018-12-17 16:56:02 +0400736 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}")
Sergey Kolekonov5dfbf7a2019-01-23 16:47:43 +0400737 // Add kubernetes-extra repo
738 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
Sergey Kolekonov3fde8b12019-04-11 16:33:54 +0400739 // docker-engine conflicts with the recent containerd versions, so it's removed during upgrade. Thus update source engine
740 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
741 "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 +0400742 common.infoMsg("Add kubernetes-extra repo")
743 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
744 "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")
745 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
746 "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")
747 }
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400748 // Add all update repositories
749 def repoIncludeBase = '- system.linux.system.repo.mcp.apt_mirantis.'
Denis Egorenko6f07b592019-09-16 16:41:26 +0400750 def updateRepoList = ['cassandra', 'ceph', 'contrail', 'docker', 'elastic', 'extra', 'openstack', 'maas', 'percona', 'salt-formulas', 'saltstack', 'ubuntu']
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400751 updateRepoList.each { repo ->
752 def repoNameUpdateInclude = "${repoIncludeBase}update.${repo}"
753 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')
754 filesWithInclude.each { file ->
755 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()
756 if (updateRepoIncludeExist == 'not_found') {
757 // Include needs to be added
758 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsevbc359d42019-04-10 19:53:22 +0300759 "sed -i 's/\\( *\\)${repoIncludeBase}${repo}\$/&\\n\\1${repoNameUpdateInclude}/g' ${file}")
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400760 common.infoMsg("Update repo for ${repo} is added to ${file}")
761 }
762 }
763 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400764 if (applyWorkarounds) {
765 wa32182(cluster_name)
766 wa33771(cluster_name)
767 wa33867(cluster_name)
768 wa33930_33931(cluster_name)
769 wa34528(cluster_name)
770 }
Sergey382581a2018-10-25 12:22:26 +0400771 // Add new defaults
772 common.infoMsg("Add new defaults")
Denis Egorenkod13ad132018-12-17 16:56:02 +0400773 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 +0400774 "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 +0400775 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 +0400776 "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 +0400777 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300778 "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 +0400779 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300780 "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 +0400781 common.infoMsg("The following changes were made to the cluster model and will be commited. " +
azvyagintsev6dac3802018-11-09 15:11:30 +0200782 "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 +0400783 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff")
784 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " +
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200785 "git add -u && git commit --allow-empty -m 'Cluster model update to the release $targetMcpVersion on $dateTime'")
Sergey382581a2018-10-25 12:22:26 +0400786 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400787 try {
788 common.infoMsg('Perform: UPDATE Salt Formulas')
Ivan Berezovskiyc4dc5012020-03-19 14:03:43 +0400789 fullRefreshOneByOne(venvPepper, allMinions)
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400790 salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400791 def saltEnv = salt.getPillar(venvPepper, 'I@salt:master', "_param:salt_master_base_environment").get("return")[0].values()[0]
azvyagintsevbc359d42019-04-10 19:53:22 +0300792 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas", 'salt.master.env'])
Ivan Berezovskiyc4dc5012020-03-19 14:03:43 +0400793 fullRefreshOneByOne(venvPepper, allMinions)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400794 } catch (Exception updateErr) {
795 common.warningMsg(updateErr)
796 common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
797 input message: 'Continue anyway?'
798 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400799 if (applyWorkarounds) {
800 wa29352(cluster_name)
801 wa29155(computeMinions, cluster_name)
802 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400803
804 try {
805 common.infoMsg('Perform: UPDATE Reclass package')
806 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"])
807 } catch (Exception updateErr) {
808 common.warningMsg(updateErr)
809 common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
810 input message: 'Continue anyway?'
811 }
812
813 salt.fullRefresh(venvPepper, 'I@salt:master')
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400814 salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true, true, null, false, 60, 2)
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400815 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && " +
816 "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 +0400817 try {
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400818 salt.enforceState(venvPepper, 'I@salt:master', 'reclass', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400819 }
820 catch (Exception ex) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300821 common.errorMsg(ex.toString())
822 error('Reclass fails rendering. Pay attention to your cluster model.')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400823 }
824
Ivan Berezovskiyc4dc5012020-03-19 14:03:43 +0400825 fullRefreshOneByOne(venvPepper, allMinions)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400826 try {
827 salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top")
828 }
829 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300830
831 error('Reclass fails rendering. Pay attention to your cluster model.' +
832 'ErrorMessage:' + ex.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400833 }
834
azvyagintsevbc359d42019-04-10 19:53:22 +0300835 common.infoMsg('Perform: archiveReclassInventory AFTER upgrade')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400836 archiveReclassInventory(inventoryAfterFilename)
837
838 sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true"
839 archiveArtifacts artifacts: "reclass-inventory-diff.out"
840
841 validateReclassModel(minions, 'after')
842 archiveReclassModelChanges(minions)
Jakub Josefa63f9862018-01-11 17:58:38 +0100843 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100844
Denis Egorenkod13ad132018-12-17 16:56:02 +0400845 if (updateLocalRepos) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200846 stage("Update local repos") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100847 common.infoMsg("Updating local repositories")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700848
Sergey1b81c062018-10-16 17:10:21 +0400849 def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700850 runningOnDocker = engine.get("return")[0].containsValue("docker")
851
852 if (runningOnDocker) {
853 common.infoMsg("Aptly is running as Docker container")
azvyagintsev6dac3802018-11-09 15:11:30 +0200854 } else {
Sam Stoelingaaab79702018-04-09 18:49:39 -0700855 common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands")
856 }
857
azvyagintsev6dac3802018-11-09 15:11:30 +0200858 if (runningOnDocker) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200859 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 +0200860 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200861 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 +0100862 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100863
Sergey1b81c062018-10-16 17:10:21 +0400864 salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100865
azvyagintsev6dac3802018-11-09 15:11:30 +0200866 if (runningOnDocker) {
Sergey1b81c062018-10-16 17:10:21 +0400867 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true)
868 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 +0200869 } else {
Sergey1b81c062018-10-16 17:10:21 +0400870 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true)
871 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 +0100872 }
Richard Felkl79d7df12018-01-05 16:40:11 +0100873
Sergey1b81c062018-10-16 17:10:21 +0400874 salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100875
Sergey1b81c062018-10-16 17:10:21 +0400876 salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100877
Sergey1b81c062018-10-16 17:10:21 +0400878 salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100879
Sergey1b81c062018-10-16 17:10:21 +0400880 salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100881 }
882 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100883
azvyagintsevbc359d42019-04-10 19:53:22 +0300884 stage('Update Drivetrain') {
Oleksii Molchanov68eb72c2020-05-15 13:33:45 +0300885 salt.enforceState(venvPepper, '*', 'linux.system.package', true, true, batchSize, false, 60, 2)
886
Denis Egorenkod13ad132018-12-17 16:56:02 +0400887 if (upgradeSaltStack) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300888 updateSaltStack('I@salt:master', '["salt-master", "salt-common", "salt-api", "salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200889
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400890 salt.enforceState(venvPepper, 'I@linux:system', 'linux.system.repo', true, true, batchSize, false, 60, 2)
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300891 updateSaltStack('I@salt:minion and not I@salt:master', '["salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200892 }
893
Denis Egorenkod13ad132018-12-17 16:56:02 +0400894 if (updatePipelines) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300895 common.infoMsg('Perform: UPDATE git repos')
896 triggerMirrorJob('git-mirror-downstream-mk-pipelines', reclassSystemBranch)
897 triggerMirrorJob('git-mirror-downstream-pipeline-library', reclassSystemBranch)
Richard Felkl970e0082018-06-12 18:00:51 +0200898 }
899
Denis Egorenko7a4cf032019-04-25 20:48:26 +0400900 // update minions certs
Denis Egorenkoaf3a2202019-04-26 15:13:16 +0400901 // call for `salt.minion.ca` state on related nodes to make sure
902 // mine was updated with required data after salt-minion/salt-master restart salt:minion:ca
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400903 salt.enforceState(venvPepper, 'I@salt:minion:ca', 'salt.minion.ca', true, true, batchSize, false, 60, 2)
904 salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion.cert', true, true, batchSize, false, 60, 2)
Denis Egorenko7a4cf032019-04-25 20:48:26 +0400905
Ann Kamyshnikovae8910112019-05-06 12:56:38 +0400906 // run `salt.minion` to refresh all minion configs (for example _keystone.conf)
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400907 salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion', true, true, batchSize, false, 60, 2)
azvyagintsevbc359d42019-04-10 19:53:22 +0300908 // Retry needed only for rare race-condition in user appearance
909 common.infoMsg('Perform: updating users and keys')
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400910 salt.enforceState(venvPepper, 'I@linux:system', 'linux.system.user', true, true, batchSize, false, 60, 2)
azvyagintsevbc359d42019-04-10 19:53:22 +0300911 common.infoMsg('Perform: updating openssh')
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400912 salt.enforceState(venvPepper, 'I@linux:system', 'openssh', true, true, batchSize, false, 60, 2)
Denis Egorenko65cf2a42019-01-15 11:58:12 +0400913
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300914 // apply salt API TLS if needed
915 def nginxAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0]
916 if (nginxAtMaster.toString().toLowerCase() == 'true') {
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400917 salt.enforceState(venvPepper, 'I@salt:master', 'nginx', true, true, null, false, 60, 2)
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300918 }
919
Denis Egorenko579f1842019-10-30 13:26:59 +0400920 // 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
921 def gerritGlusterPath = salt.getPillar(venvPepper, 'I@gerrit:client', 'glusterfs:client:volumes:gerrit:path').get('return')[0].values()[0]
922 def wrongPluginJarName = "${gerritGlusterPath}/plugins/project-download-commands.jar"
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400923 salt.cmdRun(venvPepper, 'I@gerrit:client', "test -f ${wrongPluginJarName} && rm ${wrongPluginJarName} || true")
Denis Egorenko579f1842019-10-30 13:26:59 +0400924
Ivan Berezovskiy80911372020-03-19 19:11:27 +0400925 salt.enforceStateWithTest(venvPepper, 'I@jenkins:client:security and not I@salt:master', 'jenkins.client.security', "", true, true, null, true, 60, 2)
Ivan Berezovskiy89b24832020-02-27 15:21:57 +0400926 salt.enforceStateWithTest(venvPepper, 'I@jenkins:client and I@docker:client:images and not I@salt:master', 'docker.client.images', "", true, true, null, true, 60, 2)
Denis Egorenko21c78be2019-07-10 19:47:39 +0400927 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 +0400928 }
929 }
930 catch (Throwable e) {
931 // If there was an error or exception thrown, the build failed
932 currentBuild.result = "FAILURE"
933 throw e
934 }
935 }
936 // docker.client state may trigger change of jenkins master or jenkins slave services,
937 // so we need wait for slave to reconnect and continue pipeline
938 sleep(180)
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400939 def cidNodes = []
Ivan Berezovskiya766d432019-12-11 15:31:10 +0400940 node('python') {
941 try {
942 stage('Update Drivetrain: Phase 2') {
943 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400944 checkCICDDocker()
Denis Egorenko21c78be2019-07-10 19:47:39 +0400945
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400946 // Apply changes for HaProxy on CI/CD nodes
947 salt.enforceState(venvPepper, 'I@keepalived:cluster:instance:cicd_control_vip and I@haproxy:proxy', 'haproxy.proxy', true)
Valeriy Sakharovfaebb0d2020-04-06 16:46:39 +0400948 salt.upgradePackageAndRestartSaltMinion(venvPepper, 'I@jenkins:client and not I@salt:master', 'python-jenkins')
Denis Egorenko21c78be2019-07-10 19:47:39 +0400949 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 +0400950
951 // update Nginx proxy settings for Jenkins/Gerrit if needed
952 if (salt.testTarget(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit')) {
953 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)
954 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100955 }
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400956 if (packageUpgradeMode) {
957 cidNodes = salt.getMinions(venvPepper, 'I@_param:drivetrain_role:cicd')
958 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100959 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100960 catch (Throwable e) {
961 // If there was an error or exception thrown, the build failed
962 currentBuild.result = "FAILURE"
963 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +0100964 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100965 }
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400966
967 stage('Upgrade OS') {
968 if (packageUpgradeMode) {
969 def debian = new com.mirantis.mk.Debian()
970 def statusFile = '/tmp/rebooted_during_upgrade'
971 for(cidNode in cidNodes) {
972 node('python') {
973 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
974 // cmd.run async to prevent connection close in case of slave shutdown, give 5 seconds to handle request response
975 salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${cidNode}' cmd.run 'sleep 5; touch ${statusFile}; salt-call service.stop docker' --async")
976 }
977 sleep(30)
978 node('python') {
979 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
980 debian.osUpgradeNode(venvPepper, cidNode, packageUpgradeMode, false, 60)
981 salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': cidNode, wait: 60, timeout: 10])
982 if (salt.runSaltProcessStep(venvPepper, cidNode, 'file.file_exists', [statusFile], null, true, 5)['return'][0].values()[0].toBoolean()) {
983 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
984 sleep(10)
985 }
986 checkCICDDocker()
987 }
988 }
989 } else {
990 common.infoMsg('Upgrade OS skipped...')
991 }
992 }
Jakub Josef2c21c6c2018-02-08 18:51:42 +0100993}