blob: e903d959d3e69cfde55a298c7dacbf1db5cbf8f4 [file] [log] [blame]
Richard Felkl26cae4d2017-12-19 00:19:16 +01001/**
2 *
3 * Update Salt environment pipeline
4 *
5 * Expected parameters:
azvyagintsev6dac3802018-11-09 15:11:30 +02006 * TARGET_MCP_VERSION Version of MCP to upgrade to
Denis Egorenkod13ad132018-12-17 16:56:02 +04007 * GIT_REFSPEC Git repo ref to be used
8 * DRIVE_TRAIN_PARAMS Yaml, DriveTrain releated params:
9 * SALT_MASTER_URL Salt API server location
10 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
Denis Egorenko70002bc2019-08-19 19:41:27 +040011 * BATCH_SIZE Use batch sizing during upgrade for large envs
Denis Egorenkod13ad132018-12-17 16:56:02 +040012 * UPGRADE_SALTSTACK Upgrade SaltStack packages to new version.
13 * UPDATE_CLUSTER_MODEL Update MCP version parameter in cluster model
14 * UPDATE_PIPELINES Update pipeline repositories on Gerrit
15 * UPDATE_LOCAL_REPOS Update local repositories
Ivan Berezovskiycac04e42020-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 Berezovskiy24b0be02019-12-11 15:31:10 +040028def saltMastURL = ''
29def saltMastCreds = ''
Denis Egorenkobf390102020-01-24 19:47:05 +040030def packageUpgradeMode = ''
Ivan Berezovskiycac04e42020-02-17 17:08:47 +040031batchSize = ''
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010032
Ivan Berezovskiy224eb8e2020-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
Denis Egorenkoada83882019-06-11 14:03:40 +040041def triggerMirrorJob(String jobName, String reclassSystemBranch) {
Richard Felkl970e0082018-06-12 18:00:51 +020042 params = jenkinsUtils.getJobParameters(jobName)
Denis Egorenkoada83882019-06-11 14:03:40 +040043 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) {
Denis Egorenko0d0c65f2019-02-26 16:05:03 +040063 salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${target}' --async pkg.install force_yes=True pkgs='$pkgs'")
64 // 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
azvyagintsev6dac3802018-11-09 15:11:30 +020066 common.retry(20, 60) {
Richard Felkl0e80d892018-06-20 13:44:54 +020067 salt.minionsReachable(venvPepper, 'I@salt:master', '*')
68 def running = salt.runSaltProcessStep(venvPepper, target, 'saltutil.running', [], null, true, 5)
azvyagintsev6dac3802018-11-09 15:11:30 +020069 for (value in running.get("return")[0].values()) {
70 if (value != []) {
Richard Felkl0e80d892018-06-20 13:44:54 +020071 throw new Exception("Not all salt-minions are ready for execution")
72 }
73 }
74 }
75
azvyagintsevf3bf77a2018-11-15 19:30:04 +020076 def saltVersion = salt.getPillar(venvPepper, 'I@salt:master', '_param:salt_version').get('return')[0].values()[0]
Richard Felklf23257e2018-08-06 09:24:23 +020077 def saltMinionVersions = salt.cmdRun(venvPepper, target, "apt-cache policy salt-common | awk '/Installed/ && /$saltVersion/'").get("return")
Richard Felkl0e80d892018-06-20 13:44:54 +020078 def saltMinionVersion = ""
79
azvyagintsev6dac3802018-11-09 15:11:30 +020080 for (minion in saltMinionVersions[0].keySet()) {
81 saltMinionVersion = saltMinionVersions[0].get(minion).replace("Salt command execution success", "").trim()
82 if (saltMinionVersion == "") {
Richard Felkl0e80d892018-06-20 13:44:54 +020083 error("Installed version of Salt on $minion doesn't match specified version in the model.")
84 }
85 }
86}
87
Denis Egorenko6f1c8732019-09-24 14:55:50 +040088def getWorkerThreads(saltId) {
89 if (env.getEnvironment().containsKey('SALT_MASTER_OPT_WORKER_THREADS')) {
90 return env['SALT_MASTER_OPT_WORKER_THREADS'].toString()
91 }
92 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)
93 return threads['return'][0].values()[0].replaceAll('Salt command execution success','').trim()
94}
95
Ivan Berezovskiy304705c2019-12-03 18:49:09 +040096def wa29352(String cname) {
Denis Egorenkoada83882019-06-11 14:03:40 +040097 // WA for PROD-29352. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/12/openssh/client/root.yml
98 // Default soft-param has been removed, what now makes not possible to render some old env's.
99 // Like fix, we found copy-paste already generated key from backups, to secrets.yml with correct key name
100 def wa29352ClassName = 'cluster.' + cname + '.infra.secrets_root_wa29352'
101 def wa29352File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_root_wa29352.yml"
102 def wa29352SecretsFile = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets.yml"
103 def _tempFile = '/tmp/wa29352_' + UUID.randomUUID().toString().take(8)
104 try {
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400105 salt.cmdRun(venvPepper, 'I@salt:master', "! grep -qi root_private_key: ${wa29352SecretsFile}", true, null, false)
Denis Egorenkoada83882019-06-11 14:03:40 +0400106 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29352File}", true, null, false)
107 }
108 catch (Exception ex) {
Denis Egorenkoe0c88432019-10-07 12:46:14 +0400109 common.infoMsg('Work-around for PROD-29352 already applied, nothing todo')
Denis Egorenkoada83882019-06-11 14:03:40 +0400110 return
111 }
112 def rKeysDict = [
113 'parameters': [
114 '_param': [
115 'root_private_key': salt.getPillar(venvPepper, 'I@salt:master', '_param:root_private_key').get('return')[0].values()[0].trim(),
116 'root_public_key' : '',
117 ]
118 ]
119 ]
120 // save root key,and generate public one from it
121 writeFile file: _tempFile, text: rKeysDict['parameters']['_param']['root_private_key'].toString().trim()
122 sh('chmod 0600 ' + _tempFile)
123 rKeysDict['parameters']['_param']['root_public_key'] = sh(script: "ssh-keygen -q -y -f ${_tempFile}", returnStdout: true).trim()
124 sh('rm -fv ' + _tempFile)
125 writeYaml file: _tempFile, data: rKeysDict
126 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
127 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29352File}", false, null, false)
128 common.infoMsg("Add $wa29352ClassName class into secrets.yml")
129
130 // Add 'classes:' directive
131 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
132 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
133
134 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
135 "grep -q '${wa29352ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29352ClassName' infra/secrets.yml")
Denis Egorenkoada83882019-06-11 14:03:40 +0400136 sh('rm -fv ' + _tempFile)
Denis Egorenkoe0c88432019-10-07 12:46:14 +0400137 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " +
138 "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()}' ")
139 common.infoMsg('Work-around for PROD-29352 successfully applied')
Denis Egorenkoada83882019-06-11 14:03:40 +0400140}
141
142def wa29155(ArrayList saltMinions, String cname) {
143 // WA for PROD-29155. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/
144 // CHeck for existence cmp nodes, and try to render it. Is failed, apply ssh-key wa
Denis Egorenkoada83882019-06-11 14:03:40 +0400145 def patched = false
146 def wa29155ClassName = 'cluster.' + cname + '.infra.secrets_nova_wa29155'
147 def wa29155File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_nova_wa29155.yml"
148
149 try {
150 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29155File}", true, null, false)
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400151 def patch_required = false
152 for (String minion in saltMinions) {
153 def nova_key = salt.getPillar(venvPepper, minion, '_param:nova_compute_ssh_private').get("return")[0].values()[0]
154 if (nova_key == '' || nova_key == 'null' || nova_key == null) {
155 patch_required = true
156 break // no exception, proceeding to apply the patch
157 }
158 }
159 if (!patch_required) {
160 error('No need to apply work-around for PROD-29155')
161 }
Denis Egorenkoada83882019-06-11 14:03:40 +0400162 }
163 catch (Exception ex) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400164 return
165 }
Denis Egorenkoe983d452019-08-23 14:29:34 +0400166 salt.fullRefresh(venvPepper, 'I@salt:master')
Denis Egorenkoada83882019-06-11 14:03:40 +0400167 for (String minion in saltMinions) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400168 // First attempt, second will be performed in next validateReclassModel() stages
169 try {
170 salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
171 } catch (Exception e) {
172 common.errorMsg(e.toString())
173 if (patched) {
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400174 error("Node: ${minion} failed to render after reclass-system upgrade! WA29155 probably didn't help.")
Denis Egorenkoada83882019-06-11 14:03:40 +0400175 }
176 common.warningMsg('Perform: Attempt to apply WA for PROD-29155\n' +
177 'See https://gerrit.mcp.mirantis.com/#/c/37932/ for more info')
178 common.warningMsg('WA-PROD-29155 Generating new ssh key at master node')
179 def _tempFile = "/tmp/nova_wa29155_" + UUID.randomUUID().toString().take(8)
180 common.infoMsg('Perform: generation NEW ssh-private key for nova-compute')
181 salt.cmdRun(venvPepper, 'I@salt:master', "ssh-keygen -f ${_tempFile} -N '' -q")
182 def _pub_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}.pub").get('return')[0].values()[0].trim()
183 def _priv_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}").get('return')[0].values()[0].trim()
184 salt.cmdRun(venvPepper, 'I@salt:master', "rm -fv ${_tempFile}", false, null, false)
185 def novaKeysDict = [
186 "parameters": [
187 "_param": [
188 "nova_compute_ssh_private": _priv_k,
189 "nova_compute_ssh_public" : _pub_k
190 ]
191 ]
192 ]
193 writeYaml file: _tempFile, data: novaKeysDict
194 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
195 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29155File}", false, null, false)
196 common.infoMsg("Add $wa29155ClassName class into secrets.yml")
197
198 // Add 'classes:' directive
199 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
200 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
201
202 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
203 "grep -q '${wa29155ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29155ClassName' infra/secrets.yml")
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400204 salt.fullRefresh(venvPepper, 'I@salt:master')
Ivan Berezovskiy224eb8e2020-03-19 14:03:43 +0400205 salt.runSaltProcessStep(venvPepper, saltMinions, 'saltutil.refresh_pillar', [], null, true, 60)
Denis Egorenkoada83882019-06-11 14:03:40 +0400206 patched = true
207 }
208 }
209 if (patched) {
210 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " +
211 "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()}' ")
212 common.infoMsg('Work-around for PROD-29155 successfully applied')
213 }
214
215}
216
Ivan Berezovskiy8699f3f2020-01-24 17:52:26 +0400217def wa32284(String cluster_name) {
Denis Egorenkobae9dc72019-07-29 17:44:46 +0400218 def clientGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:enabled").get("return")[0].values()[0]
219 def pkiGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:volumes:salt_pki").get("return")[0].values()[0]
220 def nginxEnabledAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0]
221 if (nginxEnabledAtMaster.toString().toLowerCase() == 'true' && clientGluster.toString().toLowerCase() == 'true' && pkiGluster) {
222 def nginxRequires = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:wait_for_service').get('return')[0].values()[0]
223 if (nginxRequires.isEmpty()) {
Ivan Berezovskiy8699f3f2020-01-24 17:52:26 +0400224 def nginxRequiresClassName = "cluster.${cluster_name}.infra.config.nginx_requires_wa32284"
225 def nginxRequiresClassFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/infra/config/nginx_requires_wa32284.yml"
Denis Egorenkobae9dc72019-07-29 17:44:46 +0400226 def nginxRequiresBlock = ['parameters': ['nginx': ['server': ['wait_for_service': ['srv-salt-pki.mount'] ] ] ] ]
227 def _tempFile = '/tmp/wa32284_' + UUID.randomUUID().toString().take(8)
228 writeYaml file: _tempFile , data: nginxRequiresBlock
229 def nginxRequiresBlockString = sh(script: "cat ${_tempFile}", returnStdout: true).trim()
Ivan Berezovskiy8699f3f2020-01-24 17:52:26 +0400230 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && " +
Denis Egorenkobae9dc72019-07-29 17:44:46 +0400231 "sed -i '/^parameters:/i - ${nginxRequiresClassName}' infra/config/init.yml")
232 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${nginxRequiresBlockString}' > ${nginxRequiresClassFile}", false, null, false)
Ivan Berezovskiy8699f3f2020-01-24 17:52:26 +0400233 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${nginxRequiresClassFile}")
Denis Egorenkobae9dc72019-07-29 17:44:46 +0400234 }
235 }
236}
237
Denis Egorenkoda117892019-09-02 14:53:02 +0400238def wa32182(String cluster_name) {
Hanna Arhipova644aefd2019-09-06 17:55:40 +0300239 if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) {
Denis Egorenkoda117892019-09-02 14:53:02 +0400240 def clusterModelPath = "/srv/salt/reclass/classes/cluster/${cluster_name}"
241 def fixFile = "${clusterModelPath}/opencontrail/common_wa32182.yml"
242 def usualFile = "${clusterModelPath}/opencontrail/common.yml"
243 def fixFileContent = "classes:\n- system.opencontrail.common\n"
244 salt.cmdRun(venvPepper, 'I@salt:master', "test -f ${fixFile} -o -f ${usualFile} || echo '${fixFileContent}' > ${fixFile}")
245 def contrailFiles = ['opencontrail/analytics.yml', 'opencontrail/control.yml', 'openstack/compute/init.yml']
246 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
247 contrailFiles.add('kubernetes/compute.yml')
248 }
Ivan Berezovskiye375e6a2020-02-05 21:18:17 +0400249 for (String contrailFile in contrailFiles) {
Denis Egorenkoda117892019-09-02 14:53:02 +0400250 contrailFile = "${clusterModelPath}/${contrailFile}"
251 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()
252 if (containsFix) {
253 continue
254 } else {
255 salt.cmdRun(venvPepper, 'I@salt:master', "grep -q -E '^parameters:' ${contrailFile} && sed -i '/^parameters:/i - cluster.${cluster_name}.opencontrail.common_wa32182' ${contrailFile} || " +
Ivan Berezovskiye375e6a2020-02-05 21:18:17 +0400256 "echo '- cluster.${cluster_name}.opencontrail.common_wa32182' >> ${contrailFile}")
Denis Egorenkoda117892019-09-02 14:53:02 +0400257 }
258 }
Ivan Berezovskiye375e6a2020-02-05 21:18:17 +0400259 salt.cmdRun(venvPepper, 'I@salt:master', "test -f ${fixFile} && cd ${clusterModelPath} && git status && git add ${fixFile} || true")
Denis Egorenkoda117892019-09-02 14:53:02 +0400260 }
261}
262
Denis Egorenko32461082019-10-25 13:13:39 +0400263def wa33867(String cluster_name) {
264 if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) {
265 def contrailControlFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/opencontrail/control.yml"
266 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()
267 if (line == "- cluster.${cluster_name}.infra") {
268 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra\$/d' ${contrailControlFile}")
269 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra.backup.client_zookeeper\$/i - cluster.${cluster_name}.infra' ${contrailControlFile}")
270 }
271 }
272}
273
Denis Egorenko7e934c22019-10-18 17:06:11 +0400274def wa33771(String cluster_name) {
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400275 if (salt.getMinions(venvPepper, 'I@_param:openstack_node_role and I@apache:server')) {
276 def octaviaEnabled = salt.getMinions(venvPepper, 'I@octavia:api:enabled')
277 def octaviaWSGI = salt.getMinions(venvPepper, 'I@apache:server:site:octavia_api')
278 if (octaviaEnabled && !octaviaWSGI) {
279 def openstackControl = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/control.yml"
280 def octaviaFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/octavia_wa33771.yml"
281 def octaviaContext = [
282 'classes' : ['system.apache.server.site.octavia'],
283 'parameters': [
284 '_param': ['apache_octavia_api_address': '${_param:cluster_local_address}'],
285 ]
Denis Egorenko7e934c22019-10-18 17:06:11 +0400286 ]
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400287 def openstackHTTPSEnabled = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_internal_protocol").get("return")[0].values()[0]
288 if (openstackHTTPSEnabled == 'https') {
289 octaviaContext['parameters'] << ['apache': ['server': ['site': ['apache_proxy_openstack_api_octavia': ['enabled': false]]]]]
290 }
291 def _tempFile = '/tmp/wa33771' + UUID.randomUUID().toString().take(8)
292 writeYaml file: _tempFile, data: octaviaContext
293 def octaviaFileContent = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
294 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.octavia_wa33771' ${openstackControl}")
295 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${octaviaFileContent}' | base64 -d > ${octaviaFile}", false, null, false)
296 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${octaviaFile}")
Denis Egorenko72353092020-01-30 17:17:25 +0400297 }
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400298 } else {
299 common.warningMsg("Apache server is not defined on controller nodes. Skipping Octavia WSGI workaround");
Denis Egorenko7e934c22019-10-18 17:06:11 +0400300 }
301}
302
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400303def wa33930_33931(String cluster_name) {
304 def openstackControlFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/control.yml"
305 def fixName = 'clients_common_wa33930_33931'
306 def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/${fixName}.yml"
307 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()
308 if (! containsFix) {
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400309 def fixContext = [ 'classes': [ ] ]
310 def novaControllerNodes = salt.getMinions(venvPepper, 'I@nova:controller')
311 for (novaController in novaControllerNodes) {
312 def novaClientPillar = salt.getPillar(venvPepper, novaController, "nova:client").get("return")[0].values()[0]
313 if (novaClientPillar == '' || novaClientPillar == 'null' || novaClientPillar == null) {
314 fixContext['classes'] << 'service.nova.client'
315 break
316 }
317 }
318 def glanceServerNodes = salt.getMinions(venvPepper, 'I@glance:server')
319 for (glanceServer in glanceServerNodes) {
320 def glanceClientPillar = salt.getPillar(venvPepper, glanceServer, "glance:client").get("return")[0].values()[0]
321 if (glanceClientPillar == '' || glanceClientPillar == 'null' || glanceClientPillar == null) {
322 fixContext['classes'] << 'service.glance.client'
323 break
324 }
325 }
326 def neutronServerNodes = salt.getMinions(venvPepper, 'I@neutron:server')
327 for (neutronServer in neutronServerNodes) {
328 def neutronServerPillar = salt.getPillar(venvPepper, neutronServer, "neutron:client").get("return")[0].values()[0]
329 if (neutronServerPillar == '' || neutronServerPillar == 'null' || neutronServerPillar == null) {
330 fixContext['classes'] << 'service.neutron.client'
331 break
332 }
333 }
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400334 if (salt.getMinions(venvPepper, 'I@manila:api:enabled')) {
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400335 def manilaApiNodes = salt.getMinions(venvPepper, 'I@manila:api')
336 for (manilaNode in manilaApiNodes) {
337 def manilaNodePillar = salt.getPillar(venvPepper, manilaNode, "manila:client").get("return")[0].values()[0]
338 if (manilaNodePillar == '' || manilaNodePillar == 'null' || manilaNodePillar == null) {
339 fixContext['classes'] << 'service.manila.client'
340 break
341 }
342 }
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400343 }
344 if (salt.getMinions(venvPepper, 'I@ironic:api:enabled')) {
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400345 def ironicApiNodes = salt.getMinions(venvPepper, 'I@ironic:api')
346 for (ironicNode in ironicApiNodes) {
347 def ironicNodePillar = salt.getPillar(venvPepper, ironicNode, "ironic:client").get("return")[0].values()[0]
348 if (ironicNodePillar == '' || ironicNodePillar == 'null' || ironicNodePillar == null) {
349 fixContext['classes'] << 'service.ironic.client'
350 break
351 }
352 }
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400353 }
354 if (salt.getMinions(venvPepper, 'I@gnocchi:server:enabled')) {
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400355 def gnocchiServerNodes = salt.getMinions(venvPepper, 'I@gnocchi:server')
356 for (gnocchiNode in gnocchiServerNodes) {
357 def gnocchiNodePillar = salt.getPillar(venvPepper, gnocchiNode, "gnocchi:client").get("return")[0].values()[0]
358 if (gnocchiNodePillar == '' || gnocchiNodePillar == 'null' || gnocchiNodePillar == null) {
359 fixContext['classes'] << 'service.gnocchi.client'
360 break
361 }
362 }
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400363 }
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400364
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400365 if (salt.getMinions(venvPepper, 'I@barbican:server:enabled')) {
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400366 def barbicanServerNodes = salt.getMinions(venvPepper, 'I@barbican:server')
367 for (barbicanNode in barbicanServerNodes) {
368 def barbicanNodePillar = salt.getPillar(venvPepper, barbicanNode, "barbican:client").get("return")[0].values()[0]
369 if (barbicanNodePillar == '' || barbicanNodePillar == 'null' || barbicanNodePillar == null) {
370 fixContext['classes'] << 'service.barbican.client.single'
371 break
372 }
373 }
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400374 }
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400375 if (fixContext['classes'] != []) {
376 def _tempFile = '/tmp/wa33930_33931' + UUID.randomUUID().toString().take(8)
377 writeYaml file: _tempFile, data: fixContext
378 def fixFileContent = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
379 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${fixFileContent}' | base64 -d > ${fixFile}", false, null, false)
380 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.${fixName}' ${openstackControlFile}")
381 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${fixFile}")
382 }
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400383 }
384}
385
Denis Egorenkodb450152020-01-28 16:41:44 +0400386def wa34245(cluster_name) {
387 def infraInitFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/infra/init.yml"
388 def fixName = 'hosts_wa34245'
389 def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/infra/${fixName}.yml"
390 if (salt.testTarget(venvPepper, 'I@keystone:server')) {
391 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()
392 if (!fixApplied) {
393 def fixFileContent = []
394 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()
395 if (!containsFix) {
396 fixFileContent << '- system.linux.network.hosts.openstack'
397 }
398 if (salt.testTarget(venvPepper, 'I@gnocchi:server')) {
399 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()
400 if (!containsFix) {
401 fixFileContent << '- system.linux.network.hosts.openstack.telemetry'
402 }
403 }
404 if (salt.testTarget(venvPepper, 'I@manila:api')) {
405 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()
406 if (!containsFix) {
407 fixFileContent << '- system.linux.network.hosts.openstack.share'
408 }
409 }
410 if (salt.testTarget(venvPepper, 'I@barbican:server')) {
411 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()
412 if (!containsFix) {
413 fixFileContent << '- system.linux.network.hosts.openstack.kmn'
414 }
415 }
416 if (fixFileContent) {
417 salt.cmdRun(venvPepper, 'I@salt:master', "echo 'classes:\n${fixFileContent.join('\n')}' > ${fixFile}")
418 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.infra.${fixName}' ${infraInitFile}")
Ivan Berezovskiy8699f3f2020-01-24 17:52:26 +0400419 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${fixFile}")
Denis Egorenkodb450152020-01-28 16:41:44 +0400420 }
421 }
422 }
423}
424
Ivan Berezovskiy8699f3f2020-01-24 17:52:26 +0400425def wa34528(String cluster_name) {
426 // Mysql users have to be defined on each Galera node
427 if(salt.getMinions(venvPepper, 'I@galera:master').isEmpty()) {
428 common.errorMsg('No Galera master found in cluster. Skipping')
429 return
430 }
431 def mysqlUsersMasterPillar = salt.getPillar(venvPepper, 'I@galera:master', 'mysql:server:database').get("return")[0].values()[0]
432 if (mysqlUsersMasterPillar == '' || mysqlUsersMasterPillar == 'null' || mysqlUsersMasterPillar == null) {
433 common.errorMsg('Pillar data is broken for Galera master node!')
434 input message: 'Do you want to ignore and continue without Galera pillar patch?'
435 return
436 }
437 def fileToPatch = salt.cmdRun(venvPepper, 'I@salt:master', "ls /srv/salt/reclass/classes/cluster/${cluster_name}/openstack/database/init.yml || " +
438 "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()
439 if (fileToPatch == 'File not found') {
440 common.errorMsg('Cluster model is old and cannot be patched for PROD-34528. Patching is possible for 2019.2.x cluster models only')
441 return
442 }
443 def patchRequired = false
444 def mysqlUsersSlavePillar = ''
445 def galeraSlaveNodes = salt.getMinions(venvPepper, 'I@galera:slave')
446 if (!galeraSlaveNodes.isEmpty()) {
447 for (galeraSlave in galeraSlaveNodes) {
448 mysqlUsersSlavePillar = salt.getPillar(venvPepper, galeraSlave, 'mysql:server:database').get("return")[0].values()[0]
449 if (mysqlUsersSlavePillar == '' || mysqlUsersSlavePillar == 'null' || mysqlUsersSlavePillar == null) {
450 common.errorMsg('Mysql users data is not defined for Galera slave nodes. Fixing...')
451 patchRequired = true
452 break
453 }
454 }
455 if (patchRequired) {
456 def fixFileContent = []
457 def fixName = 'db_wa34528'
458 def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/database/${fixName}.yml"
459 for (dbName in mysqlUsersMasterPillar.keySet()) {
460 def classIncluded = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- system\\.galera\\.server\\.database\\.${dbName}\$'" +
461 " /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()
462 if(classIncluded) {
463 fixFileContent << "- system.galera.server.database.${dbName}"
464 }
465 def sslClassIncluded = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- system\\.galera\\.server\\.database\\.x509\\.${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(sslClassIncluded) {
468 fixFileContent << "- system.galera.server.database.x509.${dbName}"
469 }
470 }
471 if (fixFileContent) {
472 salt.cmdRun(venvPepper, 'I@salt:master', "echo 'classes:\n${fixFileContent.join('\n')}' > ${fixFile}")
473 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.database.${fixName}' ${fileToPatch}")
474 }
475 salt.fullRefresh(venvPepper, 'I@galera:slave')
476 // Verify
477 for (galeraSlave in galeraSlaveNodes) {
478 mysqlUsersSlavePillar = salt.getPillar(venvPepper, galeraSlave, 'mysql:server:database').get("return")[0].values()[0]
479 if (mysqlUsersSlavePillar == '' || mysqlUsersSlavePillar == 'null' || mysqlUsersSlavePillar == null || mysqlUsersSlavePillar.keySet() != mysqlUsersMasterPillar.keySet()) {
480 common.errorMsg("Mysql user data is different on master and slave node ${galeraSlave}.")
481 input message: 'Do you want to ignore and continue?'
482 }
483 }
484 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${fixFile}")
485 common.infoMsg('Galera slaves patching is done')
486 } else {
487 common.infoMsg('Galera slaves patching is not required')
488 }
489 }
490}
491
azvyagintsev6dac3802018-11-09 15:11:30 +0200492def archiveReclassInventory(filename) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400493 def _tmp_file = '/tmp/' + filename + UUID.randomUUID().toString().take(8)
494 // jenkins may fail at overheap. Compress data with gzip like WA
495 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()
496 def _tmp = sh(script: "echo '$ret' > ${_tmp_file}", returnStdout: false)
497 sh(script: "cat ${_tmp_file} | base64 -d | gzip -d > $filename", returnStdout: false)
498 archiveArtifacts artifacts: filename
499 sh(script: "rm -v ${_tmp_file}|| true")
Richard Felkl0e80d892018-06-20 13:44:54 +0200500}
501
Denis Egorenkod13ad132018-12-17 16:56:02 +0400502def validateReclassModel(ArrayList saltMinions, String suffix) {
503 try {
Denis Egorenkoada83882019-06-11 14:03:40 +0400504 for (String minion in saltMinions) {
505 common.infoMsg("Reclass model validation for minion ${minion}...")
506 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()
507 writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString()
Denis Egorenkod13ad132018-12-17 16:56:02 +0400508 }
509 } catch (Exception e) {
510 common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.')
Denis Egorenkoada83882019-06-11 14:03:40 +0400511 error(e.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400512 }
513}
514
Denis Egorenkoada83882019-06-11 14:03:40 +0400515def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix = 'before', String newSuffix = 'after') {
516 for (String minion in saltMinions) {
517 def fileName = "reclass-model-${minion}-diff.out"
518 sh "diff -u inventory-${minion}-${oldSuffix}.out inventory-${minion}-${newSuffix}.out > ${fileName} || true"
519 archiveArtifacts artifacts: "${fileName}"
Denis Egorenkod13ad132018-12-17 16:56:02 +0400520 }
521}
522
Denis Egorenkobf390102020-01-24 19:47:05 +0400523def checkCICDDocker() {
524 common.infoMsg('Perform: Checking if Docker containers are up')
525 try {
526 common.retry(10, 30) {
527 salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'")
528 }
529 }
530 catch (Exception ex) {
531 error("Docker containers for CI/CD services are having troubles with starting.")
532 }
533}
534
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400535if (common.validInputParam('PIPELINE_TIMEOUT')) {
536 try {
537 pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger()
Denis Egorenkoada83882019-06-11 14:03:40 +0400538 } catch (Exception e) {
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400539 common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger")
540 }
Martin Polreich965c9032018-08-09 16:33:57 +0200541}
542
543timeout(time: pipelineTimeout, unit: 'HOURS') {
Denis Egorenkoada83882019-06-11 14:03:40 +0400544 node("python") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100545 try {
Denis Egorenkoada83882019-06-11 14:03:40 +0400546 def inventoryBeforeFilename = "reclass-inventory-before.out"
547 def inventoryAfterFilename = "reclass-inventory-after.out"
Richard Felkl0e80d892018-06-20 13:44:54 +0200548 workspace = common.getWorkspace()
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200549 targetMcpVersion = null
550 if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) {
551 error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable')
azvyagintsev6dac3802018-11-09 15:11:30 +0200552 }
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200553 // bw comp. for 2018.X => 2018.11 release
Denis Egorenkoada83882019-06-11 14:03:40 +0400554 if (common.validInputParam('MCP_VERSION')) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200555 targetMcpVersion = env.MCP_VERSION
556 common.warningMsg("targetMcpVersion has been changed to:${targetMcpVersion}, which was taken from deprecated pipeline viriable:MCP_VERSION")
Denis Egorenkoada83882019-06-11 14:03:40 +0400557 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200558 targetMcpVersion = env.TARGET_MCP_VERSION
559 }
560 // end bw comp. for 2018.X => 2018.11 release
Denis Egorenkod13ad132018-12-17 16:56:02 +0400561 def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC')
Ivan Berezovskiyd62629c2019-01-16 19:26:18 +0400562 if (targetMcpVersion in ['nightly', 'testing']) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200563 gitTargetMcpVersion = 'master'
Ivan Berezovskiyd62629c2019-01-16 19:26:18 +0400564 } else if (targetMcpVersion == 'proposed') {
565 gitTargetMcpVersion = 'proposed'
Denis Egorenko284690e2018-12-25 15:55:12 +0400566 } else if (!gitTargetMcpVersion) {
567 // backward compatibility for 2018.11.0
568 gitTargetMcpVersion = "release/${targetMcpVersion}"
azvyagintsev6dac3802018-11-09 15:11:30 +0200569 }
Ivan Berezovskiyd62629c2019-01-16 19:26:18 +0400570 common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}")
Denis Egorenko284690e2018-12-25 15:55:12 +0400571 def upgradeSaltStack = ''
572 def updateClusterModel = ''
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400573 def applyWorkarounds = true
Denis Egorenko284690e2018-12-25 15:55:12 +0400574 def updatePipelines = ''
575 def updateLocalRepos = ''
576 def reclassSystemBranch = ''
Denis Egorenkob559e542019-03-29 13:24:15 +0400577 def reclassSystemBranchDefault = gitTargetMcpVersion
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400578 if (gitTargetMcpVersion ==~ /^\d\d\d\d\.\d\d?\.\d+$/) {
579 reclassSystemBranchDefault = "tags/${gitTargetMcpVersion}"
580 } else if (gitTargetMcpVersion != 'proposed') {
Denis Egorenkob559e542019-03-29 13:24:15 +0400581 reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}"
582 }
Hanna Arhipova644aefd2019-09-06 17:55:40 +0300583 def driveTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS')
584 if (driveTrainParamsYaml) {
585 def driveTrainParams = readYaml text: driveTrainParamsYaml
586 saltMastURL = driveTrainParams.get('SALT_MASTER_URL')
587 saltMastCreds = driveTrainParams.get('SALT_MASTER_CREDENTIALS')
588 upgradeSaltStack = driveTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean()
589 updateClusterModel = driveTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean()
590 updatePipelines = driveTrainParams.get('UPDATE_PIPELINES', false).toBoolean()
591 updateLocalRepos = driveTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean()
592 reclassSystemBranch = driveTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault)
Denis Egorenko70002bc2019-08-19 19:41:27 +0400593 batchSize = driveTrainParams.get('BATCH_SIZE', '')
Denis Egorenkobf390102020-01-24 19:47:05 +0400594 if (driveTrainParams.get('OS_DIST_UPGRADE', false).toBoolean() == true) {
595 packageUpgradeMode = 'dist-upgrade'
596 } else if (driveTrainParams.get('OS_UPGRADE', false).toBoolean() == true) {
597 packageUpgradeMode = 'upgrade'
598 }
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400599 applyWorkarounds = driveTrainParams.get('APPLY_MODEL_WORKAROUNDS', true).toBoolean()
Denis Egorenko284690e2018-12-25 15:55:12 +0400600 } else {
601 // backward compatibility for 2018.11.0
602 saltMastURL = env.getProperty('SALT_MASTER_URL')
603 saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS')
Denis Egorenkoe5f39142018-12-28 12:30:48 +0400604 upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean()
605 updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean()
606 updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean()
607 updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean()
Denis Egorenkob559e542019-03-29 13:24:15 +0400608 reclassSystemBranch = reclassSystemBranchDefault
Denis Egorenko284690e2018-12-25 15:55:12 +0400609 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400610 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400611 def minions = salt.getMinions(venvPepper, '*')
Denis Egorenkoc0538ce2019-04-19 15:05:18 +0400612 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
613 if (cluster_name == '' || cluster_name == 'null' || cluster_name == null) {
614 error('Pillar data is broken for Salt master node! Please check it manually and re-run pipeline.')
615 }
Hanna Arhipova644aefd2019-09-06 17:55:40 +0300616 if (!batchSize) {
Denis Egorenko9ef25b92019-12-19 16:45:25 +0400617 // if no batch size provided get current worker threads and set batch size to 2/3 of it to avoid
618 // 'SaltReqTimeoutError: Message timed out' issue on Salt targets for large amount of nodes
619 // do not use toDouble/Double as it requires additional approved method
620 def workerThreads = getWorkerThreads(venvPepper).toInteger()
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400621 batchSize = (workerThreads * 2 / 3).toString().tokenize('.')[0]
Denis Egorenko70002bc2019-08-19 19:41:27 +0400622 }
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400623 def computeMinions = salt.getMinions(venvPepper, 'I@nova:compute')
Ivan Berezovskiy224eb8e2020-03-19 14:03:43 +0400624 def allMinions = salt.getMinions(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400625
Denis Egorenkoada83882019-06-11 14:03:40 +0400626 stage('Update Reclass and Salt-Formulas') {
627 common.infoMsg('Perform: Full salt sync')
Ivan Berezovskiy224eb8e2020-03-19 14:03:43 +0400628 fullRefreshOneByOne(venvPepper, allMinions)
Denis Egorenkoada83882019-06-11 14:03:40 +0400629 common.infoMsg('Perform: Validate reclass medata before processing')
630 validateReclassModel(minions, 'before')
631
632 common.infoMsg('Perform: archiveReclassInventory before upgrade')
Denis Egorenko89a3c572019-03-22 17:03:40 +0400633 archiveReclassInventory(inventoryBeforeFilename)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400634
azvyagintsev6dac3802018-11-09 15:11:30 +0200635 try {
Denis Egorenkoada83882019-06-11 14:03:40 +0400636 salt.cmdRun(venvPepper, 'I@salt:master', 'cd /srv/salt/reclass/ && git status && git diff-index --quiet HEAD --')
Richard Felkl970e0082018-06-12 18:00:51 +0200637 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200638 catch (Exception ex) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400639 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 +0200640 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400641 if (updateClusterModel) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200642 common.infoMsg('Perform: UPDATE_CLUSTER_MODEL')
Sergey382581a2018-10-25 12:22:26 +0400643 def dateTime = common.getDatetime()
Ivan Berezovskiy1d780522020-01-17 13:55:18 +0400644 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git fetch")
Sergey382581a2018-10-25 12:22:26 +0400645 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400646 "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 +0200647 // Do the same, for deprecated variable-duplicate
648 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400649 "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 +0400650 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400651 "grep -r --exclude-dir=aptly -l 'jenkins_pipelines_branch: .*' * | xargs --no-run-if-empty sed -i 's|jenkins_pipelines_branch: .*|jenkins_pipelines_branch: \"$gitTargetMcpVersion\"|g'")
Victor Ryzhenkin202c5062019-01-15 19:58:03 +0400652 // Set new k8s param
653 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
654 "grep -r --exclude-dir=aptly -l 'kubernetes_containerd_enabled: .*' * | xargs --no-run-if-empty sed -i 's|kubernetes_containerd_enabled: .*|kubernetes_containerd_enabled: True|g'")
Denis Egorenko2a39d2c2019-01-16 19:18:31 +0400655 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
656 "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'")
657 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoca871c22019-02-13 13:49:13 +0400658 "grep -r --exclude-dir=aptly -l 'system.linux.system.repo.mcp.contrail' * | xargs --no-run-if-empty sed -i 's/system.linux.system.repo.mcp.contrail/system.linux.system.repo.mcp.apt_mirantis.contrail/g'")
Denis Egorenko2a39d2c2019-01-16 19:18:31 +0400659 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoca871c22019-02-13 13:49:13 +0400660 "grep -r --exclude-dir=aptly -l 'system.linux.system.repo.mcp.updates' * | xargs --no-run-if-empty sed -i 's/system.linux.system.repo.mcp.updates/system.linux.system.repo.mcp.apt_mirantis.update/g'")
Anton Samoylov72c2ccf2019-02-13 15:57:13 +0400661 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoada83882019-06-11 14:03:40 +0400662 "grep -r --exclude-dir=aptly -l 'system.linux.system.repo.mcp.extra' * | xargs --no-run-if-empty sed -i 's/system.linux.system.repo.mcp.extra/system.linux.system.repo.mcp.apt_mirantis.extra/g'")
Denis Egorenko6ca9f0d2019-07-10 19:47:39 +0400663
Denis Egorenko70f4f9a2019-09-16 16:41:26 +0400664 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")
665 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name/infra && sed -i '/maas_region_main_archive/d' maas.yml")
666
Denis Egorenko6ca9f0d2019-07-10 19:47:39 +0400667 // Switch Jenkins/Gerrit to use LDAP SSL/TLS
668 def gerritldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
669 "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()
670 if (gerritldapURI.startsWith('ldap://')) {
671 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
672 "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
673 } else if (! gerritldapURI.startsWith('ldaps://')) {
674 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
675 "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'")
676 }
677 def jenkinsldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
678 "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()
679 if (jenkinsldapURI.startsWith('ldap://')) {
680 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
681 "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
682 } else if (! jenkinsldapURI.startsWith('ldaps://')) {
683 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
684 "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'")
685 }
686
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400687 if (applyWorkarounds) {
688 wa32284(cluster_name)
689 wa34245(cluster_name)
690 }
Denis Egorenkobae9dc72019-07-29 17:44:46 +0400691
Denis Egorenkod13ad132018-12-17 16:56:02 +0400692 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}")
Sergey Kolekonov6ab15112019-01-23 16:47:43 +0400693 // Add kubernetes-extra repo
694 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
Sergey Kolekonovac9554c2019-04-11 16:33:54 +0400695 // docker-engine conflicts with the recent containerd versions, so it's removed during upgrade. Thus update source engine
696 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
697 "grep -r -l 'engine: docker_hybrid' kubernetes | xargs --no-run-if-empty sed -i 's/engine: docker_hybrid/engine: archive/g'")
Sergey Kolekonov6ab15112019-01-23 16:47:43 +0400698 common.infoMsg("Add kubernetes-extra repo")
699 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
700 "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")
701 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
702 "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")
703 }
Ivan Berezovskiybe630ee2019-04-15 13:23:58 +0400704 // Add all update repositories
705 def repoIncludeBase = '- system.linux.system.repo.mcp.apt_mirantis.'
Denis Egorenko70f4f9a2019-09-16 16:41:26 +0400706 def updateRepoList = ['cassandra', 'ceph', 'contrail', 'docker', 'elastic', 'extra', 'openstack', 'maas', 'percona', 'salt-formulas', 'saltstack', 'ubuntu']
Ivan Berezovskiybe630ee2019-04-15 13:23:58 +0400707 updateRepoList.each { repo ->
708 def repoNameUpdateInclude = "${repoIncludeBase}update.${repo}"
709 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')
710 filesWithInclude.each { file ->
711 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()
712 if (updateRepoIncludeExist == 'not_found') {
713 // Include needs to be added
714 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoada83882019-06-11 14:03:40 +0400715 "sed -i 's/\\( *\\)${repoIncludeBase}${repo}\$/&\\n\\1${repoNameUpdateInclude}/g' ${file}")
Ivan Berezovskiybe630ee2019-04-15 13:23:58 +0400716 common.infoMsg("Update repo for ${repo} is added to ${file}")
717 }
718 }
719 }
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400720 if (applyWorkarounds) {
721 wa32182(cluster_name)
722 wa33771(cluster_name)
723 wa33867(cluster_name)
724 wa33930_33931(cluster_name)
725 wa34528(cluster_name)
726 }
Sergey382581a2018-10-25 12:22:26 +0400727 // Add new defaults
728 common.infoMsg("Add new defaults")
Denis Egorenkod13ad132018-12-17 16:56:02 +0400729 salt.cmdRun(venvPepper, 'I@salt:master', "grep '^ mcp_version: ' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400730 "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 +0400731 salt.cmdRun(venvPepper, 'I@salt:master', "grep '^- system.defaults\$' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400732 "sed -i 's|^classes:|classes:\\n- system.defaults|' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml")
Ivan Berezovskiyadb7d832019-04-23 14:32:02 +0400733 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
734 "grep -r -l 'docker_image_jenkins: .*' cicd | xargs --no-run-if-empty sed -i 's|\\s*docker_image_jenkins: .*||g'")
735 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
736 "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 +0400737 common.infoMsg("The following changes were made to the cluster model and will be commited. " +
azvyagintsev6dac3802018-11-09 15:11:30 +0200738 "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 +0400739 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff")
740 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " +
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200741 "git add -u && git commit --allow-empty -m 'Cluster model update to the release $targetMcpVersion on $dateTime'")
Sergey382581a2018-10-25 12:22:26 +0400742 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400743 try {
744 common.infoMsg('Perform: UPDATE Salt Formulas')
Ivan Berezovskiy224eb8e2020-03-19 14:03:43 +0400745 fullRefreshOneByOne(venvPepper, allMinions)
746 salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400747 def saltEnv = salt.getPillar(venvPepper, 'I@salt:master', "_param:salt_master_base_environment").get("return")[0].values()[0]
Denis Egorenkoada83882019-06-11 14:03:40 +0400748 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas", 'salt.master.env'])
Ivan Berezovskiy224eb8e2020-03-19 14:03:43 +0400749 fullRefreshOneByOne(venvPepper, allMinions)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400750 } catch (Exception updateErr) {
751 common.warningMsg(updateErr)
752 common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
753 input message: 'Continue anyway?'
754 }
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400755 if (applyWorkarounds) {
756 wa29352(cluster_name)
757 wa29155(computeMinions, cluster_name)
758 }
Denis Egorenkoada83882019-06-11 14:03:40 +0400759
Denis Egorenkod13ad132018-12-17 16:56:02 +0400760 try {
761 common.infoMsg('Perform: UPDATE Reclass package')
762 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"])
763 } catch (Exception updateErr) {
764 common.warningMsg(updateErr)
765 common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
766 input message: 'Continue anyway?'
767 }
768
769 salt.fullRefresh(venvPepper, 'I@salt:master')
Sergey1b81c062018-10-16 17:10:21 +0400770 salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true)
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400771 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && " +
772 "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 +0400773 try {
774 salt.enforceState(venvPepper, "I@salt:master", 'reclass', true)
775 }
776 catch (Exception ex) {
777 error("Reclass fails rendering. Pay attention to your cluster model.")
778 }
779
Ivan Berezovskiy224eb8e2020-03-19 14:03:43 +0400780 fullRefreshOneByOne(venvPepper, allMinions)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400781 try {
782 salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top")
783 }
784 catch (Exception ex) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400785
786 error('Reclass fails rendering. Pay attention to your cluster model.' +
787 'ErrorMessage:' + ex.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400788 }
789
Denis Egorenkoada83882019-06-11 14:03:40 +0400790 common.infoMsg('Perform: archiveReclassInventory AFTER upgrade')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400791 archiveReclassInventory(inventoryAfterFilename)
792
793 sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true"
794 archiveArtifacts artifacts: "reclass-inventory-diff.out"
795
Denis Egorenkoada83882019-06-11 14:03:40 +0400796 validateReclassModel(minions, 'after')
797 archiveReclassModelChanges(minions)
Jakub Josefa63f9862018-01-11 17:58:38 +0100798 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100799
Denis Egorenkod13ad132018-12-17 16:56:02 +0400800 if (updateLocalRepos) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200801 stage("Update local repos") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100802 common.infoMsg("Updating local repositories")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700803
Sergey1b81c062018-10-16 17:10:21 +0400804 def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700805 runningOnDocker = engine.get("return")[0].containsValue("docker")
806
807 if (runningOnDocker) {
808 common.infoMsg("Aptly is running as Docker container")
azvyagintsev6dac3802018-11-09 15:11:30 +0200809 } else {
Sam Stoelingaaab79702018-04-09 18:49:39 -0700810 common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands")
811 }
812
azvyagintsev6dac3802018-11-09 15:11:30 +0200813 if (runningOnDocker) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200814 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 +0200815 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200816 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 +0100817 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100818
Sergey1b81c062018-10-16 17:10:21 +0400819 salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100820
azvyagintsev6dac3802018-11-09 15:11:30 +0200821 if (runningOnDocker) {
Sergey1b81c062018-10-16 17:10:21 +0400822 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true)
823 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 +0200824 } else {
Sergey1b81c062018-10-16 17:10:21 +0400825 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true)
826 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 +0100827 }
Richard Felkl79d7df12018-01-05 16:40:11 +0100828
Sergey1b81c062018-10-16 17:10:21 +0400829 salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100830
Sergey1b81c062018-10-16 17:10:21 +0400831 salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100832
Sergey1b81c062018-10-16 17:10:21 +0400833 salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100834
Sergey1b81c062018-10-16 17:10:21 +0400835 salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100836 }
837 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100838
Denis Egorenkoada83882019-06-11 14:03:40 +0400839 stage('Update Drivetrain') {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400840 if (upgradeSaltStack) {
841 updateSaltStack("I@salt:master", '["salt-master", "salt-common", "salt-api", "salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200842
Denis Egorenko70002bc2019-08-19 19:41:27 +0400843 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.repo', true, true, batchSize)
Richard Felkl0e80d892018-06-20 13:44:54 +0200844 updateSaltStack("I@salt:minion and not I@salt:master", '["salt-minion"]')
845 }
846
Denis Egorenkod13ad132018-12-17 16:56:02 +0400847 if (updatePipelines) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400848 common.infoMsg('Perform: UPDATE git repos')
849 triggerMirrorJob('git-mirror-downstream-mk-pipelines', reclassSystemBranch)
850 triggerMirrorJob('git-mirror-downstream-pipeline-library', reclassSystemBranch)
Richard Felkl970e0082018-06-12 18:00:51 +0200851 }
852
Denis Egorenkod00c17e2019-04-25 20:17:27 +0400853 // update minions certs
Denis Egorenko70002bc2019-08-19 19:41:27 +0400854 salt.enforceState(venvPepper, "I@salt:minion", 'salt.minion.cert', true, true, batchSize)
Denis Egorenkoada83882019-06-11 14:03:40 +0400855
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400856 // run `salt.minion` to refresh all minion configs (for example _keystone.conf)
857 salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion', true, true, batchSize, false, 60, 2)
Denis Egorenkoada83882019-06-11 14:03:40 +0400858 // Retry needed only for rare race-condition in user appearance
859 common.infoMsg('Perform: updating users and keys')
Denis Egorenko70002bc2019-08-19 19:41:27 +0400860 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.user', true, true, batchSize)
Denis Egorenkoada83882019-06-11 14:03:40 +0400861 common.infoMsg('Perform: updating openssh')
Denis Egorenko70002bc2019-08-19 19:41:27 +0400862 salt.enforceState(venvPepper, "I@linux:system", 'openssh', true, true, batchSize)
Denis Egorenkoaeaa1de2019-01-15 11:58:12 +0400863
Denis Egorenkoe69920e2019-10-30 13:26:59 +0400864 // 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
865 def gerritGlusterPath = salt.getPillar(venvPepper, 'I@gerrit:client', 'glusterfs:client:volumes:gerrit:path').get('return')[0].values()[0]
866 def wrongPluginJarName = "${gerritGlusterPath}/plugins/project-download-commands.jar"
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400867 salt.cmdRun(venvPepper, 'I@gerrit:client', "test -f ${wrongPluginJarName} && rm ${wrongPluginJarName} || true")
Denis Egorenkoe69920e2019-10-30 13:26:59 +0400868
Ivan Berezovskiy48cc4212020-03-19 19:11:27 +0400869 salt.enforceStateWithTest(venvPepper, 'I@jenkins:client:security and not I@salt:master', 'jenkins.client.security', "", true, true, null, true, 60, 2)
Ivan Berezovskiyf8139a82020-02-27 15:21:57 +0400870 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 Egorenkoada83882019-06-11 14:03:40 +0400871 salt.cmdRun(venvPepper, "I@salt:master", "salt -C 'I@jenkins:client and I@docker:client and not I@salt:master' state.sls docker.client --async")
Ivan Berezovskiy24b0be02019-12-11 15:31:10 +0400872 }
873 }
874 catch (Throwable e) {
875 // If there was an error or exception thrown, the build failed
876 currentBuild.result = "FAILURE"
877 throw e
878 }
879 }
880 // docker.client state may trigger change of jenkins master or jenkins slave services,
881 // so we need wait for slave to reconnect and continue pipeline
882 sleep(180)
Denis Egorenkobf390102020-01-24 19:47:05 +0400883 def cidNodes = []
Ivan Berezovskiy24b0be02019-12-11 15:31:10 +0400884 node('python') {
885 try {
886 stage('Update Drivetrain: Phase 2') {
887 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenkobf390102020-01-24 19:47:05 +0400888 checkCICDDocker()
Denis Egorenko6ca9f0d2019-07-10 19:47:39 +0400889
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400890 // Apply changes for HaProxy on CI/CD nodes
891 salt.enforceState(venvPepper, 'I@keepalived:cluster:instance:cicd_control_vip and I@haproxy:proxy', 'haproxy.proxy', true)
892
893 salt.enforceState(venvPepper, 'I@jenkins:client and not I@salt:master', 'jenkins.client', true, true, null, false, 60, 2)
Denis Egorenko84a0bc02019-07-23 18:01:21 +0400894
895 // update Nginx proxy settings for Jenkins/Gerrit if needed
896 if (salt.testTarget(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit')) {
897 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)
898 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100899 }
Denis Egorenkobf390102020-01-24 19:47:05 +0400900 if (packageUpgradeMode) {
901 cidNodes = salt.getMinions(venvPepper, 'I@_param:drivetrain_role:cicd')
902 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100903 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100904 catch (Throwable e) {
905 // If there was an error or exception thrown, the build failed
906 currentBuild.result = "FAILURE"
907 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +0100908 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100909 }
Denis Egorenkobf390102020-01-24 19:47:05 +0400910
911 stage('Upgrade OS') {
912 if (packageUpgradeMode) {
913 def debian = new com.mirantis.mk.Debian()
914 def statusFile = '/tmp/rebooted_during_upgrade'
915 for(cidNode in cidNodes) {
916 node('python') {
917 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
918 // cmd.run async to prevent connection close in case of slave shutdown, give 5 seconds to handle request response
919 salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${cidNode}' cmd.run 'sleep 5; touch ${statusFile}; salt-call service.stop docker' --async")
920 }
921 sleep(30)
922 node('python') {
923 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
924 debian.osUpgradeNode(venvPepper, cidNode, packageUpgradeMode, false, 60)
925 salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': cidNode, wait: 60, timeout: 10])
926 if (salt.runSaltProcessStep(venvPepper, cidNode, 'file.file_exists', [statusFile], null, true, 5)['return'][0].values()[0].toBoolean()) {
927 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
928 sleep(10)
929 }
930 checkCICDDocker()
931 }
932 }
933 } else {
934 common.infoMsg('Upgrade OS skipped...')
935 }
936 }
Hanna Arhipova644aefd2019-09-06 17:55:40 +0300937}