blob: 3c529177aa38ad6a12078b9f9bee275dcf1679e2 [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,
Владислав Наумовb8305e22021-02-10 17:23:12 +010072 ]
73
Владислав Наумов4eb1da32020-08-31 14:45:16 +020074 // optional demo deployment customization
Владислав Наумов905dd362020-06-08 16:37:01 +020075 def awsOnDemandDemo = env.ALLOW_AWS_ON_DEMAND ? env.ALLOW_AWS_ON_DEMAND.toBoolean() : false
Владислав Наумов6ec74302020-11-05 12:38:53 +010076 def vsphereOnDemandDemo = env.ALLOW_VSPHERE_ON_DEMAND ? env.ALLOW_VSPHERE_ON_DEMAND.toBoolean() : false
eromanovadf247c32020-12-25 15:44:13 +040077 def equinixOnAwsDemo = false
Владислав Наумов4eb1da32020-08-31 14:45:16 +020078 def enableOSDemo = true
azvyagintsev1761bdc2020-09-04 17:24:12 +030079 def enableBMDemo = true
vnaumov33747e12020-05-04 17:35:20 +020080
Владислав Наумов6c2afff2020-06-05 12:54:53 +020081 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
Владислав Наумовb8305e22021-02-10 17:23:12 +010082 if (commitMsg ==~ /(?s).*\[mgmt-proxy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-proxy.*/) {
83 proxyConfig['mgmtOffline'] = true
84 common.warningMsg('Forced running offline mgmt deployment, all provider CDN regions for mgmt deployment will be set to *public-ci* to verify proxy configuration')
85 }
Владислав Наумов44c64b72020-12-04 20:22:53 +010086 if (commitMsg ==~ /(?s).*\[seed-macos\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*seed-macos.*/) {
87 seedMacOs = true
88 }
vnaumov33747e12020-05-04 17:35:20 +020089 if (commitMsg ==~ /(?s).*\[child-deploy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-deploy.*/ || upgradeChild || runChildConformance) {
90 deployChild = true
91 }
92 if (commitMsg ==~ /(?s).*\[child-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-upgrade.*/) {
93 deployChild = true
94 upgradeChild = true
95 }
Владислав Наумов0dc99252020-11-13 13:30:48 +010096 if (commitMsg ==~ /(?s).*\[byo-attach\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-attach.*/) {
97 attachBYO = true
98 }
Владислав Наумовcdbd84e2020-12-01 16:51:09 +010099 if (commitMsg ==~ /(?s).*\[byo-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-upgrade.*/) {
100 attachBYO = true
101 upgradeBYO = true
102 }
Владислав Наумов7f8c9872021-03-08 17:33:08 +0400103 if (commitMsg ==~ /(?s).*\[mgmt-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-upgrade.*/) {
vnaumov33747e12020-05-04 17:35:20 +0200104 upgradeMgmt = true
105 }
106 if (commitMsg ==~ /(?s).*\[ui-e2e\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*ui-e2e.*/) {
107 runUie2e = true
108 }
109 if (commitMsg ==~ /(?s).*\[mgmt-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-cfm.*/) {
110 runMgmtConformance = true
111 }
112 if (commitMsg ==~ /(?s).*\[child-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-cfm.*/) {
113 runChildConformance = true
114 deployChild = true
115 }
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200116 if (commitMsg ==~ /(?s).*\[child-offline\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-offline.*/) {
117 proxyConfig['childOffline'] = true
118 deployChild = true
119 }
vnaumov33747e12020-05-04 17:35:20 +0200120 if (commitMsg ==~ /(?s).*\[fetch.*binaries\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*fetch.*binaries.*/) {
121 fetchServiceBinaries = true
122 }
eromanovadf247c32020-12-25 15:44:13 +0400123 if (commitMsg ==~ /(?s).*\[equinix-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinix-demo.*/) {
124 equinixOnAwsDemo = true
125 common.warningMsg('Forced running child cluster deployment on EQUINIX METAL provider based on AWS management cluster, triggered on patchset using custom keyword: \'[equinix-demo]\' ')
126 }
127 if (commitMsg ==~ /(?s).*\[aws-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*aws-demo.*/ || attachBYO || upgradeBYO || seedMacOs || equinixOnAwsDemo) {
vnaumov33747e12020-05-04 17:35:20 +0200128 awsOnDemandDemo = true
eromanovadf247c32020-12-25 15:44:13 +0400129 if (attachBYO || upgradeBYO || seedMacOs || equinixOnAwsDemo) {
Владислав Наумов44c64b72020-12-04 20:22:53 +0100130 common.warningMsg('Forced running additional kaas deployment with AWS provider, due applied trigger cross dependencies, follow docs to clarify info')
Владислав Наумов0dc99252020-11-13 13:30:48 +0100131 }
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200132 }
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400133 if (commitMsg ==~ /(?s).*\[vsphere-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*vsphere-demo.*/) {
134 vsphereOnDemandDemo = true
135 common.warningMsg('Forced running additional kaas deployment with VSPHERE provider, triggered on patchset using custom keyword: \'[vsphere-demo]\' ')
136 }
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200137 if (commitMsg ==~ /(?s).*\[disable-os-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-os-demo\.*/) {
138 enableOSDemo = false
139 common.errorMsg('Openstack demo deployment will be aborted, VF -1 will be set')
vnaumov33747e12020-05-04 17:35:20 +0200140 }
141
azvyagintsev1761bdc2020-09-04 17:24:12 +0300142 if (commitMsg ==~ /(?s).*\[disable-bm-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-bm-demo\.*/) {
143 enableBMDemo = false
144 common.errorMsg('BM demo deployment will be aborted, VF -1 will be set')
145 }
146
vnaumov33747e12020-05-04 17:35:20 +0200147 // TODO (vnaumov) remove below condition after moving all releases to UCP
148 def ucpChildMatches = (commitMsg =~ /(\[child-ucp\s*ucp-.*?\])/)
149 if (ucpChildMatches.size() > 0) {
150 deployChild = true
151 common.warningMsg('Forced UCP based child deployment triggered on patchset using custom keyword: \'[child-ucp ucp-5-1-0-3-3-0-example]\' ')
152
153 // TODO(vnaumov) delete after ucp upgrades support
154 common.errorMsg('Child upgrade test will be skipped, UCP upgrades temporally disabled')
155 upgradeChild = false
156 }
157
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200158 // multiregional tests
159 def multiRegionalMatches = (commitMsg =~ /(\[multiregion\s*.*?\])/)
160 if (multiRegionalMatches.size() > 0) {
161 multiregionalMappings = multiregionWorkflowParser(multiRegionalMatches)
162 }
163 switch (multiregionalMappings['managementLocation']) {
164 case 'aws':
Владислав Наумов53b07e52021-01-07 15:08:27 +0100165 common.warningMsg('Forced running additional kaas deployment with AWS provider according multiregional demo request')
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200166 awsOnDemandDemo = true
Владислав Наумов53b07e52021-01-07 15:08:27 +0100167
168 if (multiregionalMappings['regionLocation'] != 'aws' && seedMacOs) { // macstadium seed node has access only to *public* providers
169 error('incompatible triggers: [seed-macos] and multiregional deployment based on *private* regional provider cannot be applied simultaneously')
170 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200171 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200172 case 'os':
173 if (enableOSDemo == false) {
174 error('incompatible triggers: [disable-os-demo] and multiregional deployment based on OSt management region cannot be applied simultaneously')
175 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200176 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200177 }
178
Владислав Наумовb8305e22021-02-10 17:23:12 +0100179 // CDN configuration
180 def cdnConfig = [
181 mgmt: [
182 openstack: (proxyConfig['mgmtOffline'] == true) ? 'public-ci' : 'internal-ci',
183 vsphere: (proxyConfig['mgmtOffline'] == true) ? 'public-ci' : 'internal-ci',
184 aws: 'public-ci',
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200185 ],
Владислав Наумовb8305e22021-02-10 17:23:12 +0100186 ]
187
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100188 // calculate weight of current demo run to manage lockable resources
189 def demoWeight = (deployChild) ? 2 : 1 // management = 1, child = 1
190
vnaumov33747e12020-05-04 17:35:20 +0200191 common.infoMsg("""
Владислав Наумовb8305e22021-02-10 17:23:12 +0100192 CDN deployment configuration: ${cdnConfig}
193 MCC offline deployment configuration: ${proxyConfig}
Владислав Наумов44c64b72020-12-04 20:22:53 +0100194 Use MacOS node as seed: ${seedMacOs}
vnaumov33747e12020-05-04 17:35:20 +0200195 Child cluster deployment scheduled: ${deployChild}
196 Child cluster release upgrade scheduled: ${upgradeChild}
197 Child conformance testing scheduled: ${runChildConformance}
Владислав Наумов0dc99252020-11-13 13:30:48 +0100198 BYO cluster attachment scheduled: ${attachBYO}
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100199 Attached BYO cluster upgrade test scheduled: ${upgradeBYO}
vnaumov33747e12020-05-04 17:35:20 +0200200 Mgmt cluster release upgrade scheduled: ${upgradeMgmt}
201 Mgmt conformance testing scheduled: ${runMgmtConformance}
202 Mgmt UI e2e testing scheduled: ${runUie2e}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200203 AWS provider deployment scheduled: ${awsOnDemandDemo}
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400204 VSPHERE provider deployment scheduled: ${vsphereOnDemandDemo}
eromanovadf247c32020-12-25 15:44:13 +0400205 EQUINIX child cluster deployment scheduled: ${equinixOnAwsDemo}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200206 OS provider deployment scheduled: ${enableOSDemo}
azvyagintsev1761bdc2020-09-04 17:24:12 +0300207 BM provider deployment scheduled: ${enableBMDemo}
Владислав Наумовf793fe32020-09-11 15:19:19 +0200208 Multiregional configuration: ${multiregionalMappings}
vnaumov33747e12020-05-04 17:35:20 +0200209 Service binaries fetching scheduled: ${fetchServiceBinaries}
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100210 Current weight of the demo run: ${demoWeight} (Used to manage lockable resources)
Владислав Наумов81777472021-03-09 15:14:27 +0400211 Triggers: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
vnaumov33747e12020-05-04 17:35:20 +0200212 return [
Владислав Наумовb8305e22021-02-10 17:23:12 +0100213 cdnConfig : cdnConfig,
214 proxyConfig : proxyConfig,
Владислав Наумов44c64b72020-12-04 20:22:53 +0100215 useMacOsSeedNode : seedMacOs,
azvyagintseva12230a2020-06-05 13:24:06 +0300216 deployChildEnabled : deployChild,
217 upgradeChildEnabled : upgradeChild,
218 runChildConformanceEnabled : runChildConformance,
Владислав Наумов0dc99252020-11-13 13:30:48 +0100219 attachBYOEnabled : attachBYO,
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100220 upgradeBYOEnabled : upgradeBYO,
azvyagintseva12230a2020-06-05 13:24:06 +0300221 upgradeMgmtEnabled : upgradeMgmt,
222 runUie2eEnabled : runUie2e,
223 runMgmtConformanceEnabled : runMgmtConformance,
vnaumov33747e12020-05-04 17:35:20 +0200224 fetchServiceBinariesEnabled: fetchServiceBinaries,
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200225 awsOnDemandDemoEnabled : awsOnDemandDemo,
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400226 vsphereOnDemandDemoEnabled : vsphereOnDemandDemo,
eromanovadf247c32020-12-25 15:44:13 +0400227 equinixOnAwsDemoEnabled : equinixOnAwsDemo,
azvyagintsev1761bdc2020-09-04 17:24:12 +0300228 bmDemoEnabled : enableBMDemo,
Владислав Наумовf793fe32020-09-11 15:19:19 +0200229 osDemoEnabled : enableOSDemo,
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100230 multiregionalConfiguration : multiregionalMappings,
231 demoWeight : demoWeight]
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200232}
233
234/**
235 * Determine management and regional setup for demo workflow scenario
236 *
237 *
238 * @param: keyword (string) string , represents keyworkd trigger, specified in gerrit commit body, like `[multiregion aws,os]`
239 or Jenkins environment string variable in form like 'aws,os'
240 * @return (map)[
241 enabled: (bool),
242 * managementLocation: (string), //aws,os
243 * regionLocation: (string), //aws,os
244 * ]
245 */
246def multiregionWorkflowParser(keyword) {
Владислав Наумов8c0c39d2020-09-11 14:46:48 +0200247 def common = new com.mirantis.mk.Common()
Stanislav Riazanovb1d4ec62021-03-29 23:06:54 +0400248 def supportedManagementProviders = ['os', 'aws', 'vsphere']
249 def supportedRegionalProviders = ['os', 'vsphere']
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200250
251 def clusterTypes = ''
Владислав Наумов38ed7bf2020-09-11 14:43:39 +0200252 if (keyword.toString().contains('multiregion')) {
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200253 common.infoMsg('Multiregion definition configured via gerrit keyword trigger')
254 clusterTypes = keyword[0][0].split('multiregion')[1].replaceAll('[\\[\\]]', '').trim().split(',')
255 } else {
256 common.infoMsg('Multiregion definition configured via environment variable')
257 clusterTypes = keyword.trim().split(',')
258 }
259
260 if (clusterTypes.size() != 2) {
Владислав Наумов482fb502020-10-30 17:59:27 +0100261 error("Incorrect regions definiton, valid scheme: [multiregion ${management}, ${region}], got: ${clusterTypes}")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200262 }
263
Владислав Наумовf793fe32020-09-11 15:19:19 +0200264 def desiredManagementProvider = clusterTypes[0].trim()
265 def desiredRegionalProvider = clusterTypes[1].trim()
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200266 if (! supportedManagementProviders.contains(desiredManagementProvider) || ! supportedRegionalProviders.contains(desiredRegionalProvider)) {
267 error("""unsupported management <-> regional bundle, available options:
Владислав Наумовf793fe32020-09-11 15:19:19 +0200268 management providers list - ${supportedManagementProviders}
269 regional providers list - ${supportedRegionalProviders}""")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200270 }
271
272 return [
273 enabled: true,
274 managementLocation: desiredManagementProvider,
275 regionLocation: desiredRegionalProvider,
276 ]
vnaumov33747e12020-05-04 17:35:20 +0200277}
278
279/**
280 * Determine if custom si tests/pipelines refspec forwarded from gerrit change request
281
Владислав Наумов81777472021-03-09 15:14:27 +0400282 * 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 +0200283 * Used for components team to test component changes w/ custom SI refspecs using kaas/core deployment jobs
284 * Example scheme:
285 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
286 * manage refspecs through Jenkins Job Parameters
287 *
azvyagintseva12230a2020-06-05 13:24:06 +0300288 * @return (map)[* siTests: (string) final refspec for si-tests
vnaumov33747e12020-05-04 17:35:20 +0200289 * siPipelines: (string) final refspec for si-pipelines
290 * ]
291 */
292def checkCustomSIRefspec() {
vnaumovbdb90222020-05-04 18:25:50 +0200293 def common = new com.mirantis.mk.Common()
294
vnaumov33747e12020-05-04 17:35:20 +0200295 // Available triggers and its sane defaults
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200296 def siTestsRefspec = env.SI_TESTS_REFSPEC ?: 'master'
297 def siPipelinesRefspec = env.SI_PIPELINES_REFSPEC ?: 'master'
Владислав Наумов2db15e22020-07-14 12:29:22 +0200298 def siTestsDockerImage = env.SI_TESTS_DOCKER_IMAGE ?: 'docker-dev-kaas-local.docker.mirantis.net/mirantis/kaas/si-test'
299 def siTestsDockerImageTag = env.SI_TESTS_DOCKER_IMAGE_TAG ?: 'master'
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200300 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
vnaumov33747e12020-05-04 17:35:20 +0200301
302 def siTestMatches = (commitMsg =~ /(\[si-tests-ref\s*refs\/changes\/.*?\])/)
303 def siPipelinesMatches = (commitMsg =~ /(\[si-pipelines-ref\s*refs\/changes\/.*?\])/)
304
305 if (siTestMatches.size() > 0) {
306 siTestsRefspec = siTestMatches[0][0].split('si-tests-ref')[1].replaceAll('[\\[\\]]', '').trim()
Владислав Наумов7f6c0882021-03-23 19:10:57 +0400307 siTestsDockerImage = "docker-review-local.docker.mirantis.net/review/kaas-si-test-${siTestsRefspec.split('/')[-2]}"
Владислав Наумов2db15e22020-07-14 12:29:22 +0200308 siTestsDockerImageTag = siTestsRefspec.split('/')[-1]
vnaumov33747e12020-05-04 17:35:20 +0200309 }
310 if (siPipelinesMatches.size() > 0) {
311 siPipelinesRefspec = siPipelinesMatches[0][0].split('si-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
312 }
313
314 common.infoMsg("""
315 kaas/si-pipelines will be fetched from: ${siPipelinesRefspec}
316 kaas/si-tests will be fetched from: ${siTestsRefspec}
Владислав Наумов2db15e22020-07-14 12:29:22 +0200317 kaas/si-tests as dockerImage will be fetched from: ${siTestsDockerImage}:${siTestsDockerImageTag}
Владислав Наумов81777472021-03-09 15:14:27 +0400318 Keywords: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
Владислав Наумов2db15e22020-07-14 12:29:22 +0200319 return [siTests: siTestsRefspec, siPipelines: siPipelinesRefspec, siTestsDockerImage: siTestsDockerImage, siTestsDockerImageTag: siTestsDockerImageTag]
vnaumov33747e12020-05-04 17:35:20 +0200320}
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200321
Владислав Наумов9080f372020-06-08 13:57:16 +0200322/**
Владислав Наумов418042b2020-07-09 18:31:10 +0200323 * Parse additional configuration for kaas component CICD repo
Владислав Наумов30a516c2020-07-09 13:15:41 +0200324 * @param configurationFile (str) path to configuration file in yaml format
325 *
326 * @return (map)[ siTestsFeatureFlags (string) dedicated feature flags that will be used in SI tests,
327 * ]
328 */
329def parseKaaSComponentCIParameters(configurationFile){
330 def common = new com.mirantis.mk.Common()
331 def ciConfig = readYaml file: configurationFile
332 def ciSpec = [
333 siTestsFeatureFlags: env.SI_TESTS_FEATURE_FLAGS ?: '',
334 ]
335
336 if (ciConfig.containsKey('si-tests-feature-flags')) {
337 common.infoMsg("""SI tests feature flags customization detected,
338 results will be merged with existing flags: [${ciSpec['siTestsFeatureFlags']}] identification...""")
339
340 def ffMeta = ciSpec['siTestsFeatureFlags'].tokenize(',').collect { it.trim() }
341 ffMeta.addAll(ciConfig['si-tests-feature-flags'])
Владислав Наумов30a516c2020-07-09 13:15:41 +0200342
Владислав Наумовcb5ffca2020-07-14 15:28:36 +0200343 ciSpec['siTestsFeatureFlags'] = ffMeta.unique().join(',')
Владислав Наумов30a516c2020-07-09 13:15:41 +0200344 common.infoMsg("SI tests custom feature flags: ${ciSpec['siTestsFeatureFlags']}")
345 }
346
347 common.infoMsg("""Additional ci configuration parsed successfully:
348 siTestsFeatureFlags: ${ciSpec['siTestsFeatureFlags']}""")
349 return ciSpec
350}
351
352/**
353 * Determine if custom kaas core/pipelines refspec forwarded from gerrit change request
Владислав Наумов9080f372020-06-08 13:57:16 +0200354
Владислав Наумов81777472021-03-09 15:14:27 +0400355 * 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 +0200356 * Used for components team to test component changes w/ custom Core refspecs using kaas/core deployment jobs
357 * Example scheme:
358 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
359 * manage refspecs through Jenkins Job Parameters
360 *
361 * @return (map)[ core: (string) final refspec for kaas/core
362 * corePipelines: (string) final refspec for pipelines in kaas/core
363 * ]
364 */
365def checkCustomCoreRefspec() {
366 def common = new com.mirantis.mk.Common()
367
368 // Available triggers and its sane defaults
369 def coreRefspec = env.KAAS_CORE_REFSPEC ?: 'master'
370 // by default using value of GERRIT_REFSPEC parameter in *kaas/core jobs*
371 def corePipelinesRefspec = env.KAAS_PIPELINE_REFSPEC ?: '\$GERRIT_REFSPEC'
372 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
373
374 def coreMatches = (commitMsg =~ /(\[core-ref\s*refs\/changes\/.*?\])/)
375 def corePipelinesMatches = (commitMsg =~ /(\[core-pipelines-ref\s*refs\/changes\/.*?\])/)
376
377 if (coreMatches.size() > 0) {
378 coreRefspec = coreMatches[0][0].split('core-ref')[1].replaceAll('[\\[\\]]', '').trim()
379 }
380 if (corePipelinesMatches.size() > 0) {
381 corePipelinesRefspec = corePipelinesMatches[0][0].split('core-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
382 }
383
384 common.infoMsg("""
385 kaas/core will be fetched from: ${coreRefspec}
386 kaas/core pipelines will be fetched from: ${corePipelinesRefspec}
Владислав Наумов81777472021-03-09 15:14:27 +0400387 Keywords: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
Владислав Наумов9080f372020-06-08 13:57:16 +0200388 return [core: coreRefspec, corePipelines: corePipelinesRefspec]
389}
390
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200391
392/**
Владислав Наумов92288d92020-07-13 18:36:21 +0200393 * generate Jenkins Parameter objects from from text parameter with additonal kaas core context
394 * needed to forward inside kaas core set of jobs
395 *
396 * @param context (string) Representation of the string enviroment variables needed for kaas core jobs in yaml format
397 * @return (list)[ string(name: '', value: ''),
398 * ]
399 */
400def generateKaaSVarsFromContext(context) {
401 def common = new com.mirantis.mk.Common()
402 def parameters = []
403 def config = readYaml text: context
404
405 config.each { k,v ->
406 common.infoMsg("Custom KaaS Core context parameter: ${k}=${v}")
407 parameters.add(string(name: k, value: v))
408 }
409
410 return parameters
411}
412
413/**
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200414 * 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 +0400415 * 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 +0200416 * Used for components team to test component changes w/ customized SI tests/refspecs using kaas/core deployment jobs
417 *
Владислав Наумов418042b2020-07-09 18:31:10 +0200418 * @param: component (string) component name [iam, lcm, stacklight]
419 * @param: patchSpec (string) Patch for kaas/cluster releases in json format
420 * @param: configurationFile (string) Additional file for component repo CI config in yaml format
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200421 */
Владислав Наумов92288d92020-07-13 18:36:21 +0200422def triggerPatchedComponentDemo(component, patchSpec = '', configurationFile = '.ci-parameters.yaml', coreContext = '') {
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200423 def common = new com.mirantis.mk.Common()
424 // Determine if custom trigger keywords forwarded from gerrit
425 def triggers = checkDeploymentTestSuite()
426 // Determine SI refspecs
427 def siRefspec = checkCustomSIRefspec()
Владислав Наумов9080f372020-06-08 13:57:16 +0200428 // Determine Core refspecs
429 def coreRefspec = checkCustomCoreRefspec()
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200430
Владислав Наумов418042b2020-07-09 18:31:10 +0200431 // Determine component repo ci configuration
432 def ciSpec = [:]
433 def componentFeatureFlags = env.SI_TESTS_FEATURE_FLAGS ?: ''
434 if (fileExists(configurationFile)) {
435 common.infoMsg('Component CI configuration file detected, parsing...')
436 ciSpec = parseKaaSComponentCIParameters(configurationFile)
437 componentFeatureFlags = ciSpec['siTestsFeatureFlags']
438 } else {
439 common.warningMsg('''Component CI configuration file is not exists,
Владислав Наумовc17dd552020-07-29 17:07:38 +0200440 several code-management features may be unavailable,
Владислав Наумов92288d92020-07-13 18:36:21 +0200441 follow https://mirantis.jira.com/wiki/spaces/QA/pages/2310832276/SI-tests+feature+flags#%5BUpdated%5D-Using-a-feature-flag
442 to create the configuration file''')
Владислав Наумов418042b2020-07-09 18:31:10 +0200443 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200444 def jobs = [:]
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200445 def parameters = [
Владислав Наумов9080f372020-06-08 13:57:16 +0200446 string(name: 'GERRIT_REFSPEC', value: coreRefspec.core),
447 string(name: 'KAAS_PIPELINE_REFSPEC', value: coreRefspec.corePipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200448 string(name: 'SI_TESTS_REFSPEC', value: siRefspec.siTests),
Владислав Наумов418042b2020-07-09 18:31:10 +0200449 string(name: 'SI_TESTS_FEATURE_FLAGS', value: componentFeatureFlags),
Владислав Наумов2db15e22020-07-14 12:29:22 +0200450 string(name: 'SI_TESTS_DOCKER_IMAGE', value: siRefspec.siTestsDockerImage),
451 string(name: 'SI_TESTS_DOCKER_IMAGE_TAG', value: siRefspec.siTestsDockerImageTag),
Владислав Наумов4a5c3242020-06-08 14:36:11 +0200452 string(name: 'SI_PIPELINES_REFSPEC', value: siRefspec.siPipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200453 string(name: 'CUSTOM_RELEASE_PATCH_SPEC', value: patchSpec),
Владислав Наумовb8305e22021-02-10 17:23:12 +0100454 booleanParam(name: 'OFFLINE_MGMT_CLUSTER', value: triggers.proxyConfig['mgmtOffline']),
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200455 booleanParam(name: 'OFFLINE_CHILD_CLUSTER', value: triggers.proxyConfig['childOffline']),
Владислав Наумов44c64b72020-12-04 20:22:53 +0100456 booleanParam(name: 'SEED_MACOS', value: triggers.useMacOsSeedNode),
Владислав Наумов080d9412020-07-29 13:05:14 +0200457 booleanParam(name: 'UPGRADE_MGMT_CLUSTER', value: triggers.upgradeMgmtEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200458 booleanParam(name: 'RUN_UI_E2E', value: triggers.runUie2eEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200459 booleanParam(name: 'RUN_MGMT_CFM', value: triggers.runMgmtConformanceEnabled),
460 booleanParam(name: 'DEPLOY_CHILD_CLUSTER', value: triggers.deployChildEnabled),
461 booleanParam(name: 'UPGRADE_CHILD_CLUSTER', value: triggers.upgradeChildEnabled),
Владислав Наумов0dc99252020-11-13 13:30:48 +0100462 booleanParam(name: 'ATTACH_BYO', value: triggers.attachBYOEnabled),
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100463 booleanParam(name: 'UPGRADE_BYO', value: triggers.upgradeBYOEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200464 booleanParam(name: 'RUN_CHILD_CFM', value: triggers.runChildConformanceEnabled),
Ivan Berezovskiycbf9eeb2021-03-22 15:57:32 +0400465 booleanParam(name: 'ALLOW_AWS_ON_DEMAND', value: triggers.awsOnDemandDemoEnabled),
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400466 booleanParam(name: 'ALLOW_VSPHERE_ON_DEMAND', value: triggers.vsphereOnDemandDemoEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200467 ]
Владислав Наумов92288d92020-07-13 18:36:21 +0200468
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200469 // customize multiregional demo
470 if (triggers.multiregionalConfiguration.enabled) {
471 parameters.add(string(name: 'MULTIREGION_SETUP',
472 value: "${triggers.multiregionalConfiguration.managementLocation},${triggers.multiregionalConfiguration.regionLocation}"
473 ))
474 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200475
Владислав Наумов92288d92020-07-13 18:36:21 +0200476 // Determine component team custom context
477 if (coreContext != '') {
478 common.infoMsg('Additional KaaS Core context detected, will be forwarded into kaas core cicd...')
479 def additionalParameters = generateKaaSVarsFromContext(coreContext)
Владислав Наумовbef51a92020-10-01 17:36:51 +0200480 parameters.addAll(additionalParameters)
Владислав Наумов92288d92020-07-13 18:36:21 +0200481 }
482
Владислав Наумовaa430612020-06-08 17:18:31 +0200483 def jobResults = []
Владислав Наумов37f7f842021-03-09 16:08:39 +0400484 if (triggers.osDemoEnabled) {
485 jobs["kaas-core-openstack-patched-${component}"] = {
486 try {
487 common.infoMsg('Deploy: patched KaaS demo with Openstack provider')
488 os_job_info = build job: "kaas-testing-core-openstack-workflow-${component}", parameters: parameters, wait: true
489 def build_description = os_job_info.getDescription()
490 def build_result = os_job_info.getResult()
491 jobResults.add(build_result)
Владислав Наумовd044e842020-06-17 15:33:43 +0200492
Владислав Наумов37f7f842021-03-09 16:08:39 +0400493 if (build_description) {
494 currentBuild.description += build_description
495 }
496 } finally {
497 common.infoMsg('Patched KaaS demo with Openstack provider finished')
Владислав Наумовf86b1112020-06-09 14:04:48 +0200498 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200499 }
500 }
501 if (triggers.awsOnDemandDemoEnabled) {
Владислав Наумов59281952020-07-29 16:43:49 +0200502 common.infoMsg('AWS demo triggered, need to sync artifacts in the public-ci cdn..')
503 switch (component) {
504 case 'iam':
505 build job: 'cdn-binary-dev-replication-iam', propagate: true, wait: true
506 break
507 case 'lcm':
508 build job: 'cdn-binary-dev-replication-lcm', propagate: true, wait: true
509 break
510 }
511
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200512 jobs["kaas-core-aws-patched-${component}"] = {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200513 try {
514 common.infoMsg('Deploy: patched KaaS demo with AWS provider')
Владислав Наумов4aa112d2020-06-16 18:52:21 +0200515 aws_job_info = build job: "kaas-testing-core-aws-workflow-${component}", parameters: parameters, wait: true
516 def build_description = aws_job_info.getDescription()
Владислав Наумовd044e842020-06-17 15:33:43 +0200517 def build_result = aws_job_info.getResult()
518 jobResults.add(build_result)
519
Владислав Наумовf86b1112020-06-09 14:04:48 +0200520 if (build_description) {
521 currentBuild.description += build_description
522 }
523 } finally {
Владислав Наумов6d741fa2020-06-17 17:35:43 +0200524 common.infoMsg('Patched KaaS demo with AWS provider finished')
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200525 }
526 }
527 }
Stanislav Riazanov24b9c5d2020-10-12 22:27:12 +0400528 if (triggers.vsphereOnDemandDemoEnabled) {
529 jobs["kaas-core-vsphere-patched-${component}"] = {
530 try {
531 common.infoMsg('Deploy: patched KaaS demo with VSPHERE provider')
532 vsphere_job_info = build job: "kaas-testing-core-vsphere-workflow-${component}", parameters: parameters, wait: true
533 def build_description = vsphere_job_info.getDescription()
534 def build_result = vsphere_job_info.getResult()
535 jobResults.add(build_result)
536
537 if (build_description) {
538 currentBuild.description += build_description
539 }
540 } finally {
541 common.infoMsg('Patched KaaS demo with VSPHERE provider finished')
542 }
543 }
544 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200545
546 common.infoMsg('Trigger KaaS demo deployments according to defined provider set')
Владислав Наумов37f7f842021-03-09 16:08:39 +0400547 if (jobs.size() == 0) {
548 error('No demo jobs matched with keywords, execution will be aborted, at least 1 provider should be enabled')
549 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200550 // Limit build concurency workaround examples: https://issues.jenkins-ci.org/browse/JENKINS-44085
551 parallel jobs
Владислав Наумовaa430612020-06-08 17:18:31 +0200552
553 if (jobResults.contains('FAILURE')) {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200554 common.infoMsg('One of parallel downstream jobs is failed, mark executor job as failed')
Владислав Наумовaa430612020-06-08 17:18:31 +0200555 currentBuild.result = 'FAILURE'
556 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200557}
Владислав Наумов30a516c2020-07-09 13:15:41 +0200558
559