blob: 6e85801ef63d4ec5e3758cd3a384881ee70e60a7 [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
azvyagintsev30bc82e2018-08-22 12:26:06 +0300106
107 if (product == "infra" || (templateContext.default_context["${product}_enabled"]
108 && templateContext.default_context["${product}_enabled"].toBoolean())) {
109
110 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
111 common.infoMsg("Generating product " + product + " from " + templateDir + " to " + templateOutputDir)
112
113 sh "rm -rf ${templateOutputDir} || true"
114 sh "mkdir -p ${templateOutputDir}"
115 sh "mkdir -p ${outputDestination}"
116
117 python.buildCookiecutterTemplate(templateDir, content, templateOutputDir, virtualenv, templateBaseDir)
118 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
119 } else {
120 common.warningMsg("Product " + product + " is disabled")
121 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300122 }
azvyagintsev30bc82e2018-08-22 12:26:06 +0300123 generateSaltMaster(generatedModel, clusterDomain, clusterName)
chnydae80bb922017-05-29 17:48:40 +0200124 }
chnydae80bb922017-05-29 17:48:40 +0200125}
126
Denis Egorenkod8748942018-09-07 12:26:20 +0400127def getAndUnpackNodesInfoArtifact(jobName, copyTo, build) {
128 return {
129 dir(copyTo) {
130 copyArtifacts(projectName: jobName, selector: specific(build), filter: "nodesinfo.tar.gz")
azvyagintsev3a80e342018-09-19 19:22:48 +0300131 sh "tar -xf nodesinfo.tar.gz"
Denis Egorenkod8748942018-09-07 12:26:20 +0400132 sh "rm -v nodesinfo.tar.gz"
133 }
134 }
135}
azvyagintsev87985532018-07-10 20:49:38 +0300136
Denis Egorenkod8748942018-09-07 12:26:20 +0400137def testModel(modelFile, reclassArtifactName, artifactCopyPath) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300138 // modelFile - `modelfiname` from model/modelfiname/modelfiname.yaml
139 //* Grub all models and send it to check in paralell - by one in thread.
Denis Egorenkod8748942018-09-07 12:26:20 +0400140 def _uuid = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}_${modelFile.toLowerCase()}_" + UUID.randomUUID().toString().take(8)
141 def _values_string = """
azvyagintsev87985532018-07-10 20:49:38 +0300142 ---
Denis Egorenkod8748942018-09-07 12:26:20 +0400143 MODELS_TARGZ: "${env.BUILD_URL}/artifact/${reclassArtifactName}"
144 DockerCName: "${_uuid}"
azvyagintsev87985532018-07-10 20:49:38 +0300145 testReclassEnv: "model/${modelFile}/"
146 modelFile: "contexts/${modelFile}.yml"
azvyagintsev9df82e52018-09-06 19:17:18 +0300147 DISTRIB_REVISION: "${testDistribRevision}"
azvyagintsev87985532018-07-10 20:49:38 +0300148 reclassVersion: "${reclassVersion}"
149 """
Denis Egorenkod8748942018-09-07 12:26:20 +0400150 def chunkJob = build job: chunkJobName, parameters: [
azvyagintsev08b34e32018-09-12 12:29:42 +0300151 [$class: 'TextParameterValue', name: 'EXTRA_VARIABLES_YAML',
azvyagintsev30bc82e2018-08-22 12:26:06 +0300152 value : _values_string.stripIndent()],
azvyagintsev5c0313d2018-08-13 17:13:35 +0300153 ]
Denis Egorenkod8748942018-09-07 12:26:20 +0400154 // Put sub-job info into global map.
155 testModelBuildsData.put(_uuid, ['jobname' : chunkJob.fullProjectName,
156 'copyToDir': "${artifactCopyPath}/${modelFile}",
157 'buildId' : "${chunkJob.number}"])
chnydabc63c9a2017-05-30 15:37:54 +0200158}
159
Denis Egorenkod8748942018-09-07 12:26:20 +0400160def StepTestModel(basename, reclassArtifactName, artifactCopyPath) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300161 // We need to wrap what we return in a Groovy closure, or else it's invoked
162 // when this method is called, not when we pass it to parallel.
163 // To do this, you need to wrap the code below in { }, and either return
164 // that explicitly, or use { -> } syntax.
165 // return node object
166 return {
167 node(slaveNode) {
Denis Egorenkod8748942018-09-07 12:26:20 +0400168 testModel(basename, reclassArtifactName, artifactCopyPath)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300169 }
chnydae80bb922017-05-29 17:48:40 +0200170 }
azvyagintsev87985532018-07-10 20:49:38 +0300171}
172
azvyagintsev9df82e52018-09-06 19:17:18 +0300173def StepPrepareGit(templateEnvFolder, gerrit_data) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300174 // return git clone object
175 return {
azvyagintsev9df82e52018-09-06 19:17:18 +0300176 def checkouted = false
177 common.infoMsg("StepPrepareGit: ${gerrit_data}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300178 // fetch needed sources
179 dir(templateEnvFolder) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300180 if (gerrit_data['gerritRefSpec']) {
181 // Those part might be not work,in case manual var's pass
182 def gerritChange = gerrit.getGerritChange(gerrit_data['gerritName'], gerrit_data['gerritHost'],
183 gerrit_data['GERRIT_CHANGE_NUMBER'], gerrit_data['credentialsId'])
azvyagintsev5c0313d2018-08-13 17:13:35 +0300184 merged = gerritChange.status == "MERGED"
185 if (!merged) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300186 checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300187 } else {
azvyagintsev9df82e52018-09-06 19:17:18 +0300188 // update global variable for pretty return from pipeline
189 alreadyMerged = true
190 common.successMsg("Change ${gerrit_data['GERRIT_CHANGE_NUMBER']} is already merged, no need to gate them")
191 error('change already merged')
azvyagintsev87985532018-07-10 20:49:38 +0300192 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300193 } else {
azvyagintsev9df82e52018-09-06 19:17:18 +0300194 // Get clean HEAD
195 gerrit_data['useGerritTriggerBuildChooser'] = false
196 checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
197 if (!checkouted) {
198 error("Failed to get repo:${gerrit_data}")
199 }
azvyagintsev87985532018-07-10 20:49:38 +0300200 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300201 }
azvyagintsev87985532018-07-10 20:49:38 +0300202 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300203}
204
205def StepGenerateModels(_contextFileList, _virtualenv, _templateEnvDir) {
206 return {
207 for (contextFile in _contextFileList) {
208 generateModel(contextFile, _virtualenv, _templateEnvDir)
209 }
210 }
211}
212
azvyagintsev9df82e52018-09-06 19:17:18 +0300213def globalVariatorsUpdate() {
214 // Simple function, to check and define branch-around variables
215 // In general, simply make transition updates for non-master branch
216 // based on magic logic
217 def message = ''
azvyagintsevb266ad22018-09-11 12:11:11 +0300218 if (env.GERRIT_PROJECT) {
azvyagintseve0eb6cd2018-09-12 13:00:40 +0300219 // TODO are we going to have such branches?
azvyagintsev9df82e52018-09-06 19:17:18 +0300220 if (!['nightly', 'testing', 'stable', 'proposed', 'master'].contains(env.GERRIT_BRANCH)) {
221 gerritDataCC['gerritBranch'] = env.GERRIT_BRANCH
222 gerritDataRS['gerritBranch'] = env.GERRIT_BRANCH
223 // 'binary' branch logic w\o 'release/' prefix
224 testDistribRevision = env.GERRIT_BRANCH.split('/')[-1]
225 // Check if we are going to test bleeding-edge release, which doesn't have binary release yet
226 if (!common.checkRemoteBinary([apt_mk_version: testDistribRevision]).linux_system_repo_url) {
227 common.errorMsg("Binary release: ${testDistribRevision} not exist. Fallback to 'proposed'! ")
228 testDistribRevision = 'proposed'
229 }
230 }
231 // Identify, who triggered. To whom we should pass refspec
232 if (env.GERRIT_PROJECT == 'salt-models/reclass-system') {
233 gerritDataRS['gerritRefSpec'] = env.GERRIT_REFSPEC
234 gerritDataRS['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
235 message = "<br/>RECLASS_SYSTEM_GIT_REF =>${gerritDataRS['gerritRefSpec']}"
236 } else if (env.GERRIT_PROJECT == 'mk/cookiecutter-templates') {
237 gerritDataCC['gerritRefSpec'] = env.GERRIT_REFSPEC
238 gerritDataCC['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
239 message = "<br/>COOKIECUTTER_TEMPLATE_REF =>${gerritDataCC['gerritRefSpec']}"
240 } else {
241 error("Unsuported gerrit-project triggered:${env.GERRIT_PROJECT}")
242 }
243
244 message = "<font color='red'>GerritTrigger detected! We are in auto-mode:</font>" +
245 "<br/>Test env variables has been changed:" +
246 "<br/>COOKIECUTTER_TEMPLATE_BRANCH => ${gerritDataCC['gerritBranch']}" +
247 "<br/>DISTRIB_REVISION =>${testDistribRevision}" +
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400248 "<br/>RECLASS_MODEL_BRANCH=> ${gerritDataRS['gerritBranch']}" + message + "<br/>"
azvyagintsev9df82e52018-09-06 19:17:18 +0300249 common.warningMsg(message)
250 currentBuild.description = currentBuild.description ? message + "<br/>" + currentBuild.description : message
251 } else {
252 // Check for passed variables:
azvyagintsev3a80e342018-09-19 19:22:48 +0300253 gerritDataRS['gerritRefSpec'] = env.RECLASS_SYSTEM_GIT_REF ?: null
254 gerritDataCC['gerritRefSpec'] = env.COOKIECUTTER_TEMPLATE_REF ?: null
255 message = "<font color='red'>Non-gerrit trigger run detected!</font>" + "<br/>"
azvyagintsev9df82e52018-09-06 19:17:18 +0300256 currentBuild.description = currentBuild.description ? message + "<br/>" + currentBuild.description : message
257 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300258 gerritDataCCHEAD << gerritDataCC
259 gerritDataCCHEAD['gerritRefSpec'] = null
260 gerritDataCCHEAD['GERRIT_CHANGE_NUMBER'] = null
261 gerritDataRSHEAD << gerritDataRS
262 gerritDataRSHEAD['gerritRefSpec'] = null
263 gerritDataRSHEAD['GERRIT_CHANGE_NUMBER'] = null
264
Denis Egorenkod8748942018-09-07 12:26:20 +0400265}
azvyagintsev9df82e52018-09-06 19:17:18 +0300266
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400267def replaceGeneratedValues(path) {
268 def files = sh(script: "find ${path} -name 'secrets.yml'", returnStdout: true)
269 def stepsForParallel = [:]
270 stepsForParallel.failFast = true
271 files.tokenize().each {
272 stepsForParallel.put("Removing generated passwords/secrets from ${it}",
273 {
274 def secrets = readYaml file: it
azvyagintsev08b34e32018-09-12 12:29:42 +0300275 for (String key in secrets['parameters']['_param'].keySet()) {
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400276 secrets['parameters']['_param'][key] = 'generated'
277 }
278 // writeYaml can't write to already existing file
279 writeYaml file: "${it}.tmp", data: secrets
280 sh "mv ${it}.tmp ${it}"
281 })
282 }
283 parallel stepsForParallel
284}
285
Denis Egorenkod8748942018-09-07 12:26:20 +0400286def linkReclassModels(contextList, envPath, archiveName) {
287 // to be able share reclass for all subenvs
288 // Also, makes artifact test more solid - use one reclass for all of sub-models.
289 // Archive Structure will be:
290 // tar.gz
291 // ├── contexts
292 // │   └── ceph.yml
azvyagintsev3a80e342018-09-19 19:22:48 +0300293 // ├── ${reclassDirName} <<< reclass system
Denis Egorenkod8748942018-09-07 12:26:20 +0400294 // ├── model
295 // │   └── ceph <<< from `context basename`
296 // │   ├── classes
297 // │   │   ├── cluster
azvyagintsev3a80e342018-09-19 19:22:48 +0300298 // │   │   └── system -> ../../../${reclassDirName}
Denis Egorenkod8748942018-09-07 12:26:20 +0400299 // │   └── nodes
300 // │   └── cfg01.ceph-cluster-domain.local.yml
301 dir(envPath) {
302 for (String context : contextList) {
303 def basename = common.GetBaseName(context, '.yml')
304 dir("${envPath}/model/${basename}") {
azvyagintsev3a80e342018-09-19 19:22:48 +0300305 sh(script: "mkdir -p classes/; ln -sfv ../../../../${common.GetBaseName(archiveName, '.tar.gz')} classes/system ")
Denis Egorenkod8748942018-09-07 12:26:20 +0400306 }
307 }
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400308 // replace all generated passwords/secrets/keys with hardcode value for infra/secrets.yaml
309 replaceGeneratedValues("${envPath}/model")
azvyagintsev3a80e342018-09-19 19:22:48 +0300310 // Save all models and all contexts. Warning! `h` flag must be used!
311 sh(script: "set -ex; tar -czhf ${env.WORKSPACE}/${archiveName} --exclude='*@tmp' model contexts", returnStatus: true)
Denis Egorenkod8748942018-09-07 12:26:20 +0400312 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300313 archiveArtifacts artifacts: archiveName
azvyagintsev9df82e52018-09-06 19:17:18 +0300314}
315
azvyagintsev5c0313d2018-08-13 17:13:35 +0300316timeout(time: 1, unit: 'HOURS') {
317 node(slaveNode) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300318 globalVariatorsUpdate()
azvyagintsev30bc82e2018-08-22 12:26:06 +0300319 def templateEnvHead = "${env.WORKSPACE}/EnvHead/"
320 def templateEnvPatched = "${env.WORKSPACE}/EnvPatched/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300321 def contextFileListHead = []
322 def contextFileListPatched = []
323 def vEnv = "${env.WORKSPACE}/venv"
Denis Egorenkod8748942018-09-07 12:26:20 +0400324 def headReclassArtifactName = "head_reclass.tar.gz"
325 def patchedReclassArtifactName = "patched_reclass.tar.gz"
326 def reclassNodeInfoDir = "${env.WORKSPACE}/reclassNodeInfo_compare/"
327 def reclassInfoHeadPath = "${reclassNodeInfoDir}/old"
328 def reclassInfoPatchedPath = "${reclassNodeInfoDir}/new"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300329 try {
330 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
331 stage('Download and prepare CC env') {
332 // Prepare 2 env - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300333 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300334 paralellEnvs.failFast = true
azvyagintsev9df82e52018-09-06 19:17:18 +0300335 paralellEnvs['downloadEnvHead'] = StepPrepareGit(templateEnvHead, gerritDataCCHEAD)
azvyagintsev3a80e342018-09-19 19:22:48 +0300336 if (gerritDataCC.get('gerritRefSpec', null)) {
337 paralellEnvs['downloadEnvPatched'] = StepPrepareGit(templateEnvPatched, gerritDataCC)
338 parallel paralellEnvs
339 } else {
340 paralellEnvs['downloadEnvPatched'] = { common.warningMsg('No need to process: downloadEnvPatched') }
341 parallel paralellEnvs
342 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
343 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300344 }
345 stage("Check workflow_definition") {
346 // Check only for patchset
347 python.setupVirtualenv(vEnv, 'python2', [], "${templateEnvPatched}/requirements.txt")
azvyagintsev3a80e342018-09-19 19:22:48 +0300348 if (gerritDataCC.get('gerritRefSpec', null)) {
349 common.infoMsg(python.runVirtualenvCommand(vEnv, "python ${templateEnvPatched}/workflow_definition_test.py"))
350 } else {
351 common.infoMsg('No need to process: workflow_definition')
352 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300353 }
354
355 stage("generate models") {
356 dir("${templateEnvHead}/contexts") {
357 for (String x : findFiles(glob: "*.yml")) {
358 contextFileListHead.add(x)
359 }
360 }
361 dir("${templateEnvPatched}/contexts") {
362 for (String x : findFiles(glob: "*.yml")) {
363 contextFileListPatched.add(x)
364 }
365 }
366 // Generate over 2env's - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300367 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300368 paralellEnvs.failFast = true
azvyagintsev30bc82e2018-08-22 12:26:06 +0300369 paralellEnvs['GenerateEnvHead'] = StepGenerateModels(contextFileListHead, vEnv, templateEnvHead)
azvyagintsev3a80e342018-09-19 19:22:48 +0300370 if (gerritDataCC.get('gerritRefSpec', null)) {
371 paralellEnvs['GenerateEnvPatched'] = StepGenerateModels(contextFileListPatched, vEnv, templateEnvPatched)
372 parallel paralellEnvs
373 } else {
374 paralellEnvs['GenerateEnvPatched'] = { common.warningMsg('No need to process: GenerateEnvPatched') }
375 parallel paralellEnvs
376 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300377 }
378
azvyagintsev3a80e342018-09-19 19:22:48 +0300379 // We need 2 git's, one for HEAD, one for PATCHed.
380 // if no patch, use head for both
381 RSHeadDir = common.GetBaseName(headReclassArtifactName, '.tar.gz')
382 RSPatchedDir = common.GetBaseName(patchedReclassArtifactName, '.tar.gz')
383 common.infoMsg("gerritDataRS= ${gerritDataRS}")
384 common.infoMsg("gerritDataRSHEAD= ${gerritDataRSHEAD}")
385 if (gerritDataRS.get('gerritRefSpec', null)) {
386 StepPrepareGit("${env.WORKSPACE}/${RSPatchedDir}/", gerritDataRS).call()
387 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRSHEAD).call()
388 } else {
389 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRS).call()
390 sh("cd ${env.WORKSPACE} ; ln -svf ${RSHeadDir} ${RSPatchedDir}")
391 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300392 // link all models, to use one global reclass
393 // For HEAD
Denis Egorenkod8748942018-09-07 12:26:20 +0400394 linkReclassModels(contextFileListHead, templateEnvHead, headReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300395 // For patched
Denis Egorenkod8748942018-09-07 12:26:20 +0400396 linkReclassModels(contextFileListPatched, templateEnvPatched, patchedReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300397 }
398
Denis Egorenkod8748942018-09-07 12:26:20 +0400399 stage("Compare cluster lvl Head/Patched") {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300400 // Compare patched and HEAD reclass pillars
Denis Egorenkod8748942018-09-07 12:26:20 +0400401 compareRoot = "${env.WORKSPACE}/cluster_compare/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300402 sh(script: """
403 mkdir -pv ${compareRoot}/new ${compareRoot}/old
Denis Egorenkod8748942018-09-07 12:26:20 +0400404 tar -xzf ${patchedReclassArtifactName} --directory ${compareRoot}/new
405 tar -xzf ${headReclassArtifactName} --directory ${compareRoot}/old
azvyagintsev5c0313d2018-08-13 17:13:35 +0300406 """)
407 common.warningMsg('infra/secrets.yml has been skipped from compare!')
azvyagintsev3a80e342018-09-19 19:22:48 +0300408 result = '\n' + common.comparePillars(compareRoot, env.BUILD_URL, "-Ev \'infra/secrets.yml|\\.git\'")
Denis Egorenkod8748942018-09-07 12:26:20 +0400409 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300410 }
Denis Egorenkod8748942018-09-07 12:26:20 +0400411 stage("TestContexts Head/Patched") {
412 def stepsForParallel = [:]
413 stepsForParallel.failFast = true
414 common.infoMsg("Found: ${contextFileListHead.size()} HEAD contexts to test.")
415 for (String context : contextFileListHead) {
416 def basename = common.GetBaseName(context, '.yml')
417 stepsForParallel.put("ContextHeadTest:${basename}", StepTestModel(basename, headReclassArtifactName, reclassInfoHeadPath))
418 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300419 common.infoMsg("Found: ${contextFileListPatched.size()} patched contexts to test.")
420 for (String context : contextFileListPatched) {
421 def basename = common.GetBaseName(context, '.yml')
Denis Egorenkod8748942018-09-07 12:26:20 +0400422 stepsForParallel.put("ContextPatchedTest:${basename}", StepTestModel(basename, patchedReclassArtifactName, reclassInfoPatchedPath))
azvyagintsev5c0313d2018-08-13 17:13:35 +0300423 }
424 parallel stepsForParallel
Denis Egorenkod8748942018-09-07 12:26:20 +0400425 common.infoMsg('All TestContexts tests done')
426 }
427 stage("Compare NodesInfo Head/Patched") {
428 // Download all artifacts
429 def stepsForParallel = [:]
430 stepsForParallel.failFast = true
431 common.infoMsg("Found: ${testModelBuildsData.size()} nodeinfo artifacts to download.")
432 testModelBuildsData.each { bname, bdata ->
433 stepsForParallel.put("FetchData:${bname}",
434 getAndUnpackNodesInfoArtifact(bdata.jobname, bdata.copyToDir, bdata.buildId))
435 }
436 parallel stepsForParallel
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400437 // remove timestamp field from rendered files
438 sh("find ${reclassNodeInfoDir} -type f -exec sed -i '/ timestamp: .*/d' {} \\;")
Denis Egorenkod8748942018-09-07 12:26:20 +0400439 // Compare patched and HEAD reclass pillars
440 result = '\n' + common.comparePillars(reclassNodeInfoDir, env.BUILD_URL, '')
441 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300442 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400443 stage('Check include order') {
azvyagintseve7b8e792018-09-21 17:27:01 +0300444 if (!checkIncludeOrder) {
445 common.infoMsg('Check include order require to much time, and currently disabled!')
446
447 } else {
448 def correctIncludeOrder = ["service", "system", "cluster"]
449 dir(reclassInfoPatchedPath) {
450 def nodeInfoFiles = findFiles(glob: "**/*.reclass.nodeinfo")
451 def messages = ["<b>Wrong include ordering found</b><ul>"]
452 def stepsForParallel = [:]
453 nodeInfoFiles.each { nodeInfo ->
454 stepsForParallel.put("Checking ${nodeInfo.path}:", {
455 def node = readYaml file: nodeInfo.path
456 def classes = node['classes']
457 def curClassID = 0
458 def prevClassID = 0
459 def wrongOrder = false
460 for (String className in classes) {
461 def currentClass = className.tokenize('.')[0]
462 curClassID = correctIncludeOrder.indexOf(currentClass)
463 if (currentClass != correctIncludeOrder[prevClassID]) {
464 if (prevClassID > curClassID) {
465 wrongOrder = true
466 common.warningMsg("File ${nodeInfo.path} contains wrong order of classes including: Includes for ${className} should be declared before ${correctIncludeOrder[prevClassID]} includes")
467 } else {
468 prevClassID = curClassID
469 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400470 }
471 }
azvyagintseve7b8e792018-09-21 17:27:01 +0300472 if (wrongOrder) {
473 messages.add("<li>${nodeInfo.path} contains wrong order of classes including</li>")
474 }
475 })
476 }
477 parallel stepsForParallel
478 def includerOrder = '<b>No wrong include order</b>'
479 if (messages.size() != 1) {
480 includerOrder = messages.join('')
481 }
482 currentBuild.description = currentBuild.description ? currentBuild.description + includerOrder : includerOrder
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400483 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400484 }
485 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300486 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
487
488 } catch (Throwable e) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300489 if (alreadyMerged) {
490 currentBuild.result = 'ABORTED'
491 currentBuild.description = "Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them"
492 return
493 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300494 currentBuild.result = "FAILURE"
495 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
496 throw e
497 } finally {
498 def dummy = "dummy"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300499 }
500 }
chnydae80bb922017-05-29 17:48:40 +0200501}