blob: 49f92c38e1c533c265ddf42f4ed0cb6eaa038694 [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 Egorenkod13ad132018-12-17 16:56:02 +040036 // wait 2 mins when salt-* packages are updated which leads to salt-* services restart
37 common.retry(2, 120) {
Richard Felkl0e80d892018-06-20 13:44:54 +020038 salt.runSaltProcessStep(venvPepper, target, 'pkg.install', ["force_yes=True", "pkgs='$pkgs'"], null, true, 5)
azvyagintsev6dac3802018-11-09 15:11:30 +020039 }
Richard Felkl0e80d892018-06-20 13:44:54 +020040
azvyagintsev6dac3802018-11-09 15:11:30 +020041 common.retry(20, 60) {
Richard Felkl0e80d892018-06-20 13:44:54 +020042 salt.minionsReachable(venvPepper, 'I@salt:master', '*')
43 def running = salt.runSaltProcessStep(venvPepper, target, 'saltutil.running', [], null, true, 5)
azvyagintsev6dac3802018-11-09 15:11:30 +020044 for (value in running.get("return")[0].values()) {
45 if (value != []) {
Richard Felkl0e80d892018-06-20 13:44:54 +020046 throw new Exception("Not all salt-minions are ready for execution")
47 }
48 }
49 }
50
azvyagintsevf3bf77a2018-11-15 19:30:04 +020051 def saltVersion = salt.getPillar(venvPepper, 'I@salt:master', '_param:salt_version').get('return')[0].values()[0]
Richard Felklf23257e2018-08-06 09:24:23 +020052 def saltMinionVersions = salt.cmdRun(venvPepper, target, "apt-cache policy salt-common | awk '/Installed/ && /$saltVersion/'").get("return")
Richard Felkl0e80d892018-06-20 13:44:54 +020053 def saltMinionVersion = ""
54
azvyagintsev6dac3802018-11-09 15:11:30 +020055 for (minion in saltMinionVersions[0].keySet()) {
56 saltMinionVersion = saltMinionVersions[0].get(minion).replace("Salt command execution success", "").trim()
57 if (saltMinionVersion == "") {
Richard Felkl0e80d892018-06-20 13:44:54 +020058 error("Installed version of Salt on $minion doesn't match specified version in the model.")
59 }
60 }
61}
62
azvyagintsev6dac3802018-11-09 15:11:30 +020063def archiveReclassInventory(filename) {
Richard Felkl0e80d892018-06-20 13:44:54 +020064 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 Egorenkod13ad132018-12-17 16:56:02 +040070def 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
84def 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 Egorenko5a8a7e92018-12-27 14:13:48 +040092if (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 Polreich965c9032018-08-09 16:33:57 +020098}
99
100timeout(time: pipelineTimeout, unit: 'HOURS') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100101 node("python") {
102 try {
Richard Felkl0e80d892018-06-20 13:44:54 +0200103 workspace = common.getWorkspace()
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200104 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')
azvyagintsev6dac3802018-11-09 15:11:30 +0200107 }
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200108 // 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 Egorenkod13ad132018-12-17 16:56:02 +0400117 def gitTargetMcpVersion = env.getProperty('GIT_REFSPEC')
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400118 if (targetMcpVersion in ['nightly', 'testing']) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200119 gitTargetMcpVersion = 'master'
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400120 } else if (targetMcpVersion == 'proposed') {
121 gitTargetMcpVersion = 'proposed'
Denis Egorenko284690e2018-12-25 15:55:12 +0400122 } else if (!gitTargetMcpVersion) {
123 // backward compatibility for 2018.11.0
124 gitTargetMcpVersion = "release/${targetMcpVersion}"
azvyagintsev6dac3802018-11-09 15:11:30 +0200125 }
Ivan Berezovskiydb325092019-01-16 19:26:18 +0400126 common.warningMsg("gitTargetMcpVersion has been changed to:${gitTargetMcpVersion}")
Denis Egorenko284690e2018-12-25 15:55:12 +0400127 def saltMastURL = ''
128 def saltMastCreds = ''
129 def upgradeSaltStack = ''
130 def updateClusterModel = ''
131 def updatePipelines = ''
132 def updateLocalRepos = ''
133 def reclassSystemBranch = ''
Denis Egorenkod13ad132018-12-17 16:56:02 +0400134 def driteTrainParamsYaml = env.getProperty('DRIVE_TRAIN_PARAMS')
Denis Egorenko284690e2018-12-25 15:55:12 +0400135 if (driteTrainParamsYaml) {
136 def driteTrainParams = readYaml text: driteTrainParamsYaml
137 saltMastURL = driteTrainParams.get('SALT_MASTER_URL')
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400138 saltMastCreds = driteTrainParams.get('SALT_MASTER_CREDENTIALS')
Denis Egorenko284690e2018-12-25 15:55:12 +0400139 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 Egorenkoe5f39142018-12-28 12:30:48 +0400148 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 Egorenko284690e2018-12-25 15:55:12 +0400152 reclassSystemBranch = gitTargetMcpVersion
153 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100154
Denis Egorenkod13ad132018-12-17 16:56:02 +0400155 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 Felkl970e0082018-06-12 18:00:51 +0200165 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
azvyagintsev6dac3802018-11-09 15:11:30 +0200166 try {
Sergey382581a2018-10-25 12:22:26 +0400167 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/ && git diff-index --quiet HEAD --")
Richard Felkl970e0082018-06-12 18:00:51 +0200168 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200169 catch (Exception ex) {
Sergey382581a2018-10-25 12:22:26 +0400170 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 +0200171 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400172 if (updateClusterModel) {
azvyagintsev6dac3802018-11-09 15:11:30 +0200173 common.infoMsg('Perform: UPDATE_CLUSTER_MODEL')
Sergey382581a2018-10-25 12:22:26 +0400174 def dateTime = common.getDatetime()
Denis Egorenko166255c2019-01-28 17:50:38 +0400175 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/ && git submodule update")
Sergey382581a2018-10-25 12:22:26 +0400176 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400177 "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 +0200178 // Do the same, for deprecated variable-duplicate
179 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400180 "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 +0400181 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400182 "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 Ryzhenkinabbefe62019-01-15 19:58:03 +0400183 // Set new k8s param
184 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
185 "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 Egorenkoe5b49512019-01-16 19:18:31 +0400186 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
187 "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'")
188 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko301cc8a2019-02-13 13:49:13 +0400189 "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 Egorenkoe5b49512019-01-16 19:18:31 +0400190 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko301cc8a2019-02-13 13:49:13 +0400191 "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 Samoylov308c7ca2019-02-13 15:57:13 +0400192 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
193 "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 +0400194 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}")
Sergey Kolekonov5dfbf7a2019-01-23 16:47:43 +0400195 // Add kubernetes-extra repo
196 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
197 common.infoMsg("Add kubernetes-extra repo")
198 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
199 "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")
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.kubernetes_extra kubernetes/common.yml || sed -i '/classes:/ a - system.linux.system.repo.mcp.apt_mirantis.kubernetes_extra' kubernetes/common.yml")
202 }
Sergey382581a2018-10-25 12:22:26 +0400203 // Add new defaults
204 common.infoMsg("Add new defaults")
Denis Egorenkod13ad132018-12-17 16:56:02 +0400205 salt.cmdRun(venvPepper, 'I@salt:master', "grep '^ mcp_version: ' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400206 "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 +0400207 salt.cmdRun(venvPepper, 'I@salt:master', "grep '^- system.defaults\$' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml || " +
Denis Egorenkofcbc6b82019-01-15 11:47:16 +0400208 "sed -i 's|^classes:|classes:\\n- system.defaults|' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml")
Sergey382581a2018-10-25 12:22:26 +0400209 common.infoMsg("The following changes were made to the cluster model and will be commited. " +
azvyagintsev6dac3802018-11-09 15:11:30 +0200210 "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 +0400211 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff")
212 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " +
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200213 "git add -u && git commit --allow-empty -m 'Cluster model update to the release $targetMcpVersion on $dateTime'")
Sergey382581a2018-10-25 12:22:26 +0400214 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400215
216 try {
217 common.infoMsg('Perform: UPDATE Salt Formulas')
218 salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo')
219 def saltEnv = salt.getPillar(venvPepper, 'I@salt:master', "_param:salt_master_base_environment").get("return")[0].values()[0]
220 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas",'salt.master.env'])
221 } catch (Exception updateErr) {
222 common.warningMsg(updateErr)
223 common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
224 input message: 'Continue anyway?'
225 }
226
227 archiveReclassInventory(inventoryBeforeFilename)
228
229 try {
230 common.infoMsg('Perform: UPDATE Reclass package')
231 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"])
232 } catch (Exception updateErr) {
233 common.warningMsg(updateErr)
234 common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
235 input message: 'Continue anyway?'
236 }
237
238 salt.fullRefresh(venvPepper, 'I@salt:master')
Sergey1b81c062018-10-16 17:10:21 +0400239 salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400240 try {
241 salt.enforceState(venvPepper, "I@salt:master", 'reclass', true)
242 }
243 catch (Exception ex) {
244 error("Reclass fails rendering. Pay attention to your cluster model.")
245 }
246
247 salt.fullRefresh(venvPepper, '*')
248
249 try {
250 salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top")
251 }
252 catch (Exception ex) {
253 error("Reclass fails rendering. Pay attention to your cluster model.")
254 }
255
256 archiveReclassInventory(inventoryAfterFilename)
257
258 sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true"
259 archiveArtifacts artifacts: "reclass-inventory-diff.out"
260
261 validateReclassModel(minions, 'after')
262 archiveReclassModelChanges(minions)
Jakub Josefa63f9862018-01-11 17:58:38 +0100263 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100264
Denis Egorenkod13ad132018-12-17 16:56:02 +0400265 if (updateLocalRepos) {
Sergey1b81c062018-10-16 17:10:21 +0400266 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
azvyagintsev6dac3802018-11-09 15:11:30 +0200267 stage("Update local repos") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100268 common.infoMsg("Updating local repositories")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700269
Sergey1b81c062018-10-16 17:10:21 +0400270 def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700271 runningOnDocker = engine.get("return")[0].containsValue("docker")
272
273 if (runningOnDocker) {
274 common.infoMsg("Aptly is running as Docker container")
azvyagintsev6dac3802018-11-09 15:11:30 +0200275 } else {
Sam Stoelingaaab79702018-04-09 18:49:39 -0700276 common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands")
277 }
278
azvyagintsev6dac3802018-11-09 15:11:30 +0200279 if (runningOnDocker) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200280 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 +0200281 } else {
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, ['runas=aptly'])
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100283 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100284
Sergey1b81c062018-10-16 17:10:21 +0400285 salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100286
azvyagintsev6dac3802018-11-09 15:11:30 +0200287 if (runningOnDocker) {
Sergey1b81c062018-10-16 17:10:21 +0400288 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true)
289 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 +0200290 } else {
Sergey1b81c062018-10-16 17:10:21 +0400291 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true)
292 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 +0100293 }
Richard Felkl79d7df12018-01-05 16:40:11 +0100294
Sergey1b81c062018-10-16 17:10:21 +0400295 salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100296
Sergey1b81c062018-10-16 17:10:21 +0400297 salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100298
Sergey1b81c062018-10-16 17:10:21 +0400299 salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100300
Sergey1b81c062018-10-16 17:10:21 +0400301 salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100302 }
303 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100304
azvyagintsev6dac3802018-11-09 15:11:30 +0200305 stage("Update Drivetrain") {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400306 if (upgradeSaltStack) {
307 updateSaltStack("I@salt:master", '["salt-master", "salt-common", "salt-api", "salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200308
Richard Felkl0e80d892018-06-20 13:44:54 +0200309 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.repo', true)
Richard Felkl0e80d892018-06-20 13:44:54 +0200310 updateSaltStack("I@salt:minion and not I@salt:master", '["salt-minion"]')
311 }
312
Denis Egorenkod13ad132018-12-17 16:56:02 +0400313 if (updatePipelines) {
Richard Felkl970e0082018-06-12 18:00:51 +0200314 triggerMirrorJob("git-mirror-downstream-mk-pipelines")
315 triggerMirrorJob("git-mirror-downstream-pipeline-library")
316 }
317
Denis Egorenko65cf2a42019-01-15 11:58:12 +0400318 // updating users and keys
319 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.user', true)
320 salt.enforceState(venvPepper, "I@linux:system", 'openssh', true)
321
Richard Felkl970e0082018-06-12 18:00:51 +0200322 salt.enforceState(venvPepper, "I@jenkins:client", 'jenkins.client', true)
323
324 salt.cmdRun(venvPepper, "I@salt:master", "salt -C 'I@jenkins:client and I@docker:client' state.sls docker.client --async")
325
326 sleep(180)
327
328 common.infoMsg("Checking if Docker containers are up")
329
azvyagintsev6dac3802018-11-09 15:11:30 +0200330 try {
331 common.retry(10, 30) {
Richard Felkl970e0082018-06-12 18:00:51 +0200332 salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'")
333 }
334 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200335 catch (Exception ex) {
Richard Felkl970e0082018-06-12 18:00:51 +0200336 error("Docker containers for CI/CD services are having troubles with starting.")
337 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100338 }
339 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100340 catch (Throwable e) {
341 // If there was an error or exception thrown, the build failed
342 currentBuild.result = "FAILURE"
343 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +0100344 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100345 }
Jakub Josef2c21c6c2018-02-08 18:51:42 +0100346}