blob: 74d7cde9e7532c7b0c71209388e359568b6c249d [file] [log] [blame]
Ales Komarek24097402017-05-22 16:28:10 +02001/**
2 *
Tomáš Kukrál0d00dd22017-07-27 14:28:36 +02003 * Launch stack and work with it
Ales Komarek24097402017-05-22 16:28:10 +02004 *
5 * Expected parameters:
6 * STACK_NAME Infrastructure stack name
Tomáš Kukrál4691f682017-07-27 16:36:12 +02007 * STACK_TEMPLATE File with stack template
8 * STACK_TYPE Deploy OpenStack/AWS [heat/aws], use 'physical' if no stack should be started
Ales Komarek24097402017-05-22 16:28:10 +02009 *
10 * STACK_TEMPLATE_URL URL to git repo with stack templates
11 * STACK_TEMPLATE_CREDENTIALS Credentials to the templates repo
12 * STACK_TEMPLATE_BRANCH Stack templates repo branch
13 *
14 * STACK_DELETE Delete stack when finished (bool)
Tomáš Kukrál4691f682017-07-27 16:36:12 +020015 * STACK_REUSE Reuse existing stack (don't create one, only read outputs)
Ales Komarek24097402017-05-22 16:28:10 +020016 * STACK_INSTALL What should be installed (k8s, openstack, ...)
17 * STACK_TEST Run tests (bool)
18 * STACK_CLEANUP_JOB Name of job for deleting stack
19 *
Tomáš Kukrál74f92862017-06-05 19:18:43 +020020 * STACK_COMPUTE_COUNT Number of compute nodes to launch
Jiri Broulik61b3e5d2017-12-19 15:42:30 +010021 * STATIC_MGMT_NETWORK Check if model contains static IP address definitions for all nodes
Tomáš Kukrál74f92862017-06-05 19:18:43 +020022 *
Ales Komarek24097402017-05-22 16:28:10 +020023 * AWS_STACK_REGION CloudFormation AWS region
24 * AWS_API_CREDENTIALS AWS Access key ID with AWS secret access key
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020025 * AWS_SSH_KEY AWS key pair name (used for SSH access)
Ales Komarek24097402017-05-22 16:28:10 +020026 *
27 * HEAT_STACK_ENVIRONMENT Heat stack environmental parameters
28 * HEAT_STACK_ZONE Heat stack availability zone
29 * HEAT_STACK_PUBLIC_NET Heat stack floating IP pool
30 * OPENSTACK_API_URL OpenStack API address
31 * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
32 * OPENSTACK_API_PROJECT OpenStack project to connect to
33 * OPENSTACK_API_CLIENT Versions of OpenStack python clients
34 * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
Oleh Hryhorov9630a762017-10-24 14:33:25 +030035 * SLAVE_NODE Lable or node name where the job will be run
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020036
Ales Komarek24097402017-05-22 16:28:10 +020037 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
Tomáš Kukrál4691f682017-07-27 16:36:12 +020038 * required for STACK_TYPE=physical
Ales Komarek24097402017-05-22 16:28:10 +020039 * SALT_MASTER_URL URL of Salt master
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020040
Oleg Iurchenko9a8c3d72017-12-21 14:55:38 +020041 * BOOTSTRAP_EXTRA_REPO_PARAMS optional parameter to define a list of extra repos with parameters
42 * which have to be added during bootstrap.
43 * Format: repo 1, repo priority 1, repo pin 1; repo 2, repo priority 2, repo pin 2;
44
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020045 * Test settings:
46 * TEST_K8S_API_SERVER Kubernetes API address
47 * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
Ales Komarek24097402017-05-22 16:28:10 +020048 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020049 * TEST_DOCKER_INSTALL Install docker on the target if true
50 * TEST_TEMPEST_IMAGE Tempest image link
51 * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only
52 * TEST_TEMPEST_TARGET Salt target for tempest node
Ales Komarek24097402017-05-22 16:28:10 +020053 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020054 * optional parameters for overwriting soft params
55 * SALT_OVERRIDES YAML with overrides for Salt deployment
Ales Komarek24097402017-05-22 16:28:10 +020056 *
57 */
Tomáš Kukrál3a17dd62017-07-27 18:24:16 +020058
Ales Komarek24097402017-05-22 16:28:10 +020059common = new com.mirantis.mk.Common()
60git = new com.mirantis.mk.Git()
61openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020062aws = new com.mirantis.mk.Aws()
Ales Komarek24097402017-05-22 16:28:10 +020063orchestrate = new com.mirantis.mk.Orchestrate()
Mykyta Karpine016d7e2017-10-09 13:35:20 +030064python = new com.mirantis.mk.Python()
Ales Komarek24097402017-05-22 16:28:10 +020065salt = new com.mirantis.mk.Salt()
66test = new com.mirantis.mk.Test()
67
68_MAX_PERMITTED_STACKS = 2
69overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
70
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020071// Define global variables
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020072def venv
chnyda597fb032017-10-06 13:42:48 +020073def venvPepper
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020074def outputs = [:]
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020075
chnydae14058a2017-08-29 15:07:48 +020076def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
77
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020078if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020079 def aws_env_vars
Tomáš Kukrál8427ff52017-08-30 15:46:52 +020080} else if (STACK_TYPE == 'heat') {
81 def envParams
82 def openstackCloud
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020083}
84
Oleh Hryhorov9630a762017-10-24 14:33:25 +030085def slave_node = 'python'
86
Oleh Hryhorov54460512017-10-26 18:45:36 +030087if (common.validInputParam('SLAVE_NODE')) {
Oleh Hryhorov9630a762017-10-24 14:33:25 +030088 slave_node = SLAVE_NODE
89}
90
91node(slave_node) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040092 try {
93 // Set build-specific variables
94 venv = "${env.WORKSPACE}/venv"
chnyda597fb032017-10-06 13:42:48 +020095 venvPepper = "${env.WORKSPACE}/venvPepper"
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020096
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040097 //
98 // Prepare machines
99 //
100 stage ('Create infrastructure') {
Ales Komarek24097402017-05-22 16:28:10 +0200101
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200102 outputs.put('stack_type', STACK_TYPE)
103
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400104 if (STACK_TYPE == 'heat') {
105 // value defaults
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200106 envParams = [
107 'cluster_zone': HEAT_STACK_ZONE,
108 'cluster_public_net': HEAT_STACK_PUBLIC_NET
109 ]
Ales Komarek24097402017-05-22 16:28:10 +0200110
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400111 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
112 error("If you want to reuse existing stack you need to provide it's name")
113 }
114
115 if (STACK_REUSE.toBoolean() == false) {
116 // Don't allow to set custom heat stack name
117 wrap([$class: 'BuildUser']) {
118 if (env.BUILD_USER_ID) {
119 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
120 } else {
121 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
122 }
123 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200124 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400125 }
Ales Komarek24097402017-05-22 16:28:10 +0200126
Tomáš Kukrál86b9ab22017-09-05 16:55:58 +0200127 // no underscore in STACK_NAME
128 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Tomáš Kukrál77b1b5a2017-09-24 18:56:49 +0200129 outputs.put('stack_name', STACK_NAME)
Tomáš Kukrál86b9ab22017-09-05 16:55:58 +0200130
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400131 // set description
132 currentBuild.description = "${STACK_NAME}"
133
134 // get templates
135 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
136
137 // create openstack env
138 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
139 openstackCloud = openstack.createOpenstackEnv(
140 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
141 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
142 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
143 OPENSTACK_API_VERSION)
144 openstack.getKeystoneToken(openstackCloud, venv)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200145
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400146 //
147 // Verify possibility of create stack for given user and stack type
148 //
149 wrap([$class: 'BuildUser']) {
150 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
Oleh Hryhorov8e320ca2017-09-22 13:23:44 +0300151 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200152 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400153 STACK_DELETE = "false"
154 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
155 }
156 }
157 }
158 // launch stack
159 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400160
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200161 // set reclass repo in heat env
162 try {
163 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
164 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
165 } catch (MissingPropertyException e) {
166 common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400167 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200168
Mykyta Karpin8f961132017-09-22 12:06:44 +0300169 // put formulas revision - stable, testing or nightly
170 if (common.validInputParam('FORMULA_PKG_REVISION')) {
171 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
172 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
173 }
174
Oleg Iurchenko9a8c3d72017-12-21 14:55:38 +0200175 // put extra repo definitions
176 if (common.validInputParam('BOOTSTRAP_EXTRA_REPO_PARAMS')) {
177 common.infoMsg("Setting additional repo during bootstrap to ${BOOTSTRAP_EXTRA_REPO_PARAMS}")
178 envParams.put('cfg_bootstrap_extra_repo_params', BOOTSTRAP_EXTRA_REPO_PARAMS)
179 }
180
ibumarskov4209d752017-11-22 13:04:54 +0400181 // put extra salt-formulas
182 if (common.validInputParam('EXTRA_FORMULAS')) {
183 common.infoMsg("Setting extra salt-formulas to ${EXTRA_FORMULAS}")
184 envParams.put('cfg_extra_formulas', EXTRA_FORMULAS)
185 }
186
Mykyta Karpin0aa35d52017-08-28 11:44:42 +0300187 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400188 }
189
190 // get SALT_MASTER_URL
191 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
chnydae14058a2017-08-29 15:07:48 +0200192 // check that saltMasterHost is valid
193 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
194 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
195 throw new Exception("saltMasterHost is not a valid ip")
196 }
197
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400198 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
199
200 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
201
202 } else if (STACK_TYPE == 'aws') {
203
204 // setup environment
205 aws.setupVirtualEnv(venv)
206
207 // set aws_env_vars
208 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
209
210 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
211 error("If you want to reuse existing stack you need to provide it's name")
212 }
213
214 if (STACK_REUSE.toBoolean() == false) {
215 // Don't allow to set custom stack name
216 wrap([$class: 'BuildUser']) {
217 if (env.BUILD_USER_ID) {
218 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
219 } else {
220 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
Ales Komarek24097402017-05-22 16:28:10 +0200221 }
222 }
223
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400224 // no underscore in STACK_NAME
225 STACK_NAME = STACK_NAME.replaceAll('_', '-')
226 }
Ales Komarek24097402017-05-22 16:28:10 +0200227
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400228 // set description
229 currentBuild.description = STACK_NAME
Tomáš Kukrál77b1b5a2017-09-24 18:56:49 +0200230 outputs.put('stack_name', STACK_NAME)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400231
232 if (STACK_REUSE.toBoolean() == false) {
Ales Komarek24097402017-05-22 16:28:10 +0200233 // get templates
234 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
235
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400236 // start stack
237 def stack_params = [
238 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
239 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
240 ]
241 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
242 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200243 }
Ales Komarek24097402017-05-22 16:28:10 +0200244
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400245 // wait for stack to be ready
246 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
247
248 // get outputs
249 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200250
chnydae14058a2017-08-29 15:07:48 +0200251 // check that saltMasterHost is valid
252 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
253 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
254 throw new Exception("saltMasterHost is not a valid ip")
255 }
256
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200257 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400258 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
259
260 } else if (STACK_TYPE != 'physical') {
261 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
Ales Komarek24097402017-05-22 16:28:10 +0200262 }
263
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200264 outputs.put('salt_api', SALT_MASTER_URL)
265
chnyda597fb032017-10-06 13:42:48 +0200266 // Setup virtualenv for pepper
267 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400268 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200269
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400270
271 // Set up override params
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200272 if (common.validInputParam('SALT_OVERRIDES')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400273 stage('Set Salt overrides') {
chnyda597fb032017-10-06 13:42:48 +0200274 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES)
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200275 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400276 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200277
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400278 //
279 // Install
280 //
Ales Komarek24097402017-05-22 16:28:10 +0200281
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400282 if (common.checkContains('STACK_INSTALL', 'core')) {
283 stage('Install core infrastructure') {
Oleg Iurchenko2f234c22017-12-20 12:48:55 +0200284 def staticMgmtNetwork = false
285 if (common.validInputParam('STATIC_MGMT_NETWORK')) {
286 staticMgmtNetwork = STATIC_MGMT_NETWORK.toBoolean()
287 }
288 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400289
290 if (common.checkContains('STACK_INSTALL', 'kvm')) {
chnyda597fb032017-10-06 13:42:48 +0200291 orchestrate.installInfraKvm(venvPepper)
Oleg Iurchenko2f234c22017-12-20 12:48:55 +0200292 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400293 }
Ales Komarek24097402017-05-22 16:28:10 +0200294
chnyda597fb032017-10-06 13:42:48 +0200295 orchestrate.validateFoundationInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400296 }
297 }
Ales Komarek24097402017-05-22 16:28:10 +0200298
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200299 // install ceph
300 if (common.checkContains('STACK_INSTALL', 'ceph')) {
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200301 stage('Install Ceph MONs') {
chnyda597fb032017-10-06 13:42:48 +0200302 orchestrate.installCephMon(venvPepper)
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200303 }
304
305 stage('Install Ceph OSDs') {
chnyda597fb032017-10-06 13:42:48 +0200306 orchestrate.installCephOsd(venvPepper)
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200307 }
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200308
Tomáš Kukrál0cc01092017-08-28 18:25:00 +0200309
310 stage('Install Ceph clients') {
chnyda597fb032017-10-06 13:42:48 +0200311 orchestrate.installCephClient(venvPepper)
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200312 }
Jiri Broulik8c380032017-10-06 13:36:03 +0200313
314 stage('Connect Ceph') {
chnyda625f4b42017-10-11 14:10:31 +0200315 orchestrate.connectCeph(venvPepper)
Jiri Broulik8c380032017-10-06 13:36:03 +0200316 }
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200317 }
318
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400319 // install k8s
320 if (common.checkContains('STACK_INSTALL', 'k8s')) {
321
322 stage('Install Kubernetes infra') {
323 if (STACK_TYPE == 'aws') {
324 // configure kubernetes_control_address - save loadbalancer
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200325 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
Tomáš Kukrál685f3b82017-09-03 10:14:40 +0200326 common.prettyPrint(awsOutputs)
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200327 if (awsOutputs.containsKey('ControlLoadBalancer')) {
chnyda597fb032017-10-06 13:42:48 +0200328 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200329 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
330 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400331 }
332
333 // ensure certificates are generated properly
chnyda597fb032017-10-06 13:42:48 +0200334 salt.runSaltProcessStep(venvPepper, '*', 'saltutil.refresh_pillar', [], null, true)
335 salt.enforceState(venvPepper, '*', ['salt.minion.cert'], true)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400336
chnyda597fb032017-10-06 13:42:48 +0200337 orchestrate.installKubernetesInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400338 }
339
340 if (common.checkContains('STACK_INSTALL', 'contrail')) {
341 stage('Install Contrail for Kubernetes') {
chnyda597fb032017-10-06 13:42:48 +0200342 orchestrate.installContrailNetwork(venvPepper)
343 orchestrate.installContrailCompute(venvPepper)
Ales Komarek24097402017-05-22 16:28:10 +0200344 }
345 }
346
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400347 stage('Install Kubernetes control') {
chnyda597fb032017-10-06 13:42:48 +0200348 orchestrate.installKubernetesControl(venvPepper)
Tomáš Kukrál7e487062017-08-31 11:20:08 +0200349
350 // collect artifacts (kubeconfig)
chnyda597fb032017-10-06 13:42:48 +0200351 writeFile(file: 'kubeconfig', text: salt.getFileContent(venvPepper, 'I@kubernetes:master and *01*', '/etc/kubernetes/admin-kube-config'))
Tomáš Kukrál7e487062017-08-31 11:20:08 +0200352 archiveArtifacts(artifacts: 'kubeconfig')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400353 }
354
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100355 stage('Install Kubernetes computes') {
356 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
357 if (STACK_COMPUTE_COUNT > 0) {
358 if (STACK_TYPE == 'aws') {
359 // get stack info
360 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400361
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100362 //update autoscaling group
363 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400364
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100365 // wait for computes to boot up
366 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
367 sleep(60)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200368
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100369 } else if (STACK_TYPE == 'heat') {
370 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200371
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100372 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
373 sleep(60)
374 }
375
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200376 }
Ales Komarek24097402017-05-22 16:28:10 +0200377 }
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100378
379 orchestrate.installKubernetesCompute(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400380 }
381 }
382
383 // install openstack
384 if (common.checkContains('STACK_INSTALL', 'openstack')) {
385 // install Infra and control, tests, ...
386
387 stage('Install OpenStack infra') {
chnyda597fb032017-10-06 13:42:48 +0200388 orchestrate.installOpenstackInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400389 }
390
391 stage('Install OpenStack control') {
chnyda597fb032017-10-06 13:42:48 +0200392 orchestrate.installOpenstackControl(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400393 }
394
395 stage('Install OpenStack network') {
Ales Komarek24097402017-05-22 16:28:10 +0200396
vrovachev7be1e962017-07-05 13:28:26 +0400397 if (common.checkContains('STACK_INSTALL', 'contrail')) {
chnyda597fb032017-10-06 13:42:48 +0200398 orchestrate.installContrailNetwork(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400399 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
chnyda597fb032017-10-06 13:42:48 +0200400 orchestrate.installOpenstackNetwork(venvPepper)
vrovachev7be1e962017-07-05 13:28:26 +0400401 }
402
chnyda597fb032017-10-06 13:42:48 +0200403 salt.runSaltProcessStep(venvPepper, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
404 salt.runSaltProcessStep(venvPepper, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400405 }
Ales Komarek24097402017-05-22 16:28:10 +0200406
chnyda597fb032017-10-06 13:42:48 +0200407 if (salt.testTarget(venvPepper, 'I@ironic:conductor')){
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400408 stage('Install OpenStack Ironic conductor') {
chnyda597fb032017-10-06 13:42:48 +0200409 orchestrate.installIronicConductor(venvPepper)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200410 }
Ales Komarek24097402017-05-22 16:28:10 +0200411 }
412
Ales Komarek24097402017-05-22 16:28:10 +0200413
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400414 stage('Install OpenStack compute') {
chnyda597fb032017-10-06 13:42:48 +0200415 orchestrate.installOpenstackCompute(venvPepper)
Ales Komarek24097402017-05-22 16:28:10 +0200416
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400417 if (common.checkContains('STACK_INSTALL', 'contrail')) {
chnyda597fb032017-10-06 13:42:48 +0200418 orchestrate.installContrailCompute(venvPepper)
Martin Polreich46971102017-07-11 12:56:40 +0200419 }
420 }
421
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400422 }
423
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400424 if (common.checkContains('STACK_INSTALL', 'oss')) {
425 stage('Install Oss infra') {
426 orchestrate.installOssInfra(venvPepper)
427 }
428 }
429
Jiri Broulikb27b4832017-09-05 16:41:03 +0200430 if (common.checkContains('STACK_INSTALL', 'cicd')) {
431 stage('Install Cicd') {
Vladimir Jigulinff3567c2017-12-11 15:31:11 +0400432 orchestrate.installInfra(venvPepper)
chnyda597fb032017-10-06 13:42:48 +0200433 orchestrate.installDockerSwarm(venvPepper)
434 orchestrate.installCicd(venvPepper)
Jiri Broulikb27b4832017-09-05 16:41:03 +0200435 }
436 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400437
438 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
439 stage('Install StackLight v1') {
chnyda597fb032017-10-06 13:42:48 +0200440 orchestrate.installStacklightv1Control(venvPepper)
441 orchestrate.installStacklightv1Client(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400442 }
443 }
444
445 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
446 stage('Install StackLight') {
chnyda597fb032017-10-06 13:42:48 +0200447 orchestrate.installDockerSwarm(venvPepper)
448 orchestrate.installStacklight(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400449 }
450 }
451
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400452 if (common.checkContains('STACK_INSTALL', 'oss')) {
453 stage('Install OSS') {
454 if (!common.checkContains('STACK_INSTALL', 'stacklight')) {
455 // In case if StackLightv2 enabled containers already started
456 orchestrate.installDockerSwarm(venvPepper)
457 salt.enforceState(venvPepper, 'I@docker:swarm:role:master and I@devops_portal:config', 'docker.client', true)
458 }
459 orchestrate.installOss(venvPepper)
460 }
461 }
462
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400463 //
464 // Test
465 //
466 def artifacts_dir = '_artifacts/'
467
468 if (common.checkContains('STACK_TEST', 'k8s')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400469 stage('Run k8s conformance e2e tests') {
Anna Babich12dd5b12017-08-21 18:01:35 +0300470 def image = TEST_K8S_CONFORMANCE_IMAGE
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400471 def output_file = image.replaceAll('/', '-') + '.output'
Ales Komarek24097402017-05-22 16:28:10 +0200472
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400473 // run image
chnyda597fb032017-10-06 13:42:48 +0200474 test.runConformanceTests(venvPepper, 'ctl01*', TEST_K8S_API_SERVER, image)
Ales Komarek24097402017-05-22 16:28:10 +0200475
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400476 // collect output
477 sh "mkdir -p ${artifacts_dir}"
chnyda597fb032017-10-06 13:42:48 +0200478 file_content = salt.getFileContent(venvPepper, 'ctl01*', '/tmp/' + output_file)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400479 writeFile file: "${artifacts_dir}${output_file}", text: file_content
480 sh "cat ${artifacts_dir}${output_file}"
Ales Komarek24097402017-05-22 16:28:10 +0200481
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400482 // collect artifacts
483 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
484 }
485 }
Ales Komarek24097402017-05-22 16:28:10 +0200486
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400487 if (common.checkContains('STACK_TEST', 'openstack')) {
488 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
chnyda597fb032017-10-06 13:42:48 +0200489 test.install_docker(venvPepper, TEST_TEMPEST_TARGET)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400490 }
491 stage('Run OpenStack tests') {
chnyda597fb032017-10-06 13:42:48 +0200492 test.runTempestTests(venvPepper, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
Ales Komarek24097402017-05-22 16:28:10 +0200493 }
494
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400495 stage('Copy Tempest results to config node') {
chnyda597fb032017-10-06 13:42:48 +0200496 test.copyTempestResults(venvPepper, TEST_TEMPEST_TARGET)
Ales Komarek24097402017-05-22 16:28:10 +0200497 }
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300498
499 stage('Archive rally artifacts') {
chnyda597fb032017-10-06 13:42:48 +0200500 test.archiveRallyArtifacts(venvPepper, TEST_TEMPEST_TARGET)
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300501 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400502 }
Ales Komarek24097402017-05-22 16:28:10 +0200503
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200504
505 if (common.checkContains('STACK_TEST', 'ceph')) {
Tomáš Kukrálf5798082017-08-21 22:37:41 +0200506 stage('Run infra tests') {
Tomáš Kukrál36d43972017-08-30 12:43:17 +0200507 sleep(120)
Tomáš Kukrál07ad0c92017-08-21 23:19:40 +0200508 def cmd = "apt-get install -y python-pip && pip install -r /usr/share/salt-formulas/env/ceph/files/testinfra/requirements.txt && python -m pytest --junitxml=/root/report.xml /usr/share/salt-formulas/env/ceph/files/testinfra/"
chnyda597fb032017-10-06 13:42:48 +0200509 salt.cmdRun(venvPepper, 'I@salt:master', cmd, false)
510 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, 'I@salt:master', '/root/report.xml'))
Tomáš Kukrálc48456a2017-08-21 23:03:37 +0200511 junit(keepLongStdio: true, testResults: 'report.xml')
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200512 }
513 }
514
515
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200516 stage('Finalize') {
517 if (common.checkContains('STACK_INSTALL', 'finalize')) {
chnyda597fb032017-10-06 13:42:48 +0200518 salt.runSaltProcessStep(venvPepper, '*', 'state.apply', [], null, true)
Ales Komarek24097402017-05-22 16:28:10 +0200519 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200520
521 outputsPretty = common.prettify(outputs)
522 print(outputsPretty)
523 writeFile(file: 'outputs.json', text: outputsPretty)
524 archiveArtifacts(artifacts: 'outputs.json')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400525 }
Tomáš Kukrál53224c22017-07-26 10:53:20 +0200526
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400527 } catch (Throwable e) {
528 currentBuild.result = 'FAILURE'
529 throw e
530 } finally {
Ales Komarek24097402017-05-22 16:28:10 +0200531
532
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400533 //
534 // Clean
535 //
Ales Komarek24097402017-05-22 16:28:10 +0200536
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200537 if (common.validInputParam('STACK_NAME')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400538 // send notification
539 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
540 }
541
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200542 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400543 stage('Trigger cleanup job') {
544 common.errorMsg('Stack cleanup job triggered')
545 build(job: STACK_CLEANUP_JOB, parameters: [
546 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
547 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
548 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
549 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
550 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
551 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
552 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
553 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
554 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
555 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
556 ])
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200557 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400558 } else {
559 if (currentBuild.result == 'FAILURE') {
560 common.errorMsg("Deploy job FAILED and was not deleted. Please fix the problem and delete stack on you own.")
Ales Komarek24097402017-05-22 16:28:10 +0200561
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200562 if (common.validInputParam('SALT_MASTER_URL')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400563 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
Ales Komarek24097402017-05-22 16:28:10 +0200564 }
565 }
566 }
567 }
568}