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. |
Tomáš Kukrál | 91e4925 | 2017-05-09 14:40:26 +0200 | [diff] [blame] | 6 | * EMAIL_ADDRESS Email to send a created tar file |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 7 | * |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 8 | **/ |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 9 | |
| 10 | common = new com.mirantis.mk.Common() |
| 11 | git = new com.mirantis.mk.Git() |
| 12 | python = new com.mirantis.mk.Python() |
chnyda | 8919101 | 2017-05-29 15:38:35 +0200 | [diff] [blame] | 13 | saltModelTesting = new com.mirantis.mk.SaltModelTesting() |
Tomáš Kukrál | cebc1a0 | 2017-07-25 16:10:37 +0200 | [diff] [blame] | 14 | ssh = new com.mirantis.mk.Ssh() |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 15 | |
Vasyl Saienko | 682043d | 2018-07-23 16:04:10 +0300 | [diff] [blame] | 16 | def reclassVersion = 'v1.5.4' |
Vasyl Saienko | 772e123 | 2018-07-23 14:42:24 +0300 | [diff] [blame] | 17 | if (common.validInputParam('RECLASS_VERSION')) { |
| 18 | reclassVersion = RECLASS_VERSION |
| 19 | } |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 20 | slaveNode = (env.SLAVE_NODE ?: 'python&&docker') |
Vasyl Saienko | 772e123 | 2018-07-23 14:42:24 +0300 | [diff] [blame] | 21 | |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 22 | // install extra formulas required only for rendering cfg01. All others - should be fetched automatically via |
| 23 | // salt.master.env state, during salt-master bootstrap. |
| 24 | // TODO: In the best - those data should fetched somewhere from CC, per env\context. Like option, process _enabled |
| 25 | // options from CC contexts |
| 26 | // currently, just mix them together in one set |
| 27 | def testCfg01ExtraFormulas = 'glusterfs jenkins logrotate maas ntp rsyslog fluentd telegraf prometheus ' + |
| 28 | 'grafana backupninja auditd' |
| 29 | |
| 30 | |
| 31 | timeout(time: 2, unit: 'HOURS') { |
| 32 | node(slaveNode) { |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 33 | def templateEnv = "${env.WORKSPACE}/template" |
| 34 | def modelEnv = "${env.WORKSPACE}/model" |
| 35 | def testEnv = "${env.WORKSPACE}/test" |
| 36 | def pipelineEnv = "${env.WORKSPACE}/pipelines" |
Tomáš Kukrál | 9f6260f | 2017-03-29 23:58:26 +0200 | [diff] [blame] | 37 | |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 38 | try { |
| 39 | def templateContext = readYaml text: COOKIECUTTER_TEMPLATE_CONTEXT |
| 40 | def mcpVersion = templateContext.default_context.mcp_version |
| 41 | def sharedReclassUrl = templateContext.default_context.shared_reclass_url |
| 42 | def clusterDomain = templateContext.default_context.cluster_domain |
| 43 | def clusterName = templateContext.default_context.cluster_name |
| 44 | def saltMaster = templateContext.default_context.salt_master_hostname |
| 45 | def localRepositories = templateContext.default_context.local_repositories.toBoolean() |
| 46 | def offlineDeployment = templateContext.default_context.offline_deployment.toBoolean() |
| 47 | def cutterEnv = "${env.WORKSPACE}/cutter" |
| 48 | def jinjaEnv = "${env.WORKSPACE}/jinja" |
| 49 | def outputDestination = "${modelEnv}/classes/cluster/${clusterName}" |
| 50 | def systemEnv = "${modelEnv}/classes/system" |
| 51 | def targetBranch = "feature/${clusterName}" |
| 52 | def templateBaseDir = "${env.WORKSPACE}/template" |
| 53 | def templateDir = "${templateEnv}/template/dir" |
| 54 | def templateOutputDir = templateBaseDir |
| 55 | def user |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 56 | def testResult = false |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 57 | wrap([$class: 'BuildUser']) { |
| 58 | user = env.BUILD_USER_ID |
| 59 | } |
| 60 | |
| 61 | currentBuild.description = clusterName |
| 62 | print("Using context:\n" + COOKIECUTTER_TEMPLATE_CONTEXT) |
| 63 | |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 64 | stage('Download Cookiecutter template') { |
| 65 | sh(script: 'find . -mindepth 1 -delete > /dev/null || true') |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 66 | def cookiecutterTemplateUrl = templateContext.default_context.cookiecutter_template_url |
| 67 | def cookiecutterTemplateBranch = templateContext.default_context.cookiecutter_template_branch |
| 68 | git.checkoutGitRepository(templateEnv, cookiecutterTemplateUrl, 'master') |
| 69 | // Use refspec if exists first of all |
| 70 | if (cookiecutterTemplateBranch.toString().startsWith('refs/')) { |
| 71 | dir(templateEnv) { |
| 72 | ssh.agentSh("git fetch ${cookiecutterTemplateUrl} ${cookiecutterTemplateBranch} && git checkout FETCH_HEAD") |
| 73 | } |
| 74 | } else { |
| 75 | // Use mcpVersion git tag if not specified branch for cookiecutter-templates |
| 76 | if (cookiecutterTemplateBranch == '') { |
| 77 | cookiecutterTemplateBranch = mcpVersion |
| 78 | // Don't have nightly/testing/stable for cookiecutter-templates repo, therefore use master |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 79 | if ([ "nightly" , "testing", "stable" ].contains(mcpVersion)) { |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 80 | cookiecutterTemplateBranch = 'master' |
Tomáš Kukrál | a3f4ba7 | 2017-08-03 15:40:22 +0200 | [diff] [blame] | 81 | } |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 82 | } |
| 83 | git.changeGitBranch(templateEnv, cookiecutterTemplateBranch) |
| 84 | } |
| 85 | } |
Tomáš Kukrál | a3f4ba7 | 2017-08-03 15:40:22 +0200 | [diff] [blame] | 86 | |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 87 | stage('Create empty reclass model') { |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 88 | dir(path: modelEnv) { |
| 89 | sh "rm -rfv .git" |
| 90 | sh "git init" |
| 91 | ssh.agentSh("git submodule add ${sharedReclassUrl} 'classes/system'") |
| 92 | } |
Tomáš Kukrál | 0c6835d | 2017-07-18 16:00:27 +0200 | [diff] [blame] | 93 | |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 94 | def sharedReclassBranch = templateContext.default_context.shared_reclass_branch |
| 95 | // Use refspec if exists first of all |
| 96 | if (sharedReclassBranch.toString().startsWith('refs/')) { |
| 97 | dir(systemEnv) { |
| 98 | ssh.agentSh("git fetch ${sharedReclassUrl} ${sharedReclassBranch} && git checkout FETCH_HEAD") |
| 99 | } |
| 100 | } else { |
| 101 | // Use mcpVersion git tag if not specified branch for reclass-system |
| 102 | if (sharedReclassBranch == '') { |
| 103 | sharedReclassBranch = mcpVersion |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 104 | // Don't have nightly/testing for reclass-system repo, therefore use master |
| 105 | if ([ "nightly" , "testing", "stable" ].contains(mcpVersion)) { |
| 106 | common.warningMsg("Fetching reclass-system from master!") |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 107 | sharedReclassBranch = 'master' |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 108 | } |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 109 | } |
| 110 | git.changeGitBranch(systemEnv, sharedReclassBranch) |
| 111 | } |
| 112 | git.commitGitChanges(modelEnv, "Added new shared reclass submodule", "${user}@localhost", "${user}") |
| 113 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 114 | |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 115 | def productList = ["infra", "cicd", "opencontrail", "kubernetes", "openstack", "oss", "stacklight", "ceph"] |
| 116 | for (product in productList) { |
Richard Felkl | e77b091 | 2018-01-31 17:12:23 +0100 | [diff] [blame] | 117 | |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 118 | // get templateOutputDir and productDir |
| 119 | if (product.startsWith("stacklight")) { |
| 120 | templateOutputDir = "${env.WORKSPACE}/output/stacklight" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 121 | |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 122 | def stacklightVersion |
| 123 | try { |
| 124 | stacklightVersion = templateContext.default_context['stacklight_version'] |
| 125 | } catch (Throwable e) { |
| 126 | common.warningMsg('Stacklight version loading failed') |
| 127 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 128 | |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 129 | if (stacklightVersion) { |
| 130 | productDir = "stacklight" + stacklightVersion |
| 131 | } else { |
| 132 | productDir = "stacklight1" |
| 133 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 134 | |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 135 | } else { |
| 136 | templateOutputDir = "${env.WORKSPACE}/output/${product}" |
| 137 | productDir = product |
| 138 | } |
Richard Felkl | 9543faa | 2018-01-11 09:47:35 +0100 | [diff] [blame] | 139 | |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 140 | if (product == "infra" || (templateContext.default_context["${product}_enabled"] |
| 141 | && templateContext.default_context["${product}_enabled"].toBoolean())) { |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 142 | |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 143 | templateDir = "${templateEnv}/cluster_product/${productDir}" |
| 144 | common.infoMsg("Generating product " + product + " from " + templateDir + " to " + templateOutputDir) |
Tomáš Kukrál | a3f4ba7 | 2017-08-03 15:40:22 +0200 | [diff] [blame] | 145 | |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 146 | sh "rm -rf ${templateOutputDir} || true" |
| 147 | sh "mkdir -p ${templateOutputDir}" |
| 148 | sh "mkdir -p ${outputDestination}" |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 149 | |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 150 | python.setupCookiecutterVirtualenv(cutterEnv) |
| 151 | python.buildCookiecutterTemplate(templateDir, COOKIECUTTER_TEMPLATE_CONTEXT, templateOutputDir, cutterEnv, templateBaseDir) |
| 152 | sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}" |
| 153 | } else { |
| 154 | common.warningMsg("Product " + product + " is disabled") |
| 155 | } |
| 156 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 157 | |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 158 | if (localRepositories && !offlineDeployment) { |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 159 | def aptlyModelUrl = templateContext.default_context.local_model_url |
| 160 | dir(path: modelEnv) { |
| 161 | ssh.agentSh "git submodule add \"${aptlyModelUrl}\" \"classes/cluster/${clusterName}/cicd/aptly\"" |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 162 | if (!(mcpVersion in ["nightly", "testing", "stable"])) { |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 163 | ssh.agentSh "cd \"classes/cluster/${clusterName}/cicd/aptly\";git fetch --tags;git checkout ${mcpVersion}" |
| 164 | } |
| 165 | } |
| 166 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 167 | |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 168 | stage('Generate new SaltMaster node') { |
| 169 | def nodeFile = "${modelEnv}/nodes/${saltMaster}.${clusterDomain}.yml" |
| 170 | def nodeString = """classes: |
Leontii Istomin | 56b6b11 | 2018-01-15 12:14:24 +0300 | [diff] [blame] | 171 | - cluster.${clusterName}.infra.config |
| 172 | parameters: |
| 173 | _param: |
| 174 | linux_system_codename: xenial |
| 175 | reclass_data_revision: master |
| 176 | linux: |
| 177 | system: |
| 178 | name: ${saltMaster} |
| 179 | domain: ${clusterDomain} |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 180 | """ |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 181 | sh "mkdir -p ${modelEnv}/nodes/" |
| 182 | writeFile(file: nodeFile, text: nodeString) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 183 | |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 184 | git.commitGitChanges(modelEnv, "Create model ${clusterName}", "${user}@localhost", "${user}") |
| 185 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 186 | |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 187 | stage("Test") { |
| 188 | if (TEST_MODEL.toBoolean() && sharedReclassUrl != '') { |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 189 | sh("cp -r ${modelEnv} ${testEnv}") |
| 190 | def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}" |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 191 | common.infoMsg("Attempt to run test against formula-version: ${mcpVersion}") |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 192 | testResult = saltModelTesting.setupAndTestNode( |
| 193 | "${saltMaster}.${clusterDomain}", |
| 194 | "", |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 195 | testCfg01ExtraFormulas, |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 196 | testEnv, |
| 197 | 'pkg', |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 198 | mcpVersion, |
Vasyl Saienko | 772e123 | 2018-07-23 14:42:24 +0300 | [diff] [blame] | 199 | reclassVersion, |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 200 | 0, |
| 201 | false, |
| 202 | false, |
| 203 | '', |
| 204 | '', |
| 205 | DockerCName) |
| 206 | if (testResult) { |
| 207 | common.infoMsg("Test finished: SUCCESS") |
| 208 | } else { |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 209 | common.warningMsg('Test finished: FAILURE') |
azvyagintsev | 7c4a3cf | 2018-07-08 08:43:33 +0300 | [diff] [blame] | 210 | } |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 211 | } else { |
| 212 | common.warningMsg("Test stage has been skipped!") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 213 | } |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 214 | } |
| 215 | stage("Generate config drives") { |
| 216 | // apt package genisoimage is required for this stage |
| 217 | |
| 218 | // download create-config-drive |
| 219 | // FIXME: that should be refactored, to use git clone - to be able download it from custom repo. |
| 220 | def mcpCommonScriptsBranch = templateContext.default_context.mcp_common_scripts_branch |
| 221 | if (mcpCommonScriptsBranch == '') { |
| 222 | mcpCommonScriptsBranch = mcpVersion |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 223 | // Don't have n/t/s for mcp-common-scripts repo, therefore use master |
| 224 | if ([ "nightly" , "testing", "stable" ].contains(mcpVersion)) { |
| 225 | common.warningMsg("Fetching mcp-common-scripts from master!") |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 226 | mcpCommonScriptsBranch = 'master' |
| 227 | } |
| 228 | } |
| 229 | def config_drive_script_url = "https://raw.githubusercontent.com/Mirantis/mcp-common-scripts/${mcpCommonScriptsBranch}/config-drive/create_config_drive.sh" |
| 230 | def user_data_script_url = "https://raw.githubusercontent.com/Mirantis/mcp-common-scripts/${mcpCommonScriptsBranch}/config-drive/master_config.sh" |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 231 | common.retry(3, 5) { |
| 232 | sh "wget -O create-config-drive ${config_drive_script_url} && chmod +x create-config-drive" |
| 233 | sh "wget -O user_data.sh ${user_data_script_url}" |
| 234 | } |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 235 | |
| 236 | sh "git clone --mirror https://github.com/Mirantis/mk-pipelines.git ${pipelineEnv}/mk-pipelines" |
| 237 | sh "git clone --mirror https://github.com/Mirantis/pipeline-library.git ${pipelineEnv}/pipeline-library" |
| 238 | args = "--user-data user_data.sh --hostname ${saltMaster} --model ${modelEnv} --mk-pipelines ${pipelineEnv}/mk-pipelines/ --pipeline-library ${pipelineEnv}/pipeline-library/ ${saltMaster}.${clusterDomain}-config.iso" |
| 239 | |
| 240 | // load data from model |
| 241 | def smc = [:] |
| 242 | smc['SALT_MASTER_MINION_ID'] = "${saltMaster}.${clusterDomain}" |
| 243 | smc['SALT_MASTER_DEPLOY_IP'] = templateContext['default_context']['salt_master_management_address'] |
| 244 | smc['DEPLOY_NETWORK_GW'] = templateContext['default_context']['deploy_network_gateway'] |
| 245 | smc['DEPLOY_NETWORK_NETMASK'] = templateContext['default_context']['deploy_network_netmask'] |
| 246 | smc['DNS_SERVERS'] = templateContext['default_context']['dns_server01'] |
| 247 | smc['MCP_VERSION'] = "${mcpVersion}" |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 248 | if (templateContext['default_context']['local_repositories'] == 'True') { |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 249 | def localRepoIP = templateContext['default_context']['local_repo_url'] |
| 250 | smc['MCP_SALT_REPO_KEY'] = "http://${localRepoIP}/public.gpg" |
| 251 | smc['MCP_SALT_REPO_URL'] = "http://${localRepoIP}/ubuntu-xenial" |
| 252 | smc['PIPELINES_FROM_ISO'] = 'false' |
| 253 | smc['PIPELINE_REPO_URL'] = "http://${localRepoIP}:8088" |
| 254 | smc['LOCAL_REPOS'] = 'true' |
| 255 | } |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 256 | if (templateContext['default_context']['upstream_proxy_enabled'] == 'True') { |
| 257 | if (templateContext['default_context']['upstream_proxy_auth_enabled'] == 'True') { |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 258 | smc['http_proxy'] = 'http://' + templateContext['default_context']['upstream_proxy_user'] + ':' + templateContext['default_context']['upstream_proxy_password'] + '@' + templateContext['default_context']['upstream_proxy_address'] + ':' + templateContext['default_context']['upstream_proxy_port'] |
| 259 | smc['https_proxy'] = 'http://' + templateContext['default_context']['upstream_proxy_user'] + ':' + templateContext['default_context']['upstream_proxy_password'] + '@' + templateContext['default_context']['upstream_proxy_address'] + ':' + templateContext['default_context']['upstream_proxy_port'] |
| 260 | } else { |
| 261 | smc['http_proxy'] = 'http://' + templateContext['default_context']['upstream_proxy_address'] + ':' + templateContext['default_context']['upstream_proxy_port'] |
| 262 | smc['https_proxy'] = 'http://' + templateContext['default_context']['upstream_proxy_address'] + ':' + templateContext['default_context']['upstream_proxy_port'] |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | for (i in common.entries(smc)) { |
| 267 | sh "sed -i 's,export ${i[0]}=.*,export ${i[0]}=${i[1]},' user_data.sh" |
| 268 | } |
| 269 | |
| 270 | // create cfg config-drive |
| 271 | sh "./create-config-drive ${args}" |
| 272 | sh("mkdir output-${clusterName} && mv ${saltMaster}.${clusterDomain}-config.iso output-${clusterName}/") |
| 273 | |
| 274 | // save cfg iso to artifacts |
| 275 | archiveArtifacts artifacts: "output-${clusterName}/${saltMaster}.${clusterDomain}-config.iso" |
| 276 | |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 277 | if (templateContext['default_context']['local_repositories'] == 'True') { |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 278 | def aptlyServerHostname = templateContext.default_context.aptly_server_hostname |
| 279 | def user_data_script_apt_url = "https://raw.githubusercontent.com/Mirantis/mcp-common-scripts/master/config-drive/mirror_config.sh" |
| 280 | sh "wget -O mirror_config.sh ${user_data_script_apt_url}" |
| 281 | |
| 282 | def smc_apt = [:] |
| 283 | smc_apt['SALT_MASTER_DEPLOY_IP'] = templateContext['default_context']['salt_master_management_address'] |
| 284 | smc_apt['APTLY_DEPLOY_IP'] = templateContext['default_context']['aptly_server_deploy_address'] |
| 285 | smc_apt['APTLY_DEPLOY_NETMASK'] = templateContext['default_context']['deploy_network_netmask'] |
| 286 | smc_apt['APTLY_MINION_ID'] = "${aptlyServerHostname}.${clusterDomain}" |
| 287 | |
| 288 | for (i in common.entries(smc_apt)) { |
| 289 | sh "sed -i \"s,export ${i[0]}=.*,export ${i[0]}=${i[1]},\" mirror_config.sh" |
| 290 | } |
| 291 | |
| 292 | // create apt config-drive |
| 293 | sh "./create-config-drive --user-data mirror_config.sh --hostname ${aptlyServerHostname} ${aptlyServerHostname}.${clusterDomain}-config.iso" |
| 294 | sh("mv ${aptlyServerHostname}.${clusterDomain}-config.iso output-${clusterName}/") |
| 295 | |
| 296 | // save apt iso to artifacts |
| 297 | archiveArtifacts artifacts: "output-${clusterName}/${aptlyServerHostname}.${clusterDomain}-config.iso" |
| 298 | } |
| 299 | } |
| 300 | |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 301 | stage('Save changes reclass model') { |
| 302 | sh(returnStatus: true, script: "tar -czf output-${clusterName}/${clusterName}.tar.gz --exclude='*@tmp' -C ${modelEnv} .") |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 303 | archiveArtifacts artifacts: "output-${clusterName}/${clusterName}.tar.gz" |
| 304 | |
| 305 | |
| 306 | if (EMAIL_ADDRESS != null && EMAIL_ADDRESS != "") { |
| 307 | emailext(to: EMAIL_ADDRESS, |
| 308 | attachmentsPattern: "output-${clusterName}/*", |
| 309 | body: "Mirantis Jenkins\n\nRequested reclass model ${clusterName} has been created and attached to this email.\nEnjoy!\n\nMirantis", |
| 310 | subject: "Your Salt model ${clusterName}") |
| 311 | } |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 312 | dir("output-${clusterName}") { |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 313 | deleteDir() |
| 314 | } |
| 315 | } |
| 316 | |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 317 | // Fail, but leave possibility to get failed artifacts |
| 318 | if (!testResult && TEST_MODEL.toBoolean()) { |
| 319 | common.warningMsg('Test finished: FAILURE. Please check logs and\\or debug failed model manually!') |
| 320 | error('Test stage finished: FAILURE') |
| 321 | } |
| 322 | |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 323 | } catch (Throwable e) { |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 324 | currentBuild.result = "FAILURE" |
| 325 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 326 | throw e |
| 327 | } finally { |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame^] | 328 | stage('Clean workspace directories') { |
| 329 | sh(script: 'find . -mindepth 1 -delete > /dev/null || true') |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 330 | } |
| 331 | // common.sendNotification(currentBuild.result,"",["slack"]) |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 332 | } |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 333 | } |
Mikhail Ivanov | 9f81292 | 2017-11-07 18:52:02 +0400 | [diff] [blame] | 334 | } |