blob: e78921c41b0d92f85582a7470c1294b8b1990cc6 [file] [log] [blame]
vnaumov33747e12020-05-04 17:35:20 +02001package com.mirantis.mk
vnaumov33747e12020-05-04 17:35:20 +02002
azvyagintsevc17d14b2022-06-06 19:06:33 +03003import static groovy.json.JsonOutput.toJson
4
vnaumov33747e12020-05-04 17:35:20 +02005/**
6 *
7 * KaaS Component Testing Utilities
8 *
9 */
10
Владислав Наумовe5345812020-08-12 16:30:20 +020011/**
12 * Check KaaS Core CICD feature flags
13 * such triggers can be used in case of switching between pipelines,
14 * conditions inside pipelines to reduce dependency on jenkins job builder and jenkins job templates itself
15 *
16 * @return (map)[
17 * ffNameEnabled: (bool) True/False
18 * ]
19 */
20def checkCoreCIFeatureFlags() {
21 def common = new com.mirantis.mk.Common()
22 def ff = [
23 build_artifacts_upgrade: false,
24 ]
25
26 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
27 if (commitMsg ==~ /(?s).*\[ci-build-artifacts-upgrade\].*/) {
28 ff['build_artifacts_upgrade'] = true
29 }
30
31 common.infoMsg("Core ci feature flags status: ${ff}")
32 return ff
33}
vnaumov33747e12020-05-04 17:35:20 +020034
35/**
azvyagintseva12230a2020-06-05 13:24:06 +030036 * Determine scope of test suite against per-commit KaaS deployment based on keywords
Владислав Наумов81777472021-03-09 15:14:27 +040037 * 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 +030038 *
39 * Used for components team to combine test-suites and forward desired parameters to kaas/core deployment jobs
40 * Example scheme:
Владислав Наумовe5345812020-08-12 16:30:20 +020041 * 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 +030042 * manage test-suite through Jenkins Job Parameters
43 *
Владислав Наумов6c2afff2020-06-05 12:54:53 +020044 * @return (map)[
45 * deployChildEnabled: (bool) True if need to deploy child cluster during demo-run
46 * runUie2eEnabled: (bool) True if need to run ui-e2e cluster during demo-run
azvyagintseva12230a2020-06-05 13:24:06 +030047 * ]
48 */
vnaumov33747e12020-05-04 17:35:20 +020049def checkDeploymentTestSuite() {
vnaumovbdb90222020-05-04 18:25:50 +020050 def common = new com.mirantis.mk.Common()
51
vnaumov33747e12020-05-04 17:35:20 +020052 // Available triggers and its sane defaults
Владислав Наумов44c64b72020-12-04 20:22:53 +010053 def seedMacOs = env.SEED_MACOS ? env.SEED_MACOS.toBoolean() : false
Владислав Наумов6c2afff2020-06-05 12:54:53 +020054 def deployChild = env.DEPLOY_CHILD_CLUSTER ? env.DEPLOY_CHILD_CLUSTER.toBoolean() : false
55 def upgradeChild = env.UPGRADE_CHILD_CLUSTER ? env.UPGRADE_CHILD_CLUSTER.toBoolean() : false
Mikhail Ivanov38ee4382022-01-27 16:21:51 +040056 def mosDeployChild = env.DEPLOY_MOS_CHILD_CLUSTER ? env.DEPLOY_MOS_CHILD_CLUSTER.toBoolean() : false
57 def mosUpgradeChild = env.UPGRADE_MOS_CHILD_CLUSTER ? env.UPGRADE_MOS_CHILD_CLUSTER.toBoolean() : false
Mikhail Ivanov74504372021-05-21 17:01:06 +040058 def customChildRelease = env.KAAS_CHILD_CLUSTER_RELEASE_NAME ? env.KAAS_CHILD_CLUSTER_RELEASE_NAME : ''
slalov021171f2022-03-04 14:48:38 +040059 def mosTfDeploy = env.MOS_TF_DEPLOY ? env.MOS_TF_DEPLOY.toBoolean() : false
Владислав Наумов0dc99252020-11-13 13:30:48 +010060 def attachBYO = env.ATTACH_BYO ? env.ATTACH_BYO.toBoolean() : false
Владислав Наумовcdbd84e2020-12-01 16:51:09 +010061 def upgradeBYO = env.UPGRADE_BYO ? env.UPGRADE_BYO.toBoolean() : false
Vladislav Naumov7930ab22021-11-22 18:24:24 +010062 def runBYOMatrix = env.RUN_BYO_MATRIX ? env.RUN_BYO_MATRIX.toBoolean() : false
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +040063 def defaultBYOOs = env.DEFAULT_BYO_OS ? env.DEFAULT_BYO_OS.toString() : 'ubuntu'
Владислав Наумов6c2afff2020-06-05 12:54:53 +020064 def upgradeMgmt = env.UPGRADE_MGMT_CLUSTER ? env.UPGRADE_MGMT_CLUSTER.toBoolean() : false
slalov1202bba2022-04-20 22:31:07 +040065 def autoUpgradeMgmt = env.AUTO_UPGRADE_MCC ? env.AUTO_UPGRADE_MCC.toBoolean() : false
Victor Ryzhenkind2b7b662021-08-23 14:18:38 +040066 def enableLMALogging = env.ENABLE_LMA_LOGGING ? env.ENABLE_LMA_LOGGING.toBoolean(): false
Владислав Наумов6c2afff2020-06-05 12:54:53 +020067 def runUie2e = env.RUN_UI_E2E ? env.RUN_UI_E2E.toBoolean() : false
Mikhail Ivanovf5e20af2022-03-24 15:38:06 +040068 def runUie2eNew = env.RUN_UI_E2E_NEW ? env.RUN_UI_E2E_NEW.toBoolean() : false
Владислав Наумов6c2afff2020-06-05 12:54:53 +020069 def runMgmtConformance = env.RUN_MGMT_CFM ? env.RUN_MGMT_CFM.toBoolean() : false
Владислав Наумов9cec55d2021-08-03 15:00:59 +020070 def runLMATest = env.RUN_LMA_TEST ? env.RUN_LMA_TEST.toBoolean() : false
Vladyslav Drokc4f9c1b2021-07-22 15:34:24 +020071 def runMgmtUserControllerTest = env.RUN_MGMT_USER_CONTROLLER_TEST ? env.RUN_MGMT_USER_CONTROLLER_TEST.toBoolean() : false
Mikhail Ivanov2907e4d2022-04-25 16:41:21 +040072 def runProxyChildTest = env.RUN_PROXY_CHILD_TEST ? env.RUN_PROXY_CHILD_TEST.toBoolean() : false
Владислав Наумов6c2afff2020-06-05 12:54:53 +020073 def runChildConformance = env.RUN_CHILD_CFM ? env.RUN_CHILD_CFM.toBoolean() : false
74 def fetchServiceBinaries = env.FETCH_BINARIES_FROM_UPSTREAM ? env.FETCH_BINARIES_FROM_UPSTREAM.toBoolean() : false
Vladislav Naumov42b71dc2021-11-22 13:09:42 +010075 def equinixMetalV2ChildDiffMetro = env.EQUINIXMETALV2_CHILD_DIFF_METRO ? env.EQUINIXMETALV2_CHILD_DIFF_METRO.toBoolean() : false
slalov13e579c2022-01-31 21:37:02 +040076 def runMaintenanceTest = env.RUN_MAINTENANCE_TEST ? env.RUN_MAINTENANCE_TEST.toBoolean() : false
slalov0a4947a2022-06-09 15:44:35 +040077 def runContainerregistryTest = env.RUN_CONTAINER_REGISTRY_TEST ? env.RUN_CONTAINER_REGISTRY_TEST.toBoolean() : false
Dmitriy Kasyanov5f910e62022-02-11 14:57:05 +030078 def runMgmtDeleteMasterTest = env.RUN_MGMT_DELETE_MASTER_TEST ? env.RUN_MGMT_DELETE_MASTER_TEST.toBoolean() : false
79 def runRgnlDeleteMasterTest = env.RUN_RGNL_DELETE_MASTER_TEST ? env.RUN_RGNL_DELETE_MASTER_TEST.toBoolean() : false
80 def runChildDeleteMasterTest = env.RUN_CHILD_DELETE_MASTER_TEST ? env.RUN_CHILD_DELETE_MASTER_TEST.toBoolean() : false
Владислав Наумов765f3bd2020-09-07 18:09:24 +020081 // multiregion configuration from env variable: comma-separated string in form $mgmt_provider,$regional_provider
82 def multiregionalMappings = env.MULTIREGION_SETUP ? multiregionWorkflowParser(env.MULTIREGION_SETUP) : [
83 enabled: false,
84 managementLocation: '',
85 regionLocation: '',
86 ]
Владислав Наумов4eb1da32020-08-31 14:45:16 +020087
Владислав Наумовb8305e22021-02-10 17:23:12 +010088 // proxy customization
89 def proxyConfig = [
Владислав Наумовf8f23fa2021-04-01 16:57:52 +020090 mgmtOffline: env.OFFLINE_MGMT_CLUSTER ? env.OFFLINE_MGMT_CLUSTER.toBoolean() : false,
91 childOffline: env.OFFLINE_CHILD_CLUSTER ? env.OFFLINE_CHILD_CLUSTER.toBoolean() : false,
Владислав Наумов257ea132021-04-14 14:44:13 +020092 childProxy: env.PROXY_CHILD_CLUSTER ? env.PROXY_CHILD_CLUSTER.toBoolean() : false,
Владислав Наумовb8305e22021-02-10 17:23:12 +010093 ]
94
Владислав Наумов4eb1da32020-08-31 14:45:16 +020095 // optional demo deployment customization
Владислав Наумов905dd362020-06-08 16:37:01 +020096 def awsOnDemandDemo = env.ALLOW_AWS_ON_DEMAND ? env.ALLOW_AWS_ON_DEMAND.toBoolean() : false
Владислав Наумовe021b022021-05-06 11:26:38 +020097 def equinixOnDemandDemo = env.ALLOW_EQUINIX_ON_DEMAND ? env.ALLOW_EQUINIX_ON_DEMAND.toBoolean() : false
Владислав Наумов82305e92021-10-14 20:45:20 +020098 def equinixMetalV2OnDemandDemo = env.ALLOW_EQUINIXMETALV2_ON_DEMAND ? env.ALLOW_EQUINIXMETALV2_ON_DEMAND.toBoolean() : false
Владислав Наумовf3715802021-05-03 18:06:45 +020099 def equinixOnAwsDemo = env.EQUINIX_ON_AWS_DEMO ? env.EQUINIX_ON_AWS_DEMO.toBoolean() : false
Владислав Наумов2d3db332021-06-15 15:19:19 +0200100 def azureOnAwsDemo = env.AZURE_ON_AWS_DEMO ? env.AZURE_ON_AWS_DEMO.toBoolean() : false
Владислав Наумовc52dd9d2021-06-28 16:27:29 +0200101 def azureOnDemandDemo = env.ALLOW_AZURE_ON_DEMAND ? env.ALLOW_AZURE_ON_DEMAND.toBoolean() : false
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +0400102 def enableVsphereDemo = true
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200103 def enableOSDemo = true
azvyagintsev1761bdc2020-09-04 17:24:12 +0300104 def enableBMDemo = true
Mikhail Ivanovbd1a9fd2022-03-29 21:36:21 +0400105 def enableArtifactsBuild = true
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400106 def openstackIMC = env.OPENSTACK_CLOUD_LOCATION ? env.OPENSTACK_CLOUD_LOCATION : 'us'
Alexandr Lovtsov36473f32022-04-28 15:46:09 +0300107 def enableVsphereUbuntu = env.VSPHERE_DEPLOY_UBUNTU ? env.VSPHERE_DEPLOY_UBUNTU.toBoolean() : false
Sergey Zhemerdeeve67fb262022-06-21 00:49:34 +0300108 def childOsBootFromVolume = env.OPENSTACK_BOOT_FROM_VOLUME ? env.OPENSTACK_BOOT_FROM_VOLUME.toBoolean() : false
Ivan Berezovskiy29e72b72022-07-12 21:03:24 +0400109 def bootstrapV2Scenario = env.BOOTSTRAP_V2_ENABLED ? env.BOOTSTRAP_V2_ENABLED.toBoolean() : false
Sergey Lalovacec3c12022-07-20 16:00:14 +0400110 def equinixMetalV2Metro = env.EQUINIX_MGMT_METRO ? env.EQUINIX_MGMT_METRO : ''
vnaumov33747e12020-05-04 17:35:20 +0200111
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200112 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
Владислав Наумовb8305e22021-02-10 17:23:12 +0100113 if (commitMsg ==~ /(?s).*\[mgmt-proxy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-proxy.*/) {
114 proxyConfig['mgmtOffline'] = true
Владислав Наумов70c02422021-04-19 14:29:41 +0200115 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 +0100116 }
Владислав Наумов44c64b72020-12-04 20:22:53 +0100117 if (commitMsg ==~ /(?s).*\[seed-macos\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*seed-macos.*/) {
118 seedMacOs = true
119 }
slalov574123e2022-04-06 17:24:19 +0400120 if (commitMsg ==~ /(?s).*\[child-deploy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-deploy.*/ || upgradeChild || runChildConformance || runProxyChildTest) {
vnaumov33747e12020-05-04 17:35:20 +0200121 deployChild = true
122 }
123 if (commitMsg ==~ /(?s).*\[child-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-upgrade.*/) {
124 deployChild = true
125 upgradeChild = true
126 }
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400127 def childDeployMatches = (commitMsg =~ /(\[child-deploy\s*(\w|\-)+?\])/)
128 if (childDeployMatches.size() > 0) {
Mikhail Ivanov74504372021-05-21 17:01:06 +0400129 // override child version when it set explicitly
130 deployChild = true
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400131 customChildRelease = childDeployMatches[0][0].split('child-deploy')[1].replaceAll('[\\[\\]]', '').trim()
Mikhail Ivanov74504372021-05-21 17:01:06 +0400132 common.warningMsg("Forced child deployment using custom release version ${customChildRelease}")
133 }
Mikhail Ivanov38ee4382022-01-27 16:21:51 +0400134 if (commitMsg ==~ /(?s).*\[mos-child-deploy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mos-child-deploy.*/) {
135 mosDeployChild = true
136 }
137 if (commitMsg ==~ /(?s).*\[mos-child-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mos-child-upgrade.*/) {
138 mosDeployChild = true
139 mosUpgradeChild = true
140 }
Владислав Наумов0dc99252020-11-13 13:30:48 +0100141 if (commitMsg ==~ /(?s).*\[byo-attach\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-attach.*/) {
142 attachBYO = true
143 }
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100144 if (commitMsg ==~ /(?s).*\[byo-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-upgrade.*/) {
145 attachBYO = true
146 upgradeBYO = true
147 }
Sergey Lalovacec3c12022-07-20 16:00:14 +0400148 if (commitMsg ==~ /(?s).*\[ui-test-on-all-providers\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*ui-test-on-all-providers.*/) {
149 enableVsphereDemo = true
150 enableOSDemo = true
151 awsOnDemandDemo = true
152 azureOnDemandDemo = true
153 equinixOnDemandDemo = true
154 equinixMetalV2OnDemandDemo = true
155 runUie2e = true
Sergey Lalovacec3c12022-07-20 16:00:14 +0400156 // Edit after fix PRODX-3961
157 enableBMDemo = false
158 }
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400159 def byoDeployMatches = (commitMsg =~ /(\[run-byo-matrix\s*(ubuntu|centos)\])/)
160 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 +0100161 runBYOMatrix = true
162
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400163 if (byoDeployMatches.size() > 0) {
164 defaultBYOOs = byoDeployMatches[0][2]
165 common.warningMsg("Custom BYO OS detected, using ${defaultBYOOs}")
166 }
167
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100168 common.warningMsg('Forced byo matrix test via run-byo-matrix, all other byo triggers will be skipped')
169 attachBYO = false
170 upgradeBYO = false
171 }
Владислав Наумов7f8c9872021-03-08 17:33:08 +0400172 if (commitMsg ==~ /(?s).*\[mgmt-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-upgrade.*/) {
vnaumov33747e12020-05-04 17:35:20 +0200173 upgradeMgmt = true
174 }
slalov1202bba2022-04-20 22:31:07 +0400175 if (commitMsg ==~ /(?s).*\[auto-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*auto-upgrade.*/) {
176 autoUpgradeMgmt = true
177 }
Victor Ryzhenkind2b7b662021-08-23 14:18:38 +0400178 if (commitMsg ==~ /(?s).*\[lma-logging\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*lma-logging.*/) {
179 enableLMALogging = true
180 }
vnaumov33747e12020-05-04 17:35:20 +0200181 if (commitMsg ==~ /(?s).*\[ui-e2e\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*ui-e2e.*/) {
182 runUie2e = true
183 }
Mikhail Ivanovf5e20af2022-03-24 15:38:06 +0400184 if (commitMsg ==~ /(?s).*\[ui-e2e-new\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*ui-e2e-new.*/) {
185 runUie2eNew = true
186 }
vnaumov33747e12020-05-04 17:35:20 +0200187 if (commitMsg ==~ /(?s).*\[mgmt-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-cfm.*/) {
188 runMgmtConformance = true
189 }
Vladyslav Drokc4f9c1b2021-07-22 15:34:24 +0200190 if (commitMsg ==~ /(?s).*\[test-user-controller\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*test-user-controller.*/) {
191 runMgmtUserControllerTest = true
192 }
slalov574123e2022-04-06 17:24:19 +0400193 if (commitMsg ==~ /(?s).*\[test-proxy-child\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*test-proxy-child.*/) {
194 runProxyChildTest = true
195 deployChild = true
196 common.infoMsg('Child cluster deployment will be enabled since proxy child test suite will be executed')
197 }
vnaumov33747e12020-05-04 17:35:20 +0200198 if (commitMsg ==~ /(?s).*\[child-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-cfm.*/) {
199 runChildConformance = true
200 deployChild = true
201 }
Владислав Наумов9cec55d2021-08-03 15:00:59 +0200202 if (commitMsg ==~ /(?s).*\[lma-test\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*lma-test.*/) {
203 runLMATest = true
Victor Ryzhenkind2b7b662021-08-23 14:18:38 +0400204 enableLMALogging = true
205 common.infoMsg('LMA logging will be enabled since LMA test suite will be executed')
Victor Ryzhenkin15206592021-06-21 17:38:23 +0400206 }
slalov13e579c2022-01-31 21:37:02 +0400207 if (commitMsg ==~ /(?s).*\[maintenance-test\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*maintenance-test.*/) {
208 runMaintenanceTest = true
209 }
slalov0a4947a2022-06-09 15:44:35 +0400210 if (commitMsg ==~ /(?s).*\[container-registry-test\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*container-registry-test.*/) {
211 runContainerregistryTest = true
212 }
Dmitriy Kasyanov5f910e62022-02-11 14:57:05 +0300213 if (commitMsg ==~ /(?s).*\[mgmt-delete-master-test\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-delete-master-test.*/) {
214 runMgmtDeleteMasterTest = true
215 }
216 if (commitMsg ==~ /(?s).*\[rgnl-delete-master-test\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*rgnl-delete-master-test.*/) {
217 runRgnlDeleteMasterTest = true
218 }
219 if (commitMsg ==~ /(?s).*\[child-delete-master-test\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-delete-master-test.*/) {
220 runChildDeleteMasterTest = true
221 }
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200222 if (commitMsg ==~ /(?s).*\[child-offline\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-offline.*/) {
223 proxyConfig['childOffline'] = true
224 deployChild = true
225 }
Владислав Наумов257ea132021-04-14 14:44:13 +0200226 if (commitMsg ==~ /(?s).*\[child-proxy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-proxy.*/) {
227 proxyConfig['childOffline'] = true
228 proxyConfig['childProxy'] = true
229 deployChild = true
230 }
vnaumov33747e12020-05-04 17:35:20 +0200231 if (commitMsg ==~ /(?s).*\[fetch.*binaries\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*fetch.*binaries.*/) {
232 fetchServiceBinaries = true
233 }
Владислав Наумовf1665b52021-05-13 10:51:17 +0200234 if (commitMsg ==~ /(?s).*\[equinix-on-aws\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinix-on-aws.*/) {
eromanovadf247c32020-12-25 15:44:13 +0400235 equinixOnAwsDemo = true
Владислав Наумовf1665b52021-05-13 10:51:17 +0200236 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 +0400237 }
Владислав Наумов2d3db332021-06-15 15:19:19 +0200238 if (commitMsg ==~ /(?s).*\[azure-on-aws\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*azure-on-aws.*/) {
239 azureOnAwsDemo = true
240 common.warningMsg('Forced running child cluster deployment on Azure provider based on AWS management cluster, triggered on patchset using custom keyword: \'[azure-on-aws]\' ')
241 }
242 if (commitMsg ==~ /(?s).*\[aws-demo\].*/ ||
243 env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*aws-demo.*/ ||
244 attachBYO ||
245 upgradeBYO ||
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100246 runBYOMatrix ||
Владислав Наумов2d3db332021-06-15 15:19:19 +0200247 seedMacOs ||
248 equinixOnAwsDemo ||
249 azureOnAwsDemo) {
250
vnaumov33747e12020-05-04 17:35:20 +0200251 awsOnDemandDemo = true
Владислав Наумов2d3db332021-06-15 15:19:19 +0200252 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 +0200253 }
Владислав Наумовf1665b52021-05-13 10:51:17 +0200254 if (commitMsg ==~ /(?s).*\[equinix-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinix-demo\.*/) {
Владислав Наумовe021b022021-05-06 11:26:38 +0200255 equinixOnDemandDemo = true
256 }
Владислав Наумов82305e92021-10-14 20:45:20 +0200257 if (commitMsg ==~ /(?s).*\[equinixmetalv2-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinixmetalv2-demo\.*/) {
Владислав Наумов144956f2021-10-14 17:49:19 +0200258 equinixMetalV2OnDemandDemo = true
259 }
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100260 if (commitMsg ==~ /(?s).*\[equinixmetalv2-child-diff-metro\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinixmetalv2-child-diff-metro\.*/) {
261 equinixMetalV2OnDemandDemo = true
262 equinixMetalV2ChildDiffMetro = true
263 }
Владислав Наумовc52dd9d2021-06-28 16:27:29 +0200264 if (commitMsg ==~ /(?s).*\[azure-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*azure-demo\.*/) {
265 azureOnDemandDemo = true
266 }
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200267 if (commitMsg ==~ /(?s).*\[disable-os-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-os-demo\.*/) {
268 enableOSDemo = false
269 common.errorMsg('Openstack demo deployment will be aborted, VF -1 will be set')
vnaumov33747e12020-05-04 17:35:20 +0200270 }
271
azvyagintsev1761bdc2020-09-04 17:24:12 +0300272 if (commitMsg ==~ /(?s).*\[disable-bm-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-bm-demo\.*/) {
273 enableBMDemo = false
274 common.errorMsg('BM demo deployment will be aborted, VF -1 will be set')
275 }
276
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +0400277 if (commitMsg ==~ /(?s).*\[disable-vsphere-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-vsphere-demo\.*/) {
278 enableVsphereDemo = false
279 common.errorMsg('vSphere demo deployment will be aborted, VF -1 will be set')
280 }
Alexandr Lovtsov36473f32022-04-28 15:46:09 +0300281 if (commitMsg ==~ /(?s).*\[vsphere-ubuntu\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*vsphere-ubuntu\.*/) {
282 enableVsphereUbuntu = true
283 common.warningMsg('Ubuntu will be used to deploy vsphere machines')
284 }
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +0400285
Mikhail Ivanovbd1a9fd2022-03-29 21:36:21 +0400286 if (commitMsg ==~ /(?s).*\[disable-artifacts-build\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-artifacts-build\.*/) {
287 enableArtifactsBuild = false
288 common.errorMsg('artifacts build will be aborted, VF -1 will be set')
289 }
290
Sergey Zhemerdeeve67fb262022-06-21 00:49:34 +0300291 if (commitMsg ==~ /(?s).*\[child-os-boot-from-volume\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-os-boot-from-volume\.*/) {
292 childOsBootFromVolume = true
293 common.warningMsg('OS will be booted from Ceph volumes')
294 }
295
vnaumov33747e12020-05-04 17:35:20 +0200296 // TODO (vnaumov) remove below condition after moving all releases to UCP
297 def ucpChildMatches = (commitMsg =~ /(\[child-ucp\s*ucp-.*?\])/)
298 if (ucpChildMatches.size() > 0) {
299 deployChild = true
300 common.warningMsg('Forced UCP based child deployment triggered on patchset using custom keyword: \'[child-ucp ucp-5-1-0-3-3-0-example]\' ')
301
302 // TODO(vnaumov) delete after ucp upgrades support
303 common.errorMsg('Child upgrade test will be skipped, UCP upgrades temporally disabled')
304 upgradeChild = false
305 }
306
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200307 // multiregional tests
308 def multiRegionalMatches = (commitMsg =~ /(\[multiregion\s*.*?\])/)
309 if (multiRegionalMatches.size() > 0) {
310 multiregionalMappings = multiregionWorkflowParser(multiRegionalMatches)
311 }
312 switch (multiregionalMappings['managementLocation']) {
313 case 'aws':
Владислав Наумов53b07e52021-01-07 15:08:27 +0100314 common.warningMsg('Forced running additional kaas deployment with AWS provider according multiregional demo request')
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200315 awsOnDemandDemo = true
Владислав Наумов53b07e52021-01-07 15:08:27 +0100316
317 if (multiregionalMappings['regionLocation'] != 'aws' && seedMacOs) { // macstadium seed node has access only to *public* providers
318 error('incompatible triggers: [seed-macos] and multiregional deployment based on *private* regional provider cannot be applied simultaneously')
319 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200320 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200321 case 'os':
322 if (enableOSDemo == false) {
323 error('incompatible triggers: [disable-os-demo] and multiregional deployment based on OSt management region cannot be applied simultaneously')
324 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200325 break
Владислав Наумов865ba6c2021-05-13 13:05:45 +0200326 case 'vsphere':
327 if (enableVsphereDemo == false) {
328 error('incompatible triggers: [disable-vsphere-demo] and multiregional deployment based on Vsphere management region cannot be applied simultaneously')
329 }
330 break
Владислав Наумов5be02942021-05-13 12:34:37 +0200331 case 'equinix':
332 common.warningMsg('Forced running additional kaas deployment with Equinix provider according multiregional demo request')
333 equinixOnDemandDemo = true
eromanova35359162021-12-30 14:13:13 +0400334 break
eromanova8c702ae2021-12-24 17:43:12 +0400335 case 'equinixmetalv2':
336 common.warningMsg('Forced running additional kaas deployment with Equinix Metal V2 provider according multiregional demo request')
337 equinixMetalV2OnDemandDemo = true
eromanova35359162021-12-30 14:13:13 +0400338 break
slalovfd0b7e62021-07-28 18:05:16 +0400339 case 'azure':
340 common.warningMsg('Forced running additional kaas deployment with Azure provider according multiregional demo request')
341 azureOnDemandDemo = true
342 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200343 }
344
Владислав Наумовb8305e22021-02-10 17:23:12 +0100345 // CDN configuration
346 def cdnConfig = [
347 mgmt: [
348 openstack: (proxyConfig['mgmtOffline'] == true) ? 'public-ci' : 'internal-ci',
Владислав Наумов70c02422021-04-19 14:29:41 +0200349 vsphere: 'internal-ci',
Владислав Наумовb8305e22021-02-10 17:23:12 +0100350 aws: 'public-ci',
Владислав Наумовe021b022021-05-06 11:26:38 +0200351 equinix: 'public-ci',
Владислав Наумовc52dd9d2021-06-28 16:27:29 +0200352 azure: 'public-ci',
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200353 ],
Владислав Наумовb8305e22021-02-10 17:23:12 +0100354 ]
355
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400356 if (commitMsg ==~ /(?s).*\[eu-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*eu-demo.*/) {
357 openstackIMC = 'eu'
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400358 }
slalov021171f2022-03-04 14:48:38 +0400359 if (commitMsg ==~ /(?s).*\[mos-tf-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mos-tf-demo.*/) {
360 openstackIMC = 'eu2'
Mikhail Ivanovf05b8252022-04-27 18:14:03 +0400361 }
362 if (openstackIMC == 'eu' || openstackIMC == 'eu2') {
slalov021171f2022-03-04 14:48:38 +0400363 // use internal-eu because on internal-ci with eu cloud image pull takes much time
364 def cdnRegion = (proxyConfig['mgmtOffline'] == true) ? 'public-ci' : 'internal-eu'
365 common.infoMsg("eu2-demo was triggered, force switching CDN region to ${cdnRegion}")
366 cdnConfig['mgmt']['openstack'] = cdnRegion
367 }
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400368
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100369 // calculate weight of current demo run to manage lockable resources
Sergey Lalov46deb442022-08-18 12:11:03 +0400370 def demoWeight = deployChild ? 2 : 1 // management = 1, child += 1
371 if (runUie2e) {
372 demoWeight += 1
373 }
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100374
Ivan Berezovskiy29e72b72022-07-12 21:03:24 +0400375 if (commitMsg ==~ /(?s).*\[bootstrapv2-scenario\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*bootstrapv2-scenario\.*/) {
376 bootstrapV2Scenario = true
377 }
378
Sergey Zhemerdeevdd31ce92022-07-19 14:15:22 +0300379 // parse equinixmetalv2-metro trigger
Sergey Zhemerdeevdd31ce92022-07-19 14:15:22 +0300380 def equinixMetalV2MetroMatcher = (commitMsg =~ /\[equinixmetalv2-metro(\s+.*)?\]/)
381 if (equinixMetalV2OnDemandDemo && equinixMetalV2MetroMatcher.size() > 0) {
Sergey Zhemerdeevcc785e42022-07-22 17:15:47 +0300382 equinixMetalV2Metro = equinixMetalV2MetroMatcher[0][1].trim().toLowerCase()
Sergey Zhemerdeevdd31ce92022-07-19 14:15:22 +0300383 common.infoMsg("Forced Equnix mgmt deployment using custom metro ${equinixMetalV2Metro}")
384 }
385
vnaumov33747e12020-05-04 17:35:20 +0200386 common.infoMsg("""
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400387 OpenStack Cloud location: ${openstackIMC}
Владислав Наумовb8305e22021-02-10 17:23:12 +0100388 CDN deployment configuration: ${cdnConfig}
389 MCC offline deployment configuration: ${proxyConfig}
Владислав Наумов44c64b72020-12-04 20:22:53 +0100390 Use MacOS node as seed: ${seedMacOs}
vnaumov33747e12020-05-04 17:35:20 +0200391 Child cluster deployment scheduled: ${deployChild}
Mikhail Ivanov74504372021-05-21 17:01:06 +0400392 Custom child cluster release: ${customChildRelease}
vnaumov33747e12020-05-04 17:35:20 +0200393 Child cluster release upgrade scheduled: ${upgradeChild}
Mikhail Ivanov38ee4382022-01-27 16:21:51 +0400394 MOS child deploy scheduled: ${mosDeployChild}
395 MOS child upgrade scheduled: ${mosUpgradeChild}
vnaumov33747e12020-05-04 17:35:20 +0200396 Child conformance testing scheduled: ${runChildConformance}
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100397 Single BYO cluster attachment scheduled: ${attachBYO}
398 Single Attached BYO cluster upgrade test scheduled: ${upgradeBYO}
399 BYO test matrix whole suite scheduled: ${runBYOMatrix}
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400400 Default BYO OS: ${defaultBYOOs}
vnaumov33747e12020-05-04 17:35:20 +0200401 Mgmt cluster release upgrade scheduled: ${upgradeMgmt}
slalov1202bba2022-04-20 22:31:07 +0400402 Mgmt cluster release auto upgrade scheduled: ${autoUpgradeMgmt}
Victor Ryzhenkind2b7b662021-08-23 14:18:38 +0400403 Mgmt LMA logging enabled: ${enableLMALogging}
vnaumov33747e12020-05-04 17:35:20 +0200404 Mgmt conformance testing scheduled: ${runMgmtConformance}
Владислав Наумов9cec55d2021-08-03 15:00:59 +0200405 LMA testing scheduled: ${runLMATest}
Vladyslav Drokc4f9c1b2021-07-22 15:34:24 +0200406 Mgmt user controller testing scheduled: ${runMgmtUserControllerTest}
vnaumov33747e12020-05-04 17:35:20 +0200407 Mgmt UI e2e testing scheduled: ${runUie2e}
Mikhail Ivanovf5e20af2022-03-24 15:38:06 +0400408 Mgmt UI e2e playwrite testing scheduled: ${runUie2eNew}
slalov13e579c2022-01-31 21:37:02 +0400409 Maintenance test: ${runMaintenanceTest}
slalov0a4947a2022-06-09 15:44:35 +0400410 Container Registry test: ${runContainerregistryTest}
slalov574123e2022-04-06 17:24:19 +0400411 Child proxy test: ${runProxyChildTest}
Dmitriy Kasyanov5f910e62022-02-11 14:57:05 +0300412 Delete mgmt master node test: ${runMgmtDeleteMasterTest}
413 Delete rgnl master node test: ${runRgnlDeleteMasterTest}
414 Delete child master node test: ${runChildDeleteMasterTest}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200415 AWS provider deployment scheduled: ${awsOnDemandDemo}
Владислав Наумовe021b022021-05-06 11:26:38 +0200416 Equinix provider deployment scheduled: ${equinixOnDemandDemo}
Владислав Наумов144956f2021-10-14 17:49:19 +0200417 EquinixmetalV2 provider deployment scheduled: ${equinixMetalV2OnDemandDemo}
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100418 EquinixmetalV2 child deploy in a separate metro scheduled: ${equinixMetalV2ChildDiffMetro}
Sergey Zhemerdeev019c45a2022-08-13 00:09:07 +0300419 EquinixmetalV2 mgmt will be deployed on the metro: ${equinixMetalV2Metro?:'auto'}
Владислав Наумовf1665b52021-05-13 10:51:17 +0200420 Equinix@AWS child cluster deployment scheduled: ${equinixOnAwsDemo}
Владислав Наумовc52dd9d2021-06-28 16:27:29 +0200421 Azure provider deployment scheduled: ${azureOnDemandDemo}
Владислав Наумов2d3db332021-06-15 15:19:19 +0200422 Azure@AWS child cluster deployment scheduled: ${azureOnAwsDemo}
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +0400423 VSPHERE provider deployment scheduled: ${enableVsphereDemo}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200424 OS provider deployment scheduled: ${enableOSDemo}
azvyagintsev1761bdc2020-09-04 17:24:12 +0300425 BM provider deployment scheduled: ${enableBMDemo}
Alexandr Lovtsov36473f32022-04-28 15:46:09 +0300426 Ubuntu on vSphere scheduled: ${enableVsphereUbuntu}
Mikhail Ivanovbd1a9fd2022-03-29 21:36:21 +0400427 Artifacts build scheduled: ${enableArtifactsBuild}
Sergey Zhemerdeeve67fb262022-06-21 00:49:34 +0300428 Boot OS child from Ceph volumes: ${childOsBootFromVolume}
Владислав Наумовf793fe32020-09-11 15:19:19 +0200429 Multiregional configuration: ${multiregionalMappings}
vnaumov33747e12020-05-04 17:35:20 +0200430 Service binaries fetching scheduled: ${fetchServiceBinaries}
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100431 Current weight of the demo run: ${demoWeight} (Used to manage lockable resources)
Ivan Berezovskiy29e72b72022-07-12 21:03:24 +0400432 Bootstrap v2 scenario enabled: ${bootstrapV2Scenario}
Владислав Наумов81777472021-03-09 15:14:27 +0400433 Triggers: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
vnaumov33747e12020-05-04 17:35:20 +0200434 return [
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400435 osCloudLocation : openstackIMC,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100436 cdnConfig : cdnConfig,
437 proxyConfig : proxyConfig,
438 useMacOsSeedNode : seedMacOs,
439 deployChildEnabled : deployChild,
440 childDeployCustomRelease : customChildRelease,
441 upgradeChildEnabled : upgradeChild,
Mikhail Ivanov38ee4382022-01-27 16:21:51 +0400442 mosDeployChildEnabled : mosDeployChild,
443 mosUpgradeChildEnabled : mosUpgradeChild,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100444 runChildConformanceEnabled : runChildConformance,
445 attachBYOEnabled : attachBYO,
446 upgradeBYOEnabled : upgradeBYO,
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100447 runBYOMatrixEnabled : runBYOMatrix,
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400448 defaultBYOOs : defaultBYOOs,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100449 upgradeMgmtEnabled : upgradeMgmt,
slalov1202bba2022-04-20 22:31:07 +0400450 autoUpgradeMgmtEnabled : autoUpgradeMgmt,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100451 enableLMALoggingEnabled : enableLMALogging,
452 runUie2eEnabled : runUie2e,
Mikhail Ivanovf5e20af2022-03-24 15:38:06 +0400453 runUie2eNewEnabled : runUie2eNew,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100454 runMgmtConformanceEnabled : runMgmtConformance,
slalov0a4947a2022-06-09 15:44:35 +0400455 runMaintenanceTestEnabled : runMaintenanceTest,
Dmitriy Kasyanov5f910e62022-02-11 14:57:05 +0300456 runContainerregistryTestEnabled : runContainerregistryTest,
457 runMgmtDeleteMasterTestEnabled : runMgmtDeleteMasterTest,
458 runRgnlDeleteMasterTestEnabled : runRgnlDeleteMasterTest,
459 runChildDeleteMasterTestEnabled : runChildDeleteMasterTest,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100460 runLMATestEnabled : runLMATest,
461 runMgmtUserControllerTestEnabled : runMgmtUserControllerTest,
slalov574123e2022-04-06 17:24:19 +0400462 runProxyChildTestEnabled : runProxyChildTest,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100463 fetchServiceBinariesEnabled : fetchServiceBinaries,
464 awsOnDemandDemoEnabled : awsOnDemandDemo,
465 equinixOnDemandDemoEnabled : equinixOnDemandDemo,
466 equinixMetalV2OnDemandDemoEnabled : equinixMetalV2OnDemandDemo,
467 equinixMetalV2ChildDiffMetroEnabled : equinixMetalV2ChildDiffMetro,
468 equinixOnAwsDemoEnabled : equinixOnAwsDemo,
469 azureOnDemandDemoEnabled : azureOnDemandDemo,
470 azureOnAwsDemoEnabled : azureOnAwsDemo,
471 vsphereDemoEnabled : enableVsphereDemo,
472 vsphereOnDemandDemoEnabled : enableVsphereDemo, // TODO: remove after MCC 2.7 is out
473 bmDemoEnabled : enableBMDemo,
474 osDemoEnabled : enableOSDemo,
Alexandr Lovtsov36473f32022-04-28 15:46:09 +0300475 vsphereUbuntuEnabled : enableVsphereUbuntu,
Mikhail Ivanovbd1a9fd2022-03-29 21:36:21 +0400476 artifactsBuildEnabled : enableArtifactsBuild,
Sergey Zhemerdeeve67fb262022-06-21 00:49:34 +0300477 childOsBootFromVolume : childOsBootFromVolume,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100478 multiregionalConfiguration : multiregionalMappings,
Ivan Berezovskiy29e72b72022-07-12 21:03:24 +0400479 demoWeight : demoWeight,
Sergey Zhemerdeevdd31ce92022-07-19 14:15:22 +0300480 bootstrapV2Scenario : bootstrapV2Scenario,
481 equinixMetalV2Metro : equinixMetalV2Metro]
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200482}
483
484/**
485 * Determine management and regional setup for demo workflow scenario
486 *
487 *
Sergey Zhemerdeevdd31ce92022-07-19 14:15:22 +0300488 * @param: keyword (string) string , represents keyword trigger, specified in gerrit commit body, like `[multiregion aws,os]`
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200489 or Jenkins environment string variable in form like 'aws,os'
490 * @return (map)[
491 enabled: (bool),
492 * managementLocation: (string), //aws,os
493 * regionLocation: (string), //aws,os
494 * ]
495 */
496def multiregionWorkflowParser(keyword) {
Владислав Наумов8c0c39d2020-09-11 14:46:48 +0200497 def common = new com.mirantis.mk.Common()
eromanova8c702ae2021-12-24 17:43:12 +0400498 def supportedManagementProviders = ['os', 'aws', 'vsphere', 'equinix', 'equinixmetalv2', 'azure']
499 def supportedRegionalProviders = ['os', 'vsphere', 'equinix', 'equinixmetalv2', 'bm', 'azure', 'aws']
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200500
501 def clusterTypes = ''
Владислав Наумов38ed7bf2020-09-11 14:43:39 +0200502 if (keyword.toString().contains('multiregion')) {
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200503 common.infoMsg('Multiregion definition configured via gerrit keyword trigger')
504 clusterTypes = keyword[0][0].split('multiregion')[1].replaceAll('[\\[\\]]', '').trim().split(',')
505 } else {
506 common.infoMsg('Multiregion definition configured via environment variable')
507 clusterTypes = keyword.trim().split(',')
508 }
509
510 if (clusterTypes.size() != 2) {
Владислав Наумов482fb502020-10-30 17:59:27 +0100511 error("Incorrect regions definiton, valid scheme: [multiregion ${management}, ${region}], got: ${clusterTypes}")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200512 }
513
Владислав Наумовf793fe32020-09-11 15:19:19 +0200514 def desiredManagementProvider = clusterTypes[0].trim()
515 def desiredRegionalProvider = clusterTypes[1].trim()
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200516 if (! supportedManagementProviders.contains(desiredManagementProvider) || ! supportedRegionalProviders.contains(desiredRegionalProvider)) {
517 error("""unsupported management <-> regional bundle, available options:
Владислав Наумовf793fe32020-09-11 15:19:19 +0200518 management providers list - ${supportedManagementProviders}
519 regional providers list - ${supportedRegionalProviders}""")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200520 }
521
522 return [
523 enabled: true,
524 managementLocation: desiredManagementProvider,
525 regionLocation: desiredRegionalProvider,
526 ]
vnaumov33747e12020-05-04 17:35:20 +0200527}
528
529/**
530 * Determine if custom si tests/pipelines refspec forwarded from gerrit change request
531
Владислав Наумов81777472021-03-09 15:14:27 +0400532 * 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 +0200533 * Used for components team to test component changes w/ custom SI refspecs using kaas/core deployment jobs
534 * Example scheme:
535 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
536 * manage refspecs through Jenkins Job Parameters
537 *
azvyagintseva12230a2020-06-05 13:24:06 +0300538 * @return (map)[* siTests: (string) final refspec for si-tests
vnaumov33747e12020-05-04 17:35:20 +0200539 * siPipelines: (string) final refspec for si-pipelines
540 * ]
541 */
542def checkCustomSIRefspec() {
vnaumovbdb90222020-05-04 18:25:50 +0200543 def common = new com.mirantis.mk.Common()
544
vnaumov33747e12020-05-04 17:35:20 +0200545 // Available triggers and its sane defaults
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200546 def siTestsRefspec = env.SI_TESTS_REFSPEC ?: 'master'
547 def siPipelinesRefspec = env.SI_PIPELINES_REFSPEC ?: 'master'
Владислав Наумов2db15e22020-07-14 12:29:22 +0200548 def siTestsDockerImage = env.SI_TESTS_DOCKER_IMAGE ?: 'docker-dev-kaas-local.docker.mirantis.net/mirantis/kaas/si-test'
549 def siTestsDockerImageTag = env.SI_TESTS_DOCKER_IMAGE_TAG ?: 'master'
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200550 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
vnaumov33747e12020-05-04 17:35:20 +0200551
552 def siTestMatches = (commitMsg =~ /(\[si-tests-ref\s*refs\/changes\/.*?\])/)
553 def siPipelinesMatches = (commitMsg =~ /(\[si-pipelines-ref\s*refs\/changes\/.*?\])/)
554
555 if (siTestMatches.size() > 0) {
556 siTestsRefspec = siTestMatches[0][0].split('si-tests-ref')[1].replaceAll('[\\[\\]]', '').trim()
Владислав Наумов7f6c0882021-03-23 19:10:57 +0400557 siTestsDockerImage = "docker-review-local.docker.mirantis.net/review/kaas-si-test-${siTestsRefspec.split('/')[-2]}"
Владислав Наумов2db15e22020-07-14 12:29:22 +0200558 siTestsDockerImageTag = siTestsRefspec.split('/')[-1]
vnaumov33747e12020-05-04 17:35:20 +0200559 }
560 if (siPipelinesMatches.size() > 0) {
561 siPipelinesRefspec = siPipelinesMatches[0][0].split('si-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
562 }
563
564 common.infoMsg("""
565 kaas/si-pipelines will be fetched from: ${siPipelinesRefspec}
566 kaas/si-tests will be fetched from: ${siTestsRefspec}
Владислав Наумов2db15e22020-07-14 12:29:22 +0200567 kaas/si-tests as dockerImage will be fetched from: ${siTestsDockerImage}:${siTestsDockerImageTag}
Владислав Наумов81777472021-03-09 15:14:27 +0400568 Keywords: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
Владислав Наумов2db15e22020-07-14 12:29:22 +0200569 return [siTests: siTestsRefspec, siPipelines: siPipelinesRefspec, siTestsDockerImage: siTestsDockerImage, siTestsDockerImageTag: siTestsDockerImageTag]
vnaumov33747e12020-05-04 17:35:20 +0200570}
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200571
Владислав Наумов9080f372020-06-08 13:57:16 +0200572/**
Владислав Наумов418042b2020-07-09 18:31:10 +0200573 * Parse additional configuration for kaas component CICD repo
Владислав Наумов30a516c2020-07-09 13:15:41 +0200574 * @param configurationFile (str) path to configuration file in yaml format
575 *
576 * @return (map)[ siTestsFeatureFlags (string) dedicated feature flags that will be used in SI tests,
Alexandr Lovtsov1c78e452022-08-29 20:57:51 +0300577 * siTestsFeatureFlagsStable (string) dedicated feature flags that will be used in SI tests for deploying stable release
Владислав Наумов30a516c2020-07-09 13:15:41 +0200578 * ]
579 */
580def parseKaaSComponentCIParameters(configurationFile){
581 def common = new com.mirantis.mk.Common()
582 def ciConfig = readYaml file: configurationFile
583 def ciSpec = [
584 siTestsFeatureFlags: env.SI_TESTS_FEATURE_FLAGS ?: '',
Alexandr Lovtsov1c78e452022-08-29 20:57:51 +0300585 siTestsFeatureFlagsStable: env.SI_TESTS_FEATURE_FLAGS_STABLE ?: '',
Владислав Наумов30a516c2020-07-09 13:15:41 +0200586 ]
587
Alexandr Lovtsov1c78e452022-08-29 20:57:51 +0300588 // If exists and not empty
589 if (ciConfig.getOrDefault('si-tests-feature-flags', [])) {
Владислав Наумов30a516c2020-07-09 13:15:41 +0200590 common.infoMsg("""SI tests feature flags customization detected,
591 results will be merged with existing flags: [${ciSpec['siTestsFeatureFlags']}] identification...""")
592
593 def ffMeta = ciSpec['siTestsFeatureFlags'].tokenize(',').collect { it.trim() }
594 ffMeta.addAll(ciConfig['si-tests-feature-flags'])
Владислав Наумов30a516c2020-07-09 13:15:41 +0200595
Владислав Наумовcb5ffca2020-07-14 15:28:36 +0200596 ciSpec['siTestsFeatureFlags'] = ffMeta.unique().join(',')
Владислав Наумов30a516c2020-07-09 13:15:41 +0200597 common.infoMsg("SI tests custom feature flags: ${ciSpec['siTestsFeatureFlags']}")
598 }
Alexandr Lovtsov1c78e452022-08-29 20:57:51 +0300599 if (ciConfig.getOrDefault('si-tests-feature-flags-stable', [])) {
600 common.infoMsg("""SI tests feature flags for stable release customization detected,
601 results will be merged with existing flags: [${ciSpec['siTestsFeatureFlagsStable']}] identification...""")
602
603 def ffMeta = ciSpec['siTestsFeatureFlagsStable'].tokenize(',').collect { it.trim() }
604 ffMeta.addAll(ciConfig['si-tests-feature-flags-stable'])
605
606 ciSpec['siTestsFeatureFlagsStable'] = ffMeta.unique().join(',')
607 common.infoMsg("SI tests custom feature flags for stable release: ${ciSpec['siTestsFeatureFlagsStable']}")
608 }
Владислав Наумов30a516c2020-07-09 13:15:41 +0200609
610 common.infoMsg("""Additional ci configuration parsed successfully:
Alexandr Lovtsov1c78e452022-08-29 20:57:51 +0300611 siTestsFeatureFlags: ${ciSpec['siTestsFeatureFlags']}
612 siTestsFeatureFlagsStable: ${ciSpec['siTestsFeatureFlagsStable']}""")
Владислав Наумов30a516c2020-07-09 13:15:41 +0200613 return ciSpec
614}
615
616/**
617 * Determine if custom kaas core/pipelines refspec forwarded from gerrit change request
Владислав Наумов9080f372020-06-08 13:57:16 +0200618
Владислав Наумов81777472021-03-09 15:14:27 +0400619 * 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 +0200620 * Used for components team to test component changes w/ custom Core refspecs using kaas/core deployment jobs
621 * Example scheme:
622 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
623 * manage refspecs through Jenkins Job Parameters
624 *
625 * @return (map)[ core: (string) final refspec for kaas/core
626 * corePipelines: (string) final refspec for pipelines in kaas/core
627 * ]
628 */
629def checkCustomCoreRefspec() {
630 def common = new com.mirantis.mk.Common()
631
632 // Available triggers and its sane defaults
633 def coreRefspec = env.KAAS_CORE_REFSPEC ?: 'master'
634 // by default using value of GERRIT_REFSPEC parameter in *kaas/core jobs*
635 def corePipelinesRefspec = env.KAAS_PIPELINE_REFSPEC ?: '\$GERRIT_REFSPEC'
636 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
637
638 def coreMatches = (commitMsg =~ /(\[core-ref\s*refs\/changes\/.*?\])/)
639 def corePipelinesMatches = (commitMsg =~ /(\[core-pipelines-ref\s*refs\/changes\/.*?\])/)
640
641 if (coreMatches.size() > 0) {
642 coreRefspec = coreMatches[0][0].split('core-ref')[1].replaceAll('[\\[\\]]', '').trim()
643 }
644 if (corePipelinesMatches.size() > 0) {
645 corePipelinesRefspec = corePipelinesMatches[0][0].split('core-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
646 }
647
648 common.infoMsg("""
649 kaas/core will be fetched from: ${coreRefspec}
650 kaas/core pipelines will be fetched from: ${corePipelinesRefspec}
Владислав Наумов81777472021-03-09 15:14:27 +0400651 Keywords: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
Владислав Наумов9080f372020-06-08 13:57:16 +0200652 return [core: coreRefspec, corePipelines: corePipelinesRefspec]
653}
654
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200655
656/**
Владислав Наумов92288d92020-07-13 18:36:21 +0200657 * generate Jenkins Parameter objects from from text parameter with additonal kaas core context
658 * needed to forward inside kaas core set of jobs
659 *
660 * @param context (string) Representation of the string enviroment variables needed for kaas core jobs in yaml format
661 * @return (list)[ string(name: '', value: ''),
662 * ]
663 */
664def generateKaaSVarsFromContext(context) {
665 def common = new com.mirantis.mk.Common()
666 def parameters = []
667 def config = readYaml text: context
668
669 config.each { k,v ->
670 common.infoMsg("Custom KaaS Core context parameter: ${k}=${v}")
671 parameters.add(string(name: k, value: v))
672 }
673
674 return parameters
675}
676
677/**
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200678 * 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 +0400679 * 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 +0200680 * Used for components team to test component changes w/ customized SI tests/refspecs using kaas/core deployment jobs
681 *
Владислав Наумов418042b2020-07-09 18:31:10 +0200682 * @param: component (string) component name [iam, lcm, stacklight]
683 * @param: patchSpec (string) Patch for kaas/cluster releases in json format
684 * @param: configurationFile (string) Additional file for component repo CI config in yaml format
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200685 */
Владислав Наумов92288d92020-07-13 18:36:21 +0200686def triggerPatchedComponentDemo(component, patchSpec = '', configurationFile = '.ci-parameters.yaml', coreContext = '') {
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200687 def common = new com.mirantis.mk.Common()
688 // Determine if custom trigger keywords forwarded from gerrit
689 def triggers = checkDeploymentTestSuite()
690 // Determine SI refspecs
691 def siRefspec = checkCustomSIRefspec()
Владислав Наумов9080f372020-06-08 13:57:16 +0200692 // Determine Core refspecs
693 def coreRefspec = checkCustomCoreRefspec()
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200694
Владислав Наумов418042b2020-07-09 18:31:10 +0200695 // Determine component repo ci configuration
696 def ciSpec = [:]
697 def componentFeatureFlags = env.SI_TESTS_FEATURE_FLAGS ?: ''
698 if (fileExists(configurationFile)) {
699 common.infoMsg('Component CI configuration file detected, parsing...')
700 ciSpec = parseKaaSComponentCIParameters(configurationFile)
701 componentFeatureFlags = ciSpec['siTestsFeatureFlags']
702 } else {
703 common.warningMsg('''Component CI configuration file is not exists,
Владислав Наумовc17dd552020-07-29 17:07:38 +0200704 several code-management features may be unavailable,
Владислав Наумов92288d92020-07-13 18:36:21 +0200705 follow https://mirantis.jira.com/wiki/spaces/QA/pages/2310832276/SI-tests+feature+flags#%5BUpdated%5D-Using-a-feature-flag
706 to create the configuration file''')
Владислав Наумов418042b2020-07-09 18:31:10 +0200707 }
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400708
709 def platforms = []
710 if (component == 'ipam' && triggers.vsphereDemoEnabled) {
711 // Currently only vsphere demo is required for IPAM component
712 platforms.add('vsphere')
713 } else {
714 if (triggers.osDemoEnabled) {
715 platforms.add('openstack')
716 }
717 if (triggers.awsOnDemandDemoEnabled) {
718 platforms.add('aws')
719 }
720 if (triggers.equinixOnDemandDemoEnabled) {
721 platforms.add('equinix')
722 }
Владислав Наумов144956f2021-10-14 17:49:19 +0200723 if (triggers.equinixMetalV2OnDemandDemoEnabled) {
724 platforms.add('equinixmetalv2')
725 }
Владислав Наумовc52dd9d2021-06-28 16:27:29 +0200726 if (triggers.azureOnDemandDemoEnabled) {
727 platforms.add('azure')
728 }
Ivan Berezovskiyb0229d02021-05-17 16:55:18 +0400729 if (triggers.vsphereDemoEnabled) {
730 platforms.add('vsphere')
731 }
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400732 }
733
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200734 def jobs = [:]
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200735 def parameters = [
Владислав Наумов9080f372020-06-08 13:57:16 +0200736 string(name: 'GERRIT_REFSPEC', value: coreRefspec.core),
737 string(name: 'KAAS_PIPELINE_REFSPEC', value: coreRefspec.corePipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200738 string(name: 'SI_TESTS_REFSPEC', value: siRefspec.siTests),
Владислав Наумов418042b2020-07-09 18:31:10 +0200739 string(name: 'SI_TESTS_FEATURE_FLAGS', value: componentFeatureFlags),
Владислав Наумов2db15e22020-07-14 12:29:22 +0200740 string(name: 'SI_TESTS_DOCKER_IMAGE', value: siRefspec.siTestsDockerImage),
741 string(name: 'SI_TESTS_DOCKER_IMAGE_TAG', value: siRefspec.siTestsDockerImageTag),
Владислав Наумов4a5c3242020-06-08 14:36:11 +0200742 string(name: 'SI_PIPELINES_REFSPEC', value: siRefspec.siPipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200743 string(name: 'CUSTOM_RELEASE_PATCH_SPEC', value: patchSpec),
Mikhail Ivanov74504372021-05-21 17:01:06 +0400744 string(name: 'KAAS_CHILD_CLUSTER_RELEASE_NAME', value: triggers.childDeployCustomRelease),
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400745 string(name: 'OPENSTACK_CLOUD_LOCATION', value: triggers.osCloudLocation),
Владислав Наумовb8305e22021-02-10 17:23:12 +0100746 booleanParam(name: 'OFFLINE_MGMT_CLUSTER', value: triggers.proxyConfig['mgmtOffline']),
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200747 booleanParam(name: 'OFFLINE_CHILD_CLUSTER', value: triggers.proxyConfig['childOffline']),
Владислав Наумов257ea132021-04-14 14:44:13 +0200748 booleanParam(name: 'PROXY_CHILD_CLUSTER', value: triggers.proxyConfig['childProxy']),
Владислав Наумов44c64b72020-12-04 20:22:53 +0100749 booleanParam(name: 'SEED_MACOS', value: triggers.useMacOsSeedNode),
Владислав Наумов080d9412020-07-29 13:05:14 +0200750 booleanParam(name: 'UPGRADE_MGMT_CLUSTER', value: triggers.upgradeMgmtEnabled),
slalov1202bba2022-04-20 22:31:07 +0400751 booleanParam(name: 'AUTO_UPGRADE_MCC', value: triggers.autoUpgradeMgmtEnabled),
Victor Ryzhenkind2b7b662021-08-23 14:18:38 +0400752 booleanParam(name: 'ENABLE_LMA_LOGGING', value: triggers.enableLMALoggingEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200753 booleanParam(name: 'RUN_UI_E2E', value: triggers.runUie2eEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200754 booleanParam(name: 'RUN_MGMT_CFM', value: triggers.runMgmtConformanceEnabled),
slalov0a4947a2022-06-09 15:44:35 +0400755 booleanParam(name: 'RUN_MAINTENANCE_TEST', value: triggers.runMaintenanceTestEnabled),
756 booleanParam(name: 'RUN_CONTAINER_REGISTRY_TEST', value: triggers.runContainerregistryTestEnabled),
Dmitriy Kasyanov5f910e62022-02-11 14:57:05 +0300757 booleanParam(name: 'RUN_MGMT_DELETE_MASTER_TEST', value: triggers.runMgmtDeleteMasterTestEnabled),
758 booleanParam(name: 'RUN_RGNL_DELETE_MASTER_TEST', value: triggers.runRgnlDeleteMasterTestEnabled),
759 booleanParam(name: 'RUN_CHILD_DELETE_MASTER_TEST', value: triggers.runChildDeleteMasterTestEnabled),
Владислав Наумов9cec55d2021-08-03 15:00:59 +0200760 booleanParam(name: 'RUN_LMA_TEST', value: triggers.runLMATestEnabled),
Vladyslav Drokc4f9c1b2021-07-22 15:34:24 +0200761 booleanParam(name: 'RUN_MGMT_USER_CONTROLLER_TEST', value: triggers.runMgmtUserControllerTestEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200762 booleanParam(name: 'DEPLOY_CHILD_CLUSTER', value: triggers.deployChildEnabled),
763 booleanParam(name: 'UPGRADE_CHILD_CLUSTER', value: triggers.upgradeChildEnabled),
slalov574123e2022-04-06 17:24:19 +0400764 booleanParam(name: 'RUN_PROXY_CHILD_TEST', value: triggers.runProxyChildTestEnabled),
Владислав Наумов0dc99252020-11-13 13:30:48 +0100765 booleanParam(name: 'ATTACH_BYO', value: triggers.attachBYOEnabled),
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100766 booleanParam(name: 'UPGRADE_BYO', value: triggers.upgradeBYOEnabled),
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100767 booleanParam(name: 'RUN_BYO_MATRIX', value: triggers.runBYOMatrixEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200768 booleanParam(name: 'RUN_CHILD_CFM', value: triggers.runChildConformanceEnabled),
Ivan Berezovskiycbf9eeb2021-03-22 15:57:32 +0400769 booleanParam(name: 'ALLOW_AWS_ON_DEMAND', value: triggers.awsOnDemandDemoEnabled),
Владислав Наумовe021b022021-05-06 11:26:38 +0200770 booleanParam(name: 'ALLOW_EQUINIX_ON_DEMAND', value: triggers.equinixOnDemandDemoEnabled),
Владислав Наумов82305e92021-10-14 20:45:20 +0200771 booleanParam(name: 'ALLOW_EQUINIXMETALV2_ON_DEMAND', value: triggers.equinixMetalV2OnDemandDemoEnabled),
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100772 booleanParam(name: 'EQUINIXMETALV2_CHILD_DIFF_METRO', value: triggers.equinixMetalV2ChildDiffMetroEnabled),
eromanovad3397512021-04-01 20:19:19 +0400773 booleanParam(name: 'EQUINIX_ON_AWS_DEMO', value: triggers.equinixOnAwsDemoEnabled),
Владислав Наумовc52dd9d2021-06-28 16:27:29 +0200774 booleanParam(name: 'ALLOW_AZURE_ON_DEMAND', value: triggers.azureOnDemandDemoEnabled),
Владислав Наумов2d3db332021-06-15 15:19:19 +0200775 booleanParam(name: 'AZURE_ON_AWS_DEMO', value: triggers.azureOnAwsDemoEnabled),
Sergey Zhemerdeev9074f6e2022-06-07 12:03:16 +0300776 booleanParam(name: 'VSPHERE_DEPLOY_UBUNTU', value: triggers.vsphereUbuntuEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200777 ]
Владислав Наумов92288d92020-07-13 18:36:21 +0200778
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200779 // customize multiregional demo
780 if (triggers.multiregionalConfiguration.enabled) {
781 parameters.add(string(name: 'MULTIREGION_SETUP',
782 value: "${triggers.multiregionalConfiguration.managementLocation},${triggers.multiregionalConfiguration.regionLocation}"
783 ))
784 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200785
Владислав Наумов92288d92020-07-13 18:36:21 +0200786 // Determine component team custom context
787 if (coreContext != '') {
788 common.infoMsg('Additional KaaS Core context detected, will be forwarded into kaas core cicd...')
789 def additionalParameters = generateKaaSVarsFromContext(coreContext)
Владислав Наумовbef51a92020-10-01 17:36:51 +0200790 parameters.addAll(additionalParameters)
Владислав Наумов92288d92020-07-13 18:36:21 +0200791 }
792
Владислав Наумовaa430612020-06-08 17:18:31 +0200793 def jobResults = []
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400794
795 platforms.each { platform ->
796 jobs["kaas-core-${platform}-patched-${component}"] = {
Vladislav Naumov5313a202021-04-07 17:13:39 +0000797 try {
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400798 common.infoMsg("Deploy: patched KaaS demo with ${platform} provider")
799 def job_info = build job: "kaas-testing-core-${platform}-workflow-${component}", parameters: parameters, wait: true
800 def build_description = job_info.getDescription()
801 def build_result = job_info.getResult()
Vladislav Naumov5313a202021-04-07 17:13:39 +0000802 jobResults.add(build_result)
Владислав Наумовd044e842020-06-17 15:33:43 +0200803
Vladislav Naumov5313a202021-04-07 17:13:39 +0000804 if (build_description) {
805 currentBuild.description += build_description
806 }
807 } finally {
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400808 common.infoMsg("Patched KaaS demo with ${platform} provider finished")
Vladislav Naumov5313a202021-04-07 17:13:39 +0000809 }
810 }
811 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200812
813 common.infoMsg('Trigger KaaS demo deployments according to defined provider set')
Владислав Наумов37f7f842021-03-09 16:08:39 +0400814 if (jobs.size() == 0) {
815 error('No demo jobs matched with keywords, execution will be aborted, at least 1 provider should be enabled')
816 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200817 // Limit build concurency workaround examples: https://issues.jenkins-ci.org/browse/JENKINS-44085
818 parallel jobs
Владислав Наумовaa430612020-06-08 17:18:31 +0200819
820 if (jobResults.contains('FAILURE')) {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200821 common.infoMsg('One of parallel downstream jobs is failed, mark executor job as failed')
Владислав Наумовaa430612020-06-08 17:18:31 +0200822 currentBuild.result = 'FAILURE'
823 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200824}
Владислав Наумов30a516c2020-07-09 13:15:41 +0200825
826
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400827/**
828 * Function currently supported to be called from aws or vsphere demos. It gets particular demo context
Владислав Наумов33e1e812021-08-17 17:09:25 +0200829 * and generate proper lockResources data and netMap data for vsphere,equinix related clusters.
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400830 *
831 * @param: callBackDemo (string) Demo which requested to generate lockResources [aws or vsphere]
832 * @param: triggers (map) Custom trigger keywords forwarded from gerrit
833 * @param: multiregionalConfiguration (map) Multiregional configuration
834 * @return (map) Return aggregated map with lockResources and netMap
835 */
836
837
838def generateLockResources(callBackDemo, triggers) {
839 def common = new com.mirantis.mk.Common()
Владислав Наумов33e1e812021-08-17 17:09:25 +0200840 def netMap = [
841 vsphere: [:],
842 equinix: [:],
843 ]
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400844 // Define vsphere locklabels with initial quantity
845 def lockLabels = [
846 vsphere_networking_core_ci: 0,
847 vsphere_offline_networking_core_ci: 0,
848 ]
849 def deployChild = triggers.deployChildEnabled
slalov27833272022-06-30 02:13:50 +0400850 def testUiVsphere = triggers.runUie2eEnabled
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400851 def multiregionConfig = triggers.multiregionalConfiguration
852 def runMultiregion = multiregionConfig.enabled
853
854 // Generate vsphere netMap and lockLabels based on demo context
855 switch (callBackDemo) {
856 case 'aws':
857 // Add aws specific lock label with quantity calculated based on single mgmt deploy or mgmt + child
858 lockLabels['aws_core_ci_queue'] = triggers.demoWeight
Sergey Kolekonovf4c1f492022-02-03 14:44:45 +0400859 if (triggers.runBYOMatrixEnabled) { lockLabels['aws_core_ci_queue'] += 6 }
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400860
861 // Define netMap for Vsphere region
Mikhail Ivanov90a27fa2022-05-30 15:18:24 +0400862 if (runMultiregion && multiregionConfig.managementLocation == 'aws') {
863 if (multiregionConfig.regionLocation == 'vsphere') {
864 if (deployChild) {
865 addToProviderNetMap(netMap, 'vsphere', 'regional-child')
866 }
867 addToProviderNetMap(netMap, 'vsphere', 'region')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400868 }
Mikhail Ivanov90a27fa2022-05-30 15:18:24 +0400869
870 if (multiregionConfig.regionLocation == 'azure') {
871 lockLabels['azure_core_ci_queue'] = 1
872 if (deployChild) {
873 lockLabels['azure_core_ci_queue'] += 1
874 }
875 }
876 }
877 if (triggers.azureOnAwsDemoEnabled) {
878 lockLabels['azure_core_ci_queue'] = 1
879 }
880
881 if (triggers.equinixOnAwsDemoEnabled) {
882 lockLabels['equinix_core_ci_queue'] = 1
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400883 }
884 break
885 case 'vsphere':
Владислав Наумов33e1e812021-08-17 17:09:25 +0200886 addToProviderNetMap(netMap, 'vsphere', 'mgmt')
slalov27833272022-06-30 02:13:50 +0400887 if (deployChild || testUiVsphere) {
Владислав Наумов33e1e812021-08-17 17:09:25 +0200888 addToProviderNetMap(netMap, 'vsphere', 'child')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400889 }
890 if (runMultiregion && multiregionConfig.managementLocation == 'vsphere' &&
891 multiregionConfig.regionLocation == 'vsphere') {
892 if (deployChild) {
Владислав Наумов33e1e812021-08-17 17:09:25 +0200893 addToProviderNetMap(netMap, 'vsphere', 'regional-child')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400894 }
Владислав Наумов33e1e812021-08-17 17:09:25 +0200895 addToProviderNetMap(netMap, 'vsphere', 'region')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400896 }
897 break
Mikhail Ivanov90a27fa2022-05-30 15:18:24 +0400898 case 'azure':
899 lockLabels['azure_core_ci_queue'] = triggers.demoWeight
900 if (runMultiregion && multiregionConfig.managementLocation == 'azure') {
901 if (multiregionConfig.regionLocation == 'aws') {
902 lockLabels['aws_core_ci_queue'] = 1
903 if (deployChild) {
904 lockLabels['aws_core_ci_queue'] += 1
905 }
906 }
907
908 if (multiregionConfig.regionLocation == 'equinix') {
909 lockLabels['equinix_core_ci_queue'] = 1
910 if (deployChild) {
911 lockLabels['equinix_core_ci_queue'] +=1
912 }
913 }
914 }
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400915 default:
Mikhail Ivanov90a27fa2022-05-30 15:18:24 +0400916 error('Supposed to be called from aws, azure or vsphere demos only')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400917 }
918
919 // Checking gerrit triggers and manage lock label quantity and network types in case of Offline deployment
920 // Vsphere labels only
Владислав Наумов33e1e812021-08-17 17:09:25 +0200921 netMap['vsphere'].each { clusterType, netConfig ->
922 if (triggers.proxyConfig["${clusterType}Offline"] == true ||
923 (clusterType == 'regional-child' && triggers.proxyConfig['childOffline'] == true) ||
924 (clusterType == 'region' && triggers.proxyConfig['mgmtOffline'])) {
925
926 netMap['vsphere'][clusterType]['netName'] = 'offline'
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400927 lockLabels['vsphere_offline_networking_core_ci']++
928 } else {
929 lockLabels['vsphere_networking_core_ci']++
930 }
931 }
932
933 // generate lock metadata
934 def lockResources = []
935 lockLabels.each { label, quantity ->
936 if (quantity > 0) {
937 def res = [
938 label: label,
939 quantity: quantity,
940 ]
941 lockResources.add(res)
942 }
943 }
944
945 common.infoMsg("""Generated vsphere netMap: ${netMap}
946 Generated lockResources: ${lockResources}""")
947
948 return [
949 netMap: netMap,
950 lockResources: lockResources,
951 ]
952}
953
954/**
955 * Function gets vsphere netMap or empty map and adds new vsphere clusterType with default netName
956 * and empty rangeConfig to the this map.
957 *
Владислав Наумов33e1e812021-08-17 17:09:25 +0200958 * @param: netMap (string) vsphere, equinix netMap or empty map
959 * @param: provider (string) provider type
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400960 * @param: clusterType (string) Vsphere cluster type
961 */
962
Владислав Наумов33e1e812021-08-17 17:09:25 +0200963def addToProviderNetMap (netMap, provider, clusterType) {
964 switch (provider) {
965 case 'equinix':
966 netMap[provider][clusterType] = [
967 vlanConfig: '',
968 ]
969 break
970 case 'vsphere':
971 netMap[provider][clusterType] = [
972 netName: 'default',
973 rangeConfig: '',
974 ]
975 break
976 default:
977 error('Net map locks supported for Equinix/Vsphere providers only')
978 }
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400979}
Dmitry Teselkinfce71aa2022-03-05 19:36:52 +0300980
981/**
982* getCIKeywordsFromCommitMsg parses commit message and returns all gerrit keywords with their values as a list of maps.
983* Each element (map) contains keys 'key' for keyword name and 'value' for its value.
984* If keyword contains only 'key' part then 'value' is boolean True.
985* This function does not perform keywords validation.
986* First line of a commit message is ignored.
987* To use '[' or ']' characters inside keyword prepend it with backslash '\'.
988* TODO: Remove backslash chars from values if they prepend '[' or ']'.
989**/
990
991List getCIKeywordsFromCommitMsg() {
992 String commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
993 List commitMsgLines = commitMsg.split('\n')
994 List keywords = []
995 if (commitMsgLines.size() < 2) {
996 return keywords
997 }
998
999 String commitMsgBody = commitMsgLines[1..-1].join('\n')
1000
1001 // Split commit message body to chunks using '[' or ']' as delimiter,
1002 // ignoring them if prepended by backslash (regex negative lookbehind).
1003 // Resulting list will have chunks between '[' and ']' at odd indexes.
1004 List parts = commitMsgBody.split(/(?<!\\)[\[\]]/)
1005
1006 // Iterate chunks by odd indexes only, trim values and split to
1007 // <key> / <value> pair where <key> is the part of a sting before the first
1008 // whitespace delimiter, and <value> is the rest (may include whitespaces).
1009 // If there is no whitespace in the string then this is a 'switch'
1010 // and <value> will be boolean True.
1011 for (i = 1; i < parts.size(); i += 2) {
1012 def (key, value) = (parts[i].trim().split(/\s+/, 2) + [true, ])[0..1]
1013 keywords.add(['key': key, 'value': value])
1014 }
1015
1016 return keywords
1017}
1018
1019/**
1020* getJobsParamsFromCommitMsg parses list of CI keywords and returns values of 'job-params' keyword
1021* that were specified for given job name. `job-params` keyword has the following structure
1022*
1023* [job-params <job name> <parameter name> <parameter value>]
1024*
1025* Return value is a Map that contains those parameters using the following structure:
1026*
1027* <job name>:
1028* <parameter name>: <parameter value>
1029*
1030**/
1031Map getJobsParamsFromCommitMsg() {
1032 List keywords = getCIKeywordsFromCommitMsg()
1033
1034 List jobsParamsList = []
1035 keywords.findAll{ it.key == 'job-params' }.collect(jobsParamsList) {
1036 def (name, params) = (it['value'].split(/\s+/, 2) + [null, ])[0..1]
1037 def (key, value) = params.split(/\s+/, 2)
1038 ['name': name, 'key': key, 'value': value]
1039 }
1040
1041 Map jobsParams = jobsParamsList.inject([:]) { result, it ->
1042 if (!result.containsKey(it.name)) {
1043 result[it.name] = [:]
1044 }
1045 result[it.name][it.key] = it.value
1046 result
1047 }
1048
1049 return jobsParams
1050}
1051
1052
1053/**
1054* getJobParamsFromCommitMsg returns key:value Map of parameters set for a job in commit message.
1055* It uses getJobsParamsFromCommitMsg to get all parameters from commit message and then
1056* uses only those parametes that were set to all jobs (with <job name> == '*') or to
1057* a particular job. Parameters set to a particular job have higher precedence.
1058*
1059* Return value is a Map that contains those parameters:
1060*
1061* <parameter name>: <parameter value>
1062*
1063**/
1064Map getJobParamsFromCommitMsg(String jobName) {
1065 jobsParams = getJobsParamsFromCommitMsg()
1066 jobParams = jobsParams.getOrDefault('*', [:])
1067 if (jobName) {
1068 jobParams.putAll(jobsParams.getOrDefault(jobName, [:]))
1069 }
1070 return jobParams
1071}
azvyagintsevc17d14b2022-06-06 19:06:33 +03001072
1073/** Getting test scheme from text, which should be
1074Imput example:
1075text="""
1076 DATA
1077
1078 kaas_bm_test_schemas:
1079 KAAS_RELEASES_REFSPEC: ''
1080 KEY: VAL
1081
1082 DATA
1083 """
1084
1085 Call: parseTextForTestSchemas(['text' : text,'keyLine' : 'kaas_bm_test_schemas'])
1086
1087 Return:
1088 ['KAAS_RELEASES_REFSPEC': '', 'KEY' : 'VAL']
1089 **/
1090def parseTextForTestSchemas(Map opts) {
azvyagintsevd96aac22022-06-10 14:23:26 +03001091 String text = opts.getOrDefault('text', '')
azvyagintsevc17d14b2022-06-06 19:06:33 +03001092 String keyLine = opts.getOrDefault('keyLine', '')
1093 Map testScheme = [:]
1094 if (!text || !keyLine) {
azvyagintsevd96aac22022-06-10 14:23:26 +03001095 return testScheme
azvyagintsevc17d14b2022-06-06 19:06:33 +03001096 }
1097 if (text =~ /\n$keyLine\n.*/) {
1098 def common = new com.mirantis.mk.Common()
1099 try {
1100 String regExp = '\\n' + keyLine + '\\n'
1101 // regexep block must be followed by empty line
1102 testScheme = readYaml text: "${text.split(regExp)[1].split('\n\n')[0]}"
1103 common.infoMsg("parseTextForTestSchemas result:\n" + testScheme)
1104 common.mergeEnv(env, toJson(testScheme))
1105 }
1106 catch (Exception e) {
1107 common.errorMsg("There is an error occured during parseTextForTestSchemas execution:\n${e}")
1108 throw e
1109 }
1110 }
azvyagintsevd96aac22022-06-10 14:23:26 +03001111 return testScheme
Dmitriy Kasyanov5f910e62022-02-11 14:57:05 +03001112}
Sergey Zhemerdeev31569082022-08-10 10:13:19 +03001113
1114
1115/**
1116* getEquinixMetrosWithCapacity returns list of Equinix metros using specified
1117* instance type (nodeType) and desired count of instances (nodeCount) in a metro.
1118* Function downloads metal CLI from the
1119* https://github.com/equinix/metal-cli/releases/download/v0.9.0/metal-linux-amd64
1120* Empty list is returned in case of errors.
1121*
1122* @param: nodeCount (int) Desired count of instances
1123* @param: nodeType (string) Instance type
1124* @return ([]string) List of selected metros
1125*
1126**/
Sergey Zhemerdeevbcccb912022-08-25 14:26:52 +03001127def getEquinixMetrosWithCapacity(nodeCount = 50, nodeType = 'c3.small.x86', version = '0.9.0') {
Sergey Zhemerdeev31569082022-08-10 10:13:19 +03001128 def common = new com.mirantis.mk.Common()
1129 def metalUrl = "https://artifactory.mcp.mirantis.net:443/artifactory/binary-dev-kaas-local/core/bin/mirror/metal-${version}-linux"
1130 def metros = []
1131 def out = ''
Sergey Zhemerdeevbcccb912022-08-25 14:26:52 +03001132 def retries = 3 // number of retries
Sergey Zhemerdeev495ba582022-08-16 16:31:43 +03001133 def i = 0
1134 def delay = 60 // 1 minute sleep
Sergey Zhemerdeevbcccb912022-08-25 14:26:52 +03001135 def metal = './metal --config metal.yaml'
Sergey Zhemerdeev31569082022-08-10 10:13:19 +03001136 try {
1137 sh "curl -o metal -# ${metalUrl} && chmod +x metal"
1138 withCredentials([string(credentialsId: env.KAAS_EQUINIX_API_TOKEN, variable: 'KAAS_EQUINIX_API_TOKEN')]) {
1139 sh 'echo "project-id: ${KAAS_EQUINIX_PROJECT_ID}\ntoken: ${KAAS_EQUINIX_API_TOKEN}" >metal.yaml'
Sergey Zhemerdeev31569082022-08-10 10:13:19 +03001140 }
Sergey Zhemerdeev495ba582022-08-16 16:31:43 +03001141 while (metros.size() == 0 && i < retries) {
Sergey Zhemerdeevbcccb912022-08-25 14:26:52 +03001142 common.infoMsg("Selecting available Equinix metro with free ${nodeCount} ${nodeType} hosts, try ${i+1}/${retries} ...")
Sergey Zhemerdeev495ba582022-08-16 16:31:43 +03001143 if (i > 0 ) { // skip sleep on first step
1144 sleep(delay)
1145 }
Sergey Zhemerdeevbcccb912022-08-25 14:26:52 +03001146 out = sh(script: "${metal} capacity get -m -P ${nodeType}|awk '/${nodeType}/ {print \$2}'|paste -s -d,|xargs ${metal} capacity check -P ${nodeType} -q ${nodeCount} -m|grep true|awk '{print \$2}'|paste -s -d,", returnStdout: true).trim()
Sergey Zhemerdeev495ba582022-08-16 16:31:43 +03001147 metros = out.tokenize(',')
Sergey Zhemerdeevbcccb912022-08-25 14:26:52 +03001148 if (metros.size() == 0) {
1149 nodeCount -= 10
1150 }
Sergey Zhemerdeev495ba582022-08-16 16:31:43 +03001151 i++
1152 }
Sergey Zhemerdeevbcccb912022-08-25 14:26:52 +03001153 if (metros.size() > 0) {
1154 m = metros.size() > 1 ? "${metros[0]},${metros[1]}" : "${metros[0]}"
1155 sh "${metal} capacity check -P ${nodeType} -m ${m} -q ${nodeCount}"
1156 }
Sergey Zhemerdeev31569082022-08-10 10:13:19 +03001157 } catch (Exception e) {
1158 common.errorMsg "Exception: '${e}'"
1159 return []
Sergey Zhemerdeev495ba582022-08-16 16:31:43 +03001160 } finally {
1161 sh 'rm metal.yaml'
1162 }
1163 if (metros.size() > 0) {
1164 common.infoMsg("Selected metros: ${metros}")
1165 } else {
1166 common.warningMsg('No any metros have been selected !!! :(')
Sergey Zhemerdeev31569082022-08-10 10:13:19 +03001167 }
1168 return metros
1169}
Sergey Zhemerdeev2a273342022-08-18 12:06:11 +03001170
1171
1172/**
1173 * genCommandLine prepares command line for artifactory-replication
1174 * command using legacy environment variables
1175 *
1176 * @return: (string) Prepared command line
1177 */
1178def genCommandLine() {
1179 def envToParam = [
1180 'DESTINATION_USER': '-dst-user',
1181 'ARTIFACT_FILTER': '-artifact-filter',
1182 'ARTIFACT_FILTER_PROD': '-artifact-filter-prod',
1183 'ARTIFACT_TYPE': '-artifact-type',
1184 'BINARY_CLEAN': '-bin-cleanup',
1185 'BINARY_CLEAN_KEEP_DAYS': '-bin-clean-keep-days',
1186 'BINARY_CLEAN_PREFIX': '-bin-clean-prefix',
1187 'BUILD_URL': '-slack-build-url',
1188 'CHECK_REPOS': '-check-repos',
1189 'DESTINATION_REGISTRY': '-dst-repo',
1190 'DESTINATION_REGISTRY_TYPE': '-dst-repo-type',
1191 'DOCKER_CLEAN': '-cleanup',
1192 'DOCKER_REPO_PREFIX': '-docker-repo-prefix',
1193 'DOCKER_TAG': '-docker-tag',
1194 'FORCE': '-force',
1195 'HELM_CDN_DOMAIN': '-helm-cdn-domain',
1196 'SLACK_CHANNEL': '-slack-channel',
1197 'SLACK_USER': '-slack-user',
1198 'SOURCE_REGISTRY': '-src-repo',
1199 'SOURCE_REGISTRY_TYPE': '-src-repo-type',
1200 'SYNC_PATTERN': '-sync-pattern'
1201 ]
1202 def cmdParams = ''
Sergey Zhemerdeev88d1c3d2022-08-31 16:37:48 +03001203 def isCheckClean = false
Sergey Zhemerdeev2a273342022-08-18 12:06:11 +03001204 for (e in envToParam) {
1205 if (env[e.key] == null) {
1206 continue
1207 }
1208 if (e.key == 'CHECK_REPOS' || e.key == 'DOCKER_CLEAN') {
Sergey Zhemerdeev88d1c3d2022-08-31 16:37:48 +03001209 // Avoid CHECK_REPOS=true and DOCKER_CLEAN=true
1210 if (env[e.key].toBoolean() && !isCheckClean) {
Sergey Zhemerdeev2a273342022-08-18 12:06:11 +03001211 cmdParams += e.value + ' '
Sergey Zhemerdeev88d1c3d2022-08-31 16:37:48 +03001212 isCheckClean = true
Sergey Zhemerdeev2a273342022-08-18 12:06:11 +03001213 }
1214 } else if (e.key == 'FORCE') {
1215 if (env[e.key].toBoolean()) {
1216 cmdParams += e.value + ' '
1217 }
1218 } else {
Sergey Zhemerdeeve2926cd2022-08-29 15:28:47 +03001219 cmdParams += "${e.value} '${env[e.key]}' "
Sergey Zhemerdeev2a273342022-08-18 12:06:11 +03001220 }
1221 }
Sergey Zhemerdeev88d1c3d2022-08-31 16:37:48 +03001222 // No any check or clean was specified - take a default action
1223 if (!isCheckClean) {
1224 cmdParams += '-replicate'
1225 }
Sergey Zhemerdeev2a273342022-08-18 12:06:11 +03001226 return cmdParams
1227}
Sergey Kolekonov0e60a942022-09-05 13:02:22 +04001228
1229/**
1230 * custom scheduling algorithm
1231 * it ensures that builds of the same job are distributed as much as possible between different nodes
1232 * @param label (string) desired node label
1233 * @return: (string) node name
1234 */
1235def schedule (label='docker') {
1236 def common = new com.mirantis.mk.Common()
1237 def freeNodes = []
1238 def nodesMap = [:]
1239
1240 // filter nodes with the specified label and at least one free executor
1241 timeout(time: 30, unit: 'MINUTES') {
1242 while (!freeNodes) {
1243 freeNodes = jenkins.model.Jenkins.instance.computers.findAll { node ->
1244 label in node.getAssignedLabels().collect { it.name } &&
Sergey Kolekonovd5887172022-11-10 12:13:22 +06001245 node.isPartiallyIdle() &&
1246 node.isOnline()
Sergey Kolekonov0e60a942022-09-05 13:02:22 +04001247 }
1248 if (!freeNodes) {
1249 echo 'No nodes available for scheduling, retrying...'
1250 sleep 30
1251 }
1252 }
1253 }
1254
1255 // generate a map of nodes matching other criteria
1256 for (node in freeNodes) {
1257 // sameJobExecutors is the number of executors running the same job as the calling one
1258 sameJobExecutors = node.getExecutors() // get all executors
1259 .collect { executor -> executor.getCurrentExecutable() } // get running "threads"
1260 .collect { thread -> thread?.displayName } // filter job names from threads
1261 .minus(null) // null = empty executors, remove them from the list
1262 .findAll { it.contains(env.JOB_NAME) } // filter the same jobs as the calling one
1263 .size()
1264
1265 // calculate busy executors, we don't want to count "sameJobExecutors" twice
1266 totalBusyExecutors = node.countBusy() - sameJobExecutors
1267 // generate the final map which contains nodes matching criteria with their load score
1268 // builds of the same jobs have x10 score, all others x1
1269 nodesMap += ["${node.getName()}" : sameJobExecutors * 10 + totalBusyExecutors]
1270 }
1271
1272 // return the least loaded node
1273 return common.SortMapByValueAsc(nodesMap).collect { it.key }[0]
1274}