blob: 3efba8301db16c206c18450273f3c073c707945e [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
Владислав Наумов0dc99252020-11-13 13:30:48 +010053 def attachBYO = env.ATTACH_BYO ? env.ATTACH_BYO.toBoolean() : false
Владислав Наумовcdbd84e2020-12-01 16:51:09 +010054 def upgradeBYO = env.UPGRADE_BYO ? env.UPGRADE_BYO.toBoolean() : false
Владислав Наумов6c2afff2020-06-05 12:54:53 +020055 def upgradeMgmt = env.UPGRADE_MGMT_CLUSTER ? env.UPGRADE_MGMT_CLUSTER.toBoolean() : false
56 def runUie2e = env.RUN_UI_E2E ? env.RUN_UI_E2E.toBoolean() : false
57 def runMgmtConformance = env.RUN_MGMT_CFM ? env.RUN_MGMT_CFM.toBoolean() : false
58 def runChildConformance = env.RUN_CHILD_CFM ? env.RUN_CHILD_CFM.toBoolean() : false
59 def fetchServiceBinaries = env.FETCH_BINARIES_FROM_UPSTREAM ? env.FETCH_BINARIES_FROM_UPSTREAM.toBoolean() : false
Владислав Наумов765f3bd2020-09-07 18:09:24 +020060 // multiregion configuration from env variable: comma-separated string in form $mgmt_provider,$regional_provider
61 def multiregionalMappings = env.MULTIREGION_SETUP ? multiregionWorkflowParser(env.MULTIREGION_SETUP) : [
62 enabled: false,
63 managementLocation: '',
64 regionLocation: '',
65 ]
Владислав Наумов4eb1da32020-08-31 14:45:16 +020066
67 // optional demo deployment customization
Владислав Наумов905dd362020-06-08 16:37:01 +020068 def awsOnDemandDemo = env.ALLOW_AWS_ON_DEMAND ? env.ALLOW_AWS_ON_DEMAND.toBoolean() : false
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +040069 def awsOnRhelDemo = false
Владислав Наумов6ec74302020-11-05 12:38:53 +010070 def vsphereOnDemandDemo = env.ALLOW_VSPHERE_ON_DEMAND ? env.ALLOW_VSPHERE_ON_DEMAND.toBoolean() : false
Владислав Наумов4eb1da32020-08-31 14:45:16 +020071 def enableOSDemo = true
azvyagintsev1761bdc2020-09-04 17:24:12 +030072 def enableBMDemo = true
vnaumov33747e12020-05-04 17:35:20 +020073
Владислав Наумов6c2afff2020-06-05 12:54:53 +020074 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
vnaumov33747e12020-05-04 17:35:20 +020075 if (commitMsg ==~ /(?s).*\[child-deploy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-deploy.*/ || upgradeChild || runChildConformance) {
76 deployChild = true
77 }
78 if (commitMsg ==~ /(?s).*\[child-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-upgrade.*/) {
79 deployChild = true
80 upgradeChild = true
81 }
Владислав Наумов0dc99252020-11-13 13:30:48 +010082 if (commitMsg ==~ /(?s).*\[byo-attach\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-attach.*/) {
83 attachBYO = true
84 }
Владислав Наумовcdbd84e2020-12-01 16:51:09 +010085 if (commitMsg ==~ /(?s).*\[byo-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-upgrade.*/) {
86 attachBYO = true
87 upgradeBYO = true
88 }
89 if (commitMsg ==~ /(?s).*\[mgmt-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-upgrade.*/ || upgradeBYO) {
vnaumov33747e12020-05-04 17:35:20 +020090 upgradeMgmt = true
Владислав Наумовcdbd84e2020-12-01 16:51:09 +010091 if (upgradeBYO) {
92 // TODO (vnaumov) remove such dependency right after we can verify byo upgrade w/o mgmt upgrade
93 common.warningMsg('Forced running kaas mgmt upgrade scenario, due byo demo scenario trigger: \'[byo-upgrade]\' ')
94 }
vnaumov33747e12020-05-04 17:35:20 +020095 }
96 if (commitMsg ==~ /(?s).*\[ui-e2e\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*ui-e2e.*/) {
97 runUie2e = true
98 }
99 if (commitMsg ==~ /(?s).*\[mgmt-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-cfm.*/) {
100 runMgmtConformance = true
101 }
102 if (commitMsg ==~ /(?s).*\[child-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-cfm.*/) {
103 runChildConformance = true
104 deployChild = true
105 }
106 if (commitMsg ==~ /(?s).*\[fetch.*binaries\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*fetch.*binaries.*/) {
107 fetchServiceBinaries = true
108 }
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100109 if (commitMsg ==~ /(?s).*\[aws-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*aws-demo.*/ || attachBYO || upgradeBYO) {
vnaumov33747e12020-05-04 17:35:20 +0200110 awsOnDemandDemo = true
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100111 if (attachBYO || upgradeBYO) {
112 common.warningMsg('Forced running additional kaas deployment with AWS provider, due byo demo scenario trigger(s): \'[byo-attach] [byo-upgrade]\' ')
Владислав Наумов0dc99252020-11-13 13:30:48 +0100113 } else {
114 common.warningMsg('Forced running additional kaas deployment with AWS provider, triggered on patchset using custom keyword: \'[aws-demo]\' ')
115 }
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200116 }
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +0400117 if (commitMsg ==~ /(?s).*\[aws-rhel-demo\].*/) {
118 awsOnDemandDemo = false
119 awsOnRhelDemo = true
120 common.warningMsg('Forced running additional kaas deployment with AWS provider on RHEL, triggered on patchset using custom keyword: \'[aws-rhel-demo]\'.' +
121 'Upgrade scenario for Mgmt or Child cluster is not supported currently in such deployment')
122 }
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400123 if (commitMsg ==~ /(?s).*\[vsphere-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*vsphere-demo.*/) {
124 vsphereOnDemandDemo = true
125 common.warningMsg('Forced running additional kaas deployment with VSPHERE provider, triggered on patchset using custom keyword: \'[vsphere-demo]\' ')
126 }
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200127 if (commitMsg ==~ /(?s).*\[disable-os-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-os-demo\.*/) {
128 enableOSDemo = false
129 common.errorMsg('Openstack demo deployment will be aborted, VF -1 will be set')
vnaumov33747e12020-05-04 17:35:20 +0200130 }
131
azvyagintsev1761bdc2020-09-04 17:24:12 +0300132 if (commitMsg ==~ /(?s).*\[disable-bm-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-bm-demo\.*/) {
133 enableBMDemo = false
134 common.errorMsg('BM demo deployment will be aborted, VF -1 will be set')
135 }
136
vnaumov33747e12020-05-04 17:35:20 +0200137 // TODO (vnaumov) remove below condition after moving all releases to UCP
138 def ucpChildMatches = (commitMsg =~ /(\[child-ucp\s*ucp-.*?\])/)
139 if (ucpChildMatches.size() > 0) {
140 deployChild = true
141 common.warningMsg('Forced UCP based child deployment triggered on patchset using custom keyword: \'[child-ucp ucp-5-1-0-3-3-0-example]\' ')
142
143 // TODO(vnaumov) delete after ucp upgrades support
144 common.errorMsg('Child upgrade test will be skipped, UCP upgrades temporally disabled')
145 upgradeChild = false
146 }
147
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200148 // multiregional tests
149 def multiRegionalMatches = (commitMsg =~ /(\[multiregion\s*.*?\])/)
150 if (multiRegionalMatches.size() > 0) {
151 multiregionalMappings = multiregionWorkflowParser(multiRegionalMatches)
152 }
153 switch (multiregionalMappings['managementLocation']) {
154 case 'aws':
155 awsOnDemandDemo = true
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +0400156 if (awsOnRhelDemo) {
157 // Run only one variant: standard AWS deployment (on Ubuntu) or on RHEL
158 awsOnDemandDemo = false
159 }
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200160 common.warningMsg('Forced running additional kaas deployment with AWS provider according multiregional demo request')
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200161 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200162 case 'os':
163 if (enableOSDemo == false) {
164 error('incompatible triggers: [disable-os-demo] and multiregional deployment based on OSt management region cannot be applied simultaneously')
165 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200166 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200167 }
168
vnaumov33747e12020-05-04 17:35:20 +0200169 common.infoMsg("""
170 Child cluster deployment scheduled: ${deployChild}
171 Child cluster release upgrade scheduled: ${upgradeChild}
172 Child conformance testing scheduled: ${runChildConformance}
Владислав Наумов0dc99252020-11-13 13:30:48 +0100173 BYO cluster attachment scheduled: ${attachBYO}
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100174 Attached BYO cluster upgrade test scheduled: ${upgradeBYO}
vnaumov33747e12020-05-04 17:35:20 +0200175 Mgmt cluster release upgrade scheduled: ${upgradeMgmt}
176 Mgmt conformance testing scheduled: ${runMgmtConformance}
177 Mgmt UI e2e testing scheduled: ${runUie2e}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200178 AWS provider deployment scheduled: ${awsOnDemandDemo}
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +0400179 AWS provider on RHEL deployment scheduled: ${awsOnRhelDemo}
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400180 VSPHERE provider deployment scheduled: ${vsphereOnDemandDemo}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200181 OS provider deployment scheduled: ${enableOSDemo}
azvyagintsev1761bdc2020-09-04 17:24:12 +0300182 BM provider deployment scheduled: ${enableBMDemo}
Владислав Наумовf793fe32020-09-11 15:19:19 +0200183 Multiregional configuration: ${multiregionalMappings}
vnaumov33747e12020-05-04 17:35:20 +0200184 Service binaries fetching scheduled: ${fetchServiceBinaries}
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200185 Triggers: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/""")
vnaumov33747e12020-05-04 17:35:20 +0200186 return [
azvyagintseva12230a2020-06-05 13:24:06 +0300187 deployChildEnabled : deployChild,
188 upgradeChildEnabled : upgradeChild,
189 runChildConformanceEnabled : runChildConformance,
Владислав Наумов0dc99252020-11-13 13:30:48 +0100190 attachBYOEnabled : attachBYO,
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100191 upgradeBYOEnabled : upgradeBYO,
azvyagintseva12230a2020-06-05 13:24:06 +0300192 upgradeMgmtEnabled : upgradeMgmt,
193 runUie2eEnabled : runUie2e,
194 runMgmtConformanceEnabled : runMgmtConformance,
vnaumov33747e12020-05-04 17:35:20 +0200195 fetchServiceBinariesEnabled: fetchServiceBinaries,
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200196 awsOnDemandDemoEnabled : awsOnDemandDemo,
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +0400197 awsOnDemandRhelDemoEnabled : awsOnRhelDemo,
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400198 vsphereOnDemandDemoEnabled : vsphereOnDemandDemo,
azvyagintsev1761bdc2020-09-04 17:24:12 +0300199 bmDemoEnabled : enableBMDemo,
Владислав Наумовf793fe32020-09-11 15:19:19 +0200200 osDemoEnabled : enableOSDemo,
201 multiregionalConfiguration : multiregionalMappings]
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200202}
203
204/**
205 * Determine management and regional setup for demo workflow scenario
206 *
207 *
208 * @param: keyword (string) string , represents keyworkd trigger, specified in gerrit commit body, like `[multiregion aws,os]`
209 or Jenkins environment string variable in form like 'aws,os'
210 * @return (map)[
211 enabled: (bool),
212 * managementLocation: (string), //aws,os
213 * regionLocation: (string), //aws,os
214 * ]
215 */
216def multiregionWorkflowParser(keyword) {
Владислав Наумов8c0c39d2020-09-11 14:46:48 +0200217 def common = new com.mirantis.mk.Common()
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200218 def supportedManagementProviders = ['os', 'aws']
219 def supportedRegionalProviders = ['os']
220
221 def clusterTypes = ''
Владислав Наумов38ed7bf2020-09-11 14:43:39 +0200222 if (keyword.toString().contains('multiregion')) {
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200223 common.infoMsg('Multiregion definition configured via gerrit keyword trigger')
224 clusterTypes = keyword[0][0].split('multiregion')[1].replaceAll('[\\[\\]]', '').trim().split(',')
225 } else {
226 common.infoMsg('Multiregion definition configured via environment variable')
227 clusterTypes = keyword.trim().split(',')
228 }
229
230 if (clusterTypes.size() != 2) {
Владислав Наумов482fb502020-10-30 17:59:27 +0100231 error("Incorrect regions definiton, valid scheme: [multiregion ${management}, ${region}], got: ${clusterTypes}")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200232 }
233
Владислав Наумовf793fe32020-09-11 15:19:19 +0200234 def desiredManagementProvider = clusterTypes[0].trim()
235 def desiredRegionalProvider = clusterTypes[1].trim()
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200236 if (! supportedManagementProviders.contains(desiredManagementProvider) || ! supportedRegionalProviders.contains(desiredRegionalProvider)) {
237 error("""unsupported management <-> regional bundle, available options:
Владислав Наумовf793fe32020-09-11 15:19:19 +0200238 management providers list - ${supportedManagementProviders}
239 regional providers list - ${supportedRegionalProviders}""")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200240 }
241
242 return [
243 enabled: true,
244 managementLocation: desiredManagementProvider,
245 regionLocation: desiredRegionalProvider,
246 ]
vnaumov33747e12020-05-04 17:35:20 +0200247}
248
249/**
250 * Determine if custom si tests/pipelines refspec forwarded from gerrit change request
251
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200252 * Keyword list: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/
vnaumov33747e12020-05-04 17:35:20 +0200253 * Used for components team to test component changes w/ custom SI refspecs using kaas/core deployment jobs
254 * Example scheme:
255 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
256 * manage refspecs through Jenkins Job Parameters
257 *
azvyagintseva12230a2020-06-05 13:24:06 +0300258 * @return (map)[* siTests: (string) final refspec for si-tests
vnaumov33747e12020-05-04 17:35:20 +0200259 * siPipelines: (string) final refspec for si-pipelines
260 * ]
261 */
262def checkCustomSIRefspec() {
vnaumovbdb90222020-05-04 18:25:50 +0200263 def common = new com.mirantis.mk.Common()
264
vnaumov33747e12020-05-04 17:35:20 +0200265 // Available triggers and its sane defaults
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200266 def siTestsRefspec = env.SI_TESTS_REFSPEC ?: 'master'
267 def siPipelinesRefspec = env.SI_PIPELINES_REFSPEC ?: 'master'
Владислав Наумов2db15e22020-07-14 12:29:22 +0200268 def siTestsDockerImage = env.SI_TESTS_DOCKER_IMAGE ?: 'docker-dev-kaas-local.docker.mirantis.net/mirantis/kaas/si-test'
269 def siTestsDockerImageTag = env.SI_TESTS_DOCKER_IMAGE_TAG ?: 'master'
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200270 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
vnaumov33747e12020-05-04 17:35:20 +0200271
272 def siTestMatches = (commitMsg =~ /(\[si-tests-ref\s*refs\/changes\/.*?\])/)
273 def siPipelinesMatches = (commitMsg =~ /(\[si-pipelines-ref\s*refs\/changes\/.*?\])/)
274
275 if (siTestMatches.size() > 0) {
276 siTestsRefspec = siTestMatches[0][0].split('si-tests-ref')[1].replaceAll('[\\[\\]]', '').trim()
Владислав Наумов2db15e22020-07-14 12:29:22 +0200277 siTestsDockerImage = "docker-dev-local.docker.mirantis.net/review/kaas-si-test-${siTestsRefspec.split('/')[-2]}"
278 siTestsDockerImageTag = siTestsRefspec.split('/')[-1]
vnaumov33747e12020-05-04 17:35:20 +0200279 }
280 if (siPipelinesMatches.size() > 0) {
281 siPipelinesRefspec = siPipelinesMatches[0][0].split('si-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
282 }
283
284 common.infoMsg("""
285 kaas/si-pipelines will be fetched from: ${siPipelinesRefspec}
286 kaas/si-tests will be fetched from: ${siTestsRefspec}
Владислав Наумов2db15e22020-07-14 12:29:22 +0200287 kaas/si-tests as dockerImage will be fetched from: ${siTestsDockerImage}:${siTestsDockerImageTag}
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200288 Keywords: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/""")
Владислав Наумов2db15e22020-07-14 12:29:22 +0200289 return [siTests: siTestsRefspec, siPipelines: siPipelinesRefspec, siTestsDockerImage: siTestsDockerImage, siTestsDockerImageTag: siTestsDockerImageTag]
vnaumov33747e12020-05-04 17:35:20 +0200290}
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200291
Владислав Наумов9080f372020-06-08 13:57:16 +0200292/**
Владислав Наумов418042b2020-07-09 18:31:10 +0200293 * Parse additional configuration for kaas component CICD repo
Владислав Наумов30a516c2020-07-09 13:15:41 +0200294 * @param configurationFile (str) path to configuration file in yaml format
295 *
296 * @return (map)[ siTestsFeatureFlags (string) dedicated feature flags that will be used in SI tests,
297 * ]
298 */
299def parseKaaSComponentCIParameters(configurationFile){
300 def common = new com.mirantis.mk.Common()
301 def ciConfig = readYaml file: configurationFile
302 def ciSpec = [
303 siTestsFeatureFlags: env.SI_TESTS_FEATURE_FLAGS ?: '',
304 ]
305
306 if (ciConfig.containsKey('si-tests-feature-flags')) {
307 common.infoMsg("""SI tests feature flags customization detected,
308 results will be merged with existing flags: [${ciSpec['siTestsFeatureFlags']}] identification...""")
309
310 def ffMeta = ciSpec['siTestsFeatureFlags'].tokenize(',').collect { it.trim() }
311 ffMeta.addAll(ciConfig['si-tests-feature-flags'])
Владислав Наумов30a516c2020-07-09 13:15:41 +0200312
Владислав Наумовcb5ffca2020-07-14 15:28:36 +0200313 ciSpec['siTestsFeatureFlags'] = ffMeta.unique().join(',')
Владислав Наумов30a516c2020-07-09 13:15:41 +0200314 common.infoMsg("SI tests custom feature flags: ${ciSpec['siTestsFeatureFlags']}")
315 }
316
317 common.infoMsg("""Additional ci configuration parsed successfully:
318 siTestsFeatureFlags: ${ciSpec['siTestsFeatureFlags']}""")
319 return ciSpec
320}
321
322/**
323 * Determine if custom kaas core/pipelines refspec forwarded from gerrit change request
Владислав Наумов9080f372020-06-08 13:57:16 +0200324
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200325 * Keyword list: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/
Владислав Наумов9080f372020-06-08 13:57:16 +0200326 * Used for components team to test component changes w/ custom Core refspecs using kaas/core deployment jobs
327 * Example scheme:
328 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
329 * manage refspecs through Jenkins Job Parameters
330 *
331 * @return (map)[ core: (string) final refspec for kaas/core
332 * corePipelines: (string) final refspec for pipelines in kaas/core
333 * ]
334 */
335def checkCustomCoreRefspec() {
336 def common = new com.mirantis.mk.Common()
337
338 // Available triggers and its sane defaults
339 def coreRefspec = env.KAAS_CORE_REFSPEC ?: 'master'
340 // by default using value of GERRIT_REFSPEC parameter in *kaas/core jobs*
341 def corePipelinesRefspec = env.KAAS_PIPELINE_REFSPEC ?: '\$GERRIT_REFSPEC'
342 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
343
344 def coreMatches = (commitMsg =~ /(\[core-ref\s*refs\/changes\/.*?\])/)
345 def corePipelinesMatches = (commitMsg =~ /(\[core-pipelines-ref\s*refs\/changes\/.*?\])/)
346
347 if (coreMatches.size() > 0) {
348 coreRefspec = coreMatches[0][0].split('core-ref')[1].replaceAll('[\\[\\]]', '').trim()
349 }
350 if (corePipelinesMatches.size() > 0) {
351 corePipelinesRefspec = corePipelinesMatches[0][0].split('core-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
352 }
353
354 common.infoMsg("""
355 kaas/core will be fetched from: ${coreRefspec}
356 kaas/core pipelines will be fetched from: ${corePipelinesRefspec}
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200357 Keywords: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/""")
Владислав Наумов9080f372020-06-08 13:57:16 +0200358 return [core: coreRefspec, corePipelines: corePipelinesRefspec]
359}
360
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200361
362/**
Владислав Наумов92288d92020-07-13 18:36:21 +0200363 * generate Jenkins Parameter objects from from text parameter with additonal kaas core context
364 * needed to forward inside kaas core set of jobs
365 *
366 * @param context (string) Representation of the string enviroment variables needed for kaas core jobs in yaml format
367 * @return (list)[ string(name: '', value: ''),
368 * ]
369 */
370def generateKaaSVarsFromContext(context) {
371 def common = new com.mirantis.mk.Common()
372 def parameters = []
373 def config = readYaml text: context
374
375 config.each { k,v ->
376 common.infoMsg("Custom KaaS Core context parameter: ${k}=${v}")
377 parameters.add(string(name: k, value: v))
378 }
379
380 return parameters
381}
382
383/**
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200384 * 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 +0200385 * Keyword list: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200386 * Used for components team to test component changes w/ customized SI tests/refspecs using kaas/core deployment jobs
387 *
Владислав Наумов418042b2020-07-09 18:31:10 +0200388 * @param: component (string) component name [iam, lcm, stacklight]
389 * @param: patchSpec (string) Patch for kaas/cluster releases in json format
390 * @param: configurationFile (string) Additional file for component repo CI config in yaml format
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200391 */
Владислав Наумов92288d92020-07-13 18:36:21 +0200392def triggerPatchedComponentDemo(component, patchSpec = '', configurationFile = '.ci-parameters.yaml', coreContext = '') {
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200393 def common = new com.mirantis.mk.Common()
394 // Determine if custom trigger keywords forwarded from gerrit
395 def triggers = checkDeploymentTestSuite()
396 // Determine SI refspecs
397 def siRefspec = checkCustomSIRefspec()
Владислав Наумов9080f372020-06-08 13:57:16 +0200398 // Determine Core refspecs
399 def coreRefspec = checkCustomCoreRefspec()
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200400
Владислав Наумов418042b2020-07-09 18:31:10 +0200401 // Determine component repo ci configuration
402 def ciSpec = [:]
403 def componentFeatureFlags = env.SI_TESTS_FEATURE_FLAGS ?: ''
404 if (fileExists(configurationFile)) {
405 common.infoMsg('Component CI configuration file detected, parsing...')
406 ciSpec = parseKaaSComponentCIParameters(configurationFile)
407 componentFeatureFlags = ciSpec['siTestsFeatureFlags']
408 } else {
409 common.warningMsg('''Component CI configuration file is not exists,
Владислав Наумовc17dd552020-07-29 17:07:38 +0200410 several code-management features may be unavailable,
Владислав Наумов92288d92020-07-13 18:36:21 +0200411 follow https://mirantis.jira.com/wiki/spaces/QA/pages/2310832276/SI-tests+feature+flags#%5BUpdated%5D-Using-a-feature-flag
412 to create the configuration file''')
Владислав Наумов418042b2020-07-09 18:31:10 +0200413 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200414 def jobs = [:]
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200415 def parameters = [
Владислав Наумов9080f372020-06-08 13:57:16 +0200416 string(name: 'GERRIT_REFSPEC', value: coreRefspec.core),
417 string(name: 'KAAS_PIPELINE_REFSPEC', value: coreRefspec.corePipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200418 string(name: 'SI_TESTS_REFSPEC', value: siRefspec.siTests),
Владислав Наумов418042b2020-07-09 18:31:10 +0200419 string(name: 'SI_TESTS_FEATURE_FLAGS', value: componentFeatureFlags),
Владислав Наумов2db15e22020-07-14 12:29:22 +0200420 string(name: 'SI_TESTS_DOCKER_IMAGE', value: siRefspec.siTestsDockerImage),
421 string(name: 'SI_TESTS_DOCKER_IMAGE_TAG', value: siRefspec.siTestsDockerImageTag),
Владислав Наумов4a5c3242020-06-08 14:36:11 +0200422 string(name: 'SI_PIPELINES_REFSPEC', value: siRefspec.siPipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200423 string(name: 'CUSTOM_RELEASE_PATCH_SPEC', value: patchSpec),
Владислав Наумов080d9412020-07-29 13:05:14 +0200424 booleanParam(name: 'UPGRADE_MGMT_CLUSTER', value: triggers.upgradeMgmtEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200425 booleanParam(name: 'RUN_UI_E2E', value: triggers.runUie2eEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200426 booleanParam(name: 'RUN_MGMT_CFM', value: triggers.runMgmtConformanceEnabled),
427 booleanParam(name: 'DEPLOY_CHILD_CLUSTER', value: triggers.deployChildEnabled),
428 booleanParam(name: 'UPGRADE_CHILD_CLUSTER', value: triggers.upgradeChildEnabled),
Владислав Наумов0dc99252020-11-13 13:30:48 +0100429 booleanParam(name: 'ATTACH_BYO', value: triggers.attachBYOEnabled),
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100430 booleanParam(name: 'UPGRADE_BYO', value: triggers.upgradeBYOEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200431 booleanParam(name: 'RUN_CHILD_CFM', value: triggers.runChildConformanceEnabled),
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +0400432 booleanParam(name: 'ALLOW_AWS_ON_DEMAND', value: triggers.awsOnDemandDemoEnabled || triggers.awsOnDemandRhelDemoEnabled),
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400433 booleanParam(name: 'ALLOW_VSPHERE_ON_DEMAND', value: triggers.vsphereOnDemandDemoEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200434 ]
Владислав Наумов92288d92020-07-13 18:36:21 +0200435
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200436 // customize multiregional demo
437 if (triggers.multiregionalConfiguration.enabled) {
438 parameters.add(string(name: 'MULTIREGION_SETUP',
439 value: "${triggers.multiregionalConfiguration.managementLocation},${triggers.multiregionalConfiguration.regionLocation}"
440 ))
441 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200442
Владислав Наумов92288d92020-07-13 18:36:21 +0200443 // Determine component team custom context
444 if (coreContext != '') {
445 common.infoMsg('Additional KaaS Core context detected, will be forwarded into kaas core cicd...')
446 def additionalParameters = generateKaaSVarsFromContext(coreContext)
Владислав Наумовbef51a92020-10-01 17:36:51 +0200447 parameters.addAll(additionalParameters)
Владислав Наумов92288d92020-07-13 18:36:21 +0200448 }
449
Владислав Наумовaa430612020-06-08 17:18:31 +0200450 def jobResults = []
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200451 jobs["kaas-core-openstack-patched-${component}"] = {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200452 try {
453 common.infoMsg('Deploy: patched KaaS demo with Openstack provider')
Владислав Наумов4aa112d2020-06-16 18:52:21 +0200454 os_job_info = build job: "kaas-testing-core-openstack-workflow-${component}", parameters: parameters, wait: true
455 def build_description = os_job_info.getDescription()
Владислав Наумовd044e842020-06-17 15:33:43 +0200456 def build_result = os_job_info.getResult()
457 jobResults.add(build_result)
458
Владислав Наумовf86b1112020-06-09 14:04:48 +0200459 if (build_description) {
460 currentBuild.description += build_description
461 }
462 } finally {
Владислав Наумов6d741fa2020-06-17 17:35:43 +0200463 common.infoMsg('Patched KaaS demo with Openstack provider finished')
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200464 }
465 }
466 if (triggers.awsOnDemandDemoEnabled) {
Владислав Наумов59281952020-07-29 16:43:49 +0200467 common.infoMsg('AWS demo triggered, need to sync artifacts in the public-ci cdn..')
468 switch (component) {
469 case 'iam':
470 build job: 'cdn-binary-dev-replication-iam', propagate: true, wait: true
471 break
472 case 'lcm':
473 build job: 'cdn-binary-dev-replication-lcm', propagate: true, wait: true
474 break
475 }
476
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200477 jobs["kaas-core-aws-patched-${component}"] = {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200478 try {
479 common.infoMsg('Deploy: patched KaaS demo with AWS provider')
Владислав Наумов4aa112d2020-06-16 18:52:21 +0200480 aws_job_info = build job: "kaas-testing-core-aws-workflow-${component}", parameters: parameters, wait: true
481 def build_description = aws_job_info.getDescription()
Владислав Наумовd044e842020-06-17 15:33:43 +0200482 def build_result = aws_job_info.getResult()
483 jobResults.add(build_result)
484
Владислав Наумовf86b1112020-06-09 14:04:48 +0200485 if (build_description) {
486 currentBuild.description += build_description
487 }
488 } finally {
Владислав Наумов6d741fa2020-06-17 17:35:43 +0200489 common.infoMsg('Patched KaaS demo with AWS provider finished')
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200490 }
491 }
492 }
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400493 if (triggers.vsphereOnDemandDemoEnabled) {
494 jobs["kaas-core-vsphere-patched-${component}"] = {
495 try {
496 common.infoMsg('Deploy: patched KaaS demo with VSPHERE provider')
497 vsphere_job_info = build job: "kaas-testing-core-vsphere-workflow-${component}", parameters: parameters, wait: true
498 def build_description = vsphere_job_info.getDescription()
499 def build_result = vsphere_job_info.getResult()
500 jobResults.add(build_result)
501
502 if (build_description) {
503 currentBuild.description += build_description
504 }
505 } finally {
506 common.infoMsg('Patched KaaS demo with VSPHERE provider finished')
507 }
508 }
509 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200510
511 common.infoMsg('Trigger KaaS demo deployments according to defined provider set')
512 // Limit build concurency workaround examples: https://issues.jenkins-ci.org/browse/JENKINS-44085
513 parallel jobs
Владислав Наумовaa430612020-06-08 17:18:31 +0200514
515 if (jobResults.contains('FAILURE')) {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200516 common.infoMsg('One of parallel downstream jobs is failed, mark executor job as failed')
Владислав Наумовaa430612020-06-08 17:18:31 +0200517 currentBuild.result = 'FAILURE'
518 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200519}
Владислав Наумов30a516c2020-07-09 13:15:41 +0200520
521