blob: b380bfd6223555b0ecc3d48cba68b5ba1e26540a [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 = [:]
Vasyl Saienko772e1232018-07-23 14:42:24 +030055
chnyda467f10f2017-05-30 17:25:07 +020056def generateSaltMaster(modEnv, clusterDomain, clusterName) {
azvyagintsev5c0313d2018-08-13 17:13:35 +030057 def nodeFile = "${modEnv}/nodes/cfg01.${clusterDomain}.yml"
58 def nodeString = """classes:
chnydae80bb922017-05-29 17:48:40 +020059- cluster.${clusterName}.infra.config
60parameters:
61 _param:
62 linux_system_codename: xenial
63 reclass_data_revision: master
64 linux:
65 system:
66 name: cfg01
67 domain: ${clusterDomain}
68"""
azvyagintsev5c0313d2018-08-13 17:13:35 +030069 sh "mkdir -p ${modEnv}/nodes/"
70 println "Create file ${nodeFile}"
71 writeFile(file: nodeFile, text: nodeString)
azvyagintsev87985532018-07-10 20:49:38 +030072}
73
azvyagintsev30bc82e2018-08-22 12:26:06 +030074/**
75 *
76 * @param contextFile - path to `contexts/XXX.yaml file`
azvyagintsev9df82e52018-09-06 19:17:18 +030077 * @param virtualenv - pyvenv with CC and dep's
azvyagintsev30bc82e2018-08-22 12:26:06 +030078 * @param templateEnvDir - root of CookieCutter
79 * @return
80 */
81
azvyagintsev5c0313d2018-08-13 17:13:35 +030082def generateModel(contextFile, virtualenv, templateEnvDir) {
83 def modelEnv = "${templateEnvDir}/model"
84 def basename = common.GetBaseName(contextFile, '.yml')
85 def generatedModel = "${modelEnv}/${basename}"
86 def content = readFile(file: "${templateEnvDir}/contexts/${contextFile}")
87 def templateContext = readYaml text: content
88 def clusterDomain = templateContext.default_context.cluster_domain
89 def clusterName = templateContext.default_context.cluster_name
90 def outputDestination = "${generatedModel}/classes/cluster/${clusterName}"
91 def templateBaseDir = templateEnvDir
92 def templateDir = "${templateEnvDir}/dir"
93 def templateOutputDir = templateBaseDir
azvyagintsev30bc82e2018-08-22 12:26:06 +030094 dir(templateEnvDir) {
95 sh(script: "rm -rf ${generatedModel} || true")
96 common.infoMsg("Generating model from context ${contextFile}")
97 def productList = ["infra", "cicd", "opencontrail", "kubernetes", "openstack", "oss", "stacklight", "ceph"]
98 for (product in productList) {
chnydae80bb922017-05-29 17:48:40 +020099
azvyagintsev30bc82e2018-08-22 12:26:06 +0300100 // get templateOutputDir and productDir
101 if (product.startsWith("stacklight")) {
102 templateOutputDir = "${templateEnvDir}/output/stacklight"
103 try {
104 productDir = "stacklight" + templateContext.default_context['stacklight_version']
105 } catch (Throwable e) {
106 productDir = "stacklight1"
107 }
108 } else {
109 templateOutputDir = "${templateEnvDir}/output/${product}"
110 productDir = product
azvyagintsev5c0313d2018-08-13 17:13:35 +0300111 }
azvyagintsev30bc82e2018-08-22 12:26:06 +0300112
113 if (product == "infra" || (templateContext.default_context["${product}_enabled"]
114 && templateContext.default_context["${product}_enabled"].toBoolean())) {
115
116 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
117 common.infoMsg("Generating product " + product + " from " + templateDir + " to " + templateOutputDir)
118
119 sh "rm -rf ${templateOutputDir} || true"
120 sh "mkdir -p ${templateOutputDir}"
121 sh "mkdir -p ${outputDestination}"
122
123 python.buildCookiecutterTemplate(templateDir, content, templateOutputDir, virtualenv, templateBaseDir)
124 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
125 } else {
126 common.warningMsg("Product " + product + " is disabled")
127 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300128 }
azvyagintsev30bc82e2018-08-22 12:26:06 +0300129 generateSaltMaster(generatedModel, clusterDomain, clusterName)
chnydae80bb922017-05-29 17:48:40 +0200130 }
chnydae80bb922017-05-29 17:48:40 +0200131}
132
Denis Egorenkod8748942018-09-07 12:26:20 +0400133def getAndUnpackNodesInfoArtifact(jobName, copyTo, build) {
134 return {
135 dir(copyTo) {
136 copyArtifacts(projectName: jobName, selector: specific(build), filter: "nodesinfo.tar.gz")
137 sh "tar -xvf nodesinfo.tar.gz"
138 sh "rm -v nodesinfo.tar.gz"
139 }
140 }
141}
azvyagintsev87985532018-07-10 20:49:38 +0300142
Denis Egorenkod8748942018-09-07 12:26:20 +0400143def testModel(modelFile, reclassArtifactName, artifactCopyPath) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300144 // modelFile - `modelfiname` from model/modelfiname/modelfiname.yaml
145 //* Grub all models and send it to check in paralell - by one in thread.
Denis Egorenkod8748942018-09-07 12:26:20 +0400146 def _uuid = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}_${modelFile.toLowerCase()}_" + UUID.randomUUID().toString().take(8)
147 def _values_string = """
azvyagintsev87985532018-07-10 20:49:38 +0300148 ---
Denis Egorenkod8748942018-09-07 12:26:20 +0400149 MODELS_TARGZ: "${env.BUILD_URL}/artifact/${reclassArtifactName}"
150 DockerCName: "${_uuid}"
azvyagintsev87985532018-07-10 20:49:38 +0300151 testReclassEnv: "model/${modelFile}/"
152 modelFile: "contexts/${modelFile}.yml"
azvyagintsev9df82e52018-09-06 19:17:18 +0300153 DISTRIB_REVISION: "${testDistribRevision}"
azvyagintsev87985532018-07-10 20:49:38 +0300154 reclassVersion: "${reclassVersion}"
155 """
Denis Egorenkod8748942018-09-07 12:26:20 +0400156 def chunkJob = build job: chunkJobName, parameters: [
azvyagintsev08b34e32018-09-12 12:29:42 +0300157 [$class: 'TextParameterValue', name: 'EXTRA_VARIABLES_YAML',
azvyagintsev30bc82e2018-08-22 12:26:06 +0300158 value : _values_string.stripIndent()],
azvyagintsev5c0313d2018-08-13 17:13:35 +0300159 ]
Denis Egorenkod8748942018-09-07 12:26:20 +0400160 // Put sub-job info into global map.
161 testModelBuildsData.put(_uuid, ['jobname' : chunkJob.fullProjectName,
162 'copyToDir': "${artifactCopyPath}/${modelFile}",
163 'buildId' : "${chunkJob.number}"])
chnydabc63c9a2017-05-30 15:37:54 +0200164}
165
Denis Egorenkod8748942018-09-07 12:26:20 +0400166def StepTestModel(basename, reclassArtifactName, artifactCopyPath) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300167 // We need to wrap what we return in a Groovy closure, or else it's invoked
168 // when this method is called, not when we pass it to parallel.
169 // To do this, you need to wrap the code below in { }, and either return
170 // that explicitly, or use { -> } syntax.
171 // return node object
172 return {
173 node(slaveNode) {
Denis Egorenkod8748942018-09-07 12:26:20 +0400174 testModel(basename, reclassArtifactName, artifactCopyPath)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300175 }
chnydae80bb922017-05-29 17:48:40 +0200176 }
azvyagintsev87985532018-07-10 20:49:38 +0300177}
178
azvyagintsev9df82e52018-09-06 19:17:18 +0300179def StepPrepareGit(templateEnvFolder, gerrit_data) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300180 // return git clone object
181 return {
azvyagintsev9df82e52018-09-06 19:17:18 +0300182 def checkouted = false
183 common.infoMsg("StepPrepareGit: ${gerrit_data}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300184 // fetch needed sources
185 dir(templateEnvFolder) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300186 if (gerrit_data['gerritRefSpec']) {
187 // Those part might be not work,in case manual var's pass
188 def gerritChange = gerrit.getGerritChange(gerrit_data['gerritName'], gerrit_data['gerritHost'],
189 gerrit_data['GERRIT_CHANGE_NUMBER'], gerrit_data['credentialsId'])
azvyagintsev5c0313d2018-08-13 17:13:35 +0300190 merged = gerritChange.status == "MERGED"
191 if (!merged) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300192 checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300193 } else {
azvyagintsev9df82e52018-09-06 19:17:18 +0300194 // update global variable for pretty return from pipeline
195 alreadyMerged = true
196 common.successMsg("Change ${gerrit_data['GERRIT_CHANGE_NUMBER']} is already merged, no need to gate them")
197 error('change already merged')
azvyagintsev87985532018-07-10 20:49:38 +0300198 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300199 } else {
azvyagintsev9df82e52018-09-06 19:17:18 +0300200 // Get clean HEAD
201 gerrit_data['useGerritTriggerBuildChooser'] = false
202 checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
203 if (!checkouted) {
204 error("Failed to get repo:${gerrit_data}")
205 }
azvyagintsev87985532018-07-10 20:49:38 +0300206 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300207 }
azvyagintsev87985532018-07-10 20:49:38 +0300208 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300209}
210
211def StepGenerateModels(_contextFileList, _virtualenv, _templateEnvDir) {
212 return {
213 for (contextFile in _contextFileList) {
214 generateModel(contextFile, _virtualenv, _templateEnvDir)
215 }
216 }
217}
218
azvyagintsev9df82e52018-09-06 19:17:18 +0300219def globalVariatorsUpdate() {
220 // Simple function, to check and define branch-around variables
221 // In general, simply make transition updates for non-master branch
222 // based on magic logic
223 def message = ''
azvyagintsevb266ad22018-09-11 12:11:11 +0300224 if (env.GERRIT_PROJECT) {
azvyagintseve0eb6cd2018-09-12 13:00:40 +0300225 // TODO are we going to have such branches?
azvyagintsev9df82e52018-09-06 19:17:18 +0300226 if (!['nightly', 'testing', 'stable', 'proposed', 'master'].contains(env.GERRIT_BRANCH)) {
227 gerritDataCC['gerritBranch'] = env.GERRIT_BRANCH
228 gerritDataRS['gerritBranch'] = env.GERRIT_BRANCH
229 // 'binary' branch logic w\o 'release/' prefix
230 testDistribRevision = env.GERRIT_BRANCH.split('/')[-1]
231 // Check if we are going to test bleeding-edge release, which doesn't have binary release yet
232 if (!common.checkRemoteBinary([apt_mk_version: testDistribRevision]).linux_system_repo_url) {
233 common.errorMsg("Binary release: ${testDistribRevision} not exist. Fallback to 'proposed'! ")
234 testDistribRevision = 'proposed'
235 }
236 }
237 // Identify, who triggered. To whom we should pass refspec
238 if (env.GERRIT_PROJECT == 'salt-models/reclass-system') {
239 gerritDataRS['gerritRefSpec'] = env.GERRIT_REFSPEC
240 gerritDataRS['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
241 message = "<br/>RECLASS_SYSTEM_GIT_REF =>${gerritDataRS['gerritRefSpec']}"
242 } else if (env.GERRIT_PROJECT == 'mk/cookiecutter-templates') {
243 gerritDataCC['gerritRefSpec'] = env.GERRIT_REFSPEC
244 gerritDataCC['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
245 message = "<br/>COOKIECUTTER_TEMPLATE_REF =>${gerritDataCC['gerritRefSpec']}"
246 } else {
247 error("Unsuported gerrit-project triggered:${env.GERRIT_PROJECT}")
248 }
249
250 message = "<font color='red'>GerritTrigger detected! We are in auto-mode:</font>" +
251 "<br/>Test env variables has been changed:" +
252 "<br/>COOKIECUTTER_TEMPLATE_BRANCH => ${gerritDataCC['gerritBranch']}" +
253 "<br/>DISTRIB_REVISION =>${testDistribRevision}" +
254 "<br/>RECLASS_MODEL_BRANCH=> ${gerritDataRS['gerritBranch']}" + message
255 common.warningMsg(message)
256 currentBuild.description = currentBuild.description ? message + "<br/>" + currentBuild.description : message
257 } else {
258 // Check for passed variables:
azvyagintsevb266ad22018-09-11 12:11:11 +0300259 if (env.RECLASS_SYSTEM_GIT_REF) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300260 gerritDataRS['gerritRefSpec'] = RECLASS_SYSTEM_GIT_REF
261 }
azvyagintsevb266ad22018-09-11 12:11:11 +0300262 if (env.COOKIECUTTER_TEMPLATE_REF) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300263 gerritDataCC['gerritRefSpec'] = COOKIECUTTER_TEMPLATE_REF
264 }
265 message = "<font color='red'>Manual run detected!</font>" + "<br/>"
266 currentBuild.description = currentBuild.description ? message + "<br/>" + currentBuild.description : message
267 }
Denis Egorenkod8748942018-09-07 12:26:20 +0400268}
azvyagintsev9df82e52018-09-06 19:17:18 +0300269
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400270def replaceGeneratedValues(path) {
271 def files = sh(script: "find ${path} -name 'secrets.yml'", returnStdout: true)
272 def stepsForParallel = [:]
273 stepsForParallel.failFast = true
274 files.tokenize().each {
275 stepsForParallel.put("Removing generated passwords/secrets from ${it}",
276 {
277 def secrets = readYaml file: it
azvyagintsev08b34e32018-09-12 12:29:42 +0300278 for (String key in secrets['parameters']['_param'].keySet()) {
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400279 secrets['parameters']['_param'][key] = 'generated'
280 }
281 // writeYaml can't write to already existing file
282 writeYaml file: "${it}.tmp", data: secrets
283 sh "mv ${it}.tmp ${it}"
284 })
285 }
286 parallel stepsForParallel
287}
288
Denis Egorenkod8748942018-09-07 12:26:20 +0400289def linkReclassModels(contextList, envPath, archiveName) {
290 // to be able share reclass for all subenvs
291 // Also, makes artifact test more solid - use one reclass for all of sub-models.
292 // Archive Structure will be:
293 // tar.gz
294 // ├── contexts
295 // │   └── ceph.yml
296 // ├── global_reclass <<< reclass system
297 // ├── model
298 // │   └── ceph <<< from `context basename`
299 // │   ├── classes
300 // │   │   ├── cluster
301 // │   │   └── system -> ../../../global_reclass
302 // │   └── nodes
303 // │   └── cfg01.ceph-cluster-domain.local.yml
304 dir(envPath) {
305 for (String context : contextList) {
306 def basename = common.GetBaseName(context, '.yml')
307 dir("${envPath}/model/${basename}") {
308 sh(script: 'mkdir -p classes/; ln -sfv ../../../../global_reclass classes/system ')
309 }
310 }
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400311 // replace all generated passwords/secrets/keys with hardcode value for infra/secrets.yaml
312 replaceGeneratedValues("${envPath}/model")
Denis Egorenkod8748942018-09-07 12:26:20 +0400313 // Save all models and all contexts. Warning! `h` flag must be used.
314 sh(script: "set -ex; tar -chzf ${archiveName} --exclude='*@tmp' model contexts", returnStatus: true)
315 archiveArtifacts artifacts: archiveName
316 // move for "Compare Pillars" stage
317 sh(script: "mv -v ${archiveName} ${env.WORKSPACE}")
318 }
azvyagintsev9df82e52018-09-06 19:17:18 +0300319}
320
azvyagintsev5c0313d2018-08-13 17:13:35 +0300321timeout(time: 1, unit: 'HOURS') {
322 node(slaveNode) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300323 globalVariatorsUpdate()
324 def gerritDataCCHEAD = [:]
azvyagintsev30bc82e2018-08-22 12:26:06 +0300325 def templateEnvHead = "${env.WORKSPACE}/EnvHead/"
326 def templateEnvPatched = "${env.WORKSPACE}/EnvPatched/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300327 def contextFileListHead = []
328 def contextFileListPatched = []
329 def vEnv = "${env.WORKSPACE}/venv"
Denis Egorenkod8748942018-09-07 12:26:20 +0400330 def headReclassArtifactName = "head_reclass.tar.gz"
331 def patchedReclassArtifactName = "patched_reclass.tar.gz"
332 def reclassNodeInfoDir = "${env.WORKSPACE}/reclassNodeInfo_compare/"
333 def reclassInfoHeadPath = "${reclassNodeInfoDir}/old"
334 def reclassInfoPatchedPath = "${reclassNodeInfoDir}/new"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300335 try {
336 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
337 stage('Download and prepare CC env') {
338 // Prepare 2 env - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300339 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300340 paralellEnvs.failFast = true
azvyagintsev9df82e52018-09-06 19:17:18 +0300341 paralellEnvs['downloadEnvPatched'] = StepPrepareGit(templateEnvPatched, gerritDataCC)
342 gerritDataCCHEAD << gerritDataCC
343 gerritDataCCHEAD['gerritRefSpec'] = null; gerritDataCCHEAD['GERRIT_CHANGE_NUMBER'] = null
344 paralellEnvs['downloadEnvHead'] = StepPrepareGit(templateEnvHead, gerritDataCCHEAD)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300345 parallel paralellEnvs
346 }
347 stage("Check workflow_definition") {
348 // Check only for patchset
349 python.setupVirtualenv(vEnv, 'python2', [], "${templateEnvPatched}/requirements.txt")
350 common.infoMsg(python.runVirtualenvCommand(vEnv, "python ${templateEnvPatched}/workflow_definition_test.py"))
351 }
352
353 stage("generate models") {
354 dir("${templateEnvHead}/contexts") {
355 for (String x : findFiles(glob: "*.yml")) {
356 contextFileListHead.add(x)
357 }
358 }
359 dir("${templateEnvPatched}/contexts") {
360 for (String x : findFiles(glob: "*.yml")) {
361 contextFileListPatched.add(x)
362 }
363 }
364 // Generate over 2env's - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300365 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300366 paralellEnvs.failFast = true
azvyagintsev30bc82e2018-08-22 12:26:06 +0300367 paralellEnvs['GenerateEnvPatched'] = StepGenerateModels(contextFileListPatched, vEnv, templateEnvPatched)
368 paralellEnvs['GenerateEnvHead'] = StepGenerateModels(contextFileListHead, vEnv, templateEnvHead)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300369 parallel paralellEnvs
370
371 // Collect artifacts
372 dir(templateEnvPatched) {
373 // Collect only models. For backward comparability - who know, probably someone use it..
374 sh(script: "tar -czf model.tar.gz -C model ../contexts .", returnStatus: true)
375 archiveArtifacts artifacts: "model.tar.gz"
376 }
377
azvyagintsev9df82e52018-09-06 19:17:18 +0300378 StepPrepareGit("${env.WORKSPACE}/global_reclass/", gerritDataRS).call()
azvyagintsev5c0313d2018-08-13 17:13:35 +0300379 // link all models, to use one global reclass
380 // For HEAD
Denis Egorenkod8748942018-09-07 12:26:20 +0400381 linkReclassModels(contextFileListHead, templateEnvHead, headReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300382 // For patched
Denis Egorenkod8748942018-09-07 12:26:20 +0400383 linkReclassModels(contextFileListPatched, templateEnvPatched, patchedReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300384 }
385
Denis Egorenkod8748942018-09-07 12:26:20 +0400386 stage("Compare cluster lvl Head/Patched") {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300387 // Compare patched and HEAD reclass pillars
Denis Egorenkod8748942018-09-07 12:26:20 +0400388 compareRoot = "${env.WORKSPACE}/cluster_compare/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300389 sh(script: """
390 mkdir -pv ${compareRoot}/new ${compareRoot}/old
Denis Egorenkod8748942018-09-07 12:26:20 +0400391 tar -xzf ${patchedReclassArtifactName} --directory ${compareRoot}/new
392 tar -xzf ${headReclassArtifactName} --directory ${compareRoot}/old
azvyagintsev5c0313d2018-08-13 17:13:35 +0300393 """)
394 common.warningMsg('infra/secrets.yml has been skipped from compare!')
azvyagintsevb266ad22018-09-11 12:11:11 +0300395 result = '\n' + common.comparePillars(compareRoot, env.BUILD_URL, "-Ev \'infra/secrets.yml\'")
Denis Egorenkod8748942018-09-07 12:26:20 +0400396 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300397 }
Denis Egorenkod8748942018-09-07 12:26:20 +0400398 stage("TestContexts Head/Patched") {
399 def stepsForParallel = [:]
400 stepsForParallel.failFast = true
401 common.infoMsg("Found: ${contextFileListHead.size()} HEAD contexts to test.")
402 for (String context : contextFileListHead) {
403 def basename = common.GetBaseName(context, '.yml')
404 stepsForParallel.put("ContextHeadTest:${basename}", StepTestModel(basename, headReclassArtifactName, reclassInfoHeadPath))
405 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300406 common.infoMsg("Found: ${contextFileListPatched.size()} patched contexts to test.")
407 for (String context : contextFileListPatched) {
408 def basename = common.GetBaseName(context, '.yml')
Denis Egorenkod8748942018-09-07 12:26:20 +0400409 stepsForParallel.put("ContextPatchedTest:${basename}", StepTestModel(basename, patchedReclassArtifactName, reclassInfoPatchedPath))
azvyagintsev5c0313d2018-08-13 17:13:35 +0300410 }
411 parallel stepsForParallel
Denis Egorenkod8748942018-09-07 12:26:20 +0400412 common.infoMsg('All TestContexts tests done')
413 }
414 stage("Compare NodesInfo Head/Patched") {
415 // Download all artifacts
416 def stepsForParallel = [:]
417 stepsForParallel.failFast = true
418 common.infoMsg("Found: ${testModelBuildsData.size()} nodeinfo artifacts to download.")
419 testModelBuildsData.each { bname, bdata ->
420 stepsForParallel.put("FetchData:${bname}",
421 getAndUnpackNodesInfoArtifact(bdata.jobname, bdata.copyToDir, bdata.buildId))
422 }
423 parallel stepsForParallel
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400424 // remove timestamp field from rendered files
425 sh("find ${reclassNodeInfoDir} -type f -exec sed -i '/ timestamp: .*/d' {} \\;")
Denis Egorenkod8748942018-09-07 12:26:20 +0400426 // Compare patched and HEAD reclass pillars
427 result = '\n' + common.comparePillars(reclassNodeInfoDir, env.BUILD_URL, '')
428 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300429 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300430 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
431
432 } catch (Throwable e) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300433 if (alreadyMerged) {
434 currentBuild.result = 'ABORTED'
435 currentBuild.description = "Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them"
436 return
437 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300438 currentBuild.result = "FAILURE"
439 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
440 throw e
441 } finally {
442 def dummy = "dummy"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300443 }
444 }
chnydae80bb922017-05-29 17:48:40 +0200445}