blob: d66017c6263eba6bd342a728ac2abd4b7b7fa7e6 [file] [log] [blame]
azvyagintsev9df82e52018-09-06 19:17:18 +03001/*
2Able to be triggered from Gerrit if :
3Variators:
4Modes:
51) manual run via job-build , possible to pass refspec
Denis Egorenkod8748942018-09-07 12:26:20 +04006 TODO: currently impossible to use custom COOKIECUTTER_TEMPLATE_URL| RECLASS_SYSTEM_URL Gerrit-one always used.
azvyagintsev9df82e52018-09-06 19:17:18 +03007 - for CC
8 - Reclass
Denis Egorenkod8748942018-09-07 12:26:20 +04009
102) gerrit trigger
azvyagintsev9df82e52018-09-06 19:17:18 +030011 Automatically switches if GERRIT_PROJECT variable detected
12 Always test GERRIT_REFSPEC VS GERRIT_BRANCH-master version of opposite project
13 */
14
chnydae80bb922017-05-29 17:48:40 +020015common = new com.mirantis.mk.Common()
chnydabc63c9a2017-05-30 15:37:54 +020016gerrit = new com.mirantis.mk.Gerrit()
chnydae80bb922017-05-29 17:48:40 +020017git = new com.mirantis.mk.Git()
18python = new com.mirantis.mk.Python()
chnydae80bb922017-05-29 17:48:40 +020019
azvyagintsev9df82e52018-09-06 19:17:18 +030020slaveNode = env.SLAVE_NODE ?: 'python&&docker'
azvyagintsev5c0313d2018-08-13 17:13:35 +030021
azvyagintsev9df82e52018-09-06 19:17:18 +030022// Global var's
23alreadyMerged = false
24gerritConData = [credentialsId : env.CREDENTIALS_ID,
25 gerritName : env.GERRIT_NAME ?: 'mcp-jenkins',
26 gerritHost : env.GERRIT_HOST ?: 'gerrit.mcp.mirantis.net',
azvyagintsevb266ad22018-09-11 12:11:11 +030027 gerritScheme : env.GERRIT_SCHEME ?: 'ssh',
28 gerritPort : env.GERRIT_PORT ?: '29418',
azvyagintsev9df82e52018-09-06 19:17:18 +030029 gerritRefSpec : null,
30 gerritProject : null,
31 withWipeOut : true,
32 GERRIT_CHANGE_NUMBER: null]
33//
34//ccTemplatesRepo = env.COOKIECUTTER_TEMPLATE_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.net:29418/mk/cookiecutter-templates'
35gerritDataCC = [:]
36gerritDataCC << gerritConData
37gerritDataCC['gerritBranch'] = env.COOKIECUTTER_TEMPLATE_BRANCH ?: 'master'
38gerritDataCC['gerritProject'] = 'mk/cookiecutter-templates'
39//
40//reclassSystemRepo = env.RECLASS_SYSTEM_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.net:29418/salt-models/reclass-system'
41gerritDataRS = [:]
42gerritDataRS << gerritConData
43gerritDataRS['gerritBranch'] = env.RECLASS_MODEL_BRANCH ?: 'master'
44gerritDataRS['gerritProject'] = 'salt-models/reclass-system'
45
46// version of debRepos, aka formulas\reclass
azvyagintsev10e24012018-09-10 21:36:32 +030047testDistribRevision = env.DISTRIB_REVISION ?: 'nightly'
48reclassVersion = 'v1.5.4'
azvyagintsevb266ad22018-09-11 12:11:11 +030049if (env.RECLASS_VERSION) {
azvyagintsev9df82e52018-09-06 19:17:18 +030050 reclassVersion = env.RECLASS_VERSION
Vasyl Saienko772e1232018-07-23 14:42:24 +030051}
Denis Egorenkod8748942018-09-07 12:26:20 +040052// Name of sub-test chunk job
53chunkJobName = "test-mk-cookiecutter-templates-chunk"
54testModelBuildsData = [:]
55
Vasyl Saienko772e1232018-07-23 14:42:24 +030056
chnyda467f10f2017-05-30 17:25:07 +020057def generateSaltMaster(modEnv, clusterDomain, clusterName) {
azvyagintsev5c0313d2018-08-13 17:13:35 +030058 def nodeFile = "${modEnv}/nodes/cfg01.${clusterDomain}.yml"
59 def nodeString = """classes:
chnydae80bb922017-05-29 17:48:40 +020060- cluster.${clusterName}.infra.config
61parameters:
62 _param:
63 linux_system_codename: xenial
64 reclass_data_revision: master
65 linux:
66 system:
67 name: cfg01
68 domain: ${clusterDomain}
69"""
azvyagintsev5c0313d2018-08-13 17:13:35 +030070 sh "mkdir -p ${modEnv}/nodes/"
71 println "Create file ${nodeFile}"
72 writeFile(file: nodeFile, text: nodeString)
azvyagintsev87985532018-07-10 20:49:38 +030073}
74
azvyagintsev30bc82e2018-08-22 12:26:06 +030075/**
76 *
77 * @param contextFile - path to `contexts/XXX.yaml file`
azvyagintsev9df82e52018-09-06 19:17:18 +030078 * @param virtualenv - pyvenv with CC and dep's
azvyagintsev30bc82e2018-08-22 12:26:06 +030079 * @param templateEnvDir - root of CookieCutter
80 * @return
81 */
82
azvyagintsev5c0313d2018-08-13 17:13:35 +030083def generateModel(contextFile, virtualenv, templateEnvDir) {
84 def modelEnv = "${templateEnvDir}/model"
85 def basename = common.GetBaseName(contextFile, '.yml')
86 def generatedModel = "${modelEnv}/${basename}"
87 def content = readFile(file: "${templateEnvDir}/contexts/${contextFile}")
88 def templateContext = readYaml text: content
89 def clusterDomain = templateContext.default_context.cluster_domain
90 def clusterName = templateContext.default_context.cluster_name
91 def outputDestination = "${generatedModel}/classes/cluster/${clusterName}"
92 def templateBaseDir = templateEnvDir
93 def templateDir = "${templateEnvDir}/dir"
94 def templateOutputDir = templateBaseDir
azvyagintsev30bc82e2018-08-22 12:26:06 +030095 dir(templateEnvDir) {
96 sh(script: "rm -rf ${generatedModel} || true")
97 common.infoMsg("Generating model from context ${contextFile}")
98 def productList = ["infra", "cicd", "opencontrail", "kubernetes", "openstack", "oss", "stacklight", "ceph"]
99 for (product in productList) {
chnydae80bb922017-05-29 17:48:40 +0200100
azvyagintsev30bc82e2018-08-22 12:26:06 +0300101 // get templateOutputDir and productDir
102 if (product.startsWith("stacklight")) {
103 templateOutputDir = "${templateEnvDir}/output/stacklight"
104 try {
105 productDir = "stacklight" + templateContext.default_context['stacklight_version']
106 } catch (Throwable e) {
107 productDir = "stacklight1"
108 }
109 } else {
110 templateOutputDir = "${templateEnvDir}/output/${product}"
111 productDir = product
azvyagintsev5c0313d2018-08-13 17:13:35 +0300112 }
azvyagintsev30bc82e2018-08-22 12:26:06 +0300113
114 if (product == "infra" || (templateContext.default_context["${product}_enabled"]
115 && templateContext.default_context["${product}_enabled"].toBoolean())) {
116
117 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
118 common.infoMsg("Generating product " + product + " from " + templateDir + " to " + templateOutputDir)
119
120 sh "rm -rf ${templateOutputDir} || true"
121 sh "mkdir -p ${templateOutputDir}"
122 sh "mkdir -p ${outputDestination}"
123
124 python.buildCookiecutterTemplate(templateDir, content, templateOutputDir, virtualenv, templateBaseDir)
125 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
126 } else {
127 common.warningMsg("Product " + product + " is disabled")
128 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300129 }
azvyagintsev30bc82e2018-08-22 12:26:06 +0300130 generateSaltMaster(generatedModel, clusterDomain, clusterName)
chnydae80bb922017-05-29 17:48:40 +0200131 }
chnydae80bb922017-05-29 17:48:40 +0200132}
133
Denis Egorenkod8748942018-09-07 12:26:20 +0400134def getAndUnpackNodesInfoArtifact(jobName, copyTo, build) {
135 return {
136 dir(copyTo) {
137 copyArtifacts(projectName: jobName, selector: specific(build), filter: "nodesinfo.tar.gz")
138 sh "tar -xvf nodesinfo.tar.gz"
139 sh "rm -v nodesinfo.tar.gz"
140 }
141 }
142}
azvyagintsev87985532018-07-10 20:49:38 +0300143
Denis Egorenkod8748942018-09-07 12:26:20 +0400144def testModel(modelFile, reclassArtifactName, artifactCopyPath) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300145 // modelFile - `modelfiname` from model/modelfiname/modelfiname.yaml
146 //* Grub all models and send it to check in paralell - by one in thread.
Denis Egorenkod8748942018-09-07 12:26:20 +0400147 def _uuid = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}_${modelFile.toLowerCase()}_" + UUID.randomUUID().toString().take(8)
148 def _values_string = """
azvyagintsev87985532018-07-10 20:49:38 +0300149 ---
Denis Egorenkod8748942018-09-07 12:26:20 +0400150 MODELS_TARGZ: "${env.BUILD_URL}/artifact/${reclassArtifactName}"
151 DockerCName: "${_uuid}"
azvyagintsev87985532018-07-10 20:49:38 +0300152 testReclassEnv: "model/${modelFile}/"
153 modelFile: "contexts/${modelFile}.yml"
azvyagintsev9df82e52018-09-06 19:17:18 +0300154 DISTRIB_REVISION: "${testDistribRevision}"
azvyagintsev87985532018-07-10 20:49:38 +0300155 EXTRA_FORMULAS: "${env.EXTRA_FORMULAS}"
156 reclassVersion: "${reclassVersion}"
157 """
Denis Egorenkod8748942018-09-07 12:26:20 +0400158 def chunkJob = build job: chunkJobName, parameters: [
azvyagintsev08b34e32018-09-12 12:29:42 +0300159 [$class: 'TextParameterValue', name: 'EXTRA_VARIABLES_YAML',
azvyagintsev30bc82e2018-08-22 12:26:06 +0300160 value : _values_string.stripIndent()],
azvyagintsev5c0313d2018-08-13 17:13:35 +0300161 ]
Denis Egorenkod8748942018-09-07 12:26:20 +0400162 // Put sub-job info into global map.
163 testModelBuildsData.put(_uuid, ['jobname' : chunkJob.fullProjectName,
164 'copyToDir': "${artifactCopyPath}/${modelFile}",
165 'buildId' : "${chunkJob.number}"])
chnydabc63c9a2017-05-30 15:37:54 +0200166}
167
Denis Egorenkod8748942018-09-07 12:26:20 +0400168def StepTestModel(basename, reclassArtifactName, artifactCopyPath) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300169 // We need to wrap what we return in a Groovy closure, or else it's invoked
170 // when this method is called, not when we pass it to parallel.
171 // To do this, you need to wrap the code below in { }, and either return
172 // that explicitly, or use { -> } syntax.
173 // return node object
174 return {
175 node(slaveNode) {
Denis Egorenkod8748942018-09-07 12:26:20 +0400176 testModel(basename, reclassArtifactName, artifactCopyPath)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300177 }
chnydae80bb922017-05-29 17:48:40 +0200178 }
azvyagintsev87985532018-07-10 20:49:38 +0300179}
180
azvyagintsev9df82e52018-09-06 19:17:18 +0300181def StepPrepareGit(templateEnvFolder, gerrit_data) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300182 // return git clone object
183 return {
azvyagintsev9df82e52018-09-06 19:17:18 +0300184 def checkouted = false
185 common.infoMsg("StepPrepareGit: ${gerrit_data}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300186 // fetch needed sources
187 dir(templateEnvFolder) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300188 if (gerrit_data['gerritRefSpec']) {
189 // Those part might be not work,in case manual var's pass
190 def gerritChange = gerrit.getGerritChange(gerrit_data['gerritName'], gerrit_data['gerritHost'],
191 gerrit_data['GERRIT_CHANGE_NUMBER'], gerrit_data['credentialsId'])
azvyagintsev5c0313d2018-08-13 17:13:35 +0300192 merged = gerritChange.status == "MERGED"
193 if (!merged) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300194 checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300195 } else {
azvyagintsev9df82e52018-09-06 19:17:18 +0300196 // update global variable for pretty return from pipeline
197 alreadyMerged = true
198 common.successMsg("Change ${gerrit_data['GERRIT_CHANGE_NUMBER']} is already merged, no need to gate them")
199 error('change already merged')
azvyagintsev87985532018-07-10 20:49:38 +0300200 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300201 } else {
azvyagintsev9df82e52018-09-06 19:17:18 +0300202 // Get clean HEAD
203 gerrit_data['useGerritTriggerBuildChooser'] = false
204 checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
205 if (!checkouted) {
206 error("Failed to get repo:${gerrit_data}")
207 }
azvyagintsev87985532018-07-10 20:49:38 +0300208 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300209 }
azvyagintsev87985532018-07-10 20:49:38 +0300210 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300211}
212
213def StepGenerateModels(_contextFileList, _virtualenv, _templateEnvDir) {
214 return {
215 for (contextFile in _contextFileList) {
216 generateModel(contextFile, _virtualenv, _templateEnvDir)
217 }
218 }
219}
220
azvyagintsev9df82e52018-09-06 19:17:18 +0300221def globalVariatorsUpdate() {
222 // Simple function, to check and define branch-around variables
223 // In general, simply make transition updates for non-master branch
224 // based on magic logic
225 def message = ''
azvyagintsevb266ad22018-09-11 12:11:11 +0300226 if (env.GERRIT_PROJECT) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300227 if (!['nightly', 'testing', 'stable', 'proposed', 'master'].contains(env.GERRIT_BRANCH)) {
228 gerritDataCC['gerritBranch'] = env.GERRIT_BRANCH
229 gerritDataRS['gerritBranch'] = env.GERRIT_BRANCH
230 // 'binary' branch logic w\o 'release/' prefix
231 testDistribRevision = env.GERRIT_BRANCH.split('/')[-1]
232 // Check if we are going to test bleeding-edge release, which doesn't have binary release yet
233 if (!common.checkRemoteBinary([apt_mk_version: testDistribRevision]).linux_system_repo_url) {
234 common.errorMsg("Binary release: ${testDistribRevision} not exist. Fallback to 'proposed'! ")
235 testDistribRevision = 'proposed'
236 }
237 }
238 // Identify, who triggered. To whom we should pass refspec
239 if (env.GERRIT_PROJECT == 'salt-models/reclass-system') {
240 gerritDataRS['gerritRefSpec'] = env.GERRIT_REFSPEC
241 gerritDataRS['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
242 message = "<br/>RECLASS_SYSTEM_GIT_REF =>${gerritDataRS['gerritRefSpec']}"
243 } else if (env.GERRIT_PROJECT == 'mk/cookiecutter-templates') {
244 gerritDataCC['gerritRefSpec'] = env.GERRIT_REFSPEC
245 gerritDataCC['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
246 message = "<br/>COOKIECUTTER_TEMPLATE_REF =>${gerritDataCC['gerritRefSpec']}"
247 } else {
248 error("Unsuported gerrit-project triggered:${env.GERRIT_PROJECT}")
249 }
250
251 message = "<font color='red'>GerritTrigger detected! We are in auto-mode:</font>" +
252 "<br/>Test env variables has been changed:" +
253 "<br/>COOKIECUTTER_TEMPLATE_BRANCH => ${gerritDataCC['gerritBranch']}" +
254 "<br/>DISTRIB_REVISION =>${testDistribRevision}" +
255 "<br/>RECLASS_MODEL_BRANCH=> ${gerritDataRS['gerritBranch']}" + message
256 common.warningMsg(message)
257 currentBuild.description = currentBuild.description ? message + "<br/>" + currentBuild.description : message
258 } else {
259 // Check for passed variables:
azvyagintsevb266ad22018-09-11 12:11:11 +0300260 if (env.RECLASS_SYSTEM_GIT_REF) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300261 gerritDataRS['gerritRefSpec'] = RECLASS_SYSTEM_GIT_REF
262 }
azvyagintsevb266ad22018-09-11 12:11:11 +0300263 if (env.COOKIECUTTER_TEMPLATE_REF) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300264 gerritDataCC['gerritRefSpec'] = COOKIECUTTER_TEMPLATE_REF
265 }
266 message = "<font color='red'>Manual run detected!</font>" + "<br/>"
267 currentBuild.description = currentBuild.description ? message + "<br/>" + currentBuild.description : message
268 }
Denis Egorenkod8748942018-09-07 12:26:20 +0400269}
azvyagintsev9df82e52018-09-06 19:17:18 +0300270
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400271def replaceGeneratedValues(path) {
272 def files = sh(script: "find ${path} -name 'secrets.yml'", returnStdout: true)
273 def stepsForParallel = [:]
274 stepsForParallel.failFast = true
275 files.tokenize().each {
276 stepsForParallel.put("Removing generated passwords/secrets from ${it}",
277 {
278 def secrets = readYaml file: it
azvyagintsev08b34e32018-09-12 12:29:42 +0300279 for (String key in secrets['parameters']['_param'].keySet()) {
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400280 secrets['parameters']['_param'][key] = 'generated'
281 }
282 // writeYaml can't write to already existing file
283 writeYaml file: "${it}.tmp", data: secrets
284 sh "mv ${it}.tmp ${it}"
285 })
286 }
287 parallel stepsForParallel
288}
289
Denis Egorenkod8748942018-09-07 12:26:20 +0400290def linkReclassModels(contextList, envPath, archiveName) {
291 // to be able share reclass for all subenvs
292 // Also, makes artifact test more solid - use one reclass for all of sub-models.
293 // Archive Structure will be:
294 // tar.gz
295 // ├── contexts
296 // │   └── ceph.yml
297 // ├── global_reclass <<< reclass system
298 // ├── model
299 // │   └── ceph <<< from `context basename`
300 // │   ├── classes
301 // │   │   ├── cluster
302 // │   │   └── system -> ../../../global_reclass
303 // │   └── nodes
304 // │   └── cfg01.ceph-cluster-domain.local.yml
305 dir(envPath) {
306 for (String context : contextList) {
307 def basename = common.GetBaseName(context, '.yml')
308 dir("${envPath}/model/${basename}") {
309 sh(script: 'mkdir -p classes/; ln -sfv ../../../../global_reclass classes/system ')
310 }
311 }
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400312 // replace all generated passwords/secrets/keys with hardcode value for infra/secrets.yaml
313 replaceGeneratedValues("${envPath}/model")
Denis Egorenkod8748942018-09-07 12:26:20 +0400314 // Save all models and all contexts. Warning! `h` flag must be used.
315 sh(script: "set -ex; tar -chzf ${archiveName} --exclude='*@tmp' model contexts", returnStatus: true)
316 archiveArtifacts artifacts: archiveName
317 // move for "Compare Pillars" stage
318 sh(script: "mv -v ${archiveName} ${env.WORKSPACE}")
319 }
azvyagintsev9df82e52018-09-06 19:17:18 +0300320}
321
azvyagintsev5c0313d2018-08-13 17:13:35 +0300322timeout(time: 1, unit: 'HOURS') {
323 node(slaveNode) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300324 globalVariatorsUpdate()
325 def gerritDataCCHEAD = [:]
azvyagintsev30bc82e2018-08-22 12:26:06 +0300326 def templateEnvHead = "${env.WORKSPACE}/EnvHead/"
327 def templateEnvPatched = "${env.WORKSPACE}/EnvPatched/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300328 def contextFileListHead = []
329 def contextFileListPatched = []
330 def vEnv = "${env.WORKSPACE}/venv"
Denis Egorenkod8748942018-09-07 12:26:20 +0400331 def headReclassArtifactName = "head_reclass.tar.gz"
332 def patchedReclassArtifactName = "patched_reclass.tar.gz"
333 def reclassNodeInfoDir = "${env.WORKSPACE}/reclassNodeInfo_compare/"
334 def reclassInfoHeadPath = "${reclassNodeInfoDir}/old"
335 def reclassInfoPatchedPath = "${reclassNodeInfoDir}/new"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300336 try {
337 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
338 stage('Download and prepare CC env') {
339 // Prepare 2 env - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300340 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300341 paralellEnvs.failFast = true
azvyagintsev9df82e52018-09-06 19:17:18 +0300342 paralellEnvs['downloadEnvPatched'] = StepPrepareGit(templateEnvPatched, gerritDataCC)
343 gerritDataCCHEAD << gerritDataCC
344 gerritDataCCHEAD['gerritRefSpec'] = null; gerritDataCCHEAD['GERRIT_CHANGE_NUMBER'] = null
345 paralellEnvs['downloadEnvHead'] = StepPrepareGit(templateEnvHead, gerritDataCCHEAD)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300346 parallel paralellEnvs
347 }
348 stage("Check workflow_definition") {
349 // Check only for patchset
350 python.setupVirtualenv(vEnv, 'python2', [], "${templateEnvPatched}/requirements.txt")
351 common.infoMsg(python.runVirtualenvCommand(vEnv, "python ${templateEnvPatched}/workflow_definition_test.py"))
352 }
353
354 stage("generate models") {
355 dir("${templateEnvHead}/contexts") {
356 for (String x : findFiles(glob: "*.yml")) {
357 contextFileListHead.add(x)
358 }
359 }
360 dir("${templateEnvPatched}/contexts") {
361 for (String x : findFiles(glob: "*.yml")) {
362 contextFileListPatched.add(x)
363 }
364 }
365 // Generate over 2env's - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300366 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300367 paralellEnvs.failFast = true
azvyagintsev30bc82e2018-08-22 12:26:06 +0300368 paralellEnvs['GenerateEnvPatched'] = StepGenerateModels(contextFileListPatched, vEnv, templateEnvPatched)
369 paralellEnvs['GenerateEnvHead'] = StepGenerateModels(contextFileListHead, vEnv, templateEnvHead)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300370 parallel paralellEnvs
371
372 // Collect artifacts
373 dir(templateEnvPatched) {
374 // Collect only models. For backward comparability - who know, probably someone use it..
375 sh(script: "tar -czf model.tar.gz -C model ../contexts .", returnStatus: true)
376 archiveArtifacts artifacts: "model.tar.gz"
377 }
378
azvyagintsev9df82e52018-09-06 19:17:18 +0300379 StepPrepareGit("${env.WORKSPACE}/global_reclass/", gerritDataRS).call()
azvyagintsev5c0313d2018-08-13 17:13:35 +0300380 // link all models, to use one global reclass
381 // For HEAD
Denis Egorenkod8748942018-09-07 12:26:20 +0400382 linkReclassModels(contextFileListHead, templateEnvHead, headReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300383 // For patched
Denis Egorenkod8748942018-09-07 12:26:20 +0400384 linkReclassModels(contextFileListPatched, templateEnvPatched, patchedReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300385 }
386
Denis Egorenkod8748942018-09-07 12:26:20 +0400387 stage("Compare cluster lvl Head/Patched") {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300388 // Compare patched and HEAD reclass pillars
Denis Egorenkod8748942018-09-07 12:26:20 +0400389 compareRoot = "${env.WORKSPACE}/cluster_compare/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300390 sh(script: """
391 mkdir -pv ${compareRoot}/new ${compareRoot}/old
Denis Egorenkod8748942018-09-07 12:26:20 +0400392 tar -xzf ${patchedReclassArtifactName} --directory ${compareRoot}/new
393 tar -xzf ${headReclassArtifactName} --directory ${compareRoot}/old
azvyagintsev5c0313d2018-08-13 17:13:35 +0300394 """)
395 common.warningMsg('infra/secrets.yml has been skipped from compare!')
azvyagintsevb266ad22018-09-11 12:11:11 +0300396 result = '\n' + common.comparePillars(compareRoot, env.BUILD_URL, "-Ev \'infra/secrets.yml\'")
Denis Egorenkod8748942018-09-07 12:26:20 +0400397 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300398 }
Denis Egorenkod8748942018-09-07 12:26:20 +0400399 stage("TestContexts Head/Patched") {
400 def stepsForParallel = [:]
401 stepsForParallel.failFast = true
402 common.infoMsg("Found: ${contextFileListHead.size()} HEAD contexts to test.")
403 for (String context : contextFileListHead) {
404 def basename = common.GetBaseName(context, '.yml')
405 stepsForParallel.put("ContextHeadTest:${basename}", StepTestModel(basename, headReclassArtifactName, reclassInfoHeadPath))
406 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300407 common.infoMsg("Found: ${contextFileListPatched.size()} patched contexts to test.")
408 for (String context : contextFileListPatched) {
409 def basename = common.GetBaseName(context, '.yml')
Denis Egorenkod8748942018-09-07 12:26:20 +0400410 stepsForParallel.put("ContextPatchedTest:${basename}", StepTestModel(basename, patchedReclassArtifactName, reclassInfoPatchedPath))
azvyagintsev5c0313d2018-08-13 17:13:35 +0300411 }
412 parallel stepsForParallel
Denis Egorenkod8748942018-09-07 12:26:20 +0400413 common.infoMsg('All TestContexts tests done')
414 }
415 stage("Compare NodesInfo Head/Patched") {
416 // Download all artifacts
417 def stepsForParallel = [:]
418 stepsForParallel.failFast = true
419 common.infoMsg("Found: ${testModelBuildsData.size()} nodeinfo artifacts to download.")
420 testModelBuildsData.each { bname, bdata ->
421 stepsForParallel.put("FetchData:${bname}",
422 getAndUnpackNodesInfoArtifact(bdata.jobname, bdata.copyToDir, bdata.buildId))
423 }
424 parallel stepsForParallel
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400425 // remove timestamp field from rendered files
426 sh("find ${reclassNodeInfoDir} -type f -exec sed -i '/ timestamp: .*/d' {} \\;")
Denis Egorenkod8748942018-09-07 12:26:20 +0400427 // Compare patched and HEAD reclass pillars
428 result = '\n' + common.comparePillars(reclassNodeInfoDir, env.BUILD_URL, '')
429 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300430 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300431 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
432
433 } catch (Throwable e) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300434 if (alreadyMerged) {
435 currentBuild.result = 'ABORTED'
436 currentBuild.description = "Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them"
437 return
438 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300439 currentBuild.result = "FAILURE"
440 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
441 throw e
442 } finally {
443 def dummy = "dummy"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300444 }
445 }
chnydae80bb922017-05-29 17:48:40 +0200446}