Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Generate cookiecutter cluster by individual products |
| 3 | * |
| 4 | * Expected parameters: |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 5 | * COOKIECUTTER_TEMPLATE_CONTEXT Context parameters for the template generation. |
Sergey Galkin | 8b87f6e | 2018-10-24 18:40:13 +0400 | [diff] [blame] | 6 | * CREDENTIALS_ID Credentials id for git |
azvyagintsev | 6d678da | 2018-11-28 21:19:06 +0200 | [diff] [blame] | 7 | * TEST_MODEL Run syntax tests for model |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 8 | **/ |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 9 | import static groovy.json.JsonOutput.toJson |
| 10 | import static groovy.json.JsonOutput.prettyPrint |
Denis Egorenko | 032a2b7 | 2019-04-03 14:56:52 +0400 | [diff] [blame] | 11 | import org.apache.commons.net.util.SubnetUtils |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 12 | |
| 13 | common = new com.mirantis.mk.Common() |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 14 | common2 = new com.mirantis.mcp.Common() |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 15 | git = new com.mirantis.mk.Git() |
| 16 | python = new com.mirantis.mk.Python() |
chnyda | 8919101 | 2017-05-29 15:38:35 +0200 | [diff] [blame] | 17 | saltModelTesting = new com.mirantis.mk.SaltModelTesting() |
azvyagintsev | 5b7ec89 | 2019-05-15 16:37:34 +0300 | [diff] [blame^] | 18 | updateSaltFormulasDuringTest = true |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 19 | |
Aleksey Zvyagintsev | 4a80421 | 2019-02-07 13:02:31 +0000 | [diff] [blame] | 20 | slaveNode = env.getProperty('SLAVE_NODE') ?: 'virtual' |
azvyagintsev | 6d678da | 2018-11-28 21:19:06 +0200 | [diff] [blame] | 21 | gerritCredentials = env.getProperty('CREDENTIALS_ID') ?: 'gerrit' |
| 22 | runTestModel = (env.getProperty('TEST_MODEL') ?: true).toBoolean() |
azvyagintsev | 866b19a | 2018-11-20 18:21:43 +0200 | [diff] [blame] | 23 | distribRevision = 'proposed' |
| 24 | gitGuessedVersion = false |
| 25 | |
azvyagintsev | 866b19a | 2018-11-20 18:21:43 +0200 | [diff] [blame] | 26 | def globalVariatorsUpdate() { |
| 27 | def templateContext = readYaml text: env.COOKIECUTTER_TEMPLATE_CONTEXT |
| 28 | def context = templateContext['default_context'] |
| 29 | // TODO add more check's for critical var's |
| 30 | // Since we can't pin to any '_branch' variable from context, to identify 'default git revision' - |
| 31 | // because each of them, might be 'refs/' variable, we need to add some tricky trigger of using |
| 32 | // 'release/XXX' logic. This is totall guess - so,if even those one failed, to definitely must pass |
| 33 | // correct variable finally! |
| 34 | [context.get('cookiecutter_template_branch'), context.get('shared_reclass_branch'), context.get('mcp_common_scripts_branch')].any { branch -> |
| 35 | if (branch.toString().startsWith('release/')) { |
| 36 | gitGuessedVersion = branch |
| 37 | return true |
| 38 | } |
| 39 | } |
azvyagintsev | 866b19a | 2018-11-20 18:21:43 +0200 | [diff] [blame] | 40 | // Use mcpVersion git tag if not specified branch for cookiecutter-templates |
| 41 | if (!context.get('cookiecutter_template_branch')) { |
| 42 | context['cookiecutter_template_branch'] = gitGuessedVersion ?: context['mcp_version'] |
| 43 | } |
| 44 | // Don't have n/t/s for cookiecutter-templates repo, therefore use master |
| 45 | if (["nightly", "testing", "stable"].contains(context['cookiecutter_template_branch'])) { |
| 46 | context['cookiecutter_template_branch'] = 'master' |
| 47 | } |
| 48 | if (!context.get('shared_reclass_branch')) { |
| 49 | context['shared_reclass_branch'] = gitGuessedVersion ?: context['mcp_version'] |
| 50 | } |
| 51 | // Don't have nightly/testing for reclass-system repo, therefore use master |
| 52 | if (["nightly", "testing", "stable"].contains(context['shared_reclass_branch'])) { |
| 53 | context['shared_reclass_branch'] = 'master' |
| 54 | } |
| 55 | if (!context.get('mcp_common_scripts_branch')) { |
| 56 | // Pin exactly to CC branch, since it might use 'release/XXX' format |
| 57 | context['mcp_common_scripts_branch'] = gitGuessedVersion ?: context['mcp_version'] |
| 58 | } |
| 59 | // Don't have n/t/s for mcp-common-scripts repo, therefore use master |
| 60 | if (["nightly", "testing", "stable"].contains(context['mcp_common_scripts_branch'])) { |
| 61 | context['mcp_common_scripts_branch'] = 'master' |
| 62 | } |
| 63 | // |
| 64 | distribRevision = context['mcp_version'] |
| 65 | if (['master'].contains(context['mcp_version'])) { |
| 66 | distribRevision = 'nightly' |
| 67 | } |
| 68 | if (distribRevision.contains('/')) { |
| 69 | distribRevision = distribRevision.split('/')[-1] |
| 70 | } |
| 71 | // Check if we are going to test bleeding-edge release, which doesn't have binary release yet |
azvyagintsev | 8e08164 | 2019-02-03 19:15:22 +0200 | [diff] [blame] | 72 | // After 2018q4 releases, need to also check 'static' repo, for example ubuntu. |
azvyagintsev | 4f34f7a | 2019-02-26 18:47:37 +0200 | [diff] [blame] | 73 | def binTest = common.checkRemoteBinary(['mcp_version': distribRevision]) |
azvyagintsev | 8e08164 | 2019-02-03 19:15:22 +0200 | [diff] [blame] | 74 | if (!binTest.linux_system_repo_url || !binTest.linux_system_repo_ubuntu_url) { |
| 75 | common.errorMsg("Binary release: ${distribRevision} not exist or not full. Fallback to 'proposed'! ") |
azvyagintsev | 866b19a | 2018-11-20 18:21:43 +0200 | [diff] [blame] | 76 | distribRevision = 'proposed' |
| 77 | } |
azvyagintsev | 8e08164 | 2019-02-03 19:15:22 +0200 | [diff] [blame] | 78 | |
azvyagintsev | 5400d1d | 2018-12-11 13:19:29 +0200 | [diff] [blame] | 79 | // (azvyagintsev) WA for PROD-25732 |
| 80 | if (context.cookiecutter_template_url.contains('gerrit.mcp.mirantis.com/mk/cookiecutter-templates')) { |
| 81 | common.warningMsg('Apply WA for PROD-25732') |
| 82 | context.cookiecutter_template_url = 'ssh://gerrit.mcp.mirantis.com:29418/mk/cookiecutter-templates.git' |
| 83 | } |
azvyagintsev | 5b7ec89 | 2019-05-15 16:37:34 +0300 | [diff] [blame^] | 84 | // check, if we are going to test clear release version, w\o any updates and patches |
| 85 | if (!gitGuessedVersion && (distribRevision == context.mcp_version)) { |
| 86 | updateSaltFormulasDuringTest = false |
| 87 | } |
| 88 | |
Denis Egorenko | c1e1d04 | 2019-04-26 08:55:27 +0000 | [diff] [blame] | 89 | common.infoMsg("Using context:\n" + context) |
Aleksey Zvyagintsev | 7ca28d2 | 2019-02-25 11:05:49 +0000 | [diff] [blame] | 90 | print prettyPrint(toJson(context)) |
azvyagintsev | 866b19a | 2018-11-20 18:21:43 +0200 | [diff] [blame] | 91 | return context |
| 92 | |
| 93 | } |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame] | 94 | |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 95 | timeout(time: 1, unit: 'HOURS') { |
Aleksey Zvyagintsev | 7ca28d2 | 2019-02-25 11:05:49 +0000 | [diff] [blame] | 96 | node(slaveNode) { |
azvyagintsev | 866b19a | 2018-11-20 18:21:43 +0200 | [diff] [blame] | 97 | def context = globalVariatorsUpdate() |
azvyagintsev | 6d678da | 2018-11-28 21:19:06 +0200 | [diff] [blame] | 98 | def RequesterEmail = context.get('email_address', '') |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 99 | def templateEnv = "${env.WORKSPACE}/template" |
azvyagintsev | 4f34f7a | 2019-02-26 18:47:37 +0200 | [diff] [blame] | 100 | // modelEnv - this is reclass root, aka /srv/salt/reclass |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 101 | def modelEnv = "${env.WORKSPACE}/model" |
| 102 | def testEnv = "${env.WORKSPACE}/test" |
| 103 | def pipelineEnv = "${env.WORKSPACE}/pipelines" |
Tomáš Kukrál | 9f6260f | 2017-03-29 23:58:26 +0200 | [diff] [blame] | 104 | |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 105 | try { |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 106 | // |
| 107 | def cutterEnv = "${env.WORKSPACE}/cutter" |
| 108 | def systemEnv = "${modelEnv}/classes/system" |
| 109 | def testResult = false |
| 110 | def user |
| 111 | wrap([$class: 'BuildUser']) { |
| 112 | user = env.BUILD_USER_ID |
| 113 | } |
azvyagintsev | 6d678da | 2018-11-28 21:19:06 +0200 | [diff] [blame] | 114 | currentBuild.description = "${context['cluster_name']} ${RequesterEmail}" |
azvyagintsev | 866b19a | 2018-11-20 18:21:43 +0200 | [diff] [blame] | 115 | |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 116 | stage('Download Cookiecutter template') { |
| 117 | sh(script: 'find . -mindepth 1 -delete > /dev/null || true') |
| 118 | checkout([ |
| 119 | $class : 'GitSCM', |
| 120 | branches : [[name: 'FETCH_HEAD'],], |
| 121 | extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: templateEnv]], |
| 122 | userRemoteConfigs: [[url: context['cookiecutter_template_url'], refspec: context['cookiecutter_template_branch'], credentialsId: gerritCredentials],], |
| 123 | ]) |
| 124 | } |
| 125 | stage('Create empty reclass model') { |
| 126 | dir(path: modelEnv) { |
azvyagintsev | 4f34f7a | 2019-02-26 18:47:37 +0200 | [diff] [blame] | 127 | sh 'rm -rfv .git; git init' |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 128 | sshagent(credentials: [gerritCredentials]) { |
| 129 | sh "git submodule add ${context['shared_reclass_url']} 'classes/system'" |
| 130 | } |
| 131 | } |
| 132 | checkout([ |
| 133 | $class : 'GitSCM', |
| 134 | branches : [[name: 'FETCH_HEAD'],], |
| 135 | extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: systemEnv]], |
| 136 | userRemoteConfigs: [[url: context['shared_reclass_url'], refspec: context['shared_reclass_branch'], credentialsId: gerritCredentials],], |
| 137 | ]) |
azvyagintsev | 4f34f7a | 2019-02-26 18:47:37 +0200 | [diff] [blame] | 138 | git.commitGitChanges(modelEnv, 'Added new shared reclass submodule', "${user}@localhost", "${user}") |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | stage('Generate model') { |
Denis Egorenko | c1e1d04 | 2019-04-26 08:55:27 +0000 | [diff] [blame] | 142 | // GNUPGHOME environment variable is required for all gpg commands |
| 143 | // and for python.generateModel execution |
| 144 | withEnv(["GNUPGHOME=${env.WORKSPACE}/gpghome"]) { |
Dmitry Pyzhov | 089fb4f | 2018-12-11 16:58:00 +0300 | [diff] [blame] | 145 | if (context['secrets_encryption_enabled'] == 'True') { |
Denis Egorenko | c1e1d04 | 2019-04-26 08:55:27 +0000 | [diff] [blame] | 146 | sh "mkdir gpghome; chmod 700 gpghome" |
Dmitry Pyzhov | b5c74c7 | 2018-12-17 22:08:50 +0300 | [diff] [blame] | 147 | def secretKeyID = RequesterEmail ?: "salt@${context['cluster_domain']}".toString() |
Dmitry Pyzhov | 089fb4f | 2018-12-11 16:58:00 +0300 | [diff] [blame] | 148 | if (!context.get('secrets_encryption_private_key')) { |
| 149 | def batchData = """ |
| 150 | Key-Type: 1 |
| 151 | Key-Length: 4096 |
| 152 | Expire-Date: 0 |
| 153 | Name-Real: ${context['salt_master_hostname']}.${context['cluster_domain']} |
| 154 | Name-Email: ${secretKeyID} |
| 155 | """.stripIndent() |
azvyagintsev | 7d6d46c | 2019-02-11 14:25:41 +0200 | [diff] [blame] | 156 | writeFile file: 'gpg-batch.txt', text: batchData |
Dmitry Pyzhov | 089fb4f | 2018-12-11 16:58:00 +0300 | [diff] [blame] | 157 | sh "gpg --gen-key --batch < gpg-batch.txt" |
| 158 | sh "gpg --export-secret-key -a ${secretKeyID} > gpgkey.asc" |
| 159 | } else { |
azvyagintsev | 7d6d46c | 2019-02-11 14:25:41 +0200 | [diff] [blame] | 160 | writeFile file: 'gpgkey.asc', text: context['secrets_encryption_private_key'] |
Dmitry Pyzhov | 089fb4f | 2018-12-11 16:58:00 +0300 | [diff] [blame] | 161 | sh "gpg --import gpgkey.asc" |
| 162 | secretKeyID = sh(returnStdout: true, script: 'gpg --list-secret-keys --with-colons | awk -F: -e "/^sec/{print \\$5; exit}"').trim() |
| 163 | } |
| 164 | context['secrets_encryption_key_id'] = secretKeyID |
| 165 | } |
Stanislav Riazanov | da45ea0 | 2018-12-21 16:12:50 +0400 | [diff] [blame] | 166 | if (context.get('cfg_failsafe_ssh_public_key')) { |
azvyagintsev | 7d6d46c | 2019-02-11 14:25:41 +0200 | [diff] [blame] | 167 | writeFile file: 'failsafe-ssh-key.pub', text: context['cfg_failsafe_ssh_public_key'] |
Stanislav Riazanov | da45ea0 | 2018-12-21 16:12:50 +0400 | [diff] [blame] | 168 | } |
azvyagintsev | 4f34f7a | 2019-02-26 18:47:37 +0200 | [diff] [blame] | 169 | if (!fileExists(new File(templateEnv, 'tox.ini').toString())) { |
azvyagintsev | 06dfe40 | 2019-03-22 17:58:53 +0200 | [diff] [blame] | 170 | reqs = new File(templateEnv, 'requirements.txt').toString() |
| 171 | if (fileExists(reqs)) { |
| 172 | python.setupVirtualenv(cutterEnv, 'python2', [], reqs) |
| 173 | } else { |
| 174 | python.setupCookiecutterVirtualenv(cutterEnv) |
| 175 | } |
azvyagintsev | 4f34f7a | 2019-02-26 18:47:37 +0200 | [diff] [blame] | 176 | python.generateModel(common2.dumpYAML(['default_context': context]), 'default_context', context['salt_master_hostname'], cutterEnv, modelEnv, templateEnv, false) |
| 177 | } else { |
| 178 | // tox-based CC generated structure of reclass,from the root. Otherwise for bw compat, modelEnv |
| 179 | // still expect only lower lvl of project, aka model/classes/cluster/XXX/. So,lets dump result into |
| 180 | // temp dir, and then copy it over initial structure. |
| 181 | reclassTempRootDir = sh(script: "mktemp -d -p ${env.WORKSPACE}", returnStdout: true).trim() |
Denis Egorenko | c1e1d04 | 2019-04-26 08:55:27 +0000 | [diff] [blame] | 182 | python.generateModel(common2.dumpYAML(['default_context': context]), 'default_context', context['salt_master_hostname'], cutterEnv, reclassTempRootDir, templateEnv, false) |
azvyagintsev | 4f34f7a | 2019-02-26 18:47:37 +0200 | [diff] [blame] | 183 | dir(modelEnv) { |
| 184 | common.warningMsg('Forming reclass-root structure...') |
| 185 | sh("cp -ra ${reclassTempRootDir}/reclass/* .") |
| 186 | } |
| 187 | } |
Dmitry Pyzhov | 089fb4f | 2018-12-11 16:58:00 +0300 | [diff] [blame] | 188 | git.commitGitChanges(modelEnv, "Create model ${context['cluster_name']}", "${user}@localhost", "${user}") |
| 189 | } |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Denis Egorenko | c1e1d04 | 2019-04-26 08:55:27 +0000 | [diff] [blame] | 192 | stage("Test") { |
azvyagintsev | 6d678da | 2018-11-28 21:19:06 +0200 | [diff] [blame] | 193 | if (runTestModel) { |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 194 | sh("cp -r ${modelEnv} ${testEnv}") |
azvyagintsev | 7d6d46c | 2019-02-11 14:25:41 +0200 | [diff] [blame] | 195 | if (fileExists('gpgkey.asc')) { |
| 196 | common.infoMsg('gpgkey.asc found!Copy it into reclass folder for tests..') |
| 197 | sh("cp -v gpgkey.asc ${testEnv}/salt_master_pillar.asc") |
| 198 | } |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 199 | def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}" |
azvyagintsev | 5b7ec89 | 2019-05-15 16:37:34 +0300 | [diff] [blame^] | 200 | common.warningMsg("Attempt to run test against:\n" + |
| 201 | "DISTRIB_REVISION from ${distribRevision}\n" + |
| 202 | "updateSaltFormulasDuringTest = ${updateSaltFormulasDuringTest}") |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 203 | try { |
| 204 | def config = [ |
Denis Egorenko | 926bc7d | 2019-02-19 14:27:34 +0400 | [diff] [blame] | 205 | 'dockerHostname' : "${context['salt_master_hostname']}", |
| 206 | 'domain' : "${context['cluster_domain']}", |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 207 | 'reclassEnv' : testEnv, |
| 208 | 'distribRevision' : distribRevision, |
| 209 | 'dockerContainerName': DockerCName, |
Denis Egorenko | d87490e | 2019-02-26 20:00:41 +0400 | [diff] [blame] | 210 | 'testContext' : 'salt-model-node', |
azvyagintsev | 5b7ec89 | 2019-05-15 16:37:34 +0300 | [diff] [blame^] | 211 | 'dockerExtraOpts' : ['--memory=3g'], |
| 212 | 'updateSaltFormulas' : updateSaltFormulasDuringTest |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 213 | ] |
| 214 | testResult = saltModelTesting.testNode(config) |
| 215 | common.infoMsg("Test finished: SUCCESS") |
| 216 | } catch (Exception ex) { |
| 217 | common.warningMsg("Test finished: FAILED") |
| 218 | testResult = false |
| 219 | } |
| 220 | } else { |
| 221 | common.warningMsg("Test stage has been skipped!") |
| 222 | } |
| 223 | } |
| 224 | stage("Generate config drives") { |
| 225 | // apt package genisoimage is required for this stage |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 226 | // download create-config-drive |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 227 | def commonScriptsRepoUrl = context['mcp_common_scripts_repo'] ?: 'ssh://gerrit.mcp.mirantis.com:29418/mcp/mcp-common-scripts' |
| 228 | checkout([ |
| 229 | $class : 'GitSCM', |
| 230 | branches : [[name: 'FETCH_HEAD'],], |
| 231 | extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'mcp-common-scripts']], |
azvyagintsev | 866b19a | 2018-11-20 18:21:43 +0200 | [diff] [blame] | 232 | userRemoteConfigs: [[url: commonScriptsRepoUrl, refspec: context['mcp_common_scripts_branch'], credentialsId: gerritCredentials],], |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 233 | ]) |
| 234 | |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 235 | def outdateGeneration = false |
| 236 | if (fileExists('mcp-common-scripts/config-drive/create_config_drive.py')) { |
| 237 | sh 'cp mcp-common-scripts/config-drive/create_config_drive.py create-config-drive.py' |
| 238 | } else { |
| 239 | outdateGeneration = true |
| 240 | sh 'cp mcp-common-scripts/config-drive/create_config_drive.sh create-config-drive && chmod +x create-config-drive' |
| 241 | } |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 242 | 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' |
| 243 | |
Denis Egorenko | c1e1d04 | 2019-04-26 08:55:27 +0000 | [diff] [blame] | 244 | sh "git clone --mirror https://github.com/Mirantis/mk-pipelines.git ${pipelineEnv}/mk-pipelines" |
| 245 | sh "git clone --mirror https://github.com/Mirantis/pipeline-library.git ${pipelineEnv}/pipeline-library" |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 246 | args = [ |
azvyagintsev | 1385db9 | 2019-03-22 16:05:10 +0200 | [diff] [blame] | 247 | "--user-data user_data", "--model ${modelEnv}", |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 248 | "--mk-pipelines ${pipelineEnv}/mk-pipelines/", "--pipeline-library ${pipelineEnv}/pipeline-library/" |
| 249 | ] |
Dmitry Pyzhov | 089fb4f | 2018-12-11 16:58:00 +0300 | [diff] [blame] | 250 | if (context['secrets_encryption_enabled'] == 'True') { |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 251 | args.add('--gpg-key gpgkey.asc') |
Dmitry Pyzhov | 089fb4f | 2018-12-11 16:58:00 +0300 | [diff] [blame] | 252 | } |
Stanislav Riazanov | da45ea0 | 2018-12-21 16:12:50 +0400 | [diff] [blame] | 253 | if (context.get('cfg_failsafe_ssh_public_key')) { |
Denis Egorenko | aaeda9b | 2019-02-28 20:55:59 +0400 | [diff] [blame] | 254 | if (outdateGeneration) { |
| 255 | args.add('--ssh-key failsafe-ssh-key.pub') |
| 256 | } else { |
Denis Egorenko | 85ddf0d | 2019-03-18 18:11:19 +0400 | [diff] [blame] | 257 | if (context.get('cfg_failsafe_user')) { |
| 258 | args.add('--ssh-keys failsafe-ssh-key.pub') |
| 259 | args.add("--cloud-user-name ${context.get('cfg_failsafe_user')}") |
| 260 | } |
Denis Egorenko | aaeda9b | 2019-02-28 20:55:59 +0400 | [diff] [blame] | 261 | } |
Stanislav Riazanov | da45ea0 | 2018-12-21 16:12:50 +0400 | [diff] [blame] | 262 | } |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 263 | // load data from model |
| 264 | def smc = [:] |
| 265 | smc['SALT_MASTER_MINION_ID'] = "${context['salt_master_hostname']}.${context['cluster_domain']}" |
| 266 | smc['SALT_MASTER_DEPLOY_IP'] = context['salt_master_management_address'] |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 267 | if (outdateGeneration) { |
| 268 | smc['DEPLOY_NETWORK_GW'] = context['deploy_network_gateway'] |
| 269 | smc['DEPLOY_NETWORK_NETMASK'] = context['deploy_network_netmask'] |
| 270 | if (context.get('deploy_network_mtu')) { |
| 271 | smc['DEPLOY_NETWORK_MTU'] = context['deploy_network_mtu'] |
| 272 | } |
| 273 | smc['DNS_SERVERS'] = context['dns_server01'] |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 274 | } |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 275 | smc['MCP_VERSION'] = "${context['mcp_version']}" |
| 276 | if (context['local_repositories'] == 'True') { |
Denis Egorenko | 6bfa755 | 2019-02-05 19:09:25 +0400 | [diff] [blame] | 277 | def localRepoIP = '' |
Denis Egorenko | f97aec2 | 2019-02-05 14:57:33 +0400 | [diff] [blame] | 278 | if (context['mcp_version'] in ['2018.4.0', '2018.8.0', '2018.8.0-milestone1', '2018.11.0']) { |
Denis Egorenko | 6bfa755 | 2019-02-05 19:09:25 +0400 | [diff] [blame] | 279 | localRepoIP = context['local_repo_url'] |
Denis Egorenko | f97aec2 | 2019-02-05 14:57:33 +0400 | [diff] [blame] | 280 | smc['MCP_SALT_REPO_URL'] = "http://${localRepoIP}/ubuntu-xenial" |
| 281 | } else { |
Denis Egorenko | 6bfa755 | 2019-02-05 19:09:25 +0400 | [diff] [blame] | 282 | localRepoIP = context['aptly_server_deploy_address'] |
Denis Egorenko | f97aec2 | 2019-02-05 14:57:33 +0400 | [diff] [blame] | 283 | smc['MCP_SALT_REPO_URL'] = "http://${localRepoIP}" |
| 284 | } |
Denis Egorenko | 6bfa755 | 2019-02-05 19:09:25 +0400 | [diff] [blame] | 285 | smc['MCP_SALT_REPO_KEY'] = "http://${localRepoIP}/public.gpg" |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 286 | smc['PIPELINES_FROM_ISO'] = 'false' |
| 287 | smc['PIPELINE_REPO_URL'] = "http://${localRepoIP}:8088" |
| 288 | smc['LOCAL_REPOS'] = 'true' |
| 289 | } |
| 290 | if (context['upstream_proxy_enabled'] == 'True') { |
| 291 | if (context['upstream_proxy_auth_enabled'] == 'True') { |
| 292 | smc['http_proxy'] = 'http://' + context['upstream_proxy_user'] + ':' + context['upstream_proxy_password'] + '@' + context['upstream_proxy_address'] + ':' + context['upstream_proxy_port'] |
| 293 | smc['https_proxy'] = 'http://' + context['upstream_proxy_user'] + ':' + context['upstream_proxy_password'] + '@' + context['upstream_proxy_address'] + ':' + context['upstream_proxy_port'] |
| 294 | } else { |
| 295 | smc['http_proxy'] = 'http://' + context['upstream_proxy_address'] + ':' + context['upstream_proxy_port'] |
| 296 | smc['https_proxy'] = 'http://' + context['upstream_proxy_address'] + ':' + context['upstream_proxy_port'] |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | for (i in common.entries(smc)) { |
| 301 | sh "sed -i 's,${i[0]}=.*,${i[0]}=${i[1]},' user_data" |
| 302 | } |
| 303 | |
Denis Egorenko | 032a2b7 | 2019-04-03 14:56:52 +0400 | [diff] [blame] | 304 | // calculate netmask |
Denis Egorenko | 1f131b7 | 2019-04-05 14:42:48 +0400 | [diff] [blame] | 305 | def deployNetworkSubnet = '' |
| 306 | if (context.get('deploy_network_subnet')) { |
| 307 | def subnet = new SubnetUtils(context['deploy_network_subnet']) |
| 308 | deployNetworkSubnet = subnet.getInfo().getNetmask() |
| 309 | } else if (context.get('deploy_network_netmask')) { // case for 2018.4.0 |
| 310 | deployNetworkSubnet = context['deploy_network_netmask'] |
| 311 | } else { |
| 312 | error('Neither context parameter deploy_network_subnet or deploy_network_netmask should be set!') |
| 313 | } |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 314 | // create cfg config-drive |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 315 | if (outdateGeneration) { |
azvyagintsev | 06dfe40 | 2019-03-22 17:58:53 +0200 | [diff] [blame] | 316 | args += ["--hostname ${context['salt_master_hostname']}", "${context['salt_master_hostname']}.${context['cluster_domain']}-config.iso"] |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 317 | sh "./create-config-drive ${args.join(' ')}" |
| 318 | } else { |
| 319 | args += [ |
| 320 | "--name ${context['salt_master_hostname']}", "--hostname ${context['salt_master_hostname']}.${context['cluster_domain']}", "--clean-up", |
Denis Egorenko | 032a2b7 | 2019-04-03 14:56:52 +0400 | [diff] [blame] | 321 | "--ip ${context['salt_master_management_address']}", "--netmask ${deployNetworkSubnet}", "--gateway ${context['deploy_network_gateway']}", |
Denis Egorenko | aaeda9b | 2019-02-28 20:55:59 +0400 | [diff] [blame] | 322 | "--dns-nameservers ${context['dns_server01']},${context['dns_server02']}" |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 323 | ] |
azvyagintsev | c4c047a | 2019-04-04 17:42:48 +0300 | [diff] [blame] | 324 | sh "chmod 0755 create-config-drive.py ; ./create-config-drive.py ${args.join(' ')}" |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 325 | } |
Aleksey Zvyagintsev | aa235f2 | 2019-04-24 12:46:42 +0000 | [diff] [blame] | 326 | sh("mkdir output-${context['cluster_name']} && mv ${context['salt_master_hostname']}.${context['cluster_domain']}-config.iso output-${context['cluster_name']}/") |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 327 | |
| 328 | // save cfg iso to artifacts |
Aleksey Zvyagintsev | aa235f2 | 2019-04-24 12:46:42 +0000 | [diff] [blame] | 329 | archiveArtifacts artifacts: "output-${context['cluster_name']}/${context['salt_master_hostname']}.${context['cluster_domain']}-config.iso" |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 330 | |
| 331 | if (context['local_repositories'] == 'True') { |
| 332 | def aptlyServerHostname = context.aptly_server_hostname |
| 333 | 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" |
| 334 | |
| 335 | def smc_apt = [:] |
| 336 | smc_apt['SALT_MASTER_DEPLOY_IP'] = context['salt_master_management_address'] |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 337 | if (outdateGeneration) { |
| 338 | smc_apt['APTLY_DEPLOY_IP'] = context['aptly_server_deploy_address'] |
| 339 | smc_apt['APTLY_DEPLOY_NETMASK'] = context['deploy_network_netmask'] |
| 340 | } |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 341 | smc_apt['APTLY_MINION_ID'] = "${aptlyServerHostname}.${context['cluster_domain']}" |
| 342 | |
| 343 | for (i in common.entries(smc_apt)) { |
| 344 | sh "sed -i \"s,export ${i[0]}=.*,export ${i[0]}=${i[1]},\" mirror_config" |
| 345 | } |
| 346 | |
| 347 | // create apt config-drive |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 348 | if (outdateGeneration) { |
| 349 | sh "./create-config-drive --user-data mirror_config --hostname ${aptlyServerHostname} ${aptlyServerHostname}.${context['cluster_domain']}-config.iso" |
| 350 | } else { |
| 351 | args = [ |
Denis Egorenko | 032a2b7 | 2019-04-03 14:56:52 +0400 | [diff] [blame] | 352 | "--ip ${context['aptly_server_deploy_address']}", "--netmask ${deployNetworkSubnet}", "--gateway ${context['deploy_network_gateway']}", |
Denis Egorenko | aaeda9b | 2019-02-28 20:55:59 +0400 | [diff] [blame] | 353 | "--user-data mirror_config", "--hostname ${aptlyServerHostname}.${context['cluster_domain']}", "--name ${aptlyServerHostname}", "--clean-up", |
| 354 | "--dns-nameservers ${context['dns_server01']},${context['dns_server02']}" |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 355 | ] |
| 356 | sh "python ./create-config-drive.py ${args.join(' ')}" |
| 357 | } |
Aleksey Zvyagintsev | aa235f2 | 2019-04-24 12:46:42 +0000 | [diff] [blame] | 358 | sh("mv ${aptlyServerHostname}.${context['cluster_domain']}-config.iso output-${context['cluster_name']}/") |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 359 | |
| 360 | // save apt iso to artifacts |
Aleksey Zvyagintsev | aa235f2 | 2019-04-24 12:46:42 +0000 | [diff] [blame] | 361 | archiveArtifacts artifacts: "output-${context['cluster_name']}/${aptlyServerHostname}.${context['cluster_domain']}-config.iso" |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
| 365 | stage('Save changes reclass model') { |
Denis Egorenko | d986525 | 2019-04-24 15:41:57 +0400 | [diff] [blame] | 366 | sh(returnStatus: true, script: "tar -czf ${context['cluster_name']}.tar.gz --exclude='*@tmp' -C ${modelEnv} .") |
| 367 | archiveArtifacts artifacts: "${context['cluster_name']}.tar.gz" |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 368 | |
azvyagintsev | 5400d1d | 2018-12-11 13:19:29 +0200 | [diff] [blame] | 369 | if (RequesterEmail != '' && !RequesterEmail.contains('example')) { |
azvyagintsev | 6d678da | 2018-11-28 21:19:06 +0200 | [diff] [blame] | 370 | emailext(to: RequesterEmail, |
Aleksey Zvyagintsev | aa235f2 | 2019-04-24 12:46:42 +0000 | [diff] [blame] | 371 | attachmentsPattern: "output-${context['cluster_name']}/*", |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 372 | body: "Mirantis Jenkins\n\nRequested reclass model ${context['cluster_name']} has been created and attached to this email.\nEnjoy!\n\nMirantis", |
| 373 | subject: "Your Salt model ${context['cluster_name']}") |
| 374 | } |
Aleksey Zvyagintsev | aa235f2 | 2019-04-24 12:46:42 +0000 | [diff] [blame] | 375 | dir("output-${context['cluster_name']}") { |
| 376 | deleteDir() |
| 377 | } |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | // Fail, but leave possibility to get failed artifacts |
azvyagintsev | 6d678da | 2018-11-28 21:19:06 +0200 | [diff] [blame] | 381 | if (!testResult && runTestModel) { |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 382 | common.warningMsg('Test finished: FAILURE. Please check logs and\\or debug failed model manually!') |
| 383 | error('Test stage finished: FAILURE') |
| 384 | } |
| 385 | |
| 386 | } catch (Throwable e) { |
| 387 | currentBuild.result = "FAILURE" |
| 388 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 389 | throw e |
| 390 | } finally { |
| 391 | stage('Clean workspace directories') { |
Aleksey Zvyagintsev | 7ca28d2 | 2019-02-25 11:05:49 +0000 | [diff] [blame] | 392 | sh(script: 'find . -mindepth 1 -delete > /dev/null || true') |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 393 | } |
| 394 | // common.sendNotification(currentBuild.result,"",["slack"]) |
Denis Egorenko | 34c4a3b | 2019-03-12 12:48:15 +0400 | [diff] [blame] | 395 | stage('Save artifacts to Artifactory') { |
| 396 | def artifactory = new com.mirantis.mcp.MCPArtifactory() |
azvyagintsev | 06dfe40 | 2019-03-22 17:58:53 +0200 | [diff] [blame] | 397 | def buildProps = ["context=${context['cluster_name']}"] |
Denis Egorenko | 34c4a3b | 2019-03-12 12:48:15 +0400 | [diff] [blame] | 398 | if (RequesterEmail != '' && !RequesterEmail.contains('example')) { |
| 399 | buildProps.add("emailTo=${RequesterEmail}") |
| 400 | } |
| 401 | def artifactoryLink = artifactory.uploadJobArtifactsToArtifactory([ |
azvyagintsev | 06dfe40 | 2019-03-22 17:58:53 +0200 | [diff] [blame] | 402 | 'artifactory' : 'mcp-ci', |
Denis Egorenko | 34c4a3b | 2019-03-12 12:48:15 +0400 | [diff] [blame] | 403 | 'artifactoryRepo': "drivetrain-local/${JOB_NAME}/${context['cluster_name']}-${BUILD_NUMBER}", |
azvyagintsev | 06dfe40 | 2019-03-22 17:58:53 +0200 | [diff] [blame] | 404 | 'buildProps' : buildProps, |
Denis Egorenko | 34c4a3b | 2019-03-12 12:48:15 +0400 | [diff] [blame] | 405 | ]) |
| 406 | currentBuild.description += "<br/>${artifactoryLink}" |
| 407 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 408 | } |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 409 | } |
Mikhail Ivanov | 9f81292 | 2017-11-07 18:52:02 +0400 | [diff] [blame] | 410 | } |