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 |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 16 | * 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 Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 19 | */ |
| 20 | |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 21 | salt = new com.mirantis.mk.Salt() |
| 22 | common = new com.mirantis.mk.Common() |
| 23 | python = new com.mirantis.mk.Python() |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 24 | jenkinsUtils = new com.mirantis.mk.JenkinsUtils() |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 25 | def pipelineTimeout = 12 |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 26 | venvPepper = "venvPepper" |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 27 | workspace = "" |
Ivan Berezovskiy | 24b0be0 | 2019-12-11 15:31:10 +0400 | [diff] [blame] | 28 | def saltMastURL = '' |
| 29 | def saltMastCreds = '' |
Denis Egorenko | bf39010 | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 30 | def packageUpgradeMode = '' |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 31 | batchSize = '' |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 32 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 33 | def triggerMirrorJob(String jobName, String reclassSystemBranch) { |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 34 | params = jenkinsUtils.getJobParameters(jobName) |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 35 | 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 Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 52 | } |
| 53 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 54 | def updateSaltStack(target, pkgs) { |
Denis Egorenko | 0d0c65f | 2019-02-26 16:05:03 +0400 | [diff] [blame] | 55 | salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${target}' --async pkg.install force_yes=True pkgs='$pkgs'") |
| 56 | // can't use same function from pipeline lib, as at the moment of running upgrade pipeline Jenkins |
| 57 | // still using pipeline lib from current old mcp-version |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 58 | common.retry(20, 60) { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 59 | salt.minionsReachable(venvPepper, 'I@salt:master', '*') |
| 60 | def running = salt.runSaltProcessStep(venvPepper, target, 'saltutil.running', [], null, true, 5) |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 61 | for (value in running.get("return")[0].values()) { |
| 62 | if (value != []) { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 63 | throw new Exception("Not all salt-minions are ready for execution") |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 68 | 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] | 69 | 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] | 70 | def saltMinionVersion = "" |
| 71 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 72 | for (minion in saltMinionVersions[0].keySet()) { |
| 73 | saltMinionVersion = saltMinionVersions[0].get(minion).replace("Salt command execution success", "").trim() |
| 74 | if (saltMinionVersion == "") { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 75 | error("Installed version of Salt on $minion doesn't match specified version in the model.") |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
Denis Egorenko | 6f1c873 | 2019-09-24 14:55:50 +0400 | [diff] [blame] | 80 | def 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 Berezovskiy | 304705c | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 88 | def wa29352(String cname) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 89 | // 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 Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 97 | salt.cmdRun(venvPepper, 'I@salt:master', "! grep -qi root_private_key: ${wa29352SecretsFile}", true, null, false) |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 98 | salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29352File}", true, null, false) |
| 99 | } |
| 100 | catch (Exception ex) { |
Denis Egorenko | e0c8843 | 2019-10-07 12:46:14 +0400 | [diff] [blame] | 101 | common.infoMsg('Work-around for PROD-29352 already applied, nothing todo') |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 102 | 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 Egorenko | e0c8843 | 2019-10-07 12:46:14 +0400 | [diff] [blame] | 130 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " + |
| 131 | "git add ${wa29352File} && git add -u && git commit --allow-empty -m 'Cluster model updated with WA for PROD-29352. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/ at ${common.getDatetime()}' ") |
| 132 | common.infoMsg('Work-around for PROD-29352 successfully applied') |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | def wa29155(ArrayList saltMinions, String cname) { |
| 136 | // WA for PROD-29155. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/ |
| 137 | // CHeck for existence cmp nodes, and try to render it. Is failed, apply ssh-key wa |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 138 | 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 Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 144 | def patch_required = false |
| 145 | for (String minion in saltMinions) { |
| 146 | def nova_key = salt.getPillar(venvPepper, minion, '_param:nova_compute_ssh_private').get("return")[0].values()[0] |
| 147 | if (nova_key == '' || nova_key == 'null' || nova_key == null) { |
| 148 | patch_required = true |
| 149 | break // no exception, proceeding to apply the patch |
| 150 | } |
| 151 | } |
| 152 | if (!patch_required) { |
| 153 | error('No need to apply work-around for PROD-29155') |
| 154 | } |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 155 | } |
| 156 | catch (Exception ex) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 157 | return |
| 158 | } |
Denis Egorenko | e983d45 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 159 | salt.fullRefresh(venvPepper, 'I@salt:master') |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 160 | for (String minion in saltMinions) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 161 | // First attempt, second will be performed in next validateReclassModel() stages |
| 162 | try { |
| 163 | salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim() |
| 164 | } catch (Exception e) { |
| 165 | common.errorMsg(e.toString()) |
| 166 | if (patched) { |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 167 | error("Node: ${minion} failed to render after reclass-system upgrade! WA29155 probably didn't help.") |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 168 | } |
| 169 | common.warningMsg('Perform: Attempt to apply WA for PROD-29155\n' + |
| 170 | 'See https://gerrit.mcp.mirantis.com/#/c/37932/ for more info') |
| 171 | common.warningMsg('WA-PROD-29155 Generating new ssh key at master node') |
| 172 | def _tempFile = "/tmp/nova_wa29155_" + UUID.randomUUID().toString().take(8) |
| 173 | common.infoMsg('Perform: generation NEW ssh-private key for nova-compute') |
| 174 | salt.cmdRun(venvPepper, 'I@salt:master', "ssh-keygen -f ${_tempFile} -N '' -q") |
| 175 | def _pub_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}.pub").get('return')[0].values()[0].trim() |
| 176 | def _priv_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}").get('return')[0].values()[0].trim() |
| 177 | salt.cmdRun(venvPepper, 'I@salt:master', "rm -fv ${_tempFile}", false, null, false) |
| 178 | def novaKeysDict = [ |
| 179 | "parameters": [ |
| 180 | "_param": [ |
| 181 | "nova_compute_ssh_private": _priv_k, |
| 182 | "nova_compute_ssh_public" : _pub_k |
| 183 | ] |
| 184 | ] |
| 185 | ] |
| 186 | writeYaml file: _tempFile, data: novaKeysDict |
| 187 | def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim() |
| 188 | salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29155File}", false, null, false) |
| 189 | common.infoMsg("Add $wa29155ClassName class into secrets.yml") |
| 190 | |
| 191 | // Add 'classes:' directive |
| 192 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " + |
| 193 | "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml") |
| 194 | |
| 195 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " + |
| 196 | "grep -q '${wa29155ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29155ClassName' infra/secrets.yml") |
Ivan Berezovskiy | 304705c | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 197 | salt.fullRefresh(venvPepper, 'I@salt:master') |
| 198 | salt.fullRefresh(venvPepper, saltMinions) |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 199 | 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 Berezovskiy | 8699f3f | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 210 | def wa32284(String cluster_name) { |
Denis Egorenko | bae9dc7 | 2019-07-29 17:44:46 +0400 | [diff] [blame] | 211 | 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 Berezovskiy | 8699f3f | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 217 | 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 Egorenko | bae9dc7 | 2019-07-29 17:44:46 +0400 | [diff] [blame] | 219 | 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 Berezovskiy | 8699f3f | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 223 | 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] | 224 | "sed -i '/^parameters:/i - ${nginxRequiresClassName}' infra/config/init.yml") |
| 225 | salt.cmdRun(venvPepper, 'I@salt:master', "echo '${nginxRequiresBlockString}' > ${nginxRequiresClassFile}", false, null, false) |
Ivan Berezovskiy | 8699f3f | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 226 | 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] | 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
Denis Egorenko | da11789 | 2019-09-02 14:53:02 +0400 | [diff] [blame] | 231 | def wa32182(String cluster_name) { |
Hanna Arhipova | 644aefd | 2019-09-06 17:55:40 +0300 | [diff] [blame] | 232 | if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) { |
Denis Egorenko | da11789 | 2019-09-02 14:53:02 +0400 | [diff] [blame] | 233 | 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 Berezovskiy | e375e6a | 2020-02-05 21:18:17 +0400 | [diff] [blame] | 242 | for (String contrailFile in contrailFiles) { |
Denis Egorenko | da11789 | 2019-09-02 14:53:02 +0400 | [diff] [blame] | 243 | 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 Berezovskiy | e375e6a | 2020-02-05 21:18:17 +0400 | [diff] [blame] | 249 | "echo '- cluster.${cluster_name}.opencontrail.common_wa32182' >> ${contrailFile}") |
Denis Egorenko | da11789 | 2019-09-02 14:53:02 +0400 | [diff] [blame] | 250 | } |
| 251 | } |
Ivan Berezovskiy | e375e6a | 2020-02-05 21:18:17 +0400 | [diff] [blame] | 252 | salt.cmdRun(venvPepper, 'I@salt:master', "test -f ${fixFile} && cd ${clusterModelPath} && git status && git add ${fixFile} || true") |
Denis Egorenko | da11789 | 2019-09-02 14:53:02 +0400 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
Denis Egorenko | 3246108 | 2019-10-25 13:13:39 +0400 | [diff] [blame] | 256 | def 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 Egorenko | 7e934c2 | 2019-10-18 17:06:11 +0400 | [diff] [blame] | 267 | def wa33771(String cluster_name) { |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 268 | 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 Egorenko | 7e934c2 | 2019-10-18 17:06:11 +0400 | [diff] [blame] | 279 | ] |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 280 | 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 Egorenko | 7235309 | 2020-01-30 17:17:25 +0400 | [diff] [blame] | 290 | } |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 291 | } else { |
| 292 | common.warningMsg("Apache server is not defined on controller nodes. Skipping Octavia WSGI workaround"); |
Denis Egorenko | 7e934c2 | 2019-10-18 17:06:11 +0400 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
Denis Egorenko | 4ac89a3 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 296 | def 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 Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 302 | 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 Egorenko | 4ac89a3 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 327 | if (salt.getMinions(venvPepper, 'I@manila:api:enabled')) { |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 328 | 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 Egorenko | 4ac89a3 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 336 | } |
| 337 | if (salt.getMinions(venvPepper, 'I@ironic:api:enabled')) { |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 338 | 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 Egorenko | 4ac89a3 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 346 | } |
| 347 | if (salt.getMinions(venvPepper, 'I@gnocchi:server:enabled')) { |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 348 | 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 Egorenko | 4ac89a3 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 356 | } |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 357 | |
Denis Egorenko | 4ac89a3 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 358 | if (salt.getMinions(venvPepper, 'I@barbican:server:enabled')) { |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 359 | 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 Egorenko | 4ac89a3 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 367 | } |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 368 | 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 Egorenko | 4ac89a3 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
Denis Egorenko | db45015 | 2020-01-28 16:41:44 +0400 | [diff] [blame] | 379 | def 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 Berezovskiy | 8699f3f | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 412 | 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] | 413 | } |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | |
Ivan Berezovskiy | 8699f3f | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 418 | def 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 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 485 | def archiveReclassInventory(filename) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 486 | def _tmp_file = '/tmp/' + filename + UUID.randomUUID().toString().take(8) |
| 487 | // jenkins may fail at overheap. Compress data with gzip like WA |
| 488 | def ret = salt.cmdRun(venvPepper, 'I@salt:master', 'reclass -i 2>/dev/null | gzip -9 -c | base64', true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim() |
| 489 | def _tmp = sh(script: "echo '$ret' > ${_tmp_file}", returnStdout: false) |
| 490 | sh(script: "cat ${_tmp_file} | base64 -d | gzip -d > $filename", returnStdout: false) |
| 491 | archiveArtifacts artifacts: filename |
| 492 | sh(script: "rm -v ${_tmp_file}|| true") |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 493 | } |
| 494 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 495 | def validateReclassModel(ArrayList saltMinions, String suffix) { |
| 496 | try { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 497 | for (String minion in saltMinions) { |
| 498 | common.infoMsg("Reclass model validation for minion ${minion}...") |
| 499 | def reclassInv = salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim() |
| 500 | writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString() |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 501 | } |
| 502 | } catch (Exception e) { |
| 503 | common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.') |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 504 | error(e.toString()) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 508 | def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix = 'before', String newSuffix = 'after') { |
| 509 | for (String minion in saltMinions) { |
| 510 | def fileName = "reclass-model-${minion}-diff.out" |
| 511 | sh "diff -u inventory-${minion}-${oldSuffix}.out inventory-${minion}-${newSuffix}.out > ${fileName} || true" |
| 512 | archiveArtifacts artifacts: "${fileName}" |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | |
Denis Egorenko | bf39010 | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 516 | def checkCICDDocker() { |
| 517 | common.infoMsg('Perform: Checking if Docker containers are up') |
| 518 | try { |
| 519 | common.retry(10, 30) { |
| 520 | salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'") |
| 521 | } |
| 522 | } |
| 523 | catch (Exception ex) { |
| 524 | error("Docker containers for CI/CD services are having troubles with starting.") |
| 525 | } |
| 526 | } |
| 527 | |
Denis Egorenko | 5a8a7e9 | 2018-12-27 14:13:48 +0400 | [diff] [blame] | 528 | if (common.validInputParam('PIPELINE_TIMEOUT')) { |
| 529 | try { |
| 530 | pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger() |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 531 | } catch (Exception e) { |
Denis Egorenko | 5a8a7e9 | 2018-12-27 14:13:48 +0400 | [diff] [blame] | 532 | common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger") |
| 533 | } |
Martin Polreich | 965c903 | 2018-08-09 16:33:57 +0200 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | timeout(time: pipelineTimeout, unit: 'HOURS') { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 537 | node("python") { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 538 | try { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 539 | def inventoryBeforeFilename = "reclass-inventory-before.out" |
| 540 | def inventoryAfterFilename = "reclass-inventory-after.out" |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 541 | workspace = common.getWorkspace() |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 542 | targetMcpVersion = null |
| 543 | if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) { |
| 544 | error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable') |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 545 | } |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 546 | // bw comp. for 2018.X => 2018.11 release |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 547 | if (common.validInputParam('MCP_VERSION')) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 548 | targetMcpVersion = env.MCP_VERSION |
| 549 | 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] | 550 | } else { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 551 | targetMcpVersion = env.TARGET_MCP_VERSION |
| 552 | } |
| 553 | // end bw comp. for 2018.X => 2018.11 release |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 554 | def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC') |
Ivan Berezovskiy | d62629c | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 555 | if (targetMcpVersion in ['nightly', 'testing']) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 556 | gitTargetMcpVersion = 'master' |
Ivan Berezovskiy | d62629c | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 557 | } else if (targetMcpVersion == 'proposed') { |
| 558 | gitTargetMcpVersion = 'proposed' |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 559 | } else if (!gitTargetMcpVersion) { |
| 560 | // backward compatibility for 2018.11.0 |
| 561 | gitTargetMcpVersion = "release/${targetMcpVersion}" |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 562 | } |
Ivan Berezovskiy | d62629c | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 563 | common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}") |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 564 | def upgradeSaltStack = '' |
| 565 | def updateClusterModel = '' |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 566 | def applyWorkarounds = true |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 567 | def updatePipelines = '' |
| 568 | def updateLocalRepos = '' |
| 569 | def reclassSystemBranch = '' |
Denis Egorenko | b559e54 | 2019-03-29 13:24:15 +0400 | [diff] [blame] | 570 | def reclassSystemBranchDefault = gitTargetMcpVersion |
Ivan Berezovskiy | 304705c | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 571 | if (gitTargetMcpVersion ==~ /^\d\d\d\d\.\d\d?\.\d+$/) { |
| 572 | reclassSystemBranchDefault = "tags/${gitTargetMcpVersion}" |
| 573 | } else if (gitTargetMcpVersion != 'proposed') { |
Denis Egorenko | b559e54 | 2019-03-29 13:24:15 +0400 | [diff] [blame] | 574 | reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}" |
| 575 | } |
Hanna Arhipova | 644aefd | 2019-09-06 17:55:40 +0300 | [diff] [blame] | 576 | def driveTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS') |
| 577 | if (driveTrainParamsYaml) { |
| 578 | def driveTrainParams = readYaml text: driveTrainParamsYaml |
| 579 | saltMastURL = driveTrainParams.get('SALT_MASTER_URL') |
| 580 | saltMastCreds = driveTrainParams.get('SALT_MASTER_CREDENTIALS') |
| 581 | upgradeSaltStack = driveTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean() |
| 582 | updateClusterModel = driveTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean() |
| 583 | updatePipelines = driveTrainParams.get('UPDATE_PIPELINES', false).toBoolean() |
| 584 | updateLocalRepos = driveTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean() |
| 585 | reclassSystemBranch = driveTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault) |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 586 | batchSize = driveTrainParams.get('BATCH_SIZE', '') |
Denis Egorenko | bf39010 | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 587 | if (driveTrainParams.get('OS_DIST_UPGRADE', false).toBoolean() == true) { |
| 588 | packageUpgradeMode = 'dist-upgrade' |
| 589 | } else if (driveTrainParams.get('OS_UPGRADE', false).toBoolean() == true) { |
| 590 | packageUpgradeMode = 'upgrade' |
| 591 | } |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 592 | applyWorkarounds = driveTrainParams.get('APPLY_MODEL_WORKAROUNDS', true).toBoolean() |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 593 | } else { |
| 594 | // backward compatibility for 2018.11.0 |
| 595 | saltMastURL = env.getProperty('SALT_MASTER_URL') |
| 596 | saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS') |
Denis Egorenko | e5f3914 | 2018-12-28 12:30:48 +0400 | [diff] [blame] | 597 | upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean() |
| 598 | updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean() |
| 599 | updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean() |
| 600 | updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean() |
Denis Egorenko | b559e54 | 2019-03-29 13:24:15 +0400 | [diff] [blame] | 601 | reclassSystemBranch = reclassSystemBranchDefault |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 602 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 603 | python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 604 | def minions = salt.getMinions(venvPepper, '*') |
Denis Egorenko | c0538ce | 2019-04-19 15:05:18 +0400 | [diff] [blame] | 605 | def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0] |
| 606 | if (cluster_name == '' || cluster_name == 'null' || cluster_name == null) { |
| 607 | error('Pillar data is broken for Salt master node! Please check it manually and re-run pipeline.') |
| 608 | } |
Hanna Arhipova | 644aefd | 2019-09-06 17:55:40 +0300 | [diff] [blame] | 609 | if (!batchSize) { |
Denis Egorenko | 9ef25b9 | 2019-12-19 16:45:25 +0400 | [diff] [blame] | 610 | // if no batch size provided get current worker threads and set batch size to 2/3 of it to avoid |
| 611 | // 'SaltReqTimeoutError: Message timed out' issue on Salt targets for large amount of nodes |
| 612 | // do not use toDouble/Double as it requires additional approved method |
| 613 | def workerThreads = getWorkerThreads(venvPepper).toInteger() |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 614 | batchSize = (workerThreads * 2 / 3).toString().tokenize('.')[0] |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 615 | } |
Ivan Berezovskiy | 304705c | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 616 | def computeMinions = salt.getMinions(venvPepper, 'I@nova:compute') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 617 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 618 | stage('Update Reclass and Salt-Formulas') { |
| 619 | common.infoMsg('Perform: Full salt sync') |
| 620 | salt.fullRefresh(venvPepper, '*') |
| 621 | common.infoMsg('Perform: Validate reclass medata before processing') |
| 622 | validateReclassModel(minions, 'before') |
| 623 | |
| 624 | common.infoMsg('Perform: archiveReclassInventory before upgrade') |
Denis Egorenko | 89a3c57 | 2019-03-22 17:03:40 +0400 | [diff] [blame] | 625 | archiveReclassInventory(inventoryBeforeFilename) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 626 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 627 | try { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 628 | 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] | 629 | } |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 630 | catch (Exception ex) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 631 | 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] | 632 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 633 | if (updateClusterModel) { |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 634 | common.infoMsg('Perform: UPDATE_CLUSTER_MODEL') |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 635 | def dateTime = common.getDatetime() |
Ivan Berezovskiy | 1d78052 | 2020-01-17 13:55:18 +0400 | [diff] [blame] | 636 | 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] | 637 | 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] | 638 | "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] | 639 | // Do the same, for deprecated variable-duplicate |
| 640 | 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] | 641 | "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] | 642 | 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] | 643 | "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] | 644 | // Set new k8s param |
| 645 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 646 | "grep -r --exclude-dir=aptly -l 'kubernetes_containerd_enabled: .*' * | xargs --no-run-if-empty sed -i 's|kubernetes_containerd_enabled: .*|kubernetes_containerd_enabled: True|g'") |
Denis Egorenko | 2a39d2c | 2019-01-16 19:18:31 +0400 | [diff] [blame] | 647 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 648 | "grep -r --exclude-dir=aptly -l 'system.linux.system.repo.mcp.salt' * | xargs --no-run-if-empty sed -i 's/system.linux.system.repo.mcp.salt/system.linux.system.repo.mcp.apt_mirantis.salt-formulas/g'") |
| 649 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
Denis Egorenko | ca871c2 | 2019-02-13 13:49:13 +0400 | [diff] [blame] | 650 | "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] | 651 | 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] | 652 | "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] | 653 | 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] | 654 | "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] | 655 | |
Denis Egorenko | 70f4f9a | 2019-09-16 16:41:26 +0400 | [diff] [blame] | 656 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name/infra && sed -i '/linux_system_repo_mcp_maas_url/d' maas.yml") |
| 657 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name/infra && sed -i '/maas_region_main_archive/d' maas.yml") |
| 658 | |
Denis Egorenko | 6ca9f0d | 2019-07-10 19:47:39 +0400 | [diff] [blame] | 659 | // Switch Jenkins/Gerrit to use LDAP SSL/TLS |
| 660 | def gerritldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 661 | "grep -r --exclude-dir=aptly 'gerrit_ldap_server: .*' * | grep -Po 'gerrit_ldap_server: \\K.*' | tr -d '\"'", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim() |
| 662 | if (gerritldapURI.startsWith('ldap://')) { |
| 663 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 664 | "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'") |
| 665 | } else if (! gerritldapURI.startsWith('ldaps://')) { |
| 666 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 667 | "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|gerrit_ldap_server: .*|gerrit_ldap_server: \"ldaps://${gerritldapURI}\"|g'") |
| 668 | } |
| 669 | def jenkinsldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 670 | "grep -r --exclude-dir=aptly 'jenkins_security_ldap_server: .*' * | grep -Po 'jenkins_security_ldap_server: \\K.*' | tr -d '\"'", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim() |
| 671 | if (jenkinsldapURI.startsWith('ldap://')) { |
| 672 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 673 | "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'") |
| 674 | } else if (! jenkinsldapURI.startsWith('ldaps://')) { |
| 675 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 676 | "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|jenkins_security_ldap_server: .*|jenkins_security_ldap_server: \"ldaps://${jenkinsldapURI}\"|g'") |
| 677 | } |
| 678 | |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 679 | if (applyWorkarounds) { |
| 680 | wa32284(cluster_name) |
| 681 | wa34245(cluster_name) |
| 682 | } |
Denis Egorenko | bae9dc7 | 2019-07-29 17:44:46 +0400 | [diff] [blame] | 683 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 684 | 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] | 685 | // Add kubernetes-extra repo |
| 686 | if (salt.testTarget(venvPepper, "I@kubernetes:master")) { |
Sergey Kolekonov | ac9554c | 2019-04-11 16:33:54 +0400 | [diff] [blame] | 687 | // docker-engine conflicts with the recent containerd versions, so it's removed during upgrade. Thus update source engine |
| 688 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 689 | "grep -r -l 'engine: docker_hybrid' kubernetes | xargs --no-run-if-empty sed -i 's/engine: docker_hybrid/engine: archive/g'") |
Sergey Kolekonov | 6ab1511 | 2019-01-23 16:47:43 +0400 | [diff] [blame] | 690 | common.infoMsg("Add kubernetes-extra repo") |
| 691 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 692 | "grep -q system.linux.system.repo.mcp.apt_mirantis.update.kubernetes_extra kubernetes/common.yml || sed -i '/classes:/ a - system.linux.system.repo.mcp.apt_mirantis.update.kubernetes_extra' kubernetes/common.yml") |
| 693 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 694 | "grep -q system.linux.system.repo.mcp.apt_mirantis.kubernetes_extra kubernetes/common.yml || sed -i '/classes:/ a - system.linux.system.repo.mcp.apt_mirantis.kubernetes_extra' kubernetes/common.yml") |
| 695 | } |
Ivan Berezovskiy | be630ee | 2019-04-15 13:23:58 +0400 | [diff] [blame] | 696 | // Add all update repositories |
| 697 | def repoIncludeBase = '- system.linux.system.repo.mcp.apt_mirantis.' |
Denis Egorenko | 70f4f9a | 2019-09-16 16:41:26 +0400 | [diff] [blame] | 698 | 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] | 699 | updateRepoList.each { repo -> |
| 700 | def repoNameUpdateInclude = "${repoIncludeBase}update.${repo}" |
| 701 | def filesWithInclude = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && grep -Plr '\\${repoIncludeBase}${repo}\$' . || true", false).get('return')[0].values()[0].trim().tokenize('\n') |
| 702 | filesWithInclude.each { file -> |
| 703 | def updateRepoIncludeExist = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && grep -P '\\${repoNameUpdateInclude}\$' ${file} || echo not_found", false, null, true).get('return')[0].values()[0].trim() |
| 704 | if (updateRepoIncludeExist == 'not_found') { |
| 705 | // Include needs to be added |
| 706 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 707 | "sed -i 's/\\( *\\)${repoIncludeBase}${repo}\$/&\\n\\1${repoNameUpdateInclude}/g' ${file}") |
Ivan Berezovskiy | be630ee | 2019-04-15 13:23:58 +0400 | [diff] [blame] | 708 | common.infoMsg("Update repo for ${repo} is added to ${file}") |
| 709 | } |
| 710 | } |
| 711 | } |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 712 | if (applyWorkarounds) { |
| 713 | wa32182(cluster_name) |
| 714 | wa33771(cluster_name) |
| 715 | wa33867(cluster_name) |
| 716 | wa33930_33931(cluster_name) |
| 717 | wa34528(cluster_name) |
| 718 | } |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 719 | // Add new defaults |
| 720 | common.infoMsg("Add new defaults") |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 721 | 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] | 722 | "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] | 723 | 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] | 724 | "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] | 725 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 726 | "grep -r -l 'docker_image_jenkins: .*' cicd | xargs --no-run-if-empty sed -i 's|\\s*docker_image_jenkins: .*||g'") |
| 727 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 728 | "grep -r -l 'docker_image_jenkins_slave: .*' cicd | xargs --no-run-if-empty sed -i 's|\\s*docker_image_jenkins_slave: .*||g'") |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 729 | 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] | 730 | "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] | 731 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff") |
| 732 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " + |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 733 | "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] | 734 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 735 | try { |
| 736 | common.infoMsg('Perform: UPDATE Salt Formulas') |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 737 | salt.fullRefresh(venvPepper, '*') |
| 738 | salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 739 | 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] | 740 | salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas", 'salt.master.env']) |
| 741 | salt.fullRefresh(venvPepper, '*') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 742 | } catch (Exception updateErr) { |
| 743 | common.warningMsg(updateErr) |
| 744 | common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.') |
| 745 | input message: 'Continue anyway?' |
| 746 | } |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 747 | if (applyWorkarounds) { |
| 748 | wa29352(cluster_name) |
| 749 | wa29155(computeMinions, cluster_name) |
| 750 | } |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 751 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 752 | try { |
| 753 | common.infoMsg('Perform: UPDATE Reclass package') |
| 754 | salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"]) |
| 755 | } catch (Exception updateErr) { |
| 756 | common.warningMsg(updateErr) |
| 757 | common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.') |
| 758 | input message: 'Continue anyway?' |
| 759 | } |
| 760 | |
| 761 | salt.fullRefresh(venvPepper, 'I@salt:master') |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 762 | salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true) |
Ivan Berezovskiy | 304705c | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 763 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && " + |
| 764 | "git add -u && git commit --allow-empty -m 'Reclass nodes update to the release ${targetMcpVersion} on ${common.getDatetime()}'") |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 765 | try { |
| 766 | salt.enforceState(venvPepper, "I@salt:master", 'reclass', true) |
| 767 | } |
| 768 | catch (Exception ex) { |
| 769 | error("Reclass fails rendering. Pay attention to your cluster model.") |
| 770 | } |
| 771 | |
| 772 | salt.fullRefresh(venvPepper, '*') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 773 | try { |
| 774 | salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top") |
| 775 | } |
| 776 | catch (Exception ex) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 777 | |
| 778 | error('Reclass fails rendering. Pay attention to your cluster model.' + |
| 779 | 'ErrorMessage:' + ex.toString()) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 780 | } |
| 781 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 782 | common.infoMsg('Perform: archiveReclassInventory AFTER upgrade') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 783 | archiveReclassInventory(inventoryAfterFilename) |
| 784 | |
| 785 | sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true" |
| 786 | archiveArtifacts artifacts: "reclass-inventory-diff.out" |
| 787 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 788 | validateReclassModel(minions, 'after') |
| 789 | archiveReclassModelChanges(minions) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 790 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 791 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 792 | if (updateLocalRepos) { |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 793 | stage("Update local repos") { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 794 | common.infoMsg("Updating local repositories") |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 795 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 796 | def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine") |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 797 | runningOnDocker = engine.get("return")[0].containsValue("docker") |
| 798 | |
| 799 | if (runningOnDocker) { |
| 800 | common.infoMsg("Aptly is running as Docker container") |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 801 | } else { |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 802 | common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands") |
| 803 | } |
| 804 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 805 | if (runningOnDocker) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 806 | 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] | 807 | } else { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 808 | 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] | 809 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 810 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 811 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 812 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 813 | if (runningOnDocker) { |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 814 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true) |
| 815 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=-frv -u http://10.99.0.1:8080"], null, true) |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 816 | } else { |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 817 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true) |
| 818 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=-afrv", 'runas=aptly'], null, true) |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 819 | } |
Richard Felkl | 79d7df1 | 2018-01-05 16:40:11 +0100 | [diff] [blame] | 820 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 821 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 822 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 823 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 824 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 825 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true) |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 826 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 827 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 828 | } |
| 829 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 830 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 831 | stage('Update Drivetrain') { |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 832 | if (upgradeSaltStack) { |
| 833 | updateSaltStack("I@salt:master", '["salt-master", "salt-common", "salt-api", "salt-minion"]') |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 834 | |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 835 | salt.enforceState(venvPepper, "I@linux:system", 'linux.system.repo', true, true, batchSize) |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 836 | updateSaltStack("I@salt:minion and not I@salt:master", '["salt-minion"]') |
| 837 | } |
| 838 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 839 | if (updatePipelines) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 840 | common.infoMsg('Perform: UPDATE git repos') |
| 841 | triggerMirrorJob('git-mirror-downstream-mk-pipelines', reclassSystemBranch) |
| 842 | triggerMirrorJob('git-mirror-downstream-pipeline-library', reclassSystemBranch) |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 843 | } |
| 844 | |
Denis Egorenko | d00c17e | 2019-04-25 20:17:27 +0400 | [diff] [blame] | 845 | // update minions certs |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 846 | salt.enforceState(venvPepper, "I@salt:minion", 'salt.minion.cert', true, true, batchSize) |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 847 | |
Ivan Berezovskiy | cac04e4 | 2020-02-17 17:08:47 +0400 | [diff] [blame^] | 848 | // run `salt.minion` to refresh all minion configs (for example _keystone.conf) |
| 849 | salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion', true, true, batchSize, false, 60, 2) |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 850 | // Retry needed only for rare race-condition in user appearance |
| 851 | common.infoMsg('Perform: updating users and keys') |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 852 | salt.enforceState(venvPepper, "I@linux:system", 'linux.system.user', true, true, batchSize) |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 853 | common.infoMsg('Perform: updating openssh') |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 854 | salt.enforceState(venvPepper, "I@linux:system", 'openssh', true, true, batchSize) |
Denis Egorenko | aeaa1de | 2019-01-15 11:58:12 +0400 | [diff] [blame] | 855 | |
Denis Egorenko | e69920e | 2019-10-30 13:26:59 +0400 | [diff] [blame] | 856 | // Gerrit 2019.2.0 (2.13.6) version has wrong file name for download-commands plugin and was not loaded, let's remove if still there before upgrade |
| 857 | def gerritGlusterPath = salt.getPillar(venvPepper, 'I@gerrit:client', 'glusterfs:client:volumes:gerrit:path').get('return')[0].values()[0] |
| 858 | def wrongPluginJarName = "${gerritGlusterPath}/plugins/project-download-commands.jar" |
Ivan Berezovskiy | 304705c | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 859 | salt.cmdRun(venvPepper, 'I@gerrit:client', "test -f ${wrongPluginJarName} && rm ${wrongPluginJarName} || true") |
Denis Egorenko | e69920e | 2019-10-30 13:26:59 +0400 | [diff] [blame] | 860 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 861 | 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] | 862 | } |
| 863 | } |
| 864 | catch (Throwable e) { |
| 865 | // If there was an error or exception thrown, the build failed |
| 866 | currentBuild.result = "FAILURE" |
| 867 | throw e |
| 868 | } |
| 869 | } |
| 870 | // docker.client state may trigger change of jenkins master or jenkins slave services, |
| 871 | // so we need wait for slave to reconnect and continue pipeline |
| 872 | sleep(180) |
Denis Egorenko | bf39010 | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 873 | def cidNodes = [] |
Ivan Berezovskiy | 24b0be0 | 2019-12-11 15:31:10 +0400 | [diff] [blame] | 874 | node('python') { |
| 875 | try { |
| 876 | stage('Update Drivetrain: Phase 2') { |
| 877 | python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds) |
Denis Egorenko | bf39010 | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 878 | checkCICDDocker() |
Denis Egorenko | 6ca9f0d | 2019-07-10 19:47:39 +0400 | [diff] [blame] | 879 | |
Ivan Berezovskiy | 304705c | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 880 | // Apply changes for HaProxy on CI/CD nodes |
| 881 | salt.enforceState(venvPepper, 'I@keepalived:cluster:instance:cicd_control_vip and I@haproxy:proxy', 'haproxy.proxy', true) |
| 882 | |
| 883 | salt.enforceState(venvPepper, 'I@jenkins:client and not I@salt:master', 'jenkins.client', true, true, null, false, 60, 2) |
Denis Egorenko | 84a0bc0 | 2019-07-23 18:01:21 +0400 | [diff] [blame] | 884 | |
| 885 | // update Nginx proxy settings for Jenkins/Gerrit if needed |
| 886 | if (salt.testTarget(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit')) { |
| 887 | salt.enforceState(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit', 'nginx.server', true, true, null, false, 60, 2) |
| 888 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 889 | } |
Denis Egorenko | bf39010 | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 890 | if (packageUpgradeMode) { |
| 891 | cidNodes = salt.getMinions(venvPepper, 'I@_param:drivetrain_role:cicd') |
| 892 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 893 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 894 | catch (Throwable e) { |
| 895 | // If there was an error or exception thrown, the build failed |
| 896 | currentBuild.result = "FAILURE" |
| 897 | throw e |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 898 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 899 | } |
Denis Egorenko | bf39010 | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 900 | |
| 901 | stage('Upgrade OS') { |
| 902 | if (packageUpgradeMode) { |
| 903 | def debian = new com.mirantis.mk.Debian() |
| 904 | def statusFile = '/tmp/rebooted_during_upgrade' |
| 905 | for(cidNode in cidNodes) { |
| 906 | node('python') { |
| 907 | python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds) |
| 908 | // cmd.run async to prevent connection close in case of slave shutdown, give 5 seconds to handle request response |
| 909 | salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${cidNode}' cmd.run 'sleep 5; touch ${statusFile}; salt-call service.stop docker' --async") |
| 910 | } |
| 911 | sleep(30) |
| 912 | node('python') { |
| 913 | python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds) |
| 914 | debian.osUpgradeNode(venvPepper, cidNode, packageUpgradeMode, false, 60) |
| 915 | salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': cidNode, wait: 60, timeout: 10]) |
| 916 | if (salt.runSaltProcessStep(venvPepper, cidNode, 'file.file_exists', [statusFile], null, true, 5)['return'][0].values()[0].toBoolean()) { |
| 917 | salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${cidNode}' cmd.run 'rm ${statusFile} && salt-call service.start docker'") // in case if node was not rebooted |
| 918 | sleep(10) |
| 919 | } |
| 920 | checkCICDDocker() |
| 921 | } |
| 922 | } |
| 923 | } else { |
| 924 | common.infoMsg('Upgrade OS skipped...') |
| 925 | } |
| 926 | } |
Hanna Arhipova | 644aefd | 2019-09-06 17:55:40 +0300 | [diff] [blame] | 927 | } |