blob: d7f7fdbd6613be1b5ffea69e9202324d68d10f35 [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
Владислав Наумов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 = [
Владислав Наумовf8f23fa2021-04-01 16:57:52 +020070 mgmtOffline: env.OFFLINE_MGMT_CLUSTER ? env.OFFLINE_MGMT_CLUSTER.toBoolean() : false,
71 childOffline: env.OFFLINE_CHILD_CLUSTER ? env.OFFLINE_CHILD_CLUSTER.toBoolean() : false,
Владислав Наумов257ea132021-04-14 14:44:13 +020072 childProxy: env.PROXY_CHILD_CLUSTER ? env.PROXY_CHILD_CLUSTER.toBoolean() : false,
Владислав Наумовb8305e22021-02-10 17:23:12 +010073 ]
74
Владислав Наумов4eb1da32020-08-31 14:45:16 +020075 // optional demo deployment customization
Владислав Наумов905dd362020-06-08 16:37:01 +020076 def awsOnDemandDemo = env.ALLOW_AWS_ON_DEMAND ? env.ALLOW_AWS_ON_DEMAND.toBoolean() : false
Владислав Наумовe021b022021-05-06 11:26:38 +020077 def equinixOnDemandDemo = env.ALLOW_EQUINIX_ON_DEMAND ? env.ALLOW_EQUINIX_ON_DEMAND.toBoolean() : false
Владислав Наумовf3715802021-05-03 18:06:45 +020078 def equinixOnAwsDemo = env.EQUINIX_ON_AWS_DEMO ? env.EQUINIX_ON_AWS_DEMO.toBoolean() : false
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +040079 def enableVsphereDemo = true
Владислав Наумов4eb1da32020-08-31 14:45:16 +020080 def enableOSDemo = true
azvyagintsev1761bdc2020-09-04 17:24:12 +030081 def enableBMDemo = true
vnaumov33747e12020-05-04 17:35:20 +020082
Владислав Наумов6c2afff2020-06-05 12:54:53 +020083 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
Владислав Наумовb8305e22021-02-10 17:23:12 +010084 if (commitMsg ==~ /(?s).*\[mgmt-proxy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-proxy.*/) {
85 proxyConfig['mgmtOffline'] = true
Владислав Наумов70c02422021-04-19 14:29:41 +020086 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 +010087 }
Владислав Наумов44c64b72020-12-04 20:22:53 +010088 if (commitMsg ==~ /(?s).*\[seed-macos\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*seed-macos.*/) {
89 seedMacOs = true
90 }
vnaumov33747e12020-05-04 17:35:20 +020091 if (commitMsg ==~ /(?s).*\[child-deploy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-deploy.*/ || upgradeChild || runChildConformance) {
92 deployChild = true
93 }
94 if (commitMsg ==~ /(?s).*\[child-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-upgrade.*/) {
95 deployChild = true
96 upgradeChild = true
97 }
Владислав Наумов0dc99252020-11-13 13:30:48 +010098 if (commitMsg ==~ /(?s).*\[byo-attach\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-attach.*/) {
99 attachBYO = true
100 }
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100101 if (commitMsg ==~ /(?s).*\[byo-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-upgrade.*/) {
102 attachBYO = true
103 upgradeBYO = true
104 }
Владислав Наумов7f8c9872021-03-08 17:33:08 +0400105 if (commitMsg ==~ /(?s).*\[mgmt-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-upgrade.*/) {
vnaumov33747e12020-05-04 17:35:20 +0200106 upgradeMgmt = true
107 }
108 if (commitMsg ==~ /(?s).*\[ui-e2e\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*ui-e2e.*/) {
109 runUie2e = true
110 }
111 if (commitMsg ==~ /(?s).*\[mgmt-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-cfm.*/) {
112 runMgmtConformance = true
113 }
114 if (commitMsg ==~ /(?s).*\[child-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-cfm.*/) {
115 runChildConformance = true
116 deployChild = true
117 }
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200118 if (commitMsg ==~ /(?s).*\[child-offline\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-offline.*/) {
119 proxyConfig['childOffline'] = true
120 deployChild = true
121 }
Владислав Наумов257ea132021-04-14 14:44:13 +0200122 if (commitMsg ==~ /(?s).*\[child-proxy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-proxy.*/) {
123 proxyConfig['childOffline'] = true
124 proxyConfig['childProxy'] = true
125 deployChild = true
126 }
vnaumov33747e12020-05-04 17:35:20 +0200127 if (commitMsg ==~ /(?s).*\[fetch.*binaries\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*fetch.*binaries.*/) {
128 fetchServiceBinaries = true
129 }
Владислав Наумовf1665b52021-05-13 10:51:17 +0200130 if (commitMsg ==~ /(?s).*\[equinix-on-aws\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinix-on-aws.*/) {
eromanovadf247c32020-12-25 15:44:13 +0400131 equinixOnAwsDemo = true
Владислав Наумовf1665b52021-05-13 10:51:17 +0200132 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 +0400133 }
134 if (commitMsg ==~ /(?s).*\[aws-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*aws-demo.*/ || attachBYO || upgradeBYO || seedMacOs || equinixOnAwsDemo) {
vnaumov33747e12020-05-04 17:35:20 +0200135 awsOnDemandDemo = true
eromanovadf247c32020-12-25 15:44:13 +0400136 if (attachBYO || upgradeBYO || seedMacOs || equinixOnAwsDemo) {
Владислав Наумов44c64b72020-12-04 20:22:53 +0100137 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 +0100138 }
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200139 }
Владислав Наумовf1665b52021-05-13 10:51:17 +0200140 if (commitMsg ==~ /(?s).*\[equinix-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinix-demo\.*/) {
Владислав Наумовe021b022021-05-06 11:26:38 +0200141 equinixOnDemandDemo = true
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
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +0400153 if (commitMsg ==~ /(?s).*\[disable-vsphere-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-vsphere-demo\.*/) {
154 enableVsphereDemo = false
155 common.errorMsg('vSphere demo deployment will be aborted, VF -1 will be set')
156 }
157
vnaumov33747e12020-05-04 17:35:20 +0200158 // TODO (vnaumov) remove below condition after moving all releases to UCP
159 def ucpChildMatches = (commitMsg =~ /(\[child-ucp\s*ucp-.*?\])/)
160 if (ucpChildMatches.size() > 0) {
161 deployChild = true
162 common.warningMsg('Forced UCP based child deployment triggered on patchset using custom keyword: \'[child-ucp ucp-5-1-0-3-3-0-example]\' ')
163
164 // TODO(vnaumov) delete after ucp upgrades support
165 common.errorMsg('Child upgrade test will be skipped, UCP upgrades temporally disabled')
166 upgradeChild = false
167 }
168
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200169 // multiregional tests
170 def multiRegionalMatches = (commitMsg =~ /(\[multiregion\s*.*?\])/)
171 if (multiRegionalMatches.size() > 0) {
172 multiregionalMappings = multiregionWorkflowParser(multiRegionalMatches)
173 }
174 switch (multiregionalMappings['managementLocation']) {
175 case 'aws':
Владислав Наумов53b07e52021-01-07 15:08:27 +0100176 common.warningMsg('Forced running additional kaas deployment with AWS provider according multiregional demo request')
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200177 awsOnDemandDemo = true
Владислав Наумов53b07e52021-01-07 15:08:27 +0100178
179 if (multiregionalMappings['regionLocation'] != 'aws' && seedMacOs) { // macstadium seed node has access only to *public* providers
180 error('incompatible triggers: [seed-macos] and multiregional deployment based on *private* regional provider cannot be applied simultaneously')
181 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200182 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200183 case 'os':
184 if (enableOSDemo == false) {
185 error('incompatible triggers: [disable-os-demo] and multiregional deployment based on OSt management region cannot be applied simultaneously')
186 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200187 break
Владислав Наумов865ba6c2021-05-13 13:05:45 +0200188 case 'vsphere':
189 if (enableVsphereDemo == false) {
190 error('incompatible triggers: [disable-vsphere-demo] and multiregional deployment based on Vsphere management region cannot be applied simultaneously')
191 }
192 break
Владислав Наумов5be02942021-05-13 12:34:37 +0200193 case 'equinix':
194 common.warningMsg('Forced running additional kaas deployment with Equinix provider according multiregional demo request')
195 equinixOnDemandDemo = true
196 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200197 }
198
Владислав Наумовb8305e22021-02-10 17:23:12 +0100199 // CDN configuration
200 def cdnConfig = [
201 mgmt: [
202 openstack: (proxyConfig['mgmtOffline'] == true) ? 'public-ci' : 'internal-ci',
Владислав Наумов70c02422021-04-19 14:29:41 +0200203 vsphere: 'internal-ci',
Владислав Наумовb8305e22021-02-10 17:23:12 +0100204 aws: 'public-ci',
Владислав Наумовe021b022021-05-06 11:26:38 +0200205 equinix: 'public-ci',
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200206 ],
Владислав Наумовb8305e22021-02-10 17:23:12 +0100207 ]
208
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100209 // calculate weight of current demo run to manage lockable resources
210 def demoWeight = (deployChild) ? 2 : 1 // management = 1, child = 1
211
vnaumov33747e12020-05-04 17:35:20 +0200212 common.infoMsg("""
Владислав Наумовb8305e22021-02-10 17:23:12 +0100213 CDN deployment configuration: ${cdnConfig}
214 MCC offline deployment configuration: ${proxyConfig}
Владислав Наумов44c64b72020-12-04 20:22:53 +0100215 Use MacOS node as seed: ${seedMacOs}
vnaumov33747e12020-05-04 17:35:20 +0200216 Child cluster deployment scheduled: ${deployChild}
217 Child cluster release upgrade scheduled: ${upgradeChild}
218 Child conformance testing scheduled: ${runChildConformance}
Владислав Наумов0dc99252020-11-13 13:30:48 +0100219 BYO cluster attachment scheduled: ${attachBYO}
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100220 Attached BYO cluster upgrade test scheduled: ${upgradeBYO}
vnaumov33747e12020-05-04 17:35:20 +0200221 Mgmt cluster release upgrade scheduled: ${upgradeMgmt}
222 Mgmt conformance testing scheduled: ${runMgmtConformance}
223 Mgmt UI e2e testing scheduled: ${runUie2e}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200224 AWS provider deployment scheduled: ${awsOnDemandDemo}
Владислав Наумовe021b022021-05-06 11:26:38 +0200225 Equinix provider deployment scheduled: ${equinixOnDemandDemo}
Владислав Наумовf1665b52021-05-13 10:51:17 +0200226 Equinix@AWS child cluster deployment scheduled: ${equinixOnAwsDemo}
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +0400227 VSPHERE provider deployment scheduled: ${enableVsphereDemo}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200228 OS provider deployment scheduled: ${enableOSDemo}
azvyagintsev1761bdc2020-09-04 17:24:12 +0300229 BM provider deployment scheduled: ${enableBMDemo}
Владислав Наумовf793fe32020-09-11 15:19:19 +0200230 Multiregional configuration: ${multiregionalMappings}
vnaumov33747e12020-05-04 17:35:20 +0200231 Service binaries fetching scheduled: ${fetchServiceBinaries}
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100232 Current weight of the demo run: ${demoWeight} (Used to manage lockable resources)
Владислав Наумов81777472021-03-09 15:14:27 +0400233 Triggers: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
vnaumov33747e12020-05-04 17:35:20 +0200234 return [
Владислав Наумовb8305e22021-02-10 17:23:12 +0100235 cdnConfig : cdnConfig,
236 proxyConfig : proxyConfig,
Владислав Наумов44c64b72020-12-04 20:22:53 +0100237 useMacOsSeedNode : seedMacOs,
azvyagintseva12230a2020-06-05 13:24:06 +0300238 deployChildEnabled : deployChild,
239 upgradeChildEnabled : upgradeChild,
240 runChildConformanceEnabled : runChildConformance,
Владислав Наумов0dc99252020-11-13 13:30:48 +0100241 attachBYOEnabled : attachBYO,
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100242 upgradeBYOEnabled : upgradeBYO,
azvyagintseva12230a2020-06-05 13:24:06 +0300243 upgradeMgmtEnabled : upgradeMgmt,
244 runUie2eEnabled : runUie2e,
245 runMgmtConformanceEnabled : runMgmtConformance,
vnaumov33747e12020-05-04 17:35:20 +0200246 fetchServiceBinariesEnabled: fetchServiceBinaries,
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200247 awsOnDemandDemoEnabled : awsOnDemandDemo,
Владислав Наумовe021b022021-05-06 11:26:38 +0200248 equinixOnDemandDemoEnabled : equinixOnDemandDemo,
Владислав Наумовf1665b52021-05-13 10:51:17 +0200249 equinixOnAwsDemoEnabled : equinixOnAwsDemo,
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +0400250 vsphereDemoEnabled : enableVsphereDemo,
251 vsphereOnDemandDemoEnabled : enableVsphereDemo, // TODO: remove after MCC 2.7 is out
azvyagintsev1761bdc2020-09-04 17:24:12 +0300252 bmDemoEnabled : enableBMDemo,
Владислав Наумовf793fe32020-09-11 15:19:19 +0200253 osDemoEnabled : enableOSDemo,
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100254 multiregionalConfiguration : multiregionalMappings,
255 demoWeight : demoWeight]
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200256}
257
258/**
259 * Determine management and regional setup for demo workflow scenario
260 *
261 *
262 * @param: keyword (string) string , represents keyworkd trigger, specified in gerrit commit body, like `[multiregion aws,os]`
263 or Jenkins environment string variable in form like 'aws,os'
264 * @return (map)[
265 enabled: (bool),
266 * managementLocation: (string), //aws,os
267 * regionLocation: (string), //aws,os
268 * ]
269 */
270def multiregionWorkflowParser(keyword) {
Владислав Наумов8c0c39d2020-09-11 14:46:48 +0200271 def common = new com.mirantis.mk.Common()
Владислав Наумов5be02942021-05-13 12:34:37 +0200272 def supportedManagementProviders = ['os', 'aws', 'vsphere', 'equinix']
273 def supportedRegionalProviders = ['os', 'vsphere', 'equinix']
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200274
275 def clusterTypes = ''
Владислав Наумов38ed7bf2020-09-11 14:43:39 +0200276 if (keyword.toString().contains('multiregion')) {
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200277 common.infoMsg('Multiregion definition configured via gerrit keyword trigger')
278 clusterTypes = keyword[0][0].split('multiregion')[1].replaceAll('[\\[\\]]', '').trim().split(',')
279 } else {
280 common.infoMsg('Multiregion definition configured via environment variable')
281 clusterTypes = keyword.trim().split(',')
282 }
283
284 if (clusterTypes.size() != 2) {
Владислав Наумов482fb502020-10-30 17:59:27 +0100285 error("Incorrect regions definiton, valid scheme: [multiregion ${management}, ${region}], got: ${clusterTypes}")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200286 }
287
Владислав Наумовf793fe32020-09-11 15:19:19 +0200288 def desiredManagementProvider = clusterTypes[0].trim()
289 def desiredRegionalProvider = clusterTypes[1].trim()
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200290 if (! supportedManagementProviders.contains(desiredManagementProvider) || ! supportedRegionalProviders.contains(desiredRegionalProvider)) {
291 error("""unsupported management <-> regional bundle, available options:
Владислав Наумовf793fe32020-09-11 15:19:19 +0200292 management providers list - ${supportedManagementProviders}
293 regional providers list - ${supportedRegionalProviders}""")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200294 }
295
296 return [
297 enabled: true,
298 managementLocation: desiredManagementProvider,
299 regionLocation: desiredRegionalProvider,
300 ]
vnaumov33747e12020-05-04 17:35:20 +0200301}
302
303/**
304 * Determine if custom si tests/pipelines refspec forwarded from gerrit change request
305
Владислав Наумов81777472021-03-09 15:14:27 +0400306 * 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 +0200307 * Used for components team to test component changes w/ custom SI refspecs using kaas/core deployment jobs
308 * Example scheme:
309 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
310 * manage refspecs through Jenkins Job Parameters
311 *
azvyagintseva12230a2020-06-05 13:24:06 +0300312 * @return (map)[* siTests: (string) final refspec for si-tests
vnaumov33747e12020-05-04 17:35:20 +0200313 * siPipelines: (string) final refspec for si-pipelines
314 * ]
315 */
316def checkCustomSIRefspec() {
vnaumovbdb90222020-05-04 18:25:50 +0200317 def common = new com.mirantis.mk.Common()
318
vnaumov33747e12020-05-04 17:35:20 +0200319 // Available triggers and its sane defaults
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200320 def siTestsRefspec = env.SI_TESTS_REFSPEC ?: 'master'
321 def siPipelinesRefspec = env.SI_PIPELINES_REFSPEC ?: 'master'
Владислав Наумов2db15e22020-07-14 12:29:22 +0200322 def siTestsDockerImage = env.SI_TESTS_DOCKER_IMAGE ?: 'docker-dev-kaas-local.docker.mirantis.net/mirantis/kaas/si-test'
323 def siTestsDockerImageTag = env.SI_TESTS_DOCKER_IMAGE_TAG ?: 'master'
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200324 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
vnaumov33747e12020-05-04 17:35:20 +0200325
326 def siTestMatches = (commitMsg =~ /(\[si-tests-ref\s*refs\/changes\/.*?\])/)
327 def siPipelinesMatches = (commitMsg =~ /(\[si-pipelines-ref\s*refs\/changes\/.*?\])/)
328
329 if (siTestMatches.size() > 0) {
330 siTestsRefspec = siTestMatches[0][0].split('si-tests-ref')[1].replaceAll('[\\[\\]]', '').trim()
Владислав Наумов7f6c0882021-03-23 19:10:57 +0400331 siTestsDockerImage = "docker-review-local.docker.mirantis.net/review/kaas-si-test-${siTestsRefspec.split('/')[-2]}"
Владислав Наумов2db15e22020-07-14 12:29:22 +0200332 siTestsDockerImageTag = siTestsRefspec.split('/')[-1]
vnaumov33747e12020-05-04 17:35:20 +0200333 }
334 if (siPipelinesMatches.size() > 0) {
335 siPipelinesRefspec = siPipelinesMatches[0][0].split('si-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
336 }
337
338 common.infoMsg("""
339 kaas/si-pipelines will be fetched from: ${siPipelinesRefspec}
340 kaas/si-tests will be fetched from: ${siTestsRefspec}
Владислав Наумов2db15e22020-07-14 12:29:22 +0200341 kaas/si-tests as dockerImage will be fetched from: ${siTestsDockerImage}:${siTestsDockerImageTag}
Владислав Наумов81777472021-03-09 15:14:27 +0400342 Keywords: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
Владислав Наумов2db15e22020-07-14 12:29:22 +0200343 return [siTests: siTestsRefspec, siPipelines: siPipelinesRefspec, siTestsDockerImage: siTestsDockerImage, siTestsDockerImageTag: siTestsDockerImageTag]
vnaumov33747e12020-05-04 17:35:20 +0200344}
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200345
Владислав Наумов9080f372020-06-08 13:57:16 +0200346/**
Владислав Наумов418042b2020-07-09 18:31:10 +0200347 * Parse additional configuration for kaas component CICD repo
Владислав Наумов30a516c2020-07-09 13:15:41 +0200348 * @param configurationFile (str) path to configuration file in yaml format
349 *
350 * @return (map)[ siTestsFeatureFlags (string) dedicated feature flags that will be used in SI tests,
351 * ]
352 */
353def parseKaaSComponentCIParameters(configurationFile){
354 def common = new com.mirantis.mk.Common()
355 def ciConfig = readYaml file: configurationFile
356 def ciSpec = [
357 siTestsFeatureFlags: env.SI_TESTS_FEATURE_FLAGS ?: '',
358 ]
359
360 if (ciConfig.containsKey('si-tests-feature-flags')) {
361 common.infoMsg("""SI tests feature flags customization detected,
362 results will be merged with existing flags: [${ciSpec['siTestsFeatureFlags']}] identification...""")
363
364 def ffMeta = ciSpec['siTestsFeatureFlags'].tokenize(',').collect { it.trim() }
365 ffMeta.addAll(ciConfig['si-tests-feature-flags'])
Владислав Наумов30a516c2020-07-09 13:15:41 +0200366
Владислав Наумовcb5ffca2020-07-14 15:28:36 +0200367 ciSpec['siTestsFeatureFlags'] = ffMeta.unique().join(',')
Владислав Наумов30a516c2020-07-09 13:15:41 +0200368 common.infoMsg("SI tests custom feature flags: ${ciSpec['siTestsFeatureFlags']}")
369 }
370
371 common.infoMsg("""Additional ci configuration parsed successfully:
372 siTestsFeatureFlags: ${ciSpec['siTestsFeatureFlags']}""")
373 return ciSpec
374}
375
376/**
377 * Determine if custom kaas core/pipelines refspec forwarded from gerrit change request
Владислав Наумов9080f372020-06-08 13:57:16 +0200378
Владислав Наумов81777472021-03-09 15:14:27 +0400379 * 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 +0200380 * Used for components team to test component changes w/ custom Core refspecs using kaas/core deployment jobs
381 * Example scheme:
382 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
383 * manage refspecs through Jenkins Job Parameters
384 *
385 * @return (map)[ core: (string) final refspec for kaas/core
386 * corePipelines: (string) final refspec for pipelines in kaas/core
387 * ]
388 */
389def checkCustomCoreRefspec() {
390 def common = new com.mirantis.mk.Common()
391
392 // Available triggers and its sane defaults
393 def coreRefspec = env.KAAS_CORE_REFSPEC ?: 'master'
394 // by default using value of GERRIT_REFSPEC parameter in *kaas/core jobs*
395 def corePipelinesRefspec = env.KAAS_PIPELINE_REFSPEC ?: '\$GERRIT_REFSPEC'
396 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
397
398 def coreMatches = (commitMsg =~ /(\[core-ref\s*refs\/changes\/.*?\])/)
399 def corePipelinesMatches = (commitMsg =~ /(\[core-pipelines-ref\s*refs\/changes\/.*?\])/)
400
401 if (coreMatches.size() > 0) {
402 coreRefspec = coreMatches[0][0].split('core-ref')[1].replaceAll('[\\[\\]]', '').trim()
403 }
404 if (corePipelinesMatches.size() > 0) {
405 corePipelinesRefspec = corePipelinesMatches[0][0].split('core-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
406 }
407
408 common.infoMsg("""
409 kaas/core will be fetched from: ${coreRefspec}
410 kaas/core pipelines will be fetched from: ${corePipelinesRefspec}
Владислав Наумов81777472021-03-09 15:14:27 +0400411 Keywords: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
Владислав Наумов9080f372020-06-08 13:57:16 +0200412 return [core: coreRefspec, corePipelines: corePipelinesRefspec]
413}
414
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200415
416/**
Владислав Наумов92288d92020-07-13 18:36:21 +0200417 * generate Jenkins Parameter objects from from text parameter with additonal kaas core context
418 * needed to forward inside kaas core set of jobs
419 *
420 * @param context (string) Representation of the string enviroment variables needed for kaas core jobs in yaml format
421 * @return (list)[ string(name: '', value: ''),
422 * ]
423 */
424def generateKaaSVarsFromContext(context) {
425 def common = new com.mirantis.mk.Common()
426 def parameters = []
427 def config = readYaml text: context
428
429 config.each { k,v ->
430 common.infoMsg("Custom KaaS Core context parameter: ${k}=${v}")
431 parameters.add(string(name: k, value: v))
432 }
433
434 return parameters
435}
436
437/**
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200438 * 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 +0400439 * 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 +0200440 * Used for components team to test component changes w/ customized SI tests/refspecs using kaas/core deployment jobs
441 *
Владислав Наумов418042b2020-07-09 18:31:10 +0200442 * @param: component (string) component name [iam, lcm, stacklight]
443 * @param: patchSpec (string) Patch for kaas/cluster releases in json format
444 * @param: configurationFile (string) Additional file for component repo CI config in yaml format
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200445 */
Владислав Наумов92288d92020-07-13 18:36:21 +0200446def triggerPatchedComponentDemo(component, patchSpec = '', configurationFile = '.ci-parameters.yaml', coreContext = '') {
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200447 def common = new com.mirantis.mk.Common()
448 // Determine if custom trigger keywords forwarded from gerrit
449 def triggers = checkDeploymentTestSuite()
450 // Determine SI refspecs
451 def siRefspec = checkCustomSIRefspec()
Владислав Наумов9080f372020-06-08 13:57:16 +0200452 // Determine Core refspecs
453 def coreRefspec = checkCustomCoreRefspec()
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200454
Владислав Наумов418042b2020-07-09 18:31:10 +0200455 // Determine component repo ci configuration
456 def ciSpec = [:]
457 def componentFeatureFlags = env.SI_TESTS_FEATURE_FLAGS ?: ''
458 if (fileExists(configurationFile)) {
459 common.infoMsg('Component CI configuration file detected, parsing...')
460 ciSpec = parseKaaSComponentCIParameters(configurationFile)
461 componentFeatureFlags = ciSpec['siTestsFeatureFlags']
462 } else {
463 common.warningMsg('''Component CI configuration file is not exists,
Владислав Наумовc17dd552020-07-29 17:07:38 +0200464 several code-management features may be unavailable,
Владислав Наумов92288d92020-07-13 18:36:21 +0200465 follow https://mirantis.jira.com/wiki/spaces/QA/pages/2310832276/SI-tests+feature+flags#%5BUpdated%5D-Using-a-feature-flag
466 to create the configuration file''')
Владислав Наумов418042b2020-07-09 18:31:10 +0200467 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200468 def jobs = [:]
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200469 def parameters = [
Владислав Наумов9080f372020-06-08 13:57:16 +0200470 string(name: 'GERRIT_REFSPEC', value: coreRefspec.core),
471 string(name: 'KAAS_PIPELINE_REFSPEC', value: coreRefspec.corePipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200472 string(name: 'SI_TESTS_REFSPEC', value: siRefspec.siTests),
Владислав Наумов418042b2020-07-09 18:31:10 +0200473 string(name: 'SI_TESTS_FEATURE_FLAGS', value: componentFeatureFlags),
Владислав Наумов2db15e22020-07-14 12:29:22 +0200474 string(name: 'SI_TESTS_DOCKER_IMAGE', value: siRefspec.siTestsDockerImage),
475 string(name: 'SI_TESTS_DOCKER_IMAGE_TAG', value: siRefspec.siTestsDockerImageTag),
Владислав Наумов4a5c3242020-06-08 14:36:11 +0200476 string(name: 'SI_PIPELINES_REFSPEC', value: siRefspec.siPipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200477 string(name: 'CUSTOM_RELEASE_PATCH_SPEC', value: patchSpec),
Владислав Наумовb8305e22021-02-10 17:23:12 +0100478 booleanParam(name: 'OFFLINE_MGMT_CLUSTER', value: triggers.proxyConfig['mgmtOffline']),
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200479 booleanParam(name: 'OFFLINE_CHILD_CLUSTER', value: triggers.proxyConfig['childOffline']),
Владислав Наумов257ea132021-04-14 14:44:13 +0200480 booleanParam(name: 'PROXY_CHILD_CLUSTER', value: triggers.proxyConfig['childProxy']),
Владислав Наумов44c64b72020-12-04 20:22:53 +0100481 booleanParam(name: 'SEED_MACOS', value: triggers.useMacOsSeedNode),
Владислав Наумов080d9412020-07-29 13:05:14 +0200482 booleanParam(name: 'UPGRADE_MGMT_CLUSTER', value: triggers.upgradeMgmtEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200483 booleanParam(name: 'RUN_UI_E2E', value: triggers.runUie2eEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200484 booleanParam(name: 'RUN_MGMT_CFM', value: triggers.runMgmtConformanceEnabled),
485 booleanParam(name: 'DEPLOY_CHILD_CLUSTER', value: triggers.deployChildEnabled),
486 booleanParam(name: 'UPGRADE_CHILD_CLUSTER', value: triggers.upgradeChildEnabled),
Владислав Наумов0dc99252020-11-13 13:30:48 +0100487 booleanParam(name: 'ATTACH_BYO', value: triggers.attachBYOEnabled),
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100488 booleanParam(name: 'UPGRADE_BYO', value: triggers.upgradeBYOEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200489 booleanParam(name: 'RUN_CHILD_CFM', value: triggers.runChildConformanceEnabled),
Ivan Berezovskiycbf9eeb2021-03-22 15:57:32 +0400490 booleanParam(name: 'ALLOW_AWS_ON_DEMAND', value: triggers.awsOnDemandDemoEnabled),
Владислав Наумовe021b022021-05-06 11:26:38 +0200491 booleanParam(name: 'ALLOW_EQUINIX_ON_DEMAND', value: triggers.equinixOnDemandDemoEnabled),
eromanovad3397512021-04-01 20:19:19 +0400492 booleanParam(name: 'EQUINIX_ON_AWS_DEMO', value: triggers.equinixOnAwsDemoEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200493 ]
Владислав Наумов92288d92020-07-13 18:36:21 +0200494
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200495 // customize multiregional demo
496 if (triggers.multiregionalConfiguration.enabled) {
497 parameters.add(string(name: 'MULTIREGION_SETUP',
498 value: "${triggers.multiregionalConfiguration.managementLocation},${triggers.multiregionalConfiguration.regionLocation}"
499 ))
500 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200501
Владислав Наумов92288d92020-07-13 18:36:21 +0200502 // Determine component team custom context
503 if (coreContext != '') {
504 common.infoMsg('Additional KaaS Core context detected, will be forwarded into kaas core cicd...')
505 def additionalParameters = generateKaaSVarsFromContext(coreContext)
Владислав Наумовbef51a92020-10-01 17:36:51 +0200506 parameters.addAll(additionalParameters)
Владислав Наумов92288d92020-07-13 18:36:21 +0200507 }
508
Владислав Наумовe021b022021-05-06 11:26:38 +0200509 if (triggers.awsOnDemandDemoEnabled || triggers.equinixOnDemandDemoEnabled) {
510 common.infoMsg('Public provider demo triggered, need to sync artifacts in the public-ci cdn..')
511 switch (component) {
512 case 'iam':
513 build job: 'cdn-binary-dev-replication-iam', propagate: true, wait: true
514 break
515 case 'lcm':
516 build job: 'cdn-binary-dev-replication-lcm', propagate: true, wait: true
517 break
518 }
519 }
520
Владислав Наумовaa430612020-06-08 17:18:31 +0200521 def jobResults = []
Vladislav Naumov5313a202021-04-07 17:13:39 +0000522 if (triggers.osDemoEnabled) {
523 jobs["kaas-core-openstack-patched-${component}"] = {
524 try {
525 common.infoMsg('Deploy: patched KaaS demo with Openstack provider')
526 os_job_info = build job: "kaas-testing-core-openstack-workflow-${component}", parameters: parameters, wait: true
527 def build_description = os_job_info.getDescription()
528 def build_result = os_job_info.getResult()
529 jobResults.add(build_result)
Владислав Наумовd044e842020-06-17 15:33:43 +0200530
Vladislav Naumov5313a202021-04-07 17:13:39 +0000531 if (build_description) {
532 currentBuild.description += build_description
533 }
534 } finally {
535 common.infoMsg('Patched KaaS demo with Openstack provider finished')
Владислав Наумовf86b1112020-06-09 14:04:48 +0200536 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200537 }
538 }
539 if (triggers.awsOnDemandDemoEnabled) {
540 jobs["kaas-core-aws-patched-${component}"] = {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200541 try {
542 common.infoMsg('Deploy: patched KaaS demo with AWS provider')
Владислав Наумов4aa112d2020-06-16 18:52:21 +0200543 aws_job_info = build job: "kaas-testing-core-aws-workflow-${component}", parameters: parameters, wait: true
544 def build_description = aws_job_info.getDescription()
Владислав Наумовd044e842020-06-17 15:33:43 +0200545 def build_result = aws_job_info.getResult()
546 jobResults.add(build_result)
547
Владислав Наумовf86b1112020-06-09 14:04:48 +0200548 if (build_description) {
549 currentBuild.description += build_description
550 }
551 } finally {
Владислав Наумов6d741fa2020-06-17 17:35:43 +0200552 common.infoMsg('Patched KaaS demo with AWS provider finished')
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200553 }
554 }
555 }
Владислав Наумовe021b022021-05-06 11:26:38 +0200556 if (triggers.equinixOnDemandDemoEnabled) {
557 jobs["kaas-core-equinix-patched-${component}"] = {
558 try {
559 common.infoMsg('Deploy: patched KaaS demo with Equinix provider')
560 equinix_job_info = build job: "kaas-testing-core-equinix-workflow-${component}", parameters: parameters, wait: true
561 def build_description = equinix_job_info.getDescription()
562 def build_result = equinix_job_info.getResult()
563 jobResults.add(build_result)
564
565 if (build_description) {
566 currentBuild.description += build_description
567 }
568 } finally {
569 common.infoMsg('Patched KaaS demo with Equinix provider finished')
570 }
571 }
572 }
Vladislav Naumov5313a202021-04-07 17:13:39 +0000573 if (triggers.vsphereDemoEnabled) {
574 jobs["kaas-core-vsphere-patched-${component}"] = {
575 try {
576 common.infoMsg('Deploy: patched KaaS demo with VSPHERE provider')
577 vsphere_job_info = build job: "kaas-testing-core-vsphere-workflow-${component}", parameters: parameters, wait: true
578 def build_description = vsphere_job_info.getDescription()
579 def build_result = vsphere_job_info.getResult()
580 jobResults.add(build_result)
581
582 if (build_description) {
583 currentBuild.description += build_description
584 }
585 } finally {
586 common.infoMsg('Patched KaaS demo with VSPHERE provider finished')
587 }
588 }
589 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200590
591 common.infoMsg('Trigger KaaS demo deployments according to defined provider set')
Владислав Наумов37f7f842021-03-09 16:08:39 +0400592 if (jobs.size() == 0) {
593 error('No demo jobs matched with keywords, execution will be aborted, at least 1 provider should be enabled')
594 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200595 // Limit build concurency workaround examples: https://issues.jenkins-ci.org/browse/JENKINS-44085
596 parallel jobs
Владислав Наумовaa430612020-06-08 17:18:31 +0200597
598 if (jobResults.contains('FAILURE')) {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200599 common.infoMsg('One of parallel downstream jobs is failed, mark executor job as failed')
Владислав Наумовaa430612020-06-08 17:18:31 +0200600 currentBuild.result = 'FAILURE'
601 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200602}
Владислав Наумов30a516c2020-07-09 13:15:41 +0200603
604