blob: 3fd2b8d5098b6b5ec6e826b2d2c818c0b9d8981b [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
Vasyl Saienkoa81e9312018-03-06 01:28:35 +020021 * STACK_CLUSTER_NAME The name of cluster model to use
Jiri Broulik61b3e5d2017-12-19 15:42:30 +010022 * STATIC_MGMT_NETWORK Check if model contains static IP address definitions for all nodes
Tomáš Kukrál74f92862017-06-05 19:18:43 +020023 *
Ales Komarek24097402017-05-22 16:28:10 +020024 * AWS_STACK_REGION CloudFormation AWS region
25 * AWS_API_CREDENTIALS AWS Access key ID with AWS secret access key
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020026 * AWS_SSH_KEY AWS key pair name (used for SSH access)
Ales Komarek24097402017-05-22 16:28:10 +020027 *
28 * HEAT_STACK_ENVIRONMENT Heat stack environmental parameters
29 * HEAT_STACK_ZONE Heat stack availability zone
30 * HEAT_STACK_PUBLIC_NET Heat stack floating IP pool
31 * OPENSTACK_API_URL OpenStack API address
32 * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
33 * OPENSTACK_API_PROJECT OpenStack project to connect to
34 * OPENSTACK_API_CLIENT Versions of OpenStack python clients
35 * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
Oleh Hryhorov9630a762017-10-24 14:33:25 +030036 * SLAVE_NODE Lable or node name where the job will be run
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020037
Ales Komarek24097402017-05-22 16:28:10 +020038 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
Tomáš Kukrál4691f682017-07-27 16:36:12 +020039 * required for STACK_TYPE=physical
Ales Komarek24097402017-05-22 16:28:10 +020040 * SALT_MASTER_URL URL of Salt master
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020041
Oleg Iurchenko9a8c3d72017-12-21 14:55:38 +020042 * BOOTSTRAP_EXTRA_REPO_PARAMS optional parameter to define a list of extra repos with parameters
43 * which have to be added during bootstrap.
44 * Format: repo 1, repo priority 1, repo pin 1; repo 2, repo priority 2, repo pin 2;
45
Oleh Hryhorov825b5be2018-06-13 13:01:53 +030046 * SALT_VERSION Version of Salt which is going to be installed i.e. 'stable 2016.3' or 'stable 2017.7' etc.
47 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020048 * Test settings:
49 * TEST_K8S_API_SERVER Kubernetes API address
50 * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
Ales Komarek24097402017-05-22 16:28:10 +020051 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020052 * TEST_DOCKER_INSTALL Install docker on the target if true
53 * TEST_TEMPEST_IMAGE Tempest image link
54 * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only
55 * TEST_TEMPEST_TARGET Salt target for tempest node
ibumarskov637a2152018-01-16 10:39:57 +040056 * TESTRAIL_REPORT Whether upload results to testrail or not
57 * TESTRAIL_REPORTER_IMAGE Docker image for testrail reporter
58 * TESTRAIL_QA_CREDENTIALS Credentials for upload to testrail
59 * TESTRAIL_MILESTONE Product version for tests
60 * TESTRAIL_PLAN Testrail test plan
61 * TESTRAIL_GROUP Testrail test group
62 * TESTRAIL_SUITE Testrail test suite
Ales Komarek24097402017-05-22 16:28:10 +020063 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020064 * optional parameters for overwriting soft params
65 * SALT_OVERRIDES YAML with overrides for Salt deployment
Ales Komarek24097402017-05-22 16:28:10 +020066 *
67 */
Tomáš Kukrál3a17dd62017-07-27 18:24:16 +020068
Ales Komarek24097402017-05-22 16:28:10 +020069common = new com.mirantis.mk.Common()
70git = new com.mirantis.mk.Git()
71openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020072aws = new com.mirantis.mk.Aws()
Ales Komarek24097402017-05-22 16:28:10 +020073orchestrate = new com.mirantis.mk.Orchestrate()
Mykyta Karpine016d7e2017-10-09 13:35:20 +030074python = new com.mirantis.mk.Python()
Ales Komarek24097402017-05-22 16:28:10 +020075salt = new com.mirantis.mk.Salt()
76test = new com.mirantis.mk.Test()
77
78_MAX_PERMITTED_STACKS = 2
79overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
80
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020081// Define global variables
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020082def venv
chnyda597fb032017-10-06 13:42:48 +020083def venvPepper
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020084def outputs = [:]
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020085
chnydae14058a2017-08-29 15:07:48 +020086def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
87
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020088if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020089 def aws_env_vars
Tomáš Kukrál8427ff52017-08-30 15:46:52 +020090} else if (STACK_TYPE == 'heat') {
91 def envParams
92 def openstackCloud
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020093}
94
Oleh Hryhorov9630a762017-10-24 14:33:25 +030095def slave_node = 'python'
96
Oleh Hryhorov54460512017-10-26 18:45:36 +030097if (common.validInputParam('SLAVE_NODE')) {
Oleh Hryhorov9630a762017-10-24 14:33:25 +030098 slave_node = SLAVE_NODE
99}
Jakub Josefa63f9862018-01-11 17:58:38 +0100100timeout(time: 12, unit: 'HOURS') {
101 node(slave_node) {
102 try {
103 // Set build-specific variables
Jakub Josef88aaf832018-01-18 16:18:28 +0100104 def workspace = common.getWorkspace()
105 venv = "${workspace}/venv"
106 venvPepper = "${workspace}/venvPepper"
Jakub Josef052e77a2018-03-05 15:19:03 +0100107 if(common.validInputParam("STACK_DELETE") && STACK_DELETE.toBoolean()){
108 common.warningMsg("You running stack with STACK_DELETE option enabled, deployed stack will be removed at the end!")
109 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100110 //
111 // Prepare machines
112 //
113 stage ('Create infrastructure') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200114
Jakub Josefa63f9862018-01-11 17:58:38 +0100115 outputs.put('stack_type', STACK_TYPE)
Ales Komarek24097402017-05-22 16:28:10 +0200116
Jakub Josefa63f9862018-01-11 17:58:38 +0100117 if (STACK_TYPE == 'heat') {
118 // value defaults
119 envParams = [
120 'cluster_zone': HEAT_STACK_ZONE,
121 'cluster_public_net': HEAT_STACK_PUBLIC_NET
122 ]
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200123
Jakub Josefa63f9862018-01-11 17:58:38 +0100124 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
125 error("If you want to reuse existing stack you need to provide it's name")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400126 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200127
Jakub Josefa63f9862018-01-11 17:58:38 +0100128 if (STACK_REUSE.toBoolean() == false) {
129 // Don't allow to set custom heat stack name
130 wrap([$class: 'BuildUser']) {
131 if (env.BUILD_USER_ID) {
132 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
133 } else {
134 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
135 }
136 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200137 }
138 }
139
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400140 // no underscore in STACK_NAME
141 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Jakub Josefa63f9862018-01-11 17:58:38 +0100142 outputs.put('stack_name', STACK_NAME)
Ales Komarek24097402017-05-22 16:28:10 +0200143
Jakub Josefa63f9862018-01-11 17:58:38 +0100144 // set description
145 currentBuild.description = "${STACK_NAME}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400146
Ales Komarek24097402017-05-22 16:28:10 +0200147 // get templates
148 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
149
Jakub Josefa63f9862018-01-11 17:58:38 +0100150 // create openstack env
151 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
Jakub Josef88aaf832018-01-18 16:18:28 +0100152 openstackCloud = openstack.createOpenstackEnv(venv,
Jakub Josefa63f9862018-01-11 17:58:38 +0100153 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
154 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
155 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
156 OPENSTACK_API_VERSION)
157 openstack.getKeystoneToken(openstackCloud, venv)
Ales Komarek24097402017-05-22 16:28:10 +0200158
Jakub Josefa63f9862018-01-11 17:58:38 +0100159 //
160 // Verify possibility of create stack for given user and stack type
161 //
162 wrap([$class: 'BuildUser']) {
163 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
164 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
165 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
166 STACK_DELETE = "false"
167 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
168 }
169 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200170 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100171 // launch stack
172 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400173
Jakub Josefa63f9862018-01-11 17:58:38 +0100174 // set reclass repo in heat env
175 try {
176 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
177 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
178 } catch (MissingPropertyException e) {
179 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 +0100180 }
181
Jakub Josefa63f9862018-01-11 17:58:38 +0100182 // put formulas revision - stable, testing or nightly
183 if (common.validInputParam('FORMULA_PKG_REVISION')) {
184 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
185 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
186 }
187
188 // put extra repo definitions
189 if (common.validInputParam('BOOTSTRAP_EXTRA_REPO_PARAMS')) {
190 common.infoMsg("Setting additional repo during bootstrap to ${BOOTSTRAP_EXTRA_REPO_PARAMS}")
191 envParams.put('cfg_bootstrap_extra_repo_params', BOOTSTRAP_EXTRA_REPO_PARAMS)
192 }
193
194 // put extra salt-formulas
195 if (common.validInputParam('EXTRA_FORMULAS')) {
196 common.infoMsg("Setting extra salt-formulas to ${EXTRA_FORMULAS}")
197 envParams.put('cfg_extra_formulas', EXTRA_FORMULAS)
198 }
199
Vasyl Saienkoa81e9312018-03-06 01:28:35 +0200200 // add cluster name if specified
201 if (common.validInputParam('STACK_CLUSTER_NAME')) {
202 common.infoMsg("Setting cluster_name to ${STACK_CLUSTER_NAME}")
203 envParams.put('cluster_name', STACK_CLUSTER_NAME)
204 }
205
Vasyl Saienko51139fd2018-04-20 12:01:50 +0300206 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
207 if (STACK_COMPUTE_COUNT.toInteger() > 0){
208 common.infoMsg("Setting cluster_node_count to ${STACK_COMPUTE_COUNT}")
209 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
210 }
211 }
212
Oleh Hryhorov825b5be2018-06-13 13:01:53 +0300213
214 if (common.validInputParam('SALT_VERSION')) {
215 common.infoMsg("Setting salt version to ${SALT_VERSION}")
216 envParams.put('cfg_saltversion', SALT_VERSION)
217 }
218
Jakub Josefa63f9862018-01-11 17:58:38 +0100219 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
220 }
221
222 // get SALT_MASTER_URL
223 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
224 // check that saltMasterHost is valid
225 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
226 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
227 throw new Exception("saltMasterHost is not a valid ip")
228 }
229
230 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
231
232 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
233
234 } else if (STACK_TYPE == 'aws') {
235
236 // setup environment
237 aws.setupVirtualEnv(venv)
238
239 // set aws_env_vars
240 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
241
242 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
243 error("If you want to reuse existing stack you need to provide it's name")
244 }
245
246 if (STACK_REUSE.toBoolean() == false) {
247 // Don't allow to set custom stack name
248 wrap([$class: 'BuildUser']) {
249 if (env.BUILD_USER_ID) {
250 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
251 } else {
252 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
253 }
254 }
255
256 // no underscore in STACK_NAME
257 STACK_NAME = STACK_NAME.replaceAll('_', '-')
258 }
259
260 // set description
261 currentBuild.description = STACK_NAME
262 outputs.put('stack_name', STACK_NAME)
263
264 if (STACK_REUSE.toBoolean() == false) {
265 // get templates
266 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
267
268 // start stack
269 def stack_params = [
270 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
271 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
272 ]
273 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
274 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
275 }
276
277 // wait for stack to be ready
278 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
279
280 // get outputs
281 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
282
283 // check that saltMasterHost is valid
284 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
285 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
286 throw new Exception("saltMasterHost is not a valid ip")
287 }
288
289 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
290 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
291
292 } else if (STACK_TYPE != 'physical') {
293 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
294 }
295
296 outputs.put('salt_api', SALT_MASTER_URL)
297
298 // Setup virtualenv for pepper
299 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
300 }
301
302
303 // Set up override params
304 if (common.validInputParam('SALT_OVERRIDES')) {
305 stage('Set Salt overrides') {
306 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES)
307 }
308 }
309
310 //
311 // Install
312 //
313
314 if (common.checkContains('STACK_INSTALL', 'core')) {
315 stage('Install core infrastructure') {
316 def staticMgmtNetwork = false
317 if (common.validInputParam('STATIC_MGMT_NETWORK')) {
318 staticMgmtNetwork = STATIC_MGMT_NETWORK.toBoolean()
319 }
320 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
321
322 if (common.checkContains('STACK_INSTALL', 'kvm')) {
323 orchestrate.installInfraKvm(venvPepper)
324 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
325 }
326
327 orchestrate.validateFoundationInfra(venvPepper)
328 }
329 }
330
331 // install k8s
332 if (common.checkContains('STACK_INSTALL', 'k8s')) {
333
334 stage('Install Kubernetes infra') {
335 if (STACK_TYPE == 'aws') {
336 // configure kubernetes_control_address - save loadbalancer
337 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
338 common.prettyPrint(awsOutputs)
339 if (awsOutputs.containsKey('ControlLoadBalancer')) {
340 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
341 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
342 }
343 }
344
345 // ensure certificates are generated properly
346 salt.runSaltProcessStep(venvPepper, '*', 'saltutil.refresh_pillar', [], null, true)
347 salt.enforceState(venvPepper, '*', ['salt.minion.cert'], true)
348
349 orchestrate.installKubernetesInfra(venvPepper)
350 }
351
352 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Svimbaa554ea02018-06-06 18:45:23 +0200353 stage('Install Contrail control') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100354 orchestrate.installContrailNetwork(venvPepper)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200355 }
Ales Komarek24097402017-05-22 16:28:10 +0200356 }
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100357
Jakub Josefa63f9862018-01-11 17:58:38 +0100358 stage('Install Kubernetes control') {
359 orchestrate.installKubernetesControl(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400360
Jakub Josefa63f9862018-01-11 17:58:38 +0100361 // collect artifacts (kubeconfig)
362 writeFile(file: 'kubeconfig', text: salt.getFileContent(venvPepper, 'I@kubernetes:master and *01*', '/etc/kubernetes/admin-kube-config'))
363 archiveArtifacts(artifacts: 'kubeconfig')
vrovachev7be1e962017-07-05 13:28:26 +0400364 }
365
Svimbaa554ea02018-06-06 18:45:23 +0200366 if (common.checkContains('STACK_INSTALL', 'contrail')) {
367 stage('Install Contrail compute') {
368 orchestrate.installContrailCompute(venvPepper)
369 }
370 }
371
Jakub Josefa63f9862018-01-11 17:58:38 +0100372 stage('Install Kubernetes computes') {
373 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
374 if (STACK_COMPUTE_COUNT > 0) {
375 if (STACK_TYPE == 'aws') {
376 // get stack info
377 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
378
379 //update autoscaling group
380 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
381
382 // wait for computes to boot up
383 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
384 sleep(60)
385
386 } else if (STACK_TYPE == 'heat') {
387 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
388
389 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
390 sleep(60)
391 }
392
393 }
394 }
395
396 orchestrate.installKubernetesCompute(venvPepper)
397 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400398 }
Ales Komarek24097402017-05-22 16:28:10 +0200399
Jakub Josefa63f9862018-01-11 17:58:38 +0100400 // install openstack
401 if (common.checkContains('STACK_INSTALL', 'openstack')) {
402 // install Infra and control, tests, ...
403
404 stage('Install OpenStack infra') {
405 orchestrate.installOpenstackInfra(venvPepper)
406 }
407
408 stage('Install OpenStack control') {
409 orchestrate.installOpenstackControl(venvPepper)
410 }
411
Oleg Iurchenko86f1a842018-02-13 22:18:28 +0200412 // Workaround for PROD-17765 issue to prevent crashes of keystone.role_present state.
413 // More details: https://mirantis.jira.com/browse/PROD-17765
414 salt.runSaltProcessStep(venvPepper, 'I@keystone:client', 'service.restart', ['salt-minion'])
415 salt.minionsReachable(venvPepper, 'I@salt:master and *01*', 'I@keystone:client', null, 10, 6)
416
Jakub Josefa63f9862018-01-11 17:58:38 +0100417 stage('Install OpenStack network') {
418
419 if (common.checkContains('STACK_INSTALL', 'contrail')) {
420 orchestrate.installContrailNetwork(venvPepper)
421 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
422 orchestrate.installOpenstackNetwork(venvPepper)
423 }
424
Petr Jedinýefd668f2018-05-24 14:44:08 +0200425 // Wait for network to come up, 150s should be enough
426 common.retry(10, 15) {
427 salt.cmdRun(venvPepper, 'I@keystone:server', '. /root/keystonercv3; openstack network list')
428 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100429 }
430
431 if (salt.testTarget(venvPepper, 'I@ironic:conductor')){
432 stage('Install OpenStack Ironic conductor') {
433 orchestrate.installIronicConductor(venvPepper)
434 }
435 }
436
Vasyl Saienkob800a0f2018-02-21 18:38:53 +0200437 if (salt.testTarget(venvPepper, 'I@manila:share')){
438 stage('Install OpenStack Manila data and share') {
439 orchestrate.installManilaShare(venvPepper)
440 }
441 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100442
443 stage('Install OpenStack compute') {
444 orchestrate.installOpenstackCompute(venvPepper)
445
446 if (common.checkContains('STACK_INSTALL', 'contrail')) {
447 orchestrate.installContrailCompute(venvPepper)
448 }
449 }
450
451 }
452
453 // install ceph
454 if (common.checkContains('STACK_INSTALL', 'ceph')) {
455 stage('Install Ceph MONs') {
456 orchestrate.installCephMon(venvPepper)
457 }
458
459 stage('Install Ceph OSDs') {
460 orchestrate.installCephOsd(venvPepper)
461 }
462
463
464 stage('Install Ceph clients') {
465 orchestrate.installCephClient(venvPepper)
466 }
467
468 stage('Connect Ceph') {
469 orchestrate.connectCeph(venvPepper)
470 }
471 }
472
473 if (common.checkContains('STACK_INSTALL', 'oss')) {
474 stage('Install Oss infra') {
475 orchestrate.installOssInfra(venvPepper)
476 }
477 }
478
479 if (common.checkContains('STACK_INSTALL', 'cicd')) {
480 stage('Install Cicd') {
481 orchestrate.installInfra(venvPepper)
482 orchestrate.installDockerSwarm(venvPepper)
483 orchestrate.installCicd(venvPepper)
484 }
485 }
486
487 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
488 stage('Install StackLight v1') {
489 orchestrate.installStacklightv1Control(venvPepper)
490 orchestrate.installStacklightv1Client(venvPepper)
491 }
492 }
493
494 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
495 stage('Install StackLight') {
496 orchestrate.installDockerSwarm(venvPepper)
497 orchestrate.installStacklight(venvPepper)
498 }
499 }
500
501 if (common.checkContains('STACK_INSTALL', 'oss')) {
502 stage('Install OSS') {
503 if (!common.checkContains('STACK_INSTALL', 'stacklight')) {
504 // In case if StackLightv2 enabled containers already started
505 orchestrate.installDockerSwarm(venvPepper)
506 salt.enforceState(venvPepper, 'I@docker:swarm:role:master and I@devops_portal:config', 'docker.client', true)
507 }
508 orchestrate.installOss(venvPepper)
509 }
510 }
511
512 //
513 // Test
514 //
515 def artifacts_dir = '_artifacts/'
516
517 if (common.checkContains('STACK_TEST', 'k8s')) {
518 stage('Run k8s conformance e2e tests') {
519 def image = TEST_K8S_CONFORMANCE_IMAGE
520 def output_file = image.replaceAll('/', '-') + '.output'
vrovachevff3e72d2018-01-25 16:14:43 +0400521 def target = 'ctl01*'
522 def conformance_output_file = 'conformance_test.tar'
Jakub Josefa63f9862018-01-11 17:58:38 +0100523
524 // run image
vrovachevff3e72d2018-01-25 16:14:43 +0400525 test.runConformanceTests(venvPepper, target, TEST_K8S_API_SERVER, image)
Jakub Josefa63f9862018-01-11 17:58:38 +0100526
527 // collect output
528 sh "mkdir -p ${artifacts_dir}"
vrovachevff3e72d2018-01-25 16:14:43 +0400529 file_content = salt.getFileContent(venvPepper, target, '/tmp/' + output_file)
Jakub Josefa63f9862018-01-11 17:58:38 +0100530 writeFile file: "${artifacts_dir}${output_file}", text: file_content
531 sh "cat ${artifacts_dir}${output_file}"
532
533 // collect artifacts
534 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
vrovachevff3e72d2018-01-25 16:14:43 +0400535
536 // Copy test results
537 test.CopyConformanceResults(venvPepper, target, artifacts_dir, conformance_output_file)
Jakub Josefa63f9862018-01-11 17:58:38 +0100538 }
539 }
540
541 if (common.checkContains('STACK_TEST', 'openstack')) {
542 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
543 test.install_docker(venvPepper, TEST_TEMPEST_TARGET)
544 }
545 stage('Run OpenStack tests') {
546 test.runTempestTests(venvPepper, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
547 }
548
549 stage('Copy Tempest results to config node') {
550 test.copyTempestResults(venvPepper, TEST_TEMPEST_TARGET)
551 }
552
553 stage('Archive rally artifacts') {
554 test.archiveRallyArtifacts(venvPepper, TEST_TEMPEST_TARGET)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200555 }
ibumarskov637a2152018-01-16 10:39:57 +0400556
557 if (common.validInputParam('TESTRAIL_REPORT') && TESTRAIL_REPORT.toBoolean()) {
558 stage('Upload test results to TestRail') {
559 def date = sh(script: 'date +%Y-%m-%d', returnStdout: true).trim()
560 def plan = TESTRAIL_PLAN ?: "[${TESTRAIL_MILESTONE}]System-Devcloud-${date}"
561 def group = TESTRAIL_GROUP ?: STACK_TEMPLATE
562
563 salt.cmdRun(venvPepper, TEST_TEMPEST_TARGET, "cd /root/rally_reports && cp \$(ls -t *xml | head -n1) report.xml")
564 test.uploadResultsTestrail("/root/rally_reports/report.xml",
565 TESTRAIL_REPORTER_IMAGE, group, TESTRAIL_QA_CREDENTIALS,
566 plan, TESTRAIL_MILESTONE, TESTRAIL_SUITE)
567 }
568 }
Ales Komarek24097402017-05-22 16:28:10 +0200569 }
570
Ales Komarek24097402017-05-22 16:28:10 +0200571
Jakub Josefa63f9862018-01-11 17:58:38 +0100572 if (common.checkContains('STACK_TEST', 'ceph')) {
573 stage('Run infra tests') {
574 sleep(120)
575 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/"
576 salt.cmdRun(venvPepper, 'I@salt:master', cmd, false)
577 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, 'I@salt:master', '/root/report.xml'))
578 junit(keepLongStdio: true, testResults: 'report.xml')
Martin Polreich46971102017-07-11 12:56:40 +0200579 }
580 }
581
Jakub Josefa63f9862018-01-11 17:58:38 +0100582 if (common.checkContains('STACK_TEST', 'opencontrail')) {
583 stage('Run opencontrail tests') {
584 def opencontrail_tests_dir = "/opt/opencontrail_test/fuel-plugin-contrail/plugin_test/vapor/"
585 def report_dir = "/opt/opencontrail-test-report/"
586 def cmd = ". ${opencontrail_tests_dir}exports.sh && " +
587 "cd ${opencontrail_tests_dir} && " +
588 "py.test --junit-xml=${report_dir}report.xml" +
589 " --html=${report_dir}report.html -v vapor/tests/ -k 'not destructive' "
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400590
Jakub Josefa63f9862018-01-11 17:58:38 +0100591 salt.runSaltProcessStep(venvPepper, 'cfg*', 'saltutil.refresh_pillar', [], null, true)
592 salt.enforceState(venvPepper, 'I@opencontrail:test' , 'opencontrail.test' , true)
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100593
Jakub Josefa63f9862018-01-11 17:58:38 +0100594 salt.cmdRun(venvPepper, 'I@opencontrail:test', cmd, false)
595
596 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper,
597 'I@opencontrail:test', "${report_dir}report.xml"))
598 junit(keepLongStdio: true, testResults: 'report.xml')
599 }
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100600 }
601
602
Jakub Josefa63f9862018-01-11 17:58:38 +0100603 stage('Finalize') {
604 if (common.checkContains('STACK_INSTALL', 'finalize')) {
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100605 def gluster_compound = 'I@glusterfs:server'
Dzmitry Stremkouski47a45122018-04-25 17:05:56 +0200606 def salt_ca_compound = 'I@salt:minion:ca:salt_master_ca'
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100607 // Enforce highstate asynchronous only on the nodes which are not glusterfs servers
Dzmitry Stremkouski47a45122018-04-25 17:05:56 +0200608 salt.enforceHighstate(venvPepper, '* and not ' + gluster_compound + ' and not ' + salt_ca_compound)
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100609 // Iterate over nonempty set of gluster servers and apply highstates one by one
610 // TODO: switch to batch once salt 2017.7+ would be used
Dzmitry Stremkouski47a45122018-04-25 17:05:56 +0200611 def saltcaMinions = salt.getMinionsSorted(venvPepper, salt_ca_compound)
612 if ( !saltcaMinions.isEmpty() ) {
613 for ( target in saltcaMinions ) {
614 salt.enforceHighstate(venvPepper, target)
615 }
616 }
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100617 def glusterMinions = salt.getMinionsSorted(venvPepper, gluster_compound)
618 if ( !glusterMinions.isEmpty() ) {
619 for ( target in glusterMinions ) {
620 salt.enforceHighstate(venvPepper, target)
621 }
622 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100623 }
624
625 outputsPretty = common.prettify(outputs)
626 print(outputsPretty)
627 writeFile(file: 'outputs.json', text: outputsPretty)
628 archiveArtifacts(artifacts: 'outputs.json')
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100629 }
630
Jakub Josefa63f9862018-01-11 17:58:38 +0100631 } catch (Throwable e) {
632 currentBuild.result = 'FAILURE'
633 throw e
634 } finally {
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100635
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400636
Jakub Josefa63f9862018-01-11 17:58:38 +0100637 //
638 // Clean
639 //
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400640
Jakub Josefa63f9862018-01-11 17:58:38 +0100641 if (common.validInputParam('STACK_NAME')) {
642 // send notification
643 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
Ales Komarek24097402017-05-22 16:28:10 +0200644 }
645
Jakub Josefa63f9862018-01-11 17:58:38 +0100646 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
647 stage('Trigger cleanup job') {
648 common.errorMsg('Stack cleanup job triggered')
649 build(job: STACK_CLEANUP_JOB, parameters: [
650 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
651 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
652 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
653 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
654 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
655 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
656 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
657 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
658 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
659 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
660 ])
661 }
662 } else {
663 if (currentBuild.result == 'FAILURE') {
664 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 +0300665
Jakub Josefa63f9862018-01-11 17:58:38 +0100666 if (common.validInputParam('SALT_MASTER_URL')) {
667 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
668 }
Ales Komarek24097402017-05-22 16:28:10 +0200669 }
670 }
671 }
672 }
673}