blob: e1c48410ad0b1074b87b95af90653d8ed02a4b01 [file] [log] [blame]
vnaumov33747e12020-05-04 17:35:20 +02001package com.mirantis.mk
vnaumov33747e12020-05-04 17:35:20 +02002
3/**
4 *
5 * KaaS Component Testing Utilities
6 *
7 */
8
9
10/**
azvyagintseva12230a2020-06-05 13:24:06 +030011 * Determine scope of test suite against per-commit KaaS deployment based on keywords
Владислав Наумов5a523ef2020-07-29 13:33:38 +020012 * Keyword list: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/
azvyagintseva12230a2020-06-05 13:24:06 +030013 *
14 * Used for components team to combine test-suites and forward desired parameters to kaas/core deployment jobs
15 * Example scheme:
16 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and combine test-suite -> trigger deployment jobs from kaas/core
17 * manage test-suite through Jenkins Job Parameters
18 *
Владислав Наумов6c2afff2020-06-05 12:54:53 +020019 * @return (map)[
20 * deployChildEnabled: (bool) True if need to deploy child cluster during demo-run
21 * runUie2eEnabled: (bool) True if need to run ui-e2e cluster during demo-run
azvyagintseva12230a2020-06-05 13:24:06 +030022 * ]
23 */
vnaumov33747e12020-05-04 17:35:20 +020024def checkDeploymentTestSuite() {
vnaumovbdb90222020-05-04 18:25:50 +020025 def common = new com.mirantis.mk.Common()
26
vnaumov33747e12020-05-04 17:35:20 +020027 // Available triggers and its sane defaults
Владислав Наумов6c2afff2020-06-05 12:54:53 +020028 def deployChild = env.DEPLOY_CHILD_CLUSTER ? env.DEPLOY_CHILD_CLUSTER.toBoolean() : false
29 def upgradeChild = env.UPGRADE_CHILD_CLUSTER ? env.UPGRADE_CHILD_CLUSTER.toBoolean() : false
30 def upgradeMgmt = env.UPGRADE_MGMT_CLUSTER ? env.UPGRADE_MGMT_CLUSTER.toBoolean() : false
31 def runUie2e = env.RUN_UI_E2E ? env.RUN_UI_E2E.toBoolean() : false
32 def runMgmtConformance = env.RUN_MGMT_CFM ? env.RUN_MGMT_CFM.toBoolean() : false
33 def runChildConformance = env.RUN_CHILD_CFM ? env.RUN_CHILD_CFM.toBoolean() : false
34 def fetchServiceBinaries = env.FETCH_BINARIES_FROM_UPSTREAM ? env.FETCH_BINARIES_FROM_UPSTREAM.toBoolean() : false
Владислав Наумов905dd362020-06-08 16:37:01 +020035 def awsOnDemandDemo = env.ALLOW_AWS_ON_DEMAND ? env.ALLOW_AWS_ON_DEMAND.toBoolean() : false
vnaumov33747e12020-05-04 17:35:20 +020036
Владислав Наумов6c2afff2020-06-05 12:54:53 +020037 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
vnaumov33747e12020-05-04 17:35:20 +020038 if (commitMsg ==~ /(?s).*\[child-deploy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-deploy.*/ || upgradeChild || runChildConformance) {
39 deployChild = true
40 }
41 if (commitMsg ==~ /(?s).*\[child-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-upgrade.*/) {
42 deployChild = true
43 upgradeChild = true
44 }
45 if (commitMsg ==~ /(?s).*\[mgmt-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-upgrade.*/) {
46 upgradeMgmt = true
47 }
48 if (commitMsg ==~ /(?s).*\[ui-e2e\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*ui-e2e.*/) {
49 runUie2e = true
50 }
51 if (commitMsg ==~ /(?s).*\[mgmt-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-cfm.*/) {
52 runMgmtConformance = true
53 }
54 if (commitMsg ==~ /(?s).*\[child-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-cfm.*/) {
55 runChildConformance = true
56 deployChild = true
57 }
58 if (commitMsg ==~ /(?s).*\[fetch.*binaries\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*fetch.*binaries.*/) {
59 fetchServiceBinaries = true
60 }
61 if (commitMsg ==~ /(?s).*\[aws-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*aws-demo.*/) {
62 awsOnDemandDemo = true
63 common.warningMsg('Forced running additional kaas deployment with AWS provider, triggered on patchset using custom keyword: \'aws-demo\' ')
64 }
65
66 // TODO (vnaumov) remove below condition after moving all releases to UCP
67 def ucpChildMatches = (commitMsg =~ /(\[child-ucp\s*ucp-.*?\])/)
68 if (ucpChildMatches.size() > 0) {
69 deployChild = true
70 common.warningMsg('Forced UCP based child deployment triggered on patchset using custom keyword: \'[child-ucp ucp-5-1-0-3-3-0-example]\' ')
71
72 // TODO(vnaumov) delete after ucp upgrades support
73 common.errorMsg('Child upgrade test will be skipped, UCP upgrades temporally disabled')
74 upgradeChild = false
75 }
76
77 common.infoMsg("""
78 Child cluster deployment scheduled: ${deployChild}
79 Child cluster release upgrade scheduled: ${upgradeChild}
80 Child conformance testing scheduled: ${runChildConformance}
81 Mgmt cluster release upgrade scheduled: ${upgradeMgmt}
82 Mgmt conformance testing scheduled: ${runMgmtConformance}
83 Mgmt UI e2e testing scheduled: ${runUie2e}
84 AWS provider additional deployment scheduled: ${awsOnDemandDemo}
85 Service binaries fetching scheduled: ${fetchServiceBinaries}
Владислав Наумов5a523ef2020-07-29 13:33:38 +020086 Triggers: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/""")
vnaumov33747e12020-05-04 17:35:20 +020087 return [
azvyagintseva12230a2020-06-05 13:24:06 +030088 deployChildEnabled : deployChild,
89 upgradeChildEnabled : upgradeChild,
90 runChildConformanceEnabled : runChildConformance,
91 upgradeMgmtEnabled : upgradeMgmt,
92 runUie2eEnabled : runUie2e,
93 runMgmtConformanceEnabled : runMgmtConformance,
vnaumov33747e12020-05-04 17:35:20 +020094 fetchServiceBinariesEnabled: fetchServiceBinaries,
azvyagintseva12230a2020-06-05 13:24:06 +030095 awsOnDemandDemoEnabled : awsOnDemandDemo]
vnaumov33747e12020-05-04 17:35:20 +020096}
97
98/**
99 * Determine if custom si tests/pipelines refspec forwarded from gerrit change request
100
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200101 * Keyword list: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/
vnaumov33747e12020-05-04 17:35:20 +0200102 * Used for components team to test component changes w/ custom SI refspecs using kaas/core deployment jobs
103 * Example scheme:
104 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
105 * manage refspecs through Jenkins Job Parameters
106 *
azvyagintseva12230a2020-06-05 13:24:06 +0300107 * @return (map)[* siTests: (string) final refspec for si-tests
vnaumov33747e12020-05-04 17:35:20 +0200108 * siPipelines: (string) final refspec for si-pipelines
109 * ]
110 */
111def checkCustomSIRefspec() {
vnaumovbdb90222020-05-04 18:25:50 +0200112 def common = new com.mirantis.mk.Common()
113
vnaumov33747e12020-05-04 17:35:20 +0200114 // Available triggers and its sane defaults
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200115 def siTestsRefspec = env.SI_TESTS_REFSPEC ?: 'master'
116 def siPipelinesRefspec = env.SI_PIPELINES_REFSPEC ?: 'master'
117 def siTestsDockerImage = env.SI_TESTS_DOCKER_IMAGE ?: 'docker-dev-kaas-local.docker.mirantis.net/mirantis/kaas/si-test:master'
118 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
vnaumov33747e12020-05-04 17:35:20 +0200119
120 def siTestMatches = (commitMsg =~ /(\[si-tests-ref\s*refs\/changes\/.*?\])/)
121 def siPipelinesMatches = (commitMsg =~ /(\[si-pipelines-ref\s*refs\/changes\/.*?\])/)
122
123 if (siTestMatches.size() > 0) {
124 siTestsRefspec = siTestMatches[0][0].split('si-tests-ref')[1].replaceAll('[\\[\\]]', '').trim()
azvyagintseva12230a2020-06-05 13:24:06 +0300125 siTestsDockerImage = "docker-dev-local.docker.mirantis.net/review/" +
126 "kaas-si-test-${siTestsRefspec.split('/')[-2]}:${siTestsRefspec.split('/')[-1]}"
vnaumov33747e12020-05-04 17:35:20 +0200127 }
128 if (siPipelinesMatches.size() > 0) {
129 siPipelinesRefspec = siPipelinesMatches[0][0].split('si-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
130 }
131
132 common.infoMsg("""
133 kaas/si-pipelines will be fetched from: ${siPipelinesRefspec}
134 kaas/si-tests will be fetched from: ${siTestsRefspec}
azvyagintseva12230a2020-06-05 13:24:06 +0300135 kaas/si-tests as dockerImage will be fetched from: ${siTestsDockerImage}
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200136 Keywords: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/""")
Владислав Наумов418042b2020-07-09 18:31:10 +0200137 return [siTests: siTestsRefspec, siPipelines: siPipelinesRefspec, siTestsDockerImage: siTestsDockerImage]
vnaumov33747e12020-05-04 17:35:20 +0200138}
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200139
Владислав Наумов9080f372020-06-08 13:57:16 +0200140/**
Владислав Наумов418042b2020-07-09 18:31:10 +0200141 * Parse additional configuration for kaas component CICD repo
Владислав Наумов30a516c2020-07-09 13:15:41 +0200142 * @param configurationFile (str) path to configuration file in yaml format
143 *
144 * @return (map)[ siTestsFeatureFlags (string) dedicated feature flags that will be used in SI tests,
145 * ]
146 */
147def parseKaaSComponentCIParameters(configurationFile){
148 def common = new com.mirantis.mk.Common()
149 def ciConfig = readYaml file: configurationFile
150 def ciSpec = [
151 siTestsFeatureFlags: env.SI_TESTS_FEATURE_FLAGS ?: '',
152 ]
153
154 if (ciConfig.containsKey('si-tests-feature-flags')) {
155 common.infoMsg("""SI tests feature flags customization detected,
156 results will be merged with existing flags: [${ciSpec['siTestsFeatureFlags']}] identification...""")
157
158 def ffMeta = ciSpec['siTestsFeatureFlags'].tokenize(',').collect { it.trim() }
159 ffMeta.addAll(ciConfig['si-tests-feature-flags'])
Владислав Наумов30a516c2020-07-09 13:15:41 +0200160
Владислав Наумовcb5ffca2020-07-14 15:28:36 +0200161 ciSpec['siTestsFeatureFlags'] = ffMeta.unique().join(',')
Владислав Наумов30a516c2020-07-09 13:15:41 +0200162 common.infoMsg("SI tests custom feature flags: ${ciSpec['siTestsFeatureFlags']}")
163 }
164
165 common.infoMsg("""Additional ci configuration parsed successfully:
166 siTestsFeatureFlags: ${ciSpec['siTestsFeatureFlags']}""")
167 return ciSpec
168}
169
170/**
171 * Determine if custom kaas core/pipelines refspec forwarded from gerrit change request
Владислав Наумов9080f372020-06-08 13:57:16 +0200172
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200173 * Keyword list: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/
Владислав Наумов9080f372020-06-08 13:57:16 +0200174 * Used for components team to test component changes w/ custom Core refspecs using kaas/core deployment jobs
175 * Example scheme:
176 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
177 * manage refspecs through Jenkins Job Parameters
178 *
179 * @return (map)[ core: (string) final refspec for kaas/core
180 * corePipelines: (string) final refspec for pipelines in kaas/core
181 * ]
182 */
183def checkCustomCoreRefspec() {
184 def common = new com.mirantis.mk.Common()
185
186 // Available triggers and its sane defaults
187 def coreRefspec = env.KAAS_CORE_REFSPEC ?: 'master'
188 // by default using value of GERRIT_REFSPEC parameter in *kaas/core jobs*
189 def corePipelinesRefspec = env.KAAS_PIPELINE_REFSPEC ?: '\$GERRIT_REFSPEC'
190 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
191
192 def coreMatches = (commitMsg =~ /(\[core-ref\s*refs\/changes\/.*?\])/)
193 def corePipelinesMatches = (commitMsg =~ /(\[core-pipelines-ref\s*refs\/changes\/.*?\])/)
194
195 if (coreMatches.size() > 0) {
196 coreRefspec = coreMatches[0][0].split('core-ref')[1].replaceAll('[\\[\\]]', '').trim()
197 }
198 if (corePipelinesMatches.size() > 0) {
199 corePipelinesRefspec = corePipelinesMatches[0][0].split('core-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
200 }
201
202 common.infoMsg("""
203 kaas/core will be fetched from: ${coreRefspec}
204 kaas/core pipelines will be fetched from: ${corePipelinesRefspec}
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200205 Keywords: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/""")
Владислав Наумов9080f372020-06-08 13:57:16 +0200206 return [core: coreRefspec, corePipelines: corePipelinesRefspec]
207}
208
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200209
210/**
211 * Trigger KaaS demo jobs based on AWS/OS providers with customized test suite, parsed from external sources (gerrit commit/jj vars)
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200212 * Keyword list: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200213 * Used for components team to test component changes w/ customized SI tests/refspecs using kaas/core deployment jobs
214 *
Владислав Наумов418042b2020-07-09 18:31:10 +0200215 * @param: component (string) component name [iam, lcm, stacklight]
216 * @param: patchSpec (string) Patch for kaas/cluster releases in json format
217 * @param: configurationFile (string) Additional file for component repo CI config in yaml format
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200218 */
Владислав Наумов418042b2020-07-09 18:31:10 +0200219def triggerPatchedComponentDemo(component, patchSpec, configurationFile = '.ci-parameters.yaml') {
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200220 def common = new com.mirantis.mk.Common()
221 // Determine if custom trigger keywords forwarded from gerrit
222 def triggers = checkDeploymentTestSuite()
223 // Determine SI refspecs
224 def siRefspec = checkCustomSIRefspec()
Владислав Наумов9080f372020-06-08 13:57:16 +0200225 // Determine Core refspecs
226 def coreRefspec = checkCustomCoreRefspec()
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200227
Владислав Наумов418042b2020-07-09 18:31:10 +0200228 // Determine component repo ci configuration
229 def ciSpec = [:]
230 def componentFeatureFlags = env.SI_TESTS_FEATURE_FLAGS ?: ''
231 if (fileExists(configurationFile)) {
232 common.infoMsg('Component CI configuration file detected, parsing...')
233 ciSpec = parseKaaSComponentCIParameters(configurationFile)
234 componentFeatureFlags = ciSpec['siTestsFeatureFlags']
235 } else {
236 common.warningMsg('''Component CI configuration file is not exists,
237 several code-management features may be unavailable, follow *link* to create configuration file''')
238 }
239
240
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200241 def jobs = [:]
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200242 def parameters = [
Владислав Наумов9080f372020-06-08 13:57:16 +0200243 string(name: 'GERRIT_REFSPEC', value: coreRefspec.core),
244 string(name: 'KAAS_PIPELINE_REFSPEC', value: coreRefspec.corePipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200245 string(name: 'SI_TESTS_REFSPEC', value: siRefspec.siTests),
Владислав Наумов418042b2020-07-09 18:31:10 +0200246 string(name: 'SI_TESTS_FEATURE_FLAGS', value: componentFeatureFlags),
Владислав Наумов4a5c3242020-06-08 14:36:11 +0200247 string(name: 'SI_PIPELINES_REFSPEC', value: siRefspec.siPipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200248 string(name: 'CUSTOM_RELEASE_PATCH_SPEC', value: patchSpec),
Владислав Наумов080d9412020-07-29 13:05:14 +0200249 booleanParam(name: 'UPGRADE_MGMT_CLUSTER', value: triggers.upgradeMgmtEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200250 booleanParam(name: 'RUN_UI_E2E', value: triggers.runUie2eEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200251 booleanParam(name: 'RUN_MGMT_CFM', value: triggers.runMgmtConformanceEnabled),
252 booleanParam(name: 'DEPLOY_CHILD_CLUSTER', value: triggers.deployChildEnabled),
253 booleanParam(name: 'UPGRADE_CHILD_CLUSTER', value: triggers.upgradeChildEnabled),
254 booleanParam(name: 'RUN_CHILD_CFM', value: triggers.runChildConformanceEnabled),
Владислав Наумов905dd362020-06-08 16:37:01 +0200255 booleanParam(name: 'ALLOW_AWS_ON_DEMAND', value: triggers.awsOnDemandDemoEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200256 ]
257
Владислав Наумовaa430612020-06-08 17:18:31 +0200258 def jobResults = []
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200259 jobs["kaas-core-openstack-patched-${component}"] = {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200260 try {
261 common.infoMsg('Deploy: patched KaaS demo with Openstack provider')
Владислав Наумов4aa112d2020-06-16 18:52:21 +0200262 os_job_info = build job: "kaas-testing-core-openstack-workflow-${component}", parameters: parameters, wait: true
263 def build_description = os_job_info.getDescription()
Владислав Наумовd044e842020-06-17 15:33:43 +0200264 def build_result = os_job_info.getResult()
265 jobResults.add(build_result)
266
Владислав Наумовf86b1112020-06-09 14:04:48 +0200267 if (build_description) {
268 currentBuild.description += build_description
269 }
270 } finally {
Владислав Наумов6d741fa2020-06-17 17:35:43 +0200271 common.infoMsg('Patched KaaS demo with Openstack provider finished')
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200272 }
273 }
274 if (triggers.awsOnDemandDemoEnabled) {
275 jobs["kaas-core-aws-patched-${component}"] = {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200276 try {
277 common.infoMsg('Deploy: patched KaaS demo with AWS provider')
Владислав Наумов4aa112d2020-06-16 18:52:21 +0200278 aws_job_info = build job: "kaas-testing-core-aws-workflow-${component}", parameters: parameters, wait: true
279 def build_description = aws_job_info.getDescription()
Владислав Наумовd044e842020-06-17 15:33:43 +0200280 def build_result = aws_job_info.getResult()
281 jobResults.add(build_result)
282
Владислав Наумовf86b1112020-06-09 14:04:48 +0200283 if (build_description) {
284 currentBuild.description += build_description
285 }
286 } finally {
Владислав Наумов6d741fa2020-06-17 17:35:43 +0200287 common.infoMsg('Patched KaaS demo with AWS provider finished')
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200288 }
289 }
290 }
291
292 common.infoMsg('Trigger KaaS demo deployments according to defined provider set')
293 // Limit build concurency workaround examples: https://issues.jenkins-ci.org/browse/JENKINS-44085
294 parallel jobs
Владислав Наумовaa430612020-06-08 17:18:31 +0200295
296 if (jobResults.contains('FAILURE')) {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200297 common.infoMsg('One of parallel downstream jobs is failed, mark executor job as failed')
Владислав Наумовaa430612020-06-08 17:18:31 +0200298 currentBuild.result = 'FAILURE'
299 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200300}
Владислав Наумов30a516c2020-07-09 13:15:41 +0200301
302