blob: ce6a7adc6aa38150b289774bab56f26429def4a3 [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
Владислав Наумов81777472021-03-09 15:14:27 +040035 * Keyword list: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md
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
Mikhail Ivanov74504372021-05-21 17:01:06 +040054 def customChildRelease = env.KAAS_CHILD_CLUSTER_RELEASE_NAME ? env.KAAS_CHILD_CLUSTER_RELEASE_NAME : ''
Владислав Наумов0dc99252020-11-13 13:30:48 +010055 def attachBYO = env.ATTACH_BYO ? env.ATTACH_BYO.toBoolean() : false
Владислав Наумовcdbd84e2020-12-01 16:51:09 +010056 def upgradeBYO = env.UPGRADE_BYO ? env.UPGRADE_BYO.toBoolean() : false
Владислав Наумов6c2afff2020-06-05 12:54:53 +020057 def upgradeMgmt = env.UPGRADE_MGMT_CLUSTER ? env.UPGRADE_MGMT_CLUSTER.toBoolean() : false
58 def runUie2e = env.RUN_UI_E2E ? env.RUN_UI_E2E.toBoolean() : false
59 def runMgmtConformance = env.RUN_MGMT_CFM ? env.RUN_MGMT_CFM.toBoolean() : false
60 def runChildConformance = env.RUN_CHILD_CFM ? env.RUN_CHILD_CFM.toBoolean() : false
61 def fetchServiceBinaries = env.FETCH_BINARIES_FROM_UPSTREAM ? env.FETCH_BINARIES_FROM_UPSTREAM.toBoolean() : false
Владислав Наумов765f3bd2020-09-07 18:09:24 +020062 // multiregion configuration from env variable: comma-separated string in form $mgmt_provider,$regional_provider
63 def multiregionalMappings = env.MULTIREGION_SETUP ? multiregionWorkflowParser(env.MULTIREGION_SETUP) : [
64 enabled: false,
65 managementLocation: '',
66 regionLocation: '',
67 ]
Владислав Наумов4eb1da32020-08-31 14:45:16 +020068
Владислав Наумовb8305e22021-02-10 17:23:12 +010069 // proxy customization
70 def proxyConfig = [
Владислав Наумовf8f23fa2021-04-01 16:57:52 +020071 mgmtOffline: env.OFFLINE_MGMT_CLUSTER ? env.OFFLINE_MGMT_CLUSTER.toBoolean() : false,
72 childOffline: env.OFFLINE_CHILD_CLUSTER ? env.OFFLINE_CHILD_CLUSTER.toBoolean() : false,
Владислав Наумов257ea132021-04-14 14:44:13 +020073 childProxy: env.PROXY_CHILD_CLUSTER ? env.PROXY_CHILD_CLUSTER.toBoolean() : false,
Владислав Наумовb8305e22021-02-10 17:23:12 +010074 ]
75
Владислав Наумов4eb1da32020-08-31 14:45:16 +020076 // optional demo deployment customization
Владислав Наумов905dd362020-06-08 16:37:01 +020077 def awsOnDemandDemo = env.ALLOW_AWS_ON_DEMAND ? env.ALLOW_AWS_ON_DEMAND.toBoolean() : false
Владислав Наумовe021b022021-05-06 11:26:38 +020078 def equinixOnDemandDemo = env.ALLOW_EQUINIX_ON_DEMAND ? env.ALLOW_EQUINIX_ON_DEMAND.toBoolean() : false
Владислав Наумовf3715802021-05-03 18:06:45 +020079 def equinixOnAwsDemo = env.EQUINIX_ON_AWS_DEMO ? env.EQUINIX_ON_AWS_DEMO.toBoolean() : false
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +040080 def enableVsphereDemo = true
Владислав Наумов4eb1da32020-08-31 14:45:16 +020081 def enableOSDemo = true
azvyagintsev1761bdc2020-09-04 17:24:12 +030082 def enableBMDemo = true
vnaumov33747e12020-05-04 17:35:20 +020083
Владислав Наумов6c2afff2020-06-05 12:54:53 +020084 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
Владислав Наумовb8305e22021-02-10 17:23:12 +010085 if (commitMsg ==~ /(?s).*\[mgmt-proxy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-proxy.*/) {
86 proxyConfig['mgmtOffline'] = true
Владислав Наумов70c02422021-04-19 14:29:41 +020087 common.warningMsg('Forced running offline mgmt deployment, some provider CDN regions for mgmt deployment may be set to *public-ci* to verify proxy configuration')
Владислав Наумовb8305e22021-02-10 17:23:12 +010088 }
Владислав Наумов44c64b72020-12-04 20:22:53 +010089 if (commitMsg ==~ /(?s).*\[seed-macos\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*seed-macos.*/) {
90 seedMacOs = true
91 }
vnaumov33747e12020-05-04 17:35:20 +020092 if (commitMsg ==~ /(?s).*\[child-deploy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-deploy.*/ || upgradeChild || runChildConformance) {
93 deployChild = true
94 }
95 if (commitMsg ==~ /(?s).*\[child-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-upgrade.*/) {
96 deployChild = true
97 upgradeChild = true
98 }
Mikhail Ivanov76d69952021-06-04 16:06:45 +040099 def deployMatches = (commitMsg =~ /(\[child-deploy\s*(\w|\-)+?\])/)
Mikhail Ivanov74504372021-05-21 17:01:06 +0400100 if (deployMatches.size() > 0) {
101 // override child version when it set explicitly
102 deployChild = true
Mikhail Ivanoved543492021-05-24 16:26:55 +0400103 customChildRelease = deployMatches[0][0].split('child-deploy')[1].replaceAll('[\\[\\]]', '').trim()
Mikhail Ivanov74504372021-05-21 17:01:06 +0400104 common.warningMsg("Forced child deployment using custom release version ${customChildRelease}")
105 }
Владислав Наумов0dc99252020-11-13 13:30:48 +0100106 if (commitMsg ==~ /(?s).*\[byo-attach\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-attach.*/) {
107 attachBYO = true
108 }
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100109 if (commitMsg ==~ /(?s).*\[byo-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-upgrade.*/) {
110 attachBYO = true
111 upgradeBYO = true
112 }
Владислав Наумов7f8c9872021-03-08 17:33:08 +0400113 if (commitMsg ==~ /(?s).*\[mgmt-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-upgrade.*/) {
vnaumov33747e12020-05-04 17:35:20 +0200114 upgradeMgmt = true
115 }
116 if (commitMsg ==~ /(?s).*\[ui-e2e\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*ui-e2e.*/) {
117 runUie2e = true
118 }
119 if (commitMsg ==~ /(?s).*\[mgmt-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-cfm.*/) {
120 runMgmtConformance = true
121 }
122 if (commitMsg ==~ /(?s).*\[child-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-cfm.*/) {
123 runChildConformance = true
124 deployChild = true
125 }
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200126 if (commitMsg ==~ /(?s).*\[child-offline\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-offline.*/) {
127 proxyConfig['childOffline'] = true
128 deployChild = true
129 }
Владислав Наумов257ea132021-04-14 14:44:13 +0200130 if (commitMsg ==~ /(?s).*\[child-proxy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-proxy.*/) {
131 proxyConfig['childOffline'] = true
132 proxyConfig['childProxy'] = true
133 deployChild = true
134 }
vnaumov33747e12020-05-04 17:35:20 +0200135 if (commitMsg ==~ /(?s).*\[fetch.*binaries\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*fetch.*binaries.*/) {
136 fetchServiceBinaries = true
137 }
Владислав Наумовf1665b52021-05-13 10:51:17 +0200138 if (commitMsg ==~ /(?s).*\[equinix-on-aws\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinix-on-aws.*/) {
eromanovadf247c32020-12-25 15:44:13 +0400139 equinixOnAwsDemo = true
Владислав Наумовf1665b52021-05-13 10:51:17 +0200140 common.warningMsg('Forced running child cluster deployment on EQUINIX METAL provider based on AWS management cluster, triggered on patchset using custom keyword: \'[equinix-on-aws]\' ')
eromanovadf247c32020-12-25 15:44:13 +0400141 }
142 if (commitMsg ==~ /(?s).*\[aws-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*aws-demo.*/ || attachBYO || upgradeBYO || seedMacOs || equinixOnAwsDemo) {
vnaumov33747e12020-05-04 17:35:20 +0200143 awsOnDemandDemo = true
eromanovadf247c32020-12-25 15:44:13 +0400144 if (attachBYO || upgradeBYO || seedMacOs || equinixOnAwsDemo) {
Владислав Наумов44c64b72020-12-04 20:22:53 +0100145 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 +0100146 }
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200147 }
Владислав Наумовf1665b52021-05-13 10:51:17 +0200148 if (commitMsg ==~ /(?s).*\[equinix-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinix-demo\.*/) {
Владислав Наумовe021b022021-05-06 11:26:38 +0200149 equinixOnDemandDemo = true
150 }
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200151 if (commitMsg ==~ /(?s).*\[disable-os-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-os-demo\.*/) {
152 enableOSDemo = false
153 common.errorMsg('Openstack demo deployment will be aborted, VF -1 will be set')
vnaumov33747e12020-05-04 17:35:20 +0200154 }
155
azvyagintsev1761bdc2020-09-04 17:24:12 +0300156 if (commitMsg ==~ /(?s).*\[disable-bm-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-bm-demo\.*/) {
157 enableBMDemo = false
158 common.errorMsg('BM demo deployment will be aborted, VF -1 will be set')
159 }
160
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +0400161 if (commitMsg ==~ /(?s).*\[disable-vsphere-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-vsphere-demo\.*/) {
162 enableVsphereDemo = false
163 common.errorMsg('vSphere demo deployment will be aborted, VF -1 will be set')
164 }
165
vnaumov33747e12020-05-04 17:35:20 +0200166 // TODO (vnaumov) remove below condition after moving all releases to UCP
167 def ucpChildMatches = (commitMsg =~ /(\[child-ucp\s*ucp-.*?\])/)
168 if (ucpChildMatches.size() > 0) {
169 deployChild = true
170 common.warningMsg('Forced UCP based child deployment triggered on patchset using custom keyword: \'[child-ucp ucp-5-1-0-3-3-0-example]\' ')
171
172 // TODO(vnaumov) delete after ucp upgrades support
173 common.errorMsg('Child upgrade test will be skipped, UCP upgrades temporally disabled')
174 upgradeChild = false
175 }
176
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200177 // multiregional tests
178 def multiRegionalMatches = (commitMsg =~ /(\[multiregion\s*.*?\])/)
179 if (multiRegionalMatches.size() > 0) {
180 multiregionalMappings = multiregionWorkflowParser(multiRegionalMatches)
181 }
182 switch (multiregionalMappings['managementLocation']) {
183 case 'aws':
Владислав Наумов53b07e52021-01-07 15:08:27 +0100184 common.warningMsg('Forced running additional kaas deployment with AWS provider according multiregional demo request')
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200185 awsOnDemandDemo = true
Владислав Наумов53b07e52021-01-07 15:08:27 +0100186
187 if (multiregionalMappings['regionLocation'] != 'aws' && seedMacOs) { // macstadium seed node has access only to *public* providers
188 error('incompatible triggers: [seed-macos] and multiregional deployment based on *private* regional provider cannot be applied simultaneously')
189 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200190 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200191 case 'os':
192 if (enableOSDemo == false) {
193 error('incompatible triggers: [disable-os-demo] and multiregional deployment based on OSt management region cannot be applied simultaneously')
194 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200195 break
Владислав Наумов865ba6c2021-05-13 13:05:45 +0200196 case 'vsphere':
197 if (enableVsphereDemo == false) {
198 error('incompatible triggers: [disable-vsphere-demo] and multiregional deployment based on Vsphere management region cannot be applied simultaneously')
199 }
200 break
Владислав Наумов5be02942021-05-13 12:34:37 +0200201 case 'equinix':
202 common.warningMsg('Forced running additional kaas deployment with Equinix provider according multiregional demo request')
203 equinixOnDemandDemo = true
204 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200205 }
206
Владислав Наумовb8305e22021-02-10 17:23:12 +0100207 // CDN configuration
208 def cdnConfig = [
209 mgmt: [
210 openstack: (proxyConfig['mgmtOffline'] == true) ? 'public-ci' : 'internal-ci',
Владислав Наумов70c02422021-04-19 14:29:41 +0200211 vsphere: 'internal-ci',
Владислав Наумовb8305e22021-02-10 17:23:12 +0100212 aws: 'public-ci',
Владислав Наумовe021b022021-05-06 11:26:38 +0200213 equinix: 'public-ci',
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200214 ],
Владислав Наумовb8305e22021-02-10 17:23:12 +0100215 ]
216
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100217 // calculate weight of current demo run to manage lockable resources
218 def demoWeight = (deployChild) ? 2 : 1 // management = 1, child = 1
219
vnaumov33747e12020-05-04 17:35:20 +0200220 common.infoMsg("""
Владислав Наумовb8305e22021-02-10 17:23:12 +0100221 CDN deployment configuration: ${cdnConfig}
222 MCC offline deployment configuration: ${proxyConfig}
Владислав Наумов44c64b72020-12-04 20:22:53 +0100223 Use MacOS node as seed: ${seedMacOs}
vnaumov33747e12020-05-04 17:35:20 +0200224 Child cluster deployment scheduled: ${deployChild}
Mikhail Ivanov74504372021-05-21 17:01:06 +0400225 Custom child cluster release: ${customChildRelease}
vnaumov33747e12020-05-04 17:35:20 +0200226 Child cluster release upgrade scheduled: ${upgradeChild}
227 Child conformance testing scheduled: ${runChildConformance}
Владислав Наумов0dc99252020-11-13 13:30:48 +0100228 BYO cluster attachment scheduled: ${attachBYO}
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100229 Attached BYO cluster upgrade test scheduled: ${upgradeBYO}
vnaumov33747e12020-05-04 17:35:20 +0200230 Mgmt cluster release upgrade scheduled: ${upgradeMgmt}
231 Mgmt conformance testing scheduled: ${runMgmtConformance}
232 Mgmt UI e2e testing scheduled: ${runUie2e}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200233 AWS provider deployment scheduled: ${awsOnDemandDemo}
Владислав Наумовe021b022021-05-06 11:26:38 +0200234 Equinix provider deployment scheduled: ${equinixOnDemandDemo}
Владислав Наумовf1665b52021-05-13 10:51:17 +0200235 Equinix@AWS child cluster deployment scheduled: ${equinixOnAwsDemo}
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +0400236 VSPHERE provider deployment scheduled: ${enableVsphereDemo}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200237 OS provider deployment scheduled: ${enableOSDemo}
azvyagintsev1761bdc2020-09-04 17:24:12 +0300238 BM provider deployment scheduled: ${enableBMDemo}
Владислав Наумовf793fe32020-09-11 15:19:19 +0200239 Multiregional configuration: ${multiregionalMappings}
vnaumov33747e12020-05-04 17:35:20 +0200240 Service binaries fetching scheduled: ${fetchServiceBinaries}
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100241 Current weight of the demo run: ${demoWeight} (Used to manage lockable resources)
Владислав Наумов81777472021-03-09 15:14:27 +0400242 Triggers: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
vnaumov33747e12020-05-04 17:35:20 +0200243 return [
Владислав Наумовb8305e22021-02-10 17:23:12 +0100244 cdnConfig : cdnConfig,
245 proxyConfig : proxyConfig,
Владислав Наумов44c64b72020-12-04 20:22:53 +0100246 useMacOsSeedNode : seedMacOs,
azvyagintseva12230a2020-06-05 13:24:06 +0300247 deployChildEnabled : deployChild,
Mikhail Ivanov74504372021-05-21 17:01:06 +0400248 childDeployCustomRelease : customChildRelease,
azvyagintseva12230a2020-06-05 13:24:06 +0300249 upgradeChildEnabled : upgradeChild,
250 runChildConformanceEnabled : runChildConformance,
Владислав Наумов0dc99252020-11-13 13:30:48 +0100251 attachBYOEnabled : attachBYO,
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100252 upgradeBYOEnabled : upgradeBYO,
azvyagintseva12230a2020-06-05 13:24:06 +0300253 upgradeMgmtEnabled : upgradeMgmt,
254 runUie2eEnabled : runUie2e,
255 runMgmtConformanceEnabled : runMgmtConformance,
vnaumov33747e12020-05-04 17:35:20 +0200256 fetchServiceBinariesEnabled: fetchServiceBinaries,
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200257 awsOnDemandDemoEnabled : awsOnDemandDemo,
Владислав Наумовe021b022021-05-06 11:26:38 +0200258 equinixOnDemandDemoEnabled : equinixOnDemandDemo,
Владислав Наумовf1665b52021-05-13 10:51:17 +0200259 equinixOnAwsDemoEnabled : equinixOnAwsDemo,
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +0400260 vsphereDemoEnabled : enableVsphereDemo,
261 vsphereOnDemandDemoEnabled : enableVsphereDemo, // TODO: remove after MCC 2.7 is out
azvyagintsev1761bdc2020-09-04 17:24:12 +0300262 bmDemoEnabled : enableBMDemo,
Владислав Наумовf793fe32020-09-11 15:19:19 +0200263 osDemoEnabled : enableOSDemo,
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100264 multiregionalConfiguration : multiregionalMappings,
265 demoWeight : demoWeight]
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200266}
267
268/**
269 * Determine management and regional setup for demo workflow scenario
270 *
271 *
272 * @param: keyword (string) string , represents keyworkd trigger, specified in gerrit commit body, like `[multiregion aws,os]`
273 or Jenkins environment string variable in form like 'aws,os'
274 * @return (map)[
275 enabled: (bool),
276 * managementLocation: (string), //aws,os
277 * regionLocation: (string), //aws,os
278 * ]
279 */
280def multiregionWorkflowParser(keyword) {
Владислав Наумов8c0c39d2020-09-11 14:46:48 +0200281 def common = new com.mirantis.mk.Common()
Владислав Наумов5be02942021-05-13 12:34:37 +0200282 def supportedManagementProviders = ['os', 'aws', 'vsphere', 'equinix']
azvyagintsevcb0635c2021-06-07 13:50:05 +0300283 def supportedRegionalProviders = ['os', 'vsphere', 'equinix', 'bm']
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200284
285 def clusterTypes = ''
Владислав Наумов38ed7bf2020-09-11 14:43:39 +0200286 if (keyword.toString().contains('multiregion')) {
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200287 common.infoMsg('Multiregion definition configured via gerrit keyword trigger')
288 clusterTypes = keyword[0][0].split('multiregion')[1].replaceAll('[\\[\\]]', '').trim().split(',')
289 } else {
290 common.infoMsg('Multiregion definition configured via environment variable')
291 clusterTypes = keyword.trim().split(',')
292 }
293
294 if (clusterTypes.size() != 2) {
Владислав Наумов482fb502020-10-30 17:59:27 +0100295 error("Incorrect regions definiton, valid scheme: [multiregion ${management}, ${region}], got: ${clusterTypes}")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200296 }
297
Владислав Наумовf793fe32020-09-11 15:19:19 +0200298 def desiredManagementProvider = clusterTypes[0].trim()
299 def desiredRegionalProvider = clusterTypes[1].trim()
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200300 if (! supportedManagementProviders.contains(desiredManagementProvider) || ! supportedRegionalProviders.contains(desiredRegionalProvider)) {
301 error("""unsupported management <-> regional bundle, available options:
Владислав Наумовf793fe32020-09-11 15:19:19 +0200302 management providers list - ${supportedManagementProviders}
303 regional providers list - ${supportedRegionalProviders}""")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200304 }
305
306 return [
307 enabled: true,
308 managementLocation: desiredManagementProvider,
309 regionLocation: desiredRegionalProvider,
310 ]
vnaumov33747e12020-05-04 17:35:20 +0200311}
312
313/**
314 * Determine if custom si tests/pipelines refspec forwarded from gerrit change request
315
Владислав Наумов81777472021-03-09 15:14:27 +0400316 * Keyword list: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md
vnaumov33747e12020-05-04 17:35:20 +0200317 * Used for components team to test component changes w/ custom SI refspecs using kaas/core deployment jobs
318 * Example scheme:
319 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
320 * manage refspecs through Jenkins Job Parameters
321 *
azvyagintseva12230a2020-06-05 13:24:06 +0300322 * @return (map)[* siTests: (string) final refspec for si-tests
vnaumov33747e12020-05-04 17:35:20 +0200323 * siPipelines: (string) final refspec for si-pipelines
324 * ]
325 */
326def checkCustomSIRefspec() {
vnaumovbdb90222020-05-04 18:25:50 +0200327 def common = new com.mirantis.mk.Common()
328
vnaumov33747e12020-05-04 17:35:20 +0200329 // Available triggers and its sane defaults
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200330 def siTestsRefspec = env.SI_TESTS_REFSPEC ?: 'master'
331 def siPipelinesRefspec = env.SI_PIPELINES_REFSPEC ?: 'master'
Владислав Наумов2db15e22020-07-14 12:29:22 +0200332 def siTestsDockerImage = env.SI_TESTS_DOCKER_IMAGE ?: 'docker-dev-kaas-local.docker.mirantis.net/mirantis/kaas/si-test'
333 def siTestsDockerImageTag = env.SI_TESTS_DOCKER_IMAGE_TAG ?: 'master'
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200334 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
vnaumov33747e12020-05-04 17:35:20 +0200335
336 def siTestMatches = (commitMsg =~ /(\[si-tests-ref\s*refs\/changes\/.*?\])/)
337 def siPipelinesMatches = (commitMsg =~ /(\[si-pipelines-ref\s*refs\/changes\/.*?\])/)
338
339 if (siTestMatches.size() > 0) {
340 siTestsRefspec = siTestMatches[0][0].split('si-tests-ref')[1].replaceAll('[\\[\\]]', '').trim()
Владислав Наумов7f6c0882021-03-23 19:10:57 +0400341 siTestsDockerImage = "docker-review-local.docker.mirantis.net/review/kaas-si-test-${siTestsRefspec.split('/')[-2]}"
Владислав Наумов2db15e22020-07-14 12:29:22 +0200342 siTestsDockerImageTag = siTestsRefspec.split('/')[-1]
vnaumov33747e12020-05-04 17:35:20 +0200343 }
344 if (siPipelinesMatches.size() > 0) {
345 siPipelinesRefspec = siPipelinesMatches[0][0].split('si-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
346 }
347
348 common.infoMsg("""
349 kaas/si-pipelines will be fetched from: ${siPipelinesRefspec}
350 kaas/si-tests will be fetched from: ${siTestsRefspec}
Владислав Наумов2db15e22020-07-14 12:29:22 +0200351 kaas/si-tests as dockerImage will be fetched from: ${siTestsDockerImage}:${siTestsDockerImageTag}
Владислав Наумов81777472021-03-09 15:14:27 +0400352 Keywords: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
Владислав Наумов2db15e22020-07-14 12:29:22 +0200353 return [siTests: siTestsRefspec, siPipelines: siPipelinesRefspec, siTestsDockerImage: siTestsDockerImage, siTestsDockerImageTag: siTestsDockerImageTag]
vnaumov33747e12020-05-04 17:35:20 +0200354}
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200355
Владислав Наумов9080f372020-06-08 13:57:16 +0200356/**
Владислав Наумов418042b2020-07-09 18:31:10 +0200357 * Parse additional configuration for kaas component CICD repo
Владислав Наумов30a516c2020-07-09 13:15:41 +0200358 * @param configurationFile (str) path to configuration file in yaml format
359 *
360 * @return (map)[ siTestsFeatureFlags (string) dedicated feature flags that will be used in SI tests,
361 * ]
362 */
363def parseKaaSComponentCIParameters(configurationFile){
364 def common = new com.mirantis.mk.Common()
365 def ciConfig = readYaml file: configurationFile
366 def ciSpec = [
367 siTestsFeatureFlags: env.SI_TESTS_FEATURE_FLAGS ?: '',
368 ]
369
370 if (ciConfig.containsKey('si-tests-feature-flags')) {
371 common.infoMsg("""SI tests feature flags customization detected,
372 results will be merged with existing flags: [${ciSpec['siTestsFeatureFlags']}] identification...""")
373
374 def ffMeta = ciSpec['siTestsFeatureFlags'].tokenize(',').collect { it.trim() }
375 ffMeta.addAll(ciConfig['si-tests-feature-flags'])
Владислав Наумов30a516c2020-07-09 13:15:41 +0200376
Владислав Наумовcb5ffca2020-07-14 15:28:36 +0200377 ciSpec['siTestsFeatureFlags'] = ffMeta.unique().join(',')
Владислав Наумов30a516c2020-07-09 13:15:41 +0200378 common.infoMsg("SI tests custom feature flags: ${ciSpec['siTestsFeatureFlags']}")
379 }
380
381 common.infoMsg("""Additional ci configuration parsed successfully:
382 siTestsFeatureFlags: ${ciSpec['siTestsFeatureFlags']}""")
383 return ciSpec
384}
385
386/**
387 * Determine if custom kaas core/pipelines refspec forwarded from gerrit change request
Владислав Наумов9080f372020-06-08 13:57:16 +0200388
Владислав Наумов81777472021-03-09 15:14:27 +0400389 * Keyword list: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md
Владислав Наумов9080f372020-06-08 13:57:16 +0200390 * Used for components team to test component changes w/ custom Core refspecs using kaas/core deployment jobs
391 * Example scheme:
392 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
393 * manage refspecs through Jenkins Job Parameters
394 *
395 * @return (map)[ core: (string) final refspec for kaas/core
396 * corePipelines: (string) final refspec for pipelines in kaas/core
397 * ]
398 */
399def checkCustomCoreRefspec() {
400 def common = new com.mirantis.mk.Common()
401
402 // Available triggers and its sane defaults
403 def coreRefspec = env.KAAS_CORE_REFSPEC ?: 'master'
404 // by default using value of GERRIT_REFSPEC parameter in *kaas/core jobs*
405 def corePipelinesRefspec = env.KAAS_PIPELINE_REFSPEC ?: '\$GERRIT_REFSPEC'
406 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
407
408 def coreMatches = (commitMsg =~ /(\[core-ref\s*refs\/changes\/.*?\])/)
409 def corePipelinesMatches = (commitMsg =~ /(\[core-pipelines-ref\s*refs\/changes\/.*?\])/)
410
411 if (coreMatches.size() > 0) {
412 coreRefspec = coreMatches[0][0].split('core-ref')[1].replaceAll('[\\[\\]]', '').trim()
413 }
414 if (corePipelinesMatches.size() > 0) {
415 corePipelinesRefspec = corePipelinesMatches[0][0].split('core-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
416 }
417
418 common.infoMsg("""
419 kaas/core will be fetched from: ${coreRefspec}
420 kaas/core pipelines will be fetched from: ${corePipelinesRefspec}
Владислав Наумов81777472021-03-09 15:14:27 +0400421 Keywords: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
Владислав Наумов9080f372020-06-08 13:57:16 +0200422 return [core: coreRefspec, corePipelines: corePipelinesRefspec]
423}
424
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200425
426/**
Владислав Наумов92288d92020-07-13 18:36:21 +0200427 * generate Jenkins Parameter objects from from text parameter with additonal kaas core context
428 * needed to forward inside kaas core set of jobs
429 *
430 * @param context (string) Representation of the string enviroment variables needed for kaas core jobs in yaml format
431 * @return (list)[ string(name: '', value: ''),
432 * ]
433 */
434def generateKaaSVarsFromContext(context) {
435 def common = new com.mirantis.mk.Common()
436 def parameters = []
437 def config = readYaml text: context
438
439 config.each { k,v ->
440 common.infoMsg("Custom KaaS Core context parameter: ${k}=${v}")
441 parameters.add(string(name: k, value: v))
442 }
443
444 return parameters
445}
446
447/**
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200448 * Trigger KaaS demo jobs based on AWS/OS providers with customized test suite, parsed from external sources (gerrit commit/jj vars)
Владислав Наумов81777472021-03-09 15:14:27 +0400449 * Keyword list: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200450 * Used for components team to test component changes w/ customized SI tests/refspecs using kaas/core deployment jobs
451 *
Владислав Наумов418042b2020-07-09 18:31:10 +0200452 * @param: component (string) component name [iam, lcm, stacklight]
453 * @param: patchSpec (string) Patch for kaas/cluster releases in json format
454 * @param: configurationFile (string) Additional file for component repo CI config in yaml format
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200455 */
Владислав Наумов92288d92020-07-13 18:36:21 +0200456def triggerPatchedComponentDemo(component, patchSpec = '', configurationFile = '.ci-parameters.yaml', coreContext = '') {
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200457 def common = new com.mirantis.mk.Common()
458 // Determine if custom trigger keywords forwarded from gerrit
459 def triggers = checkDeploymentTestSuite()
460 // Determine SI refspecs
461 def siRefspec = checkCustomSIRefspec()
Владислав Наумов9080f372020-06-08 13:57:16 +0200462 // Determine Core refspecs
463 def coreRefspec = checkCustomCoreRefspec()
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200464
Владислав Наумов418042b2020-07-09 18:31:10 +0200465 // Determine component repo ci configuration
466 def ciSpec = [:]
467 def componentFeatureFlags = env.SI_TESTS_FEATURE_FLAGS ?: ''
468 if (fileExists(configurationFile)) {
469 common.infoMsg('Component CI configuration file detected, parsing...')
470 ciSpec = parseKaaSComponentCIParameters(configurationFile)
471 componentFeatureFlags = ciSpec['siTestsFeatureFlags']
472 } else {
473 common.warningMsg('''Component CI configuration file is not exists,
Владислав Наумовc17dd552020-07-29 17:07:38 +0200474 several code-management features may be unavailable,
Владислав Наумов92288d92020-07-13 18:36:21 +0200475 follow https://mirantis.jira.com/wiki/spaces/QA/pages/2310832276/SI-tests+feature+flags#%5BUpdated%5D-Using-a-feature-flag
476 to create the configuration file''')
Владислав Наумов418042b2020-07-09 18:31:10 +0200477 }
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400478
479 def platforms = []
480 if (component == 'ipam' && triggers.vsphereDemoEnabled) {
481 // Currently only vsphere demo is required for IPAM component
482 platforms.add('vsphere')
483 } else {
484 if (triggers.osDemoEnabled) {
485 platforms.add('openstack')
486 }
487 if (triggers.awsOnDemandDemoEnabled) {
488 platforms.add('aws')
489 }
490 if (triggers.equinixOnDemandDemoEnabled) {
491 platforms.add('equinix')
492 }
Ivan Berezovskiyb0229d02021-05-17 16:55:18 +0400493 if (triggers.vsphereDemoEnabled) {
494 platforms.add('vsphere')
495 }
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400496 }
497
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200498 def jobs = [:]
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200499 def parameters = [
Владислав Наумов9080f372020-06-08 13:57:16 +0200500 string(name: 'GERRIT_REFSPEC', value: coreRefspec.core),
501 string(name: 'KAAS_PIPELINE_REFSPEC', value: coreRefspec.corePipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200502 string(name: 'SI_TESTS_REFSPEC', value: siRefspec.siTests),
Владислав Наумов418042b2020-07-09 18:31:10 +0200503 string(name: 'SI_TESTS_FEATURE_FLAGS', value: componentFeatureFlags),
Владислав Наумов2db15e22020-07-14 12:29:22 +0200504 string(name: 'SI_TESTS_DOCKER_IMAGE', value: siRefspec.siTestsDockerImage),
505 string(name: 'SI_TESTS_DOCKER_IMAGE_TAG', value: siRefspec.siTestsDockerImageTag),
Владислав Наумов4a5c3242020-06-08 14:36:11 +0200506 string(name: 'SI_PIPELINES_REFSPEC', value: siRefspec.siPipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200507 string(name: 'CUSTOM_RELEASE_PATCH_SPEC', value: patchSpec),
Mikhail Ivanov74504372021-05-21 17:01:06 +0400508 string(name: 'KAAS_CHILD_CLUSTER_RELEASE_NAME', value: triggers.childDeployCustomRelease),
Владислав Наумовb8305e22021-02-10 17:23:12 +0100509 booleanParam(name: 'OFFLINE_MGMT_CLUSTER', value: triggers.proxyConfig['mgmtOffline']),
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200510 booleanParam(name: 'OFFLINE_CHILD_CLUSTER', value: triggers.proxyConfig['childOffline']),
Владислав Наумов257ea132021-04-14 14:44:13 +0200511 booleanParam(name: 'PROXY_CHILD_CLUSTER', value: triggers.proxyConfig['childProxy']),
Владислав Наумов44c64b72020-12-04 20:22:53 +0100512 booleanParam(name: 'SEED_MACOS', value: triggers.useMacOsSeedNode),
Владислав Наумов080d9412020-07-29 13:05:14 +0200513 booleanParam(name: 'UPGRADE_MGMT_CLUSTER', value: triggers.upgradeMgmtEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200514 booleanParam(name: 'RUN_UI_E2E', value: triggers.runUie2eEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200515 booleanParam(name: 'RUN_MGMT_CFM', value: triggers.runMgmtConformanceEnabled),
516 booleanParam(name: 'DEPLOY_CHILD_CLUSTER', value: triggers.deployChildEnabled),
517 booleanParam(name: 'UPGRADE_CHILD_CLUSTER', value: triggers.upgradeChildEnabled),
Владислав Наумов0dc99252020-11-13 13:30:48 +0100518 booleanParam(name: 'ATTACH_BYO', value: triggers.attachBYOEnabled),
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100519 booleanParam(name: 'UPGRADE_BYO', value: triggers.upgradeBYOEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200520 booleanParam(name: 'RUN_CHILD_CFM', value: triggers.runChildConformanceEnabled),
Ivan Berezovskiycbf9eeb2021-03-22 15:57:32 +0400521 booleanParam(name: 'ALLOW_AWS_ON_DEMAND', value: triggers.awsOnDemandDemoEnabled),
Владислав Наумовe021b022021-05-06 11:26:38 +0200522 booleanParam(name: 'ALLOW_EQUINIX_ON_DEMAND', value: triggers.equinixOnDemandDemoEnabled),
eromanovad3397512021-04-01 20:19:19 +0400523 booleanParam(name: 'EQUINIX_ON_AWS_DEMO', value: triggers.equinixOnAwsDemoEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200524 ]
Владислав Наумов92288d92020-07-13 18:36:21 +0200525
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200526 // customize multiregional demo
527 if (triggers.multiregionalConfiguration.enabled) {
528 parameters.add(string(name: 'MULTIREGION_SETUP',
529 value: "${triggers.multiregionalConfiguration.managementLocation},${triggers.multiregionalConfiguration.regionLocation}"
530 ))
531 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200532
Владислав Наумов92288d92020-07-13 18:36:21 +0200533 // Determine component team custom context
534 if (coreContext != '') {
535 common.infoMsg('Additional KaaS Core context detected, will be forwarded into kaas core cicd...')
536 def additionalParameters = generateKaaSVarsFromContext(coreContext)
Владислав Наумовbef51a92020-10-01 17:36:51 +0200537 parameters.addAll(additionalParameters)
Владислав Наумов92288d92020-07-13 18:36:21 +0200538 }
539
Владислав Наумовe021b022021-05-06 11:26:38 +0200540 if (triggers.awsOnDemandDemoEnabled || triggers.equinixOnDemandDemoEnabled) {
541 common.infoMsg('Public provider demo triggered, need to sync artifacts in the public-ci cdn..')
542 switch (component) {
543 case 'iam':
544 build job: 'cdn-binary-dev-replication-iam', propagate: true, wait: true
545 break
546 case 'lcm':
547 build job: 'cdn-binary-dev-replication-lcm', propagate: true, wait: true
548 break
549 }
550 }
551
Владислав Наумовaa430612020-06-08 17:18:31 +0200552 def jobResults = []
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400553
554 platforms.each { platform ->
555 jobs["kaas-core-${platform}-patched-${component}"] = {
Vladislav Naumov5313a202021-04-07 17:13:39 +0000556 try {
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400557 common.infoMsg("Deploy: patched KaaS demo with ${platform} provider")
558 def job_info = build job: "kaas-testing-core-${platform}-workflow-${component}", parameters: parameters, wait: true
559 def build_description = job_info.getDescription()
560 def build_result = job_info.getResult()
Vladislav Naumov5313a202021-04-07 17:13:39 +0000561 jobResults.add(build_result)
Владислав Наумовd044e842020-06-17 15:33:43 +0200562
Vladislav Naumov5313a202021-04-07 17:13:39 +0000563 if (build_description) {
564 currentBuild.description += build_description
565 }
566 } finally {
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400567 common.infoMsg("Patched KaaS demo with ${platform} provider finished")
Vladislav Naumov5313a202021-04-07 17:13:39 +0000568 }
569 }
570 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200571
572 common.infoMsg('Trigger KaaS demo deployments according to defined provider set')
Владислав Наумов37f7f842021-03-09 16:08:39 +0400573 if (jobs.size() == 0) {
574 error('No demo jobs matched with keywords, execution will be aborted, at least 1 provider should be enabled')
575 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200576 // Limit build concurency workaround examples: https://issues.jenkins-ci.org/browse/JENKINS-44085
577 parallel jobs
Владислав Наумовaa430612020-06-08 17:18:31 +0200578
579 if (jobResults.contains('FAILURE')) {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200580 common.infoMsg('One of parallel downstream jobs is failed, mark executor job as failed')
Владислав Наумовaa430612020-06-08 17:18:31 +0200581 currentBuild.result = 'FAILURE'
582 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200583}
Владислав Наумов30a516c2020-07-09 13:15:41 +0200584
585