blob: 989d13083ef0017a10fc171b64c6cad3322ede5d [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}
Jakub Josefa63f9862018-01-11 17:58:38 +010090timeout(time: 12, unit: 'HOURS') {
91 node(slave_node) {
92 try {
93 // Set build-specific variables
Jakub Josef88aaf832018-01-18 16:18:28 +010094 def workspace = common.getWorkspace()
95 venv = "${workspace}/venv"
96 venvPepper = "${workspace}/venvPepper"
Oleh Hryhorov9630a762017-10-24 14:33:25 +030097
Jakub Josefa63f9862018-01-11 17:58:38 +010098 //
99 // Prepare machines
100 //
101 stage ('Create infrastructure') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200102
Jakub Josefa63f9862018-01-11 17:58:38 +0100103 outputs.put('stack_type', STACK_TYPE)
Ales Komarek24097402017-05-22 16:28:10 +0200104
Jakub Josefa63f9862018-01-11 17:58:38 +0100105 if (STACK_TYPE == 'heat') {
106 // value defaults
107 envParams = [
108 'cluster_zone': HEAT_STACK_ZONE,
109 'cluster_public_net': HEAT_STACK_PUBLIC_NET
110 ]
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200111
Jakub Josefa63f9862018-01-11 17:58:38 +0100112 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
113 error("If you want to reuse existing stack you need to provide it's name")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400114 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200115
Jakub Josefa63f9862018-01-11 17:58:38 +0100116 if (STACK_REUSE.toBoolean() == false) {
117 // Don't allow to set custom heat stack name
118 wrap([$class: 'BuildUser']) {
119 if (env.BUILD_USER_ID) {
120 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
121 } else {
122 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
123 }
124 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200125 }
126 }
127
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400128 // no underscore in STACK_NAME
129 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Jakub Josefa63f9862018-01-11 17:58:38 +0100130 outputs.put('stack_name', STACK_NAME)
Ales Komarek24097402017-05-22 16:28:10 +0200131
Jakub Josefa63f9862018-01-11 17:58:38 +0100132 // set description
133 currentBuild.description = "${STACK_NAME}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400134
Ales Komarek24097402017-05-22 16:28:10 +0200135 // get templates
136 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
137
Jakub Josefa63f9862018-01-11 17:58:38 +0100138 // create openstack env
139 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
Jakub Josef88aaf832018-01-18 16:18:28 +0100140 openstackCloud = openstack.createOpenstackEnv(venv,
Jakub Josefa63f9862018-01-11 17:58:38 +0100141 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
142 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
143 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
144 OPENSTACK_API_VERSION)
145 openstack.getKeystoneToken(openstackCloud, venv)
Ales Komarek24097402017-05-22 16:28:10 +0200146
Jakub Josefa63f9862018-01-11 17:58:38 +0100147 //
148 // Verify possibility of create stack for given user and stack type
149 //
150 wrap([$class: 'BuildUser']) {
151 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
152 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
153 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
154 STACK_DELETE = "false"
155 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
156 }
157 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200158 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100159 // launch stack
160 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400161
Jakub Josefa63f9862018-01-11 17:58:38 +0100162 // set reclass repo in heat env
163 try {
164 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
165 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
166 } catch (MissingPropertyException e) {
167 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 +0100168 }
169
Jakub Josefa63f9862018-01-11 17:58:38 +0100170 // put formulas revision - stable, testing or nightly
171 if (common.validInputParam('FORMULA_PKG_REVISION')) {
172 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
173 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
174 }
175
176 // put extra repo definitions
177 if (common.validInputParam('BOOTSTRAP_EXTRA_REPO_PARAMS')) {
178 common.infoMsg("Setting additional repo during bootstrap to ${BOOTSTRAP_EXTRA_REPO_PARAMS}")
179 envParams.put('cfg_bootstrap_extra_repo_params', BOOTSTRAP_EXTRA_REPO_PARAMS)
180 }
181
182 // put extra salt-formulas
183 if (common.validInputParam('EXTRA_FORMULAS')) {
184 common.infoMsg("Setting extra salt-formulas to ${EXTRA_FORMULAS}")
185 envParams.put('cfg_extra_formulas', EXTRA_FORMULAS)
186 }
187
188 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
189 }
190
191 // get SALT_MASTER_URL
192 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
193 // check that saltMasterHost is valid
194 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
195 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
196 throw new Exception("saltMasterHost is not a valid ip")
197 }
198
199 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
200
201 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
202
203 } else if (STACK_TYPE == 'aws') {
204
205 // setup environment
206 aws.setupVirtualEnv(venv)
207
208 // set aws_env_vars
209 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
210
211 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
212 error("If you want to reuse existing stack you need to provide it's name")
213 }
214
215 if (STACK_REUSE.toBoolean() == false) {
216 // Don't allow to set custom stack name
217 wrap([$class: 'BuildUser']) {
218 if (env.BUILD_USER_ID) {
219 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
220 } else {
221 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
222 }
223 }
224
225 // no underscore in STACK_NAME
226 STACK_NAME = STACK_NAME.replaceAll('_', '-')
227 }
228
229 // set description
230 currentBuild.description = STACK_NAME
231 outputs.put('stack_name', STACK_NAME)
232
233 if (STACK_REUSE.toBoolean() == false) {
234 // get templates
235 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
236
237 // start stack
238 def stack_params = [
239 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
240 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
241 ]
242 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
243 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
244 }
245
246 // wait for stack to be ready
247 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
248
249 // get outputs
250 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
251
252 // check that saltMasterHost is valid
253 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
254 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
255 throw new Exception("saltMasterHost is not a valid ip")
256 }
257
258 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
259 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
260
261 } else if (STACK_TYPE != 'physical') {
262 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
263 }
264
265 outputs.put('salt_api', SALT_MASTER_URL)
266
267 // Setup virtualenv for pepper
268 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
269 }
270
271
272 // Set up override params
273 if (common.validInputParam('SALT_OVERRIDES')) {
274 stage('Set Salt overrides') {
275 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES)
276 }
277 }
278
279 //
280 // Install
281 //
282
283 if (common.checkContains('STACK_INSTALL', 'core')) {
284 stage('Install core infrastructure') {
285 def staticMgmtNetwork = false
286 if (common.validInputParam('STATIC_MGMT_NETWORK')) {
287 staticMgmtNetwork = STATIC_MGMT_NETWORK.toBoolean()
288 }
289 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
290
291 if (common.checkContains('STACK_INSTALL', 'kvm')) {
292 orchestrate.installInfraKvm(venvPepper)
293 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
294 }
295
296 orchestrate.validateFoundationInfra(venvPepper)
297 }
298 }
299
300 // install k8s
301 if (common.checkContains('STACK_INSTALL', 'k8s')) {
302
303 stage('Install Kubernetes infra') {
304 if (STACK_TYPE == 'aws') {
305 // configure kubernetes_control_address - save loadbalancer
306 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
307 common.prettyPrint(awsOutputs)
308 if (awsOutputs.containsKey('ControlLoadBalancer')) {
309 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
310 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
311 }
312 }
313
314 // ensure certificates are generated properly
315 salt.runSaltProcessStep(venvPepper, '*', 'saltutil.refresh_pillar', [], null, true)
316 salt.enforceState(venvPepper, '*', ['salt.minion.cert'], true)
317
318 orchestrate.installKubernetesInfra(venvPepper)
319 }
320
321 if (common.checkContains('STACK_INSTALL', 'contrail')) {
322 stage('Install Contrail for Kubernetes') {
323 orchestrate.installContrailNetwork(venvPepper)
324 orchestrate.installContrailCompute(venvPepper)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200325 }
Ales Komarek24097402017-05-22 16:28:10 +0200326 }
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100327
Jakub Josefa63f9862018-01-11 17:58:38 +0100328 stage('Install Kubernetes control') {
329 orchestrate.installKubernetesControl(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400330
Jakub Josefa63f9862018-01-11 17:58:38 +0100331 // collect artifacts (kubeconfig)
332 writeFile(file: 'kubeconfig', text: salt.getFileContent(venvPepper, 'I@kubernetes:master and *01*', '/etc/kubernetes/admin-kube-config'))
333 archiveArtifacts(artifacts: 'kubeconfig')
vrovachev7be1e962017-07-05 13:28:26 +0400334 }
335
Jakub Josefa63f9862018-01-11 17:58:38 +0100336 stage('Install Kubernetes computes') {
337 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
338 if (STACK_COMPUTE_COUNT > 0) {
339 if (STACK_TYPE == 'aws') {
340 // get stack info
341 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
342
343 //update autoscaling group
344 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
345
346 // wait for computes to boot up
347 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
348 sleep(60)
349
350 } else if (STACK_TYPE == 'heat') {
351 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
352
353 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
354 sleep(60)
355 }
356
357 }
358 }
359
360 orchestrate.installKubernetesCompute(venvPepper)
361 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400362 }
Ales Komarek24097402017-05-22 16:28:10 +0200363
Jakub Josefa63f9862018-01-11 17:58:38 +0100364 // install openstack
365 if (common.checkContains('STACK_INSTALL', 'openstack')) {
366 // install Infra and control, tests, ...
367
368 stage('Install OpenStack infra') {
369 orchestrate.installOpenstackInfra(venvPepper)
370 }
371
372 stage('Install OpenStack control') {
373 orchestrate.installOpenstackControl(venvPepper)
374 }
375
376 stage('Install OpenStack network') {
377
378 if (common.checkContains('STACK_INSTALL', 'contrail')) {
379 orchestrate.installContrailNetwork(venvPepper)
380 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
381 orchestrate.installOpenstackNetwork(venvPepper)
382 }
383
384 salt.runSaltProcessStep(venvPepper, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
385 salt.runSaltProcessStep(venvPepper, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
386 }
387
388 if (salt.testTarget(venvPepper, 'I@ironic:conductor')){
389 stage('Install OpenStack Ironic conductor') {
390 orchestrate.installIronicConductor(venvPepper)
391 }
392 }
393
394
395 stage('Install OpenStack compute') {
396 orchestrate.installOpenstackCompute(venvPepper)
397
398 if (common.checkContains('STACK_INSTALL', 'contrail')) {
399 orchestrate.installContrailCompute(venvPepper)
400 }
401 }
402
403 }
404
405 // install ceph
406 if (common.checkContains('STACK_INSTALL', 'ceph')) {
407 stage('Install Ceph MONs') {
408 orchestrate.installCephMon(venvPepper)
409 }
410
411 stage('Install Ceph OSDs') {
412 orchestrate.installCephOsd(venvPepper)
413 }
414
415
416 stage('Install Ceph clients') {
417 orchestrate.installCephClient(venvPepper)
418 }
419
420 stage('Connect Ceph') {
421 orchestrate.connectCeph(venvPepper)
422 }
423 }
424
425 if (common.checkContains('STACK_INSTALL', 'oss')) {
426 stage('Install Oss infra') {
427 orchestrate.installOssInfra(venvPepper)
428 }
429 }
430
431 if (common.checkContains('STACK_INSTALL', 'cicd')) {
432 stage('Install Cicd') {
433 orchestrate.installInfra(venvPepper)
434 orchestrate.installDockerSwarm(venvPepper)
435 orchestrate.installCicd(venvPepper)
436 }
437 }
438
439 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
440 stage('Install StackLight v1') {
441 orchestrate.installStacklightv1Control(venvPepper)
442 orchestrate.installStacklightv1Client(venvPepper)
443 }
444 }
445
446 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
447 stage('Install StackLight') {
448 orchestrate.installDockerSwarm(venvPepper)
449 orchestrate.installStacklight(venvPepper)
450 }
451 }
452
453 if (common.checkContains('STACK_INSTALL', 'oss')) {
454 stage('Install OSS') {
455 if (!common.checkContains('STACK_INSTALL', 'stacklight')) {
456 // In case if StackLightv2 enabled containers already started
457 orchestrate.installDockerSwarm(venvPepper)
458 salt.enforceState(venvPepper, 'I@docker:swarm:role:master and I@devops_portal:config', 'docker.client', true)
459 }
460 orchestrate.installOss(venvPepper)
461 }
462 }
463
464 //
465 // Test
466 //
467 def artifacts_dir = '_artifacts/'
468
469 if (common.checkContains('STACK_TEST', 'k8s')) {
470 stage('Run k8s conformance e2e tests') {
471 def image = TEST_K8S_CONFORMANCE_IMAGE
472 def output_file = image.replaceAll('/', '-') + '.output'
473
474 // run image
475 test.runConformanceTests(venvPepper, 'ctl01*', TEST_K8S_API_SERVER, image)
476
477 // collect output
478 sh "mkdir -p ${artifacts_dir}"
479 file_content = salt.getFileContent(venvPepper, 'ctl01*', '/tmp/' + output_file)
480 writeFile file: "${artifacts_dir}${output_file}", text: file_content
481 sh "cat ${artifacts_dir}${output_file}"
482
483 // collect artifacts
484 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
485 }
486 }
487
488 if (common.checkContains('STACK_TEST', 'openstack')) {
489 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
490 test.install_docker(venvPepper, TEST_TEMPEST_TARGET)
491 }
492 stage('Run OpenStack tests') {
493 test.runTempestTests(venvPepper, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
494 }
495
496 stage('Copy Tempest results to config node') {
497 test.copyTempestResults(venvPepper, TEST_TEMPEST_TARGET)
498 }
499
500 stage('Archive rally artifacts') {
501 test.archiveRallyArtifacts(venvPepper, TEST_TEMPEST_TARGET)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200502 }
Ales Komarek24097402017-05-22 16:28:10 +0200503 }
504
Ales Komarek24097402017-05-22 16:28:10 +0200505
Jakub Josefa63f9862018-01-11 17:58:38 +0100506 if (common.checkContains('STACK_TEST', 'ceph')) {
507 stage('Run infra tests') {
508 sleep(120)
509 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/"
510 salt.cmdRun(venvPepper, 'I@salt:master', cmd, false)
511 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, 'I@salt:master', '/root/report.xml'))
512 junit(keepLongStdio: true, testResults: 'report.xml')
Martin Polreich46971102017-07-11 12:56:40 +0200513 }
514 }
515
Jakub Josefa63f9862018-01-11 17:58:38 +0100516 if (common.checkContains('STACK_TEST', 'opencontrail')) {
517 stage('Run opencontrail tests') {
518 def opencontrail_tests_dir = "/opt/opencontrail_test/fuel-plugin-contrail/plugin_test/vapor/"
519 def report_dir = "/opt/opencontrail-test-report/"
520 def cmd = ". ${opencontrail_tests_dir}exports.sh && " +
521 "cd ${opencontrail_tests_dir} && " +
522 "py.test --junit-xml=${report_dir}report.xml" +
523 " --html=${report_dir}report.html -v vapor/tests/ -k 'not destructive' "
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400524
Jakub Josefa63f9862018-01-11 17:58:38 +0100525 salt.runSaltProcessStep(venvPepper, 'cfg*', 'saltutil.refresh_pillar', [], null, true)
526 salt.enforceState(venvPepper, 'I@opencontrail:test' , 'opencontrail.test' , true)
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100527
Jakub Josefa63f9862018-01-11 17:58:38 +0100528 salt.cmdRun(venvPepper, 'I@opencontrail:test', cmd, false)
529
530 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper,
531 'I@opencontrail:test', "${report_dir}report.xml"))
532 junit(keepLongStdio: true, testResults: 'report.xml')
533 }
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100534 }
535
536
Jakub Josefa63f9862018-01-11 17:58:38 +0100537 stage('Finalize') {
538 if (common.checkContains('STACK_INSTALL', 'finalize')) {
539 salt.runSaltProcessStep(venvPepper, '*', 'state.apply', [], null, true)
540 }
541
542 outputsPretty = common.prettify(outputs)
543 print(outputsPretty)
544 writeFile(file: 'outputs.json', text: outputsPretty)
545 archiveArtifacts(artifacts: 'outputs.json')
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100546 }
547
Jakub Josefa63f9862018-01-11 17:58:38 +0100548 } catch (Throwable e) {
549 currentBuild.result = 'FAILURE'
550 throw e
551 } finally {
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100552
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400553
Jakub Josefa63f9862018-01-11 17:58:38 +0100554 //
555 // Clean
556 //
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400557
Jakub Josefa63f9862018-01-11 17:58:38 +0100558 if (common.validInputParam('STACK_NAME')) {
559 // send notification
560 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
Ales Komarek24097402017-05-22 16:28:10 +0200561 }
562
Jakub Josefa63f9862018-01-11 17:58:38 +0100563 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
564 stage('Trigger cleanup job') {
565 common.errorMsg('Stack cleanup job triggered')
566 build(job: STACK_CLEANUP_JOB, parameters: [
567 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
568 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
569 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
570 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
571 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
572 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
573 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
574 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
575 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
576 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
577 ])
578 }
579 } else {
580 if (currentBuild.result == 'FAILURE') {
581 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 +0300582
Jakub Josefa63f9862018-01-11 17:58:38 +0100583 if (common.validInputParam('SALT_MASTER_URL')) {
584 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
585 }
Ales Komarek24097402017-05-22 16:28:10 +0200586 }
587 }
588 }
589 }
590}