blob: 8076041c7bf800e2fa9f643a2034528b9feccb2e [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
Aleksey Zvyagintsev4a804212019-02-07 13:02:31 +000030slaveNode = 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
azvyagintsev9df82e52018-09-06 19:17:18 +030034gerritConData = [credentialsId : env.CREDENTIALS_ID,
35 gerritName : env.GERRIT_NAME ?: 'mcp-jenkins',
Roman Vyalovf0c596e2018-10-01 17:56:09 +030036 gerritHost : env.GERRIT_HOST ?: 'gerrit.mcp.mirantis.com',
azvyagintsevb266ad22018-09-11 12:11:11 +030037 gerritScheme : env.GERRIT_SCHEME ?: 'ssh',
38 gerritPort : env.GERRIT_PORT ?: '29418',
azvyagintsev9df82e52018-09-06 19:17:18 +030039 gerritRefSpec : null,
40 gerritProject : null,
41 withWipeOut : true,
42 GERRIT_CHANGE_NUMBER: null]
43//
Roman Vyalovf0c596e2018-10-01 17:56:09 +030044//ccTemplatesRepo = env.COOKIECUTTER_TEMPLATE_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.com:29418/mk/cookiecutter-templates'
azvyagintsev3a80e342018-09-19 19:22:48 +030045gerritDataCCHEAD = [:]
azvyagintsev9df82e52018-09-06 19:17:18 +030046gerritDataCC = [:]
47gerritDataCC << gerritConData
48gerritDataCC['gerritBranch'] = env.COOKIECUTTER_TEMPLATE_BRANCH ?: 'master'
azvyagintsev458278c2018-09-25 18:38:30 +030049gerritDataCC['gerritRefSpec'] = env.COOKIECUTTER_TEMPLATE_REF ?: null
azvyagintsev9df82e52018-09-06 19:17:18 +030050gerritDataCC['gerritProject'] = 'mk/cookiecutter-templates'
51//
Roman Vyalovf0c596e2018-10-01 17:56:09 +030052//reclassSystemRepo = env.RECLASS_SYSTEM_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.com:29418/salt-models/reclass-system'
azvyagintsev3a80e342018-09-19 19:22:48 +030053gerritDataRSHEAD = [:]
azvyagintsev9df82e52018-09-06 19:17:18 +030054gerritDataRS = [:]
55gerritDataRS << gerritConData
Denis Egorenkoe7040ac2018-10-24 20:11:04 +040056gerritDataRS['gerritBranch'] = env.RECLASS_SYSTEM_BRANCH ?: 'master'
azvyagintsev458278c2018-09-25 18:38:30 +030057gerritDataRS['gerritRefSpec'] = env.RECLASS_SYSTEM_GIT_REF ?: null
azvyagintsev9df82e52018-09-06 19:17:18 +030058gerritDataRS['gerritProject'] = 'salt-models/reclass-system'
59
azvyagintsevec055b42018-10-11 12:59:05 +030060// version of debRepos, aka formulas|reclass|ubuntu
azvyagintsev10e24012018-09-10 21:36:32 +030061testDistribRevision = env.DISTRIB_REVISION ?: 'nightly'
Denis Egorenko086aff12018-10-18 17:54:59 +040062
Denis Egorenkod8748942018-09-07 12:26:20 +040063// Name of sub-test chunk job
64chunkJobName = "test-mk-cookiecutter-templates-chunk"
65testModelBuildsData = [:]
Vasyl Saienko772e1232018-07-23 14:42:24 +030066
Denis Egorenkod8748942018-09-07 12:26:20 +040067def getAndUnpackNodesInfoArtifact(jobName, copyTo, build) {
68 return {
69 dir(copyTo) {
70 copyArtifacts(projectName: jobName, selector: specific(build), filter: "nodesinfo.tar.gz")
azvyagintsev3a80e342018-09-19 19:22:48 +030071 sh "tar -xf nodesinfo.tar.gz"
Denis Egorenkod8748942018-09-07 12:26:20 +040072 sh "rm -v nodesinfo.tar.gz"
73 }
74 }
75}
azvyagintsev87985532018-07-10 20:49:38 +030076
Denis Egorenko086aff12018-10-18 17:54:59 +040077def testModel(modelFile, reclassArtifactName, artifactCopyPath, useExtraRepos = false) {
azvyagintsev5c0313d2018-08-13 17:13:35 +030078 // modelFile - `modelfiname` from model/modelfiname/modelfiname.yaml
79 //* Grub all models and send it to check in paralell - by one in thread.
Denis Egorenkod8748942018-09-07 12:26:20 +040080 def _uuid = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}_${modelFile.toLowerCase()}_" + UUID.randomUUID().toString().take(8)
Alexander Evseev02fe5eb2018-11-15 13:58:36 +010081 def _values = [
azvyagintsev4220bff2019-01-09 21:32:11 +020082 MODELS_TARGZ : "${env.BUILD_URL}/artifact/${reclassArtifactName}",
83 DockerCName : _uuid,
84 testReclassEnv : "model/${modelFile}/",
85 modelFile : "contexts/${modelFile}.yml",
Alexander Evseev02fe5eb2018-11-15 13:58:36 +010086 DISTRIB_REVISION: testDistribRevision,
azvyagintsev4220bff2019-01-09 21:32:11 +020087 useExtraRepos : useExtraRepos,
Alexander Evseev02fe5eb2018-11-15 13:58:36 +010088 ]
89 def _values_string = JsonOutput.toJson(_values << extraVars)
Denis Egorenkod8748942018-09-07 12:26:20 +040090 def chunkJob = build job: chunkJobName, parameters: [
azvyagintsev08b34e32018-09-12 12:29:42 +030091 [$class: 'TextParameterValue', name: 'EXTRA_VARIABLES_YAML',
azvyagintsev30bc82e2018-08-22 12:26:06 +030092 value : _values_string.stripIndent()],
azvyagintsev5c0313d2018-08-13 17:13:35 +030093 ]
Denis Egorenkod8748942018-09-07 12:26:20 +040094 // Put sub-job info into global map.
95 testModelBuildsData.put(_uuid, ['jobname' : chunkJob.fullProjectName,
96 'copyToDir': "${artifactCopyPath}/${modelFile}",
97 'buildId' : "${chunkJob.number}"])
chnydabc63c9a2017-05-30 15:37:54 +020098}
99
Denis Egorenko086aff12018-10-18 17:54:59 +0400100def StepTestModel(basename, reclassArtifactName, artifactCopyPath, useExtraRepos = false) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300101 // We need to wrap what we return in a Groovy closure, or else it's invoked
102 // when this method is called, not when we pass it to parallel.
103 // To do this, you need to wrap the code below in { }, and either return
104 // that explicitly, or use { -> } syntax.
105 // return node object
106 return {
107 node(slaveNode) {
Denis Egorenko086aff12018-10-18 17:54:59 +0400108 testModel(basename, reclassArtifactName, artifactCopyPath, useExtraRepos)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300109 }
chnydae80bb922017-05-29 17:48:40 +0200110 }
azvyagintsev87985532018-07-10 20:49:38 +0300111}
112
azvyagintsev9df82e52018-09-06 19:17:18 +0300113def StepPrepareGit(templateEnvFolder, gerrit_data) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300114 // return git clone object
115 return {
azvyagintsev9df82e52018-09-06 19:17:18 +0300116 common.infoMsg("StepPrepareGit: ${gerrit_data}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300117 // fetch needed sources
118 dir(templateEnvFolder) {
Denis Egorenko80d45b22019-01-31 22:28:38 +0400119 if (! gerrit_data['gerritRefSpec']) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300120 // Get clean HEAD
121 gerrit_data['useGerritTriggerBuildChooser'] = false
Denis Egorenko80d45b22019-01-31 22:28:38 +0400122 }
123 def checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
124 if (!checkouted) {
125 error("Failed to get repo:${gerrit_data}")
azvyagintsev87985532018-07-10 20:49:38 +0300126 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300127 }
azvyagintsev87985532018-07-10 20:49:38 +0300128 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300129}
130
131def StepGenerateModels(_contextFileList, _virtualenv, _templateEnvDir) {
132 return {
133 for (contextFile in _contextFileList) {
Denis Egorenkof3469092018-10-17 17:05:50 +0400134 def basename = common.GetBaseName(contextFile, '.yml')
135 def context = readFile(file: "${_templateEnvDir}/contexts/${contextFile}")
136 python.generateModel(context, basename, 'cfg01', _virtualenv, "${_templateEnvDir}/model", _templateEnvDir)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300137 }
138 }
139}
140
azvyagintsev9df82e52018-09-06 19:17:18 +0300141def globalVariatorsUpdate() {
142 // Simple function, to check and define branch-around variables
143 // In general, simply make transition updates for non-master branch
144 // based on magic logic
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400145 def newline = '<br/>'
146 def messages = []
azvyagintsevb266ad22018-09-11 12:11:11 +0300147 if (env.GERRIT_PROJECT) {
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400148 messages.add("<font color='red'>GerritTrigger detected! We are in auto-mode:</font>")
149 messages.add("Test env variables has been changed:")
azvyagintseve0eb6cd2018-09-12 13:00:40 +0300150 // TODO are we going to have such branches?
azvyagintsev9df82e52018-09-06 19:17:18 +0300151 if (!['nightly', 'testing', 'stable', 'proposed', 'master'].contains(env.GERRIT_BRANCH)) {
152 gerritDataCC['gerritBranch'] = env.GERRIT_BRANCH
153 gerritDataRS['gerritBranch'] = env.GERRIT_BRANCH
azvyagintsev458278c2018-09-25 18:38:30 +0300154 testDistribRevision = env.GERRIT_BRANCH
azvyagintsev9df82e52018-09-06 19:17:18 +0300155 }
Denis Egorenko60e45c12018-11-12 12:00:11 +0400156 messages.add("COOKIECUTTER_TEMPLATE_BRANCH => ${gerritDataCC['gerritBranch']}")
157 messages.add("RECLASS_SYSTEM_BRANCH => ${gerritDataRS['gerritBranch']}")
azvyagintsev9df82e52018-09-06 19:17:18 +0300158 // Identify, who triggered. To whom we should pass refspec
159 if (env.GERRIT_PROJECT == 'salt-models/reclass-system') {
160 gerritDataRS['gerritRefSpec'] = env.GERRIT_REFSPEC
161 gerritDataRS['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400162 messages.add("RECLASS_SYSTEM_GIT_REF => ${gerritDataRS['gerritRefSpec']}")
azvyagintsev9df82e52018-09-06 19:17:18 +0300163 } else if (env.GERRIT_PROJECT == 'mk/cookiecutter-templates') {
164 gerritDataCC['gerritRefSpec'] = env.GERRIT_REFSPEC
165 gerritDataCC['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400166 messages.add("COOKIECUTTER_TEMPLATE_REF => ${gerritDataCC['gerritRefSpec']}")
azvyagintsev9df82e52018-09-06 19:17:18 +0300167 } else {
168 error("Unsuported gerrit-project triggered:${env.GERRIT_PROJECT}")
169 }
azvyagintsev9df82e52018-09-06 19:17:18 +0300170 } else {
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400171 messages.add("<font color='red'>Non-gerrit trigger run detected!</font>")
azvyagintsev9df82e52018-09-06 19:17:18 +0300172 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300173 gerritDataCCHEAD << gerritDataCC
174 gerritDataCCHEAD['gerritRefSpec'] = null
175 gerritDataCCHEAD['GERRIT_CHANGE_NUMBER'] = null
176 gerritDataRSHEAD << gerritDataRS
177 gerritDataRSHEAD['gerritRefSpec'] = null
178 gerritDataRSHEAD['GERRIT_CHANGE_NUMBER'] = null
azvyagintsev458278c2018-09-25 18:38:30 +0300179 // 'binary' branch logic w\o 'release/' prefix
180 if (testDistribRevision.contains('/')) {
181 testDistribRevision = testDistribRevision.split('/')[-1]
182 }
183 // Check if we are going to test bleeding-edge release, which doesn't have binary release yet
azvyagintsev5c200e72018-12-28 15:58:09 +0200184 // After 2018q4 releases, need to also check 'static' repo, for example ubuntu.
azvyagintsev4220bff2019-01-09 21:32:11 +0200185 binTest = common.checkRemoteBinary(['mcp_version': testDistribRevision])
azvyagintsev5c200e72018-12-28 15:58:09 +0200186 if (!binTest.linux_system_repo_url || !binTest.linux_system_repo_ubuntu_url) {
187 common.errorMsg("Binary release: ${testDistribRevision} not exist or not full. Fallback to 'proposed'! ")
azvyagintsev458278c2018-09-25 18:38:30 +0300188 testDistribRevision = 'proposed'
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400189 messages.add("DISTRIB_REVISION => ${testDistribRevision}")
azvyagintsev458278c2018-09-25 18:38:30 +0300190 }
Denis Egorenkofe9a3362018-10-17 15:33:25 +0400191 def message = messages.join(newline) + newline
azvyagintsev458278c2018-09-25 18:38:30 +0300192 currentBuild.description = currentBuild.description ? message + currentBuild.description : message
Denis Egorenkod8748942018-09-07 12:26:20 +0400193}
azvyagintsev9df82e52018-09-06 19:17:18 +0300194
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400195def replaceGeneratedValues(path) {
196 def files = sh(script: "find ${path} -name 'secrets.yml'", returnStdout: true)
197 def stepsForParallel = [:]
198 stepsForParallel.failFast = true
199 files.tokenize().each {
200 stepsForParallel.put("Removing generated passwords/secrets from ${it}",
201 {
202 def secrets = readYaml file: it
azvyagintsev08b34e32018-09-12 12:29:42 +0300203 for (String key in secrets['parameters']['_param'].keySet()) {
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400204 secrets['parameters']['_param'][key] = 'generated'
205 }
206 // writeYaml can't write to already existing file
207 writeYaml file: "${it}.tmp", data: secrets
208 sh "mv ${it}.tmp ${it}"
209 })
210 }
211 parallel stepsForParallel
212}
213
Denis Egorenkod8748942018-09-07 12:26:20 +0400214def linkReclassModels(contextList, envPath, archiveName) {
215 // to be able share reclass for all subenvs
216 // Also, makes artifact test more solid - use one reclass for all of sub-models.
217 // Archive Structure will be:
218 // tar.gz
219 // ├── contexts
220 // │   └── ceph.yml
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400221 // ├── classes-system <<< reclass system
Denis Egorenkod8748942018-09-07 12:26:20 +0400222 // ├── model
223 // │   └── ceph <<< from `context basename`
224 // │   ├── classes
225 // │   │   ├── cluster
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400226 // │   │   └── system -> ../../../classes-system
Denis Egorenkod8748942018-09-07 12:26:20 +0400227 // │   └── nodes
228 // │   └── cfg01.ceph-cluster-domain.local.yml
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400229 def archiveBaseName = common.GetBaseName(archiveName, '.tar.gz')
230 def classesSystemDir = 'classes-system'
231 // copy reclass system under envPath with -R and trailing / to support symlinks direct copy
232 sh("cp -R ${archiveBaseName}/ ${envPath}/${classesSystemDir}")
Denis Egorenkod8748942018-09-07 12:26:20 +0400233 dir(envPath) {
234 for (String context : contextList) {
235 def basename = common.GetBaseName(context, '.yml')
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400236 dir("${envPath}/model/${basename}/classes") {
237 sh(script: "ln -sfv ../../../${classesSystemDir} system ")
Denis Egorenkod8748942018-09-07 12:26:20 +0400238 }
239 }
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400240 // replace all generated passwords/secrets/keys with hardcode value for infra/secrets.yaml
241 replaceGeneratedValues("${envPath}/model")
azvyagintsev3a80e342018-09-19 19:22:48 +0300242 // Save all models and all contexts. Warning! `h` flag must be used!
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400243 sh(script: "set -ex; tar -czhf ${env.WORKSPACE}/${archiveName} --exclude='*@tmp' contexts model ${classesSystemDir}", returnStatus: true)
Denis Egorenkod8748942018-09-07 12:26:20 +0400244 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300245 archiveArtifacts artifacts: archiveName
azvyagintsev9df82e52018-09-06 19:17:18 +0300246}
247
azvyagintsev5c0313d2018-08-13 17:13:35 +0300248timeout(time: 1, unit: 'HOURS') {
249 node(slaveNode) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300250 globalVariatorsUpdate()
azvyagintsev30bc82e2018-08-22 12:26:06 +0300251 def templateEnvHead = "${env.WORKSPACE}/EnvHead/"
252 def templateEnvPatched = "${env.WORKSPACE}/EnvPatched/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300253 def contextFileListHead = []
254 def contextFileListPatched = []
255 def vEnv = "${env.WORKSPACE}/venv"
Denis Egorenkod8748942018-09-07 12:26:20 +0400256 def headReclassArtifactName = "head_reclass.tar.gz"
257 def patchedReclassArtifactName = "patched_reclass.tar.gz"
258 def reclassNodeInfoDir = "${env.WORKSPACE}/reclassNodeInfo_compare/"
259 def reclassInfoHeadPath = "${reclassNodeInfoDir}/old"
260 def reclassInfoPatchedPath = "${reclassNodeInfoDir}/new"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300261 try {
262 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
263 stage('Download and prepare CC env') {
264 // Prepare 2 env - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300265 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300266 paralellEnvs.failFast = true
azvyagintsev9df82e52018-09-06 19:17:18 +0300267 paralellEnvs['downloadEnvHead'] = StepPrepareGit(templateEnvHead, gerritDataCCHEAD)
azvyagintsev3a80e342018-09-19 19:22:48 +0300268 if (gerritDataCC.get('gerritRefSpec', null)) {
269 paralellEnvs['downloadEnvPatched'] = StepPrepareGit(templateEnvPatched, gerritDataCC)
270 parallel paralellEnvs
271 } else {
272 paralellEnvs['downloadEnvPatched'] = { common.warningMsg('No need to process: downloadEnvPatched') }
273 parallel paralellEnvs
274 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
275 }
Denis Egorenko3de070c2018-11-20 13:57:35 +0400276 if (env.CUSTOM_COOKIECUTTER_CONTEXT) {
277 // readYaml to check custom context structure
278 def customContext = readYaml text: env.CUSTOM_COOKIECUTTER_CONTEXT
279 writeYaml file: "${templateEnvHead}/contexts/custom_context.yml", data: customContext
280 writeYaml file: "${templateEnvPatched}/contexts/custom_context.yml", data: customContext
281 common.infoMsg("Using custom context provided from job parameter 'CUSTOM_COOKIECUTTER_CONTEXT'")
282 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300283 }
azvyagintsev8ab34fd2019-01-10 15:32:26 +0200284 stage('Check workflow_definition') {
285 // Prepare venv for old env's, aka non-tox based
286 if (!fileExists(new File(templateEnvPatched, 'tox.ini').toString()) || !fileExists(new File(templateEnvHead, 'tox.ini').toString())) {
287 python.setupVirtualenv(vEnv, 'python2', [], "${templateEnvPatched}/requirements.txt")
288 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300289 // Check only for patchset
azvyagintsev1037fb42019-01-10 13:52:38 +0200290 if (fileExists(new File(templateEnvPatched, 'tox.ini').toString())) {
291 dir(templateEnvPatched) {
292 output = sh(returnStdout: true, script: "tox -ve test")
293 common.infoMsg("[Cookiecutter test] Result: ${output}")
azvyagintsev4220bff2019-01-09 21:32:11 +0200294 }
azvyagintsev1037fb42019-01-10 13:52:38 +0200295
azvyagintsev3a80e342018-09-19 19:22:48 +0300296 } else {
azvyagintsev1037fb42019-01-10 13:52:38 +0200297 common.warningMsg('Old Cookiecutter env detected!')
azvyagintsev1037fb42019-01-10 13:52:38 +0200298 common.infoMsg(python.runVirtualenvCommand(vEnv, "python ${templateEnvPatched}/workflow_definition_test.py"))
azvyagintsev3a80e342018-09-19 19:22:48 +0300299 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300300 }
301
azvyagintsev8ab34fd2019-01-10 15:32:26 +0200302 stage('generate models') {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300303 dir("${templateEnvHead}/contexts") {
304 for (String x : findFiles(glob: "*.yml")) {
305 contextFileListHead.add(x)
306 }
307 }
308 dir("${templateEnvPatched}/contexts") {
309 for (String x : findFiles(glob: "*.yml")) {
310 contextFileListPatched.add(x)
311 }
312 }
313 // Generate over 2env's - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300314 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300315 paralellEnvs.failFast = true
azvyagintsev30bc82e2018-08-22 12:26:06 +0300316 paralellEnvs['GenerateEnvHead'] = StepGenerateModels(contextFileListHead, vEnv, templateEnvHead)
azvyagintsev3a80e342018-09-19 19:22:48 +0300317 if (gerritDataCC.get('gerritRefSpec', null)) {
318 paralellEnvs['GenerateEnvPatched'] = StepGenerateModels(contextFileListPatched, vEnv, templateEnvPatched)
319 parallel paralellEnvs
320 } else {
321 paralellEnvs['GenerateEnvPatched'] = { common.warningMsg('No need to process: GenerateEnvPatched') }
322 parallel paralellEnvs
323 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300324 }
325
azvyagintsev3a80e342018-09-19 19:22:48 +0300326 // We need 2 git's, one for HEAD, one for PATCHed.
327 // if no patch, use head for both
328 RSHeadDir = common.GetBaseName(headReclassArtifactName, '.tar.gz')
329 RSPatchedDir = common.GetBaseName(patchedReclassArtifactName, '.tar.gz')
330 common.infoMsg("gerritDataRS= ${gerritDataRS}")
331 common.infoMsg("gerritDataRSHEAD= ${gerritDataRSHEAD}")
332 if (gerritDataRS.get('gerritRefSpec', null)) {
333 StepPrepareGit("${env.WORKSPACE}/${RSPatchedDir}/", gerritDataRS).call()
334 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRSHEAD).call()
335 } else {
336 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRS).call()
337 sh("cd ${env.WORKSPACE} ; ln -svf ${RSHeadDir} ${RSPatchedDir}")
338 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300339 // link all models, to use one global reclass
340 // For HEAD
Denis Egorenkod8748942018-09-07 12:26:20 +0400341 linkReclassModels(contextFileListHead, templateEnvHead, headReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300342 // For patched
Denis Egorenkod8748942018-09-07 12:26:20 +0400343 linkReclassModels(contextFileListPatched, templateEnvPatched, patchedReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300344 }
345
Denis Egorenkod8748942018-09-07 12:26:20 +0400346 stage("Compare cluster lvl Head/Patched") {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300347 // Compare patched and HEAD reclass pillars
Denis Egorenkod8748942018-09-07 12:26:20 +0400348 compareRoot = "${env.WORKSPACE}/cluster_compare/"
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400349 // extract archive and drop all copied classes/system before comparing
azvyagintsev5c0313d2018-08-13 17:13:35 +0300350 sh(script: """
351 mkdir -pv ${compareRoot}/new ${compareRoot}/old
Denis Egorenkod8748942018-09-07 12:26:20 +0400352 tar -xzf ${patchedReclassArtifactName} --directory ${compareRoot}/new
353 tar -xzf ${headReclassArtifactName} --directory ${compareRoot}/old
Denis Egorenko7aa5ac52018-10-17 15:14:56 +0400354 find ${compareRoot} -name classes -type d -exec rm -rf '{}/system' \\;
azvyagintsev5c0313d2018-08-13 17:13:35 +0300355 """)
356 common.warningMsg('infra/secrets.yml has been skipped from compare!')
azvyagintsev3a80e342018-09-19 19:22:48 +0300357 result = '\n' + common.comparePillars(compareRoot, env.BUILD_URL, "-Ev \'infra/secrets.yml|\\.git\'")
Denis Egorenkod8748942018-09-07 12:26:20 +0400358 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300359 }
Denis Egorenkod8748942018-09-07 12:26:20 +0400360 stage("TestContexts Head/Patched") {
361 def stepsForParallel = [:]
362 stepsForParallel.failFast = true
363 common.infoMsg("Found: ${contextFileListHead.size()} HEAD contexts to test.")
364 for (String context : contextFileListHead) {
365 def basename = common.GetBaseName(context, '.yml')
366 stepsForParallel.put("ContextHeadTest:${basename}", StepTestModel(basename, headReclassArtifactName, reclassInfoHeadPath))
367 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300368 common.infoMsg("Found: ${contextFileListPatched.size()} patched contexts to test.")
369 for (String context : contextFileListPatched) {
370 def basename = common.GetBaseName(context, '.yml')
Denis Egorenko086aff12018-10-18 17:54:59 +0400371 stepsForParallel.put("ContextPatchedTest:${basename}", StepTestModel(basename, patchedReclassArtifactName, reclassInfoPatchedPath, true))
azvyagintsev5c0313d2018-08-13 17:13:35 +0300372 }
373 parallel stepsForParallel
Denis Egorenkod8748942018-09-07 12:26:20 +0400374 common.infoMsg('All TestContexts tests done')
375 }
376 stage("Compare NodesInfo Head/Patched") {
377 // Download all artifacts
378 def stepsForParallel = [:]
379 stepsForParallel.failFast = true
380 common.infoMsg("Found: ${testModelBuildsData.size()} nodeinfo artifacts to download.")
381 testModelBuildsData.each { bname, bdata ->
382 stepsForParallel.put("FetchData:${bname}",
383 getAndUnpackNodesInfoArtifact(bdata.jobname, bdata.copyToDir, bdata.buildId))
384 }
385 parallel stepsForParallel
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400386 // remove timestamp field from rendered files
387 sh("find ${reclassNodeInfoDir} -type f -exec sed -i '/ timestamp: .*/d' {} \\;")
Denis Egorenkod8748942018-09-07 12:26:20 +0400388 // Compare patched and HEAD reclass pillars
389 result = '\n' + common.comparePillars(reclassNodeInfoDir, env.BUILD_URL, '')
390 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300391 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400392 stage('Check include order') {
azvyagintseve7b8e792018-09-21 17:27:01 +0300393 if (!checkIncludeOrder) {
394 common.infoMsg('Check include order require to much time, and currently disabled!')
395
396 } else {
397 def correctIncludeOrder = ["service", "system", "cluster"]
398 dir(reclassInfoPatchedPath) {
399 def nodeInfoFiles = findFiles(glob: "**/*.reclass.nodeinfo")
400 def messages = ["<b>Wrong include ordering found</b><ul>"]
401 def stepsForParallel = [:]
402 nodeInfoFiles.each { nodeInfo ->
403 stepsForParallel.put("Checking ${nodeInfo.path}:", {
404 def node = readYaml file: nodeInfo.path
405 def classes = node['classes']
406 def curClassID = 0
407 def prevClassID = 0
408 def wrongOrder = false
409 for (String className in classes) {
410 def currentClass = className.tokenize('.')[0]
411 curClassID = correctIncludeOrder.indexOf(currentClass)
412 if (currentClass != correctIncludeOrder[prevClassID]) {
413 if (prevClassID > curClassID) {
414 wrongOrder = true
415 common.warningMsg("File ${nodeInfo.path} contains wrong order of classes including: Includes for ${className} should be declared before ${correctIncludeOrder[prevClassID]} includes")
416 } else {
417 prevClassID = curClassID
418 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400419 }
420 }
azvyagintseve7b8e792018-09-21 17:27:01 +0300421 if (wrongOrder) {
422 messages.add("<li>${nodeInfo.path} contains wrong order of classes including</li>")
423 }
424 })
425 }
426 parallel stepsForParallel
427 def includerOrder = '<b>No wrong include order</b>'
428 if (messages.size() != 1) {
429 includerOrder = messages.join('')
430 }
431 currentBuild.description = currentBuild.description ? currentBuild.description + includerOrder : includerOrder
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400432 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400433 }
434 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300435 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
436
437 } catch (Throwable e) {
438 currentBuild.result = "FAILURE"
439 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
440 throw e
441 } finally {
442 def dummy = "dummy"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300443 }
444 }
chnydae80bb922017-05-29 17:48:40 +0200445}