blob: 7f7337aa05d4cd0a7761254b5b625ca29493cffe [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
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020046 * Test settings:
47 * TEST_K8S_API_SERVER Kubernetes API address
48 * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
Ales Komarek24097402017-05-22 16:28:10 +020049 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020050 * TEST_DOCKER_INSTALL Install docker on the target if true
51 * TEST_TEMPEST_IMAGE Tempest image link
52 * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only
53 * TEST_TEMPEST_TARGET Salt target for tempest node
ibumarskov637a2152018-01-16 10:39:57 +040054 * TESTRAIL_REPORT Whether upload results to testrail or not
55 * TESTRAIL_REPORTER_IMAGE Docker image for testrail reporter
56 * TESTRAIL_QA_CREDENTIALS Credentials for upload to testrail
57 * TESTRAIL_MILESTONE Product version for tests
58 * TESTRAIL_PLAN Testrail test plan
59 * TESTRAIL_GROUP Testrail test group
60 * TESTRAIL_SUITE Testrail test suite
Ales Komarek24097402017-05-22 16:28:10 +020061 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020062 * optional parameters for overwriting soft params
63 * SALT_OVERRIDES YAML with overrides for Salt deployment
Ales Komarek24097402017-05-22 16:28:10 +020064 *
65 */
Tomáš Kukrál3a17dd62017-07-27 18:24:16 +020066
Ales Komarek24097402017-05-22 16:28:10 +020067common = new com.mirantis.mk.Common()
68git = new com.mirantis.mk.Git()
69openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020070aws = new com.mirantis.mk.Aws()
Ales Komarek24097402017-05-22 16:28:10 +020071orchestrate = new com.mirantis.mk.Orchestrate()
Mykyta Karpine016d7e2017-10-09 13:35:20 +030072python = new com.mirantis.mk.Python()
Ales Komarek24097402017-05-22 16:28:10 +020073salt = new com.mirantis.mk.Salt()
74test = new com.mirantis.mk.Test()
75
76_MAX_PERMITTED_STACKS = 2
77overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
78
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020079// Define global variables
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020080def venv
chnyda597fb032017-10-06 13:42:48 +020081def venvPepper
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020082def outputs = [:]
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020083
chnydae14058a2017-08-29 15:07:48 +020084def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
85
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020086if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020087 def aws_env_vars
Tomáš Kukrál8427ff52017-08-30 15:46:52 +020088} else if (STACK_TYPE == 'heat') {
89 def envParams
90 def openstackCloud
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020091}
92
Oleh Hryhorov9630a762017-10-24 14:33:25 +030093def slave_node = 'python'
94
Oleh Hryhorov54460512017-10-26 18:45:36 +030095if (common.validInputParam('SLAVE_NODE')) {
Oleh Hryhorov9630a762017-10-24 14:33:25 +030096 slave_node = SLAVE_NODE
97}
Jakub Josefa63f9862018-01-11 17:58:38 +010098timeout(time: 12, unit: 'HOURS') {
99 node(slave_node) {
100 try {
101 // Set build-specific variables
Jakub Josef88aaf832018-01-18 16:18:28 +0100102 def workspace = common.getWorkspace()
103 venv = "${workspace}/venv"
104 venvPepper = "${workspace}/venvPepper"
Jakub Josef052e77a2018-03-05 15:19:03 +0100105 if(common.validInputParam("STACK_DELETE") && STACK_DELETE.toBoolean()){
106 common.warningMsg("You running stack with STACK_DELETE option enabled, deployed stack will be removed at the end!")
107 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100108 //
109 // Prepare machines
110 //
111 stage ('Create infrastructure') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200112
Jakub Josefa63f9862018-01-11 17:58:38 +0100113 outputs.put('stack_type', STACK_TYPE)
Ales Komarek24097402017-05-22 16:28:10 +0200114
Jakub Josefa63f9862018-01-11 17:58:38 +0100115 if (STACK_TYPE == 'heat') {
116 // value defaults
117 envParams = [
118 'cluster_zone': HEAT_STACK_ZONE,
119 'cluster_public_net': HEAT_STACK_PUBLIC_NET
120 ]
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200121
Jakub Josefa63f9862018-01-11 17:58:38 +0100122 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
123 error("If you want to reuse existing stack you need to provide it's name")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400124 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200125
Jakub Josefa63f9862018-01-11 17:58:38 +0100126 if (STACK_REUSE.toBoolean() == false) {
127 // Don't allow to set custom heat stack name
128 wrap([$class: 'BuildUser']) {
129 if (env.BUILD_USER_ID) {
130 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
131 } else {
132 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
133 }
134 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200135 }
136 }
137
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400138 // no underscore in STACK_NAME
139 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Jakub Josefa63f9862018-01-11 17:58:38 +0100140 outputs.put('stack_name', STACK_NAME)
Ales Komarek24097402017-05-22 16:28:10 +0200141
Jakub Josefa63f9862018-01-11 17:58:38 +0100142 // set description
143 currentBuild.description = "${STACK_NAME}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400144
Ales Komarek24097402017-05-22 16:28:10 +0200145 // get templates
146 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
147
Jakub Josefa63f9862018-01-11 17:58:38 +0100148 // create openstack env
149 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
Jakub Josef88aaf832018-01-18 16:18:28 +0100150 openstackCloud = openstack.createOpenstackEnv(venv,
Jakub Josefa63f9862018-01-11 17:58:38 +0100151 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
152 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
153 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
154 OPENSTACK_API_VERSION)
155 openstack.getKeystoneToken(openstackCloud, venv)
Ales Komarek24097402017-05-22 16:28:10 +0200156
Jakub Josefa63f9862018-01-11 17:58:38 +0100157 //
158 // Verify possibility of create stack for given user and stack type
159 //
160 wrap([$class: 'BuildUser']) {
161 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
162 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
163 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
164 STACK_DELETE = "false"
165 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
166 }
167 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200168 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100169 // launch stack
170 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400171
Jakub Josefa63f9862018-01-11 17:58:38 +0100172 // set reclass repo in heat env
173 try {
174 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
175 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
176 } catch (MissingPropertyException e) {
177 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 +0100178 }
179
Jakub Josefa63f9862018-01-11 17:58:38 +0100180 // put formulas revision - stable, testing or nightly
181 if (common.validInputParam('FORMULA_PKG_REVISION')) {
182 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
183 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
184 }
185
186 // put extra repo definitions
187 if (common.validInputParam('BOOTSTRAP_EXTRA_REPO_PARAMS')) {
188 common.infoMsg("Setting additional repo during bootstrap to ${BOOTSTRAP_EXTRA_REPO_PARAMS}")
189 envParams.put('cfg_bootstrap_extra_repo_params', BOOTSTRAP_EXTRA_REPO_PARAMS)
190 }
191
192 // put extra salt-formulas
193 if (common.validInputParam('EXTRA_FORMULAS')) {
194 common.infoMsg("Setting extra salt-formulas to ${EXTRA_FORMULAS}")
195 envParams.put('cfg_extra_formulas', EXTRA_FORMULAS)
196 }
197
Vasyl Saienkoa81e9312018-03-06 01:28:35 +0200198 // add cluster name if specified
199 if (common.validInputParam('STACK_CLUSTER_NAME')) {
200 common.infoMsg("Setting cluster_name to ${STACK_CLUSTER_NAME}")
201 envParams.put('cluster_name', STACK_CLUSTER_NAME)
202 }
203
Vasyl Saienko51139fd2018-04-20 12:01:50 +0300204 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
205 if (STACK_COMPUTE_COUNT.toInteger() > 0){
206 common.infoMsg("Setting cluster_node_count to ${STACK_COMPUTE_COUNT}")
207 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
208 }
209 }
210
Jakub Josefa63f9862018-01-11 17:58:38 +0100211 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
212 }
213
214 // get SALT_MASTER_URL
215 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
216 // check that saltMasterHost is valid
217 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
218 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
219 throw new Exception("saltMasterHost is not a valid ip")
220 }
221
222 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
223
224 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
225
226 } else if (STACK_TYPE == 'aws') {
227
228 // setup environment
229 aws.setupVirtualEnv(venv)
230
231 // set aws_env_vars
232 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
233
234 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
235 error("If you want to reuse existing stack you need to provide it's name")
236 }
237
238 if (STACK_REUSE.toBoolean() == false) {
239 // Don't allow to set custom stack name
240 wrap([$class: 'BuildUser']) {
241 if (env.BUILD_USER_ID) {
242 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
243 } else {
244 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
245 }
246 }
247
248 // no underscore in STACK_NAME
249 STACK_NAME = STACK_NAME.replaceAll('_', '-')
250 }
251
252 // set description
253 currentBuild.description = STACK_NAME
254 outputs.put('stack_name', STACK_NAME)
255
256 if (STACK_REUSE.toBoolean() == false) {
257 // get templates
258 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
259
260 // start stack
261 def stack_params = [
262 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
263 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
264 ]
265 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
266 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
267 }
268
269 // wait for stack to be ready
270 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
271
272 // get outputs
273 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
274
275 // check that saltMasterHost is valid
276 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
277 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
278 throw new Exception("saltMasterHost is not a valid ip")
279 }
280
281 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
282 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
283
284 } else if (STACK_TYPE != 'physical') {
285 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
286 }
287
288 outputs.put('salt_api', SALT_MASTER_URL)
289
290 // Setup virtualenv for pepper
291 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
292 }
293
294
295 // Set up override params
296 if (common.validInputParam('SALT_OVERRIDES')) {
297 stage('Set Salt overrides') {
298 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES)
299 }
300 }
301
302 //
303 // Install
304 //
305
306 if (common.checkContains('STACK_INSTALL', 'core')) {
307 stage('Install core infrastructure') {
308 def staticMgmtNetwork = false
309 if (common.validInputParam('STATIC_MGMT_NETWORK')) {
310 staticMgmtNetwork = STATIC_MGMT_NETWORK.toBoolean()
311 }
312 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
313
314 if (common.checkContains('STACK_INSTALL', 'kvm')) {
315 orchestrate.installInfraKvm(venvPepper)
316 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
317 }
318
319 orchestrate.validateFoundationInfra(venvPepper)
320 }
321 }
322
323 // install k8s
324 if (common.checkContains('STACK_INSTALL', 'k8s')) {
325
326 stage('Install Kubernetes infra') {
327 if (STACK_TYPE == 'aws') {
328 // configure kubernetes_control_address - save loadbalancer
329 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
330 common.prettyPrint(awsOutputs)
331 if (awsOutputs.containsKey('ControlLoadBalancer')) {
332 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
333 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
334 }
335 }
336
337 // ensure certificates are generated properly
338 salt.runSaltProcessStep(venvPepper, '*', 'saltutil.refresh_pillar', [], null, true)
339 salt.enforceState(venvPepper, '*', ['salt.minion.cert'], true)
340
341 orchestrate.installKubernetesInfra(venvPepper)
342 }
343
344 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Svimbaa554ea02018-06-06 18:45:23 +0200345 stage('Install Contrail control') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100346 orchestrate.installContrailNetwork(venvPepper)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200347 }
Ales Komarek24097402017-05-22 16:28:10 +0200348 }
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100349
Jakub Josefa63f9862018-01-11 17:58:38 +0100350 stage('Install Kubernetes control') {
351 orchestrate.installKubernetesControl(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400352
Jakub Josefa63f9862018-01-11 17:58:38 +0100353 // collect artifacts (kubeconfig)
354 writeFile(file: 'kubeconfig', text: salt.getFileContent(venvPepper, 'I@kubernetes:master and *01*', '/etc/kubernetes/admin-kube-config'))
355 archiveArtifacts(artifacts: 'kubeconfig')
vrovachev7be1e962017-07-05 13:28:26 +0400356 }
357
Svimbaa554ea02018-06-06 18:45:23 +0200358 if (common.checkContains('STACK_INSTALL', 'contrail')) {
359 stage('Install Contrail compute') {
360 orchestrate.installContrailCompute(venvPepper)
361 }
362 }
363
Jakub Josefa63f9862018-01-11 17:58:38 +0100364 stage('Install Kubernetes computes') {
365 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
366 if (STACK_COMPUTE_COUNT > 0) {
367 if (STACK_TYPE == 'aws') {
368 // get stack info
369 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
370
371 //update autoscaling group
372 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
373
374 // wait for computes to boot up
375 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
376 sleep(60)
377
378 } else if (STACK_TYPE == 'heat') {
379 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
380
381 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
382 sleep(60)
383 }
384
385 }
386 }
387
388 orchestrate.installKubernetesCompute(venvPepper)
389 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400390 }
Ales Komarek24097402017-05-22 16:28:10 +0200391
Jakub Josefa63f9862018-01-11 17:58:38 +0100392 // install openstack
393 if (common.checkContains('STACK_INSTALL', 'openstack')) {
394 // install Infra and control, tests, ...
395
396 stage('Install OpenStack infra') {
397 orchestrate.installOpenstackInfra(venvPepper)
398 }
399
400 stage('Install OpenStack control') {
401 orchestrate.installOpenstackControl(venvPepper)
402 }
403
Oleg Iurchenko86f1a842018-02-13 22:18:28 +0200404 // Workaround for PROD-17765 issue to prevent crashes of keystone.role_present state.
405 // More details: https://mirantis.jira.com/browse/PROD-17765
406 salt.runSaltProcessStep(venvPepper, 'I@keystone:client', 'service.restart', ['salt-minion'])
407 salt.minionsReachable(venvPepper, 'I@salt:master and *01*', 'I@keystone:client', null, 10, 6)
408
Jakub Josefa63f9862018-01-11 17:58:38 +0100409 stage('Install OpenStack network') {
410
411 if (common.checkContains('STACK_INSTALL', 'contrail')) {
412 orchestrate.installContrailNetwork(venvPepper)
413 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
414 orchestrate.installOpenstackNetwork(venvPepper)
415 }
416
Petr Jedinýefd668f2018-05-24 14:44:08 +0200417 // Wait for network to come up, 150s should be enough
418 common.retry(10, 15) {
419 salt.cmdRun(venvPepper, 'I@keystone:server', '. /root/keystonercv3; openstack network list')
420 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100421 }
422
423 if (salt.testTarget(venvPepper, 'I@ironic:conductor')){
424 stage('Install OpenStack Ironic conductor') {
425 orchestrate.installIronicConductor(venvPepper)
426 }
427 }
428
Vasyl Saienkob800a0f2018-02-21 18:38:53 +0200429 if (salt.testTarget(venvPepper, 'I@manila:share')){
430 stage('Install OpenStack Manila data and share') {
431 orchestrate.installManilaShare(venvPepper)
432 }
433 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100434
435 stage('Install OpenStack compute') {
436 orchestrate.installOpenstackCompute(venvPepper)
437
438 if (common.checkContains('STACK_INSTALL', 'contrail')) {
439 orchestrate.installContrailCompute(venvPepper)
440 }
441 }
442
443 }
444
445 // install ceph
446 if (common.checkContains('STACK_INSTALL', 'ceph')) {
447 stage('Install Ceph MONs') {
448 orchestrate.installCephMon(venvPepper)
449 }
450
451 stage('Install Ceph OSDs') {
452 orchestrate.installCephOsd(venvPepper)
453 }
454
455
456 stage('Install Ceph clients') {
457 orchestrate.installCephClient(venvPepper)
458 }
459
460 stage('Connect Ceph') {
461 orchestrate.connectCeph(venvPepper)
462 }
463 }
464
465 if (common.checkContains('STACK_INSTALL', 'oss')) {
466 stage('Install Oss infra') {
467 orchestrate.installOssInfra(venvPepper)
468 }
469 }
470
471 if (common.checkContains('STACK_INSTALL', 'cicd')) {
472 stage('Install Cicd') {
473 orchestrate.installInfra(venvPepper)
474 orchestrate.installDockerSwarm(venvPepper)
475 orchestrate.installCicd(venvPepper)
476 }
477 }
478
479 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
480 stage('Install StackLight v1') {
481 orchestrate.installStacklightv1Control(venvPepper)
482 orchestrate.installStacklightv1Client(venvPepper)
483 }
484 }
485
486 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
487 stage('Install StackLight') {
488 orchestrate.installDockerSwarm(venvPepper)
489 orchestrate.installStacklight(venvPepper)
490 }
491 }
492
493 if (common.checkContains('STACK_INSTALL', 'oss')) {
494 stage('Install OSS') {
495 if (!common.checkContains('STACK_INSTALL', 'stacklight')) {
496 // In case if StackLightv2 enabled containers already started
497 orchestrate.installDockerSwarm(venvPepper)
498 salt.enforceState(venvPepper, 'I@docker:swarm:role:master and I@devops_portal:config', 'docker.client', true)
499 }
500 orchestrate.installOss(venvPepper)
501 }
502 }
503
504 //
505 // Test
506 //
507 def artifacts_dir = '_artifacts/'
508
509 if (common.checkContains('STACK_TEST', 'k8s')) {
510 stage('Run k8s conformance e2e tests') {
511 def image = TEST_K8S_CONFORMANCE_IMAGE
512 def output_file = image.replaceAll('/', '-') + '.output'
vrovachevff3e72d2018-01-25 16:14:43 +0400513 def target = 'ctl01*'
514 def conformance_output_file = 'conformance_test.tar'
Jakub Josefa63f9862018-01-11 17:58:38 +0100515
516 // run image
vrovachevff3e72d2018-01-25 16:14:43 +0400517 test.runConformanceTests(venvPepper, target, TEST_K8S_API_SERVER, image)
Jakub Josefa63f9862018-01-11 17:58:38 +0100518
519 // collect output
520 sh "mkdir -p ${artifacts_dir}"
vrovachevff3e72d2018-01-25 16:14:43 +0400521 file_content = salt.getFileContent(venvPepper, target, '/tmp/' + output_file)
Jakub Josefa63f9862018-01-11 17:58:38 +0100522 writeFile file: "${artifacts_dir}${output_file}", text: file_content
523 sh "cat ${artifacts_dir}${output_file}"
524
525 // collect artifacts
526 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
vrovachevff3e72d2018-01-25 16:14:43 +0400527
528 // Copy test results
529 test.CopyConformanceResults(venvPepper, target, artifacts_dir, conformance_output_file)
Jakub Josefa63f9862018-01-11 17:58:38 +0100530 }
531 }
532
533 if (common.checkContains('STACK_TEST', 'openstack')) {
534 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
535 test.install_docker(venvPepper, TEST_TEMPEST_TARGET)
536 }
537 stage('Run OpenStack tests') {
538 test.runTempestTests(venvPepper, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
539 }
540
541 stage('Copy Tempest results to config node') {
542 test.copyTempestResults(venvPepper, TEST_TEMPEST_TARGET)
543 }
544
545 stage('Archive rally artifacts') {
546 test.archiveRallyArtifacts(venvPepper, TEST_TEMPEST_TARGET)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200547 }
ibumarskov637a2152018-01-16 10:39:57 +0400548
549 if (common.validInputParam('TESTRAIL_REPORT') && TESTRAIL_REPORT.toBoolean()) {
550 stage('Upload test results to TestRail') {
551 def date = sh(script: 'date +%Y-%m-%d', returnStdout: true).trim()
552 def plan = TESTRAIL_PLAN ?: "[${TESTRAIL_MILESTONE}]System-Devcloud-${date}"
553 def group = TESTRAIL_GROUP ?: STACK_TEMPLATE
554
555 salt.cmdRun(venvPepper, TEST_TEMPEST_TARGET, "cd /root/rally_reports && cp \$(ls -t *xml | head -n1) report.xml")
556 test.uploadResultsTestrail("/root/rally_reports/report.xml",
557 TESTRAIL_REPORTER_IMAGE, group, TESTRAIL_QA_CREDENTIALS,
558 plan, TESTRAIL_MILESTONE, TESTRAIL_SUITE)
559 }
560 }
Ales Komarek24097402017-05-22 16:28:10 +0200561 }
562
Ales Komarek24097402017-05-22 16:28:10 +0200563
Jakub Josefa63f9862018-01-11 17:58:38 +0100564 if (common.checkContains('STACK_TEST', 'ceph')) {
565 stage('Run infra tests') {
566 sleep(120)
567 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/"
568 salt.cmdRun(venvPepper, 'I@salt:master', cmd, false)
569 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, 'I@salt:master', '/root/report.xml'))
570 junit(keepLongStdio: true, testResults: 'report.xml')
Martin Polreich46971102017-07-11 12:56:40 +0200571 }
572 }
573
Jakub Josefa63f9862018-01-11 17:58:38 +0100574 if (common.checkContains('STACK_TEST', 'opencontrail')) {
575 stage('Run opencontrail tests') {
576 def opencontrail_tests_dir = "/opt/opencontrail_test/fuel-plugin-contrail/plugin_test/vapor/"
577 def report_dir = "/opt/opencontrail-test-report/"
578 def cmd = ". ${opencontrail_tests_dir}exports.sh && " +
579 "cd ${opencontrail_tests_dir} && " +
580 "py.test --junit-xml=${report_dir}report.xml" +
581 " --html=${report_dir}report.html -v vapor/tests/ -k 'not destructive' "
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400582
Jakub Josefa63f9862018-01-11 17:58:38 +0100583 salt.runSaltProcessStep(venvPepper, 'cfg*', 'saltutil.refresh_pillar', [], null, true)
584 salt.enforceState(venvPepper, 'I@opencontrail:test' , 'opencontrail.test' , true)
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100585
Jakub Josefa63f9862018-01-11 17:58:38 +0100586 salt.cmdRun(venvPepper, 'I@opencontrail:test', cmd, false)
587
588 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper,
589 'I@opencontrail:test', "${report_dir}report.xml"))
590 junit(keepLongStdio: true, testResults: 'report.xml')
591 }
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100592 }
593
594
Jakub Josefa63f9862018-01-11 17:58:38 +0100595 stage('Finalize') {
596 if (common.checkContains('STACK_INSTALL', 'finalize')) {
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100597 def gluster_compound = 'I@glusterfs:server'
Dzmitry Stremkouski47a45122018-04-25 17:05:56 +0200598 def salt_ca_compound = 'I@salt:minion:ca:salt_master_ca'
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100599 // Enforce highstate asynchronous only on the nodes which are not glusterfs servers
Dzmitry Stremkouski47a45122018-04-25 17:05:56 +0200600 salt.enforceHighstate(venvPepper, '* and not ' + gluster_compound + ' and not ' + salt_ca_compound)
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100601 // Iterate over nonempty set of gluster servers and apply highstates one by one
602 // TODO: switch to batch once salt 2017.7+ would be used
Dzmitry Stremkouski47a45122018-04-25 17:05:56 +0200603 def saltcaMinions = salt.getMinionsSorted(venvPepper, salt_ca_compound)
604 if ( !saltcaMinions.isEmpty() ) {
605 for ( target in saltcaMinions ) {
606 salt.enforceHighstate(venvPepper, target)
607 }
608 }
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100609 def glusterMinions = salt.getMinionsSorted(venvPepper, gluster_compound)
610 if ( !glusterMinions.isEmpty() ) {
611 for ( target in glusterMinions ) {
612 salt.enforceHighstate(venvPepper, target)
613 }
614 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100615 }
616
617 outputsPretty = common.prettify(outputs)
618 print(outputsPretty)
619 writeFile(file: 'outputs.json', text: outputsPretty)
620 archiveArtifacts(artifacts: 'outputs.json')
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100621 }
622
Jakub Josefa63f9862018-01-11 17:58:38 +0100623 } catch (Throwable e) {
624 currentBuild.result = 'FAILURE'
625 throw e
626 } finally {
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100627
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400628
Jakub Josefa63f9862018-01-11 17:58:38 +0100629 //
630 // Clean
631 //
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400632
Jakub Josefa63f9862018-01-11 17:58:38 +0100633 if (common.validInputParam('STACK_NAME')) {
634 // send notification
635 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
Ales Komarek24097402017-05-22 16:28:10 +0200636 }
637
Jakub Josefa63f9862018-01-11 17:58:38 +0100638 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
639 stage('Trigger cleanup job') {
640 common.errorMsg('Stack cleanup job triggered')
641 build(job: STACK_CLEANUP_JOB, parameters: [
642 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
643 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
644 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
645 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
646 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
647 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
648 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
649 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
650 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
651 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
652 ])
653 }
654 } else {
655 if (currentBuild.result == 'FAILURE') {
656 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 +0300657
Jakub Josefa63f9862018-01-11 17:58:38 +0100658 if (common.validInputParam('SALT_MASTER_URL')) {
659 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
660 }
Ales Komarek24097402017-05-22 16:28:10 +0200661 }
662 }
663 }
664 }
665}