blob: 24ac15fdcf2a94b9a5ef9b66edc680348d315c01 [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 Berezovskiyd62629c2019-01-16 19:26:18 +0400118 if (targetMcpVersion in ['nightly', 'testing']) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200119 gitTargetMcpVersion = 'master'
Ivan Berezovskiyd62629c2019-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 Berezovskiyd62629c2019-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 Egorenko928b3e82019-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()
175 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400176 "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 +0200177 // Do the same, for deprecated variable-duplicate
178 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 '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 +0400180 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
Denis Egorenko928b3e82019-01-15 11:47:16 +0400181 "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 +0400182 // 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 Egorenko2a39d2c2019-01-16 19:18:31 +0400185 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 Egorenkod13ad132018-12-17 16:56:02 +0400191 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/system && git checkout ${reclassSystemBranch}")
Sergey Kolekonov6ab15112019-01-23 16:47:43 +0400192 // Add kubernetes-extra repo
193 if (salt.testTarget(venvPepper, "I@kubernetes:master")) {
194 common.infoMsg("Add kubernetes-extra repo")
195 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
196 "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")
197 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && " +
198 "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")
199 }
Sergey382581a2018-10-25 12:22:26 +0400200 // Add new defaults
201 common.infoMsg("Add new defaults")
Denis Egorenkod13ad132018-12-17 16:56:02 +0400202 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 +0400203 "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 +0400204 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 +0400205 "sed -i 's|^classes:|classes:\\n- system.defaults|' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml")
Sergey382581a2018-10-25 12:22:26 +0400206 common.infoMsg("The following changes were made to the cluster model and will be commited. " +
azvyagintsev6dac3802018-11-09 15:11:30 +0200207 "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 +0400208 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git diff")
209 salt.cmdRun(venvPepper, 'I@salt:master', "cd /srv/salt/reclass/classes/cluster/$cluster_name && git status && " +
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200210 "git add -u && git commit --allow-empty -m 'Cluster model update to the release $targetMcpVersion on $dateTime'")
Sergey382581a2018-10-25 12:22:26 +0400211 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400212
213 try {
214 common.infoMsg('Perform: UPDATE Salt Formulas')
215 salt.enforceState(venvPepper, 'I@salt:master', 'linux.system.repo')
216 def saltEnv = salt.getPillar(venvPepper, 'I@salt:master', "_param:salt_master_base_environment").get("return")[0].values()[0]
217 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'state.sls_id', ["salt_master_${saltEnv}_pkg_formulas",'salt.master.env'])
218 } catch (Exception updateErr) {
219 common.warningMsg(updateErr)
220 common.warningMsg('Failed to update Salt Formulas repos/packages. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
221 input message: 'Continue anyway?'
222 }
223
224 archiveReclassInventory(inventoryBeforeFilename)
225
226 try {
227 common.infoMsg('Perform: UPDATE Reclass package')
228 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'pkg.install', ["reclass"])
229 } catch (Exception updateErr) {
230 common.warningMsg(updateErr)
231 common.warningMsg('Failed to update Reclass package. Check current available documentation on https://docs.mirantis.com/mcp/latest/, how to update packages.')
232 input message: 'Continue anyway?'
233 }
234
235 salt.fullRefresh(venvPepper, 'I@salt:master')
Sergey1b81c062018-10-16 17:10:21 +0400236 salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400237 try {
238 salt.enforceState(venvPepper, "I@salt:master", 'reclass', true)
239 }
240 catch (Exception ex) {
241 error("Reclass fails rendering. Pay attention to your cluster model.")
242 }
243
244 salt.fullRefresh(venvPepper, '*')
245
246 try {
247 salt.cmdRun(venvPepper, 'I@salt:master', "reclass-salt --top")
248 }
249 catch (Exception ex) {
250 error("Reclass fails rendering. Pay attention to your cluster model.")
251 }
252
253 archiveReclassInventory(inventoryAfterFilename)
254
255 sh "diff -u $inventoryBeforeFilename $inventoryAfterFilename > reclass-inventory-diff.out || true"
256 archiveArtifacts artifacts: "reclass-inventory-diff.out"
257
258 validateReclassModel(minions, 'after')
259 archiveReclassModelChanges(minions)
Jakub Josefa63f9862018-01-11 17:58:38 +0100260 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100261
Denis Egorenkod13ad132018-12-17 16:56:02 +0400262 if (updateLocalRepos) {
Sergey1b81c062018-10-16 17:10:21 +0400263 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
azvyagintsev6dac3802018-11-09 15:11:30 +0200264 stage("Update local repos") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100265 common.infoMsg("Updating local repositories")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700266
Sergey1b81c062018-10-16 17:10:21 +0400267 def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700268 runningOnDocker = engine.get("return")[0].containsValue("docker")
269
270 if (runningOnDocker) {
271 common.infoMsg("Aptly is running as Docker container")
azvyagintsev6dac3802018-11-09 15:11:30 +0200272 } else {
Sam Stoelingaaab79702018-04-09 18:49:39 -0700273 common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands")
274 }
275
azvyagintsev6dac3802018-11-09 15:11:30 +0200276 if (runningOnDocker) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200277 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 +0200278 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200279 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 +0100280 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100281
Sergey1b81c062018-10-16 17:10:21 +0400282 salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100283
azvyagintsev6dac3802018-11-09 15:11:30 +0200284 if (runningOnDocker) {
Sergey1b81c062018-10-16 17:10:21 +0400285 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true)
286 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 +0200287 } else {
Sergey1b81c062018-10-16 17:10:21 +0400288 salt.runSaltProcessStep(venvPepper, 'I@aptly:publisher', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true)
289 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 +0100290 }
Richard Felkl79d7df12018-01-05 16:40:11 +0100291
Sergey1b81c062018-10-16 17:10:21 +0400292 salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100293
Sergey1b81c062018-10-16 17:10:21 +0400294 salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100295
Sergey1b81c062018-10-16 17:10:21 +0400296 salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100297
Sergey1b81c062018-10-16 17:10:21 +0400298 salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100299 }
300 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100301
azvyagintsev6dac3802018-11-09 15:11:30 +0200302 stage("Update Drivetrain") {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400303 if (upgradeSaltStack) {
304 updateSaltStack("I@salt:master", '["salt-master", "salt-common", "salt-api", "salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200305
Richard Felkl0e80d892018-06-20 13:44:54 +0200306 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.repo', true)
Richard Felkl0e80d892018-06-20 13:44:54 +0200307 updateSaltStack("I@salt:minion and not I@salt:master", '["salt-minion"]')
308 }
309
Denis Egorenkod13ad132018-12-17 16:56:02 +0400310 if (updatePipelines) {
Richard Felkl970e0082018-06-12 18:00:51 +0200311 triggerMirrorJob("git-mirror-downstream-mk-pipelines")
312 triggerMirrorJob("git-mirror-downstream-pipeline-library")
313 }
314
Denis Egorenkoaeaa1de2019-01-15 11:58:12 +0400315 // updating users and keys
316 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.user', true)
317 salt.enforceState(venvPepper, "I@linux:system", 'openssh', true)
318
Richard Felkl970e0082018-06-12 18:00:51 +0200319 salt.enforceState(venvPepper, "I@jenkins:client", 'jenkins.client', true)
320
321 salt.cmdRun(venvPepper, "I@salt:master", "salt -C 'I@jenkins:client and I@docker:client' state.sls docker.client --async")
322
323 sleep(180)
324
325 common.infoMsg("Checking if Docker containers are up")
326
azvyagintsev6dac3802018-11-09 15:11:30 +0200327 try {
328 common.retry(10, 30) {
Richard Felkl970e0082018-06-12 18:00:51 +0200329 salt.cmdRun(venvPepper, 'I@jenkins:client and I@docker:client', "! docker service ls | tail -n +2 | grep -v -E '\\s([0-9])/\\1\\s'")
330 }
331 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200332 catch (Exception ex) {
Richard Felkl970e0082018-06-12 18:00:51 +0200333 error("Docker containers for CI/CD services are having troubles with starting.")
334 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100335 }
336 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100337 catch (Throwable e) {
338 // If there was an error or exception thrown, the build failed
339 currentBuild.result = "FAILURE"
340 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +0100341 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100342 }
Jakub Josef2c21c6c2018-02-08 18:51:42 +0100343}