blob: 7deea8712f6993fb90db7f5ae273d7a84ba3d3c6 [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
Denis Egorenkoada83882019-06-11 14:03:40 +040033def triggerMirrorJob(String jobName, String reclassSystemBranch) {
Richard Felkl970e0082018-06-12 18:00:51 +020034 params = jenkinsUtils.getJobParameters(jobName)
Denis Egorenkoada83882019-06-11 14:03:40 +040035 try {
36 build job: jobName, parameters: [
37 [$class: 'StringParameterValue', name: 'BRANCHES', value: params.get('BRANCHES')],
38 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')],
39 [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')],
40 [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')]
41 ]
42 } catch (Exception updateErr) {
43 common.warningMsg(updateErr)
44 common.warningMsg('Attempt to update git repo in failsafe manner')
45 build job: jobName, parameters: [
46 [$class: 'StringParameterValue', name: 'BRANCHES', value: reclassSystemBranch.replace('origin/', '')],
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 }
Richard Felkl970e0082018-06-12 18:00:51 +020052}
53
azvyagintsev6dac3802018-11-09 15:11:30 +020054def updateSaltStack(target, pkgs) {
Denis Egorenko0d0c65f2019-02-26 16:05:03 +040055 salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${target}' --async pkg.install force_yes=True pkgs='$pkgs'")
56 // can't use same function from pipeline lib, as at the moment of running upgrade pipeline Jenkins
57 // still using pipeline lib from current old mcp-version
azvyagintsev6dac3802018-11-09 15:11:30 +020058 common.retry(20, 60) {
Richard Felkl0e80d892018-06-20 13:44:54 +020059 salt.minionsReachable(venvPepper, 'I@salt:master', '*')
60 def running = salt.runSaltProcessStep(venvPepper, target, 'saltutil.running', [], null, true, 5)
azvyagintsev6dac3802018-11-09 15:11:30 +020061 for (value in running.get("return")[0].values()) {
62 if (value != []) {
Richard Felkl0e80d892018-06-20 13:44:54 +020063 throw new Exception("Not all salt-minions are ready for execution")
64 }
65 }
66 }
67
azvyagintsevf3bf77a2018-11-15 19:30:04 +020068 def saltVersion = salt.getPillar(venvPepper, 'I@salt:master', '_param:salt_version').get('return')[0].values()[0]
Richard Felklf23257e2018-08-06 09:24:23 +020069 def saltMinionVersions = salt.cmdRun(venvPepper, target, "apt-cache policy salt-common | awk '/Installed/ && /$saltVersion/'").get("return")
Richard Felkl0e80d892018-06-20 13:44:54 +020070 def saltMinionVersion = ""
71
azvyagintsev6dac3802018-11-09 15:11:30 +020072 for (minion in saltMinionVersions[0].keySet()) {
73 saltMinionVersion = saltMinionVersions[0].get(minion).replace("Salt command execution success", "").trim()
74 if (saltMinionVersion == "") {
Richard Felkl0e80d892018-06-20 13:44:54 +020075 error("Installed version of Salt on $minion doesn't match specified version in the model.")
76 }
77 }
78}
79
Denis Egorenko6f1c8732019-09-24 14:55:50 +040080def getWorkerThreads(saltId) {
81 if (env.getEnvironment().containsKey('SALT_MASTER_OPT_WORKER_THREADS')) {
82 return env['SALT_MASTER_OPT_WORKER_THREADS'].toString()
83 }
84 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)
85 return threads['return'][0].values()[0].replaceAll('Salt command execution success','').trim()
86}
87
Ivan Berezovskiy304705c2019-12-03 18:49:09 +040088def wa29352(String cname) {
Denis Egorenkoada83882019-06-11 14:03:40 +040089 // WA for PROD-29352. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/12/openssh/client/root.yml
90 // Default soft-param has been removed, what now makes not possible to render some old env's.
91 // Like fix, we found copy-paste already generated key from backups, to secrets.yml with correct key name
92 def wa29352ClassName = 'cluster.' + cname + '.infra.secrets_root_wa29352'
93 def wa29352File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_root_wa29352.yml"
94 def wa29352SecretsFile = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets.yml"
95 def _tempFile = '/tmp/wa29352_' + UUID.randomUUID().toString().take(8)
96 try {
Ivan Berezovskiycac04e42020-02-17 17:08:47 +040097 salt.cmdRun(venvPepper, 'I@salt:master', "! grep -qi root_private_key: ${wa29352SecretsFile}", true, null, false)
Denis Egorenkoada83882019-06-11 14:03:40 +040098 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29352File}", true, null, false)
99 }
100 catch (Exception ex) {
Denis Egorenkoe0c88432019-10-07 12:46:14 +0400101 common.infoMsg('Work-around for PROD-29352 already applied, nothing todo')
Denis Egorenkoada83882019-06-11 14:03:40 +0400102 return
103 }
104 def rKeysDict = [
105 'parameters': [
106 '_param': [
107 'root_private_key': salt.getPillar(venvPepper, 'I@salt:master', '_param:root_private_key').get('return')[0].values()[0].trim(),
108 'root_public_key' : '',
109 ]
110 ]
111 ]
112 // save root key,and generate public one from it
113 writeFile file: _tempFile, text: rKeysDict['parameters']['_param']['root_private_key'].toString().trim()
114 sh('chmod 0600 ' + _tempFile)
115 rKeysDict['parameters']['_param']['root_public_key'] = sh(script: "ssh-keygen -q -y -f ${_tempFile}", returnStdout: true).trim()
116 sh('rm -fv ' + _tempFile)
117 writeYaml file: _tempFile, data: rKeysDict
118 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
119 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29352File}", false, null, false)
120 common.infoMsg("Add $wa29352ClassName class into secrets.yml")
121
122 // Add 'classes:' directive
123 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
124 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
125
126 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
127 "grep -q '${wa29352ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29352ClassName' infra/secrets.yml")
128 salt.fullRefresh(venvPepper, '*')
129 sh('rm -fv ' + _tempFile)
Denis Egorenkoe0c88432019-10-07 12:46:14 +0400130 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " +
131 "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()}' ")
132 common.infoMsg('Work-around for PROD-29352 successfully applied')
Denis Egorenkoada83882019-06-11 14:03:40 +0400133}
134
135def wa29155(ArrayList saltMinions, String cname) {
136 // WA for PROD-29155. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/
137 // CHeck for existence cmp nodes, and try to render it. Is failed, apply ssh-key wa
Denis Egorenkoada83882019-06-11 14:03:40 +0400138 def patched = false
139 def wa29155ClassName = 'cluster.' + cname + '.infra.secrets_nova_wa29155'
140 def wa29155File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_nova_wa29155.yml"
141
142 try {
143 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29155File}", true, null, false)
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400144 def patch_required = false
145 for (String minion in saltMinions) {
146 def nova_key = salt.getPillar(venvPepper, minion, '_param:nova_compute_ssh_private').get("return")[0].values()[0]
147 if (nova_key == '' || nova_key == 'null' || nova_key == null) {
148 patch_required = true
149 break // no exception, proceeding to apply the patch
150 }
151 }
152 if (!patch_required) {
153 error('No need to apply work-around for PROD-29155')
154 }
Denis Egorenkoada83882019-06-11 14:03:40 +0400155 }
156 catch (Exception ex) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400157 return
158 }
Denis Egorenkoe983d452019-08-23 14:29:34 +0400159 salt.fullRefresh(venvPepper, 'I@salt:master')
Denis Egorenkoada83882019-06-11 14:03:40 +0400160 for (String minion in saltMinions) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400161 // First attempt, second will be performed in next validateReclassModel() stages
162 try {
163 salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
164 } catch (Exception e) {
165 common.errorMsg(e.toString())
166 if (patched) {
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400167 error("Node: ${minion} failed to render after reclass-system upgrade! WA29155 probably didn't help.")
Denis Egorenkoada83882019-06-11 14:03:40 +0400168 }
169 common.warningMsg('Perform: Attempt to apply WA for PROD-29155\n' +
170 'See https://gerrit.mcp.mirantis.com/#/c/37932/ for more info')
171 common.warningMsg('WA-PROD-29155 Generating new ssh key at master node')
172 def _tempFile = "/tmp/nova_wa29155_" + UUID.randomUUID().toString().take(8)
173 common.infoMsg('Perform: generation NEW ssh-private key for nova-compute')
174 salt.cmdRun(venvPepper, 'I@salt:master', "ssh-keygen -f ${_tempFile} -N '' -q")
175 def _pub_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}.pub").get('return')[0].values()[0].trim()
176 def _priv_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}").get('return')[0].values()[0].trim()
177 salt.cmdRun(venvPepper, 'I@salt:master', "rm -fv ${_tempFile}", false, null, false)
178 def novaKeysDict = [
179 "parameters": [
180 "_param": [
181 "nova_compute_ssh_private": _priv_k,
182 "nova_compute_ssh_public" : _pub_k
183 ]
184 ]
185 ]
186 writeYaml file: _tempFile, data: novaKeysDict
187 def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
188 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29155File}", false, null, false)
189 common.infoMsg("Add $wa29155ClassName class into secrets.yml")
190
191 // Add 'classes:' directive
192 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
193 "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml")
194
195 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " +
196 "grep -q '${wa29155ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29155ClassName' infra/secrets.yml")
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400197 salt.fullRefresh(venvPepper, 'I@salt:master')
198 salt.fullRefresh(venvPepper, saltMinions)
Denis Egorenkoada83882019-06-11 14:03:40 +0400199 patched = true
200 }
201 }
202 if (patched) {
203 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " +
204 "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()}' ")
205 common.infoMsg('Work-around for PROD-29155 successfully applied')
206 }
207
208}
209
Ivan Berezovskiy8699f3f2020-01-24 17:52:26 +0400210def wa32284(String cluster_name) {
Denis Egorenkobae9dc72019-07-29 17:44:46 +0400211 def clientGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:enabled").get("return")[0].values()[0]
212 def pkiGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:volumes:salt_pki").get("return")[0].values()[0]
213 def nginxEnabledAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0]
214 if (nginxEnabledAtMaster.toString().toLowerCase() == 'true' && clientGluster.toString().toLowerCase() == 'true' && pkiGluster) {
215 def nginxRequires = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:wait_for_service').get('return')[0].values()[0]
216 if (nginxRequires.isEmpty()) {
Ivan Berezovskiy8699f3f2020-01-24 17:52:26 +0400217 def nginxRequiresClassName = "cluster.${cluster_name}.infra.config.nginx_requires_wa32284"
218 def nginxRequiresClassFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/infra/config/nginx_requires_wa32284.yml"
Denis Egorenkobae9dc72019-07-29 17:44:46 +0400219 def nginxRequiresBlock = ['parameters': ['nginx': ['server': ['wait_for_service': ['srv-salt-pki.mount'] ] ] ] ]
220 def _tempFile = '/tmp/wa32284_' + UUID.randomUUID().toString().take(8)
221 writeYaml file: _tempFile , data: nginxRequiresBlock
222 def nginxRequiresBlockString = sh(script: "cat ${_tempFile}", returnStdout: true).trim()
Ivan Berezovskiy8699f3f2020-01-24 17:52:26 +0400223 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && " +
Denis Egorenkobae9dc72019-07-29 17:44:46 +0400224 "sed -i '/^parameters:/i - ${nginxRequiresClassName}' infra/config/init.yml")
225 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${nginxRequiresBlockString}' > ${nginxRequiresClassFile}", false, null, false)
Ivan Berezovskiy8699f3f2020-01-24 17:52:26 +0400226 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 +0400227 }
228 }
229}
230
Denis Egorenkoda117892019-09-02 14:53:02 +0400231def wa32182(String cluster_name) {
Hanna Arhipova644aefd2019-09-06 17:55:40 +0300232 if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) {
Denis Egorenkoda117892019-09-02 14:53:02 +0400233 def clusterModelPath = "/srv/salt/reclass/classes/cluster/${cluster_name}"
234 def fixFile = "${clusterModelPath}/opencontrail/common_wa32182.yml"
235 def usualFile = "${clusterModelPath}/opencontrail/common.yml"
236 def fixFileContent = "classes:\n- system.opencontrail.common\n"
237 salt.cmdRun(venvPepper, 'I@salt:master', "test -f ${fixFile} -o -f ${usualFile} || echo '${fixFileContent}' > ${fixFile}")
238 def contrailFiles = ['opencontrail/analytics.yml', 'opencontrail/control.yml', 'openstack/compute/init.yml']
239 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
240 contrailFiles.add('kubernetes/compute.yml')
241 }
Ivan Berezovskiye375e6a2020-02-05 21:18:17 +0400242 for (String contrailFile in contrailFiles) {
Denis Egorenkoda117892019-09-02 14:53:02 +0400243 contrailFile = "${clusterModelPath}/${contrailFile}"
244 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()
245 if (containsFix) {
246 continue
247 } else {
248 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 +0400249 "echo '- cluster.${cluster_name}.opencontrail.common_wa32182' >> ${contrailFile}")
Denis Egorenkoda117892019-09-02 14:53:02 +0400250 }
251 }
Ivan Berezovskiye375e6a2020-02-05 21:18:17 +0400252 salt.cmdRun(venvPepper, 'I@salt:master', "test -f ${fixFile} && cd ${clusterModelPath} && git status && git add ${fixFile} || true")
Denis Egorenkoda117892019-09-02 14:53:02 +0400253 }
254}
255
Denis Egorenko32461082019-10-25 13:13:39 +0400256def wa33867(String cluster_name) {
257 if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) {
258 def contrailControlFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/opencontrail/control.yml"
259 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()
260 if (line == "- cluster.${cluster_name}.infra") {
261 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra\$/d' ${contrailControlFile}")
262 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra.backup.client_zookeeper\$/i - cluster.${cluster_name}.infra' ${contrailControlFile}")
263 }
264 }
265}
266
Denis Egorenko7e934c22019-10-18 17:06:11 +0400267def wa33771(String cluster_name) {
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400268 if (salt.getMinions(venvPepper, 'I@_param:openstack_node_role and I@apache:server')) {
269 def octaviaEnabled = salt.getMinions(venvPepper, 'I@octavia:api:enabled')
270 def octaviaWSGI = salt.getMinions(venvPepper, 'I@apache:server:site:octavia_api')
271 if (octaviaEnabled && !octaviaWSGI) {
272 def openstackControl = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/control.yml"
273 def octaviaFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/octavia_wa33771.yml"
274 def octaviaContext = [
275 'classes' : ['system.apache.server.site.octavia'],
276 'parameters': [
277 '_param': ['apache_octavia_api_address': '${_param:cluster_local_address}'],
278 ]
Denis Egorenko7e934c22019-10-18 17:06:11 +0400279 ]
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400280 def openstackHTTPSEnabled = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_internal_protocol").get("return")[0].values()[0]
281 if (openstackHTTPSEnabled == 'https') {
282 octaviaContext['parameters'] << ['apache': ['server': ['site': ['apache_proxy_openstack_api_octavia': ['enabled': false]]]]]
283 }
284 def _tempFile = '/tmp/wa33771' + UUID.randomUUID().toString().take(8)
285 writeYaml file: _tempFile, data: octaviaContext
286 def octaviaFileContent = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
287 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.octavia_wa33771' ${openstackControl}")
288 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${octaviaFileContent}' | base64 -d > ${octaviaFile}", false, null, false)
289 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 +0400290 }
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400291 } else {
292 common.warningMsg("Apache server is not defined on controller nodes. Skipping Octavia WSGI workaround");
Denis Egorenko7e934c22019-10-18 17:06:11 +0400293 }
294}
295
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400296def wa33930_33931(String cluster_name) {
297 def openstackControlFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/control.yml"
298 def fixName = 'clients_common_wa33930_33931'
299 def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/${fixName}.yml"
300 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()
301 if (! containsFix) {
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400302 def fixContext = [ 'classes': [ ] ]
303 def novaControllerNodes = salt.getMinions(venvPepper, 'I@nova:controller')
304 for (novaController in novaControllerNodes) {
305 def novaClientPillar = salt.getPillar(venvPepper, novaController, "nova:client").get("return")[0].values()[0]
306 if (novaClientPillar == '' || novaClientPillar == 'null' || novaClientPillar == null) {
307 fixContext['classes'] << 'service.nova.client'
308 break
309 }
310 }
311 def glanceServerNodes = salt.getMinions(venvPepper, 'I@glance:server')
312 for (glanceServer in glanceServerNodes) {
313 def glanceClientPillar = salt.getPillar(venvPepper, glanceServer, "glance:client").get("return")[0].values()[0]
314 if (glanceClientPillar == '' || glanceClientPillar == 'null' || glanceClientPillar == null) {
315 fixContext['classes'] << 'service.glance.client'
316 break
317 }
318 }
319 def neutronServerNodes = salt.getMinions(venvPepper, 'I@neutron:server')
320 for (neutronServer in neutronServerNodes) {
321 def neutronServerPillar = salt.getPillar(venvPepper, neutronServer, "neutron:client").get("return")[0].values()[0]
322 if (neutronServerPillar == '' || neutronServerPillar == 'null' || neutronServerPillar == null) {
323 fixContext['classes'] << 'service.neutron.client'
324 break
325 }
326 }
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400327 if (salt.getMinions(venvPepper, 'I@manila:api:enabled')) {
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400328 def manilaApiNodes = salt.getMinions(venvPepper, 'I@manila:api')
329 for (manilaNode in manilaApiNodes) {
330 def manilaNodePillar = salt.getPillar(venvPepper, manilaNode, "manila:client").get("return")[0].values()[0]
331 if (manilaNodePillar == '' || manilaNodePillar == 'null' || manilaNodePillar == null) {
332 fixContext['classes'] << 'service.manila.client'
333 break
334 }
335 }
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400336 }
337 if (salt.getMinions(venvPepper, 'I@ironic:api:enabled')) {
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400338 def ironicApiNodes = salt.getMinions(venvPepper, 'I@ironic:api')
339 for (ironicNode in ironicApiNodes) {
340 def ironicNodePillar = salt.getPillar(venvPepper, ironicNode, "ironic:client").get("return")[0].values()[0]
341 if (ironicNodePillar == '' || ironicNodePillar == 'null' || ironicNodePillar == null) {
342 fixContext['classes'] << 'service.ironic.client'
343 break
344 }
345 }
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400346 }
347 if (salt.getMinions(venvPepper, 'I@gnocchi:server:enabled')) {
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400348 def gnocchiServerNodes = salt.getMinions(venvPepper, 'I@gnocchi:server')
349 for (gnocchiNode in gnocchiServerNodes) {
350 def gnocchiNodePillar = salt.getPillar(venvPepper, gnocchiNode, "gnocchi:client").get("return")[0].values()[0]
351 if (gnocchiNodePillar == '' || gnocchiNodePillar == 'null' || gnocchiNodePillar == null) {
352 fixContext['classes'] << 'service.gnocchi.client'
353 break
354 }
355 }
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400356 }
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400357
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400358 if (salt.getMinions(venvPepper, 'I@barbican:server:enabled')) {
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400359 def barbicanServerNodes = salt.getMinions(venvPepper, 'I@barbican:server')
360 for (barbicanNode in barbicanServerNodes) {
361 def barbicanNodePillar = salt.getPillar(venvPepper, barbicanNode, "barbican:client").get("return")[0].values()[0]
362 if (barbicanNodePillar == '' || barbicanNodePillar == 'null' || barbicanNodePillar == null) {
363 fixContext['classes'] << 'service.barbican.client.single'
364 break
365 }
366 }
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400367 }
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400368 if (fixContext['classes'] != []) {
369 def _tempFile = '/tmp/wa33930_33931' + UUID.randomUUID().toString().take(8)
370 writeYaml file: _tempFile, data: fixContext
371 def fixFileContent = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim()
372 salt.cmdRun(venvPepper, 'I@salt:master', "echo '${fixFileContent}' | base64 -d > ${fixFile}", false, null, false)
373 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.${fixName}' ${openstackControlFile}")
374 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${fixFile}")
375 }
Denis Egorenko4ac89a32019-11-14 19:56:17 +0400376 }
377}
378
Denis Egorenkodb450152020-01-28 16:41:44 +0400379def wa34245(cluster_name) {
380 def infraInitFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/infra/init.yml"
381 def fixName = 'hosts_wa34245'
382 def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/infra/${fixName}.yml"
383 if (salt.testTarget(venvPepper, 'I@keystone:server')) {
384 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()
385 if (!fixApplied) {
386 def fixFileContent = []
387 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()
388 if (!containsFix) {
389 fixFileContent << '- system.linux.network.hosts.openstack'
390 }
391 if (salt.testTarget(venvPepper, 'I@gnocchi:server')) {
392 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()
393 if (!containsFix) {
394 fixFileContent << '- system.linux.network.hosts.openstack.telemetry'
395 }
396 }
397 if (salt.testTarget(venvPepper, 'I@manila:api')) {
398 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()
399 if (!containsFix) {
400 fixFileContent << '- system.linux.network.hosts.openstack.share'
401 }
402 }
403 if (salt.testTarget(venvPepper, 'I@barbican:server')) {
404 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()
405 if (!containsFix) {
406 fixFileContent << '- system.linux.network.hosts.openstack.kmn'
407 }
408 }
409 if (fixFileContent) {
410 salt.cmdRun(venvPepper, 'I@salt:master', "echo 'classes:\n${fixFileContent.join('\n')}' > ${fixFile}")
411 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.infra.${fixName}' ${infraInitFile}")
Ivan Berezovskiy8699f3f2020-01-24 17:52:26 +0400412 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 +0400413 }
414 }
415 }
416}
417
Ivan Berezovskiy8699f3f2020-01-24 17:52:26 +0400418def wa34528(String cluster_name) {
419 // Mysql users have to be defined on each Galera node
420 if(salt.getMinions(venvPepper, 'I@galera:master').isEmpty()) {
421 common.errorMsg('No Galera master found in cluster. Skipping')
422 return
423 }
424 def mysqlUsersMasterPillar = salt.getPillar(venvPepper, 'I@galera:master', 'mysql:server:database').get("return")[0].values()[0]
425 if (mysqlUsersMasterPillar == '' || mysqlUsersMasterPillar == 'null' || mysqlUsersMasterPillar == null) {
426 common.errorMsg('Pillar data is broken for Galera master node!')
427 input message: 'Do you want to ignore and continue without Galera pillar patch?'
428 return
429 }
430 def fileToPatch = salt.cmdRun(venvPepper, 'I@salt:master', "ls /srv/salt/reclass/classes/cluster/${cluster_name}/openstack/database/init.yml || " +
431 "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()
432 if (fileToPatch == 'File not found') {
433 common.errorMsg('Cluster model is old and cannot be patched for PROD-34528. Patching is possible for 2019.2.x cluster models only')
434 return
435 }
436 def patchRequired = false
437 def mysqlUsersSlavePillar = ''
438 def galeraSlaveNodes = salt.getMinions(venvPepper, 'I@galera:slave')
439 if (!galeraSlaveNodes.isEmpty()) {
440 for (galeraSlave in galeraSlaveNodes) {
441 mysqlUsersSlavePillar = salt.getPillar(venvPepper, galeraSlave, 'mysql:server:database').get("return")[0].values()[0]
442 if (mysqlUsersSlavePillar == '' || mysqlUsersSlavePillar == 'null' || mysqlUsersSlavePillar == null) {
443 common.errorMsg('Mysql users data is not defined for Galera slave nodes. Fixing...')
444 patchRequired = true
445 break
446 }
447 }
448 if (patchRequired) {
449 def fixFileContent = []
450 def fixName = 'db_wa34528'
451 def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/database/${fixName}.yml"
452 for (dbName in mysqlUsersMasterPillar.keySet()) {
453 def classIncluded = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- system\\.galera\\.server\\.database\\.${dbName}\$'" +
454 " /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()
455 if(classIncluded) {
456 fixFileContent << "- system.galera.server.database.${dbName}"
457 }
458 def sslClassIncluded = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- system\\.galera\\.server\\.database\\.x509\\.${dbName}\$'" +
459 " /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()
460 if(sslClassIncluded) {
461 fixFileContent << "- system.galera.server.database.x509.${dbName}"
462 }
463 }
464 if (fixFileContent) {
465 salt.cmdRun(venvPepper, 'I@salt:master', "echo 'classes:\n${fixFileContent.join('\n')}' > ${fixFile}")
466 salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.database.${fixName}' ${fileToPatch}")
467 }
468 salt.fullRefresh(venvPepper, 'I@galera:slave')
469 // Verify
470 for (galeraSlave in galeraSlaveNodes) {
471 mysqlUsersSlavePillar = salt.getPillar(venvPepper, galeraSlave, 'mysql:server:database').get("return")[0].values()[0]
472 if (mysqlUsersSlavePillar == '' || mysqlUsersSlavePillar == 'null' || mysqlUsersSlavePillar == null || mysqlUsersSlavePillar.keySet() != mysqlUsersMasterPillar.keySet()) {
473 common.errorMsg("Mysql user data is different on master and slave node ${galeraSlave}.")
474 input message: 'Do you want to ignore and continue?'
475 }
476 }
477 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${fixFile}")
478 common.infoMsg('Galera slaves patching is done')
479 } else {
480 common.infoMsg('Galera slaves patching is not required')
481 }
482 }
483}
484
azvyagintsev6dac3802018-11-09 15:11:30 +0200485def archiveReclassInventory(filename) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400486 def _tmp_file = '/tmp/' + filename + UUID.randomUUID().toString().take(8)
487 // jenkins may fail at overheap. Compress data with gzip like WA
488 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()
489 def _tmp = sh(script: "echo '$ret' > ${_tmp_file}", returnStdout: false)
490 sh(script: "cat ${_tmp_file} | base64 -d | gzip -d > $filename", returnStdout: false)
491 archiveArtifacts artifacts: filename
492 sh(script: "rm -v ${_tmp_file}|| true")
Richard Felkl0e80d892018-06-20 13:44:54 +0200493}
494
Denis Egorenkod13ad132018-12-17 16:56:02 +0400495def validateReclassModel(ArrayList saltMinions, String suffix) {
496 try {
Denis Egorenkoada83882019-06-11 14:03:40 +0400497 for (String minion in saltMinions) {
498 common.infoMsg("Reclass model validation for minion ${minion}...")
499 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()
500 writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString()
Denis Egorenkod13ad132018-12-17 16:56:02 +0400501 }
502 } catch (Exception e) {
503 common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.')
Denis Egorenkoada83882019-06-11 14:03:40 +0400504 error(e.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400505 }
506}
507
Denis Egorenkoada83882019-06-11 14:03:40 +0400508def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix = 'before', String newSuffix = 'after') {
509 for (String minion in saltMinions) {
510 def fileName = "reclass-model-${minion}-diff.out"
511 sh "diff -u inventory-${minion}-${oldSuffix}.out inventory-${minion}-${newSuffix}.out > ${fileName} || true"
512 archiveArtifacts artifacts: "${fileName}"
Denis Egorenkod13ad132018-12-17 16:56:02 +0400513 }
514}
515
Denis Egorenkobf390102020-01-24 19:47:05 +0400516def checkCICDDocker() {
517 common.infoMsg('Perform: Checking if Docker containers are up')
518 try {
519 common.retry(10, 30) {
520 salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'")
521 }
522 }
523 catch (Exception ex) {
524 error("Docker containers for CI/CD services are having troubles with starting.")
525 }
526}
527
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400528if (common.validInputParam('PIPELINE_TIMEOUT')) {
529 try {
530 pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger()
Denis Egorenkoada83882019-06-11 14:03:40 +0400531 } catch (Exception e) {
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400532 common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger")
533 }
Martin Polreich965c9032018-08-09 16:33:57 +0200534}
535
536timeout(time: pipelineTimeout, unit: 'HOURS') {
Denis Egorenkoada83882019-06-11 14:03:40 +0400537 node("python") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100538 try {
Denis Egorenkoada83882019-06-11 14:03:40 +0400539 def inventoryBeforeFilename = "reclass-inventory-before.out"
540 def inventoryAfterFilename = "reclass-inventory-after.out"
Richard Felkl0e80d892018-06-20 13:44:54 +0200541 workspace = common.getWorkspace()
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200542 targetMcpVersion = null
543 if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) {
544 error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable')
azvyagintsev6dac3802018-11-09 15:11:30 +0200545 }
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200546 // bw comp. for 2018.X => 2018.11 release
Denis Egorenkoada83882019-06-11 14:03:40 +0400547 if (common.validInputParam('MCP_VERSION')) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200548 targetMcpVersion = env.MCP_VERSION
549 common.warningMsg("targetMcpVersion has been changed to:${targetMcpVersion}, which was taken from deprecated pipeline viriable:MCP_VERSION")
Denis Egorenkoada83882019-06-11 14:03:40 +0400550 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200551 targetMcpVersion = env.TARGET_MCP_VERSION
552 }
553 // end bw comp. for 2018.X => 2018.11 release
Denis Egorenkod13ad132018-12-17 16:56:02 +0400554 def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC')
Ivan Berezovskiyd62629c2019-01-16 19:26:18 +0400555 if (targetMcpVersion in ['nightly', 'testing']) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200556 gitTargetMcpVersion = 'master'
Ivan Berezovskiyd62629c2019-01-16 19:26:18 +0400557 } else if (targetMcpVersion == 'proposed') {
558 gitTargetMcpVersion = 'proposed'
Denis Egorenko284690e2018-12-25 15:55:12 +0400559 } else if (!gitTargetMcpVersion) {
560 // backward compatibility for 2018.11.0
561 gitTargetMcpVersion = "release/${targetMcpVersion}"
azvyagintsev6dac3802018-11-09 15:11:30 +0200562 }
Ivan Berezovskiyd62629c2019-01-16 19:26:18 +0400563 common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}")
Denis Egorenko284690e2018-12-25 15:55:12 +0400564 def upgradeSaltStack = ''
565 def updateClusterModel = ''
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400566 def applyWorkarounds = true
Denis Egorenko284690e2018-12-25 15:55:12 +0400567 def updatePipelines = ''
568 def updateLocalRepos = ''
569 def reclassSystemBranch = ''
Denis Egorenkob559e542019-03-29 13:24:15 +0400570 def reclassSystemBranchDefault = gitTargetMcpVersion
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400571 if (gitTargetMcpVersion ==~ /^\d\d\d\d\.\d\d?\.\d+$/) {
572 reclassSystemBranchDefault = "tags/${gitTargetMcpVersion}"
573 } else if (gitTargetMcpVersion != 'proposed') {
Denis Egorenkob559e542019-03-29 13:24:15 +0400574 reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}"
575 }
Hanna Arhipova644aefd2019-09-06 17:55:40 +0300576 def driveTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS')
577 if (driveTrainParamsYaml) {
578 def driveTrainParams = readYaml text: driveTrainParamsYaml
579 saltMastURL = driveTrainParams.get('SALT_MASTER_URL')
580 saltMastCreds = driveTrainParams.get('SALT_MASTER_CREDENTIALS')
581 upgradeSaltStack = driveTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean()
582 updateClusterModel = driveTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean()
583 updatePipelines = driveTrainParams.get('UPDATE_PIPELINES', false).toBoolean()
584 updateLocalRepos = driveTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean()
585 reclassSystemBranch = driveTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault)
Denis Egorenko70002bc2019-08-19 19:41:27 +0400586 batchSize = driveTrainParams.get('BATCH_SIZE', '')
Denis Egorenkobf390102020-01-24 19:47:05 +0400587 if (driveTrainParams.get('OS_DIST_UPGRADE', false).toBoolean() == true) {
588 packageUpgradeMode = 'dist-upgrade'
589 } else if (driveTrainParams.get('OS_UPGRADE', false).toBoolean() == true) {
590 packageUpgradeMode = 'upgrade'
591 }
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400592 applyWorkarounds = driveTrainParams.get('APPLY_MODEL_WORKAROUNDS', true).toBoolean()
Denis Egorenko284690e2018-12-25 15:55:12 +0400593 } else {
594 // backward compatibility for 2018.11.0
595 saltMastURL = env.getProperty('SALT_MASTER_URL')
596 saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS')
Denis Egorenkoe5f39142018-12-28 12:30:48 +0400597 upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean()
598 updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean()
599 updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean()
600 updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean()
Denis Egorenkob559e542019-03-29 13:24:15 +0400601 reclassSystemBranch = reclassSystemBranchDefault
Denis Egorenko284690e2018-12-25 15:55:12 +0400602 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400603 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400604 def minions = salt.getMinions(venvPepper, '*')
Denis Egorenkoc0538ce2019-04-19 15:05:18 +0400605 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
606 if (cluster_name == '' || cluster_name == 'null' || cluster_name == null) {
607 error('Pillar data is broken for Salt master node! Please check it manually and re-run pipeline.')
608 }
Hanna Arhipova644aefd2019-09-06 17:55:40 +0300609 if (!batchSize) {
Denis Egorenko9ef25b92019-12-19 16:45:25 +0400610 // if no batch size provided get current worker threads and set batch size to 2/3 of it to avoid
611 // 'SaltReqTimeoutError: Message timed out' issue on Salt targets for large amount of nodes
612 // do not use toDouble/Double as it requires additional approved method
613 def workerThreads = getWorkerThreads(venvPepper).toInteger()
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400614 batchSize = (workerThreads * 2 / 3).toString().tokenize('.')[0]
Denis Egorenko70002bc2019-08-19 19:41:27 +0400615 }
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400616 def computeMinions = salt.getMinions(venvPepper, 'I@nova:compute')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400617
Denis Egorenkoada83882019-06-11 14:03:40 +0400618 stage('Update Reclass and Salt-Formulas') {
619 common.infoMsg('Perform: Full salt sync')
620 salt.fullRefresh(venvPepper, '*')
621 common.infoMsg('Perform: Validate reclass medata before processing')
622 validateReclassModel(minions, 'before')
623
624 common.infoMsg('Perform: archiveReclassInventory before upgrade')
Denis Egorenko89a3c572019-03-22 17:03:40 +0400625 archiveReclassInventory(inventoryBeforeFilename)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400626
azvyagintsev6dac3802018-11-09 15:11:30 +0200627 try {
Denis Egorenkoada83882019-06-11 14:03:40 +0400628 salt.cmdRun(venvPepper, 'I@salt:master', 'cd /srv/salt/reclass/ && git status && git diff-index --quiet HEAD --')
Richard Felkl970e0082018-06-12 18:00:51 +0200629 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200630 catch (Exception ex) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400631 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 +0200632 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400633 if (updateClusterModel) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200634 common.infoMsg('Perform: UPDATE_CLUSTER_MODEL')
Sergey382581a2018-10-25 12:22:26 +0400635 def dateTime = common.getDatetime()
Ivan Berezovskiy1d780522020-01-17 13:55:18 +0400636 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git fetch")
Sergey382581a2018-10-25 12:22:26 +0400637 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400638 "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 +0200639 // Do the same, for deprecated variable-duplicate
640 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400641 "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 +0400642 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400643 "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 +0400644 // Set new k8s param
645 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
646 "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 +0400647 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
648 "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'")
649 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoca871c22019-02-13 13:49:13 +0400650 "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 +0400651 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoca871c22019-02-13 13:49:13 +0400652 "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 +0400653 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoada83882019-06-11 14:03:40 +0400654 "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 +0400655
Denis Egorenko70f4f9a2019-09-16 16:41:26 +0400656 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")
657 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name/infra && sed -i '/maas_region_main_archive/d' maas.yml")
658
Denis Egorenko6ca9f0d2019-07-10 19:47:39 +0400659 // Switch Jenkins/Gerrit to use LDAP SSL/TLS
660 def gerritldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
661 "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()
662 if (gerritldapURI.startsWith('ldap://')) {
663 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
664 "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
665 } else if (! gerritldapURI.startsWith('ldaps://')) {
666 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
667 "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'")
668 }
669 def jenkinsldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
670 "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()
671 if (jenkinsldapURI.startsWith('ldap://')) {
672 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
673 "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
674 } else if (! jenkinsldapURI.startsWith('ldaps://')) {
675 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
676 "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'")
677 }
678
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400679 if (applyWorkarounds) {
680 wa32284(cluster_name)
681 wa34245(cluster_name)
682 }
Denis Egorenkobae9dc72019-07-29 17:44:46 +0400683
Denis Egorenkod13ad132018-12-17 16:56:02 +0400684 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}")
Sergey Kolekonov6ab15112019-01-23 16:47:43 +0400685 // Add kubernetes-extra repo
686 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
Sergey Kolekonovac9554c2019-04-11 16:33:54 +0400687 // docker-engine conflicts with the recent containerd versions, so it's removed during upgrade. Thus update source engine
688 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
689 "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 +0400690 common.infoMsg("Add kubernetes-extra repo")
691 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
692 "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")
693 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
694 "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")
695 }
Ivan Berezovskiybe630ee2019-04-15 13:23:58 +0400696 // Add all update repositories
697 def repoIncludeBase = '- system.linux.system.repo.mcp.apt_mirantis.'
Denis Egorenko70f4f9a2019-09-16 16:41:26 +0400698 def updateRepoList = ['cassandra', 'ceph', 'contrail', 'docker', 'elastic', 'extra', 'openstack', 'maas', 'percona', 'salt-formulas', 'saltstack', 'ubuntu']
Ivan Berezovskiybe630ee2019-04-15 13:23:58 +0400699 updateRepoList.each { repo ->
700 def repoNameUpdateInclude = "${repoIncludeBase}update.${repo}"
701 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')
702 filesWithInclude.each { file ->
703 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()
704 if (updateRepoIncludeExist == 'not_found') {
705 // Include needs to be added
706 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoada83882019-06-11 14:03:40 +0400707 "sed -i 's/\\( *\\)${repoIncludeBase}${repo}\$/&\\n\\1${repoNameUpdateInclude}/g' ${file}")
Ivan Berezovskiybe630ee2019-04-15 13:23:58 +0400708 common.infoMsg("Update repo for ${repo} is added to ${file}")
709 }
710 }
711 }
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400712 if (applyWorkarounds) {
713 wa32182(cluster_name)
714 wa33771(cluster_name)
715 wa33867(cluster_name)
716 wa33930_33931(cluster_name)
717 wa34528(cluster_name)
718 }
Sergey382581a2018-10-25 12:22:26 +0400719 // Add new defaults
720 common.infoMsg("Add new defaults")
Denis Egorenkod13ad132018-12-17 16:56:02 +0400721 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 +0400722 "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 +0400723 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 +0400724 "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 +0400725 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
726 "grep -r -l 'docker_image_jenkins: .*' cicd | xargs --no-run-if-empty sed -i 's|\\s*docker_image_jenkins: .*||g'")
727 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
728 "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 +0400729 common.infoMsg("The following changes were made to the cluster model and will be commited. " +
azvyagintsev6dac3802018-11-09 15:11:30 +0200730 "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 +0400731 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff")
732 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " +
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200733 "git add -u && git commit --allow-empty -m 'Cluster model update to the release $targetMcpVersion on $dateTime'")
Sergey382581a2018-10-25 12:22:26 +0400734 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400735 try {
736 common.infoMsg('Perform: UPDATE Salt Formulas')
Denis Egorenkoada83882019-06-11 14:03:40 +0400737 salt.fullRefresh(venvPepper, '*')
738 salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400739 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 +0400740 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas", 'salt.master.env'])
741 salt.fullRefresh(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400742 } catch (Exception updateErr) {
743 common.warningMsg(updateErr)
744 common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
745 input message: 'Continue anyway?'
746 }
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400747 if (applyWorkarounds) {
748 wa29352(cluster_name)
749 wa29155(computeMinions, cluster_name)
750 }
Denis Egorenkoada83882019-06-11 14:03:40 +0400751
Denis Egorenkod13ad132018-12-17 16:56:02 +0400752 try {
753 common.infoMsg('Perform: UPDATE Reclass package')
754 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"])
755 } catch (Exception updateErr) {
756 common.warningMsg(updateErr)
757 common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
758 input message: 'Continue anyway?'
759 }
760
761 salt.fullRefresh(venvPepper, 'I@salt:master')
Sergey1b81c062018-10-16 17:10:21 +0400762 salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true)
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400763 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && " +
764 "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 +0400765 try {
766 salt.enforceState(venvPepper, "I@salt:master", 'reclass', true)
767 }
768 catch (Exception ex) {
769 error("Reclass fails rendering. Pay attention to your cluster model.")
770 }
771
772 salt.fullRefresh(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400773 try {
774 salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top")
775 }
776 catch (Exception ex) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400777
778 error('Reclass fails rendering. Pay attention to your cluster model.' +
779 'ErrorMessage:' + ex.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400780 }
781
Denis Egorenkoada83882019-06-11 14:03:40 +0400782 common.infoMsg('Perform: archiveReclassInventory AFTER upgrade')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400783 archiveReclassInventory(inventoryAfterFilename)
784
785 sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true"
786 archiveArtifacts artifacts: "reclass-inventory-diff.out"
787
Denis Egorenkoada83882019-06-11 14:03:40 +0400788 validateReclassModel(minions, 'after')
789 archiveReclassModelChanges(minions)
Jakub Josefa63f9862018-01-11 17:58:38 +0100790 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100791
Denis Egorenkod13ad132018-12-17 16:56:02 +0400792 if (updateLocalRepos) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200793 stage("Update local repos") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100794 common.infoMsg("Updating local repositories")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700795
Sergey1b81c062018-10-16 17:10:21 +0400796 def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700797 runningOnDocker = engine.get("return")[0].containsValue("docker")
798
799 if (runningOnDocker) {
800 common.infoMsg("Aptly is running as Docker container")
azvyagintsev6dac3802018-11-09 15:11:30 +0200801 } else {
Sam Stoelingaaab79702018-04-09 18:49:39 -0700802 common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands")
803 }
804
azvyagintsev6dac3802018-11-09 15:11:30 +0200805 if (runningOnDocker) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200806 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 +0200807 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200808 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 +0100809 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100810
Sergey1b81c062018-10-16 17:10:21 +0400811 salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100812
azvyagintsev6dac3802018-11-09 15:11:30 +0200813 if (runningOnDocker) {
Sergey1b81c062018-10-16 17:10:21 +0400814 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true)
815 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 +0200816 } else {
Sergey1b81c062018-10-16 17:10:21 +0400817 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true)
818 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 +0100819 }
Richard Felkl79d7df12018-01-05 16:40:11 +0100820
Sergey1b81c062018-10-16 17:10:21 +0400821 salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100822
Sergey1b81c062018-10-16 17:10:21 +0400823 salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100824
Sergey1b81c062018-10-16 17:10:21 +0400825 salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100826
Sergey1b81c062018-10-16 17:10:21 +0400827 salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100828 }
829 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100830
Denis Egorenkoada83882019-06-11 14:03:40 +0400831 stage('Update Drivetrain') {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400832 if (upgradeSaltStack) {
833 updateSaltStack("I@salt:master", '["salt-master", "salt-common", "salt-api", "salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200834
Denis Egorenko70002bc2019-08-19 19:41:27 +0400835 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.repo', true, true, batchSize)
Richard Felkl0e80d892018-06-20 13:44:54 +0200836 updateSaltStack("I@salt:minion and not I@salt:master", '["salt-minion"]')
837 }
838
Denis Egorenkod13ad132018-12-17 16:56:02 +0400839 if (updatePipelines) {
Denis Egorenkoada83882019-06-11 14:03:40 +0400840 common.infoMsg('Perform: UPDATE git repos')
841 triggerMirrorJob('git-mirror-downstream-mk-pipelines', reclassSystemBranch)
842 triggerMirrorJob('git-mirror-downstream-pipeline-library', reclassSystemBranch)
Richard Felkl970e0082018-06-12 18:00:51 +0200843 }
844
Denis Egorenkod00c17e2019-04-25 20:17:27 +0400845 // update minions certs
Denis Egorenko70002bc2019-08-19 19:41:27 +0400846 salt.enforceState(venvPepper, "I@salt:minion", 'salt.minion.cert', true, true, batchSize)
Denis Egorenkoada83882019-06-11 14:03:40 +0400847
Ivan Berezovskiycac04e42020-02-17 17:08:47 +0400848 // run `salt.minion` to refresh all minion configs (for example _keystone.conf)
849 salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion', true, true, batchSize, false, 60, 2)
Denis Egorenkoada83882019-06-11 14:03:40 +0400850 // Retry needed only for rare race-condition in user appearance
851 common.infoMsg('Perform: updating users and keys')
Denis Egorenko70002bc2019-08-19 19:41:27 +0400852 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.user', true, true, batchSize)
Denis Egorenkoada83882019-06-11 14:03:40 +0400853 common.infoMsg('Perform: updating openssh')
Denis Egorenko70002bc2019-08-19 19:41:27 +0400854 salt.enforceState(venvPepper, "I@linux:system", 'openssh', true, true, batchSize)
Denis Egorenkoaeaa1de2019-01-15 11:58:12 +0400855
Denis Egorenkoe69920e2019-10-30 13:26:59 +0400856 // 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
857 def gerritGlusterPath = salt.getPillar(venvPepper, 'I@gerrit:client', 'glusterfs:client:volumes:gerrit:path').get('return')[0].values()[0]
858 def wrongPluginJarName = "${gerritGlusterPath}/plugins/project-download-commands.jar"
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400859 salt.cmdRun(venvPepper, 'I@gerrit:client', "test -f ${wrongPluginJarName} && rm ${wrongPluginJarName} || true")
Denis Egorenkoe69920e2019-10-30 13:26:59 +0400860
Denis Egorenkoada83882019-06-11 14:03:40 +0400861 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 +0400862 }
863 }
864 catch (Throwable e) {
865 // If there was an error or exception thrown, the build failed
866 currentBuild.result = "FAILURE"
867 throw e
868 }
869 }
870 // docker.client state may trigger change of jenkins master or jenkins slave services,
871 // so we need wait for slave to reconnect and continue pipeline
872 sleep(180)
Denis Egorenkobf390102020-01-24 19:47:05 +0400873 def cidNodes = []
Ivan Berezovskiy24b0be02019-12-11 15:31:10 +0400874 node('python') {
875 try {
876 stage('Update Drivetrain: Phase 2') {
877 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenkobf390102020-01-24 19:47:05 +0400878 checkCICDDocker()
Denis Egorenko6ca9f0d2019-07-10 19:47:39 +0400879
Ivan Berezovskiy304705c2019-12-03 18:49:09 +0400880 // Apply changes for HaProxy on CI/CD nodes
881 salt.enforceState(venvPepper, 'I@keepalived:cluster:instance:cicd_control_vip and I@haproxy:proxy', 'haproxy.proxy', true)
882
883 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 +0400884
885 // update Nginx proxy settings for Jenkins/Gerrit if needed
886 if (salt.testTarget(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit')) {
887 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)
888 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100889 }
Denis Egorenkobf390102020-01-24 19:47:05 +0400890 if (packageUpgradeMode) {
891 cidNodes = salt.getMinions(venvPepper, 'I@_param:drivetrain_role:cicd')
892 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100893 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100894 catch (Throwable e) {
895 // If there was an error or exception thrown, the build failed
896 currentBuild.result = "FAILURE"
897 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +0100898 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100899 }
Denis Egorenkobf390102020-01-24 19:47:05 +0400900
901 stage('Upgrade OS') {
902 if (packageUpgradeMode) {
903 def debian = new com.mirantis.mk.Debian()
904 def statusFile = '/tmp/rebooted_during_upgrade'
905 for(cidNode in cidNodes) {
906 node('python') {
907 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
908 // cmd.run async to prevent connection close in case of slave shutdown, give 5 seconds to handle request response
909 salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${cidNode}' cmd.run 'sleep 5; touch ${statusFile}; salt-call service.stop docker' --async")
910 }
911 sleep(30)
912 node('python') {
913 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
914 debian.osUpgradeNode(venvPepper, cidNode, packageUpgradeMode, false, 60)
915 salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': cidNode, wait: 60, timeout: 10])
916 if (salt.runSaltProcessStep(venvPepper, cidNode, 'file.file_exists', [statusFile], null, true, 5)['return'][0].values()[0].toBoolean()) {
917 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
918 sleep(10)
919 }
920 checkCICDDocker()
921 }
922 }
923 } else {
924 common.infoMsg('Upgrade OS skipped...')
925 }
926 }
Hanna Arhipova644aefd2019-09-06 17:55:40 +0300927}