blob: d0f1a97ce1aee1ba56c090b6eea521d4efb16282 [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 = ''
Roman Lubianyi1ee62562021-11-08 15:05:45 +020032upgradeChecks = new com.mirantis.mcp.UpgradeChecks()
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010033
Ivan Berezovskiyc4dc5012020-03-19 14:03:43 +040034def fullRefreshOneByOne(venvPepper, minions) {
35 for (minion in minions) {
36 salt.runSaltProcessStep(venvPepper, minion, 'saltutil.refresh_pillar', [], null, true, 60)
37 salt.runSaltProcessStep(venvPepper, minion, 'saltutil.refresh_grains', [], null, true, 60)
38 salt.runSaltProcessStep(venvPepper, minion, 'saltutil.sync_all', [], null, true, 180)
39 }
40}
41
azvyagintsevbc359d42019-04-10 19:53:22 +030042def triggerMirrorJob(String jobName, String reclassSystemBranch) {
Richard Felkl970e0082018-06-12 18:00:51 +020043 params = jenkinsUtils.getJobParameters(jobName)
azvyagintsevbc359d42019-04-10 19:53:22 +030044 try {
45 build job: jobName, parameters: [
46 [$class: 'StringParameterValue', name: 'BRANCHES', value: params.get('BRANCHES')],
47 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')],
48 [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')],
49 [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')]
50 ]
51 } catch (Exception updateErr) {
52 common.warningMsg(updateErr)
53 common.warningMsg('Attempt to update git repo in failsafe manner')
54 build job: jobName, parameters: [
55 [$class: 'StringParameterValue', name: 'BRANCHES', value: reclassSystemBranch.replace('origin/', '')],
56 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')],
57 [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')],
58 [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')]
59 ]
60 }
Richard Felkl970e0082018-06-12 18:00:51 +020061}
62
azvyagintsev6dac3802018-11-09 15:11:30 +020063def updateSaltStack(target, pkgs) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +030064 salt.cmdRun(venvPepper, 'I@salt:master', "salt -C '${target}' --async pkg.install force_yes=True pkgs='$pkgs'")
Denis Egorenko4b54e7f2019-02-26 16:05:03 +040065 // can't use same function from pipeline lib, as at the moment of running upgrade pipeline Jenkins
66 // still using pipeline lib from current old mcp-version
Denis V. Meltsaykinfd7586b2020-06-02 11:23:18 +020067
68 // sleep to make sure package update started, otherwise checks will pass on still running old instance
69 sleep(120)
70
azvyagintsev6dac3802018-11-09 15:11:30 +020071 common.retry(20, 60) {
Richard Felkl0e80d892018-06-20 13:44:54 +020072 salt.minionsReachable(venvPepper, 'I@salt:master', '*')
73 def running = salt.runSaltProcessStep(venvPepper, target, 'saltutil.running', [], null, true, 5)
azvyagintsev6dac3802018-11-09 15:11:30 +020074 for (value in running.get("return")[0].values()) {
75 if (value != []) {
Richard Felkl0e80d892018-06-20 13:44:54 +020076 throw new Exception("Not all salt-minions are ready for execution")
77 }
78 }
79 }
80
azvyagintsevf3bf77a2018-11-15 19:30:04 +020081 def saltVersion = salt.getPillar(venvPepper, 'I@salt:master', '_param:salt_version').get('return')[0].values()[0]
Richard Felklf23257e2018-08-06 09:24:23 +020082 def saltMinionVersions = salt.cmdRun(venvPepper, target, "apt-cache policy salt-common | awk '/Installed/ && /$saltVersion/'").get("return")
Richard Felkl0e80d892018-06-20 13:44:54 +020083 def saltMinionVersion = ""
84
azvyagintsev6dac3802018-11-09 15:11:30 +020085 for (minion in saltMinionVersions[0].keySet()) {
86 saltMinionVersion = saltMinionVersions[0].get(minion).replace("Salt command execution success", "").trim()
87 if (saltMinionVersion == "") {
Richard Felkl0e80d892018-06-20 13:44:54 +020088 error("Installed version of Salt on $minion doesn't match specified version in the model.")
89 }
90 }
91}
92
Denis Egorenko20a43462019-09-24 14:55:50 +040093def getWorkerThreads(saltId) {
94 if (env.getEnvironment().containsKey('SALT_MASTER_OPT_WORKER_THREADS')) {
95 return env['SALT_MASTER_OPT_WORKER_THREADS'].toString()
96 }
97 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)
98 return threads['return'][0].values()[0].replaceAll('Salt command execution success','').trim()
99}
100
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400101def wa29352(String cname) {
azvyagintsev745a6e52019-04-18 13:19:39 +0300102 // WA for PROD-29352. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/12/openssh/client/root.yml
103 // Default soft-param has been removed, what now makes not possible to render some old env's.
104 // Like fix, we found copy-paste already generated key from backups, to secrets.yml with correct key name
105 def wa29352ClassName = 'cluster.' + cname + '.infra.secrets_root_wa29352'
106 def wa29352File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_root_wa29352.yml"
107 def wa29352SecretsFile = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets.yml"
108 def _tempFile = '/tmp/wa29352_' + UUID.randomUUID().toString().take(8)
109 try {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400110 salt.cmdRun(venvPepper, 'I@salt:master', "! grep -qi root_private_key: ${wa29352SecretsFile}", true, null, false)
azvyagintsev745a6e52019-04-18 13:19:39 +0300111 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29352File}", true, null, false)
112 }
113 catch (Exception ex) {
Denis Egorenkodfa35422019-10-07 12:46:14 +0400114 common.infoMsg('Work-around for PROD-29352 already applied, nothing todo')
azvyagintsev745a6e52019-04-18 13:19:39 +0300115 return
116 }
117 def rKeysDict = [
118 'parameters': [
119 '_param': [
120 'root_private_key': salt.getPillar(venvPepper, 'I@salt:master', '_param:root_private_key').get('return')[0].values()[0].trim(),
121 'root_public_key' : '',
122 ]
123 ]
124 ]
125 // save root key,and generate public one from it
126 writeFile file: _tempFile, text: rKeysDict['parameters']['_param']['root_private_key'].toString().trim()
127 sh('chmod 0600 ' + _tempFile)
128 rKeysDict['parameters']['_param']['root_public_key'] = sh(script: "ssh-keygen -q -y -f ${_tempFile}", returnStdout: true).trim()
129 sh('rm -fv ' + _tempFile)
130 writeYaml file: _tempFile, data: rKeysDict
131 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
132 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29352File}", false, null, false)
133 common.infoMsg("Add $wa29352ClassName class into secrets.yml")
134
135 // Add 'classes:' directive
136 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
137 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
138
139 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
140 "grep -q '${wa29352ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29352ClassName' infra/secrets.yml")
azvyagintsev745a6e52019-04-18 13:19:39 +0300141 sh('rm -fv ' + _tempFile)
Denis Egorenkodfa35422019-10-07 12:46:14 +0400142 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " +
143 "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()}' ")
144 common.infoMsg('Work-around for PROD-29352 successfully applied')
azvyagintsev745a6e52019-04-18 13:19:39 +0300145}
146
azvyagintsevbc359d42019-04-10 19:53:22 +0300147def wa29155(ArrayList saltMinions, String cname) {
148 // WA for PROD-29155. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/
149 // CHeck for existence cmp nodes, and try to render it. Is failed, apply ssh-key wa
azvyagintsevbc359d42019-04-10 19:53:22 +0300150 def patched = false
151 def wa29155ClassName = 'cluster.' + cname + '.infra.secrets_nova_wa29155'
152 def wa29155File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_nova_wa29155.yml"
153
154 try {
155 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29155File}", true, null, false)
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400156 def patch_required = false
157 for (String minion in saltMinions) {
158 def nova_key = salt.getPillar(venvPepper, minion, '_param:nova_compute_ssh_private').get("return")[0].values()[0]
159 if (nova_key == '' || nova_key == 'null' || nova_key == null) {
160 patch_required = true
161 break // no exception, proceeding to apply the patch
162 }
163 }
164 if (!patch_required) {
165 error('No need to apply work-around for PROD-29155')
166 }
azvyagintsevbc359d42019-04-10 19:53:22 +0300167 }
168 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300169 return
170 }
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400171 salt.fullRefresh(venvPepper, 'I@salt:master')
azvyagintsevbc359d42019-04-10 19:53:22 +0300172 for (String minion in saltMinions) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300173 // First attempt, second will be performed in next validateReclassModel() stages
174 try {
azvyagintsev745a6e52019-04-18 13:19:39 +0300175 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 +0300176 } catch (Exception e) {
177 common.errorMsg(e.toString())
178 if (patched) {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400179 error("Node: ${minion} failed to render after reclass-system upgrade! WA29155 probably didn't help.")
azvyagintsevbc359d42019-04-10 19:53:22 +0300180 }
azvyagintsev745a6e52019-04-18 13:19:39 +0300181 common.warningMsg('Perform: Attempt to apply WA for PROD-29155\n' +
182 'See https://gerrit.mcp.mirantis.com/#/c/37932/ for more info')
azvyagintsevbc359d42019-04-10 19:53:22 +0300183 common.warningMsg('WA-PROD-29155 Generating new ssh key at master node')
184 def _tempFile = "/tmp/nova_wa29155_" + UUID.randomUUID().toString().take(8)
185 common.infoMsg('Perform: generation NEW ssh-private key for nova-compute')
186 salt.cmdRun(venvPepper, 'I@salt:master', "ssh-keygen -f ${_tempFile} -N '' -q")
187 def _pub_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}.pub").get('return')[0].values()[0].trim()
188 def _priv_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}").get('return')[0].values()[0].trim()
189 salt.cmdRun(venvPepper, 'I@salt:master', "rm -fv ${_tempFile}", false, null, false)
190 def novaKeysDict = [
191 "parameters": [
192 "_param": [
193 "nova_compute_ssh_private": _priv_k,
194 "nova_compute_ssh_public" : _pub_k
195 ]
196 ]
197 ]
azvyagintsev745a6e52019-04-18 13:19:39 +0300198 writeYaml file: _tempFile, data: novaKeysDict
azvyagintsevbc359d42019-04-10 19:53:22 +0300199 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
200 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29155File}", false, null, false)
201 common.infoMsg("Add $wa29155ClassName class into secrets.yml")
202
203 // Add 'classes:' directive
204 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
205 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
206
207 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
208 "grep -q '${wa29155ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29155ClassName' infra/secrets.yml")
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400209 salt.fullRefresh(venvPepper, 'I@salt:master')
Ivan Berezovskiyc4dc5012020-03-19 14:03:43 +0400210 salt.runSaltProcessStep(venvPepper, saltMinions, 'saltutil.refresh_pillar', [], null, true, 60)
azvyagintsevbc359d42019-04-10 19:53:22 +0300211 patched = true
212 }
213 }
214 if (patched) {
215 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " +
216 "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()}' ")
217 common.infoMsg('Work-around for PROD-29155 successfully applied')
218 }
219
220}
221
Ivan Berezovskiy5b62e9c2020-01-24 17:52:26 +0400222def wa32284(String cluster_name) {
Denis Egorenko1b11d232019-07-29 17:44:46 +0400223 def clientGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:enabled").get("return")[0].values()[0]
224 def pkiGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:volumes:salt_pki").get("return")[0].values()[0]
225 def nginxEnabledAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0]
226 if (nginxEnabledAtMaster.toString().toLowerCase() == 'true' && clientGluster.toString().toLowerCase() == 'true' && pkiGluster) {
227 def nginxRequires = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:wait_for_service').get('return')[0].values()[0]
228 if (nginxRequires.isEmpty()) {
Ivan Berezovskiy5b62e9c2020-01-24 17:52:26 +0400229 def nginxRequiresClassName = "cluster.${cluster_name}.infra.config.nginx_requires_wa32284"
230 def nginxRequiresClassFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/infra/config/nginx_requires_wa32284.yml"
Denis Egorenko1b11d232019-07-29 17:44:46 +0400231 def nginxRequiresBlock = ['parameters': ['nginx': ['server': ['wait_for_service': ['srv-salt-pki.mount'] ] ] ] ]
232 def _tempFile = '/tmp/wa32284_' + UUID.randomUUID().toString().take(8)
233 writeYaml file: _tempFile , data: nginxRequiresBlock
234 def nginxRequiresBlockString = sh(script: "cat ${_tempFile}", returnStdout: true).trim()
Ivan Berezovskiy5b62e9c2020-01-24 17:52:26 +0400235 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && " +
Denis Egorenko1b11d232019-07-29 17:44:46 +0400236 "sed -i '/^parameters:/i - ${nginxRequiresClassName}' infra/config/init.yml")
237 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${nginxRequiresBlockString}' > ${nginxRequiresClassFile}", false, null, false)
Ivan Berezovskiy5b62e9c2020-01-24 17:52:26 +0400238 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 +0400239 }
240 }
241}
242
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400243def wa32182(String cluster_name) {
Hanna Arhipovad5eec4c2019-09-06 17:55:40 +0300244 if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) {
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400245 def clusterModelPath = "/srv/salt/reclass/classes/cluster/${cluster_name}"
246 def fixFile = "${clusterModelPath}/opencontrail/common_wa32182.yml"
247 def usualFile = "${clusterModelPath}/opencontrail/common.yml"
248 def fixFileContent = "classes:\n- system.opencontrail.common\n"
249 salt.cmdRun(venvPepper, 'I@salt:master', "test -f ${fixFile} -o -f ${usualFile} || echo '${fixFileContent}' > ${fixFile}")
250 def contrailFiles = ['opencontrail/analytics.yml', 'opencontrail/control.yml', 'openstack/compute/init.yml']
251 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
252 contrailFiles.add('kubernetes/compute.yml')
253 }
Ivan Berezovskiy9f6330b2020-02-05 21:18:17 +0400254 for (String contrailFile in contrailFiles) {
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400255 contrailFile = "${clusterModelPath}/${contrailFile}"
256 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()
257 if (containsFix) {
258 continue
259 } else {
260 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 +0400261 "echo '- cluster.${cluster_name}.opencontrail.common_wa32182' >> ${contrailFile}")
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400262 }
263 }
Ivan Berezovskiy9f6330b2020-02-05 21:18:17 +0400264 salt.cmdRun(venvPepper, 'I@salt:master', "test -f ${fixFile} && cd ${clusterModelPath} && git status && git add ${fixFile} || true")
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400265 }
266}
267
Denis Egorenkoba631332019-10-25 13:13:39 +0400268def wa33867(String cluster_name) {
269 if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) {
270 def contrailControlFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/opencontrail/control.yml"
271 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()
272 if (line == "- cluster.${cluster_name}.infra") {
273 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra\$/d' ${contrailControlFile}")
274 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra.backup.client_zookeeper\$/i - cluster.${cluster_name}.infra' ${contrailControlFile}")
275 }
276 }
277}
278
Denis Egorenkoe312cc92019-10-18 17:06:11 +0400279def wa33771(String cluster_name) {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400280 if (salt.getMinions(venvPepper, 'I@_param:openstack_node_role and I@apache:server')) {
281 def octaviaEnabled = salt.getMinions(venvPepper, 'I@octavia:api:enabled')
282 def octaviaWSGI = salt.getMinions(venvPepper, 'I@apache:server:site:octavia_api')
283 if (octaviaEnabled && !octaviaWSGI) {
284 def openstackControl = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/control.yml"
285 def octaviaFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/octavia_wa33771.yml"
286 def octaviaContext = [
287 'classes' : ['system.apache.server.site.octavia'],
288 'parameters': [
289 '_param': ['apache_octavia_api_address': '${_param:cluster_local_address}'],
290 ]
Denis Egorenkoe312cc92019-10-18 17:06:11 +0400291 ]
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400292 def openstackHTTPSEnabled = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_internal_protocol").get("return")[0].values()[0]
293 if (openstackHTTPSEnabled == 'https') {
294 octaviaContext['parameters'] << ['apache': ['server': ['site': ['apache_proxy_openstack_api_octavia': ['enabled': false]]]]]
295 }
296 def _tempFile = '/tmp/wa33771' + UUID.randomUUID().toString().take(8)
297 writeYaml file: _tempFile, data: octaviaContext
298 def octaviaFileContent = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
299 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.octavia_wa33771' ${openstackControl}")
300 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${octaviaFileContent}' | base64 -d > ${octaviaFile}", false, null, false)
301 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 +0400302 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400303 } else {
304 common.warningMsg("Apache server is not defined on controller nodes. Skipping Octavia WSGI workaround");
Denis Egorenkoe312cc92019-10-18 17:06:11 +0400305 }
306}
307
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400308def wa33930_33931(String cluster_name) {
309 def openstackControlFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/control.yml"
310 def fixName = 'clients_common_wa33930_33931'
311 def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/${fixName}.yml"
312 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()
313 if (! containsFix) {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400314 def fixContext = [ 'classes': [ ] ]
315 def novaControllerNodes = salt.getMinions(venvPepper, 'I@nova:controller')
316 for (novaController in novaControllerNodes) {
317 def novaClientPillar = salt.getPillar(venvPepper, novaController, "nova:client").get("return")[0].values()[0]
318 if (novaClientPillar == '' || novaClientPillar == 'null' || novaClientPillar == null) {
319 fixContext['classes'] << 'service.nova.client'
320 break
321 }
322 }
323 def glanceServerNodes = salt.getMinions(venvPepper, 'I@glance:server')
324 for (glanceServer in glanceServerNodes) {
325 def glanceClientPillar = salt.getPillar(venvPepper, glanceServer, "glance:client").get("return")[0].values()[0]
326 if (glanceClientPillar == '' || glanceClientPillar == 'null' || glanceClientPillar == null) {
327 fixContext['classes'] << 'service.glance.client'
328 break
329 }
330 }
331 def neutronServerNodes = salt.getMinions(venvPepper, 'I@neutron:server')
332 for (neutronServer in neutronServerNodes) {
333 def neutronServerPillar = salt.getPillar(venvPepper, neutronServer, "neutron:client").get("return")[0].values()[0]
334 if (neutronServerPillar == '' || neutronServerPillar == 'null' || neutronServerPillar == null) {
335 fixContext['classes'] << 'service.neutron.client'
336 break
337 }
338 }
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400339 if (salt.getMinions(venvPepper, 'I@manila:api:enabled')) {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400340 def manilaApiNodes = salt.getMinions(venvPepper, 'I@manila:api')
341 for (manilaNode in manilaApiNodes) {
342 def manilaNodePillar = salt.getPillar(venvPepper, manilaNode, "manila:client").get("return")[0].values()[0]
343 if (manilaNodePillar == '' || manilaNodePillar == 'null' || manilaNodePillar == null) {
344 fixContext['classes'] << 'service.manila.client'
345 break
346 }
347 }
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400348 }
349 if (salt.getMinions(venvPepper, 'I@ironic:api:enabled')) {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400350 def ironicApiNodes = salt.getMinions(venvPepper, 'I@ironic:api')
351 for (ironicNode in ironicApiNodes) {
352 def ironicNodePillar = salt.getPillar(venvPepper, ironicNode, "ironic:client").get("return")[0].values()[0]
353 if (ironicNodePillar == '' || ironicNodePillar == 'null' || ironicNodePillar == null) {
354 fixContext['classes'] << 'service.ironic.client'
355 break
356 }
357 }
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400358 }
359 if (salt.getMinions(venvPepper, 'I@gnocchi:server:enabled')) {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400360 def gnocchiServerNodes = salt.getMinions(venvPepper, 'I@gnocchi:server')
361 for (gnocchiNode in gnocchiServerNodes) {
362 def gnocchiNodePillar = salt.getPillar(venvPepper, gnocchiNode, "gnocchi:client").get("return")[0].values()[0]
363 if (gnocchiNodePillar == '' || gnocchiNodePillar == 'null' || gnocchiNodePillar == null) {
364 fixContext['classes'] << 'service.gnocchi.client'
365 break
366 }
367 }
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400368 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400369
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400370 if (salt.getMinions(venvPepper, 'I@barbican:server:enabled')) {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400371 def barbicanServerNodes = salt.getMinions(venvPepper, 'I@barbican:server')
372 for (barbicanNode in barbicanServerNodes) {
373 def barbicanNodePillar = salt.getPillar(venvPepper, barbicanNode, "barbican:client").get("return")[0].values()[0]
374 if (barbicanNodePillar == '' || barbicanNodePillar == 'null' || barbicanNodePillar == null) {
375 fixContext['classes'] << 'service.barbican.client.single'
376 break
377 }
378 }
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400379 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400380 if (fixContext['classes'] != []) {
381 def _tempFile = '/tmp/wa33930_33931' + UUID.randomUUID().toString().take(8)
382 writeYaml file: _tempFile, data: fixContext
383 def fixFileContent = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
384 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${fixFileContent}' | base64 -d > ${fixFile}", false, null, false)
385 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.${fixName}' ${openstackControlFile}")
386 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${fixFile}")
387 }
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400388 }
389}
390
Denis Egorenko215acda2020-01-28 16:41:44 +0400391def wa34245(cluster_name) {
392 def infraInitFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/infra/init.yml"
393 def fixName = 'hosts_wa34245'
394 def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/infra/${fixName}.yml"
395 if (salt.testTarget(venvPepper, 'I@keystone:server')) {
396 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()
397 if (!fixApplied) {
398 def fixFileContent = []
399 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()
400 if (!containsFix) {
401 fixFileContent << '- system.linux.network.hosts.openstack'
402 }
403 if (salt.testTarget(venvPepper, 'I@gnocchi:server')) {
404 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()
405 if (!containsFix) {
406 fixFileContent << '- system.linux.network.hosts.openstack.telemetry'
407 }
408 }
409 if (salt.testTarget(venvPepper, 'I@manila:api')) {
410 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()
411 if (!containsFix) {
412 fixFileContent << '- system.linux.network.hosts.openstack.share'
413 }
414 }
415 if (salt.testTarget(venvPepper, 'I@barbican:server')) {
416 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()
417 if (!containsFix) {
418 fixFileContent << '- system.linux.network.hosts.openstack.kmn'
419 }
420 }
421 if (fixFileContent) {
422 salt.cmdRun(venvPepper, 'I@salt:master', "echo 'classes:\n${fixFileContent.join('\n')}' > ${fixFile}")
423 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.infra.${fixName}' ${infraInitFile}")
Ivan Berezovskiy5b62e9c2020-01-24 17:52:26 +0400424 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 +0400425 }
426 }
427 }
428}
429
Ivan Berezovskiy5b62e9c2020-01-24 17:52:26 +0400430def wa34528(String cluster_name) {
431 // Mysql users have to be defined on each Galera node
432 if(salt.getMinions(venvPepper, 'I@galera:master').isEmpty()) {
433 common.errorMsg('No Galera master found in cluster. Skipping')
434 return
435 }
436 def mysqlUsersMasterPillar = salt.getPillar(venvPepper, 'I@galera:master', 'mysql:server:database').get("return")[0].values()[0]
437 if (mysqlUsersMasterPillar == '' || mysqlUsersMasterPillar == 'null' || mysqlUsersMasterPillar == null) {
438 common.errorMsg('Pillar data is broken for Galera master node!')
439 input message: 'Do you want to ignore and continue without Galera pillar patch?'
440 return
441 }
442 def fileToPatch = salt.cmdRun(venvPepper, 'I@salt:master', "ls /srv/salt/reclass/classes/cluster/${cluster_name}/openstack/database/init.yml || " +
443 "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()
444 if (fileToPatch == 'File not found') {
445 common.errorMsg('Cluster model is old and cannot be patched for PROD-34528. Patching is possible for 2019.2.x cluster models only')
446 return
447 }
448 def patchRequired = false
449 def mysqlUsersSlavePillar = ''
450 def galeraSlaveNodes = salt.getMinions(venvPepper, 'I@galera:slave')
451 if (!galeraSlaveNodes.isEmpty()) {
452 for (galeraSlave in galeraSlaveNodes) {
453 mysqlUsersSlavePillar = salt.getPillar(venvPepper, galeraSlave, 'mysql:server:database').get("return")[0].values()[0]
454 if (mysqlUsersSlavePillar == '' || mysqlUsersSlavePillar == 'null' || mysqlUsersSlavePillar == null) {
455 common.errorMsg('Mysql users data is not defined for Galera slave nodes. Fixing...')
456 patchRequired = true
457 break
458 }
459 }
460 if (patchRequired) {
461 def fixFileContent = []
462 def fixName = 'db_wa34528'
463 def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/database/${fixName}.yml"
464 for (dbName in mysqlUsersMasterPillar.keySet()) {
465 def classIncluded = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- system\\.galera\\.server\\.database\\.${dbName}\$'" +
466 " /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()
467 if(classIncluded) {
468 fixFileContent << "- system.galera.server.database.${dbName}"
469 }
470 def sslClassIncluded = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- system\\.galera\\.server\\.database\\.x509\\.${dbName}\$'" +
471 " /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()
472 if(sslClassIncluded) {
473 fixFileContent << "- system.galera.server.database.x509.${dbName}"
474 }
475 }
476 if (fixFileContent) {
477 salt.cmdRun(venvPepper, 'I@salt:master', "echo 'classes:\n${fixFileContent.join('\n')}' > ${fixFile}")
478 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.database.${fixName}' ${fileToPatch}")
479 }
480 salt.fullRefresh(venvPepper, 'I@galera:slave')
481 // Verify
482 for (galeraSlave in galeraSlaveNodes) {
483 mysqlUsersSlavePillar = salt.getPillar(venvPepper, galeraSlave, 'mysql:server:database').get("return")[0].values()[0]
484 if (mysqlUsersSlavePillar == '' || mysqlUsersSlavePillar == 'null' || mysqlUsersSlavePillar == null || mysqlUsersSlavePillar.keySet() != mysqlUsersMasterPillar.keySet()) {
485 common.errorMsg("Mysql user data is different on master and slave node ${galeraSlave}.")
486 input message: 'Do you want to ignore and continue?'
487 }
488 }
489 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${fixFile}")
490 common.infoMsg('Galera slaves patching is done')
491 } else {
492 common.infoMsg('Galera slaves patching is not required')
493 }
494 }
495}
496
azvyagintsev6dac3802018-11-09 15:11:30 +0200497def archiveReclassInventory(filename) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300498 def _tmp_file = '/tmp/' + filename + UUID.randomUUID().toString().take(8)
499 // jenkins may fail at overheap. Compress data with gzip like WA
azvyagintsev745a6e52019-04-18 13:19:39 +0300500 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 +0300501 def _tmp = sh(script: "echo '$ret' > ${_tmp_file}", returnStdout: false)
502 sh(script: "cat ${_tmp_file} | base64 -d | gzip -d > $filename", returnStdout: false)
503 archiveArtifacts artifacts: filename
504 sh(script: "rm -v ${_tmp_file}|| true")
Richard Felkl0e80d892018-06-20 13:44:54 +0200505}
506
Denis Egorenkod13ad132018-12-17 16:56:02 +0400507def validateReclassModel(ArrayList saltMinions, String suffix) {
508 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300509 for (String minion in saltMinions) {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400510 common.infoMsg("Reclass model validation for minion ${minion}...")
azvyagintsev745a6e52019-04-18 13:19:39 +0300511 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 +0400512 writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString()
513 }
514 } catch (Exception e) {
515 common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.')
azvyagintsevbc359d42019-04-10 19:53:22 +0300516 error(e.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400517 }
518}
519
azvyagintsevbc359d42019-04-10 19:53:22 +0300520def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix = 'before', String newSuffix = 'after') {
521 for (String minion in saltMinions) {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400522 def fileName = "reclass-model-${minion}-diff.out"
523 sh "diff -u inventory-${minion}-${oldSuffix}.out inventory-${minion}-${newSuffix}.out > ${fileName} || true"
524 archiveArtifacts artifacts: "${fileName}"
525 }
526}
527
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300528def checkDebsums() {
529 // check for salt-formulas consistency
530 try {
531 try {
532 salt.cmdRun(venvPepper, 'I@salt:master', "salt -C 'I@salt:master' pkg.install force_yes=True pkgs=[debsums]")
533 }
534 catch (Exception ex) {
535 common.warningMsg('Unable to install package "debsums" at cfg01. Salt-formulas integrity check skipped')
536 }
537 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')
538 salt.cmdRun(venvPepper, 'I@salt:master', 'if [ -s "/root/debdsums_report" ]; then exit 1 ; fi')
539 }
540 catch (Exception ex) {
541 common.errorMsg(salt.cmdRun(venvPepper, 'I@salt:master', 'cat /root/debdsums_report ', true, null, false).get('return')[0].values()[0].trim())
542 common.errorMsg(ex.toString())
543 error('You have unexpected changes in formulas. All of them will be overwrited by update. Unable to continue in automatic way')
544 }
545}
546
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400547def checkCICDDocker() {
548 common.infoMsg('Perform: Checking if Docker containers are up')
549 try {
550 common.retry(10, 30) {
551 salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'")
552 }
553 }
554 catch (Exception ex) {
555 error("Docker containers for CI/CD services are having troubles with starting.")
556 }
557}
558
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400559if (common.validInputParam('PIPELINE_TIMEOUT')) {
560 try {
561 pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger()
azvyagintsevbc359d42019-04-10 19:53:22 +0300562 } catch (Exception e) {
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400563 common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger")
564 }
Martin Polreich965c9032018-08-09 16:33:57 +0200565}
566
567timeout(time: pipelineTimeout, unit: 'HOURS') {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300568 node('python') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100569 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300570 def inventoryBeforeFilename = "reclass-inventory-before.out"
571 def inventoryAfterFilename = "reclass-inventory-after.out"
Richard Felkl0e80d892018-06-20 13:44:54 +0200572 workspace = common.getWorkspace()
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200573 targetMcpVersion = null
574 if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) {
575 error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable')
azvyagintsev6dac3802018-11-09 15:11:30 +0200576 }
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200577 // bw comp. for 2018.X => 2018.11 release
azvyagintsevbc359d42019-04-10 19:53:22 +0300578 if (common.validInputParam('MCP_VERSION')) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200579 targetMcpVersion = env.MCP_VERSION
580 common.warningMsg("targetMcpVersion has been changed to:${targetMcpVersion}, which was taken from deprecated pipeline viriable:MCP_VERSION")
azvyagintsevbc359d42019-04-10 19:53:22 +0300581 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200582 targetMcpVersion = env.TARGET_MCP_VERSION
583 }
584 // end bw comp. for 2018.X => 2018.11 release
Denis Egorenkod13ad132018-12-17 16:56:02 +0400585 def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC')
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400586 if (targetMcpVersion in ['nightly', 'testing']) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200587 gitTargetMcpVersion = 'master'
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400588 } else if (targetMcpVersion == 'proposed') {
589 gitTargetMcpVersion = 'proposed'
Denis Egorenko284690e2018-12-25 15:55:12 +0400590 } else if (!gitTargetMcpVersion) {
591 // backward compatibility for 2018.11.0
592 gitTargetMcpVersion = "release/${targetMcpVersion}"
azvyagintsev6dac3802018-11-09 15:11:30 +0200593 }
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400594 common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}")
Denis Egorenko284690e2018-12-25 15:55:12 +0400595 def upgradeSaltStack = ''
596 def updateClusterModel = ''
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400597 def applyWorkarounds = true
Denis Egorenko284690e2018-12-25 15:55:12 +0400598 def updatePipelines = ''
599 def updateLocalRepos = ''
600 def reclassSystemBranch = ''
Denis Egorenko517e06c2019-03-29 13:24:15 +0400601 def reclassSystemBranchDefault = gitTargetMcpVersion
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400602 if (gitTargetMcpVersion ==~ /^\d\d\d\d\.\d\d?\.\d+$/) {
603 reclassSystemBranchDefault = "tags/${gitTargetMcpVersion}"
604 } else if (gitTargetMcpVersion != 'proposed') {
Denis Egorenko517e06c2019-03-29 13:24:15 +0400605 reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}"
606 }
Hanna Arhipovad5eec4c2019-09-06 17:55:40 +0300607 def driveTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS')
608 if (driveTrainParamsYaml) {
609 def driveTrainParams = readYaml text: driveTrainParamsYaml
610 saltMastURL = driveTrainParams.get('SALT_MASTER_URL')
611 saltMastCreds = driveTrainParams.get('SALT_MASTER_CREDENTIALS')
612 upgradeSaltStack = driveTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean()
613 updateClusterModel = driveTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean()
614 updatePipelines = driveTrainParams.get('UPDATE_PIPELINES', false).toBoolean()
615 updateLocalRepos = driveTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean()
616 reclassSystemBranch = driveTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault)
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400617 batchSize = driveTrainParams.get('BATCH_SIZE', '')
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400618 if (driveTrainParams.get('OS_DIST_UPGRADE', false).toBoolean() == true) {
619 packageUpgradeMode = 'dist-upgrade'
620 } else if (driveTrainParams.get('OS_UPGRADE', false).toBoolean() == true) {
621 packageUpgradeMode = 'upgrade'
622 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400623 applyWorkarounds = driveTrainParams.get('APPLY_MODEL_WORKAROUNDS', true).toBoolean()
Denis Egorenko284690e2018-12-25 15:55:12 +0400624 } else {
625 // backward compatibility for 2018.11.0
626 saltMastURL = env.getProperty('SALT_MASTER_URL')
627 saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS')
Denis Egorenkoe5f39142018-12-28 12:30:48 +0400628 upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean()
629 updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean()
630 updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean()
631 updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean()
Denis Egorenko517e06c2019-03-29 13:24:15 +0400632 reclassSystemBranch = reclassSystemBranchDefault
Denis Egorenko284690e2018-12-25 15:55:12 +0400633 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400634 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400635 def minions = salt.getMinions(venvPepper, '*')
Denis Egorenkofbcee412019-04-19 15:05:18 +0400636 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
637 if (cluster_name == '' || cluster_name == 'null' || cluster_name == null) {
638 error('Pillar data is broken for Salt master node! Please check it manually and re-run pipeline.')
639 }
Hanna Arhipovad5eec4c2019-09-06 17:55:40 +0300640 if (!batchSize) {
Denis Egorenko7b098c32019-12-19 16:45:25 +0400641 // if no batch size provided get current worker threads and set batch size to 2/3 of it to avoid
642 // 'SaltReqTimeoutError: Message timed out' issue on Salt targets for large amount of nodes
643 // do not use toDouble/Double as it requires additional approved method
644 def workerThreads = getWorkerThreads(venvPepper).toInteger()
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400645 batchSize = (workerThreads * 2 / 3).toString().tokenize('.')[0]
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400646 }
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400647 def computeMinions = salt.getMinions(venvPepper, 'I@nova:compute')
Ivan Berezovskiyc4dc5012020-03-19 14:03:43 +0400648 def allMinions = salt.getMinions(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400649
azvyagintsevbc359d42019-04-10 19:53:22 +0300650 stage('Update Reclass and Salt-Formulas') {
651 common.infoMsg('Perform: Full salt sync')
Ivan Berezovskiyc4dc5012020-03-19 14:03:43 +0400652 fullRefreshOneByOne(venvPepper, allMinions)
Oleksii Molchanov5b7fceb2020-03-13 13:28:10 +0200653
Roman Lubianyi1ee62562021-11-08 15:05:45 +0200654 upgradeChecks.check_34406(salt, venvPepper, cluster_name, true)
655 upgradeChecks.check_34645(salt, venvPepper, cluster_name, true)
656 upgradeChecks.check_35705(salt, venvPepper, cluster_name, true)
657 upgradeChecks.check_35884(salt, venvPepper, cluster_name, true)
658 upgradeChecks.check_36461(salt, venvPepper, cluster_name, true)
659 upgradeChecks.check_36461_2(salt, venvPepper, cluster_name, true)
Oleksii Molchanov5b7fceb2020-03-13 13:28:10 +0200660
azvyagintsevbc359d42019-04-10 19:53:22 +0300661 common.infoMsg('Perform: Validate reclass medata before processing')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400662 validateReclassModel(minions, 'before')
663
azvyagintsev745a6e52019-04-18 13:19:39 +0300664 common.infoMsg('Perform: archiveReclassInventory before upgrade')
665 archiveReclassInventory(inventoryBeforeFilename)
666
azvyagintsev6dac3802018-11-09 15:11:30 +0200667 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300668 salt.cmdRun(venvPepper, 'I@salt:master', 'cd /srv/salt/reclass/ && git status && git diff-index --quiet HEAD --')
Richard Felkl970e0082018-06-12 18:00:51 +0200669 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200670 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300671 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 +0200672 }
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300673 checkDebsums()
Denis Egorenkod13ad132018-12-17 16:56:02 +0400674 if (updateClusterModel) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200675 common.infoMsg('Perform: UPDATE_CLUSTER_MODEL')
Sergey382581a2018-10-25 12:22:26 +0400676 def dateTime = common.getDatetime()
Ivan Berezovskiycfa1b2f2020-01-17 13:55:18 +0400677 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git fetch")
Sergey382581a2018-10-25 12:22:26 +0400678 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400679 "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 +0200680 // Do the same, for deprecated variable-duplicate
681 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400682 "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 +0400683 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400684 "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 +0400685 // Set new k8s param
686 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
687 "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 +0400688 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
689 "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'")
690 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko301cc8a2019-02-13 13:49:13 +0400691 "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 +0400692 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Vladimir Khlyunev8efa75a2021-07-13 14:44:01 +0400693 "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 +0400694 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsevbc359d42019-04-10 19:53:22 +0300695 "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 +0400696
Denis Egorenko6f07b592019-09-16 16:41:26 +0400697 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")
698 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name/infra && sed -i '/maas_region_main_archive/d' maas.yml")
699
Denis Egorenko21c78be2019-07-10 19:47:39 +0400700 // Switch Jenkins/Gerrit to use LDAP SSL/TLS
701 def gerritldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
702 "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()
703 if (gerritldapURI.startsWith('ldap://')) {
704 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
705 "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
706 } else if (! gerritldapURI.startsWith('ldaps://')) {
707 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
708 "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'")
709 }
710 def jenkinsldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
711 "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()
712 if (jenkinsldapURI.startsWith('ldap://')) {
713 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
714 "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
715 } else if (! jenkinsldapURI.startsWith('ldaps://')) {
716 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
717 "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'")
718 }
719
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400720 if (applyWorkarounds) {
721 wa32284(cluster_name)
722 wa34245(cluster_name)
723 }
Denis Egorenko1b11d232019-07-29 17:44:46 +0400724
Denis Egorenkod13ad132018-12-17 16:56:02 +0400725 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}")
Sergey Kolekonov5dfbf7a2019-01-23 16:47:43 +0400726 // Add kubernetes-extra repo
727 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
Sergey Kolekonov3fde8b12019-04-11 16:33:54 +0400728 // docker-engine conflicts with the recent containerd versions, so it's removed during upgrade. Thus update source engine
729 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
730 "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 +0400731 common.infoMsg("Add kubernetes-extra repo")
732 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
733 "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")
734 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
735 "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")
736 }
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400737 // Add all update repositories
738 def repoIncludeBase = '- system.linux.system.repo.mcp.apt_mirantis.'
Denis Egorenko6f07b592019-09-16 16:41:26 +0400739 def updateRepoList = ['cassandra', 'ceph', 'contrail', 'docker', 'elastic', 'extra', 'openstack', 'maas', 'percona', 'salt-formulas', 'saltstack', 'ubuntu']
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400740 updateRepoList.each { repo ->
741 def repoNameUpdateInclude = "${repoIncludeBase}update.${repo}"
742 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')
743 filesWithInclude.each { file ->
744 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()
745 if (updateRepoIncludeExist == 'not_found') {
746 // Include needs to be added
747 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsevbc359d42019-04-10 19:53:22 +0300748 "sed -i 's/\\( *\\)${repoIncludeBase}${repo}\$/&\\n\\1${repoNameUpdateInclude}/g' ${file}")
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400749 common.infoMsg("Update repo for ${repo} is added to ${file}")
750 }
751 }
752 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400753 if (applyWorkarounds) {
754 wa32182(cluster_name)
755 wa33771(cluster_name)
756 wa33867(cluster_name)
757 wa33930_33931(cluster_name)
758 wa34528(cluster_name)
759 }
Sergey382581a2018-10-25 12:22:26 +0400760 // Add new defaults
761 common.infoMsg("Add new defaults")
Denis Egorenkod13ad132018-12-17 16:56:02 +0400762 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 +0400763 "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 +0400764 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 +0400765 "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 +0400766 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300767 "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 +0400768 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300769 "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 +0400770 common.infoMsg("The following changes were made to the cluster model and will be commited. " +
azvyagintsev6dac3802018-11-09 15:11:30 +0200771 "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 +0400772 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff")
773 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " +
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200774 "git add -u && git commit --allow-empty -m 'Cluster model update to the release $targetMcpVersion on $dateTime'")
Sergey382581a2018-10-25 12:22:26 +0400775 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400776 try {
777 common.infoMsg('Perform: UPDATE Salt Formulas')
Ivan Berezovskiyc4dc5012020-03-19 14:03:43 +0400778 fullRefreshOneByOne(venvPepper, allMinions)
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400779 salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400780 def saltEnv = salt.getPillar(venvPepper, 'I@salt:master', "_param:salt_master_base_environment").get("return")[0].values()[0]
azvyagintsevbc359d42019-04-10 19:53:22 +0300781 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas", 'salt.master.env'])
Ivan Berezovskiyc4dc5012020-03-19 14:03:43 +0400782 fullRefreshOneByOne(venvPepper, allMinions)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400783 } catch (Exception updateErr) {
784 common.warningMsg(updateErr)
785 common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
786 input message: 'Continue anyway?'
787 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400788 if (applyWorkarounds) {
789 wa29352(cluster_name)
790 wa29155(computeMinions, cluster_name)
791 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400792
793 try {
794 common.infoMsg('Perform: UPDATE Reclass package')
795 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"])
796 } catch (Exception updateErr) {
797 common.warningMsg(updateErr)
798 common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
799 input message: 'Continue anyway?'
800 }
801
802 salt.fullRefresh(venvPepper, 'I@salt:master')
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400803 salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true, true, null, false, 60, 2)
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400804 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && " +
805 "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 +0400806 try {
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400807 salt.enforceState(venvPepper, 'I@salt:master', 'reclass', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400808 }
809 catch (Exception ex) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300810 common.errorMsg(ex.toString())
811 error('Reclass fails rendering. Pay attention to your cluster model.')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400812 }
813
Ivan Berezovskiyc4dc5012020-03-19 14:03:43 +0400814 fullRefreshOneByOne(venvPepper, allMinions)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400815 try {
816 salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top")
817 }
818 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300819
820 error('Reclass fails rendering. Pay attention to your cluster model.' +
821 'ErrorMessage:' + ex.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400822 }
823
azvyagintsevbc359d42019-04-10 19:53:22 +0300824 common.infoMsg('Perform: archiveReclassInventory AFTER upgrade')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400825 archiveReclassInventory(inventoryAfterFilename)
826
827 sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true"
828 archiveArtifacts artifacts: "reclass-inventory-diff.out"
829
830 validateReclassModel(minions, 'after')
831 archiveReclassModelChanges(minions)
Jakub Josefa63f9862018-01-11 17:58:38 +0100832 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100833
Denis Egorenkod13ad132018-12-17 16:56:02 +0400834 if (updateLocalRepos) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200835 stage("Update local repos") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100836 common.infoMsg("Updating local repositories")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700837
Sergey1b81c062018-10-16 17:10:21 +0400838 def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700839 runningOnDocker = engine.get("return")[0].containsValue("docker")
840
841 if (runningOnDocker) {
842 common.infoMsg("Aptly is running as Docker container")
azvyagintsev6dac3802018-11-09 15:11:30 +0200843 } else {
Sam Stoelingaaab79702018-04-09 18:49:39 -0700844 common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands")
845 }
846
azvyagintsev6dac3802018-11-09 15:11:30 +0200847 if (runningOnDocker) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200848 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 +0200849 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200850 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 +0100851 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100852
Sergey1b81c062018-10-16 17:10:21 +0400853 salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100854
azvyagintsev6dac3802018-11-09 15:11:30 +0200855 if (runningOnDocker) {
Sergey1b81c062018-10-16 17:10:21 +0400856 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true)
857 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 +0200858 } else {
Sergey1b81c062018-10-16 17:10:21 +0400859 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true)
860 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 +0100861 }
Richard Felkl79d7df12018-01-05 16:40:11 +0100862
Sergey1b81c062018-10-16 17:10:21 +0400863 salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100864
Sergey1b81c062018-10-16 17:10:21 +0400865 salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100866
Sergey1b81c062018-10-16 17:10:21 +0400867 salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100868
Sergey1b81c062018-10-16 17:10:21 +0400869 salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100870 }
871 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100872
Vladimir Khlyunev20d63672021-06-18 13:43:08 +0400873 stage('Update Drivetrain: Part 1') {
Vladimir Khlyunev2dd5bfd2021-03-19 18:45:54 +0400874 salt.enforceState(venvPepper, 'I@linux:system', 'linux.system.repo', true, true, batchSize, false, 60, 2)
Oleksii Molchanov68eb72c2020-05-15 13:33:45 +0300875 salt.enforceState(venvPepper, '*', 'linux.system.package', true, true, batchSize, false, 60, 2)
876
Denis Egorenkod13ad132018-12-17 16:56:02 +0400877 if (upgradeSaltStack) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300878 updateSaltStack('I@salt:master', '["salt-master", "salt-common", "salt-api", "salt-minion"]')
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300879 updateSaltStack('I@salt:minion and not I@salt:master', '["salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200880 }
881
Denis Egorenkod13ad132018-12-17 16:56:02 +0400882 if (updatePipelines) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300883 common.infoMsg('Perform: UPDATE git repos')
884 triggerMirrorJob('git-mirror-downstream-mk-pipelines', reclassSystemBranch)
885 triggerMirrorJob('git-mirror-downstream-pipeline-library', reclassSystemBranch)
Richard Felkl970e0082018-06-12 18:00:51 +0200886 }
887
Denis Egorenko7a4cf032019-04-25 20:48:26 +0400888 // update minions certs
Denis Egorenkoaf3a2202019-04-26 15:13:16 +0400889 // call for `salt.minion.ca` state on related nodes to make sure
890 // mine was updated with required data after salt-minion/salt-master restart salt:minion:ca
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400891 salt.enforceState(venvPepper, 'I@salt:minion:ca', 'salt.minion.ca', true, true, batchSize, false, 60, 2)
892 salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion.cert', true, true, batchSize, false, 60, 2)
Denis Egorenko7a4cf032019-04-25 20:48:26 +0400893
Ann Kamyshnikovae8910112019-05-06 12:56:38 +0400894 // run `salt.minion` to refresh all minion configs (for example _keystone.conf)
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400895 salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion', true, true, batchSize, false, 60, 2)
azvyagintsevbc359d42019-04-10 19:53:22 +0300896 // Retry needed only for rare race-condition in user appearance
897 common.infoMsg('Perform: updating users and keys')
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400898 salt.enforceState(venvPepper, 'I@linux:system', 'linux.system.user', true, true, batchSize, false, 60, 2)
azvyagintsevbc359d42019-04-10 19:53:22 +0300899 common.infoMsg('Perform: updating openssh')
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400900 salt.enforceState(venvPepper, 'I@linux:system', 'openssh', true, true, batchSize, false, 60, 2)
Denis Egorenko65cf2a42019-01-15 11:58:12 +0400901
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300902 // apply salt API TLS if needed
903 def nginxAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0]
904 if (nginxAtMaster.toString().toLowerCase() == 'true') {
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400905 salt.enforceState(venvPepper, 'I@salt:master', 'nginx', true, true, null, false, 60, 2)
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300906 }
Ivan Berezovskiya766d432019-12-11 15:31:10 +0400907 }
908 }
909 catch (Throwable e) {
910 // If there was an error or exception thrown, the build failed
911 currentBuild.result = "FAILURE"
912 throw e
913 }
914 }
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400915 stage('Upgrade OS') {
916 if (packageUpgradeMode) {
Vladimir Khlyunev20d63672021-06-18 13:43:08 +0400917 def cidNodes = []
918 node('python') {
919 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
920 cidNodes = salt.getMinions(venvPepper, 'I@_param:drivetrain_role:cicd')
921 }
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400922 def debian = new com.mirantis.mk.Debian()
923 def statusFile = '/tmp/rebooted_during_upgrade'
924 for(cidNode in cidNodes) {
925 node('python') {
926 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
927 // cmd.run async to prevent connection close in case of slave shutdown, give 5 seconds to handle request response
928 salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${cidNode}' cmd.run 'sleep 5; touch ${statusFile}; salt-call service.stop docker' --async")
929 }
930 sleep(30)
931 node('python') {
932 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
933 debian.osUpgradeNode(venvPepper, cidNode, packageUpgradeMode, false, 60)
934 salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': cidNode, wait: 60, timeout: 10])
935 if (salt.runSaltProcessStep(venvPepper, cidNode, 'file.file_exists', [statusFile], null, true, 5)['return'][0].values()[0].toBoolean()) {
936 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
937 sleep(10)
938 }
939 checkCICDDocker()
940 }
941 }
942 } else {
943 common.infoMsg('Upgrade OS skipped...')
944 }
945 }
Vladimir Khlyunev20d63672021-06-18 13:43:08 +0400946
947 node('python') {
948 stage('Update Drivetrain: Part 2') {
949 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
950 // 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
951 def gerritGlusterPath = salt.getPillar(venvPepper, 'I@gerrit:client', 'glusterfs:client:volumes:gerrit:path').get('return')[0].values()[0]
952 def wrongPluginJarName = "${gerritGlusterPath}/plugins/project-download-commands.jar"
953 salt.cmdRun(venvPepper, 'I@gerrit:client', "test -f ${wrongPluginJarName} && rm ${wrongPluginJarName} || true")
954
955 salt.enforceStateWithTest(venvPepper, 'I@jenkins:client:security and not I@salt:master', 'jenkins.client.security', "", true, true, null, true, 60, 2)
956 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)
957 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")
958 }
959 }
960 // docker.client state may trigger change of jenkins master or jenkins slave services,
961 // so we need wait for slave to reconnect and continue pipeline
962 sleep(180)
963 node('python') {
964 stage('Update Drivetrain: Part 3') {
965 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
966 checkCICDDocker()
967
968 // update Nginx proxy settings for Jenkins/Gerrit if needed
969 if (salt.testTarget(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit')) {
970 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)
971 }
972 // Apply changes for HaProxy on CI/CD nodes
973 salt.enforceState(venvPepper, 'I@keepalived:cluster:instance:cicd_control_vip and I@haproxy:proxy', 'haproxy.proxy', true)
974 salt.upgradePackageAndRestartSaltMinion(venvPepper, 'I@jenkins:client and not I@salt:master', 'python-jenkins')
975 salt.cmdRun(venvPepper, "I@salt:master", "salt -C 'I@jenkins:client and not I@salt:master' state.sls jenkins.client --async")
976
977 common.warningMsg("Jenkins update started in background in order to handle plugin post-install issues.")
978 common.warningMsg("Please wait until it finished. Jenkins could be restarted during this procedure.")
979 common.warningMsg("You can monitor job progress by running 'salt-run jobs.active' on master node")
980 common.warningMsg("For ensuring that upgrade is done and there are no errors you can run the following command on salt master node")
981 common.warningMsg("salt-run jobs.lookup_jid %salt_job_id%")
982 common.warningMsg("Salt job ID could be found in the log above.")
983 }
984 }
Jakub Josef2c21c6c2018-02-08 18:51:42 +0100985}