blob: bb391b9d8ba7733ea08e5c9a44d74bcdcb417b6b [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
ibumarskov637a2152018-01-16 10:39:57 +040053 * TESTRAIL_REPORT Whether upload results to testrail or not
54 * TESTRAIL_REPORTER_IMAGE Docker image for testrail reporter
55 * TESTRAIL_QA_CREDENTIALS Credentials for upload to testrail
56 * TESTRAIL_MILESTONE Product version for tests
57 * TESTRAIL_PLAN Testrail test plan
58 * TESTRAIL_GROUP Testrail test group
59 * TESTRAIL_SUITE Testrail test suite
Ales Komarek24097402017-05-22 16:28:10 +020060 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020061 * optional parameters for overwriting soft params
62 * SALT_OVERRIDES YAML with overrides for Salt deployment
Ales Komarek24097402017-05-22 16:28:10 +020063 *
64 */
Tomáš Kukrál3a17dd62017-07-27 18:24:16 +020065
Ales Komarek24097402017-05-22 16:28:10 +020066common = new com.mirantis.mk.Common()
67git = new com.mirantis.mk.Git()
68openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020069aws = new com.mirantis.mk.Aws()
Ales Komarek24097402017-05-22 16:28:10 +020070orchestrate = new com.mirantis.mk.Orchestrate()
Mykyta Karpine016d7e2017-10-09 13:35:20 +030071python = new com.mirantis.mk.Python()
Ales Komarek24097402017-05-22 16:28:10 +020072salt = new com.mirantis.mk.Salt()
73test = new com.mirantis.mk.Test()
74
75_MAX_PERMITTED_STACKS = 2
76overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
77
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020078// Define global variables
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020079def venv
chnyda597fb032017-10-06 13:42:48 +020080def venvPepper
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020081def outputs = [:]
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020082
chnydae14058a2017-08-29 15:07:48 +020083def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
84
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020085if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020086 def aws_env_vars
Tomáš Kukrál8427ff52017-08-30 15:46:52 +020087} else if (STACK_TYPE == 'heat') {
88 def envParams
89 def openstackCloud
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020090}
91
Oleh Hryhorov9630a762017-10-24 14:33:25 +030092def slave_node = 'python'
93
Oleh Hryhorov54460512017-10-26 18:45:36 +030094if (common.validInputParam('SLAVE_NODE')) {
Oleh Hryhorov9630a762017-10-24 14:33:25 +030095 slave_node = SLAVE_NODE
96}
Jakub Josefa63f9862018-01-11 17:58:38 +010097timeout(time: 12, unit: 'HOURS') {
98 node(slave_node) {
99 try {
100 // Set build-specific variables
Jakub Josef88aaf832018-01-18 16:18:28 +0100101 def workspace = common.getWorkspace()
102 venv = "${workspace}/venv"
103 venvPepper = "${workspace}/venvPepper"
Oleh Hryhorov9630a762017-10-24 14:33:25 +0300104
Jakub Josefa63f9862018-01-11 17:58:38 +0100105 //
106 // Prepare machines
107 //
108 stage ('Create infrastructure') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200109
Jakub Josefa63f9862018-01-11 17:58:38 +0100110 outputs.put('stack_type', STACK_TYPE)
Ales Komarek24097402017-05-22 16:28:10 +0200111
Jakub Josefa63f9862018-01-11 17:58:38 +0100112 if (STACK_TYPE == 'heat') {
113 // value defaults
114 envParams = [
115 'cluster_zone': HEAT_STACK_ZONE,
116 'cluster_public_net': HEAT_STACK_PUBLIC_NET
117 ]
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200118
Jakub Josefa63f9862018-01-11 17:58:38 +0100119 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
120 error("If you want to reuse existing stack you need to provide it's name")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400121 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200122
Jakub Josefa63f9862018-01-11 17:58:38 +0100123 if (STACK_REUSE.toBoolean() == false) {
124 // Don't allow to set custom heat stack name
125 wrap([$class: 'BuildUser']) {
126 if (env.BUILD_USER_ID) {
127 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
128 } else {
129 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
130 }
131 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200132 }
133 }
134
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400135 // no underscore in STACK_NAME
136 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Jakub Josefa63f9862018-01-11 17:58:38 +0100137 outputs.put('stack_name', STACK_NAME)
Ales Komarek24097402017-05-22 16:28:10 +0200138
Jakub Josefa63f9862018-01-11 17:58:38 +0100139 // set description
140 currentBuild.description = "${STACK_NAME}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400141
Ales Komarek24097402017-05-22 16:28:10 +0200142 // get templates
143 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
144
Jakub Josefa63f9862018-01-11 17:58:38 +0100145 // create openstack env
146 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
Jakub Josef88aaf832018-01-18 16:18:28 +0100147 openstackCloud = openstack.createOpenstackEnv(venv,
Jakub Josefa63f9862018-01-11 17:58:38 +0100148 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
149 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
150 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
151 OPENSTACK_API_VERSION)
152 openstack.getKeystoneToken(openstackCloud, venv)
Ales Komarek24097402017-05-22 16:28:10 +0200153
Jakub Josefa63f9862018-01-11 17:58:38 +0100154 //
155 // Verify possibility of create stack for given user and stack type
156 //
157 wrap([$class: 'BuildUser']) {
158 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
159 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
160 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
161 STACK_DELETE = "false"
162 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
163 }
164 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200165 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100166 // launch stack
167 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400168
Jakub Josefa63f9862018-01-11 17:58:38 +0100169 // set reclass repo in heat env
170 try {
171 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
172 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
173 } catch (MissingPropertyException e) {
174 common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.")
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100175 }
176
Jakub Josefa63f9862018-01-11 17:58:38 +0100177 // put formulas revision - stable, testing or nightly
178 if (common.validInputParam('FORMULA_PKG_REVISION')) {
179 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
180 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
181 }
182
183 // put extra repo definitions
184 if (common.validInputParam('BOOTSTRAP_EXTRA_REPO_PARAMS')) {
185 common.infoMsg("Setting additional repo during bootstrap to ${BOOTSTRAP_EXTRA_REPO_PARAMS}")
186 envParams.put('cfg_bootstrap_extra_repo_params', BOOTSTRAP_EXTRA_REPO_PARAMS)
187 }
188
189 // put extra salt-formulas
190 if (common.validInputParam('EXTRA_FORMULAS')) {
191 common.infoMsg("Setting extra salt-formulas to ${EXTRA_FORMULAS}")
192 envParams.put('cfg_extra_formulas', EXTRA_FORMULAS)
193 }
194
195 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
196 }
197
198 // get SALT_MASTER_URL
199 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
200 // check that saltMasterHost is valid
201 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
202 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
203 throw new Exception("saltMasterHost is not a valid ip")
204 }
205
206 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
207
208 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
209
210 } else if (STACK_TYPE == 'aws') {
211
212 // setup environment
213 aws.setupVirtualEnv(venv)
214
215 // set aws_env_vars
216 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
217
218 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
219 error("If you want to reuse existing stack you need to provide it's name")
220 }
221
222 if (STACK_REUSE.toBoolean() == false) {
223 // Don't allow to set custom stack name
224 wrap([$class: 'BuildUser']) {
225 if (env.BUILD_USER_ID) {
226 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
227 } else {
228 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
229 }
230 }
231
232 // no underscore in STACK_NAME
233 STACK_NAME = STACK_NAME.replaceAll('_', '-')
234 }
235
236 // set description
237 currentBuild.description = STACK_NAME
238 outputs.put('stack_name', STACK_NAME)
239
240 if (STACK_REUSE.toBoolean() == false) {
241 // get templates
242 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
243
244 // start stack
245 def stack_params = [
246 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
247 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
248 ]
249 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
250 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
251 }
252
253 // wait for stack to be ready
254 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
255
256 // get outputs
257 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
258
259 // check that saltMasterHost is valid
260 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
261 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
262 throw new Exception("saltMasterHost is not a valid ip")
263 }
264
265 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
266 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
267
268 } else if (STACK_TYPE != 'physical') {
269 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
270 }
271
272 outputs.put('salt_api', SALT_MASTER_URL)
273
274 // Setup virtualenv for pepper
275 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
276 }
277
278
279 // Set up override params
280 if (common.validInputParam('SALT_OVERRIDES')) {
281 stage('Set Salt overrides') {
282 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES)
283 }
284 }
285
286 //
287 // Install
288 //
289
290 if (common.checkContains('STACK_INSTALL', 'core')) {
291 stage('Install core infrastructure') {
292 def staticMgmtNetwork = false
293 if (common.validInputParam('STATIC_MGMT_NETWORK')) {
294 staticMgmtNetwork = STATIC_MGMT_NETWORK.toBoolean()
295 }
296 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
297
298 if (common.checkContains('STACK_INSTALL', 'kvm')) {
299 orchestrate.installInfraKvm(venvPepper)
300 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
301 }
302
303 orchestrate.validateFoundationInfra(venvPepper)
304 }
305 }
306
307 // install k8s
308 if (common.checkContains('STACK_INSTALL', 'k8s')) {
309
310 stage('Install Kubernetes infra') {
311 if (STACK_TYPE == 'aws') {
312 // configure kubernetes_control_address - save loadbalancer
313 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
314 common.prettyPrint(awsOutputs)
315 if (awsOutputs.containsKey('ControlLoadBalancer')) {
316 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
317 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
318 }
319 }
320
321 // ensure certificates are generated properly
322 salt.runSaltProcessStep(venvPepper, '*', 'saltutil.refresh_pillar', [], null, true)
323 salt.enforceState(venvPepper, '*', ['salt.minion.cert'], true)
324
325 orchestrate.installKubernetesInfra(venvPepper)
326 }
327
328 if (common.checkContains('STACK_INSTALL', 'contrail')) {
329 stage('Install Contrail for Kubernetes') {
330 orchestrate.installContrailNetwork(venvPepper)
331 orchestrate.installContrailCompute(venvPepper)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200332 }
Ales Komarek24097402017-05-22 16:28:10 +0200333 }
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100334
Jakub Josefa63f9862018-01-11 17:58:38 +0100335 stage('Install Kubernetes control') {
336 orchestrate.installKubernetesControl(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400337
Jakub Josefa63f9862018-01-11 17:58:38 +0100338 // collect artifacts (kubeconfig)
339 writeFile(file: 'kubeconfig', text: salt.getFileContent(venvPepper, 'I@kubernetes:master and *01*', '/etc/kubernetes/admin-kube-config'))
340 archiveArtifacts(artifacts: 'kubeconfig')
vrovachev7be1e962017-07-05 13:28:26 +0400341 }
342
Jakub Josefa63f9862018-01-11 17:58:38 +0100343 stage('Install Kubernetes computes') {
344 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
345 if (STACK_COMPUTE_COUNT > 0) {
346 if (STACK_TYPE == 'aws') {
347 // get stack info
348 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
349
350 //update autoscaling group
351 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
352
353 // wait for computes to boot up
354 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
355 sleep(60)
356
357 } else if (STACK_TYPE == 'heat') {
358 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
359
360 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
361 sleep(60)
362 }
363
364 }
365 }
366
367 orchestrate.installKubernetesCompute(venvPepper)
368 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400369 }
Ales Komarek24097402017-05-22 16:28:10 +0200370
Jakub Josefa63f9862018-01-11 17:58:38 +0100371 // install openstack
372 if (common.checkContains('STACK_INSTALL', 'openstack')) {
373 // install Infra and control, tests, ...
374
375 stage('Install OpenStack infra') {
376 orchestrate.installOpenstackInfra(venvPepper)
377 }
378
379 stage('Install OpenStack control') {
380 orchestrate.installOpenstackControl(venvPepper)
381 }
382
Oleg Iurchenko86f1a842018-02-13 22:18:28 +0200383 // Workaround for PROD-17765 issue to prevent crashes of keystone.role_present state.
384 // More details: https://mirantis.jira.com/browse/PROD-17765
385 salt.runSaltProcessStep(venvPepper, 'I@keystone:client', 'service.restart', ['salt-minion'])
386 salt.minionsReachable(venvPepper, 'I@salt:master and *01*', 'I@keystone:client', null, 10, 6)
387
Jakub Josefa63f9862018-01-11 17:58:38 +0100388 stage('Install OpenStack network') {
389
390 if (common.checkContains('STACK_INSTALL', 'contrail')) {
391 orchestrate.installContrailNetwork(venvPepper)
392 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
393 orchestrate.installOpenstackNetwork(venvPepper)
394 }
395
Oleh Hryhorov89da0502018-02-13 16:57:46 +0200396 salt.cmdRun(venvPepper, 'I@keystone:server', '. /root/keystonercv3; openstack network list')
Jakub Josefa63f9862018-01-11 17:58:38 +0100397 }
398
399 if (salt.testTarget(venvPepper, 'I@ironic:conductor')){
400 stage('Install OpenStack Ironic conductor') {
401 orchestrate.installIronicConductor(venvPepper)
402 }
403 }
404
Vasyl Saienkob800a0f2018-02-21 18:38:53 +0200405 if (salt.testTarget(venvPepper, 'I@manila:share')){
406 stage('Install OpenStack Manila data and share') {
407 orchestrate.installManilaShare(venvPepper)
408 }
409 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100410
411 stage('Install OpenStack compute') {
412 orchestrate.installOpenstackCompute(venvPepper)
413
414 if (common.checkContains('STACK_INSTALL', 'contrail')) {
415 orchestrate.installContrailCompute(venvPepper)
416 }
417 }
418
419 }
420
421 // install ceph
422 if (common.checkContains('STACK_INSTALL', 'ceph')) {
423 stage('Install Ceph MONs') {
424 orchestrate.installCephMon(venvPepper)
425 }
426
427 stage('Install Ceph OSDs') {
428 orchestrate.installCephOsd(venvPepper)
429 }
430
431
432 stage('Install Ceph clients') {
433 orchestrate.installCephClient(venvPepper)
434 }
435
436 stage('Connect Ceph') {
437 orchestrate.connectCeph(venvPepper)
438 }
439 }
440
441 if (common.checkContains('STACK_INSTALL', 'oss')) {
442 stage('Install Oss infra') {
443 orchestrate.installOssInfra(venvPepper)
444 }
445 }
446
447 if (common.checkContains('STACK_INSTALL', 'cicd')) {
448 stage('Install Cicd') {
449 orchestrate.installInfra(venvPepper)
450 orchestrate.installDockerSwarm(venvPepper)
451 orchestrate.installCicd(venvPepper)
452 }
453 }
454
455 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
456 stage('Install StackLight v1') {
457 orchestrate.installStacklightv1Control(venvPepper)
458 orchestrate.installStacklightv1Client(venvPepper)
459 }
460 }
461
462 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
463 stage('Install StackLight') {
464 orchestrate.installDockerSwarm(venvPepper)
465 orchestrate.installStacklight(venvPepper)
466 }
467 }
468
469 if (common.checkContains('STACK_INSTALL', 'oss')) {
470 stage('Install OSS') {
471 if (!common.checkContains('STACK_INSTALL', 'stacklight')) {
472 // In case if StackLightv2 enabled containers already started
473 orchestrate.installDockerSwarm(venvPepper)
474 salt.enforceState(venvPepper, 'I@docker:swarm:role:master and I@devops_portal:config', 'docker.client', true)
475 }
476 orchestrate.installOss(venvPepper)
477 }
478 }
479
480 //
481 // Test
482 //
483 def artifacts_dir = '_artifacts/'
484
485 if (common.checkContains('STACK_TEST', 'k8s')) {
486 stage('Run k8s conformance e2e tests') {
487 def image = TEST_K8S_CONFORMANCE_IMAGE
488 def output_file = image.replaceAll('/', '-') + '.output'
vrovachevff3e72d2018-01-25 16:14:43 +0400489 def target = 'ctl01*'
490 def conformance_output_file = 'conformance_test.tar'
Jakub Josefa63f9862018-01-11 17:58:38 +0100491
492 // run image
vrovachevff3e72d2018-01-25 16:14:43 +0400493 test.runConformanceTests(venvPepper, target, TEST_K8S_API_SERVER, image)
Jakub Josefa63f9862018-01-11 17:58:38 +0100494
495 // collect output
496 sh "mkdir -p ${artifacts_dir}"
vrovachevff3e72d2018-01-25 16:14:43 +0400497 file_content = salt.getFileContent(venvPepper, target, '/tmp/' + output_file)
Jakub Josefa63f9862018-01-11 17:58:38 +0100498 writeFile file: "${artifacts_dir}${output_file}", text: file_content
499 sh "cat ${artifacts_dir}${output_file}"
500
501 // collect artifacts
502 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
vrovachevff3e72d2018-01-25 16:14:43 +0400503
504 // Copy test results
505 test.CopyConformanceResults(venvPepper, target, artifacts_dir, conformance_output_file)
Jakub Josefa63f9862018-01-11 17:58:38 +0100506 }
507 }
508
509 if (common.checkContains('STACK_TEST', 'openstack')) {
510 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
511 test.install_docker(venvPepper, TEST_TEMPEST_TARGET)
512 }
513 stage('Run OpenStack tests') {
514 test.runTempestTests(venvPepper, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
515 }
516
517 stage('Copy Tempest results to config node') {
518 test.copyTempestResults(venvPepper, TEST_TEMPEST_TARGET)
519 }
520
521 stage('Archive rally artifacts') {
522 test.archiveRallyArtifacts(venvPepper, TEST_TEMPEST_TARGET)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200523 }
ibumarskov637a2152018-01-16 10:39:57 +0400524
525 if (common.validInputParam('TESTRAIL_REPORT') && TESTRAIL_REPORT.toBoolean()) {
526 stage('Upload test results to TestRail') {
527 def date = sh(script: 'date +%Y-%m-%d', returnStdout: true).trim()
528 def plan = TESTRAIL_PLAN ?: "[${TESTRAIL_MILESTONE}]System-Devcloud-${date}"
529 def group = TESTRAIL_GROUP ?: STACK_TEMPLATE
530
531 salt.cmdRun(venvPepper, TEST_TEMPEST_TARGET, "cd /root/rally_reports && cp \$(ls -t *xml | head -n1) report.xml")
532 test.uploadResultsTestrail("/root/rally_reports/report.xml",
533 TESTRAIL_REPORTER_IMAGE, group, TESTRAIL_QA_CREDENTIALS,
534 plan, TESTRAIL_MILESTONE, TESTRAIL_SUITE)
535 }
536 }
Ales Komarek24097402017-05-22 16:28:10 +0200537 }
538
Ales Komarek24097402017-05-22 16:28:10 +0200539
Jakub Josefa63f9862018-01-11 17:58:38 +0100540 if (common.checkContains('STACK_TEST', 'ceph')) {
541 stage('Run infra tests') {
542 sleep(120)
543 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/"
544 salt.cmdRun(venvPepper, 'I@salt:master', cmd, false)
545 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, 'I@salt:master', '/root/report.xml'))
546 junit(keepLongStdio: true, testResults: 'report.xml')
Martin Polreich46971102017-07-11 12:56:40 +0200547 }
548 }
549
Jakub Josefa63f9862018-01-11 17:58:38 +0100550 if (common.checkContains('STACK_TEST', 'opencontrail')) {
551 stage('Run opencontrail tests') {
552 def opencontrail_tests_dir = "/opt/opencontrail_test/fuel-plugin-contrail/plugin_test/vapor/"
553 def report_dir = "/opt/opencontrail-test-report/"
554 def cmd = ". ${opencontrail_tests_dir}exports.sh && " +
555 "cd ${opencontrail_tests_dir} && " +
556 "py.test --junit-xml=${report_dir}report.xml" +
557 " --html=${report_dir}report.html -v vapor/tests/ -k 'not destructive' "
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400558
Jakub Josefa63f9862018-01-11 17:58:38 +0100559 salt.runSaltProcessStep(venvPepper, 'cfg*', 'saltutil.refresh_pillar', [], null, true)
560 salt.enforceState(venvPepper, 'I@opencontrail:test' , 'opencontrail.test' , true)
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100561
Jakub Josefa63f9862018-01-11 17:58:38 +0100562 salt.cmdRun(venvPepper, 'I@opencontrail:test', cmd, false)
563
564 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper,
565 'I@opencontrail:test', "${report_dir}report.xml"))
566 junit(keepLongStdio: true, testResults: 'report.xml')
567 }
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100568 }
569
570
Jakub Josefa63f9862018-01-11 17:58:38 +0100571 stage('Finalize') {
572 if (common.checkContains('STACK_INSTALL', 'finalize')) {
573 salt.runSaltProcessStep(venvPepper, '*', 'state.apply', [], null, true)
574 }
575
576 outputsPretty = common.prettify(outputs)
577 print(outputsPretty)
578 writeFile(file: 'outputs.json', text: outputsPretty)
579 archiveArtifacts(artifacts: 'outputs.json')
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100580 }
581
Jakub Josefa63f9862018-01-11 17:58:38 +0100582 } catch (Throwable e) {
583 currentBuild.result = 'FAILURE'
584 throw e
585 } finally {
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100586
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400587
Jakub Josefa63f9862018-01-11 17:58:38 +0100588 //
589 // Clean
590 //
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400591
Jakub Josefa63f9862018-01-11 17:58:38 +0100592 if (common.validInputParam('STACK_NAME')) {
593 // send notification
594 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
Ales Komarek24097402017-05-22 16:28:10 +0200595 }
596
Jakub Josefa63f9862018-01-11 17:58:38 +0100597 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
598 stage('Trigger cleanup job') {
599 common.errorMsg('Stack cleanup job triggered')
600 build(job: STACK_CLEANUP_JOB, parameters: [
601 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
602 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
603 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
604 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
605 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
606 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
607 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
608 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
609 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
610 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
611 ])
612 }
613 } else {
614 if (currentBuild.result == 'FAILURE') {
615 common.errorMsg("Deploy job FAILED and was not deleted. Please fix the problem and delete stack on you own.")
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300616
Jakub Josefa63f9862018-01-11 17:58:38 +0100617 if (common.validInputParam('SALT_MASTER_URL')) {
618 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
619 }
Ales Komarek24097402017-05-22 16:28:10 +0200620 }
621 }
622 }
623 }
624}