blob: a2c23651498c4a132a99e1de3a9e5c2b55ce974b [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
Владислав Наумовe5345812020-08-12 16:30:20 +02009/**
10 * Check KaaS Core CICD feature flags
11 * such triggers can be used in case of switching between pipelines,
12 * conditions inside pipelines to reduce dependency on jenkins job builder and jenkins job templates itself
13 *
14 * @return (map)[
15 * ffNameEnabled: (bool) True/False
16 * ]
17 */
18def checkCoreCIFeatureFlags() {
19 def common = new com.mirantis.mk.Common()
20 def ff = [
21 build_artifacts_upgrade: false,
22 ]
23
24 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
25 if (commitMsg ==~ /(?s).*\[ci-build-artifacts-upgrade\].*/) {
26 ff['build_artifacts_upgrade'] = true
27 }
28
29 common.infoMsg("Core ci feature flags status: ${ff}")
30 return ff
31}
vnaumov33747e12020-05-04 17:35:20 +020032
33/**
azvyagintseva12230a2020-06-05 13:24:06 +030034 * Determine scope of test suite against per-commit KaaS deployment based on keywords
Владислав Наумов5a523ef2020-07-29 13:33:38 +020035 * Keyword list: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/
azvyagintseva12230a2020-06-05 13:24:06 +030036 *
37 * Used for components team to combine test-suites and forward desired parameters to kaas/core deployment jobs
38 * Example scheme:
Владислав Наумовe5345812020-08-12 16:30:20 +020039 * New CR pushed in kubernetes/lcm-ansible -> parsing it'cs commit body and combine test-suite -> trigger deployment jobs from kaas/core
azvyagintseva12230a2020-06-05 13:24:06 +030040 * manage test-suite through Jenkins Job Parameters
41 *
Владислав Наумов6c2afff2020-06-05 12:54:53 +020042 * @return (map)[
43 * deployChildEnabled: (bool) True if need to deploy child cluster during demo-run
44 * runUie2eEnabled: (bool) True if need to run ui-e2e cluster during demo-run
azvyagintseva12230a2020-06-05 13:24:06 +030045 * ]
46 */
vnaumov33747e12020-05-04 17:35:20 +020047def checkDeploymentTestSuite() {
vnaumovbdb90222020-05-04 18:25:50 +020048 def common = new com.mirantis.mk.Common()
49
vnaumov33747e12020-05-04 17:35:20 +020050 // Available triggers and its sane defaults
Владислав Наумов6c2afff2020-06-05 12:54:53 +020051 def deployChild = env.DEPLOY_CHILD_CLUSTER ? env.DEPLOY_CHILD_CLUSTER.toBoolean() : false
52 def upgradeChild = env.UPGRADE_CHILD_CLUSTER ? env.UPGRADE_CHILD_CLUSTER.toBoolean() : false
53 def upgradeMgmt = env.UPGRADE_MGMT_CLUSTER ? env.UPGRADE_MGMT_CLUSTER.toBoolean() : false
54 def runUie2e = env.RUN_UI_E2E ? env.RUN_UI_E2E.toBoolean() : false
55 def runMgmtConformance = env.RUN_MGMT_CFM ? env.RUN_MGMT_CFM.toBoolean() : false
56 def runChildConformance = env.RUN_CHILD_CFM ? env.RUN_CHILD_CFM.toBoolean() : false
57 def fetchServiceBinaries = env.FETCH_BINARIES_FROM_UPSTREAM ? env.FETCH_BINARIES_FROM_UPSTREAM.toBoolean() : false
Владислав Наумов765f3bd2020-09-07 18:09:24 +020058 // multiregion configuration from env variable: comma-separated string in form $mgmt_provider,$regional_provider
59 def multiregionalMappings = env.MULTIREGION_SETUP ? multiregionWorkflowParser(env.MULTIREGION_SETUP) : [
60 enabled: false,
61 managementLocation: '',
62 regionLocation: '',
63 ]
Владислав Наумов4eb1da32020-08-31 14:45:16 +020064
65 // optional demo deployment customization
Владислав Наумов905dd362020-06-08 16:37:01 +020066 def awsOnDemandDemo = env.ALLOW_AWS_ON_DEMAND ? env.ALLOW_AWS_ON_DEMAND.toBoolean() : false
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +040067 def awsOnRhelDemo = false
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +040068 def vsphereOnDemandDemo = false
Владислав Наумов4eb1da32020-08-31 14:45:16 +020069 def enableOSDemo = true
azvyagintsev1761bdc2020-09-04 17:24:12 +030070 def enableBMDemo = true
vnaumov33747e12020-05-04 17:35:20 +020071
Владислав Наумов6c2afff2020-06-05 12:54:53 +020072 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
vnaumov33747e12020-05-04 17:35:20 +020073 if (commitMsg ==~ /(?s).*\[child-deploy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-deploy.*/ || upgradeChild || runChildConformance) {
74 deployChild = true
75 }
76 if (commitMsg ==~ /(?s).*\[child-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-upgrade.*/) {
77 deployChild = true
78 upgradeChild = true
79 }
80 if (commitMsg ==~ /(?s).*\[mgmt-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-upgrade.*/) {
81 upgradeMgmt = true
82 }
83 if (commitMsg ==~ /(?s).*\[ui-e2e\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*ui-e2e.*/) {
84 runUie2e = true
85 }
86 if (commitMsg ==~ /(?s).*\[mgmt-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-cfm.*/) {
87 runMgmtConformance = true
88 }
89 if (commitMsg ==~ /(?s).*\[child-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-cfm.*/) {
90 runChildConformance = true
91 deployChild = true
92 }
93 if (commitMsg ==~ /(?s).*\[fetch.*binaries\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*fetch.*binaries.*/) {
94 fetchServiceBinaries = true
95 }
96 if (commitMsg ==~ /(?s).*\[aws-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*aws-demo.*/) {
97 awsOnDemandDemo = true
Владислав Наумов4eb1da32020-08-31 14:45:16 +020098 common.warningMsg('Forced running additional kaas deployment with AWS provider, triggered on patchset using custom keyword: \'[aws-demo]\' ')
99 }
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +0400100 if (commitMsg ==~ /(?s).*\[aws-rhel-demo\].*/) {
101 awsOnDemandDemo = false
102 awsOnRhelDemo = true
103 common.warningMsg('Forced running additional kaas deployment with AWS provider on RHEL, triggered on patchset using custom keyword: \'[aws-rhel-demo]\'.' +
104 'Upgrade scenario for Mgmt or Child cluster is not supported currently in such deployment')
105 }
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400106 if (commitMsg ==~ /(?s).*\[vsphere-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*vsphere-demo.*/) {
107 vsphereOnDemandDemo = true
108 common.warningMsg('Forced running additional kaas deployment with VSPHERE provider, triggered on patchset using custom keyword: \'[vsphere-demo]\' ')
109 }
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200110 if (commitMsg ==~ /(?s).*\[disable-os-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-os-demo\.*/) {
111 enableOSDemo = false
112 common.errorMsg('Openstack demo deployment will be aborted, VF -1 will be set')
vnaumov33747e12020-05-04 17:35:20 +0200113 }
114
azvyagintsev1761bdc2020-09-04 17:24:12 +0300115 if (commitMsg ==~ /(?s).*\[disable-bm-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-bm-demo\.*/) {
116 enableBMDemo = false
117 common.errorMsg('BM demo deployment will be aborted, VF -1 will be set')
118 }
119
vnaumov33747e12020-05-04 17:35:20 +0200120 // TODO (vnaumov) remove below condition after moving all releases to UCP
121 def ucpChildMatches = (commitMsg =~ /(\[child-ucp\s*ucp-.*?\])/)
122 if (ucpChildMatches.size() > 0) {
123 deployChild = true
124 common.warningMsg('Forced UCP based child deployment triggered on patchset using custom keyword: \'[child-ucp ucp-5-1-0-3-3-0-example]\' ')
125
126 // TODO(vnaumov) delete after ucp upgrades support
127 common.errorMsg('Child upgrade test will be skipped, UCP upgrades temporally disabled')
128 upgradeChild = false
129 }
130
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200131 // multiregional tests
132 def multiRegionalMatches = (commitMsg =~ /(\[multiregion\s*.*?\])/)
133 if (multiRegionalMatches.size() > 0) {
134 multiregionalMappings = multiregionWorkflowParser(multiRegionalMatches)
135 }
136 switch (multiregionalMappings['managementLocation']) {
137 case 'aws':
138 awsOnDemandDemo = true
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +0400139 if (awsOnRhelDemo) {
140 // Run only one variant: standard AWS deployment (on Ubuntu) or on RHEL
141 awsOnDemandDemo = false
142 }
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200143 common.warningMsg('Forced running additional kaas deployment with AWS provider according multiregional demo request')
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200144 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200145 case 'os':
146 if (enableOSDemo == false) {
147 error('incompatible triggers: [disable-os-demo] and multiregional deployment based on OSt management region cannot be applied simultaneously')
148 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200149 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200150 }
151
vnaumov33747e12020-05-04 17:35:20 +0200152 common.infoMsg("""
153 Child cluster deployment scheduled: ${deployChild}
154 Child cluster release upgrade scheduled: ${upgradeChild}
155 Child conformance testing scheduled: ${runChildConformance}
156 Mgmt cluster release upgrade scheduled: ${upgradeMgmt}
157 Mgmt conformance testing scheduled: ${runMgmtConformance}
158 Mgmt UI e2e testing scheduled: ${runUie2e}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200159 AWS provider deployment scheduled: ${awsOnDemandDemo}
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +0400160 AWS provider on RHEL deployment scheduled: ${awsOnRhelDemo}
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400161 VSPHERE provider deployment scheduled: ${vsphereOnDemandDemo}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200162 OS provider deployment scheduled: ${enableOSDemo}
azvyagintsev1761bdc2020-09-04 17:24:12 +0300163 BM provider deployment scheduled: ${enableBMDemo}
Владислав Наумовf793fe32020-09-11 15:19:19 +0200164 Multiregional configuration: ${multiregionalMappings}
vnaumov33747e12020-05-04 17:35:20 +0200165 Service binaries fetching scheduled: ${fetchServiceBinaries}
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200166 Triggers: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/""")
vnaumov33747e12020-05-04 17:35:20 +0200167 return [
azvyagintseva12230a2020-06-05 13:24:06 +0300168 deployChildEnabled : deployChild,
169 upgradeChildEnabled : upgradeChild,
170 runChildConformanceEnabled : runChildConformance,
171 upgradeMgmtEnabled : upgradeMgmt,
172 runUie2eEnabled : runUie2e,
173 runMgmtConformanceEnabled : runMgmtConformance,
vnaumov33747e12020-05-04 17:35:20 +0200174 fetchServiceBinariesEnabled: fetchServiceBinaries,
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200175 awsOnDemandDemoEnabled : awsOnDemandDemo,
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +0400176 awsOnDemandRhelDemoEnabled : awsOnRhelDemo,
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400177 vsphereOnDemandDemoEnabled : vsphereOnDemandDemo,
azvyagintsev1761bdc2020-09-04 17:24:12 +0300178 bmDemoEnabled : enableBMDemo,
Владислав Наумовf793fe32020-09-11 15:19:19 +0200179 osDemoEnabled : enableOSDemo,
180 multiregionalConfiguration : multiregionalMappings]
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200181}
182
183/**
184 * Determine management and regional setup for demo workflow scenario
185 *
186 *
187 * @param: keyword (string) string , represents keyworkd trigger, specified in gerrit commit body, like `[multiregion aws,os]`
188 or Jenkins environment string variable in form like 'aws,os'
189 * @return (map)[
190 enabled: (bool),
191 * managementLocation: (string), //aws,os
192 * regionLocation: (string), //aws,os
193 * ]
194 */
195def multiregionWorkflowParser(keyword) {
Владислав Наумов8c0c39d2020-09-11 14:46:48 +0200196 def common = new com.mirantis.mk.Common()
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200197 def supportedManagementProviders = ['os', 'aws']
198 def supportedRegionalProviders = ['os']
199
200 def clusterTypes = ''
Владислав Наумов38ed7bf2020-09-11 14:43:39 +0200201 if (keyword.toString().contains('multiregion')) {
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200202 common.infoMsg('Multiregion definition configured via gerrit keyword trigger')
203 clusterTypes = keyword[0][0].split('multiregion')[1].replaceAll('[\\[\\]]', '').trim().split(',')
204 } else {
205 common.infoMsg('Multiregion definition configured via environment variable')
206 clusterTypes = keyword.trim().split(',')
207 }
208
209 if (clusterTypes.size() != 2) {
Владислав Наумов482fb502020-10-30 17:59:27 +0100210 error("Incorrect regions definiton, valid scheme: [multiregion ${management}, ${region}], got: ${clusterTypes}")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200211 }
212
Владислав Наумовf793fe32020-09-11 15:19:19 +0200213 def desiredManagementProvider = clusterTypes[0].trim()
214 def desiredRegionalProvider = clusterTypes[1].trim()
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200215 if (! supportedManagementProviders.contains(desiredManagementProvider) || ! supportedRegionalProviders.contains(desiredRegionalProvider)) {
216 error("""unsupported management <-> regional bundle, available options:
Владислав Наумовf793fe32020-09-11 15:19:19 +0200217 management providers list - ${supportedManagementProviders}
218 regional providers list - ${supportedRegionalProviders}""")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200219 }
220
221 return [
222 enabled: true,
223 managementLocation: desiredManagementProvider,
224 regionLocation: desiredRegionalProvider,
225 ]
vnaumov33747e12020-05-04 17:35:20 +0200226}
227
228/**
229 * Determine if custom si tests/pipelines refspec forwarded from gerrit change request
230
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200231 * Keyword list: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/
vnaumov33747e12020-05-04 17:35:20 +0200232 * Used for components team to test component changes w/ custom SI refspecs using kaas/core deployment jobs
233 * Example scheme:
234 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
235 * manage refspecs through Jenkins Job Parameters
236 *
azvyagintseva12230a2020-06-05 13:24:06 +0300237 * @return (map)[* siTests: (string) final refspec for si-tests
vnaumov33747e12020-05-04 17:35:20 +0200238 * siPipelines: (string) final refspec for si-pipelines
239 * ]
240 */
241def checkCustomSIRefspec() {
vnaumovbdb90222020-05-04 18:25:50 +0200242 def common = new com.mirantis.mk.Common()
243
vnaumov33747e12020-05-04 17:35:20 +0200244 // Available triggers and its sane defaults
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200245 def siTestsRefspec = env.SI_TESTS_REFSPEC ?: 'master'
246 def siPipelinesRefspec = env.SI_PIPELINES_REFSPEC ?: 'master'
Владислав Наумов2db15e22020-07-14 12:29:22 +0200247 def siTestsDockerImage = env.SI_TESTS_DOCKER_IMAGE ?: 'docker-dev-kaas-local.docker.mirantis.net/mirantis/kaas/si-test'
248 def siTestsDockerImageTag = env.SI_TESTS_DOCKER_IMAGE_TAG ?: 'master'
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200249 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
vnaumov33747e12020-05-04 17:35:20 +0200250
251 def siTestMatches = (commitMsg =~ /(\[si-tests-ref\s*refs\/changes\/.*?\])/)
252 def siPipelinesMatches = (commitMsg =~ /(\[si-pipelines-ref\s*refs\/changes\/.*?\])/)
253
254 if (siTestMatches.size() > 0) {
255 siTestsRefspec = siTestMatches[0][0].split('si-tests-ref')[1].replaceAll('[\\[\\]]', '').trim()
Владислав Наумов2db15e22020-07-14 12:29:22 +0200256 siTestsDockerImage = "docker-dev-local.docker.mirantis.net/review/kaas-si-test-${siTestsRefspec.split('/')[-2]}"
257 siTestsDockerImageTag = siTestsRefspec.split('/')[-1]
vnaumov33747e12020-05-04 17:35:20 +0200258 }
259 if (siPipelinesMatches.size() > 0) {
260 siPipelinesRefspec = siPipelinesMatches[0][0].split('si-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
261 }
262
263 common.infoMsg("""
264 kaas/si-pipelines will be fetched from: ${siPipelinesRefspec}
265 kaas/si-tests will be fetched from: ${siTestsRefspec}
Владислав Наумов2db15e22020-07-14 12:29:22 +0200266 kaas/si-tests as dockerImage will be fetched from: ${siTestsDockerImage}:${siTestsDockerImageTag}
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200267 Keywords: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/""")
Владислав Наумов2db15e22020-07-14 12:29:22 +0200268 return [siTests: siTestsRefspec, siPipelines: siPipelinesRefspec, siTestsDockerImage: siTestsDockerImage, siTestsDockerImageTag: siTestsDockerImageTag]
vnaumov33747e12020-05-04 17:35:20 +0200269}
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200270
Владислав Наумов9080f372020-06-08 13:57:16 +0200271/**
Владислав Наумов418042b2020-07-09 18:31:10 +0200272 * Parse additional configuration for kaas component CICD repo
Владислав Наумов30a516c2020-07-09 13:15:41 +0200273 * @param configurationFile (str) path to configuration file in yaml format
274 *
275 * @return (map)[ siTestsFeatureFlags (string) dedicated feature flags that will be used in SI tests,
276 * ]
277 */
278def parseKaaSComponentCIParameters(configurationFile){
279 def common = new com.mirantis.mk.Common()
280 def ciConfig = readYaml file: configurationFile
281 def ciSpec = [
282 siTestsFeatureFlags: env.SI_TESTS_FEATURE_FLAGS ?: '',
283 ]
284
285 if (ciConfig.containsKey('si-tests-feature-flags')) {
286 common.infoMsg("""SI tests feature flags customization detected,
287 results will be merged with existing flags: [${ciSpec['siTestsFeatureFlags']}] identification...""")
288
289 def ffMeta = ciSpec['siTestsFeatureFlags'].tokenize(',').collect { it.trim() }
290 ffMeta.addAll(ciConfig['si-tests-feature-flags'])
Владислав Наумов30a516c2020-07-09 13:15:41 +0200291
Владислав Наумовcb5ffca2020-07-14 15:28:36 +0200292 ciSpec['siTestsFeatureFlags'] = ffMeta.unique().join(',')
Владислав Наумов30a516c2020-07-09 13:15:41 +0200293 common.infoMsg("SI tests custom feature flags: ${ciSpec['siTestsFeatureFlags']}")
294 }
295
296 common.infoMsg("""Additional ci configuration parsed successfully:
297 siTestsFeatureFlags: ${ciSpec['siTestsFeatureFlags']}""")
298 return ciSpec
299}
300
301/**
302 * Determine if custom kaas core/pipelines refspec forwarded from gerrit change request
Владислав Наумов9080f372020-06-08 13:57:16 +0200303
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200304 * Keyword list: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/
Владислав Наумов9080f372020-06-08 13:57:16 +0200305 * Used for components team to test component changes w/ custom Core refspecs using kaas/core deployment jobs
306 * Example scheme:
307 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
308 * manage refspecs through Jenkins Job Parameters
309 *
310 * @return (map)[ core: (string) final refspec for kaas/core
311 * corePipelines: (string) final refspec for pipelines in kaas/core
312 * ]
313 */
314def checkCustomCoreRefspec() {
315 def common = new com.mirantis.mk.Common()
316
317 // Available triggers and its sane defaults
318 def coreRefspec = env.KAAS_CORE_REFSPEC ?: 'master'
319 // by default using value of GERRIT_REFSPEC parameter in *kaas/core jobs*
320 def corePipelinesRefspec = env.KAAS_PIPELINE_REFSPEC ?: '\$GERRIT_REFSPEC'
321 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
322
323 def coreMatches = (commitMsg =~ /(\[core-ref\s*refs\/changes\/.*?\])/)
324 def corePipelinesMatches = (commitMsg =~ /(\[core-pipelines-ref\s*refs\/changes\/.*?\])/)
325
326 if (coreMatches.size() > 0) {
327 coreRefspec = coreMatches[0][0].split('core-ref')[1].replaceAll('[\\[\\]]', '').trim()
328 }
329 if (corePipelinesMatches.size() > 0) {
330 corePipelinesRefspec = corePipelinesMatches[0][0].split('core-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
331 }
332
333 common.infoMsg("""
334 kaas/core will be fetched from: ${coreRefspec}
335 kaas/core pipelines will be fetched from: ${corePipelinesRefspec}
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200336 Keywords: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/""")
Владислав Наумов9080f372020-06-08 13:57:16 +0200337 return [core: coreRefspec, corePipelines: corePipelinesRefspec]
338}
339
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200340
341/**
Владислав Наумов92288d92020-07-13 18:36:21 +0200342 * generate Jenkins Parameter objects from from text parameter with additonal kaas core context
343 * needed to forward inside kaas core set of jobs
344 *
345 * @param context (string) Representation of the string enviroment variables needed for kaas core jobs in yaml format
346 * @return (list)[ string(name: '', value: ''),
347 * ]
348 */
349def generateKaaSVarsFromContext(context) {
350 def common = new com.mirantis.mk.Common()
351 def parameters = []
352 def config = readYaml text: context
353
354 config.each { k,v ->
355 common.infoMsg("Custom KaaS Core context parameter: ${k}=${v}")
356 parameters.add(string(name: k, value: v))
357 }
358
359 return parameters
360}
361
362/**
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200363 * 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 +0200364 * Keyword list: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200365 * Used for components team to test component changes w/ customized SI tests/refspecs using kaas/core deployment jobs
366 *
Владислав Наумов418042b2020-07-09 18:31:10 +0200367 * @param: component (string) component name [iam, lcm, stacklight]
368 * @param: patchSpec (string) Patch for kaas/cluster releases in json format
369 * @param: configurationFile (string) Additional file for component repo CI config in yaml format
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200370 */
Владислав Наумов92288d92020-07-13 18:36:21 +0200371def triggerPatchedComponentDemo(component, patchSpec = '', configurationFile = '.ci-parameters.yaml', coreContext = '') {
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200372 def common = new com.mirantis.mk.Common()
373 // Determine if custom trigger keywords forwarded from gerrit
374 def triggers = checkDeploymentTestSuite()
375 // Determine SI refspecs
376 def siRefspec = checkCustomSIRefspec()
Владислав Наумов9080f372020-06-08 13:57:16 +0200377 // Determine Core refspecs
378 def coreRefspec = checkCustomCoreRefspec()
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200379
Владислав Наумов418042b2020-07-09 18:31:10 +0200380 // Determine component repo ci configuration
381 def ciSpec = [:]
382 def componentFeatureFlags = env.SI_TESTS_FEATURE_FLAGS ?: ''
383 if (fileExists(configurationFile)) {
384 common.infoMsg('Component CI configuration file detected, parsing...')
385 ciSpec = parseKaaSComponentCIParameters(configurationFile)
386 componentFeatureFlags = ciSpec['siTestsFeatureFlags']
387 } else {
388 common.warningMsg('''Component CI configuration file is not exists,
Владислав Наумовc17dd552020-07-29 17:07:38 +0200389 several code-management features may be unavailable,
Владислав Наумов92288d92020-07-13 18:36:21 +0200390 follow https://mirantis.jira.com/wiki/spaces/QA/pages/2310832276/SI-tests+feature+flags#%5BUpdated%5D-Using-a-feature-flag
391 to create the configuration file''')
Владислав Наумов418042b2020-07-09 18:31:10 +0200392 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200393 def jobs = [:]
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200394 def parameters = [
Владислав Наумов9080f372020-06-08 13:57:16 +0200395 string(name: 'GERRIT_REFSPEC', value: coreRefspec.core),
396 string(name: 'KAAS_PIPELINE_REFSPEC', value: coreRefspec.corePipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200397 string(name: 'SI_TESTS_REFSPEC', value: siRefspec.siTests),
Владислав Наумов418042b2020-07-09 18:31:10 +0200398 string(name: 'SI_TESTS_FEATURE_FLAGS', value: componentFeatureFlags),
Владислав Наумов2db15e22020-07-14 12:29:22 +0200399 string(name: 'SI_TESTS_DOCKER_IMAGE', value: siRefspec.siTestsDockerImage),
400 string(name: 'SI_TESTS_DOCKER_IMAGE_TAG', value: siRefspec.siTestsDockerImageTag),
Владислав Наумов4a5c3242020-06-08 14:36:11 +0200401 string(name: 'SI_PIPELINES_REFSPEC', value: siRefspec.siPipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200402 string(name: 'CUSTOM_RELEASE_PATCH_SPEC', value: patchSpec),
Владислав Наумов080d9412020-07-29 13:05:14 +0200403 booleanParam(name: 'UPGRADE_MGMT_CLUSTER', value: triggers.upgradeMgmtEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200404 booleanParam(name: 'RUN_UI_E2E', value: triggers.runUie2eEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200405 booleanParam(name: 'RUN_MGMT_CFM', value: triggers.runMgmtConformanceEnabled),
406 booleanParam(name: 'DEPLOY_CHILD_CLUSTER', value: triggers.deployChildEnabled),
407 booleanParam(name: 'UPGRADE_CHILD_CLUSTER', value: triggers.upgradeChildEnabled),
408 booleanParam(name: 'RUN_CHILD_CFM', value: triggers.runChildConformanceEnabled),
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +0400409 booleanParam(name: 'ALLOW_AWS_ON_DEMAND', value: triggers.awsOnDemandDemoEnabled || triggers.awsOnDemandRhelDemoEnabled),
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400410 booleanParam(name: 'ALLOW_VSPHERE_ON_DEMAND', value: triggers.vsphereOnDemandDemoEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200411 ]
Владислав Наумов92288d92020-07-13 18:36:21 +0200412
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200413 // customize multiregional demo
414 if (triggers.multiregionalConfiguration.enabled) {
415 parameters.add(string(name: 'MULTIREGION_SETUP',
416 value: "${triggers.multiregionalConfiguration.managementLocation},${triggers.multiregionalConfiguration.regionLocation}"
417 ))
418 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200419
Владислав Наумов92288d92020-07-13 18:36:21 +0200420 // Determine component team custom context
421 if (coreContext != '') {
422 common.infoMsg('Additional KaaS Core context detected, will be forwarded into kaas core cicd...')
423 def additionalParameters = generateKaaSVarsFromContext(coreContext)
Владислав Наумовbef51a92020-10-01 17:36:51 +0200424 parameters.addAll(additionalParameters)
Владислав Наумов92288d92020-07-13 18:36:21 +0200425 }
426
Владислав Наумовaa430612020-06-08 17:18:31 +0200427 def jobResults = []
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200428 jobs["kaas-core-openstack-patched-${component}"] = {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200429 try {
430 common.infoMsg('Deploy: patched KaaS demo with Openstack provider')
Владислав Наумов4aa112d2020-06-16 18:52:21 +0200431 os_job_info = build job: "kaas-testing-core-openstack-workflow-${component}", parameters: parameters, wait: true
432 def build_description = os_job_info.getDescription()
Владислав Наумовd044e842020-06-17 15:33:43 +0200433 def build_result = os_job_info.getResult()
434 jobResults.add(build_result)
435
Владислав Наумовf86b1112020-06-09 14:04:48 +0200436 if (build_description) {
437 currentBuild.description += build_description
438 }
439 } finally {
Владислав Наумов6d741fa2020-06-17 17:35:43 +0200440 common.infoMsg('Patched KaaS demo with Openstack provider finished')
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200441 }
442 }
443 if (triggers.awsOnDemandDemoEnabled) {
Владислав Наумов59281952020-07-29 16:43:49 +0200444 common.infoMsg('AWS demo triggered, need to sync artifacts in the public-ci cdn..')
445 switch (component) {
446 case 'iam':
447 build job: 'cdn-binary-dev-replication-iam', propagate: true, wait: true
448 break
449 case 'lcm':
450 build job: 'cdn-binary-dev-replication-lcm', propagate: true, wait: true
451 break
452 }
453
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200454 jobs["kaas-core-aws-patched-${component}"] = {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200455 try {
456 common.infoMsg('Deploy: patched KaaS demo with AWS provider')
Владислав Наумов4aa112d2020-06-16 18:52:21 +0200457 aws_job_info = build job: "kaas-testing-core-aws-workflow-${component}", parameters: parameters, wait: true
458 def build_description = aws_job_info.getDescription()
Владислав Наумовd044e842020-06-17 15:33:43 +0200459 def build_result = aws_job_info.getResult()
460 jobResults.add(build_result)
461
Владислав Наумовf86b1112020-06-09 14:04:48 +0200462 if (build_description) {
463 currentBuild.description += build_description
464 }
465 } finally {
Владислав Наумов6d741fa2020-06-17 17:35:43 +0200466 common.infoMsg('Patched KaaS demo with AWS provider finished')
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200467 }
468 }
469 }
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400470 if (triggers.vsphereOnDemandDemoEnabled) {
471 jobs["kaas-core-vsphere-patched-${component}"] = {
472 try {
473 common.infoMsg('Deploy: patched KaaS demo with VSPHERE provider')
474 vsphere_job_info = build job: "kaas-testing-core-vsphere-workflow-${component}", parameters: parameters, wait: true
475 def build_description = vsphere_job_info.getDescription()
476 def build_result = vsphere_job_info.getResult()
477 jobResults.add(build_result)
478
479 if (build_description) {
480 currentBuild.description += build_description
481 }
482 } finally {
483 common.infoMsg('Patched KaaS demo with VSPHERE provider finished')
484 }
485 }
486 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200487
488 common.infoMsg('Trigger KaaS demo deployments according to defined provider set')
489 // Limit build concurency workaround examples: https://issues.jenkins-ci.org/browse/JENKINS-44085
490 parallel jobs
Владислав Наумовaa430612020-06-08 17:18:31 +0200491
492 if (jobResults.contains('FAILURE')) {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200493 common.infoMsg('One of parallel downstream jobs is failed, mark executor job as failed')
Владислав Наумовaa430612020-06-08 17:18:31 +0200494 currentBuild.result = 'FAILURE'
495 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200496}
Владислав Наумов30a516c2020-07-09 13:15:41 +0200497
498