Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Update Salt environment pipeline |
| 4 | * |
| 5 | * Expected parameters: |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 6 | * TARGET_MCP_VERSION Version of MCP to upgrade to |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 7 | * 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 Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 11 | * BATCH_SIZE Use batch sizing during upgrade for large envs |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 12 | * 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 |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 16 | */ |
| 17 | |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 18 | salt = new com.mirantis.mk.Salt() |
| 19 | common = new com.mirantis.mk.Common() |
| 20 | python = new com.mirantis.mk.Python() |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 21 | jenkinsUtils = new com.mirantis.mk.JenkinsUtils() |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 22 | def pipelineTimeout = 12 |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 23 | venvPepper = "venvPepper" |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 24 | workspace = "" |
Ivan Berezovskiy | 24b0be0 | 2019-12-11 15:31:10 +0400 | [diff] [blame] | 25 | def saltMastURL = '' |
| 26 | def saltMastCreds = '' |
Denis Egorenko | bf39010 | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 27 | def packageUpgradeMode = '' |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 28 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 29 | def triggerMirrorJob(String jobName, String reclassSystemBranch) { |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 30 | params = jenkinsUtils.getJobParameters(jobName) |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 31 | try { |
| 32 | build job: jobName, parameters: [ |
| 33 | [$class: 'StringParameterValue', name: 'BRANCHES', value: params.get('BRANCHES')], |
| 34 | [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')], |
| 35 | [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')], |
| 36 | [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')] |
| 37 | ] |
| 38 | } catch (Exception updateErr) { |
| 39 | common.warningMsg(updateErr) |
| 40 | common.warningMsg('Attempt to update git repo in failsafe manner') |
| 41 | build job: jobName, parameters: [ |
| 42 | [$class: 'StringParameterValue', name: 'BRANCHES', value: reclassSystemBranch.replace('origin/', '')], |
| 43 | [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')], |
| 44 | [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')], |
| 45 | [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')] |
| 46 | ] |
| 47 | } |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 48 | } |
| 49 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 50 | def updateSaltStack(target, pkgs) { |
Denis Egorenko | 0d0c65f | 2019-02-26 16:05:03 +0400 | [diff] [blame] | 51 | salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${target}' --async pkg.install force_yes=True pkgs='$pkgs'") |
| 52 | // can't use same function from pipeline lib, as at the moment of running upgrade pipeline Jenkins |
| 53 | // still using pipeline lib from current old mcp-version |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 54 | common.retry(20, 60) { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 55 | salt.minionsReachable(venvPepper, 'I@salt:master', '*') |
| 56 | def running = salt.runSaltProcessStep(venvPepper, target, 'saltutil.running', [], null, true, 5) |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 57 | for (value in running.get("return")[0].values()) { |
| 58 | if (value != []) { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 59 | throw new Exception("Not all salt-minions are ready for execution") |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 64 | def saltVersion = salt.getPillar(venvPepper, 'I@salt:master', '_param:salt_version').get('return')[0].values()[0] |
Richard Felkl | f23257e | 2018-08-06 09:24:23 +0200 | [diff] [blame] | 65 | def saltMinionVersions = salt.cmdRun(venvPepper, target, "apt-cache policy salt-common | awk '/Installed/ && /$saltVersion/'").get("return") |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 66 | def saltMinionVersion = "" |
| 67 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 68 | for (minion in saltMinionVersions[0].keySet()) { |
| 69 | saltMinionVersion = saltMinionVersions[0].get(minion).replace("Salt command execution success", "").trim() |
| 70 | if (saltMinionVersion == "") { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 71 | error("Installed version of Salt on $minion doesn't match specified version in the model.") |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
Denis Egorenko | 6f1c873 | 2019-09-24 14:55:50 +0400 | [diff] [blame] | 76 | def getWorkerThreads(saltId) { |
| 77 | if (env.getEnvironment().containsKey('SALT_MASTER_OPT_WORKER_THREADS')) { |
| 78 | return env['SALT_MASTER_OPT_WORKER_THREADS'].toString() |
| 79 | } |
| 80 | 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) |
| 81 | return threads['return'][0].values()[0].replaceAll('Salt command execution success','').trim() |
| 82 | } |
| 83 | |
Ivan Berezovskiy | 304705c | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 84 | def wa29352(String cname) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 85 | // WA for PROD-29352. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/12/openssh/client/root.yml |
| 86 | // Default soft-param has been removed, what now makes not possible to render some old env's. |
| 87 | // Like fix, we found copy-paste already generated key from backups, to secrets.yml with correct key name |
| 88 | def wa29352ClassName = 'cluster.' + cname + '.infra.secrets_root_wa29352' |
| 89 | def wa29352File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_root_wa29352.yml" |
| 90 | def wa29352SecretsFile = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets.yml" |
| 91 | def _tempFile = '/tmp/wa29352_' + UUID.randomUUID().toString().take(8) |
| 92 | try { |
| 93 | salt.cmdRun(venvPepper, 'I@salt:master', "grep -qiv root_private_key ${wa29352SecretsFile}", true, null, false) |
| 94 | salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29352File}", true, null, false) |
| 95 | } |
| 96 | catch (Exception ex) { |
Denis Egorenko | e0c8843 | 2019-10-07 12:46:14 +0400 | [diff] [blame] | 97 | common.infoMsg('Work-around for PROD-29352 already applied, nothing todo') |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 98 | return |
| 99 | } |
| 100 | def rKeysDict = [ |
| 101 | 'parameters': [ |
| 102 | '_param': [ |
| 103 | 'root_private_key': salt.getPillar(venvPepper, 'I@salt:master', '_param:root_private_key').get('return')[0].values()[0].trim(), |
| 104 | 'root_public_key' : '', |
| 105 | ] |
| 106 | ] |
| 107 | ] |
| 108 | // save root key,and generate public one from it |
| 109 | writeFile file: _tempFile, text: rKeysDict['parameters']['_param']['root_private_key'].toString().trim() |
| 110 | sh('chmod 0600 ' + _tempFile) |
| 111 | rKeysDict['parameters']['_param']['root_public_key'] = sh(script: "ssh-keygen -q -y -f ${_tempFile}", returnStdout: true).trim() |
| 112 | sh('rm -fv ' + _tempFile) |
| 113 | writeYaml file: _tempFile, data: rKeysDict |
| 114 | def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim() |
| 115 | salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29352File}", false, null, false) |
| 116 | common.infoMsg("Add $wa29352ClassName class into secrets.yml") |
| 117 | |
| 118 | // Add 'classes:' directive |
| 119 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " + |
| 120 | "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml") |
| 121 | |
| 122 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " + |
| 123 | "grep -q '${wa29352ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29352ClassName' infra/secrets.yml") |
| 124 | salt.fullRefresh(venvPepper, '*') |
| 125 | sh('rm -fv ' + _tempFile) |
Denis Egorenko | e0c8843 | 2019-10-07 12:46:14 +0400 | [diff] [blame] | 126 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " + |
| 127 | "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()}' ") |
| 128 | common.infoMsg('Work-around for PROD-29352 successfully applied') |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | def wa29155(ArrayList saltMinions, String cname) { |
| 132 | // WA for PROD-29155. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/ |
| 133 | // CHeck for existence cmp nodes, and try to render it. Is failed, apply ssh-key wa |
| 134 | def ret = '' |
| 135 | def patched = false |
| 136 | def wa29155ClassName = 'cluster.' + cname + '.infra.secrets_nova_wa29155' |
| 137 | def wa29155File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_nova_wa29155.yml" |
| 138 | |
| 139 | try { |
| 140 | salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29155File}", true, null, false) |
| 141 | } |
| 142 | catch (Exception ex) { |
| 143 | common.infoMsg('Work-around for PROD-29155 already apply, nothing todo') |
| 144 | return |
| 145 | } |
Denis Egorenko | e983d45 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 146 | salt.fullRefresh(venvPepper, 'I@salt:master') |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 147 | for (String minion in saltMinions) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 148 | // First attempt, second will be performed in next validateReclassModel() stages |
| 149 | try { |
| 150 | salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim() |
| 151 | } catch (Exception e) { |
| 152 | common.errorMsg(e.toString()) |
| 153 | if (patched) { |
| 154 | error("Node: ${minion} failed to render after reclass-system upgrade!WA29155 probably didn't help.") |
| 155 | } |
| 156 | // check, that failed exactly by our case, by key-length check. |
| 157 | def missed_key = salt.getPillar(venvPepper, minion, '_param:nova_compute_ssh_private').get("return")[0].values()[0] |
| 158 | if (missed_key != '') { |
| 159 | error("Node: ${minion} failed to render after reclass-system upgrade!") |
| 160 | } |
| 161 | common.warningMsg('Perform: Attempt to apply WA for PROD-29155\n' + |
| 162 | 'See https://gerrit.mcp.mirantis.com/#/c/37932/ for more info') |
| 163 | common.warningMsg('WA-PROD-29155 Generating new ssh key at master node') |
| 164 | def _tempFile = "/tmp/nova_wa29155_" + UUID.randomUUID().toString().take(8) |
| 165 | common.infoMsg('Perform: generation NEW ssh-private key for nova-compute') |
| 166 | salt.cmdRun(venvPepper, 'I@salt:master', "ssh-keygen -f ${_tempFile} -N '' -q") |
| 167 | def _pub_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}.pub").get('return')[0].values()[0].trim() |
| 168 | def _priv_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}").get('return')[0].values()[0].trim() |
| 169 | salt.cmdRun(venvPepper, 'I@salt:master', "rm -fv ${_tempFile}", false, null, false) |
| 170 | def novaKeysDict = [ |
| 171 | "parameters": [ |
| 172 | "_param": [ |
| 173 | "nova_compute_ssh_private": _priv_k, |
| 174 | "nova_compute_ssh_public" : _pub_k |
| 175 | ] |
| 176 | ] |
| 177 | ] |
| 178 | writeYaml file: _tempFile, data: novaKeysDict |
| 179 | def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim() |
| 180 | salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29155File}", false, null, false) |
| 181 | common.infoMsg("Add $wa29155ClassName class into secrets.yml") |
| 182 | |
| 183 | // Add 'classes:' directive |
| 184 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " + |
| 185 | "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml") |
| 186 | |
| 187 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " + |
| 188 | "grep -q '${wa29155ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29155ClassName' infra/secrets.yml") |
Ivan Berezovskiy | 304705c | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 189 | salt.fullRefresh(venvPepper, 'I@salt:master') |
| 190 | salt.fullRefresh(venvPepper, saltMinions) |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 191 | patched = true |
| 192 | } |
| 193 | } |
| 194 | if (patched) { |
| 195 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " + |
| 196 | "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()}' ") |
| 197 | common.infoMsg('Work-around for PROD-29155 successfully applied') |
| 198 | } |
| 199 | |
| 200 | } |
| 201 | |
Ivan Berezovskiy | 8699f3f | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 202 | def wa32284(String cluster_name) { |
Denis Egorenko | bae9dc7 | 2019-07-29 17:44:46 +0400 | [diff] [blame] | 203 | def clientGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:enabled").get("return")[0].values()[0] |
| 204 | def pkiGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:volumes:salt_pki").get("return")[0].values()[0] |
| 205 | def nginxEnabledAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0] |
| 206 | if (nginxEnabledAtMaster.toString().toLowerCase() == 'true' && clientGluster.toString().toLowerCase() == 'true' && pkiGluster) { |
| 207 | def nginxRequires = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:wait_for_service').get('return')[0].values()[0] |
| 208 | if (nginxRequires.isEmpty()) { |
Ivan Berezovskiy | 8699f3f | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 209 | def nginxRequiresClassName = "cluster.${cluster_name}.infra.config.nginx_requires_wa32284" |
| 210 | def nginxRequiresClassFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/infra/config/nginx_requires_wa32284.yml" |
Denis Egorenko | bae9dc7 | 2019-07-29 17:44:46 +0400 | [diff] [blame] | 211 | def nginxRequiresBlock = ['parameters': ['nginx': ['server': ['wait_for_service': ['srv-salt-pki.mount'] ] ] ] ] |
| 212 | def _tempFile = '/tmp/wa32284_' + UUID.randomUUID().toString().take(8) |
| 213 | writeYaml file: _tempFile , data: nginxRequiresBlock |
| 214 | def nginxRequiresBlockString = sh(script: "cat ${_tempFile}", returnStdout: true).trim() |
Ivan Berezovskiy | 8699f3f | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 215 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && " + |
Denis Egorenko | bae9dc7 | 2019-07-29 17:44:46 +0400 | [diff] [blame] | 216 | "sed -i '/^parameters:/i - ${nginxRequiresClassName}' infra/config/init.yml") |
| 217 | salt.cmdRun(venvPepper, 'I@salt:master', "echo '${nginxRequiresBlockString}' > ${nginxRequiresClassFile}", false, null, false) |
Ivan Berezovskiy | 8699f3f | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 218 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${nginxRequiresClassFile}") |
Denis Egorenko | bae9dc7 | 2019-07-29 17:44:46 +0400 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
Denis Egorenko | da11789 | 2019-09-02 14:53:02 +0400 | [diff] [blame] | 223 | def wa32182(String cluster_name) { |
Hanna Arhipova | 644aefd | 2019-09-06 17:55:40 +0300 | [diff] [blame] | 224 | if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) { |
Denis Egorenko | da11789 | 2019-09-02 14:53:02 +0400 | [diff] [blame] | 225 | def clusterModelPath = "/srv/salt/reclass/classes/cluster/${cluster_name}" |
| 226 | def fixFile = "${clusterModelPath}/opencontrail/common_wa32182.yml" |
| 227 | def usualFile = "${clusterModelPath}/opencontrail/common.yml" |
| 228 | def fixFileContent = "classes:\n- system.opencontrail.common\n" |
| 229 | salt.cmdRun(venvPepper, 'I@salt:master', "test -f ${fixFile} -o -f ${usualFile} || echo '${fixFileContent}' > ${fixFile}") |
| 230 | def contrailFiles = ['opencontrail/analytics.yml', 'opencontrail/control.yml', 'openstack/compute/init.yml'] |
| 231 | if (salt.testTarget(venvPepper, "I@kubernetes:master")) { |
| 232 | contrailFiles.add('kubernetes/compute.yml') |
| 233 | } |
| 234 | for(String contrailFile in contrailFiles) { |
| 235 | contrailFile = "${clusterModelPath}/${contrailFile}" |
| 236 | 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() |
| 237 | if (containsFix) { |
| 238 | continue |
| 239 | } else { |
| 240 | salt.cmdRun(venvPepper, 'I@salt:master', "grep -q -E '^parameters:' ${contrailFile} && sed -i '/^parameters:/i - cluster.${cluster_name}.opencontrail.common_wa32182' ${contrailFile} || " + |
| 241 | "echo '- cluster.${cluster_name}.opencontrail.common_wa32182' >> ${contrailFile}") |
| 242 | } |
| 243 | } |
Ivan Berezovskiy | 8699f3f | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 244 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${fixFile}") |
Denis Egorenko | da11789 | 2019-09-02 14:53:02 +0400 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
Denis Egorenko | 3246108 | 2019-10-25 13:13:39 +0400 | [diff] [blame] | 248 | def wa33867(String cluster_name) { |
| 249 | if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) { |
| 250 | def contrailControlFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/opencontrail/control.yml" |
| 251 | 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() |
| 252 | if (line == "- cluster.${cluster_name}.infra") { |
| 253 | salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra\$/d' ${contrailControlFile}") |
| 254 | salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra.backup.client_zookeeper\$/i - cluster.${cluster_name}.infra' ${contrailControlFile}") |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | |
Denis Egorenko | 7e934c2 | 2019-10-18 17:06:11 +0400 | [diff] [blame] | 259 | def wa33771(String cluster_name) { |
| 260 | def octaviaEnabled = salt.getMinions(venvPepper, 'I@octavia:api:enabled') |
| 261 | def octaviaWSGI = salt.getMinions(venvPepper, 'I@apache:server:site:octavia_api') |
| 262 | if (octaviaEnabled && ! octaviaWSGI) { |
| 263 | def openstackControl = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/control.yml" |
| 264 | def octaviaFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/octavia_wa33771.yml" |
| 265 | def octaviaContext = [ |
| 266 | 'classes': [ 'system.apache.server.site.octavia' ], |
| 267 | 'parameters': [ |
| 268 | '_param': [ 'apache_octavia_api_address' : '${_param:cluster_local_address}' ], |
Denis Egorenko | 7e934c2 | 2019-10-18 17:06:11 +0400 | [diff] [blame] | 269 | ] |
| 270 | ] |
Denis Egorenko | 7235309 | 2020-01-30 17:17:25 +0400 | [diff] [blame] | 271 | def openstackHTTPSEnabled = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_internal_protocol").get("return")[0].values()[0] |
| 272 | if (openstackHTTPSEnabled == 'https') { |
| 273 | octaviaContext['parameters'] << [ 'apache': [ 'server': [ 'site': [ 'apache_proxy_openstack_api_octavia': [ 'enabled': false ] ] ] ] ] |
| 274 | } |
Denis Egorenko | 7e934c2 | 2019-10-18 17:06:11 +0400 | [diff] [blame] | 275 | def _tempFile = '/tmp/wa33771' + UUID.randomUUID().toString().take(8) |
| 276 | writeYaml file: _tempFile , data: octaviaContext |
| 277 | def octaviaFileContent = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim() |
| 278 | salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.octavia_wa33771' ${openstackControl}") |
| 279 | salt.cmdRun(venvPepper, 'I@salt:master', "echo '${octaviaFileContent}' | base64 -d > ${octaviaFile}", false, null, false) |
Ivan Berezovskiy | 8699f3f | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 280 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${octaviaFile}") |
Denis Egorenko | 7e934c2 | 2019-10-18 17:06:11 +0400 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
Denis Egorenko | 4ac89a3 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 284 | def wa33930_33931(String cluster_name) { |
| 285 | def openstackControlFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/control.yml" |
| 286 | def fixName = 'clients_common_wa33930_33931' |
| 287 | def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/${fixName}.yml" |
| 288 | 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() |
| 289 | if (! containsFix) { |
| 290 | def fixContext = [ |
| 291 | 'classes': [ 'service.nova.client', 'service.glance.client', 'service.neutron.client' ] |
| 292 | ] |
| 293 | if (salt.getMinions(venvPepper, 'I@manila:api:enabled')) { |
| 294 | fixContext['classes'] << 'service.manila.client' |
| 295 | } |
| 296 | if (salt.getMinions(venvPepper, 'I@ironic:api:enabled')) { |
| 297 | fixContext['classes'] << 'service.ironic.client' |
| 298 | } |
| 299 | if (salt.getMinions(venvPepper, 'I@gnocchi:server:enabled')) { |
| 300 | fixContext['classes'] << 'service.gnocchi.client' |
| 301 | } |
| 302 | if (salt.getMinions(venvPepper, 'I@barbican:server:enabled')) { |
| 303 | fixContext['classes'] << 'service.barbican.client.single' |
| 304 | } |
| 305 | def _tempFile = '/tmp/wa33930_33931' + UUID.randomUUID().toString().take(8) |
| 306 | writeYaml file: _tempFile , data: fixContext |
| 307 | def fixFileContent = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim() |
| 308 | salt.cmdRun(venvPepper, 'I@salt:master', "echo '${fixFileContent}' | base64 -d > ${fixFile}", false, null, false) |
| 309 | salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.${fixName}' ${openstackControlFile}") |
Ivan Berezovskiy | 8699f3f | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 310 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${fixFile}") |
Denis Egorenko | 4ac89a3 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
Denis Egorenko | db45015 | 2020-01-28 16:41:44 +0400 | [diff] [blame] | 314 | def wa34245(cluster_name) { |
| 315 | def infraInitFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/infra/init.yml" |
| 316 | def fixName = 'hosts_wa34245' |
| 317 | def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/infra/${fixName}.yml" |
| 318 | if (salt.testTarget(venvPepper, 'I@keystone:server')) { |
| 319 | 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() |
| 320 | if (!fixApplied) { |
| 321 | def fixFileContent = [] |
| 322 | 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() |
| 323 | if (!containsFix) { |
| 324 | fixFileContent << '- system.linux.network.hosts.openstack' |
| 325 | } |
| 326 | if (salt.testTarget(venvPepper, 'I@gnocchi:server')) { |
| 327 | 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() |
| 328 | if (!containsFix) { |
| 329 | fixFileContent << '- system.linux.network.hosts.openstack.telemetry' |
| 330 | } |
| 331 | } |
| 332 | if (salt.testTarget(venvPepper, 'I@manila:api')) { |
| 333 | 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() |
| 334 | if (!containsFix) { |
| 335 | fixFileContent << '- system.linux.network.hosts.openstack.share' |
| 336 | } |
| 337 | } |
| 338 | if (salt.testTarget(venvPepper, 'I@barbican:server')) { |
| 339 | 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() |
| 340 | if (!containsFix) { |
| 341 | fixFileContent << '- system.linux.network.hosts.openstack.kmn' |
| 342 | } |
| 343 | } |
| 344 | if (fixFileContent) { |
| 345 | salt.cmdRun(venvPepper, 'I@salt:master', "echo 'classes:\n${fixFileContent.join('\n')}' > ${fixFile}") |
| 346 | salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.infra.${fixName}' ${infraInitFile}") |
Ivan Berezovskiy | 8699f3f | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 347 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${fixFile}") |
Denis Egorenko | db45015 | 2020-01-28 16:41:44 +0400 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | |
Ivan Berezovskiy | 8699f3f | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 353 | def wa34528(String cluster_name) { |
| 354 | // Mysql users have to be defined on each Galera node |
| 355 | if(salt.getMinions(venvPepper, 'I@galera:master').isEmpty()) { |
| 356 | common.errorMsg('No Galera master found in cluster. Skipping') |
| 357 | return |
| 358 | } |
| 359 | def mysqlUsersMasterPillar = salt.getPillar(venvPepper, 'I@galera:master', 'mysql:server:database').get("return")[0].values()[0] |
| 360 | if (mysqlUsersMasterPillar == '' || mysqlUsersMasterPillar == 'null' || mysqlUsersMasterPillar == null) { |
| 361 | common.errorMsg('Pillar data is broken for Galera master node!') |
| 362 | input message: 'Do you want to ignore and continue without Galera pillar patch?' |
| 363 | return |
| 364 | } |
| 365 | def fileToPatch = salt.cmdRun(venvPepper, 'I@salt:master', "ls /srv/salt/reclass/classes/cluster/${cluster_name}/openstack/database/init.yml || " + |
| 366 | "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() |
| 367 | if (fileToPatch == 'File not found') { |
| 368 | common.errorMsg('Cluster model is old and cannot be patched for PROD-34528. Patching is possible for 2019.2.x cluster models only') |
| 369 | return |
| 370 | } |
| 371 | def patchRequired = false |
| 372 | def mysqlUsersSlavePillar = '' |
| 373 | def galeraSlaveNodes = salt.getMinions(venvPepper, 'I@galera:slave') |
| 374 | if (!galeraSlaveNodes.isEmpty()) { |
| 375 | for (galeraSlave in galeraSlaveNodes) { |
| 376 | mysqlUsersSlavePillar = salt.getPillar(venvPepper, galeraSlave, 'mysql:server:database').get("return")[0].values()[0] |
| 377 | if (mysqlUsersSlavePillar == '' || mysqlUsersSlavePillar == 'null' || mysqlUsersSlavePillar == null) { |
| 378 | common.errorMsg('Mysql users data is not defined for Galera slave nodes. Fixing...') |
| 379 | patchRequired = true |
| 380 | break |
| 381 | } |
| 382 | } |
| 383 | if (patchRequired) { |
| 384 | def fixFileContent = [] |
| 385 | def fixName = 'db_wa34528' |
| 386 | def fixFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/database/${fixName}.yml" |
| 387 | for (dbName in mysqlUsersMasterPillar.keySet()) { |
| 388 | def classIncluded = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- system\\.galera\\.server\\.database\\.${dbName}\$'" + |
| 389 | " /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() |
| 390 | if(classIncluded) { |
| 391 | fixFileContent << "- system.galera.server.database.${dbName}" |
| 392 | } |
| 393 | def sslClassIncluded = salt.cmdRun(venvPepper, 'I@salt:master', "grep -E '^- system\\.galera\\.server\\.database\\.x509\\.${dbName}\$'" + |
| 394 | " /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() |
| 395 | if(sslClassIncluded) { |
| 396 | fixFileContent << "- system.galera.server.database.x509.${dbName}" |
| 397 | } |
| 398 | } |
| 399 | if (fixFileContent) { |
| 400 | salt.cmdRun(venvPepper, 'I@salt:master', "echo 'classes:\n${fixFileContent.join('\n')}' > ${fixFile}") |
| 401 | salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.database.${fixName}' ${fileToPatch}") |
| 402 | } |
| 403 | salt.fullRefresh(venvPepper, 'I@galera:slave') |
| 404 | // Verify |
| 405 | for (galeraSlave in galeraSlaveNodes) { |
| 406 | mysqlUsersSlavePillar = salt.getPillar(venvPepper, galeraSlave, 'mysql:server:database').get("return")[0].values()[0] |
| 407 | if (mysqlUsersSlavePillar == '' || mysqlUsersSlavePillar == 'null' || mysqlUsersSlavePillar == null || mysqlUsersSlavePillar.keySet() != mysqlUsersMasterPillar.keySet()) { |
| 408 | common.errorMsg("Mysql user data is different on master and slave node ${galeraSlave}.") |
| 409 | input message: 'Do you want to ignore and continue?' |
| 410 | } |
| 411 | } |
| 412 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && git add ${fixFile}") |
| 413 | common.infoMsg('Galera slaves patching is done') |
| 414 | } else { |
| 415 | common.infoMsg('Galera slaves patching is not required') |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 420 | def archiveReclassInventory(filename) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 421 | def _tmp_file = '/tmp/' + filename + UUID.randomUUID().toString().take(8) |
| 422 | // jenkins may fail at overheap. Compress data with gzip like WA |
| 423 | 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() |
| 424 | def _tmp = sh(script: "echo '$ret' > ${_tmp_file}", returnStdout: false) |
| 425 | sh(script: "cat ${_tmp_file} | base64 -d | gzip -d > $filename", returnStdout: false) |
| 426 | archiveArtifacts artifacts: filename |
| 427 | sh(script: "rm -v ${_tmp_file}|| true") |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 428 | } |
| 429 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 430 | def validateReclassModel(ArrayList saltMinions, String suffix) { |
| 431 | try { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 432 | for (String minion in saltMinions) { |
| 433 | common.infoMsg("Reclass model validation for minion ${minion}...") |
| 434 | 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() |
| 435 | writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString() |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 436 | } |
| 437 | } catch (Exception e) { |
| 438 | common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.') |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 439 | error(e.toString()) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 443 | def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix = 'before', String newSuffix = 'after') { |
| 444 | for (String minion in saltMinions) { |
| 445 | def fileName = "reclass-model-${minion}-diff.out" |
| 446 | sh "diff -u inventory-${minion}-${oldSuffix}.out inventory-${minion}-${newSuffix}.out > ${fileName} || true" |
| 447 | archiveArtifacts artifacts: "${fileName}" |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | |
Denis Egorenko | bf39010 | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 451 | def checkCICDDocker() { |
| 452 | common.infoMsg('Perform: Checking if Docker containers are up') |
| 453 | try { |
| 454 | common.retry(10, 30) { |
| 455 | salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'") |
| 456 | } |
| 457 | } |
| 458 | catch (Exception ex) { |
| 459 | error("Docker containers for CI/CD services are having troubles with starting.") |
| 460 | } |
| 461 | } |
| 462 | |
Denis Egorenko | 5a8a7e9 | 2018-12-27 14:13:48 +0400 | [diff] [blame] | 463 | if (common.validInputParam('PIPELINE_TIMEOUT')) { |
| 464 | try { |
| 465 | pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger() |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 466 | } catch (Exception e) { |
Denis Egorenko | 5a8a7e9 | 2018-12-27 14:13:48 +0400 | [diff] [blame] | 467 | common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger") |
| 468 | } |
Martin Polreich | 965c903 | 2018-08-09 16:33:57 +0200 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | timeout(time: pipelineTimeout, unit: 'HOURS') { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 472 | node("python") { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 473 | try { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 474 | def inventoryBeforeFilename = "reclass-inventory-before.out" |
| 475 | def inventoryAfterFilename = "reclass-inventory-after.out" |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 476 | workspace = common.getWorkspace() |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 477 | targetMcpVersion = null |
| 478 | if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) { |
| 479 | error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable') |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 480 | } |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 481 | // bw comp. for 2018.X => 2018.11 release |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 482 | if (common.validInputParam('MCP_VERSION')) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 483 | targetMcpVersion = env.MCP_VERSION |
| 484 | common.warningMsg("targetMcpVersion has been changed to:${targetMcpVersion}, which was taken from deprecated pipeline viriable:MCP_VERSION") |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 485 | } else { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 486 | targetMcpVersion = env.TARGET_MCP_VERSION |
| 487 | } |
| 488 | // end bw comp. for 2018.X => 2018.11 release |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 489 | def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC') |
Ivan Berezovskiy | d62629c | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 490 | if (targetMcpVersion in ['nightly', 'testing']) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 491 | gitTargetMcpVersion = 'master' |
Ivan Berezovskiy | d62629c | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 492 | } else if (targetMcpVersion == 'proposed') { |
| 493 | gitTargetMcpVersion = 'proposed' |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 494 | } else if (!gitTargetMcpVersion) { |
| 495 | // backward compatibility for 2018.11.0 |
| 496 | gitTargetMcpVersion = "release/${targetMcpVersion}" |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 497 | } |
Ivan Berezovskiy | d62629c | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 498 | common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}") |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 499 | def upgradeSaltStack = '' |
| 500 | def updateClusterModel = '' |
| 501 | def updatePipelines = '' |
| 502 | def updateLocalRepos = '' |
| 503 | def reclassSystemBranch = '' |
Denis Egorenko | b559e54 | 2019-03-29 13:24:15 +0400 | [diff] [blame] | 504 | def reclassSystemBranchDefault = gitTargetMcpVersion |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 505 | def batchSize = '' |
Ivan Berezovskiy | 304705c | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 506 | if (gitTargetMcpVersion ==~ /^\d\d\d\d\.\d\d?\.\d+$/) { |
| 507 | reclassSystemBranchDefault = "tags/${gitTargetMcpVersion}" |
| 508 | } else if (gitTargetMcpVersion != 'proposed') { |
Denis Egorenko | b559e54 | 2019-03-29 13:24:15 +0400 | [diff] [blame] | 509 | reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}" |
| 510 | } |
Hanna Arhipova | 644aefd | 2019-09-06 17:55:40 +0300 | [diff] [blame] | 511 | def driveTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS') |
| 512 | if (driveTrainParamsYaml) { |
| 513 | def driveTrainParams = readYaml text: driveTrainParamsYaml |
| 514 | saltMastURL = driveTrainParams.get('SALT_MASTER_URL') |
| 515 | saltMastCreds = driveTrainParams.get('SALT_MASTER_CREDENTIALS') |
| 516 | upgradeSaltStack = driveTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean() |
| 517 | updateClusterModel = driveTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean() |
| 518 | updatePipelines = driveTrainParams.get('UPDATE_PIPELINES', false).toBoolean() |
| 519 | updateLocalRepos = driveTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean() |
| 520 | reclassSystemBranch = driveTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault) |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 521 | batchSize = driveTrainParams.get('BATCH_SIZE', '') |
Denis Egorenko | bf39010 | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 522 | if (driveTrainParams.get('OS_DIST_UPGRADE', false).toBoolean() == true) { |
| 523 | packageUpgradeMode = 'dist-upgrade' |
| 524 | } else if (driveTrainParams.get('OS_UPGRADE', false).toBoolean() == true) { |
| 525 | packageUpgradeMode = 'upgrade' |
| 526 | } |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 527 | } else { |
| 528 | // backward compatibility for 2018.11.0 |
| 529 | saltMastURL = env.getProperty('SALT_MASTER_URL') |
| 530 | saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS') |
Denis Egorenko | e5f3914 | 2018-12-28 12:30:48 +0400 | [diff] [blame] | 531 | upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean() |
| 532 | updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean() |
| 533 | updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean() |
| 534 | updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean() |
Denis Egorenko | b559e54 | 2019-03-29 13:24:15 +0400 | [diff] [blame] | 535 | reclassSystemBranch = reclassSystemBranchDefault |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 536 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 537 | python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 538 | def minions = salt.getMinions(venvPepper, '*') |
Denis Egorenko | c0538ce | 2019-04-19 15:05:18 +0400 | [diff] [blame] | 539 | def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0] |
| 540 | if (cluster_name == '' || cluster_name == 'null' || cluster_name == null) { |
| 541 | error('Pillar data is broken for Salt master node! Please check it manually and re-run pipeline.') |
| 542 | } |
Hanna Arhipova | 644aefd | 2019-09-06 17:55:40 +0300 | [diff] [blame] | 543 | if (!batchSize) { |
Denis Egorenko | 9ef25b9 | 2019-12-19 16:45:25 +0400 | [diff] [blame] | 544 | // if no batch size provided get current worker threads and set batch size to 2/3 of it to avoid |
| 545 | // 'SaltReqTimeoutError: Message timed out' issue on Salt targets for large amount of nodes |
| 546 | // do not use toDouble/Double as it requires additional approved method |
| 547 | def workerThreads = getWorkerThreads(venvPepper).toInteger() |
| 548 | batch_size = (workerThreads * 2 / 3).toString().tokenize('.')[0] |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 549 | } |
Ivan Berezovskiy | 304705c | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 550 | def computeMinions = salt.getMinions(venvPepper, 'I@nova:compute') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 551 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 552 | stage('Update Reclass and Salt-Formulas') { |
| 553 | common.infoMsg('Perform: Full salt sync') |
| 554 | salt.fullRefresh(venvPepper, '*') |
| 555 | common.infoMsg('Perform: Validate reclass medata before processing') |
| 556 | validateReclassModel(minions, 'before') |
| 557 | |
| 558 | common.infoMsg('Perform: archiveReclassInventory before upgrade') |
Denis Egorenko | 89a3c57 | 2019-03-22 17:03:40 +0400 | [diff] [blame] | 559 | archiveReclassInventory(inventoryBeforeFilename) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 560 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 561 | try { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 562 | salt.cmdRun(venvPepper, 'I@salt:master', 'cd /srv/salt/reclass/ && git status && git diff-index --quiet HEAD --') |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 563 | } |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 564 | catch (Exception ex) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 565 | error('You have uncommitted changes in your Reclass cluster model repository. Please commit or reset them and rerun the pipeline.') |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 566 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 567 | if (updateClusterModel) { |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 568 | common.infoMsg('Perform: UPDATE_CLUSTER_MODEL') |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 569 | def dateTime = common.getDatetime() |
Ivan Berezovskiy | 1d78052 | 2020-01-17 13:55:18 +0400 | [diff] [blame] | 570 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git fetch") |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 571 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
Denis Egorenko | 928b3e8 | 2019-01-15 11:47:16 +0400 | [diff] [blame] | 572 | "grep -r --exclude-dir=aptly -l 'mcp_version: .*' * | xargs --no-run-if-empty sed -i 's|mcp_version: .*|mcp_version: \"$targetMcpVersion\"|g'") |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 573 | // Do the same, for deprecated variable-duplicate |
| 574 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
Denis Egorenko | 928b3e8 | 2019-01-15 11:47:16 +0400 | [diff] [blame] | 575 | "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 Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 576 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
Denis Egorenko | 928b3e8 | 2019-01-15 11:47:16 +0400 | [diff] [blame] | 577 | "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 Ryzhenkin | 202c506 | 2019-01-15 19:58:03 +0400 | [diff] [blame] | 578 | // Set new k8s param |
| 579 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 580 | "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 Egorenko | 2a39d2c | 2019-01-16 19:18:31 +0400 | [diff] [blame] | 581 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 582 | "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'") |
| 583 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
Denis Egorenko | ca871c2 | 2019-02-13 13:49:13 +0400 | [diff] [blame] | 584 | "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 Egorenko | 2a39d2c | 2019-01-16 19:18:31 +0400 | [diff] [blame] | 585 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
Denis Egorenko | ca871c2 | 2019-02-13 13:49:13 +0400 | [diff] [blame] | 586 | "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 Samoylov | 72c2ccf | 2019-02-13 15:57:13 +0400 | [diff] [blame] | 587 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 588 | "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 Egorenko | 6ca9f0d | 2019-07-10 19:47:39 +0400 | [diff] [blame] | 589 | |
Denis Egorenko | 70f4f9a | 2019-09-16 16:41:26 +0400 | [diff] [blame] | 590 | 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") |
| 591 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name/infra && sed -i '/maas_region_main_archive/d' maas.yml") |
| 592 | |
Denis Egorenko | 6ca9f0d | 2019-07-10 19:47:39 +0400 | [diff] [blame] | 593 | // Switch Jenkins/Gerrit to use LDAP SSL/TLS |
| 594 | def gerritldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 595 | "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() |
| 596 | if (gerritldapURI.startsWith('ldap://')) { |
| 597 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 598 | "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'") |
| 599 | } else if (! gerritldapURI.startsWith('ldaps://')) { |
| 600 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 601 | "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'") |
| 602 | } |
| 603 | def jenkinsldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 604 | "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() |
| 605 | if (jenkinsldapURI.startsWith('ldap://')) { |
| 606 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 607 | "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'") |
| 608 | } else if (! jenkinsldapURI.startsWith('ldaps://')) { |
| 609 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 610 | "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'") |
| 611 | } |
| 612 | |
Denis Egorenko | bae9dc7 | 2019-07-29 17:44:46 +0400 | [diff] [blame] | 613 | wa32284(cluster_name) |
Denis Egorenko | db45015 | 2020-01-28 16:41:44 +0400 | [diff] [blame] | 614 | wa34245(cluster_name) |
Denis Egorenko | bae9dc7 | 2019-07-29 17:44:46 +0400 | [diff] [blame] | 615 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 616 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}") |
Sergey Kolekonov | 6ab1511 | 2019-01-23 16:47:43 +0400 | [diff] [blame] | 617 | // Add kubernetes-extra repo |
| 618 | if (salt.testTarget(venvPepper, "I@kubernetes:master")) { |
Sergey Kolekonov | ac9554c | 2019-04-11 16:33:54 +0400 | [diff] [blame] | 619 | // docker-engine conflicts with the recent containerd versions, so it's removed during upgrade. Thus update source engine |
| 620 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 621 | "grep -r -l 'engine: docker_hybrid' kubernetes | xargs --no-run-if-empty sed -i 's/engine: docker_hybrid/engine: archive/g'") |
Sergey Kolekonov | 6ab1511 | 2019-01-23 16:47:43 +0400 | [diff] [blame] | 622 | common.infoMsg("Add kubernetes-extra repo") |
| 623 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 624 | "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") |
| 625 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 626 | "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") |
| 627 | } |
Ivan Berezovskiy | be630ee | 2019-04-15 13:23:58 +0400 | [diff] [blame] | 628 | // Add all update repositories |
| 629 | def repoIncludeBase = '- system.linux.system.repo.mcp.apt_mirantis.' |
Denis Egorenko | 70f4f9a | 2019-09-16 16:41:26 +0400 | [diff] [blame] | 630 | def updateRepoList = ['cassandra', 'ceph', 'contrail', 'docker', 'elastic', 'extra', 'openstack', 'maas', 'percona', 'salt-formulas', 'saltstack', 'ubuntu'] |
Ivan Berezovskiy | be630ee | 2019-04-15 13:23:58 +0400 | [diff] [blame] | 631 | updateRepoList.each { repo -> |
| 632 | def repoNameUpdateInclude = "${repoIncludeBase}update.${repo}" |
| 633 | 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') |
| 634 | filesWithInclude.each { file -> |
| 635 | 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() |
| 636 | if (updateRepoIncludeExist == 'not_found') { |
| 637 | // Include needs to be added |
| 638 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 639 | "sed -i 's/\\( *\\)${repoIncludeBase}${repo}\$/&\\n\\1${repoNameUpdateInclude}/g' ${file}") |
Ivan Berezovskiy | be630ee | 2019-04-15 13:23:58 +0400 | [diff] [blame] | 640 | common.infoMsg("Update repo for ${repo} is added to ${file}") |
| 641 | } |
| 642 | } |
| 643 | } |
Denis Egorenko | da11789 | 2019-09-02 14:53:02 +0400 | [diff] [blame] | 644 | wa32182(cluster_name) |
Denis Egorenko | 7e934c2 | 2019-10-18 17:06:11 +0400 | [diff] [blame] | 645 | wa33771(cluster_name) |
Denis Egorenko | 3246108 | 2019-10-25 13:13:39 +0400 | [diff] [blame] | 646 | wa33867(cluster_name) |
Denis Egorenko | 4ac89a3 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 647 | wa33930_33931(cluster_name) |
Ivan Berezovskiy | 8699f3f | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 648 | wa34528(cluster_name) |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 649 | // Add new defaults |
| 650 | common.infoMsg("Add new defaults") |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 651 | salt.cmdRun(venvPepper, 'I@salt:master', "grep '^ mcp_version: ' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " + |
Denis Egorenko | 928b3e8 | 2019-01-15 11:47:16 +0400 | [diff] [blame] | 652 | "sed -i 's|^ _param:| _param:\\n mcp_version: \"$targetMcpVersion\"|' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml") |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 653 | salt.cmdRun(venvPepper, 'I@salt:master', "grep '^- system.defaults\$' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " + |
Denis Egorenko | 928b3e8 | 2019-01-15 11:47:16 +0400 | [diff] [blame] | 654 | "sed -i 's|^classes:|classes:\\n- system.defaults|' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml") |
Ivan Berezovskiy | adb7d83 | 2019-04-23 14:32:02 +0400 | [diff] [blame] | 655 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 656 | "grep -r -l 'docker_image_jenkins: .*' cicd | xargs --no-run-if-empty sed -i 's|\\s*docker_image_jenkins: .*||g'") |
| 657 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 658 | "grep -r -l 'docker_image_jenkins_slave: .*' cicd | xargs --no-run-if-empty sed -i 's|\\s*docker_image_jenkins_slave: .*||g'") |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 659 | common.infoMsg("The following changes were made to the cluster model and will be commited. " + |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 660 | "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.") |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 661 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff") |
| 662 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " + |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 663 | "git add -u && git commit --allow-empty -m 'Cluster model update to the release $targetMcpVersion on $dateTime'") |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 664 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 665 | try { |
| 666 | common.infoMsg('Perform: UPDATE Salt Formulas') |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 667 | salt.fullRefresh(venvPepper, '*') |
| 668 | salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 669 | def saltEnv = salt.getPillar(venvPepper, 'I@salt:master', "_param:salt_master_base_environment").get("return")[0].values()[0] |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 670 | salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas", 'salt.master.env']) |
| 671 | salt.fullRefresh(venvPepper, '*') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 672 | } catch (Exception updateErr) { |
| 673 | common.warningMsg(updateErr) |
| 674 | common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.') |
| 675 | input message: 'Continue anyway?' |
| 676 | } |
| 677 | |
Ivan Berezovskiy | 304705c | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 678 | wa29352(cluster_name) |
Denis Egorenko | e983d45 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 679 | wa29155(computeMinions, cluster_name) |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 680 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 681 | try { |
| 682 | common.infoMsg('Perform: UPDATE Reclass package') |
| 683 | salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"]) |
| 684 | } catch (Exception updateErr) { |
| 685 | common.warningMsg(updateErr) |
| 686 | common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.') |
| 687 | input message: 'Continue anyway?' |
| 688 | } |
| 689 | |
| 690 | salt.fullRefresh(venvPepper, 'I@salt:master') |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 691 | salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true) |
Ivan Berezovskiy | 304705c | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 692 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && " + |
| 693 | "git add -u && git commit --allow-empty -m 'Reclass nodes update to the release ${targetMcpVersion} on ${common.getDatetime()}'") |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 694 | try { |
| 695 | salt.enforceState(venvPepper, "I@salt:master", 'reclass', true) |
| 696 | } |
| 697 | catch (Exception ex) { |
| 698 | error("Reclass fails rendering. Pay attention to your cluster model.") |
| 699 | } |
| 700 | |
| 701 | salt.fullRefresh(venvPepper, '*') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 702 | try { |
| 703 | salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top") |
| 704 | } |
| 705 | catch (Exception ex) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 706 | |
| 707 | error('Reclass fails rendering. Pay attention to your cluster model.' + |
| 708 | 'ErrorMessage:' + ex.toString()) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 709 | } |
| 710 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 711 | common.infoMsg('Perform: archiveReclassInventory AFTER upgrade') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 712 | archiveReclassInventory(inventoryAfterFilename) |
| 713 | |
| 714 | sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true" |
| 715 | archiveArtifacts artifacts: "reclass-inventory-diff.out" |
| 716 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 717 | validateReclassModel(minions, 'after') |
| 718 | archiveReclassModelChanges(minions) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 719 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 720 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 721 | if (updateLocalRepos) { |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 722 | stage("Update local repos") { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 723 | common.infoMsg("Updating local repositories") |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 724 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 725 | def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine") |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 726 | runningOnDocker = engine.get("return")[0].containsValue("docker") |
| 727 | |
| 728 | if (runningOnDocker) { |
| 729 | common.infoMsg("Aptly is running as Docker container") |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 730 | } else { |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 731 | common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands") |
| 732 | } |
| 733 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 734 | if (runningOnDocker) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 735 | 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) |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 736 | } else { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 737 | 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 Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 738 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 739 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 740 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 741 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 742 | if (runningOnDocker) { |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 743 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true) |
| 744 | 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) |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 745 | } else { |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 746 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true) |
| 747 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=-afrv", 'runas=aptly'], null, true) |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 748 | } |
Richard Felkl | 79d7df1 | 2018-01-05 16:40:11 +0100 | [diff] [blame] | 749 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 750 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 751 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 752 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 753 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 754 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true) |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 755 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 756 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 757 | } |
| 758 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 759 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 760 | stage('Update Drivetrain') { |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 761 | if (upgradeSaltStack) { |
| 762 | updateSaltStack("I@salt:master", '["salt-master", "salt-common", "salt-api", "salt-minion"]') |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 763 | |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 764 | salt.enforceState(venvPepper, "I@linux:system", 'linux.system.repo', true, true, batchSize) |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 765 | updateSaltStack("I@salt:minion and not I@salt:master", '["salt-minion"]') |
| 766 | } |
| 767 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 768 | if (updatePipelines) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 769 | common.infoMsg('Perform: UPDATE git repos') |
| 770 | triggerMirrorJob('git-mirror-downstream-mk-pipelines', reclassSystemBranch) |
| 771 | triggerMirrorJob('git-mirror-downstream-pipeline-library', reclassSystemBranch) |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 772 | } |
| 773 | |
Denis Egorenko | d00c17e | 2019-04-25 20:17:27 +0400 | [diff] [blame] | 774 | // update minions certs |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 775 | salt.enforceState(venvPepper, "I@salt:minion", 'salt.minion.cert', true, true, batchSize) |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 776 | |
| 777 | // Retry needed only for rare race-condition in user appearance |
| 778 | common.infoMsg('Perform: updating users and keys') |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 779 | salt.enforceState(venvPepper, "I@linux:system", 'linux.system.user', true, true, batchSize) |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 780 | common.infoMsg('Perform: updating openssh') |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 781 | salt.enforceState(venvPepper, "I@linux:system", 'openssh', true, true, batchSize) |
Denis Egorenko | aeaa1de | 2019-01-15 11:58:12 +0400 | [diff] [blame] | 782 | |
Denis Egorenko | e69920e | 2019-10-30 13:26:59 +0400 | [diff] [blame] | 783 | // 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 |
| 784 | def gerritGlusterPath = salt.getPillar(venvPepper, 'I@gerrit:client', 'glusterfs:client:volumes:gerrit:path').get('return')[0].values()[0] |
| 785 | def wrongPluginJarName = "${gerritGlusterPath}/plugins/project-download-commands.jar" |
Ivan Berezovskiy | 304705c | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 786 | salt.cmdRun(venvPepper, 'I@gerrit:client', "test -f ${wrongPluginJarName} && rm ${wrongPluginJarName} || true") |
Denis Egorenko | e69920e | 2019-10-30 13:26:59 +0400 | [diff] [blame] | 787 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 788 | 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 Berezovskiy | 24b0be0 | 2019-12-11 15:31:10 +0400 | [diff] [blame] | 789 | } |
| 790 | } |
| 791 | catch (Throwable e) { |
| 792 | // If there was an error or exception thrown, the build failed |
| 793 | currentBuild.result = "FAILURE" |
| 794 | throw e |
| 795 | } |
| 796 | } |
| 797 | // docker.client state may trigger change of jenkins master or jenkins slave services, |
| 798 | // so we need wait for slave to reconnect and continue pipeline |
| 799 | sleep(180) |
Denis Egorenko | bf39010 | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 800 | def cidNodes = [] |
Ivan Berezovskiy | 24b0be0 | 2019-12-11 15:31:10 +0400 | [diff] [blame] | 801 | node('python') { |
| 802 | try { |
| 803 | stage('Update Drivetrain: Phase 2') { |
| 804 | python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds) |
Denis Egorenko | bf39010 | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 805 | checkCICDDocker() |
Denis Egorenko | 6ca9f0d | 2019-07-10 19:47:39 +0400 | [diff] [blame] | 806 | |
Ivan Berezovskiy | 304705c | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 807 | // Apply changes for HaProxy on CI/CD nodes |
| 808 | salt.enforceState(venvPepper, 'I@keepalived:cluster:instance:cicd_control_vip and I@haproxy:proxy', 'haproxy.proxy', true) |
| 809 | |
| 810 | salt.enforceState(venvPepper, 'I@jenkins:client and not I@salt:master', 'jenkins.client', true, true, null, false, 60, 2) |
Denis Egorenko | 84a0bc0 | 2019-07-23 18:01:21 +0400 | [diff] [blame] | 811 | |
| 812 | // update Nginx proxy settings for Jenkins/Gerrit if needed |
| 813 | if (salt.testTarget(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit')) { |
| 814 | 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) |
| 815 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 816 | } |
Denis Egorenko | bf39010 | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 817 | if (packageUpgradeMode) { |
| 818 | cidNodes = salt.getMinions(venvPepper, 'I@_param:drivetrain_role:cicd') |
| 819 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 820 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 821 | catch (Throwable e) { |
| 822 | // If there was an error or exception thrown, the build failed |
| 823 | currentBuild.result = "FAILURE" |
| 824 | throw e |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 825 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 826 | } |
Denis Egorenko | bf39010 | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 827 | |
| 828 | stage('Upgrade OS') { |
| 829 | if (packageUpgradeMode) { |
| 830 | def debian = new com.mirantis.mk.Debian() |
| 831 | def statusFile = '/tmp/rebooted_during_upgrade' |
| 832 | for(cidNode in cidNodes) { |
| 833 | node('python') { |
| 834 | python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds) |
| 835 | // cmd.run async to prevent connection close in case of slave shutdown, give 5 seconds to handle request response |
| 836 | salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${cidNode}' cmd.run 'sleep 5; touch ${statusFile}; salt-call service.stop docker' --async") |
| 837 | } |
| 838 | sleep(30) |
| 839 | node('python') { |
| 840 | python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds) |
| 841 | debian.osUpgradeNode(venvPepper, cidNode, packageUpgradeMode, false, 60) |
| 842 | salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': cidNode, wait: 60, timeout: 10]) |
| 843 | if (salt.runSaltProcessStep(venvPepper, cidNode, 'file.file_exists', [statusFile], null, true, 5)['return'][0].values()[0].toBoolean()) { |
| 844 | 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 |
| 845 | sleep(10) |
| 846 | } |
| 847 | checkCICDDocker() |
| 848 | } |
| 849 | } |
| 850 | } else { |
| 851 | common.infoMsg('Upgrade OS skipped...') |
| 852 | } |
| 853 | } |
Hanna Arhipova | 644aefd | 2019-09-06 17:55:40 +0300 | [diff] [blame] | 854 | } |