blob: a6607c50831128b655eb281b3e4c5d518dc4069a [file] [log] [blame]
vnaumov33747e12020-05-04 17:35:20 +02001package com.mirantis.mk
vnaumov33747e12020-05-04 17:35:20 +02002
3/**
4 *
5 * KaaS Component Testing Utilities
6 *
7 */
8
Владислав Наумовe5345812020-08-12 16:30:20 +02009/**
10 * Check KaaS Core CICD feature flags
11 * such triggers can be used in case of switching between pipelines,
12 * conditions inside pipelines to reduce dependency on jenkins job builder and jenkins job templates itself
13 *
14 * @return (map)[
15 * ffNameEnabled: (bool) True/False
16 * ]
17 */
18def checkCoreCIFeatureFlags() {
19 def common = new com.mirantis.mk.Common()
20 def ff = [
21 build_artifacts_upgrade: false,
22 ]
23
24 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
25 if (commitMsg ==~ /(?s).*\[ci-build-artifacts-upgrade\].*/) {
26 ff['build_artifacts_upgrade'] = true
27 }
28
29 common.infoMsg("Core ci feature flags status: ${ff}")
30 return ff
31}
vnaumov33747e12020-05-04 17:35:20 +020032
33/**
azvyagintseva12230a2020-06-05 13:24:06 +030034 * Determine scope of test suite against per-commit KaaS deployment based on keywords
Владислав Наумов81777472021-03-09 15:14:27 +040035 * Keyword list: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md
azvyagintseva12230a2020-06-05 13:24:06 +030036 *
37 * Used for components team to combine test-suites and forward desired parameters to kaas/core deployment jobs
38 * Example scheme:
Владислав Наумовe5345812020-08-12 16:30:20 +020039 * New CR pushed in kubernetes/lcm-ansible -> parsing it'cs commit body and combine test-suite -> trigger deployment jobs from kaas/core
azvyagintseva12230a2020-06-05 13:24:06 +030040 * manage test-suite through Jenkins Job Parameters
41 *
Владислав Наумов6c2afff2020-06-05 12:54:53 +020042 * @return (map)[
43 * deployChildEnabled: (bool) True if need to deploy child cluster during demo-run
44 * runUie2eEnabled: (bool) True if need to run ui-e2e cluster during demo-run
azvyagintseva12230a2020-06-05 13:24:06 +030045 * ]
46 */
vnaumov33747e12020-05-04 17:35:20 +020047def checkDeploymentTestSuite() {
vnaumovbdb90222020-05-04 18:25:50 +020048 def common = new com.mirantis.mk.Common()
49
vnaumov33747e12020-05-04 17:35:20 +020050 // Available triggers and its sane defaults
Владислав Наумов44c64b72020-12-04 20:22:53 +010051 def seedMacOs = env.SEED_MACOS ? env.SEED_MACOS.toBoolean() : false
Владислав Наумов6c2afff2020-06-05 12:54:53 +020052 def deployChild = env.DEPLOY_CHILD_CLUSTER ? env.DEPLOY_CHILD_CLUSTER.toBoolean() : false
53 def upgradeChild = env.UPGRADE_CHILD_CLUSTER ? env.UPGRADE_CHILD_CLUSTER.toBoolean() : false
Mikhail Ivanov38ee4382022-01-27 16:21:51 +040054 def mosDeployChild = env.DEPLOY_MOS_CHILD_CLUSTER ? env.DEPLOY_MOS_CHILD_CLUSTER.toBoolean() : false
55 def mosUpgradeChild = env.UPGRADE_MOS_CHILD_CLUSTER ? env.UPGRADE_MOS_CHILD_CLUSTER.toBoolean() : false
Mikhail Ivanov74504372021-05-21 17:01:06 +040056 def customChildRelease = env.KAAS_CHILD_CLUSTER_RELEASE_NAME ? env.KAAS_CHILD_CLUSTER_RELEASE_NAME : ''
slalov021171f2022-03-04 14:48:38 +040057 def mosTfDeploy = env.MOS_TF_DEPLOY ? env.MOS_TF_DEPLOY.toBoolean() : false
Владислав Наумов0dc99252020-11-13 13:30:48 +010058 def attachBYO = env.ATTACH_BYO ? env.ATTACH_BYO.toBoolean() : false
Владислав Наумовcdbd84e2020-12-01 16:51:09 +010059 def upgradeBYO = env.UPGRADE_BYO ? env.UPGRADE_BYO.toBoolean() : false
Vladislav Naumov7930ab22021-11-22 18:24:24 +010060 def runBYOMatrix = env.RUN_BYO_MATRIX ? env.RUN_BYO_MATRIX.toBoolean() : false
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +040061 def defaultBYOOs = env.DEFAULT_BYO_OS ? env.DEFAULT_BYO_OS.toString() : 'ubuntu'
Владислав Наумов6c2afff2020-06-05 12:54:53 +020062 def upgradeMgmt = env.UPGRADE_MGMT_CLUSTER ? env.UPGRADE_MGMT_CLUSTER.toBoolean() : false
slalov1202bba2022-04-20 22:31:07 +040063 def autoUpgradeMgmt = env.AUTO_UPGRADE_MCC ? env.AUTO_UPGRADE_MCC.toBoolean() : false
Victor Ryzhenkind2b7b662021-08-23 14:18:38 +040064 def enableLMALogging = env.ENABLE_LMA_LOGGING ? env.ENABLE_LMA_LOGGING.toBoolean(): false
Владислав Наумов6c2afff2020-06-05 12:54:53 +020065 def runUie2e = env.RUN_UI_E2E ? env.RUN_UI_E2E.toBoolean() : false
Mikhail Ivanovf5e20af2022-03-24 15:38:06 +040066 def runUie2eNew = env.RUN_UI_E2E_NEW ? env.RUN_UI_E2E_NEW.toBoolean() : false
Владислав Наумов6c2afff2020-06-05 12:54:53 +020067 def runMgmtConformance = env.RUN_MGMT_CFM ? env.RUN_MGMT_CFM.toBoolean() : false
Владислав Наумов9cec55d2021-08-03 15:00:59 +020068 def runLMATest = env.RUN_LMA_TEST ? env.RUN_LMA_TEST.toBoolean() : false
Vladyslav Drokc4f9c1b2021-07-22 15:34:24 +020069 def runMgmtUserControllerTest = env.RUN_MGMT_USER_CONTROLLER_TEST ? env.RUN_MGMT_USER_CONTROLLER_TEST.toBoolean() : false
Mikhail Ivanov2907e4d2022-04-25 16:41:21 +040070 def runProxyChildTest = env.RUN_PROXY_CHILD_TEST ? env.RUN_PROXY_CHILD_TEST.toBoolean() : false
Владислав Наумов6c2afff2020-06-05 12:54:53 +020071 def runChildConformance = env.RUN_CHILD_CFM ? env.RUN_CHILD_CFM.toBoolean() : false
72 def fetchServiceBinaries = env.FETCH_BINARIES_FROM_UPSTREAM ? env.FETCH_BINARIES_FROM_UPSTREAM.toBoolean() : false
Vladislav Naumov42b71dc2021-11-22 13:09:42 +010073 def equinixMetalV2ChildDiffMetro = env.EQUINIXMETALV2_CHILD_DIFF_METRO ? env.EQUINIXMETALV2_CHILD_DIFF_METRO.toBoolean() : false
slalov13e579c2022-01-31 21:37:02 +040074 def runMaintenanceTest = env.RUN_MAINTENANCE_TEST ? env.RUN_MAINTENANCE_TEST.toBoolean() : false
Владислав Наумов765f3bd2020-09-07 18:09:24 +020075 // multiregion configuration from env variable: comma-separated string in form $mgmt_provider,$regional_provider
76 def multiregionalMappings = env.MULTIREGION_SETUP ? multiregionWorkflowParser(env.MULTIREGION_SETUP) : [
77 enabled: false,
78 managementLocation: '',
79 regionLocation: '',
80 ]
Владислав Наумов4eb1da32020-08-31 14:45:16 +020081
Владислав Наумовb8305e22021-02-10 17:23:12 +010082 // proxy customization
83 def proxyConfig = [
Владислав Наумовf8f23fa2021-04-01 16:57:52 +020084 mgmtOffline: env.OFFLINE_MGMT_CLUSTER ? env.OFFLINE_MGMT_CLUSTER.toBoolean() : false,
85 childOffline: env.OFFLINE_CHILD_CLUSTER ? env.OFFLINE_CHILD_CLUSTER.toBoolean() : false,
Владислав Наумов257ea132021-04-14 14:44:13 +020086 childProxy: env.PROXY_CHILD_CLUSTER ? env.PROXY_CHILD_CLUSTER.toBoolean() : false,
Владислав Наумовb8305e22021-02-10 17:23:12 +010087 ]
88
Владислав Наумов4eb1da32020-08-31 14:45:16 +020089 // optional demo deployment customization
Владислав Наумов905dd362020-06-08 16:37:01 +020090 def awsOnDemandDemo = env.ALLOW_AWS_ON_DEMAND ? env.ALLOW_AWS_ON_DEMAND.toBoolean() : false
Владислав Наумовe021b022021-05-06 11:26:38 +020091 def equinixOnDemandDemo = env.ALLOW_EQUINIX_ON_DEMAND ? env.ALLOW_EQUINIX_ON_DEMAND.toBoolean() : false
Владислав Наумов82305e92021-10-14 20:45:20 +020092 def equinixMetalV2OnDemandDemo = env.ALLOW_EQUINIXMETALV2_ON_DEMAND ? env.ALLOW_EQUINIXMETALV2_ON_DEMAND.toBoolean() : false
Владислав Наумовf3715802021-05-03 18:06:45 +020093 def equinixOnAwsDemo = env.EQUINIX_ON_AWS_DEMO ? env.EQUINIX_ON_AWS_DEMO.toBoolean() : false
Владислав Наумов2d3db332021-06-15 15:19:19 +020094 def azureOnAwsDemo = env.AZURE_ON_AWS_DEMO ? env.AZURE_ON_AWS_DEMO.toBoolean() : false
Владислав Наумовc52dd9d2021-06-28 16:27:29 +020095 def azureOnDemandDemo = env.ALLOW_AZURE_ON_DEMAND ? env.ALLOW_AZURE_ON_DEMAND.toBoolean() : false
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +040096 def enableVsphereDemo = true
Владислав Наумов4eb1da32020-08-31 14:45:16 +020097 def enableOSDemo = true
azvyagintsev1761bdc2020-09-04 17:24:12 +030098 def enableBMDemo = true
Mikhail Ivanovbd1a9fd2022-03-29 21:36:21 +040099 def enableArtifactsBuild = true
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400100 def openstackIMC = env.OPENSTACK_CLOUD_LOCATION ? env.OPENSTACK_CLOUD_LOCATION : 'us'
Alexandr Lovtsov36473f32022-04-28 15:46:09 +0300101 def enableVsphereUbuntu = env.VSPHERE_DEPLOY_UBUNTU ? env.VSPHERE_DEPLOY_UBUNTU.toBoolean() : false
vnaumov33747e12020-05-04 17:35:20 +0200102
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200103 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
Владислав Наумовb8305e22021-02-10 17:23:12 +0100104 if (commitMsg ==~ /(?s).*\[mgmt-proxy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-proxy.*/) {
105 proxyConfig['mgmtOffline'] = true
Владислав Наумов70c02422021-04-19 14:29:41 +0200106 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 +0100107 }
Владислав Наумов44c64b72020-12-04 20:22:53 +0100108 if (commitMsg ==~ /(?s).*\[seed-macos\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*seed-macos.*/) {
109 seedMacOs = true
110 }
slalov574123e2022-04-06 17:24:19 +0400111 if (commitMsg ==~ /(?s).*\[child-deploy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-deploy.*/ || upgradeChild || runChildConformance || runProxyChildTest) {
vnaumov33747e12020-05-04 17:35:20 +0200112 deployChild = true
113 }
114 if (commitMsg ==~ /(?s).*\[child-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-upgrade.*/) {
115 deployChild = true
116 upgradeChild = true
117 }
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400118 def childDeployMatches = (commitMsg =~ /(\[child-deploy\s*(\w|\-)+?\])/)
119 if (childDeployMatches.size() > 0) {
Mikhail Ivanov74504372021-05-21 17:01:06 +0400120 // override child version when it set explicitly
121 deployChild = true
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400122 customChildRelease = childDeployMatches[0][0].split('child-deploy')[1].replaceAll('[\\[\\]]', '').trim()
Mikhail Ivanov74504372021-05-21 17:01:06 +0400123 common.warningMsg("Forced child deployment using custom release version ${customChildRelease}")
124 }
Mikhail Ivanov38ee4382022-01-27 16:21:51 +0400125 if (commitMsg ==~ /(?s).*\[mos-child-deploy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mos-child-deploy.*/) {
126 mosDeployChild = true
127 }
128 if (commitMsg ==~ /(?s).*\[mos-child-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mos-child-upgrade.*/) {
129 mosDeployChild = true
130 mosUpgradeChild = true
131 }
Владислав Наумов0dc99252020-11-13 13:30:48 +0100132 if (commitMsg ==~ /(?s).*\[byo-attach\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-attach.*/) {
133 attachBYO = true
134 }
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100135 if (commitMsg ==~ /(?s).*\[byo-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-upgrade.*/) {
136 attachBYO = true
137 upgradeBYO = true
138 }
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400139
140 def byoDeployMatches = (commitMsg =~ /(\[run-byo-matrix\s*(ubuntu|centos)\])/)
141 if (commitMsg ==~ /(?s).*\[run-byo-matrix\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*run-byo-matrix\.*/ || byoDeployMatches.size() > 0) {
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100142 runBYOMatrix = true
143
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400144 if (byoDeployMatches.size() > 0) {
145 defaultBYOOs = byoDeployMatches[0][2]
146 common.warningMsg("Custom BYO OS detected, using ${defaultBYOOs}")
147 }
148
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100149 common.warningMsg('Forced byo matrix test via run-byo-matrix, all other byo triggers will be skipped')
150 attachBYO = false
151 upgradeBYO = false
152 }
Владислав Наумов7f8c9872021-03-08 17:33:08 +0400153 if (commitMsg ==~ /(?s).*\[mgmt-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-upgrade.*/) {
vnaumov33747e12020-05-04 17:35:20 +0200154 upgradeMgmt = true
155 }
slalov1202bba2022-04-20 22:31:07 +0400156 if (commitMsg ==~ /(?s).*\[auto-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*auto-upgrade.*/) {
157 autoUpgradeMgmt = true
158 }
Victor Ryzhenkind2b7b662021-08-23 14:18:38 +0400159 if (commitMsg ==~ /(?s).*\[lma-logging\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*lma-logging.*/) {
160 enableLMALogging = true
161 }
vnaumov33747e12020-05-04 17:35:20 +0200162 if (commitMsg ==~ /(?s).*\[ui-e2e\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*ui-e2e.*/) {
163 runUie2e = true
164 }
Mikhail Ivanovf5e20af2022-03-24 15:38:06 +0400165 if (commitMsg ==~ /(?s).*\[ui-e2e-new\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*ui-e2e-new.*/) {
166 runUie2eNew = true
167 }
vnaumov33747e12020-05-04 17:35:20 +0200168 if (commitMsg ==~ /(?s).*\[mgmt-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-cfm.*/) {
169 runMgmtConformance = true
170 }
Vladyslav Drokc4f9c1b2021-07-22 15:34:24 +0200171 if (commitMsg ==~ /(?s).*\[test-user-controller\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*test-user-controller.*/) {
172 runMgmtUserControllerTest = true
173 }
slalov574123e2022-04-06 17:24:19 +0400174 if (commitMsg ==~ /(?s).*\[test-proxy-child\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*test-proxy-child.*/) {
175 runProxyChildTest = true
176 deployChild = true
177 common.infoMsg('Child cluster deployment will be enabled since proxy child test suite will be executed')
178 }
vnaumov33747e12020-05-04 17:35:20 +0200179 if (commitMsg ==~ /(?s).*\[child-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-cfm.*/) {
180 runChildConformance = true
181 deployChild = true
182 }
Владислав Наумов9cec55d2021-08-03 15:00:59 +0200183 if (commitMsg ==~ /(?s).*\[lma-test\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*lma-test.*/) {
184 runLMATest = true
Victor Ryzhenkind2b7b662021-08-23 14:18:38 +0400185 enableLMALogging = true
186 common.infoMsg('LMA logging will be enabled since LMA test suite will be executed')
Victor Ryzhenkin15206592021-06-21 17:38:23 +0400187 }
slalov13e579c2022-01-31 21:37:02 +0400188 if (commitMsg ==~ /(?s).*\[maintenance-test\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*maintenance-test.*/) {
189 runMaintenanceTest = true
190 }
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200191 if (commitMsg ==~ /(?s).*\[child-offline\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-offline.*/) {
192 proxyConfig['childOffline'] = true
193 deployChild = true
194 }
Владислав Наумов257ea132021-04-14 14:44:13 +0200195 if (commitMsg ==~ /(?s).*\[child-proxy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-proxy.*/) {
196 proxyConfig['childOffline'] = true
197 proxyConfig['childProxy'] = true
198 deployChild = true
199 }
vnaumov33747e12020-05-04 17:35:20 +0200200 if (commitMsg ==~ /(?s).*\[fetch.*binaries\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*fetch.*binaries.*/) {
201 fetchServiceBinaries = true
202 }
Владислав Наумовf1665b52021-05-13 10:51:17 +0200203 if (commitMsg ==~ /(?s).*\[equinix-on-aws\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinix-on-aws.*/) {
eromanovadf247c32020-12-25 15:44:13 +0400204 equinixOnAwsDemo = true
Владислав Наумовf1665b52021-05-13 10:51:17 +0200205 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 +0400206 }
Владислав Наумов2d3db332021-06-15 15:19:19 +0200207 if (commitMsg ==~ /(?s).*\[azure-on-aws\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*azure-on-aws.*/) {
208 azureOnAwsDemo = true
209 common.warningMsg('Forced running child cluster deployment on Azure provider based on AWS management cluster, triggered on patchset using custom keyword: \'[azure-on-aws]\' ')
210 }
211 if (commitMsg ==~ /(?s).*\[aws-demo\].*/ ||
212 env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*aws-demo.*/ ||
213 attachBYO ||
214 upgradeBYO ||
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100215 runBYOMatrix ||
Владислав Наумов2d3db332021-06-15 15:19:19 +0200216 seedMacOs ||
217 equinixOnAwsDemo ||
218 azureOnAwsDemo) {
219
vnaumov33747e12020-05-04 17:35:20 +0200220 awsOnDemandDemo = true
Владислав Наумов2d3db332021-06-15 15:19:19 +0200221 common.warningMsg('Running additional kaas deployment with AWS provider, may be forced due applied trigger cross dependencies, follow docs to clarify info')
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200222 }
Владислав Наумовf1665b52021-05-13 10:51:17 +0200223 if (commitMsg ==~ /(?s).*\[equinix-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinix-demo\.*/) {
Владислав Наумовe021b022021-05-06 11:26:38 +0200224 equinixOnDemandDemo = true
225 }
Владислав Наумов82305e92021-10-14 20:45:20 +0200226 if (commitMsg ==~ /(?s).*\[equinixmetalv2-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinixmetalv2-demo\.*/) {
Владислав Наумов144956f2021-10-14 17:49:19 +0200227 equinixMetalV2OnDemandDemo = true
228 }
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100229 if (commitMsg ==~ /(?s).*\[equinixmetalv2-child-diff-metro\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinixmetalv2-child-diff-metro\.*/) {
230 equinixMetalV2OnDemandDemo = true
231 equinixMetalV2ChildDiffMetro = true
232 }
Владислав Наумовc52dd9d2021-06-28 16:27:29 +0200233 if (commitMsg ==~ /(?s).*\[azure-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*azure-demo\.*/) {
234 azureOnDemandDemo = true
235 }
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200236 if (commitMsg ==~ /(?s).*\[disable-os-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-os-demo\.*/) {
237 enableOSDemo = false
238 common.errorMsg('Openstack demo deployment will be aborted, VF -1 will be set')
vnaumov33747e12020-05-04 17:35:20 +0200239 }
240
azvyagintsev1761bdc2020-09-04 17:24:12 +0300241 if (commitMsg ==~ /(?s).*\[disable-bm-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-bm-demo\.*/) {
242 enableBMDemo = false
243 common.errorMsg('BM demo deployment will be aborted, VF -1 will be set')
244 }
245
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +0400246 if (commitMsg ==~ /(?s).*\[disable-vsphere-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-vsphere-demo\.*/) {
247 enableVsphereDemo = false
248 common.errorMsg('vSphere demo deployment will be aborted, VF -1 will be set')
249 }
Alexandr Lovtsov36473f32022-04-28 15:46:09 +0300250 if (commitMsg ==~ /(?s).*\[vsphere-ubuntu\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*vsphere-ubuntu\.*/) {
251 enableVsphereUbuntu = true
252 common.warningMsg('Ubuntu will be used to deploy vsphere machines')
253 }
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +0400254
Mikhail Ivanovbd1a9fd2022-03-29 21:36:21 +0400255 if (commitMsg ==~ /(?s).*\[disable-artifacts-build\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-artifacts-build\.*/) {
256 enableArtifactsBuild = false
257 common.errorMsg('artifacts build will be aborted, VF -1 will be set')
258 }
259
vnaumov33747e12020-05-04 17:35:20 +0200260 // TODO (vnaumov) remove below condition after moving all releases to UCP
261 def ucpChildMatches = (commitMsg =~ /(\[child-ucp\s*ucp-.*?\])/)
262 if (ucpChildMatches.size() > 0) {
263 deployChild = true
264 common.warningMsg('Forced UCP based child deployment triggered on patchset using custom keyword: \'[child-ucp ucp-5-1-0-3-3-0-example]\' ')
265
266 // TODO(vnaumov) delete after ucp upgrades support
267 common.errorMsg('Child upgrade test will be skipped, UCP upgrades temporally disabled')
268 upgradeChild = false
269 }
270
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200271 // multiregional tests
272 def multiRegionalMatches = (commitMsg =~ /(\[multiregion\s*.*?\])/)
273 if (multiRegionalMatches.size() > 0) {
274 multiregionalMappings = multiregionWorkflowParser(multiRegionalMatches)
275 }
276 switch (multiregionalMappings['managementLocation']) {
277 case 'aws':
Владислав Наумов53b07e52021-01-07 15:08:27 +0100278 common.warningMsg('Forced running additional kaas deployment with AWS provider according multiregional demo request')
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200279 awsOnDemandDemo = true
Владислав Наумов53b07e52021-01-07 15:08:27 +0100280
281 if (multiregionalMappings['regionLocation'] != 'aws' && seedMacOs) { // macstadium seed node has access only to *public* providers
282 error('incompatible triggers: [seed-macos] and multiregional deployment based on *private* regional provider cannot be applied simultaneously')
283 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200284 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200285 case 'os':
286 if (enableOSDemo == false) {
287 error('incompatible triggers: [disable-os-demo] and multiregional deployment based on OSt management region cannot be applied simultaneously')
288 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200289 break
Владислав Наумов865ba6c2021-05-13 13:05:45 +0200290 case 'vsphere':
291 if (enableVsphereDemo == false) {
292 error('incompatible triggers: [disable-vsphere-demo] and multiregional deployment based on Vsphere management region cannot be applied simultaneously')
293 }
294 break
Владислав Наумов5be02942021-05-13 12:34:37 +0200295 case 'equinix':
296 common.warningMsg('Forced running additional kaas deployment with Equinix provider according multiregional demo request')
297 equinixOnDemandDemo = true
eromanova35359162021-12-30 14:13:13 +0400298 break
eromanova8c702ae2021-12-24 17:43:12 +0400299 case 'equinixmetalv2':
300 common.warningMsg('Forced running additional kaas deployment with Equinix Metal V2 provider according multiregional demo request')
301 equinixMetalV2OnDemandDemo = true
eromanova35359162021-12-30 14:13:13 +0400302 break
slalovfd0b7e62021-07-28 18:05:16 +0400303 case 'azure':
304 common.warningMsg('Forced running additional kaas deployment with Azure provider according multiregional demo request')
305 azureOnDemandDemo = true
306 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200307 }
308
Владислав Наумовb8305e22021-02-10 17:23:12 +0100309 // CDN configuration
310 def cdnConfig = [
311 mgmt: [
312 openstack: (proxyConfig['mgmtOffline'] == true) ? 'public-ci' : 'internal-ci',
Владислав Наумов70c02422021-04-19 14:29:41 +0200313 vsphere: 'internal-ci',
Владислав Наумовb8305e22021-02-10 17:23:12 +0100314 aws: 'public-ci',
Владислав Наумовe021b022021-05-06 11:26:38 +0200315 equinix: 'public-ci',
Владислав Наумовc52dd9d2021-06-28 16:27:29 +0200316 azure: 'public-ci',
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200317 ],
Владислав Наумовb8305e22021-02-10 17:23:12 +0100318 ]
319
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400320 if (commitMsg ==~ /(?s).*\[eu-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*eu-demo.*/) {
321 openstackIMC = 'eu'
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400322 }
slalov021171f2022-03-04 14:48:38 +0400323 if (commitMsg ==~ /(?s).*\[mos-tf-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mos-tf-demo.*/) {
324 openstackIMC = 'eu2'
Mikhail Ivanovf05b8252022-04-27 18:14:03 +0400325 }
326 if (openstackIMC == 'eu' || openstackIMC == 'eu2') {
slalov021171f2022-03-04 14:48:38 +0400327 // use internal-eu because on internal-ci with eu cloud image pull takes much time
328 def cdnRegion = (proxyConfig['mgmtOffline'] == true) ? 'public-ci' : 'internal-eu'
329 common.infoMsg("eu2-demo was triggered, force switching CDN region to ${cdnRegion}")
330 cdnConfig['mgmt']['openstack'] = cdnRegion
331 }
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400332
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100333 // calculate weight of current demo run to manage lockable resources
334 def demoWeight = (deployChild) ? 2 : 1 // management = 1, child = 1
335
vnaumov33747e12020-05-04 17:35:20 +0200336 common.infoMsg("""
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400337 OpenStack Cloud location: ${openstackIMC}
Владислав Наумовb8305e22021-02-10 17:23:12 +0100338 CDN deployment configuration: ${cdnConfig}
339 MCC offline deployment configuration: ${proxyConfig}
Владислав Наумов44c64b72020-12-04 20:22:53 +0100340 Use MacOS node as seed: ${seedMacOs}
vnaumov33747e12020-05-04 17:35:20 +0200341 Child cluster deployment scheduled: ${deployChild}
Mikhail Ivanov74504372021-05-21 17:01:06 +0400342 Custom child cluster release: ${customChildRelease}
vnaumov33747e12020-05-04 17:35:20 +0200343 Child cluster release upgrade scheduled: ${upgradeChild}
Mikhail Ivanov38ee4382022-01-27 16:21:51 +0400344 MOS child deploy scheduled: ${mosDeployChild}
345 MOS child upgrade scheduled: ${mosUpgradeChild}
vnaumov33747e12020-05-04 17:35:20 +0200346 Child conformance testing scheduled: ${runChildConformance}
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100347 Single BYO cluster attachment scheduled: ${attachBYO}
348 Single Attached BYO cluster upgrade test scheduled: ${upgradeBYO}
349 BYO test matrix whole suite scheduled: ${runBYOMatrix}
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400350 Default BYO OS: ${defaultBYOOs}
vnaumov33747e12020-05-04 17:35:20 +0200351 Mgmt cluster release upgrade scheduled: ${upgradeMgmt}
slalov1202bba2022-04-20 22:31:07 +0400352 Mgmt cluster release auto upgrade scheduled: ${autoUpgradeMgmt}
Victor Ryzhenkind2b7b662021-08-23 14:18:38 +0400353 Mgmt LMA logging enabled: ${enableLMALogging}
vnaumov33747e12020-05-04 17:35:20 +0200354 Mgmt conformance testing scheduled: ${runMgmtConformance}
Владислав Наумов9cec55d2021-08-03 15:00:59 +0200355 LMA testing scheduled: ${runLMATest}
Vladyslav Drokc4f9c1b2021-07-22 15:34:24 +0200356 Mgmt user controller testing scheduled: ${runMgmtUserControllerTest}
vnaumov33747e12020-05-04 17:35:20 +0200357 Mgmt UI e2e testing scheduled: ${runUie2e}
Mikhail Ivanovf5e20af2022-03-24 15:38:06 +0400358 Mgmt UI e2e playwrite testing scheduled: ${runUie2eNew}
slalov13e579c2022-01-31 21:37:02 +0400359 Maintenance test: ${runMaintenanceTest}
slalov574123e2022-04-06 17:24:19 +0400360 Child proxy test: ${runProxyChildTest}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200361 AWS provider deployment scheduled: ${awsOnDemandDemo}
Владислав Наумовe021b022021-05-06 11:26:38 +0200362 Equinix provider deployment scheduled: ${equinixOnDemandDemo}
Владислав Наумов144956f2021-10-14 17:49:19 +0200363 EquinixmetalV2 provider deployment scheduled: ${equinixMetalV2OnDemandDemo}
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100364 EquinixmetalV2 child deploy in a separate metro scheduled: ${equinixMetalV2ChildDiffMetro}
Владислав Наумовf1665b52021-05-13 10:51:17 +0200365 Equinix@AWS child cluster deployment scheduled: ${equinixOnAwsDemo}
Владислав Наумовc52dd9d2021-06-28 16:27:29 +0200366 Azure provider deployment scheduled: ${azureOnDemandDemo}
Владислав Наумов2d3db332021-06-15 15:19:19 +0200367 Azure@AWS child cluster deployment scheduled: ${azureOnAwsDemo}
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +0400368 VSPHERE provider deployment scheduled: ${enableVsphereDemo}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200369 OS provider deployment scheduled: ${enableOSDemo}
azvyagintsev1761bdc2020-09-04 17:24:12 +0300370 BM provider deployment scheduled: ${enableBMDemo}
Alexandr Lovtsov36473f32022-04-28 15:46:09 +0300371 Ubuntu on vSphere scheduled: ${enableVsphereUbuntu}
Mikhail Ivanovbd1a9fd2022-03-29 21:36:21 +0400372 Artifacts build scheduled: ${enableArtifactsBuild}
Владислав Наумовf793fe32020-09-11 15:19:19 +0200373 Multiregional configuration: ${multiregionalMappings}
vnaumov33747e12020-05-04 17:35:20 +0200374 Service binaries fetching scheduled: ${fetchServiceBinaries}
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100375 Current weight of the demo run: ${demoWeight} (Used to manage lockable resources)
Владислав Наумов81777472021-03-09 15:14:27 +0400376 Triggers: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
vnaumov33747e12020-05-04 17:35:20 +0200377 return [
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400378 osCloudLocation : openstackIMC,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100379 cdnConfig : cdnConfig,
380 proxyConfig : proxyConfig,
381 useMacOsSeedNode : seedMacOs,
382 deployChildEnabled : deployChild,
383 childDeployCustomRelease : customChildRelease,
384 upgradeChildEnabled : upgradeChild,
Mikhail Ivanov38ee4382022-01-27 16:21:51 +0400385 mosDeployChildEnabled : mosDeployChild,
386 mosUpgradeChildEnabled : mosUpgradeChild,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100387 runChildConformanceEnabled : runChildConformance,
388 attachBYOEnabled : attachBYO,
389 upgradeBYOEnabled : upgradeBYO,
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100390 runBYOMatrixEnabled : runBYOMatrix,
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400391 defaultBYOOs : defaultBYOOs,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100392 upgradeMgmtEnabled : upgradeMgmt,
slalov1202bba2022-04-20 22:31:07 +0400393 autoUpgradeMgmtEnabled : autoUpgradeMgmt,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100394 enableLMALoggingEnabled : enableLMALogging,
395 runUie2eEnabled : runUie2e,
Mikhail Ivanovf5e20af2022-03-24 15:38:06 +0400396 runUie2eNewEnabled : runUie2eNew,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100397 runMgmtConformanceEnabled : runMgmtConformance,
slalov13e579c2022-01-31 21:37:02 +0400398 runMaintenanceTestEnable : runMaintenanceTest,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100399 runLMATestEnabled : runLMATest,
400 runMgmtUserControllerTestEnabled : runMgmtUserControllerTest,
slalov574123e2022-04-06 17:24:19 +0400401 runProxyChildTestEnabled : runProxyChildTest,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100402 fetchServiceBinariesEnabled : fetchServiceBinaries,
403 awsOnDemandDemoEnabled : awsOnDemandDemo,
404 equinixOnDemandDemoEnabled : equinixOnDemandDemo,
405 equinixMetalV2OnDemandDemoEnabled : equinixMetalV2OnDemandDemo,
406 equinixMetalV2ChildDiffMetroEnabled : equinixMetalV2ChildDiffMetro,
407 equinixOnAwsDemoEnabled : equinixOnAwsDemo,
408 azureOnDemandDemoEnabled : azureOnDemandDemo,
409 azureOnAwsDemoEnabled : azureOnAwsDemo,
410 vsphereDemoEnabled : enableVsphereDemo,
411 vsphereOnDemandDemoEnabled : enableVsphereDemo, // TODO: remove after MCC 2.7 is out
412 bmDemoEnabled : enableBMDemo,
413 osDemoEnabled : enableOSDemo,
Alexandr Lovtsov36473f32022-04-28 15:46:09 +0300414 vsphereUbuntuEnabled : enableVsphereUbuntu,
Mikhail Ivanovbd1a9fd2022-03-29 21:36:21 +0400415 artifactsBuildEnabled : enableArtifactsBuild,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100416 multiregionalConfiguration : multiregionalMappings,
417 demoWeight : demoWeight]
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200418}
419
420/**
421 * Determine management and regional setup for demo workflow scenario
422 *
423 *
424 * @param: keyword (string) string , represents keyworkd trigger, specified in gerrit commit body, like `[multiregion aws,os]`
425 or Jenkins environment string variable in form like 'aws,os'
426 * @return (map)[
427 enabled: (bool),
428 * managementLocation: (string), //aws,os
429 * regionLocation: (string), //aws,os
430 * ]
431 */
432def multiregionWorkflowParser(keyword) {
Владислав Наумов8c0c39d2020-09-11 14:46:48 +0200433 def common = new com.mirantis.mk.Common()
eromanova8c702ae2021-12-24 17:43:12 +0400434 def supportedManagementProviders = ['os', 'aws', 'vsphere', 'equinix', 'equinixmetalv2', 'azure']
435 def supportedRegionalProviders = ['os', 'vsphere', 'equinix', 'equinixmetalv2', 'bm', 'azure', 'aws']
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200436
437 def clusterTypes = ''
Владислав Наумов38ed7bf2020-09-11 14:43:39 +0200438 if (keyword.toString().contains('multiregion')) {
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200439 common.infoMsg('Multiregion definition configured via gerrit keyword trigger')
440 clusterTypes = keyword[0][0].split('multiregion')[1].replaceAll('[\\[\\]]', '').trim().split(',')
441 } else {
442 common.infoMsg('Multiregion definition configured via environment variable')
443 clusterTypes = keyword.trim().split(',')
444 }
445
446 if (clusterTypes.size() != 2) {
Владислав Наумов482fb502020-10-30 17:59:27 +0100447 error("Incorrect regions definiton, valid scheme: [multiregion ${management}, ${region}], got: ${clusterTypes}")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200448 }
449
Владислав Наумовf793fe32020-09-11 15:19:19 +0200450 def desiredManagementProvider = clusterTypes[0].trim()
451 def desiredRegionalProvider = clusterTypes[1].trim()
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200452 if (! supportedManagementProviders.contains(desiredManagementProvider) || ! supportedRegionalProviders.contains(desiredRegionalProvider)) {
453 error("""unsupported management <-> regional bundle, available options:
Владислав Наумовf793fe32020-09-11 15:19:19 +0200454 management providers list - ${supportedManagementProviders}
455 regional providers list - ${supportedRegionalProviders}""")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200456 }
457
458 return [
459 enabled: true,
460 managementLocation: desiredManagementProvider,
461 regionLocation: desiredRegionalProvider,
462 ]
vnaumov33747e12020-05-04 17:35:20 +0200463}
464
465/**
466 * Determine if custom si tests/pipelines refspec forwarded from gerrit change request
467
Владислав Наумов81777472021-03-09 15:14:27 +0400468 * 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 +0200469 * Used for components team to test component changes w/ custom SI refspecs using kaas/core deployment jobs
470 * Example scheme:
471 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
472 * manage refspecs through Jenkins Job Parameters
473 *
azvyagintseva12230a2020-06-05 13:24:06 +0300474 * @return (map)[* siTests: (string) final refspec for si-tests
vnaumov33747e12020-05-04 17:35:20 +0200475 * siPipelines: (string) final refspec for si-pipelines
476 * ]
477 */
478def checkCustomSIRefspec() {
vnaumovbdb90222020-05-04 18:25:50 +0200479 def common = new com.mirantis.mk.Common()
480
vnaumov33747e12020-05-04 17:35:20 +0200481 // Available triggers and its sane defaults
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200482 def siTestsRefspec = env.SI_TESTS_REFSPEC ?: 'master'
483 def siPipelinesRefspec = env.SI_PIPELINES_REFSPEC ?: 'master'
Владислав Наумов2db15e22020-07-14 12:29:22 +0200484 def siTestsDockerImage = env.SI_TESTS_DOCKER_IMAGE ?: 'docker-dev-kaas-local.docker.mirantis.net/mirantis/kaas/si-test'
485 def siTestsDockerImageTag = env.SI_TESTS_DOCKER_IMAGE_TAG ?: 'master'
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200486 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
vnaumov33747e12020-05-04 17:35:20 +0200487
488 def siTestMatches = (commitMsg =~ /(\[si-tests-ref\s*refs\/changes\/.*?\])/)
489 def siPipelinesMatches = (commitMsg =~ /(\[si-pipelines-ref\s*refs\/changes\/.*?\])/)
490
491 if (siTestMatches.size() > 0) {
492 siTestsRefspec = siTestMatches[0][0].split('si-tests-ref')[1].replaceAll('[\\[\\]]', '').trim()
Владислав Наумов7f6c0882021-03-23 19:10:57 +0400493 siTestsDockerImage = "docker-review-local.docker.mirantis.net/review/kaas-si-test-${siTestsRefspec.split('/')[-2]}"
Владислав Наумов2db15e22020-07-14 12:29:22 +0200494 siTestsDockerImageTag = siTestsRefspec.split('/')[-1]
vnaumov33747e12020-05-04 17:35:20 +0200495 }
496 if (siPipelinesMatches.size() > 0) {
497 siPipelinesRefspec = siPipelinesMatches[0][0].split('si-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
498 }
499
500 common.infoMsg("""
501 kaas/si-pipelines will be fetched from: ${siPipelinesRefspec}
502 kaas/si-tests will be fetched from: ${siTestsRefspec}
Владислав Наумов2db15e22020-07-14 12:29:22 +0200503 kaas/si-tests as dockerImage will be fetched from: ${siTestsDockerImage}:${siTestsDockerImageTag}
Владислав Наумов81777472021-03-09 15:14:27 +0400504 Keywords: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
Владислав Наумов2db15e22020-07-14 12:29:22 +0200505 return [siTests: siTestsRefspec, siPipelines: siPipelinesRefspec, siTestsDockerImage: siTestsDockerImage, siTestsDockerImageTag: siTestsDockerImageTag]
vnaumov33747e12020-05-04 17:35:20 +0200506}
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200507
Владислав Наумов9080f372020-06-08 13:57:16 +0200508/**
Владислав Наумов418042b2020-07-09 18:31:10 +0200509 * Parse additional configuration for kaas component CICD repo
Владислав Наумов30a516c2020-07-09 13:15:41 +0200510 * @param configurationFile (str) path to configuration file in yaml format
511 *
512 * @return (map)[ siTestsFeatureFlags (string) dedicated feature flags that will be used in SI tests,
513 * ]
514 */
515def parseKaaSComponentCIParameters(configurationFile){
516 def common = new com.mirantis.mk.Common()
517 def ciConfig = readYaml file: configurationFile
518 def ciSpec = [
519 siTestsFeatureFlags: env.SI_TESTS_FEATURE_FLAGS ?: '',
520 ]
521
522 if (ciConfig.containsKey('si-tests-feature-flags')) {
523 common.infoMsg("""SI tests feature flags customization detected,
524 results will be merged with existing flags: [${ciSpec['siTestsFeatureFlags']}] identification...""")
525
526 def ffMeta = ciSpec['siTestsFeatureFlags'].tokenize(',').collect { it.trim() }
527 ffMeta.addAll(ciConfig['si-tests-feature-flags'])
Владислав Наумов30a516c2020-07-09 13:15:41 +0200528
Владислав Наумовcb5ffca2020-07-14 15:28:36 +0200529 ciSpec['siTestsFeatureFlags'] = ffMeta.unique().join(',')
Владислав Наумов30a516c2020-07-09 13:15:41 +0200530 common.infoMsg("SI tests custom feature flags: ${ciSpec['siTestsFeatureFlags']}")
531 }
532
533 common.infoMsg("""Additional ci configuration parsed successfully:
534 siTestsFeatureFlags: ${ciSpec['siTestsFeatureFlags']}""")
535 return ciSpec
536}
537
538/**
539 * Determine if custom kaas core/pipelines refspec forwarded from gerrit change request
Владислав Наумов9080f372020-06-08 13:57:16 +0200540
Владислав Наумов81777472021-03-09 15:14:27 +0400541 * 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 +0200542 * Used for components team to test component changes w/ custom Core refspecs using kaas/core deployment jobs
543 * Example scheme:
544 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
545 * manage refspecs through Jenkins Job Parameters
546 *
547 * @return (map)[ core: (string) final refspec for kaas/core
548 * corePipelines: (string) final refspec for pipelines in kaas/core
549 * ]
550 */
551def checkCustomCoreRefspec() {
552 def common = new com.mirantis.mk.Common()
553
554 // Available triggers and its sane defaults
555 def coreRefspec = env.KAAS_CORE_REFSPEC ?: 'master'
556 // by default using value of GERRIT_REFSPEC parameter in *kaas/core jobs*
557 def corePipelinesRefspec = env.KAAS_PIPELINE_REFSPEC ?: '\$GERRIT_REFSPEC'
558 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
559
560 def coreMatches = (commitMsg =~ /(\[core-ref\s*refs\/changes\/.*?\])/)
561 def corePipelinesMatches = (commitMsg =~ /(\[core-pipelines-ref\s*refs\/changes\/.*?\])/)
562
563 if (coreMatches.size() > 0) {
564 coreRefspec = coreMatches[0][0].split('core-ref')[1].replaceAll('[\\[\\]]', '').trim()
565 }
566 if (corePipelinesMatches.size() > 0) {
567 corePipelinesRefspec = corePipelinesMatches[0][0].split('core-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
568 }
569
570 common.infoMsg("""
571 kaas/core will be fetched from: ${coreRefspec}
572 kaas/core pipelines will be fetched from: ${corePipelinesRefspec}
Владислав Наумов81777472021-03-09 15:14:27 +0400573 Keywords: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
Владислав Наумов9080f372020-06-08 13:57:16 +0200574 return [core: coreRefspec, corePipelines: corePipelinesRefspec]
575}
576
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200577
578/**
Владислав Наумов92288d92020-07-13 18:36:21 +0200579 * generate Jenkins Parameter objects from from text parameter with additonal kaas core context
580 * needed to forward inside kaas core set of jobs
581 *
582 * @param context (string) Representation of the string enviroment variables needed for kaas core jobs in yaml format
583 * @return (list)[ string(name: '', value: ''),
584 * ]
585 */
586def generateKaaSVarsFromContext(context) {
587 def common = new com.mirantis.mk.Common()
588 def parameters = []
589 def config = readYaml text: context
590
591 config.each { k,v ->
592 common.infoMsg("Custom KaaS Core context parameter: ${k}=${v}")
593 parameters.add(string(name: k, value: v))
594 }
595
596 return parameters
597}
598
599/**
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200600 * 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 +0400601 * 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 +0200602 * Used for components team to test component changes w/ customized SI tests/refspecs using kaas/core deployment jobs
603 *
Владислав Наумов418042b2020-07-09 18:31:10 +0200604 * @param: component (string) component name [iam, lcm, stacklight]
605 * @param: patchSpec (string) Patch for kaas/cluster releases in json format
606 * @param: configurationFile (string) Additional file for component repo CI config in yaml format
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200607 */
Владислав Наумов92288d92020-07-13 18:36:21 +0200608def triggerPatchedComponentDemo(component, patchSpec = '', configurationFile = '.ci-parameters.yaml', coreContext = '') {
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200609 def common = new com.mirantis.mk.Common()
610 // Determine if custom trigger keywords forwarded from gerrit
611 def triggers = checkDeploymentTestSuite()
612 // Determine SI refspecs
613 def siRefspec = checkCustomSIRefspec()
Владислав Наумов9080f372020-06-08 13:57:16 +0200614 // Determine Core refspecs
615 def coreRefspec = checkCustomCoreRefspec()
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200616
Владислав Наумов418042b2020-07-09 18:31:10 +0200617 // Determine component repo ci configuration
618 def ciSpec = [:]
619 def componentFeatureFlags = env.SI_TESTS_FEATURE_FLAGS ?: ''
620 if (fileExists(configurationFile)) {
621 common.infoMsg('Component CI configuration file detected, parsing...')
622 ciSpec = parseKaaSComponentCIParameters(configurationFile)
623 componentFeatureFlags = ciSpec['siTestsFeatureFlags']
624 } else {
625 common.warningMsg('''Component CI configuration file is not exists,
Владислав Наумовc17dd552020-07-29 17:07:38 +0200626 several code-management features may be unavailable,
Владислав Наумов92288d92020-07-13 18:36:21 +0200627 follow https://mirantis.jira.com/wiki/spaces/QA/pages/2310832276/SI-tests+feature+flags#%5BUpdated%5D-Using-a-feature-flag
628 to create the configuration file''')
Владислав Наумов418042b2020-07-09 18:31:10 +0200629 }
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400630
631 def platforms = []
632 if (component == 'ipam' && triggers.vsphereDemoEnabled) {
633 // Currently only vsphere demo is required for IPAM component
634 platforms.add('vsphere')
635 } else {
636 if (triggers.osDemoEnabled) {
637 platforms.add('openstack')
638 }
639 if (triggers.awsOnDemandDemoEnabled) {
640 platforms.add('aws')
641 }
642 if (triggers.equinixOnDemandDemoEnabled) {
643 platforms.add('equinix')
644 }
Владислав Наумов144956f2021-10-14 17:49:19 +0200645 if (triggers.equinixMetalV2OnDemandDemoEnabled) {
646 platforms.add('equinixmetalv2')
647 }
Владислав Наумовc52dd9d2021-06-28 16:27:29 +0200648 if (triggers.azureOnDemandDemoEnabled) {
649 platforms.add('azure')
650 }
Ivan Berezovskiyb0229d02021-05-17 16:55:18 +0400651 if (triggers.vsphereDemoEnabled) {
652 platforms.add('vsphere')
653 }
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400654 }
655
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200656 def jobs = [:]
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200657 def parameters = [
Владислав Наумов9080f372020-06-08 13:57:16 +0200658 string(name: 'GERRIT_REFSPEC', value: coreRefspec.core),
659 string(name: 'KAAS_PIPELINE_REFSPEC', value: coreRefspec.corePipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200660 string(name: 'SI_TESTS_REFSPEC', value: siRefspec.siTests),
Владислав Наумов418042b2020-07-09 18:31:10 +0200661 string(name: 'SI_TESTS_FEATURE_FLAGS', value: componentFeatureFlags),
Владислав Наумов2db15e22020-07-14 12:29:22 +0200662 string(name: 'SI_TESTS_DOCKER_IMAGE', value: siRefspec.siTestsDockerImage),
663 string(name: 'SI_TESTS_DOCKER_IMAGE_TAG', value: siRefspec.siTestsDockerImageTag),
Владислав Наумов4a5c3242020-06-08 14:36:11 +0200664 string(name: 'SI_PIPELINES_REFSPEC', value: siRefspec.siPipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200665 string(name: 'CUSTOM_RELEASE_PATCH_SPEC', value: patchSpec),
Mikhail Ivanov74504372021-05-21 17:01:06 +0400666 string(name: 'KAAS_CHILD_CLUSTER_RELEASE_NAME', value: triggers.childDeployCustomRelease),
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400667 string(name: 'OPENSTACK_CLOUD_LOCATION', value: triggers.osCloudLocation),
Владислав Наумовb8305e22021-02-10 17:23:12 +0100668 booleanParam(name: 'OFFLINE_MGMT_CLUSTER', value: triggers.proxyConfig['mgmtOffline']),
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200669 booleanParam(name: 'OFFLINE_CHILD_CLUSTER', value: triggers.proxyConfig['childOffline']),
Владислав Наумов257ea132021-04-14 14:44:13 +0200670 booleanParam(name: 'PROXY_CHILD_CLUSTER', value: triggers.proxyConfig['childProxy']),
Владислав Наумов44c64b72020-12-04 20:22:53 +0100671 booleanParam(name: 'SEED_MACOS', value: triggers.useMacOsSeedNode),
Владислав Наумов080d9412020-07-29 13:05:14 +0200672 booleanParam(name: 'UPGRADE_MGMT_CLUSTER', value: triggers.upgradeMgmtEnabled),
slalov1202bba2022-04-20 22:31:07 +0400673 booleanParam(name: 'AUTO_UPGRADE_MCC', value: triggers.autoUpgradeMgmtEnabled),
Victor Ryzhenkind2b7b662021-08-23 14:18:38 +0400674 booleanParam(name: 'ENABLE_LMA_LOGGING', value: triggers.enableLMALoggingEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200675 booleanParam(name: 'RUN_UI_E2E', value: triggers.runUie2eEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200676 booleanParam(name: 'RUN_MGMT_CFM', value: triggers.runMgmtConformanceEnabled),
slalov13e579c2022-01-31 21:37:02 +0400677 booleanParam(name: 'RUN_MAINTENANCE_TEST', value: triggers.runMaintenanceTestEnable),
Владислав Наумов9cec55d2021-08-03 15:00:59 +0200678 booleanParam(name: 'RUN_LMA_TEST', value: triggers.runLMATestEnabled),
Vladyslav Drokc4f9c1b2021-07-22 15:34:24 +0200679 booleanParam(name: 'RUN_MGMT_USER_CONTROLLER_TEST', value: triggers.runMgmtUserControllerTestEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200680 booleanParam(name: 'DEPLOY_CHILD_CLUSTER', value: triggers.deployChildEnabled),
681 booleanParam(name: 'UPGRADE_CHILD_CLUSTER', value: triggers.upgradeChildEnabled),
slalov574123e2022-04-06 17:24:19 +0400682 booleanParam(name: 'RUN_PROXY_CHILD_TEST', value: triggers.runProxyChildTestEnabled),
Владислав Наумов0dc99252020-11-13 13:30:48 +0100683 booleanParam(name: 'ATTACH_BYO', value: triggers.attachBYOEnabled),
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100684 booleanParam(name: 'UPGRADE_BYO', value: triggers.upgradeBYOEnabled),
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100685 booleanParam(name: 'RUN_BYO_MATRIX', value: triggers.runBYOMatrixEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200686 booleanParam(name: 'RUN_CHILD_CFM', value: triggers.runChildConformanceEnabled),
Ivan Berezovskiycbf9eeb2021-03-22 15:57:32 +0400687 booleanParam(name: 'ALLOW_AWS_ON_DEMAND', value: triggers.awsOnDemandDemoEnabled),
Владислав Наумовe021b022021-05-06 11:26:38 +0200688 booleanParam(name: 'ALLOW_EQUINIX_ON_DEMAND', value: triggers.equinixOnDemandDemoEnabled),
Владислав Наумов82305e92021-10-14 20:45:20 +0200689 booleanParam(name: 'ALLOW_EQUINIXMETALV2_ON_DEMAND', value: triggers.equinixMetalV2OnDemandDemoEnabled),
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100690 booleanParam(name: 'EQUINIXMETALV2_CHILD_DIFF_METRO', value: triggers.equinixMetalV2ChildDiffMetroEnabled),
eromanovad3397512021-04-01 20:19:19 +0400691 booleanParam(name: 'EQUINIX_ON_AWS_DEMO', value: triggers.equinixOnAwsDemoEnabled),
Владислав Наумовc52dd9d2021-06-28 16:27:29 +0200692 booleanParam(name: 'ALLOW_AZURE_ON_DEMAND', value: triggers.azureOnDemandDemoEnabled),
Владислав Наумов2d3db332021-06-15 15:19:19 +0200693 booleanParam(name: 'AZURE_ON_AWS_DEMO', value: triggers.azureOnAwsDemoEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200694 ]
Владислав Наумов92288d92020-07-13 18:36:21 +0200695
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200696 // customize multiregional demo
697 if (triggers.multiregionalConfiguration.enabled) {
698 parameters.add(string(name: 'MULTIREGION_SETUP',
699 value: "${triggers.multiregionalConfiguration.managementLocation},${triggers.multiregionalConfiguration.regionLocation}"
700 ))
701 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200702
Владислав Наумов92288d92020-07-13 18:36:21 +0200703 // Determine component team custom context
704 if (coreContext != '') {
705 common.infoMsg('Additional KaaS Core context detected, will be forwarded into kaas core cicd...')
706 def additionalParameters = generateKaaSVarsFromContext(coreContext)
Владислав Наумовbef51a92020-10-01 17:36:51 +0200707 parameters.addAll(additionalParameters)
Владислав Наумов92288d92020-07-13 18:36:21 +0200708 }
709
Владислав Наумовaa430612020-06-08 17:18:31 +0200710 def jobResults = []
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400711
712 platforms.each { platform ->
713 jobs["kaas-core-${platform}-patched-${component}"] = {
Vladislav Naumov5313a202021-04-07 17:13:39 +0000714 try {
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400715 common.infoMsg("Deploy: patched KaaS demo with ${platform} provider")
716 def job_info = build job: "kaas-testing-core-${platform}-workflow-${component}", parameters: parameters, wait: true
717 def build_description = job_info.getDescription()
718 def build_result = job_info.getResult()
Vladislav Naumov5313a202021-04-07 17:13:39 +0000719 jobResults.add(build_result)
Владислав Наумовd044e842020-06-17 15:33:43 +0200720
Vladislav Naumov5313a202021-04-07 17:13:39 +0000721 if (build_description) {
722 currentBuild.description += build_description
723 }
724 } finally {
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400725 common.infoMsg("Patched KaaS demo with ${platform} provider finished")
Vladislav Naumov5313a202021-04-07 17:13:39 +0000726 }
727 }
728 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200729
730 common.infoMsg('Trigger KaaS demo deployments according to defined provider set')
Владислав Наумов37f7f842021-03-09 16:08:39 +0400731 if (jobs.size() == 0) {
732 error('No demo jobs matched with keywords, execution will be aborted, at least 1 provider should be enabled')
733 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200734 // Limit build concurency workaround examples: https://issues.jenkins-ci.org/browse/JENKINS-44085
735 parallel jobs
Владислав Наумовaa430612020-06-08 17:18:31 +0200736
737 if (jobResults.contains('FAILURE')) {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200738 common.infoMsg('One of parallel downstream jobs is failed, mark executor job as failed')
Владислав Наумовaa430612020-06-08 17:18:31 +0200739 currentBuild.result = 'FAILURE'
740 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200741}
Владислав Наумов30a516c2020-07-09 13:15:41 +0200742
743
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400744/**
745 * Function currently supported to be called from aws or vsphere demos. It gets particular demo context
Владислав Наумов33e1e812021-08-17 17:09:25 +0200746 * and generate proper lockResources data and netMap data for vsphere,equinix related clusters.
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400747 *
748 * @param: callBackDemo (string) Demo which requested to generate lockResources [aws or vsphere]
749 * @param: triggers (map) Custom trigger keywords forwarded from gerrit
750 * @param: multiregionalConfiguration (map) Multiregional configuration
751 * @return (map) Return aggregated map with lockResources and netMap
752 */
753
754
755def generateLockResources(callBackDemo, triggers) {
756 def common = new com.mirantis.mk.Common()
Владислав Наумов33e1e812021-08-17 17:09:25 +0200757 def netMap = [
758 vsphere: [:],
759 equinix: [:],
760 ]
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400761 // Define vsphere locklabels with initial quantity
762 def lockLabels = [
763 vsphere_networking_core_ci: 0,
764 vsphere_offline_networking_core_ci: 0,
765 ]
766 def deployChild = triggers.deployChildEnabled
767 def multiregionConfig = triggers.multiregionalConfiguration
768 def runMultiregion = multiregionConfig.enabled
769
770 // Generate vsphere netMap and lockLabels based on demo context
771 switch (callBackDemo) {
772 case 'aws':
773 // Add aws specific lock label with quantity calculated based on single mgmt deploy or mgmt + child
774 lockLabels['aws_core_ci_queue'] = triggers.demoWeight
Sergey Kolekonovf4c1f492022-02-03 14:44:45 +0400775 if (triggers.runBYOMatrixEnabled) { lockLabels['aws_core_ci_queue'] += 6 }
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400776
777 // Define netMap for Vsphere region
Mikhail Ivanov90a27fa2022-05-30 15:18:24 +0400778 if (runMultiregion && multiregionConfig.managementLocation == 'aws') {
779 if (multiregionConfig.regionLocation == 'vsphere') {
780 if (deployChild) {
781 addToProviderNetMap(netMap, 'vsphere', 'regional-child')
782 }
783 addToProviderNetMap(netMap, 'vsphere', 'region')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400784 }
Mikhail Ivanov90a27fa2022-05-30 15:18:24 +0400785
786 if (multiregionConfig.regionLocation == 'azure') {
787 lockLabels['azure_core_ci_queue'] = 1
788 if (deployChild) {
789 lockLabels['azure_core_ci_queue'] += 1
790 }
791 }
792 }
793 if (triggers.azureOnAwsDemoEnabled) {
794 lockLabels['azure_core_ci_queue'] = 1
795 }
796
797 if (triggers.equinixOnAwsDemoEnabled) {
798 lockLabels['equinix_core_ci_queue'] = 1
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400799 }
800 break
801 case 'vsphere':
Владислав Наумов33e1e812021-08-17 17:09:25 +0200802 addToProviderNetMap(netMap, 'vsphere', 'mgmt')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400803 if (deployChild) {
Владислав Наумов33e1e812021-08-17 17:09:25 +0200804 addToProviderNetMap(netMap, 'vsphere', 'child')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400805 }
806 if (runMultiregion && multiregionConfig.managementLocation == 'vsphere' &&
807 multiregionConfig.regionLocation == 'vsphere') {
808 if (deployChild) {
Владислав Наумов33e1e812021-08-17 17:09:25 +0200809 addToProviderNetMap(netMap, 'vsphere', 'regional-child')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400810 }
Владислав Наумов33e1e812021-08-17 17:09:25 +0200811 addToProviderNetMap(netMap, 'vsphere', 'region')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400812 }
813 break
Mikhail Ivanov90a27fa2022-05-30 15:18:24 +0400814 case 'azure':
815 lockLabels['azure_core_ci_queue'] = triggers.demoWeight
816 if (runMultiregion && multiregionConfig.managementLocation == 'azure') {
817 if (multiregionConfig.regionLocation == 'aws') {
818 lockLabels['aws_core_ci_queue'] = 1
819 if (deployChild) {
820 lockLabels['aws_core_ci_queue'] += 1
821 }
822 }
823
824 if (multiregionConfig.regionLocation == 'equinix') {
825 lockLabels['equinix_core_ci_queue'] = 1
826 if (deployChild) {
827 lockLabels['equinix_core_ci_queue'] +=1
828 }
829 }
830 }
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400831 default:
Mikhail Ivanov90a27fa2022-05-30 15:18:24 +0400832 error('Supposed to be called from aws, azure or vsphere demos only')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400833 }
834
835 // Checking gerrit triggers and manage lock label quantity and network types in case of Offline deployment
836 // Vsphere labels only
Владислав Наумов33e1e812021-08-17 17:09:25 +0200837 netMap['vsphere'].each { clusterType, netConfig ->
838 if (triggers.proxyConfig["${clusterType}Offline"] == true ||
839 (clusterType == 'regional-child' && triggers.proxyConfig['childOffline'] == true) ||
840 (clusterType == 'region' && triggers.proxyConfig['mgmtOffline'])) {
841
842 netMap['vsphere'][clusterType]['netName'] = 'offline'
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400843 lockLabels['vsphere_offline_networking_core_ci']++
844 } else {
845 lockLabels['vsphere_networking_core_ci']++
846 }
847 }
848
849 // generate lock metadata
850 def lockResources = []
851 lockLabels.each { label, quantity ->
852 if (quantity > 0) {
853 def res = [
854 label: label,
855 quantity: quantity,
856 ]
857 lockResources.add(res)
858 }
859 }
860
861 common.infoMsg("""Generated vsphere netMap: ${netMap}
862 Generated lockResources: ${lockResources}""")
863
864 return [
865 netMap: netMap,
866 lockResources: lockResources,
867 ]
868}
869
870/**
871 * Function gets vsphere netMap or empty map and adds new vsphere clusterType with default netName
872 * and empty rangeConfig to the this map.
873 *
Владислав Наумов33e1e812021-08-17 17:09:25 +0200874 * @param: netMap (string) vsphere, equinix netMap or empty map
875 * @param: provider (string) provider type
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400876 * @param: clusterType (string) Vsphere cluster type
877 */
878
Владислав Наумов33e1e812021-08-17 17:09:25 +0200879def addToProviderNetMap (netMap, provider, clusterType) {
880 switch (provider) {
881 case 'equinix':
882 netMap[provider][clusterType] = [
883 vlanConfig: '',
884 ]
885 break
886 case 'vsphere':
887 netMap[provider][clusterType] = [
888 netName: 'default',
889 rangeConfig: '',
890 ]
891 break
892 default:
893 error('Net map locks supported for Equinix/Vsphere providers only')
894 }
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400895}
Dmitry Teselkinfce71aa2022-03-05 19:36:52 +0300896
897/**
898* getCIKeywordsFromCommitMsg parses commit message and returns all gerrit keywords with their values as a list of maps.
899* Each element (map) contains keys 'key' for keyword name and 'value' for its value.
900* If keyword contains only 'key' part then 'value' is boolean True.
901* This function does not perform keywords validation.
902* First line of a commit message is ignored.
903* To use '[' or ']' characters inside keyword prepend it with backslash '\'.
904* TODO: Remove backslash chars from values if they prepend '[' or ']'.
905**/
906
907List getCIKeywordsFromCommitMsg() {
908 String commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
909 List commitMsgLines = commitMsg.split('\n')
910 List keywords = []
911 if (commitMsgLines.size() < 2) {
912 return keywords
913 }
914
915 String commitMsgBody = commitMsgLines[1..-1].join('\n')
916
917 // Split commit message body to chunks using '[' or ']' as delimiter,
918 // ignoring them if prepended by backslash (regex negative lookbehind).
919 // Resulting list will have chunks between '[' and ']' at odd indexes.
920 List parts = commitMsgBody.split(/(?<!\\)[\[\]]/)
921
922 // Iterate chunks by odd indexes only, trim values and split to
923 // <key> / <value> pair where <key> is the part of a sting before the first
924 // whitespace delimiter, and <value> is the rest (may include whitespaces).
925 // If there is no whitespace in the string then this is a 'switch'
926 // and <value> will be boolean True.
927 for (i = 1; i < parts.size(); i += 2) {
928 def (key, value) = (parts[i].trim().split(/\s+/, 2) + [true, ])[0..1]
929 keywords.add(['key': key, 'value': value])
930 }
931
932 return keywords
933}
934
935/**
936* getJobsParamsFromCommitMsg parses list of CI keywords and returns values of 'job-params' keyword
937* that were specified for given job name. `job-params` keyword has the following structure
938*
939* [job-params <job name> <parameter name> <parameter value>]
940*
941* Return value is a Map that contains those parameters using the following structure:
942*
943* <job name>:
944* <parameter name>: <parameter value>
945*
946**/
947Map getJobsParamsFromCommitMsg() {
948 List keywords = getCIKeywordsFromCommitMsg()
949
950 List jobsParamsList = []
951 keywords.findAll{ it.key == 'job-params' }.collect(jobsParamsList) {
952 def (name, params) = (it['value'].split(/\s+/, 2) + [null, ])[0..1]
953 def (key, value) = params.split(/\s+/, 2)
954 ['name': name, 'key': key, 'value': value]
955 }
956
957 Map jobsParams = jobsParamsList.inject([:]) { result, it ->
958 if (!result.containsKey(it.name)) {
959 result[it.name] = [:]
960 }
961 result[it.name][it.key] = it.value
962 result
963 }
964
965 return jobsParams
966}
967
968
969/**
970* getJobParamsFromCommitMsg returns key:value Map of parameters set for a job in commit message.
971* It uses getJobsParamsFromCommitMsg to get all parameters from commit message and then
972* uses only those parametes that were set to all jobs (with <job name> == '*') or to
973* a particular job. Parameters set to a particular job have higher precedence.
974*
975* Return value is a Map that contains those parameters:
976*
977* <parameter name>: <parameter value>
978*
979**/
980Map getJobParamsFromCommitMsg(String jobName) {
981 jobsParams = getJobsParamsFromCommitMsg()
982 jobParams = jobsParams.getOrDefault('*', [:])
983 if (jobName) {
984 jobParams.putAll(jobsParams.getOrDefault(jobName, [:]))
985 }
986 return jobParams
987}