blob: 17590c4de9d453f7552b08c08c04c8d7f6af14c0 [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
Denis Egorenko535d5b62018-09-28 11:28:10 +040020def extraVarsYAML = env.EXTRA_VARIABLES_YAML ?: false
21if (extraVarsYAML) {
22 common.mergeEnv(env, extraVarsYAML)
23}
24
azvyagintsev3a80e342018-09-19 19:22:48 +030025slaveNode = env.SLAVE_NODE ?: 'docker'
azvyagintseve7b8e792018-09-21 17:27:01 +030026checkIncludeOrder = env.CHECK_INCLUDE_ORDER ?: false
azvyagintsev5c0313d2018-08-13 17:13:35 +030027
azvyagintsev9df82e52018-09-06 19:17:18 +030028// Global var's
29alreadyMerged = false
30gerritConData = [credentialsId : env.CREDENTIALS_ID,
31 gerritName : env.GERRIT_NAME ?: 'mcp-jenkins',
32 gerritHost : env.GERRIT_HOST ?: 'gerrit.mcp.mirantis.net',
azvyagintsevb266ad22018-09-11 12:11:11 +030033 gerritScheme : env.GERRIT_SCHEME ?: 'ssh',
34 gerritPort : env.GERRIT_PORT ?: '29418',
azvyagintsev9df82e52018-09-06 19:17:18 +030035 gerritRefSpec : null,
36 gerritProject : null,
37 withWipeOut : true,
38 GERRIT_CHANGE_NUMBER: null]
39//
40//ccTemplatesRepo = env.COOKIECUTTER_TEMPLATE_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.net:29418/mk/cookiecutter-templates'
azvyagintsev3a80e342018-09-19 19:22:48 +030041gerritDataCCHEAD = [:]
azvyagintsev9df82e52018-09-06 19:17:18 +030042gerritDataCC = [:]
43gerritDataCC << gerritConData
44gerritDataCC['gerritBranch'] = env.COOKIECUTTER_TEMPLATE_BRANCH ?: 'master'
azvyagintsev458278c2018-09-25 18:38:30 +030045gerritDataCC['gerritRefSpec'] = env.COOKIECUTTER_TEMPLATE_REF ?: null
azvyagintsev9df82e52018-09-06 19:17:18 +030046gerritDataCC['gerritProject'] = 'mk/cookiecutter-templates'
47//
48//reclassSystemRepo = env.RECLASS_SYSTEM_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.net:29418/salt-models/reclass-system'
azvyagintsev3a80e342018-09-19 19:22:48 +030049gerritDataRSHEAD = [:]
azvyagintsev9df82e52018-09-06 19:17:18 +030050gerritDataRS = [:]
51gerritDataRS << gerritConData
52gerritDataRS['gerritBranch'] = env.RECLASS_MODEL_BRANCH ?: 'master'
azvyagintsev458278c2018-09-25 18:38:30 +030053gerritDataRS['gerritRefSpec'] = env.RECLASS_SYSTEM_GIT_REF ?: null
azvyagintsev9df82e52018-09-06 19:17:18 +030054gerritDataRS['gerritProject'] = 'salt-models/reclass-system'
55
56// version of debRepos, aka formulas\reclass
azvyagintsev10e24012018-09-10 21:36:32 +030057testDistribRevision = env.DISTRIB_REVISION ?: 'nightly'
58reclassVersion = 'v1.5.4'
azvyagintsevb266ad22018-09-11 12:11:11 +030059if (env.RECLASS_VERSION) {
azvyagintsev9df82e52018-09-06 19:17:18 +030060 reclassVersion = env.RECLASS_VERSION
Vasyl Saienko772e1232018-07-23 14:42:24 +030061}
Denis Egorenkod8748942018-09-07 12:26:20 +040062// Name of sub-test chunk job
63chunkJobName = "test-mk-cookiecutter-templates-chunk"
64testModelBuildsData = [:]
Vasyl Saienko772e1232018-07-23 14:42:24 +030065
chnyda467f10f2017-05-30 17:25:07 +020066def generateSaltMaster(modEnv, clusterDomain, clusterName) {
azvyagintsev5c0313d2018-08-13 17:13:35 +030067 def nodeFile = "${modEnv}/nodes/cfg01.${clusterDomain}.yml"
68 def nodeString = """classes:
chnydae80bb922017-05-29 17:48:40 +020069- cluster.${clusterName}.infra.config
70parameters:
71 _param:
72 linux_system_codename: xenial
73 reclass_data_revision: master
74 linux:
75 system:
76 name: cfg01
77 domain: ${clusterDomain}
78"""
azvyagintsev5c0313d2018-08-13 17:13:35 +030079 sh "mkdir -p ${modEnv}/nodes/"
80 println "Create file ${nodeFile}"
81 writeFile(file: nodeFile, text: nodeString)
azvyagintsev87985532018-07-10 20:49:38 +030082}
83
azvyagintsev30bc82e2018-08-22 12:26:06 +030084/**
85 *
86 * @param contextFile - path to `contexts/XXX.yaml file`
azvyagintsev9df82e52018-09-06 19:17:18 +030087 * @param virtualenv - pyvenv with CC and dep's
azvyagintsev30bc82e2018-08-22 12:26:06 +030088 * @param templateEnvDir - root of CookieCutter
89 * @return
90 */
91
azvyagintsev5c0313d2018-08-13 17:13:35 +030092def generateModel(contextFile, virtualenv, templateEnvDir) {
93 def modelEnv = "${templateEnvDir}/model"
94 def basename = common.GetBaseName(contextFile, '.yml')
95 def generatedModel = "${modelEnv}/${basename}"
96 def content = readFile(file: "${templateEnvDir}/contexts/${contextFile}")
97 def templateContext = readYaml text: content
98 def clusterDomain = templateContext.default_context.cluster_domain
99 def clusterName = templateContext.default_context.cluster_name
100 def outputDestination = "${generatedModel}/classes/cluster/${clusterName}"
101 def templateBaseDir = templateEnvDir
102 def templateDir = "${templateEnvDir}/dir"
103 def templateOutputDir = templateBaseDir
azvyagintsev30bc82e2018-08-22 12:26:06 +0300104 dir(templateEnvDir) {
105 sh(script: "rm -rf ${generatedModel} || true")
106 common.infoMsg("Generating model from context ${contextFile}")
107 def productList = ["infra", "cicd", "opencontrail", "kubernetes", "openstack", "oss", "stacklight", "ceph"]
108 for (product in productList) {
chnydae80bb922017-05-29 17:48:40 +0200109
azvyagintsev30bc82e2018-08-22 12:26:06 +0300110 // get templateOutputDir and productDir
Michal Kobus197f6112018-09-21 14:30:16 +0200111 templateOutputDir = "${templateEnvDir}/output/${product}"
112 productDir = product
azvyagintsev7cdcc7a2018-09-25 16:47:24 +0300113 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
114 // Bw for 2018.8.1 and older releases
115 if (product.startsWith("stacklight") && (!fileExists(templateDir))) {
116 common.warningMsg("Old release detected! productDir => 'stacklight2' ")
117 productDir = "stacklight2"
118 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
119 }
azvyagintsev30bc82e2018-08-22 12:26:06 +0300120 if (product == "infra" || (templateContext.default_context["${product}_enabled"]
121 && templateContext.default_context["${product}_enabled"].toBoolean())) {
122
azvyagintsev30bc82e2018-08-22 12:26:06 +0300123 common.infoMsg("Generating product " + product + " from " + templateDir + " to " + templateOutputDir)
124
125 sh "rm -rf ${templateOutputDir} || true"
126 sh "mkdir -p ${templateOutputDir}"
127 sh "mkdir -p ${outputDestination}"
128
129 python.buildCookiecutterTemplate(templateDir, content, templateOutputDir, virtualenv, templateBaseDir)
130 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
131 } else {
132 common.warningMsg("Product " + product + " is disabled")
133 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300134 }
azvyagintsev30bc82e2018-08-22 12:26:06 +0300135 generateSaltMaster(generatedModel, clusterDomain, clusterName)
chnydae80bb922017-05-29 17:48:40 +0200136 }
chnydae80bb922017-05-29 17:48:40 +0200137}
138
Denis Egorenkod8748942018-09-07 12:26:20 +0400139def getAndUnpackNodesInfoArtifact(jobName, copyTo, build) {
140 return {
141 dir(copyTo) {
142 copyArtifacts(projectName: jobName, selector: specific(build), filter: "nodesinfo.tar.gz")
azvyagintsev3a80e342018-09-19 19:22:48 +0300143 sh "tar -xf nodesinfo.tar.gz"
Denis Egorenkod8748942018-09-07 12:26:20 +0400144 sh "rm -v nodesinfo.tar.gz"
145 }
146 }
147}
azvyagintsev87985532018-07-10 20:49:38 +0300148
Denis Egorenkod8748942018-09-07 12:26:20 +0400149def testModel(modelFile, reclassArtifactName, artifactCopyPath) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300150 // modelFile - `modelfiname` from model/modelfiname/modelfiname.yaml
151 //* Grub all models and send it to check in paralell - by one in thread.
Denis Egorenkod8748942018-09-07 12:26:20 +0400152 def _uuid = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}_${modelFile.toLowerCase()}_" + UUID.randomUUID().toString().take(8)
153 def _values_string = """
azvyagintsev87985532018-07-10 20:49:38 +0300154 ---
Denis Egorenkod8748942018-09-07 12:26:20 +0400155 MODELS_TARGZ: "${env.BUILD_URL}/artifact/${reclassArtifactName}"
156 DockerCName: "${_uuid}"
azvyagintsev87985532018-07-10 20:49:38 +0300157 testReclassEnv: "model/${modelFile}/"
158 modelFile: "contexts/${modelFile}.yml"
azvyagintsev9df82e52018-09-06 19:17:18 +0300159 DISTRIB_REVISION: "${testDistribRevision}"
azvyagintsev87985532018-07-10 20:49:38 +0300160 reclassVersion: "${reclassVersion}"
161 """
Denis Egorenkod8748942018-09-07 12:26:20 +0400162 def chunkJob = build job: chunkJobName, parameters: [
azvyagintsev08b34e32018-09-12 12:29:42 +0300163 [$class: 'TextParameterValue', name: 'EXTRA_VARIABLES_YAML',
azvyagintsev30bc82e2018-08-22 12:26:06 +0300164 value : _values_string.stripIndent()],
azvyagintsev5c0313d2018-08-13 17:13:35 +0300165 ]
Denis Egorenkod8748942018-09-07 12:26:20 +0400166 // Put sub-job info into global map.
167 testModelBuildsData.put(_uuid, ['jobname' : chunkJob.fullProjectName,
168 'copyToDir': "${artifactCopyPath}/${modelFile}",
169 'buildId' : "${chunkJob.number}"])
chnydabc63c9a2017-05-30 15:37:54 +0200170}
171
Denis Egorenkod8748942018-09-07 12:26:20 +0400172def StepTestModel(basename, reclassArtifactName, artifactCopyPath) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300173 // We need to wrap what we return in a Groovy closure, or else it's invoked
174 // when this method is called, not when we pass it to parallel.
175 // To do this, you need to wrap the code below in { }, and either return
176 // that explicitly, or use { -> } syntax.
177 // return node object
178 return {
179 node(slaveNode) {
Denis Egorenkod8748942018-09-07 12:26:20 +0400180 testModel(basename, reclassArtifactName, artifactCopyPath)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300181 }
chnydae80bb922017-05-29 17:48:40 +0200182 }
azvyagintsev87985532018-07-10 20:49:38 +0300183}
184
azvyagintsev9df82e52018-09-06 19:17:18 +0300185def StepPrepareGit(templateEnvFolder, gerrit_data) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300186 // return git clone object
187 return {
azvyagintsev9df82e52018-09-06 19:17:18 +0300188 def checkouted = false
189 common.infoMsg("StepPrepareGit: ${gerrit_data}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300190 // fetch needed sources
191 dir(templateEnvFolder) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300192 if (gerrit_data['gerritRefSpec']) {
193 // Those part might be not work,in case manual var's pass
194 def gerritChange = gerrit.getGerritChange(gerrit_data['gerritName'], gerrit_data['gerritHost'],
195 gerrit_data['GERRIT_CHANGE_NUMBER'], gerrit_data['credentialsId'])
azvyagintsev5c0313d2018-08-13 17:13:35 +0300196 merged = gerritChange.status == "MERGED"
197 if (!merged) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300198 checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300199 } else {
azvyagintsev9df82e52018-09-06 19:17:18 +0300200 // update global variable for pretty return from pipeline
201 alreadyMerged = true
202 common.successMsg("Change ${gerrit_data['GERRIT_CHANGE_NUMBER']} is already merged, no need to gate them")
203 error('change already merged')
azvyagintsev87985532018-07-10 20:49:38 +0300204 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300205 } else {
azvyagintsev9df82e52018-09-06 19:17:18 +0300206 // Get clean HEAD
207 gerrit_data['useGerritTriggerBuildChooser'] = false
208 checkouted = gerrit.gerritPatchsetCheckout(gerrit_data)
209 if (!checkouted) {
210 error("Failed to get repo:${gerrit_data}")
211 }
azvyagintsev87985532018-07-10 20:49:38 +0300212 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300213 }
azvyagintsev87985532018-07-10 20:49:38 +0300214 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300215}
216
217def StepGenerateModels(_contextFileList, _virtualenv, _templateEnvDir) {
218 return {
219 for (contextFile in _contextFileList) {
220 generateModel(contextFile, _virtualenv, _templateEnvDir)
221 }
222 }
223}
224
azvyagintsev9df82e52018-09-06 19:17:18 +0300225def globalVariatorsUpdate() {
226 // Simple function, to check and define branch-around variables
227 // In general, simply make transition updates for non-master branch
228 // based on magic logic
azvyagintsev458278c2018-09-25 18:38:30 +0300229 def message = '<br/>'
azvyagintsevb266ad22018-09-11 12:11:11 +0300230 if (env.GERRIT_PROJECT) {
azvyagintseve0eb6cd2018-09-12 13:00:40 +0300231 // TODO are we going to have such branches?
azvyagintsev9df82e52018-09-06 19:17:18 +0300232 if (!['nightly', 'testing', 'stable', 'proposed', 'master'].contains(env.GERRIT_BRANCH)) {
233 gerritDataCC['gerritBranch'] = env.GERRIT_BRANCH
234 gerritDataRS['gerritBranch'] = env.GERRIT_BRANCH
azvyagintsev458278c2018-09-25 18:38:30 +0300235 testDistribRevision = env.GERRIT_BRANCH
azvyagintsev9df82e52018-09-06 19:17:18 +0300236 }
237 // Identify, who triggered. To whom we should pass refspec
238 if (env.GERRIT_PROJECT == 'salt-models/reclass-system') {
239 gerritDataRS['gerritRefSpec'] = env.GERRIT_REFSPEC
240 gerritDataRS['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
azvyagintsev458278c2018-09-25 18:38:30 +0300241 message = message + "<br/>RECLASS_SYSTEM_GIT_REF =>${gerritDataRS['gerritRefSpec']}"
azvyagintsev9df82e52018-09-06 19:17:18 +0300242 } else if (env.GERRIT_PROJECT == 'mk/cookiecutter-templates') {
243 gerritDataCC['gerritRefSpec'] = env.GERRIT_REFSPEC
244 gerritDataCC['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER
azvyagintsev458278c2018-09-25 18:38:30 +0300245 message = message + "<br/>COOKIECUTTER_TEMPLATE_REF =>${gerritDataCC['gerritRefSpec']}"
azvyagintsev9df82e52018-09-06 19:17:18 +0300246 } else {
247 error("Unsuported gerrit-project triggered:${env.GERRIT_PROJECT}")
248 }
azvyagintsev9df82e52018-09-06 19:17:18 +0300249 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']}" +
azvyagintsev458278c2018-09-25 18:38:30 +0300252 "<br/>RECLASS_MODEL_BRANCH=> ${gerritDataRS['gerritBranch']}" + message
azvyagintsev9df82e52018-09-06 19:17:18 +0300253 } else {
azvyagintsev458278c2018-09-25 18:38:30 +0300254 message = "<font color='red'>Non-gerrit trigger run detected!</font>" + message
azvyagintsev9df82e52018-09-06 19:17:18 +0300255 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300256 gerritDataCCHEAD << gerritDataCC
257 gerritDataCCHEAD['gerritRefSpec'] = null
258 gerritDataCCHEAD['GERRIT_CHANGE_NUMBER'] = null
259 gerritDataRSHEAD << gerritDataRS
260 gerritDataRSHEAD['gerritRefSpec'] = null
261 gerritDataRSHEAD['GERRIT_CHANGE_NUMBER'] = null
azvyagintsev458278c2018-09-25 18:38:30 +0300262 // 'binary' branch logic w\o 'release/' prefix
263 if (testDistribRevision.contains('/')) {
264 testDistribRevision = testDistribRevision.split('/')[-1]
265 }
266 // Check if we are going to test bleeding-edge release, which doesn't have binary release yet
267 if (!common.checkRemoteBinary([apt_mk_version: testDistribRevision]).linux_system_repo_url) {
268 common.errorMsg("Binary release: ${testDistribRevision} not exist. Fallback to 'proposed'! ")
269 testDistribRevision = 'proposed'
270 message = "<br/>DISTRIB_REVISION =>${testDistribRevision}" + message
271 }
272 currentBuild.description = currentBuild.description ? message + currentBuild.description : message
Denis Egorenkod8748942018-09-07 12:26:20 +0400273}
azvyagintsev9df82e52018-09-06 19:17:18 +0300274
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400275def replaceGeneratedValues(path) {
276 def files = sh(script: "find ${path} -name 'secrets.yml'", returnStdout: true)
277 def stepsForParallel = [:]
278 stepsForParallel.failFast = true
279 files.tokenize().each {
280 stepsForParallel.put("Removing generated passwords/secrets from ${it}",
281 {
282 def secrets = readYaml file: it
azvyagintsev08b34e32018-09-12 12:29:42 +0300283 for (String key in secrets['parameters']['_param'].keySet()) {
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400284 secrets['parameters']['_param'][key] = 'generated'
285 }
286 // writeYaml can't write to already existing file
287 writeYaml file: "${it}.tmp", data: secrets
288 sh "mv ${it}.tmp ${it}"
289 })
290 }
291 parallel stepsForParallel
292}
293
Denis Egorenkod8748942018-09-07 12:26:20 +0400294def linkReclassModels(contextList, envPath, archiveName) {
295 // to be able share reclass for all subenvs
296 // Also, makes artifact test more solid - use one reclass for all of sub-models.
297 // Archive Structure will be:
298 // tar.gz
299 // ├── contexts
300 // │   └── ceph.yml
azvyagintsev3a80e342018-09-19 19:22:48 +0300301 // ├── ${reclassDirName} <<< reclass system
Denis Egorenkod8748942018-09-07 12:26:20 +0400302 // ├── model
303 // │   └── ceph <<< from `context basename`
304 // │   ├── classes
305 // │   │   ├── cluster
azvyagintsev3a80e342018-09-19 19:22:48 +0300306 // │   │   └── system -> ../../../${reclassDirName}
Denis Egorenkod8748942018-09-07 12:26:20 +0400307 // │   └── nodes
308 // │   └── cfg01.ceph-cluster-domain.local.yml
309 dir(envPath) {
310 for (String context : contextList) {
311 def basename = common.GetBaseName(context, '.yml')
312 dir("${envPath}/model/${basename}") {
azvyagintsev3a80e342018-09-19 19:22:48 +0300313 sh(script: "mkdir -p classes/; ln -sfv ../../../../${common.GetBaseName(archiveName, '.tar.gz')} classes/system ")
Denis Egorenkod8748942018-09-07 12:26:20 +0400314 }
315 }
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400316 // replace all generated passwords/secrets/keys with hardcode value for infra/secrets.yaml
317 replaceGeneratedValues("${envPath}/model")
azvyagintsev3a80e342018-09-19 19:22:48 +0300318 // Save all models and all contexts. Warning! `h` flag must be used!
319 sh(script: "set -ex; tar -czhf ${env.WORKSPACE}/${archiveName} --exclude='*@tmp' model contexts", returnStatus: true)
Denis Egorenkod8748942018-09-07 12:26:20 +0400320 }
azvyagintsev3a80e342018-09-19 19:22:48 +0300321 archiveArtifacts artifacts: archiveName
azvyagintsev9df82e52018-09-06 19:17:18 +0300322}
323
azvyagintsev5c0313d2018-08-13 17:13:35 +0300324timeout(time: 1, unit: 'HOURS') {
325 node(slaveNode) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300326 globalVariatorsUpdate()
azvyagintsev30bc82e2018-08-22 12:26:06 +0300327 def templateEnvHead = "${env.WORKSPACE}/EnvHead/"
328 def templateEnvPatched = "${env.WORKSPACE}/EnvPatched/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300329 def contextFileListHead = []
330 def contextFileListPatched = []
331 def vEnv = "${env.WORKSPACE}/venv"
Denis Egorenkod8748942018-09-07 12:26:20 +0400332 def headReclassArtifactName = "head_reclass.tar.gz"
333 def patchedReclassArtifactName = "patched_reclass.tar.gz"
334 def reclassNodeInfoDir = "${env.WORKSPACE}/reclassNodeInfo_compare/"
335 def reclassInfoHeadPath = "${reclassNodeInfoDir}/old"
336 def reclassInfoPatchedPath = "${reclassNodeInfoDir}/new"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300337 try {
338 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
339 stage('Download and prepare CC env') {
340 // Prepare 2 env - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300341 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300342 paralellEnvs.failFast = true
azvyagintsev9df82e52018-09-06 19:17:18 +0300343 paralellEnvs['downloadEnvHead'] = StepPrepareGit(templateEnvHead, gerritDataCCHEAD)
azvyagintsev3a80e342018-09-19 19:22:48 +0300344 if (gerritDataCC.get('gerritRefSpec', null)) {
345 paralellEnvs['downloadEnvPatched'] = StepPrepareGit(templateEnvPatched, gerritDataCC)
346 parallel paralellEnvs
347 } else {
348 paralellEnvs['downloadEnvPatched'] = { common.warningMsg('No need to process: downloadEnvPatched') }
349 parallel paralellEnvs
350 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
351 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300352 }
353 stage("Check workflow_definition") {
354 // Check only for patchset
355 python.setupVirtualenv(vEnv, 'python2', [], "${templateEnvPatched}/requirements.txt")
azvyagintsev3a80e342018-09-19 19:22:48 +0300356 if (gerritDataCC.get('gerritRefSpec', null)) {
357 common.infoMsg(python.runVirtualenvCommand(vEnv, "python ${templateEnvPatched}/workflow_definition_test.py"))
358 } else {
359 common.infoMsg('No need to process: workflow_definition')
360 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300361 }
362
363 stage("generate models") {
364 dir("${templateEnvHead}/contexts") {
365 for (String x : findFiles(glob: "*.yml")) {
366 contextFileListHead.add(x)
367 }
368 }
369 dir("${templateEnvPatched}/contexts") {
370 for (String x : findFiles(glob: "*.yml")) {
371 contextFileListPatched.add(x)
372 }
373 }
374 // Generate over 2env's - for patchset, and for HEAD
azvyagintsev9df82e52018-09-06 19:17:18 +0300375 def paralellEnvs = [:]
azvyagintsev5c0313d2018-08-13 17:13:35 +0300376 paralellEnvs.failFast = true
azvyagintsev30bc82e2018-08-22 12:26:06 +0300377 paralellEnvs['GenerateEnvHead'] = StepGenerateModels(contextFileListHead, vEnv, templateEnvHead)
azvyagintsev3a80e342018-09-19 19:22:48 +0300378 if (gerritDataCC.get('gerritRefSpec', null)) {
379 paralellEnvs['GenerateEnvPatched'] = StepGenerateModels(contextFileListPatched, vEnv, templateEnvPatched)
380 parallel paralellEnvs
381 } else {
382 paralellEnvs['GenerateEnvPatched'] = { common.warningMsg('No need to process: GenerateEnvPatched') }
383 parallel paralellEnvs
384 sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}")
azvyagintsev5c0313d2018-08-13 17:13:35 +0300385 }
386
azvyagintsev3a80e342018-09-19 19:22:48 +0300387 // We need 2 git's, one for HEAD, one for PATCHed.
388 // if no patch, use head for both
389 RSHeadDir = common.GetBaseName(headReclassArtifactName, '.tar.gz')
390 RSPatchedDir = common.GetBaseName(patchedReclassArtifactName, '.tar.gz')
391 common.infoMsg("gerritDataRS= ${gerritDataRS}")
392 common.infoMsg("gerritDataRSHEAD= ${gerritDataRSHEAD}")
393 if (gerritDataRS.get('gerritRefSpec', null)) {
394 StepPrepareGit("${env.WORKSPACE}/${RSPatchedDir}/", gerritDataRS).call()
395 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRSHEAD).call()
396 } else {
397 StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRS).call()
398 sh("cd ${env.WORKSPACE} ; ln -svf ${RSHeadDir} ${RSPatchedDir}")
399 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300400 // link all models, to use one global reclass
401 // For HEAD
Denis Egorenkod8748942018-09-07 12:26:20 +0400402 linkReclassModels(contextFileListHead, templateEnvHead, headReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300403 // For patched
Denis Egorenkod8748942018-09-07 12:26:20 +0400404 linkReclassModels(contextFileListPatched, templateEnvPatched, patchedReclassArtifactName)
azvyagintsev5c0313d2018-08-13 17:13:35 +0300405 }
406
Denis Egorenkod8748942018-09-07 12:26:20 +0400407 stage("Compare cluster lvl Head/Patched") {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300408 // Compare patched and HEAD reclass pillars
Denis Egorenkod8748942018-09-07 12:26:20 +0400409 compareRoot = "${env.WORKSPACE}/cluster_compare/"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300410 sh(script: """
411 mkdir -pv ${compareRoot}/new ${compareRoot}/old
Denis Egorenkod8748942018-09-07 12:26:20 +0400412 tar -xzf ${patchedReclassArtifactName} --directory ${compareRoot}/new
413 tar -xzf ${headReclassArtifactName} --directory ${compareRoot}/old
azvyagintsev5c0313d2018-08-13 17:13:35 +0300414 """)
415 common.warningMsg('infra/secrets.yml has been skipped from compare!')
azvyagintsev3a80e342018-09-19 19:22:48 +0300416 result = '\n' + common.comparePillars(compareRoot, env.BUILD_URL, "-Ev \'infra/secrets.yml|\\.git\'")
Denis Egorenkod8748942018-09-07 12:26:20 +0400417 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300418 }
Denis Egorenkod8748942018-09-07 12:26:20 +0400419 stage("TestContexts Head/Patched") {
420 def stepsForParallel = [:]
421 stepsForParallel.failFast = true
422 common.infoMsg("Found: ${contextFileListHead.size()} HEAD contexts to test.")
423 for (String context : contextFileListHead) {
424 def basename = common.GetBaseName(context, '.yml')
425 stepsForParallel.put("ContextHeadTest:${basename}", StepTestModel(basename, headReclassArtifactName, reclassInfoHeadPath))
426 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300427 common.infoMsg("Found: ${contextFileListPatched.size()} patched contexts to test.")
428 for (String context : contextFileListPatched) {
429 def basename = common.GetBaseName(context, '.yml')
Denis Egorenkod8748942018-09-07 12:26:20 +0400430 stepsForParallel.put("ContextPatchedTest:${basename}", StepTestModel(basename, patchedReclassArtifactName, reclassInfoPatchedPath))
azvyagintsev5c0313d2018-08-13 17:13:35 +0300431 }
432 parallel stepsForParallel
Denis Egorenkod8748942018-09-07 12:26:20 +0400433 common.infoMsg('All TestContexts tests done')
434 }
435 stage("Compare NodesInfo Head/Patched") {
436 // Download all artifacts
437 def stepsForParallel = [:]
438 stepsForParallel.failFast = true
439 common.infoMsg("Found: ${testModelBuildsData.size()} nodeinfo artifacts to download.")
440 testModelBuildsData.each { bname, bdata ->
441 stepsForParallel.put("FetchData:${bname}",
442 getAndUnpackNodesInfoArtifact(bdata.jobname, bdata.copyToDir, bdata.buildId))
443 }
444 parallel stepsForParallel
Denis Egorenkoa6117fc2018-09-11 13:40:00 +0400445 // remove timestamp field from rendered files
446 sh("find ${reclassNodeInfoDir} -type f -exec sed -i '/ timestamp: .*/d' {} \\;")
Denis Egorenkod8748942018-09-07 12:26:20 +0400447 // Compare patched and HEAD reclass pillars
448 result = '\n' + common.comparePillars(reclassNodeInfoDir, env.BUILD_URL, '')
449 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
azvyagintsev5c0313d2018-08-13 17:13:35 +0300450 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400451 stage('Check include order') {
azvyagintseve7b8e792018-09-21 17:27:01 +0300452 if (!checkIncludeOrder) {
453 common.infoMsg('Check include order require to much time, and currently disabled!')
454
455 } else {
456 def correctIncludeOrder = ["service", "system", "cluster"]
457 dir(reclassInfoPatchedPath) {
458 def nodeInfoFiles = findFiles(glob: "**/*.reclass.nodeinfo")
459 def messages = ["<b>Wrong include ordering found</b><ul>"]
460 def stepsForParallel = [:]
461 nodeInfoFiles.each { nodeInfo ->
462 stepsForParallel.put("Checking ${nodeInfo.path}:", {
463 def node = readYaml file: nodeInfo.path
464 def classes = node['classes']
465 def curClassID = 0
466 def prevClassID = 0
467 def wrongOrder = false
468 for (String className in classes) {
469 def currentClass = className.tokenize('.')[0]
470 curClassID = correctIncludeOrder.indexOf(currentClass)
471 if (currentClass != correctIncludeOrder[prevClassID]) {
472 if (prevClassID > curClassID) {
473 wrongOrder = true
474 common.warningMsg("File ${nodeInfo.path} contains wrong order of classes including: Includes for ${className} should be declared before ${correctIncludeOrder[prevClassID]} includes")
475 } else {
476 prevClassID = curClassID
477 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400478 }
479 }
azvyagintseve7b8e792018-09-21 17:27:01 +0300480 if (wrongOrder) {
481 messages.add("<li>${nodeInfo.path} contains wrong order of classes including</li>")
482 }
483 })
484 }
485 parallel stepsForParallel
486 def includerOrder = '<b>No wrong include order</b>'
487 if (messages.size() != 1) {
488 includerOrder = messages.join('')
489 }
490 currentBuild.description = currentBuild.description ? currentBuild.description + includerOrder : includerOrder
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400491 }
Denis Egorenko04ca9f22018-09-19 16:06:49 +0400492 }
493 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300494 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
495
496 } catch (Throwable e) {
azvyagintsev9df82e52018-09-06 19:17:18 +0300497 if (alreadyMerged) {
498 currentBuild.result = 'ABORTED'
499 currentBuild.description = "Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them"
500 return
501 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300502 currentBuild.result = "FAILURE"
503 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
504 throw e
505 } finally {
506 def dummy = "dummy"
azvyagintsev5c0313d2018-08-13 17:13:35 +0300507 }
508 }
chnydae80bb922017-05-29 17:48:40 +0200509}