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 | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 20 | slaveNode = env.SLAVE_NODE ?: 'python&&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' |
| 35 | gerritDataCC = [:] |
| 36 | gerritDataCC << gerritConData |
| 37 | gerritDataCC['gerritBranch'] = env.COOKIECUTTER_TEMPLATE_BRANCH ?: 'master' |
| 38 | gerritDataCC['gerritProject'] = 'mk/cookiecutter-templates' |
| 39 | // |
| 40 | //reclassSystemRepo = env.RECLASS_SYSTEM_URL ?: 'ssh://mcp-jenkins@gerrit.mcp.mirantis.net:29418/salt-models/reclass-system' |
| 41 | gerritDataRS = [:] |
| 42 | gerritDataRS << gerritConData |
| 43 | gerritDataRS['gerritBranch'] = env.RECLASS_MODEL_BRANCH ?: 'master' |
| 44 | gerritDataRS['gerritProject'] = 'salt-models/reclass-system' |
| 45 | |
| 46 | // version of debRepos, aka formulas\reclass |
azvyagintsev | 10e2401 | 2018-09-10 21:36:32 +0300 | [diff] [blame] | 47 | testDistribRevision = env.DISTRIB_REVISION ?: 'nightly' |
| 48 | reclassVersion = 'v1.5.4' |
azvyagintsev | b266ad2 | 2018-09-11 12:11:11 +0300 | [diff] [blame] | 49 | if (env.RECLASS_VERSION) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 50 | reclassVersion = env.RECLASS_VERSION |
Vasyl Saienko | 772e123 | 2018-07-23 14:42:24 +0300 | [diff] [blame] | 51 | } |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 52 | // Name of sub-test chunk job |
| 53 | chunkJobName = "test-mk-cookiecutter-templates-chunk" |
| 54 | testModelBuildsData = [:] |
| 55 | |
Vasyl Saienko | 772e123 | 2018-07-23 14:42:24 +0300 | [diff] [blame] | 56 | |
chnyda | 467f10f | 2017-05-30 17:25:07 +0200 | [diff] [blame] | 57 | def generateSaltMaster(modEnv, clusterDomain, clusterName) { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 58 | def nodeFile = "${modEnv}/nodes/cfg01.${clusterDomain}.yml" |
| 59 | def nodeString = """classes: |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 60 | - cluster.${clusterName}.infra.config |
| 61 | parameters: |
| 62 | _param: |
| 63 | linux_system_codename: xenial |
| 64 | reclass_data_revision: master |
| 65 | linux: |
| 66 | system: |
| 67 | name: cfg01 |
| 68 | domain: ${clusterDomain} |
| 69 | """ |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 70 | sh "mkdir -p ${modEnv}/nodes/" |
| 71 | println "Create file ${nodeFile}" |
| 72 | writeFile(file: nodeFile, text: nodeString) |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 73 | } |
| 74 | |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 75 | /** |
| 76 | * |
| 77 | * @param contextFile - path to `contexts/XXX.yaml file` |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 78 | * @param virtualenv - pyvenv with CC and dep's |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 79 | * @param templateEnvDir - root of CookieCutter |
| 80 | * @return |
| 81 | */ |
| 82 | |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 83 | def generateModel(contextFile, virtualenv, templateEnvDir) { |
| 84 | def modelEnv = "${templateEnvDir}/model" |
| 85 | def basename = common.GetBaseName(contextFile, '.yml') |
| 86 | def generatedModel = "${modelEnv}/${basename}" |
| 87 | def content = readFile(file: "${templateEnvDir}/contexts/${contextFile}") |
| 88 | def templateContext = readYaml text: content |
| 89 | def clusterDomain = templateContext.default_context.cluster_domain |
| 90 | def clusterName = templateContext.default_context.cluster_name |
| 91 | def outputDestination = "${generatedModel}/classes/cluster/${clusterName}" |
| 92 | def templateBaseDir = templateEnvDir |
| 93 | def templateDir = "${templateEnvDir}/dir" |
| 94 | def templateOutputDir = templateBaseDir |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 95 | dir(templateEnvDir) { |
| 96 | sh(script: "rm -rf ${generatedModel} || true") |
| 97 | common.infoMsg("Generating model from context ${contextFile}") |
| 98 | def productList = ["infra", "cicd", "opencontrail", "kubernetes", "openstack", "oss", "stacklight", "ceph"] |
| 99 | for (product in productList) { |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 100 | |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 101 | // get templateOutputDir and productDir |
| 102 | if (product.startsWith("stacklight")) { |
| 103 | templateOutputDir = "${templateEnvDir}/output/stacklight" |
| 104 | try { |
| 105 | productDir = "stacklight" + templateContext.default_context['stacklight_version'] |
| 106 | } catch (Throwable e) { |
| 107 | productDir = "stacklight1" |
| 108 | } |
| 109 | } else { |
| 110 | templateOutputDir = "${templateEnvDir}/output/${product}" |
| 111 | productDir = product |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 112 | } |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 113 | |
| 114 | if (product == "infra" || (templateContext.default_context["${product}_enabled"] |
| 115 | && templateContext.default_context["${product}_enabled"].toBoolean())) { |
| 116 | |
| 117 | templateDir = "${templateEnvDir}/cluster_product/${productDir}" |
| 118 | common.infoMsg("Generating product " + product + " from " + templateDir + " to " + templateOutputDir) |
| 119 | |
| 120 | sh "rm -rf ${templateOutputDir} || true" |
| 121 | sh "mkdir -p ${templateOutputDir}" |
| 122 | sh "mkdir -p ${outputDestination}" |
| 123 | |
| 124 | python.buildCookiecutterTemplate(templateDir, content, templateOutputDir, virtualenv, templateBaseDir) |
| 125 | sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}" |
| 126 | } else { |
| 127 | common.warningMsg("Product " + product + " is disabled") |
| 128 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 129 | } |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 130 | generateSaltMaster(generatedModel, clusterDomain, clusterName) |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 131 | } |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 132 | } |
| 133 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 134 | def getAndUnpackNodesInfoArtifact(jobName, copyTo, build) { |
| 135 | return { |
| 136 | dir(copyTo) { |
| 137 | copyArtifacts(projectName: jobName, selector: specific(build), filter: "nodesinfo.tar.gz") |
| 138 | sh "tar -xvf nodesinfo.tar.gz" |
| 139 | sh "rm -v nodesinfo.tar.gz" |
| 140 | } |
| 141 | } |
| 142 | } |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 143 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 144 | def testModel(modelFile, reclassArtifactName, artifactCopyPath) { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 145 | // modelFile - `modelfiname` from model/modelfiname/modelfiname.yaml |
| 146 | //* 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] | 147 | def _uuid = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}_${modelFile.toLowerCase()}_" + UUID.randomUUID().toString().take(8) |
| 148 | def _values_string = """ |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 149 | --- |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 150 | MODELS_TARGZ: "${env.BUILD_URL}/artifact/${reclassArtifactName}" |
| 151 | DockerCName: "${_uuid}" |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 152 | testReclassEnv: "model/${modelFile}/" |
| 153 | modelFile: "contexts/${modelFile}.yml" |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 154 | DISTRIB_REVISION: "${testDistribRevision}" |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 155 | EXTRA_FORMULAS: "${env.EXTRA_FORMULAS}" |
| 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 | 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 |
| 230 | // 'binary' branch logic w\o 'release/' prefix |
| 231 | testDistribRevision = env.GERRIT_BRANCH.split('/')[-1] |
| 232 | // Check if we are going to test bleeding-edge release, which doesn't have binary release yet |
| 233 | if (!common.checkRemoteBinary([apt_mk_version: testDistribRevision]).linux_system_repo_url) { |
| 234 | common.errorMsg("Binary release: ${testDistribRevision} not exist. Fallback to 'proposed'! ") |
| 235 | testDistribRevision = 'proposed' |
| 236 | } |
| 237 | } |
| 238 | // Identify, who triggered. To whom we should pass refspec |
| 239 | if (env.GERRIT_PROJECT == 'salt-models/reclass-system') { |
| 240 | gerritDataRS['gerritRefSpec'] = env.GERRIT_REFSPEC |
| 241 | gerritDataRS['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER |
| 242 | message = "<br/>RECLASS_SYSTEM_GIT_REF =>${gerritDataRS['gerritRefSpec']}" |
| 243 | } else if (env.GERRIT_PROJECT == 'mk/cookiecutter-templates') { |
| 244 | gerritDataCC['gerritRefSpec'] = env.GERRIT_REFSPEC |
| 245 | gerritDataCC['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER |
| 246 | message = "<br/>COOKIECUTTER_TEMPLATE_REF =>${gerritDataCC['gerritRefSpec']}" |
| 247 | } else { |
| 248 | error("Unsuported gerrit-project triggered:${env.GERRIT_PROJECT}") |
| 249 | } |
| 250 | |
| 251 | message = "<font color='red'>GerritTrigger detected! We are in auto-mode:</font>" + |
| 252 | "<br/>Test env variables has been changed:" + |
| 253 | "<br/>COOKIECUTTER_TEMPLATE_BRANCH => ${gerritDataCC['gerritBranch']}" + |
| 254 | "<br/>DISTRIB_REVISION =>${testDistribRevision}" + |
| 255 | "<br/>RECLASS_MODEL_BRANCH=> ${gerritDataRS['gerritBranch']}" + message |
| 256 | common.warningMsg(message) |
| 257 | currentBuild.description = currentBuild.description ? message + "<br/>" + currentBuild.description : message |
| 258 | } else { |
| 259 | // Check for passed variables: |
azvyagintsev | b266ad2 | 2018-09-11 12:11:11 +0300 | [diff] [blame] | 260 | if (env.RECLASS_SYSTEM_GIT_REF) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 261 | gerritDataRS['gerritRefSpec'] = RECLASS_SYSTEM_GIT_REF |
| 262 | } |
azvyagintsev | b266ad2 | 2018-09-11 12:11:11 +0300 | [diff] [blame] | 263 | if (env.COOKIECUTTER_TEMPLATE_REF) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 264 | gerritDataCC['gerritRefSpec'] = COOKIECUTTER_TEMPLATE_REF |
| 265 | } |
| 266 | message = "<font color='red'>Manual run detected!</font>" + "<br/>" |
| 267 | currentBuild.description = currentBuild.description ? message + "<br/>" + currentBuild.description : message |
| 268 | } |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 269 | } |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 270 | |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 271 | def replaceGeneratedValues(path) { |
| 272 | def files = sh(script: "find ${path} -name 'secrets.yml'", returnStdout: true) |
| 273 | def stepsForParallel = [:] |
| 274 | stepsForParallel.failFast = true |
| 275 | files.tokenize().each { |
| 276 | stepsForParallel.put("Removing generated passwords/secrets from ${it}", |
| 277 | { |
| 278 | def secrets = readYaml file: it |
azvyagintsev | 08b34e3 | 2018-09-12 12:29:42 +0300 | [diff] [blame^] | 279 | for (String key in secrets['parameters']['_param'].keySet()) { |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 280 | secrets['parameters']['_param'][key] = 'generated' |
| 281 | } |
| 282 | // writeYaml can't write to already existing file |
| 283 | writeYaml file: "${it}.tmp", data: secrets |
| 284 | sh "mv ${it}.tmp ${it}" |
| 285 | }) |
| 286 | } |
| 287 | parallel stepsForParallel |
| 288 | } |
| 289 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 290 | def linkReclassModels(contextList, envPath, archiveName) { |
| 291 | // to be able share reclass for all subenvs |
| 292 | // Also, makes artifact test more solid - use one reclass for all of sub-models. |
| 293 | // Archive Structure will be: |
| 294 | // tar.gz |
| 295 | // ├── contexts |
| 296 | // │  └── ceph.yml |
| 297 | // ├── global_reclass <<< reclass system |
| 298 | // ├── model |
| 299 | // │  └── ceph <<< from `context basename` |
| 300 | // │  ├── classes |
| 301 | // │  │  ├── cluster |
| 302 | // │  │  └── system -> ../../../global_reclass |
| 303 | // │  └── nodes |
| 304 | // │  └── cfg01.ceph-cluster-domain.local.yml |
| 305 | dir(envPath) { |
| 306 | for (String context : contextList) { |
| 307 | def basename = common.GetBaseName(context, '.yml') |
| 308 | dir("${envPath}/model/${basename}") { |
| 309 | sh(script: 'mkdir -p classes/; ln -sfv ../../../../global_reclass classes/system ') |
| 310 | } |
| 311 | } |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 312 | // replace all generated passwords/secrets/keys with hardcode value for infra/secrets.yaml |
| 313 | replaceGeneratedValues("${envPath}/model") |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 314 | // Save all models and all contexts. Warning! `h` flag must be used. |
| 315 | sh(script: "set -ex; tar -chzf ${archiveName} --exclude='*@tmp' model contexts", returnStatus: true) |
| 316 | archiveArtifacts artifacts: archiveName |
| 317 | // move for "Compare Pillars" stage |
| 318 | sh(script: "mv -v ${archiveName} ${env.WORKSPACE}") |
| 319 | } |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 320 | } |
| 321 | |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 322 | timeout(time: 1, unit: 'HOURS') { |
| 323 | node(slaveNode) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 324 | globalVariatorsUpdate() |
| 325 | def gerritDataCCHEAD = [:] |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 326 | def templateEnvHead = "${env.WORKSPACE}/EnvHead/" |
| 327 | def templateEnvPatched = "${env.WORKSPACE}/EnvPatched/" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 328 | def contextFileListHead = [] |
| 329 | def contextFileListPatched = [] |
| 330 | def vEnv = "${env.WORKSPACE}/venv" |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 331 | def headReclassArtifactName = "head_reclass.tar.gz" |
| 332 | def patchedReclassArtifactName = "patched_reclass.tar.gz" |
| 333 | def reclassNodeInfoDir = "${env.WORKSPACE}/reclassNodeInfo_compare/" |
| 334 | def reclassInfoHeadPath = "${reclassNodeInfoDir}/old" |
| 335 | def reclassInfoPatchedPath = "${reclassNodeInfoDir}/new" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 336 | try { |
| 337 | sh(script: 'find . -mindepth 1 -delete > /dev/null || true') |
| 338 | stage('Download and prepare CC env') { |
| 339 | // Prepare 2 env - for patchset, and for HEAD |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 340 | def paralellEnvs = [:] |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 341 | paralellEnvs.failFast = true |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 342 | paralellEnvs['downloadEnvPatched'] = StepPrepareGit(templateEnvPatched, gerritDataCC) |
| 343 | gerritDataCCHEAD << gerritDataCC |
| 344 | gerritDataCCHEAD['gerritRefSpec'] = null; gerritDataCCHEAD['GERRIT_CHANGE_NUMBER'] = null |
| 345 | paralellEnvs['downloadEnvHead'] = StepPrepareGit(templateEnvHead, gerritDataCCHEAD) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 346 | parallel paralellEnvs |
| 347 | } |
| 348 | stage("Check workflow_definition") { |
| 349 | // Check only for patchset |
| 350 | python.setupVirtualenv(vEnv, 'python2', [], "${templateEnvPatched}/requirements.txt") |
| 351 | common.infoMsg(python.runVirtualenvCommand(vEnv, "python ${templateEnvPatched}/workflow_definition_test.py")) |
| 352 | } |
| 353 | |
| 354 | stage("generate models") { |
| 355 | dir("${templateEnvHead}/contexts") { |
| 356 | for (String x : findFiles(glob: "*.yml")) { |
| 357 | contextFileListHead.add(x) |
| 358 | } |
| 359 | } |
| 360 | dir("${templateEnvPatched}/contexts") { |
| 361 | for (String x : findFiles(glob: "*.yml")) { |
| 362 | contextFileListPatched.add(x) |
| 363 | } |
| 364 | } |
| 365 | // Generate over 2env's - for patchset, and for HEAD |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 366 | def paralellEnvs = [:] |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 367 | paralellEnvs.failFast = true |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 368 | paralellEnvs['GenerateEnvPatched'] = StepGenerateModels(contextFileListPatched, vEnv, templateEnvPatched) |
| 369 | paralellEnvs['GenerateEnvHead'] = StepGenerateModels(contextFileListHead, vEnv, templateEnvHead) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 370 | parallel paralellEnvs |
| 371 | |
| 372 | // Collect artifacts |
| 373 | dir(templateEnvPatched) { |
| 374 | // Collect only models. For backward comparability - who know, probably someone use it.. |
| 375 | sh(script: "tar -czf model.tar.gz -C model ../contexts .", returnStatus: true) |
| 376 | archiveArtifacts artifacts: "model.tar.gz" |
| 377 | } |
| 378 | |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 379 | StepPrepareGit("${env.WORKSPACE}/global_reclass/", gerritDataRS).call() |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 380 | // link all models, to use one global reclass |
| 381 | // For HEAD |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 382 | linkReclassModels(contextFileListHead, templateEnvHead, headReclassArtifactName) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 383 | // For patched |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 384 | linkReclassModels(contextFileListPatched, templateEnvPatched, patchedReclassArtifactName) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 385 | } |
| 386 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 387 | stage("Compare cluster lvl Head/Patched") { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 388 | // Compare patched and HEAD reclass pillars |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 389 | compareRoot = "${env.WORKSPACE}/cluster_compare/" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 390 | sh(script: """ |
| 391 | mkdir -pv ${compareRoot}/new ${compareRoot}/old |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 392 | tar -xzf ${patchedReclassArtifactName} --directory ${compareRoot}/new |
| 393 | tar -xzf ${headReclassArtifactName} --directory ${compareRoot}/old |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 394 | """) |
| 395 | common.warningMsg('infra/secrets.yml has been skipped from compare!') |
azvyagintsev | b266ad2 | 2018-09-11 12:11:11 +0300 | [diff] [blame] | 396 | result = '\n' + common.comparePillars(compareRoot, env.BUILD_URL, "-Ev \'infra/secrets.yml\'") |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 397 | currentBuild.description = currentBuild.description ? currentBuild.description + result : result |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 398 | } |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 399 | stage("TestContexts Head/Patched") { |
| 400 | def stepsForParallel = [:] |
| 401 | stepsForParallel.failFast = true |
| 402 | common.infoMsg("Found: ${contextFileListHead.size()} HEAD contexts to test.") |
| 403 | for (String context : contextFileListHead) { |
| 404 | def basename = common.GetBaseName(context, '.yml') |
| 405 | stepsForParallel.put("ContextHeadTest:${basename}", StepTestModel(basename, headReclassArtifactName, reclassInfoHeadPath)) |
| 406 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 407 | common.infoMsg("Found: ${contextFileListPatched.size()} patched contexts to test.") |
| 408 | for (String context : contextFileListPatched) { |
| 409 | def basename = common.GetBaseName(context, '.yml') |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 410 | stepsForParallel.put("ContextPatchedTest:${basename}", StepTestModel(basename, patchedReclassArtifactName, reclassInfoPatchedPath)) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 411 | } |
| 412 | parallel stepsForParallel |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 413 | common.infoMsg('All TestContexts tests done') |
| 414 | } |
| 415 | stage("Compare NodesInfo Head/Patched") { |
| 416 | // Download all artifacts |
| 417 | def stepsForParallel = [:] |
| 418 | stepsForParallel.failFast = true |
| 419 | common.infoMsg("Found: ${testModelBuildsData.size()} nodeinfo artifacts to download.") |
| 420 | testModelBuildsData.each { bname, bdata -> |
| 421 | stepsForParallel.put("FetchData:${bname}", |
| 422 | getAndUnpackNodesInfoArtifact(bdata.jobname, bdata.copyToDir, bdata.buildId)) |
| 423 | } |
| 424 | parallel stepsForParallel |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 425 | // remove timestamp field from rendered files |
| 426 | sh("find ${reclassNodeInfoDir} -type f -exec sed -i '/ timestamp: .*/d' {} \\;") |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 427 | // Compare patched and HEAD reclass pillars |
| 428 | result = '\n' + common.comparePillars(reclassNodeInfoDir, env.BUILD_URL, '') |
| 429 | currentBuild.description = currentBuild.description ? currentBuild.description + result : result |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 430 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 431 | sh(script: 'find . -mindepth 1 -delete > /dev/null || true') |
| 432 | |
| 433 | } catch (Throwable e) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 434 | if (alreadyMerged) { |
| 435 | currentBuild.result = 'ABORTED' |
| 436 | currentBuild.description = "Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them" |
| 437 | return |
| 438 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 439 | currentBuild.result = "FAILURE" |
| 440 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 441 | throw e |
| 442 | } finally { |
| 443 | def dummy = "dummy" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 444 | } |
| 445 | } |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 446 | } |