blob: fa6e89e33cf48f14437546c749ded1c722afebb5 [file] [log] [blame]
Richard Felkl26cae4d2017-12-19 00:19:16 +01001/**
2 *
3 * Update Salt environment pipeline
4 *
5 * Expected parameters:
azvyagintsev6dac3802018-11-09 15:11:30 +02006 * TARGET_MCP_VERSION Version of MCP to upgrade to
Denis Egorenkod13ad132018-12-17 16:56:02 +04007 * 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 Felkl26cae4d2017-12-19 00:19:16 +010015 */
16
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010017salt = new com.mirantis.mk.Salt()
18common = new com.mirantis.mk.Common()
19python = new com.mirantis.mk.Python()
Richard Felkl970e0082018-06-12 18:00:51 +020020jenkinsUtils = new com.mirantis.mk.JenkinsUtils()
azvyagintsevf3bf77a2018-11-15 19:30:04 +020021def pipelineTimeout = 12
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010022venvPepper = "venvPepper"
Richard Felkl0e80d892018-06-20 13:44:54 +020023workspace = ""
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010024
azvyagintsev6dac3802018-11-09 15:11:30 +020025def triggerMirrorJob(jobName) {
Richard Felkl970e0082018-06-12 18:00:51 +020026 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
azvyagintsev6dac3802018-11-09 15:11:30 +020035def updateSaltStack(target, pkgs) {
Denis Egorenko0d0c65f2019-02-26 16:05:03 +040036 salt.cmdRun(venvPepper, "I@salt:master", "salt -C '${target}' --async pkg.install force_yes=True pkgs='$pkgs'")
37 // can't use same function from pipeline lib, as at the moment of running upgrade pipeline Jenkins
38 // still using pipeline lib from current old mcp-version
azvyagintsev6dac3802018-11-09 15:11:30 +020039 common.retry(20, 60) {
Richard Felkl0e80d892018-06-20 13:44:54 +020040 salt.minionsReachable(venvPepper, 'I@salt:master', '*')
41 def running = salt.runSaltProcessStep(venvPepper, target, 'saltutil.running', [], null, true, 5)
azvyagintsev6dac3802018-11-09 15:11:30 +020042 for (value in running.get("return")[0].values()) {
43 if (value != []) {
Richard Felkl0e80d892018-06-20 13:44:54 +020044 throw new Exception("Not all salt-minions are ready for execution")
45 }
46 }
47 }
48
azvyagintsevf3bf77a2018-11-15 19:30:04 +020049 def saltVersion = salt.getPillar(venvPepper, 'I@salt:master', '_param:salt_version').get('return')[0].values()[0]
Richard Felklf23257e2018-08-06 09:24:23 +020050 def saltMinionVersions = salt.cmdRun(venvPepper, target, "apt-cache policy salt-common | awk '/Installed/ && /$saltVersion/'").get("return")
Richard Felkl0e80d892018-06-20 13:44:54 +020051 def saltMinionVersion = ""
52
azvyagintsev6dac3802018-11-09 15:11:30 +020053 for (minion in saltMinionVersions[0].keySet()) {
54 saltMinionVersion = saltMinionVersions[0].get(minion).replace("Salt command execution success", "").trim()
55 if (saltMinionVersion == "") {
Richard Felkl0e80d892018-06-20 13:44:54 +020056 error("Installed version of Salt on $minion doesn't match specified version in the model.")
57 }
58 }
59}
60
azvyagintsev6dac3802018-11-09 15:11:30 +020061def archiveReclassInventory(filename) {
Richard Felkl0e80d892018-06-20 13:44:54 +020062 def ret = salt.cmdRun(venvPepper, 'I@salt:master', "reclass -i", true, null, false)
63 def reclassInv = ret.values()[0]
64 writeFile file: filename, text: reclassInv.toString()
65 archiveArtifacts artifacts: "$filename"
66}
67
Denis Egorenkod13ad132018-12-17 16:56:02 +040068def validateReclassModel(ArrayList saltMinions, String suffix) {
69 try {
70 for(String minion in saltMinions) {
71 common.infoMsg("Reclass model validation for minion ${minion}...")
72 def ret = salt.cmdRun(venvPepper, 'I@salt:master', "reclass -n ${minion}", true, null, false)
73 def reclassInv = ret.values()[0]
74 writeFile file: "inventory-${minion}-${suffix}.out", text: reclassInv.toString()
75 }
76 } catch (Exception e) {
77 common.errorMsg('Can not validate current Reclass model. Inspect failed minion manually.')
78 error(e)
79 }
80}
81
82def archiveReclassModelChanges(ArrayList saltMinions, String oldSuffix='before', String newSuffix='after') {
83 for(String minion in saltMinions) {
84 def fileName = "reclass-model-${minion}-diff.out"
85 sh "diff -u inventory-${minion}-${oldSuffix}.out inventory-${minion}-${newSuffix}.out > ${fileName} || true"
86 archiveArtifacts artifacts: "${fileName}"
87 }
88}
89
Denis Egorenko5a8a7e92018-12-27 14:13:48 +040090if (common.validInputParam('PIPELINE_TIMEOUT')) {
91 try {
92 pipelineTimeout = env.PIPELINE_TIMEOUT.toInteger()
93 } catch(Exception e) {
94 common.warningMsg("Provided PIPELINE_TIMEOUT parameter has invalid value: ${env.PIPELINE_TIMEOUT} - should be interger")
95 }
Martin Polreich965c9032018-08-09 16:33:57 +020096}
97
98timeout(time: pipelineTimeout, unit: 'HOURS') {
Jakub Josefa63f9862018-01-11 17:58:38 +010099 node("python") {
100 try {
Richard Felkl0e80d892018-06-20 13:44:54 +0200101 workspace = common.getWorkspace()
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200102 targetMcpVersion = null
103 if (!common.validInputParam('TARGET_MCP_VERSION') && !common.validInputParam('MCP_VERSION')) {
104 error('You must specify MCP version in TARGET_MCP_VERSION|MCP_VERSION variable')
azvyagintsev6dac3802018-11-09 15:11:30 +0200105 }
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200106 // bw comp. for 2018.X => 2018.11 release
107 if (common.validInputParam('MCP_VERSION')){
108 targetMcpVersion = env.MCP_VERSION
109 common.warningMsg("targetMcpVersion has been changed to:${targetMcpVersion}, which was taken from deprecated pipeline viriable:MCP_VERSION")
110 }
111 else {
112 targetMcpVersion = env.TARGET_MCP_VERSION
113 }
114 // end bw comp. for 2018.X => 2018.11 release
Denis Egorenkod13ad132018-12-17 16:56:02 +0400115 def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC')
Ivan Berezovskiyd62629c2019-01-16 19:26:18 +0400116 if (targetMcpVersion in ['nightly', 'testing']) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200117 gitTargetMcpVersion = 'master'
Ivan Berezovskiyd62629c2019-01-16 19:26:18 +0400118 } else if (targetMcpVersion == 'proposed') {
119 gitTargetMcpVersion = 'proposed'
Denis Egorenko284690e2018-12-25 15:55:12 +0400120 } else if (!gitTargetMcpVersion) {
121 // backward compatibility for 2018.11.0
122 gitTargetMcpVersion = "release/${targetMcpVersion}"
azvyagintsev6dac3802018-11-09 15:11:30 +0200123 }
Ivan Berezovskiyd62629c2019-01-16 19:26:18 +0400124 common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}")
Denis Egorenko284690e2018-12-25 15:55:12 +0400125 def saltMastURL = ''
126 def saltMastCreds = ''
127 def upgradeSaltStack = ''
128 def updateClusterModel = ''
129 def updatePipelines = ''
130 def updateLocalRepos = ''
131 def reclassSystemBranch = ''
Denis Egorenkob559e542019-03-29 13:24:15 +0400132 def reclassSystemBranchDefault = gitTargetMcpVersion
133 if (gitTargetMcpVersion != 'proposed') {
134 reclassSystemBranchDefault = "origin/${gitTargetMcpVersion}"
135 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400136 def driteTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS')
Denis Egorenko284690e2018-12-25 15:55:12 +0400137 if (driteTrainParamsYaml) {
138 def driteTrainParams = readYaml text: driteTrainParamsYaml
139 saltMastURL = driteTrainParams.get('SALT_MASTER_URL')
Denis Egorenko928b3e82019-01-15 11:47:16 +0400140 saltMastCreds = driteTrainParams.get('SALT_MASTER_CREDENTIALS')
Denis Egorenko284690e2018-12-25 15:55:12 +0400141 upgradeSaltStack = driteTrainParams.get('UPGRADE_SALTSTACK', false).toBoolean()
142 updateClusterModel = driteTrainParams.get('UPDATE_CLUSTER_MODEL', false).toBoolean()
143 updatePipelines = driteTrainParams.get('UPDATE_PIPELINES', false).toBoolean()
144 updateLocalRepos = driteTrainParams.get('UPDATE_LOCAL_REPOS', false).toBoolean()
Denis Egorenkob559e542019-03-29 13:24:15 +0400145 reclassSystemBranch = driteTrainParams.get('RECLASS_SYSTEM_BRANCH', reclassSystemBranchDefault)
Denis Egorenko284690e2018-12-25 15:55:12 +0400146 } else {
147 // backward compatibility for 2018.11.0
148 saltMastURL = env.getProperty('SALT_MASTER_URL')
149 saltMastCreds = env.getProperty('SALT_MASTER_CREDENTIALS')
Denis Egorenkoe5f39142018-12-28 12:30:48 +0400150 upgradeSaltStack = env.getProperty('UPGRADE_SALTSTACK').toBoolean()
151 updateClusterModel = env.getProperty('UPDATE_CLUSTER_MODEL').toBoolean()
152 updatePipelines = env.getProperty('UPDATE_PIPELINES').toBoolean()
153 updateLocalRepos = env.getProperty('UPDATE_LOCAL_REPOS').toBoolean()
Denis Egorenkob559e542019-03-29 13:24:15 +0400154 reclassSystemBranch = reclassSystemBranchDefault
Denis Egorenko284690e2018-12-25 15:55:12 +0400155 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100156
Denis Egorenkod13ad132018-12-17 16:56:02 +0400157 python.setupPepperVirtualenv(venvPepper, saltMastURL, saltMastCreds)
158
159 def inventoryBeforeFilename = "reclass-inventory-before.out"
160 def inventoryAfterFilename = "reclass-inventory-after.out"
161
162 def minions = salt.getMinions(venvPepper, '*')
163
164 stage("Update Reclass and Salt-Formulas ") {
165 validateReclassModel(minions, 'before')
166
Richard Felkl970e0082018-06-12 18:00:51 +0200167 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
azvyagintsev6dac3802018-11-09 15:11:30 +0200168 try {
Sergey382581a2018-10-25 12:22:26 +0400169 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/ && git diff-index --quiet HEAD --")
Richard Felkl970e0082018-06-12 18:00:51 +0200170 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200171 catch (Exception ex) {
Sergey382581a2018-10-25 12:22:26 +0400172 error("You have uncommited changes in your Reclass cluster model repository. Please commit or reset them and rerun the pipeline.")
Richard Felkl970e0082018-06-12 18:00:51 +0200173 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400174 if (updateClusterModel) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200175 common.infoMsg('Perform: UPDATE_CLUSTER_MODEL')
Sergey382581a2018-10-25 12:22:26 +0400176 def dateTime = common.getDatetime()
Denis Egorenko00897c52019-03-18 15:47:33 +0400177 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/ && git submodule foreach git fetch")
Sergey382581a2018-10-25 12:22:26 +0400178 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400179 "grep -r --exclude-dir=aptly -l 'mcp_version: .*' * | xargs --no-run-if-empty sed -i 's|mcp_version: .*|mcp_version: \"$targetMcpVersion\"|g'")
azvyagintsev6dac3802018-11-09 15:11:30 +0200180 // Do the same, for deprecated variable-duplicate
181 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400182 "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 Egorenko284690e2018-12-25 15:55:12 +0400183 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400184 "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 Ryzhenkin202c5062019-01-15 19:58:03 +0400185 // Set new k8s param
186 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
187 "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 Egorenko2a39d2c2019-01-16 19:18:31 +0400188 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
189 "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'")
190 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoca871c22019-02-13 13:49:13 +0400191 "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 Egorenko2a39d2c2019-01-16 19:18:31 +0400192 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkoca871c22019-02-13 13:49:13 +0400193 "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 Samoylov72c2ccf2019-02-13 15:57:13 +0400194 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
195 "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 Egorenkod13ad132018-12-17 16:56:02 +0400196 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}")
Sergey Kolekonov6ab15112019-01-23 16:47:43 +0400197 // Add kubernetes-extra repo
198 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
199 common.infoMsg("Add kubernetes-extra repo")
200 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
201 "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")
202 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
203 "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")
204 }
Sergey382581a2018-10-25 12:22:26 +0400205 // Add new defaults
206 common.infoMsg("Add new defaults")
Denis Egorenkod13ad132018-12-17 16:56:02 +0400207 salt.cmdRun(venvPepper, 'I@salt:master', "grep '^ mcp_version: ' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400208 "sed -i 's|^ _param:| _param:\\n mcp_version: \"$targetMcpVersion\"|' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml")
Sergey382581a2018-10-25 12:22:26 +0400209 salt.cmdRun(venvPepper, 'I@salt:master', "grep '^- system.defaults\$' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400210 "sed -i 's|^classes:|classes:\\n- system.defaults|' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml")
Sergey382581a2018-10-25 12:22:26 +0400211 common.infoMsg("The following changes were made to the cluster model and will be commited. " +
azvyagintsev6dac3802018-11-09 15:11:30 +0200212 "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.")
Sergey382581a2018-10-25 12:22:26 +0400213 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff")
214 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " +
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200215 "git add -u && git commit --allow-empty -m 'Cluster model update to the release $targetMcpVersion on $dateTime'")
Sergey382581a2018-10-25 12:22:26 +0400216 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400217
218 try {
219 common.infoMsg('Perform: UPDATE Salt Formulas')
220 salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo')
221 def saltEnv = salt.getPillar(venvPepper, 'I@salt:master', "_param:salt_master_base_environment").get("return")[0].values()[0]
222 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas",'salt.master.env'])
223 } catch (Exception updateErr) {
224 common.warningMsg(updateErr)
225 common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
226 input message: 'Continue anyway?'
227 }
228
229 archiveReclassInventory(inventoryBeforeFilename)
230
231 try {
232 common.infoMsg('Perform: UPDATE Reclass package')
233 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"])
234 } catch (Exception updateErr) {
235 common.warningMsg(updateErr)
236 common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
237 input message: 'Continue anyway?'
238 }
239
240 salt.fullRefresh(venvPepper, 'I@salt:master')
Sergey1b81c062018-10-16 17:10:21 +0400241 salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400242 try {
243 salt.enforceState(venvPepper, "I@salt:master", 'reclass', true)
244 }
245 catch (Exception ex) {
246 error("Reclass fails rendering. Pay attention to your cluster model.")
247 }
248
249 salt.fullRefresh(venvPepper, '*')
250
251 try {
252 salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top")
253 }
254 catch (Exception ex) {
255 error("Reclass fails rendering. Pay attention to your cluster model.")
256 }
257
258 archiveReclassInventory(inventoryAfterFilename)
259
260 sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true"
261 archiveArtifacts artifacts: "reclass-inventory-diff.out"
262
263 validateReclassModel(minions, 'after')
264 archiveReclassModelChanges(minions)
Jakub Josefa63f9862018-01-11 17:58:38 +0100265 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100266
Denis Egorenkod13ad132018-12-17 16:56:02 +0400267 if (updateLocalRepos) {
Sergey1b81c062018-10-16 17:10:21 +0400268 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
azvyagintsev6dac3802018-11-09 15:11:30 +0200269 stage("Update local repos") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100270 common.infoMsg("Updating local repositories")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700271
Sergey1b81c062018-10-16 17:10:21 +0400272 def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700273 runningOnDocker = engine.get("return")[0].containsValue("docker")
274
275 if (runningOnDocker) {
276 common.infoMsg("Aptly is running as Docker container")
azvyagintsev6dac3802018-11-09 15:11:30 +0200277 } else {
Sam Stoelingaaab79702018-04-09 18:49:39 -0700278 common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands")
279 }
280
azvyagintsev6dac3802018-11-09 15:11:30 +0200281 if (runningOnDocker) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200282 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)
azvyagintsev6dac3802018-11-09 15:11:30 +0200283 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200284 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 Felkl5f7fdaf2018-02-15 15:38:31 +0100285 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100286
Sergey1b81c062018-10-16 17:10:21 +0400287 salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100288
azvyagintsev6dac3802018-11-09 15:11:30 +0200289 if (runningOnDocker) {
Sergey1b81c062018-10-16 17:10:21 +0400290 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true)
291 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)
azvyagintsev6dac3802018-11-09 15:11:30 +0200292 } else {
Sergey1b81c062018-10-16 17:10:21 +0400293 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true)
294 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=-afrv", 'runas=aptly'], null, true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100295 }
Richard Felkl79d7df12018-01-05 16:40:11 +0100296
Sergey1b81c062018-10-16 17:10:21 +0400297 salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100298
Sergey1b81c062018-10-16 17:10:21 +0400299 salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100300
Sergey1b81c062018-10-16 17:10:21 +0400301 salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100302
Sergey1b81c062018-10-16 17:10:21 +0400303 salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100304 }
305 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100306
azvyagintsev6dac3802018-11-09 15:11:30 +0200307 stage("Update Drivetrain") {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400308 if (upgradeSaltStack) {
309 updateSaltStack("I@salt:master", '["salt-master", "salt-common", "salt-api", "salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200310
Richard Felkl0e80d892018-06-20 13:44:54 +0200311 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.repo', true)
Richard Felkl0e80d892018-06-20 13:44:54 +0200312 updateSaltStack("I@salt:minion and not I@salt:master", '["salt-minion"]')
313 }
314
Denis Egorenkod13ad132018-12-17 16:56:02 +0400315 if (updatePipelines) {
Richard Felkl970e0082018-06-12 18:00:51 +0200316 triggerMirrorJob("git-mirror-downstream-mk-pipelines")
317 triggerMirrorJob("git-mirror-downstream-pipeline-library")
318 }
319
Denis Egorenkoaeaa1de2019-01-15 11:58:12 +0400320 // updating users and keys
321 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.user', true)
322 salt.enforceState(venvPepper, "I@linux:system", 'openssh', true)
323
Richard Felkl970e0082018-06-12 18:00:51 +0200324 salt.enforceState(venvPepper, "I@jenkins:client", 'jenkins.client', true)
325
326 salt.cmdRun(venvPepper, "I@salt:master", "salt -C 'I@jenkins:client and I@docker:client' state.sls docker.client --async")
327
328 sleep(180)
329
330 common.infoMsg("Checking if Docker containers are up")
331
azvyagintsev6dac3802018-11-09 15:11:30 +0200332 try {
333 common.retry(10, 30) {
Richard Felkl970e0082018-06-12 18:00:51 +0200334 salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'")
335 }
336 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200337 catch (Exception ex) {
Richard Felkl970e0082018-06-12 18:00:51 +0200338 error("Docker containers for CI/CD services are having troubles with starting.")
339 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100340 }
341 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100342 catch (Throwable e) {
343 // If there was an error or exception thrown, the build failed
344 currentBuild.result = "FAILURE"
345 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +0100346 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100347 }
Jakub Josef2c21c6c2018-02-08 18:51:42 +0100348}