blob: 72c5cba11e9ed81718e8b6302d7e1cbd9a1e643b [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.
azvyagintsev4f34f7a2019-02-26 18:47:37 +020072 def binTest = common.checkRemoteBinary(['mcp_version': distribRevision])
azvyagintsev8e081642019-02-03 19:15:22 +020073 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}")
Aleksey Zvyagintsev7ca28d22019-02-25 11:05:49 +000085 common.infoMsg("Using context:\n" + context)
86 print prettyPrint(toJson(context))
azvyagintsev866b19a2018-11-20 18:21:43 +020087 return context
88
89}
azvyagintsevf252b592018-08-13 18:39:14 +030090
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +000091timeout(time: 1, unit: 'HOURS') {
Aleksey Zvyagintsev7ca28d22019-02-25 11:05:49 +000092 node(slaveNode) {
azvyagintsev866b19a2018-11-20 18:21:43 +020093 def context = globalVariatorsUpdate()
azvyagintsev6d678da2018-11-28 21:19:06 +020094 def RequesterEmail = context.get('email_address', '')
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +000095 def templateEnv = "${env.WORKSPACE}/template"
azvyagintsev4f34f7a2019-02-26 18:47:37 +020096 // modelEnv - this is reclass root, aka /srv/salt/reclass
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +000097 def modelEnv = "${env.WORKSPACE}/model"
98 def testEnv = "${env.WORKSPACE}/test"
99 def pipelineEnv = "${env.WORKSPACE}/pipelines"
Tomáš Kukrál9f6260f2017-03-29 23:58:26 +0200100
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000101 try {
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000102 //
103 def cutterEnv = "${env.WORKSPACE}/cutter"
104 def systemEnv = "${modelEnv}/classes/system"
105 def testResult = false
106 def user
107 wrap([$class: 'BuildUser']) {
108 user = env.BUILD_USER_ID
109 }
azvyagintsev6d678da2018-11-28 21:19:06 +0200110 currentBuild.description = "${context['cluster_name']} ${RequesterEmail}"
azvyagintsev866b19a2018-11-20 18:21:43 +0200111
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000112 stage('Download Cookiecutter template') {
113 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
114 checkout([
115 $class : 'GitSCM',
116 branches : [[name: 'FETCH_HEAD'],],
117 extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: templateEnv]],
118 userRemoteConfigs: [[url: context['cookiecutter_template_url'], refspec: context['cookiecutter_template_branch'], credentialsId: gerritCredentials],],
119 ])
120 }
121 stage('Create empty reclass model') {
122 dir(path: modelEnv) {
azvyagintsev4f34f7a2019-02-26 18:47:37 +0200123 sh 'rm -rfv .git; git init'
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000124 sshagent(credentials: [gerritCredentials]) {
125 sh "git submodule add ${context['shared_reclass_url']} 'classes/system'"
126 }
127 }
128 checkout([
129 $class : 'GitSCM',
130 branches : [[name: 'FETCH_HEAD'],],
131 extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: systemEnv]],
132 userRemoteConfigs: [[url: context['shared_reclass_url'], refspec: context['shared_reclass_branch'], credentialsId: gerritCredentials],],
133 ])
azvyagintsev4f34f7a2019-02-26 18:47:37 +0200134 git.commitGitChanges(modelEnv, 'Added new shared reclass submodule', "${user}@localhost", "${user}")
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000135 }
136
137 stage('Generate model') {
Dmitry Pyzhov089fb4f2018-12-11 16:58:00 +0300138 // GNUPGHOME environment variable is required for all gpg commands
139 // and for python.generateModel execution
140 withEnv(["GNUPGHOME=${env.WORKSPACE}/gpghome"]) {
141 if (context['secrets_encryption_enabled'] == 'True') {
142 sh "mkdir gpghome; chmod 700 gpghome"
Dmitry Pyzhovb5c74c72018-12-17 22:08:50 +0300143 def secretKeyID = RequesterEmail ?: "salt@${context['cluster_domain']}".toString()
Dmitry Pyzhov089fb4f2018-12-11 16:58:00 +0300144 if (!context.get('secrets_encryption_private_key')) {
145 def batchData = """
146 Key-Type: 1
147 Key-Length: 4096
148 Expire-Date: 0
149 Name-Real: ${context['salt_master_hostname']}.${context['cluster_domain']}
150 Name-Email: ${secretKeyID}
151 """.stripIndent()
azvyagintsev7d6d46c2019-02-11 14:25:41 +0200152 writeFile file: 'gpg-batch.txt', text: batchData
Dmitry Pyzhov089fb4f2018-12-11 16:58:00 +0300153 sh "gpg --gen-key --batch < gpg-batch.txt"
154 sh "gpg --export-secret-key -a ${secretKeyID} > gpgkey.asc"
155 } else {
azvyagintsev7d6d46c2019-02-11 14:25:41 +0200156 writeFile file: 'gpgkey.asc', text: context['secrets_encryption_private_key']
Dmitry Pyzhov089fb4f2018-12-11 16:58:00 +0300157 sh "gpg --import gpgkey.asc"
158 secretKeyID = sh(returnStdout: true, script: 'gpg --list-secret-keys --with-colons | awk -F: -e "/^sec/{print \\$5; exit}"').trim()
159 }
160 context['secrets_encryption_key_id'] = secretKeyID
161 }
Stanislav Riazanovda45ea02018-12-21 16:12:50 +0400162 if (context.get('cfg_failsafe_ssh_public_key')) {
azvyagintsev7d6d46c2019-02-11 14:25:41 +0200163 writeFile file: 'failsafe-ssh-key.pub', text: context['cfg_failsafe_ssh_public_key']
Stanislav Riazanovda45ea02018-12-21 16:12:50 +0400164 }
azvyagintsev4f34f7a2019-02-26 18:47:37 +0200165 if (!fileExists(new File(templateEnv, 'tox.ini').toString())) {
azvyagintsev06dfe402019-03-22 17:58:53 +0200166 reqs = new File(templateEnv, 'requirements.txt').toString()
167 if (fileExists(reqs)) {
168 python.setupVirtualenv(cutterEnv, 'python2', [], reqs)
169 } else {
170 python.setupCookiecutterVirtualenv(cutterEnv)
171 }
azvyagintsev4f34f7a2019-02-26 18:47:37 +0200172 python.generateModel(common2.dumpYAML(['default_context': context]), 'default_context', context['salt_master_hostname'], cutterEnv, modelEnv, templateEnv, false)
173 } else {
174 // tox-based CC generated structure of reclass,from the root. Otherwise for bw compat, modelEnv
175 // still expect only lower lvl of project, aka model/classes/cluster/XXX/. So,lets dump result into
176 // temp dir, and then copy it over initial structure.
177 reclassTempRootDir = sh(script: "mktemp -d -p ${env.WORKSPACE}", returnStdout: true).trim()
178 python.generateModel(common2.dumpYAML(['default_context': context]), 'default_context', context['salt_master_hostname'], cutterEnv, reclassTempRootDir, templateEnv, false)
179 dir(modelEnv) {
180 common.warningMsg('Forming reclass-root structure...')
181 sh("cp -ra ${reclassTempRootDir}/reclass/* .")
182 }
183 }
Dmitry Pyzhov089fb4f2018-12-11 16:58:00 +0300184 git.commitGitChanges(modelEnv, "Create model ${context['cluster_name']}", "${user}@localhost", "${user}")
185 }
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000186 }
187
188 stage("Test") {
azvyagintsev6d678da2018-11-28 21:19:06 +0200189 if (runTestModel) {
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000190 sh("cp -r ${modelEnv} ${testEnv}")
azvyagintsev7d6d46c2019-02-11 14:25:41 +0200191 if (fileExists('gpgkey.asc')) {
192 common.infoMsg('gpgkey.asc found!Copy it into reclass folder for tests..')
193 sh("cp -v gpgkey.asc ${testEnv}/salt_master_pillar.asc")
194 }
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000195 def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}"
196 common.infoMsg("Attempt to run test against distribRevision: ${distribRevision}")
197 try {
198 def config = [
Denis Egorenko926bc7d2019-02-19 14:27:34 +0400199 'dockerHostname' : "${context['salt_master_hostname']}",
200 'domain' : "${context['cluster_domain']}",
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000201 'reclassEnv' : testEnv,
202 'distribRevision' : distribRevision,
203 'dockerContainerName': DockerCName,
Denis Egorenkod87490e2019-02-26 20:00:41 +0400204 'testContext' : 'salt-model-node',
azvyagintsev4f34f7a2019-02-26 18:47:37 +0200205 'dockerExtraOpts' : ['--memory=3g']
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000206 ]
207 testResult = saltModelTesting.testNode(config)
208 common.infoMsg("Test finished: SUCCESS")
209 } catch (Exception ex) {
210 common.warningMsg("Test finished: FAILED")
211 testResult = false
212 }
213 } else {
214 common.warningMsg("Test stage has been skipped!")
215 }
216 }
217 stage("Generate config drives") {
218 // apt package genisoimage is required for this stage
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000219 // download create-config-drive
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000220 def commonScriptsRepoUrl = context['mcp_common_scripts_repo'] ?: 'ssh://gerrit.mcp.mirantis.com:29418/mcp/mcp-common-scripts'
221 checkout([
222 $class : 'GitSCM',
223 branches : [[name: 'FETCH_HEAD'],],
224 extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'mcp-common-scripts']],
azvyagintsev866b19a2018-11-20 18:21:43 +0200225 userRemoteConfigs: [[url: commonScriptsRepoUrl, refspec: context['mcp_common_scripts_branch'], credentialsId: gerritCredentials],],
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000226 ])
227
Denis Egorenkoaeaa0132019-02-25 16:55:08 +0400228 def outdateGeneration = false
229 if (fileExists('mcp-common-scripts/config-drive/create_config_drive.py')) {
230 sh 'cp mcp-common-scripts/config-drive/create_config_drive.py create-config-drive.py'
231 } else {
232 outdateGeneration = true
233 sh 'cp mcp-common-scripts/config-drive/create_config_drive.sh create-config-drive && chmod +x create-config-drive'
234 }
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000235 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'
236
237 sh "git clone --mirror https://github.com/Mirantis/mk-pipelines.git ${pipelineEnv}/mk-pipelines"
238 sh "git clone --mirror https://github.com/Mirantis/pipeline-library.git ${pipelineEnv}/pipeline-library"
Denis Egorenkoaeaa0132019-02-25 16:55:08 +0400239 args = [
azvyagintsev1385db92019-03-22 16:05:10 +0200240 "--user-data user_data", "--model ${modelEnv}",
Denis Egorenkoaeaa0132019-02-25 16:55:08 +0400241 "--mk-pipelines ${pipelineEnv}/mk-pipelines/", "--pipeline-library ${pipelineEnv}/pipeline-library/"
242 ]
Dmitry Pyzhov089fb4f2018-12-11 16:58:00 +0300243 if (context['secrets_encryption_enabled'] == 'True') {
Denis Egorenkoaeaa0132019-02-25 16:55:08 +0400244 args.add('--gpg-key gpgkey.asc')
Dmitry Pyzhov089fb4f2018-12-11 16:58:00 +0300245 }
Stanislav Riazanovda45ea02018-12-21 16:12:50 +0400246 if (context.get('cfg_failsafe_ssh_public_key')) {
Denis Egorenkoaaeda9b2019-02-28 20:55:59 +0400247 if (outdateGeneration) {
248 args.add('--ssh-key failsafe-ssh-key.pub')
249 } else {
Denis Egorenko85ddf0d2019-03-18 18:11:19 +0400250 if (context.get('cfg_failsafe_user')) {
251 args.add('--ssh-keys failsafe-ssh-key.pub')
252 args.add("--cloud-user-name ${context.get('cfg_failsafe_user')}")
253 }
Denis Egorenkoaaeda9b2019-02-28 20:55:59 +0400254 }
Stanislav Riazanovda45ea02018-12-21 16:12:50 +0400255 }
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000256 // load data from model
257 def smc = [:]
258 smc['SALT_MASTER_MINION_ID'] = "${context['salt_master_hostname']}.${context['cluster_domain']}"
259 smc['SALT_MASTER_DEPLOY_IP'] = context['salt_master_management_address']
Denis Egorenkoaeaa0132019-02-25 16:55:08 +0400260 if (outdateGeneration) {
261 smc['DEPLOY_NETWORK_GW'] = context['deploy_network_gateway']
262 smc['DEPLOY_NETWORK_NETMASK'] = context['deploy_network_netmask']
263 if (context.get('deploy_network_mtu')) {
264 smc['DEPLOY_NETWORK_MTU'] = context['deploy_network_mtu']
265 }
266 smc['DNS_SERVERS'] = context['dns_server01']
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000267 }
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000268 smc['MCP_VERSION'] = "${context['mcp_version']}"
269 if (context['local_repositories'] == 'True') {
Denis Egorenko6bfa7552019-02-05 19:09:25 +0400270 def localRepoIP = ''
Denis Egorenkof97aec22019-02-05 14:57:33 +0400271 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 +0400272 localRepoIP = context['local_repo_url']
Denis Egorenkof97aec22019-02-05 14:57:33 +0400273 smc['MCP_SALT_REPO_URL'] = "http://${localRepoIP}/ubuntu-xenial"
274 } else {
Denis Egorenko6bfa7552019-02-05 19:09:25 +0400275 localRepoIP = context['aptly_server_deploy_address']
Denis Egorenkof97aec22019-02-05 14:57:33 +0400276 smc['MCP_SALT_REPO_URL'] = "http://${localRepoIP}"
277 }
Denis Egorenko6bfa7552019-02-05 19:09:25 +0400278 smc['MCP_SALT_REPO_KEY'] = "http://${localRepoIP}/public.gpg"
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000279 smc['PIPELINES_FROM_ISO'] = 'false'
280 smc['PIPELINE_REPO_URL'] = "http://${localRepoIP}:8088"
281 smc['LOCAL_REPOS'] = 'true'
282 }
283 if (context['upstream_proxy_enabled'] == 'True') {
284 if (context['upstream_proxy_auth_enabled'] == 'True') {
285 smc['http_proxy'] = 'http://' + context['upstream_proxy_user'] + ':' + context['upstream_proxy_password'] + '@' + context['upstream_proxy_address'] + ':' + context['upstream_proxy_port']
286 smc['https_proxy'] = 'http://' + context['upstream_proxy_user'] + ':' + context['upstream_proxy_password'] + '@' + context['upstream_proxy_address'] + ':' + context['upstream_proxy_port']
287 } else {
288 smc['http_proxy'] = 'http://' + context['upstream_proxy_address'] + ':' + context['upstream_proxy_port']
289 smc['https_proxy'] = 'http://' + context['upstream_proxy_address'] + ':' + context['upstream_proxy_port']
290 }
291 }
292
293 for (i in common.entries(smc)) {
294 sh "sed -i 's,${i[0]}=.*,${i[0]}=${i[1]},' user_data"
295 }
296
297 // create cfg config-drive
Denis Egorenkoaeaa0132019-02-25 16:55:08 +0400298 if (outdateGeneration) {
azvyagintsev06dfe402019-03-22 17:58:53 +0200299 args += ["--hostname ${context['salt_master_hostname']}", "${context['salt_master_hostname']}.${context['cluster_domain']}-config.iso"]
Denis Egorenkoaeaa0132019-02-25 16:55:08 +0400300 sh "./create-config-drive ${args.join(' ')}"
301 } else {
302 args += [
303 "--name ${context['salt_master_hostname']}", "--hostname ${context['salt_master_hostname']}.${context['cluster_domain']}", "--clean-up",
Denis Egorenkoa741cb32019-03-20 14:49:24 +0000304 "--ip ${context['salt_master_management_address']}", "--netmask ${context['deploy_network_netmask']}", "--gateway ${context['deploy_network_gateway']}",
Denis Egorenkoaaeda9b2019-02-28 20:55:59 +0400305 "--dns-nameservers ${context['dns_server01']},${context['dns_server02']}"
Denis Egorenkoaeaa0132019-02-25 16:55:08 +0400306 ]
307 sh "python ./create-config-drive.py ${args.join(' ')}"
308 }
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000309 sh("mkdir output-${context['cluster_name']} && mv ${context['salt_master_hostname']}.${context['cluster_domain']}-config.iso output-${context['cluster_name']}/")
310
311 // save cfg iso to artifacts
312 archiveArtifacts artifacts: "output-${context['cluster_name']}/${context['salt_master_hostname']}.${context['cluster_domain']}-config.iso"
313
314 if (context['local_repositories'] == 'True') {
315 def aptlyServerHostname = context.aptly_server_hostname
316 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"
317
318 def smc_apt = [:]
319 smc_apt['SALT_MASTER_DEPLOY_IP'] = context['salt_master_management_address']
Denis Egorenkoaeaa0132019-02-25 16:55:08 +0400320 if (outdateGeneration) {
321 smc_apt['APTLY_DEPLOY_IP'] = context['aptly_server_deploy_address']
322 smc_apt['APTLY_DEPLOY_NETMASK'] = context['deploy_network_netmask']
323 }
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000324 smc_apt['APTLY_MINION_ID'] = "${aptlyServerHostname}.${context['cluster_domain']}"
325
326 for (i in common.entries(smc_apt)) {
327 sh "sed -i \"s,export ${i[0]}=.*,export ${i[0]}=${i[1]},\" mirror_config"
328 }
329
330 // create apt config-drive
Denis Egorenkoaeaa0132019-02-25 16:55:08 +0400331 if (outdateGeneration) {
332 sh "./create-config-drive --user-data mirror_config --hostname ${aptlyServerHostname} ${aptlyServerHostname}.${context['cluster_domain']}-config.iso"
333 } else {
334 args = [
335 "--ip ${context['aptly_server_deploy_address']}", "--netmask ${context['deploy_network_netmask']}", "--gateway ${context['deploy_network_gateway']}",
Denis Egorenkoaaeda9b2019-02-28 20:55:59 +0400336 "--user-data mirror_config", "--hostname ${aptlyServerHostname}.${context['cluster_domain']}", "--name ${aptlyServerHostname}", "--clean-up",
337 "--dns-nameservers ${context['dns_server01']},${context['dns_server02']}"
Denis Egorenkoaeaa0132019-02-25 16:55:08 +0400338 ]
339 sh "python ./create-config-drive.py ${args.join(' ')}"
340 }
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000341 sh("mv ${aptlyServerHostname}.${context['cluster_domain']}-config.iso output-${context['cluster_name']}/")
342
343 // save apt iso to artifacts
344 archiveArtifacts artifacts: "output-${context['cluster_name']}/${aptlyServerHostname}.${context['cluster_domain']}-config.iso"
345 }
346 }
347
348 stage('Save changes reclass model') {
349 sh(returnStatus: true, script: "tar -czf output-${context['cluster_name']}/${context['cluster_name']}.tar.gz --exclude='*@tmp' -C ${modelEnv} .")
350 archiveArtifacts artifacts: "output-${context['cluster_name']}/${context['cluster_name']}.tar.gz"
351
azvyagintsev5400d1d2018-12-11 13:19:29 +0200352 if (RequesterEmail != '' && !RequesterEmail.contains('example')) {
azvyagintsev6d678da2018-11-28 21:19:06 +0200353 emailext(to: RequesterEmail,
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000354 attachmentsPattern: "output-${context['cluster_name']}/*",
355 body: "Mirantis Jenkins\n\nRequested reclass model ${context['cluster_name']} has been created and attached to this email.\nEnjoy!\n\nMirantis",
356 subject: "Your Salt model ${context['cluster_name']}")
357 }
358 dir("output-${context['cluster_name']}") {
359 deleteDir()
360 }
361 }
362
363 // Fail, but leave possibility to get failed artifacts
azvyagintsev6d678da2018-11-28 21:19:06 +0200364 if (!testResult && runTestModel) {
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000365 common.warningMsg('Test finished: FAILURE. Please check logs and\\or debug failed model manually!')
366 error('Test stage finished: FAILURE')
367 }
368
369 } catch (Throwable e) {
370 currentBuild.result = "FAILURE"
371 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
372 throw e
373 } finally {
374 stage('Clean workspace directories') {
Aleksey Zvyagintsev7ca28d22019-02-25 11:05:49 +0000375 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
Aleksey Zvyagintsevb16902d2018-10-29 12:33:48 +0000376 }
377 // common.sendNotification(currentBuild.result,"",["slack"])
Denis Egorenko34c4a3b2019-03-12 12:48:15 +0400378 stage('Save artifacts to Artifactory') {
379 def artifactory = new com.mirantis.mcp.MCPArtifactory()
azvyagintsev06dfe402019-03-22 17:58:53 +0200380 def buildProps = ["context=${context['cluster_name']}"]
Denis Egorenko34c4a3b2019-03-12 12:48:15 +0400381 if (RequesterEmail != '' && !RequesterEmail.contains('example')) {
382 buildProps.add("emailTo=${RequesterEmail}")
383 }
384 def artifactoryLink = artifactory.uploadJobArtifactsToArtifactory([
azvyagintsev06dfe402019-03-22 17:58:53 +0200385 'artifactory' : 'mcp-ci',
Denis Egorenko34c4a3b2019-03-12 12:48:15 +0400386 'artifactoryRepo': "drivetrain-local/${JOB_NAME}/${context['cluster_name']}-${BUILD_NUMBER}",
azvyagintsev06dfe402019-03-22 17:58:53 +0200387 'buildProps' : buildProps,
Denis Egorenko34c4a3b2019-03-12 12:48:15 +0400388 ])
389 currentBuild.description += "<br/>${artifactoryLink}"
390 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400391 }
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200392 }
Mikhail Ivanov9f812922017-11-07 18:52:02 +0400393}