blob: becfb15f068f050b1e5f4871ccd5f2e7c875860b [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
azvyagintsev3a80e342018-09-19 19:22:48 +030020slaveNode = env.SLAVE_NODE ?: 'docker'
azvyagintseve7b8e792018-09-21 17:27:01 +030021checkIncludeOrder = env.CHECK_INCLUDE_ORDER ?: false
azvyagintsev5c0313d2018-08-13 17:13:35 +030022
azvyagintsev9df82e52018-09-06 19:17:18 +030023// Global var's
24alreadyMerged = false
25gerritConData = [credentialsId : env.CREDENTIALS_ID,
26 gerritName : env.GERRIT_NAME ?: 'mcp-jenkins',
27 gerritHost : env.GERRIT_HOST ?: 'gerrit.mcp.mirantis.net',
azvyagintsevb266ad22018-09-11 12:11:11 +030028 gerritScheme : env.GERRIT_SCHEME ?: 'ssh',
29 gerritPort : env.GERRIT_PORT ?: '29418',
azvyagintsev9df82e52018-09-06 19:17:18 +030030 gerritRefSpec : null,
31 gerritProject : null,
32 withWipeOut : true,
33 GERRIT_CHANGE_NUMBER: null]
34//
35//ccTemplatesRepo = env.COOKIECUTTER_TEMPLATE_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.net:29418/mk/cookiecutter-templates'
azvyagintsev3a80e342018-09-19 19:22:48 +030036gerritDataCCHEAD = [:]
azvyagintsev9df82e52018-09-06 19:17:18 +030037gerritDataCC = [:]
38gerritDataCC << gerritConData
39gerritDataCC['gerritBranch'] = env.COOKIECUTTER_TEMPLATE_BRANCH ?: 'master'
40gerritDataCC['gerritProject'] = 'mk/cookiecutter-templates'
41//
42//reclassSystemRepo = env.RECLASS_SYSTEM_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.net:29418/salt-models/reclass-system'
azvyagintsev3a80e342018-09-19 19:22:48 +030043gerritDataRSHEAD = [:]
azvyagintsev9df82e52018-09-06 19:17:18 +030044gerritDataRS = [:]
45gerritDataRS << gerritConData
46gerritDataRS['gerritBranch'] = env.RECLASS_MODEL_BRANCH ?: 'master'
47gerritDataRS['gerritProject'] = 'salt-models/reclass-system'
48
49// version of debRepos, aka formulas\reclass
azvyagintsev10e24012018-09-10 21:36:32 +030050testDistribRevision = env.DISTRIB_REVISION ?: 'nightly'
51reclassVersion = 'v1.5.4'
azvyagintsevb266ad22018-09-11 12:11:11 +030052if (env.RECLASS_VERSION) {
azvyagintsev9df82e52018-09-06 19:17:18 +030053 reclassVersion = env.RECLASS_VERSION
Vasyl Saienko772e1232018-07-23 14:42:24 +030054}
Denis Egorenkod8748942018-09-07 12:26:20 +040055// Name of sub-test chunk job
56chunkJobName = "test-mk-cookiecutter-templates-chunk"
57testModelBuildsData = [:]
Vasyl Saienko772e1232018-07-23 14:42:24 +030058
chnyda467f10f2017-05-30 17:25:07 +020059def generateSaltMaster(modEnv, clusterDomain, clusterName) {
azvyagintsev5c0313d2018-08-13 17:13:35 +030060 def nodeFile = "${modEnv}/nodes/cfg01.${clusterDomain}.yml"
61 def nodeString = """classes:
chnydae80bb922017-05-29 17:48:40 +020062- cluster.${clusterName}.infra.config
63parameters:
64 _param:
65 linux_system_codename: xenial
66 reclass_data_revision: master
67 linux:
68 system:
69 name: cfg01
70 domain: ${clusterDomain}
71"""
azvyagintsev5c0313d2018-08-13 17:13:35 +030072 sh "mkdir -p ${modEnv}/nodes/"
73 println "Create file ${nodeFile}"
74 writeFile(file: nodeFile, text: nodeString)
azvyagintsev87985532018-07-10 20:49:38 +030075}
76
azvyagintsev30bc82e2018-08-22 12:26:06 +030077/**
78 *
79 * @param contextFile - path to `contexts/XXX.yaml file`
azvyagintsev9df82e52018-09-06 19:17:18 +030080 * @param virtualenv - pyvenv with CC and dep's
azvyagintsev30bc82e2018-08-22 12:26:06 +030081 * @param templateEnvDir - root of CookieCutter
82 * @return
83 */
84
azvyagintsev5c0313d2018-08-13 17:13:35 +030085def generateModel(contextFile, virtualenv, templateEnvDir) {
86 def modelEnv = "${templateEnvDir}/model"
87 def basename = common.GetBaseName(contextFile, '.yml')
88 def generatedModel = "${modelEnv}/${basename}"
89 def content = readFile(file: "${templateEnvDir}/contexts/${contextFile}")
90 def templateContext = readYaml text: content
91 def clusterDomain = templateContext.default_context.cluster_domain
92 def clusterName = templateContext.default_context.cluster_name
93 def outputDestination = "${generatedModel}/classes/cluster/${clusterName}"
94 def templateBaseDir = templateEnvDir
95 def templateDir = "${templateEnvDir}/dir"
96 def templateOutputDir = templateBaseDir
azvyagintsev30bc82e2018-08-22 12:26:06 +030097 dir(templateEnvDir) {
98 sh(script: "rm -rf ${generatedModel} || true")
99 common.infoMsg("Generating model from context ${contextFile}")
100 def productList = ["infra", "cicd", "opencontrail", "kubernetes", "openstack", "oss", "stacklight", "ceph"]
101 for (product in productList) {
chnydae80bb922017-05-29 17:48:40 +0200102
azvyagintsev30bc82e2018-08-22 12:26:06 +0300103 // get templateOutputDir and productDir
Michal Kobus197f6112018-09-21 14:30:16 +0200104 templateOutputDir = "${templateEnvDir}/output/${product}"
105 productDir = product
azvyagintsev7cdcc7a2018-09-25 16:47:24 +0300106 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
107 // Bw for 2018.8.1 and older releases
108 if (product.startsWith("stacklight") && (!fileExists(templateDir))) {
109 common.warningMsg("Old release detected! productDir => 'stacklight2' ")
110 productDir = "stacklight2"
111 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
112 }
azvyagintsev30bc82e2018-08-22 12:26:06 +0300113 if (product == "infra" || (templateContext.default_context["${product}_enabled"]
114 && templateContext.default_context["${product}_enabled"].toBoolean())) {
115
azvyagintsev30bc82e2018-08-22 12:26:06 +0300116 common.infoMsg("Generating product " + product + " from " + templateDir + " to " + templateOutputDir)
117
118 sh "rm -rf ${templateOutputDir} || true"
119 sh "mkdir -p ${templateOutputDir}"
120 sh "mkdir -p ${outputDestination}"
121
122 python.buildCookiecutterTemplate(templateDir, content, templateOutputDir, virtualenv, templateBaseDir)
123 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
124 } else {
125 common.warningMsg("Product " + product + " is disabled")
126 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300127 }
azvyagintsev30bc82e2018-08-22 12:26:06 +0300128 generateSaltMaster(generatedModel, clusterDomain, clusterName)
chnydae80bb922017-05-29 17:48:40 +0200129 }
chnydae80bb922017-05-29 17:48:40 +0200130}
131
Denis Egorenkod8748942018-09-07 12:26:20 +0400132def getAndUnpackNodesInfoArtifact(jobName, copyTo, build) {
133 return {
134 dir(copyTo) {
135 copyArtifacts(projectName: jobName, selector: specific(build), filter: "nodesinfo.tar.gz")
azvyagintsev3a80e342018-09-19 19:22:48 +0300136 sh "tar -xf nodesinfo.tar.gz"
Denis Egorenkod8748942018-09-07 12:26:20 +0400137 sh "rm -v nodesinfo.tar.gz"
138 }
139 }
140}
azvyagintsev87985532018-07-10 20:49:38 +0300141
Denis Egorenkod8748942018-09-07 12:26:20 +0400142def testModel(modelFile, reclassArtifactName, artifactCopyPath) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300143 // modelFile - `modelfiname` from model/modelfiname/modelfiname.yaml
144 //* Grub all models and send it to check in paralell - by one in thread.
Denis Egorenkod8748942018-09-07 12:26:20 +0400145 def _uuid = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}_${modelFile.toLowerCase()}_" + UUID.randomUUID().toString().take(8)
146 def _values_string = """
azvyagintsev87985532018-07-10 20:49:38 +0300147 ---
Denis Egorenkod8748942018-09-07 12:26:20 +0400148 MODELS_TARGZ: "${env.BUILD_URL}/artifact/${reclassArtifactName}"
149 DockerCName: "${_uuid}"
azvyagintsev87985532018-07-10 20:49:38 +0300150 testReclassEnv: "model/${modelFile}/"
151 modelFile: "contexts/${modelFile}.yml"
azvyagintsev9df82e52018-09-06 19:17:18 +0300152 DISTRIB_REVISION: "${testDistribRevision}"
azvyagintsev87985532018-07-10 20:49:38 +0300153 reclassVersion: "${reclassVersion}"
154 """
Denis Egorenkod8748942018-09-07 12:26:20 +0400155 def chunkJob = build job: chunkJobName, parameters: [
azvyagintsev08b34e32018-09-12 12:29:42 +0300156 [$class: 'TextParameterValue', name: 'EXTRA_VARIABLES_YAML',
azvyagintsev30bc82e2018-08-22 12:26:06 +0300157 value : _values_string.stripIndent()],
azvyagintsev5c0313d2018-08-13 17:13:35 +0300158 ]
Denis Egorenkod8748942018-09-07 12:26:20 +0400159 // Put sub-job info into global map.
160 testModelBuildsData.put(_uuid, ['jobname' : chunkJob.fullProjectName,
161 'copyToDir': "${artifactCopyPath}/${modelFile}",
162 'buildId' : "${chunkJob.number}"])
chnydabc63c9a2017-05-30 15:37:54 +0200163}
164
Denis Egorenkod8748942018-09-07 12:26:20 +0400165def StepTestModel(basename, reclassArtifactName, artifactCopyPath) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300166 // We need to wrap what we return in a Groovy closure, or else it's invoked
167 // when this method is called, not when we pass it to parallel.
168 // To do this, you need to wrap the code below in { }, and either return
169 // that explicitly, or use { -> } syntax.
170 // return node object
171 return {
172 node(slaveNode) {
Denis Egorenkod8748942018-09-07 12:26:20 +0400173 testModel(basename, reclassArtifactName, artifactCopyPath)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300174 }
chnydae80bb922017-05-29 17:48:40 +0200175 }
azvyagintsev87985532018-07-10 20:49:38 +0300176}
177
azvyagintsev9df82e52018-09-06 19:17:18 +0300178def StepPrepareGit(templateEnvFolder, gerrit_data) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300179 // return git clone object
180 return {
azvyagintsev9df82e52018-09-06 19:17:18 +0300181 def checkouted = false
182 common.infoMsg("StepPrepareGit: ${gerrit_data}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300183 // fetch needed sources
184 dir(templateEnvFolder) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300185 if (gerrit_data['gerritRefSpec']) {
186 // Those part might be not work,in case manual var's pass
187 def gerritChange = gerrit.getGerritChange(gerrit_data['gerritName'], gerrit_data['gerritHost'],
188 gerrit_data['GERRIT_CHANGE_NUMBER'], gerrit_data['credentialsId'])
azvyagintsev5c0313d2018-08-13 17:13:35 +0300189 merged = gerritChange.status == "MERGED"
190 if (!merged) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300191 checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300192 } else {
azvyagintsev9df82e52018-09-06 19:17:18 +0300193 // update global variable for pretty return from pipeline
194 alreadyMerged = true
195 common.successMsg("Change ${gerrit_data['GERRIT_CHANGE_NUMBER']} is already merged, no need to gate them")
196 error('change already merged')
azvyagintsev87985532018-07-10 20:49:38 +0300197 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300198 } else {
azvyagintsev9df82e52018-09-06 19:17:18 +0300199 // Get clean HEAD
200 gerrit_data['useGerritTriggerBuildChooser'] = false
201 checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
202 if (!checkouted) {
203 error("Failed to get repo:${gerrit_data}")
204 }
azvyagintsev87985532018-07-10 20:49:38 +0300205 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300206 }
azvyagintsev87985532018-07-10 20:49:38 +0300207 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300208}
209
210def StepGenerateModels(_contextFileList, _virtualenv, _templateEnvDir) {
211 return {
212 for (contextFile in _contextFileList) {
213 generateModel(contextFile, _virtualenv, _templateEnvDir)
214 }
215 }
216}
217
azvyagintsev9df82e52018-09-06 19:17:18 +0300218def globalVariatorsUpdate() {
219 // Simple function, to check and define branch-around variables
220 // In general, simply make transition updates for non-master branch
221 // based on magic logic
222 def message = ''
azvyagintsevb266ad22018-09-11 12:11:11 +0300223 if (env.GERRIT_PROJECT) {
azvyagintseve0eb6cd2018-09-12 13:00:40 +0300224 // TODO are we going to have such branches?
azvyagintsev9df82e52018-09-06 19:17:18 +0300225 if (!['nightly', 'testing', 'stable', 'proposed', 'master'].contains(env.GERRIT_BRANCH)) {
226 gerritDataCC['gerritBranch'] = env.GERRIT_BRANCH
227 gerritDataRS['gerritBranch'] = env.GERRIT_BRANCH
228 // 'binary' branch logic w\o 'release/' prefix
229 testDistribRevision = env.GERRIT_BRANCH.split('/')[-1]
230 // Check if we are going to test bleeding-edge release, which doesn't have binary release yet
231 if (!common.checkRemoteBinary([apt_mk_version: testDistribRevision]).linux_system_repo_url) {
232 common.errorMsg("Binary release: ${testDistribRevision} not exist. Fallback to 'proposed'! ")
233 testDistribRevision = 'proposed'
234 }
235 }
236 // Identify, who triggered. To whom we should pass refspec
237 if (env.GERRIT_PROJECT == 'salt-models/reclass-system') {
238 gerritDataRS['gerritRefSpec'] = env.GERRIT_REFSPEC
239 gerritDataRS['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
240 message = "<br/>RECLASS_SYSTEM_GIT_REF =>${gerritDataRS['gerritRefSpec']}"
241 } else if (env.GERRIT_PROJECT == 'mk/cookiecutter-templates') {
242 gerritDataCC['gerritRefSpec'] = env.GERRIT_REFSPEC
243 gerritDataCC['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
244 message = "<br/>COOKIECUTTER_TEMPLATE_REF =>${gerritDataCC['gerritRefSpec']}"
245 } else {
246 error("Unsuported gerrit-project triggered:${env.GERRIT_PROJECT}")
247 }
248
249 message = "<font color='red'>GerritTrigger detected! We are in auto-mode:</font>" +
250 "<br/>Test env variables has been changed:" +
251 "<br/>COOKIECUTTER_TEMPLATE_BRANCH => ${gerritDataCC['gerritBranch']}" +
252 "<br/>DISTRIB_REVISION =>${testDistribRevision}" +
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400253 "<br/>RECLASS_MODEL_BRANCH=> ${gerritDataRS['gerritBranch']}" + message + "<br/>"
azvyagintsev9df82e52018-09-06 19:17:18 +0300254 common.warningMsg(message)
255 currentBuild.description = currentBuild.description ? message + "<br/>" + currentBuild.description : message
256 } else {
257 // Check for passed variables:
azvyagintsev3a80e342018-09-19 19:22:48 +0300258 gerritDataRS['gerritRefSpec'] = env.RECLASS_SYSTEM_GIT_REF ?: null
259 gerritDataCC['gerritRefSpec'] = env.COOKIECUTTER_TEMPLATE_REF ?: null
260 message = "<font color='red'>Non-gerrit trigger run detected!</font>" + "<br/>"
azvyagintsev9df82e52018-09-06 19:17:18 +0300261 currentBuild.description = currentBuild.description ? message + "<br/>" + currentBuild.description : message
262 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300263 gerritDataCCHEAD << gerritDataCC
264 gerritDataCCHEAD['gerritRefSpec'] = null
265 gerritDataCCHEAD['GERRIT_CHANGE_NUMBER'] = null
266 gerritDataRSHEAD << gerritDataRS
267 gerritDataRSHEAD['gerritRefSpec'] = null
268 gerritDataRSHEAD['GERRIT_CHANGE_NUMBER'] = null
269
Denis Egorenkod8748942018-09-07 12:26:20 +0400270}
azvyagintsev9df82e52018-09-06 19:17:18 +0300271
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400272def replaceGeneratedValues(path) {
273 def files = sh(script: "find ${path} -name 'secrets.yml'", returnStdout: true)
274 def stepsForParallel = [:]
275 stepsForParallel.failFast = true
276 files.tokenize().each {
277 stepsForParallel.put("Removing generated passwords/secrets from ${it}",
278 {
279 def secrets = readYaml file: it
azvyagintsev08b34e32018-09-12 12:29:42 +0300280 for (String key in secrets['parameters']['_param'].keySet()) {
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400281 secrets['parameters']['_param'][key] = 'generated'
282 }
283 // writeYaml can't write to already existing file
284 writeYaml file: "${it}.tmp", data: secrets
285 sh "mv ${it}.tmp ${it}"
286 })
287 }
288 parallel stepsForParallel
289}
290
Denis Egorenkod8748942018-09-07 12:26:20 +0400291def linkReclassModels(contextList, envPath, archiveName) {
292 // to be able share reclass for all subenvs
293 // Also, makes artifact test more solid - use one reclass for all of sub-models.
294 // Archive Structure will be:
295 // tar.gz
296 // ├── contexts
297 // │   └── ceph.yml
azvyagintsev3a80e342018-09-19 19:22:48 +0300298 // ├── ${reclassDirName} <<< reclass system
Denis Egorenkod8748942018-09-07 12:26:20 +0400299 // ├── model
300 // │   └── ceph <<< from `context basename`
301 // │   ├── classes
302 // │   │   ├── cluster
azvyagintsev3a80e342018-09-19 19:22:48 +0300303 // │   │   └── system -> ../../../${reclassDirName}
Denis Egorenkod8748942018-09-07 12:26:20 +0400304 // │   └── nodes
305 // │   └── cfg01.ceph-cluster-domain.local.yml
306 dir(envPath) {
307 for (String context : contextList) {
308 def basename = common.GetBaseName(context, '.yml')
309 dir("${envPath}/model/${basename}") {
azvyagintsev3a80e342018-09-19 19:22:48 +0300310 sh(script: "mkdir -p classes/; ln -sfv ../../../../${common.GetBaseName(archiveName, '.tar.gz')} classes/system ")
Denis Egorenkod8748942018-09-07 12:26:20 +0400311 }
312 }
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400313 // replace all generated passwords/secrets/keys with hardcode value for infra/secrets.yaml
314 replaceGeneratedValues("${envPath}/model")
azvyagintsev3a80e342018-09-19 19:22:48 +0300315 // Save all models and all contexts. Warning! `h` flag must be used!
316 sh(script: "set -ex; tar -czhf ${env.WORKSPACE}/${archiveName} --exclude='*@tmp' model contexts", returnStatus: true)
Denis Egorenkod8748942018-09-07 12:26:20 +0400317 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300318 archiveArtifacts artifacts: archiveName
azvyagintsev9df82e52018-09-06 19:17:18 +0300319}
320
azvyagintsev5c0313d2018-08-13 17:13:35 +0300321timeout(time: 1, unit: 'HOURS') {
322 node(slaveNode) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300323 globalVariatorsUpdate()
azvyagintsev30bc82e2018-08-22 12:26:06 +0300324 def templateEnvHead = "${env.WORKSPACE}/EnvHead/"
325 def templateEnvPatched = "${env.WORKSPACE}/EnvPatched/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300326 def contextFileListHead = []
327 def contextFileListPatched = []
328 def vEnv = "${env.WORKSPACE}/venv"
Denis Egorenkod8748942018-09-07 12:26:20 +0400329 def headReclassArtifactName = "head_reclass.tar.gz"
330 def patchedReclassArtifactName = "patched_reclass.tar.gz"
331 def reclassNodeInfoDir = "${env.WORKSPACE}/reclassNodeInfo_compare/"
332 def reclassInfoHeadPath = "${reclassNodeInfoDir}/old"
333 def reclassInfoPatchedPath = "${reclassNodeInfoDir}/new"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300334 try {
335 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
336 stage('Download and prepare CC env') {
337 // Prepare 2 env - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300338 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300339 paralellEnvs.failFast = true
azvyagintsev9df82e52018-09-06 19:17:18 +0300340 paralellEnvs['downloadEnvHead'] = StepPrepareGit(templateEnvHead, gerritDataCCHEAD)
azvyagintsev3a80e342018-09-19 19:22:48 +0300341 if (gerritDataCC.get('gerritRefSpec', null)) {
342 paralellEnvs['downloadEnvPatched'] = StepPrepareGit(templateEnvPatched, gerritDataCC)
343 parallel paralellEnvs
344 } else {
345 paralellEnvs['downloadEnvPatched'] = { common.warningMsg('No need to process: downloadEnvPatched') }
346 parallel paralellEnvs
347 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
348 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300349 }
350 stage("Check workflow_definition") {
351 // Check only for patchset
352 python.setupVirtualenv(vEnv, 'python2', [], "${templateEnvPatched}/requirements.txt")
azvyagintsev3a80e342018-09-19 19:22:48 +0300353 if (gerritDataCC.get('gerritRefSpec', null)) {
354 common.infoMsg(python.runVirtualenvCommand(vEnv, "python ${templateEnvPatched}/workflow_definition_test.py"))
355 } else {
356 common.infoMsg('No need to process: workflow_definition')
357 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300358 }
359
360 stage("generate models") {
361 dir("${templateEnvHead}/contexts") {
362 for (String x : findFiles(glob: "*.yml")) {
363 contextFileListHead.add(x)
364 }
365 }
366 dir("${templateEnvPatched}/contexts") {
367 for (String x : findFiles(glob: "*.yml")) {
368 contextFileListPatched.add(x)
369 }
370 }
371 // Generate over 2env's - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300372 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300373 paralellEnvs.failFast = true
azvyagintsev30bc82e2018-08-22 12:26:06 +0300374 paralellEnvs['GenerateEnvHead'] = StepGenerateModels(contextFileListHead, vEnv, templateEnvHead)
azvyagintsev3a80e342018-09-19 19:22:48 +0300375 if (gerritDataCC.get('gerritRefSpec', null)) {
376 paralellEnvs['GenerateEnvPatched'] = StepGenerateModels(contextFileListPatched, vEnv, templateEnvPatched)
377 parallel paralellEnvs
378 } else {
379 paralellEnvs['GenerateEnvPatched'] = { common.warningMsg('No need to process: GenerateEnvPatched') }
380 parallel paralellEnvs
381 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300382 }
383
azvyagintsev3a80e342018-09-19 19:22:48 +0300384 // We need 2 git's, one for HEAD, one for PATCHed.
385 // if no patch, use head for both
386 RSHeadDir = common.GetBaseName(headReclassArtifactName, '.tar.gz')
387 RSPatchedDir = common.GetBaseName(patchedReclassArtifactName, '.tar.gz')
388 common.infoMsg("gerritDataRS= ${gerritDataRS}")
389 common.infoMsg("gerritDataRSHEAD= ${gerritDataRSHEAD}")
390 if (gerritDataRS.get('gerritRefSpec', null)) {
391 StepPrepareGit("${env.WORKSPACE}/${RSPatchedDir}/", gerritDataRS).call()
392 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRSHEAD).call()
393 } else {
394 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRS).call()
395 sh("cd ${env.WORKSPACE} ; ln -svf ${RSHeadDir} ${RSPatchedDir}")
396 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300397 // link all models, to use one global reclass
398 // For HEAD
Denis Egorenkod8748942018-09-07 12:26:20 +0400399 linkReclassModels(contextFileListHead, templateEnvHead, headReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300400 // For patched
Denis Egorenkod8748942018-09-07 12:26:20 +0400401 linkReclassModels(contextFileListPatched, templateEnvPatched, patchedReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300402 }
403
Denis Egorenkod8748942018-09-07 12:26:20 +0400404 stage("Compare cluster lvl Head/Patched") {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300405 // Compare patched and HEAD reclass pillars
Denis Egorenkod8748942018-09-07 12:26:20 +0400406 compareRoot = "${env.WORKSPACE}/cluster_compare/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300407 sh(script: """
408 mkdir -pv ${compareRoot}/new ${compareRoot}/old
Denis Egorenkod8748942018-09-07 12:26:20 +0400409 tar -xzf ${patchedReclassArtifactName} --directory ${compareRoot}/new
410 tar -xzf ${headReclassArtifactName} --directory ${compareRoot}/old
azvyagintsev5c0313d2018-08-13 17:13:35 +0300411 """)
412 common.warningMsg('infra/secrets.yml has been skipped from compare!')
azvyagintsev3a80e342018-09-19 19:22:48 +0300413 result = '\n' + common.comparePillars(compareRoot, env.BUILD_URL, "-Ev \'infra/secrets.yml|\\.git\'")
Denis Egorenkod8748942018-09-07 12:26:20 +0400414 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300415 }
Denis Egorenkod8748942018-09-07 12:26:20 +0400416 stage("TestContexts Head/Patched") {
417 def stepsForParallel = [:]
418 stepsForParallel.failFast = true
419 common.infoMsg("Found: ${contextFileListHead.size()} HEAD contexts to test.")
420 for (String context : contextFileListHead) {
421 def basename = common.GetBaseName(context, '.yml')
422 stepsForParallel.put("ContextHeadTest:${basename}", StepTestModel(basename, headReclassArtifactName, reclassInfoHeadPath))
423 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300424 common.infoMsg("Found: ${contextFileListPatched.size()} patched contexts to test.")
425 for (String context : contextFileListPatched) {
426 def basename = common.GetBaseName(context, '.yml')
Denis Egorenkod8748942018-09-07 12:26:20 +0400427 stepsForParallel.put("ContextPatchedTest:${basename}", StepTestModel(basename, patchedReclassArtifactName, reclassInfoPatchedPath))
azvyagintsev5c0313d2018-08-13 17:13:35 +0300428 }
429 parallel stepsForParallel
Denis Egorenkod8748942018-09-07 12:26:20 +0400430 common.infoMsg('All TestContexts tests done')
431 }
432 stage("Compare NodesInfo Head/Patched") {
433 // Download all artifacts
434 def stepsForParallel = [:]
435 stepsForParallel.failFast = true
436 common.infoMsg("Found: ${testModelBuildsData.size()} nodeinfo artifacts to download.")
437 testModelBuildsData.each { bname, bdata ->
438 stepsForParallel.put("FetchData:${bname}",
439 getAndUnpackNodesInfoArtifact(bdata.jobname, bdata.copyToDir, bdata.buildId))
440 }
441 parallel stepsForParallel
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400442 // remove timestamp field from rendered files
443 sh("find ${reclassNodeInfoDir} -type f -exec sed -i '/ timestamp: .*/d' {} \\;")
Denis Egorenkod8748942018-09-07 12:26:20 +0400444 // Compare patched and HEAD reclass pillars
445 result = '\n' + common.comparePillars(reclassNodeInfoDir, env.BUILD_URL, '')
446 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300447 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400448 stage('Check include order') {
azvyagintseve7b8e792018-09-21 17:27:01 +0300449 if (!checkIncludeOrder) {
450 common.infoMsg('Check include order require to much time, and currently disabled!')
451
452 } else {
453 def correctIncludeOrder = ["service", "system", "cluster"]
454 dir(reclassInfoPatchedPath) {
455 def nodeInfoFiles = findFiles(glob: "**/*.reclass.nodeinfo")
456 def messages = ["<b>Wrong include ordering found</b><ul>"]
457 def stepsForParallel = [:]
458 nodeInfoFiles.each { nodeInfo ->
459 stepsForParallel.put("Checking ${nodeInfo.path}:", {
460 def node = readYaml file: nodeInfo.path
461 def classes = node['classes']
462 def curClassID = 0
463 def prevClassID = 0
464 def wrongOrder = false
465 for (String className in classes) {
466 def currentClass = className.tokenize('.')[0]
467 curClassID = correctIncludeOrder.indexOf(currentClass)
468 if (currentClass != correctIncludeOrder[prevClassID]) {
469 if (prevClassID > curClassID) {
470 wrongOrder = true
471 common.warningMsg("File ${nodeInfo.path} contains wrong order of classes including: Includes for ${className} should be declared before ${correctIncludeOrder[prevClassID]} includes")
472 } else {
473 prevClassID = curClassID
474 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400475 }
476 }
azvyagintseve7b8e792018-09-21 17:27:01 +0300477 if (wrongOrder) {
478 messages.add("<li>${nodeInfo.path} contains wrong order of classes including</li>")
479 }
480 })
481 }
482 parallel stepsForParallel
483 def includerOrder = '<b>No wrong include order</b>'
484 if (messages.size() != 1) {
485 includerOrder = messages.join('')
486 }
487 currentBuild.description = currentBuild.description ? currentBuild.description + includerOrder : includerOrder
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400488 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400489 }
490 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300491 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
492
493 } catch (Throwable e) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300494 if (alreadyMerged) {
495 currentBuild.result = 'ABORTED'
496 currentBuild.description = "Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them"
497 return
498 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300499 currentBuild.result = "FAILURE"
500 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
501 throw e
502 } finally {
503 def dummy = "dummy"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300504 }
505 }
chnydae80bb922017-05-29 17:48:40 +0200506}