blob: 2a63e2e05958c40d3cf46f2bdb56726e136a55d9 [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
Tomáš Kukrál86b9ab22017-09-05 16:55:58 +0200113 // no underscore in STACK_NAME
114 STACK_NAME = STACK_NAME.replaceAll('_', '-')
115
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400116 // set description
117 currentBuild.description = "${STACK_NAME}"
118
119 // get templates
120 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
121
122 // create openstack env
123 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
124 openstackCloud = openstack.createOpenstackEnv(
125 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
126 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
127 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
128 OPENSTACK_API_VERSION)
129 openstack.getKeystoneToken(openstackCloud, venv)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200130
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400131 //
132 // Verify possibility of create stack for given user and stack type
133 //
134 wrap([$class: 'BuildUser']) {
135 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
136 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}", venv)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200137 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400138 STACK_DELETE = "false"
139 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
140 }
141 }
142 }
143 // launch stack
144 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400145
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200146 // set reclass repo in heat env
147 try {
148 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
149 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
150 } catch (MissingPropertyException e) {
151 common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400152 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200153
Mykyta Karpin0aa35d52017-08-28 11:44:42 +0300154 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400155 }
156
157 // get SALT_MASTER_URL
158 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
chnydae14058a2017-08-29 15:07:48 +0200159 // check that saltMasterHost is valid
160 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
161 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
162 throw new Exception("saltMasterHost is not a valid ip")
163 }
164
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400165 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
166
167 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
168
169 } else if (STACK_TYPE == 'aws') {
170
171 // setup environment
172 aws.setupVirtualEnv(venv)
173
174 // set aws_env_vars
175 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
176
177 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
178 error("If you want to reuse existing stack you need to provide it's name")
179 }
180
181 if (STACK_REUSE.toBoolean() == false) {
182 // Don't allow to set custom stack name
183 wrap([$class: 'BuildUser']) {
184 if (env.BUILD_USER_ID) {
185 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
186 } else {
187 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
Ales Komarek24097402017-05-22 16:28:10 +0200188 }
189 }
190
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400191 // no underscore in STACK_NAME
192 STACK_NAME = STACK_NAME.replaceAll('_', '-')
193 }
Ales Komarek24097402017-05-22 16:28:10 +0200194
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400195 // set description
196 currentBuild.description = STACK_NAME
197
198 if (STACK_REUSE.toBoolean() == false) {
Ales Komarek24097402017-05-22 16:28:10 +0200199 // get templates
200 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
201
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400202 // start stack
203 def stack_params = [
204 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
205 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
206 ]
207 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
208 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200209 }
Ales Komarek24097402017-05-22 16:28:10 +0200210
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400211 // wait for stack to be ready
212 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
213
214 // get outputs
215 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200216
chnydae14058a2017-08-29 15:07:48 +0200217 // check that saltMasterHost is valid
218 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
219 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
220 throw new Exception("saltMasterHost is not a valid ip")
221 }
222
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200223 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400224 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
225
226 } else if (STACK_TYPE != 'physical') {
227 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
Ales Komarek24097402017-05-22 16:28:10 +0200228 }
229
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200230 outputs.put('salt_api', SALT_MASTER_URL)
231
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400232 // Connect to Salt master
233 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
234 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200235
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400236
237 // Set up override params
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200238 if (common.validInputParam('SALT_OVERRIDES')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400239 stage('Set Salt overrides') {
240 salt.setSaltOverrides(saltMaster, SALT_OVERRIDES)
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200241 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400242 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200243
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400244 //
245 // Install
246 //
Ales Komarek24097402017-05-22 16:28:10 +0200247
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400248 if (common.checkContains('STACK_INSTALL', 'core')) {
249 stage('Install core infrastructure') {
250 orchestrate.installFoundationInfra(saltMaster)
251
252 if (common.checkContains('STACK_INSTALL', 'kvm')) {
253 orchestrate.installInfraKvm(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200254 orchestrate.installFoundationInfra(saltMaster)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400255 }
Ales Komarek24097402017-05-22 16:28:10 +0200256
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400257 orchestrate.validateFoundationInfra(saltMaster)
258 }
259 }
Ales Komarek24097402017-05-22 16:28:10 +0200260
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200261 // install ceph
262 if (common.checkContains('STACK_INSTALL', 'ceph')) {
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200263 stage('Install Ceph MONs') {
264 orchestrate.installCephMon(saltMaster)
265 }
266
267 stage('Install Ceph OSDs') {
268 orchestrate.installCephOsd(saltMaster)
269 }
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200270
Tomáš Kukrál0cc01092017-08-28 18:25:00 +0200271
272 stage('Install Ceph clients') {
273 orchestrate.installCephClient(saltMaster)
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200274 }
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200275 }
276
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400277 // install k8s
278 if (common.checkContains('STACK_INSTALL', 'k8s')) {
279
280 stage('Install Kubernetes infra') {
281 if (STACK_TYPE == 'aws') {
282 // configure kubernetes_control_address - save loadbalancer
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200283 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
Tomáš Kukrál685f3b82017-09-03 10:14:40 +0200284 common.prettyPrint(awsOutputs)
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200285 if (awsOutputs.containsKey('ControlLoadBalancer')) {
286 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
287 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
288 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400289 }
290
291 // ensure certificates are generated properly
292 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true)
293 salt.enforceState(saltMaster, '*', ['salt.minion.cert'], true)
294
295 orchestrate.installKubernetesInfra(saltMaster)
296 }
297
298 if (common.checkContains('STACK_INSTALL', 'contrail')) {
299 stage('Install Contrail for Kubernetes') {
300 orchestrate.installContrailNetwork(saltMaster)
301 orchestrate.installContrailCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200302 }
303 }
304
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400305 stage('Install Kubernetes control') {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400306 orchestrate.installKubernetesControl(saltMaster)
Tomáš Kukrál7e487062017-08-31 11:20:08 +0200307
308 // collect artifacts (kubeconfig)
Tomáš Kukrál897b7a72017-08-31 11:54:33 +0200309 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 +0200310 archiveArtifacts(artifacts: 'kubeconfig')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400311 }
312
313 stage('Scale Kubernetes computes') {
314 if (STACK_COMPUTE_COUNT > 0) {
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200315 if (STACK_TYPE == 'aws') {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400316 // get stack info
317 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
318
319 //update autoscaling group
320 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
321
322 // wait for computes to boot up
323 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
324 sleep(60)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200325
326 } else if (STACK_TYPE == 'heat') {
327 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
328
329 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
330 sleep(60)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200331 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200332
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400333 orchestrate.installKubernetesCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200334 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400335 }
336 }
337
338 // install openstack
339 if (common.checkContains('STACK_INSTALL', 'openstack')) {
340 // install Infra and control, tests, ...
341
342 stage('Install OpenStack infra') {
343 orchestrate.installOpenstackInfra(saltMaster)
344 }
345
346 stage('Install OpenStack control') {
347 orchestrate.installOpenstackControl(saltMaster)
348 }
349
350 stage('Install OpenStack network') {
Ales Komarek24097402017-05-22 16:28:10 +0200351
vrovachev7be1e962017-07-05 13:28:26 +0400352 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400353 orchestrate.installContrailNetwork(saltMaster)
354 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
355 orchestrate.installOpenstackNetwork(saltMaster)
vrovachev7be1e962017-07-05 13:28:26 +0400356 }
357
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400358 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
359 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
360 }
Ales Komarek24097402017-05-22 16:28:10 +0200361
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400362 if (salt.testTarget(saltMaster, 'I@ironic:conductor')){
363 stage('Install OpenStack Ironic conductor') {
364 orchestrate.installIronicConductor(saltMaster)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200365 }
Ales Komarek24097402017-05-22 16:28:10 +0200366 }
367
Ales Komarek24097402017-05-22 16:28:10 +0200368
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400369 stage('Install OpenStack compute') {
370 orchestrate.installOpenstackCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200371
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400372 if (common.checkContains('STACK_INSTALL', 'contrail')) {
373 orchestrate.installContrailCompute(saltMaster)
Martin Polreich46971102017-07-11 12:56:40 +0200374 }
375 }
376
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400377 }
378
379
380 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
381 stage('Install StackLight v1') {
382 orchestrate.installStacklightv1Control(saltMaster)
383 orchestrate.installStacklightv1Client(saltMaster)
384 }
385 }
386
387 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
388 stage('Install StackLight') {
389 orchestrate.installDockerSwarm(saltMaster)
390 orchestrate.installStacklight(saltMaster)
391 }
392 }
393
394 //
395 // Test
396 //
397 def artifacts_dir = '_artifacts/'
398
399 if (common.checkContains('STACK_TEST', 'k8s')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400400 stage('Run k8s conformance e2e tests') {
Anna Babich12dd5b12017-08-21 18:01:35 +0300401 def image = TEST_K8S_CONFORMANCE_IMAGE
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400402 def output_file = image.replaceAll('/', '-') + '.output'
Ales Komarek24097402017-05-22 16:28:10 +0200403
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400404 // run image
405 test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image)
Ales Komarek24097402017-05-22 16:28:10 +0200406
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400407 // collect output
408 sh "mkdir -p ${artifacts_dir}"
409 file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
410 writeFile file: "${artifacts_dir}${output_file}", text: file_content
411 sh "cat ${artifacts_dir}${output_file}"
Ales Komarek24097402017-05-22 16:28:10 +0200412
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400413 // collect artifacts
414 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
415 }
416 }
Ales Komarek24097402017-05-22 16:28:10 +0200417
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400418 if (common.checkContains('STACK_TEST', 'openstack')) {
419 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
420 test.install_docker(saltMaster, TEST_TEMPEST_TARGET)
421 }
422 stage('Run OpenStack tests') {
423 test.runTempestTests(saltMaster, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
Ales Komarek24097402017-05-22 16:28:10 +0200424 }
425
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400426 stage('Copy Tempest results to config node') {
427 test.copyTempestResults(saltMaster, TEST_TEMPEST_TARGET)
Ales Komarek24097402017-05-22 16:28:10 +0200428 }
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300429
430 stage('Archive rally artifacts') {
431 test.archiveRallyArtifacts(saltMaster, TEST_TEMPEST_TARGET)
432 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400433 }
Ales Komarek24097402017-05-22 16:28:10 +0200434
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200435
436 if (common.checkContains('STACK_TEST', 'ceph')) {
Tomáš Kukrálf5798082017-08-21 22:37:41 +0200437 stage('Run infra tests') {
Tomáš Kukrál36d43972017-08-30 12:43:17 +0200438 sleep(120)
Tomáš Kukrál07ad0c92017-08-21 23:19:40 +0200439 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 +0200440 salt.cmdRun(saltMaster, 'I@salt:master', cmd, false)
Tomáš Kukrál09d67cd2017-08-21 23:22:21 +0200441 writeFile(file: 'report.xml', text: salt.getFileContent(saltMaster, 'I@salt:master', '/root/report.xml'))
Tomáš Kukrálc48456a2017-08-21 23:03:37 +0200442 junit(keepLongStdio: true, testResults: 'report.xml')
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200443 }
444 }
445
446
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200447 stage('Finalize') {
448 if (common.checkContains('STACK_INSTALL', 'finalize')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400449 salt.runSaltProcessStep(saltMaster, '*', 'state.apply', [], null, true)
Ales Komarek24097402017-05-22 16:28:10 +0200450 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200451
452 outputsPretty = common.prettify(outputs)
453 print(outputsPretty)
454 writeFile(file: 'outputs.json', text: outputsPretty)
455 archiveArtifacts(artifacts: 'outputs.json')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400456 }
Tomáš Kukrál53224c22017-07-26 10:53:20 +0200457
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400458 } catch (Throwable e) {
459 currentBuild.result = 'FAILURE'
460 throw e
461 } finally {
Ales Komarek24097402017-05-22 16:28:10 +0200462
463
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400464 //
465 // Clean
466 //
Ales Komarek24097402017-05-22 16:28:10 +0200467
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200468 if (common.validInputParam('STACK_NAME')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400469 // send notification
470 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
471 }
472
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200473 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400474 stage('Trigger cleanup job') {
475 common.errorMsg('Stack cleanup job triggered')
476 build(job: STACK_CLEANUP_JOB, parameters: [
477 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
478 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
479 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
480 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
481 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
482 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
483 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
484 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
485 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
486 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
487 ])
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200488 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400489 } else {
490 if (currentBuild.result == 'FAILURE') {
491 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 +0200492
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200493 if (common.validInputParam('SALT_MASTER_URL')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400494 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
Ales Komarek24097402017-05-22 16:28:10 +0200495 }
496 }
497 }
498 }
499}