blob: 9a87c94c34e164eedf9718a91da0838a283ae410 [file] [log] [blame]
Richard Felkl26cae4d2017-12-19 00:19:16 +01001/**
2 *
3 * Update Salt environment pipeline
4 *
5 * Expected parameters:
azvyagintsev6dac3802018-11-09 15:11:30 +02006 * TARGET_MCP_VERSION Version of MCP to upgrade to
Denis Egorenkod13ad132018-12-17 16:56:02 +04007 * GIT_REFSPEC Git repo ref to be used
8 * DRIVE_TRAIN_PARAMS Yaml, DriveTrain releated params:
9 * SALT_MASTER_URL Salt API server location
10 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040011 * BATCH_SIZE Use batch sizing during upgrade for large envs
Denis Egorenkod13ad132018-12-17 16:56:02 +040012 * UPGRADE_SALTSTACK Upgrade SaltStack packages to new version.
13 * UPDATE_CLUSTER_MODEL Update MCP version parameter in cluster model
14 * UPDATE_PIPELINES Update pipeline repositories on Gerrit
15 * UPDATE_LOCAL_REPOS Update local repositories
Ivan Berezovskiy22390f62020-02-17 17:08:47 +040016 * OS_UPGRADE Run apt-get upgrade on Drivetrain nodes
17 * OS_DIST_UPGRADE Run apt-get dist-upgrade on Drivetrain nodes and reboot to apply changes
18 * APPLY_MODEL_WORKAROUNDS Whether to apply cluster model workarounds from the pipeline
Richard Felkl26cae4d2017-12-19 00:19:16 +010019 */
20
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010021salt = new com.mirantis.mk.Salt()
22common = new com.mirantis.mk.Common()
23python = new com.mirantis.mk.Python()
Richard Felkl970e0082018-06-12 18:00:51 +020024jenkinsUtils = new com.mirantis.mk.JenkinsUtils()
azvyagintsevf3bf77a2018-11-15 19:30:04 +020025def pipelineTimeout = 12
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010026venvPepper = "venvPepper"
Richard Felkl0e80d892018-06-20 13:44:54 +020027workspace = ""
Ivan Berezovskiya766d432019-12-11 15:31:10 +040028def saltMastURL = ''
29def saltMastCreds = ''
Denis Egorenko96cc57d2020-01-24 19:47:05 +040030def packageUpgradeMode = ''
Ivan Berezovskiy22390f62020-02-17 17:08:47 +040031batchSize = ''
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010032
azvyagintsevbc359d42019-04-10 19:53:22 +030033def triggerMirrorJob(String jobName, String reclassSystemBranch) {
Richard Felkl970e0082018-06-12 18:00:51 +020034 params = jenkinsUtils.getJobParameters(jobName)
azvyagintsevbc359d42019-04-10 19:53:22 +030035 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) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +030055 salt.cmdRun(venvPepper, 'I@salt:master', "salt -C '${target}' --async pkg.install force_yes=True pkgs='$pkgs'")
Denis Egorenko4b54e7f2019-02-26 16:05:03 +040056 // 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 Egorenko20a43462019-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 Berezovskiyf5c911b2019-12-03 18:49:09 +040088def wa29352(String cname) {
azvyagintsev745a6e52019-04-18 13:19:39 +030089 // 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 Berezovskiy22390f62020-02-17 17:08:47 +040097 salt.cmdRun(venvPepper, 'I@salt:master', "! grep -qi root_private_key: ${wa29352SecretsFile}", true, null, false)
azvyagintsev745a6e52019-04-18 13:19:39 +030098 salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29352File}", true, null, false)
99 }
100 catch (Exception ex) {
Denis Egorenkodfa35422019-10-07 12:46:14 +0400101 common.infoMsg('Work-around for PROD-29352 already applied, nothing todo')
azvyagintsev745a6e52019-04-18 13:19:39 +0300102 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 Egorenkodfa35422019-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')
azvyagintsev745a6e52019-04-18 13:19:39 +0300133}
134
azvyagintsevbc359d42019-04-10 19:53:22 +0300135def 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
azvyagintsevbc359d42019-04-10 19:53:22 +0300138 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 Berezovskiy22390f62020-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 }
azvyagintsevbc359d42019-04-10 19:53:22 +0300155 }
156 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300157 return
158 }
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400159 salt.fullRefresh(venvPepper, 'I@salt:master')
azvyagintsevbc359d42019-04-10 19:53:22 +0300160 for (String minion in saltMinions) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300161 // First attempt, second will be performed in next validateReclassModel() stages
162 try {
azvyagintsev745a6e52019-04-18 13:19:39 +0300163 salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
azvyagintsevbc359d42019-04-10 19:53:22 +0300164 } catch (Exception e) {
165 common.errorMsg(e.toString())
166 if (patched) {
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400167 error("Node: ${minion} failed to render after reclass-system upgrade! WA29155 probably didn't help.")
azvyagintsevbc359d42019-04-10 19:53:22 +0300168 }
azvyagintsev745a6e52019-04-18 13:19:39 +0300169 common.warningMsg('Perform: Attempt to apply WA for PROD-29155\n' +
170 'See https://gerrit.mcp.mirantis.com/#/c/37932/ for more info')
azvyagintsevbc359d42019-04-10 19:53:22 +0300171 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 ]
azvyagintsev745a6e52019-04-18 13:19:39 +0300186 writeYaml file: _tempFile, data: novaKeysDict
azvyagintsevbc359d42019-04-10 19:53:22 +0300187 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 Berezovskiyf5c911b2019-12-03 18:49:09 +0400197 salt.fullRefresh(venvPepper, 'I@salt:master')
198 salt.fullRefresh(venvPepper, saltMinions)
azvyagintsevbc359d42019-04-10 19:53:22 +0300199 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 Berezovskiy5b62e9c2020-01-24 17:52:26 +0400210def wa32284(String cluster_name) {
Denis Egorenko1b11d232019-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 Berezovskiy5b62e9c2020-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 Egorenko1b11d232019-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 Berezovskiy5b62e9c2020-01-24 17:52:26 +0400223 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && " +
Denis Egorenko1b11d232019-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 Berezovskiy5b62e9c2020-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 Egorenko1b11d232019-07-29 17:44:46 +0400227 }
228 }
229}
230
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400231def wa32182(String cluster_name) {
Hanna Arhipovad5eec4c2019-09-06 17:55:40 +0300232 if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) {
Denis Egorenkoaf18b252019-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 Berezovskiy9f6330b2020-02-05 21:18:17 +0400242 for (String contrailFile in contrailFiles) {
Denis Egorenkoaf18b252019-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 Berezovskiy9f6330b2020-02-05 21:18:17 +0400249 "echo '- cluster.${cluster_name}.opencontrail.common_wa32182' >> ${contrailFile}")
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400250 }
251 }
Ivan Berezovskiy9f6330b2020-02-05 21:18:17 +0400252 salt.cmdRun(venvPepper, 'I@salt:master', "test -f ${fixFile} && cd ${clusterModelPath} && git status && git add ${fixFile} || true")
Denis Egorenkoaf18b252019-09-02 14:53:02 +0400253 }
254}
255
Denis Egorenkoba631332019-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 Egorenkoe312cc92019-10-18 17:06:11 +0400267def wa33771(String cluster_name) {
Ivan Berezovskiy22390f62020-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 Egorenkoe312cc92019-10-18 17:06:11 +0400279 ]
Ivan Berezovskiy22390f62020-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 Egorenko59f82a52020-01-30 17:17:25 +0400290 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400291 } else {
292 common.warningMsg("Apache server is not defined on controller nodes. Skipping Octavia WSGI workaround");
Denis Egorenkoe312cc92019-10-18 17:06:11 +0400293 }
294}
295
Denis Egorenkoe9fc0592019-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 Berezovskiy22390f62020-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 Egorenkoe9fc0592019-11-14 19:56:17 +0400327 if (salt.getMinions(venvPepper, 'I@manila:api:enabled')) {
Ivan Berezovskiy22390f62020-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 Egorenkoe9fc0592019-11-14 19:56:17 +0400336 }
337 if (salt.getMinions(venvPepper, 'I@ironic:api:enabled')) {
Ivan Berezovskiy22390f62020-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 Egorenkoe9fc0592019-11-14 19:56:17 +0400346 }
347 if (salt.getMinions(venvPepper, 'I@gnocchi:server:enabled')) {
Ivan Berezovskiy22390f62020-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 Egorenkoe9fc0592019-11-14 19:56:17 +0400356 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400357
Denis Egorenkoe9fc0592019-11-14 19:56:17 +0400358 if (salt.getMinions(venvPepper, 'I@barbican:server:enabled')) {
Ivan Berezovskiy22390f62020-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 Egorenkoe9fc0592019-11-14 19:56:17 +0400367 }
Ivan Berezovskiy22390f62020-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 Egorenkoe9fc0592019-11-14 19:56:17 +0400376 }
377}
378
Denis Egorenko215acda2020-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 Berezovskiy5b62e9c2020-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 Egorenko215acda2020-01-28 16:41:44 +0400413 }
414 }
415 }
416}
417
Ivan Berezovskiy5b62e9c2020-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) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300486 def _tmp_file = '/tmp/' + filename + UUID.randomUUID().toString().take(8)
487 // jenkins may fail at overheap. Compress data with gzip like WA
azvyagintsev745a6e52019-04-18 13:19:39 +0300488 def ret = salt.cmdRun(venvPepper, 'I@salt:master', 'reclass -i 2>/dev/null | gzip -9 -c | base64', true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
azvyagintsevbc359d42019-04-10 19:53:22 +0300489 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 {
azvyagintsevbc359d42019-04-10 19:53:22 +0300497 for (String minion in saltMinions) {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400498 common.infoMsg("Reclass model validation for minion ${minion}...")
azvyagintsev745a6e52019-04-18 13:19:39 +0300499 def reclassInv = salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim()
Denis Egorenkod13ad132018-12-17 16:56:02 +0400500 writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString()
501 }
502 } catch (Exception e) {
503 common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.')
azvyagintsevbc359d42019-04-10 19:53:22 +0300504 error(e.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400505 }
506}
507
azvyagintsevbc359d42019-04-10 19:53:22 +0300508def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix = 'before', String newSuffix = 'after') {
509 for (String minion in saltMinions) {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400510 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}"
513 }
514}
515
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300516def checkDebsums() {
517 // check for salt-formulas consistency
518 try {
519 try {
520 salt.cmdRun(venvPepper, 'I@salt:master', "salt -C 'I@salt:master' pkg.install force_yes=True pkgs=[debsums]")
521 }
522 catch (Exception ex) {
523 common.warningMsg('Unable to install package "debsums" at cfg01. Salt-formulas integrity check skipped')
524 }
525 salt.cmdRun(venvPepper, 'I@salt:master', '> /root/debdsums_report; for i in $(dpkg-query -W -f=\'${Package}\\n\' | sed "s/ //g" |grep \'salt-formula-\'); do debsums -s ${i} 2>> /root/debdsums_report; done')
526 salt.cmdRun(venvPepper, 'I@salt:master', 'if [ -s "/root/debdsums_report" ]; then exit 1 ; fi')
527 }
528 catch (Exception ex) {
529 common.errorMsg(salt.cmdRun(venvPepper, 'I@salt:master', 'cat /root/debdsums_report ', true, null, false).get('return')[0].values()[0].trim())
530 common.errorMsg(ex.toString())
531 error('You have unexpected changes in formulas. All of them will be overwrited by update. Unable to continue in automatic way')
532 }
533}
534
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400535def checkCICDDocker() {
536 common.infoMsg('Perform: Checking if Docker containers are up')
537 try {
538 common.retry(10, 30) {
539 salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'")
540 }
541 }
542 catch (Exception ex) {
543 error("Docker containers for CI/CD services are having troubles with starting.")
544 }
545}
546
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400547if (common.validInputParam('PIPELINE_TIMEOUT')) {
548 try {
549 pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger()
azvyagintsevbc359d42019-04-10 19:53:22 +0300550 } catch (Exception e) {
Denis Egorenko5a8a7e92018-12-27 14:13:48 +0400551 common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger")
552 }
Martin Polreich965c9032018-08-09 16:33:57 +0200553}
554
555timeout(time: pipelineTimeout, unit: 'HOURS') {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300556 node('python') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100557 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300558 def inventoryBeforeFilename = "reclass-inventory-before.out"
559 def inventoryAfterFilename = "reclass-inventory-after.out"
Richard Felkl0e80d892018-06-20 13:44:54 +0200560 workspace = common.getWorkspace()
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200561 targetMcpVersion = null
562 if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) {
563 error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable')
azvyagintsev6dac3802018-11-09 15:11:30 +0200564 }
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200565 // bw comp. for 2018.X => 2018.11 release
azvyagintsevbc359d42019-04-10 19:53:22 +0300566 if (common.validInputParam('MCP_VERSION')) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200567 targetMcpVersion = env.MCP_VERSION
568 common.warningMsg("targetMcpVersion has been changed to:${targetMcpVersion}, which was taken from deprecated pipeline viriable:MCP_VERSION")
azvyagintsevbc359d42019-04-10 19:53:22 +0300569 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200570 targetMcpVersion = env.TARGET_MCP_VERSION
571 }
572 // end bw comp. for 2018.X => 2018.11 release
Denis Egorenkod13ad132018-12-17 16:56:02 +0400573 def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC')
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400574 if (targetMcpVersion in ['nightly', 'testing']) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200575 gitTargetMcpVersion = 'master'
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400576 } else if (targetMcpVersion == 'proposed') {
577 gitTargetMcpVersion = 'proposed'
Denis Egorenko284690e2018-12-25 15:55:12 +0400578 } else if (!gitTargetMcpVersion) {
579 // backward compatibility for 2018.11.0
580 gitTargetMcpVersion = "release/${targetMcpVersion}"
azvyagintsev6dac3802018-11-09 15:11:30 +0200581 }
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400582 common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}")
Denis Egorenko284690e2018-12-25 15:55:12 +0400583 def upgradeSaltStack = ''
584 def updateClusterModel = ''
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400585 def applyWorkarounds = true
Denis Egorenko284690e2018-12-25 15:55:12 +0400586 def updatePipelines = ''
587 def updateLocalRepos = ''
588 def reclassSystemBranch = ''
Denis Egorenko517e06c2019-03-29 13:24:15 +0400589 def reclassSystemBranchDefault = gitTargetMcpVersion
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400590 if (gitTargetMcpVersion ==~ /^\d\d\d\d\.\d\d?\.\d+$/) {
591 reclassSystemBranchDefault = "tags/${gitTargetMcpVersion}"
592 } else if (gitTargetMcpVersion != 'proposed') {
Denis Egorenko517e06c2019-03-29 13:24:15 +0400593 reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}"
594 }
Hanna Arhipovad5eec4c2019-09-06 17:55:40 +0300595 def driveTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS')
596 if (driveTrainParamsYaml) {
597 def driveTrainParams = readYaml text: driveTrainParamsYaml
598 saltMastURL = driveTrainParams.get('SALT_MASTER_URL')
599 saltMastCreds = driveTrainParams.get('SALT_MASTER_CREDENTIALS')
600 upgradeSaltStack = driveTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean()
601 updateClusterModel = driveTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean()
602 updatePipelines = driveTrainParams.get('UPDATE_PIPELINES', false).toBoolean()
603 updateLocalRepos = driveTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean()
604 reclassSystemBranch = driveTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault)
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400605 batchSize = driveTrainParams.get('BATCH_SIZE', '')
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400606 if (driveTrainParams.get('OS_DIST_UPGRADE', false).toBoolean() == true) {
607 packageUpgradeMode = 'dist-upgrade'
608 } else if (driveTrainParams.get('OS_UPGRADE', false).toBoolean() == true) {
609 packageUpgradeMode = 'upgrade'
610 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400611 applyWorkarounds = driveTrainParams.get('APPLY_MODEL_WORKAROUNDS', true).toBoolean()
Denis Egorenko284690e2018-12-25 15:55:12 +0400612 } else {
613 // backward compatibility for 2018.11.0
614 saltMastURL = env.getProperty('SALT_MASTER_URL')
615 saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS')
Denis Egorenkoe5f39142018-12-28 12:30:48 +0400616 upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean()
617 updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean()
618 updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean()
619 updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean()
Denis Egorenko517e06c2019-03-29 13:24:15 +0400620 reclassSystemBranch = reclassSystemBranchDefault
Denis Egorenko284690e2018-12-25 15:55:12 +0400621 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400622 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400623 def minions = salt.getMinions(venvPepper, '*')
Denis Egorenkofbcee412019-04-19 15:05:18 +0400624 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
625 if (cluster_name == '' || cluster_name == 'null' || cluster_name == null) {
626 error('Pillar data is broken for Salt master node! Please check it manually and re-run pipeline.')
627 }
Hanna Arhipovad5eec4c2019-09-06 17:55:40 +0300628 if (!batchSize) {
Denis Egorenko7b098c32019-12-19 16:45:25 +0400629 // if no batch size provided get current worker threads and set batch size to 2/3 of it to avoid
630 // 'SaltReqTimeoutError: Message timed out' issue on Salt targets for large amount of nodes
631 // do not use toDouble/Double as it requires additional approved method
632 def workerThreads = getWorkerThreads(venvPepper).toInteger()
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400633 batchSize = (workerThreads * 2 / 3).toString().tokenize('.')[0]
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400634 }
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400635 def computeMinions = salt.getMinions(venvPepper, 'I@nova:compute')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400636
azvyagintsevbc359d42019-04-10 19:53:22 +0300637 stage('Update Reclass and Salt-Formulas') {
638 common.infoMsg('Perform: Full salt sync')
639 salt.fullRefresh(venvPepper, '*')
640 common.infoMsg('Perform: Validate reclass medata before processing')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400641 validateReclassModel(minions, 'before')
642
azvyagintsev745a6e52019-04-18 13:19:39 +0300643 common.infoMsg('Perform: archiveReclassInventory before upgrade')
644 archiveReclassInventory(inventoryBeforeFilename)
645
azvyagintsev6dac3802018-11-09 15:11:30 +0200646 try {
azvyagintsevbc359d42019-04-10 19:53:22 +0300647 salt.cmdRun(venvPepper, 'I@salt:master', 'cd /srv/salt/reclass/ && git status && git diff-index --quiet HEAD --')
Richard Felkl970e0082018-06-12 18:00:51 +0200648 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200649 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300650 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 +0200651 }
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300652 checkDebsums()
Denis Egorenkod13ad132018-12-17 16:56:02 +0400653 if (updateClusterModel) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200654 common.infoMsg('Perform: UPDATE_CLUSTER_MODEL')
Sergey382581a2018-10-25 12:22:26 +0400655 def dateTime = common.getDatetime()
Ivan Berezovskiycfa1b2f2020-01-17 13:55:18 +0400656 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git fetch")
Sergey382581a2018-10-25 12:22:26 +0400657 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400658 "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 +0200659 // Do the same, for deprecated variable-duplicate
660 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400661 "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 +0400662 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400663 "grep -r --exclude-dir=aptly -l 'jenkins_pipelines_branch: .*' * | xargs --no-run-if-empty sed -i 's|jenkins_pipelines_branch: .*|jenkins_pipelines_branch: \"$gitTargetMcpVersion\"|g'")
Victor Ryzhenkinabbefe62019-01-15 19:58:03 +0400664 // Set new k8s param
665 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
666 "grep -r --exclude-dir=aptly -l 'kubernetes_containerd_enabled: .*' * | xargs --no-run-if-empty sed -i 's|kubernetes_containerd_enabled: .*|kubernetes_containerd_enabled: True|g'")
Denis Egorenkoe5b49512019-01-16 19:18:31 +0400667 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
668 "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'")
669 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko301cc8a2019-02-13 13:49:13 +0400670 "grep -r --exclude-dir=aptly -l 'system.linux.system.repo.mcp.contrail' * | xargs --no-run-if-empty sed -i 's/system.linux.system.repo.mcp.contrail/system.linux.system.repo.mcp.apt_mirantis.contrail/g'")
Denis Egorenkoe5b49512019-01-16 19:18:31 +0400671 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko301cc8a2019-02-13 13:49:13 +0400672 "grep -r --exclude-dir=aptly -l 'system.linux.system.repo.mcp.updates' * | xargs --no-run-if-empty sed -i 's/system.linux.system.repo.mcp.updates/system.linux.system.repo.mcp.apt_mirantis.update/g'")
Anton Samoylov308c7ca2019-02-13 15:57:13 +0400673 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsevbc359d42019-04-10 19:53:22 +0300674 "grep -r --exclude-dir=aptly -l 'system.linux.system.repo.mcp.extra' * | xargs --no-run-if-empty sed -i 's/system.linux.system.repo.mcp.extra/system.linux.system.repo.mcp.apt_mirantis.extra/g'")
Denis Egorenko21c78be2019-07-10 19:47:39 +0400675
Denis Egorenko6f07b592019-09-16 16:41:26 +0400676 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")
677 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name/infra && sed -i '/maas_region_main_archive/d' maas.yml")
678
Denis Egorenko21c78be2019-07-10 19:47:39 +0400679 // Switch Jenkins/Gerrit to use LDAP SSL/TLS
680 def gerritldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
681 "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()
682 if (gerritldapURI.startsWith('ldap://')) {
683 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
684 "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
685 } else if (! gerritldapURI.startsWith('ldaps://')) {
686 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
687 "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'")
688 }
689 def jenkinsldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
690 "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()
691 if (jenkinsldapURI.startsWith('ldap://')) {
692 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
693 "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'")
694 } else if (! jenkinsldapURI.startsWith('ldaps://')) {
695 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
696 "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'")
697 }
698
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400699 if (applyWorkarounds) {
700 wa32284(cluster_name)
701 wa34245(cluster_name)
702 }
Denis Egorenko1b11d232019-07-29 17:44:46 +0400703
Denis Egorenkod13ad132018-12-17 16:56:02 +0400704 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}")
Sergey Kolekonov5dfbf7a2019-01-23 16:47:43 +0400705 // Add kubernetes-extra repo
706 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
Sergey Kolekonov3fde8b12019-04-11 16:33:54 +0400707 // docker-engine conflicts with the recent containerd versions, so it's removed during upgrade. Thus update source engine
708 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
709 "grep -r -l 'engine: docker_hybrid' kubernetes | xargs --no-run-if-empty sed -i 's/engine: docker_hybrid/engine: archive/g'")
Sergey Kolekonov5dfbf7a2019-01-23 16:47:43 +0400710 common.infoMsg("Add kubernetes-extra repo")
711 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
712 "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")
713 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
714 "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")
715 }
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400716 // Add all update repositories
717 def repoIncludeBase = '- system.linux.system.repo.mcp.apt_mirantis.'
Denis Egorenko6f07b592019-09-16 16:41:26 +0400718 def updateRepoList = ['cassandra', 'ceph', 'contrail', 'docker', 'elastic', 'extra', 'openstack', 'maas', 'percona', 'salt-formulas', 'saltstack', 'ubuntu']
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400719 updateRepoList.each { repo ->
720 def repoNameUpdateInclude = "${repoIncludeBase}update.${repo}"
721 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')
722 filesWithInclude.each { file ->
723 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()
724 if (updateRepoIncludeExist == 'not_found') {
725 // Include needs to be added
726 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsevbc359d42019-04-10 19:53:22 +0300727 "sed -i 's/\\( *\\)${repoIncludeBase}${repo}\$/&\\n\\1${repoNameUpdateInclude}/g' ${file}")
Ivan Berezovskiy41c76792019-04-15 13:23:58 +0400728 common.infoMsg("Update repo for ${repo} is added to ${file}")
729 }
730 }
731 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400732 if (applyWorkarounds) {
733 wa32182(cluster_name)
734 wa33771(cluster_name)
735 wa33867(cluster_name)
736 wa33930_33931(cluster_name)
737 wa34528(cluster_name)
738 }
Sergey382581a2018-10-25 12:22:26 +0400739 // Add new defaults
740 common.infoMsg("Add new defaults")
Denis Egorenkod13ad132018-12-17 16:56:02 +0400741 salt.cmdRun(venvPepper, 'I@salt:master', "grep '^ mcp_version: ' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400742 "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 +0400743 salt.cmdRun(venvPepper, 'I@salt:master', "grep '^- system.defaults\$' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400744 "sed -i 's|^classes:|classes:\\n- system.defaults|' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml")
Ivan Berezovskiy5113c7c2019-04-23 14:32:02 +0400745 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300746 "grep -r -l 'docker_image_jenkins: .*' cicd | xargs --no-run-if-empty sed -i 's|\\s*docker_image_jenkins: .*||g'")
Ivan Berezovskiy5113c7c2019-04-23 14:32:02 +0400747 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300748 "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 +0400749 common.infoMsg("The following changes were made to the cluster model and will be commited. " +
azvyagintsev6dac3802018-11-09 15:11:30 +0200750 "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 +0400751 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff")
752 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " +
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200753 "git add -u && git commit --allow-empty -m 'Cluster model update to the release $targetMcpVersion on $dateTime'")
Sergey382581a2018-10-25 12:22:26 +0400754 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400755 try {
756 common.infoMsg('Perform: UPDATE Salt Formulas')
azvyagintsevca97a112019-04-22 17:53:40 +0300757 salt.fullRefresh(venvPepper, '*')
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400758 salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400759 def saltEnv = salt.getPillar(venvPepper, 'I@salt:master', "_param:salt_master_base_environment").get("return")[0].values()[0]
azvyagintsevbc359d42019-04-10 19:53:22 +0300760 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas", 'salt.master.env'])
azvyagintsevca97a112019-04-22 17:53:40 +0300761 salt.fullRefresh(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400762 } catch (Exception updateErr) {
763 common.warningMsg(updateErr)
764 common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
765 input message: 'Continue anyway?'
766 }
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400767 if (applyWorkarounds) {
768 wa29352(cluster_name)
769 wa29155(computeMinions, cluster_name)
770 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400771
772 try {
773 common.infoMsg('Perform: UPDATE Reclass package')
774 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"])
775 } catch (Exception updateErr) {
776 common.warningMsg(updateErr)
777 common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
778 input message: 'Continue anyway?'
779 }
780
781 salt.fullRefresh(venvPepper, 'I@salt:master')
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400782 salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true, true, null, false, 60, 2)
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400783 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && " +
784 "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 +0400785 try {
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400786 salt.enforceState(venvPepper, 'I@salt:master', 'reclass', true, true, null, false, 60, 2)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400787 }
788 catch (Exception ex) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300789 common.errorMsg(ex.toString())
790 error('Reclass fails rendering. Pay attention to your cluster model.')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400791 }
792
793 salt.fullRefresh(venvPepper, '*')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400794 try {
795 salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top")
796 }
797 catch (Exception ex) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300798
799 error('Reclass fails rendering. Pay attention to your cluster model.' +
800 'ErrorMessage:' + ex.toString())
Denis Egorenkod13ad132018-12-17 16:56:02 +0400801 }
802
azvyagintsevbc359d42019-04-10 19:53:22 +0300803 common.infoMsg('Perform: archiveReclassInventory AFTER upgrade')
Denis Egorenkod13ad132018-12-17 16:56:02 +0400804 archiveReclassInventory(inventoryAfterFilename)
805
806 sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true"
807 archiveArtifacts artifacts: "reclass-inventory-diff.out"
808
809 validateReclassModel(minions, 'after')
810 archiveReclassModelChanges(minions)
Jakub Josefa63f9862018-01-11 17:58:38 +0100811 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100812
Denis Egorenkod13ad132018-12-17 16:56:02 +0400813 if (updateLocalRepos) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200814 stage("Update local repos") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100815 common.infoMsg("Updating local repositories")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700816
Sergey1b81c062018-10-16 17:10:21 +0400817 def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700818 runningOnDocker = engine.get("return")[0].containsValue("docker")
819
820 if (runningOnDocker) {
821 common.infoMsg("Aptly is running as Docker container")
azvyagintsev6dac3802018-11-09 15:11:30 +0200822 } else {
Sam Stoelingaaab79702018-04-09 18:49:39 -0700823 common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands")
824 }
825
azvyagintsev6dac3802018-11-09 15:11:30 +0200826 if (runningOnDocker) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200827 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 +0200828 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200829 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 +0100830 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100831
Sergey1b81c062018-10-16 17:10:21 +0400832 salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100833
azvyagintsev6dac3802018-11-09 15:11:30 +0200834 if (runningOnDocker) {
Sergey1b81c062018-10-16 17:10:21 +0400835 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true)
836 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 +0200837 } else {
Sergey1b81c062018-10-16 17:10:21 +0400838 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true)
839 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 +0100840 }
Richard Felkl79d7df12018-01-05 16:40:11 +0100841
Sergey1b81c062018-10-16 17:10:21 +0400842 salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100843
Sergey1b81c062018-10-16 17:10:21 +0400844 salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100845
Sergey1b81c062018-10-16 17:10:21 +0400846 salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100847
Sergey1b81c062018-10-16 17:10:21 +0400848 salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100849 }
850 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100851
azvyagintsevbc359d42019-04-10 19:53:22 +0300852 stage('Update Drivetrain') {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400853 if (upgradeSaltStack) {
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300854 updateSaltStack('I@salt:master', '["salt-master", "salt-common", "salt-api", "salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200855
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400856 salt.enforceState(venvPepper, 'I@linux:system', 'linux.system.repo', true, true, batchSize, false, 60, 2)
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300857 updateSaltStack('I@salt:minion and not I@salt:master', '["salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200858 }
859
Denis Egorenkod13ad132018-12-17 16:56:02 +0400860 if (updatePipelines) {
azvyagintsevbc359d42019-04-10 19:53:22 +0300861 common.infoMsg('Perform: UPDATE git repos')
862 triggerMirrorJob('git-mirror-downstream-mk-pipelines', reclassSystemBranch)
863 triggerMirrorJob('git-mirror-downstream-pipeline-library', reclassSystemBranch)
Richard Felkl970e0082018-06-12 18:00:51 +0200864 }
865
Denis Egorenko7a4cf032019-04-25 20:48:26 +0400866 // update minions certs
Denis Egorenkoaf3a2202019-04-26 15:13:16 +0400867 // call for `salt.minion.ca` state on related nodes to make sure
868 // mine was updated with required data after salt-minion/salt-master restart salt:minion:ca
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400869 salt.enforceState(venvPepper, 'I@salt:minion:ca', 'salt.minion.ca', true, true, batchSize, false, 60, 2)
870 salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion.cert', true, true, batchSize, false, 60, 2)
Denis Egorenko7a4cf032019-04-25 20:48:26 +0400871
Ann Kamyshnikovae8910112019-05-06 12:56:38 +0400872 // run `salt.minion` to refresh all minion configs (for example _keystone.conf)
Ivan Berezovskiy22390f62020-02-17 17:08:47 +0400873 salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion', true, true, batchSize, false, 60, 2)
azvyagintsevbc359d42019-04-10 19:53:22 +0300874 // Retry needed only for rare race-condition in user appearance
875 common.infoMsg('Perform: updating users and keys')
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400876 salt.enforceState(venvPepper, 'I@linux:system', 'linux.system.user', true, true, batchSize, false, 60, 2)
azvyagintsevbc359d42019-04-10 19:53:22 +0300877 common.infoMsg('Perform: updating openssh')
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400878 salt.enforceState(venvPepper, 'I@linux:system', 'openssh', true, true, batchSize, false, 60, 2)
Denis Egorenko65cf2a42019-01-15 11:58:12 +0400879
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300880 // apply salt API TLS if needed
881 def nginxAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0]
882 if (nginxAtMaster.toString().toLowerCase() == 'true') {
Denis Egorenkoea0ba7d2019-07-04 14:16:40 +0400883 salt.enforceState(venvPepper, 'I@salt:master', 'nginx', true, true, null, false, 60, 2)
azvyagintsev97fd5ae2019-06-03 19:09:43 +0300884 }
885
Denis Egorenko579f1842019-10-30 13:26:59 +0400886 // 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
887 def gerritGlusterPath = salt.getPillar(venvPepper, 'I@gerrit:client', 'glusterfs:client:volumes:gerrit:path').get('return')[0].values()[0]
888 def wrongPluginJarName = "${gerritGlusterPath}/plugins/project-download-commands.jar"
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400889 salt.cmdRun(venvPepper, 'I@gerrit:client', "test -f ${wrongPluginJarName} && rm ${wrongPluginJarName} || true")
Denis Egorenko579f1842019-10-30 13:26:59 +0400890
Ivan Berezovskiy89b24832020-02-27 15:21:57 +0400891 salt.enforceStateWithTest(venvPepper, 'I@jenkins:client and I@docker:client:images and not I@salt:master', 'docker.client.images', "", true, true, null, true, 60, 2)
Denis Egorenko21c78be2019-07-10 19:47:39 +0400892 salt.cmdRun(venvPepper, "I@salt:master", "salt -C 'I@jenkins:client and I@docker:client and not I@salt:master' state.sls docker.client --async")
Ivan Berezovskiya766d432019-12-11 15:31:10 +0400893 }
894 }
895 catch (Throwable e) {
896 // If there was an error or exception thrown, the build failed
897 currentBuild.result = "FAILURE"
898 throw e
899 }
900 }
901 // docker.client state may trigger change of jenkins master or jenkins slave services,
902 // so we need wait for slave to reconnect and continue pipeline
903 sleep(180)
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400904 def cidNodes = []
Ivan Berezovskiya766d432019-12-11 15:31:10 +0400905 node('python') {
906 try {
907 stage('Update Drivetrain: Phase 2') {
908 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400909 checkCICDDocker()
Denis Egorenko21c78be2019-07-10 19:47:39 +0400910
Ivan Berezovskiyf5c911b2019-12-03 18:49:09 +0400911 // Apply changes for HaProxy on CI/CD nodes
912 salt.enforceState(venvPepper, 'I@keepalived:cluster:instance:cicd_control_vip and I@haproxy:proxy', 'haproxy.proxy', true)
913
Denis Egorenko21c78be2019-07-10 19:47:39 +0400914 salt.enforceState(venvPepper, 'I@jenkins:client and not I@salt:master', 'jenkins.client', true, true, null, false, 60, 2)
Denis Egorenko312bcd42019-07-23 17:59:13 +0400915
916 // update Nginx proxy settings for Jenkins/Gerrit if needed
917 if (salt.testTarget(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit')) {
918 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)
919 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100920 }
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400921 if (packageUpgradeMode) {
922 cidNodes = salt.getMinions(venvPepper, 'I@_param:drivetrain_role:cicd')
923 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100924 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100925 catch (Throwable e) {
926 // If there was an error or exception thrown, the build failed
927 currentBuild.result = "FAILURE"
928 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +0100929 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100930 }
Denis Egorenko96cc57d2020-01-24 19:47:05 +0400931
932 stage('Upgrade OS') {
933 if (packageUpgradeMode) {
934 def debian = new com.mirantis.mk.Debian()
935 def statusFile = '/tmp/rebooted_during_upgrade'
936 for(cidNode in cidNodes) {
937 node('python') {
938 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
939 // cmd.run async to prevent connection close in case of slave shutdown, give 5 seconds to handle request response
940 salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${cidNode}' cmd.run 'sleep 5; touch ${statusFile}; salt-call service.stop docker' --async")
941 }
942 sleep(30)
943 node('python') {
944 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
945 debian.osUpgradeNode(venvPepper, cidNode, packageUpgradeMode, false, 60)
946 salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': cidNode, wait: 60, timeout: 10])
947 if (salt.runSaltProcessStep(venvPepper, cidNode, 'file.file_exists', [statusFile], null, true, 5)['return'][0].values()[0].toBoolean()) {
948 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
949 sleep(10)
950 }
951 checkCICDDocker()
952 }
953 }
954 } else {
955 common.infoMsg('Upgrade OS skipped...')
956 }
957 }
Jakub Josef2c21c6c2018-02-08 18:51:42 +0100958}