blob: ad46e2f84f233f9817e4b292e35e01a4e31e6280 [file] [log] [blame]
Ales Komarek24097402017-05-22 16:28:10 +02001/**
2 *
Tomáš Kukrál0d00dd22017-07-27 14:28:36 +02003 * Launch stack and work with it
Ales Komarek24097402017-05-22 16:28:10 +02004 *
5 * Expected parameters:
6 * STACK_NAME Infrastructure stack name
Tomáš Kukrál4691f682017-07-27 16:36:12 +02007 * STACK_TEMPLATE File with stack template
8 * STACK_TYPE Deploy OpenStack/AWS [heat/aws], use 'physical' if no stack should be started
Ales Komarek24097402017-05-22 16:28:10 +02009 *
10 * STACK_TEMPLATE_URL URL to git repo with stack templates
11 * STACK_TEMPLATE_CREDENTIALS Credentials to the templates repo
12 * STACK_TEMPLATE_BRANCH Stack templates repo branch
13 *
14 * STACK_DELETE Delete stack when finished (bool)
Tomáš Kukrál4691f682017-07-27 16:36:12 +020015 * STACK_REUSE Reuse existing stack (don't create one, only read outputs)
Ales Komarek24097402017-05-22 16:28:10 +020016 * STACK_INSTALL What should be installed (k8s, openstack, ...)
17 * STACK_TEST Run tests (bool)
18 * STACK_CLEANUP_JOB Name of job for deleting stack
19 *
Tomáš Kukrál74f92862017-06-05 19:18:43 +020020 * STACK_COMPUTE_COUNT Number of compute nodes to launch
Jiri Broulik61b3e5d2017-12-19 15:42:30 +010021 * STATIC_MGMT_NETWORK Check if model contains static IP address definitions for all nodes
Tomáš Kukrál74f92862017-06-05 19:18:43 +020022 *
Ales Komarek24097402017-05-22 16:28:10 +020023 * AWS_STACK_REGION CloudFormation AWS region
24 * AWS_API_CREDENTIALS AWS Access key ID with AWS secret access key
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020025 * AWS_SSH_KEY AWS key pair name (used for SSH access)
Ales Komarek24097402017-05-22 16:28:10 +020026 *
27 * HEAT_STACK_ENVIRONMENT Heat stack environmental parameters
28 * HEAT_STACK_ZONE Heat stack availability zone
29 * HEAT_STACK_PUBLIC_NET Heat stack floating IP pool
30 * OPENSTACK_API_URL OpenStack API address
31 * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
32 * OPENSTACK_API_PROJECT OpenStack project to connect to
33 * OPENSTACK_API_CLIENT Versions of OpenStack python clients
34 * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
Oleh Hryhorov9630a762017-10-24 14:33:25 +030035 * SLAVE_NODE Lable or node name where the job will be run
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020036
Ales Komarek24097402017-05-22 16:28:10 +020037 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
Tomáš Kukrál4691f682017-07-27 16:36:12 +020038 * required for STACK_TYPE=physical
Ales Komarek24097402017-05-22 16:28:10 +020039 * SALT_MASTER_URL URL of Salt master
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020040
Oleg Iurchenko9a8c3d72017-12-21 14:55:38 +020041 * BOOTSTRAP_EXTRA_REPO_PARAMS optional parameter to define a list of extra repos with parameters
42 * which have to be added during bootstrap.
43 * Format: repo 1, repo priority 1, repo pin 1; repo 2, repo priority 2, repo pin 2;
44
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020045 * Test settings:
46 * TEST_K8S_API_SERVER Kubernetes API address
47 * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
Ales Komarek24097402017-05-22 16:28:10 +020048 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020049 * TEST_DOCKER_INSTALL Install docker on the target if true
50 * TEST_TEMPEST_IMAGE Tempest image link
51 * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only
52 * TEST_TEMPEST_TARGET Salt target for tempest node
ibumarskov637a2152018-01-16 10:39:57 +040053 * TESTRAIL_REPORT Whether upload results to testrail or not
54 * TESTRAIL_REPORTER_IMAGE Docker image for testrail reporter
55 * TESTRAIL_QA_CREDENTIALS Credentials for upload to testrail
56 * TESTRAIL_MILESTONE Product version for tests
57 * TESTRAIL_PLAN Testrail test plan
58 * TESTRAIL_GROUP Testrail test group
59 * TESTRAIL_SUITE Testrail test suite
Ales Komarek24097402017-05-22 16:28:10 +020060 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020061 * optional parameters for overwriting soft params
62 * SALT_OVERRIDES YAML with overrides for Salt deployment
Ales Komarek24097402017-05-22 16:28:10 +020063 *
64 */
Tomáš Kukrál3a17dd62017-07-27 18:24:16 +020065
Ales Komarek24097402017-05-22 16:28:10 +020066common = new com.mirantis.mk.Common()
67git = new com.mirantis.mk.Git()
68openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020069aws = new com.mirantis.mk.Aws()
Ales Komarek24097402017-05-22 16:28:10 +020070orchestrate = new com.mirantis.mk.Orchestrate()
Mykyta Karpine016d7e2017-10-09 13:35:20 +030071python = new com.mirantis.mk.Python()
Ales Komarek24097402017-05-22 16:28:10 +020072salt = new com.mirantis.mk.Salt()
73test = new com.mirantis.mk.Test()
74
75_MAX_PERMITTED_STACKS = 2
76overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
77
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020078// Define global variables
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020079def venv
chnyda597fb032017-10-06 13:42:48 +020080def venvPepper
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020081def outputs = [:]
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020082
chnydae14058a2017-08-29 15:07:48 +020083def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
84
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020085if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020086 def aws_env_vars
Tomáš Kukrál8427ff52017-08-30 15:46:52 +020087} else if (STACK_TYPE == 'heat') {
88 def envParams
89 def openstackCloud
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020090}
91
Oleh Hryhorov9630a762017-10-24 14:33:25 +030092def slave_node = 'python'
93
Oleh Hryhorov54460512017-10-26 18:45:36 +030094if (common.validInputParam('SLAVE_NODE')) {
Oleh Hryhorov9630a762017-10-24 14:33:25 +030095 slave_node = SLAVE_NODE
96}
Jakub Josefa63f9862018-01-11 17:58:38 +010097timeout(time: 12, unit: 'HOURS') {
98 node(slave_node) {
99 try {
100 // Set build-specific variables
Jakub Josef88aaf832018-01-18 16:18:28 +0100101 def workspace = common.getWorkspace()
102 venv = "${workspace}/venv"
103 venvPepper = "${workspace}/venvPepper"
Jakub Josef052e77a2018-03-05 15:19:03 +0100104 if(common.validInputParam("STACK_DELETE") && STACK_DELETE.toBoolean()){
105 common.warningMsg("You running stack with STACK_DELETE option enabled, deployed stack will be removed at the end!")
106 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100107 //
108 // Prepare machines
109 //
110 stage ('Create infrastructure') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200111
Jakub Josefa63f9862018-01-11 17:58:38 +0100112 outputs.put('stack_type', STACK_TYPE)
Ales Komarek24097402017-05-22 16:28:10 +0200113
Jakub Josefa63f9862018-01-11 17:58:38 +0100114 if (STACK_TYPE == 'heat') {
115 // value defaults
116 envParams = [
117 'cluster_zone': HEAT_STACK_ZONE,
118 'cluster_public_net': HEAT_STACK_PUBLIC_NET
119 ]
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200120
Jakub Josefa63f9862018-01-11 17:58:38 +0100121 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
122 error("If you want to reuse existing stack you need to provide it's name")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400123 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200124
Jakub Josefa63f9862018-01-11 17:58:38 +0100125 if (STACK_REUSE.toBoolean() == false) {
126 // Don't allow to set custom heat stack name
127 wrap([$class: 'BuildUser']) {
128 if (env.BUILD_USER_ID) {
129 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
130 } else {
131 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
132 }
133 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200134 }
135 }
136
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400137 // no underscore in STACK_NAME
138 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Jakub Josefa63f9862018-01-11 17:58:38 +0100139 outputs.put('stack_name', STACK_NAME)
Ales Komarek24097402017-05-22 16:28:10 +0200140
Jakub Josefa63f9862018-01-11 17:58:38 +0100141 // set description
142 currentBuild.description = "${STACK_NAME}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400143
Ales Komarek24097402017-05-22 16:28:10 +0200144 // get templates
145 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
146
Jakub Josefa63f9862018-01-11 17:58:38 +0100147 // create openstack env
148 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
Jakub Josef88aaf832018-01-18 16:18:28 +0100149 openstackCloud = openstack.createOpenstackEnv(venv,
Jakub Josefa63f9862018-01-11 17:58:38 +0100150 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
151 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
152 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
153 OPENSTACK_API_VERSION)
154 openstack.getKeystoneToken(openstackCloud, venv)
Ales Komarek24097402017-05-22 16:28:10 +0200155
Jakub Josefa63f9862018-01-11 17:58:38 +0100156 //
157 // Verify possibility of create stack for given user and stack type
158 //
159 wrap([$class: 'BuildUser']) {
160 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
161 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
162 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
163 STACK_DELETE = "false"
164 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
165 }
166 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200167 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100168 // launch stack
169 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400170
Jakub Josefa63f9862018-01-11 17:58:38 +0100171 // set reclass repo in heat env
172 try {
173 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
174 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
175 } catch (MissingPropertyException e) {
176 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 +0100177 }
178
Jakub Josefa63f9862018-01-11 17:58:38 +0100179 // put formulas revision - stable, testing or nightly
180 if (common.validInputParam('FORMULA_PKG_REVISION')) {
181 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
182 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
183 }
184
185 // put extra repo definitions
186 if (common.validInputParam('BOOTSTRAP_EXTRA_REPO_PARAMS')) {
187 common.infoMsg("Setting additional repo during bootstrap to ${BOOTSTRAP_EXTRA_REPO_PARAMS}")
188 envParams.put('cfg_bootstrap_extra_repo_params', BOOTSTRAP_EXTRA_REPO_PARAMS)
189 }
190
191 // put extra salt-formulas
192 if (common.validInputParam('EXTRA_FORMULAS')) {
193 common.infoMsg("Setting extra salt-formulas to ${EXTRA_FORMULAS}")
194 envParams.put('cfg_extra_formulas', EXTRA_FORMULAS)
195 }
196
197 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
198 }
199
200 // get SALT_MASTER_URL
201 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
202 // check that saltMasterHost is valid
203 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
204 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
205 throw new Exception("saltMasterHost is not a valid ip")
206 }
207
208 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
209
210 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
211
212 } else if (STACK_TYPE == 'aws') {
213
214 // setup environment
215 aws.setupVirtualEnv(venv)
216
217 // set aws_env_vars
218 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
219
220 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
221 error("If you want to reuse existing stack you need to provide it's name")
222 }
223
224 if (STACK_REUSE.toBoolean() == false) {
225 // Don't allow to set custom stack name
226 wrap([$class: 'BuildUser']) {
227 if (env.BUILD_USER_ID) {
228 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
229 } else {
230 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
231 }
232 }
233
234 // no underscore in STACK_NAME
235 STACK_NAME = STACK_NAME.replaceAll('_', '-')
236 }
237
238 // set description
239 currentBuild.description = STACK_NAME
240 outputs.put('stack_name', STACK_NAME)
241
242 if (STACK_REUSE.toBoolean() == false) {
243 // get templates
244 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
245
246 // start stack
247 def stack_params = [
248 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
249 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
250 ]
251 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
252 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
253 }
254
255 // wait for stack to be ready
256 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
257
258 // get outputs
259 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
260
261 // check that saltMasterHost is valid
262 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
263 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
264 throw new Exception("saltMasterHost is not a valid ip")
265 }
266
267 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
268 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
269
270 } else if (STACK_TYPE != 'physical') {
271 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
272 }
273
274 outputs.put('salt_api', SALT_MASTER_URL)
275
276 // Setup virtualenv for pepper
277 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
278 }
279
280
281 // Set up override params
282 if (common.validInputParam('SALT_OVERRIDES')) {
283 stage('Set Salt overrides') {
284 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES)
285 }
286 }
287
288 //
289 // Install
290 //
291
292 if (common.checkContains('STACK_INSTALL', 'core')) {
293 stage('Install core infrastructure') {
294 def staticMgmtNetwork = false
295 if (common.validInputParam('STATIC_MGMT_NETWORK')) {
296 staticMgmtNetwork = STATIC_MGMT_NETWORK.toBoolean()
297 }
298 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
299
300 if (common.checkContains('STACK_INSTALL', 'kvm')) {
301 orchestrate.installInfraKvm(venvPepper)
302 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
303 }
304
305 orchestrate.validateFoundationInfra(venvPepper)
306 }
307 }
308
309 // install k8s
310 if (common.checkContains('STACK_INSTALL', 'k8s')) {
311
312 stage('Install Kubernetes infra') {
313 if (STACK_TYPE == 'aws') {
314 // configure kubernetes_control_address - save loadbalancer
315 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
316 common.prettyPrint(awsOutputs)
317 if (awsOutputs.containsKey('ControlLoadBalancer')) {
318 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
319 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
320 }
321 }
322
323 // ensure certificates are generated properly
324 salt.runSaltProcessStep(venvPepper, '*', 'saltutil.refresh_pillar', [], null, true)
325 salt.enforceState(venvPepper, '*', ['salt.minion.cert'], true)
326
327 orchestrate.installKubernetesInfra(venvPepper)
328 }
329
330 if (common.checkContains('STACK_INSTALL', 'contrail')) {
331 stage('Install Contrail for Kubernetes') {
332 orchestrate.installContrailNetwork(venvPepper)
333 orchestrate.installContrailCompute(venvPepper)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200334 }
Ales Komarek24097402017-05-22 16:28:10 +0200335 }
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100336
Jakub Josefa63f9862018-01-11 17:58:38 +0100337 stage('Install Kubernetes control') {
338 orchestrate.installKubernetesControl(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400339
Jakub Josefa63f9862018-01-11 17:58:38 +0100340 // collect artifacts (kubeconfig)
341 writeFile(file: 'kubeconfig', text: salt.getFileContent(venvPepper, 'I@kubernetes:master and *01*', '/etc/kubernetes/admin-kube-config'))
342 archiveArtifacts(artifacts: 'kubeconfig')
vrovachev7be1e962017-07-05 13:28:26 +0400343 }
344
Jakub Josefa63f9862018-01-11 17:58:38 +0100345 stage('Install Kubernetes computes') {
346 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
347 if (STACK_COMPUTE_COUNT > 0) {
348 if (STACK_TYPE == 'aws') {
349 // get stack info
350 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
351
352 //update autoscaling group
353 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
354
355 // wait for computes to boot up
356 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
357 sleep(60)
358
359 } else if (STACK_TYPE == 'heat') {
360 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
361
362 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
363 sleep(60)
364 }
365
366 }
367 }
368
369 orchestrate.installKubernetesCompute(venvPepper)
370 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400371 }
Ales Komarek24097402017-05-22 16:28:10 +0200372
Jakub Josefa63f9862018-01-11 17:58:38 +0100373 // install openstack
374 if (common.checkContains('STACK_INSTALL', 'openstack')) {
375 // install Infra and control, tests, ...
376
377 stage('Install OpenStack infra') {
378 orchestrate.installOpenstackInfra(venvPepper)
379 }
380
381 stage('Install OpenStack control') {
382 orchestrate.installOpenstackControl(venvPepper)
383 }
384
Oleg Iurchenko86f1a842018-02-13 22:18:28 +0200385 // Workaround for PROD-17765 issue to prevent crashes of keystone.role_present state.
386 // More details: https://mirantis.jira.com/browse/PROD-17765
387 salt.runSaltProcessStep(venvPepper, 'I@keystone:client', 'service.restart', ['salt-minion'])
388 salt.minionsReachable(venvPepper, 'I@salt:master and *01*', 'I@keystone:client', null, 10, 6)
389
Jakub Josefa63f9862018-01-11 17:58:38 +0100390 stage('Install OpenStack network') {
391
392 if (common.checkContains('STACK_INSTALL', 'contrail')) {
393 orchestrate.installContrailNetwork(venvPepper)
394 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
395 orchestrate.installOpenstackNetwork(venvPepper)
396 }
397
Oleh Hryhorov89da0502018-02-13 16:57:46 +0200398 salt.cmdRun(venvPepper, 'I@keystone:server', '. /root/keystonercv3; openstack network list')
Jakub Josefa63f9862018-01-11 17:58:38 +0100399 }
400
401 if (salt.testTarget(venvPepper, 'I@ironic:conductor')){
402 stage('Install OpenStack Ironic conductor') {
403 orchestrate.installIronicConductor(venvPepper)
404 }
405 }
406
Vasyl Saienkob800a0f2018-02-21 18:38:53 +0200407 if (salt.testTarget(venvPepper, 'I@manila:share')){
408 stage('Install OpenStack Manila data and share') {
409 orchestrate.installManilaShare(venvPepper)
410 }
411 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100412
413 stage('Install OpenStack compute') {
414 orchestrate.installOpenstackCompute(venvPepper)
415
416 if (common.checkContains('STACK_INSTALL', 'contrail')) {
417 orchestrate.installContrailCompute(venvPepper)
418 }
419 }
420
421 }
422
423 // install ceph
424 if (common.checkContains('STACK_INSTALL', 'ceph')) {
425 stage('Install Ceph MONs') {
426 orchestrate.installCephMon(venvPepper)
427 }
428
429 stage('Install Ceph OSDs') {
430 orchestrate.installCephOsd(venvPepper)
431 }
432
433
434 stage('Install Ceph clients') {
435 orchestrate.installCephClient(venvPepper)
436 }
437
438 stage('Connect Ceph') {
439 orchestrate.connectCeph(venvPepper)
440 }
441 }
442
443 if (common.checkContains('STACK_INSTALL', 'oss')) {
444 stage('Install Oss infra') {
445 orchestrate.installOssInfra(venvPepper)
446 }
447 }
448
449 if (common.checkContains('STACK_INSTALL', 'cicd')) {
450 stage('Install Cicd') {
451 orchestrate.installInfra(venvPepper)
452 orchestrate.installDockerSwarm(venvPepper)
453 orchestrate.installCicd(venvPepper)
454 }
455 }
456
457 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
458 stage('Install StackLight v1') {
459 orchestrate.installStacklightv1Control(venvPepper)
460 orchestrate.installStacklightv1Client(venvPepper)
461 }
462 }
463
464 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
465 stage('Install StackLight') {
466 orchestrate.installDockerSwarm(venvPepper)
467 orchestrate.installStacklight(venvPepper)
468 }
469 }
470
471 if (common.checkContains('STACK_INSTALL', 'oss')) {
472 stage('Install OSS') {
473 if (!common.checkContains('STACK_INSTALL', 'stacklight')) {
474 // In case if StackLightv2 enabled containers already started
475 orchestrate.installDockerSwarm(venvPepper)
476 salt.enforceState(venvPepper, 'I@docker:swarm:role:master and I@devops_portal:config', 'docker.client', true)
477 }
478 orchestrate.installOss(venvPepper)
479 }
480 }
481
482 //
483 // Test
484 //
485 def artifacts_dir = '_artifacts/'
486
487 if (common.checkContains('STACK_TEST', 'k8s')) {
488 stage('Run k8s conformance e2e tests') {
489 def image = TEST_K8S_CONFORMANCE_IMAGE
490 def output_file = image.replaceAll('/', '-') + '.output'
vrovachevff3e72d2018-01-25 16:14:43 +0400491 def target = 'ctl01*'
492 def conformance_output_file = 'conformance_test.tar'
Jakub Josefa63f9862018-01-11 17:58:38 +0100493
494 // run image
vrovachevff3e72d2018-01-25 16:14:43 +0400495 test.runConformanceTests(venvPepper, target, TEST_K8S_API_SERVER, image)
Jakub Josefa63f9862018-01-11 17:58:38 +0100496
497 // collect output
498 sh "mkdir -p ${artifacts_dir}"
vrovachevff3e72d2018-01-25 16:14:43 +0400499 file_content = salt.getFileContent(venvPepper, target, '/tmp/' + output_file)
Jakub Josefa63f9862018-01-11 17:58:38 +0100500 writeFile file: "${artifacts_dir}${output_file}", text: file_content
501 sh "cat ${artifacts_dir}${output_file}"
502
503 // collect artifacts
504 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
vrovachevff3e72d2018-01-25 16:14:43 +0400505
506 // Copy test results
507 test.CopyConformanceResults(venvPepper, target, artifacts_dir, conformance_output_file)
Jakub Josefa63f9862018-01-11 17:58:38 +0100508 }
509 }
510
511 if (common.checkContains('STACK_TEST', 'openstack')) {
512 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
513 test.install_docker(venvPepper, TEST_TEMPEST_TARGET)
514 }
515 stage('Run OpenStack tests') {
516 test.runTempestTests(venvPepper, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
517 }
518
519 stage('Copy Tempest results to config node') {
520 test.copyTempestResults(venvPepper, TEST_TEMPEST_TARGET)
521 }
522
523 stage('Archive rally artifacts') {
524 test.archiveRallyArtifacts(venvPepper, TEST_TEMPEST_TARGET)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200525 }
ibumarskov637a2152018-01-16 10:39:57 +0400526
527 if (common.validInputParam('TESTRAIL_REPORT') && TESTRAIL_REPORT.toBoolean()) {
528 stage('Upload test results to TestRail') {
529 def date = sh(script: 'date +%Y-%m-%d', returnStdout: true).trim()
530 def plan = TESTRAIL_PLAN ?: "[${TESTRAIL_MILESTONE}]System-Devcloud-${date}"
531 def group = TESTRAIL_GROUP ?: STACK_TEMPLATE
532
533 salt.cmdRun(venvPepper, TEST_TEMPEST_TARGET, "cd /root/rally_reports && cp \$(ls -t *xml | head -n1) report.xml")
534 test.uploadResultsTestrail("/root/rally_reports/report.xml",
535 TESTRAIL_REPORTER_IMAGE, group, TESTRAIL_QA_CREDENTIALS,
536 plan, TESTRAIL_MILESTONE, TESTRAIL_SUITE)
537 }
538 }
Ales Komarek24097402017-05-22 16:28:10 +0200539 }
540
Ales Komarek24097402017-05-22 16:28:10 +0200541
Jakub Josefa63f9862018-01-11 17:58:38 +0100542 if (common.checkContains('STACK_TEST', 'ceph')) {
543 stage('Run infra tests') {
544 sleep(120)
545 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/"
546 salt.cmdRun(venvPepper, 'I@salt:master', cmd, false)
547 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, 'I@salt:master', '/root/report.xml'))
548 junit(keepLongStdio: true, testResults: 'report.xml')
Martin Polreich46971102017-07-11 12:56:40 +0200549 }
550 }
551
Jakub Josefa63f9862018-01-11 17:58:38 +0100552 if (common.checkContains('STACK_TEST', 'opencontrail')) {
553 stage('Run opencontrail tests') {
554 def opencontrail_tests_dir = "/opt/opencontrail_test/fuel-plugin-contrail/plugin_test/vapor/"
555 def report_dir = "/opt/opencontrail-test-report/"
556 def cmd = ". ${opencontrail_tests_dir}exports.sh && " +
557 "cd ${opencontrail_tests_dir} && " +
558 "py.test --junit-xml=${report_dir}report.xml" +
559 " --html=${report_dir}report.html -v vapor/tests/ -k 'not destructive' "
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400560
Jakub Josefa63f9862018-01-11 17:58:38 +0100561 salt.runSaltProcessStep(venvPepper, 'cfg*', 'saltutil.refresh_pillar', [], null, true)
562 salt.enforceState(venvPepper, 'I@opencontrail:test' , 'opencontrail.test' , true)
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100563
Jakub Josefa63f9862018-01-11 17:58:38 +0100564 salt.cmdRun(venvPepper, 'I@opencontrail:test', cmd, false)
565
566 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper,
567 'I@opencontrail:test', "${report_dir}report.xml"))
568 junit(keepLongStdio: true, testResults: 'report.xml')
569 }
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100570 }
571
572
Jakub Josefa63f9862018-01-11 17:58:38 +0100573 stage('Finalize') {
574 if (common.checkContains('STACK_INSTALL', 'finalize')) {
575 salt.runSaltProcessStep(venvPepper, '*', 'state.apply', [], null, true)
576 }
577
578 outputsPretty = common.prettify(outputs)
579 print(outputsPretty)
580 writeFile(file: 'outputs.json', text: outputsPretty)
581 archiveArtifacts(artifacts: 'outputs.json')
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100582 }
583
Jakub Josefa63f9862018-01-11 17:58:38 +0100584 } catch (Throwable e) {
585 currentBuild.result = 'FAILURE'
586 throw e
587 } finally {
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100588
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400589
Jakub Josefa63f9862018-01-11 17:58:38 +0100590 //
591 // Clean
592 //
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400593
Jakub Josefa63f9862018-01-11 17:58:38 +0100594 if (common.validInputParam('STACK_NAME')) {
595 // send notification
596 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
Ales Komarek24097402017-05-22 16:28:10 +0200597 }
598
Jakub Josefa63f9862018-01-11 17:58:38 +0100599 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
600 stage('Trigger cleanup job') {
601 common.errorMsg('Stack cleanup job triggered')
602 build(job: STACK_CLEANUP_JOB, parameters: [
603 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
604 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
605 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
606 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
607 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
608 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
609 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
610 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
611 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
612 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
613 ])
614 }
615 } else {
616 if (currentBuild.result == 'FAILURE') {
617 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 +0300618
Jakub Josefa63f9862018-01-11 17:58:38 +0100619 if (common.validInputParam('SALT_MASTER_URL')) {
620 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
621 }
Ales Komarek24097402017-05-22 16:28:10 +0200622 }
623 }
624 }
625 }
626}