blob: c09c5728fb20f60cea43dfbad316588dc27d5f7f [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',
Roman Vyalovf0c596e2018-10-01 17:56:09 +030032 gerritHost : env.GERRIT_HOST ?: 'gerrit.mcp.mirantis.com',
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//
Roman Vyalovf0c596e2018-10-01 17:56:09 +030040//ccTemplatesRepo = env.COOKIECUTTER_TEMPLATE_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.com: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//
Roman Vyalovf0c596e2018-10-01 17:56:09 +030048//reclassSystemRepo = env.RECLASS_SYSTEM_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.com: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
azvyagintsevec055b42018-10-11 12:59:05 +030056// version of debRepos, aka formulas|reclass|ubuntu
azvyagintsev10e24012018-09-10 21:36:32 +030057testDistribRevision = env.DISTRIB_REVISION ?: 'nightly'
Denis Egorenkod8748942018-09-07 12:26:20 +040058// Name of sub-test chunk job
59chunkJobName = "test-mk-cookiecutter-templates-chunk"
60testModelBuildsData = [:]
Vasyl Saienko772e1232018-07-23 14:42:24 +030061
chnyda467f10f2017-05-30 17:25:07 +020062def generateSaltMaster(modEnv, clusterDomain, clusterName) {
azvyagintsev5c0313d2018-08-13 17:13:35 +030063 def nodeFile = "${modEnv}/nodes/cfg01.${clusterDomain}.yml"
64 def nodeString = """classes:
chnydae80bb922017-05-29 17:48:40 +020065- cluster.${clusterName}.infra.config
66parameters:
67 _param:
68 linux_system_codename: xenial
69 reclass_data_revision: master
70 linux:
71 system:
72 name: cfg01
73 domain: ${clusterDomain}
74"""
azvyagintsev5c0313d2018-08-13 17:13:35 +030075 sh "mkdir -p ${modEnv}/nodes/"
76 println "Create file ${nodeFile}"
77 writeFile(file: nodeFile, text: nodeString)
azvyagintsev87985532018-07-10 20:49:38 +030078}
79
azvyagintsev30bc82e2018-08-22 12:26:06 +030080/**
81 *
82 * @param contextFile - path to `contexts/XXX.yaml file`
azvyagintsev9df82e52018-09-06 19:17:18 +030083 * @param virtualenv - pyvenv with CC and dep's
azvyagintsev30bc82e2018-08-22 12:26:06 +030084 * @param templateEnvDir - root of CookieCutter
85 * @return
86 */
87
azvyagintsev5c0313d2018-08-13 17:13:35 +030088def generateModel(contextFile, virtualenv, templateEnvDir) {
89 def modelEnv = "${templateEnvDir}/model"
90 def basename = common.GetBaseName(contextFile, '.yml')
91 def generatedModel = "${modelEnv}/${basename}"
92 def content = readFile(file: "${templateEnvDir}/contexts/${contextFile}")
93 def templateContext = readYaml text: content
94 def clusterDomain = templateContext.default_context.cluster_domain
95 def clusterName = templateContext.default_context.cluster_name
96 def outputDestination = "${generatedModel}/classes/cluster/${clusterName}"
97 def templateBaseDir = templateEnvDir
98 def templateDir = "${templateEnvDir}/dir"
99 def templateOutputDir = templateBaseDir
azvyagintsev30bc82e2018-08-22 12:26:06 +0300100 dir(templateEnvDir) {
101 sh(script: "rm -rf ${generatedModel} || true")
102 common.infoMsg("Generating model from context ${contextFile}")
103 def productList = ["infra", "cicd", "opencontrail", "kubernetes", "openstack", "oss", "stacklight", "ceph"]
104 for (product in productList) {
chnydae80bb922017-05-29 17:48:40 +0200105
azvyagintsev30bc82e2018-08-22 12:26:06 +0300106 // get templateOutputDir and productDir
Michal Kobus197f6112018-09-21 14:30:16 +0200107 templateOutputDir = "${templateEnvDir}/output/${product}"
108 productDir = product
azvyagintsev7cdcc7a2018-09-25 16:47:24 +0300109 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
110 // Bw for 2018.8.1 and older releases
111 if (product.startsWith("stacklight") && (!fileExists(templateDir))) {
112 common.warningMsg("Old release detected! productDir => 'stacklight2' ")
113 productDir = "stacklight2"
114 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
115 }
azvyagintsev30bc82e2018-08-22 12:26:06 +0300116 if (product == "infra" || (templateContext.default_context["${product}_enabled"]
117 && templateContext.default_context["${product}_enabled"].toBoolean())) {
118
azvyagintsev30bc82e2018-08-22 12:26:06 +0300119 common.infoMsg("Generating product " + product + " from " + templateDir + " to " + templateOutputDir)
120
121 sh "rm -rf ${templateOutputDir} || true"
122 sh "mkdir -p ${templateOutputDir}"
123 sh "mkdir -p ${outputDestination}"
124
125 python.buildCookiecutterTemplate(templateDir, content, templateOutputDir, virtualenv, templateBaseDir)
126 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
127 } else {
128 common.warningMsg("Product " + product + " is disabled")
129 }
azvyagintsev5c0313d2018-08-13 17:13:35 +0300130 }
azvyagintsev30bc82e2018-08-22 12:26:06 +0300131 generateSaltMaster(generatedModel, clusterDomain, clusterName)
chnydae80bb922017-05-29 17:48:40 +0200132 }
chnydae80bb922017-05-29 17:48:40 +0200133}
134
Denis Egorenkod8748942018-09-07 12:26:20 +0400135def getAndUnpackNodesInfoArtifact(jobName, copyTo, build) {
136 return {
137 dir(copyTo) {
138 copyArtifacts(projectName: jobName, selector: specific(build), filter: "nodesinfo.tar.gz")
azvyagintsev3a80e342018-09-19 19:22:48 +0300139 sh "tar -xf nodesinfo.tar.gz"
Denis Egorenkod8748942018-09-07 12:26:20 +0400140 sh "rm -v nodesinfo.tar.gz"
141 }
142 }
143}
azvyagintsev87985532018-07-10 20:49:38 +0300144
Denis Egorenkod8748942018-09-07 12:26:20 +0400145def testModel(modelFile, reclassArtifactName, artifactCopyPath) {
azvyagintsev5c0313d2018-08-13 17:13:35 +0300146 // modelFile - `modelfiname` from model/modelfiname/modelfiname.yaml
147 //* Grub all models and send it to check in paralell - by one in thread.
Denis Egorenkod8748942018-09-07 12:26:20 +0400148 def _uuid = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}_${modelFile.toLowerCase()}_" + UUID.randomUUID().toString().take(8)
149 def _values_string = """
azvyagintsev87985532018-07-10 20:49:38 +0300150 ---
Denis Egorenkod8748942018-09-07 12:26:20 +0400151 MODELS_TARGZ: "${env.BUILD_URL}/artifact/${reclassArtifactName}"
152 DockerCName: "${_uuid}"
azvyagintsev87985532018-07-10 20:49:38 +0300153 testReclassEnv: "model/${modelFile}/"
154 modelFile: "contexts/${modelFile}.yml"
azvyagintsev9df82e52018-09-06 19:17:18 +0300155 DISTRIB_REVISION: "${testDistribRevision}"
azvyagintsev87985532018-07-10 20:49:38 +0300156 """
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}