blob: 6813be9b335a32e2df0fa54a731cac5f8f1e3b62 [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'
azvyagintsev458278c2018-09-25 18:38:30 +030040gerritDataCC['gerritRefSpec'] = env.COOKIECUTTER_TEMPLATE_REF ?: null
azvyagintsev9df82e52018-09-06 19:17:18 +030041gerritDataCC['gerritProject'] = 'mk/cookiecutter-templates'
42//
43//reclassSystemRepo = env.RECLASS_SYSTEM_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.net:29418/salt-models/reclass-system'
azvyagintsev3a80e342018-09-19 19:22:48 +030044gerritDataRSHEAD = [:]
azvyagintsev9df82e52018-09-06 19:17:18 +030045gerritDataRS = [:]
46gerritDataRS << gerritConData
47gerritDataRS['gerritBranch'] = env.RECLASS_MODEL_BRANCH ?: 'master'
azvyagintsev458278c2018-09-25 18:38:30 +030048gerritDataRS['gerritRefSpec'] = env.RECLASS_SYSTEM_GIT_REF ?: null
azvyagintsev9df82e52018-09-06 19:17:18 +030049gerritDataRS['gerritProject'] = 'salt-models/reclass-system'
50
51// version of debRepos, aka formulas\reclass
azvyagintsev10e24012018-09-10 21:36:32 +030052testDistribRevision = env.DISTRIB_REVISION ?: 'nightly'
53reclassVersion = 'v1.5.4'
azvyagintsevb266ad22018-09-11 12:11:11 +030054if (env.RECLASS_VERSION) {
azvyagintsev9df82e52018-09-06 19:17:18 +030055 reclassVersion = env.RECLASS_VERSION
Vasyl Saienko772e1232018-07-23 14:42:24 +030056}
Denis Egorenkod8748942018-09-07 12:26:20 +040057// Name of sub-test chunk job
58chunkJobName = "test-mk-cookiecutter-templates-chunk"
59testModelBuildsData = [:]
Vasyl Saienko772e1232018-07-23 14:42:24 +030060
chnyda467f10f2017-05-30 17:25:07 +020061def generateSaltMaster(modEnv, clusterDomain, clusterName) {
azvyagintsev5c0313d2018-08-13 17:13:35 +030062 def nodeFile = "${modEnv}/nodes/cfg01.${clusterDomain}.yml"
63 def nodeString = """classes:
chnydae80bb922017-05-29 17:48:40 +020064- cluster.${clusterName}.infra.config
65parameters:
66 _param:
67 linux_system_codename: xenial
68 reclass_data_revision: master
69 linux:
70 system:
71 name: cfg01
72 domain: ${clusterDomain}
73"""
azvyagintsev5c0313d2018-08-13 17:13:35 +030074 sh "mkdir -p ${modEnv}/nodes/"
75 println "Create file ${nodeFile}"
76 writeFile(file: nodeFile, text: nodeString)
azvyagintsev87985532018-07-10 20:49:38 +030077}
78
azvyagintsev30bc82e2018-08-22 12:26:06 +030079/**
80 *
81 * @param contextFile - path to `contexts/XXX.yaml file`
azvyagintsev9df82e52018-09-06 19:17:18 +030082 * @param virtualenv - pyvenv with CC and dep's
azvyagintsev30bc82e2018-08-22 12:26:06 +030083 * @param templateEnvDir - root of CookieCutter
84 * @return
85 */
86
azvyagintsev5c0313d2018-08-13 17:13:35 +030087def generateModel(contextFile, virtualenv, templateEnvDir) {
88 def modelEnv = "${templateEnvDir}/model"
89 def basename = common.GetBaseName(contextFile, '.yml')
90 def generatedModel = "${modelEnv}/${basename}"
91 def content = readFile(file: "${templateEnvDir}/contexts/${contextFile}")
92 def templateContext = readYaml text: content
93 def clusterDomain = templateContext.default_context.cluster_domain
94 def clusterName = templateContext.default_context.cluster_name
95 def outputDestination = "${generatedModel}/classes/cluster/${clusterName}"
96 def templateBaseDir = templateEnvDir
97 def templateDir = "${templateEnvDir}/dir"
98 def templateOutputDir = templateBaseDir
azvyagintsev30bc82e2018-08-22 12:26:06 +030099 dir(templateEnvDir) {
100 sh(script: "rm -rf ${generatedModel} || true")
101 common.infoMsg("Generating model from context ${contextFile}")
102 def productList = ["infra", "cicd", "opencontrail", "kubernetes", "openstack", "oss", "stacklight", "ceph"]
103 for (product in productList) {
chnydae80bb922017-05-29 17:48:40 +0200104
azvyagintsev30bc82e2018-08-22 12:26:06 +0300105 // get templateOutputDir and productDir
Michal Kobus197f6112018-09-21 14:30:16 +0200106 templateOutputDir = "${templateEnvDir}/output/${product}"
107 productDir = product
azvyagintsev7cdcc7a2018-09-25 16:47:24 +0300108 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
109 // Bw for 2018.8.1 and older releases
110 if (product.startsWith("stacklight") && (!fileExists(templateDir))) {
111 common.warningMsg("Old release detected! productDir => 'stacklight2' ")
112 productDir = "stacklight2"
113 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
114 }
azvyagintsev30bc82e2018-08-22 12:26:06 +0300115 if (product == "infra" || (templateContext.default_context["${product}_enabled"]
116 && templateContext.default_context["${product}_enabled"].toBoolean())) {
117
azvyagintsev30bc82e2018-08-22 12:26:06 +0300118 common.infoMsg("Generating product " + product + " from " + templateDir + " to " + templateOutputDir)
119
120 sh "rm -rf ${templateOutputDir} || true"
121 sh "mkdir -p ${templateOutputDir}"
122 sh "mkdir -p ${outputDestination}"
123
124 python.buildCookiecutterTemplate(templateDir, content, templateOutputDir, virtualenv, templateBaseDir)
125 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
126 } else {
127 common.warningMsg("Product " + product + " is disabled")
128 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300129 }
azvyagintsev30bc82e2018-08-22 12:26:06 +0300130 generateSaltMaster(generatedModel, clusterDomain, clusterName)
chnydae80bb922017-05-29 17:48:40 +0200131 }
chnydae80bb922017-05-29 17:48:40 +0200132}
133
Denis Egorenkod8748942018-09-07 12:26:20 +0400134def getAndUnpackNodesInfoArtifact(jobName, copyTo, build) {
135 return {
136 dir(copyTo) {
137 copyArtifacts(projectName: jobName, selector: specific(build), filter: "nodesinfo.tar.gz")
azvyagintsev3a80e342018-09-19 19:22:48 +0300138 sh "tar -xf nodesinfo.tar.gz"
Denis Egorenkod8748942018-09-07 12:26:20 +0400139 sh "rm -v nodesinfo.tar.gz"
140 }
141 }
142}
azvyagintsev87985532018-07-10 20:49:38 +0300143
Denis Egorenkod8748942018-09-07 12:26:20 +0400144def testModel(modelFile, reclassArtifactName, artifactCopyPath) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300145 // modelFile - `modelfiname` from model/modelfiname/modelfiname.yaml
146 //* Grub all models and send it to check in paralell - by one in thread.
Denis Egorenkod8748942018-09-07 12:26:20 +0400147 def _uuid = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}_${modelFile.toLowerCase()}_" + UUID.randomUUID().toString().take(8)
148 def _values_string = """
azvyagintsev87985532018-07-10 20:49:38 +0300149 ---
Denis Egorenkod8748942018-09-07 12:26:20 +0400150 MODELS_TARGZ: "${env.BUILD_URL}/artifact/${reclassArtifactName}"
151 DockerCName: "${_uuid}"
azvyagintsev87985532018-07-10 20:49:38 +0300152 testReclassEnv: "model/${modelFile}/"
153 modelFile: "contexts/${modelFile}.yml"
azvyagintsev9df82e52018-09-06 19:17:18 +0300154 DISTRIB_REVISION: "${testDistribRevision}"
azvyagintsev87985532018-07-10 20:49:38 +0300155 reclassVersion: "${reclassVersion}"
156 """
Denis Egorenkod8748942018-09-07 12:26:20 +0400157 def chunkJob = build job: chunkJobName, parameters: [
azvyagintsev08b34e32018-09-12 12:29:42 +0300158 [$class: 'TextParameterValue', name: 'EXTRA_VARIABLES_YAML',
azvyagintsev30bc82e2018-08-22 12:26:06 +0300159 value : _values_string.stripIndent()],
azvyagintsev5c0313d2018-08-13 17:13:35 +0300160 ]
Denis Egorenkod8748942018-09-07 12:26:20 +0400161 // Put sub-job info into global map.
162 testModelBuildsData.put(_uuid, ['jobname' : chunkJob.fullProjectName,
163 'copyToDir': "${artifactCopyPath}/${modelFile}",
164 'buildId' : "${chunkJob.number}"])
chnydabc63c9a2017-05-30 15:37:54 +0200165}
166
Denis Egorenkod8748942018-09-07 12:26:20 +0400167def StepTestModel(basename, reclassArtifactName, artifactCopyPath) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300168 // We need to wrap what we return in a Groovy closure, or else it's invoked
169 // when this method is called, not when we pass it to parallel.
170 // To do this, you need to wrap the code below in { }, and either return
171 // that explicitly, or use { -> } syntax.
172 // return node object
173 return {
174 node(slaveNode) {
Denis Egorenkod8748942018-09-07 12:26:20 +0400175 testModel(basename, reclassArtifactName, artifactCopyPath)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300176 }
chnydae80bb922017-05-29 17:48:40 +0200177 }
azvyagintsev87985532018-07-10 20:49:38 +0300178}
179
azvyagintsev9df82e52018-09-06 19:17:18 +0300180def StepPrepareGit(templateEnvFolder, gerrit_data) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300181 // return git clone object
182 return {
azvyagintsev9df82e52018-09-06 19:17:18 +0300183 def checkouted = false
184 common.infoMsg("StepPrepareGit: ${gerrit_data}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300185 // fetch needed sources
186 dir(templateEnvFolder) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300187 if (gerrit_data['gerritRefSpec']) {
188 // Those part might be not work,in case manual var's pass
189 def gerritChange = gerrit.getGerritChange(gerrit_data['gerritName'], gerrit_data['gerritHost'],
190 gerrit_data['GERRIT_CHANGE_NUMBER'], gerrit_data['credentialsId'])
azvyagintsev5c0313d2018-08-13 17:13:35 +0300191 merged = gerritChange.status == "MERGED"
192 if (!merged) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300193 checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300194 } else {
azvyagintsev9df82e52018-09-06 19:17:18 +0300195 // update global variable for pretty return from pipeline
196 alreadyMerged = true
197 common.successMsg("Change ${gerrit_data['GERRIT_CHANGE_NUMBER']} is already merged, no need to gate them")
198 error('change already merged')
azvyagintsev87985532018-07-10 20:49:38 +0300199 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300200 } else {
azvyagintsev9df82e52018-09-06 19:17:18 +0300201 // Get clean HEAD
202 gerrit_data['useGerritTriggerBuildChooser'] = false
203 checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
204 if (!checkouted) {
205 error("Failed to get repo:${gerrit_data}")
206 }
azvyagintsev87985532018-07-10 20:49:38 +0300207 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300208 }
azvyagintsev87985532018-07-10 20:49:38 +0300209 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300210}
211
212def StepGenerateModels(_contextFileList, _virtualenv, _templateEnvDir) {
213 return {
214 for (contextFile in _contextFileList) {
215 generateModel(contextFile, _virtualenv, _templateEnvDir)
216 }
217 }
218}
219
azvyagintsev9df82e52018-09-06 19:17:18 +0300220def globalVariatorsUpdate() {
221 // Simple function, to check and define branch-around variables
222 // In general, simply make transition updates for non-master branch
223 // based on magic logic
azvyagintsev458278c2018-09-25 18:38:30 +0300224 def message = '<br/>'
azvyagintsevb266ad22018-09-11 12:11:11 +0300225 if (env.GERRIT_PROJECT) {
azvyagintseve0eb6cd2018-09-12 13:00:40 +0300226 // TODO are we going to have such branches?
azvyagintsev9df82e52018-09-06 19:17:18 +0300227 if (!['nightly', 'testing', 'stable', 'proposed', 'master'].contains(env.GERRIT_BRANCH)) {
228 gerritDataCC['gerritBranch'] = env.GERRIT_BRANCH
229 gerritDataRS['gerritBranch'] = env.GERRIT_BRANCH
azvyagintsev458278c2018-09-25 18:38:30 +0300230 testDistribRevision = env.GERRIT_BRANCH
azvyagintsev9df82e52018-09-06 19:17:18 +0300231 }
232 // Identify, who triggered. To whom we should pass refspec
233 if (env.GERRIT_PROJECT == 'salt-models/reclass-system') {
234 gerritDataRS['gerritRefSpec'] = env.GERRIT_REFSPEC
235 gerritDataRS['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
azvyagintsev458278c2018-09-25 18:38:30 +0300236 message = message + "<br/>RECLASS_SYSTEM_GIT_REF =>${gerritDataRS['gerritRefSpec']}"
azvyagintsev9df82e52018-09-06 19:17:18 +0300237 } else if (env.GERRIT_PROJECT == 'mk/cookiecutter-templates') {
238 gerritDataCC['gerritRefSpec'] = env.GERRIT_REFSPEC
239 gerritDataCC['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
azvyagintsev458278c2018-09-25 18:38:30 +0300240 message = message + "<br/>COOKIECUTTER_TEMPLATE_REF =>${gerritDataCC['gerritRefSpec']}"
azvyagintsev9df82e52018-09-06 19:17:18 +0300241 } else {
242 error("Unsuported gerrit-project triggered:${env.GERRIT_PROJECT}")
243 }
azvyagintsev9df82e52018-09-06 19:17:18 +0300244 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']}" +
azvyagintsev458278c2018-09-25 18:38:30 +0300247 "<br/>RECLASS_MODEL_BRANCH=> ${gerritDataRS['gerritBranch']}" + message
azvyagintsev9df82e52018-09-06 19:17:18 +0300248 } else {
azvyagintsev458278c2018-09-25 18:38:30 +0300249 message = "<font color='red'>Non-gerrit trigger run detected!</font>" + message
azvyagintsev9df82e52018-09-06 19:17:18 +0300250 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300251 gerritDataCCHEAD << gerritDataCC
252 gerritDataCCHEAD['gerritRefSpec'] = null
253 gerritDataCCHEAD['GERRIT_CHANGE_NUMBER'] = null
254 gerritDataRSHEAD << gerritDataRS
255 gerritDataRSHEAD['gerritRefSpec'] = null
256 gerritDataRSHEAD['GERRIT_CHANGE_NUMBER'] = null
azvyagintsev458278c2018-09-25 18:38:30 +0300257 // 'binary' branch logic w\o 'release/' prefix
258 if (testDistribRevision.contains('/')) {
259 testDistribRevision = testDistribRevision.split('/')[-1]
260 }
261 // Check if we are going to test bleeding-edge release, which doesn't have binary release yet
262 if (!common.checkRemoteBinary([apt_mk_version: testDistribRevision]).linux_system_repo_url) {
263 common.errorMsg("Binary release: ${testDistribRevision} not exist. Fallback to 'proposed'! ")
264 testDistribRevision = 'proposed'
265 message = "<br/>DISTRIB_REVISION =>${testDistribRevision}" + message
266 }
267 currentBuild.description = currentBuild.description ? message + currentBuild.description : message
Denis Egorenkod8748942018-09-07 12:26:20 +0400268}
azvyagintsev9df82e52018-09-06 19:17:18 +0300269
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400270def replaceGeneratedValues(path) {
271 def files = sh(script: "find ${path} -name 'secrets.yml'", returnStdout: true)
272 def stepsForParallel = [:]
273 stepsForParallel.failFast = true
274 files.tokenize().each {
275 stepsForParallel.put("Removing generated passwords/secrets from ${it}",
276 {
277 def secrets = readYaml file: it
azvyagintsev08b34e32018-09-12 12:29:42 +0300278 for (String key in secrets['parameters']['_param'].keySet()) {
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400279 secrets['parameters']['_param'][key] = 'generated'
280 }
281 // writeYaml can't write to already existing file
282 writeYaml file: "${it}.tmp", data: secrets
283 sh "mv ${it}.tmp ${it}"
284 })
285 }
286 parallel stepsForParallel
287}
288
Denis Egorenkod8748942018-09-07 12:26:20 +0400289def linkReclassModels(contextList, envPath, archiveName) {
290 // to be able share reclass for all subenvs
291 // Also, makes artifact test more solid - use one reclass for all of sub-models.
292 // Archive Structure will be:
293 // tar.gz
294 // ├── contexts
295 // │   └── ceph.yml
azvyagintsev3a80e342018-09-19 19:22:48 +0300296 // ├── ${reclassDirName} <<< reclass system
Denis Egorenkod8748942018-09-07 12:26:20 +0400297 // ├── model
298 // │   └── ceph <<< from `context basename`
299 // │   ├── classes
300 // │   │   ├── cluster
azvyagintsev3a80e342018-09-19 19:22:48 +0300301 // │   │   └── system -> ../../../${reclassDirName}
Denis Egorenkod8748942018-09-07 12:26:20 +0400302 // │   └── nodes
303 // │   └── cfg01.ceph-cluster-domain.local.yml
304 dir(envPath) {
305 for (String context : contextList) {
306 def basename = common.GetBaseName(context, '.yml')
307 dir("${envPath}/model/${basename}") {
azvyagintsev3a80e342018-09-19 19:22:48 +0300308 sh(script: "mkdir -p classes/; ln -sfv ../../../../${common.GetBaseName(archiveName, '.tar.gz')} classes/system ")
Denis Egorenkod8748942018-09-07 12:26:20 +0400309 }
310 }
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400311 // replace all generated passwords/secrets/keys with hardcode value for infra/secrets.yaml
312 replaceGeneratedValues("${envPath}/model")
azvyagintsev3a80e342018-09-19 19:22:48 +0300313 // Save all models and all contexts. Warning! `h` flag must be used!
314 sh(script: "set -ex; tar -czhf ${env.WORKSPACE}/${archiveName} --exclude='*@tmp' model contexts", returnStatus: true)
Denis Egorenkod8748942018-09-07 12:26:20 +0400315 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300316 archiveArtifacts artifacts: archiveName
azvyagintsev9df82e52018-09-06 19:17:18 +0300317}
318
azvyagintsev5c0313d2018-08-13 17:13:35 +0300319timeout(time: 1, unit: 'HOURS') {
320 node(slaveNode) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300321 globalVariatorsUpdate()
azvyagintsev30bc82e2018-08-22 12:26:06 +0300322 def templateEnvHead = "${env.WORKSPACE}/EnvHead/"
323 def templateEnvPatched = "${env.WORKSPACE}/EnvPatched/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300324 def contextFileListHead = []
325 def contextFileListPatched = []
326 def vEnv = "${env.WORKSPACE}/venv"
Denis Egorenkod8748942018-09-07 12:26:20 +0400327 def headReclassArtifactName = "head_reclass.tar.gz"
328 def patchedReclassArtifactName = "patched_reclass.tar.gz"
329 def reclassNodeInfoDir = "${env.WORKSPACE}/reclassNodeInfo_compare/"
330 def reclassInfoHeadPath = "${reclassNodeInfoDir}/old"
331 def reclassInfoPatchedPath = "${reclassNodeInfoDir}/new"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300332 try {
333 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
334 stage('Download and prepare CC env') {
335 // Prepare 2 env - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300336 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300337 paralellEnvs.failFast = true
azvyagintsev9df82e52018-09-06 19:17:18 +0300338 paralellEnvs['downloadEnvHead'] = StepPrepareGit(templateEnvHead, gerritDataCCHEAD)
azvyagintsev3a80e342018-09-19 19:22:48 +0300339 if (gerritDataCC.get('gerritRefSpec', null)) {
340 paralellEnvs['downloadEnvPatched'] = StepPrepareGit(templateEnvPatched, gerritDataCC)
341 parallel paralellEnvs
342 } else {
343 paralellEnvs['downloadEnvPatched'] = { common.warningMsg('No need to process: downloadEnvPatched') }
344 parallel paralellEnvs
345 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
346 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300347 }
348 stage("Check workflow_definition") {
349 // Check only for patchset
350 python.setupVirtualenv(vEnv, 'python2', [], "${templateEnvPatched}/requirements.txt")
azvyagintsev3a80e342018-09-19 19:22:48 +0300351 if (gerritDataCC.get('gerritRefSpec', null)) {
352 common.infoMsg(python.runVirtualenvCommand(vEnv, "python ${templateEnvPatched}/workflow_definition_test.py"))
353 } else {
354 common.infoMsg('No need to process: workflow_definition')
355 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300356 }
357
358 stage("generate models") {
359 dir("${templateEnvHead}/contexts") {
360 for (String x : findFiles(glob: "*.yml")) {
361 contextFileListHead.add(x)
362 }
363 }
364 dir("${templateEnvPatched}/contexts") {
365 for (String x : findFiles(glob: "*.yml")) {
366 contextFileListPatched.add(x)
367 }
368 }
369 // Generate over 2env's - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300370 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300371 paralellEnvs.failFast = true
azvyagintsev30bc82e2018-08-22 12:26:06 +0300372 paralellEnvs['GenerateEnvHead'] = StepGenerateModels(contextFileListHead, vEnv, templateEnvHead)
azvyagintsev3a80e342018-09-19 19:22:48 +0300373 if (gerritDataCC.get('gerritRefSpec', null)) {
374 paralellEnvs['GenerateEnvPatched'] = StepGenerateModels(contextFileListPatched, vEnv, templateEnvPatched)
375 parallel paralellEnvs
376 } else {
377 paralellEnvs['GenerateEnvPatched'] = { common.warningMsg('No need to process: GenerateEnvPatched') }
378 parallel paralellEnvs
379 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300380 }
381
azvyagintsev3a80e342018-09-19 19:22:48 +0300382 // We need 2 git's, one for HEAD, one for PATCHed.
383 // if no patch, use head for both
384 RSHeadDir = common.GetBaseName(headReclassArtifactName, '.tar.gz')
385 RSPatchedDir = common.GetBaseName(patchedReclassArtifactName, '.tar.gz')
386 common.infoMsg("gerritDataRS= ${gerritDataRS}")
387 common.infoMsg("gerritDataRSHEAD= ${gerritDataRSHEAD}")
388 if (gerritDataRS.get('gerritRefSpec', null)) {
389 StepPrepareGit("${env.WORKSPACE}/${RSPatchedDir}/", gerritDataRS).call()
390 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRSHEAD).call()
391 } else {
392 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRS).call()
393 sh("cd ${env.WORKSPACE} ; ln -svf ${RSHeadDir} ${RSPatchedDir}")
394 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300395 // link all models, to use one global reclass
396 // For HEAD
Denis Egorenkod8748942018-09-07 12:26:20 +0400397 linkReclassModels(contextFileListHead, templateEnvHead, headReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300398 // For patched
Denis Egorenkod8748942018-09-07 12:26:20 +0400399 linkReclassModels(contextFileListPatched, templateEnvPatched, patchedReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300400 }
401
Denis Egorenkod8748942018-09-07 12:26:20 +0400402 stage("Compare cluster lvl Head/Patched") {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300403 // Compare patched and HEAD reclass pillars
Denis Egorenkod8748942018-09-07 12:26:20 +0400404 compareRoot = "${env.WORKSPACE}/cluster_compare/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300405 sh(script: """
406 mkdir -pv ${compareRoot}/new ${compareRoot}/old
Denis Egorenkod8748942018-09-07 12:26:20 +0400407 tar -xzf ${patchedReclassArtifactName} --directory ${compareRoot}/new
408 tar -xzf ${headReclassArtifactName} --directory ${compareRoot}/old
azvyagintsev5c0313d2018-08-13 17:13:35 +0300409 """)
410 common.warningMsg('infra/secrets.yml has been skipped from compare!')
azvyagintsev3a80e342018-09-19 19:22:48 +0300411 result = '\n' + common.comparePillars(compareRoot, env.BUILD_URL, "-Ev \'infra/secrets.yml|\\.git\'")
Denis Egorenkod8748942018-09-07 12:26:20 +0400412 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300413 }
Denis Egorenkod8748942018-09-07 12:26:20 +0400414 stage("TestContexts Head/Patched") {
415 def stepsForParallel = [:]
416 stepsForParallel.failFast = true
417 common.infoMsg("Found: ${contextFileListHead.size()} HEAD contexts to test.")
418 for (String context : contextFileListHead) {
419 def basename = common.GetBaseName(context, '.yml')
420 stepsForParallel.put("ContextHeadTest:${basename}", StepTestModel(basename, headReclassArtifactName, reclassInfoHeadPath))
421 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300422 common.infoMsg("Found: ${contextFileListPatched.size()} patched contexts to test.")
423 for (String context : contextFileListPatched) {
424 def basename = common.GetBaseName(context, '.yml')
Denis Egorenkod8748942018-09-07 12:26:20 +0400425 stepsForParallel.put("ContextPatchedTest:${basename}", StepTestModel(basename, patchedReclassArtifactName, reclassInfoPatchedPath))
azvyagintsev5c0313d2018-08-13 17:13:35 +0300426 }
427 parallel stepsForParallel
Denis Egorenkod8748942018-09-07 12:26:20 +0400428 common.infoMsg('All TestContexts tests done')
429 }
430 stage("Compare NodesInfo Head/Patched") {
431 // Download all artifacts
432 def stepsForParallel = [:]
433 stepsForParallel.failFast = true
434 common.infoMsg("Found: ${testModelBuildsData.size()} nodeinfo artifacts to download.")
435 testModelBuildsData.each { bname, bdata ->
436 stepsForParallel.put("FetchData:${bname}",
437 getAndUnpackNodesInfoArtifact(bdata.jobname, bdata.copyToDir, bdata.buildId))
438 }
439 parallel stepsForParallel
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400440 // remove timestamp field from rendered files
441 sh("find ${reclassNodeInfoDir} -type f -exec sed -i '/ timestamp: .*/d' {} \\;")
Denis Egorenkod8748942018-09-07 12:26:20 +0400442 // Compare patched and HEAD reclass pillars
443 result = '\n' + common.comparePillars(reclassNodeInfoDir, env.BUILD_URL, '')
444 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300445 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400446 stage('Check include order') {
azvyagintseve7b8e792018-09-21 17:27:01 +0300447 if (!checkIncludeOrder) {
448 common.infoMsg('Check include order require to much time, and currently disabled!')
449
450 } else {
451 def correctIncludeOrder = ["service", "system", "cluster"]
452 dir(reclassInfoPatchedPath) {
453 def nodeInfoFiles = findFiles(glob: "**/*.reclass.nodeinfo")
454 def messages = ["<b>Wrong include ordering found</b><ul>"]
455 def stepsForParallel = [:]
456 nodeInfoFiles.each { nodeInfo ->
457 stepsForParallel.put("Checking ${nodeInfo.path}:", {
458 def node = readYaml file: nodeInfo.path
459 def classes = node['classes']
460 def curClassID = 0
461 def prevClassID = 0
462 def wrongOrder = false
463 for (String className in classes) {
464 def currentClass = className.tokenize('.')[0]
465 curClassID = correctIncludeOrder.indexOf(currentClass)
466 if (currentClass != correctIncludeOrder[prevClassID]) {
467 if (prevClassID > curClassID) {
468 wrongOrder = true
469 common.warningMsg("File ${nodeInfo.path} contains wrong order of classes including: Includes for ${className} should be declared before ${correctIncludeOrder[prevClassID]} includes")
470 } else {
471 prevClassID = curClassID
472 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400473 }
474 }
azvyagintseve7b8e792018-09-21 17:27:01 +0300475 if (wrongOrder) {
476 messages.add("<li>${nodeInfo.path} contains wrong order of classes including</li>")
477 }
478 })
479 }
480 parallel stepsForParallel
481 def includerOrder = '<b>No wrong include order</b>'
482 if (messages.size() != 1) {
483 includerOrder = messages.join('')
484 }
485 currentBuild.description = currentBuild.description ? currentBuild.description + includerOrder : includerOrder
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400486 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400487 }
488 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300489 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
490
491 } catch (Throwable e) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300492 if (alreadyMerged) {
493 currentBuild.result = 'ABORTED'
494 currentBuild.description = "Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them"
495 return
496 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300497 currentBuild.result = "FAILURE"
498 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
499 throw e
500 } finally {
501 def dummy = "dummy"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300502 }
503 }
chnydae80bb922017-05-29 17:48:40 +0200504}