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 | |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 20 | slaveNode = env.SLAVE_NODE ?: 'docker' |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 21 | |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 22 | // Global var's |
| 23 | alreadyMerged = false |
| 24 | gerritConData = [credentialsId : env.CREDENTIALS_ID, |
| 25 | gerritName : env.GERRIT_NAME ?: 'mcp-jenkins', |
| 26 | gerritHost : env.GERRIT_HOST ?: 'gerrit.mcp.mirantis.net', |
azvyagintsev | b266ad2 | 2018-09-11 12:11:11 +0300 | [diff] [blame] | 27 | gerritScheme : env.GERRIT_SCHEME ?: 'ssh', |
| 28 | gerritPort : env.GERRIT_PORT ?: '29418', |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 29 | gerritRefSpec : null, |
| 30 | gerritProject : null, |
| 31 | withWipeOut : true, |
| 32 | GERRIT_CHANGE_NUMBER: null] |
| 33 | // |
| 34 | //ccTemplatesRepo = env.COOKIECUTTER_TEMPLATE_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.net:29418/mk/cookiecutter-templates' |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 35 | gerritDataCCHEAD = [:] |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 36 | gerritDataCC = [:] |
| 37 | gerritDataCC << gerritConData |
| 38 | gerritDataCC['gerritBranch'] = env.COOKIECUTTER_TEMPLATE_BRANCH ?: 'master' |
| 39 | gerritDataCC['gerritProject'] = 'mk/cookiecutter-templates' |
| 40 | // |
| 41 | //reclassSystemRepo = env.RECLASS_SYSTEM_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.net:29418/salt-models/reclass-system' |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 42 | gerritDataRSHEAD = [:] |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 43 | gerritDataRS = [:] |
| 44 | gerritDataRS << gerritConData |
| 45 | gerritDataRS['gerritBranch'] = env.RECLASS_MODEL_BRANCH ?: 'master' |
| 46 | gerritDataRS['gerritProject'] = 'salt-models/reclass-system' |
| 47 | |
| 48 | // version of debRepos, aka formulas\reclass |
azvyagintsev | 10e2401 | 2018-09-10 21:36:32 +0300 | [diff] [blame] | 49 | testDistribRevision = env.DISTRIB_REVISION ?: 'nightly' |
| 50 | reclassVersion = 'v1.5.4' |
azvyagintsev | b266ad2 | 2018-09-11 12:11:11 +0300 | [diff] [blame] | 51 | if (env.RECLASS_VERSION) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 52 | reclassVersion = env.RECLASS_VERSION |
Vasyl Saienko | 772e123 | 2018-07-23 14:42:24 +0300 | [diff] [blame] | 53 | } |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 54 | // Name of sub-test chunk job |
| 55 | chunkJobName = "test-mk-cookiecutter-templates-chunk" |
| 56 | testModelBuildsData = [:] |
Vasyl Saienko | 772e123 | 2018-07-23 14:42:24 +0300 | [diff] [blame] | 57 | |
chnyda | 467f10f | 2017-05-30 17:25:07 +0200 | [diff] [blame] | 58 | def generateSaltMaster(modEnv, clusterDomain, clusterName) { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 59 | def nodeFile = "${modEnv}/nodes/cfg01.${clusterDomain}.yml" |
| 60 | def nodeString = """classes: |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 61 | - cluster.${clusterName}.infra.config |
| 62 | parameters: |
| 63 | _param: |
| 64 | linux_system_codename: xenial |
| 65 | reclass_data_revision: master |
| 66 | linux: |
| 67 | system: |
| 68 | name: cfg01 |
| 69 | domain: ${clusterDomain} |
| 70 | """ |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 71 | sh "mkdir -p ${modEnv}/nodes/" |
| 72 | println "Create file ${nodeFile}" |
| 73 | writeFile(file: nodeFile, text: nodeString) |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 74 | } |
| 75 | |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 76 | /** |
| 77 | * |
| 78 | * @param contextFile - path to `contexts/XXX.yaml file` |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 79 | * @param virtualenv - pyvenv with CC and dep's |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 80 | * @param templateEnvDir - root of CookieCutter |
| 81 | * @return |
| 82 | */ |
| 83 | |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 84 | def generateModel(contextFile, virtualenv, templateEnvDir) { |
| 85 | def modelEnv = "${templateEnvDir}/model" |
| 86 | def basename = common.GetBaseName(contextFile, '.yml') |
| 87 | def generatedModel = "${modelEnv}/${basename}" |
| 88 | def content = readFile(file: "${templateEnvDir}/contexts/${contextFile}") |
| 89 | def templateContext = readYaml text: content |
| 90 | def clusterDomain = templateContext.default_context.cluster_domain |
| 91 | def clusterName = templateContext.default_context.cluster_name |
| 92 | def outputDestination = "${generatedModel}/classes/cluster/${clusterName}" |
| 93 | def templateBaseDir = templateEnvDir |
| 94 | def templateDir = "${templateEnvDir}/dir" |
| 95 | def templateOutputDir = templateBaseDir |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 96 | dir(templateEnvDir) { |
| 97 | sh(script: "rm -rf ${generatedModel} || true") |
| 98 | common.infoMsg("Generating model from context ${contextFile}") |
| 99 | def productList = ["infra", "cicd", "opencontrail", "kubernetes", "openstack", "oss", "stacklight", "ceph"] |
| 100 | for (product in productList) { |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 101 | |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 102 | // get templateOutputDir and productDir |
| 103 | if (product.startsWith("stacklight")) { |
| 104 | templateOutputDir = "${templateEnvDir}/output/stacklight" |
| 105 | try { |
| 106 | productDir = "stacklight" + templateContext.default_context['stacklight_version'] |
| 107 | } catch (Throwable e) { |
| 108 | productDir = "stacklight1" |
| 109 | } |
| 110 | } else { |
| 111 | templateOutputDir = "${templateEnvDir}/output/${product}" |
| 112 | productDir = product |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 113 | } |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 114 | |
| 115 | if (product == "infra" || (templateContext.default_context["${product}_enabled"] |
| 116 | && templateContext.default_context["${product}_enabled"].toBoolean())) { |
| 117 | |
| 118 | templateDir = "${templateEnvDir}/cluster_product/${productDir}" |
| 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 | reclassVersion: "${reclassVersion}" |
| 157 | """ |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 158 | def chunkJob = build job: chunkJobName, parameters: [ |
azvyagintsev | 08b34e3 | 2018-09-12 12:29:42 +0300 | [diff] [blame] | 159 | [$class: 'TextParameterValue', name: 'EXTRA_VARIABLES_YAML', |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 160 | value : _values_string.stripIndent()], |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 161 | ] |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 162 | // Put sub-job info into global map. |
| 163 | testModelBuildsData.put(_uuid, ['jobname' : chunkJob.fullProjectName, |
| 164 | 'copyToDir': "${artifactCopyPath}/${modelFile}", |
| 165 | 'buildId' : "${chunkJob.number}"]) |
chnyda | bc63c9a | 2017-05-30 15:37:54 +0200 | [diff] [blame] | 166 | } |
| 167 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 168 | def StepTestModel(basename, reclassArtifactName, artifactCopyPath) { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 169 | // We need to wrap what we return in a Groovy closure, or else it's invoked |
| 170 | // when this method is called, not when we pass it to parallel. |
| 171 | // To do this, you need to wrap the code below in { }, and either return |
| 172 | // that explicitly, or use { -> } syntax. |
| 173 | // return node object |
| 174 | return { |
| 175 | node(slaveNode) { |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 176 | testModel(basename, reclassArtifactName, artifactCopyPath) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 177 | } |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 178 | } |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 179 | } |
| 180 | |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 181 | def StepPrepareGit(templateEnvFolder, gerrit_data) { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 182 | // return git clone object |
| 183 | return { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 184 | def checkouted = false |
| 185 | common.infoMsg("StepPrepareGit: ${gerrit_data}") |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 186 | // fetch needed sources |
| 187 | dir(templateEnvFolder) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 188 | if (gerrit_data['gerritRefSpec']) { |
| 189 | // Those part might be not work,in case manual var's pass |
| 190 | def gerritChange = gerrit.getGerritChange(gerrit_data['gerritName'], gerrit_data['gerritHost'], |
| 191 | gerrit_data['GERRIT_CHANGE_NUMBER'], gerrit_data['credentialsId']) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 192 | merged = gerritChange.status == "MERGED" |
| 193 | if (!merged) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 194 | checkouted = gerrit.gerritPatchsetCheckout(gerrit_data) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 195 | } else { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 196 | // update global variable for pretty return from pipeline |
| 197 | alreadyMerged = true |
| 198 | common.successMsg("Change ${gerrit_data['GERRIT_CHANGE_NUMBER']} is already merged, no need to gate them") |
| 199 | error('change already merged') |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 200 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 201 | } else { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 202 | // Get clean HEAD |
| 203 | gerrit_data['useGerritTriggerBuildChooser'] = false |
| 204 | checkouted = gerrit.gerritPatchsetCheckout(gerrit_data) |
| 205 | if (!checkouted) { |
| 206 | error("Failed to get repo:${gerrit_data}") |
| 207 | } |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 208 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 209 | } |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 210 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | def StepGenerateModels(_contextFileList, _virtualenv, _templateEnvDir) { |
| 214 | return { |
| 215 | for (contextFile in _contextFileList) { |
| 216 | generateModel(contextFile, _virtualenv, _templateEnvDir) |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 221 | def globalVariatorsUpdate() { |
| 222 | // Simple function, to check and define branch-around variables |
| 223 | // In general, simply make transition updates for non-master branch |
| 224 | // based on magic logic |
| 225 | def message = '' |
azvyagintsev | b266ad2 | 2018-09-11 12:11:11 +0300 | [diff] [blame] | 226 | if (env.GERRIT_PROJECT) { |
azvyagintsev | e0eb6cd | 2018-09-12 13:00:40 +0300 | [diff] [blame] | 227 | // TODO are we going to have such branches? |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 228 | if (!['nightly', 'testing', 'stable', 'proposed', 'master'].contains(env.GERRIT_BRANCH)) { |
| 229 | gerritDataCC['gerritBranch'] = env.GERRIT_BRANCH |
| 230 | gerritDataRS['gerritBranch'] = env.GERRIT_BRANCH |
| 231 | // 'binary' branch logic w\o 'release/' prefix |
| 232 | testDistribRevision = env.GERRIT_BRANCH.split('/')[-1] |
| 233 | // Check if we are going to test bleeding-edge release, which doesn't have binary release yet |
| 234 | if (!common.checkRemoteBinary([apt_mk_version: testDistribRevision]).linux_system_repo_url) { |
| 235 | common.errorMsg("Binary release: ${testDistribRevision} not exist. Fallback to 'proposed'! ") |
| 236 | testDistribRevision = 'proposed' |
| 237 | } |
| 238 | } |
| 239 | // Identify, who triggered. To whom we should pass refspec |
| 240 | if (env.GERRIT_PROJECT == 'salt-models/reclass-system') { |
| 241 | gerritDataRS['gerritRefSpec'] = env.GERRIT_REFSPEC |
| 242 | gerritDataRS['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER |
| 243 | message = "<br/>RECLASS_SYSTEM_GIT_REF =>${gerritDataRS['gerritRefSpec']}" |
| 244 | } else if (env.GERRIT_PROJECT == 'mk/cookiecutter-templates') { |
| 245 | gerritDataCC['gerritRefSpec'] = env.GERRIT_REFSPEC |
| 246 | gerritDataCC['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER |
| 247 | message = "<br/>COOKIECUTTER_TEMPLATE_REF =>${gerritDataCC['gerritRefSpec']}" |
| 248 | } else { |
| 249 | error("Unsuported gerrit-project triggered:${env.GERRIT_PROJECT}") |
| 250 | } |
| 251 | |
| 252 | message = "<font color='red'>GerritTrigger detected! We are in auto-mode:</font>" + |
| 253 | "<br/>Test env variables has been changed:" + |
| 254 | "<br/>COOKIECUTTER_TEMPLATE_BRANCH => ${gerritDataCC['gerritBranch']}" + |
| 255 | "<br/>DISTRIB_REVISION =>${testDistribRevision}" + |
Denis Egorenko | 04ca9f2 | 2018-09-19 16:06:49 +0400 | [diff] [blame^] | 256 | "<br/>RECLASS_MODEL_BRANCH=> ${gerritDataRS['gerritBranch']}" + message + "<br/>" |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 257 | common.warningMsg(message) |
| 258 | currentBuild.description = currentBuild.description ? message + "<br/>" + currentBuild.description : message |
| 259 | } else { |
| 260 | // Check for passed variables: |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 261 | gerritDataRS['gerritRefSpec'] = env.RECLASS_SYSTEM_GIT_REF ?: null |
| 262 | gerritDataCC['gerritRefSpec'] = env.COOKIECUTTER_TEMPLATE_REF ?: null |
| 263 | message = "<font color='red'>Non-gerrit trigger run detected!</font>" + "<br/>" |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 264 | currentBuild.description = currentBuild.description ? message + "<br/>" + currentBuild.description : message |
| 265 | } |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 266 | gerritDataCCHEAD << gerritDataCC |
| 267 | gerritDataCCHEAD['gerritRefSpec'] = null |
| 268 | gerritDataCCHEAD['GERRIT_CHANGE_NUMBER'] = null |
| 269 | gerritDataRSHEAD << gerritDataRS |
| 270 | gerritDataRSHEAD['gerritRefSpec'] = null |
| 271 | gerritDataRSHEAD['GERRIT_CHANGE_NUMBER'] = null |
| 272 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 273 | } |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 274 | |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 275 | def 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 |
azvyagintsev | 08b34e3 | 2018-09-12 12:29:42 +0300 | [diff] [blame] | 283 | for (String key in secrets['parameters']['_param'].keySet()) { |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 284 | 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 Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 294 | def 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 |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 301 | // ├── ${reclassDirName} <<< reclass system |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 302 | // ├── model |
| 303 | // │  └── ceph <<< from `context basename` |
| 304 | // │  ├── classes |
| 305 | // │  │  ├── cluster |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 306 | // │  │  └── system -> ../../../${reclassDirName} |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 307 | // │  └── 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}") { |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 313 | 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] | 314 | } |
| 315 | } |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 316 | // replace all generated passwords/secrets/keys with hardcode value for infra/secrets.yaml |
| 317 | replaceGeneratedValues("${envPath}/model") |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 318 | // 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 Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 320 | } |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 321 | archiveArtifacts artifacts: archiveName |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 322 | } |
| 323 | |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 324 | timeout(time: 1, unit: 'HOURS') { |
| 325 | node(slaveNode) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 326 | globalVariatorsUpdate() |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 327 | def templateEnvHead = "${env.WORKSPACE}/EnvHead/" |
| 328 | def templateEnvPatched = "${env.WORKSPACE}/EnvPatched/" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 329 | def contextFileListHead = [] |
| 330 | def contextFileListPatched = [] |
| 331 | def vEnv = "${env.WORKSPACE}/venv" |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 332 | 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" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 337 | 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 |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 341 | def paralellEnvs = [:] |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 342 | paralellEnvs.failFast = true |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 343 | paralellEnvs['downloadEnvHead'] = StepPrepareGit(templateEnvHead, gerritDataCCHEAD) |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 344 | 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 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 352 | } |
| 353 | stage("Check workflow_definition") { |
| 354 | // Check only for patchset |
| 355 | python.setupVirtualenv(vEnv, 'python2', [], "${templateEnvPatched}/requirements.txt") |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 356 | 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 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 361 | } |
| 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 |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 375 | def paralellEnvs = [:] |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 376 | paralellEnvs.failFast = true |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 377 | paralellEnvs['GenerateEnvHead'] = StepGenerateModels(contextFileListHead, vEnv, templateEnvHead) |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 378 | 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}") |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 385 | } |
| 386 | |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 387 | // 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 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 400 | // link all models, to use one global reclass |
| 401 | // For HEAD |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 402 | linkReclassModels(contextFileListHead, templateEnvHead, headReclassArtifactName) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 403 | // For patched |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 404 | linkReclassModels(contextFileListPatched, templateEnvPatched, patchedReclassArtifactName) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 405 | } |
| 406 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 407 | stage("Compare cluster lvl Head/Patched") { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 408 | // Compare patched and HEAD reclass pillars |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 409 | compareRoot = "${env.WORKSPACE}/cluster_compare/" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 410 | sh(script: """ |
| 411 | mkdir -pv ${compareRoot}/new ${compareRoot}/old |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 412 | tar -xzf ${patchedReclassArtifactName} --directory ${compareRoot}/new |
| 413 | tar -xzf ${headReclassArtifactName} --directory ${compareRoot}/old |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 414 | """) |
| 415 | common.warningMsg('infra/secrets.yml has been skipped from compare!') |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 416 | 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] | 417 | currentBuild.description = currentBuild.description ? currentBuild.description + result : result |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 418 | } |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 419 | 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 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 427 | common.infoMsg("Found: ${contextFileListPatched.size()} patched contexts to test.") |
| 428 | for (String context : contextFileListPatched) { |
| 429 | def basename = common.GetBaseName(context, '.yml') |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 430 | stepsForParallel.put("ContextPatchedTest:${basename}", StepTestModel(basename, patchedReclassArtifactName, reclassInfoPatchedPath)) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 431 | } |
| 432 | parallel stepsForParallel |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 433 | 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 Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 445 | // remove timestamp field from rendered files |
| 446 | sh("find ${reclassNodeInfoDir} -type f -exec sed -i '/ timestamp: .*/d' {} \\;") |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 447 | // Compare patched and HEAD reclass pillars |
| 448 | result = '\n' + common.comparePillars(reclassNodeInfoDir, env.BUILD_URL, '') |
| 449 | currentBuild.description = currentBuild.description ? currentBuild.description + result : result |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 450 | } |
Denis Egorenko | 04ca9f2 | 2018-09-19 16:06:49 +0400 | [diff] [blame^] | 451 | stage('Check include order') { |
| 452 | def correctIncludeOrder = ["service", "system", "cluster"] |
| 453 | dir(reclassInfoPatchedPath) { |
| 454 | def nodeInfoFiles = findFiles(glob: "**/*.reclass.nodeinfo") |
| 455 | def messages = ["<b>Wrong include ordering found</b><ul>"] |
| 456 | def stepsForParallel = [:] |
| 457 | nodeInfoFiles.each { nodeInfo -> |
| 458 | stepsForParallel.put("Checking ${nodeInfo.path}:", { |
| 459 | def node = readYaml file: nodeInfo.path |
| 460 | def classes = node['classes'] |
| 461 | def curClassID = 0 |
| 462 | def prevClassID = 0 |
| 463 | def wrongOrder = false |
| 464 | for(String className in classes) { |
| 465 | def currentClass = className.tokenize('.')[0] |
| 466 | curClassID = correctIncludeOrder.indexOf(currentClass) |
| 467 | if (currentClass != correctIncludeOrder[prevClassID]) { |
| 468 | if (prevClassID > curClassID) { |
| 469 | wrongOrder = true |
| 470 | common.warningMsg("File ${nodeInfo.path} contains wrong order of classes including: Includes for ${className} should be declared before ${correctIncludeOrder[prevClassID]} includes") |
| 471 | } else { |
| 472 | prevClassID = curClassID |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | if(wrongOrder) { |
| 477 | messages.add("<li>${nodeInfo.path} contains wrong order of classes including</li>") |
| 478 | } |
| 479 | }) |
| 480 | } |
| 481 | parallel stepsForParallel |
| 482 | def includerOrder = '<b>No wrong include order</b>' |
| 483 | if (messages.size() != 1) { |
| 484 | includerOrder = messages.join('') |
| 485 | } |
| 486 | currentBuild.description = currentBuild.description ? currentBuild.description + includerOrder : includerOrder |
| 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 | } |