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 | |
Alexander Evseev | 02fe5eb | 2018-11-15 13:58:36 +0100 | [diff] [blame^] | 15 | import groovy.json.JsonOutput |
| 16 | |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 17 | common = new com.mirantis.mk.Common() |
chnyda | bc63c9a | 2017-05-30 15:37:54 +0200 | [diff] [blame] | 18 | gerrit = new com.mirantis.mk.Gerrit() |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 19 | git = new com.mirantis.mk.Git() |
| 20 | python = new com.mirantis.mk.Python() |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 21 | |
Denis Egorenko | d67a6d2 | 2018-10-18 16:00:46 +0400 | [diff] [blame] | 22 | extraVarsYAML = env.EXTRA_VARIABLES_YAML.trim() ?: '' |
Denis Egorenko | 535d5b6 | 2018-09-28 11:28:10 +0400 | [diff] [blame] | 23 | if (extraVarsYAML) { |
| 24 | common.mergeEnv(env, extraVarsYAML) |
Alexander Evseev | 02fe5eb | 2018-11-15 13:58:36 +0100 | [diff] [blame^] | 25 | extraVars = readYaml text: extraVarsYAML |
| 26 | } else { |
| 27 | extraVars = [:] |
Denis Egorenko | 535d5b6 | 2018-09-28 11:28:10 +0400 | [diff] [blame] | 28 | } |
| 29 | |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 30 | slaveNode = env.SLAVE_NODE ?: 'docker' |
azvyagintsev | e7b8e79 | 2018-09-21 17:27:01 +0300 | [diff] [blame] | 31 | checkIncludeOrder = env.CHECK_INCLUDE_ORDER ?: false |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 32 | |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 33 | // Global var's |
| 34 | alreadyMerged = false |
| 35 | gerritConData = [credentialsId : env.CREDENTIALS_ID, |
| 36 | gerritName : env.GERRIT_NAME ?: 'mcp-jenkins', |
Roman Vyalov | f0c596e | 2018-10-01 17:56:09 +0300 | [diff] [blame] | 37 | gerritHost : env.GERRIT_HOST ?: 'gerrit.mcp.mirantis.com', |
azvyagintsev | b266ad2 | 2018-09-11 12:11:11 +0300 | [diff] [blame] | 38 | gerritScheme : env.GERRIT_SCHEME ?: 'ssh', |
| 39 | gerritPort : env.GERRIT_PORT ?: '29418', |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 40 | gerritRefSpec : null, |
| 41 | gerritProject : null, |
| 42 | withWipeOut : true, |
| 43 | GERRIT_CHANGE_NUMBER: null] |
| 44 | // |
Roman Vyalov | f0c596e | 2018-10-01 17:56:09 +0300 | [diff] [blame] | 45 | //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] | 46 | gerritDataCCHEAD = [:] |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 47 | gerritDataCC = [:] |
| 48 | gerritDataCC << gerritConData |
| 49 | gerritDataCC['gerritBranch'] = env.COOKIECUTTER_TEMPLATE_BRANCH ?: 'master' |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 50 | gerritDataCC['gerritRefSpec'] = env.COOKIECUTTER_TEMPLATE_REF ?: null |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 51 | gerritDataCC['gerritProject'] = 'mk/cookiecutter-templates' |
| 52 | // |
Roman Vyalov | f0c596e | 2018-10-01 17:56:09 +0300 | [diff] [blame] | 53 | //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] | 54 | gerritDataRSHEAD = [:] |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 55 | gerritDataRS = [:] |
| 56 | gerritDataRS << gerritConData |
Denis Egorenko | e7040ac | 2018-10-24 20:11:04 +0400 | [diff] [blame] | 57 | gerritDataRS['gerritBranch'] = env.RECLASS_SYSTEM_BRANCH ?: 'master' |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 58 | gerritDataRS['gerritRefSpec'] = env.RECLASS_SYSTEM_GIT_REF ?: null |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 59 | gerritDataRS['gerritProject'] = 'salt-models/reclass-system' |
| 60 | |
azvyagintsev | ec055b4 | 2018-10-11 12:59:05 +0300 | [diff] [blame] | 61 | // version of debRepos, aka formulas|reclass|ubuntu |
azvyagintsev | 10e2401 | 2018-09-10 21:36:32 +0300 | [diff] [blame] | 62 | testDistribRevision = env.DISTRIB_REVISION ?: 'nightly' |
Denis Egorenko | 086aff1 | 2018-10-18 17:54:59 +0400 | [diff] [blame] | 63 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 64 | // Name of sub-test chunk job |
| 65 | chunkJobName = "test-mk-cookiecutter-templates-chunk" |
| 66 | testModelBuildsData = [:] |
Vasyl Saienko | 772e123 | 2018-07-23 14:42:24 +0300 | [diff] [blame] | 67 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 68 | def getAndUnpackNodesInfoArtifact(jobName, copyTo, build) { |
| 69 | return { |
| 70 | dir(copyTo) { |
| 71 | copyArtifacts(projectName: jobName, selector: specific(build), filter: "nodesinfo.tar.gz") |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 72 | sh "tar -xf nodesinfo.tar.gz" |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 73 | sh "rm -v nodesinfo.tar.gz" |
| 74 | } |
| 75 | } |
| 76 | } |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 77 | |
Denis Egorenko | 086aff1 | 2018-10-18 17:54:59 +0400 | [diff] [blame] | 78 | def testModel(modelFile, reclassArtifactName, artifactCopyPath, useExtraRepos = false) { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 79 | // modelFile - `modelfiname` from model/modelfiname/modelfiname.yaml |
| 80 | //* 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] | 81 | def _uuid = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}_${modelFile.toLowerCase()}_" + UUID.randomUUID().toString().take(8) |
Alexander Evseev | 02fe5eb | 2018-11-15 13:58:36 +0100 | [diff] [blame^] | 82 | def _values = [ |
| 83 | MODELS_TARGZ: "${env.BUILD_URL}/artifact/${reclassArtifactName}", |
| 84 | DockerCName: _uuid, |
| 85 | testReclassEnv: "model/${modelFile}/", |
| 86 | modelFile: "contexts/${modelFile}.yml", |
| 87 | DISTRIB_REVISION: testDistribRevision, |
| 88 | useExtraRepos: useExtraRepos, |
| 89 | ] |
| 90 | def _values_string = JsonOutput.toJson(_values << extraVars) |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 91 | def chunkJob = build job: chunkJobName, parameters: [ |
azvyagintsev | 08b34e3 | 2018-09-12 12:29:42 +0300 | [diff] [blame] | 92 | [$class: 'TextParameterValue', name: 'EXTRA_VARIABLES_YAML', |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 93 | value : _values_string.stripIndent()], |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 94 | ] |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 95 | // Put sub-job info into global map. |
| 96 | testModelBuildsData.put(_uuid, ['jobname' : chunkJob.fullProjectName, |
| 97 | 'copyToDir': "${artifactCopyPath}/${modelFile}", |
| 98 | 'buildId' : "${chunkJob.number}"]) |
chnyda | bc63c9a | 2017-05-30 15:37:54 +0200 | [diff] [blame] | 99 | } |
| 100 | |
Denis Egorenko | 086aff1 | 2018-10-18 17:54:59 +0400 | [diff] [blame] | 101 | def StepTestModel(basename, reclassArtifactName, artifactCopyPath, useExtraRepos = false) { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 102 | // We need to wrap what we return in a Groovy closure, or else it's invoked |
| 103 | // when this method is called, not when we pass it to parallel. |
| 104 | // To do this, you need to wrap the code below in { }, and either return |
| 105 | // that explicitly, or use { -> } syntax. |
| 106 | // return node object |
| 107 | return { |
| 108 | node(slaveNode) { |
Denis Egorenko | 086aff1 | 2018-10-18 17:54:59 +0400 | [diff] [blame] | 109 | testModel(basename, reclassArtifactName, artifactCopyPath, useExtraRepos) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 110 | } |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 111 | } |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 112 | } |
| 113 | |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 114 | def StepPrepareGit(templateEnvFolder, gerrit_data) { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 115 | // return git clone object |
| 116 | return { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 117 | def checkouted = false |
| 118 | common.infoMsg("StepPrepareGit: ${gerrit_data}") |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 119 | // fetch needed sources |
| 120 | dir(templateEnvFolder) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 121 | if (gerrit_data['gerritRefSpec']) { |
| 122 | // Those part might be not work,in case manual var's pass |
| 123 | def gerritChange = gerrit.getGerritChange(gerrit_data['gerritName'], gerrit_data['gerritHost'], |
| 124 | gerrit_data['GERRIT_CHANGE_NUMBER'], gerrit_data['credentialsId']) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 125 | merged = gerritChange.status == "MERGED" |
| 126 | if (!merged) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 127 | checkouted = gerrit.gerritPatchsetCheckout(gerrit_data) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 128 | } else { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 129 | // update global variable for pretty return from pipeline |
| 130 | alreadyMerged = true |
| 131 | common.successMsg("Change ${gerrit_data['GERRIT_CHANGE_NUMBER']} is already merged, no need to gate them") |
| 132 | error('change already merged') |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 133 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 134 | } else { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 135 | // Get clean HEAD |
| 136 | gerrit_data['useGerritTriggerBuildChooser'] = false |
| 137 | checkouted = gerrit.gerritPatchsetCheckout(gerrit_data) |
| 138 | if (!checkouted) { |
| 139 | error("Failed to get repo:${gerrit_data}") |
| 140 | } |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 141 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 142 | } |
azvyagintsev | 8798553 | 2018-07-10 20:49:38 +0300 | [diff] [blame] | 143 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | def StepGenerateModels(_contextFileList, _virtualenv, _templateEnvDir) { |
| 147 | return { |
| 148 | for (contextFile in _contextFileList) { |
Denis Egorenko | f346909 | 2018-10-17 17:05:50 +0400 | [diff] [blame] | 149 | def basename = common.GetBaseName(contextFile, '.yml') |
| 150 | def context = readFile(file: "${_templateEnvDir}/contexts/${contextFile}") |
| 151 | python.generateModel(context, basename, 'cfg01', _virtualenv, "${_templateEnvDir}/model", _templateEnvDir) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 156 | def globalVariatorsUpdate() { |
| 157 | // Simple function, to check and define branch-around variables |
| 158 | // In general, simply make transition updates for non-master branch |
| 159 | // based on magic logic |
Denis Egorenko | fe9a336 | 2018-10-17 15:33:25 +0400 | [diff] [blame] | 160 | def newline = '<br/>' |
| 161 | def messages = [] |
azvyagintsev | b266ad2 | 2018-09-11 12:11:11 +0300 | [diff] [blame] | 162 | if (env.GERRIT_PROJECT) { |
Denis Egorenko | fe9a336 | 2018-10-17 15:33:25 +0400 | [diff] [blame] | 163 | messages.add("<font color='red'>GerritTrigger detected! We are in auto-mode:</font>") |
| 164 | messages.add("Test env variables has been changed:") |
azvyagintsev | e0eb6cd | 2018-09-12 13:00:40 +0300 | [diff] [blame] | 165 | // TODO are we going to have such branches? |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 166 | if (!['nightly', 'testing', 'stable', 'proposed', 'master'].contains(env.GERRIT_BRANCH)) { |
| 167 | gerritDataCC['gerritBranch'] = env.GERRIT_BRANCH |
| 168 | gerritDataRS['gerritBranch'] = env.GERRIT_BRANCH |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 169 | testDistribRevision = env.GERRIT_BRANCH |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 170 | } |
Denis Egorenko | 60e45c1 | 2018-11-12 12:00:11 +0400 | [diff] [blame] | 171 | messages.add("COOKIECUTTER_TEMPLATE_BRANCH => ${gerritDataCC['gerritBranch']}") |
| 172 | messages.add("RECLASS_SYSTEM_BRANCH => ${gerritDataRS['gerritBranch']}") |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 173 | // Identify, who triggered. To whom we should pass refspec |
| 174 | if (env.GERRIT_PROJECT == 'salt-models/reclass-system') { |
| 175 | gerritDataRS['gerritRefSpec'] = env.GERRIT_REFSPEC |
| 176 | gerritDataRS['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER |
Denis Egorenko | fe9a336 | 2018-10-17 15:33:25 +0400 | [diff] [blame] | 177 | messages.add("RECLASS_SYSTEM_GIT_REF => ${gerritDataRS['gerritRefSpec']}") |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 178 | } else if (env.GERRIT_PROJECT == 'mk/cookiecutter-templates') { |
| 179 | gerritDataCC['gerritRefSpec'] = env.GERRIT_REFSPEC |
| 180 | gerritDataCC['GERRIT_CHANGE_NUMBER'] = env.GERRIT_CHANGE_NUMBER |
Denis Egorenko | fe9a336 | 2018-10-17 15:33:25 +0400 | [diff] [blame] | 181 | messages.add("COOKIECUTTER_TEMPLATE_REF => ${gerritDataCC['gerritRefSpec']}") |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 182 | } else { |
| 183 | error("Unsuported gerrit-project triggered:${env.GERRIT_PROJECT}") |
| 184 | } |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 185 | } else { |
Denis Egorenko | fe9a336 | 2018-10-17 15:33:25 +0400 | [diff] [blame] | 186 | messages.add("<font color='red'>Non-gerrit trigger run detected!</font>") |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 187 | } |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 188 | gerritDataCCHEAD << gerritDataCC |
| 189 | gerritDataCCHEAD['gerritRefSpec'] = null |
| 190 | gerritDataCCHEAD['GERRIT_CHANGE_NUMBER'] = null |
| 191 | gerritDataRSHEAD << gerritDataRS |
| 192 | gerritDataRSHEAD['gerritRefSpec'] = null |
| 193 | gerritDataRSHEAD['GERRIT_CHANGE_NUMBER'] = null |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 194 | // 'binary' branch logic w\o 'release/' prefix |
| 195 | if (testDistribRevision.contains('/')) { |
| 196 | testDistribRevision = testDistribRevision.split('/')[-1] |
| 197 | } |
| 198 | // Check if we are going to test bleeding-edge release, which doesn't have binary release yet |
| 199 | if (!common.checkRemoteBinary([apt_mk_version: testDistribRevision]).linux_system_repo_url) { |
| 200 | common.errorMsg("Binary release: ${testDistribRevision} not exist. Fallback to 'proposed'! ") |
| 201 | testDistribRevision = 'proposed' |
Denis Egorenko | fe9a336 | 2018-10-17 15:33:25 +0400 | [diff] [blame] | 202 | messages.add("DISTRIB_REVISION => ${testDistribRevision}") |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 203 | } |
Denis Egorenko | fe9a336 | 2018-10-17 15:33:25 +0400 | [diff] [blame] | 204 | def message = messages.join(newline) + newline |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 205 | currentBuild.description = currentBuild.description ? message + currentBuild.description : message |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 206 | } |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 207 | |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 208 | def replaceGeneratedValues(path) { |
| 209 | def files = sh(script: "find ${path} -name 'secrets.yml'", returnStdout: true) |
| 210 | def stepsForParallel = [:] |
| 211 | stepsForParallel.failFast = true |
| 212 | files.tokenize().each { |
| 213 | stepsForParallel.put("Removing generated passwords/secrets from ${it}", |
| 214 | { |
| 215 | def secrets = readYaml file: it |
azvyagintsev | 08b34e3 | 2018-09-12 12:29:42 +0300 | [diff] [blame] | 216 | for (String key in secrets['parameters']['_param'].keySet()) { |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 217 | secrets['parameters']['_param'][key] = 'generated' |
| 218 | } |
| 219 | // writeYaml can't write to already existing file |
| 220 | writeYaml file: "${it}.tmp", data: secrets |
| 221 | sh "mv ${it}.tmp ${it}" |
| 222 | }) |
| 223 | } |
| 224 | parallel stepsForParallel |
| 225 | } |
| 226 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 227 | def linkReclassModels(contextList, envPath, archiveName) { |
| 228 | // to be able share reclass for all subenvs |
| 229 | // Also, makes artifact test more solid - use one reclass for all of sub-models. |
| 230 | // Archive Structure will be: |
| 231 | // tar.gz |
| 232 | // ├── contexts |
| 233 | // │  └── ceph.yml |
Denis Egorenko | 7aa5ac5 | 2018-10-17 15:14:56 +0400 | [diff] [blame] | 234 | // ├── classes-system <<< reclass system |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 235 | // ├── model |
| 236 | // │  └── ceph <<< from `context basename` |
| 237 | // │  ├── classes |
| 238 | // │  │  ├── cluster |
Denis Egorenko | 7aa5ac5 | 2018-10-17 15:14:56 +0400 | [diff] [blame] | 239 | // │  │  └── system -> ../../../classes-system |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 240 | // │  └── nodes |
| 241 | // │  └── cfg01.ceph-cluster-domain.local.yml |
Denis Egorenko | 7aa5ac5 | 2018-10-17 15:14:56 +0400 | [diff] [blame] | 242 | def archiveBaseName = common.GetBaseName(archiveName, '.tar.gz') |
| 243 | def classesSystemDir = 'classes-system' |
| 244 | // copy reclass system under envPath with -R and trailing / to support symlinks direct copy |
| 245 | sh("cp -R ${archiveBaseName}/ ${envPath}/${classesSystemDir}") |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 246 | dir(envPath) { |
| 247 | for (String context : contextList) { |
| 248 | def basename = common.GetBaseName(context, '.yml') |
Denis Egorenko | 7aa5ac5 | 2018-10-17 15:14:56 +0400 | [diff] [blame] | 249 | dir("${envPath}/model/${basename}/classes") { |
| 250 | sh(script: "ln -sfv ../../../${classesSystemDir} system ") |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 251 | } |
| 252 | } |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 253 | // replace all generated passwords/secrets/keys with hardcode value for infra/secrets.yaml |
| 254 | replaceGeneratedValues("${envPath}/model") |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 255 | // Save all models and all contexts. Warning! `h` flag must be used! |
Denis Egorenko | 7aa5ac5 | 2018-10-17 15:14:56 +0400 | [diff] [blame] | 256 | sh(script: "set -ex; tar -czhf ${env.WORKSPACE}/${archiveName} --exclude='*@tmp' contexts model ${classesSystemDir}", returnStatus: true) |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 257 | } |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 258 | archiveArtifacts artifacts: archiveName |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 259 | } |
| 260 | |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 261 | timeout(time: 1, unit: 'HOURS') { |
| 262 | node(slaveNode) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 263 | globalVariatorsUpdate() |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 264 | def templateEnvHead = "${env.WORKSPACE}/EnvHead/" |
| 265 | def templateEnvPatched = "${env.WORKSPACE}/EnvPatched/" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 266 | def contextFileListHead = [] |
| 267 | def contextFileListPatched = [] |
| 268 | def vEnv = "${env.WORKSPACE}/venv" |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 269 | def headReclassArtifactName = "head_reclass.tar.gz" |
| 270 | def patchedReclassArtifactName = "patched_reclass.tar.gz" |
| 271 | def reclassNodeInfoDir = "${env.WORKSPACE}/reclassNodeInfo_compare/" |
| 272 | def reclassInfoHeadPath = "${reclassNodeInfoDir}/old" |
| 273 | def reclassInfoPatchedPath = "${reclassNodeInfoDir}/new" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 274 | try { |
| 275 | sh(script: 'find . -mindepth 1 -delete > /dev/null || true') |
| 276 | stage('Download and prepare CC env') { |
| 277 | // Prepare 2 env - for patchset, and for HEAD |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 278 | def paralellEnvs = [:] |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 279 | paralellEnvs.failFast = true |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 280 | paralellEnvs['downloadEnvHead'] = StepPrepareGit(templateEnvHead, gerritDataCCHEAD) |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 281 | if (gerritDataCC.get('gerritRefSpec', null)) { |
| 282 | paralellEnvs['downloadEnvPatched'] = StepPrepareGit(templateEnvPatched, gerritDataCC) |
| 283 | parallel paralellEnvs |
| 284 | } else { |
| 285 | paralellEnvs['downloadEnvPatched'] = { common.warningMsg('No need to process: downloadEnvPatched') } |
| 286 | parallel paralellEnvs |
| 287 | sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}") |
| 288 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 289 | } |
| 290 | stage("Check workflow_definition") { |
| 291 | // Check only for patchset |
| 292 | python.setupVirtualenv(vEnv, 'python2', [], "${templateEnvPatched}/requirements.txt") |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 293 | if (gerritDataCC.get('gerritRefSpec', null)) { |
| 294 | common.infoMsg(python.runVirtualenvCommand(vEnv, "python ${templateEnvPatched}/workflow_definition_test.py")) |
| 295 | } else { |
| 296 | common.infoMsg('No need to process: workflow_definition') |
| 297 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | stage("generate models") { |
| 301 | dir("${templateEnvHead}/contexts") { |
| 302 | for (String x : findFiles(glob: "*.yml")) { |
| 303 | contextFileListHead.add(x) |
| 304 | } |
| 305 | } |
| 306 | dir("${templateEnvPatched}/contexts") { |
| 307 | for (String x : findFiles(glob: "*.yml")) { |
| 308 | contextFileListPatched.add(x) |
| 309 | } |
| 310 | } |
| 311 | // Generate over 2env's - for patchset, and for HEAD |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 312 | def paralellEnvs = [:] |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 313 | paralellEnvs.failFast = true |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 314 | paralellEnvs['GenerateEnvHead'] = StepGenerateModels(contextFileListHead, vEnv, templateEnvHead) |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 315 | if (gerritDataCC.get('gerritRefSpec', null)) { |
| 316 | paralellEnvs['GenerateEnvPatched'] = StepGenerateModels(contextFileListPatched, vEnv, templateEnvPatched) |
| 317 | parallel paralellEnvs |
| 318 | } else { |
| 319 | paralellEnvs['GenerateEnvPatched'] = { common.warningMsg('No need to process: GenerateEnvPatched') } |
| 320 | parallel paralellEnvs |
| 321 | sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}") |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 322 | } |
| 323 | |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 324 | // We need 2 git's, one for HEAD, one for PATCHed. |
| 325 | // if no patch, use head for both |
| 326 | RSHeadDir = common.GetBaseName(headReclassArtifactName, '.tar.gz') |
| 327 | RSPatchedDir = common.GetBaseName(patchedReclassArtifactName, '.tar.gz') |
| 328 | common.infoMsg("gerritDataRS= ${gerritDataRS}") |
| 329 | common.infoMsg("gerritDataRSHEAD= ${gerritDataRSHEAD}") |
| 330 | if (gerritDataRS.get('gerritRefSpec', null)) { |
| 331 | StepPrepareGit("${env.WORKSPACE}/${RSPatchedDir}/", gerritDataRS).call() |
| 332 | StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRSHEAD).call() |
| 333 | } else { |
| 334 | StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRS).call() |
| 335 | sh("cd ${env.WORKSPACE} ; ln -svf ${RSHeadDir} ${RSPatchedDir}") |
| 336 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 337 | // link all models, to use one global reclass |
| 338 | // For HEAD |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 339 | linkReclassModels(contextFileListHead, templateEnvHead, headReclassArtifactName) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 340 | // For patched |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 341 | linkReclassModels(contextFileListPatched, templateEnvPatched, patchedReclassArtifactName) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 342 | } |
| 343 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 344 | stage("Compare cluster lvl Head/Patched") { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 345 | // Compare patched and HEAD reclass pillars |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 346 | compareRoot = "${env.WORKSPACE}/cluster_compare/" |
Denis Egorenko | 7aa5ac5 | 2018-10-17 15:14:56 +0400 | [diff] [blame] | 347 | // extract archive and drop all copied classes/system before comparing |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 348 | sh(script: """ |
| 349 | mkdir -pv ${compareRoot}/new ${compareRoot}/old |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 350 | tar -xzf ${patchedReclassArtifactName} --directory ${compareRoot}/new |
| 351 | tar -xzf ${headReclassArtifactName} --directory ${compareRoot}/old |
Denis Egorenko | 7aa5ac5 | 2018-10-17 15:14:56 +0400 | [diff] [blame] | 352 | find ${compareRoot} -name classes -type d -exec rm -rf '{}/system' \\; |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 353 | """) |
| 354 | common.warningMsg('infra/secrets.yml has been skipped from compare!') |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 355 | 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] | 356 | currentBuild.description = currentBuild.description ? currentBuild.description + result : result |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 357 | } |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 358 | stage("TestContexts Head/Patched") { |
| 359 | def stepsForParallel = [:] |
| 360 | stepsForParallel.failFast = true |
| 361 | common.infoMsg("Found: ${contextFileListHead.size()} HEAD contexts to test.") |
| 362 | for (String context : contextFileListHead) { |
| 363 | def basename = common.GetBaseName(context, '.yml') |
| 364 | stepsForParallel.put("ContextHeadTest:${basename}", StepTestModel(basename, headReclassArtifactName, reclassInfoHeadPath)) |
| 365 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 366 | common.infoMsg("Found: ${contextFileListPatched.size()} patched contexts to test.") |
| 367 | for (String context : contextFileListPatched) { |
| 368 | def basename = common.GetBaseName(context, '.yml') |
Denis Egorenko | 086aff1 | 2018-10-18 17:54:59 +0400 | [diff] [blame] | 369 | stepsForParallel.put("ContextPatchedTest:${basename}", StepTestModel(basename, patchedReclassArtifactName, reclassInfoPatchedPath, true)) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 370 | } |
| 371 | parallel stepsForParallel |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 372 | common.infoMsg('All TestContexts tests done') |
| 373 | } |
| 374 | stage("Compare NodesInfo Head/Patched") { |
| 375 | // Download all artifacts |
| 376 | def stepsForParallel = [:] |
| 377 | stepsForParallel.failFast = true |
| 378 | common.infoMsg("Found: ${testModelBuildsData.size()} nodeinfo artifacts to download.") |
| 379 | testModelBuildsData.each { bname, bdata -> |
| 380 | stepsForParallel.put("FetchData:${bname}", |
| 381 | getAndUnpackNodesInfoArtifact(bdata.jobname, bdata.copyToDir, bdata.buildId)) |
| 382 | } |
| 383 | parallel stepsForParallel |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 384 | // remove timestamp field from rendered files |
| 385 | sh("find ${reclassNodeInfoDir} -type f -exec sed -i '/ timestamp: .*/d' {} \\;") |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 386 | // Compare patched and HEAD reclass pillars |
| 387 | result = '\n' + common.comparePillars(reclassNodeInfoDir, env.BUILD_URL, '') |
| 388 | currentBuild.description = currentBuild.description ? currentBuild.description + result : result |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 389 | } |
Denis Egorenko | 04ca9f2 | 2018-09-19 16:06:49 +0400 | [diff] [blame] | 390 | stage('Check include order') { |
azvyagintsev | e7b8e79 | 2018-09-21 17:27:01 +0300 | [diff] [blame] | 391 | if (!checkIncludeOrder) { |
| 392 | common.infoMsg('Check include order require to much time, and currently disabled!') |
| 393 | |
| 394 | } else { |
| 395 | def correctIncludeOrder = ["service", "system", "cluster"] |
| 396 | dir(reclassInfoPatchedPath) { |
| 397 | def nodeInfoFiles = findFiles(glob: "**/*.reclass.nodeinfo") |
| 398 | def messages = ["<b>Wrong include ordering found</b><ul>"] |
| 399 | def stepsForParallel = [:] |
| 400 | nodeInfoFiles.each { nodeInfo -> |
| 401 | stepsForParallel.put("Checking ${nodeInfo.path}:", { |
| 402 | def node = readYaml file: nodeInfo.path |
| 403 | def classes = node['classes'] |
| 404 | def curClassID = 0 |
| 405 | def prevClassID = 0 |
| 406 | def wrongOrder = false |
| 407 | for (String className in classes) { |
| 408 | def currentClass = className.tokenize('.')[0] |
| 409 | curClassID = correctIncludeOrder.indexOf(currentClass) |
| 410 | if (currentClass != correctIncludeOrder[prevClassID]) { |
| 411 | if (prevClassID > curClassID) { |
| 412 | wrongOrder = true |
| 413 | common.warningMsg("File ${nodeInfo.path} contains wrong order of classes including: Includes for ${className} should be declared before ${correctIncludeOrder[prevClassID]} includes") |
| 414 | } else { |
| 415 | prevClassID = curClassID |
| 416 | } |
Denis Egorenko | 04ca9f2 | 2018-09-19 16:06:49 +0400 | [diff] [blame] | 417 | } |
| 418 | } |
azvyagintsev | e7b8e79 | 2018-09-21 17:27:01 +0300 | [diff] [blame] | 419 | if (wrongOrder) { |
| 420 | messages.add("<li>${nodeInfo.path} contains wrong order of classes including</li>") |
| 421 | } |
| 422 | }) |
| 423 | } |
| 424 | parallel stepsForParallel |
| 425 | def includerOrder = '<b>No wrong include order</b>' |
| 426 | if (messages.size() != 1) { |
| 427 | includerOrder = messages.join('') |
| 428 | } |
| 429 | currentBuild.description = currentBuild.description ? currentBuild.description + includerOrder : includerOrder |
Denis Egorenko | 04ca9f2 | 2018-09-19 16:06:49 +0400 | [diff] [blame] | 430 | } |
Denis Egorenko | 04ca9f2 | 2018-09-19 16:06:49 +0400 | [diff] [blame] | 431 | } |
| 432 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 433 | sh(script: 'find . -mindepth 1 -delete > /dev/null || true') |
| 434 | |
| 435 | } catch (Throwable e) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 436 | if (alreadyMerged) { |
| 437 | currentBuild.result = 'ABORTED' |
| 438 | currentBuild.description = "Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them" |
| 439 | return |
| 440 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 441 | currentBuild.result = "FAILURE" |
| 442 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 443 | throw e |
| 444 | } finally { |
| 445 | def dummy = "dummy" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 446 | } |
| 447 | } |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 448 | } |