blob: 6882315753d26be548a5831e53a43bd07beaff64 [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
Владислав Наумов44c64b72020-12-04 20:22:53 +010051 def seedMacOs = env.SEED_MACOS ? env.SEED_MACOS.toBoolean() : false
Владислав Наумов6c2afff2020-06-05 12:54:53 +020052 def deployChild = env.DEPLOY_CHILD_CLUSTER ? env.DEPLOY_CHILD_CLUSTER.toBoolean() : false
53 def upgradeChild = env.UPGRADE_CHILD_CLUSTER ? env.UPGRADE_CHILD_CLUSTER.toBoolean() : false
Владислав Наумов0dc99252020-11-13 13:30:48 +010054 def attachBYO = env.ATTACH_BYO ? env.ATTACH_BYO.toBoolean() : false
Владислав Наумовcdbd84e2020-12-01 16:51:09 +010055 def upgradeBYO = env.UPGRADE_BYO ? env.UPGRADE_BYO.toBoolean() : false
Владислав Наумов6c2afff2020-06-05 12:54:53 +020056 def upgradeMgmt = env.UPGRADE_MGMT_CLUSTER ? env.UPGRADE_MGMT_CLUSTER.toBoolean() : false
57 def runUie2e = env.RUN_UI_E2E ? env.RUN_UI_E2E.toBoolean() : false
58 def runMgmtConformance = env.RUN_MGMT_CFM ? env.RUN_MGMT_CFM.toBoolean() : false
59 def runChildConformance = env.RUN_CHILD_CFM ? env.RUN_CHILD_CFM.toBoolean() : false
60 def fetchServiceBinaries = env.FETCH_BINARIES_FROM_UPSTREAM ? env.FETCH_BINARIES_FROM_UPSTREAM.toBoolean() : false
Владислав Наумов765f3bd2020-09-07 18:09:24 +020061 // multiregion configuration from env variable: comma-separated string in form $mgmt_provider,$regional_provider
62 def multiregionalMappings = env.MULTIREGION_SETUP ? multiregionWorkflowParser(env.MULTIREGION_SETUP) : [
63 enabled: false,
64 managementLocation: '',
65 regionLocation: '',
66 ]
Владислав Наумов4eb1da32020-08-31 14:45:16 +020067
Владислав Наумовb8305e22021-02-10 17:23:12 +010068 // proxy customization
69 def proxyConfig = [
70 mgmtOffline: env.OFFLINE_MGMT_CLUSTER ? env.OFFLINE_MGMT_CLUSTER.toBoolean() : false, // TODO(vnaumov) add additonal vars for regional/child cluster ops
71 ]
72
Владислав Наумов4eb1da32020-08-31 14:45:16 +020073 // optional demo deployment customization
Владислав Наумов905dd362020-06-08 16:37:01 +020074 def awsOnDemandDemo = env.ALLOW_AWS_ON_DEMAND ? env.ALLOW_AWS_ON_DEMAND.toBoolean() : false
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +040075 def awsOnRhelDemo = false
Владислав Наумов6ec74302020-11-05 12:38:53 +010076 def vsphereOnDemandDemo = env.ALLOW_VSPHERE_ON_DEMAND ? env.ALLOW_VSPHERE_ON_DEMAND.toBoolean() : false
eromanovadf247c32020-12-25 15:44:13 +040077 def equinixOnAwsDemo = false
Владислав Наумов4eb1da32020-08-31 14:45:16 +020078 def enableOSDemo = true
azvyagintsev1761bdc2020-09-04 17:24:12 +030079 def enableBMDemo = true
vnaumov33747e12020-05-04 17:35:20 +020080
Владислав Наумов6c2afff2020-06-05 12:54:53 +020081 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
Владислав Наумовb8305e22021-02-10 17:23:12 +010082 if (commitMsg ==~ /(?s).*\[mgmt-proxy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-proxy.*/) {
83 proxyConfig['mgmtOffline'] = true
84 common.warningMsg('Forced running offline mgmt deployment, all provider CDN regions for mgmt deployment will be set to *public-ci* to verify proxy configuration')
85 }
Владислав Наумов44c64b72020-12-04 20:22:53 +010086 if (commitMsg ==~ /(?s).*\[seed-macos\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*seed-macos.*/) {
87 seedMacOs = true
88 }
vnaumov33747e12020-05-04 17:35:20 +020089 if (commitMsg ==~ /(?s).*\[child-deploy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-deploy.*/ || upgradeChild || runChildConformance) {
90 deployChild = true
91 }
92 if (commitMsg ==~ /(?s).*\[child-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-upgrade.*/) {
93 deployChild = true
94 upgradeChild = true
95 }
Владислав Наумов0dc99252020-11-13 13:30:48 +010096 if (commitMsg ==~ /(?s).*\[byo-attach\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-attach.*/) {
97 attachBYO = true
98 }
Владислав Наумовcdbd84e2020-12-01 16:51:09 +010099 if (commitMsg ==~ /(?s).*\[byo-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-upgrade.*/) {
100 attachBYO = true
101 upgradeBYO = true
102 }
103 if (commitMsg ==~ /(?s).*\[mgmt-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-upgrade.*/ || upgradeBYO) {
vnaumov33747e12020-05-04 17:35:20 +0200104 upgradeMgmt = true
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100105 if (upgradeBYO) {
106 // TODO (vnaumov) remove such dependency right after we can verify byo upgrade w/o mgmt upgrade
107 common.warningMsg('Forced running kaas mgmt upgrade scenario, due byo demo scenario trigger: \'[byo-upgrade]\' ')
108 }
vnaumov33747e12020-05-04 17:35:20 +0200109 }
110 if (commitMsg ==~ /(?s).*\[ui-e2e\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*ui-e2e.*/) {
111 runUie2e = true
112 }
113 if (commitMsg ==~ /(?s).*\[mgmt-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-cfm.*/) {
114 runMgmtConformance = true
115 }
116 if (commitMsg ==~ /(?s).*\[child-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-cfm.*/) {
117 runChildConformance = true
118 deployChild = true
119 }
120 if (commitMsg ==~ /(?s).*\[fetch.*binaries\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*fetch.*binaries.*/) {
121 fetchServiceBinaries = true
122 }
eromanovadf247c32020-12-25 15:44:13 +0400123 if (commitMsg ==~ /(?s).*\[equinix-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinix-demo.*/) {
124 equinixOnAwsDemo = true
125 common.warningMsg('Forced running child cluster deployment on EQUINIX METAL provider based on AWS management cluster, triggered on patchset using custom keyword: \'[equinix-demo]\' ')
126 }
127 if (commitMsg ==~ /(?s).*\[aws-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*aws-demo.*/ || attachBYO || upgradeBYO || seedMacOs || equinixOnAwsDemo) {
vnaumov33747e12020-05-04 17:35:20 +0200128 awsOnDemandDemo = true
eromanovadf247c32020-12-25 15:44:13 +0400129 if (attachBYO || upgradeBYO || seedMacOs || equinixOnAwsDemo) {
Владислав Наумов44c64b72020-12-04 20:22:53 +0100130 common.warningMsg('Forced running additional kaas deployment with AWS provider, due applied trigger cross dependencies, follow docs to clarify info')
Владислав Наумов0dc99252020-11-13 13:30:48 +0100131 }
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200132 }
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +0400133 if (commitMsg ==~ /(?s).*\[aws-rhel-demo\].*/) {
134 awsOnDemandDemo = false
135 awsOnRhelDemo = true
136 common.warningMsg('Forced running additional kaas deployment with AWS provider on RHEL, triggered on patchset using custom keyword: \'[aws-rhel-demo]\'.' +
137 'Upgrade scenario for Mgmt or Child cluster is not supported currently in such deployment')
138 }
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400139 if (commitMsg ==~ /(?s).*\[vsphere-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*vsphere-demo.*/) {
140 vsphereOnDemandDemo = true
141 common.warningMsg('Forced running additional kaas deployment with VSPHERE provider, triggered on patchset using custom keyword: \'[vsphere-demo]\' ')
142 }
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200143 if (commitMsg ==~ /(?s).*\[disable-os-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-os-demo\.*/) {
144 enableOSDemo = false
145 common.errorMsg('Openstack demo deployment will be aborted, VF -1 will be set')
vnaumov33747e12020-05-04 17:35:20 +0200146 }
147
azvyagintsev1761bdc2020-09-04 17:24:12 +0300148 if (commitMsg ==~ /(?s).*\[disable-bm-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-bm-demo\.*/) {
149 enableBMDemo = false
150 common.errorMsg('BM demo deployment will be aborted, VF -1 will be set')
151 }
152
vnaumov33747e12020-05-04 17:35:20 +0200153 // TODO (vnaumov) remove below condition after moving all releases to UCP
154 def ucpChildMatches = (commitMsg =~ /(\[child-ucp\s*ucp-.*?\])/)
155 if (ucpChildMatches.size() > 0) {
156 deployChild = true
157 common.warningMsg('Forced UCP based child deployment triggered on patchset using custom keyword: \'[child-ucp ucp-5-1-0-3-3-0-example]\' ')
158
159 // TODO(vnaumov) delete after ucp upgrades support
160 common.errorMsg('Child upgrade test will be skipped, UCP upgrades temporally disabled')
161 upgradeChild = false
162 }
163
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200164 // multiregional tests
165 def multiRegionalMatches = (commitMsg =~ /(\[multiregion\s*.*?\])/)
166 if (multiRegionalMatches.size() > 0) {
167 multiregionalMappings = multiregionWorkflowParser(multiRegionalMatches)
168 }
169 switch (multiregionalMappings['managementLocation']) {
170 case 'aws':
Владислав Наумов53b07e52021-01-07 15:08:27 +0100171 common.warningMsg('Forced running additional kaas deployment with AWS provider according multiregional demo request')
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200172 awsOnDemandDemo = true
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +0400173 if (awsOnRhelDemo) {
174 // Run only one variant: standard AWS deployment (on Ubuntu) or on RHEL
175 awsOnDemandDemo = false
176 }
Владислав Наумов53b07e52021-01-07 15:08:27 +0100177
178 if (multiregionalMappings['regionLocation'] != 'aws' && seedMacOs) { // macstadium seed node has access only to *public* providers
179 error('incompatible triggers: [seed-macos] and multiregional deployment based on *private* regional provider cannot be applied simultaneously')
180 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200181 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200182 case 'os':
183 if (enableOSDemo == false) {
184 error('incompatible triggers: [disable-os-demo] and multiregional deployment based on OSt management region cannot be applied simultaneously')
185 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200186 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200187 }
188
Владислав Наумовb8305e22021-02-10 17:23:12 +0100189 // CDN configuration
190 def cdnConfig = [
191 mgmt: [
192 openstack: (proxyConfig['mgmtOffline'] == true) ? 'public-ci' : 'internal-ci',
193 vsphere: (proxyConfig['mgmtOffline'] == true) ? 'public-ci' : 'internal-ci',
194 aws: 'public-ci',
195 ], // TODO(vnaumov) add additonal vars for regional cluster cdn ops
196 ]
197
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100198 // calculate weight of current demo run to manage lockable resources
199 def demoWeight = (deployChild) ? 2 : 1 // management = 1, child = 1
200
vnaumov33747e12020-05-04 17:35:20 +0200201 common.infoMsg("""
Владислав Наумовb8305e22021-02-10 17:23:12 +0100202 CDN deployment configuration: ${cdnConfig}
203 MCC offline deployment configuration: ${proxyConfig}
Владислав Наумов44c64b72020-12-04 20:22:53 +0100204 Use MacOS node as seed: ${seedMacOs}
vnaumov33747e12020-05-04 17:35:20 +0200205 Child cluster deployment scheduled: ${deployChild}
206 Child cluster release upgrade scheduled: ${upgradeChild}
207 Child conformance testing scheduled: ${runChildConformance}
Владислав Наумов0dc99252020-11-13 13:30:48 +0100208 BYO cluster attachment scheduled: ${attachBYO}
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100209 Attached BYO cluster upgrade test scheduled: ${upgradeBYO}
vnaumov33747e12020-05-04 17:35:20 +0200210 Mgmt cluster release upgrade scheduled: ${upgradeMgmt}
211 Mgmt conformance testing scheduled: ${runMgmtConformance}
212 Mgmt UI e2e testing scheduled: ${runUie2e}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200213 AWS provider deployment scheduled: ${awsOnDemandDemo}
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +0400214 AWS provider on RHEL deployment scheduled: ${awsOnRhelDemo}
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400215 VSPHERE provider deployment scheduled: ${vsphereOnDemandDemo}
eromanovadf247c32020-12-25 15:44:13 +0400216 EQUINIX child cluster deployment scheduled: ${equinixOnAwsDemo}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200217 OS provider deployment scheduled: ${enableOSDemo}
azvyagintsev1761bdc2020-09-04 17:24:12 +0300218 BM provider deployment scheduled: ${enableBMDemo}
Владислав Наумовf793fe32020-09-11 15:19:19 +0200219 Multiregional configuration: ${multiregionalMappings}
vnaumov33747e12020-05-04 17:35:20 +0200220 Service binaries fetching scheduled: ${fetchServiceBinaries}
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100221 Current weight of the demo run: ${demoWeight} (Used to manage lockable resources)
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200222 Triggers: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/""")
vnaumov33747e12020-05-04 17:35:20 +0200223 return [
Владислав Наумовb8305e22021-02-10 17:23:12 +0100224 cdnConfig : cdnConfig,
225 proxyConfig : proxyConfig,
Владислав Наумов44c64b72020-12-04 20:22:53 +0100226 useMacOsSeedNode : seedMacOs,
azvyagintseva12230a2020-06-05 13:24:06 +0300227 deployChildEnabled : deployChild,
228 upgradeChildEnabled : upgradeChild,
229 runChildConformanceEnabled : runChildConformance,
Владислав Наумов0dc99252020-11-13 13:30:48 +0100230 attachBYOEnabled : attachBYO,
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100231 upgradeBYOEnabled : upgradeBYO,
azvyagintseva12230a2020-06-05 13:24:06 +0300232 upgradeMgmtEnabled : upgradeMgmt,
233 runUie2eEnabled : runUie2e,
234 runMgmtConformanceEnabled : runMgmtConformance,
vnaumov33747e12020-05-04 17:35:20 +0200235 fetchServiceBinariesEnabled: fetchServiceBinaries,
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200236 awsOnDemandDemoEnabled : awsOnDemandDemo,
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +0400237 awsOnDemandRhelDemoEnabled : awsOnRhelDemo,
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400238 vsphereOnDemandDemoEnabled : vsphereOnDemandDemo,
eromanovadf247c32020-12-25 15:44:13 +0400239 equinixOnAwsDemoEnabled : equinixOnAwsDemo,
azvyagintsev1761bdc2020-09-04 17:24:12 +0300240 bmDemoEnabled : enableBMDemo,
Владислав Наумовf793fe32020-09-11 15:19:19 +0200241 osDemoEnabled : enableOSDemo,
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100242 multiregionalConfiguration : multiregionalMappings,
243 demoWeight : demoWeight]
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200244}
245
246/**
247 * Determine management and regional setup for demo workflow scenario
248 *
249 *
250 * @param: keyword (string) string , represents keyworkd trigger, specified in gerrit commit body, like `[multiregion aws,os]`
251 or Jenkins environment string variable in form like 'aws,os'
252 * @return (map)[
253 enabled: (bool),
254 * managementLocation: (string), //aws,os
255 * regionLocation: (string), //aws,os
256 * ]
257 */
258def multiregionWorkflowParser(keyword) {
Владислав Наумов8c0c39d2020-09-11 14:46:48 +0200259 def common = new com.mirantis.mk.Common()
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200260 def supportedManagementProviders = ['os', 'aws']
261 def supportedRegionalProviders = ['os']
262
263 def clusterTypes = ''
Владислав Наумов38ed7bf2020-09-11 14:43:39 +0200264 if (keyword.toString().contains('multiregion')) {
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200265 common.infoMsg('Multiregion definition configured via gerrit keyword trigger')
266 clusterTypes = keyword[0][0].split('multiregion')[1].replaceAll('[\\[\\]]', '').trim().split(',')
267 } else {
268 common.infoMsg('Multiregion definition configured via environment variable')
269 clusterTypes = keyword.trim().split(',')
270 }
271
272 if (clusterTypes.size() != 2) {
Владислав Наумов482fb502020-10-30 17:59:27 +0100273 error("Incorrect regions definiton, valid scheme: [multiregion ${management}, ${region}], got: ${clusterTypes}")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200274 }
275
Владислав Наумовf793fe32020-09-11 15:19:19 +0200276 def desiredManagementProvider = clusterTypes[0].trim()
277 def desiredRegionalProvider = clusterTypes[1].trim()
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200278 if (! supportedManagementProviders.contains(desiredManagementProvider) || ! supportedRegionalProviders.contains(desiredRegionalProvider)) {
279 error("""unsupported management <-> regional bundle, available options:
Владислав Наумовf793fe32020-09-11 15:19:19 +0200280 management providers list - ${supportedManagementProviders}
281 regional providers list - ${supportedRegionalProviders}""")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200282 }
283
284 return [
285 enabled: true,
286 managementLocation: desiredManagementProvider,
287 regionLocation: desiredRegionalProvider,
288 ]
vnaumov33747e12020-05-04 17:35:20 +0200289}
290
291/**
292 * Determine if custom si tests/pipelines refspec forwarded from gerrit change request
293
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200294 * Keyword list: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/
vnaumov33747e12020-05-04 17:35:20 +0200295 * Used for components team to test component changes w/ custom SI refspecs using kaas/core deployment jobs
296 * Example scheme:
297 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
298 * manage refspecs through Jenkins Job Parameters
299 *
azvyagintseva12230a2020-06-05 13:24:06 +0300300 * @return (map)[* siTests: (string) final refspec for si-tests
vnaumov33747e12020-05-04 17:35:20 +0200301 * siPipelines: (string) final refspec for si-pipelines
302 * ]
303 */
304def checkCustomSIRefspec() {
vnaumovbdb90222020-05-04 18:25:50 +0200305 def common = new com.mirantis.mk.Common()
306
vnaumov33747e12020-05-04 17:35:20 +0200307 // Available triggers and its sane defaults
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200308 def siTestsRefspec = env.SI_TESTS_REFSPEC ?: 'master'
309 def siPipelinesRefspec = env.SI_PIPELINES_REFSPEC ?: 'master'
Владислав Наумов2db15e22020-07-14 12:29:22 +0200310 def siTestsDockerImage = env.SI_TESTS_DOCKER_IMAGE ?: 'docker-dev-kaas-local.docker.mirantis.net/mirantis/kaas/si-test'
311 def siTestsDockerImageTag = env.SI_TESTS_DOCKER_IMAGE_TAG ?: 'master'
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200312 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
vnaumov33747e12020-05-04 17:35:20 +0200313
314 def siTestMatches = (commitMsg =~ /(\[si-tests-ref\s*refs\/changes\/.*?\])/)
315 def siPipelinesMatches = (commitMsg =~ /(\[si-pipelines-ref\s*refs\/changes\/.*?\])/)
316
317 if (siTestMatches.size() > 0) {
318 siTestsRefspec = siTestMatches[0][0].split('si-tests-ref')[1].replaceAll('[\\[\\]]', '').trim()
Владислав Наумов2db15e22020-07-14 12:29:22 +0200319 siTestsDockerImage = "docker-dev-local.docker.mirantis.net/review/kaas-si-test-${siTestsRefspec.split('/')[-2]}"
320 siTestsDockerImageTag = siTestsRefspec.split('/')[-1]
vnaumov33747e12020-05-04 17:35:20 +0200321 }
322 if (siPipelinesMatches.size() > 0) {
323 siPipelinesRefspec = siPipelinesMatches[0][0].split('si-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
324 }
325
326 common.infoMsg("""
327 kaas/si-pipelines will be fetched from: ${siPipelinesRefspec}
328 kaas/si-tests will be fetched from: ${siTestsRefspec}
Владислав Наумов2db15e22020-07-14 12:29:22 +0200329 kaas/si-tests as dockerImage will be fetched from: ${siTestsDockerImage}:${siTestsDockerImageTag}
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200330 Keywords: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/""")
Владислав Наумов2db15e22020-07-14 12:29:22 +0200331 return [siTests: siTestsRefspec, siPipelines: siPipelinesRefspec, siTestsDockerImage: siTestsDockerImage, siTestsDockerImageTag: siTestsDockerImageTag]
vnaumov33747e12020-05-04 17:35:20 +0200332}
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200333
Владислав Наумов9080f372020-06-08 13:57:16 +0200334/**
Владислав Наумов418042b2020-07-09 18:31:10 +0200335 * Parse additional configuration for kaas component CICD repo
Владислав Наумов30a516c2020-07-09 13:15:41 +0200336 * @param configurationFile (str) path to configuration file in yaml format
337 *
338 * @return (map)[ siTestsFeatureFlags (string) dedicated feature flags that will be used in SI tests,
339 * ]
340 */
341def parseKaaSComponentCIParameters(configurationFile){
342 def common = new com.mirantis.mk.Common()
343 def ciConfig = readYaml file: configurationFile
344 def ciSpec = [
345 siTestsFeatureFlags: env.SI_TESTS_FEATURE_FLAGS ?: '',
346 ]
347
348 if (ciConfig.containsKey('si-tests-feature-flags')) {
349 common.infoMsg("""SI tests feature flags customization detected,
350 results will be merged with existing flags: [${ciSpec['siTestsFeatureFlags']}] identification...""")
351
352 def ffMeta = ciSpec['siTestsFeatureFlags'].tokenize(',').collect { it.trim() }
353 ffMeta.addAll(ciConfig['si-tests-feature-flags'])
Владислав Наумов30a516c2020-07-09 13:15:41 +0200354
Владислав Наумовcb5ffca2020-07-14 15:28:36 +0200355 ciSpec['siTestsFeatureFlags'] = ffMeta.unique().join(',')
Владислав Наумов30a516c2020-07-09 13:15:41 +0200356 common.infoMsg("SI tests custom feature flags: ${ciSpec['siTestsFeatureFlags']}")
357 }
358
359 common.infoMsg("""Additional ci configuration parsed successfully:
360 siTestsFeatureFlags: ${ciSpec['siTestsFeatureFlags']}""")
361 return ciSpec
362}
363
364/**
365 * Determine if custom kaas core/pipelines refspec forwarded from gerrit change request
Владислав Наумов9080f372020-06-08 13:57:16 +0200366
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200367 * Keyword list: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/
Владислав Наумов9080f372020-06-08 13:57:16 +0200368 * Used for components team to test component changes w/ custom Core refspecs using kaas/core deployment jobs
369 * Example scheme:
370 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
371 * manage refspecs through Jenkins Job Parameters
372 *
373 * @return (map)[ core: (string) final refspec for kaas/core
374 * corePipelines: (string) final refspec for pipelines in kaas/core
375 * ]
376 */
377def checkCustomCoreRefspec() {
378 def common = new com.mirantis.mk.Common()
379
380 // Available triggers and its sane defaults
381 def coreRefspec = env.KAAS_CORE_REFSPEC ?: 'master'
382 // by default using value of GERRIT_REFSPEC parameter in *kaas/core jobs*
383 def corePipelinesRefspec = env.KAAS_PIPELINE_REFSPEC ?: '\$GERRIT_REFSPEC'
384 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
385
386 def coreMatches = (commitMsg =~ /(\[core-ref\s*refs\/changes\/.*?\])/)
387 def corePipelinesMatches = (commitMsg =~ /(\[core-pipelines-ref\s*refs\/changes\/.*?\])/)
388
389 if (coreMatches.size() > 0) {
390 coreRefspec = coreMatches[0][0].split('core-ref')[1].replaceAll('[\\[\\]]', '').trim()
391 }
392 if (corePipelinesMatches.size() > 0) {
393 corePipelinesRefspec = corePipelinesMatches[0][0].split('core-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
394 }
395
396 common.infoMsg("""
397 kaas/core will be fetched from: ${coreRefspec}
398 kaas/core pipelines will be fetched from: ${corePipelinesRefspec}
Владислав Наумов5a523ef2020-07-29 13:33:38 +0200399 Keywords: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/""")
Владислав Наумов9080f372020-06-08 13:57:16 +0200400 return [core: coreRefspec, corePipelines: corePipelinesRefspec]
401}
402
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200403
404/**
Владислав Наумов92288d92020-07-13 18:36:21 +0200405 * generate Jenkins Parameter objects from from text parameter with additonal kaas core context
406 * needed to forward inside kaas core set of jobs
407 *
408 * @param context (string) Representation of the string enviroment variables needed for kaas core jobs in yaml format
409 * @return (list)[ string(name: '', value: ''),
410 * ]
411 */
412def generateKaaSVarsFromContext(context) {
413 def common = new com.mirantis.mk.Common()
414 def parameters = []
415 def config = readYaml text: context
416
417 config.each { k,v ->
418 common.infoMsg("Custom KaaS Core context parameter: ${k}=${v}")
419 parameters.add(string(name: k, value: v))
420 }
421
422 return parameters
423}
424
425/**
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200426 * 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 +0200427 * Keyword list: https://docs.google.com/document/d/1SSPD8ZdljbqmNl_FEAvTHUTow9Ki8NIMu82IcAVhzXw/
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200428 * Used for components team to test component changes w/ customized SI tests/refspecs using kaas/core deployment jobs
429 *
Владислав Наумов418042b2020-07-09 18:31:10 +0200430 * @param: component (string) component name [iam, lcm, stacklight]
431 * @param: patchSpec (string) Patch for kaas/cluster releases in json format
432 * @param: configurationFile (string) Additional file for component repo CI config in yaml format
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200433 */
Владислав Наумов92288d92020-07-13 18:36:21 +0200434def triggerPatchedComponentDemo(component, patchSpec = '', configurationFile = '.ci-parameters.yaml', coreContext = '') {
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200435 def common = new com.mirantis.mk.Common()
436 // Determine if custom trigger keywords forwarded from gerrit
437 def triggers = checkDeploymentTestSuite()
438 // Determine SI refspecs
439 def siRefspec = checkCustomSIRefspec()
Владислав Наумов9080f372020-06-08 13:57:16 +0200440 // Determine Core refspecs
441 def coreRefspec = checkCustomCoreRefspec()
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200442
Владислав Наумов418042b2020-07-09 18:31:10 +0200443 // Determine component repo ci configuration
444 def ciSpec = [:]
445 def componentFeatureFlags = env.SI_TESTS_FEATURE_FLAGS ?: ''
446 if (fileExists(configurationFile)) {
447 common.infoMsg('Component CI configuration file detected, parsing...')
448 ciSpec = parseKaaSComponentCIParameters(configurationFile)
449 componentFeatureFlags = ciSpec['siTestsFeatureFlags']
450 } else {
451 common.warningMsg('''Component CI configuration file is not exists,
Владислав Наумовc17dd552020-07-29 17:07:38 +0200452 several code-management features may be unavailable,
Владислав Наумов92288d92020-07-13 18:36:21 +0200453 follow https://mirantis.jira.com/wiki/spaces/QA/pages/2310832276/SI-tests+feature+flags#%5BUpdated%5D-Using-a-feature-flag
454 to create the configuration file''')
Владислав Наумов418042b2020-07-09 18:31:10 +0200455 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200456 def jobs = [:]
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200457 def parameters = [
Владислав Наумов9080f372020-06-08 13:57:16 +0200458 string(name: 'GERRIT_REFSPEC', value: coreRefspec.core),
459 string(name: 'KAAS_PIPELINE_REFSPEC', value: coreRefspec.corePipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200460 string(name: 'SI_TESTS_REFSPEC', value: siRefspec.siTests),
Владислав Наумов418042b2020-07-09 18:31:10 +0200461 string(name: 'SI_TESTS_FEATURE_FLAGS', value: componentFeatureFlags),
Владислав Наумов2db15e22020-07-14 12:29:22 +0200462 string(name: 'SI_TESTS_DOCKER_IMAGE', value: siRefspec.siTestsDockerImage),
463 string(name: 'SI_TESTS_DOCKER_IMAGE_TAG', value: siRefspec.siTestsDockerImageTag),
Владислав Наумов4a5c3242020-06-08 14:36:11 +0200464 string(name: 'SI_PIPELINES_REFSPEC', value: siRefspec.siPipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200465 string(name: 'CUSTOM_RELEASE_PATCH_SPEC', value: patchSpec),
Владислав Наумовb8305e22021-02-10 17:23:12 +0100466 booleanParam(name: 'OFFLINE_MGMT_CLUSTER', value: triggers.proxyConfig['mgmtOffline']),
Владислав Наумов44c64b72020-12-04 20:22:53 +0100467 booleanParam(name: 'SEED_MACOS', value: triggers.useMacOsSeedNode),
Владислав Наумов080d9412020-07-29 13:05:14 +0200468 booleanParam(name: 'UPGRADE_MGMT_CLUSTER', value: triggers.upgradeMgmtEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200469 booleanParam(name: 'RUN_UI_E2E', value: triggers.runUie2eEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200470 booleanParam(name: 'RUN_MGMT_CFM', value: triggers.runMgmtConformanceEnabled),
471 booleanParam(name: 'DEPLOY_CHILD_CLUSTER', value: triggers.deployChildEnabled),
472 booleanParam(name: 'UPGRADE_CHILD_CLUSTER', value: triggers.upgradeChildEnabled),
Владислав Наумов0dc99252020-11-13 13:30:48 +0100473 booleanParam(name: 'ATTACH_BYO', value: triggers.attachBYOEnabled),
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100474 booleanParam(name: 'UPGRADE_BYO', value: triggers.upgradeBYOEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200475 booleanParam(name: 'RUN_CHILD_CFM', value: triggers.runChildConformanceEnabled),
Ivan Berezovskiy07e1de12020-10-09 13:07:05 +0400476 booleanParam(name: 'ALLOW_AWS_ON_DEMAND', value: triggers.awsOnDemandDemoEnabled || triggers.awsOnDemandRhelDemoEnabled),
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400477 booleanParam(name: 'ALLOW_VSPHERE_ON_DEMAND', value: triggers.vsphereOnDemandDemoEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200478 ]
Владислав Наумов92288d92020-07-13 18:36:21 +0200479
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200480 // customize multiregional demo
481 if (triggers.multiregionalConfiguration.enabled) {
482 parameters.add(string(name: 'MULTIREGION_SETUP',
483 value: "${triggers.multiregionalConfiguration.managementLocation},${triggers.multiregionalConfiguration.regionLocation}"
484 ))
485 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200486
Владислав Наумов92288d92020-07-13 18:36:21 +0200487 // Determine component team custom context
488 if (coreContext != '') {
489 common.infoMsg('Additional KaaS Core context detected, will be forwarded into kaas core cicd...')
490 def additionalParameters = generateKaaSVarsFromContext(coreContext)
Владислав Наумовbef51a92020-10-01 17:36:51 +0200491 parameters.addAll(additionalParameters)
Владислав Наумов92288d92020-07-13 18:36:21 +0200492 }
493
Владислав Наумовaa430612020-06-08 17:18:31 +0200494 def jobResults = []
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200495 jobs["kaas-core-openstack-patched-${component}"] = {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200496 try {
497 common.infoMsg('Deploy: patched KaaS demo with Openstack provider')
Владислав Наумов4aa112d2020-06-16 18:52:21 +0200498 os_job_info = build job: "kaas-testing-core-openstack-workflow-${component}", parameters: parameters, wait: true
499 def build_description = os_job_info.getDescription()
Владислав Наумовd044e842020-06-17 15:33:43 +0200500 def build_result = os_job_info.getResult()
501 jobResults.add(build_result)
502
Владислав Наумовf86b1112020-06-09 14:04:48 +0200503 if (build_description) {
504 currentBuild.description += build_description
505 }
506 } finally {
Владислав Наумов6d741fa2020-06-17 17:35:43 +0200507 common.infoMsg('Patched KaaS demo with Openstack provider finished')
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200508 }
509 }
510 if (triggers.awsOnDemandDemoEnabled) {
Владислав Наумов59281952020-07-29 16:43:49 +0200511 common.infoMsg('AWS demo triggered, need to sync artifacts in the public-ci cdn..')
512 switch (component) {
513 case 'iam':
514 build job: 'cdn-binary-dev-replication-iam', propagate: true, wait: true
515 break
516 case 'lcm':
517 build job: 'cdn-binary-dev-replication-lcm', propagate: true, wait: true
518 break
519 }
520
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200521 jobs["kaas-core-aws-patched-${component}"] = {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200522 try {
523 common.infoMsg('Deploy: patched KaaS demo with AWS provider')
Владислав Наумов4aa112d2020-06-16 18:52:21 +0200524 aws_job_info = build job: "kaas-testing-core-aws-workflow-${component}", parameters: parameters, wait: true
525 def build_description = aws_job_info.getDescription()
Владислав Наумовd044e842020-06-17 15:33:43 +0200526 def build_result = aws_job_info.getResult()
527 jobResults.add(build_result)
528
Владислав Наумовf86b1112020-06-09 14:04:48 +0200529 if (build_description) {
530 currentBuild.description += build_description
531 }
532 } finally {
Владислав Наумов6d741fa2020-06-17 17:35:43 +0200533 common.infoMsg('Patched KaaS demo with AWS provider finished')
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200534 }
535 }
536 }
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400537 if (triggers.vsphereOnDemandDemoEnabled) {
538 jobs["kaas-core-vsphere-patched-${component}"] = {
539 try {
540 common.infoMsg('Deploy: patched KaaS demo with VSPHERE provider')
541 vsphere_job_info = build job: "kaas-testing-core-vsphere-workflow-${component}", parameters: parameters, wait: true
542 def build_description = vsphere_job_info.getDescription()
543 def build_result = vsphere_job_info.getResult()
544 jobResults.add(build_result)
545
546 if (build_description) {
547 currentBuild.description += build_description
548 }
549 } finally {
550 common.infoMsg('Patched KaaS demo with VSPHERE provider finished')
551 }
552 }
553 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200554
555 common.infoMsg('Trigger KaaS demo deployments according to defined provider set')
556 // Limit build concurency workaround examples: https://issues.jenkins-ci.org/browse/JENKINS-44085
557 parallel jobs
Владислав Наумовaa430612020-06-08 17:18:31 +0200558
559 if (jobResults.contains('FAILURE')) {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200560 common.infoMsg('One of parallel downstream jobs is failed, mark executor job as failed')
Владислав Наумовaa430612020-06-08 17:18:31 +0200561 currentBuild.result = 'FAILURE'
562 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200563}
Владислав Наумов30a516c2020-07-09 13:15:41 +0200564
565