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 |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 11 | |
| 12 | common = new com.mirantis.mk.Common() |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 13 | common2 = new com.mirantis.mcp.Common() |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 14 | git = new com.mirantis.mk.Git() |
| 15 | python = new com.mirantis.mk.Python() |
chnyda | 8919101 | 2017-05-29 15:38:35 +0200 | [diff] [blame] | 16 | saltModelTesting = new com.mirantis.mk.SaltModelTesting() |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 17 | |
Aleksey Zvyagintsev | 4a80421 | 2019-02-07 13:02:31 +0000 | [diff] [blame] | 18 | slaveNode = env.getProperty('SLAVE_NODE') ?: 'virtual' |
azvyagintsev | 6d678da | 2018-11-28 21:19:06 +0200 | [diff] [blame] | 19 | gerritCredentials = env.getProperty('CREDENTIALS_ID') ?: 'gerrit' |
| 20 | runTestModel = (env.getProperty('TEST_MODEL') ?: true).toBoolean() |
azvyagintsev | 866b19a | 2018-11-20 18:21:43 +0200 | [diff] [blame] | 21 | distribRevision = 'proposed' |
| 22 | gitGuessedVersion = false |
| 23 | |
| 24 | |
| 25 | def 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 | } |
azvyagintsev | 866b19a | 2018-11-20 18:21:43 +0200 | [diff] [blame] | 39 | // 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 |
azvyagintsev | 8e08164 | 2019-02-03 19:15:22 +0200 | [diff] [blame] | 71 | // 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'! ") |
azvyagintsev | 866b19a | 2018-11-20 18:21:43 +0200 | [diff] [blame] | 75 | distribRevision = 'proposed' |
| 76 | } |
azvyagintsev | 8e08164 | 2019-02-03 19:15:22 +0200 | [diff] [blame] | 77 | |
azvyagintsev | 5400d1d | 2018-12-11 13:19:29 +0200 | [diff] [blame] | 78 | // (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 | } |
azvyagintsev | 866b19a | 2018-11-20 18:21:43 +0200 | [diff] [blame] | 83 | common.warningMsg("Fetching:\n" + |
| 84 | "DISTRIB_REVISION from ${distribRevision}") |
Aleksey Zvyagintsev | 7ca28d2 | 2019-02-25 11:05:49 +0000 | [diff] [blame] | 85 | common.infoMsg("Using context:\n" + context) |
| 86 | print prettyPrint(toJson(context)) |
azvyagintsev | 866b19a | 2018-11-20 18:21:43 +0200 | [diff] [blame] | 87 | return context |
| 88 | |
| 89 | } |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame] | 90 | |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 91 | timeout(time: 1, unit: 'HOURS') { |
Aleksey Zvyagintsev | 7ca28d2 | 2019-02-25 11:05:49 +0000 | [diff] [blame] | 92 | node(slaveNode) { |
azvyagintsev | 866b19a | 2018-11-20 18:21:43 +0200 | [diff] [blame] | 93 | def context = globalVariatorsUpdate() |
azvyagintsev | 6d678da | 2018-11-28 21:19:06 +0200 | [diff] [blame] | 94 | def RequesterEmail = context.get('email_address', '') |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 95 | def templateEnv = "${env.WORKSPACE}/template" |
| 96 | def modelEnv = "${env.WORKSPACE}/model" |
| 97 | def testEnv = "${env.WORKSPACE}/test" |
| 98 | def pipelineEnv = "${env.WORKSPACE}/pipelines" |
Tomáš Kukrál | 9f6260f | 2017-03-29 23:58:26 +0200 | [diff] [blame] | 99 | |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 100 | try { |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 101 | // |
| 102 | def cutterEnv = "${env.WORKSPACE}/cutter" |
| 103 | def systemEnv = "${modelEnv}/classes/system" |
| 104 | def testResult = false |
| 105 | def user |
| 106 | wrap([$class: 'BuildUser']) { |
| 107 | user = env.BUILD_USER_ID |
| 108 | } |
azvyagintsev | 6d678da | 2018-11-28 21:19:06 +0200 | [diff] [blame] | 109 | currentBuild.description = "${context['cluster_name']} ${RequesterEmail}" |
azvyagintsev | 866b19a | 2018-11-20 18:21:43 +0200 | [diff] [blame] | 110 | |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 111 | stage('Download Cookiecutter template') { |
| 112 | sh(script: 'find . -mindepth 1 -delete > /dev/null || true') |
| 113 | checkout([ |
| 114 | $class : 'GitSCM', |
| 115 | branches : [[name: 'FETCH_HEAD'],], |
| 116 | extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: templateEnv]], |
| 117 | userRemoteConfigs: [[url: context['cookiecutter_template_url'], refspec: context['cookiecutter_template_branch'], credentialsId: gerritCredentials],], |
| 118 | ]) |
| 119 | } |
| 120 | stage('Create empty reclass model') { |
| 121 | dir(path: modelEnv) { |
Aleksey Zvyagintsev | 2f8283e | 2019-02-27 21:43:15 +0000 | [diff] [blame] | 122 | sh "rm -rfv .git; git init" |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 123 | sshagent(credentials: [gerritCredentials]) { |
| 124 | sh "git submodule add ${context['shared_reclass_url']} 'classes/system'" |
| 125 | } |
| 126 | } |
| 127 | checkout([ |
| 128 | $class : 'GitSCM', |
| 129 | branches : [[name: 'FETCH_HEAD'],], |
| 130 | extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: systemEnv]], |
| 131 | userRemoteConfigs: [[url: context['shared_reclass_url'], refspec: context['shared_reclass_branch'], credentialsId: gerritCredentials],], |
| 132 | ]) |
Aleksey Zvyagintsev | 2f8283e | 2019-02-27 21:43:15 +0000 | [diff] [blame] | 133 | git.commitGitChanges(modelEnv, "Added new shared reclass submodule", "${user}@localhost", "${user}") |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | stage('Generate model') { |
Dmitry Pyzhov | 089fb4f | 2018-12-11 16:58:00 +0300 | [diff] [blame] | 137 | // GNUPGHOME environment variable is required for all gpg commands |
| 138 | // and for python.generateModel execution |
| 139 | withEnv(["GNUPGHOME=${env.WORKSPACE}/gpghome"]) { |
| 140 | if (context['secrets_encryption_enabled'] == 'True') { |
| 141 | sh "mkdir gpghome; chmod 700 gpghome" |
Dmitry Pyzhov | b5c74c7 | 2018-12-17 22:08:50 +0300 | [diff] [blame] | 142 | def secretKeyID = RequesterEmail ?: "salt@${context['cluster_domain']}".toString() |
Dmitry Pyzhov | 089fb4f | 2018-12-11 16:58:00 +0300 | [diff] [blame] | 143 | if (!context.get('secrets_encryption_private_key')) { |
| 144 | def batchData = """ |
| 145 | Key-Type: 1 |
| 146 | Key-Length: 4096 |
| 147 | Expire-Date: 0 |
| 148 | Name-Real: ${context['salt_master_hostname']}.${context['cluster_domain']} |
| 149 | Name-Email: ${secretKeyID} |
| 150 | """.stripIndent() |
azvyagintsev | 7d6d46c | 2019-02-11 14:25:41 +0200 | [diff] [blame] | 151 | writeFile file: 'gpg-batch.txt', text: batchData |
Dmitry Pyzhov | 089fb4f | 2018-12-11 16:58:00 +0300 | [diff] [blame] | 152 | sh "gpg --gen-key --batch < gpg-batch.txt" |
| 153 | sh "gpg --export-secret-key -a ${secretKeyID} > gpgkey.asc" |
| 154 | } else { |
azvyagintsev | 7d6d46c | 2019-02-11 14:25:41 +0200 | [diff] [blame] | 155 | writeFile file: 'gpgkey.asc', text: context['secrets_encryption_private_key'] |
Dmitry Pyzhov | 089fb4f | 2018-12-11 16:58:00 +0300 | [diff] [blame] | 156 | sh "gpg --import gpgkey.asc" |
| 157 | secretKeyID = sh(returnStdout: true, script: 'gpg --list-secret-keys --with-colons | awk -F: -e "/^sec/{print \\$5; exit}"').trim() |
| 158 | } |
| 159 | context['secrets_encryption_key_id'] = secretKeyID |
| 160 | } |
Stanislav Riazanov | da45ea0 | 2018-12-21 16:12:50 +0400 | [diff] [blame] | 161 | if (context.get('cfg_failsafe_ssh_public_key')) { |
azvyagintsev | 7d6d46c | 2019-02-11 14:25:41 +0200 | [diff] [blame] | 162 | 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] | 163 | } |
Aleksey Zvyagintsev | 2f8283e | 2019-02-27 21:43:15 +0000 | [diff] [blame] | 164 | python.setupCookiecutterVirtualenv(cutterEnv) |
| 165 | // FIXME refactor generateModel |
| 166 | python.generateModel(common2.dumpYAML(['default_context': context]), 'default_context', context['salt_master_hostname'], cutterEnv, modelEnv, templateEnv, false) |
Dmitry Pyzhov | 089fb4f | 2018-12-11 16:58:00 +0300 | [diff] [blame] | 167 | git.commitGitChanges(modelEnv, "Create model ${context['cluster_name']}", "${user}@localhost", "${user}") |
| 168 | } |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | stage("Test") { |
azvyagintsev | 6d678da | 2018-11-28 21:19:06 +0200 | [diff] [blame] | 172 | if (runTestModel) { |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 173 | sh("cp -r ${modelEnv} ${testEnv}") |
azvyagintsev | 7d6d46c | 2019-02-11 14:25:41 +0200 | [diff] [blame] | 174 | if (fileExists('gpgkey.asc')) { |
| 175 | common.infoMsg('gpgkey.asc found!Copy it into reclass folder for tests..') |
| 176 | sh("cp -v gpgkey.asc ${testEnv}/salt_master_pillar.asc") |
| 177 | } |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 178 | def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}" |
| 179 | common.infoMsg("Attempt to run test against distribRevision: ${distribRevision}") |
| 180 | try { |
| 181 | def config = [ |
Denis Egorenko | 926bc7d | 2019-02-19 14:27:34 +0400 | [diff] [blame] | 182 | 'dockerHostname' : "${context['salt_master_hostname']}", |
| 183 | 'domain' : "${context['cluster_domain']}", |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 184 | 'reclassEnv' : testEnv, |
| 185 | 'distribRevision' : distribRevision, |
| 186 | 'dockerContainerName': DockerCName, |
Denis Egorenko | d87490e | 2019-02-26 20:00:41 +0400 | [diff] [blame] | 187 | 'testContext' : 'salt-model-node', |
Aleksey Zvyagintsev | 2f8283e | 2019-02-27 21:43:15 +0000 | [diff] [blame] | 188 | 'dockerExtraOpts' : [ '--memory=3g' ] |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 189 | ] |
| 190 | testResult = saltModelTesting.testNode(config) |
| 191 | common.infoMsg("Test finished: SUCCESS") |
| 192 | } catch (Exception ex) { |
| 193 | common.warningMsg("Test finished: FAILED") |
| 194 | testResult = false |
| 195 | } |
| 196 | } else { |
| 197 | common.warningMsg("Test stage has been skipped!") |
| 198 | } |
| 199 | } |
| 200 | stage("Generate config drives") { |
| 201 | // apt package genisoimage is required for this stage |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 202 | // download create-config-drive |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 203 | def commonScriptsRepoUrl = context['mcp_common_scripts_repo'] ?: 'ssh://gerrit.mcp.mirantis.com:29418/mcp/mcp-common-scripts' |
| 204 | checkout([ |
| 205 | $class : 'GitSCM', |
| 206 | branches : [[name: 'FETCH_HEAD'],], |
| 207 | extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'mcp-common-scripts']], |
azvyagintsev | 866b19a | 2018-11-20 18:21:43 +0200 | [diff] [blame] | 208 | userRemoteConfigs: [[url: commonScriptsRepoUrl, refspec: context['mcp_common_scripts_branch'], credentialsId: gerritCredentials],], |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 209 | ]) |
| 210 | |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 211 | def outdateGeneration = false |
| 212 | if (fileExists('mcp-common-scripts/config-drive/create_config_drive.py')) { |
| 213 | sh 'cp mcp-common-scripts/config-drive/create_config_drive.py create-config-drive.py' |
| 214 | } else { |
| 215 | outdateGeneration = true |
| 216 | sh 'cp mcp-common-scripts/config-drive/create_config_drive.sh create-config-drive && chmod +x create-config-drive' |
| 217 | } |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 218 | 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' |
| 219 | |
| 220 | sh "git clone --mirror https://github.com/Mirantis/mk-pipelines.git ${pipelineEnv}/mk-pipelines" |
| 221 | 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] | 222 | args = [ |
| 223 | "--user-data user_data", , "--model ${modelEnv}", |
| 224 | "--mk-pipelines ${pipelineEnv}/mk-pipelines/", "--pipeline-library ${pipelineEnv}/pipeline-library/" |
| 225 | ] |
Dmitry Pyzhov | 089fb4f | 2018-12-11 16:58:00 +0300 | [diff] [blame] | 226 | if (context['secrets_encryption_enabled'] == 'True') { |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 227 | args.add('--gpg-key gpgkey.asc') |
Dmitry Pyzhov | 089fb4f | 2018-12-11 16:58:00 +0300 | [diff] [blame] | 228 | } |
Stanislav Riazanov | da45ea0 | 2018-12-21 16:12:50 +0400 | [diff] [blame] | 229 | if (context.get('cfg_failsafe_ssh_public_key')) { |
Denis Egorenko | aaeda9b | 2019-02-28 20:55:59 +0400 | [diff] [blame^] | 230 | if (outdateGeneration) { |
| 231 | args.add('--ssh-key failsafe-ssh-key.pub') |
| 232 | } else { |
| 233 | args.add('--ssh-keys failsafe-ssh-key.pub') |
| 234 | } |
Stanislav Riazanov | da45ea0 | 2018-12-21 16:12:50 +0400 | [diff] [blame] | 235 | } |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 236 | // load data from model |
| 237 | def smc = [:] |
| 238 | smc['SALT_MASTER_MINION_ID'] = "${context['salt_master_hostname']}.${context['cluster_domain']}" |
| 239 | smc['SALT_MASTER_DEPLOY_IP'] = context['salt_master_management_address'] |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 240 | if (outdateGeneration) { |
| 241 | smc['DEPLOY_NETWORK_GW'] = context['deploy_network_gateway'] |
| 242 | smc['DEPLOY_NETWORK_NETMASK'] = context['deploy_network_netmask'] |
| 243 | if (context.get('deploy_network_mtu')) { |
| 244 | smc['DEPLOY_NETWORK_MTU'] = context['deploy_network_mtu'] |
| 245 | } |
| 246 | smc['DNS_SERVERS'] = context['dns_server01'] |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 247 | } |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 248 | smc['MCP_VERSION'] = "${context['mcp_version']}" |
| 249 | if (context['local_repositories'] == 'True') { |
Denis Egorenko | 6bfa755 | 2019-02-05 19:09:25 +0400 | [diff] [blame] | 250 | def localRepoIP = '' |
Denis Egorenko | f97aec2 | 2019-02-05 14:57:33 +0400 | [diff] [blame] | 251 | 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] | 252 | localRepoIP = context['local_repo_url'] |
Denis Egorenko | f97aec2 | 2019-02-05 14:57:33 +0400 | [diff] [blame] | 253 | smc['MCP_SALT_REPO_URL'] = "http://${localRepoIP}/ubuntu-xenial" |
| 254 | } else { |
Denis Egorenko | 6bfa755 | 2019-02-05 19:09:25 +0400 | [diff] [blame] | 255 | localRepoIP = context['aptly_server_deploy_address'] |
Denis Egorenko | f97aec2 | 2019-02-05 14:57:33 +0400 | [diff] [blame] | 256 | smc['MCP_SALT_REPO_URL'] = "http://${localRepoIP}" |
| 257 | } |
Denis Egorenko | 6bfa755 | 2019-02-05 19:09:25 +0400 | [diff] [blame] | 258 | smc['MCP_SALT_REPO_KEY'] = "http://${localRepoIP}/public.gpg" |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 259 | smc['PIPELINES_FROM_ISO'] = 'false' |
| 260 | smc['PIPELINE_REPO_URL'] = "http://${localRepoIP}:8088" |
| 261 | smc['LOCAL_REPOS'] = 'true' |
| 262 | } |
| 263 | if (context['upstream_proxy_enabled'] == 'True') { |
| 264 | if (context['upstream_proxy_auth_enabled'] == 'True') { |
| 265 | smc['http_proxy'] = 'http://' + context['upstream_proxy_user'] + ':' + context['upstream_proxy_password'] + '@' + context['upstream_proxy_address'] + ':' + context['upstream_proxy_port'] |
| 266 | smc['https_proxy'] = 'http://' + context['upstream_proxy_user'] + ':' + context['upstream_proxy_password'] + '@' + context['upstream_proxy_address'] + ':' + context['upstream_proxy_port'] |
| 267 | } else { |
| 268 | smc['http_proxy'] = 'http://' + context['upstream_proxy_address'] + ':' + context['upstream_proxy_port'] |
| 269 | smc['https_proxy'] = 'http://' + context['upstream_proxy_address'] + ':' + context['upstream_proxy_port'] |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | for (i in common.entries(smc)) { |
| 274 | sh "sed -i 's,${i[0]}=.*,${i[0]}=${i[1]},' user_data" |
| 275 | } |
| 276 | |
| 277 | // create cfg config-drive |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 278 | if (outdateGeneration) { |
| 279 | args += [ "--hostname ${context['salt_master_hostname']}", "${context['salt_master_hostname']}.${context['cluster_domain']}-config.iso" ] |
| 280 | sh "./create-config-drive ${args.join(' ')}" |
| 281 | } else { |
| 282 | args += [ |
| 283 | "--name ${context['salt_master_hostname']}", "--hostname ${context['salt_master_hostname']}.${context['cluster_domain']}", "--clean-up", |
Denis Egorenko | aaeda9b | 2019-02-28 20:55:59 +0400 | [diff] [blame^] | 284 | "--ip ${context['salt_master_management_address']}", "--netmask ${context['deploy_network_netmask']}", "--gateway ${context['deploy_network_gateway']}", |
| 285 | "--dns-nameservers ${context['dns_server01']},${context['dns_server02']}" |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 286 | ] |
| 287 | sh "python ./create-config-drive.py ${args.join(' ')}" |
| 288 | } |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 289 | sh("mkdir output-${context['cluster_name']} && mv ${context['salt_master_hostname']}.${context['cluster_domain']}-config.iso output-${context['cluster_name']}/") |
| 290 | |
| 291 | // save cfg iso to artifacts |
| 292 | archiveArtifacts artifacts: "output-${context['cluster_name']}/${context['salt_master_hostname']}.${context['cluster_domain']}-config.iso" |
| 293 | |
| 294 | if (context['local_repositories'] == 'True') { |
| 295 | def aptlyServerHostname = context.aptly_server_hostname |
| 296 | 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" |
| 297 | |
| 298 | def smc_apt = [:] |
| 299 | smc_apt['SALT_MASTER_DEPLOY_IP'] = context['salt_master_management_address'] |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 300 | if (outdateGeneration) { |
| 301 | smc_apt['APTLY_DEPLOY_IP'] = context['aptly_server_deploy_address'] |
| 302 | smc_apt['APTLY_DEPLOY_NETMASK'] = context['deploy_network_netmask'] |
| 303 | } |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 304 | smc_apt['APTLY_MINION_ID'] = "${aptlyServerHostname}.${context['cluster_domain']}" |
| 305 | |
| 306 | for (i in common.entries(smc_apt)) { |
| 307 | sh "sed -i \"s,export ${i[0]}=.*,export ${i[0]}=${i[1]},\" mirror_config" |
| 308 | } |
| 309 | |
| 310 | // create apt config-drive |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 311 | if (outdateGeneration) { |
| 312 | sh "./create-config-drive --user-data mirror_config --hostname ${aptlyServerHostname} ${aptlyServerHostname}.${context['cluster_domain']}-config.iso" |
| 313 | } else { |
| 314 | args = [ |
| 315 | "--ip ${context['aptly_server_deploy_address']}", "--netmask ${context['deploy_network_netmask']}", "--gateway ${context['deploy_network_gateway']}", |
Denis Egorenko | aaeda9b | 2019-02-28 20:55:59 +0400 | [diff] [blame^] | 316 | "--user-data mirror_config", "--hostname ${aptlyServerHostname}.${context['cluster_domain']}", "--name ${aptlyServerHostname}", "--clean-up", |
| 317 | "--dns-nameservers ${context['dns_server01']},${context['dns_server02']}" |
Denis Egorenko | aeaa013 | 2019-02-25 16:55:08 +0400 | [diff] [blame] | 318 | ] |
| 319 | sh "python ./create-config-drive.py ${args.join(' ')}" |
| 320 | } |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 321 | sh("mv ${aptlyServerHostname}.${context['cluster_domain']}-config.iso output-${context['cluster_name']}/") |
| 322 | |
| 323 | // save apt iso to artifacts |
| 324 | archiveArtifacts artifacts: "output-${context['cluster_name']}/${aptlyServerHostname}.${context['cluster_domain']}-config.iso" |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | stage('Save changes reclass model') { |
| 329 | sh(returnStatus: true, script: "tar -czf output-${context['cluster_name']}/${context['cluster_name']}.tar.gz --exclude='*@tmp' -C ${modelEnv} .") |
| 330 | archiveArtifacts artifacts: "output-${context['cluster_name']}/${context['cluster_name']}.tar.gz" |
| 331 | |
azvyagintsev | 5400d1d | 2018-12-11 13:19:29 +0200 | [diff] [blame] | 332 | if (RequesterEmail != '' && !RequesterEmail.contains('example')) { |
azvyagintsev | 6d678da | 2018-11-28 21:19:06 +0200 | [diff] [blame] | 333 | emailext(to: RequesterEmail, |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 334 | attachmentsPattern: "output-${context['cluster_name']}/*", |
| 335 | body: "Mirantis Jenkins\n\nRequested reclass model ${context['cluster_name']} has been created and attached to this email.\nEnjoy!\n\nMirantis", |
| 336 | subject: "Your Salt model ${context['cluster_name']}") |
| 337 | } |
| 338 | dir("output-${context['cluster_name']}") { |
| 339 | deleteDir() |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | // Fail, but leave possibility to get failed artifacts |
azvyagintsev | 6d678da | 2018-11-28 21:19:06 +0200 | [diff] [blame] | 344 | if (!testResult && runTestModel) { |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 345 | common.warningMsg('Test finished: FAILURE. Please check logs and\\or debug failed model manually!') |
| 346 | error('Test stage finished: FAILURE') |
| 347 | } |
| 348 | |
| 349 | } catch (Throwable e) { |
| 350 | currentBuild.result = "FAILURE" |
| 351 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 352 | throw e |
| 353 | } finally { |
| 354 | stage('Clean workspace directories') { |
Aleksey Zvyagintsev | 7ca28d2 | 2019-02-25 11:05:49 +0000 | [diff] [blame] | 355 | sh(script: 'find . -mindepth 1 -delete > /dev/null || true') |
Aleksey Zvyagintsev | b16902d | 2018-10-29 12:33:48 +0000 | [diff] [blame] | 356 | } |
| 357 | // common.sendNotification(currentBuild.result,"",["slack"]) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 358 | } |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 359 | } |
Mikhail Ivanov | 9f81292 | 2017-11-07 18:52:02 +0400 | [diff] [blame] | 360 | } |