blob: cee90d1274ad5d8a7c81d3b6a89c0ad838b4bcae [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
Alexander Evseev02fe5eb2018-11-15 13:58:36 +010015import groovy.json.JsonOutput
16
chnydae80bb922017-05-29 17:48:40 +020017common = new com.mirantis.mk.Common()
chnydabc63c9a2017-05-30 15:37:54 +020018gerrit = new com.mirantis.mk.Gerrit()
chnydae80bb922017-05-29 17:48:40 +020019git = new com.mirantis.mk.Git()
20python = new com.mirantis.mk.Python()
chnydae80bb922017-05-29 17:48:40 +020021
Denis Egorenkod67a6d22018-10-18 16:00:46 +040022extraVarsYAML = env.EXTRA_VARIABLES_YAML.trim() ?: ''
Denis Egorenko535d5b62018-09-28 11:28:10 +040023if (extraVarsYAML) {
24 common.mergeEnv(env, extraVarsYAML)
Alexander Evseev02fe5eb2018-11-15 13:58:36 +010025 extraVars = readYaml text: extraVarsYAML
26} else {
27 extraVars = [:]
Denis Egorenko535d5b62018-09-28 11:28:10 +040028}
29
azvyagintsev3a80e342018-09-19 19:22:48 +030030slaveNode = env.SLAVE_NODE ?: 'docker'
azvyagintseve7b8e792018-09-21 17:27:01 +030031checkIncludeOrder = env.CHECK_INCLUDE_ORDER ?: false
azvyagintsev5c0313d2018-08-13 17:13:35 +030032
azvyagintsev9df82e52018-09-06 19:17:18 +030033// Global var's
34alreadyMerged = false
35gerritConData = [credentialsId : env.CREDENTIALS_ID,
36 gerritName : env.GERRIT_NAME ?: 'mcp-jenkins',
Roman Vyalovf0c596e2018-10-01 17:56:09 +030037 gerritHost : env.GERRIT_HOST ?: 'gerrit.mcp.mirantis.com',
azvyagintsevb266ad22018-09-11 12:11:11 +030038 gerritScheme : env.GERRIT_SCHEME ?: 'ssh',
39 gerritPort : env.GERRIT_PORT ?: '29418',
azvyagintsev9df82e52018-09-06 19:17:18 +030040 gerritRefSpec : null,
41 gerritProject : null,
42 withWipeOut : true,
43 GERRIT_CHANGE_NUMBER: null]
44//
Roman Vyalovf0c596e2018-10-01 17:56:09 +030045//ccTemplatesRepo = env.COOKIECUTTER_TEMPLATE_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.com:29418/mk/cookiecutter-templates'
azvyagintsev3a80e342018-09-19 19:22:48 +030046gerritDataCCHEAD = [:]
azvyagintsev9df82e52018-09-06 19:17:18 +030047gerritDataCC = [:]
48gerritDataCC << gerritConData
49gerritDataCC['gerritBranch'] = env.COOKIECUTTER_TEMPLATE_BRANCH ?: 'master'
azvyagintsev458278c2018-09-25 18:38:30 +030050gerritDataCC['gerritRefSpec'] = env.COOKIECUTTER_TEMPLATE_REF ?: null
azvyagintsev9df82e52018-09-06 19:17:18 +030051gerritDataCC['gerritProject'] = 'mk/cookiecutter-templates'
52//
Roman Vyalovf0c596e2018-10-01 17:56:09 +030053//reclassSystemRepo = env.RECLASS_SYSTEM_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.com:29418/salt-models/reclass-system'
azvyagintsev3a80e342018-09-19 19:22:48 +030054gerritDataRSHEAD = [:]
azvyagintsev9df82e52018-09-06 19:17:18 +030055gerritDataRS = [:]
56gerritDataRS << gerritConData
Denis Egorenkoe7040ac2018-10-24 20:11:04 +040057gerritDataRS['gerritBranch'] = env.RECLASS_SYSTEM_BRANCH ?: 'master'
azvyagintsev458278c2018-09-25 18:38:30 +030058gerritDataRS['gerritRefSpec'] = env.RECLASS_SYSTEM_GIT_REF ?: null
azvyagintsev9df82e52018-09-06 19:17:18 +030059gerritDataRS['gerritProject'] = 'salt-models/reclass-system'
60
azvyagintsevec055b42018-10-11 12:59:05 +030061// version of debRepos, aka formulas|reclass|ubuntu
azvyagintsev10e24012018-09-10 21:36:32 +030062testDistribRevision = env.DISTRIB_REVISION ?: 'nightly'
Denis Egorenko086aff12018-10-18 17:54:59 +040063
Denis Egorenkod8748942018-09-07 12:26:20 +040064// Name of sub-test chunk job
65chunkJobName = "test-mk-cookiecutter-templates-chunk"
66testModelBuildsData = [:]
Vasyl Saienko772e1232018-07-23 14:42:24 +030067
Denis Egorenkod8748942018-09-07 12:26:20 +040068def getAndUnpackNodesInfoArtifact(jobName, copyTo, build) {
69 return {
70 dir(copyTo) {
71 copyArtifacts(projectName: jobName, selector: specific(build), filter: "nodesinfo.tar.gz")
azvyagintsev3a80e342018-09-19 19:22:48 +030072 sh "tar -xf nodesinfo.tar.gz"
Denis Egorenkod8748942018-09-07 12:26:20 +040073 sh "rm -v nodesinfo.tar.gz"
74 }
75 }
76}
azvyagintsev87985532018-07-10 20:49:38 +030077
Denis Egorenko086aff12018-10-18 17:54:59 +040078def testModel(modelFile, reclassArtifactName, artifactCopyPath, useExtraRepos = false) {
azvyagintsev5c0313d2018-08-13 17:13:35 +030079 // modelFile - `modelfiname` from model/modelfiname/modelfiname.yaml
80 //* Grub all models and send it to check in paralell - by one in thread.
Denis Egorenkod8748942018-09-07 12:26:20 +040081 def _uuid = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}_${modelFile.toLowerCase()}_" + UUID.randomUUID().toString().take(8)
Alexander Evseev02fe5eb2018-11-15 13:58:36 +010082 def _values = [
83 MODELS_TARGZ: "${env.BUILD_URL}/artifact/${reclassArtifactName}",
84 DockerCName: _uuid,
85 testReclassEnv: "model/${modelFile}/",
86 modelFile: "contexts/${modelFile}.yml",
87 DISTRIB_REVISION: testDistribRevision,
88 useExtraRepos: useExtraRepos,
89 ]
90 def _values_string = JsonOutput.toJson(_values << extraVars)
Denis Egorenkod8748942018-09-07 12:26:20 +040091 def chunkJob = build job: chunkJobName, parameters: [
azvyagintsev08b34e32018-09-12 12:29:42 +030092 [$class: 'TextParameterValue', name: 'EXTRA_VARIABLES_YAML',
azvyagintsev30bc82e2018-08-22 12:26:06 +030093 value : _values_string.stripIndent()],
azvyagintsev5c0313d2018-08-13 17:13:35 +030094 ]
Denis Egorenkod8748942018-09-07 12:26:20 +040095 // Put sub-job info into global map.
96 testModelBuildsData.put(_uuid, ['jobname' : chunkJob.fullProjectName,
97 'copyToDir': "${artifactCopyPath}/${modelFile}",
98 'buildId' : "${chunkJob.number}"])
chnydabc63c9a2017-05-30 15:37:54 +020099}
100
Denis Egorenko086aff12018-10-18 17:54:59 +0400101def StepTestModel(basename, reclassArtifactName, artifactCopyPath, useExtraRepos = false) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300102 // We need to wrap what we return in a Groovy closure, or else it's invoked
103 // when this method is called, not when we pass it to parallel.
104 // To do this, you need to wrap the code below in { }, and either return
105 // that explicitly, or use { -> } syntax.
106 // return node object
107 return {
108 node(slaveNode) {
Denis Egorenko086aff12018-10-18 17:54:59 +0400109 testModel(basename, reclassArtifactName, artifactCopyPath, useExtraRepos)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300110 }
chnydae80bb922017-05-29 17:48:40 +0200111 }
azvyagintsev87985532018-07-10 20:49:38 +0300112}
113
azvyagintsev9df82e52018-09-06 19:17:18 +0300114def StepPrepareGit(templateEnvFolder, gerrit_data) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300115 // return git clone object
116 return {
azvyagintsev9df82e52018-09-06 19:17:18 +0300117 def checkouted = false
118 common.infoMsg("StepPrepareGit: ${gerrit_data}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300119 // fetch needed sources
120 dir(templateEnvFolder) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300121 if (gerrit_data['gerritRefSpec']) {
122 // Those part might be not work,in case manual var's pass
123 def gerritChange = gerrit.getGerritChange(gerrit_data['gerritName'], gerrit_data['gerritHost'],
124 gerrit_data['GERRIT_CHANGE_NUMBER'], gerrit_data['credentialsId'])
azvyagintsev5c0313d2018-08-13 17:13:35 +0300125 merged = gerritChange.status == "MERGED"
126 if (!merged) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300127 checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300128 } else {
azvyagintsev9df82e52018-09-06 19:17:18 +0300129 // update global variable for pretty return from pipeline
130 alreadyMerged = true
131 common.successMsg("Change ${gerrit_data['GERRIT_CHANGE_NUMBER']} is already merged, no need to gate them")
132 error('change already merged')
azvyagintsev87985532018-07-10 20:49:38 +0300133 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300134 } else {
azvyagintsev9df82e52018-09-06 19:17:18 +0300135 // Get clean HEAD
136 gerrit_data['useGerritTriggerBuildChooser'] = false
137 checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
138 if (!checkouted) {
139 error("Failed to get repo:${gerrit_data}")
140 }
azvyagintsev87985532018-07-10 20:49:38 +0300141 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300142 }
azvyagintsev87985532018-07-10 20:49:38 +0300143 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300144}
145
146def StepGenerateModels(_contextFileList, _virtualenv, _templateEnvDir) {
147 return {
148 for (contextFile in _contextFileList) {
Denis Egorenkof3469092018-10-17 17:05:50 +0400149 def basename = common.GetBaseName(contextFile, '.yml')
150 def context = readFile(file: "${_templateEnvDir}/contexts/${contextFile}")
151 python.generateModel(context, basename, 'cfg01', _virtualenv, "${_templateEnvDir}/model", _templateEnvDir)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300152 }
153 }
154}
155
azvyagintsev9df82e52018-09-06 19:17:18 +0300156def globalVariatorsUpdate() {
157 // Simple function, to check and define branch-around variables
158 // In general, simply make transition updates for non-master branch
159 // based on magic logic
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400160 def newline = '<br/>'
161 def messages = []
azvyagintsevb266ad22018-09-11 12:11:11 +0300162 if (env.GERRIT_PROJECT) {
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400163 messages.add("<font color='red'>GerritTrigger detected! We are in auto-mode:</font>")
164 messages.add("Test env variables has been changed:")
azvyagintseve0eb6cd2018-09-12 13:00:40 +0300165 // TODO are we going to have such branches?
azvyagintsev9df82e52018-09-06 19:17:18 +0300166 if (!['nightly', 'testing', 'stable', 'proposed', 'master'].contains(env.GERRIT_BRANCH)) {
167 gerritDataCC['gerritBranch'] = env.GERRIT_BRANCH
168 gerritDataRS['gerritBranch'] = env.GERRIT_BRANCH
azvyagintsev458278c2018-09-25 18:38:30 +0300169 testDistribRevision = env.GERRIT_BRANCH
azvyagintsev9df82e52018-09-06 19:17:18 +0300170 }
Denis Egorenko60e45c12018-11-12 12:00:11 +0400171 messages.add("COOKIECUTTER_TEMPLATE_BRANCH => ${gerritDataCC['gerritBranch']}")
172 messages.add("RECLASS_SYSTEM_BRANCH => ${gerritDataRS['gerritBranch']}")
azvyagintsev9df82e52018-09-06 19:17:18 +0300173 // Identify, who triggered. To whom we should pass refspec
174 if (env.GERRIT_PROJECT == 'salt-models/reclass-system') {
175 gerritDataRS['gerritRefSpec'] = env.GERRIT_REFSPEC
176 gerritDataRS['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400177 messages.add("RECLASS_SYSTEM_GIT_REF => ${gerritDataRS['gerritRefSpec']}")
azvyagintsev9df82e52018-09-06 19:17:18 +0300178 } else if (env.GERRIT_PROJECT == 'mk/cookiecutter-templates') {
179 gerritDataCC['gerritRefSpec'] = env.GERRIT_REFSPEC
180 gerritDataCC['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400181 messages.add("COOKIECUTTER_TEMPLATE_REF => ${gerritDataCC['gerritRefSpec']}")
azvyagintsev9df82e52018-09-06 19:17:18 +0300182 } else {
183 error("Unsuported gerrit-project triggered:${env.GERRIT_PROJECT}")
184 }
azvyagintsev9df82e52018-09-06 19:17:18 +0300185 } else {
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400186 messages.add("<font color='red'>Non-gerrit trigger run detected!</font>")
azvyagintsev9df82e52018-09-06 19:17:18 +0300187 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300188 gerritDataCCHEAD << gerritDataCC
189 gerritDataCCHEAD['gerritRefSpec'] = null
190 gerritDataCCHEAD['GERRIT_CHANGE_NUMBER'] = null
191 gerritDataRSHEAD << gerritDataRS
192 gerritDataRSHEAD['gerritRefSpec'] = null
193 gerritDataRSHEAD['GERRIT_CHANGE_NUMBER'] = null
azvyagintsev458278c2018-09-25 18:38:30 +0300194 // 'binary' branch logic w\o 'release/' prefix
195 if (testDistribRevision.contains('/')) {
196 testDistribRevision = testDistribRevision.split('/')[-1]
197 }
198 // Check if we are going to test bleeding-edge release, which doesn't have binary release yet
199 if (!common.checkRemoteBinary([apt_mk_version: testDistribRevision]).linux_system_repo_url) {
200 common.errorMsg("Binary release: ${testDistribRevision} not exist. Fallback to 'proposed'! ")
201 testDistribRevision = 'proposed'
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400202 messages.add("DISTRIB_REVISION => ${testDistribRevision}")
azvyagintsev458278c2018-09-25 18:38:30 +0300203 }
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400204 def message = messages.join(newline) + newline
azvyagintsev458278c2018-09-25 18:38:30 +0300205 currentBuild.description = currentBuild.description ? message + currentBuild.description : message
Denis Egorenkod8748942018-09-07 12:26:20 +0400206}
azvyagintsev9df82e52018-09-06 19:17:18 +0300207
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400208def replaceGeneratedValues(path) {
209 def files = sh(script: "find ${path} -name 'secrets.yml'", returnStdout: true)
210 def stepsForParallel = [:]
211 stepsForParallel.failFast = true
212 files.tokenize().each {
213 stepsForParallel.put("Removing generated passwords/secrets from ${it}",
214 {
215 def secrets = readYaml file: it
azvyagintsev08b34e32018-09-12 12:29:42 +0300216 for (String key in secrets['parameters']['_param'].keySet()) {
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400217 secrets['parameters']['_param'][key] = 'generated'
218 }
219 // writeYaml can't write to already existing file
220 writeYaml file: "${it}.tmp", data: secrets
221 sh "mv ${it}.tmp ${it}"
222 })
223 }
224 parallel stepsForParallel
225}
226
Denis Egorenkod8748942018-09-07 12:26:20 +0400227def linkReclassModels(contextList, envPath, archiveName) {
228 // to be able share reclass for all subenvs
229 // Also, makes artifact test more solid - use one reclass for all of sub-models.
230 // Archive Structure will be:
231 // tar.gz
232 // ├── contexts
233 // │   └── ceph.yml
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400234 // ├── classes-system <<< reclass system
Denis Egorenkod8748942018-09-07 12:26:20 +0400235 // ├── model
236 // │   └── ceph <<< from `context basename`
237 // │   ├── classes
238 // │   │   ├── cluster
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400239 // │   │   └── system -> ../../../classes-system
Denis Egorenkod8748942018-09-07 12:26:20 +0400240 // │   └── nodes
241 // │   └── cfg01.ceph-cluster-domain.local.yml
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400242 def archiveBaseName = common.GetBaseName(archiveName, '.tar.gz')
243 def classesSystemDir = 'classes-system'
244 // copy reclass system under envPath with -R and trailing / to support symlinks direct copy
245 sh("cp -R ${archiveBaseName}/ ${envPath}/${classesSystemDir}")
Denis Egorenkod8748942018-09-07 12:26:20 +0400246 dir(envPath) {
247 for (String context : contextList) {
248 def basename = common.GetBaseName(context, '.yml')
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400249 dir("${envPath}/model/${basename}/classes") {
250 sh(script: "ln -sfv ../../../${classesSystemDir} system ")
Denis Egorenkod8748942018-09-07 12:26:20 +0400251 }
252 }
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400253 // replace all generated passwords/secrets/keys with hardcode value for infra/secrets.yaml
254 replaceGeneratedValues("${envPath}/model")
azvyagintsev3a80e342018-09-19 19:22:48 +0300255 // Save all models and all contexts. Warning! `h` flag must be used!
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400256 sh(script: "set -ex; tar -czhf ${env.WORKSPACE}/${archiveName} --exclude='*@tmp' contexts model ${classesSystemDir}", returnStatus: true)
Denis Egorenkod8748942018-09-07 12:26:20 +0400257 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300258 archiveArtifacts artifacts: archiveName
azvyagintsev9df82e52018-09-06 19:17:18 +0300259}
260
azvyagintsev5c0313d2018-08-13 17:13:35 +0300261timeout(time: 1, unit: 'HOURS') {
262 node(slaveNode) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300263 globalVariatorsUpdate()
azvyagintsev30bc82e2018-08-22 12:26:06 +0300264 def templateEnvHead = "${env.WORKSPACE}/EnvHead/"
265 def templateEnvPatched = "${env.WORKSPACE}/EnvPatched/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300266 def contextFileListHead = []
267 def contextFileListPatched = []
268 def vEnv = "${env.WORKSPACE}/venv"
Denis Egorenkod8748942018-09-07 12:26:20 +0400269 def headReclassArtifactName = "head_reclass.tar.gz"
270 def patchedReclassArtifactName = "patched_reclass.tar.gz"
271 def reclassNodeInfoDir = "${env.WORKSPACE}/reclassNodeInfo_compare/"
272 def reclassInfoHeadPath = "${reclassNodeInfoDir}/old"
273 def reclassInfoPatchedPath = "${reclassNodeInfoDir}/new"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300274 try {
275 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
276 stage('Download and prepare CC env') {
277 // Prepare 2 env - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300278 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300279 paralellEnvs.failFast = true
azvyagintsev9df82e52018-09-06 19:17:18 +0300280 paralellEnvs['downloadEnvHead'] = StepPrepareGit(templateEnvHead, gerritDataCCHEAD)
azvyagintsev3a80e342018-09-19 19:22:48 +0300281 if (gerritDataCC.get('gerritRefSpec', null)) {
282 paralellEnvs['downloadEnvPatched'] = StepPrepareGit(templateEnvPatched, gerritDataCC)
283 parallel paralellEnvs
284 } else {
285 paralellEnvs['downloadEnvPatched'] = { common.warningMsg('No need to process: downloadEnvPatched') }
286 parallel paralellEnvs
287 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
288 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300289 }
290 stage("Check workflow_definition") {
291 // Check only for patchset
292 python.setupVirtualenv(vEnv, 'python2', [], "${templateEnvPatched}/requirements.txt")
azvyagintsev3a80e342018-09-19 19:22:48 +0300293 if (gerritDataCC.get('gerritRefSpec', null)) {
294 common.infoMsg(python.runVirtualenvCommand(vEnv, "python ${templateEnvPatched}/workflow_definition_test.py"))
295 } else {
296 common.infoMsg('No need to process: workflow_definition')
297 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300298 }
299
300 stage("generate models") {
301 dir("${templateEnvHead}/contexts") {
302 for (String x : findFiles(glob: "*.yml")) {
303 contextFileListHead.add(x)
304 }
305 }
306 dir("${templateEnvPatched}/contexts") {
307 for (String x : findFiles(glob: "*.yml")) {
308 contextFileListPatched.add(x)
309 }
310 }
311 // Generate over 2env's - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300312 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300313 paralellEnvs.failFast = true
azvyagintsev30bc82e2018-08-22 12:26:06 +0300314 paralellEnvs['GenerateEnvHead'] = StepGenerateModels(contextFileListHead, vEnv, templateEnvHead)
azvyagintsev3a80e342018-09-19 19:22:48 +0300315 if (gerritDataCC.get('gerritRefSpec', null)) {
316 paralellEnvs['GenerateEnvPatched'] = StepGenerateModels(contextFileListPatched, vEnv, templateEnvPatched)
317 parallel paralellEnvs
318 } else {
319 paralellEnvs['GenerateEnvPatched'] = { common.warningMsg('No need to process: GenerateEnvPatched') }
320 parallel paralellEnvs
321 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300322 }
323
azvyagintsev3a80e342018-09-19 19:22:48 +0300324 // We need 2 git's, one for HEAD, one for PATCHed.
325 // if no patch, use head for both
326 RSHeadDir = common.GetBaseName(headReclassArtifactName, '.tar.gz')
327 RSPatchedDir = common.GetBaseName(patchedReclassArtifactName, '.tar.gz')
328 common.infoMsg("gerritDataRS= ${gerritDataRS}")
329 common.infoMsg("gerritDataRSHEAD= ${gerritDataRSHEAD}")
330 if (gerritDataRS.get('gerritRefSpec', null)) {
331 StepPrepareGit("${env.WORKSPACE}/${RSPatchedDir}/", gerritDataRS).call()
332 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRSHEAD).call()
333 } else {
334 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRS).call()
335 sh("cd ${env.WORKSPACE} ; ln -svf ${RSHeadDir} ${RSPatchedDir}")
336 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300337 // link all models, to use one global reclass
338 // For HEAD
Denis Egorenkod8748942018-09-07 12:26:20 +0400339 linkReclassModels(contextFileListHead, templateEnvHead, headReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300340 // For patched
Denis Egorenkod8748942018-09-07 12:26:20 +0400341 linkReclassModels(contextFileListPatched, templateEnvPatched, patchedReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300342 }
343
Denis Egorenkod8748942018-09-07 12:26:20 +0400344 stage("Compare cluster lvl Head/Patched") {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300345 // Compare patched and HEAD reclass pillars
Denis Egorenkod8748942018-09-07 12:26:20 +0400346 compareRoot = "${env.WORKSPACE}/cluster_compare/"
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400347 // extract archive and drop all copied classes/system before comparing
azvyagintsev5c0313d2018-08-13 17:13:35 +0300348 sh(script: """
349 mkdir -pv ${compareRoot}/new ${compareRoot}/old
Denis Egorenkod8748942018-09-07 12:26:20 +0400350 tar -xzf ${patchedReclassArtifactName} --directory ${compareRoot}/new
351 tar -xzf ${headReclassArtifactName} --directory ${compareRoot}/old
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400352 find ${compareRoot} -name classes -type d -exec rm -rf '{}/system' \\;
azvyagintsev5c0313d2018-08-13 17:13:35 +0300353 """)
354 common.warningMsg('infra/secrets.yml has been skipped from compare!')
azvyagintsev3a80e342018-09-19 19:22:48 +0300355 result = '\n' + common.comparePillars(compareRoot, env.BUILD_URL, "-Ev \'infra/secrets.yml|\\.git\'")
Denis Egorenkod8748942018-09-07 12:26:20 +0400356 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300357 }
Denis Egorenkod8748942018-09-07 12:26:20 +0400358 stage("TestContexts Head/Patched") {
359 def stepsForParallel = [:]
360 stepsForParallel.failFast = true
361 common.infoMsg("Found: ${contextFileListHead.size()} HEAD contexts to test.")
362 for (String context : contextFileListHead) {
363 def basename = common.GetBaseName(context, '.yml')
364 stepsForParallel.put("ContextHeadTest:${basename}", StepTestModel(basename, headReclassArtifactName, reclassInfoHeadPath))
365 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300366 common.infoMsg("Found: ${contextFileListPatched.size()} patched contexts to test.")
367 for (String context : contextFileListPatched) {
368 def basename = common.GetBaseName(context, '.yml')
Denis Egorenko086aff12018-10-18 17:54:59 +0400369 stepsForParallel.put("ContextPatchedTest:${basename}", StepTestModel(basename, patchedReclassArtifactName, reclassInfoPatchedPath, true))
azvyagintsev5c0313d2018-08-13 17:13:35 +0300370 }
371 parallel stepsForParallel
Denis Egorenkod8748942018-09-07 12:26:20 +0400372 common.infoMsg('All TestContexts tests done')
373 }
374 stage("Compare NodesInfo Head/Patched") {
375 // Download all artifacts
376 def stepsForParallel = [:]
377 stepsForParallel.failFast = true
378 common.infoMsg("Found: ${testModelBuildsData.size()} nodeinfo artifacts to download.")
379 testModelBuildsData.each { bname, bdata ->
380 stepsForParallel.put("FetchData:${bname}",
381 getAndUnpackNodesInfoArtifact(bdata.jobname, bdata.copyToDir, bdata.buildId))
382 }
383 parallel stepsForParallel
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400384 // remove timestamp field from rendered files
385 sh("find ${reclassNodeInfoDir} -type f -exec sed -i '/ timestamp: .*/d' {} \\;")
Denis Egorenkod8748942018-09-07 12:26:20 +0400386 // Compare patched and HEAD reclass pillars
387 result = '\n' + common.comparePillars(reclassNodeInfoDir, env.BUILD_URL, '')
388 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300389 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400390 stage('Check include order') {
azvyagintseve7b8e792018-09-21 17:27:01 +0300391 if (!checkIncludeOrder) {
392 common.infoMsg('Check include order require to much time, and currently disabled!')
393
394 } else {
395 def correctIncludeOrder = ["service", "system", "cluster"]
396 dir(reclassInfoPatchedPath) {
397 def nodeInfoFiles = findFiles(glob: "**/*.reclass.nodeinfo")
398 def messages = ["<b>Wrong include ordering found</b><ul>"]
399 def stepsForParallel = [:]
400 nodeInfoFiles.each { nodeInfo ->
401 stepsForParallel.put("Checking ${nodeInfo.path}:", {
402 def node = readYaml file: nodeInfo.path
403 def classes = node['classes']
404 def curClassID = 0
405 def prevClassID = 0
406 def wrongOrder = false
407 for (String className in classes) {
408 def currentClass = className.tokenize('.')[0]
409 curClassID = correctIncludeOrder.indexOf(currentClass)
410 if (currentClass != correctIncludeOrder[prevClassID]) {
411 if (prevClassID > curClassID) {
412 wrongOrder = true
413 common.warningMsg("File ${nodeInfo.path} contains wrong order of classes including: Includes for ${className} should be declared before ${correctIncludeOrder[prevClassID]} includes")
414 } else {
415 prevClassID = curClassID
416 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400417 }
418 }
azvyagintseve7b8e792018-09-21 17:27:01 +0300419 if (wrongOrder) {
420 messages.add("<li>${nodeInfo.path} contains wrong order of classes including</li>")
421 }
422 })
423 }
424 parallel stepsForParallel
425 def includerOrder = '<b>No wrong include order</b>'
426 if (messages.size() != 1) {
427 includerOrder = messages.join('')
428 }
429 currentBuild.description = currentBuild.description ? currentBuild.description + includerOrder : includerOrder
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400430 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400431 }
432 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300433 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
434
435 } catch (Throwable e) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300436 if (alreadyMerged) {
437 currentBuild.result = 'ABORTED'
438 currentBuild.description = "Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them"
439 return
440 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300441 currentBuild.result = "FAILURE"
442 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
443 throw e
444 } finally {
445 def dummy = "dummy"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300446 }
447 }
chnydae80bb922017-05-29 17:48:40 +0200448}