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