blob: bb0890fa625ad8d310dd945758c1096fae4559fb [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ál8427ff52017-08-30 15:46:52 +020073} else if (STACK_TYPE == 'heat') {
74 def envParams
75 def openstackCloud
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020076}
77
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040078node("python") {
79 try {
80 // Set build-specific variables
81 venv = "${env.WORKSPACE}/venv"
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020082
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040083 //
84 // Prepare machines
85 //
86 stage ('Create infrastructure') {
Ales Komarek24097402017-05-22 16:28:10 +020087
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020088 outputs.put('stack_type', STACK_TYPE)
89
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040090 if (STACK_TYPE == 'heat') {
91 // value defaults
Tomáš Kukrál8427ff52017-08-30 15:46:52 +020092 envParams = [
93 'cluster_zone': HEAT_STACK_ZONE,
94 'cluster_public_net': HEAT_STACK_PUBLIC_NET
95 ]
Ales Komarek24097402017-05-22 16:28:10 +020096
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040097 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
98 error("If you want to reuse existing stack you need to provide it's name")
99 }
100
101 if (STACK_REUSE.toBoolean() == false) {
102 // Don't allow to set custom heat stack name
103 wrap([$class: 'BuildUser']) {
104 if (env.BUILD_USER_ID) {
105 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
106 } else {
107 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
108 }
109 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200110 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400111 }
Ales Komarek24097402017-05-22 16:28:10 +0200112
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400113 // set description
114 currentBuild.description = "${STACK_NAME}"
115
116 // get templates
117 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
118
119 // create openstack env
120 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
121 openstackCloud = openstack.createOpenstackEnv(
122 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
123 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
124 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
125 OPENSTACK_API_VERSION)
126 openstack.getKeystoneToken(openstackCloud, venv)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200127
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400128 //
129 // Verify possibility of create stack for given user and stack type
130 //
131 wrap([$class: 'BuildUser']) {
132 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
133 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}", venv)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200134 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400135 STACK_DELETE = "false"
136 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
137 }
138 }
139 }
140 // launch stack
141 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400142
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200143 // set reclass repo in heat env
144 try {
145 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
146 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
147 } catch (MissingPropertyException e) {
148 common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400149 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200150
Mykyta Karpin0aa35d52017-08-28 11:44:42 +0300151 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400152 }
153
154 // get SALT_MASTER_URL
155 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
chnydae14058a2017-08-29 15:07:48 +0200156 // check that saltMasterHost is valid
157 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
158 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
159 throw new Exception("saltMasterHost is not a valid ip")
160 }
161
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400162 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
163
164 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
165
166 } else if (STACK_TYPE == 'aws') {
167
168 // setup environment
169 aws.setupVirtualEnv(venv)
170
171 // set aws_env_vars
172 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
173
174 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
175 error("If you want to reuse existing stack you need to provide it's name")
176 }
177
178 if (STACK_REUSE.toBoolean() == false) {
179 // Don't allow to set custom stack name
180 wrap([$class: 'BuildUser']) {
181 if (env.BUILD_USER_ID) {
182 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
183 } else {
184 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
Ales Komarek24097402017-05-22 16:28:10 +0200185 }
186 }
187
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400188 // no underscore in STACK_NAME
189 STACK_NAME = STACK_NAME.replaceAll('_', '-')
190 }
Ales Komarek24097402017-05-22 16:28:10 +0200191
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400192 // set description
193 currentBuild.description = STACK_NAME
194
195 if (STACK_REUSE.toBoolean() == false) {
Ales Komarek24097402017-05-22 16:28:10 +0200196 // get templates
197 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
198
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400199 // start stack
200 def stack_params = [
201 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
202 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
203 ]
204 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
205 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200206 }
Ales Komarek24097402017-05-22 16:28:10 +0200207
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400208 // wait for stack to be ready
209 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
210
211 // get outputs
212 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200213
chnydae14058a2017-08-29 15:07:48 +0200214 // check that saltMasterHost is valid
215 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
216 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
217 throw new Exception("saltMasterHost is not a valid ip")
218 }
219
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200220 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400221 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
222
223 } else if (STACK_TYPE != 'physical') {
224 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
Ales Komarek24097402017-05-22 16:28:10 +0200225 }
226
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200227 outputs.put('salt_api', SALT_MASTER_URL)
228
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400229 // Connect to Salt master
230 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
231 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200232
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400233
234 // Set up override params
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200235 if (common.validInputParam('SALT_OVERRIDES')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400236 stage('Set Salt overrides') {
237 salt.setSaltOverrides(saltMaster, SALT_OVERRIDES)
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200238 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400239 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200240
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400241 //
242 // Install
243 //
Ales Komarek24097402017-05-22 16:28:10 +0200244
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400245 if (common.checkContains('STACK_INSTALL', 'core')) {
246 stage('Install core infrastructure') {
247 orchestrate.installFoundationInfra(saltMaster)
248
249 if (common.checkContains('STACK_INSTALL', 'kvm')) {
250 orchestrate.installInfraKvm(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200251 orchestrate.installFoundationInfra(saltMaster)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400252 }
Ales Komarek24097402017-05-22 16:28:10 +0200253
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400254 orchestrate.validateFoundationInfra(saltMaster)
255 }
256 }
Ales Komarek24097402017-05-22 16:28:10 +0200257
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200258 // install ceph
259 if (common.checkContains('STACK_INSTALL', 'ceph')) {
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200260 stage('Install Ceph MONs') {
261 orchestrate.installCephMon(saltMaster)
262 }
263
264 stage('Install Ceph OSDs') {
265 orchestrate.installCephOsd(saltMaster)
266 }
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200267
Tomáš Kukrál0cc01092017-08-28 18:25:00 +0200268
269 stage('Install Ceph clients') {
270 orchestrate.installCephClient(saltMaster)
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200271 }
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200272 }
273
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400274 // install k8s
275 if (common.checkContains('STACK_INSTALL', 'k8s')) {
276
277 stage('Install Kubernetes infra') {
278 if (STACK_TYPE == 'aws') {
279 // configure kubernetes_control_address - save loadbalancer
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200280 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
Tomáš Kukrál685f3b82017-09-03 10:14:40 +0200281 common.prettyPrint(awsOutputs)
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200282 if (awsOutputs.containsKey('ControlLoadBalancer')) {
283 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
284 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
285 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400286 }
287
288 // ensure certificates are generated properly
289 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true)
290 salt.enforceState(saltMaster, '*', ['salt.minion.cert'], true)
291
292 orchestrate.installKubernetesInfra(saltMaster)
293 }
294
295 if (common.checkContains('STACK_INSTALL', 'contrail')) {
296 stage('Install Contrail for Kubernetes') {
297 orchestrate.installContrailNetwork(saltMaster)
298 orchestrate.installContrailCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200299 }
300 }
301
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400302 stage('Install Kubernetes control') {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400303 orchestrate.installKubernetesControl(saltMaster)
Tomáš Kukrál7e487062017-08-31 11:20:08 +0200304
305 // collect artifacts (kubeconfig)
Tomáš Kukrál897b7a72017-08-31 11:54:33 +0200306 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 +0200307 archiveArtifacts(artifacts: 'kubeconfig')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400308 }
309
310 stage('Scale Kubernetes computes') {
311 if (STACK_COMPUTE_COUNT > 0) {
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200312 if (STACK_TYPE == 'aws') {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400313 // get stack info
314 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
315
316 //update autoscaling group
317 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
318
319 // wait for computes to boot up
320 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
321 sleep(60)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200322
323 } else if (STACK_TYPE == 'heat') {
324 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
325
326 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
327 sleep(60)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200328 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200329
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400330 orchestrate.installKubernetesCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200331 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400332 }
333 }
334
335 // install openstack
336 if (common.checkContains('STACK_INSTALL', 'openstack')) {
337 // install Infra and control, tests, ...
338
339 stage('Install OpenStack infra') {
340 orchestrate.installOpenstackInfra(saltMaster)
341 }
342
343 stage('Install OpenStack control') {
344 orchestrate.installOpenstackControl(saltMaster)
345 }
346
347 stage('Install OpenStack network') {
Ales Komarek24097402017-05-22 16:28:10 +0200348
vrovachev7be1e962017-07-05 13:28:26 +0400349 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400350 orchestrate.installContrailNetwork(saltMaster)
351 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
352 orchestrate.installOpenstackNetwork(saltMaster)
vrovachev7be1e962017-07-05 13:28:26 +0400353 }
354
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400355 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
356 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
357 }
Ales Komarek24097402017-05-22 16:28:10 +0200358
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400359 if (salt.testTarget(saltMaster, 'I@ironic:conductor')){
360 stage('Install OpenStack Ironic conductor') {
361 orchestrate.installIronicConductor(saltMaster)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200362 }
Ales Komarek24097402017-05-22 16:28:10 +0200363 }
364
Ales Komarek24097402017-05-22 16:28:10 +0200365
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400366 stage('Install OpenStack compute') {
367 orchestrate.installOpenstackCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200368
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400369 if (common.checkContains('STACK_INSTALL', 'contrail')) {
370 orchestrate.installContrailCompute(saltMaster)
Martin Polreich46971102017-07-11 12:56:40 +0200371 }
372 }
373
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400374 }
375
376
377 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
378 stage('Install StackLight v1') {
379 orchestrate.installStacklightv1Control(saltMaster)
380 orchestrate.installStacklightv1Client(saltMaster)
381 }
382 }
383
384 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
385 stage('Install StackLight') {
386 orchestrate.installDockerSwarm(saltMaster)
387 orchestrate.installStacklight(saltMaster)
388 }
389 }
390
391 //
392 // Test
393 //
394 def artifacts_dir = '_artifacts/'
395
396 if (common.checkContains('STACK_TEST', 'k8s')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400397 stage('Run k8s conformance e2e tests') {
Anna Babich12dd5b12017-08-21 18:01:35 +0300398 def image = TEST_K8S_CONFORMANCE_IMAGE
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400399 def output_file = image.replaceAll('/', '-') + '.output'
Ales Komarek24097402017-05-22 16:28:10 +0200400
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400401 // run image
402 test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image)
Ales Komarek24097402017-05-22 16:28:10 +0200403
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400404 // collect output
405 sh "mkdir -p ${artifacts_dir}"
406 file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
407 writeFile file: "${artifacts_dir}${output_file}", text: file_content
408 sh "cat ${artifacts_dir}${output_file}"
Ales Komarek24097402017-05-22 16:28:10 +0200409
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400410 // collect artifacts
411 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
412 }
413 }
Ales Komarek24097402017-05-22 16:28:10 +0200414
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400415 if (common.checkContains('STACK_TEST', 'openstack')) {
416 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
417 test.install_docker(saltMaster, TEST_TEMPEST_TARGET)
418 }
419 stage('Run OpenStack tests') {
420 test.runTempestTests(saltMaster, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
Ales Komarek24097402017-05-22 16:28:10 +0200421 }
422
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400423 stage('Copy Tempest results to config node') {
424 test.copyTempestResults(saltMaster, TEST_TEMPEST_TARGET)
Ales Komarek24097402017-05-22 16:28:10 +0200425 }
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300426
427 stage('Archive rally artifacts') {
428 test.archiveRallyArtifacts(saltMaster, TEST_TEMPEST_TARGET)
429 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400430 }
Ales Komarek24097402017-05-22 16:28:10 +0200431
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200432
433 if (common.checkContains('STACK_TEST', 'ceph')) {
Tomáš Kukrálf5798082017-08-21 22:37:41 +0200434 stage('Run infra tests') {
Tomáš Kukrál36d43972017-08-30 12:43:17 +0200435 sleep(120)
Tomáš Kukrál07ad0c92017-08-21 23:19:40 +0200436 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 +0200437 salt.cmdRun(saltMaster, 'I@salt:master', cmd, false)
Tomáš Kukrál09d67cd2017-08-21 23:22:21 +0200438 writeFile(file: 'report.xml', text: salt.getFileContent(saltMaster, 'I@salt:master', '/root/report.xml'))
Tomáš Kukrálc48456a2017-08-21 23:03:37 +0200439 junit(keepLongStdio: true, testResults: 'report.xml')
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200440 }
441 }
442
443
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200444 stage('Finalize') {
445 if (common.checkContains('STACK_INSTALL', 'finalize')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400446 salt.runSaltProcessStep(saltMaster, '*', 'state.apply', [], null, true)
Ales Komarek24097402017-05-22 16:28:10 +0200447 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200448
449 outputsPretty = common.prettify(outputs)
450 print(outputsPretty)
451 writeFile(file: 'outputs.json', text: outputsPretty)
452 archiveArtifacts(artifacts: 'outputs.json')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400453 }
Tomáš Kukrál53224c22017-07-26 10:53:20 +0200454
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400455 } catch (Throwable e) {
456 currentBuild.result = 'FAILURE'
457 throw e
458 } finally {
Ales Komarek24097402017-05-22 16:28:10 +0200459
460
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400461 //
462 // Clean
463 //
Ales Komarek24097402017-05-22 16:28:10 +0200464
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200465 if (common.validInputParam('STACK_NAME')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400466 // send notification
467 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
468 }
469
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200470 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400471 stage('Trigger cleanup job') {
472 common.errorMsg('Stack cleanup job triggered')
473 build(job: STACK_CLEANUP_JOB, parameters: [
474 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
475 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
476 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
477 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
478 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
479 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
480 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
481 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
482 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
483 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
484 ])
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200485 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400486 } else {
487 if (currentBuild.result == 'FAILURE') {
488 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 +0200489
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200490 if (common.validInputParam('SALT_MASTER_URL')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400491 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
Ales Komarek24097402017-05-22 16:28:10 +0200492 }
493 }
494 }
495 }
496}