blob: f5f06224b3cca9cdf38fb46527c15289d6325ceb [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
Kirill Mashchenko3dec0822018-12-12 20:01:51 +040030slaveNode = env.SLAVE_NODE ?: 'virtual'
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 = [
azvyagintsev4220bff2019-01-09 21:32:11 +020083 MODELS_TARGZ : "${env.BUILD_URL}/artifact/${reclassArtifactName}",
84 DockerCName : _uuid,
85 testReclassEnv : "model/${modelFile}/",
86 modelFile : "contexts/${modelFile}.yml",
Alexander Evseev02fe5eb2018-11-15 13:58:36 +010087 DISTRIB_REVISION: testDistribRevision,
azvyagintsev4220bff2019-01-09 21:32:11 +020088 useExtraRepos : useExtraRepos,
Alexander Evseev02fe5eb2018-11-15 13:58:36 +010089 ]
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
azvyagintsev5c200e72018-12-28 15:58:09 +0200199 // After 2018q4 releases, need to also check 'static' repo, for example ubuntu.
azvyagintsev4220bff2019-01-09 21:32:11 +0200200 binTest = common.checkRemoteBinary(['mcp_version': testDistribRevision])
azvyagintsev5c200e72018-12-28 15:58:09 +0200201 if (!binTest.linux_system_repo_url || !binTest.linux_system_repo_ubuntu_url) {
202 common.errorMsg("Binary release: ${testDistribRevision} not exist or not full. Fallback to 'proposed'! ")
azvyagintsev458278c2018-09-25 18:38:30 +0300203 testDistribRevision = 'proposed'
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400204 messages.add("DISTRIB_REVISION => ${testDistribRevision}")
azvyagintsev458278c2018-09-25 18:38:30 +0300205 }
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400206 def message = messages.join(newline) + newline
azvyagintsev458278c2018-09-25 18:38:30 +0300207 currentBuild.description = currentBuild.description ? message + currentBuild.description : message
Denis Egorenkod8748942018-09-07 12:26:20 +0400208}
azvyagintsev9df82e52018-09-06 19:17:18 +0300209
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400210def replaceGeneratedValues(path) {
211 def files = sh(script: "find ${path} -name 'secrets.yml'", returnStdout: true)
212 def stepsForParallel = [:]
213 stepsForParallel.failFast = true
214 files.tokenize().each {
215 stepsForParallel.put("Removing generated passwords/secrets from ${it}",
216 {
217 def secrets = readYaml file: it
azvyagintsev08b34e32018-09-12 12:29:42 +0300218 for (String key in secrets['parameters']['_param'].keySet()) {
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400219 secrets['parameters']['_param'][key] = 'generated'
220 }
221 // writeYaml can't write to already existing file
222 writeYaml file: "${it}.tmp", data: secrets
223 sh "mv ${it}.tmp ${it}"
224 })
225 }
226 parallel stepsForParallel
227}
228
Denis Egorenkod8748942018-09-07 12:26:20 +0400229def linkReclassModels(contextList, envPath, archiveName) {
230 // to be able share reclass for all subenvs
231 // Also, makes artifact test more solid - use one reclass for all of sub-models.
232 // Archive Structure will be:
233 // tar.gz
234 // ├── contexts
235 // │   └── ceph.yml
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400236 // ├── classes-system <<< reclass system
Denis Egorenkod8748942018-09-07 12:26:20 +0400237 // ├── model
238 // │   └── ceph <<< from `context basename`
239 // │   ├── classes
240 // │   │   ├── cluster
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400241 // │   │   └── system -> ../../../classes-system
Denis Egorenkod8748942018-09-07 12:26:20 +0400242 // │   └── nodes
243 // │   └── cfg01.ceph-cluster-domain.local.yml
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400244 def archiveBaseName = common.GetBaseName(archiveName, '.tar.gz')
245 def classesSystemDir = 'classes-system'
246 // copy reclass system under envPath with -R and trailing / to support symlinks direct copy
247 sh("cp -R ${archiveBaseName}/ ${envPath}/${classesSystemDir}")
Denis Egorenkod8748942018-09-07 12:26:20 +0400248 dir(envPath) {
249 for (String context : contextList) {
250 def basename = common.GetBaseName(context, '.yml')
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400251 dir("${envPath}/model/${basename}/classes") {
252 sh(script: "ln -sfv ../../../${classesSystemDir} system ")
Denis Egorenkod8748942018-09-07 12:26:20 +0400253 }
254 }
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400255 // replace all generated passwords/secrets/keys with hardcode value for infra/secrets.yaml
256 replaceGeneratedValues("${envPath}/model")
azvyagintsev3a80e342018-09-19 19:22:48 +0300257 // Save all models and all contexts. Warning! `h` flag must be used!
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400258 sh(script: "set -ex; tar -czhf ${env.WORKSPACE}/${archiveName} --exclude='*@tmp' contexts model ${classesSystemDir}", returnStatus: true)
Denis Egorenkod8748942018-09-07 12:26:20 +0400259 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300260 archiveArtifacts artifacts: archiveName
azvyagintsev9df82e52018-09-06 19:17:18 +0300261}
262
azvyagintsev5c0313d2018-08-13 17:13:35 +0300263timeout(time: 1, unit: 'HOURS') {
264 node(slaveNode) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300265 globalVariatorsUpdate()
azvyagintsev30bc82e2018-08-22 12:26:06 +0300266 def templateEnvHead = "${env.WORKSPACE}/EnvHead/"
267 def templateEnvPatched = "${env.WORKSPACE}/EnvPatched/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300268 def contextFileListHead = []
269 def contextFileListPatched = []
270 def vEnv = "${env.WORKSPACE}/venv"
Denis Egorenkod8748942018-09-07 12:26:20 +0400271 def headReclassArtifactName = "head_reclass.tar.gz"
272 def patchedReclassArtifactName = "patched_reclass.tar.gz"
273 def reclassNodeInfoDir = "${env.WORKSPACE}/reclassNodeInfo_compare/"
274 def reclassInfoHeadPath = "${reclassNodeInfoDir}/old"
275 def reclassInfoPatchedPath = "${reclassNodeInfoDir}/new"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300276 try {
277 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
278 stage('Download and prepare CC env') {
279 // Prepare 2 env - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300280 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300281 paralellEnvs.failFast = true
azvyagintsev9df82e52018-09-06 19:17:18 +0300282 paralellEnvs['downloadEnvHead'] = StepPrepareGit(templateEnvHead, gerritDataCCHEAD)
azvyagintsev3a80e342018-09-19 19:22:48 +0300283 if (gerritDataCC.get('gerritRefSpec', null)) {
284 paralellEnvs['downloadEnvPatched'] = StepPrepareGit(templateEnvPatched, gerritDataCC)
285 parallel paralellEnvs
286 } else {
287 paralellEnvs['downloadEnvPatched'] = { common.warningMsg('No need to process: downloadEnvPatched') }
288 parallel paralellEnvs
289 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
290 }
Denis Egorenko3de070c2018-11-20 13:57:35 +0400291 if (env.CUSTOM_COOKIECUTTER_CONTEXT) {
292 // readYaml to check custom context structure
293 def customContext = readYaml text: env.CUSTOM_COOKIECUTTER_CONTEXT
294 writeYaml file: "${templateEnvHead}/contexts/custom_context.yml", data: customContext
295 writeYaml file: "${templateEnvPatched}/contexts/custom_context.yml", data: customContext
296 common.infoMsg("Using custom context provided from job parameter 'CUSTOM_COOKIECUTTER_CONTEXT'")
297 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300298 }
azvyagintsev8ab34fd2019-01-10 15:32:26 +0200299 stage('Check workflow_definition') {
300 // Prepare venv for old env's, aka non-tox based
301 if (!fileExists(new File(templateEnvPatched, 'tox.ini').toString()) || !fileExists(new File(templateEnvHead, 'tox.ini').toString())) {
302 python.setupVirtualenv(vEnv, 'python2', [], "${templateEnvPatched}/requirements.txt")
303 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300304 // Check only for patchset
azvyagintsev1037fb42019-01-10 13:52:38 +0200305 if (fileExists(new File(templateEnvPatched, 'tox.ini').toString())) {
306 dir(templateEnvPatched) {
307 output = sh(returnStdout: true, script: "tox -ve test")
308 common.infoMsg("[Cookiecutter test] Result: ${output}")
azvyagintsev4220bff2019-01-09 21:32:11 +0200309 }
azvyagintsev1037fb42019-01-10 13:52:38 +0200310
azvyagintsev3a80e342018-09-19 19:22:48 +0300311 } else {
azvyagintsev1037fb42019-01-10 13:52:38 +0200312 common.warningMsg('Old Cookiecutter env detected!')
azvyagintsev1037fb42019-01-10 13:52:38 +0200313 common.infoMsg(python.runVirtualenvCommand(vEnv, "python ${templateEnvPatched}/workflow_definition_test.py"))
azvyagintsev3a80e342018-09-19 19:22:48 +0300314 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300315 }
316
azvyagintsev8ab34fd2019-01-10 15:32:26 +0200317 stage('generate models') {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300318 dir("${templateEnvHead}/contexts") {
319 for (String x : findFiles(glob: "*.yml")) {
320 contextFileListHead.add(x)
321 }
322 }
323 dir("${templateEnvPatched}/contexts") {
324 for (String x : findFiles(glob: "*.yml")) {
325 contextFileListPatched.add(x)
326 }
327 }
328 // Generate over 2env's - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300329 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300330 paralellEnvs.failFast = true
azvyagintsev30bc82e2018-08-22 12:26:06 +0300331 paralellEnvs['GenerateEnvHead'] = StepGenerateModels(contextFileListHead, vEnv, templateEnvHead)
azvyagintsev3a80e342018-09-19 19:22:48 +0300332 if (gerritDataCC.get('gerritRefSpec', null)) {
333 paralellEnvs['GenerateEnvPatched'] = StepGenerateModels(contextFileListPatched, vEnv, templateEnvPatched)
334 parallel paralellEnvs
335 } else {
336 paralellEnvs['GenerateEnvPatched'] = { common.warningMsg('No need to process: GenerateEnvPatched') }
337 parallel paralellEnvs
338 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300339 }
340
azvyagintsev3a80e342018-09-19 19:22:48 +0300341 // We need 2 git's, one for HEAD, one for PATCHed.
342 // if no patch, use head for both
343 RSHeadDir = common.GetBaseName(headReclassArtifactName, '.tar.gz')
344 RSPatchedDir = common.GetBaseName(patchedReclassArtifactName, '.tar.gz')
345 common.infoMsg("gerritDataRS= ${gerritDataRS}")
346 common.infoMsg("gerritDataRSHEAD= ${gerritDataRSHEAD}")
347 if (gerritDataRS.get('gerritRefSpec', null)) {
348 StepPrepareGit("${env.WORKSPACE}/${RSPatchedDir}/", gerritDataRS).call()
349 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRSHEAD).call()
350 } else {
351 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRS).call()
352 sh("cd ${env.WORKSPACE} ; ln -svf ${RSHeadDir} ${RSPatchedDir}")
353 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300354 // link all models, to use one global reclass
355 // For HEAD
Denis Egorenkod8748942018-09-07 12:26:20 +0400356 linkReclassModels(contextFileListHead, templateEnvHead, headReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300357 // For patched
Denis Egorenkod8748942018-09-07 12:26:20 +0400358 linkReclassModels(contextFileListPatched, templateEnvPatched, patchedReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300359 }
360
Denis Egorenkod8748942018-09-07 12:26:20 +0400361 stage("Compare cluster lvl Head/Patched") {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300362 // Compare patched and HEAD reclass pillars
Denis Egorenkod8748942018-09-07 12:26:20 +0400363 compareRoot = "${env.WORKSPACE}/cluster_compare/"
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400364 // extract archive and drop all copied classes/system before comparing
azvyagintsev5c0313d2018-08-13 17:13:35 +0300365 sh(script: """
366 mkdir -pv ${compareRoot}/new ${compareRoot}/old
Denis Egorenkod8748942018-09-07 12:26:20 +0400367 tar -xzf ${patchedReclassArtifactName} --directory ${compareRoot}/new
368 tar -xzf ${headReclassArtifactName} --directory ${compareRoot}/old
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400369 find ${compareRoot} -name classes -type d -exec rm -rf '{}/system' \\;
azvyagintsev5c0313d2018-08-13 17:13:35 +0300370 """)
371 common.warningMsg('infra/secrets.yml has been skipped from compare!')
azvyagintsev3a80e342018-09-19 19:22:48 +0300372 result = '\n' + common.comparePillars(compareRoot, env.BUILD_URL, "-Ev \'infra/secrets.yml|\\.git\'")
Denis Egorenkod8748942018-09-07 12:26:20 +0400373 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300374 }
Denis Egorenkod8748942018-09-07 12:26:20 +0400375 stage("TestContexts Head/Patched") {
376 def stepsForParallel = [:]
377 stepsForParallel.failFast = true
378 common.infoMsg("Found: ${contextFileListHead.size()} HEAD contexts to test.")
379 for (String context : contextFileListHead) {
380 def basename = common.GetBaseName(context, '.yml')
381 stepsForParallel.put("ContextHeadTest:${basename}", StepTestModel(basename, headReclassArtifactName, reclassInfoHeadPath))
382 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300383 common.infoMsg("Found: ${contextFileListPatched.size()} patched contexts to test.")
384 for (String context : contextFileListPatched) {
385 def basename = common.GetBaseName(context, '.yml')
Denis Egorenko086aff12018-10-18 17:54:59 +0400386 stepsForParallel.put("ContextPatchedTest:${basename}", StepTestModel(basename, patchedReclassArtifactName, reclassInfoPatchedPath, true))
azvyagintsev5c0313d2018-08-13 17:13:35 +0300387 }
388 parallel stepsForParallel
Denis Egorenkod8748942018-09-07 12:26:20 +0400389 common.infoMsg('All TestContexts tests done')
390 }
391 stage("Compare NodesInfo Head/Patched") {
392 // Download all artifacts
393 def stepsForParallel = [:]
394 stepsForParallel.failFast = true
395 common.infoMsg("Found: ${testModelBuildsData.size()} nodeinfo artifacts to download.")
396 testModelBuildsData.each { bname, bdata ->
397 stepsForParallel.put("FetchData:${bname}",
398 getAndUnpackNodesInfoArtifact(bdata.jobname, bdata.copyToDir, bdata.buildId))
399 }
400 parallel stepsForParallel
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400401 // remove timestamp field from rendered files
402 sh("find ${reclassNodeInfoDir} -type f -exec sed -i '/ timestamp: .*/d' {} \\;")
Denis Egorenkod8748942018-09-07 12:26:20 +0400403 // Compare patched and HEAD reclass pillars
404 result = '\n' + common.comparePillars(reclassNodeInfoDir, env.BUILD_URL, '')
405 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300406 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400407 stage('Check include order') {
azvyagintseve7b8e792018-09-21 17:27:01 +0300408 if (!checkIncludeOrder) {
409 common.infoMsg('Check include order require to much time, and currently disabled!')
410
411 } else {
412 def correctIncludeOrder = ["service", "system", "cluster"]
413 dir(reclassInfoPatchedPath) {
414 def nodeInfoFiles = findFiles(glob: "**/*.reclass.nodeinfo")
415 def messages = ["<b>Wrong include ordering found</b><ul>"]
416 def stepsForParallel = [:]
417 nodeInfoFiles.each { nodeInfo ->
418 stepsForParallel.put("Checking ${nodeInfo.path}:", {
419 def node = readYaml file: nodeInfo.path
420 def classes = node['classes']
421 def curClassID = 0
422 def prevClassID = 0
423 def wrongOrder = false
424 for (String className in classes) {
425 def currentClass = className.tokenize('.')[0]
426 curClassID = correctIncludeOrder.indexOf(currentClass)
427 if (currentClass != correctIncludeOrder[prevClassID]) {
428 if (prevClassID > curClassID) {
429 wrongOrder = true
430 common.warningMsg("File ${nodeInfo.path} contains wrong order of classes including: Includes for ${className} should be declared before ${correctIncludeOrder[prevClassID]} includes")
431 } else {
432 prevClassID = curClassID
433 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400434 }
435 }
azvyagintseve7b8e792018-09-21 17:27:01 +0300436 if (wrongOrder) {
437 messages.add("<li>${nodeInfo.path} contains wrong order of classes including</li>")
438 }
439 })
440 }
441 parallel stepsForParallel
442 def includerOrder = '<b>No wrong include order</b>'
443 if (messages.size() != 1) {
444 includerOrder = messages.join('')
445 }
446 currentBuild.description = currentBuild.description ? currentBuild.description + includerOrder : includerOrder
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400447 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400448 }
449 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300450 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
451
452 } catch (Throwable e) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300453 if (alreadyMerged) {
454 currentBuild.result = 'ABORTED'
455 currentBuild.description = "Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them"
456 return
457 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300458 currentBuild.result = "FAILURE"
459 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
460 throw e
461 } finally {
462 def dummy = "dummy"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300463 }
464 }
chnydae80bb922017-05-29 17:48:40 +0200465}