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 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 25 | def triggerMirrorJob(jobName) { |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 26 | params = jenkinsUtils.getJobParameters(jobName) |
| 27 | build job: jobName, parameters: [ |
| 28 | [$class: 'StringParameterValue', name: 'BRANCHES', value: params.get("BRANCHES")], |
| 29 | [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: params.get("CREDENTIALS_ID")], |
| 30 | [$class: 'StringParameterValue', name: 'SOURCE_URL', value: params.get("SOURCE_URL")], |
| 31 | [$class: 'StringParameterValue', name: 'TARGET_URL', value: params.get("TARGET_URL")] |
| 32 | ] |
| 33 | } |
| 34 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 35 | def updateSaltStack(target, pkgs) { |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 36 | // wait 2 mins when salt-* packages are updated which leads to salt-* services restart |
| 37 | common.retry(2, 120) { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 38 | salt.runSaltProcessStep(venvPepper, target, 'pkg.install', ["force_yes=True", "pkgs='$pkgs'"], null, true, 5) |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 39 | } |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 40 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 41 | common.retry(20, 60) { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 42 | salt.minionsReachable(venvPepper, 'I@salt:master', '*') |
| 43 | def running = salt.runSaltProcessStep(venvPepper, target, 'saltutil.running', [], null, true, 5) |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 44 | for (value in running.get("return")[0].values()) { |
| 45 | if (value != []) { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 46 | throw new Exception("Not all salt-minions are ready for execution") |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 51 | 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] | 52 | 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] | 53 | def saltMinionVersion = "" |
| 54 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 55 | for (minion in saltMinionVersions[0].keySet()) { |
| 56 | saltMinionVersion = saltMinionVersions[0].get(minion).replace("Salt command execution success", "").trim() |
| 57 | if (saltMinionVersion == "") { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 58 | error("Installed version of Salt on $minion doesn't match specified version in the model.") |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 63 | def archiveReclassInventory(filename) { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 64 | def ret = salt.cmdRun(venvPepper, 'I@salt:master', "reclass -i", true, null, false) |
| 65 | def reclassInv = ret.values()[0] |
| 66 | writeFile file: filename, text: reclassInv.toString() |
| 67 | archiveArtifacts artifacts: "$filename" |
| 68 | } |
| 69 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 70 | def validateReclassModel(ArrayList saltMinions, String suffix) { |
| 71 | try { |
| 72 | for(String minion in saltMinions) { |
| 73 | common.infoMsg("Reclass model validation for minion ${minion}...") |
| 74 | def ret = salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false) |
| 75 | def reclassInv = ret.values()[0] |
| 76 | writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString() |
| 77 | } |
| 78 | } catch (Exception e) { |
| 79 | common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.') |
| 80 | error(e) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix='before', String newSuffix='after') { |
| 85 | for(String minion in saltMinions) { |
| 86 | def fileName = "reclass-model-${minion}-diff.out" |
| 87 | sh "diff -u inventory-${minion}-${oldSuffix}.out inventory-${minion}-${newSuffix}.out > ${fileName} || true" |
| 88 | archiveArtifacts artifacts: "${fileName}" |
| 89 | } |
| 90 | } |
| 91 | |
Denis Egorenko | 5a8a7e9 | 2018-12-27 14:13:48 +0400 | [diff] [blame] | 92 | if (common.validInputParam('PIPELINE_TIMEOUT')) { |
| 93 | try { |
| 94 | pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger() |
| 95 | } catch(Exception e) { |
| 96 | common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger") |
| 97 | } |
Martin Polreich | 965c903 | 2018-08-09 16:33:57 +0200 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | timeout(time: pipelineTimeout, unit: 'HOURS') { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 101 | node("python") { |
| 102 | try { |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 103 | workspace = common.getWorkspace() |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 104 | targetMcpVersion = null |
| 105 | if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) { |
| 106 | error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable') |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 107 | } |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 108 | // bw comp. for 2018.X => 2018.11 release |
| 109 | if (common.validInputParam('MCP_VERSION')){ |
| 110 | targetMcpVersion = env.MCP_VERSION |
| 111 | common.warningMsg("targetMcpVersion has been changed to:${targetMcpVersion}, which was taken from deprecated pipeline viriable:MCP_VERSION") |
| 112 | } |
| 113 | else { |
| 114 | targetMcpVersion = env.TARGET_MCP_VERSION |
| 115 | } |
| 116 | // end bw comp. for 2018.X => 2018.11 release |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 117 | def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC') |
Ivan Berezovskiy | d62629c | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 118 | if (targetMcpVersion in ['nightly', 'testing']) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 119 | gitTargetMcpVersion = 'master' |
Ivan Berezovskiy | d62629c | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 120 | } else if (targetMcpVersion == 'proposed') { |
| 121 | gitTargetMcpVersion = 'proposed' |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 122 | } else if (!gitTargetMcpVersion) { |
| 123 | // backward compatibility for 2018.11.0 |
| 124 | gitTargetMcpVersion = "release/${targetMcpVersion}" |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 125 | } |
Ivan Berezovskiy | d62629c | 2019-01-16 19:26:18 +0400 | [diff] [blame] | 126 | common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}") |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 127 | def saltMastURL = '' |
| 128 | def saltMastCreds = '' |
| 129 | def upgradeSaltStack = '' |
| 130 | def updateClusterModel = '' |
| 131 | def updatePipelines = '' |
| 132 | def updateLocalRepos = '' |
| 133 | def reclassSystemBranch = '' |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 134 | def driteTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS') |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 135 | if (driteTrainParamsYaml) { |
| 136 | def driteTrainParams = readYaml text: driteTrainParamsYaml |
| 137 | saltMastURL = driteTrainParams.get('SALT_MASTER_URL') |
Denis Egorenko | 928b3e8 | 2019-01-15 11:47:16 +0400 | [diff] [blame] | 138 | saltMastCreds = driteTrainParams.get('SALT_MASTER_CREDENTIALS') |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 139 | upgradeSaltStack = driteTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean() |
| 140 | updateClusterModel = driteTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean() |
| 141 | updatePipelines = driteTrainParams.get('UPDATE_PIPELINES', false).toBoolean() |
| 142 | updateLocalRepos = driteTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean() |
| 143 | reclassSystemBranch = driteTrainParams.get('RECLASS_SYSTEM_BRANCH', gitTargetMcpVersion) |
| 144 | } else { |
| 145 | // backward compatibility for 2018.11.0 |
| 146 | saltMastURL = env.getProperty('SALT_MASTER_URL') |
| 147 | saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS') |
Denis Egorenko | e5f3914 | 2018-12-28 12:30:48 +0400 | [diff] [blame] | 148 | upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean() |
| 149 | updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean() |
| 150 | updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean() |
| 151 | updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean() |
Denis Egorenko | 284690e | 2018-12-25 15:55:12 +0400 | [diff] [blame] | 152 | reclassSystemBranch = gitTargetMcpVersion |
| 153 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 154 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 155 | python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds) |
| 156 | |
| 157 | def inventoryBeforeFilename = "reclass-inventory-before.out" |
| 158 | def inventoryAfterFilename = "reclass-inventory-after.out" |
| 159 | |
| 160 | def minions = salt.getMinions(venvPepper, '*') |
| 161 | |
| 162 | stage("Update Reclass and Salt-Formulas ") { |
| 163 | validateReclassModel(minions, 'before') |
| 164 | |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 165 | def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0] |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 166 | try { |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 167 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/ && git diff-index --quiet HEAD --") |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 168 | } |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 169 | catch (Exception ex) { |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 170 | error("You have uncommited 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] | 171 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 172 | if (updateClusterModel) { |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 173 | common.infoMsg('Perform: UPDATE_CLUSTER_MODEL') |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 174 | def dateTime = common.getDatetime() |
| 175 | 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] | 176 | "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] | 177 | // Do the same, for deprecated variable-duplicate |
| 178 | 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] | 179 | "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] | 180 | 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] | 181 | "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] | 182 | // Set new k8s param |
| 183 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 184 | "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^] | 185 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 186 | "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'") |
| 187 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 188 | "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.salt/system.linux.system.repo.mcp.apt_mirantis.contrail/g'") |
| 189 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " + |
| 190 | "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.salt/system.linux.system.repo.mcp.apt_mirantis.update/g'") |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 191 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}") |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 192 | // Add new defaults |
| 193 | common.infoMsg("Add new defaults") |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 194 | 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] | 195 | "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] | 196 | 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] | 197 | "sed -i 's|^classes:|classes:\\n- system.defaults|' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml") |
Sergey | 382581a | 2018-10-25 12:22:26 +0400 | [diff] [blame] | 198 | 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] | 199 | "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] | 200 | salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff") |
| 201 | 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] | 202 | "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] | 203 | } |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 204 | |
| 205 | try { |
| 206 | common.infoMsg('Perform: UPDATE Salt Formulas') |
| 207 | salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo') |
| 208 | def saltEnv = salt.getPillar(venvPepper, 'I@salt:master', "_param:salt_master_base_environment").get("return")[0].values()[0] |
| 209 | salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas",'salt.master.env']) |
| 210 | } catch (Exception updateErr) { |
| 211 | common.warningMsg(updateErr) |
| 212 | common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.') |
| 213 | input message: 'Continue anyway?' |
| 214 | } |
| 215 | |
| 216 | archiveReclassInventory(inventoryBeforeFilename) |
| 217 | |
| 218 | try { |
| 219 | common.infoMsg('Perform: UPDATE Reclass package') |
| 220 | salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"]) |
| 221 | } catch (Exception updateErr) { |
| 222 | common.warningMsg(updateErr) |
| 223 | common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.') |
| 224 | input message: 'Continue anyway?' |
| 225 | } |
| 226 | |
| 227 | salt.fullRefresh(venvPepper, 'I@salt:master') |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 228 | salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true) |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 229 | try { |
| 230 | salt.enforceState(venvPepper, "I@salt:master", 'reclass', true) |
| 231 | } |
| 232 | catch (Exception ex) { |
| 233 | error("Reclass fails rendering. Pay attention to your cluster model.") |
| 234 | } |
| 235 | |
| 236 | salt.fullRefresh(venvPepper, '*') |
| 237 | |
| 238 | try { |
| 239 | salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top") |
| 240 | } |
| 241 | catch (Exception ex) { |
| 242 | error("Reclass fails rendering. Pay attention to your cluster model.") |
| 243 | } |
| 244 | |
| 245 | archiveReclassInventory(inventoryAfterFilename) |
| 246 | |
| 247 | sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true" |
| 248 | archiveArtifacts artifacts: "reclass-inventory-diff.out" |
| 249 | |
| 250 | validateReclassModel(minions, 'after') |
| 251 | archiveReclassModelChanges(minions) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 252 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 253 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 254 | if (updateLocalRepos) { |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 255 | def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0] |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 256 | stage("Update local repos") { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 257 | common.infoMsg("Updating local repositories") |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 258 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 259 | def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine") |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 260 | runningOnDocker = engine.get("return")[0].containsValue("docker") |
| 261 | |
| 262 | if (runningOnDocker) { |
| 263 | common.infoMsg("Aptly is running as Docker container") |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 264 | } else { |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 265 | common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands") |
| 266 | } |
| 267 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 268 | if (runningOnDocker) { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 269 | 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] | 270 | } else { |
azvyagintsev | f3bf77a | 2018-11-15 19:30:04 +0200 | [diff] [blame] | 271 | 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] | 272 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 273 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 274 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 275 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 276 | if (runningOnDocker) { |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 277 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true) |
| 278 | 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] | 279 | } else { |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 280 | salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true) |
| 281 | 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] | 282 | } |
Richard Felkl | 79d7df1 | 2018-01-05 16:40:11 +0100 | [diff] [blame] | 283 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 284 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 285 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 286 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 287 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 288 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true) |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 289 | |
Sergey | 1b81c06 | 2018-10-16 17:10:21 +0400 | [diff] [blame] | 290 | salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 291 | } |
| 292 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 293 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 294 | stage("Update Drivetrain") { |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 295 | if (upgradeSaltStack) { |
| 296 | updateSaltStack("I@salt:master", '["salt-master", "salt-common", "salt-api", "salt-minion"]') |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 297 | |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 298 | salt.enforceState(venvPepper, "I@linux:system", 'linux.system.repo', true) |
Richard Felkl | 0e80d89 | 2018-06-20 13:44:54 +0200 | [diff] [blame] | 299 | updateSaltStack("I@salt:minion and not I@salt:master", '["salt-minion"]') |
| 300 | } |
| 301 | |
Denis Egorenko | d13ad13 | 2018-12-17 16:56:02 +0400 | [diff] [blame] | 302 | if (updatePipelines) { |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 303 | triggerMirrorJob("git-mirror-downstream-mk-pipelines") |
| 304 | triggerMirrorJob("git-mirror-downstream-pipeline-library") |
| 305 | } |
| 306 | |
Denis Egorenko | aeaa1de | 2019-01-15 11:58:12 +0400 | [diff] [blame] | 307 | // updating users and keys |
| 308 | salt.enforceState(venvPepper, "I@linux:system", 'linux.system.user', true) |
| 309 | salt.enforceState(venvPepper, "I@linux:system", 'openssh', true) |
| 310 | |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 311 | salt.enforceState(venvPepper, "I@jenkins:client", 'jenkins.client', true) |
| 312 | |
| 313 | salt.cmdRun(venvPepper, "I@salt:master", "salt -C 'I@jenkins:client and I@docker:client' state.sls docker.client --async") |
| 314 | |
| 315 | sleep(180) |
| 316 | |
| 317 | common.infoMsg("Checking if Docker containers are up") |
| 318 | |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 319 | try { |
| 320 | common.retry(10, 30) { |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 321 | salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'") |
| 322 | } |
| 323 | } |
azvyagintsev | 6dac380 | 2018-11-09 15:11:30 +0200 | [diff] [blame] | 324 | catch (Exception ex) { |
Richard Felkl | 970e008 | 2018-06-12 18:00:51 +0200 | [diff] [blame] | 325 | error("Docker containers for CI/CD services are having troubles with starting.") |
| 326 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 327 | } |
| 328 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 329 | catch (Throwable e) { |
| 330 | // If there was an error or exception thrown, the build failed |
| 331 | currentBuild.result = "FAILURE" |
| 332 | throw e |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 333 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 334 | } |
Jakub Josef | 2c21c6c | 2018-02-08 18:51:42 +0100 | [diff] [blame] | 335 | } |