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 |
| 11 | * UPGRADE_SALTSTACK Upgrade SaltStack packages to new version. |
| 12 | * UPDATE_CLUSTER_MODEL Update MCP version parameter in cluster model |
| 13 | * UPDATE_PIPELINES Update pipeline repositories on Gerrit |
| 14 | * UPDATE_LOCAL_REPOS Update local repositories |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 15 | */ |
| 16 | |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 17 | salt = new com.mirantis.mk.Salt() |
| 18 | common = new com.mirantis.mk.Common() |
| 19 | python = new com.mirantis.mk.Python() |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 20 | jenkinsUtils = new com.mirantis.mk.JenkinsUtils() |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 21 | def pipelineTimeout = 12 |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 22 | venvPepper = "venvPepper" |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 23 | workspace = "" |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 24 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 25 | def triggerMirrorJob(String jobName, String reclassSystemBranch) { |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 26 | params = jenkinsUtils.getJobParameters(jobName) |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 27 | try { |
| 28 | build job: jobName, parameters: [ |
| 29 | [$class: 'StringParameterValue', name: 'BRANCHES', value: params.get('BRANCHES')], |
| 30 | [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')], |
| 31 | [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')], |
| 32 | [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')] |
| 33 | ] |
| 34 | } catch (Exception updateErr) { |
| 35 | common.warningMsg(updateErr) |
| 36 | common.warningMsg('Attempt to update git repo in failsafe manner') |
| 37 | build job: jobName, parameters: [ |
| 38 | [$class: 'StringParameterValue', name: 'BRANCHES', value: reclassSystemBranch.replace('origin/', '')], |
| 39 | [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')], |
| 40 | [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')], |
| 41 | [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')] |
| 42 | ] |
| 43 | } |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 44 | } |
| 45 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 46 | def updateSaltStack(target, pkgs) { |
Denis Egorenko | 0d0c65f | 2019-02-26 16:05:03 +0400 | [diff] [blame] | 47 | salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${target}' --async pkg.install force_yes=True pkgs='$pkgs'") |
| 48 | // can't use same function from pipeline lib, as at the moment of running upgrade pipeline Jenkins |
| 49 | // still using pipeline lib from current old mcp-version |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 50 | common.retry(20, 60) { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 51 | salt.minionsReachable(venvPepper, 'I@salt:master', '*') |
| 52 | def running = salt.runSaltProcessStep(venvPepper, target, 'saltutil.running', [], null, true, 5) |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 53 | for (value in running.get("return")[0].values()) { |
| 54 | if (value != []) { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 55 | throw new Exception("Not all salt-minions are ready for execution") |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 60 | 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] | 61 | 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] | 62 | def saltMinionVersion = "" |
| 63 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 64 | for (minion in saltMinionVersions[0].keySet()) { |
| 65 | saltMinionVersion = saltMinionVersions[0].get(minion).replace("Salt command execution success", "").trim() |
| 66 | if (saltMinionVersion == "") { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 67 | error("Installed version of Salt on $minion doesn't match specified version in the model.") |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 72 | def wa29352(ArrayList saltMinions, String cname) { |
| 73 | // WA for PROD-29352. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/12/openssh/client/root.yml |
| 74 | // Default soft-param has been removed, what now makes not possible to render some old env's. |
| 75 | // Like fix, we found copy-paste already generated key from backups, to secrets.yml with correct key name |
| 76 | def wa29352ClassName = 'cluster.' + cname + '.infra.secrets_root_wa29352' |
| 77 | def wa29352File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_root_wa29352.yml" |
| 78 | def wa29352SecretsFile = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets.yml" |
| 79 | def _tempFile = '/tmp/wa29352_' + UUID.randomUUID().toString().take(8) |
| 80 | try { |
| 81 | salt.cmdRun(venvPepper, 'I@salt:master', "grep -qiv root_private_key ${wa29352SecretsFile}", true, null, false) |
| 82 | salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29352File}", true, null, false) |
| 83 | } |
| 84 | catch (Exception ex) { |
| 85 | common.infoMsg('Work-around for PROD-29352 already apply, nothing todo') |
| 86 | return |
| 87 | } |
| 88 | def rKeysDict = [ |
| 89 | 'parameters': [ |
| 90 | '_param': [ |
| 91 | 'root_private_key': salt.getPillar(venvPepper, 'I@salt:master', '_param:root_private_key').get('return')[0].values()[0].trim(), |
| 92 | 'root_public_key' : '', |
| 93 | ] |
| 94 | ] |
| 95 | ] |
| 96 | // save root key,and generate public one from it |
| 97 | writeFile file: _tempFile, text: rKeysDict['parameters']['_param']['root_private_key'].toString().trim() |
| 98 | sh('chmod 0600 ' + _tempFile) |
| 99 | rKeysDict['parameters']['_param']['root_public_key'] = sh(script: "ssh-keygen -q -y -f ${_tempFile}", returnStdout: true).trim() |
| 100 | sh('rm -fv ' + _tempFile) |
| 101 | writeYaml file: _tempFile, data: rKeysDict |
| 102 | def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim() |
| 103 | salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29352File}", false, null, false) |
| 104 | common.infoMsg("Add $wa29352ClassName class into secrets.yml") |
| 105 | |
| 106 | // Add 'classes:' directive |
| 107 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " + |
| 108 | "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml") |
| 109 | |
| 110 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " + |
| 111 | "grep -q '${wa29352ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29352ClassName' infra/secrets.yml") |
| 112 | salt.fullRefresh(venvPepper, '*') |
| 113 | sh('rm -fv ' + _tempFile) |
| 114 | } |
| 115 | |
| 116 | def wa29155(ArrayList saltMinions, String cname) { |
| 117 | // WA for PROD-29155. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/ |
| 118 | // CHeck for existence cmp nodes, and try to render it. Is failed, apply ssh-key wa |
| 119 | def ret = '' |
| 120 | def patched = false |
| 121 | def wa29155ClassName = 'cluster.' + cname + '.infra.secrets_nova_wa29155' |
| 122 | def wa29155File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_nova_wa29155.yml" |
| 123 | |
| 124 | try { |
| 125 | salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29155File}", true, null, false) |
| 126 | } |
| 127 | catch (Exception ex) { |
| 128 | common.infoMsg('Work-around for PROD-29155 already apply, nothing todo') |
| 129 | return |
| 130 | } |
| 131 | salt.fullRefresh(venvPepper, 'cfg*') |
| 132 | salt.fullRefresh(venvPepper, 'cmp*') |
| 133 | for (String minion in saltMinions) { |
| 134 | if (!minion.startsWith('cmp')) { |
| 135 | continue |
| 136 | } |
| 137 | // First attempt, second will be performed in next validateReclassModel() stages |
| 138 | try { |
| 139 | salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false).get('return')[0].values()[0].replaceAll('Salt command execution success', '').trim() |
| 140 | } catch (Exception e) { |
| 141 | common.errorMsg(e.toString()) |
| 142 | if (patched) { |
| 143 | error("Node: ${minion} failed to render after reclass-system upgrade!WA29155 probably didn't help.") |
| 144 | } |
| 145 | // check, that failed exactly by our case, by key-length check. |
| 146 | def missed_key = salt.getPillar(venvPepper, minion, '_param:nova_compute_ssh_private').get("return")[0].values()[0] |
| 147 | if (missed_key != '') { |
| 148 | error("Node: ${minion} failed to render after reclass-system upgrade!") |
| 149 | } |
| 150 | common.warningMsg('Perform: Attempt to apply WA for PROD-29155\n' + |
| 151 | 'See https://gerrit.mcp.mirantis.com/#/c/37932/ for more info') |
| 152 | common.warningMsg('WA-PROD-29155 Generating new ssh key at master node') |
| 153 | def _tempFile = "/tmp/nova_wa29155_" + UUID.randomUUID().toString().take(8) |
| 154 | common.infoMsg('Perform: generation NEW ssh-private key for nova-compute') |
| 155 | salt.cmdRun(venvPepper, 'I@salt:master', "ssh-keygen -f ${_tempFile} -N '' -q") |
| 156 | def _pub_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}.pub").get('return')[0].values()[0].trim() |
| 157 | def _priv_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}").get('return')[0].values()[0].trim() |
| 158 | salt.cmdRun(venvPepper, 'I@salt:master', "rm -fv ${_tempFile}", false, null, false) |
| 159 | def novaKeysDict = [ |
| 160 | "parameters": [ |
| 161 | "_param": [ |
| 162 | "nova_compute_ssh_private": _priv_k, |
| 163 | "nova_compute_ssh_public" : _pub_k |
| 164 | ] |
| 165 | ] |
| 166 | ] |
| 167 | writeYaml file: _tempFile, data: novaKeysDict |
| 168 | def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim() |
| 169 | salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29155File}", false, null, false) |
| 170 | common.infoMsg("Add $wa29155ClassName class into secrets.yml") |
| 171 | |
| 172 | // Add 'classes:' directive |
| 173 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " + |
| 174 | "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml") |
| 175 | |
| 176 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " + |
| 177 | "grep -q '${wa29155ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29155ClassName' infra/secrets.yml") |
| 178 | salt.fullRefresh(venvPepper, 'cfg*') |
| 179 | salt.fullRefresh(venvPepper, 'cmp*') |
| 180 | patched = true |
| 181 | } |
| 182 | } |
| 183 | if (patched) { |
| 184 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " + |
| 185 | "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()}' ") |
| 186 | common.infoMsg('Work-around for PROD-29155 successfully applied') |
| 187 | } |
| 188 | |
| 189 | } |
| 190 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 191 | def archiveReclassInventory(filename) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 192 | def _tmp_file = '/tmp/' + filename + UUID.randomUUID().toString().take(8) |
| 193 | // jenkins may fail at overheap. Compress data with gzip like WA |
| 194 | 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() |
| 195 | def _tmp = sh(script: "echo '$ret' > ${_tmp_file}", returnStdout: false) |
| 196 | sh(script: "cat ${_tmp_file} | base64 -d | gzip -d > $filename", returnStdout: false) |
| 197 | archiveArtifacts artifacts: filename |
| 198 | sh(script: "rm -v ${_tmp_file}|| true") |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 199 | } |
| 200 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 201 | def validateReclassModel(ArrayList saltMinions, String suffix) { |
| 202 | try { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 203 | for (String minion in saltMinions) { |
| 204 | common.infoMsg("Reclass model validation for minion ${minion}...") |
| 205 | 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() |
| 206 | writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString() |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 207 | } |
| 208 | } catch (Exception e) { |
| 209 | common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.') |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 210 | error(e.toString()) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 214 | def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix = 'before', String newSuffix = 'after') { |
| 215 | for (String minion in saltMinions) { |
| 216 | def fileName = "reclass-model-${minion}-diff.out" |
| 217 | sh "diff -u inventory-${minion}-${oldSuffix}.out inventory-${minion}-${newSuffix}.out > ${fileName} || true" |
| 218 | archiveArtifacts artifacts: "${fileName}" |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
Denis Egorenko | 5a8a7e9 | 2018-12-27 14:13:48 +0400 | [diff] [blame] | 222 | if (common.validInputParam('PIPELINE_TIMEOUT')) { |
| 223 | try { |
| 224 | pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger() |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 225 | } catch (Exception e) { |
Denis Egorenko | 5a8a7e9 | 2018-12-27 14:13:48 +0400 | [diff] [blame] | 226 | common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger") |
| 227 | } |
Martin Polreich | 965c903 | 2018-08-09 16:33:57 +0200 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | timeout(time: pipelineTimeout, unit: 'HOURS') { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 231 | node("python") { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 232 | try { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 233 | def inventoryBeforeFilename = "reclass-inventory-before.out" |
| 234 | def inventoryAfterFilename = "reclass-inventory-after.out" |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 235 | workspace = common.getWorkspace() |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 236 | targetMcpVersion = null |
| 237 | if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) { |
| 238 | error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable') |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 239 | } |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 240 | // bw comp. for 2018.X => 2018.11 release |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 241 | if (common.validInputParam('MCP_VERSION')) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 242 | targetMcpVersion = env.MCP_VERSION |
| 243 | 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] | 244 | } else { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 245 | targetMcpVersion = env.TARGET_MCP_VERSION |
| 246 | } |
| 247 | // end bw comp. for 2018.X => 2018.11 release |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 248 | def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC') |
Ivan Berezovskiy | d62629c | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 249 | if (targetMcpVersion in ['nightly', 'testing']) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 250 | gitTargetMcpVersion = 'master' |
Ivan Berezovskiy | d62629c | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 251 | } else if (targetMcpVersion == 'proposed') { |
| 252 | gitTargetMcpVersion = 'proposed' |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 253 | } else if (!gitTargetMcpVersion) { |
| 254 | // backward compatibility for 2018.11.0 |
| 255 | gitTargetMcpVersion = "release/${targetMcpVersion}" |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 256 | } |
Ivan Berezovskiy | d62629c | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 257 | common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}") |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 258 | def saltMastURL = '' |
| 259 | def saltMastCreds = '' |
| 260 | def upgradeSaltStack = '' |
| 261 | def updateClusterModel = '' |
| 262 | def updatePipelines = '' |
| 263 | def updateLocalRepos = '' |
| 264 | def reclassSystemBranch = '' |
Denis Egorenko | b559e54 | 2019-03-29 13:24:15 +0400 | [diff] [blame] | 265 | def reclassSystemBranchDefault = gitTargetMcpVersion |
| 266 | if (gitTargetMcpVersion != 'proposed') { |
| 267 | reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}" |
| 268 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 269 | def driteTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS') |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 270 | if (driteTrainParamsYaml) { |
| 271 | def driteTrainParams = readYaml text: driteTrainParamsYaml |
| 272 | saltMastURL = driteTrainParams.get('SALT_MASTER_URL') |
Denis Egorenko | 928b3e8 | 2019-01-15 11:47:16 +0400 | [diff] [blame] | 273 | saltMastCreds = driteTrainParams.get('SALT_MASTER_CREDENTIALS') |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 274 | upgradeSaltStack = driteTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean() |
| 275 | updateClusterModel = driteTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean() |
| 276 | updatePipelines = driteTrainParams.get('UPDATE_PIPELINES', false).toBoolean() |
| 277 | updateLocalRepos = driteTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean() |
Denis Egorenko | b559e54 | 2019-03-29 13:24:15 +0400 | [diff] [blame] | 278 | reclassSystemBranch = driteTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault) |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 279 | } else { |
| 280 | // backward compatibility for 2018.11.0 |
| 281 | saltMastURL = env.getProperty('SALT_MASTER_URL') |
| 282 | saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS') |
Denis Egorenko | e5f3914 | 2018-12-28 12:30:48 +0400 | [diff] [blame] | 283 | upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean() |
| 284 | updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean() |
| 285 | updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean() |
| 286 | updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean() |
Denis Egorenko | b559e54 | 2019-03-29 13:24:15 +0400 | [diff] [blame] | 287 | reclassSystemBranch = reclassSystemBranchDefault |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 288 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 289 | python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 290 | def minions = salt.getMinions(venvPepper, '*') |
Denis Egorenko | c0538ce | 2019-04-19 15:05:18 +0400 | [diff] [blame] | 291 | def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0] |
| 292 | if (cluster_name == '' || cluster_name == 'null' || cluster_name == null) { |
| 293 | error('Pillar data is broken for Salt master node! Please check it manually and re-run pipeline.') |
| 294 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 295 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 296 | stage('Update Reclass and Salt-Formulas') { |
| 297 | common.infoMsg('Perform: Full salt sync') |
| 298 | salt.fullRefresh(venvPepper, '*') |
| 299 | common.infoMsg('Perform: Validate reclass medata before processing') |
| 300 | validateReclassModel(minions, 'before') |
| 301 | |
| 302 | common.infoMsg('Perform: archiveReclassInventory before upgrade') |
Denis Egorenko | 89a3c57 | 2019-03-22 17:03:40 +0400 | [diff] [blame] | 303 | archiveReclassInventory(inventoryBeforeFilename) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 304 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 305 | try { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 306 | 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] | 307 | } |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 308 | catch (Exception ex) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 309 | 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] | 310 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 311 | if (updateClusterModel) { |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 312 | common.infoMsg('Perform: UPDATE_CLUSTER_MODEL') |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 313 | def dateTime = common.getDatetime() |
Denis Egorenko | 00897c5 | 2019-03-18 15:47:33 +0400 | [diff] [blame] | 314 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/ && git submodule foreach git fetch") |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 315 | 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] | 316 | "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] | 317 | // Do the same, for deprecated variable-duplicate |
| 318 | 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] | 319 | "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] | 320 | 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] | 321 | "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] | 322 | // Set new k8s param |
| 323 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 324 | "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] | 325 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 326 | "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'") |
| 327 | 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] | 328 | "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] | 329 | 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] | 330 | "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] | 331 | 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] | 332 | "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] | 333 | |
| 334 | // Switch Jenkins/Gerrit to use LDAP SSL/TLS |
| 335 | def gerritldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 336 | "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() |
| 337 | if (gerritldapURI.startsWith('ldap://')) { |
| 338 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 339 | "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'") |
| 340 | } else if (! gerritldapURI.startsWith('ldaps://')) { |
| 341 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 342 | "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'") |
| 343 | } |
| 344 | def jenkinsldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 345 | "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() |
| 346 | if (jenkinsldapURI.startsWith('ldap://')) { |
| 347 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 348 | "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'") |
| 349 | } else if (! jenkinsldapURI.startsWith('ldaps://')) { |
| 350 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 351 | "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'") |
| 352 | } |
| 353 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 354 | 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] | 355 | // Add kubernetes-extra repo |
| 356 | if (salt.testTarget(venvPepper, "I@kubernetes:master")) { |
Sergey Kolekonov | ac9554c | 2019-04-11 16:33:54 +0400 | [diff] [blame] | 357 | // docker-engine conflicts with the recent containerd versions, so it's removed during upgrade. Thus update source engine |
| 358 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 359 | "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] | 360 | common.infoMsg("Add kubernetes-extra repo") |
| 361 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 362 | "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") |
| 363 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 364 | "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") |
| 365 | } |
Ivan Berezovskiy | be630ee | 2019-04-15 13:23:58 +0400 | [diff] [blame] | 366 | // Add all update repositories |
| 367 | def repoIncludeBase = '- system.linux.system.repo.mcp.apt_mirantis.' |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 368 | def updateRepoList = ['cassandra', 'ceph', 'contrail', 'docker', 'elastic', 'extra', 'openstack', 'percona', 'salt-formulas', 'saltstack', 'ubuntu'] |
Ivan Berezovskiy | be630ee | 2019-04-15 13:23:58 +0400 | [diff] [blame] | 369 | updateRepoList.each { repo -> |
| 370 | def repoNameUpdateInclude = "${repoIncludeBase}update.${repo}" |
| 371 | 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') |
| 372 | filesWithInclude.each { file -> |
| 373 | 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() |
| 374 | if (updateRepoIncludeExist == 'not_found') { |
| 375 | // Include needs to be added |
| 376 | 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] | 377 | "sed -i 's/\\( *\\)${repoIncludeBase}${repo}\$/&\\n\\1${repoNameUpdateInclude}/g' ${file}") |
Ivan Berezovskiy | be630ee | 2019-04-15 13:23:58 +0400 | [diff] [blame] | 378 | common.infoMsg("Update repo for ${repo} is added to ${file}") |
| 379 | } |
| 380 | } |
| 381 | } |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 382 | // Add new defaults |
| 383 | common.infoMsg("Add new defaults") |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 384 | 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] | 385 | "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] | 386 | 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] | 387 | "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] | 388 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 389 | "grep -r -l 'docker_image_jenkins: .*' cicd | xargs --no-run-if-empty sed -i 's|\\s*docker_image_jenkins: .*||g'") |
| 390 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 391 | "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] | 392 | 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] | 393 | "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] | 394 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff") |
| 395 | 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] | 396 | "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] | 397 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 398 | try { |
| 399 | common.infoMsg('Perform: UPDATE Salt Formulas') |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 400 | salt.fullRefresh(venvPepper, '*') |
| 401 | salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 402 | 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] | 403 | salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas", 'salt.master.env']) |
| 404 | salt.fullRefresh(venvPepper, '*') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 405 | } catch (Exception updateErr) { |
| 406 | common.warningMsg(updateErr) |
| 407 | common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.') |
| 408 | input message: 'Continue anyway?' |
| 409 | } |
| 410 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 411 | wa29352(minions, cluster_name) |
| 412 | wa29155(minions, cluster_name) |
| 413 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 414 | try { |
| 415 | common.infoMsg('Perform: UPDATE Reclass package') |
| 416 | salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"]) |
| 417 | } catch (Exception updateErr) { |
| 418 | common.warningMsg(updateErr) |
| 419 | common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.') |
| 420 | input message: 'Continue anyway?' |
| 421 | } |
| 422 | |
| 423 | salt.fullRefresh(venvPepper, 'I@salt:master') |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 424 | salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 425 | try { |
| 426 | salt.enforceState(venvPepper, "I@salt:master", 'reclass', true) |
| 427 | } |
| 428 | catch (Exception ex) { |
| 429 | error("Reclass fails rendering. Pay attention to your cluster model.") |
| 430 | } |
| 431 | |
| 432 | salt.fullRefresh(venvPepper, '*') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 433 | try { |
| 434 | salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top") |
| 435 | } |
| 436 | catch (Exception ex) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 437 | |
| 438 | error('Reclass fails rendering. Pay attention to your cluster model.' + |
| 439 | 'ErrorMessage:' + ex.toString()) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 440 | } |
| 441 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 442 | common.infoMsg('Perform: archiveReclassInventory AFTER upgrade') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 443 | archiveReclassInventory(inventoryAfterFilename) |
| 444 | |
| 445 | sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true" |
| 446 | archiveArtifacts artifacts: "reclass-inventory-diff.out" |
| 447 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 448 | validateReclassModel(minions, 'after') |
| 449 | archiveReclassModelChanges(minions) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 450 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 451 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 452 | if (updateLocalRepos) { |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 453 | stage("Update local repos") { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 454 | common.infoMsg("Updating local repositories") |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 455 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 456 | def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine") |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 457 | runningOnDocker = engine.get("return")[0].containsValue("docker") |
| 458 | |
| 459 | if (runningOnDocker) { |
| 460 | common.infoMsg("Aptly is running as Docker container") |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 461 | } else { |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 462 | common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands") |
| 463 | } |
| 464 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 465 | if (runningOnDocker) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 466 | 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] | 467 | } else { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 468 | 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] | 469 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 470 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 471 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 472 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 473 | if (runningOnDocker) { |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 474 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true) |
| 475 | 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] | 476 | } else { |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 477 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true) |
| 478 | 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] | 479 | } |
Richard Felkl | 79d7df1 | 2018-01-05 16:40:11 +0100 | [diff] [blame] | 480 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 481 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 482 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 483 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 484 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 485 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true) |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 486 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 487 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 488 | } |
| 489 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 490 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 491 | stage('Update Drivetrain') { |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 492 | if (upgradeSaltStack) { |
| 493 | updateSaltStack("I@salt:master", '["salt-master", "salt-common", "salt-api", "salt-minion"]') |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 494 | |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 495 | salt.enforceState(venvPepper, "I@linux:system", 'linux.system.repo', true) |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 496 | updateSaltStack("I@salt:minion and not I@salt:master", '["salt-minion"]') |
| 497 | } |
| 498 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 499 | if (updatePipelines) { |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 500 | common.infoMsg('Perform: UPDATE git repos') |
| 501 | triggerMirrorJob('git-mirror-downstream-mk-pipelines', reclassSystemBranch) |
| 502 | triggerMirrorJob('git-mirror-downstream-pipeline-library', reclassSystemBranch) |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 503 | } |
| 504 | |
Denis Egorenko | d00c17e | 2019-04-25 20:17:27 +0400 | [diff] [blame] | 505 | // update minions certs |
| 506 | salt.enforceState(venvPepper, "I@salt:minion", 'salt.minion.cert', true) |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 507 | |
| 508 | // Retry needed only for rare race-condition in user appearance |
| 509 | common.infoMsg('Perform: updating users and keys') |
Denis Egorenko | aeaa1de | 2019-01-15 11:58:12 +0400 | [diff] [blame] | 510 | salt.enforceState(venvPepper, "I@linux:system", 'linux.system.user', true) |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 511 | common.infoMsg('Perform: updating openssh') |
Denis Egorenko | aeaa1de | 2019-01-15 11:58:12 +0400 | [diff] [blame] | 512 | salt.enforceState(venvPepper, "I@linux:system", 'openssh', true) |
| 513 | |
Denis Egorenko | 242f9bd | 2019-07-09 18:55:35 +0400 | [diff] [blame] | 514 | // Apply changes for HaProxy on CI/CD nodes |
| 515 | salt.enforceState(venvPepper, 'I@keepalived:cluster:instance:cicd_control_vip and I@haproxy:proxy', 'haproxy.proxy', true) |
| 516 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 517 | 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") |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 518 | |
| 519 | sleep(180) |
| 520 | |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 521 | common.infoMsg('Perform: Checking if Docker containers are up') |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 522 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 523 | try { |
| 524 | common.retry(10, 30) { |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 525 | salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'") |
| 526 | } |
| 527 | } |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 528 | catch (Exception ex) { |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 529 | error("Docker containers for CI/CD services are having troubles with starting.") |
| 530 | } |
Denis Egorenko | 6ca9f0d | 2019-07-10 19:47:39 +0400 | [diff] [blame] | 531 | |
| 532 | salt.enforceState(venvPepper, 'I@jenkins:client and not I@salt:master', 'jenkins.client', true) |
Denis Egorenko | 84a0bc0 | 2019-07-23 18:01:21 +0400 | [diff] [blame^] | 533 | |
| 534 | // update Nginx proxy settings for Jenkins/Gerrit if needed |
| 535 | if (salt.testTarget(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit')) { |
| 536 | 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) |
| 537 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 538 | } |
| 539 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 540 | catch (Throwable e) { |
| 541 | // If there was an error or exception thrown, the build failed |
| 542 | currentBuild.result = "FAILURE" |
| 543 | throw e |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 544 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 545 | } |
Denis Egorenko | ada8388 | 2019-06-11 14:03:40 +0400 | [diff] [blame] | 546 | } |