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 | |
Kirill Mashchenko | 3dec082 | 2018-12-12 20:01:51 +0400 | [diff] [blame] | 30 | slaveNode = env.SLAVE_NODE ?: 'virtual' |
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 = [ |
azvyagintsev | 4220bff | 2019-01-09 21:32:11 +0200 | [diff] [blame] | 83 | MODELS_TARGZ : "${env.BUILD_URL}/artifact/${reclassArtifactName}", |
| 84 | DockerCName : _uuid, |
| 85 | testReclassEnv : "model/${modelFile}/", |
| 86 | modelFile : "contexts/${modelFile}.yml", |
Alexander Evseev | 02fe5eb | 2018-11-15 13:58:36 +0100 | [diff] [blame] | 87 | DISTRIB_REVISION: testDistribRevision, |
azvyagintsev | 4220bff | 2019-01-09 21:32:11 +0200 | [diff] [blame] | 88 | useExtraRepos : useExtraRepos, |
Alexander Evseev | 02fe5eb | 2018-11-15 13:58:36 +0100 | [diff] [blame] | 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 |
azvyagintsev | 5c200e7 | 2018-12-28 15:58:09 +0200 | [diff] [blame] | 199 | // After 2018q4 releases, need to also check 'static' repo, for example ubuntu. |
azvyagintsev | 4220bff | 2019-01-09 21:32:11 +0200 | [diff] [blame] | 200 | binTest = common.checkRemoteBinary(['mcp_version': testDistribRevision]) |
azvyagintsev | 5c200e7 | 2018-12-28 15:58:09 +0200 | [diff] [blame] | 201 | if (!binTest.linux_system_repo_url || !binTest.linux_system_repo_ubuntu_url) { |
| 202 | common.errorMsg("Binary release: ${testDistribRevision} not exist or not full. Fallback to 'proposed'! ") |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 203 | testDistribRevision = 'proposed' |
Denis Egorenko | fe9a336 | 2018-10-17 15:33:25 +0400 | [diff] [blame] | 204 | messages.add("DISTRIB_REVISION => ${testDistribRevision}") |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 205 | } |
Denis Egorenko | fe9a336 | 2018-10-17 15:33:25 +0400 | [diff] [blame] | 206 | def message = messages.join(newline) + newline |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 207 | currentBuild.description = currentBuild.description ? message + currentBuild.description : message |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 208 | } |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 209 | |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 210 | def replaceGeneratedValues(path) { |
| 211 | def files = sh(script: "find ${path} -name 'secrets.yml'", returnStdout: true) |
| 212 | def stepsForParallel = [:] |
| 213 | stepsForParallel.failFast = true |
| 214 | files.tokenize().each { |
| 215 | stepsForParallel.put("Removing generated passwords/secrets from ${it}", |
| 216 | { |
| 217 | def secrets = readYaml file: it |
azvyagintsev | 08b34e3 | 2018-09-12 12:29:42 +0300 | [diff] [blame] | 218 | for (String key in secrets['parameters']['_param'].keySet()) { |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 219 | secrets['parameters']['_param'][key] = 'generated' |
| 220 | } |
| 221 | // writeYaml can't write to already existing file |
| 222 | writeYaml file: "${it}.tmp", data: secrets |
| 223 | sh "mv ${it}.tmp ${it}" |
| 224 | }) |
| 225 | } |
| 226 | parallel stepsForParallel |
| 227 | } |
| 228 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 229 | def linkReclassModels(contextList, envPath, archiveName) { |
| 230 | // to be able share reclass for all subenvs |
| 231 | // Also, makes artifact test more solid - use one reclass for all of sub-models. |
| 232 | // Archive Structure will be: |
| 233 | // tar.gz |
| 234 | // ├── contexts |
| 235 | // │  └── ceph.yml |
Denis Egorenko | 7aa5ac5 | 2018-10-17 15:14:56 +0400 | [diff] [blame] | 236 | // ├── classes-system <<< reclass system |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 237 | // ├── model |
| 238 | // │  └── ceph <<< from `context basename` |
| 239 | // │  ├── classes |
| 240 | // │  │  ├── cluster |
Denis Egorenko | 7aa5ac5 | 2018-10-17 15:14:56 +0400 | [diff] [blame] | 241 | // │  │  └── system -> ../../../classes-system |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 242 | // │  └── nodes |
| 243 | // │  └── cfg01.ceph-cluster-domain.local.yml |
Denis Egorenko | 7aa5ac5 | 2018-10-17 15:14:56 +0400 | [diff] [blame] | 244 | def archiveBaseName = common.GetBaseName(archiveName, '.tar.gz') |
| 245 | def classesSystemDir = 'classes-system' |
| 246 | // copy reclass system under envPath with -R and trailing / to support symlinks direct copy |
| 247 | sh("cp -R ${archiveBaseName}/ ${envPath}/${classesSystemDir}") |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 248 | dir(envPath) { |
| 249 | for (String context : contextList) { |
| 250 | def basename = common.GetBaseName(context, '.yml') |
Denis Egorenko | 7aa5ac5 | 2018-10-17 15:14:56 +0400 | [diff] [blame] | 251 | dir("${envPath}/model/${basename}/classes") { |
| 252 | sh(script: "ln -sfv ../../../${classesSystemDir} system ") |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 253 | } |
| 254 | } |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 255 | // replace all generated passwords/secrets/keys with hardcode value for infra/secrets.yaml |
| 256 | replaceGeneratedValues("${envPath}/model") |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 257 | // Save all models and all contexts. Warning! `h` flag must be used! |
Denis Egorenko | 7aa5ac5 | 2018-10-17 15:14:56 +0400 | [diff] [blame] | 258 | 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] | 259 | } |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 260 | archiveArtifacts artifacts: archiveName |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 261 | } |
| 262 | |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 263 | timeout(time: 1, unit: 'HOURS') { |
| 264 | node(slaveNode) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 265 | globalVariatorsUpdate() |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 266 | def templateEnvHead = "${env.WORKSPACE}/EnvHead/" |
| 267 | def templateEnvPatched = "${env.WORKSPACE}/EnvPatched/" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 268 | def contextFileListHead = [] |
| 269 | def contextFileListPatched = [] |
| 270 | def vEnv = "${env.WORKSPACE}/venv" |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 271 | def headReclassArtifactName = "head_reclass.tar.gz" |
| 272 | def patchedReclassArtifactName = "patched_reclass.tar.gz" |
| 273 | def reclassNodeInfoDir = "${env.WORKSPACE}/reclassNodeInfo_compare/" |
| 274 | def reclassInfoHeadPath = "${reclassNodeInfoDir}/old" |
| 275 | def reclassInfoPatchedPath = "${reclassNodeInfoDir}/new" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 276 | try { |
| 277 | sh(script: 'find . -mindepth 1 -delete > /dev/null || true') |
| 278 | stage('Download and prepare CC env') { |
| 279 | // Prepare 2 env - for patchset, and for HEAD |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 280 | def paralellEnvs = [:] |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 281 | paralellEnvs.failFast = true |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 282 | paralellEnvs['downloadEnvHead'] = StepPrepareGit(templateEnvHead, gerritDataCCHEAD) |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 283 | if (gerritDataCC.get('gerritRefSpec', null)) { |
| 284 | paralellEnvs['downloadEnvPatched'] = StepPrepareGit(templateEnvPatched, gerritDataCC) |
| 285 | parallel paralellEnvs |
| 286 | } else { |
| 287 | paralellEnvs['downloadEnvPatched'] = { common.warningMsg('No need to process: downloadEnvPatched') } |
| 288 | parallel paralellEnvs |
| 289 | sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}") |
| 290 | } |
Denis Egorenko | 3de070c | 2018-11-20 13:57:35 +0400 | [diff] [blame] | 291 | if (env.CUSTOM_COOKIECUTTER_CONTEXT) { |
| 292 | // readYaml to check custom context structure |
| 293 | def customContext = readYaml text: env.CUSTOM_COOKIECUTTER_CONTEXT |
| 294 | writeYaml file: "${templateEnvHead}/contexts/custom_context.yml", data: customContext |
| 295 | writeYaml file: "${templateEnvPatched}/contexts/custom_context.yml", data: customContext |
| 296 | common.infoMsg("Using custom context provided from job parameter 'CUSTOM_COOKIECUTTER_CONTEXT'") |
| 297 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 298 | } |
| 299 | stage("Check workflow_definition") { |
| 300 | // Check only for patchset |
azvyagintsev | 1037fb4 | 2019-01-10 13:52:38 +0200 | [diff] [blame^] | 301 | if (fileExists(new File(templateEnvPatched, 'tox.ini').toString())) { |
| 302 | dir(templateEnvPatched) { |
| 303 | output = sh(returnStdout: true, script: "tox -ve test") |
| 304 | common.infoMsg("[Cookiecutter test] Result: ${output}") |
azvyagintsev | 4220bff | 2019-01-09 21:32:11 +0200 | [diff] [blame] | 305 | } |
azvyagintsev | 1037fb4 | 2019-01-10 13:52:38 +0200 | [diff] [blame^] | 306 | |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 307 | } else { |
azvyagintsev | 1037fb4 | 2019-01-10 13:52:38 +0200 | [diff] [blame^] | 308 | common.warningMsg('Old Cookiecutter env detected!') |
| 309 | python.setupVirtualenv(vEnv, 'python2', [], "${templateEnvPatched}/requirements.txt") |
| 310 | common.infoMsg(python.runVirtualenvCommand(vEnv, "python ${templateEnvPatched}/workflow_definition_test.py")) |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 311 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | stage("generate models") { |
| 315 | dir("${templateEnvHead}/contexts") { |
| 316 | for (String x : findFiles(glob: "*.yml")) { |
| 317 | contextFileListHead.add(x) |
| 318 | } |
| 319 | } |
| 320 | dir("${templateEnvPatched}/contexts") { |
| 321 | for (String x : findFiles(glob: "*.yml")) { |
| 322 | contextFileListPatched.add(x) |
| 323 | } |
| 324 | } |
| 325 | // Generate over 2env's - for patchset, and for HEAD |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 326 | def paralellEnvs = [:] |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 327 | paralellEnvs.failFast = true |
azvyagintsev | 30bc82e | 2018-08-22 12:26:06 +0300 | [diff] [blame] | 328 | paralellEnvs['GenerateEnvHead'] = StepGenerateModels(contextFileListHead, vEnv, templateEnvHead) |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 329 | if (gerritDataCC.get('gerritRefSpec', null)) { |
| 330 | paralellEnvs['GenerateEnvPatched'] = StepGenerateModels(contextFileListPatched, vEnv, templateEnvPatched) |
| 331 | parallel paralellEnvs |
| 332 | } else { |
| 333 | paralellEnvs['GenerateEnvPatched'] = { common.warningMsg('No need to process: GenerateEnvPatched') } |
| 334 | parallel paralellEnvs |
| 335 | sh("rsync -a --exclude '*@tmp' ${templateEnvHead} ${templateEnvPatched}") |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 336 | } |
| 337 | |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 338 | // We need 2 git's, one for HEAD, one for PATCHed. |
| 339 | // if no patch, use head for both |
| 340 | RSHeadDir = common.GetBaseName(headReclassArtifactName, '.tar.gz') |
| 341 | RSPatchedDir = common.GetBaseName(patchedReclassArtifactName, '.tar.gz') |
| 342 | common.infoMsg("gerritDataRS= ${gerritDataRS}") |
| 343 | common.infoMsg("gerritDataRSHEAD= ${gerritDataRSHEAD}") |
| 344 | if (gerritDataRS.get('gerritRefSpec', null)) { |
| 345 | StepPrepareGit("${env.WORKSPACE}/${RSPatchedDir}/", gerritDataRS).call() |
| 346 | StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRSHEAD).call() |
| 347 | } else { |
| 348 | StepPrepareGit("${env.WORKSPACE}/${RSHeadDir}/", gerritDataRS).call() |
| 349 | sh("cd ${env.WORKSPACE} ; ln -svf ${RSHeadDir} ${RSPatchedDir}") |
| 350 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 351 | // link all models, to use one global reclass |
| 352 | // For HEAD |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 353 | linkReclassModels(contextFileListHead, templateEnvHead, headReclassArtifactName) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 354 | // For patched |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 355 | linkReclassModels(contextFileListPatched, templateEnvPatched, patchedReclassArtifactName) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 356 | } |
| 357 | |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 358 | stage("Compare cluster lvl Head/Patched") { |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 359 | // Compare patched and HEAD reclass pillars |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 360 | compareRoot = "${env.WORKSPACE}/cluster_compare/" |
Denis Egorenko | 7aa5ac5 | 2018-10-17 15:14:56 +0400 | [diff] [blame] | 361 | // extract archive and drop all copied classes/system before comparing |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 362 | sh(script: """ |
| 363 | mkdir -pv ${compareRoot}/new ${compareRoot}/old |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 364 | tar -xzf ${patchedReclassArtifactName} --directory ${compareRoot}/new |
| 365 | tar -xzf ${headReclassArtifactName} --directory ${compareRoot}/old |
Denis Egorenko | 7aa5ac5 | 2018-10-17 15:14:56 +0400 | [diff] [blame] | 366 | find ${compareRoot} -name classes -type d -exec rm -rf '{}/system' \\; |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 367 | """) |
| 368 | common.warningMsg('infra/secrets.yml has been skipped from compare!') |
azvyagintsev | 3a80e34 | 2018-09-19 19:22:48 +0300 | [diff] [blame] | 369 | 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] | 370 | currentBuild.description = currentBuild.description ? currentBuild.description + result : result |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 371 | } |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 372 | stage("TestContexts Head/Patched") { |
| 373 | def stepsForParallel = [:] |
| 374 | stepsForParallel.failFast = true |
| 375 | common.infoMsg("Found: ${contextFileListHead.size()} HEAD contexts to test.") |
| 376 | for (String context : contextFileListHead) { |
| 377 | def basename = common.GetBaseName(context, '.yml') |
| 378 | stepsForParallel.put("ContextHeadTest:${basename}", StepTestModel(basename, headReclassArtifactName, reclassInfoHeadPath)) |
| 379 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 380 | common.infoMsg("Found: ${contextFileListPatched.size()} patched contexts to test.") |
| 381 | for (String context : contextFileListPatched) { |
| 382 | def basename = common.GetBaseName(context, '.yml') |
Denis Egorenko | 086aff1 | 2018-10-18 17:54:59 +0400 | [diff] [blame] | 383 | stepsForParallel.put("ContextPatchedTest:${basename}", StepTestModel(basename, patchedReclassArtifactName, reclassInfoPatchedPath, true)) |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 384 | } |
| 385 | parallel stepsForParallel |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 386 | common.infoMsg('All TestContexts tests done') |
| 387 | } |
| 388 | stage("Compare NodesInfo Head/Patched") { |
| 389 | // Download all artifacts |
| 390 | def stepsForParallel = [:] |
| 391 | stepsForParallel.failFast = true |
| 392 | common.infoMsg("Found: ${testModelBuildsData.size()} nodeinfo artifacts to download.") |
| 393 | testModelBuildsData.each { bname, bdata -> |
| 394 | stepsForParallel.put("FetchData:${bname}", |
| 395 | getAndUnpackNodesInfoArtifact(bdata.jobname, bdata.copyToDir, bdata.buildId)) |
| 396 | } |
| 397 | parallel stepsForParallel |
Denis Egorenko | a6117fc | 2018-09-11 13:40:00 +0400 | [diff] [blame] | 398 | // remove timestamp field from rendered files |
| 399 | sh("find ${reclassNodeInfoDir} -type f -exec sed -i '/ timestamp: .*/d' {} \\;") |
Denis Egorenko | d874894 | 2018-09-07 12:26:20 +0400 | [diff] [blame] | 400 | // Compare patched and HEAD reclass pillars |
| 401 | result = '\n' + common.comparePillars(reclassNodeInfoDir, env.BUILD_URL, '') |
| 402 | currentBuild.description = currentBuild.description ? currentBuild.description + result : result |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 403 | } |
Denis Egorenko | 04ca9f2 | 2018-09-19 16:06:49 +0400 | [diff] [blame] | 404 | stage('Check include order') { |
azvyagintsev | e7b8e79 | 2018-09-21 17:27:01 +0300 | [diff] [blame] | 405 | if (!checkIncludeOrder) { |
| 406 | common.infoMsg('Check include order require to much time, and currently disabled!') |
| 407 | |
| 408 | } else { |
| 409 | def correctIncludeOrder = ["service", "system", "cluster"] |
| 410 | dir(reclassInfoPatchedPath) { |
| 411 | def nodeInfoFiles = findFiles(glob: "**/*.reclass.nodeinfo") |
| 412 | def messages = ["<b>Wrong include ordering found</b><ul>"] |
| 413 | def stepsForParallel = [:] |
| 414 | nodeInfoFiles.each { nodeInfo -> |
| 415 | stepsForParallel.put("Checking ${nodeInfo.path}:", { |
| 416 | def node = readYaml file: nodeInfo.path |
| 417 | def classes = node['classes'] |
| 418 | def curClassID = 0 |
| 419 | def prevClassID = 0 |
| 420 | def wrongOrder = false |
| 421 | for (String className in classes) { |
| 422 | def currentClass = className.tokenize('.')[0] |
| 423 | curClassID = correctIncludeOrder.indexOf(currentClass) |
| 424 | if (currentClass != correctIncludeOrder[prevClassID]) { |
| 425 | if (prevClassID > curClassID) { |
| 426 | wrongOrder = true |
| 427 | common.warningMsg("File ${nodeInfo.path} contains wrong order of classes including: Includes for ${className} should be declared before ${correctIncludeOrder[prevClassID]} includes") |
| 428 | } else { |
| 429 | prevClassID = curClassID |
| 430 | } |
Denis Egorenko | 04ca9f2 | 2018-09-19 16:06:49 +0400 | [diff] [blame] | 431 | } |
| 432 | } |
azvyagintsev | e7b8e79 | 2018-09-21 17:27:01 +0300 | [diff] [blame] | 433 | if (wrongOrder) { |
| 434 | messages.add("<li>${nodeInfo.path} contains wrong order of classes including</li>") |
| 435 | } |
| 436 | }) |
| 437 | } |
| 438 | parallel stepsForParallel |
| 439 | def includerOrder = '<b>No wrong include order</b>' |
| 440 | if (messages.size() != 1) { |
| 441 | includerOrder = messages.join('') |
| 442 | } |
| 443 | currentBuild.description = currentBuild.description ? currentBuild.description + includerOrder : includerOrder |
Denis Egorenko | 04ca9f2 | 2018-09-19 16:06:49 +0400 | [diff] [blame] | 444 | } |
Denis Egorenko | 04ca9f2 | 2018-09-19 16:06:49 +0400 | [diff] [blame] | 445 | } |
| 446 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 447 | sh(script: 'find . -mindepth 1 -delete > /dev/null || true') |
| 448 | |
| 449 | } catch (Throwable e) { |
azvyagintsev | 9df82e5 | 2018-09-06 19:17:18 +0300 | [diff] [blame] | 450 | if (alreadyMerged) { |
| 451 | currentBuild.result = 'ABORTED' |
| 452 | currentBuild.description = "Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them" |
| 453 | return |
| 454 | } |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 455 | currentBuild.result = "FAILURE" |
| 456 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 457 | throw e |
| 458 | } finally { |
| 459 | def dummy = "dummy" |
azvyagintsev | 5c0313d | 2018-08-13 17:13:35 +0300 | [diff] [blame] | 460 | } |
| 461 | } |
chnyda | e80bb92 | 2017-05-29 17:48:40 +0200 | [diff] [blame] | 462 | } |