blob: 598c63510eb571fe9d0ce3575f1f456733e4e00c [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 = [
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
Владислав Наумов6ec74302020-11-05 12:38:53 +010075 def vsphereOnDemandDemo = env.ALLOW_VSPHERE_ON_DEMAND ? env.ALLOW_VSPHERE_ON_DEMAND.toBoolean() : false
eromanovad3397512021-04-01 20:19:19 +040076 def equinixOnAwsDemo = env.EQUNIX_ON_AWS_DEMO ? env.EQUNIX_ON_AWS_DEMO.toBoolean() : false
Владислав Наумов4eb1da32020-08-31 14:45:16 +020077 def enableOSDemo = true
azvyagintsev1761bdc2020-09-04 17:24:12 +030078 def enableBMDemo = true
vnaumov33747e12020-05-04 17:35:20 +020079
Владислав Наумов6c2afff2020-06-05 12:54:53 +020080 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
Владислав Наумовb8305e22021-02-10 17:23:12 +010081 if (commitMsg ==~ /(?s).*\[mgmt-proxy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-proxy.*/) {
82 proxyConfig['mgmtOffline'] = true
83 common.warningMsg('Forced running offline mgmt deployment, all provider CDN regions for mgmt deployment will be set to *public-ci* to verify proxy configuration')
84 }
Владислав Наумов44c64b72020-12-04 20:22:53 +010085 if (commitMsg ==~ /(?s).*\[seed-macos\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*seed-macos.*/) {
86 seedMacOs = true
87 }
vnaumov33747e12020-05-04 17:35:20 +020088 if (commitMsg ==~ /(?s).*\[child-deploy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-deploy.*/ || upgradeChild || runChildConformance) {
89 deployChild = true
90 }
91 if (commitMsg ==~ /(?s).*\[child-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-upgrade.*/) {
92 deployChild = true
93 upgradeChild = true
94 }
Владислав Наумов0dc99252020-11-13 13:30:48 +010095 if (commitMsg ==~ /(?s).*\[byo-attach\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-attach.*/) {
96 attachBYO = true
97 }
Владислав Наумовcdbd84e2020-12-01 16:51:09 +010098 if (commitMsg ==~ /(?s).*\[byo-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-upgrade.*/) {
99 attachBYO = true
100 upgradeBYO = true
101 }
Владислав Наумов7f8c9872021-03-08 17:33:08 +0400102 if (commitMsg ==~ /(?s).*\[mgmt-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-upgrade.*/) {
vnaumov33747e12020-05-04 17:35:20 +0200103 upgradeMgmt = true
104 }
105 if (commitMsg ==~ /(?s).*\[ui-e2e\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*ui-e2e.*/) {
106 runUie2e = true
107 }
108 if (commitMsg ==~ /(?s).*\[mgmt-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-cfm.*/) {
109 runMgmtConformance = true
110 }
111 if (commitMsg ==~ /(?s).*\[child-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-cfm.*/) {
112 runChildConformance = true
113 deployChild = true
114 }
115 if (commitMsg ==~ /(?s).*\[fetch.*binaries\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*fetch.*binaries.*/) {
116 fetchServiceBinaries = true
117 }
eromanovadf247c32020-12-25 15:44:13 +0400118 if (commitMsg ==~ /(?s).*\[equinix-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinix-demo.*/) {
119 equinixOnAwsDemo = true
120 common.warningMsg('Forced running child cluster deployment on EQUINIX METAL provider based on AWS management cluster, triggered on patchset using custom keyword: \'[equinix-demo]\' ')
121 }
122 if (commitMsg ==~ /(?s).*\[aws-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*aws-demo.*/ || attachBYO || upgradeBYO || seedMacOs || equinixOnAwsDemo) {
vnaumov33747e12020-05-04 17:35:20 +0200123 awsOnDemandDemo = true
eromanovadf247c32020-12-25 15:44:13 +0400124 if (attachBYO || upgradeBYO || seedMacOs || equinixOnAwsDemo) {
Владислав Наумов44c64b72020-12-04 20:22:53 +0100125 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 +0100126 }
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200127 }
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400128 if (commitMsg ==~ /(?s).*\[vsphere-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*vsphere-demo.*/) {
129 vsphereOnDemandDemo = true
130 common.warningMsg('Forced running additional kaas deployment with VSPHERE provider, triggered on patchset using custom keyword: \'[vsphere-demo]\' ')
131 }
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200132 if (commitMsg ==~ /(?s).*\[disable-os-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-os-demo\.*/) {
133 enableOSDemo = false
134 common.errorMsg('Openstack demo deployment will be aborted, VF -1 will be set')
vnaumov33747e12020-05-04 17:35:20 +0200135 }
136
azvyagintsev1761bdc2020-09-04 17:24:12 +0300137 if (commitMsg ==~ /(?s).*\[disable-bm-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-bm-demo\.*/) {
138 enableBMDemo = false
139 common.errorMsg('BM demo deployment will be aborted, VF -1 will be set')
140 }
141
vnaumov33747e12020-05-04 17:35:20 +0200142 // TODO (vnaumov) remove below condition after moving all releases to UCP
143 def ucpChildMatches = (commitMsg =~ /(\[child-ucp\s*ucp-.*?\])/)
144 if (ucpChildMatches.size() > 0) {
145 deployChild = true
146 common.warningMsg('Forced UCP based child deployment triggered on patchset using custom keyword: \'[child-ucp ucp-5-1-0-3-3-0-example]\' ')
147
148 // TODO(vnaumov) delete after ucp upgrades support
149 common.errorMsg('Child upgrade test will be skipped, UCP upgrades temporally disabled')
150 upgradeChild = false
151 }
152
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200153 // multiregional tests
154 def multiRegionalMatches = (commitMsg =~ /(\[multiregion\s*.*?\])/)
155 if (multiRegionalMatches.size() > 0) {
156 multiregionalMappings = multiregionWorkflowParser(multiRegionalMatches)
157 }
158 switch (multiregionalMappings['managementLocation']) {
159 case 'aws':
Владислав Наумов53b07e52021-01-07 15:08:27 +0100160 common.warningMsg('Forced running additional kaas deployment with AWS provider according multiregional demo request')
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200161 awsOnDemandDemo = true
Владислав Наумов53b07e52021-01-07 15:08:27 +0100162
163 if (multiregionalMappings['regionLocation'] != 'aws' && seedMacOs) { // macstadium seed node has access only to *public* providers
164 error('incompatible triggers: [seed-macos] and multiregional deployment based on *private* regional provider cannot be applied simultaneously')
165 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200166 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200167 case 'os':
168 if (enableOSDemo == false) {
169 error('incompatible triggers: [disable-os-demo] and multiregional deployment based on OSt management region cannot be applied simultaneously')
170 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200171 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200172 }
173
Владислав Наумовb8305e22021-02-10 17:23:12 +0100174 // CDN configuration
175 def cdnConfig = [
176 mgmt: [
177 openstack: (proxyConfig['mgmtOffline'] == true) ? 'public-ci' : 'internal-ci',
178 vsphere: (proxyConfig['mgmtOffline'] == true) ? 'public-ci' : 'internal-ci',
179 aws: 'public-ci',
180 ], // TODO(vnaumov) add additonal vars for regional cluster cdn ops
181 ]
182
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100183 // calculate weight of current demo run to manage lockable resources
184 def demoWeight = (deployChild) ? 2 : 1 // management = 1, child = 1
185
vnaumov33747e12020-05-04 17:35:20 +0200186 common.infoMsg("""
Владислав Наумовb8305e22021-02-10 17:23:12 +0100187 CDN deployment configuration: ${cdnConfig}
188 MCC offline deployment configuration: ${proxyConfig}
Владислав Наумов44c64b72020-12-04 20:22:53 +0100189 Use MacOS node as seed: ${seedMacOs}
vnaumov33747e12020-05-04 17:35:20 +0200190 Child cluster deployment scheduled: ${deployChild}
191 Child cluster release upgrade scheduled: ${upgradeChild}
192 Child conformance testing scheduled: ${runChildConformance}
Владислав Наумов0dc99252020-11-13 13:30:48 +0100193 BYO cluster attachment scheduled: ${attachBYO}
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100194 Attached BYO cluster upgrade test scheduled: ${upgradeBYO}
vnaumov33747e12020-05-04 17:35:20 +0200195 Mgmt cluster release upgrade scheduled: ${upgradeMgmt}
196 Mgmt conformance testing scheduled: ${runMgmtConformance}
197 Mgmt UI e2e testing scheduled: ${runUie2e}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200198 AWS provider deployment scheduled: ${awsOnDemandDemo}
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400199 VSPHERE provider deployment scheduled: ${vsphereOnDemandDemo}
eromanovadf247c32020-12-25 15:44:13 +0400200 EQUINIX child cluster deployment scheduled: ${equinixOnAwsDemo}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200201 OS provider deployment scheduled: ${enableOSDemo}
azvyagintsev1761bdc2020-09-04 17:24:12 +0300202 BM provider deployment scheduled: ${enableBMDemo}
Владислав Наумовf793fe32020-09-11 15:19:19 +0200203 Multiregional configuration: ${multiregionalMappings}
vnaumov33747e12020-05-04 17:35:20 +0200204 Service binaries fetching scheduled: ${fetchServiceBinaries}
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100205 Current weight of the demo run: ${demoWeight} (Used to manage lockable resources)
Владислав Наумов81777472021-03-09 15:14:27 +0400206 Triggers: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
vnaumov33747e12020-05-04 17:35:20 +0200207 return [
Владислав Наумовb8305e22021-02-10 17:23:12 +0100208 cdnConfig : cdnConfig,
209 proxyConfig : proxyConfig,
Владислав Наумов44c64b72020-12-04 20:22:53 +0100210 useMacOsSeedNode : seedMacOs,
azvyagintseva12230a2020-06-05 13:24:06 +0300211 deployChildEnabled : deployChild,
212 upgradeChildEnabled : upgradeChild,
213 runChildConformanceEnabled : runChildConformance,
Владислав Наумов0dc99252020-11-13 13:30:48 +0100214 attachBYOEnabled : attachBYO,
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100215 upgradeBYOEnabled : upgradeBYO,
azvyagintseva12230a2020-06-05 13:24:06 +0300216 upgradeMgmtEnabled : upgradeMgmt,
217 runUie2eEnabled : runUie2e,
218 runMgmtConformanceEnabled : runMgmtConformance,
vnaumov33747e12020-05-04 17:35:20 +0200219 fetchServiceBinariesEnabled: fetchServiceBinaries,
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200220 awsOnDemandDemoEnabled : awsOnDemandDemo,
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400221 vsphereOnDemandDemoEnabled : vsphereOnDemandDemo,
eromanovadf247c32020-12-25 15:44:13 +0400222 equinixOnAwsDemoEnabled : equinixOnAwsDemo,
azvyagintsev1761bdc2020-09-04 17:24:12 +0300223 bmDemoEnabled : enableBMDemo,
Владислав Наумовf793fe32020-09-11 15:19:19 +0200224 osDemoEnabled : enableOSDemo,
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100225 multiregionalConfiguration : multiregionalMappings,
226 demoWeight : demoWeight]
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200227}
228
229/**
230 * Determine management and regional setup for demo workflow scenario
231 *
232 *
233 * @param: keyword (string) string , represents keyworkd trigger, specified in gerrit commit body, like `[multiregion aws,os]`
234 or Jenkins environment string variable in form like 'aws,os'
235 * @return (map)[
236 enabled: (bool),
237 * managementLocation: (string), //aws,os
238 * regionLocation: (string), //aws,os
239 * ]
240 */
241def multiregionWorkflowParser(keyword) {
Владислав Наумов8c0c39d2020-09-11 14:46:48 +0200242 def common = new com.mirantis.mk.Common()
Stanislav Riazanovb1d4ec62021-03-29 23:06:54 +0400243 def supportedManagementProviders = ['os', 'aws', 'vsphere']
244 def supportedRegionalProviders = ['os', 'vsphere']
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200245
246 def clusterTypes = ''
Владислав Наумов38ed7bf2020-09-11 14:43:39 +0200247 if (keyword.toString().contains('multiregion')) {
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200248 common.infoMsg('Multiregion definition configured via gerrit keyword trigger')
249 clusterTypes = keyword[0][0].split('multiregion')[1].replaceAll('[\\[\\]]', '').trim().split(',')
250 } else {
251 common.infoMsg('Multiregion definition configured via environment variable')
252 clusterTypes = keyword.trim().split(',')
253 }
254
255 if (clusterTypes.size() != 2) {
Владислав Наумов482fb502020-10-30 17:59:27 +0100256 error("Incorrect regions definiton, valid scheme: [multiregion ${management}, ${region}], got: ${clusterTypes}")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200257 }
258
Владислав Наумовf793fe32020-09-11 15:19:19 +0200259 def desiredManagementProvider = clusterTypes[0].trim()
260 def desiredRegionalProvider = clusterTypes[1].trim()
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200261 if (! supportedManagementProviders.contains(desiredManagementProvider) || ! supportedRegionalProviders.contains(desiredRegionalProvider)) {
262 error("""unsupported management <-> regional bundle, available options:
Владислав Наумовf793fe32020-09-11 15:19:19 +0200263 management providers list - ${supportedManagementProviders}
264 regional providers list - ${supportedRegionalProviders}""")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200265 }
266
267 return [
268 enabled: true,
269 managementLocation: desiredManagementProvider,
270 regionLocation: desiredRegionalProvider,
271 ]
vnaumov33747e12020-05-04 17:35:20 +0200272}
273
274/**
275 * Determine if custom si tests/pipelines refspec forwarded from gerrit change request
276
Владислав Наумов81777472021-03-09 15:14:27 +0400277 * 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 +0200278 * Used for components team to test component changes w/ custom SI refspecs using kaas/core deployment jobs
279 * Example scheme:
280 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
281 * manage refspecs through Jenkins Job Parameters
282 *
azvyagintseva12230a2020-06-05 13:24:06 +0300283 * @return (map)[* siTests: (string) final refspec for si-tests
vnaumov33747e12020-05-04 17:35:20 +0200284 * siPipelines: (string) final refspec for si-pipelines
285 * ]
286 */
287def checkCustomSIRefspec() {
vnaumovbdb90222020-05-04 18:25:50 +0200288 def common = new com.mirantis.mk.Common()
289
vnaumov33747e12020-05-04 17:35:20 +0200290 // Available triggers and its sane defaults
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200291 def siTestsRefspec = env.SI_TESTS_REFSPEC ?: 'master'
292 def siPipelinesRefspec = env.SI_PIPELINES_REFSPEC ?: 'master'
Владислав Наумов2db15e22020-07-14 12:29:22 +0200293 def siTestsDockerImage = env.SI_TESTS_DOCKER_IMAGE ?: 'docker-dev-kaas-local.docker.mirantis.net/mirantis/kaas/si-test'
294 def siTestsDockerImageTag = env.SI_TESTS_DOCKER_IMAGE_TAG ?: 'master'
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200295 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
vnaumov33747e12020-05-04 17:35:20 +0200296
297 def siTestMatches = (commitMsg =~ /(\[si-tests-ref\s*refs\/changes\/.*?\])/)
298 def siPipelinesMatches = (commitMsg =~ /(\[si-pipelines-ref\s*refs\/changes\/.*?\])/)
299
300 if (siTestMatches.size() > 0) {
301 siTestsRefspec = siTestMatches[0][0].split('si-tests-ref')[1].replaceAll('[\\[\\]]', '').trim()
Владислав Наумов7f6c0882021-03-23 19:10:57 +0400302 siTestsDockerImage = "docker-review-local.docker.mirantis.net/review/kaas-si-test-${siTestsRefspec.split('/')[-2]}"
Владислав Наумов2db15e22020-07-14 12:29:22 +0200303 siTestsDockerImageTag = siTestsRefspec.split('/')[-1]
vnaumov33747e12020-05-04 17:35:20 +0200304 }
305 if (siPipelinesMatches.size() > 0) {
306 siPipelinesRefspec = siPipelinesMatches[0][0].split('si-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
307 }
308
309 common.infoMsg("""
310 kaas/si-pipelines will be fetched from: ${siPipelinesRefspec}
311 kaas/si-tests will be fetched from: ${siTestsRefspec}
Владислав Наумов2db15e22020-07-14 12:29:22 +0200312 kaas/si-tests as dockerImage will be fetched from: ${siTestsDockerImage}:${siTestsDockerImageTag}
Владислав Наумов81777472021-03-09 15:14:27 +0400313 Keywords: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
Владислав Наумов2db15e22020-07-14 12:29:22 +0200314 return [siTests: siTestsRefspec, siPipelines: siPipelinesRefspec, siTestsDockerImage: siTestsDockerImage, siTestsDockerImageTag: siTestsDockerImageTag]
vnaumov33747e12020-05-04 17:35:20 +0200315}
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200316
Владислав Наумов9080f372020-06-08 13:57:16 +0200317/**
Владислав Наумов418042b2020-07-09 18:31:10 +0200318 * Parse additional configuration for kaas component CICD repo
Владислав Наумов30a516c2020-07-09 13:15:41 +0200319 * @param configurationFile (str) path to configuration file in yaml format
320 *
321 * @return (map)[ siTestsFeatureFlags (string) dedicated feature flags that will be used in SI tests,
322 * ]
323 */
324def parseKaaSComponentCIParameters(configurationFile){
325 def common = new com.mirantis.mk.Common()
326 def ciConfig = readYaml file: configurationFile
327 def ciSpec = [
328 siTestsFeatureFlags: env.SI_TESTS_FEATURE_FLAGS ?: '',
329 ]
330
331 if (ciConfig.containsKey('si-tests-feature-flags')) {
332 common.infoMsg("""SI tests feature flags customization detected,
333 results will be merged with existing flags: [${ciSpec['siTestsFeatureFlags']}] identification...""")
334
335 def ffMeta = ciSpec['siTestsFeatureFlags'].tokenize(',').collect { it.trim() }
336 ffMeta.addAll(ciConfig['si-tests-feature-flags'])
Владислав Наумов30a516c2020-07-09 13:15:41 +0200337
Владислав Наумовcb5ffca2020-07-14 15:28:36 +0200338 ciSpec['siTestsFeatureFlags'] = ffMeta.unique().join(',')
Владислав Наумов30a516c2020-07-09 13:15:41 +0200339 common.infoMsg("SI tests custom feature flags: ${ciSpec['siTestsFeatureFlags']}")
340 }
341
342 common.infoMsg("""Additional ci configuration parsed successfully:
343 siTestsFeatureFlags: ${ciSpec['siTestsFeatureFlags']}""")
344 return ciSpec
345}
346
347/**
348 * Determine if custom kaas core/pipelines refspec forwarded from gerrit change request
Владислав Наумов9080f372020-06-08 13:57:16 +0200349
Владислав Наумов81777472021-03-09 15:14:27 +0400350 * 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 +0200351 * Used for components team to test component changes w/ custom Core refspecs using kaas/core deployment jobs
352 * Example scheme:
353 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
354 * manage refspecs through Jenkins Job Parameters
355 *
356 * @return (map)[ core: (string) final refspec for kaas/core
357 * corePipelines: (string) final refspec for pipelines in kaas/core
358 * ]
359 */
360def checkCustomCoreRefspec() {
361 def common = new com.mirantis.mk.Common()
362
363 // Available triggers and its sane defaults
364 def coreRefspec = env.KAAS_CORE_REFSPEC ?: 'master'
365 // by default using value of GERRIT_REFSPEC parameter in *kaas/core jobs*
366 def corePipelinesRefspec = env.KAAS_PIPELINE_REFSPEC ?: '\$GERRIT_REFSPEC'
367 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
368
369 def coreMatches = (commitMsg =~ /(\[core-ref\s*refs\/changes\/.*?\])/)
370 def corePipelinesMatches = (commitMsg =~ /(\[core-pipelines-ref\s*refs\/changes\/.*?\])/)
371
372 if (coreMatches.size() > 0) {
373 coreRefspec = coreMatches[0][0].split('core-ref')[1].replaceAll('[\\[\\]]', '').trim()
374 }
375 if (corePipelinesMatches.size() > 0) {
376 corePipelinesRefspec = corePipelinesMatches[0][0].split('core-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
377 }
378
379 common.infoMsg("""
380 kaas/core will be fetched from: ${coreRefspec}
381 kaas/core pipelines will be fetched from: ${corePipelinesRefspec}
Владислав Наумов81777472021-03-09 15:14:27 +0400382 Keywords: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
Владислав Наумов9080f372020-06-08 13:57:16 +0200383 return [core: coreRefspec, corePipelines: corePipelinesRefspec]
384}
385
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200386
387/**
Владислав Наумов92288d92020-07-13 18:36:21 +0200388 * generate Jenkins Parameter objects from from text parameter with additonal kaas core context
389 * needed to forward inside kaas core set of jobs
390 *
391 * @param context (string) Representation of the string enviroment variables needed for kaas core jobs in yaml format
392 * @return (list)[ string(name: '', value: ''),
393 * ]
394 */
395def generateKaaSVarsFromContext(context) {
396 def common = new com.mirantis.mk.Common()
397 def parameters = []
398 def config = readYaml text: context
399
400 config.each { k,v ->
401 common.infoMsg("Custom KaaS Core context parameter: ${k}=${v}")
402 parameters.add(string(name: k, value: v))
403 }
404
405 return parameters
406}
407
408/**
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200409 * 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 +0400410 * 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 +0200411 * Used for components team to test component changes w/ customized SI tests/refspecs using kaas/core deployment jobs
412 *
Владислав Наумов418042b2020-07-09 18:31:10 +0200413 * @param: component (string) component name [iam, lcm, stacklight]
414 * @param: patchSpec (string) Patch for kaas/cluster releases in json format
415 * @param: configurationFile (string) Additional file for component repo CI config in yaml format
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200416 */
Владислав Наумов92288d92020-07-13 18:36:21 +0200417def triggerPatchedComponentDemo(component, patchSpec = '', configurationFile = '.ci-parameters.yaml', coreContext = '') {
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200418 def common = new com.mirantis.mk.Common()
419 // Determine if custom trigger keywords forwarded from gerrit
420 def triggers = checkDeploymentTestSuite()
421 // Determine SI refspecs
422 def siRefspec = checkCustomSIRefspec()
Владислав Наумов9080f372020-06-08 13:57:16 +0200423 // Determine Core refspecs
424 def coreRefspec = checkCustomCoreRefspec()
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200425
Владислав Наумов418042b2020-07-09 18:31:10 +0200426 // Determine component repo ci configuration
427 def ciSpec = [:]
428 def componentFeatureFlags = env.SI_TESTS_FEATURE_FLAGS ?: ''
429 if (fileExists(configurationFile)) {
430 common.infoMsg('Component CI configuration file detected, parsing...')
431 ciSpec = parseKaaSComponentCIParameters(configurationFile)
432 componentFeatureFlags = ciSpec['siTestsFeatureFlags']
433 } else {
434 common.warningMsg('''Component CI configuration file is not exists,
Владислав Наумовc17dd552020-07-29 17:07:38 +0200435 several code-management features may be unavailable,
Владислав Наумов92288d92020-07-13 18:36:21 +0200436 follow https://mirantis.jira.com/wiki/spaces/QA/pages/2310832276/SI-tests+feature+flags#%5BUpdated%5D-Using-a-feature-flag
437 to create the configuration file''')
Владислав Наумов418042b2020-07-09 18:31:10 +0200438 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200439 def jobs = [:]
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200440 def parameters = [
Владислав Наумов9080f372020-06-08 13:57:16 +0200441 string(name: 'GERRIT_REFSPEC', value: coreRefspec.core),
442 string(name: 'KAAS_PIPELINE_REFSPEC', value: coreRefspec.corePipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200443 string(name: 'SI_TESTS_REFSPEC', value: siRefspec.siTests),
Владислав Наумов418042b2020-07-09 18:31:10 +0200444 string(name: 'SI_TESTS_FEATURE_FLAGS', value: componentFeatureFlags),
Владислав Наумов2db15e22020-07-14 12:29:22 +0200445 string(name: 'SI_TESTS_DOCKER_IMAGE', value: siRefspec.siTestsDockerImage),
446 string(name: 'SI_TESTS_DOCKER_IMAGE_TAG', value: siRefspec.siTestsDockerImageTag),
Владислав Наумов4a5c3242020-06-08 14:36:11 +0200447 string(name: 'SI_PIPELINES_REFSPEC', value: siRefspec.siPipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200448 string(name: 'CUSTOM_RELEASE_PATCH_SPEC', value: patchSpec),
Владислав Наумовb8305e22021-02-10 17:23:12 +0100449 booleanParam(name: 'OFFLINE_MGMT_CLUSTER', value: triggers.proxyConfig['mgmtOffline']),
Владислав Наумов44c64b72020-12-04 20:22:53 +0100450 booleanParam(name: 'SEED_MACOS', value: triggers.useMacOsSeedNode),
Владислав Наумов080d9412020-07-29 13:05:14 +0200451 booleanParam(name: 'UPGRADE_MGMT_CLUSTER', value: triggers.upgradeMgmtEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200452 booleanParam(name: 'RUN_UI_E2E', value: triggers.runUie2eEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200453 booleanParam(name: 'RUN_MGMT_CFM', value: triggers.runMgmtConformanceEnabled),
454 booleanParam(name: 'DEPLOY_CHILD_CLUSTER', value: triggers.deployChildEnabled),
455 booleanParam(name: 'UPGRADE_CHILD_CLUSTER', value: triggers.upgradeChildEnabled),
Владислав Наумов0dc99252020-11-13 13:30:48 +0100456 booleanParam(name: 'ATTACH_BYO', value: triggers.attachBYOEnabled),
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100457 booleanParam(name: 'UPGRADE_BYO', value: triggers.upgradeBYOEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200458 booleanParam(name: 'RUN_CHILD_CFM', value: triggers.runChildConformanceEnabled),
Ivan Berezovskiycbf9eeb2021-03-22 15:57:32 +0400459 booleanParam(name: 'ALLOW_AWS_ON_DEMAND', value: triggers.awsOnDemandDemoEnabled),
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400460 booleanParam(name: 'ALLOW_VSPHERE_ON_DEMAND', value: triggers.vsphereOnDemandDemoEnabled),
eromanovad3397512021-04-01 20:19:19 +0400461 booleanParam(name: 'EQUINIX_ON_AWS_DEMO', value: triggers.equinixOnAwsDemoEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200462 ]
Владислав Наумов92288d92020-07-13 18:36:21 +0200463
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200464 // customize multiregional demo
465 if (triggers.multiregionalConfiguration.enabled) {
466 parameters.add(string(name: 'MULTIREGION_SETUP',
467 value: "${triggers.multiregionalConfiguration.managementLocation},${triggers.multiregionalConfiguration.regionLocation}"
468 ))
469 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200470
Владислав Наумов92288d92020-07-13 18:36:21 +0200471 // Determine component team custom context
472 if (coreContext != '') {
473 common.infoMsg('Additional KaaS Core context detected, will be forwarded into kaas core cicd...')
474 def additionalParameters = generateKaaSVarsFromContext(coreContext)
Владислав Наумовbef51a92020-10-01 17:36:51 +0200475 parameters.addAll(additionalParameters)
Владислав Наумов92288d92020-07-13 18:36:21 +0200476 }
477
Владислав Наумовaa430612020-06-08 17:18:31 +0200478 def jobResults = []
Владислав Наумов37f7f842021-03-09 16:08:39 +0400479 if (triggers.osDemoEnabled) {
480 jobs["kaas-core-openstack-patched-${component}"] = {
481 try {
482 common.infoMsg('Deploy: patched KaaS demo with Openstack provider')
483 os_job_info = build job: "kaas-testing-core-openstack-workflow-${component}", parameters: parameters, wait: true
484 def build_description = os_job_info.getDescription()
485 def build_result = os_job_info.getResult()
486 jobResults.add(build_result)
Владислав Наумовd044e842020-06-17 15:33:43 +0200487
Владислав Наумов37f7f842021-03-09 16:08:39 +0400488 if (build_description) {
489 currentBuild.description += build_description
490 }
491 } finally {
492 common.infoMsg('Patched KaaS demo with Openstack provider finished')
Владислав Наумовf86b1112020-06-09 14:04:48 +0200493 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200494 }
495 }
496 if (triggers.awsOnDemandDemoEnabled) {
Владислав Наумов59281952020-07-29 16:43:49 +0200497 common.infoMsg('AWS demo triggered, need to sync artifacts in the public-ci cdn..')
498 switch (component) {
499 case 'iam':
500 build job: 'cdn-binary-dev-replication-iam', propagate: true, wait: true
501 break
502 case 'lcm':
503 build job: 'cdn-binary-dev-replication-lcm', propagate: true, wait: true
504 break
505 }
506
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200507 jobs["kaas-core-aws-patched-${component}"] = {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200508 try {
509 common.infoMsg('Deploy: patched KaaS demo with AWS provider')
Владислав Наумов4aa112d2020-06-16 18:52:21 +0200510 aws_job_info = build job: "kaas-testing-core-aws-workflow-${component}", parameters: parameters, wait: true
511 def build_description = aws_job_info.getDescription()
Владислав Наумовd044e842020-06-17 15:33:43 +0200512 def build_result = aws_job_info.getResult()
513 jobResults.add(build_result)
514
Владислав Наумовf86b1112020-06-09 14:04:48 +0200515 if (build_description) {
516 currentBuild.description += build_description
517 }
518 } finally {
Владислав Наумов6d741fa2020-06-17 17:35:43 +0200519 common.infoMsg('Patched KaaS demo with AWS provider finished')
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200520 }
521 }
522 }
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400523 if (triggers.vsphereOnDemandDemoEnabled) {
524 jobs["kaas-core-vsphere-patched-${component}"] = {
525 try {
526 common.infoMsg('Deploy: patched KaaS demo with VSPHERE provider')
527 vsphere_job_info = build job: "kaas-testing-core-vsphere-workflow-${component}", parameters: parameters, wait: true
528 def build_description = vsphere_job_info.getDescription()
529 def build_result = vsphere_job_info.getResult()
530 jobResults.add(build_result)
531
532 if (build_description) {
533 currentBuild.description += build_description
534 }
535 } finally {
536 common.infoMsg('Patched KaaS demo with VSPHERE provider finished')
537 }
538 }
539 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200540
541 common.infoMsg('Trigger KaaS demo deployments according to defined provider set')
Владислав Наумов37f7f842021-03-09 16:08:39 +0400542 if (jobs.size() == 0) {
543 error('No demo jobs matched with keywords, execution will be aborted, at least 1 provider should be enabled')
544 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200545 // Limit build concurency workaround examples: https://issues.jenkins-ci.org/browse/JENKINS-44085
546 parallel jobs
Владислав Наумовaa430612020-06-08 17:18:31 +0200547
548 if (jobResults.contains('FAILURE')) {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200549 common.infoMsg('One of parallel downstream jobs is failed, mark executor job as failed')
Владислав Наумовaa430612020-06-08 17:18:31 +0200550 currentBuild.result = 'FAILURE'
551 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200552}
Владислав Наумов30a516c2020-07-09 13:15:41 +0200553
554