Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 1 | /* |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 2 | Global CI wrapper for testing next projects: |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 3 | - salt-models/reclass-system |
| 4 | - mk/cookiecutter-templates |
Denis Egorenko | d71aaa0 | 2018-12-11 16:03:37 +0400 | [diff] [blame] | 5 | |
| 6 | Wrapper allows to test cross-project patches, based on |
| 7 | 'Depends-On: http://<gerrit_address>/<change_number>' key phrase |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | import groovy.json.JsonOutput |
Denis Egorenko | abf6397 | 2019-02-06 19:38:27 +0400 | [diff] [blame] | 11 | |
Denis Egorenko | 6c32511 | 2018-12-05 19:58:34 +0400 | [diff] [blame] | 12 | gerrit = new com.mirantis.mk.Gerrit() |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 13 | |
Denis Egorenko | abf6397 | 2019-02-06 19:38:27 +0400 | [diff] [blame] | 14 | cookiecutterTemplatesRepo = 'mk/cookiecutter-templates' |
| 15 | reclassSystemRepo = 'salt-models/reclass-system' |
Denis Egorenko | 6c6b08e | 2018-12-13 13:23:43 +0400 | [diff] [blame] | 16 | slaveNode = env.getProperty('SLAVE_NODE') ?: 'virtual' |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 17 | |
Denis Egorenko | 76a0be8 | 2018-12-04 13:36:07 +0400 | [diff] [blame] | 18 | voteMatrix = [ |
Denis Egorenko | abf6397 | 2019-02-06 19:38:27 +0400 | [diff] [blame] | 19 | 'test-mk-cookiecutter-templates' : true, |
| 20 | 'test-drivetrain' : true, |
| 21 | 'oscore-test-cookiecutter-models': false, |
| 22 | 'test-salt-model-infra' : true, |
| 23 | 'test-salt-model-mcp-virtual-lab': false, |
Denis Egorenko | 76a0be8 | 2018-12-04 13:36:07 +0400 | [diff] [blame] | 24 | ] |
| 25 | |
Denis Egorenko | 6c32511 | 2018-12-05 19:58:34 +0400 | [diff] [blame] | 26 | baseGerritConfig = [:] |
Denis Egorenko | d71aaa0 | 2018-12-11 16:03:37 +0400 | [diff] [blame] | 27 | buildTestParams = [:] |
Denis Egorenko | f4d3f52 | 2018-12-06 16:33:11 +0400 | [diff] [blame] | 28 | jobResultComments = [:] |
| 29 | commentLock = false |
Denis Egorenko | 6c32511 | 2018-12-05 19:58:34 +0400 | [diff] [blame] | 30 | |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 31 | // post Gerrit review comment to patch |
| 32 | def setGerritReviewComment() { |
Denis Egorenko | 6c32511 | 2018-12-05 19:58:34 +0400 | [diff] [blame] | 33 | if (baseGerritConfig) { |
Denis Egorenko | 42ea661 | 2019-01-31 18:00:25 +0400 | [diff] [blame] | 34 | while (commentLock) { |
Denis Egorenko | f4d3f52 | 2018-12-06 16:33:11 +0400 | [diff] [blame] | 35 | sleep 5 |
| 36 | } |
| 37 | commentLock = true |
Denis Egorenko | 6c32511 | 2018-12-05 19:58:34 +0400 | [diff] [blame] | 38 | LinkedHashMap config = baseGerritConfig.clone() |
Denis Egorenko | f4d3f52 | 2018-12-06 16:33:11 +0400 | [diff] [blame] | 39 | String jobResultComment = '' |
Denis Egorenko | 42ea661 | 2019-01-31 18:00:25 +0400 | [diff] [blame] | 40 | jobResultComments.each { threadName, info -> |
| 41 | String skipped = voteMatrix.get(info.job, 'true') ? '' : '(non-voting)' |
| 42 | jobResultComment += "- ${threadName} ${info.url}console : ${info.status} ${skipped}".trim() + '\n' |
Denis Egorenko | f4d3f52 | 2018-12-06 16:33:11 +0400 | [diff] [blame] | 43 | } |
| 44 | config['message'] = sh(script: "echo '${jobResultComment}'", returnStdout: true).trim() |
Denis Egorenko | 6c32511 | 2018-12-05 19:58:34 +0400 | [diff] [blame] | 45 | gerrit.postGerritComment(config) |
Denis Egorenko | f4d3f52 | 2018-12-06 16:33:11 +0400 | [diff] [blame] | 46 | commentLock = false |
Denis Egorenko | 6c32511 | 2018-12-05 19:58:34 +0400 | [diff] [blame] | 47 | } |
Denis Egorenko | 76a0be8 | 2018-12-04 13:36:07 +0400 | [diff] [blame] | 48 | } |
| 49 | |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 50 | // get job parameters for YAML-based job parametrization |
| 51 | def yamlJobParameters(LinkedHashMap jobParams) { |
| 52 | return [ |
Denis Egorenko | abf6397 | 2019-02-06 19:38:27 +0400 | [diff] [blame] | 53 | [$class: 'TextParameterValue', name: 'EXTRA_VARIABLES_YAML', value: JsonOutput.toJson(jobParams)] |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 54 | ] |
| 55 | } |
| 56 | |
| 57 | // run needed job with params |
Denis Egorenko | 04c8a2c | 2019-02-22 14:30:44 +0400 | [diff] [blame] | 58 | def runTests(String jobName, ArrayList jobParams, String threadName = '', Boolean voteOverride = null) { |
Denis Egorenko | 42ea661 | 2019-01-31 18:00:25 +0400 | [diff] [blame] | 59 | threadName = threadName ? threadName : jobName |
Denis Egorenko | 04c8a2c | 2019-02-22 14:30:44 +0400 | [diff] [blame] | 60 | def propagateStatus = voteOverride != null ? voteOverride : voteMatrix.get(jobName, true) |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 61 | return { |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 62 | def jobBuild = build job: jobName, propagate: false, parameters: jobParams |
Denis Egorenko | abf6397 | 2019-02-06 19:38:27 +0400 | [diff] [blame] | 63 | jobResultComments[threadName] = ['url': jobBuild.absoluteUrl, 'status': jobBuild.result, 'job': jobName] |
Denis Egorenko | f4d3f52 | 2018-12-06 16:33:11 +0400 | [diff] [blame] | 64 | setGerritReviewComment() |
Denis Egorenko | 76a0be8 | 2018-12-04 13:36:07 +0400 | [diff] [blame] | 65 | if (propagateStatus && jobBuild.result == 'FAILURE') { |
Denis Egorenko | 42ea661 | 2019-01-31 18:00:25 +0400 | [diff] [blame] | 66 | throw new Exception("Build ${threadName} is failed!") |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
Denis Egorenko | d71aaa0 | 2018-12-11 16:03:37 +0400 | [diff] [blame] | 71 | // set params based on depending patches |
| 72 | def setupDependingVars(LinkedHashMap dependingProjects) { |
| 73 | if (dependingProjects) { |
| 74 | if (dependingProjects.containsKey(reclassSystemRepo)) { |
| 75 | buildTestParams['RECLASS_SYSTEM_GIT_REF'] = dependingProjects[reclassSystemRepo].ref |
| 76 | buildTestParams['RECLASS_SYSTEM_BRANCH'] = dependingProjects[reclassSystemRepo].branch |
| 77 | } |
| 78 | if (dependingProjects.containsKey(cookiecutterTemplatesRepo)) { |
| 79 | buildTestParams['COOKIECUTTER_TEMPLATE_REF'] = dependingProjects[cookiecutterTemplatesRepo].ref |
| 80 | buildTestParams['COOKIECUTTER_TEMPLATE_BRANCH'] = dependingProjects[cookiecutterTemplatesRepo].branch |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 85 | timeout(time: 12, unit: 'HOURS') { |
| 86 | node(slaveNode) { |
| 87 | def common = new com.mirantis.mk.Common() |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 88 | |
Denis Egorenko | 28f8c81 | 2018-12-10 16:06:37 +0400 | [diff] [blame] | 89 | // Var EXTRA_VARIABLES_YAML contains any additional parameters for tests, |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 90 | // like manually specified Gerrit Refs/URLs, additional parameters and so on |
Denis Egorenko | 28f8c81 | 2018-12-10 16:06:37 +0400 | [diff] [blame] | 91 | def buildTestParamsYaml = env.getProperty('EXTRA_VARIABLES_YAML') |
Denis Egorenko | 76a0be8 | 2018-12-04 13:36:07 +0400 | [diff] [blame] | 92 | if (buildTestParamsYaml) { |
| 93 | common.mergeEnv(env, buildTestParamsYaml) |
| 94 | buildTestParams = readYaml text: buildTestParamsYaml |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | // init required job variables |
| 98 | LinkedHashMap job_env = env.getEnvironment().findAll { k, v -> v } |
| 99 | |
| 100 | // Gerrit parameters |
| 101 | String gerritCredentials = job_env.get('CREDENTIALS_ID', 'gerrit') |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 102 | String gerritRef = job_env.get('GERRIT_REFSPEC') |
| 103 | String gerritProject = job_env.get('GERRIT_PROJECT') |
| 104 | String gerritName = job_env.get('GERRIT_NAME') |
| 105 | String gerritScheme = job_env.get('GERRIT_SCHEME') |
| 106 | String gerritHost = job_env.get('GERRIT_HOST') |
| 107 | String gerritPort = job_env.get('GERRIT_PORT') |
| 108 | String gerritChangeNumber = job_env.get('GERRIT_CHANGE_NUMBER') |
| 109 | String gerritPatchSetNumber = job_env.get('GERRIT_PATCHSET_NUMBER') |
| 110 | String gerritBranch = job_env.get('GERRIT_BRANCH') |
Denis Egorenko | e581f9e | 2018-12-11 18:56:14 +0400 | [diff] [blame] | 111 | Boolean gateMode = job_env.get('GERRIT_CI_MERGE_TRIGGER', false).toBoolean() |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 112 | |
| 113 | // Common and manual build parameters |
| 114 | LinkedHashMap projectsMap = [:] |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 115 | String distribRevision = 'nightly' |
| 116 | //checking if the branch is from release |
| 117 | if (gerritBranch.startsWith('release')) { |
Denis Egorenko | abf6397 | 2019-02-06 19:38:27 +0400 | [diff] [blame] | 118 | distribRevision = gerritBranch.tokenize('/')[-1] |
| 119 | // Check if we are going to test bleeding-edge release, which doesn't have binary release yet |
| 120 | // After 2018q4 releases, need to also check 'static' repo, for example ubuntu. |
| 121 | binTest = common.checkRemoteBinary(['mcp_version': distribRevision]) |
| 122 | if (!binTest.linux_system_repo_url || !binTest.linux_system_repo_ubuntu_url) { |
| 123 | common.errorMsg("Binary release: ${distribRevision} not exist or not full. Fallback to 'proposed'! ") |
| 124 | distribRevision = 'proposed' |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 125 | } |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 126 | } |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 127 | ArrayList testModels = job_env.get('TEST_MODELS', 'mcp-virtual-lab,infra').split(',') |
| 128 | |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 129 | stage('Gerrit prepare') { |
| 130 | // check if change aren't already merged |
| 131 | def gerritChange = gerrit.getGerritChange(gerritName, gerritHost, gerritChangeNumber, gerritCredentials) |
| 132 | if (gerritChange.status == "MERGED") { |
| 133 | common.successMsg('Patch set is alredy merged, no need to test it') |
| 134 | currentBuild.result = 'SUCCESS' |
| 135 | return |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 136 | } |
Denis Egorenko | abf6397 | 2019-02-06 19:38:27 +0400 | [diff] [blame] | 137 | buildTestParams << job_env.findAll { k, v -> k ==~ /GERRIT_.+/ } |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 138 | baseGerritConfig = [ |
Denis Egorenko | abf6397 | 2019-02-06 19:38:27 +0400 | [diff] [blame] | 139 | 'gerritName' : gerritName, |
| 140 | 'gerritHost' : gerritHost, |
| 141 | 'gerritPort' : gerritPort, |
| 142 | 'gerritChangeNumber' : gerritChangeNumber, |
| 143 | 'credentialsId' : gerritCredentials, |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 144 | 'gerritPatchSetNumber': gerritPatchSetNumber, |
| 145 | ] |
Denis Egorenko | d71aaa0 | 2018-12-11 16:03:37 +0400 | [diff] [blame] | 146 | LinkedHashMap gerritDependingProjects = gerrit.getDependentPatches(baseGerritConfig) |
| 147 | setupDependingVars(gerritDependingProjects) |
| 148 | ArrayList descriptionMsgs = [ |
| 149 | "Running with next parameters:", |
| 150 | "Ref for ${gerritProject} => ${gerritRef}", |
| 151 | "Branch for ${gerritProject} => ${gerritBranch}" |
| 152 | ] |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 153 | descriptionMsgs.add("Distrib revision => ${distribRevision}") |
Denis Egorenko | abf6397 | 2019-02-06 19:38:27 +0400 | [diff] [blame] | 154 | for (String project in gerritDependingProjects.keySet()) { |
Denis Egorenko | d71aaa0 | 2018-12-11 16:03:37 +0400 | [diff] [blame] | 155 | descriptionMsgs.add("---") |
| 156 | descriptionMsgs.add("Depending patch to ${project} found:") |
| 157 | descriptionMsgs.add("Ref for ${project} => ${gerritDependingProjects[project]['ref']}") |
| 158 | descriptionMsgs.add("Branch for ${project} => ${gerritDependingProjects[project]['branch']}") |
| 159 | } |
Denis Egorenko | 76a0be8 | 2018-12-04 13:36:07 +0400 | [diff] [blame] | 160 | currentBuild.description = descriptionMsgs.join('<br/>') |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 161 | gerrit.gerritPatchsetCheckout([ |
| 162 | credentialsId: gerritCredentials |
| 163 | ]) |
| 164 | } |
| 165 | |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 166 | stage("Run tests") { |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 167 | def documentationOnly = sh(script: "git diff-tree --no-commit-id --name-only -r HEAD | grep -v .releasenotes", returnStatus: true) == 1 |
| 168 | if (documentationOnly) { |
| 169 | common.infoMsg("Tests skipped, documenation only changed!") |
| 170 | currentBuild.result = 'SUCCESS' |
| 171 | return |
| 172 | } |
| 173 | |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 174 | def branches = [:] |
Vasyl Saienko | b121eb8 | 2018-12-27 17:34:28 +0200 | [diff] [blame] | 175 | branches.failFast = false |
Denis Egorenko | f4d3f52 | 2018-12-06 16:33:11 +0400 | [diff] [blame] | 176 | String branchJobName = '' |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 177 | |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 178 | if (gerritProject == reclassSystemRepo && gerritBranch == 'master') { |
Denis Egorenko | bbc1268 | 2018-12-11 18:38:43 +0400 | [diff] [blame] | 179 | sh("git diff-tree --no-commit-id --diff-filter=d --name-only -r HEAD | grep .yml | xargs -I {} python -c \"import yaml; yaml.load(open('{}', 'r'))\" \\;") |
Denis Egorenko | d71aaa0 | 2018-12-11 16:03:37 +0400 | [diff] [blame] | 180 | def defaultSystemURL = "${gerritScheme}://${gerritName}@${gerritHost}:${gerritPort}/${gerritProject}" |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 181 | for (int i = 0; i < testModels.size(); i++) { |
| 182 | def cluster = testModels[i] |
Denis Egorenko | d71aaa0 | 2018-12-11 16:03:37 +0400 | [diff] [blame] | 183 | def clusterGitUrl = defaultSystemURL.substring(0, defaultSystemURL.lastIndexOf("/") + 1) + cluster |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 184 | branchJobName = "test-salt-model-${cluster}" |
| 185 | def jobParams = [ |
| 186 | [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: clusterGitUrl], |
| 187 | [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: "HEAD"], |
Denis Egorenko | abf6397 | 2019-02-06 19:38:27 +0400 | [diff] [blame] | 188 | [$class: 'StringParameterValue', name: 'SYSTEM_GIT_URL', value: defaultSystemURL], |
| 189 | [$class: 'StringParameterValue', name: 'SYSTEM_GIT_REF', value: gerritRef], |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 190 | ] |
| 191 | branches[branchJobName] = runTests(branchJobName, jobParams) |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 192 | } |
| 193 | } |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 194 | if (gerritProject == reclassSystemRepo || gerritProject == cookiecutterTemplatesRepo) { |
Denis Egorenko | f4d3f52 | 2018-12-06 16:33:11 +0400 | [diff] [blame] | 195 | branchJobName = 'test-mk-cookiecutter-templates' |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 196 | branches[branchJobName] = runTests(branchJobName, yamlJobParameters(buildTestParams)) |
Denis Egorenko | 80d45b2 | 2019-01-31 22:28:38 +0400 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | if (!gateMode) { |
Denis Egorenko | 42ea661 | 2019-01-31 18:00:25 +0400 | [diff] [blame] | 200 | // testing backward compatibility |
| 201 | if (gerritBranch == 'master' && gerritProject == reclassSystemRepo) { |
| 202 | def backwardCompatibilityRefsToTest = ['proposed', 'release/2018.11.0', 'release/2019.2.0'] |
| 203 | for (String oldRef in backwardCompatibilityRefsToTest) { |
Denis Egorenko | 80d45b2 | 2019-01-31 22:28:38 +0400 | [diff] [blame] | 204 | LinkedHashMap buildTestParamsOld = buildTestParams.clone() |
| 205 | buildTestParamsOld['COOKIECUTTER_TEMPLATE_REF'] = '' |
| 206 | buildTestParamsOld['COOKIECUTTER_TEMPLATE_BRANCH'] = oldRef |
| 207 | String threadName = "${branchJobName}-${oldRef}" |
Denis Egorenko | c8c4bd1 | 2019-02-22 16:18:13 +0400 | [diff] [blame] | 208 | // disable votes for release/2018.11.0 branch |
| 209 | overrideVote = oldRef == 'release/2018.11.0' ? false : null |
Denis Egorenko | 04c8a2c | 2019-02-22 14:30:44 +0400 | [diff] [blame] | 210 | branches[threadName] = runTests(branchJobName, yamlJobParameters(buildTestParamsOld), threadName, overrideVote) |
Denis Egorenko | 42ea661 | 2019-01-31 18:00:25 +0400 | [diff] [blame] | 211 | } |
| 212 | } |
Denis Egorenko | 28f8c81 | 2018-12-10 16:06:37 +0400 | [diff] [blame] | 213 | if (gerritProject == cookiecutterTemplatesRepo) { |
| 214 | branchJobName = 'test-drivetrain' |
| 215 | branches[branchJobName] = runTests(branchJobName, yamlJobParameters(buildTestParams)) |
| 216 | branchJobName = 'oscore-test-cookiecutter-models' |
| 217 | branches[branchJobName] = runTests(branchJobName, yamlJobParameters(buildTestParams)) |
| 218 | } |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 219 | } |
| 220 | |
Denis Egorenko | f4d3f52 | 2018-12-06 16:33:11 +0400 | [diff] [blame] | 221 | branches.keySet().each { key -> |
| 222 | if (branches[key] instanceof Closure) { |
Denis Egorenko | abf6397 | 2019-02-06 19:38:27 +0400 | [diff] [blame] | 223 | jobResultComments[key] = ['url': job_env.get('BUILD_URL'), 'status': 'WAITING'] |
Denis Egorenko | f4d3f52 | 2018-12-06 16:33:11 +0400 | [diff] [blame] | 224 | } |
| 225 | } |
Denis Egorenko | 8616487 | 2018-12-10 17:34:46 +0400 | [diff] [blame] | 226 | setGerritReviewComment() |
Denis Egorenko | d8d13e8 | 2018-12-07 16:16:31 +0400 | [diff] [blame] | 227 | parallel branches |
Denis Egorenko | 358a4fc | 2018-11-27 17:57:22 +0400 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | } |