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 | ca6aeca | 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 | 22390f6 | 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 | a766d43 | 2019-12-11 15:31:10 +0400 | [diff] [blame] | 28 | def saltMastURL = '' |
| 29 | def saltMastCreds = '' |
Denis Egorenko | 96cc57d | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 30 | def packageUpgradeMode = '' |
Ivan Berezovskiy | 22390f6 | 2020-02-17 17:08:47 +0400 | [diff] [blame] | 31 | batchSize = '' |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 32 | |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [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) |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [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) { |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 55 | salt.cmdRun(venvPepper, 'I@salt:master', "salt -C '${target}' --async pkg.install force_yes=True pkgs='$pkgs'") |
Denis Egorenko | 4b54e7f | 2019-02-26 16:05:03 +0400 | [diff] [blame] | 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 | 20a4346 | 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 | f5c911b | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 88 | def wa29352(String cname) { |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [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 | 22390f6 | 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) |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 98 | salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29352File}", true, null, false) |
| 99 | } |
| 100 | catch (Exception ex) { |
Denis Egorenko | dfa3542 | 2019-10-07 12:46:14 +0400 | [diff] [blame] | 101 | common.infoMsg('Work-around for PROD-29352 already applied, nothing todo') |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [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 | dfa3542 | 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') |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 133 | } |
| 134 | |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 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 |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [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 | 22390f6 | 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 | } |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 155 | } |
| 156 | catch (Exception ex) { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 157 | return |
| 158 | } |
Denis Egorenko | 14fa6e1 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 159 | salt.fullRefresh(venvPepper, 'I@salt:master') |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 160 | for (String minion in saltMinions) { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 161 | // First attempt, second will be performed in next validateReclassModel() stages |
| 162 | try { |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 163 | salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim() |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 164 | } catch (Exception e) { |
| 165 | common.errorMsg(e.toString()) |
| 166 | if (patched) { |
Ivan Berezovskiy | 22390f6 | 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.") |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 168 | } |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 169 | common.warningMsg('Perform: Attempt to apply WA for PROD-29155\n' + |
| 170 | 'See https://gerrit.mcp.mirantis.com/#/c/37932/ for more info') |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 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 | ] |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 186 | writeYaml file: _tempFile, data: novaKeysDict |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 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 | f5c911b | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 197 | salt.fullRefresh(venvPepper, 'I@salt:master') |
| 198 | salt.fullRefresh(venvPepper, saltMinions) |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [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 | 5b62e9c | 2020-01-24 17:52:26 +0400 | [diff] [blame] | 210 | def wa32284(String cluster_name) { |
Denis Egorenko | 1b11d23 | 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 | 5b62e9c | 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 | 1b11d23 | 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 | 5b62e9c | 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 | 1b11d23 | 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 | 5b62e9c | 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 | 1b11d23 | 2019-07-29 17:44:46 +0400 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
Denis Egorenko | af18b25 | 2019-09-02 14:53:02 +0400 | [diff] [blame] | 231 | def wa32182(String cluster_name) { |
Hanna Arhipova | d5eec4c | 2019-09-06 17:55:40 +0300 | [diff] [blame] | 232 | if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) { |
Denis Egorenko | af18b25 | 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 | 9f6330b | 2020-02-05 21:18:17 +0400 | [diff] [blame] | 242 | for (String contrailFile in contrailFiles) { |
Denis Egorenko | af18b25 | 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 | 9f6330b | 2020-02-05 21:18:17 +0400 | [diff] [blame] | 249 | "echo '- cluster.${cluster_name}.opencontrail.common_wa32182' >> ${contrailFile}") |
Denis Egorenko | af18b25 | 2019-09-02 14:53:02 +0400 | [diff] [blame] | 250 | } |
| 251 | } |
Ivan Berezovskiy | 9f6330b | 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 | af18b25 | 2019-09-02 14:53:02 +0400 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
Denis Egorenko | ba63133 | 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 | e312cc9 | 2019-10-18 17:06:11 +0400 | [diff] [blame] | 267 | def wa33771(String cluster_name) { |
Ivan Berezovskiy | 22390f6 | 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 | e312cc9 | 2019-10-18 17:06:11 +0400 | [diff] [blame] | 279 | ] |
Ivan Berezovskiy | 22390f6 | 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 | 59f82a5 | 2020-01-30 17:17:25 +0400 | [diff] [blame] | 290 | } |
Ivan Berezovskiy | 22390f6 | 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 | e312cc9 | 2019-10-18 17:06:11 +0400 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
Denis Egorenko | e9fc059 | 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 | 22390f6 | 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 | e9fc059 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 327 | if (salt.getMinions(venvPepper, 'I@manila:api:enabled')) { |
Ivan Berezovskiy | 22390f6 | 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 | e9fc059 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 336 | } |
| 337 | if (salt.getMinions(venvPepper, 'I@ironic:api:enabled')) { |
Ivan Berezovskiy | 22390f6 | 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 | e9fc059 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 346 | } |
| 347 | if (salt.getMinions(venvPepper, 'I@gnocchi:server:enabled')) { |
Ivan Berezovskiy | 22390f6 | 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 | e9fc059 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 356 | } |
Ivan Berezovskiy | 22390f6 | 2020-02-17 17:08:47 +0400 | [diff] [blame] | 357 | |
Denis Egorenko | e9fc059 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 358 | if (salt.getMinions(venvPepper, 'I@barbican:server:enabled')) { |
Ivan Berezovskiy | 22390f6 | 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 | e9fc059 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 367 | } |
Ivan Berezovskiy | 22390f6 | 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 | e9fc059 | 2019-11-14 19:56:17 +0400 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
Denis Egorenko | 215acda | 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 | 5b62e9c | 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 | 215acda | 2020-01-28 16:41:44 +0400 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | |
Ivan Berezovskiy | 5b62e9c | 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) { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [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 |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 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() |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 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 { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 497 | for (String minion in saltMinions) { |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 498 | common.infoMsg("Reclass model validation for minion ${minion}...") |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 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() |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 500 | writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString() |
| 501 | } |
| 502 | } catch (Exception e) { |
| 503 | common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.') |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 504 | error(e.toString()) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 508 | def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix = 'before', String newSuffix = 'after') { |
| 509 | for (String minion in saltMinions) { |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 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}" |
| 513 | } |
| 514 | } |
| 515 | |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 516 | def checkDebsums() { |
| 517 | // check for salt-formulas consistency |
| 518 | try { |
| 519 | try { |
| 520 | salt.cmdRun(venvPepper, 'I@salt:master', "salt -C 'I@salt:master' pkg.install force_yes=True pkgs=[debsums]") |
| 521 | } |
| 522 | catch (Exception ex) { |
| 523 | common.warningMsg('Unable to install package "debsums" at cfg01. Salt-formulas integrity check skipped') |
| 524 | } |
| 525 | salt.cmdRun(venvPepper, 'I@salt:master', '> /root/debdsums_report; for i in $(dpkg-query -W -f=\'${Package}\\n\' | sed "s/ //g" |grep \'salt-formula-\'); do debsums -s ${i} 2>> /root/debdsums_report; done') |
| 526 | salt.cmdRun(venvPepper, 'I@salt:master', 'if [ -s "/root/debdsums_report" ]; then exit 1 ; fi') |
| 527 | } |
| 528 | catch (Exception ex) { |
| 529 | common.errorMsg(salt.cmdRun(venvPepper, 'I@salt:master', 'cat /root/debdsums_report ', true, null, false).get('return')[0].values()[0].trim()) |
| 530 | common.errorMsg(ex.toString()) |
| 531 | error('You have unexpected changes in formulas. All of them will be overwrited by update. Unable to continue in automatic way') |
| 532 | } |
| 533 | } |
| 534 | |
Denis Egorenko | 96cc57d | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 535 | def checkCICDDocker() { |
| 536 | common.infoMsg('Perform: Checking if Docker containers are up') |
| 537 | try { |
| 538 | common.retry(10, 30) { |
| 539 | salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'") |
| 540 | } |
| 541 | } |
| 542 | catch (Exception ex) { |
| 543 | error("Docker containers for CI/CD services are having troubles with starting.") |
| 544 | } |
| 545 | } |
| 546 | |
Denis Egorenko | 5a8a7e9 | 2018-12-27 14:13:48 +0400 | [diff] [blame] | 547 | if (common.validInputParam('PIPELINE_TIMEOUT')) { |
| 548 | try { |
| 549 | pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger() |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 550 | } catch (Exception e) { |
Denis Egorenko | 5a8a7e9 | 2018-12-27 14:13:48 +0400 | [diff] [blame] | 551 | common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger") |
| 552 | } |
Martin Polreich | 965c903 | 2018-08-09 16:33:57 +0200 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | timeout(time: pipelineTimeout, unit: 'HOURS') { |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 556 | node('python') { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 557 | try { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 558 | def inventoryBeforeFilename = "reclass-inventory-before.out" |
| 559 | def inventoryAfterFilename = "reclass-inventory-after.out" |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 560 | workspace = common.getWorkspace() |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 561 | targetMcpVersion = null |
| 562 | if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) { |
| 563 | error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable') |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 564 | } |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 565 | // bw comp. for 2018.X => 2018.11 release |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 566 | if (common.validInputParam('MCP_VERSION')) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 567 | targetMcpVersion = env.MCP_VERSION |
| 568 | common.warningMsg("targetMcpVersion has been changed to:${targetMcpVersion}, which was taken from deprecated pipeline viriable:MCP_VERSION") |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 569 | } else { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 570 | targetMcpVersion = env.TARGET_MCP_VERSION |
| 571 | } |
| 572 | // end bw comp. for 2018.X => 2018.11 release |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 573 | def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC') |
Ivan Berezovskiy | db32509 | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 574 | if (targetMcpVersion in ['nightly', 'testing']) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 575 | gitTargetMcpVersion = 'master' |
Ivan Berezovskiy | db32509 | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 576 | } else if (targetMcpVersion == 'proposed') { |
| 577 | gitTargetMcpVersion = 'proposed' |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 578 | } else if (!gitTargetMcpVersion) { |
| 579 | // backward compatibility for 2018.11.0 |
| 580 | gitTargetMcpVersion = "release/${targetMcpVersion}" |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 581 | } |
Ivan Berezovskiy | db32509 | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 582 | common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}") |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 583 | def upgradeSaltStack = '' |
| 584 | def updateClusterModel = '' |
Ivan Berezovskiy | 22390f6 | 2020-02-17 17:08:47 +0400 | [diff] [blame] | 585 | def applyWorkarounds = true |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 586 | def updatePipelines = '' |
| 587 | def updateLocalRepos = '' |
| 588 | def reclassSystemBranch = '' |
Denis Egorenko | 517e06c | 2019-03-29 13:24:15 +0400 | [diff] [blame] | 589 | def reclassSystemBranchDefault = gitTargetMcpVersion |
Ivan Berezovskiy | f5c911b | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 590 | if (gitTargetMcpVersion ==~ /^\d\d\d\d\.\d\d?\.\d+$/) { |
| 591 | reclassSystemBranchDefault = "tags/${gitTargetMcpVersion}" |
| 592 | } else if (gitTargetMcpVersion != 'proposed') { |
Denis Egorenko | 517e06c | 2019-03-29 13:24:15 +0400 | [diff] [blame] | 593 | reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}" |
| 594 | } |
Hanna Arhipova | d5eec4c | 2019-09-06 17:55:40 +0300 | [diff] [blame] | 595 | def driveTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS') |
| 596 | if (driveTrainParamsYaml) { |
| 597 | def driveTrainParams = readYaml text: driveTrainParamsYaml |
| 598 | saltMastURL = driveTrainParams.get('SALT_MASTER_URL') |
| 599 | saltMastCreds = driveTrainParams.get('SALT_MASTER_CREDENTIALS') |
| 600 | upgradeSaltStack = driveTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean() |
| 601 | updateClusterModel = driveTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean() |
| 602 | updatePipelines = driveTrainParams.get('UPDATE_PIPELINES', false).toBoolean() |
| 603 | updateLocalRepos = driveTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean() |
| 604 | reclassSystemBranch = driveTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault) |
Denis Egorenko | ca6aeca | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 605 | batchSize = driveTrainParams.get('BATCH_SIZE', '') |
Denis Egorenko | 96cc57d | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 606 | if (driveTrainParams.get('OS_DIST_UPGRADE', false).toBoolean() == true) { |
| 607 | packageUpgradeMode = 'dist-upgrade' |
| 608 | } else if (driveTrainParams.get('OS_UPGRADE', false).toBoolean() == true) { |
| 609 | packageUpgradeMode = 'upgrade' |
| 610 | } |
Ivan Berezovskiy | 22390f6 | 2020-02-17 17:08:47 +0400 | [diff] [blame] | 611 | applyWorkarounds = driveTrainParams.get('APPLY_MODEL_WORKAROUNDS', true).toBoolean() |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 612 | } else { |
| 613 | // backward compatibility for 2018.11.0 |
| 614 | saltMastURL = env.getProperty('SALT_MASTER_URL') |
| 615 | saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS') |
Denis Egorenko | e5f3914 | 2018-12-28 12:30:48 +0400 | [diff] [blame] | 616 | upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean() |
| 617 | updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean() |
| 618 | updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean() |
| 619 | updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean() |
Denis Egorenko | 517e06c | 2019-03-29 13:24:15 +0400 | [diff] [blame] | 620 | reclassSystemBranch = reclassSystemBranchDefault |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 621 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 622 | python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 623 | def minions = salt.getMinions(venvPepper, '*') |
Denis Egorenko | fbcee41 | 2019-04-19 15:05:18 +0400 | [diff] [blame] | 624 | def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0] |
| 625 | if (cluster_name == '' || cluster_name == 'null' || cluster_name == null) { |
| 626 | error('Pillar data is broken for Salt master node! Please check it manually and re-run pipeline.') |
| 627 | } |
Hanna Arhipova | d5eec4c | 2019-09-06 17:55:40 +0300 | [diff] [blame] | 628 | if (!batchSize) { |
Denis Egorenko | 7b098c3 | 2019-12-19 16:45:25 +0400 | [diff] [blame] | 629 | // if no batch size provided get current worker threads and set batch size to 2/3 of it to avoid |
| 630 | // 'SaltReqTimeoutError: Message timed out' issue on Salt targets for large amount of nodes |
| 631 | // do not use toDouble/Double as it requires additional approved method |
| 632 | def workerThreads = getWorkerThreads(venvPepper).toInteger() |
Ivan Berezovskiy | 22390f6 | 2020-02-17 17:08:47 +0400 | [diff] [blame] | 633 | batchSize = (workerThreads * 2 / 3).toString().tokenize('.')[0] |
Denis Egorenko | ca6aeca | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 634 | } |
Ivan Berezovskiy | f5c911b | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 635 | def computeMinions = salt.getMinions(venvPepper, 'I@nova:compute') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 636 | |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 637 | stage('Update Reclass and Salt-Formulas') { |
| 638 | common.infoMsg('Perform: Full salt sync') |
| 639 | salt.fullRefresh(venvPepper, '*') |
| 640 | common.infoMsg('Perform: Validate reclass medata before processing') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 641 | validateReclassModel(minions, 'before') |
| 642 | |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 643 | common.infoMsg('Perform: archiveReclassInventory before upgrade') |
| 644 | archiveReclassInventory(inventoryBeforeFilename) |
| 645 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 646 | try { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 647 | 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] | 648 | } |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 649 | catch (Exception ex) { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 650 | 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] | 651 | } |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 652 | checkDebsums() |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 653 | if (updateClusterModel) { |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 654 | common.infoMsg('Perform: UPDATE_CLUSTER_MODEL') |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 655 | def dateTime = common.getDatetime() |
Ivan Berezovskiy | cfa1b2f | 2020-01-17 13:55:18 +0400 | [diff] [blame] | 656 | 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] | 657 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
Denis Egorenko | fcbc6b8 | 2019-01-15 11:47:16 +0400 | [diff] [blame] | 658 | "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] | 659 | // Do the same, for deprecated variable-duplicate |
| 660 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
Denis Egorenko | fcbc6b8 | 2019-01-15 11:47:16 +0400 | [diff] [blame] | 661 | "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] | 662 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
Denis Egorenko | fcbc6b8 | 2019-01-15 11:47:16 +0400 | [diff] [blame] | 663 | "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 | abbefe6 | 2019-01-15 19:58:03 +0400 | [diff] [blame] | 664 | // Set new k8s param |
| 665 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 666 | "grep -r --exclude-dir=aptly -l 'kubernetes_containerd_enabled: .*' * | xargs --no-run-if-empty sed -i 's|kubernetes_containerd_enabled: .*|kubernetes_containerd_enabled: True|g'") |
Denis Egorenko | e5b4951 | 2019-01-16 19:18:31 +0400 | [diff] [blame] | 667 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 668 | "grep -r --exclude-dir=aptly -l 'system.linux.system.repo.mcp.salt' * | xargs --no-run-if-empty sed -i 's/system.linux.system.repo.mcp.salt/system.linux.system.repo.mcp.apt_mirantis.salt-formulas/g'") |
| 669 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
Denis Egorenko | 301cc8a | 2019-02-13 13:49:13 +0400 | [diff] [blame] | 670 | "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 | e5b4951 | 2019-01-16 19:18:31 +0400 | [diff] [blame] | 671 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
Denis Egorenko | 301cc8a | 2019-02-13 13:49:13 +0400 | [diff] [blame] | 672 | "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 | 308c7ca | 2019-02-13 15:57:13 +0400 | [diff] [blame] | 673 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 674 | "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 | 21c78be | 2019-07-10 19:47:39 +0400 | [diff] [blame] | 675 | |
Denis Egorenko | 6f07b59 | 2019-09-16 16:41:26 +0400 | [diff] [blame] | 676 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name/infra && sed -i '/linux_system_repo_mcp_maas_url/d' maas.yml") |
| 677 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name/infra && sed -i '/maas_region_main_archive/d' maas.yml") |
| 678 | |
Denis Egorenko | 21c78be | 2019-07-10 19:47:39 +0400 | [diff] [blame] | 679 | // Switch Jenkins/Gerrit to use LDAP SSL/TLS |
| 680 | def gerritldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 681 | "grep -r --exclude-dir=aptly 'gerrit_ldap_server: .*' * | grep -Po 'gerrit_ldap_server: \\K.*' | tr -d '\"'", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim() |
| 682 | if (gerritldapURI.startsWith('ldap://')) { |
| 683 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 684 | "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'") |
| 685 | } else if (! gerritldapURI.startsWith('ldaps://')) { |
| 686 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 687 | "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|gerrit_ldap_server: .*|gerrit_ldap_server: \"ldaps://${gerritldapURI}\"|g'") |
| 688 | } |
| 689 | def jenkinsldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 690 | "grep -r --exclude-dir=aptly 'jenkins_security_ldap_server: .*' * | grep -Po 'jenkins_security_ldap_server: \\K.*' | tr -d '\"'", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim() |
| 691 | if (jenkinsldapURI.startsWith('ldap://')) { |
| 692 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 693 | "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'") |
| 694 | } else if (! jenkinsldapURI.startsWith('ldaps://')) { |
| 695 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 696 | "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|jenkins_security_ldap_server: .*|jenkins_security_ldap_server: \"ldaps://${jenkinsldapURI}\"|g'") |
| 697 | } |
| 698 | |
Ivan Berezovskiy | 22390f6 | 2020-02-17 17:08:47 +0400 | [diff] [blame] | 699 | if (applyWorkarounds) { |
| 700 | wa32284(cluster_name) |
| 701 | wa34245(cluster_name) |
| 702 | } |
Denis Egorenko | 1b11d23 | 2019-07-29 17:44:46 +0400 | [diff] [blame] | 703 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 704 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}") |
Sergey Kolekonov | 5dfbf7a | 2019-01-23 16:47:43 +0400 | [diff] [blame] | 705 | // Add kubernetes-extra repo |
| 706 | if (salt.testTarget(venvPepper, "I@kubernetes:master")) { |
Sergey Kolekonov | 3fde8b1 | 2019-04-11 16:33:54 +0400 | [diff] [blame] | 707 | // docker-engine conflicts with the recent containerd versions, so it's removed during upgrade. Thus update source engine |
| 708 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 709 | "grep -r -l 'engine: docker_hybrid' kubernetes | xargs --no-run-if-empty sed -i 's/engine: docker_hybrid/engine: archive/g'") |
Sergey Kolekonov | 5dfbf7a | 2019-01-23 16:47:43 +0400 | [diff] [blame] | 710 | common.infoMsg("Add kubernetes-extra repo") |
| 711 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 712 | "grep -q system.linux.system.repo.mcp.apt_mirantis.update.kubernetes_extra kubernetes/common.yml || sed -i '/classes:/ a - system.linux.system.repo.mcp.apt_mirantis.update.kubernetes_extra' kubernetes/common.yml") |
| 713 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 714 | "grep -q system.linux.system.repo.mcp.apt_mirantis.kubernetes_extra kubernetes/common.yml || sed -i '/classes:/ a - system.linux.system.repo.mcp.apt_mirantis.kubernetes_extra' kubernetes/common.yml") |
| 715 | } |
Ivan Berezovskiy | 41c7679 | 2019-04-15 13:23:58 +0400 | [diff] [blame] | 716 | // Add all update repositories |
| 717 | def repoIncludeBase = '- system.linux.system.repo.mcp.apt_mirantis.' |
Denis Egorenko | 6f07b59 | 2019-09-16 16:41:26 +0400 | [diff] [blame] | 718 | def updateRepoList = ['cassandra', 'ceph', 'contrail', 'docker', 'elastic', 'extra', 'openstack', 'maas', 'percona', 'salt-formulas', 'saltstack', 'ubuntu'] |
Ivan Berezovskiy | 41c7679 | 2019-04-15 13:23:58 +0400 | [diff] [blame] | 719 | updateRepoList.each { repo -> |
| 720 | def repoNameUpdateInclude = "${repoIncludeBase}update.${repo}" |
| 721 | def filesWithInclude = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && grep -Plr '\\${repoIncludeBase}${repo}\$' . || true", false).get('return')[0].values()[0].trim().tokenize('\n') |
| 722 | filesWithInclude.each { file -> |
| 723 | def updateRepoIncludeExist = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && grep -P '\\${repoNameUpdateInclude}\$' ${file} || echo not_found", false, null, true).get('return')[0].values()[0].trim() |
| 724 | if (updateRepoIncludeExist == 'not_found') { |
| 725 | // Include needs to be added |
| 726 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 727 | "sed -i 's/\\( *\\)${repoIncludeBase}${repo}\$/&\\n\\1${repoNameUpdateInclude}/g' ${file}") |
Ivan Berezovskiy | 41c7679 | 2019-04-15 13:23:58 +0400 | [diff] [blame] | 728 | common.infoMsg("Update repo for ${repo} is added to ${file}") |
| 729 | } |
| 730 | } |
| 731 | } |
Ivan Berezovskiy | 22390f6 | 2020-02-17 17:08:47 +0400 | [diff] [blame] | 732 | if (applyWorkarounds) { |
| 733 | wa32182(cluster_name) |
| 734 | wa33771(cluster_name) |
| 735 | wa33867(cluster_name) |
| 736 | wa33930_33931(cluster_name) |
| 737 | wa34528(cluster_name) |
| 738 | } |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 739 | // Add new defaults |
| 740 | common.infoMsg("Add new defaults") |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 741 | salt.cmdRun(venvPepper, 'I@salt:master', "grep '^ mcp_version: ' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " + |
Denis Egorenko | fcbc6b8 | 2019-01-15 11:47:16 +0400 | [diff] [blame] | 742 | "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] | 743 | salt.cmdRun(venvPepper, 'I@salt:master', "grep '^- system.defaults\$' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " + |
Denis Egorenko | fcbc6b8 | 2019-01-15 11:47:16 +0400 | [diff] [blame] | 744 | "sed -i 's|^classes:|classes:\\n- system.defaults|' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml") |
Ivan Berezovskiy | 5113c7c | 2019-04-23 14:32:02 +0400 | [diff] [blame] | 745 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 746 | "grep -r -l 'docker_image_jenkins: .*' cicd | xargs --no-run-if-empty sed -i 's|\\s*docker_image_jenkins: .*||g'") |
Ivan Berezovskiy | 5113c7c | 2019-04-23 14:32:02 +0400 | [diff] [blame] | 747 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 748 | "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] | 749 | 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] | 750 | "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] | 751 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff") |
| 752 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " + |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 753 | "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] | 754 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 755 | try { |
| 756 | common.infoMsg('Perform: UPDATE Salt Formulas') |
azvyagintsev | ca97a11 | 2019-04-22 17:53:40 +0300 | [diff] [blame] | 757 | salt.fullRefresh(venvPepper, '*') |
Denis Egorenko | ea0ba7d | 2019-07-04 14:16:40 +0400 | [diff] [blame] | 758 | salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo', true, true, null, false, 60, 2) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 759 | def saltEnv = salt.getPillar(venvPepper, 'I@salt:master', "_param:salt_master_base_environment").get("return")[0].values()[0] |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 760 | salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas", 'salt.master.env']) |
azvyagintsev | ca97a11 | 2019-04-22 17:53:40 +0300 | [diff] [blame] | 761 | salt.fullRefresh(venvPepper, '*') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 762 | } catch (Exception updateErr) { |
| 763 | common.warningMsg(updateErr) |
| 764 | common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.') |
| 765 | input message: 'Continue anyway?' |
| 766 | } |
Ivan Berezovskiy | 22390f6 | 2020-02-17 17:08:47 +0400 | [diff] [blame] | 767 | if (applyWorkarounds) { |
| 768 | wa29352(cluster_name) |
| 769 | wa29155(computeMinions, cluster_name) |
| 770 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 771 | |
| 772 | try { |
| 773 | common.infoMsg('Perform: UPDATE Reclass package') |
| 774 | salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"]) |
| 775 | } catch (Exception updateErr) { |
| 776 | common.warningMsg(updateErr) |
| 777 | common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.') |
| 778 | input message: 'Continue anyway?' |
| 779 | } |
| 780 | |
| 781 | salt.fullRefresh(venvPepper, 'I@salt:master') |
Denis Egorenko | ea0ba7d | 2019-07-04 14:16:40 +0400 | [diff] [blame] | 782 | salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true, true, null, false, 60, 2) |
Ivan Berezovskiy | f5c911b | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 783 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${cluster_name} && git status && " + |
| 784 | "git add -u && git commit --allow-empty -m 'Reclass nodes update to the release ${targetMcpVersion} on ${common.getDatetime()}'") |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 785 | try { |
Denis Egorenko | ea0ba7d | 2019-07-04 14:16:40 +0400 | [diff] [blame] | 786 | salt.enforceState(venvPepper, 'I@salt:master', 'reclass', true, true, null, false, 60, 2) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 787 | } |
| 788 | catch (Exception ex) { |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 789 | common.errorMsg(ex.toString()) |
| 790 | error('Reclass fails rendering. Pay attention to your cluster model.') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | salt.fullRefresh(venvPepper, '*') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 794 | try { |
| 795 | salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top") |
| 796 | } |
| 797 | catch (Exception ex) { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 798 | |
| 799 | error('Reclass fails rendering. Pay attention to your cluster model.' + |
| 800 | 'ErrorMessage:' + ex.toString()) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 801 | } |
| 802 | |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 803 | common.infoMsg('Perform: archiveReclassInventory AFTER upgrade') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 804 | archiveReclassInventory(inventoryAfterFilename) |
| 805 | |
| 806 | sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true" |
| 807 | archiveArtifacts artifacts: "reclass-inventory-diff.out" |
| 808 | |
| 809 | validateReclassModel(minions, 'after') |
| 810 | archiveReclassModelChanges(minions) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 811 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 812 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 813 | if (updateLocalRepos) { |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 814 | stage("Update local repos") { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 815 | common.infoMsg("Updating local repositories") |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 816 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 817 | def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine") |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 818 | runningOnDocker = engine.get("return")[0].containsValue("docker") |
| 819 | |
| 820 | if (runningOnDocker) { |
| 821 | common.infoMsg("Aptly is running as Docker container") |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 822 | } else { |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 823 | common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands") |
| 824 | } |
| 825 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 826 | if (runningOnDocker) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 827 | 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] | 828 | } else { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 829 | 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] | 830 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 831 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 832 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 833 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 834 | if (runningOnDocker) { |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 835 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true) |
| 836 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=-frv -u http://10.99.0.1:8080"], null, true) |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 837 | } else { |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 838 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true) |
| 839 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=-afrv", 'runas=aptly'], null, true) |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 840 | } |
Richard Felkl | 79d7df1 | 2018-01-05 16:40:11 +0100 | [diff] [blame] | 841 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 842 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 843 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 844 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 845 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 846 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true) |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 847 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 848 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 849 | } |
| 850 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 851 | |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 852 | stage('Update Drivetrain') { |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 853 | if (upgradeSaltStack) { |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 854 | updateSaltStack('I@salt:master', '["salt-master", "salt-common", "salt-api", "salt-minion"]') |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 855 | |
Denis Egorenko | ca6aeca | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 856 | salt.enforceState(venvPepper, 'I@linux:system', 'linux.system.repo', true, true, batchSize, false, 60, 2) |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 857 | updateSaltStack('I@salt:minion and not I@salt:master', '["salt-minion"]') |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 858 | } |
| 859 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 860 | if (updatePipelines) { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 861 | common.infoMsg('Perform: UPDATE git repos') |
| 862 | triggerMirrorJob('git-mirror-downstream-mk-pipelines', reclassSystemBranch) |
| 863 | triggerMirrorJob('git-mirror-downstream-pipeline-library', reclassSystemBranch) |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 864 | } |
| 865 | |
Denis Egorenko | 7a4cf03 | 2019-04-25 20:48:26 +0400 | [diff] [blame] | 866 | // update minions certs |
Denis Egorenko | af3a220 | 2019-04-26 15:13:16 +0400 | [diff] [blame] | 867 | // call for `salt.minion.ca` state on related nodes to make sure |
| 868 | // mine was updated with required data after salt-minion/salt-master restart salt:minion:ca |
Denis Egorenko | ca6aeca | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 869 | salt.enforceState(venvPepper, 'I@salt:minion:ca', 'salt.minion.ca', true, true, batchSize, false, 60, 2) |
| 870 | salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion.cert', true, true, batchSize, false, 60, 2) |
Denis Egorenko | 7a4cf03 | 2019-04-25 20:48:26 +0400 | [diff] [blame] | 871 | |
Ann Kamyshnikova | e891011 | 2019-05-06 12:56:38 +0400 | [diff] [blame] | 872 | // run `salt.minion` to refresh all minion configs (for example _keystone.conf) |
Ivan Berezovskiy | 22390f6 | 2020-02-17 17:08:47 +0400 | [diff] [blame] | 873 | salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion', true, true, batchSize, false, 60, 2) |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 874 | // Retry needed only for rare race-condition in user appearance |
| 875 | common.infoMsg('Perform: updating users and keys') |
Denis Egorenko | ca6aeca | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 876 | salt.enforceState(venvPepper, 'I@linux:system', 'linux.system.user', true, true, batchSize, false, 60, 2) |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 877 | common.infoMsg('Perform: updating openssh') |
Denis Egorenko | ca6aeca | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 878 | salt.enforceState(venvPepper, 'I@linux:system', 'openssh', true, true, batchSize, false, 60, 2) |
Denis Egorenko | 65cf2a4 | 2019-01-15 11:58:12 +0400 | [diff] [blame] | 879 | |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 880 | // apply salt API TLS if needed |
| 881 | def nginxAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0] |
| 882 | if (nginxAtMaster.toString().toLowerCase() == 'true') { |
Denis Egorenko | ea0ba7d | 2019-07-04 14:16:40 +0400 | [diff] [blame] | 883 | salt.enforceState(venvPepper, 'I@salt:master', 'nginx', true, true, null, false, 60, 2) |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 884 | } |
| 885 | |
Denis Egorenko | 579f184 | 2019-10-30 13:26:59 +0400 | [diff] [blame] | 886 | // Gerrit 2019.2.0 (2.13.6) version has wrong file name for download-commands plugin and was not loaded, let's remove if still there before upgrade |
| 887 | def gerritGlusterPath = salt.getPillar(venvPepper, 'I@gerrit:client', 'glusterfs:client:volumes:gerrit:path').get('return')[0].values()[0] |
| 888 | def wrongPluginJarName = "${gerritGlusterPath}/plugins/project-download-commands.jar" |
Ivan Berezovskiy | f5c911b | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 889 | salt.cmdRun(venvPepper, 'I@gerrit:client', "test -f ${wrongPluginJarName} && rm ${wrongPluginJarName} || true") |
Denis Egorenko | 579f184 | 2019-10-30 13:26:59 +0400 | [diff] [blame] | 890 | |
Ivan Berezovskiy | 89b2483 | 2020-02-27 15:21:57 +0400 | [diff] [blame] | 891 | salt.enforceStateWithTest(venvPepper, 'I@jenkins:client and I@docker:client:images and not I@salt:master', 'docker.client.images', "", true, true, null, true, 60, 2) |
Denis Egorenko | 21c78be | 2019-07-10 19:47:39 +0400 | [diff] [blame] | 892 | 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 | a766d43 | 2019-12-11 15:31:10 +0400 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | catch (Throwable e) { |
| 896 | // If there was an error or exception thrown, the build failed |
| 897 | currentBuild.result = "FAILURE" |
| 898 | throw e |
| 899 | } |
| 900 | } |
| 901 | // docker.client state may trigger change of jenkins master or jenkins slave services, |
| 902 | // so we need wait for slave to reconnect and continue pipeline |
| 903 | sleep(180) |
Denis Egorenko | 96cc57d | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 904 | def cidNodes = [] |
Ivan Berezovskiy | a766d43 | 2019-12-11 15:31:10 +0400 | [diff] [blame] | 905 | node('python') { |
| 906 | try { |
| 907 | stage('Update Drivetrain: Phase 2') { |
| 908 | python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds) |
Denis Egorenko | 96cc57d | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 909 | checkCICDDocker() |
Denis Egorenko | 21c78be | 2019-07-10 19:47:39 +0400 | [diff] [blame] | 910 | |
Ivan Berezovskiy | f5c911b | 2019-12-03 18:49:09 +0400 | [diff] [blame] | 911 | // Apply changes for HaProxy on CI/CD nodes |
| 912 | salt.enforceState(venvPepper, 'I@keepalived:cluster:instance:cicd_control_vip and I@haproxy:proxy', 'haproxy.proxy', true) |
| 913 | |
Denis Egorenko | 21c78be | 2019-07-10 19:47:39 +0400 | [diff] [blame] | 914 | salt.enforceState(venvPepper, 'I@jenkins:client and not I@salt:master', 'jenkins.client', true, true, null, false, 60, 2) |
Denis Egorenko | 312bcd4 | 2019-07-23 17:59:13 +0400 | [diff] [blame] | 915 | |
| 916 | // update Nginx proxy settings for Jenkins/Gerrit if needed |
| 917 | if (salt.testTarget(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit')) { |
| 918 | salt.enforceState(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit', 'nginx.server', true, true, null, false, 60, 2) |
| 919 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 920 | } |
Denis Egorenko | 96cc57d | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 921 | if (packageUpgradeMode) { |
| 922 | cidNodes = salt.getMinions(venvPepper, 'I@_param:drivetrain_role:cicd') |
| 923 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 924 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 925 | catch (Throwable e) { |
| 926 | // If there was an error or exception thrown, the build failed |
| 927 | currentBuild.result = "FAILURE" |
| 928 | throw e |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 929 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 930 | } |
Denis Egorenko | 96cc57d | 2020-01-24 19:47:05 +0400 | [diff] [blame] | 931 | |
| 932 | stage('Upgrade OS') { |
| 933 | if (packageUpgradeMode) { |
| 934 | def debian = new com.mirantis.mk.Debian() |
| 935 | def statusFile = '/tmp/rebooted_during_upgrade' |
| 936 | for(cidNode in cidNodes) { |
| 937 | node('python') { |
| 938 | python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds) |
| 939 | // cmd.run async to prevent connection close in case of slave shutdown, give 5 seconds to handle request response |
| 940 | salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${cidNode}' cmd.run 'sleep 5; touch ${statusFile}; salt-call service.stop docker' --async") |
| 941 | } |
| 942 | sleep(30) |
| 943 | node('python') { |
| 944 | python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds) |
| 945 | debian.osUpgradeNode(venvPepper, cidNode, packageUpgradeMode, false, 60) |
| 946 | salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': cidNode, wait: 60, timeout: 10]) |
| 947 | if (salt.runSaltProcessStep(venvPepper, cidNode, 'file.file_exists', [statusFile], null, true, 5)['return'][0].values()[0].toBoolean()) { |
| 948 | salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${cidNode}' cmd.run 'rm ${statusFile} && salt-call service.start docker'") // in case if node was not rebooted |
| 949 | sleep(10) |
| 950 | } |
| 951 | checkCICDDocker() |
| 952 | } |
| 953 | } |
| 954 | } else { |
| 955 | common.infoMsg('Upgrade OS skipped...') |
| 956 | } |
| 957 | } |
Jakub Josef | 2c21c6c | 2018-02-08 18:51:42 +0100 | [diff] [blame] | 958 | } |