blob: bd3373cfdf8ae011e25f3adf03d6c0083c849845 [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
Denis Egorenkod67a6d22018-10-18 16:00:46 +040020extraVarsYAML = env.EXTRA_VARIABLES_YAML.trim() ?: ''
Denis Egorenko535d5b62018-09-28 11:28:10 +040021if (extraVarsYAML) {
22 common.mergeEnv(env, extraVarsYAML)
23}
24
azvyagintsev3a80e342018-09-19 19:22:48 +030025slaveNode = env.SLAVE_NODE ?: 'docker'
azvyagintseve7b8e792018-09-21 17:27:01 +030026checkIncludeOrder = env.CHECK_INCLUDE_ORDER ?: false
azvyagintsev5c0313d2018-08-13 17:13:35 +030027
azvyagintsev9df82e52018-09-06 19:17:18 +030028// Global var's
29alreadyMerged = false
30gerritConData = [credentialsId : env.CREDENTIALS_ID,
31 gerritName : env.GERRIT_NAME ?: 'mcp-jenkins',
Roman Vyalovf0c596e2018-10-01 17:56:09 +030032 gerritHost : env.GERRIT_HOST ?: 'gerrit.mcp.mirantis.com',
azvyagintsevb266ad22018-09-11 12:11:11 +030033 gerritScheme : env.GERRIT_SCHEME ?: 'ssh',
34 gerritPort : env.GERRIT_PORT ?: '29418',
azvyagintsev9df82e52018-09-06 19:17:18 +030035 gerritRefSpec : null,
36 gerritProject : null,
37 withWipeOut : true,
38 GERRIT_CHANGE_NUMBER: null]
39//
Roman Vyalovf0c596e2018-10-01 17:56:09 +030040//ccTemplatesRepo = env.COOKIECUTTER_TEMPLATE_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.com:29418/mk/cookiecutter-templates'
azvyagintsev3a80e342018-09-19 19:22:48 +030041gerritDataCCHEAD = [:]
azvyagintsev9df82e52018-09-06 19:17:18 +030042gerritDataCC = [:]
43gerritDataCC << gerritConData
44gerritDataCC['gerritBranch'] = env.COOKIECUTTER_TEMPLATE_BRANCH ?: 'master'
azvyagintsev458278c2018-09-25 18:38:30 +030045gerritDataCC['gerritRefSpec'] = env.COOKIECUTTER_TEMPLATE_REF ?: null
azvyagintsev9df82e52018-09-06 19:17:18 +030046gerritDataCC['gerritProject'] = 'mk/cookiecutter-templates'
47//
Roman Vyalovf0c596e2018-10-01 17:56:09 +030048//reclassSystemRepo = env.RECLASS_SYSTEM_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.com:29418/salt-models/reclass-system'
azvyagintsev3a80e342018-09-19 19:22:48 +030049gerritDataRSHEAD = [:]
azvyagintsev9df82e52018-09-06 19:17:18 +030050gerritDataRS = [:]
51gerritDataRS << gerritConData
Denis Egorenkoe7040ac2018-10-24 20:11:04 +040052gerritDataRS['gerritBranch'] = env.RECLASS_SYSTEM_BRANCH ?: 'master'
azvyagintsev458278c2018-09-25 18:38:30 +030053gerritDataRS['gerritRefSpec'] = env.RECLASS_SYSTEM_GIT_REF ?: null
azvyagintsev9df82e52018-09-06 19:17:18 +030054gerritDataRS['gerritProject'] = 'salt-models/reclass-system'
55
azvyagintsevec055b42018-10-11 12:59:05 +030056// version of debRepos, aka formulas|reclass|ubuntu
azvyagintsev10e24012018-09-10 21:36:32 +030057testDistribRevision = env.DISTRIB_REVISION ?: 'nightly'
Denis Egorenko086aff12018-10-18 17:54:59 +040058
Denis Egorenkod8748942018-09-07 12:26:20 +040059// Name of sub-test chunk job
60chunkJobName = "test-mk-cookiecutter-templates-chunk"
61testModelBuildsData = [:]
Vasyl Saienko772e1232018-07-23 14:42:24 +030062
Denis Egorenkod8748942018-09-07 12:26:20 +040063def getAndUnpackNodesInfoArtifact(jobName, copyTo, build) {
64 return {
65 dir(copyTo) {
66 copyArtifacts(projectName: jobName, selector: specific(build), filter: "nodesinfo.tar.gz")
azvyagintsev3a80e342018-09-19 19:22:48 +030067 sh "tar -xf nodesinfo.tar.gz"
Denis Egorenkod8748942018-09-07 12:26:20 +040068 sh "rm -v nodesinfo.tar.gz"
69 }
70 }
71}
azvyagintsev87985532018-07-10 20:49:38 +030072
Denis Egorenko086aff12018-10-18 17:54:59 +040073def testModel(modelFile, reclassArtifactName, artifactCopyPath, useExtraRepos = false) {
azvyagintsev5c0313d2018-08-13 17:13:35 +030074 // modelFile - `modelfiname` from model/modelfiname/modelfiname.yaml
75 //* Grub all models and send it to check in paralell - by one in thread.
Denis Egorenkod8748942018-09-07 12:26:20 +040076 def _uuid = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}_${modelFile.toLowerCase()}_" + UUID.randomUUID().toString().take(8)
77 def _values_string = """
Denis Egorenko086aff12018-10-18 17:54:59 +040078---
79MODELS_TARGZ: "${env.BUILD_URL}/artifact/${reclassArtifactName}"
80DockerCName: "${_uuid}"
81testReclassEnv: "model/${modelFile}/"
82modelFile: "contexts/${modelFile}.yml"
83DISTRIB_REVISION: "${testDistribRevision}"
84useExtraRepos: ${useExtraRepos}
85${extraVarsYAML.replaceAll('---', '')}
86"""
Denis Egorenkod8748942018-09-07 12:26:20 +040087 def chunkJob = build job: chunkJobName, parameters: [
azvyagintsev08b34e32018-09-12 12:29:42 +030088 [$class: 'TextParameterValue', name: 'EXTRA_VARIABLES_YAML',
azvyagintsev30bc82e2018-08-22 12:26:06 +030089 value : _values_string.stripIndent()],
azvyagintsev5c0313d2018-08-13 17:13:35 +030090 ]
Denis Egorenkod8748942018-09-07 12:26:20 +040091 // Put sub-job info into global map.
92 testModelBuildsData.put(_uuid, ['jobname' : chunkJob.fullProjectName,
93 'copyToDir': "${artifactCopyPath}/${modelFile}",
94 'buildId' : "${chunkJob.number}"])
chnydabc63c9a2017-05-30 15:37:54 +020095}
96
Denis Egorenko086aff12018-10-18 17:54:59 +040097def StepTestModel(basename, reclassArtifactName, artifactCopyPath, useExtraRepos = false) {
azvyagintsev5c0313d2018-08-13 17:13:35 +030098 // We need to wrap what we return in a Groovy closure, or else it's invoked
99 // when this method is called, not when we pass it to parallel.
100 // To do this, you need to wrap the code below in { }, and either return
101 // that explicitly, or use { -> } syntax.
102 // return node object
103 return {
104 node(slaveNode) {
Denis Egorenko086aff12018-10-18 17:54:59 +0400105 testModel(basename, reclassArtifactName, artifactCopyPath, useExtraRepos)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300106 }
chnydae80bb922017-05-29 17:48:40 +0200107 }
azvyagintsev87985532018-07-10 20:49:38 +0300108}
109
azvyagintsev9df82e52018-09-06 19:17:18 +0300110def StepPrepareGit(templateEnvFolder, gerrit_data) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300111 // return git clone object
112 return {
azvyagintsev9df82e52018-09-06 19:17:18 +0300113 def checkouted = false
114 common.infoMsg("StepPrepareGit: ${gerrit_data}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300115 // fetch needed sources
116 dir(templateEnvFolder) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300117 if (gerrit_data['gerritRefSpec']) {
118 // Those part might be not work,in case manual var's pass
119 def gerritChange = gerrit.getGerritChange(gerrit_data['gerritName'], gerrit_data['gerritHost'],
120 gerrit_data['GERRIT_CHANGE_NUMBER'], gerrit_data['credentialsId'])
azvyagintsev5c0313d2018-08-13 17:13:35 +0300121 merged = gerritChange.status == "MERGED"
122 if (!merged) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300123 checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300124 } else {
azvyagintsev9df82e52018-09-06 19:17:18 +0300125 // update global variable for pretty return from pipeline
126 alreadyMerged = true
127 common.successMsg("Change ${gerrit_data['GERRIT_CHANGE_NUMBER']} is already merged, no need to gate them")
128 error('change already merged')
azvyagintsev87985532018-07-10 20:49:38 +0300129 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300130 } else {
azvyagintsev9df82e52018-09-06 19:17:18 +0300131 // Get clean HEAD
132 gerrit_data['useGerritTriggerBuildChooser'] = false
133 checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
134 if (!checkouted) {
135 error("Failed to get repo:${gerrit_data}")
136 }
azvyagintsev87985532018-07-10 20:49:38 +0300137 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300138 }
azvyagintsev87985532018-07-10 20:49:38 +0300139 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300140}
141
142def StepGenerateModels(_contextFileList, _virtualenv, _templateEnvDir) {
143 return {
144 for (contextFile in _contextFileList) {
Denis Egorenkof3469092018-10-17 17:05:50 +0400145 def basename = common.GetBaseName(contextFile, '.yml')
146 def context = readFile(file: "${_templateEnvDir}/contexts/${contextFile}")
147 python.generateModel(context, basename, 'cfg01', _virtualenv, "${_templateEnvDir}/model", _templateEnvDir)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300148 }
149 }
150}
151
azvyagintsev9df82e52018-09-06 19:17:18 +0300152def globalVariatorsUpdate() {
153 // Simple function, to check and define branch-around variables
154 // In general, simply make transition updates for non-master branch
155 // based on magic logic
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400156 def newline = '<br/>'
157 def messages = []
azvyagintsevb266ad22018-09-11 12:11:11 +0300158 if (env.GERRIT_PROJECT) {
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400159 messages.add("<font color='red'>GerritTrigger detected! We are in auto-mode:</font>")
160 messages.add("Test env variables has been changed:")
161 messages.add("COOKIECUTTER_TEMPLATE_BRANCH => ${gerritDataCC['gerritBranch']}")
162 messages.add("RECLASS_MODEL_BRANCH => ${gerritDataRS['gerritBranch']}")
azvyagintseve0eb6cd2018-09-12 13:00:40 +0300163 // TODO are we going to have such branches?
azvyagintsev9df82e52018-09-06 19:17:18 +0300164 if (!['nightly', 'testing', 'stable', 'proposed', 'master'].contains(env.GERRIT_BRANCH)) {
165 gerritDataCC['gerritBranch'] = env.GERRIT_BRANCH
166 gerritDataRS['gerritBranch'] = env.GERRIT_BRANCH
azvyagintsev458278c2018-09-25 18:38:30 +0300167 testDistribRevision = env.GERRIT_BRANCH
azvyagintsev9df82e52018-09-06 19:17:18 +0300168 }
169 // Identify, who triggered. To whom we should pass refspec
170 if (env.GERRIT_PROJECT == 'salt-models/reclass-system') {
171 gerritDataRS['gerritRefSpec'] = env.GERRIT_REFSPEC
172 gerritDataRS['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400173 messages.add("RECLASS_SYSTEM_GIT_REF => ${gerritDataRS['gerritRefSpec']}")
azvyagintsev9df82e52018-09-06 19:17:18 +0300174 } else if (env.GERRIT_PROJECT == 'mk/cookiecutter-templates') {
175 gerritDataCC['gerritRefSpec'] = env.GERRIT_REFSPEC
176 gerritDataCC['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400177 messages.add("COOKIECUTTER_TEMPLATE_REF => ${gerritDataCC['gerritRefSpec']}")
azvyagintsev9df82e52018-09-06 19:17:18 +0300178 } else {
179 error("Unsuported gerrit-project triggered:${env.GERRIT_PROJECT}")
180 }
azvyagintsev9df82e52018-09-06 19:17:18 +0300181 } else {
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400182 messages.add("<font color='red'>Non-gerrit trigger run detected!</font>")
azvyagintsev9df82e52018-09-06 19:17:18 +0300183 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300184 gerritDataCCHEAD << gerritDataCC
185 gerritDataCCHEAD['gerritRefSpec'] = null
186 gerritDataCCHEAD['GERRIT_CHANGE_NUMBER'] = null
187 gerritDataRSHEAD << gerritDataRS
188 gerritDataRSHEAD['gerritRefSpec'] = null
189 gerritDataRSHEAD['GERRIT_CHANGE_NUMBER'] = null
azvyagintsev458278c2018-09-25 18:38:30 +0300190 // 'binary' branch logic w\o 'release/' prefix
191 if (testDistribRevision.contains('/')) {
192 testDistribRevision = testDistribRevision.split('/')[-1]
193 }
194 // Check if we are going to test bleeding-edge release, which doesn't have binary release yet
195 if (!common.checkRemoteBinary([apt_mk_version: testDistribRevision]).linux_system_repo_url) {
196 common.errorMsg("Binary release: ${testDistribRevision} not exist. Fallback to 'proposed'! ")
197 testDistribRevision = 'proposed'
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400198 messages.add("DISTRIB_REVISION => ${testDistribRevision}")
azvyagintsev458278c2018-09-25 18:38:30 +0300199 }
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400200 def message = messages.join(newline) + newline
azvyagintsev458278c2018-09-25 18:38:30 +0300201 currentBuild.description = currentBuild.description ? message + currentBuild.description : message
Denis Egorenkod8748942018-09-07 12:26:20 +0400202}
azvyagintsev9df82e52018-09-06 19:17:18 +0300203
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400204def replaceGeneratedValues(path) {
205 def files = sh(script: "find ${path} -name 'secrets.yml'", returnStdout: true)
206 def stepsForParallel = [:]
207 stepsForParallel.failFast = true
208 files.tokenize().each {
209 stepsForParallel.put("Removing generated passwords/secrets from ${it}",
210 {
211 def secrets = readYaml file: it
azvyagintsev08b34e32018-09-12 12:29:42 +0300212 for (String key in secrets['parameters']['_param'].keySet()) {
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400213 secrets['parameters']['_param'][key] = 'generated'
214 }
215 // writeYaml can't write to already existing file
216 writeYaml file: "${it}.tmp", data: secrets
217 sh "mv ${it}.tmp ${it}"
218 })
219 }
220 parallel stepsForParallel
221}
222
Denis Egorenkod8748942018-09-07 12:26:20 +0400223def linkReclassModels(contextList, envPath, archiveName) {
224 // to be able share reclass for all subenvs
225 // Also, makes artifact test more solid - use one reclass for all of sub-models.
226 // Archive Structure will be:
227 // tar.gz
228 // ├── contexts
229 // │   └── ceph.yml
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400230 // ├── classes-system <<< reclass system
Denis Egorenkod8748942018-09-07 12:26:20 +0400231 // ├── model
232 // │   └── ceph <<< from `context basename`
233 // │   ├── classes
234 // │   │   ├── cluster
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400235 // │   │   └── system -> ../../../classes-system
Denis Egorenkod8748942018-09-07 12:26:20 +0400236 // │   └── nodes
237 // │   └── cfg01.ceph-cluster-domain.local.yml
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400238 def archiveBaseName = common.GetBaseName(archiveName, '.tar.gz')
239 def classesSystemDir = 'classes-system'
240 // copy reclass system under envPath with -R and trailing / to support symlinks direct copy
241 sh("cp -R ${archiveBaseName}/ ${envPath}/${classesSystemDir}")
Denis Egorenkod8748942018-09-07 12:26:20 +0400242 dir(envPath) {
243 for (String context : contextList) {
244 def basename = common.GetBaseName(context, '.yml')
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400245 dir("${envPath}/model/${basename}/classes") {
246 sh(script: "ln -sfv ../../../${classesSystemDir} system ")
Denis Egorenkod8748942018-09-07 12:26:20 +0400247 }
248 }
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400249 // replace all generated passwords/secrets/keys with hardcode value for infra/secrets.yaml
250 replaceGeneratedValues("${envPath}/model")
azvyagintsev3a80e342018-09-19 19:22:48 +0300251 // Save all models and all contexts. Warning! `h` flag must be used!
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400252 sh(script: "set -ex; tar -czhf ${env.WORKSPACE}/${archiveName} --exclude='*@tmp' contexts model ${classesSystemDir}", returnStatus: true)
Denis Egorenkod8748942018-09-07 12:26:20 +0400253 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300254 archiveArtifacts artifacts: archiveName
azvyagintsev9df82e52018-09-06 19:17:18 +0300255}
256
azvyagintsev5c0313d2018-08-13 17:13:35 +0300257timeout(time: 1, unit: 'HOURS') {
258 node(slaveNode) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300259 globalVariatorsUpdate()
azvyagintsev30bc82e2018-08-22 12:26:06 +0300260 def templateEnvHead = "${env.WORKSPACE}/EnvHead/"
261 def templateEnvPatched = "${env.WORKSPACE}/EnvPatched/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300262 def contextFileListHead = []
263 def contextFileListPatched = []
264 def vEnv = "${env.WORKSPACE}/venv"
Denis Egorenkod8748942018-09-07 12:26:20 +0400265 def headReclassArtifactName = "head_reclass.tar.gz"
266 def patchedReclassArtifactName = "patched_reclass.tar.gz"
267 def reclassNodeInfoDir = "${env.WORKSPACE}/reclassNodeInfo_compare/"
268 def reclassInfoHeadPath = "${reclassNodeInfoDir}/old"
269 def reclassInfoPatchedPath = "${reclassNodeInfoDir}/new"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300270 try {
271 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
272 stage('Download and prepare CC env') {
273 // Prepare 2 env - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300274 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300275 paralellEnvs.failFast = true
azvyagintsev9df82e52018-09-06 19:17:18 +0300276 paralellEnvs['downloadEnvHead'] = StepPrepareGit(templateEnvHead, gerritDataCCHEAD)
azvyagintsev3a80e342018-09-19 19:22:48 +0300277 if (gerritDataCC.get('gerritRefSpec', null)) {
278 paralellEnvs['downloadEnvPatched'] = StepPrepareGit(templateEnvPatched, gerritDataCC)
279 parallel paralellEnvs
280 } else {
281 paralellEnvs['downloadEnvPatched'] = { common.warningMsg('No need to process: downloadEnvPatched') }
282 parallel paralellEnvs
283 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
284 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300285 }
286 stage("Check workflow_definition") {
287 // Check only for patchset
288 python.setupVirtualenv(vEnv, 'python2', [], "${templateEnvPatched}/requirements.txt")
azvyagintsev3a80e342018-09-19 19:22:48 +0300289 if (gerritDataCC.get('gerritRefSpec', null)) {
290 common.infoMsg(python.runVirtualenvCommand(vEnv, "python ${templateEnvPatched}/workflow_definition_test.py"))
291 } else {
292 common.infoMsg('No need to process: workflow_definition')
293 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300294 }
295
296 stage("generate models") {
297 dir("${templateEnvHead}/contexts") {
298 for (String x : findFiles(glob: "*.yml")) {
299 contextFileListHead.add(x)
300 }
301 }
302 dir("${templateEnvPatched}/contexts") {
303 for (String x : findFiles(glob: "*.yml")) {
304 contextFileListPatched.add(x)
305 }
306 }
307 // Generate over 2env's - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300308 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300309 paralellEnvs.failFast = true
azvyagintsev30bc82e2018-08-22 12:26:06 +0300310 paralellEnvs['GenerateEnvHead'] = StepGenerateModels(contextFileListHead, vEnv, templateEnvHead)
azvyagintsev3a80e342018-09-19 19:22:48 +0300311 if (gerritDataCC.get('gerritRefSpec', null)) {
312 paralellEnvs['GenerateEnvPatched'] = StepGenerateModels(contextFileListPatched, vEnv, templateEnvPatched)
313 parallel paralellEnvs
314 } else {
315 paralellEnvs['GenerateEnvPatched'] = { common.warningMsg('No need to process: GenerateEnvPatched') }
316 parallel paralellEnvs
317 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300318 }
319
azvyagintsev3a80e342018-09-19 19:22:48 +0300320 // We need 2 git's, one for HEAD, one for PATCHed.
321 // if no patch, use head for both
322 RSHeadDir = common.GetBaseName(headReclassArtifactName, '.tar.gz')
323 RSPatchedDir = common.GetBaseName(patchedReclassArtifactName, '.tar.gz')
324 common.infoMsg("gerritDataRS= ${gerritDataRS}")
325 common.infoMsg("gerritDataRSHEAD= ${gerritDataRSHEAD}")
326 if (gerritDataRS.get('gerritRefSpec', null)) {
327 StepPrepareGit("${env.WORKSPACE}/${RSPatchedDir}/", gerritDataRS).call()
328 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRSHEAD).call()
329 } else {
330 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRS).call()
331 sh("cd ${env.WORKSPACE} ; ln -svf ${RSHeadDir} ${RSPatchedDir}")
332 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300333 // link all models, to use one global reclass
334 // For HEAD
Denis Egorenkod8748942018-09-07 12:26:20 +0400335 linkReclassModels(contextFileListHead, templateEnvHead, headReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300336 // For patched
Denis Egorenkod8748942018-09-07 12:26:20 +0400337 linkReclassModels(contextFileListPatched, templateEnvPatched, patchedReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300338 }
339
Denis Egorenkod8748942018-09-07 12:26:20 +0400340 stage("Compare cluster lvl Head/Patched") {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300341 // Compare patched and HEAD reclass pillars
Denis Egorenkod8748942018-09-07 12:26:20 +0400342 compareRoot = "${env.WORKSPACE}/cluster_compare/"
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400343 // extract archive and drop all copied classes/system before comparing
azvyagintsev5c0313d2018-08-13 17:13:35 +0300344 sh(script: """
345 mkdir -pv ${compareRoot}/new ${compareRoot}/old
Denis Egorenkod8748942018-09-07 12:26:20 +0400346 tar -xzf ${patchedReclassArtifactName} --directory ${compareRoot}/new
347 tar -xzf ${headReclassArtifactName} --directory ${compareRoot}/old
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400348 find ${compareRoot} -name classes -type d -exec rm -rf '{}/system' \\;
azvyagintsev5c0313d2018-08-13 17:13:35 +0300349 """)
350 common.warningMsg('infra/secrets.yml has been skipped from compare!')
azvyagintsev3a80e342018-09-19 19:22:48 +0300351 result = '\n' + common.comparePillars(compareRoot, env.BUILD_URL, "-Ev \'infra/secrets.yml|\\.git\'")
Denis Egorenkod8748942018-09-07 12:26:20 +0400352 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300353 }
Denis Egorenkod8748942018-09-07 12:26:20 +0400354 stage("TestContexts Head/Patched") {
355 def stepsForParallel = [:]
356 stepsForParallel.failFast = true
357 common.infoMsg("Found: ${contextFileListHead.size()} HEAD contexts to test.")
358 for (String context : contextFileListHead) {
359 def basename = common.GetBaseName(context, '.yml')
360 stepsForParallel.put("ContextHeadTest:${basename}", StepTestModel(basename, headReclassArtifactName, reclassInfoHeadPath))
361 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300362 common.infoMsg("Found: ${contextFileListPatched.size()} patched contexts to test.")
363 for (String context : contextFileListPatched) {
364 def basename = common.GetBaseName(context, '.yml')
Denis Egorenko086aff12018-10-18 17:54:59 +0400365 stepsForParallel.put("ContextPatchedTest:${basename}", StepTestModel(basename, patchedReclassArtifactName, reclassInfoPatchedPath, true))
azvyagintsev5c0313d2018-08-13 17:13:35 +0300366 }
367 parallel stepsForParallel
Denis Egorenkod8748942018-09-07 12:26:20 +0400368 common.infoMsg('All TestContexts tests done')
369 }
370 stage("Compare NodesInfo Head/Patched") {
371 // Download all artifacts
372 def stepsForParallel = [:]
373 stepsForParallel.failFast = true
374 common.infoMsg("Found: ${testModelBuildsData.size()} nodeinfo artifacts to download.")
375 testModelBuildsData.each { bname, bdata ->
376 stepsForParallel.put("FetchData:${bname}",
377 getAndUnpackNodesInfoArtifact(bdata.jobname, bdata.copyToDir, bdata.buildId))
378 }
379 parallel stepsForParallel
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400380 // remove timestamp field from rendered files
381 sh("find ${reclassNodeInfoDir} -type f -exec sed -i '/ timestamp: .*/d' {} \\;")
Denis Egorenkod8748942018-09-07 12:26:20 +0400382 // Compare patched and HEAD reclass pillars
383 result = '\n' + common.comparePillars(reclassNodeInfoDir, env.BUILD_URL, '')
384 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300385 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400386 stage('Check include order') {
azvyagintseve7b8e792018-09-21 17:27:01 +0300387 if (!checkIncludeOrder) {
388 common.infoMsg('Check include order require to much time, and currently disabled!')
389
390 } else {
391 def correctIncludeOrder = ["service", "system", "cluster"]
392 dir(reclassInfoPatchedPath) {
393 def nodeInfoFiles = findFiles(glob: "**/*.reclass.nodeinfo")
394 def messages = ["<b>Wrong include ordering found</b><ul>"]
395 def stepsForParallel = [:]
396 nodeInfoFiles.each { nodeInfo ->
397 stepsForParallel.put("Checking ${nodeInfo.path}:", {
398 def node = readYaml file: nodeInfo.path
399 def classes = node['classes']
400 def curClassID = 0
401 def prevClassID = 0
402 def wrongOrder = false
403 for (String className in classes) {
404 def currentClass = className.tokenize('.')[0]
405 curClassID = correctIncludeOrder.indexOf(currentClass)
406 if (currentClass != correctIncludeOrder[prevClassID]) {
407 if (prevClassID > curClassID) {
408 wrongOrder = true
409 common.warningMsg("File ${nodeInfo.path} contains wrong order of classes including: Includes for ${className} should be declared before ${correctIncludeOrder[prevClassID]} includes")
410 } else {
411 prevClassID = curClassID
412 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400413 }
414 }
azvyagintseve7b8e792018-09-21 17:27:01 +0300415 if (wrongOrder) {
416 messages.add("<li>${nodeInfo.path} contains wrong order of classes including</li>")
417 }
418 })
419 }
420 parallel stepsForParallel
421 def includerOrder = '<b>No wrong include order</b>'
422 if (messages.size() != 1) {
423 includerOrder = messages.join('')
424 }
425 currentBuild.description = currentBuild.description ? currentBuild.description + includerOrder : includerOrder
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400426 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400427 }
428 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300429 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
430
431 } catch (Throwable e) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300432 if (alreadyMerged) {
433 currentBuild.result = 'ABORTED'
434 currentBuild.description = "Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them"
435 return
436 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300437 currentBuild.result = "FAILURE"
438 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
439 throw e
440 } finally {
441 def dummy = "dummy"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300442 }
443 }
chnydae80bb922017-05-29 17:48:40 +0200444}