blob: dd0ff0f6712c5af9e8fb79c59b58685d7b7c643e [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
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020068if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020069 def aws_env_vars
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020070}
71
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040072node("python") {
73 try {
74 // Set build-specific variables
75 venv = "${env.WORKSPACE}/venv"
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020076
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040077 //
78 // Prepare machines
79 //
80 stage ('Create infrastructure') {
Ales Komarek24097402017-05-22 16:28:10 +020081
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040082 if (STACK_TYPE == 'heat') {
83 // value defaults
84 def openstackCloud
Ales Komarek24097402017-05-22 16:28:10 +020085
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040086 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
87 error("If you want to reuse existing stack you need to provide it's name")
88 }
89
90 if (STACK_REUSE.toBoolean() == false) {
91 // Don't allow to set custom heat stack name
92 wrap([$class: 'BuildUser']) {
93 if (env.BUILD_USER_ID) {
94 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
95 } else {
96 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
97 }
98 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +020099 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400100 }
Ales Komarek24097402017-05-22 16:28:10 +0200101
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400102 // set description
103 currentBuild.description = "${STACK_NAME}"
104
105 // get templates
106 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
107
108 // create openstack env
109 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
110 openstackCloud = openstack.createOpenstackEnv(
111 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
112 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
113 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
114 OPENSTACK_API_VERSION)
115 openstack.getKeystoneToken(openstackCloud, venv)
116 //
117 // Verify possibility of create stack for given user and stack type
118 //
119 wrap([$class: 'BuildUser']) {
120 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
121 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}", venv)
122 if(existingStacks.size() >= _MAX_PERMITTED_STACKS){
123 STACK_DELETE = "false"
124 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
125 }
126 }
127 }
128 // launch stack
129 if (STACK_REUSE.toBoolean() == false) {
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200130 envParams = [
131 'cluster_zone': HEAT_STACK_ZONE,
132 'cluster_public_net': HEAT_STACK_PUBLIC_NET
133 ]
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400134
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200135 // set reclass repo in heat env
136 try {
137 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
138 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
139 } catch (MissingPropertyException e) {
140 common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400141 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200142
Mykyta Karpin0aa35d52017-08-28 11:44:42 +0300143 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400144 }
145
146 // get SALT_MASTER_URL
147 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
148 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
149
150 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
151
152 } else if (STACK_TYPE == 'aws') {
153
154 // setup environment
155 aws.setupVirtualEnv(venv)
156
157 // set aws_env_vars
158 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
159
160 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
161 error("If you want to reuse existing stack you need to provide it's name")
162 }
163
164 if (STACK_REUSE.toBoolean() == false) {
165 // Don't allow to set custom stack name
166 wrap([$class: 'BuildUser']) {
167 if (env.BUILD_USER_ID) {
168 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
169 } else {
170 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
Ales Komarek24097402017-05-22 16:28:10 +0200171 }
172 }
173
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400174 // no underscore in STACK_NAME
175 STACK_NAME = STACK_NAME.replaceAll('_', '-')
176 }
Ales Komarek24097402017-05-22 16:28:10 +0200177
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400178 // set description
179 currentBuild.description = STACK_NAME
180
181 if (STACK_REUSE.toBoolean() == false) {
Ales Komarek24097402017-05-22 16:28:10 +0200182 // get templates
183 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
184
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400185 // start stack
186 def stack_params = [
187 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
188 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
189 ]
190 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
191 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200192 }
Ales Komarek24097402017-05-22 16:28:10 +0200193
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400194 // wait for stack to be ready
195 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
196
197 // get outputs
198 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
199 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
200 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
201
202 } else if (STACK_TYPE != 'physical') {
203 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
Ales Komarek24097402017-05-22 16:28:10 +0200204 }
205
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400206 // Connect to Salt master
207 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
208 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200209
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400210
211 // Set up override params
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200212 if (common.validInputParam('SALT_OVERRIDES')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400213 stage('Set Salt overrides') {
214 salt.setSaltOverrides(saltMaster, SALT_OVERRIDES)
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200215 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400216 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200217
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400218 //
219 // Install
220 //
Ales Komarek24097402017-05-22 16:28:10 +0200221
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400222 if (common.checkContains('STACK_INSTALL', 'core')) {
223 stage('Install core infrastructure') {
224 orchestrate.installFoundationInfra(saltMaster)
225
226 if (common.checkContains('STACK_INSTALL', 'kvm')) {
227 orchestrate.installInfraKvm(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200228 orchestrate.installFoundationInfra(saltMaster)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400229 }
Ales Komarek24097402017-05-22 16:28:10 +0200230
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400231 orchestrate.validateFoundationInfra(saltMaster)
232 }
233 }
Ales Komarek24097402017-05-22 16:28:10 +0200234
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200235 // install ceph
236 if (common.checkContains('STACK_INSTALL', 'ceph')) {
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200237 stage('Install Ceph MONs') {
238 orchestrate.installCephMon(saltMaster)
239 }
240
241 stage('Install Ceph OSDs') {
242 orchestrate.installCephOsd(saltMaster)
243 }
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200244
Tomáš Kukrál0cc01092017-08-28 18:25:00 +0200245
246 stage('Install Ceph clients') {
247 orchestrate.installCephClient(saltMaster)
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200248 }
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200249 }
250
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400251 // install k8s
252 if (common.checkContains('STACK_INSTALL', 'k8s')) {
253
254 stage('Install Kubernetes infra') {
255 if (STACK_TYPE == 'aws') {
256 // configure kubernetes_control_address - save loadbalancer
257 def kubernetes_control_address = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ControlLoadBalancer')
258 print(kubernetes_control_address)
259 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', kubernetes_control_address], null, true)
260 }
261
262 // ensure certificates are generated properly
263 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true)
264 salt.enforceState(saltMaster, '*', ['salt.minion.cert'], true)
265
266 orchestrate.installKubernetesInfra(saltMaster)
267 }
268
269 if (common.checkContains('STACK_INSTALL', 'contrail')) {
270 stage('Install Contrail for Kubernetes') {
271 orchestrate.installContrailNetwork(saltMaster)
272 orchestrate.installContrailCompute(saltMaster)
273 orchestrate.installKubernetesContrailCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200274 }
275 }
276
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400277 stage('Install Kubernetes control') {
vrovachev7be1e962017-07-05 13:28:26 +0400278
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400279 orchestrate.installKubernetesControl(saltMaster)
280 }
281
282 stage('Scale Kubernetes computes') {
283 if (STACK_COMPUTE_COUNT > 0) {
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200284 if (STACK_TYPE == 'aws') {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400285 // get stack info
286 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
287
288 //update autoscaling group
289 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
290
291 // wait for computes to boot up
292 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
293 sleep(60)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200294 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200295
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400296 orchestrate.installKubernetesCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200297 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400298 }
299 }
300
301 // install openstack
302 if (common.checkContains('STACK_INSTALL', 'openstack')) {
303 // install Infra and control, tests, ...
304
305 stage('Install OpenStack infra') {
306 orchestrate.installOpenstackInfra(saltMaster)
307 }
308
309 stage('Install OpenStack control') {
310 orchestrate.installOpenstackControl(saltMaster)
311 }
312
313 stage('Install OpenStack network') {
Ales Komarek24097402017-05-22 16:28:10 +0200314
vrovachev7be1e962017-07-05 13:28:26 +0400315 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400316 orchestrate.installContrailNetwork(saltMaster)
317 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
318 orchestrate.installOpenstackNetwork(saltMaster)
vrovachev7be1e962017-07-05 13:28:26 +0400319 }
320
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400321 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
322 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
323 }
Ales Komarek24097402017-05-22 16:28:10 +0200324
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400325 if (salt.testTarget(saltMaster, 'I@ironic:conductor')){
326 stage('Install OpenStack Ironic conductor') {
327 orchestrate.installIronicConductor(saltMaster)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200328 }
Ales Komarek24097402017-05-22 16:28:10 +0200329 }
330
Ales Komarek24097402017-05-22 16:28:10 +0200331
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400332 stage('Install OpenStack compute') {
333 orchestrate.installOpenstackCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200334
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400335 if (common.checkContains('STACK_INSTALL', 'contrail')) {
336 orchestrate.installContrailCompute(saltMaster)
Martin Polreich46971102017-07-11 12:56:40 +0200337 }
338 }
339
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400340 }
341
342
343 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
344 stage('Install StackLight v1') {
345 orchestrate.installStacklightv1Control(saltMaster)
346 orchestrate.installStacklightv1Client(saltMaster)
347 }
348 }
349
350 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
351 stage('Install StackLight') {
352 orchestrate.installDockerSwarm(saltMaster)
353 orchestrate.installStacklight(saltMaster)
354 }
355 }
356
357 //
358 // Test
359 //
360 def artifacts_dir = '_artifacts/'
361
362 if (common.checkContains('STACK_TEST', 'k8s')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400363 stage('Run k8s conformance e2e tests') {
Anna Babich12dd5b12017-08-21 18:01:35 +0300364 def image = TEST_K8S_CONFORMANCE_IMAGE
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400365 def output_file = image.replaceAll('/', '-') + '.output'
Ales Komarek24097402017-05-22 16:28:10 +0200366
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400367 // run image
368 test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image)
Ales Komarek24097402017-05-22 16:28:10 +0200369
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400370 // collect output
371 sh "mkdir -p ${artifacts_dir}"
372 file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
373 writeFile file: "${artifacts_dir}${output_file}", text: file_content
374 sh "cat ${artifacts_dir}${output_file}"
Ales Komarek24097402017-05-22 16:28:10 +0200375
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400376 // collect artifacts
377 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
378 }
379 }
Ales Komarek24097402017-05-22 16:28:10 +0200380
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400381 if (common.checkContains('STACK_TEST', 'openstack')) {
382 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
383 test.install_docker(saltMaster, TEST_TEMPEST_TARGET)
384 }
385 stage('Run OpenStack tests') {
386 test.runTempestTests(saltMaster, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
Ales Komarek24097402017-05-22 16:28:10 +0200387 }
388
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400389 stage('Copy Tempest results to config node') {
390 test.copyTempestResults(saltMaster, TEST_TEMPEST_TARGET)
Ales Komarek24097402017-05-22 16:28:10 +0200391 }
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300392
393 stage('Archive rally artifacts') {
394 test.archiveRallyArtifacts(saltMaster, TEST_TEMPEST_TARGET)
395 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400396 }
Ales Komarek24097402017-05-22 16:28:10 +0200397
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200398
399 if (common.checkContains('STACK_TEST', 'ceph')) {
Tomáš Kukrálf5798082017-08-21 22:37:41 +0200400 stage('Run infra tests') {
Tomáš Kukrál07ad0c92017-08-21 23:19:40 +0200401 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 +0200402 salt.cmdRun(saltMaster, 'I@salt:master', cmd, false)
Tomáš Kukrál09d67cd2017-08-21 23:22:21 +0200403 writeFile(file: 'report.xml', text: salt.getFileContent(saltMaster, 'I@salt:master', '/root/report.xml'))
Tomáš Kukrálc48456a2017-08-21 23:03:37 +0200404 junit(keepLongStdio: true, testResults: 'report.xml')
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200405 }
406 }
407
408
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400409 if (common.checkContains('STACK_INSTALL', 'finalize')) {
410 stage('Finalize') {
411 salt.runSaltProcessStep(saltMaster, '*', 'state.apply', [], null, true)
Ales Komarek24097402017-05-22 16:28:10 +0200412 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400413 }
Tomáš Kukrál53224c22017-07-26 10:53:20 +0200414
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400415 } catch (Throwable e) {
416 currentBuild.result = 'FAILURE'
417 throw e
418 } finally {
Ales Komarek24097402017-05-22 16:28:10 +0200419
420
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400421 //
422 // Clean
423 //
Ales Komarek24097402017-05-22 16:28:10 +0200424
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200425 if (common.validInputParam('STACK_NAME')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400426 // send notification
427 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
428 }
429
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200430 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400431 stage('Trigger cleanup job') {
432 common.errorMsg('Stack cleanup job triggered')
433 build(job: STACK_CLEANUP_JOB, parameters: [
434 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
435 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
436 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
437 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
438 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
439 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
440 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
441 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
442 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
443 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
444 ])
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200445 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400446 } else {
447 if (currentBuild.result == 'FAILURE') {
448 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 +0200449
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200450 if (common.validInputParam('SALT_MASTER_URL')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400451 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
Ales Komarek24097402017-05-22 16:28:10 +0200452 }
453 }
454 }
455 }
456}