blob: f6f950a88db8c73c3d4a23a6b09c12cc870f8038 [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
azvyagintsevaa7b43a2019-02-02 10:17:58 +020030// slaveNode = env.SLAVE_NODE ?: 'virtual'
31slaveNode = env.SLAVE_NODE ?: 'hardware'
azvyagintseve7b8e792018-09-21 17:27:01 +030032checkIncludeOrder = env.CHECK_INCLUDE_ORDER ?: false
azvyagintsev5c0313d2018-08-13 17:13:35 +030033
azvyagintsev9df82e52018-09-06 19:17:18 +030034// Global var's
azvyagintsev9df82e52018-09-06 19:17:18 +030035gerritConData = [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 common.infoMsg("StepPrepareGit: ${gerrit_data}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300118 // fetch needed sources
119 dir(templateEnvFolder) {
Denis Egorenko80d45b22019-01-31 22:28:38 +0400120 if (! gerrit_data['gerritRefSpec']) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300121 // Get clean HEAD
122 gerrit_data['useGerritTriggerBuildChooser'] = false
Denis Egorenko80d45b22019-01-31 22:28:38 +0400123 }
124 def checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
125 if (!checkouted) {
126 error("Failed to get repo:${gerrit_data}")
azvyagintsev87985532018-07-10 20:49:38 +0300127 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300128 }
azvyagintsev87985532018-07-10 20:49:38 +0300129 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300130}
131
132def StepGenerateModels(_contextFileList, _virtualenv, _templateEnvDir) {
133 return {
134 for (contextFile in _contextFileList) {
Denis Egorenkof3469092018-10-17 17:05:50 +0400135 def basename = common.GetBaseName(contextFile, '.yml')
136 def context = readFile(file: "${_templateEnvDir}/contexts/${contextFile}")
137 python.generateModel(context, basename, 'cfg01', _virtualenv, "${_templateEnvDir}/model", _templateEnvDir)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300138 }
139 }
140}
141
azvyagintsev9df82e52018-09-06 19:17:18 +0300142def globalVariatorsUpdate() {
143 // Simple function, to check and define branch-around variables
144 // In general, simply make transition updates for non-master branch
145 // based on magic logic
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400146 def newline = '<br/>'
147 def messages = []
azvyagintsevb266ad22018-09-11 12:11:11 +0300148 if (env.GERRIT_PROJECT) {
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400149 messages.add("<font color='red'>GerritTrigger detected! We are in auto-mode:</font>")
150 messages.add("Test env variables has been changed:")
azvyagintseve0eb6cd2018-09-12 13:00:40 +0300151 // TODO are we going to have such branches?
azvyagintsev9df82e52018-09-06 19:17:18 +0300152 if (!['nightly', 'testing', 'stable', 'proposed', 'master'].contains(env.GERRIT_BRANCH)) {
153 gerritDataCC['gerritBranch'] = env.GERRIT_BRANCH
154 gerritDataRS['gerritBranch'] = env.GERRIT_BRANCH
azvyagintsev458278c2018-09-25 18:38:30 +0300155 testDistribRevision = env.GERRIT_BRANCH
azvyagintsev9df82e52018-09-06 19:17:18 +0300156 }
Denis Egorenko60e45c12018-11-12 12:00:11 +0400157 messages.add("COOKIECUTTER_TEMPLATE_BRANCH => ${gerritDataCC['gerritBranch']}")
158 messages.add("RECLASS_SYSTEM_BRANCH => ${gerritDataRS['gerritBranch']}")
azvyagintsev9df82e52018-09-06 19:17:18 +0300159 // Identify, who triggered. To whom we should pass refspec
160 if (env.GERRIT_PROJECT == 'salt-models/reclass-system') {
161 gerritDataRS['gerritRefSpec'] = env.GERRIT_REFSPEC
162 gerritDataRS['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400163 messages.add("RECLASS_SYSTEM_GIT_REF => ${gerritDataRS['gerritRefSpec']}")
azvyagintsev9df82e52018-09-06 19:17:18 +0300164 } else if (env.GERRIT_PROJECT == 'mk/cookiecutter-templates') {
165 gerritDataCC['gerritRefSpec'] = env.GERRIT_REFSPEC
166 gerritDataCC['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400167 messages.add("COOKIECUTTER_TEMPLATE_REF => ${gerritDataCC['gerritRefSpec']}")
azvyagintsev9df82e52018-09-06 19:17:18 +0300168 } else {
169 error("Unsuported gerrit-project triggered:${env.GERRIT_PROJECT}")
170 }
azvyagintsev9df82e52018-09-06 19:17:18 +0300171 } else {
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400172 messages.add("<font color='red'>Non-gerrit trigger run detected!</font>")
azvyagintsev9df82e52018-09-06 19:17:18 +0300173 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300174 gerritDataCCHEAD << gerritDataCC
175 gerritDataCCHEAD['gerritRefSpec'] = null
176 gerritDataCCHEAD['GERRIT_CHANGE_NUMBER'] = null
177 gerritDataRSHEAD << gerritDataRS
178 gerritDataRSHEAD['gerritRefSpec'] = null
179 gerritDataRSHEAD['GERRIT_CHANGE_NUMBER'] = null
azvyagintsev458278c2018-09-25 18:38:30 +0300180 // 'binary' branch logic w\o 'release/' prefix
181 if (testDistribRevision.contains('/')) {
182 testDistribRevision = testDistribRevision.split('/')[-1]
183 }
184 // Check if we are going to test bleeding-edge release, which doesn't have binary release yet
azvyagintsev5c200e72018-12-28 15:58:09 +0200185 // After 2018q4 releases, need to also check 'static' repo, for example ubuntu.
azvyagintsev4220bff2019-01-09 21:32:11 +0200186 binTest = common.checkRemoteBinary(['mcp_version': testDistribRevision])
azvyagintsev5c200e72018-12-28 15:58:09 +0200187 if (!binTest.linux_system_repo_url || !binTest.linux_system_repo_ubuntu_url) {
188 common.errorMsg("Binary release: ${testDistribRevision} not exist or not full. Fallback to 'proposed'! ")
azvyagintsev458278c2018-09-25 18:38:30 +0300189 testDistribRevision = 'proposed'
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400190 messages.add("DISTRIB_REVISION => ${testDistribRevision}")
azvyagintsev458278c2018-09-25 18:38:30 +0300191 }
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400192 def message = messages.join(newline) + newline
azvyagintsev458278c2018-09-25 18:38:30 +0300193 currentBuild.description = currentBuild.description ? message + currentBuild.description : message
Denis Egorenkod8748942018-09-07 12:26:20 +0400194}
azvyagintsev9df82e52018-09-06 19:17:18 +0300195
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400196def replaceGeneratedValues(path) {
197 def files = sh(script: "find ${path} -name 'secrets.yml'", returnStdout: true)
198 def stepsForParallel = [:]
199 stepsForParallel.failFast = true
200 files.tokenize().each {
201 stepsForParallel.put("Removing generated passwords/secrets from ${it}",
202 {
203 def secrets = readYaml file: it
azvyagintsev08b34e32018-09-12 12:29:42 +0300204 for (String key in secrets['parameters']['_param'].keySet()) {
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400205 secrets['parameters']['_param'][key] = 'generated'
206 }
207 // writeYaml can't write to already existing file
208 writeYaml file: "${it}.tmp", data: secrets
209 sh "mv ${it}.tmp ${it}"
210 })
211 }
212 parallel stepsForParallel
213}
214
Denis Egorenkod8748942018-09-07 12:26:20 +0400215def linkReclassModels(contextList, envPath, archiveName) {
216 // to be able share reclass for all subenvs
217 // Also, makes artifact test more solid - use one reclass for all of sub-models.
218 // Archive Structure will be:
219 // tar.gz
220 // ├── contexts
221 // │   └── ceph.yml
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400222 // ├── classes-system <<< reclass system
Denis Egorenkod8748942018-09-07 12:26:20 +0400223 // ├── model
224 // │   └── ceph <<< from `context basename`
225 // │   ├── classes
226 // │   │   ├── cluster
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400227 // │   │   └── system -> ../../../classes-system
Denis Egorenkod8748942018-09-07 12:26:20 +0400228 // │   └── nodes
229 // │   └── cfg01.ceph-cluster-domain.local.yml
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400230 def archiveBaseName = common.GetBaseName(archiveName, '.tar.gz')
231 def classesSystemDir = 'classes-system'
232 // copy reclass system under envPath with -R and trailing / to support symlinks direct copy
233 sh("cp -R ${archiveBaseName}/ ${envPath}/${classesSystemDir}")
Denis Egorenkod8748942018-09-07 12:26:20 +0400234 dir(envPath) {
235 for (String context : contextList) {
236 def basename = common.GetBaseName(context, '.yml')
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400237 dir("${envPath}/model/${basename}/classes") {
238 sh(script: "ln -sfv ../../../${classesSystemDir} system ")
Denis Egorenkod8748942018-09-07 12:26:20 +0400239 }
240 }
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400241 // replace all generated passwords/secrets/keys with hardcode value for infra/secrets.yaml
242 replaceGeneratedValues("${envPath}/model")
azvyagintsev3a80e342018-09-19 19:22:48 +0300243 // Save all models and all contexts. Warning! `h` flag must be used!
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400244 sh(script: "set -ex; tar -czhf ${env.WORKSPACE}/${archiveName} --exclude='*@tmp' contexts model ${classesSystemDir}", returnStatus: true)
Denis Egorenkod8748942018-09-07 12:26:20 +0400245 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300246 archiveArtifacts artifacts: archiveName
azvyagintsev9df82e52018-09-06 19:17:18 +0300247}
248
azvyagintsev5c0313d2018-08-13 17:13:35 +0300249timeout(time: 1, unit: 'HOURS') {
250 node(slaveNode) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300251 globalVariatorsUpdate()
azvyagintsev30bc82e2018-08-22 12:26:06 +0300252 def templateEnvHead = "${env.WORKSPACE}/EnvHead/"
253 def templateEnvPatched = "${env.WORKSPACE}/EnvPatched/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300254 def contextFileListHead = []
255 def contextFileListPatched = []
256 def vEnv = "${env.WORKSPACE}/venv"
Denis Egorenkod8748942018-09-07 12:26:20 +0400257 def headReclassArtifactName = "head_reclass.tar.gz"
258 def patchedReclassArtifactName = "patched_reclass.tar.gz"
259 def reclassNodeInfoDir = "${env.WORKSPACE}/reclassNodeInfo_compare/"
260 def reclassInfoHeadPath = "${reclassNodeInfoDir}/old"
261 def reclassInfoPatchedPath = "${reclassNodeInfoDir}/new"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300262 try {
263 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
264 stage('Download and prepare CC env') {
265 // Prepare 2 env - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300266 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300267 paralellEnvs.failFast = true
azvyagintsev9df82e52018-09-06 19:17:18 +0300268 paralellEnvs['downloadEnvHead'] = StepPrepareGit(templateEnvHead, gerritDataCCHEAD)
azvyagintsev3a80e342018-09-19 19:22:48 +0300269 if (gerritDataCC.get('gerritRefSpec', null)) {
270 paralellEnvs['downloadEnvPatched'] = StepPrepareGit(templateEnvPatched, gerritDataCC)
271 parallel paralellEnvs
272 } else {
273 paralellEnvs['downloadEnvPatched'] = { common.warningMsg('No need to process: downloadEnvPatched') }
274 parallel paralellEnvs
275 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
276 }
Denis Egorenko3de070c2018-11-20 13:57:35 +0400277 if (env.CUSTOM_COOKIECUTTER_CONTEXT) {
278 // readYaml to check custom context structure
279 def customContext = readYaml text: env.CUSTOM_COOKIECUTTER_CONTEXT
280 writeYaml file: "${templateEnvHead}/contexts/custom_context.yml", data: customContext
281 writeYaml file: "${templateEnvPatched}/contexts/custom_context.yml", data: customContext
282 common.infoMsg("Using custom context provided from job parameter 'CUSTOM_COOKIECUTTER_CONTEXT'")
283 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300284 }
azvyagintsev8ab34fd2019-01-10 15:32:26 +0200285 stage('Check workflow_definition') {
286 // Prepare venv for old env's, aka non-tox based
287 if (!fileExists(new File(templateEnvPatched, 'tox.ini').toString()) || !fileExists(new File(templateEnvHead, 'tox.ini').toString())) {
288 python.setupVirtualenv(vEnv, 'python2', [], "${templateEnvPatched}/requirements.txt")
289 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300290 // Check only for patchset
azvyagintsev1037fb42019-01-10 13:52:38 +0200291 if (fileExists(new File(templateEnvPatched, 'tox.ini').toString())) {
292 dir(templateEnvPatched) {
293 output = sh(returnStdout: true, script: "tox -ve test")
294 common.infoMsg("[Cookiecutter test] Result: ${output}")
azvyagintsev4220bff2019-01-09 21:32:11 +0200295 }
azvyagintsev1037fb42019-01-10 13:52:38 +0200296
azvyagintsev3a80e342018-09-19 19:22:48 +0300297 } else {
azvyagintsev1037fb42019-01-10 13:52:38 +0200298 common.warningMsg('Old Cookiecutter env detected!')
azvyagintsev1037fb42019-01-10 13:52:38 +0200299 common.infoMsg(python.runVirtualenvCommand(vEnv, "python ${templateEnvPatched}/workflow_definition_test.py"))
azvyagintsev3a80e342018-09-19 19:22:48 +0300300 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300301 }
302
azvyagintsev8ab34fd2019-01-10 15:32:26 +0200303 stage('generate models') {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300304 dir("${templateEnvHead}/contexts") {
305 for (String x : findFiles(glob: "*.yml")) {
306 contextFileListHead.add(x)
307 }
308 }
309 dir("${templateEnvPatched}/contexts") {
310 for (String x : findFiles(glob: "*.yml")) {
311 contextFileListPatched.add(x)
312 }
313 }
314 // Generate over 2env's - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300315 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300316 paralellEnvs.failFast = true
azvyagintsev30bc82e2018-08-22 12:26:06 +0300317 paralellEnvs['GenerateEnvHead'] = StepGenerateModels(contextFileListHead, vEnv, templateEnvHead)
azvyagintsev3a80e342018-09-19 19:22:48 +0300318 if (gerritDataCC.get('gerritRefSpec', null)) {
319 paralellEnvs['GenerateEnvPatched'] = StepGenerateModels(contextFileListPatched, vEnv, templateEnvPatched)
320 parallel paralellEnvs
321 } else {
322 paralellEnvs['GenerateEnvPatched'] = { common.warningMsg('No need to process: GenerateEnvPatched') }
323 parallel paralellEnvs
324 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300325 }
326
azvyagintsev3a80e342018-09-19 19:22:48 +0300327 // We need 2 git's, one for HEAD, one for PATCHed.
328 // if no patch, use head for both
329 RSHeadDir = common.GetBaseName(headReclassArtifactName, '.tar.gz')
330 RSPatchedDir = common.GetBaseName(patchedReclassArtifactName, '.tar.gz')
331 common.infoMsg("gerritDataRS= ${gerritDataRS}")
332 common.infoMsg("gerritDataRSHEAD= ${gerritDataRSHEAD}")
333 if (gerritDataRS.get('gerritRefSpec', null)) {
334 StepPrepareGit("${env.WORKSPACE}/${RSPatchedDir}/", gerritDataRS).call()
335 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRSHEAD).call()
336 } else {
337 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRS).call()
338 sh("cd ${env.WORKSPACE} ; ln -svf ${RSHeadDir} ${RSPatchedDir}")
339 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300340 // link all models, to use one global reclass
341 // For HEAD
Denis Egorenkod8748942018-09-07 12:26:20 +0400342 linkReclassModels(contextFileListHead, templateEnvHead, headReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300343 // For patched
Denis Egorenkod8748942018-09-07 12:26:20 +0400344 linkReclassModels(contextFileListPatched, templateEnvPatched, patchedReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300345 }
346
Denis Egorenkod8748942018-09-07 12:26:20 +0400347 stage("Compare cluster lvl Head/Patched") {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300348 // Compare patched and HEAD reclass pillars
Denis Egorenkod8748942018-09-07 12:26:20 +0400349 compareRoot = "${env.WORKSPACE}/cluster_compare/"
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400350 // extract archive and drop all copied classes/system before comparing
azvyagintsev5c0313d2018-08-13 17:13:35 +0300351 sh(script: """
352 mkdir -pv ${compareRoot}/new ${compareRoot}/old
Denis Egorenkod8748942018-09-07 12:26:20 +0400353 tar -xzf ${patchedReclassArtifactName} --directory ${compareRoot}/new
354 tar -xzf ${headReclassArtifactName} --directory ${compareRoot}/old
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400355 find ${compareRoot} -name classes -type d -exec rm -rf '{}/system' \\;
azvyagintsev5c0313d2018-08-13 17:13:35 +0300356 """)
357 common.warningMsg('infra/secrets.yml has been skipped from compare!')
azvyagintsev3a80e342018-09-19 19:22:48 +0300358 result = '\n' + common.comparePillars(compareRoot, env.BUILD_URL, "-Ev \'infra/secrets.yml|\\.git\'")
Denis Egorenkod8748942018-09-07 12:26:20 +0400359 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300360 }
Denis Egorenkod8748942018-09-07 12:26:20 +0400361 stage("TestContexts Head/Patched") {
362 def stepsForParallel = [:]
363 stepsForParallel.failFast = true
364 common.infoMsg("Found: ${contextFileListHead.size()} HEAD contexts to test.")
365 for (String context : contextFileListHead) {
366 def basename = common.GetBaseName(context, '.yml')
367 stepsForParallel.put("ContextHeadTest:${basename}", StepTestModel(basename, headReclassArtifactName, reclassInfoHeadPath))
368 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300369 common.infoMsg("Found: ${contextFileListPatched.size()} patched contexts to test.")
370 for (String context : contextFileListPatched) {
371 def basename = common.GetBaseName(context, '.yml')
Denis Egorenko086aff12018-10-18 17:54:59 +0400372 stepsForParallel.put("ContextPatchedTest:${basename}", StepTestModel(basename, patchedReclassArtifactName, reclassInfoPatchedPath, true))
azvyagintsev5c0313d2018-08-13 17:13:35 +0300373 }
374 parallel stepsForParallel
Denis Egorenkod8748942018-09-07 12:26:20 +0400375 common.infoMsg('All TestContexts tests done')
376 }
377 stage("Compare NodesInfo Head/Patched") {
378 // Download all artifacts
379 def stepsForParallel = [:]
380 stepsForParallel.failFast = true
381 common.infoMsg("Found: ${testModelBuildsData.size()} nodeinfo artifacts to download.")
382 testModelBuildsData.each { bname, bdata ->
383 stepsForParallel.put("FetchData:${bname}",
384 getAndUnpackNodesInfoArtifact(bdata.jobname, bdata.copyToDir, bdata.buildId))
385 }
386 parallel stepsForParallel
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400387 // remove timestamp field from rendered files
388 sh("find ${reclassNodeInfoDir} -type f -exec sed -i '/ timestamp: .*/d' {} \\;")
Denis Egorenkod8748942018-09-07 12:26:20 +0400389 // Compare patched and HEAD reclass pillars
390 result = '\n' + common.comparePillars(reclassNodeInfoDir, env.BUILD_URL, '')
391 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300392 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400393 stage('Check include order') {
azvyagintseve7b8e792018-09-21 17:27:01 +0300394 if (!checkIncludeOrder) {
395 common.infoMsg('Check include order require to much time, and currently disabled!')
396
397 } else {
398 def correctIncludeOrder = ["service", "system", "cluster"]
399 dir(reclassInfoPatchedPath) {
400 def nodeInfoFiles = findFiles(glob: "**/*.reclass.nodeinfo")
401 def messages = ["<b>Wrong include ordering found</b><ul>"]
402 def stepsForParallel = [:]
403 nodeInfoFiles.each { nodeInfo ->
404 stepsForParallel.put("Checking ${nodeInfo.path}:", {
405 def node = readYaml file: nodeInfo.path
406 def classes = node['classes']
407 def curClassID = 0
408 def prevClassID = 0
409 def wrongOrder = false
410 for (String className in classes) {
411 def currentClass = className.tokenize('.')[0]
412 curClassID = correctIncludeOrder.indexOf(currentClass)
413 if (currentClass != correctIncludeOrder[prevClassID]) {
414 if (prevClassID > curClassID) {
415 wrongOrder = true
416 common.warningMsg("File ${nodeInfo.path} contains wrong order of classes including: Includes for ${className} should be declared before ${correctIncludeOrder[prevClassID]} includes")
417 } else {
418 prevClassID = curClassID
419 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400420 }
421 }
azvyagintseve7b8e792018-09-21 17:27:01 +0300422 if (wrongOrder) {
423 messages.add("<li>${nodeInfo.path} contains wrong order of classes including</li>")
424 }
425 })
426 }
427 parallel stepsForParallel
428 def includerOrder = '<b>No wrong include order</b>'
429 if (messages.size() != 1) {
430 includerOrder = messages.join('')
431 }
432 currentBuild.description = currentBuild.description ? currentBuild.description + includerOrder : includerOrder
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400433 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400434 }
435 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300436 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
437
438 } catch (Throwable e) {
439 currentBuild.result = "FAILURE"
440 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
441 throw e
442 } finally {
443 def dummy = "dummy"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300444 }
445 }
chnydae80bb922017-05-29 17:48:40 +0200446}