blob: 947904a0f5debd85e542f4af3e835815abecafe2 [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
101 venv = "${env.WORKSPACE}/venv"
102 venvPepper = "${env.WORKSPACE}/venvPepper"
Oleh Hryhorov9630a762017-10-24 14:33:25 +0300103
Jakub Josefa63f9862018-01-11 17:58:38 +0100104 //
105 // Prepare machines
106 //
107 stage ('Create infrastructure') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200108
Jakub Josefa63f9862018-01-11 17:58:38 +0100109 outputs.put('stack_type', STACK_TYPE)
Ales Komarek24097402017-05-22 16:28:10 +0200110
Jakub Josefa63f9862018-01-11 17:58:38 +0100111 if (STACK_TYPE == 'heat') {
112 // value defaults
113 envParams = [
114 'cluster_zone': HEAT_STACK_ZONE,
115 'cluster_public_net': HEAT_STACK_PUBLIC_NET
116 ]
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200117
Jakub Josefa63f9862018-01-11 17:58:38 +0100118 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
119 error("If you want to reuse existing stack you need to provide it's name")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400120 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200121
Jakub Josefa63f9862018-01-11 17:58:38 +0100122 if (STACK_REUSE.toBoolean() == false) {
123 // Don't allow to set custom heat stack name
124 wrap([$class: 'BuildUser']) {
125 if (env.BUILD_USER_ID) {
126 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
127 } else {
128 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
129 }
130 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200131 }
132 }
133
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400134 // no underscore in STACK_NAME
135 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Jakub Josefa63f9862018-01-11 17:58:38 +0100136 outputs.put('stack_name', STACK_NAME)
Ales Komarek24097402017-05-22 16:28:10 +0200137
Jakub Josefa63f9862018-01-11 17:58:38 +0100138 // set description
139 currentBuild.description = "${STACK_NAME}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400140
Ales Komarek24097402017-05-22 16:28:10 +0200141 // get templates
142 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
143
Jakub Josefa63f9862018-01-11 17:58:38 +0100144 // create openstack env
145 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
146 openstackCloud = openstack.createOpenstackEnv(
147 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
148 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
149 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
150 OPENSTACK_API_VERSION)
151 openstack.getKeystoneToken(openstackCloud, venv)
Ales Komarek24097402017-05-22 16:28:10 +0200152
Jakub Josefa63f9862018-01-11 17:58:38 +0100153 //
154 // Verify possibility of create stack for given user and stack type
155 //
156 wrap([$class: 'BuildUser']) {
157 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
158 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
159 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
160 STACK_DELETE = "false"
161 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
162 }
163 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200164 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100165 // launch stack
166 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400167
Jakub Josefa63f9862018-01-11 17:58:38 +0100168 // set reclass repo in heat env
169 try {
170 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
171 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
172 } catch (MissingPropertyException e) {
173 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 +0100174 }
175
Jakub Josefa63f9862018-01-11 17:58:38 +0100176 // put formulas revision - stable, testing or nightly
177 if (common.validInputParam('FORMULA_PKG_REVISION')) {
178 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
179 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
180 }
181
182 // put extra repo definitions
183 if (common.validInputParam('BOOTSTRAP_EXTRA_REPO_PARAMS')) {
184 common.infoMsg("Setting additional repo during bootstrap to ${BOOTSTRAP_EXTRA_REPO_PARAMS}")
185 envParams.put('cfg_bootstrap_extra_repo_params', BOOTSTRAP_EXTRA_REPO_PARAMS)
186 }
187
188 // put extra salt-formulas
189 if (common.validInputParam('EXTRA_FORMULAS')) {
190 common.infoMsg("Setting extra salt-formulas to ${EXTRA_FORMULAS}")
191 envParams.put('cfg_extra_formulas', EXTRA_FORMULAS)
192 }
193
194 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
195 }
196
197 // get SALT_MASTER_URL
198 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
199 // check that saltMasterHost is valid
200 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
201 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
202 throw new Exception("saltMasterHost is not a valid ip")
203 }
204
205 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
206
207 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
208
209 } else if (STACK_TYPE == 'aws') {
210
211 // setup environment
212 aws.setupVirtualEnv(venv)
213
214 // set aws_env_vars
215 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
216
217 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
218 error("If you want to reuse existing stack you need to provide it's name")
219 }
220
221 if (STACK_REUSE.toBoolean() == false) {
222 // Don't allow to set custom stack name
223 wrap([$class: 'BuildUser']) {
224 if (env.BUILD_USER_ID) {
225 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
226 } else {
227 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
228 }
229 }
230
231 // no underscore in STACK_NAME
232 STACK_NAME = STACK_NAME.replaceAll('_', '-')
233 }
234
235 // set description
236 currentBuild.description = STACK_NAME
237 outputs.put('stack_name', STACK_NAME)
238
239 if (STACK_REUSE.toBoolean() == false) {
240 // get templates
241 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
242
243 // start stack
244 def stack_params = [
245 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
246 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
247 ]
248 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
249 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
250 }
251
252 // wait for stack to be ready
253 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
254
255 // get outputs
256 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
257
258 // check that saltMasterHost is valid
259 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
260 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
261 throw new Exception("saltMasterHost is not a valid ip")
262 }
263
264 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
265 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
266
267 } else if (STACK_TYPE != 'physical') {
268 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
269 }
270
271 outputs.put('salt_api', SALT_MASTER_URL)
272
273 // Setup virtualenv for pepper
274 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
275 }
276
277
278 // Set up override params
279 if (common.validInputParam('SALT_OVERRIDES')) {
280 stage('Set Salt overrides') {
281 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES)
282 }
283 }
284
285 //
286 // Install
287 //
288
289 if (common.checkContains('STACK_INSTALL', 'core')) {
290 stage('Install core infrastructure') {
291 def staticMgmtNetwork = false
292 if (common.validInputParam('STATIC_MGMT_NETWORK')) {
293 staticMgmtNetwork = STATIC_MGMT_NETWORK.toBoolean()
294 }
295 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
296
297 if (common.checkContains('STACK_INSTALL', 'kvm')) {
298 orchestrate.installInfraKvm(venvPepper)
299 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
300 }
301
302 orchestrate.validateFoundationInfra(venvPepper)
303 }
304 }
305
306 // install k8s
307 if (common.checkContains('STACK_INSTALL', 'k8s')) {
308
309 stage('Install Kubernetes infra') {
310 if (STACK_TYPE == 'aws') {
311 // configure kubernetes_control_address - save loadbalancer
312 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
313 common.prettyPrint(awsOutputs)
314 if (awsOutputs.containsKey('ControlLoadBalancer')) {
315 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
316 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
317 }
318 }
319
320 // ensure certificates are generated properly
321 salt.runSaltProcessStep(venvPepper, '*', 'saltutil.refresh_pillar', [], null, true)
322 salt.enforceState(venvPepper, '*', ['salt.minion.cert'], true)
323
324 orchestrate.installKubernetesInfra(venvPepper)
325 }
326
327 if (common.checkContains('STACK_INSTALL', 'contrail')) {
328 stage('Install Contrail for Kubernetes') {
329 orchestrate.installContrailNetwork(venvPepper)
330 orchestrate.installContrailCompute(venvPepper)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200331 }
Ales Komarek24097402017-05-22 16:28:10 +0200332 }
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100333
Jakub Josefa63f9862018-01-11 17:58:38 +0100334 stage('Install Kubernetes control') {
335 orchestrate.installKubernetesControl(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400336
Jakub Josefa63f9862018-01-11 17:58:38 +0100337 // collect artifacts (kubeconfig)
338 writeFile(file: 'kubeconfig', text: salt.getFileContent(venvPepper, 'I@kubernetes:master and *01*', '/etc/kubernetes/admin-kube-config'))
339 archiveArtifacts(artifacts: 'kubeconfig')
vrovachev7be1e962017-07-05 13:28:26 +0400340 }
341
Jakub Josefa63f9862018-01-11 17:58:38 +0100342 stage('Install Kubernetes computes') {
343 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
344 if (STACK_COMPUTE_COUNT > 0) {
345 if (STACK_TYPE == 'aws') {
346 // get stack info
347 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
348
349 //update autoscaling group
350 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
351
352 // wait for computes to boot up
353 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
354 sleep(60)
355
356 } else if (STACK_TYPE == 'heat') {
357 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
358
359 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
360 sleep(60)
361 }
362
363 }
364 }
365
366 orchestrate.installKubernetesCompute(venvPepper)
367 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400368 }
Ales Komarek24097402017-05-22 16:28:10 +0200369
Jakub Josefa63f9862018-01-11 17:58:38 +0100370 // install openstack
371 if (common.checkContains('STACK_INSTALL', 'openstack')) {
372 // install Infra and control, tests, ...
373
374 stage('Install OpenStack infra') {
375 orchestrate.installOpenstackInfra(venvPepper)
376 }
377
378 stage('Install OpenStack control') {
379 orchestrate.installOpenstackControl(venvPepper)
380 }
381
382 stage('Install OpenStack network') {
383
384 if (common.checkContains('STACK_INSTALL', 'contrail')) {
385 orchestrate.installContrailNetwork(venvPepper)
386 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
387 orchestrate.installOpenstackNetwork(venvPepper)
388 }
389
390 salt.runSaltProcessStep(venvPepper, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
391 salt.runSaltProcessStep(venvPepper, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
392 }
393
394 if (salt.testTarget(venvPepper, 'I@ironic:conductor')){
395 stage('Install OpenStack Ironic conductor') {
396 orchestrate.installIronicConductor(venvPepper)
397 }
398 }
399
400
401 stage('Install OpenStack compute') {
402 orchestrate.installOpenstackCompute(venvPepper)
403
404 if (common.checkContains('STACK_INSTALL', 'contrail')) {
405 orchestrate.installContrailCompute(venvPepper)
406 }
407 }
408
409 }
410
411 // install ceph
412 if (common.checkContains('STACK_INSTALL', 'ceph')) {
413 stage('Install Ceph MONs') {
414 orchestrate.installCephMon(venvPepper)
415 }
416
417 stage('Install Ceph OSDs') {
418 orchestrate.installCephOsd(venvPepper)
419 }
420
421
422 stage('Install Ceph clients') {
423 orchestrate.installCephClient(venvPepper)
424 }
425
426 stage('Connect Ceph') {
427 orchestrate.connectCeph(venvPepper)
428 }
429 }
430
431 if (common.checkContains('STACK_INSTALL', 'oss')) {
432 stage('Install Oss infra') {
433 orchestrate.installOssInfra(venvPepper)
434 }
435 }
436
437 if (common.checkContains('STACK_INSTALL', 'cicd')) {
438 stage('Install Cicd') {
439 orchestrate.installInfra(venvPepper)
440 orchestrate.installDockerSwarm(venvPepper)
441 orchestrate.installCicd(venvPepper)
442 }
443 }
444
445 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
446 stage('Install StackLight v1') {
447 orchestrate.installStacklightv1Control(venvPepper)
448 orchestrate.installStacklightv1Client(venvPepper)
449 }
450 }
451
452 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
453 stage('Install StackLight') {
454 orchestrate.installDockerSwarm(venvPepper)
455 orchestrate.installStacklight(venvPepper)
456 }
457 }
458
459 if (common.checkContains('STACK_INSTALL', 'oss')) {
460 stage('Install OSS') {
461 if (!common.checkContains('STACK_INSTALL', 'stacklight')) {
462 // In case if StackLightv2 enabled containers already started
463 orchestrate.installDockerSwarm(venvPepper)
464 salt.enforceState(venvPepper, 'I@docker:swarm:role:master and I@devops_portal:config', 'docker.client', true)
465 }
466 orchestrate.installOss(venvPepper)
467 }
468 }
469
470 //
471 // Test
472 //
473 def artifacts_dir = '_artifacts/'
474
475 if (common.checkContains('STACK_TEST', 'k8s')) {
476 stage('Run k8s conformance e2e tests') {
477 def image = TEST_K8S_CONFORMANCE_IMAGE
478 def output_file = image.replaceAll('/', '-') + '.output'
479
480 // run image
481 test.runConformanceTests(venvPepper, 'ctl01*', TEST_K8S_API_SERVER, image)
482
483 // collect output
484 sh "mkdir -p ${artifacts_dir}"
485 file_content = salt.getFileContent(venvPepper, 'ctl01*', '/tmp/' + output_file)
486 writeFile file: "${artifacts_dir}${output_file}", text: file_content
487 sh "cat ${artifacts_dir}${output_file}"
488
489 // collect artifacts
490 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
491 }
492 }
493
494 if (common.checkContains('STACK_TEST', 'openstack')) {
495 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
496 test.install_docker(venvPepper, TEST_TEMPEST_TARGET)
497 }
498 stage('Run OpenStack tests') {
499 test.runTempestTests(venvPepper, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
500 }
501
502 stage('Copy Tempest results to config node') {
503 test.copyTempestResults(venvPepper, TEST_TEMPEST_TARGET)
504 }
505
506 stage('Archive rally artifacts') {
507 test.archiveRallyArtifacts(venvPepper, TEST_TEMPEST_TARGET)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200508 }
ibumarskov637a2152018-01-16 10:39:57 +0400509
510 if (common.validInputParam('TESTRAIL_REPORT') && TESTRAIL_REPORT.toBoolean()) {
511 stage('Upload test results to TestRail') {
512 def date = sh(script: 'date +%Y-%m-%d', returnStdout: true).trim()
513 def plan = TESTRAIL_PLAN ?: "[${TESTRAIL_MILESTONE}]System-Devcloud-${date}"
514 def group = TESTRAIL_GROUP ?: STACK_TEMPLATE
515
516 salt.cmdRun(venvPepper, TEST_TEMPEST_TARGET, "cd /root/rally_reports && cp \$(ls -t *xml | head -n1) report.xml")
517 test.uploadResultsTestrail("/root/rally_reports/report.xml",
518 TESTRAIL_REPORTER_IMAGE, group, TESTRAIL_QA_CREDENTIALS,
519 plan, TESTRAIL_MILESTONE, TESTRAIL_SUITE)
520 }
521 }
Ales Komarek24097402017-05-22 16:28:10 +0200522 }
523
Ales Komarek24097402017-05-22 16:28:10 +0200524
Jakub Josefa63f9862018-01-11 17:58:38 +0100525 if (common.checkContains('STACK_TEST', 'ceph')) {
526 stage('Run infra tests') {
527 sleep(120)
528 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/"
529 salt.cmdRun(venvPepper, 'I@salt:master', cmd, false)
530 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, 'I@salt:master', '/root/report.xml'))
531 junit(keepLongStdio: true, testResults: 'report.xml')
Martin Polreich46971102017-07-11 12:56:40 +0200532 }
533 }
534
Jakub Josefa63f9862018-01-11 17:58:38 +0100535 if (common.checkContains('STACK_TEST', 'opencontrail')) {
536 stage('Run opencontrail tests') {
537 def opencontrail_tests_dir = "/opt/opencontrail_test/fuel-plugin-contrail/plugin_test/vapor/"
538 def report_dir = "/opt/opencontrail-test-report/"
539 def cmd = ". ${opencontrail_tests_dir}exports.sh && " +
540 "cd ${opencontrail_tests_dir} && " +
541 "py.test --junit-xml=${report_dir}report.xml" +
542 " --html=${report_dir}report.html -v vapor/tests/ -k 'not destructive' "
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400543
Jakub Josefa63f9862018-01-11 17:58:38 +0100544 salt.runSaltProcessStep(venvPepper, 'cfg*', 'saltutil.refresh_pillar', [], null, true)
545 salt.enforceState(venvPepper, 'I@opencontrail:test' , 'opencontrail.test' , true)
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100546
Jakub Josefa63f9862018-01-11 17:58:38 +0100547 salt.cmdRun(venvPepper, 'I@opencontrail:test', cmd, false)
548
549 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper,
550 'I@opencontrail:test', "${report_dir}report.xml"))
551 junit(keepLongStdio: true, testResults: 'report.xml')
552 }
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100553 }
554
555
Jakub Josefa63f9862018-01-11 17:58:38 +0100556 stage('Finalize') {
557 if (common.checkContains('STACK_INSTALL', 'finalize')) {
558 salt.runSaltProcessStep(venvPepper, '*', 'state.apply', [], null, true)
559 }
560
561 outputsPretty = common.prettify(outputs)
562 print(outputsPretty)
563 writeFile(file: 'outputs.json', text: outputsPretty)
564 archiveArtifacts(artifacts: 'outputs.json')
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100565 }
566
Jakub Josefa63f9862018-01-11 17:58:38 +0100567 } catch (Throwable e) {
568 currentBuild.result = 'FAILURE'
569 throw e
570 } finally {
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100571
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400572
Jakub Josefa63f9862018-01-11 17:58:38 +0100573 //
574 // Clean
575 //
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400576
Jakub Josefa63f9862018-01-11 17:58:38 +0100577 if (common.validInputParam('STACK_NAME')) {
578 // send notification
579 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
Ales Komarek24097402017-05-22 16:28:10 +0200580 }
581
Jakub Josefa63f9862018-01-11 17:58:38 +0100582 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
583 stage('Trigger cleanup job') {
584 common.errorMsg('Stack cleanup job triggered')
585 build(job: STACK_CLEANUP_JOB, parameters: [
586 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
587 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
588 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
589 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
590 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
591 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
592 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
593 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
594 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
595 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
596 ])
597 }
598 } else {
599 if (currentBuild.result == 'FAILURE') {
600 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 +0300601
Jakub Josefa63f9862018-01-11 17:58:38 +0100602 if (common.validInputParam('SALT_MASTER_URL')) {
603 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
604 }
Ales Komarek24097402017-05-22 16:28:10 +0200605 }
606 }
607 }
608 }
609}