blob: 6cc6fbdf03c5fdeb653eafe2ec2cbf437d28a219 [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
21 *
Ales Komarek24097402017-05-22 16:28:10 +020022 * AWS_STACK_REGION CloudFormation AWS region
23 * AWS_API_CREDENTIALS AWS Access key ID with AWS secret access key
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020024 * AWS_SSH_KEY AWS key pair name (used for SSH access)
Ales Komarek24097402017-05-22 16:28:10 +020025 *
26 * HEAT_STACK_ENVIRONMENT Heat stack environmental parameters
27 * HEAT_STACK_ZONE Heat stack availability zone
28 * HEAT_STACK_PUBLIC_NET Heat stack floating IP pool
29 * OPENSTACK_API_URL OpenStack API address
30 * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
31 * OPENSTACK_API_PROJECT OpenStack project to connect to
32 * OPENSTACK_API_CLIENT Versions of OpenStack python clients
33 * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020034
Ales Komarek24097402017-05-22 16:28:10 +020035 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
Tomáš Kukrál4691f682017-07-27 16:36:12 +020036 * required for STACK_TYPE=physical
Ales Komarek24097402017-05-22 16:28:10 +020037 * SALT_MASTER_URL URL of Salt master
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020038
39 * Test settings:
40 * TEST_K8S_API_SERVER Kubernetes API address
41 * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
Ales Komarek24097402017-05-22 16:28:10 +020042 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020043 * TEST_DOCKER_INSTALL Install docker on the target if true
44 * TEST_TEMPEST_IMAGE Tempest image link
45 * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only
46 * TEST_TEMPEST_TARGET Salt target for tempest node
Ales Komarek24097402017-05-22 16:28:10 +020047 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020048 * optional parameters for overwriting soft params
49 * SALT_OVERRIDES YAML with overrides for Salt deployment
Ales Komarek24097402017-05-22 16:28:10 +020050 *
51 */
Tomáš Kukrál3a17dd62017-07-27 18:24:16 +020052
Ales Komarek24097402017-05-22 16:28:10 +020053common = new com.mirantis.mk.Common()
54git = new com.mirantis.mk.Git()
55openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020056aws = new com.mirantis.mk.Aws()
Ales Komarek24097402017-05-22 16:28:10 +020057orchestrate = new com.mirantis.mk.Orchestrate()
58salt = new com.mirantis.mk.Salt()
59test = new com.mirantis.mk.Test()
60
61_MAX_PERMITTED_STACKS = 2
62overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
63
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020064// Define global variables
Tomáš Kukrál31414a22017-06-09 14:17:53 +020065def saltMaster
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020066def venv
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020067
chnydae14058a2017-08-29 15:07:48 +020068def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
69
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020070if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020071 def aws_env_vars
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020072}
73
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040074node("python") {
75 try {
76 // Set build-specific variables
77 venv = "${env.WORKSPACE}/venv"
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020078
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040079 //
80 // Prepare machines
81 //
82 stage ('Create infrastructure') {
Ales Komarek24097402017-05-22 16:28:10 +020083
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040084 if (STACK_TYPE == 'heat') {
85 // value defaults
86 def openstackCloud
Ales Komarek24097402017-05-22 16:28:10 +020087
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040088 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
89 error("If you want to reuse existing stack you need to provide it's name")
90 }
91
92 if (STACK_REUSE.toBoolean() == false) {
93 // Don't allow to set custom heat stack name
94 wrap([$class: 'BuildUser']) {
95 if (env.BUILD_USER_ID) {
96 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
97 } else {
98 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
99 }
100 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200101 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400102 }
Ales Komarek24097402017-05-22 16:28:10 +0200103
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400104 // set description
105 currentBuild.description = "${STACK_NAME}"
106
107 // get templates
108 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
109
110 // create openstack env
111 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
112 openstackCloud = openstack.createOpenstackEnv(
113 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
114 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
115 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
116 OPENSTACK_API_VERSION)
117 openstack.getKeystoneToken(openstackCloud, venv)
118 //
119 // Verify possibility of create stack for given user and stack type
120 //
121 wrap([$class: 'BuildUser']) {
122 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
123 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}", venv)
124 if(existingStacks.size() >= _MAX_PERMITTED_STACKS){
125 STACK_DELETE = "false"
126 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
127 }
128 }
129 }
130 // launch stack
131 if (STACK_REUSE.toBoolean() == false) {
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200132 envParams = [
133 'cluster_zone': HEAT_STACK_ZONE,
134 'cluster_public_net': HEAT_STACK_PUBLIC_NET
135 ]
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400136
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200137 // set reclass repo in heat env
138 try {
139 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
140 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
141 } catch (MissingPropertyException e) {
142 common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400143 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200144
Mykyta Karpin0aa35d52017-08-28 11:44:42 +0300145 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400146 }
147
148 // get SALT_MASTER_URL
149 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
chnydae14058a2017-08-29 15:07:48 +0200150 // check that saltMasterHost is valid
151 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
152 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
153 throw new Exception("saltMasterHost is not a valid ip")
154 }
155
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400156 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
157
158 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
159
160 } else if (STACK_TYPE == 'aws') {
161
162 // setup environment
163 aws.setupVirtualEnv(venv)
164
165 // set aws_env_vars
166 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
167
168 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
169 error("If you want to reuse existing stack you need to provide it's name")
170 }
171
172 if (STACK_REUSE.toBoolean() == false) {
173 // Don't allow to set custom stack name
174 wrap([$class: 'BuildUser']) {
175 if (env.BUILD_USER_ID) {
176 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
177 } else {
178 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
Ales Komarek24097402017-05-22 16:28:10 +0200179 }
180 }
181
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400182 // no underscore in STACK_NAME
183 STACK_NAME = STACK_NAME.replaceAll('_', '-')
184 }
Ales Komarek24097402017-05-22 16:28:10 +0200185
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400186 // set description
187 currentBuild.description = STACK_NAME
188
189 if (STACK_REUSE.toBoolean() == false) {
Ales Komarek24097402017-05-22 16:28:10 +0200190 // get templates
191 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
192
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400193 // start stack
194 def stack_params = [
195 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
196 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
197 ]
198 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
199 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200200 }
Ales Komarek24097402017-05-22 16:28:10 +0200201
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400202 // wait for stack to be ready
203 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
204
205 // get outputs
206 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
Jakub Pavlikc65d2582017-08-31 11:21:26 +0200207 awsLoadBalancer = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ControlLoadBalancer')
chnydae14058a2017-08-29 15:07:48 +0200208 // check that saltMasterHost is valid
209 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
210 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
211 throw new Exception("saltMasterHost is not a valid ip")
212 }
213
Jakub Pavlikc65d2582017-08-31 11:21:26 +0200214 currentBuild.description = "Stack name: ${STACK_NAME}, Salt API: http://${saltMasterHost}:6969, k8s API: https://${awsLoadBalancer}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400215 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
216
217 } else if (STACK_TYPE != 'physical') {
218 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
Ales Komarek24097402017-05-22 16:28:10 +0200219 }
220
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400221 // Connect to Salt master
222 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
223 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200224
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400225
226 // Set up override params
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200227 if (common.validInputParam('SALT_OVERRIDES')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400228 stage('Set Salt overrides') {
229 salt.setSaltOverrides(saltMaster, SALT_OVERRIDES)
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200230 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400231 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200232
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400233 //
234 // Install
235 //
Ales Komarek24097402017-05-22 16:28:10 +0200236
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400237 if (common.checkContains('STACK_INSTALL', 'core')) {
238 stage('Install core infrastructure') {
239 orchestrate.installFoundationInfra(saltMaster)
240
241 if (common.checkContains('STACK_INSTALL', 'kvm')) {
242 orchestrate.installInfraKvm(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200243 orchestrate.installFoundationInfra(saltMaster)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400244 }
Ales Komarek24097402017-05-22 16:28:10 +0200245
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400246 orchestrate.validateFoundationInfra(saltMaster)
247 }
248 }
Ales Komarek24097402017-05-22 16:28:10 +0200249
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200250 // install ceph
251 if (common.checkContains('STACK_INSTALL', 'ceph')) {
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200252 stage('Install Ceph MONs') {
253 orchestrate.installCephMon(saltMaster)
254 }
255
256 stage('Install Ceph OSDs') {
257 orchestrate.installCephOsd(saltMaster)
258 }
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200259
Tomáš Kukrál0cc01092017-08-28 18:25:00 +0200260
261 stage('Install Ceph clients') {
262 orchestrate.installCephClient(saltMaster)
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200263 }
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200264 }
265
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400266 // install k8s
267 if (common.checkContains('STACK_INSTALL', 'k8s')) {
268
269 stage('Install Kubernetes infra') {
270 if (STACK_TYPE == 'aws') {
271 // configure kubernetes_control_address - save loadbalancer
272 def kubernetes_control_address = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ControlLoadBalancer')
273 print(kubernetes_control_address)
274 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', kubernetes_control_address], null, true)
275 }
276
277 // ensure certificates are generated properly
278 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true)
279 salt.enforceState(saltMaster, '*', ['salt.minion.cert'], true)
280
281 orchestrate.installKubernetesInfra(saltMaster)
282 }
283
284 if (common.checkContains('STACK_INSTALL', 'contrail')) {
285 stage('Install Contrail for Kubernetes') {
286 orchestrate.installContrailNetwork(saltMaster)
287 orchestrate.installContrailCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200288 }
289 }
290
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400291 stage('Install Kubernetes control') {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400292 orchestrate.installKubernetesControl(saltMaster)
Tomáš Kukrál7e487062017-08-31 11:20:08 +0200293
294 // collect artifacts (kubeconfig)
Tomáš Kukrál897b7a72017-08-31 11:54:33 +0200295 writeFile(file: 'kubeconfig', text: salt.getFileContent(saltMaster, 'I@kubernetes:master and *01*', '/etc/kubernetes/admin-kube-config'))
Tomáš Kukrál7e487062017-08-31 11:20:08 +0200296 archiveArtifacts(artifacts: 'kubeconfig')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400297 }
298
299 stage('Scale Kubernetes computes') {
300 if (STACK_COMPUTE_COUNT > 0) {
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200301 if (STACK_TYPE == 'aws') {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400302 // get stack info
303 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
304
305 //update autoscaling group
306 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
307
308 // wait for computes to boot up
309 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
310 sleep(60)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200311 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200312
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400313 orchestrate.installKubernetesCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200314 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400315 }
316 }
317
318 // install openstack
319 if (common.checkContains('STACK_INSTALL', 'openstack')) {
320 // install Infra and control, tests, ...
321
322 stage('Install OpenStack infra') {
323 orchestrate.installOpenstackInfra(saltMaster)
324 }
325
326 stage('Install OpenStack control') {
327 orchestrate.installOpenstackControl(saltMaster)
328 }
329
330 stage('Install OpenStack network') {
Ales Komarek24097402017-05-22 16:28:10 +0200331
vrovachev7be1e962017-07-05 13:28:26 +0400332 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400333 orchestrate.installContrailNetwork(saltMaster)
334 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
335 orchestrate.installOpenstackNetwork(saltMaster)
vrovachev7be1e962017-07-05 13:28:26 +0400336 }
337
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400338 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
339 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
340 }
Ales Komarek24097402017-05-22 16:28:10 +0200341
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400342 if (salt.testTarget(saltMaster, 'I@ironic:conductor')){
343 stage('Install OpenStack Ironic conductor') {
344 orchestrate.installIronicConductor(saltMaster)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200345 }
Ales Komarek24097402017-05-22 16:28:10 +0200346 }
347
Ales Komarek24097402017-05-22 16:28:10 +0200348
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400349 stage('Install OpenStack compute') {
350 orchestrate.installOpenstackCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200351
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400352 if (common.checkContains('STACK_INSTALL', 'contrail')) {
353 orchestrate.installContrailCompute(saltMaster)
Martin Polreich46971102017-07-11 12:56:40 +0200354 }
355 }
356
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400357 }
358
359
360 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
361 stage('Install StackLight v1') {
362 orchestrate.installStacklightv1Control(saltMaster)
363 orchestrate.installStacklightv1Client(saltMaster)
364 }
365 }
366
367 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
368 stage('Install StackLight') {
369 orchestrate.installDockerSwarm(saltMaster)
370 orchestrate.installStacklight(saltMaster)
371 }
372 }
373
374 //
375 // Test
376 //
377 def artifacts_dir = '_artifacts/'
378
379 if (common.checkContains('STACK_TEST', 'k8s')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400380 stage('Run k8s conformance e2e tests') {
Anna Babich12dd5b12017-08-21 18:01:35 +0300381 def image = TEST_K8S_CONFORMANCE_IMAGE
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400382 def output_file = image.replaceAll('/', '-') + '.output'
Ales Komarek24097402017-05-22 16:28:10 +0200383
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400384 // run image
385 test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image)
Ales Komarek24097402017-05-22 16:28:10 +0200386
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400387 // collect output
388 sh "mkdir -p ${artifacts_dir}"
389 file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
390 writeFile file: "${artifacts_dir}${output_file}", text: file_content
391 sh "cat ${artifacts_dir}${output_file}"
Ales Komarek24097402017-05-22 16:28:10 +0200392
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400393 // collect artifacts
394 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
395 }
396 }
Ales Komarek24097402017-05-22 16:28:10 +0200397
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400398 if (common.checkContains('STACK_TEST', 'openstack')) {
399 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
400 test.install_docker(saltMaster, TEST_TEMPEST_TARGET)
401 }
402 stage('Run OpenStack tests') {
403 test.runTempestTests(saltMaster, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
Ales Komarek24097402017-05-22 16:28:10 +0200404 }
405
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400406 stage('Copy Tempest results to config node') {
407 test.copyTempestResults(saltMaster, TEST_TEMPEST_TARGET)
Ales Komarek24097402017-05-22 16:28:10 +0200408 }
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300409
410 stage('Archive rally artifacts') {
411 test.archiveRallyArtifacts(saltMaster, TEST_TEMPEST_TARGET)
412 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400413 }
Ales Komarek24097402017-05-22 16:28:10 +0200414
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200415
416 if (common.checkContains('STACK_TEST', 'ceph')) {
Tomáš Kukrálf5798082017-08-21 22:37:41 +0200417 stage('Run infra tests') {
Tomáš Kukrál36d43972017-08-30 12:43:17 +0200418 sleep(120)
Tomáš Kukrál07ad0c92017-08-21 23:19:40 +0200419 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/"
Tomáš Kukrálfcb214a2017-08-25 09:47:03 +0200420 salt.cmdRun(saltMaster, 'I@salt:master', cmd, false)
Tomáš Kukrál09d67cd2017-08-21 23:22:21 +0200421 writeFile(file: 'report.xml', text: salt.getFileContent(saltMaster, 'I@salt:master', '/root/report.xml'))
Tomáš Kukrálc48456a2017-08-21 23:03:37 +0200422 junit(keepLongStdio: true, testResults: 'report.xml')
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200423 }
424 }
425
426
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400427 if (common.checkContains('STACK_INSTALL', 'finalize')) {
428 stage('Finalize') {
429 salt.runSaltProcessStep(saltMaster, '*', 'state.apply', [], null, true)
Ales Komarek24097402017-05-22 16:28:10 +0200430 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400431 }
Tomáš Kukrál53224c22017-07-26 10:53:20 +0200432
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400433 } catch (Throwable e) {
434 currentBuild.result = 'FAILURE'
435 throw e
436 } finally {
Ales Komarek24097402017-05-22 16:28:10 +0200437
438
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400439 //
440 // Clean
441 //
Ales Komarek24097402017-05-22 16:28:10 +0200442
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200443 if (common.validInputParam('STACK_NAME')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400444 // send notification
445 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
446 }
447
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200448 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400449 stage('Trigger cleanup job') {
450 common.errorMsg('Stack cleanup job triggered')
451 build(job: STACK_CLEANUP_JOB, parameters: [
452 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
453 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
454 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
455 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
456 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
457 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
458 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
459 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
460 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
461 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
462 ])
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200463 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400464 } else {
465 if (currentBuild.result == 'FAILURE') {
466 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 +0200467
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200468 if (common.validInputParam('SALT_MASTER_URL')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400469 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
Ales Komarek24097402017-05-22 16:28:10 +0200470 }
471 }
472 }
473 }
474}