blob: f98251fea20656434194e76707e12221e24d9c4b [file] [log] [blame]
Tomáš Kukrál7ded3642017-03-27 15:52:51 +02001/**
2 * Generate cookiecutter cluster by individual products
3 *
4 * Expected parameters:
Tomáš Kukrál7ded3642017-03-27 15:52:51 +02005 * COOKIECUTTER_TEMPLATE_CONTEXT Context parameters for the template generation.
Sergey Galkin8b87f6e2018-10-24 18:40:13 +04006 * CREDENTIALS_ID Credentials id for git
azvyagintsev6d678da2018-11-28 21:19:06 +02007 * TEST_MODEL Run syntax tests for model
azvyagintsev3ed704f2018-07-09 15:49:27 +03008 **/
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +00009import static groovy.json.JsonOutput.toJson
10import static groovy.json.JsonOutput.prettyPrint
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020011
12common = new com.mirantis.mk.Common()
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +000013common2 = new com.mirantis.mcp.Common()
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020014git = new com.mirantis.mk.Git()
15python = new com.mirantis.mk.Python()
chnyda89191012017-05-29 15:38:35 +020016saltModelTesting = new com.mirantis.mk.SaltModelTesting()
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020017
Aleksey Zvyagintsev4a804212019-02-07 13:02:31 +000018slaveNode = env.getProperty('SLAVE_NODE') ?: 'virtual'
azvyagintsev6d678da2018-11-28 21:19:06 +020019gerritCredentials = env.getProperty('CREDENTIALS_ID') ?: 'gerrit'
20runTestModel = (env.getProperty('TEST_MODEL') ?: true).toBoolean()
azvyagintsev866b19a2018-11-20 18:21:43 +020021distribRevision = 'proposed'
22gitGuessedVersion = false
23
24
25def globalVariatorsUpdate() {
26 def templateContext = readYaml text: env.COOKIECUTTER_TEMPLATE_CONTEXT
27 def context = templateContext['default_context']
28 // TODO add more check's for critical var's
29 // Since we can't pin to any '_branch' variable from context, to identify 'default git revision' -
30 // because each of them, might be 'refs/' variable, we need to add some tricky trigger of using
31 // 'release/XXX' logic. This is totall guess - so,if even those one failed, to definitely must pass
32 // correct variable finally!
33 [context.get('cookiecutter_template_branch'), context.get('shared_reclass_branch'), context.get('mcp_common_scripts_branch')].any { branch ->
34 if (branch.toString().startsWith('release/')) {
35 gitGuessedVersion = branch
36 return true
37 }
38 }
azvyagintsev866b19a2018-11-20 18:21:43 +020039 // Use mcpVersion git tag if not specified branch for cookiecutter-templates
40 if (!context.get('cookiecutter_template_branch')) {
41 context['cookiecutter_template_branch'] = gitGuessedVersion ?: context['mcp_version']
42 }
43 // Don't have n/t/s for cookiecutter-templates repo, therefore use master
44 if (["nightly", "testing", "stable"].contains(context['cookiecutter_template_branch'])) {
45 context['cookiecutter_template_branch'] = 'master'
46 }
47 if (!context.get('shared_reclass_branch')) {
48 context['shared_reclass_branch'] = gitGuessedVersion ?: context['mcp_version']
49 }
50 // Don't have nightly/testing for reclass-system repo, therefore use master
51 if (["nightly", "testing", "stable"].contains(context['shared_reclass_branch'])) {
52 context['shared_reclass_branch'] = 'master'
53 }
54 if (!context.get('mcp_common_scripts_branch')) {
55 // Pin exactly to CC branch, since it might use 'release/XXX' format
56 context['mcp_common_scripts_branch'] = gitGuessedVersion ?: context['mcp_version']
57 }
58 // Don't have n/t/s for mcp-common-scripts repo, therefore use master
59 if (["nightly", "testing", "stable"].contains(context['mcp_common_scripts_branch'])) {
60 context['mcp_common_scripts_branch'] = 'master'
61 }
62 //
63 distribRevision = context['mcp_version']
64 if (['master'].contains(context['mcp_version'])) {
65 distribRevision = 'nightly'
66 }
67 if (distribRevision.contains('/')) {
68 distribRevision = distribRevision.split('/')[-1]
69 }
70 // Check if we are going to test bleeding-edge release, which doesn't have binary release yet
azvyagintsev8e081642019-02-03 19:15:22 +020071 // After 2018q4 releases, need to also check 'static' repo, for example ubuntu.
72 binTest = common.checkRemoteBinary(['mcp_version': distribRevision])
73 if (!binTest.linux_system_repo_url || !binTest.linux_system_repo_ubuntu_url) {
74 common.errorMsg("Binary release: ${distribRevision} not exist or not full. Fallback to 'proposed'! ")
azvyagintsev866b19a2018-11-20 18:21:43 +020075 distribRevision = 'proposed'
76 }
azvyagintsev8e081642019-02-03 19:15:22 +020077
azvyagintsev5400d1d2018-12-11 13:19:29 +020078 // (azvyagintsev) WA for PROD-25732
79 if (context.cookiecutter_template_url.contains('gerrit.mcp.mirantis.com/mk/cookiecutter-templates')) {
80 common.warningMsg('Apply WA for PROD-25732')
81 context.cookiecutter_template_url = 'ssh://gerrit.mcp.mirantis.com:29418/mk/cookiecutter-templates.git'
82 }
azvyagintsev866b19a2018-11-20 18:21:43 +020083 common.warningMsg("Fetching:\n" +
84 "DISTRIB_REVISION from ${distribRevision}")
azvyagintsev816d7fd2019-02-20 14:19:14 +020085 common.infoMsg('Using context:\n')
86 print(prettyPrint(toJson(context)))
azvyagintsev866b19a2018-11-20 18:21:43 +020087 return context
88
89}
azvyagintsevf252b592018-08-13 18:39:14 +030090
azvyagintsev816d7fd2019-02-20 14:19:14 +020091def generateModel(context, contextName, saltMasterName, virtualenv, modelEnv, templateEnvDir, multiModels = true) {
92 def common = new com.mirantis.mk.Common()
93 def generatedModel = multiModels ? "${modelEnv}/${contextName}" : modelEnv
94 def templateContext = readYaml text: context
95 def clusterDomain = templateContext.default_context.cluster_domain
96 def clusterName = templateContext.default_context.cluster_name
97 def outputDestination = "${generatedModel}/classes/cluster/${clusterName}"
98 def templateBaseDir = templateEnvDir
99 def templateDir = "${templateEnvDir}/dir"
100 def templateOutputDir = templateBaseDir
101 dir(templateEnvDir) {
102 if (fileExists(new File(templateEnvDir, 'tox.ini').toString())) {
103 tempContextFile = 'tempContext.yaml'
104 writeFile file: tempContextFile, text: context
105 common.warningMsg('Generating models using context:\n')
106 print(context)
107 withEnv(["CONFIG_FILE=$tempContextFile",
108 "OUTPUT_DIR=$templateOutputDir",
109 ]) {
110 print('[Cookiecutter build] Result:\n' +
111 sh(returnStdout: true, script: 'tox -ve generate_auto'))
112 }
113 // dropme after impelementation new format
114 sh "mkdir -p ${generatedModel}/nodes/"
115 def nodeFile = "${generatedModel}/nodes/${saltMasterName}.${clusterDomain}.yml"
116 def nodeString = """classes:
117- cluster.${clusterName}.infra.config
118parameters:
119 _param:
120 linux_system_codename: xenial
121 reclass_data_revision: master
122 linux:
123 system:
124 name: ${saltMasterName}
125 domain: ${clusterDomain}
126 """
127 writeFile(file: nodeFile, text: nodeString)
128 //
129 } else {
130 common.warningMsg("Old format: Generating model from context ${contextName}")
131 def productList = ["infra", "cicd", "kdt", "opencontrail", "kubernetes", "openstack", "oss", "stacklight", "ceph"]
132 for (product in productList) {
133 // get templateOutputDir and productDir
134 templateOutputDir = "${templateEnvDir}/output/${product}"
135 productDir = product
136 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
137 // Bw for 2018.8.1 and older releases
138 if (product.startsWith("stacklight") && (!fileExists(templateDir))) {
139 common.warningMsg("Old release detected! productDir => 'stacklight2' ")
140 productDir = "stacklight2"
141 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
142 }
143 // generate infra unless its explicitly disabled
144 if ((product == "infra" && templateContext.default_context.get("infra_enabled", "True").toBoolean())
145 || (templateContext.default_context.get(product + "_enabled", "False").toBoolean())) {
146
147 common.infoMsg("Generating product " + product + " from " + templateDir + " to " + templateOutputDir)
148
149 sh "rm -rf ${templateOutputDir} || true"
150 sh "mkdir -p ${templateOutputDir}"
151 sh "mkdir -p ${outputDestination}"
152
153 buildCookiecutterTemplate(templateDir, context, templateOutputDir, virtualenv, templateBaseDir)
154 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
155 } else {
156 common.warningMsg("Product " + product + " is disabled")
157 }
158 }
159
160 def localRepositories = templateContext.default_context.local_repositories
161 localRepositories = localRepositories ? localRepositories.toBoolean() : false
162 def offlineDeployment = templateContext.default_context.offline_deployment
163 offlineDeployment = offlineDeployment ? offlineDeployment.toBoolean() : false
164 if (localRepositories && !offlineDeployment) {
165 def mcpVersion = templateContext.default_context.mcp_version
166 def aptlyModelUrl = templateContext.default_context.local_model_url
167 def ssh = new com.mirantis.mk.Ssh()
168 dir(path: modelEnv) {
169 ssh.agentSh "git submodule add \"${aptlyModelUrl}\" \"classes/cluster/${clusterName}/cicd/aptly\""
170 if (!(mcpVersion in ["nightly", "testing", "stable"])) {
171 ssh.agentSh "cd \"classes/cluster/${clusterName}/cicd/aptly\";git fetch --tags;git checkout ${mcpVersion}"
172 }
173 }
174 }
175
176 def nodeFile = "${generatedModel}/nodes/${saltMasterName}.${clusterDomain}.yml"
177 def nodeString = """classes:
178- cluster.${clusterName}.infra.config
179parameters:
180 _param:
181 linux_system_codename: xenial
182 reclass_data_revision: master
183 linux:
184 system:
185 name: ${saltMasterName}
186 domain: ${clusterDomain}
187 """
188 sh "mkdir -p ${generatedModel}/nodes/"
189 writeFile(file: nodeFile, text: nodeString)
190 }
191 }
192}
193
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000194timeout(time: 1, unit: 'HOURS') {
azvyagintsev816d7fd2019-02-20 14:19:14 +0200195 node('jsl-image-publisher.mcp.mirantis.net') {
azvyagintsev866b19a2018-11-20 18:21:43 +0200196 def context = globalVariatorsUpdate()
azvyagintsev6d678da2018-11-28 21:19:06 +0200197 def RequesterEmail = context.get('email_address', '')
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000198 def templateEnv = "${env.WORKSPACE}/template"
199 def modelEnv = "${env.WORKSPACE}/model"
200 def testEnv = "${env.WORKSPACE}/test"
201 def pipelineEnv = "${env.WORKSPACE}/pipelines"
Tomáš Kukrál9f6260f2017-03-29 23:58:26 +0200202
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000203 try {
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000204 //
205 def cutterEnv = "${env.WORKSPACE}/cutter"
206 def systemEnv = "${modelEnv}/classes/system"
207 def testResult = false
208 def user
209 wrap([$class: 'BuildUser']) {
210 user = env.BUILD_USER_ID
211 }
azvyagintsev6d678da2018-11-28 21:19:06 +0200212 currentBuild.description = "${context['cluster_name']} ${RequesterEmail}"
azvyagintsev866b19a2018-11-20 18:21:43 +0200213
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000214 stage('Download Cookiecutter template') {
215 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
216 checkout([
217 $class : 'GitSCM',
218 branches : [[name: 'FETCH_HEAD'],],
219 extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: templateEnv]],
220 userRemoteConfigs: [[url: context['cookiecutter_template_url'], refspec: context['cookiecutter_template_branch'], credentialsId: gerritCredentials],],
221 ])
222 }
223 stage('Create empty reclass model') {
224 dir(path: modelEnv) {
225 sh "rm -rfv .git; git init"
226 sshagent(credentials: [gerritCredentials]) {
227 sh "git submodule add ${context['shared_reclass_url']} 'classes/system'"
228 }
229 }
230 checkout([
231 $class : 'GitSCM',
232 branches : [[name: 'FETCH_HEAD'],],
233 extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: systemEnv]],
234 userRemoteConfigs: [[url: context['shared_reclass_url'], refspec: context['shared_reclass_branch'], credentialsId: gerritCredentials],],
235 ])
236 git.commitGitChanges(modelEnv, "Added new shared reclass submodule", "${user}@localhost", "${user}")
237 }
238
239 stage('Generate model') {
Dmitry Pyzhov089fb4f2018-12-11 16:58:00 +0300240 // GNUPGHOME environment variable is required for all gpg commands
241 // and for python.generateModel execution
242 withEnv(["GNUPGHOME=${env.WORKSPACE}/gpghome"]) {
243 if (context['secrets_encryption_enabled'] == 'True') {
244 sh "mkdir gpghome; chmod 700 gpghome"
Dmitry Pyzhovb5c74c72018-12-17 22:08:50 +0300245 def secretKeyID = RequesterEmail ?: "salt@${context['cluster_domain']}".toString()
Dmitry Pyzhov089fb4f2018-12-11 16:58:00 +0300246 if (!context.get('secrets_encryption_private_key')) {
247 def batchData = """
248 Key-Type: 1
249 Key-Length: 4096
250 Expire-Date: 0
251 Name-Real: ${context['salt_master_hostname']}.${context['cluster_domain']}
252 Name-Email: ${secretKeyID}
253 """.stripIndent()
azvyagintsev7d6d46c2019-02-11 14:25:41 +0200254 writeFile file: 'gpg-batch.txt', text: batchData
Dmitry Pyzhov089fb4f2018-12-11 16:58:00 +0300255 sh "gpg --gen-key --batch < gpg-batch.txt"
256 sh "gpg --export-secret-key -a ${secretKeyID} > gpgkey.asc"
257 } else {
azvyagintsev7d6d46c2019-02-11 14:25:41 +0200258 writeFile file: 'gpgkey.asc', text: context['secrets_encryption_private_key']
Dmitry Pyzhov089fb4f2018-12-11 16:58:00 +0300259 sh "gpg --import gpgkey.asc"
260 secretKeyID = sh(returnStdout: true, script: 'gpg --list-secret-keys --with-colons | awk -F: -e "/^sec/{print \\$5; exit}"').trim()
261 }
262 context['secrets_encryption_key_id'] = secretKeyID
263 }
Stanislav Riazanovda45ea02018-12-21 16:12:50 +0400264 if (context.get('cfg_failsafe_ssh_public_key')) {
azvyagintsev7d6d46c2019-02-11 14:25:41 +0200265 writeFile file: 'failsafe-ssh-key.pub', text: context['cfg_failsafe_ssh_public_key']
Stanislav Riazanovda45ea02018-12-21 16:12:50 +0400266 }
azvyagintsev816d7fd2019-02-20 14:19:14 +0200267 templateEnv
268 if (!fileExists(new File(templateEnv, 'tox.ini').toString())) {
269 python.setupCookiecutterVirtualenv(cutterEnv)
270 }
Dmitry Pyzhov089fb4f2018-12-11 16:58:00 +0300271 // FIXME refactor generateModel
azvyagintsev816d7fd2019-02-20 14:19:14 +0200272 //python.generateModel(common2.dumpYAML(['default_context': context]), 'default_context', context['salt_master_hostname'], cutterEnv, modelEnv, templateEnv, false)
273 generateModel(common2.dumpYAML(['default_context': context]), 'default_context', context['salt_master_hostname'], cutterEnv, modelEnv, templateEnv, false)
Dmitry Pyzhov089fb4f2018-12-11 16:58:00 +0300274 git.commitGitChanges(modelEnv, "Create model ${context['cluster_name']}", "${user}@localhost", "${user}")
275 }
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000276 }
277
278 stage("Test") {
azvyagintsev6d678da2018-11-28 21:19:06 +0200279 if (runTestModel) {
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000280 sh("cp -r ${modelEnv} ${testEnv}")
azvyagintsev7d6d46c2019-02-11 14:25:41 +0200281 if (fileExists('gpgkey.asc')) {
282 common.infoMsg('gpgkey.asc found!Copy it into reclass folder for tests..')
283 sh("cp -v gpgkey.asc ${testEnv}/salt_master_pillar.asc")
284 }
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000285 def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}"
286 common.infoMsg("Attempt to run test against distribRevision: ${distribRevision}")
287 try {
288 def config = [
Denis Egorenko926bc7d2019-02-19 14:27:34 +0400289 'dockerHostname' : "${context['salt_master_hostname']}",
290 'domain' : "${context['cluster_domain']}",
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000291 'reclassEnv' : testEnv,
292 'distribRevision' : distribRevision,
293 'dockerContainerName': DockerCName,
294 'testContext' : 'salt-model-node'
295 ]
296 testResult = saltModelTesting.testNode(config)
297 common.infoMsg("Test finished: SUCCESS")
298 } catch (Exception ex) {
299 common.warningMsg("Test finished: FAILED")
300 testResult = false
301 }
302 } else {
303 common.warningMsg("Test stage has been skipped!")
304 }
305 }
306 stage("Generate config drives") {
307 // apt package genisoimage is required for this stage
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000308 // download create-config-drive
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000309 def commonScriptsRepoUrl = context['mcp_common_scripts_repo'] ?: 'ssh://gerrit.mcp.mirantis.com:29418/mcp/mcp-common-scripts'
310 checkout([
311 $class : 'GitSCM',
312 branches : [[name: 'FETCH_HEAD'],],
313 extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'mcp-common-scripts']],
azvyagintsev866b19a2018-11-20 18:21:43 +0200314 userRemoteConfigs: [[url: commonScriptsRepoUrl, refspec: context['mcp_common_scripts_branch'], credentialsId: gerritCredentials],],
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000315 ])
316
317 sh 'cp mcp-common-scripts/config-drive/create_config_drive.sh create-config-drive && chmod +x create-config-drive'
318 sh '[ -f mcp-common-scripts/config-drive/master_config.sh ] && cp mcp-common-scripts/config-drive/master_config.sh user_data || cp mcp-common-scripts/config-drive/master_config.yaml user_data'
319
320 sh "git clone --mirror https://github.com/Mirantis/mk-pipelines.git ${pipelineEnv}/mk-pipelines"
321 sh "git clone --mirror https://github.com/Mirantis/pipeline-library.git ${pipelineEnv}/pipeline-library"
322 args = "--user-data user_data --hostname ${context['salt_master_hostname']} --model ${modelEnv} --mk-pipelines ${pipelineEnv}/mk-pipelines/ --pipeline-library ${pipelineEnv}/pipeline-library/ ${context['salt_master_hostname']}.${context['cluster_domain']}-config.iso"
Dmitry Pyzhov089fb4f2018-12-11 16:58:00 +0300323 if (context['secrets_encryption_enabled'] == 'True') {
324 args = "--gpg-key gpgkey.asc " + args
325 }
Stanislav Riazanovda45ea02018-12-21 16:12:50 +0400326 if (context.get('cfg_failsafe_ssh_public_key')) {
327 args = "--ssh-key failsafe-ssh-key.pub " + args
328 }
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000329
330 // load data from model
331 def smc = [:]
332 smc['SALT_MASTER_MINION_ID'] = "${context['salt_master_hostname']}.${context['cluster_domain']}"
333 smc['SALT_MASTER_DEPLOY_IP'] = context['salt_master_management_address']
334 smc['DEPLOY_NETWORK_GW'] = context['deploy_network_gateway']
335 smc['DEPLOY_NETWORK_NETMASK'] = context['deploy_network_netmask']
336 if (context.get('deploy_network_mtu')) {
337 smc['DEPLOY_NETWORK_MTU'] = context['deploy_network_mtu']
338 }
339 smc['DNS_SERVERS'] = context['dns_server01']
340 smc['MCP_VERSION'] = "${context['mcp_version']}"
341 if (context['local_repositories'] == 'True') {
Denis Egorenko6bfa7552019-02-05 19:09:25 +0400342 def localRepoIP = ''
Denis Egorenkof97aec22019-02-05 14:57:33 +0400343 if (context['mcp_version'] in ['2018.4.0', '2018.8.0', '2018.8.0-milestone1', '2018.11.0']) {
Denis Egorenko6bfa7552019-02-05 19:09:25 +0400344 localRepoIP = context['local_repo_url']
Denis Egorenkof97aec22019-02-05 14:57:33 +0400345 smc['MCP_SALT_REPO_URL'] = "http://${localRepoIP}/ubuntu-xenial"
346 } else {
Denis Egorenko6bfa7552019-02-05 19:09:25 +0400347 localRepoIP = context['aptly_server_deploy_address']
Denis Egorenkof97aec22019-02-05 14:57:33 +0400348 smc['MCP_SALT_REPO_URL'] = "http://${localRepoIP}"
349 }
Denis Egorenko6bfa7552019-02-05 19:09:25 +0400350 smc['MCP_SALT_REPO_KEY'] = "http://${localRepoIP}/public.gpg"
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000351 smc['PIPELINES_FROM_ISO'] = 'false'
352 smc['PIPELINE_REPO_URL'] = "http://${localRepoIP}:8088"
353 smc['LOCAL_REPOS'] = 'true'
354 }
355 if (context['upstream_proxy_enabled'] == 'True') {
356 if (context['upstream_proxy_auth_enabled'] == 'True') {
357 smc['http_proxy'] = 'http://' + context['upstream_proxy_user'] + ':' + context['upstream_proxy_password'] + '@' + context['upstream_proxy_address'] + ':' + context['upstream_proxy_port']
358 smc['https_proxy'] = 'http://' + context['upstream_proxy_user'] + ':' + context['upstream_proxy_password'] + '@' + context['upstream_proxy_address'] + ':' + context['upstream_proxy_port']
359 } else {
360 smc['http_proxy'] = 'http://' + context['upstream_proxy_address'] + ':' + context['upstream_proxy_port']
361 smc['https_proxy'] = 'http://' + context['upstream_proxy_address'] + ':' + context['upstream_proxy_port']
362 }
363 }
364
365 for (i in common.entries(smc)) {
366 sh "sed -i 's,${i[0]}=.*,${i[0]}=${i[1]},' user_data"
367 }
368
369 // create cfg config-drive
370 sh "./create-config-drive ${args}"
371 sh("mkdir output-${context['cluster_name']} && mv ${context['salt_master_hostname']}.${context['cluster_domain']}-config.iso output-${context['cluster_name']}/")
372
373 // save cfg iso to artifacts
374 archiveArtifacts artifacts: "output-${context['cluster_name']}/${context['salt_master_hostname']}.${context['cluster_domain']}-config.iso"
375
376 if (context['local_repositories'] == 'True') {
377 def aptlyServerHostname = context.aptly_server_hostname
378 sh "[ -f mcp-common-scripts/config-drive/mirror_config.yaml ] && cp mcp-common-scripts/config-drive/mirror_config.yaml mirror_config || cp mcp-common-scripts/config-drive/mirror_config.sh mirror_config"
379
380 def smc_apt = [:]
381 smc_apt['SALT_MASTER_DEPLOY_IP'] = context['salt_master_management_address']
382 smc_apt['APTLY_DEPLOY_IP'] = context['aptly_server_deploy_address']
383 smc_apt['APTLY_DEPLOY_NETMASK'] = context['deploy_network_netmask']
384 smc_apt['APTLY_MINION_ID'] = "${aptlyServerHostname}.${context['cluster_domain']}"
385
386 for (i in common.entries(smc_apt)) {
387 sh "sed -i \"s,export ${i[0]}=.*,export ${i[0]}=${i[1]},\" mirror_config"
388 }
389
390 // create apt config-drive
391 sh "./create-config-drive --user-data mirror_config --hostname ${aptlyServerHostname} ${aptlyServerHostname}.${context['cluster_domain']}-config.iso"
392 sh("mv ${aptlyServerHostname}.${context['cluster_domain']}-config.iso output-${context['cluster_name']}/")
393
394 // save apt iso to artifacts
395 archiveArtifacts artifacts: "output-${context['cluster_name']}/${aptlyServerHostname}.${context['cluster_domain']}-config.iso"
396 }
397 }
398
399 stage('Save changes reclass model') {
400 sh(returnStatus: true, script: "tar -czf output-${context['cluster_name']}/${context['cluster_name']}.tar.gz --exclude='*@tmp' -C ${modelEnv} .")
401 archiveArtifacts artifacts: "output-${context['cluster_name']}/${context['cluster_name']}.tar.gz"
402
azvyagintsev5400d1d2018-12-11 13:19:29 +0200403 if (RequesterEmail != '' && !RequesterEmail.contains('example')) {
azvyagintsev6d678da2018-11-28 21:19:06 +0200404 emailext(to: RequesterEmail,
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000405 attachmentsPattern: "output-${context['cluster_name']}/*",
406 body: "Mirantis Jenkins\n\nRequested reclass model ${context['cluster_name']} has been created and attached to this email.\nEnjoy!\n\nMirantis",
407 subject: "Your Salt model ${context['cluster_name']}")
408 }
409 dir("output-${context['cluster_name']}") {
410 deleteDir()
411 }
412 }
413
414 // Fail, but leave possibility to get failed artifacts
azvyagintsev6d678da2018-11-28 21:19:06 +0200415 if (!testResult && runTestModel) {
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000416 common.warningMsg('Test finished: FAILURE. Please check logs and\\or debug failed model manually!')
417 error('Test stage finished: FAILURE')
418 }
419
420 } catch (Throwable e) {
421 currentBuild.result = "FAILURE"
422 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
423 throw e
424 } finally {
425 stage('Clean workspace directories') {
azvyagintsev816d7fd2019-02-20 14:19:14 +0200426 //sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000427 }
428 // common.sendNotification(currentBuild.result,"",["slack"])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400429 }
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200430 }
Mikhail Ivanov9f812922017-11-07 18:52:02 +0400431}