blob: 14a746b9d5b4001e8c86c82a78cfad278badfc7c [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}")
Sergey382581a2018-10-25 12:22:26 +0400192 // Add new defaults
193 common.infoMsg("Add new defaults")
Denis Egorenkod13ad132018-12-17 16:56:02 +0400194 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 +0400195 "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 +0400196 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 +0400197 "sed -i 's|^classes:|classes:\\n- system.defaults|' /srv/salt/reclass/classes/cluster/$cluster_name/infra/init.yml")
Sergey382581a2018-10-25 12:22:26 +0400198 common.infoMsg("The following changes were made to the cluster model and will be commited. " +
azvyagintsev6dac3802018-11-09 15:11:30 +0200199 "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 +0400200 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 && " +
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200202 "git add -u && git commit --allow-empty -m 'Cluster model update to the release $targetMcpVersion on $dateTime'")
Sergey382581a2018-10-25 12:22:26 +0400203 }
Denis Egorenkod13ad132018-12-17 16:56:02 +0400204
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')
Sergey1b81c062018-10-16 17:10:21 +0400228 salt.enforceState(venvPepper, 'I@salt:master', 'reclass.storage', true)
Denis Egorenkod13ad132018-12-17 16:56:02 +0400229 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 Josefa63f9862018-01-11 17:58:38 +0100252 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100253
Denis Egorenkod13ad132018-12-17 16:56:02 +0400254 if (updateLocalRepos) {
Sergey1b81c062018-10-16 17:10:21 +0400255 def cluster_name = salt.getPillar(venvPepper, 'I@salt:master', "_param:cluster_name").get("return")[0].values()[0]
azvyagintsev6dac3802018-11-09 15:11:30 +0200256 stage("Update local repos") {
Jakub Josefa63f9862018-01-11 17:58:38 +0100257 common.infoMsg("Updating local repositories")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700258
Sergey1b81c062018-10-16 17:10:21 +0400259 def engine = salt.getPillar(venvPepper, 'I@aptly:publisher', "aptly:publisher:source:engine")
Sam Stoelingaaab79702018-04-09 18:49:39 -0700260 runningOnDocker = engine.get("return")[0].containsValue("docker")
261
262 if (runningOnDocker) {
263 common.infoMsg("Aptly is running as Docker container")
azvyagintsev6dac3802018-11-09 15:11:30 +0200264 } else {
Sam Stoelingaaab79702018-04-09 18:49:39 -0700265 common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands")
266 }
267
azvyagintsev6dac3802018-11-09 15:11:30 +0200268 if (runningOnDocker) {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200269 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 +0200270 } else {
azvyagintsevf3bf77a2018-11-15 19:30:04 +0200271 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 +0100272 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100273
Sergey1b81c062018-10-16 17:10:21 +0400274 salt.enforceState(venvPepper, 'I@aptly:publisher', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100275
azvyagintsev6dac3802018-11-09 15:11:30 +0200276 if (runningOnDocker) {
Sergey1b81c062018-10-16 17:10:21 +0400277 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)
azvyagintsev6dac3802018-11-09 15:11:30 +0200279 } else {
Sergey1b81c062018-10-16 17:10:21 +0400280 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 Felkl5f7fdaf2018-02-15 15:38:31 +0100282 }
Richard Felkl79d7df12018-01-05 16:40:11 +0100283
Sergey1b81c062018-10-16 17:10:21 +0400284 salt.enforceState(venvPepper, 'I@aptly:publisher', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100285
Sergey1b81c062018-10-16 17:10:21 +0400286 salt.enforceState(venvPepper, 'I@aptly:publisher', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +0100287
Sergey1b81c062018-10-16 17:10:21 +0400288 salt.enforceState(venvPepper, 'I@aptly:publisher', 'git.server', true)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100289
Sergey1b81c062018-10-16 17:10:21 +0400290 salt.enforceState(venvPepper, 'I@aptly:publisher', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100291 }
292 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100293
azvyagintsev6dac3802018-11-09 15:11:30 +0200294 stage("Update Drivetrain") {
Denis Egorenkod13ad132018-12-17 16:56:02 +0400295 if (upgradeSaltStack) {
296 updateSaltStack("I@salt:master", '["salt-master", "salt-common", "salt-api", "salt-minion"]')
Richard Felkl0e80d892018-06-20 13:44:54 +0200297
Richard Felkl0e80d892018-06-20 13:44:54 +0200298 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.repo', true)
Richard Felkl0e80d892018-06-20 13:44:54 +0200299 updateSaltStack("I@salt:minion and not I@salt:master", '["salt-minion"]')
300 }
301
Denis Egorenkod13ad132018-12-17 16:56:02 +0400302 if (updatePipelines) {
Richard Felkl970e0082018-06-12 18:00:51 +0200303 triggerMirrorJob("git-mirror-downstream-mk-pipelines")
304 triggerMirrorJob("git-mirror-downstream-pipeline-library")
305 }
306
Denis Egorenkoaeaa1de2019-01-15 11:58:12 +0400307 // 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 Felkl970e0082018-06-12 18:00:51 +0200311 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
azvyagintsev6dac3802018-11-09 15:11:30 +0200319 try {
320 common.retry(10, 30) {
Richard Felkl970e0082018-06-12 18:00:51 +0200321 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 }
azvyagintsev6dac3802018-11-09 15:11:30 +0200324 catch (Exception ex) {
Richard Felkl970e0082018-06-12 18:00:51 +0200325 error("Docker containers for CI/CD services are having troubles with starting.")
326 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100327 }
328 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100329 catch (Throwable e) {
330 // If there was an error or exception thrown, the build failed
331 currentBuild.result = "FAILURE"
332 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +0100333 }
Richard Felkl26cae4d2017-12-19 00:19:16 +0100334 }
Jakub Josef2c21c6c2018-02-08 18:51:42 +0100335}