azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 1 | /* |
| 2 | Able to be triggered from Gerrit if : |
| 3 | Variators: |
| 4 | Modes: |
| 5 | 1) manual run via job-build , possible to pass refspec |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 6 | TODO: currently impossible to use custom COOKIECUTTER_TEMPLATE_URL| RECLASS_SYSTEM_URL Gerrit-one always used. |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 7 | - for CC |
| 8 | - Reclass |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 9 | |
| 10 | 2) gerrit trigger |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 11 | Automatically switches if GERRIT_PROJECT variable detected |
| 12 | Always test GERRIT_REFSPEC VS GERRIT_BRANCH-master version of opposite project |
| 13 | */ |
| 14 | |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 15 | common = new com.mirantis.mk.Common() |
chnyda | bc63c9a | 2017-05-30 15:37:54 +0200 | [diff] [blame] | 16 | gerrit = new com.mirantis.mk.Gerrit() |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 17 | git = new com.mirantis.mk.Git() |
| 18 | python = new com.mirantis.mk.Python() |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 19 | |
Denis Egorenko | 535d5b6 | 2018-09-28 11:28:10 +0400 | [diff] [blame] | 20 | def extraVarsYAML = env.EXTRA_VARIABLES_YAML ?: false |
| 21 | if (extraVarsYAML) { |
| 22 | common.mergeEnv(env, extraVarsYAML) |
| 23 | } |
| 24 | |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 25 | slaveNode = env.SLAVE_NODE ?: 'docker' |
azvyagintsev | e7b8e79 | 2018-09-21 17:27:01 +0300 | [diff] [blame] | 26 | checkIncludeOrder = env.CHECK_INCLUDE_ORDER ?: false |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 27 | |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 28 | // Global var's |
| 29 | alreadyMerged = false |
| 30 | gerritConData = [credentialsId : env.CREDENTIALS_ID, |
| 31 | gerritName : env.GERRIT_NAME ?: 'mcp-jenkins', |
Roman Vyalov | f0c596e | 2018-10-01 17:56:09 +0300 | [diff] [blame] | 32 | gerritHost : env.GERRIT_HOST ?: 'gerrit.mcp.mirantis.com', |
azvyagintsev | b266ad2 | 2018-09-11 12:11:11 +0300 | [diff] [blame] | 33 | gerritScheme : env.GERRIT_SCHEME ?: 'ssh', |
| 34 | gerritPort : env.GERRIT_PORT ?: '29418', |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 35 | gerritRefSpec : null, |
| 36 | gerritProject : null, |
| 37 | withWipeOut : true, |
| 38 | GERRIT_CHANGE_NUMBER: null] |
| 39 | // |
Roman Vyalov | f0c596e | 2018-10-01 17:56:09 +0300 | [diff] [blame] | 40 | //ccTemplatesRepo = env.COOKIECUTTER_TEMPLATE_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.com:29418/mk/cookiecutter-templates' |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 41 | gerritDataCCHEAD = [:] |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 42 | gerritDataCC = [:] |
| 43 | gerritDataCC << gerritConData |
| 44 | gerritDataCC['gerritBranch'] = env.COOKIECUTTER_TEMPLATE_BRANCH ?: 'master' |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 45 | gerritDataCC['gerritRefSpec'] = env.COOKIECUTTER_TEMPLATE_REF ?: null |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 46 | gerritDataCC['gerritProject'] = 'mk/cookiecutter-templates' |
| 47 | // |
Roman Vyalov | f0c596e | 2018-10-01 17:56:09 +0300 | [diff] [blame] | 48 | //reclassSystemRepo = env.RECLASS_SYSTEM_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.com:29418/salt-models/reclass-system' |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 49 | gerritDataRSHEAD = [:] |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 50 | gerritDataRS = [:] |
| 51 | gerritDataRS << gerritConData |
| 52 | gerritDataRS['gerritBranch'] = env.RECLASS_MODEL_BRANCH ?: 'master' |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 53 | gerritDataRS['gerritRefSpec'] = env.RECLASS_SYSTEM_GIT_REF ?: null |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 54 | gerritDataRS['gerritProject'] = 'salt-models/reclass-system' |
| 55 | |
azvyagintsev | ec055b4 | 2018-10-11 12:59:05 +0300 | [diff] [blame^] | 56 | // version of debRepos, aka formulas|reclass|ubuntu |
azvyagintsev | 10e2401 | 2018-09-10 21:36:32 +0300 | [diff] [blame] | 57 | testDistribRevision = env.DISTRIB_REVISION ?: 'nightly' |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 58 | // Name of sub-test chunk job |
| 59 | chunkJobName = "test-mk-cookiecutter-templates-chunk" |
| 60 | testModelBuildsData = [:] |
Vasyl Saienko | 772e123 | 2018-07-23 14:42:24 +0300 | [diff] [blame] | 61 | |
chnyda | 467f10f | 2017-05-30 17:25:07 +0200 | [diff] [blame] | 62 | def generateSaltMaster(modEnv, clusterDomain, clusterName) { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 63 | def nodeFile = "${modEnv}/nodes/cfg01.${clusterDomain}.yml" |
| 64 | def nodeString = """classes: |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 65 | - cluster.${clusterName}.infra.config |
| 66 | parameters: |
| 67 | _param: |
| 68 | linux_system_codename: xenial |
| 69 | reclass_data_revision: master |
| 70 | linux: |
| 71 | system: |
| 72 | name: cfg01 |
| 73 | domain: ${clusterDomain} |
| 74 | """ |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 75 | sh "mkdir -p ${modEnv}/nodes/" |
| 76 | println "Create file ${nodeFile}" |
| 77 | writeFile(file: nodeFile, text: nodeString) |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 78 | } |
| 79 | |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 80 | /** |
| 81 | * |
| 82 | * @param contextFile - path to `contexts/XXX.yaml file` |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 83 | * @param virtualenv - pyvenv with CC and dep's |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 84 | * @param templateEnvDir - root of CookieCutter |
| 85 | * @return |
| 86 | */ |
| 87 | |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 88 | def 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 |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 100 | 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) { |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 105 | |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 106 | // get templateOutputDir and productDir |
Michal Kobus | 197f611 | 2018-09-21 14:30:16 +0200 | [diff] [blame] | 107 | templateOutputDir = "${templateEnvDir}/output/${product}" |
| 108 | productDir = product |
azvyagintsev | 7cdcc7a | 2018-09-25 16:47:24 +0300 | [diff] [blame] | 109 | 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 | } |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 116 | if (product == "infra" || (templateContext.default_context["${product}_enabled"] |
| 117 | && templateContext.default_context["${product}_enabled"].toBoolean())) { |
| 118 | |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 119 | 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 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 130 | } |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 131 | generateSaltMaster(generatedModel, clusterDomain, clusterName) |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 132 | } |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 133 | } |
| 134 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 135 | def getAndUnpackNodesInfoArtifact(jobName, copyTo, build) { |
| 136 | return { |
| 137 | dir(copyTo) { |
| 138 | copyArtifacts(projectName: jobName, selector: specific(build), filter: "nodesinfo.tar.gz") |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 139 | sh "tar -xf nodesinfo.tar.gz" |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 140 | sh "rm -v nodesinfo.tar.gz" |
| 141 | } |
| 142 | } |
| 143 | } |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 144 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 145 | def testModel(modelFile, reclassArtifactName, artifactCopyPath) { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 146 | // modelFile - `modelfiname` from model/modelfiname/modelfiname.yaml |
| 147 | //* Grub all models and send it to check in paralell - by one in thread. |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 148 | def _uuid = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}_${modelFile.toLowerCase()}_" + UUID.randomUUID().toString().take(8) |
| 149 | def _values_string = """ |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 150 | --- |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 151 | MODELS_TARGZ: "${env.BUILD_URL}/artifact/${reclassArtifactName}" |
| 152 | DockerCName: "${_uuid}" |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 153 | testReclassEnv: "model/${modelFile}/" |
| 154 | modelFile: "contexts/${modelFile}.yml" |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 155 | DISTRIB_REVISION: "${testDistribRevision}" |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 156 | """ |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 157 | def chunkJob = build job: chunkJobName, parameters: [ |
azvyagintsev | 08b34e3 | 2018-09-12 12:29:42 +0300 | [diff] [blame] | 158 | [$class: 'TextParameterValue', name: 'EXTRA_VARIABLES_YAML', |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 159 | value : _values_string.stripIndent()], |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 160 | ] |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 161 | // Put sub-job info into global map. |
| 162 | testModelBuildsData.put(_uuid, ['jobname' : chunkJob.fullProjectName, |
| 163 | 'copyToDir': "${artifactCopyPath}/${modelFile}", |
| 164 | 'buildId' : "${chunkJob.number}"]) |
chnyda | bc63c9a | 2017-05-30 15:37:54 +0200 | [diff] [blame] | 165 | } |
| 166 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 167 | def StepTestModel(basename, reclassArtifactName, artifactCopyPath) { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 168 | // 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 Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 175 | testModel(basename, reclassArtifactName, artifactCopyPath) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 176 | } |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 177 | } |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 178 | } |
| 179 | |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 180 | def StepPrepareGit(templateEnvFolder, gerrit_data) { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 181 | // return git clone object |
| 182 | return { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 183 | def checkouted = false |
| 184 | common.infoMsg("StepPrepareGit: ${gerrit_data}") |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 185 | // fetch needed sources |
| 186 | dir(templateEnvFolder) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 187 | 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']) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 191 | merged = gerritChange.status == "MERGED" |
| 192 | if (!merged) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 193 | checkouted = gerrit.gerritPatchsetCheckout(gerrit_data) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 194 | } else { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 195 | // 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') |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 199 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 200 | } else { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 201 | // 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 | } |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 207 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 208 | } |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 209 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | def StepGenerateModels(_contextFileList, _virtualenv, _templateEnvDir) { |
| 213 | return { |
| 214 | for (contextFile in _contextFileList) { |
| 215 | generateModel(contextFile, _virtualenv, _templateEnvDir) |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 220 | def 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 |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 224 | def message = '<br/>' |
azvyagintsev | b266ad2 | 2018-09-11 12:11:11 +0300 | [diff] [blame] | 225 | if (env.GERRIT_PROJECT) { |
azvyagintsev | e0eb6cd | 2018-09-12 13:00:40 +0300 | [diff] [blame] | 226 | // TODO are we going to have such branches? |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 227 | if (!['nightly', 'testing', 'stable', 'proposed', 'master'].contains(env.GERRIT_BRANCH)) { |
| 228 | gerritDataCC['gerritBranch'] = env.GERRIT_BRANCH |
| 229 | gerritDataRS['gerritBranch'] = env.GERRIT_BRANCH |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 230 | testDistribRevision = env.GERRIT_BRANCH |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 231 | } |
| 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 |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 236 | message = message + "<br/>RECLASS_SYSTEM_GIT_REF =>${gerritDataRS['gerritRefSpec']}" |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 237 | } else if (env.GERRIT_PROJECT == 'mk/cookiecutter-templates') { |
| 238 | gerritDataCC['gerritRefSpec'] = env.GERRIT_REFSPEC |
| 239 | gerritDataCC['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 240 | message = message + "<br/>COOKIECUTTER_TEMPLATE_REF =>${gerritDataCC['gerritRefSpec']}" |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 241 | } else { |
| 242 | error("Unsuported gerrit-project triggered:${env.GERRIT_PROJECT}") |
| 243 | } |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 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']}" + |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 247 | "<br/>RECLASS_MODEL_BRANCH=> ${gerritDataRS['gerritBranch']}" + message |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 248 | } else { |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 249 | message = "<font color='red'>Non-gerrit trigger run detected!</font>" + message |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 250 | } |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 251 | 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 |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 257 | // '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 Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 268 | } |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 269 | |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 270 | def 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 |
azvyagintsev | 08b34e3 | 2018-09-12 12:29:42 +0300 | [diff] [blame] | 278 | for (String key in secrets['parameters']['_param'].keySet()) { |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 279 | 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 Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 289 | def 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 |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 296 | // ├── ${reclassDirName} <<< reclass system |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 297 | // ├── model |
| 298 | // │  └── ceph <<< from `context basename` |
| 299 | // │  ├── classes |
| 300 | // │  │  ├── cluster |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 301 | // │  │  └── system -> ../../../${reclassDirName} |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 302 | // │  └── 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}") { |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 308 | sh(script: "mkdir -p classes/; ln -sfv ../../../../${common.GetBaseName(archiveName, '.tar.gz')} classes/system ") |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 309 | } |
| 310 | } |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 311 | // replace all generated passwords/secrets/keys with hardcode value for infra/secrets.yaml |
| 312 | replaceGeneratedValues("${envPath}/model") |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 313 | // 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 Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 315 | } |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 316 | archiveArtifacts artifacts: archiveName |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 317 | } |
| 318 | |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 319 | timeout(time: 1, unit: 'HOURS') { |
| 320 | node(slaveNode) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 321 | globalVariatorsUpdate() |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 322 | def templateEnvHead = "${env.WORKSPACE}/EnvHead/" |
| 323 | def templateEnvPatched = "${env.WORKSPACE}/EnvPatched/" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 324 | def contextFileListHead = [] |
| 325 | def contextFileListPatched = [] |
| 326 | def vEnv = "${env.WORKSPACE}/venv" |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 327 | 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" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 332 | 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 |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 336 | def paralellEnvs = [:] |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 337 | paralellEnvs.failFast = true |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 338 | paralellEnvs['downloadEnvHead'] = StepPrepareGit(templateEnvHead, gerritDataCCHEAD) |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 339 | 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 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 347 | } |
| 348 | stage("Check workflow_definition") { |
| 349 | // Check only for patchset |
| 350 | python.setupVirtualenv(vEnv, 'python2', [], "${templateEnvPatched}/requirements.txt") |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 351 | 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 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 356 | } |
| 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 |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 370 | def paralellEnvs = [:] |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 371 | paralellEnvs.failFast = true |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 372 | paralellEnvs['GenerateEnvHead'] = StepGenerateModels(contextFileListHead, vEnv, templateEnvHead) |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 373 | 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}") |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 380 | } |
| 381 | |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 382 | // 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 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 395 | // link all models, to use one global reclass |
| 396 | // For HEAD |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 397 | linkReclassModels(contextFileListHead, templateEnvHead, headReclassArtifactName) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 398 | // For patched |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 399 | linkReclassModels(contextFileListPatched, templateEnvPatched, patchedReclassArtifactName) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 400 | } |
| 401 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 402 | stage("Compare cluster lvl Head/Patched") { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 403 | // Compare patched and HEAD reclass pillars |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 404 | compareRoot = "${env.WORKSPACE}/cluster_compare/" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 405 | sh(script: """ |
| 406 | mkdir -pv ${compareRoot}/new ${compareRoot}/old |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 407 | tar -xzf ${patchedReclassArtifactName} --directory ${compareRoot}/new |
| 408 | tar -xzf ${headReclassArtifactName} --directory ${compareRoot}/old |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 409 | """) |
| 410 | common.warningMsg('infra/secrets.yml has been skipped from compare!') |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 411 | result = '\n' + common.comparePillars(compareRoot, env.BUILD_URL, "-Ev \'infra/secrets.yml|\\.git\'") |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 412 | currentBuild.description = currentBuild.description ? currentBuild.description + result : result |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 413 | } |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 414 | 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 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 422 | common.infoMsg("Found: ${contextFileListPatched.size()} patched contexts to test.") |
| 423 | for (String context : contextFileListPatched) { |
| 424 | def basename = common.GetBaseName(context, '.yml') |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 425 | stepsForParallel.put("ContextPatchedTest:${basename}", StepTestModel(basename, patchedReclassArtifactName, reclassInfoPatchedPath)) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 426 | } |
| 427 | parallel stepsForParallel |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 428 | 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 Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 440 | // remove timestamp field from rendered files |
| 441 | sh("find ${reclassNodeInfoDir} -type f -exec sed -i '/ timestamp: .*/d' {} \\;") |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 442 | // Compare patched and HEAD reclass pillars |
| 443 | result = '\n' + common.comparePillars(reclassNodeInfoDir, env.BUILD_URL, '') |
| 444 | currentBuild.description = currentBuild.description ? currentBuild.description + result : result |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 445 | } |
Denis Egorenko | 04ca9f2 | 2018-09-19 16:06:49 +0400 | [diff] [blame] | 446 | stage('Check include order') { |
azvyagintsev | e7b8e79 | 2018-09-21 17:27:01 +0300 | [diff] [blame] | 447 | 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 Egorenko | 04ca9f2 | 2018-09-19 16:06:49 +0400 | [diff] [blame] | 473 | } |
| 474 | } |
azvyagintsev | e7b8e79 | 2018-09-21 17:27:01 +0300 | [diff] [blame] | 475 | 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 Egorenko | 04ca9f2 | 2018-09-19 16:06:49 +0400 | [diff] [blame] | 486 | } |
Denis Egorenko | 04ca9f2 | 2018-09-19 16:06:49 +0400 | [diff] [blame] | 487 | } |
| 488 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 489 | sh(script: 'find . -mindepth 1 -delete > /dev/null || true') |
| 490 | |
| 491 | } catch (Throwable e) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 492 | if (alreadyMerged) { |
| 493 | currentBuild.result = 'ABORTED' |
| 494 | currentBuild.description = "Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them" |
| 495 | return |
| 496 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 497 | currentBuild.result = "FAILURE" |
| 498 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 499 | throw e |
| 500 | } finally { |
| 501 | def dummy = "dummy" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 502 | } |
| 503 | } |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 504 | } |