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 |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 16 | */ |
| 17 | |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 18 | salt = new com.mirantis.mk.Salt() |
| 19 | common = new com.mirantis.mk.Common() |
| 20 | python = new com.mirantis.mk.Python() |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 21 | jenkinsUtils = new com.mirantis.mk.JenkinsUtils() |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 22 | def pipelineTimeout = 12 |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 23 | venvPepper = "venvPepper" |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 24 | workspace = "" |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 25 | |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 26 | def triggerMirrorJob(String jobName, String reclassSystemBranch) { |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 27 | params = jenkinsUtils.getJobParameters(jobName) |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 28 | try { |
| 29 | build job: jobName, parameters: [ |
| 30 | [$class: 'StringParameterValue', name: 'BRANCHES', value: params.get('BRANCHES')], |
| 31 | [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')], |
| 32 | [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')], |
| 33 | [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')] |
| 34 | ] |
| 35 | } catch (Exception updateErr) { |
| 36 | common.warningMsg(updateErr) |
| 37 | common.warningMsg('Attempt to update git repo in failsafe manner') |
| 38 | build job: jobName, parameters: [ |
| 39 | [$class: 'StringParameterValue', name: 'BRANCHES', value: reclassSystemBranch.replace('origin/', '')], |
| 40 | [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get('CREDENTIALS_ID')], |
| 41 | [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get('SOURCE_URL')], |
| 42 | [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get('TARGET_URL')] |
| 43 | ] |
| 44 | } |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 45 | } |
| 46 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 47 | def updateSaltStack(target, pkgs) { |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 48 | 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] | 49 | // can't use same function from pipeline lib, as at the moment of running upgrade pipeline Jenkins |
| 50 | // still using pipeline lib from current old mcp-version |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 51 | common.retry(20, 60) { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 52 | salt.minionsReachable(venvPepper, 'I@salt:master', '*') |
| 53 | def running = salt.runSaltProcessStep(venvPepper, target, 'saltutil.running', [], null, true, 5) |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 54 | for (value in running.get("return")[0].values()) { |
| 55 | if (value != []) { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 56 | throw new Exception("Not all salt-minions are ready for execution") |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 61 | 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] | 62 | 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] | 63 | def saltMinionVersion = "" |
| 64 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 65 | for (minion in saltMinionVersions[0].keySet()) { |
| 66 | saltMinionVersion = saltMinionVersions[0].get(minion).replace("Salt command execution success", "").trim() |
| 67 | if (saltMinionVersion == "") { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 68 | error("Installed version of Salt on $minion doesn't match specified version in the model.") |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
Denis Egorenko | 20a4346 | 2019-09-24 14:55:50 +0400 | [diff] [blame] | 73 | def getWorkerThreads(saltId) { |
| 74 | if (env.getEnvironment().containsKey('SALT_MASTER_OPT_WORKER_THREADS')) { |
| 75 | return env['SALT_MASTER_OPT_WORKER_THREADS'].toString() |
| 76 | } |
| 77 | 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) |
| 78 | return threads['return'][0].values()[0].replaceAll('Salt command execution success','').trim() |
| 79 | } |
| 80 | |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 81 | def wa29352(ArrayList saltMinions, String cname) { |
| 82 | // WA for PROD-29352. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/12/openssh/client/root.yml |
| 83 | // Default soft-param has been removed, what now makes not possible to render some old env's. |
| 84 | // Like fix, we found copy-paste already generated key from backups, to secrets.yml with correct key name |
| 85 | def wa29352ClassName = 'cluster.' + cname + '.infra.secrets_root_wa29352' |
| 86 | def wa29352File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_root_wa29352.yml" |
| 87 | def wa29352SecretsFile = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets.yml" |
| 88 | def _tempFile = '/tmp/wa29352_' + UUID.randomUUID().toString().take(8) |
| 89 | try { |
| 90 | salt.cmdRun(venvPepper, 'I@salt:master', "grep -qiv root_private_key ${wa29352SecretsFile}", true, null, false) |
| 91 | salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29352File}", true, null, false) |
| 92 | } |
| 93 | catch (Exception ex) { |
Denis Egorenko | dfa3542 | 2019-10-07 12:46:14 +0400 | [diff] [blame] | 94 | common.infoMsg('Work-around for PROD-29352 already applied, nothing todo') |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 95 | return |
| 96 | } |
| 97 | def rKeysDict = [ |
| 98 | 'parameters': [ |
| 99 | '_param': [ |
| 100 | 'root_private_key': salt.getPillar(venvPepper, 'I@salt:master', '_param:root_private_key').get('return')[0].values()[0].trim(), |
| 101 | 'root_public_key' : '', |
| 102 | ] |
| 103 | ] |
| 104 | ] |
| 105 | // save root key,and generate public one from it |
| 106 | writeFile file: _tempFile, text: rKeysDict['parameters']['_param']['root_private_key'].toString().trim() |
| 107 | sh('chmod 0600 ' + _tempFile) |
| 108 | rKeysDict['parameters']['_param']['root_public_key'] = sh(script: "ssh-keygen -q -y -f ${_tempFile}", returnStdout: true).trim() |
| 109 | sh('rm -fv ' + _tempFile) |
| 110 | writeYaml file: _tempFile, data: rKeysDict |
| 111 | def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim() |
| 112 | salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29352File}", false, null, false) |
| 113 | common.infoMsg("Add $wa29352ClassName class into secrets.yml") |
| 114 | |
| 115 | // Add 'classes:' directive |
| 116 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " + |
| 117 | "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml") |
| 118 | |
| 119 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " + |
| 120 | "grep -q '${wa29352ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29352ClassName' infra/secrets.yml") |
| 121 | salt.fullRefresh(venvPepper, '*') |
| 122 | sh('rm -fv ' + _tempFile) |
Denis Egorenko | dfa3542 | 2019-10-07 12:46:14 +0400 | [diff] [blame] | 123 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " + |
| 124 | "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()}' ") |
| 125 | common.infoMsg('Work-around for PROD-29352 successfully applied') |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 126 | } |
| 127 | |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 128 | def wa29155(ArrayList saltMinions, String cname) { |
| 129 | // WA for PROD-29155. Issue cause due patch https://gerrit.mcp.mirantis.com/#/c/37932/ |
| 130 | // CHeck for existence cmp nodes, and try to render it. Is failed, apply ssh-key wa |
| 131 | def ret = '' |
| 132 | def patched = false |
| 133 | def wa29155ClassName = 'cluster.' + cname + '.infra.secrets_nova_wa29155' |
| 134 | def wa29155File = "/srv/salt/reclass/classes/cluster/${cname}/infra/secrets_nova_wa29155.yml" |
| 135 | |
| 136 | try { |
| 137 | salt.cmdRun(venvPepper, 'I@salt:master', "test ! -f ${wa29155File}", true, null, false) |
| 138 | } |
| 139 | catch (Exception ex) { |
| 140 | common.infoMsg('Work-around for PROD-29155 already apply, nothing todo') |
| 141 | return |
| 142 | } |
Denis Egorenko | 14fa6e1 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 143 | salt.fullRefresh(venvPepper, 'I@salt:master') |
| 144 | salt.fullRefresh(venvPepper, 'I@nova:compute') |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 145 | for (String minion in saltMinions) { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 146 | // First attempt, second will be performed in next validateReclassModel() stages |
| 147 | try { |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 148 | 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] | 149 | } catch (Exception e) { |
| 150 | common.errorMsg(e.toString()) |
| 151 | if (patched) { |
| 152 | error("Node: ${minion} failed to render after reclass-system upgrade!WA29155 probably didn't help.") |
| 153 | } |
| 154 | // check, that failed exactly by our case, by key-length check. |
| 155 | def missed_key = salt.getPillar(venvPepper, minion, '_param:nova_compute_ssh_private').get("return")[0].values()[0] |
| 156 | if (missed_key != '') { |
| 157 | error("Node: ${minion} failed to render after reclass-system upgrade!") |
| 158 | } |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 159 | common.warningMsg('Perform: Attempt to apply WA for PROD-29155\n' + |
| 160 | 'See https://gerrit.mcp.mirantis.com/#/c/37932/ for more info') |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 161 | common.warningMsg('WA-PROD-29155 Generating new ssh key at master node') |
| 162 | def _tempFile = "/tmp/nova_wa29155_" + UUID.randomUUID().toString().take(8) |
| 163 | common.infoMsg('Perform: generation NEW ssh-private key for nova-compute') |
| 164 | salt.cmdRun(venvPepper, 'I@salt:master', "ssh-keygen -f ${_tempFile} -N '' -q") |
| 165 | def _pub_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}.pub").get('return')[0].values()[0].trim() |
| 166 | def _priv_k = salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', "cat ${_tempFile}").get('return')[0].values()[0].trim() |
| 167 | salt.cmdRun(venvPepper, 'I@salt:master', "rm -fv ${_tempFile}", false, null, false) |
| 168 | def novaKeysDict = [ |
| 169 | "parameters": [ |
| 170 | "_param": [ |
| 171 | "nova_compute_ssh_private": _priv_k, |
| 172 | "nova_compute_ssh_public" : _pub_k |
| 173 | ] |
| 174 | ] |
| 175 | ] |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 176 | writeYaml file: _tempFile, data: novaKeysDict |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 177 | def yamlData = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim() |
| 178 | salt.cmdRun(venvPepper, 'I@salt:master', "echo '${yamlData}' | base64 -d > ${wa29155File}", false, null, false) |
| 179 | common.infoMsg("Add $wa29155ClassName class into secrets.yml") |
| 180 | |
| 181 | // Add 'classes:' directive |
| 182 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " + |
| 183 | "grep -q 'classes:' infra/secrets.yml || sed -i '1iclasses:' infra/secrets.yml") |
| 184 | |
| 185 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && " + |
| 186 | "grep -q '${wa29155ClassName}' infra/secrets.yml || sed -i '/classes:/ a - $wa29155ClassName' infra/secrets.yml") |
| 187 | salt.fullRefresh(venvPepper, 'cfg*') |
| 188 | salt.fullRefresh(venvPepper, 'cmp*') |
| 189 | patched = true |
| 190 | } |
| 191 | } |
| 192 | if (patched) { |
| 193 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cname && git status && " + |
| 194 | "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()}' ") |
| 195 | common.infoMsg('Work-around for PROD-29155 successfully applied') |
| 196 | } |
| 197 | |
| 198 | } |
| 199 | |
Denis Egorenko | 1b11d23 | 2019-07-29 17:44:46 +0400 | [diff] [blame] | 200 | def wa32284(String clusterName) { |
| 201 | def clientGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:enabled").get("return")[0].values()[0] |
| 202 | def pkiGluster = salt.getPillar(venvPepper, 'I@salt:master', "glusterfs:client:volumes:salt_pki").get("return")[0].values()[0] |
| 203 | def nginxEnabledAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0] |
| 204 | if (nginxEnabledAtMaster.toString().toLowerCase() == 'true' && clientGluster.toString().toLowerCase() == 'true' && pkiGluster) { |
| 205 | def nginxRequires = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:wait_for_service').get('return')[0].values()[0] |
| 206 | if (nginxRequires.isEmpty()) { |
| 207 | def nginxRequiresClassName = "cluster.${clusterName}.infra.config.nginx_requires_wa32284" |
| 208 | def nginxRequiresClassFile = "/srv/salt/reclass/classes/cluster/${clusterName}/infra/config/nginx_requires_wa32284.yml" |
| 209 | def nginxRequiresBlock = ['parameters': ['nginx': ['server': ['wait_for_service': ['srv-salt-pki.mount'] ] ] ] ] |
| 210 | def _tempFile = '/tmp/wa32284_' + UUID.randomUUID().toString().take(8) |
| 211 | writeYaml file: _tempFile , data: nginxRequiresBlock |
| 212 | def nginxRequiresBlockString = sh(script: "cat ${_tempFile}", returnStdout: true).trim() |
| 213 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/${clusterName} && " + |
| 214 | "sed -i '/^parameters:/i - ${nginxRequiresClassName}' infra/config/init.yml") |
| 215 | salt.cmdRun(venvPepper, 'I@salt:master', "echo '${nginxRequiresBlockString}' > ${nginxRequiresClassFile}", false, null, false) |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
Denis Egorenko | af18b25 | 2019-09-02 14:53:02 +0400 | [diff] [blame] | 220 | def wa32182(String cluster_name) { |
Hanna Arhipova | d5eec4c | 2019-09-06 17:55:40 +0300 | [diff] [blame] | 221 | if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) { |
Denis Egorenko | af18b25 | 2019-09-02 14:53:02 +0400 | [diff] [blame] | 222 | def clusterModelPath = "/srv/salt/reclass/classes/cluster/${cluster_name}" |
| 223 | def fixFile = "${clusterModelPath}/opencontrail/common_wa32182.yml" |
| 224 | def usualFile = "${clusterModelPath}/opencontrail/common.yml" |
| 225 | def fixFileContent = "classes:\n- system.opencontrail.common\n" |
| 226 | salt.cmdRun(venvPepper, 'I@salt:master', "test -f ${fixFile} -o -f ${usualFile} || echo '${fixFileContent}' > ${fixFile}") |
| 227 | def contrailFiles = ['opencontrail/analytics.yml', 'opencontrail/control.yml', 'openstack/compute/init.yml'] |
| 228 | if (salt.testTarget(venvPepper, "I@kubernetes:master")) { |
| 229 | contrailFiles.add('kubernetes/compute.yml') |
| 230 | } |
| 231 | for(String contrailFile in contrailFiles) { |
| 232 | contrailFile = "${clusterModelPath}/${contrailFile}" |
| 233 | 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() |
| 234 | if (containsFix) { |
| 235 | continue |
| 236 | } else { |
| 237 | salt.cmdRun(venvPepper, 'I@salt:master', "grep -q -E '^parameters:' ${contrailFile} && sed -i '/^parameters:/i - cluster.${cluster_name}.opencontrail.common_wa32182' ${contrailFile} || " + |
| 238 | "echo '- cluster.${cluster_name}.opencontrail.common_wa32182' >> ${contrailFile}") |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
Denis Egorenko | ba63133 | 2019-10-25 13:13:39 +0400 | [diff] [blame] | 244 | def wa33867(String cluster_name) { |
| 245 | if (salt.testTarget(venvPepper, 'I@opencontrail:control or I@opencontrail:collector')) { |
| 246 | def contrailControlFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/opencontrail/control.yml" |
| 247 | 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() |
| 248 | if (line == "- cluster.${cluster_name}.infra") { |
| 249 | salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra\$/d' ${contrailControlFile}") |
| 250 | salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^- cluster.${cluster_name}.infra.backup.client_zookeeper\$/i - cluster.${cluster_name}.infra' ${contrailControlFile}") |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
Denis Egorenko | e312cc9 | 2019-10-18 17:06:11 +0400 | [diff] [blame] | 255 | def wa33771(String cluster_name) { |
| 256 | def octaviaEnabled = salt.getMinions(venvPepper, 'I@octavia:api:enabled') |
| 257 | def octaviaWSGI = salt.getMinions(venvPepper, 'I@apache:server:site:octavia_api') |
| 258 | if (octaviaEnabled && ! octaviaWSGI) { |
| 259 | def openstackControl = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/control.yml" |
| 260 | def octaviaFile = "/srv/salt/reclass/classes/cluster/${cluster_name}/openstack/octavia_wa33771.yml" |
| 261 | def octaviaContext = [ |
| 262 | 'classes': [ 'system.apache.server.site.octavia' ], |
| 263 | 'parameters': [ |
| 264 | '_param': [ 'apache_octavia_api_address' : '${_param:cluster_local_address}' ], |
| 265 | 'apache': [ 'server': [ 'site': [ 'apache_proxy_openstack_api_octavia': [ 'enabled': false ] ] ] ] |
| 266 | ] |
| 267 | ] |
| 268 | def _tempFile = '/tmp/wa33771' + UUID.randomUUID().toString().take(8) |
| 269 | writeYaml file: _tempFile , data: octaviaContext |
| 270 | def octaviaFileContent = sh(script: "cat ${_tempFile} | base64", returnStdout: true).trim() |
| 271 | salt.cmdRun(venvPepper, 'I@salt:master', "sed -i '/^parameters:/i - cluster.${cluster_name}.openstack.octavia_wa33771' ${openstackControl}") |
| 272 | salt.cmdRun(venvPepper, 'I@salt:master', "echo '${octaviaFileContent}' | base64 -d > ${octaviaFile}", false, null, false) |
| 273 | } |
| 274 | } |
| 275 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 276 | def archiveReclassInventory(filename) { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 277 | def _tmp_file = '/tmp/' + filename + UUID.randomUUID().toString().take(8) |
| 278 | // jenkins may fail at overheap. Compress data with gzip like WA |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 279 | 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] | 280 | def _tmp = sh(script: "echo '$ret' > ${_tmp_file}", returnStdout: false) |
| 281 | sh(script: "cat ${_tmp_file} | base64 -d | gzip -d > $filename", returnStdout: false) |
| 282 | archiveArtifacts artifacts: filename |
| 283 | sh(script: "rm -v ${_tmp_file}|| true") |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 284 | } |
| 285 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 286 | def validateReclassModel(ArrayList saltMinions, String suffix) { |
| 287 | try { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 288 | for (String minion in saltMinions) { |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 289 | common.infoMsg("Reclass model validation for minion ${minion}...") |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 290 | 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] | 291 | writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString() |
| 292 | } |
| 293 | } catch (Exception e) { |
| 294 | common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.') |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 295 | error(e.toString()) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 299 | def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix = 'before', String newSuffix = 'after') { |
| 300 | for (String minion in saltMinions) { |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 301 | def fileName = "reclass-model-${minion}-diff.out" |
| 302 | sh "diff -u inventory-${minion}-${oldSuffix}.out inventory-${minion}-${newSuffix}.out > ${fileName} || true" |
| 303 | archiveArtifacts artifacts: "${fileName}" |
| 304 | } |
| 305 | } |
| 306 | |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 307 | def checkDebsums() { |
| 308 | // check for salt-formulas consistency |
| 309 | try { |
| 310 | try { |
| 311 | salt.cmdRun(venvPepper, 'I@salt:master', "salt -C 'I@salt:master' pkg.install force_yes=True pkgs=[debsums]") |
| 312 | } |
| 313 | catch (Exception ex) { |
| 314 | common.warningMsg('Unable to install package "debsums" at cfg01. Salt-formulas integrity check skipped') |
| 315 | } |
| 316 | 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') |
| 317 | salt.cmdRun(venvPepper, 'I@salt:master', 'if [ -s "/root/debdsums_report" ]; then exit 1 ; fi') |
| 318 | } |
| 319 | catch (Exception ex) { |
| 320 | common.errorMsg(salt.cmdRun(venvPepper, 'I@salt:master', 'cat /root/debdsums_report ', true, null, false).get('return')[0].values()[0].trim()) |
| 321 | common.errorMsg(ex.toString()) |
| 322 | error('You have unexpected changes in formulas. All of them will be overwrited by update. Unable to continue in automatic way') |
| 323 | } |
| 324 | } |
| 325 | |
Denis Egorenko | 5a8a7e9 | 2018-12-27 14:13:48 +0400 | [diff] [blame] | 326 | if (common.validInputParam('PIPELINE_TIMEOUT')) { |
| 327 | try { |
| 328 | pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger() |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 329 | } catch (Exception e) { |
Denis Egorenko | 5a8a7e9 | 2018-12-27 14:13:48 +0400 | [diff] [blame] | 330 | common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger") |
| 331 | } |
Martin Polreich | 965c903 | 2018-08-09 16:33:57 +0200 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | timeout(time: pipelineTimeout, unit: 'HOURS') { |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 335 | node('python') { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 336 | try { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 337 | def inventoryBeforeFilename = "reclass-inventory-before.out" |
| 338 | def inventoryAfterFilename = "reclass-inventory-after.out" |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 339 | workspace = common.getWorkspace() |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 340 | targetMcpVersion = null |
| 341 | if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) { |
| 342 | error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable') |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 343 | } |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 344 | // bw comp. for 2018.X => 2018.11 release |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 345 | if (common.validInputParam('MCP_VERSION')) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 346 | targetMcpVersion = env.MCP_VERSION |
| 347 | 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] | 348 | } else { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 349 | targetMcpVersion = env.TARGET_MCP_VERSION |
| 350 | } |
| 351 | // end bw comp. for 2018.X => 2018.11 release |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 352 | def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC') |
Ivan Berezovskiy | db32509 | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 353 | if (targetMcpVersion in ['nightly', 'testing']) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 354 | gitTargetMcpVersion = 'master' |
Ivan Berezovskiy | db32509 | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 355 | } else if (targetMcpVersion == 'proposed') { |
| 356 | gitTargetMcpVersion = 'proposed' |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 357 | } else if (!gitTargetMcpVersion) { |
| 358 | // backward compatibility for 2018.11.0 |
| 359 | gitTargetMcpVersion = "release/${targetMcpVersion}" |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 360 | } |
Ivan Berezovskiy | db32509 | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 361 | common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}") |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 362 | def saltMastURL = '' |
| 363 | def saltMastCreds = '' |
| 364 | def upgradeSaltStack = '' |
| 365 | def updateClusterModel = '' |
| 366 | def updatePipelines = '' |
| 367 | def updateLocalRepos = '' |
| 368 | def reclassSystemBranch = '' |
Denis Egorenko | 517e06c | 2019-03-29 13:24:15 +0400 | [diff] [blame] | 369 | def reclassSystemBranchDefault = gitTargetMcpVersion |
Denis Egorenko | ca6aeca | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 370 | def batchSize = '' |
Denis Egorenko | 517e06c | 2019-03-29 13:24:15 +0400 | [diff] [blame] | 371 | if (gitTargetMcpVersion != 'proposed') { |
| 372 | reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}" |
| 373 | } |
Hanna Arhipova | d5eec4c | 2019-09-06 17:55:40 +0300 | [diff] [blame] | 374 | def driveTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS') |
| 375 | if (driveTrainParamsYaml) { |
| 376 | def driveTrainParams = readYaml text: driveTrainParamsYaml |
| 377 | saltMastURL = driveTrainParams.get('SALT_MASTER_URL') |
| 378 | saltMastCreds = driveTrainParams.get('SALT_MASTER_CREDENTIALS') |
| 379 | upgradeSaltStack = driveTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean() |
| 380 | updateClusterModel = driveTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean() |
| 381 | updatePipelines = driveTrainParams.get('UPDATE_PIPELINES', false).toBoolean() |
| 382 | updateLocalRepos = driveTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean() |
| 383 | reclassSystemBranch = driveTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault) |
Denis Egorenko | ca6aeca | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 384 | batchSize = driveTrainParams.get('BATCH_SIZE', '') |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 385 | } else { |
| 386 | // backward compatibility for 2018.11.0 |
| 387 | saltMastURL = env.getProperty('SALT_MASTER_URL') |
| 388 | saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS') |
Denis Egorenko | e5f3914 | 2018-12-28 12:30:48 +0400 | [diff] [blame] | 389 | upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean() |
| 390 | updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean() |
| 391 | updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean() |
| 392 | updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean() |
Denis Egorenko | 517e06c | 2019-03-29 13:24:15 +0400 | [diff] [blame] | 393 | reclassSystemBranch = reclassSystemBranchDefault |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 394 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 395 | python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 396 | def minions = salt.getMinions(venvPepper, '*') |
Denis Egorenko | fbcee41 | 2019-04-19 15:05:18 +0400 | [diff] [blame] | 397 | def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0] |
| 398 | if (cluster_name == '' || cluster_name == 'null' || cluster_name == null) { |
| 399 | error('Pillar data is broken for Salt master node! Please check it manually and re-run pipeline.') |
| 400 | } |
Hanna Arhipova | d5eec4c | 2019-09-06 17:55:40 +0300 | [diff] [blame] | 401 | if (!batchSize) { |
Denis Egorenko | 20a4346 | 2019-09-24 14:55:50 +0400 | [diff] [blame] | 402 | batchSize = getWorkerThreads(venvPepper) |
Denis Egorenko | ca6aeca | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 403 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 404 | |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 405 | stage('Update Reclass and Salt-Formulas') { |
| 406 | common.infoMsg('Perform: Full salt sync') |
| 407 | salt.fullRefresh(venvPepper, '*') |
| 408 | common.infoMsg('Perform: Validate reclass medata before processing') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 409 | validateReclassModel(minions, 'before') |
| 410 | |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 411 | common.infoMsg('Perform: archiveReclassInventory before upgrade') |
| 412 | archiveReclassInventory(inventoryBeforeFilename) |
| 413 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 414 | try { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 415 | 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] | 416 | } |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 417 | catch (Exception ex) { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 418 | 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] | 419 | } |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 420 | checkDebsums() |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 421 | if (updateClusterModel) { |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 422 | common.infoMsg('Perform: UPDATE_CLUSTER_MODEL') |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 423 | def dateTime = common.getDatetime() |
Denis Egorenko | 20254e7 | 2019-03-18 15:47:33 +0400 | [diff] [blame] | 424 | 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] | 425 | 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] | 426 | "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] | 427 | // Do the same, for deprecated variable-duplicate |
| 428 | 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] | 429 | "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] | 430 | 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] | 431 | "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] | 432 | // Set new k8s param |
| 433 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 434 | "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] | 435 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 436 | "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'") |
| 437 | 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] | 438 | "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] | 439 | 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] | 440 | "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] | 441 | 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] | 442 | "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] | 443 | |
Denis Egorenko | 6f07b59 | 2019-09-16 16:41:26 +0400 | [diff] [blame] | 444 | 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") |
| 445 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name/infra && sed -i '/maas_region_main_archive/d' maas.yml") |
| 446 | |
Denis Egorenko | 21c78be | 2019-07-10 19:47:39 +0400 | [diff] [blame] | 447 | // Switch Jenkins/Gerrit to use LDAP SSL/TLS |
| 448 | def gerritldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 449 | "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() |
| 450 | if (gerritldapURI.startsWith('ldap://')) { |
| 451 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 452 | "grep -r --exclude-dir=aptly -l 'gerrit_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'") |
| 453 | } else if (! gerritldapURI.startsWith('ldaps://')) { |
| 454 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 455 | "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'") |
| 456 | } |
| 457 | def jenkinsldapURI = salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 458 | "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() |
| 459 | if (jenkinsldapURI.startsWith('ldap://')) { |
| 460 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 461 | "grep -r --exclude-dir=aptly -l 'jenkins_security_ldap_server: .*' * | xargs --no-run-if-empty sed -i 's|ldap://|ldaps://|g'") |
| 462 | } else if (! jenkinsldapURI.startsWith('ldaps://')) { |
| 463 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 464 | "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'") |
| 465 | } |
| 466 | |
Denis Egorenko | 1b11d23 | 2019-07-29 17:44:46 +0400 | [diff] [blame] | 467 | wa32284(cluster_name) |
| 468 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 469 | 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] | 470 | // Add kubernetes-extra repo |
| 471 | if (salt.testTarget(venvPepper, "I@kubernetes:master")) { |
Sergey Kolekonov | 3fde8b1 | 2019-04-11 16:33:54 +0400 | [diff] [blame] | 472 | // docker-engine conflicts with the recent containerd versions, so it's removed during upgrade. Thus update source engine |
| 473 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 474 | "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] | 475 | common.infoMsg("Add kubernetes-extra repo") |
| 476 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 477 | "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") |
| 478 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 479 | "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") |
| 480 | } |
Ivan Berezovskiy | 41c7679 | 2019-04-15 13:23:58 +0400 | [diff] [blame] | 481 | // Add all update repositories |
| 482 | def repoIncludeBase = '- system.linux.system.repo.mcp.apt_mirantis.' |
Denis Egorenko | 6f07b59 | 2019-09-16 16:41:26 +0400 | [diff] [blame] | 483 | 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] | 484 | updateRepoList.each { repo -> |
| 485 | def repoNameUpdateInclude = "${repoIncludeBase}update.${repo}" |
| 486 | 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') |
| 487 | filesWithInclude.each { file -> |
| 488 | 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() |
| 489 | if (updateRepoIncludeExist == 'not_found') { |
| 490 | // Include needs to be added |
| 491 | 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] | 492 | "sed -i 's/\\( *\\)${repoIncludeBase}${repo}\$/&\\n\\1${repoNameUpdateInclude}/g' ${file}") |
Ivan Berezovskiy | 41c7679 | 2019-04-15 13:23:58 +0400 | [diff] [blame] | 493 | common.infoMsg("Update repo for ${repo} is added to ${file}") |
| 494 | } |
| 495 | } |
| 496 | } |
Denis Egorenko | af18b25 | 2019-09-02 14:53:02 +0400 | [diff] [blame] | 497 | wa32182(cluster_name) |
Denis Egorenko | e312cc9 | 2019-10-18 17:06:11 +0400 | [diff] [blame] | 498 | wa33771(cluster_name) |
Denis Egorenko | ba63133 | 2019-10-25 13:13:39 +0400 | [diff] [blame] | 499 | wa33867(cluster_name) |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 500 | // Add new defaults |
| 501 | common.infoMsg("Add new defaults") |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 502 | 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] | 503 | "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] | 504 | 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] | 505 | "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] | 506 | 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] | 507 | "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] | 508 | 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] | 509 | "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] | 510 | 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] | 511 | "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] | 512 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff") |
| 513 | 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] | 514 | "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] | 515 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 516 | try { |
| 517 | common.infoMsg('Perform: UPDATE Salt Formulas') |
azvyagintsev | ca97a11 | 2019-04-22 17:53:40 +0300 | [diff] [blame] | 518 | salt.fullRefresh(venvPepper, '*') |
Denis Egorenko | ea0ba7d | 2019-07-04 14:16:40 +0400 | [diff] [blame] | 519 | 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] | 520 | 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] | 521 | 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] | 522 | salt.fullRefresh(venvPepper, '*') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 523 | } catch (Exception updateErr) { |
| 524 | common.warningMsg(updateErr) |
| 525 | common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.') |
| 526 | input message: 'Continue anyway?' |
| 527 | } |
| 528 | |
azvyagintsev | 745a6e5 | 2019-04-18 13:19:39 +0300 | [diff] [blame] | 529 | wa29352(minions, cluster_name) |
Denis Egorenko | 14fa6e1 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 530 | def computeMinions = salt.getMinions(venvPepper, 'I@nova:compute') |
| 531 | wa29155(computeMinions, cluster_name) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 532 | |
| 533 | try { |
| 534 | common.infoMsg('Perform: UPDATE Reclass package') |
| 535 | salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"]) |
| 536 | } catch (Exception updateErr) { |
| 537 | common.warningMsg(updateErr) |
| 538 | common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.') |
| 539 | input message: 'Continue anyway?' |
| 540 | } |
| 541 | |
| 542 | salt.fullRefresh(venvPepper, 'I@salt:master') |
Denis Egorenko | ea0ba7d | 2019-07-04 14:16:40 +0400 | [diff] [blame] | 543 | salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true, true, null, false, 60, 2) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 544 | try { |
Denis Egorenko | ea0ba7d | 2019-07-04 14:16:40 +0400 | [diff] [blame] | 545 | 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] | 546 | } |
| 547 | catch (Exception ex) { |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 548 | common.errorMsg(ex.toString()) |
| 549 | error('Reclass fails rendering. Pay attention to your cluster model.') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | salt.fullRefresh(venvPepper, '*') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 553 | try { |
| 554 | salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top") |
| 555 | } |
| 556 | catch (Exception ex) { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 557 | |
| 558 | error('Reclass fails rendering. Pay attention to your cluster model.' + |
| 559 | 'ErrorMessage:' + ex.toString()) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 560 | } |
| 561 | |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 562 | common.infoMsg('Perform: archiveReclassInventory AFTER upgrade') |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 563 | archiveReclassInventory(inventoryAfterFilename) |
| 564 | |
| 565 | sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true" |
| 566 | archiveArtifacts artifacts: "reclass-inventory-diff.out" |
| 567 | |
| 568 | validateReclassModel(minions, 'after') |
| 569 | archiveReclassModelChanges(minions) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 570 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 571 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 572 | if (updateLocalRepos) { |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 573 | stage("Update local repos") { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 574 | common.infoMsg("Updating local repositories") |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 575 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 576 | def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine") |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 577 | runningOnDocker = engine.get("return")[0].containsValue("docker") |
| 578 | |
| 579 | if (runningOnDocker) { |
| 580 | common.infoMsg("Aptly is running as Docker container") |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 581 | } else { |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 582 | common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands") |
| 583 | } |
| 584 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 585 | if (runningOnDocker) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 586 | 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] | 587 | } else { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 588 | 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] | 589 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 590 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 591 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 592 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 593 | if (runningOnDocker) { |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 594 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true) |
| 595 | 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] | 596 | } else { |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 597 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true) |
| 598 | 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] | 599 | } |
Richard Felkl | 79d7df1 | 2018-01-05 16:40:11 +0100 | [diff] [blame] | 600 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 601 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 602 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 603 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 604 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 605 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true) |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 606 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 607 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 608 | } |
| 609 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 610 | |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 611 | stage('Update Drivetrain') { |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 612 | if (upgradeSaltStack) { |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 613 | updateSaltStack('I@salt:master', '["salt-master", "salt-common", "salt-api", "salt-minion"]') |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 614 | |
Denis Egorenko | ca6aeca | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 615 | 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] | 616 | updateSaltStack('I@salt:minion and not I@salt:master', '["salt-minion"]') |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 617 | } |
| 618 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 619 | if (updatePipelines) { |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 620 | common.infoMsg('Perform: UPDATE git repos') |
| 621 | triggerMirrorJob('git-mirror-downstream-mk-pipelines', reclassSystemBranch) |
| 622 | triggerMirrorJob('git-mirror-downstream-pipeline-library', reclassSystemBranch) |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 623 | } |
| 624 | |
Denis Egorenko | 7a4cf03 | 2019-04-25 20:48:26 +0400 | [diff] [blame] | 625 | // update minions certs |
Denis Egorenko | af3a220 | 2019-04-26 15:13:16 +0400 | [diff] [blame] | 626 | // call for `salt.minion.ca` state on related nodes to make sure |
| 627 | // 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] | 628 | salt.enforceState(venvPepper, 'I@salt:minion:ca', 'salt.minion.ca', true, true, batchSize, false, 60, 2) |
| 629 | 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] | 630 | |
Ann Kamyshnikova | e891011 | 2019-05-06 12:56:38 +0400 | [diff] [blame] | 631 | // run `salt.minion` to refresh all minion configs (for example _keystone.conf) |
Denis Egorenko | ea0ba7d | 2019-07-04 14:16:40 +0400 | [diff] [blame] | 632 | salt.enforceState(venvPepper, 'I@salt:minion', 'salt.minion', true, true, null, false, 60, 2) |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 633 | // Retry needed only for rare race-condition in user appearance |
| 634 | common.infoMsg('Perform: updating users and keys') |
Denis Egorenko | ca6aeca | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 635 | 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] | 636 | common.infoMsg('Perform: updating openssh') |
Denis Egorenko | ca6aeca | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 637 | 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] | 638 | |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 639 | // apply salt API TLS if needed |
| 640 | def nginxAtMaster = salt.getPillar(venvPepper, 'I@salt:master', 'nginx:server:enabled').get('return')[0].values()[0] |
| 641 | if (nginxAtMaster.toString().toLowerCase() == 'true') { |
Denis Egorenko | ea0ba7d | 2019-07-04 14:16:40 +0400 | [diff] [blame] | 642 | salt.enforceState(venvPepper, 'I@salt:master', 'nginx', true, true, null, false, 60, 2) |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 643 | } |
| 644 | |
Denis Egorenko | bc44032 | 2019-07-09 18:55:35 +0400 | [diff] [blame] | 645 | // Apply changes for HaProxy on CI/CD nodes |
| 646 | salt.enforceState(venvPepper, 'I@keepalived:cluster:instance:cicd_control_vip and I@haproxy:proxy', 'haproxy.proxy', true) |
| 647 | |
Denis Egorenko | 579f184 | 2019-10-30 13:26:59 +0400 | [diff] [blame] | 648 | // 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 |
| 649 | def gerritGlusterPath = salt.getPillar(venvPepper, 'I@gerrit:client', 'glusterfs:client:volumes:gerrit:path').get('return')[0].values()[0] |
| 650 | def wrongPluginJarName = "${gerritGlusterPath}/plugins/project-download-commands.jar" |
| 651 | salt.cmdRun(venvPepper, 'I@gerrit:client', "test -f ${wrongPluginJarName} && rm ${wrongPluginJarName}") |
| 652 | |
Denis Egorenko | 21c78be | 2019-07-10 19:47:39 +0400 | [diff] [blame] | 653 | 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] | 654 | |
| 655 | sleep(180) |
| 656 | |
azvyagintsev | bc359d4 | 2019-04-10 19:53:22 +0300 | [diff] [blame] | 657 | common.infoMsg('Perform: Checking if Docker containers are up') |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 658 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 659 | try { |
azvyagintsev | 97fd5ae | 2019-06-03 19:09:43 +0300 | [diff] [blame] | 660 | common.retry(20, 30) { |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 661 | salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'") |
| 662 | } |
| 663 | } |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 664 | catch (Exception ex) { |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 665 | error("Docker containers for CI/CD services are having troubles with starting.") |
| 666 | } |
Denis Egorenko | 21c78be | 2019-07-10 19:47:39 +0400 | [diff] [blame] | 667 | |
| 668 | 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] | 669 | |
| 670 | // update Nginx proxy settings for Jenkins/Gerrit if needed |
| 671 | if (salt.testTarget(venvPepper, 'I@nginx:server:site:nginx_proxy_jenkins and I@nginx:server:site:nginx_proxy_gerrit')) { |
| 672 | 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) |
| 673 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 674 | } |
| 675 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 676 | catch (Throwable e) { |
| 677 | // If there was an error or exception thrown, the build failed |
| 678 | currentBuild.result = "FAILURE" |
| 679 | throw e |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 680 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 681 | } |
Jakub Josef | 2c21c6c | 2018-02-08 18:51:42 +0100 | [diff] [blame] | 682 | } |