blob: 2f3386f4d6515bca3a6d6187120c74a62c24998a [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ál8e50d8e2017-09-01 17:40:53 +020067def outputs = [:]
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020068
chnydae14058a2017-08-29 15:07:48 +020069def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
70
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020071if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020072 def aws_env_vars
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020073}
74
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040075node("python") {
76 try {
77 // Set build-specific variables
78 venv = "${env.WORKSPACE}/venv"
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020079
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040080 //
81 // Prepare machines
82 //
83 stage ('Create infrastructure') {
Ales Komarek24097402017-05-22 16:28:10 +020084
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020085 outputs.put('stack_type', STACK_TYPE)
86
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040087 if (STACK_TYPE == 'heat') {
88 // value defaults
89 def openstackCloud
Ales Komarek24097402017-05-22 16:28:10 +020090
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040091 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
92 error("If you want to reuse existing stack you need to provide it's name")
93 }
94
95 if (STACK_REUSE.toBoolean() == false) {
96 // Don't allow to set custom heat stack name
97 wrap([$class: 'BuildUser']) {
98 if (env.BUILD_USER_ID) {
99 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
100 } else {
101 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
102 }
103 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200104 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400105 }
Ales Komarek24097402017-05-22 16:28:10 +0200106
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400107 // set description
108 currentBuild.description = "${STACK_NAME}"
109
110 // get templates
111 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
112
113 // create openstack env
114 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
115 openstackCloud = openstack.createOpenstackEnv(
116 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
117 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
118 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
119 OPENSTACK_API_VERSION)
120 openstack.getKeystoneToken(openstackCloud, venv)
121 //
122 // Verify possibility of create stack for given user and stack type
123 //
124 wrap([$class: 'BuildUser']) {
125 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
126 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}", venv)
127 if(existingStacks.size() >= _MAX_PERMITTED_STACKS){
128 STACK_DELETE = "false"
129 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
130 }
131 }
132 }
133 // launch stack
134 if (STACK_REUSE.toBoolean() == false) {
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200135 envParams = [
136 'cluster_zone': HEAT_STACK_ZONE,
137 'cluster_public_net': HEAT_STACK_PUBLIC_NET
138 ]
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400139
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200140 // set reclass repo in heat env
141 try {
142 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
143 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
144 } catch (MissingPropertyException e) {
145 common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400146 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200147
Mykyta Karpin0aa35d52017-08-28 11:44:42 +0300148 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400149 }
150
151 // get SALT_MASTER_URL
152 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
chnydae14058a2017-08-29 15:07:48 +0200153 // check that saltMasterHost is valid
154 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
155 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
156 throw new Exception("saltMasterHost is not a valid ip")
157 }
158
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400159 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
160
161 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
162
163 } else if (STACK_TYPE == 'aws') {
164
165 // setup environment
166 aws.setupVirtualEnv(venv)
167
168 // set aws_env_vars
169 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
170
171 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
172 error("If you want to reuse existing stack you need to provide it's name")
173 }
174
175 if (STACK_REUSE.toBoolean() == false) {
176 // Don't allow to set custom stack name
177 wrap([$class: 'BuildUser']) {
178 if (env.BUILD_USER_ID) {
179 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
180 } else {
181 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
Ales Komarek24097402017-05-22 16:28:10 +0200182 }
183 }
184
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400185 // no underscore in STACK_NAME
186 STACK_NAME = STACK_NAME.replaceAll('_', '-')
187 }
Ales Komarek24097402017-05-22 16:28:10 +0200188
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400189 // set description
190 currentBuild.description = STACK_NAME
191
192 if (STACK_REUSE.toBoolean() == false) {
Ales Komarek24097402017-05-22 16:28:10 +0200193 // get templates
194 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
195
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400196 // start stack
197 def stack_params = [
198 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
199 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
200 ]
201 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
202 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200203 }
Ales Komarek24097402017-05-22 16:28:10 +0200204
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400205 // wait for stack to be ready
206 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
207
208 // get outputs
209 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200210
chnydae14058a2017-08-29 15:07:48 +0200211 // check that saltMasterHost is valid
212 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
213 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
214 throw new Exception("saltMasterHost is not a valid ip")
215 }
216
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200217 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400218 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
219
220 } else if (STACK_TYPE != 'physical') {
221 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
Ales Komarek24097402017-05-22 16:28:10 +0200222 }
223
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200224 outputs.put('salt_api', SALT_MASTER_URL)
225
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400226 // Connect to Salt master
227 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
228 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200229
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400230
231 // Set up override params
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200232 if (common.validInputParam('SALT_OVERRIDES')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400233 stage('Set Salt overrides') {
234 salt.setSaltOverrides(saltMaster, SALT_OVERRIDES)
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200235 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400236 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200237
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400238 //
239 // Install
240 //
Ales Komarek24097402017-05-22 16:28:10 +0200241
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400242 if (common.checkContains('STACK_INSTALL', 'core')) {
243 stage('Install core infrastructure') {
244 orchestrate.installFoundationInfra(saltMaster)
245
246 if (common.checkContains('STACK_INSTALL', 'kvm')) {
247 orchestrate.installInfraKvm(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200248 orchestrate.installFoundationInfra(saltMaster)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400249 }
Ales Komarek24097402017-05-22 16:28:10 +0200250
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400251 orchestrate.validateFoundationInfra(saltMaster)
252 }
253 }
Ales Komarek24097402017-05-22 16:28:10 +0200254
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200255 // install ceph
256 if (common.checkContains('STACK_INSTALL', 'ceph')) {
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200257 stage('Install Ceph MONs') {
258 orchestrate.installCephMon(saltMaster)
259 }
260
261 stage('Install Ceph OSDs') {
262 orchestrate.installCephOsd(saltMaster)
263 }
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200264
Tomáš Kukrál0cc01092017-08-28 18:25:00 +0200265
266 stage('Install Ceph clients') {
267 orchestrate.installCephClient(saltMaster)
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200268 }
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200269 }
270
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400271 // install k8s
272 if (common.checkContains('STACK_INSTALL', 'k8s')) {
273
274 stage('Install Kubernetes infra') {
275 if (STACK_TYPE == 'aws') {
276 // configure kubernetes_control_address - save loadbalancer
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200277 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
Tomáš Kukrál685f3b82017-09-03 10:14:40 +0200278 common.prettyPrint(awsOutputs)
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200279 if (awsOutputs.containsKey('ControlLoadBalancer')) {
280 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
281 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
282 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400283 }
284
285 // ensure certificates are generated properly
286 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true)
287 salt.enforceState(saltMaster, '*', ['salt.minion.cert'], true)
288
289 orchestrate.installKubernetesInfra(saltMaster)
290 }
291
292 if (common.checkContains('STACK_INSTALL', 'contrail')) {
293 stage('Install Contrail for Kubernetes') {
294 orchestrate.installContrailNetwork(saltMaster)
295 orchestrate.installContrailCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200296 }
297 }
298
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400299 stage('Install Kubernetes control') {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400300 orchestrate.installKubernetesControl(saltMaster)
Tomáš Kukrál7e487062017-08-31 11:20:08 +0200301
302 // collect artifacts (kubeconfig)
Tomáš Kukrál897b7a72017-08-31 11:54:33 +0200303 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 +0200304 archiveArtifacts(artifacts: 'kubeconfig')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400305 }
306
307 stage('Scale Kubernetes computes') {
308 if (STACK_COMPUTE_COUNT > 0) {
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200309 if (STACK_TYPE == 'aws') {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400310 // get stack info
311 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
312
313 //update autoscaling group
314 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
315
316 // wait for computes to boot up
317 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
318 sleep(60)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200319 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200320
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400321 orchestrate.installKubernetesCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200322 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400323 }
324 }
325
326 // install openstack
327 if (common.checkContains('STACK_INSTALL', 'openstack')) {
328 // install Infra and control, tests, ...
329
330 stage('Install OpenStack infra') {
331 orchestrate.installOpenstackInfra(saltMaster)
332 }
333
334 stage('Install OpenStack control') {
335 orchestrate.installOpenstackControl(saltMaster)
336 }
337
338 stage('Install OpenStack network') {
Ales Komarek24097402017-05-22 16:28:10 +0200339
vrovachev7be1e962017-07-05 13:28:26 +0400340 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400341 orchestrate.installContrailNetwork(saltMaster)
342 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
343 orchestrate.installOpenstackNetwork(saltMaster)
vrovachev7be1e962017-07-05 13:28:26 +0400344 }
345
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400346 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
347 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
348 }
Ales Komarek24097402017-05-22 16:28:10 +0200349
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400350 if (salt.testTarget(saltMaster, 'I@ironic:conductor')){
351 stage('Install OpenStack Ironic conductor') {
352 orchestrate.installIronicConductor(saltMaster)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200353 }
Ales Komarek24097402017-05-22 16:28:10 +0200354 }
355
Ales Komarek24097402017-05-22 16:28:10 +0200356
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400357 stage('Install OpenStack compute') {
358 orchestrate.installOpenstackCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200359
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400360 if (common.checkContains('STACK_INSTALL', 'contrail')) {
361 orchestrate.installContrailCompute(saltMaster)
Martin Polreich46971102017-07-11 12:56:40 +0200362 }
363 }
364
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400365 }
366
367
368 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
369 stage('Install StackLight v1') {
370 orchestrate.installStacklightv1Control(saltMaster)
371 orchestrate.installStacklightv1Client(saltMaster)
372 }
373 }
374
375 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
376 stage('Install StackLight') {
377 orchestrate.installDockerSwarm(saltMaster)
378 orchestrate.installStacklight(saltMaster)
379 }
380 }
381
382 //
383 // Test
384 //
385 def artifacts_dir = '_artifacts/'
386
387 if (common.checkContains('STACK_TEST', 'k8s')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400388 stage('Run k8s conformance e2e tests') {
Anna Babich12dd5b12017-08-21 18:01:35 +0300389 def image = TEST_K8S_CONFORMANCE_IMAGE
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400390 def output_file = image.replaceAll('/', '-') + '.output'
Ales Komarek24097402017-05-22 16:28:10 +0200391
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400392 // run image
393 test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image)
Ales Komarek24097402017-05-22 16:28:10 +0200394
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400395 // collect output
396 sh "mkdir -p ${artifacts_dir}"
397 file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
398 writeFile file: "${artifacts_dir}${output_file}", text: file_content
399 sh "cat ${artifacts_dir}${output_file}"
Ales Komarek24097402017-05-22 16:28:10 +0200400
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400401 // collect artifacts
402 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
403 }
404 }
Ales Komarek24097402017-05-22 16:28:10 +0200405
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400406 if (common.checkContains('STACK_TEST', 'openstack')) {
407 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
408 test.install_docker(saltMaster, TEST_TEMPEST_TARGET)
409 }
410 stage('Run OpenStack tests') {
411 test.runTempestTests(saltMaster, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
Ales Komarek24097402017-05-22 16:28:10 +0200412 }
413
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400414 stage('Copy Tempest results to config node') {
415 test.copyTempestResults(saltMaster, TEST_TEMPEST_TARGET)
Ales Komarek24097402017-05-22 16:28:10 +0200416 }
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300417
418 stage('Archive rally artifacts') {
419 test.archiveRallyArtifacts(saltMaster, TEST_TEMPEST_TARGET)
420 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400421 }
Ales Komarek24097402017-05-22 16:28:10 +0200422
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200423
424 if (common.checkContains('STACK_TEST', 'ceph')) {
Tomáš Kukrálf5798082017-08-21 22:37:41 +0200425 stage('Run infra tests') {
Tomáš Kukrál36d43972017-08-30 12:43:17 +0200426 sleep(120)
Tomáš Kukrál07ad0c92017-08-21 23:19:40 +0200427 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 +0200428 salt.cmdRun(saltMaster, 'I@salt:master', cmd, false)
Tomáš Kukrál09d67cd2017-08-21 23:22:21 +0200429 writeFile(file: 'report.xml', text: salt.getFileContent(saltMaster, 'I@salt:master', '/root/report.xml'))
Tomáš Kukrálc48456a2017-08-21 23:03:37 +0200430 junit(keepLongStdio: true, testResults: 'report.xml')
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200431 }
432 }
433
434
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200435 stage('Finalize') {
436 if (common.checkContains('STACK_INSTALL', 'finalize')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400437 salt.runSaltProcessStep(saltMaster, '*', 'state.apply', [], null, true)
Ales Komarek24097402017-05-22 16:28:10 +0200438 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200439
440 outputsPretty = common.prettify(outputs)
441 print(outputsPretty)
442 writeFile(file: 'outputs.json', text: outputsPretty)
443 archiveArtifacts(artifacts: 'outputs.json')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400444 }
Tomáš Kukrál53224c22017-07-26 10:53:20 +0200445
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400446 } catch (Throwable e) {
447 currentBuild.result = 'FAILURE'
448 throw e
449 } finally {
Ales Komarek24097402017-05-22 16:28:10 +0200450
451
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400452 //
453 // Clean
454 //
Ales Komarek24097402017-05-22 16:28:10 +0200455
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200456 if (common.validInputParam('STACK_NAME')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400457 // send notification
458 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
459 }
460
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200461 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400462 stage('Trigger cleanup job') {
463 common.errorMsg('Stack cleanup job triggered')
464 build(job: STACK_CLEANUP_JOB, parameters: [
465 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
466 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
467 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
468 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
469 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
470 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
471 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
472 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
473 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
474 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
475 ])
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200476 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400477 } else {
478 if (currentBuild.result == 'FAILURE') {
479 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 +0200480
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200481 if (common.validInputParam('SALT_MASTER_URL')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400482 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
Ales Komarek24097402017-05-22 16:28:10 +0200483 }
484 }
485 }
486 }
487}