blob: c408dd857aaaf51812203c204db3efb602e248fc [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ála1d86b82017-07-10 17:24:01 +020065def venv
chnyda597fb032017-10-06 13:42:48 +020066def venvPepper
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"
chnyda597fb032017-10-06 13:42:48 +020082 venvPepper = "${env.WORKSPACE}/venvPepper"
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020083
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040084 //
85 // Prepare machines
86 //
87 stage ('Create infrastructure') {
Ales Komarek24097402017-05-22 16:28:10 +020088
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020089 outputs.put('stack_type', STACK_TYPE)
90
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040091 if (STACK_TYPE == 'heat') {
92 // value defaults
Tomáš Kukrál8427ff52017-08-30 15:46:52 +020093 envParams = [
94 'cluster_zone': HEAT_STACK_ZONE,
95 'cluster_public_net': HEAT_STACK_PUBLIC_NET
96 ]
Ales Komarek24097402017-05-22 16:28:10 +020097
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040098 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
99 error("If you want to reuse existing stack you need to provide it's name")
100 }
101
102 if (STACK_REUSE.toBoolean() == false) {
103 // Don't allow to set custom heat stack name
104 wrap([$class: 'BuildUser']) {
105 if (env.BUILD_USER_ID) {
106 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
107 } else {
108 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
109 }
110 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200111 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400112 }
Ales Komarek24097402017-05-22 16:28:10 +0200113
Tomáš Kukrál86b9ab22017-09-05 16:55:58 +0200114 // no underscore in STACK_NAME
115 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Tomáš Kukrál77b1b5a2017-09-24 18:56:49 +0200116 outputs.put('stack_name', STACK_NAME)
Tomáš Kukrál86b9ab22017-09-05 16:55:58 +0200117
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400118 // set description
119 currentBuild.description = "${STACK_NAME}"
120
121 // get templates
122 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
123
124 // create openstack env
125 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
126 openstackCloud = openstack.createOpenstackEnv(
127 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
128 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
129 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
130 OPENSTACK_API_VERSION)
131 openstack.getKeystoneToken(openstackCloud, venv)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200132
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400133 //
134 // Verify possibility of create stack for given user and stack type
135 //
136 wrap([$class: 'BuildUser']) {
137 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
Oleh Hryhorov8e320ca2017-09-22 13:23:44 +0300138 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200139 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400140 STACK_DELETE = "false"
141 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
142 }
143 }
144 }
145 // launch stack
146 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400147
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200148 // set reclass repo in heat env
149 try {
150 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
151 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
152 } catch (MissingPropertyException e) {
153 common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400154 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200155
Mykyta Karpin8f961132017-09-22 12:06:44 +0300156 // put formulas revision - stable, testing or nightly
157 if (common.validInputParam('FORMULA_PKG_REVISION')) {
158 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
159 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
160 }
161
Mykyta Karpin0aa35d52017-08-28 11:44:42 +0300162 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400163 }
164
165 // get SALT_MASTER_URL
166 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
chnydae14058a2017-08-29 15:07:48 +0200167 // check that saltMasterHost is valid
168 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
169 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
170 throw new Exception("saltMasterHost is not a valid ip")
171 }
172
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400173 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
174
175 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
176
177 } else if (STACK_TYPE == 'aws') {
178
179 // setup environment
180 aws.setupVirtualEnv(venv)
181
182 // set aws_env_vars
183 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
184
185 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
186 error("If you want to reuse existing stack you need to provide it's name")
187 }
188
189 if (STACK_REUSE.toBoolean() == false) {
190 // Don't allow to set custom stack name
191 wrap([$class: 'BuildUser']) {
192 if (env.BUILD_USER_ID) {
193 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
194 } else {
195 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
Ales Komarek24097402017-05-22 16:28:10 +0200196 }
197 }
198
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400199 // no underscore in STACK_NAME
200 STACK_NAME = STACK_NAME.replaceAll('_', '-')
201 }
Ales Komarek24097402017-05-22 16:28:10 +0200202
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400203 // set description
204 currentBuild.description = STACK_NAME
Tomáš Kukrál77b1b5a2017-09-24 18:56:49 +0200205 outputs.put('stack_name', STACK_NAME)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400206
207 if (STACK_REUSE.toBoolean() == false) {
Ales Komarek24097402017-05-22 16:28:10 +0200208 // get templates
209 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
210
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400211 // start stack
212 def stack_params = [
213 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
214 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
215 ]
216 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
217 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200218 }
Ales Komarek24097402017-05-22 16:28:10 +0200219
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400220 // wait for stack to be ready
221 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
222
223 // get outputs
224 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200225
chnydae14058a2017-08-29 15:07:48 +0200226 // check that saltMasterHost is valid
227 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
228 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
229 throw new Exception("saltMasterHost is not a valid ip")
230 }
231
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200232 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400233 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
234
235 } else if (STACK_TYPE != 'physical') {
236 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
Ales Komarek24097402017-05-22 16:28:10 +0200237 }
238
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200239 outputs.put('salt_api', SALT_MASTER_URL)
240
chnyda597fb032017-10-06 13:42:48 +0200241 // Setup virtualenv for pepper
242 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400243 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200244
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400245
246 // Set up override params
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200247 if (common.validInputParam('SALT_OVERRIDES')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400248 stage('Set Salt overrides') {
chnyda597fb032017-10-06 13:42:48 +0200249 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES)
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200250 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400251 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200252
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400253 //
254 // Install
255 //
Ales Komarek24097402017-05-22 16:28:10 +0200256
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400257 if (common.checkContains('STACK_INSTALL', 'core')) {
258 stage('Install core infrastructure') {
chnyda597fb032017-10-06 13:42:48 +0200259 orchestrate.installFoundationInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400260
261 if (common.checkContains('STACK_INSTALL', 'kvm')) {
chnyda597fb032017-10-06 13:42:48 +0200262 orchestrate.installInfraKvm(venvPepper)
263 orchestrate.installFoundationInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400264 }
Ales Komarek24097402017-05-22 16:28:10 +0200265
chnyda597fb032017-10-06 13:42:48 +0200266 orchestrate.validateFoundationInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400267 }
268 }
Ales Komarek24097402017-05-22 16:28:10 +0200269
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200270 // install ceph
271 if (common.checkContains('STACK_INSTALL', 'ceph')) {
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200272 stage('Install Ceph MONs') {
chnyda597fb032017-10-06 13:42:48 +0200273 orchestrate.installCephMon(venvPepper)
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200274 }
275
276 stage('Install Ceph OSDs') {
chnyda597fb032017-10-06 13:42:48 +0200277 orchestrate.installCephOsd(venvPepper)
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200278 }
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200279
Tomáš Kukrál0cc01092017-08-28 18:25:00 +0200280
281 stage('Install Ceph clients') {
chnyda597fb032017-10-06 13:42:48 +0200282 orchestrate.installCephClient(venvPepper)
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200283 }
Jiri Broulik8c380032017-10-06 13:36:03 +0200284
285 stage('Connect Ceph') {
286 orchestrate.connectCeph(saltMaster)
287 }
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200288 }
289
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400290 // install k8s
291 if (common.checkContains('STACK_INSTALL', 'k8s')) {
292
293 stage('Install Kubernetes infra') {
294 if (STACK_TYPE == 'aws') {
295 // configure kubernetes_control_address - save loadbalancer
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200296 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
Tomáš Kukrál685f3b82017-09-03 10:14:40 +0200297 common.prettyPrint(awsOutputs)
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200298 if (awsOutputs.containsKey('ControlLoadBalancer')) {
chnyda597fb032017-10-06 13:42:48 +0200299 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200300 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
301 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400302 }
303
304 // ensure certificates are generated properly
chnyda597fb032017-10-06 13:42:48 +0200305 salt.runSaltProcessStep(venvPepper, '*', 'saltutil.refresh_pillar', [], null, true)
306 salt.enforceState(venvPepper, '*', ['salt.minion.cert'], true)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400307
chnyda597fb032017-10-06 13:42:48 +0200308 orchestrate.installKubernetesInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400309 }
310
311 if (common.checkContains('STACK_INSTALL', 'contrail')) {
312 stage('Install Contrail for Kubernetes') {
chnyda597fb032017-10-06 13:42:48 +0200313 orchestrate.installContrailNetwork(venvPepper)
314 orchestrate.installContrailCompute(venvPepper)
Ales Komarek24097402017-05-22 16:28:10 +0200315 }
316 }
317
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400318 stage('Install Kubernetes control') {
chnyda597fb032017-10-06 13:42:48 +0200319 orchestrate.installKubernetesControl(venvPepper)
Tomáš Kukrál7e487062017-08-31 11:20:08 +0200320
321 // collect artifacts (kubeconfig)
chnyda597fb032017-10-06 13:42:48 +0200322 writeFile(file: 'kubeconfig', text: salt.getFileContent(venvPepper, 'I@kubernetes:master and *01*', '/etc/kubernetes/admin-kube-config'))
Tomáš Kukrál7e487062017-08-31 11:20:08 +0200323 archiveArtifacts(artifacts: 'kubeconfig')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400324 }
325
326 stage('Scale Kubernetes computes') {
327 if (STACK_COMPUTE_COUNT > 0) {
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200328 if (STACK_TYPE == 'aws') {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400329 // get stack info
330 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
331
332 //update autoscaling group
333 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
334
335 // wait for computes to boot up
336 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
337 sleep(60)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200338
339 } else if (STACK_TYPE == 'heat') {
340 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
341
342 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
343 sleep(60)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200344 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200345
chnyda597fb032017-10-06 13:42:48 +0200346 orchestrate.installKubernetesCompute(venvPepper)
Ales Komarek24097402017-05-22 16:28:10 +0200347 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400348 }
349 }
350
351 // install openstack
352 if (common.checkContains('STACK_INSTALL', 'openstack')) {
353 // install Infra and control, tests, ...
354
355 stage('Install OpenStack infra') {
chnyda597fb032017-10-06 13:42:48 +0200356 orchestrate.installOpenstackInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400357 }
358
359 stage('Install OpenStack control') {
chnyda597fb032017-10-06 13:42:48 +0200360 orchestrate.installOpenstackControl(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400361 }
362
363 stage('Install OpenStack network') {
Ales Komarek24097402017-05-22 16:28:10 +0200364
vrovachev7be1e962017-07-05 13:28:26 +0400365 if (common.checkContains('STACK_INSTALL', 'contrail')) {
chnyda597fb032017-10-06 13:42:48 +0200366 orchestrate.installContrailNetwork(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400367 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
chnyda597fb032017-10-06 13:42:48 +0200368 orchestrate.installOpenstackNetwork(venvPepper)
vrovachev7be1e962017-07-05 13:28:26 +0400369 }
370
chnyda597fb032017-10-06 13:42:48 +0200371 salt.runSaltProcessStep(venvPepper, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
372 salt.runSaltProcessStep(venvPepper, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400373 }
Ales Komarek24097402017-05-22 16:28:10 +0200374
chnyda597fb032017-10-06 13:42:48 +0200375 if (salt.testTarget(venvPepper, 'I@ironic:conductor')){
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400376 stage('Install OpenStack Ironic conductor') {
chnyda597fb032017-10-06 13:42:48 +0200377 orchestrate.installIronicConductor(venvPepper)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200378 }
Ales Komarek24097402017-05-22 16:28:10 +0200379 }
380
Ales Komarek24097402017-05-22 16:28:10 +0200381
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400382 stage('Install OpenStack compute') {
chnyda597fb032017-10-06 13:42:48 +0200383 orchestrate.installOpenstackCompute(venvPepper)
Ales Komarek24097402017-05-22 16:28:10 +0200384
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400385 if (common.checkContains('STACK_INSTALL', 'contrail')) {
chnyda597fb032017-10-06 13:42:48 +0200386 orchestrate.installContrailCompute(venvPepper)
Martin Polreich46971102017-07-11 12:56:40 +0200387 }
388 }
389
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400390 }
391
Jiri Broulikb27b4832017-09-05 16:41:03 +0200392 if (common.checkContains('STACK_INSTALL', 'cicd')) {
393 stage('Install Cicd') {
chnyda597fb032017-10-06 13:42:48 +0200394 orchestrate.installDockerSwarm(venvPepper)
395 orchestrate.installCicd(venvPepper)
Jiri Broulikb27b4832017-09-05 16:41:03 +0200396 }
397 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400398
399 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
400 stage('Install StackLight v1') {
chnyda597fb032017-10-06 13:42:48 +0200401 orchestrate.installStacklightv1Control(venvPepper)
402 orchestrate.installStacklightv1Client(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400403 }
404 }
405
406 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
407 stage('Install StackLight') {
chnyda597fb032017-10-06 13:42:48 +0200408 orchestrate.installDockerSwarm(venvPepper)
409 orchestrate.installStacklight(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400410 }
411 }
412
413 //
414 // Test
415 //
416 def artifacts_dir = '_artifacts/'
417
418 if (common.checkContains('STACK_TEST', 'k8s')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400419 stage('Run k8s conformance e2e tests') {
Anna Babich12dd5b12017-08-21 18:01:35 +0300420 def image = TEST_K8S_CONFORMANCE_IMAGE
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400421 def output_file = image.replaceAll('/', '-') + '.output'
Ales Komarek24097402017-05-22 16:28:10 +0200422
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400423 // run image
chnyda597fb032017-10-06 13:42:48 +0200424 test.runConformanceTests(venvPepper, 'ctl01*', TEST_K8S_API_SERVER, image)
Ales Komarek24097402017-05-22 16:28:10 +0200425
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400426 // collect output
427 sh "mkdir -p ${artifacts_dir}"
chnyda597fb032017-10-06 13:42:48 +0200428 file_content = salt.getFileContent(venvPepper, 'ctl01*', '/tmp/' + output_file)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400429 writeFile file: "${artifacts_dir}${output_file}", text: file_content
430 sh "cat ${artifacts_dir}${output_file}"
Ales Komarek24097402017-05-22 16:28:10 +0200431
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400432 // collect artifacts
433 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
434 }
435 }
Ales Komarek24097402017-05-22 16:28:10 +0200436
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400437 if (common.checkContains('STACK_TEST', 'openstack')) {
438 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
chnyda597fb032017-10-06 13:42:48 +0200439 test.install_docker(venvPepper, TEST_TEMPEST_TARGET)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400440 }
441 stage('Run OpenStack tests') {
chnyda597fb032017-10-06 13:42:48 +0200442 test.runTempestTests(venvPepper, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
Ales Komarek24097402017-05-22 16:28:10 +0200443 }
444
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400445 stage('Copy Tempest results to config node') {
chnyda597fb032017-10-06 13:42:48 +0200446 test.copyTempestResults(venvPepper, TEST_TEMPEST_TARGET)
Ales Komarek24097402017-05-22 16:28:10 +0200447 }
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300448
449 stage('Archive rally artifacts') {
chnyda597fb032017-10-06 13:42:48 +0200450 test.archiveRallyArtifacts(venvPepper, TEST_TEMPEST_TARGET)
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300451 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400452 }
Ales Komarek24097402017-05-22 16:28:10 +0200453
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200454
455 if (common.checkContains('STACK_TEST', 'ceph')) {
Tomáš Kukrálf5798082017-08-21 22:37:41 +0200456 stage('Run infra tests') {
Tomáš Kukrál36d43972017-08-30 12:43:17 +0200457 sleep(120)
Tomáš Kukrál07ad0c92017-08-21 23:19:40 +0200458 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/"
chnyda597fb032017-10-06 13:42:48 +0200459 salt.cmdRun(venvPepper, 'I@salt:master', cmd, false)
460 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, 'I@salt:master', '/root/report.xml'))
Tomáš Kukrálc48456a2017-08-21 23:03:37 +0200461 junit(keepLongStdio: true, testResults: 'report.xml')
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200462 }
463 }
464
465
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200466 stage('Finalize') {
467 if (common.checkContains('STACK_INSTALL', 'finalize')) {
chnyda597fb032017-10-06 13:42:48 +0200468 salt.runSaltProcessStep(venvPepper, '*', 'state.apply', [], null, true)
Ales Komarek24097402017-05-22 16:28:10 +0200469 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200470
471 outputsPretty = common.prettify(outputs)
472 print(outputsPretty)
473 writeFile(file: 'outputs.json', text: outputsPretty)
474 archiveArtifacts(artifacts: 'outputs.json')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400475 }
Tomáš Kukrál53224c22017-07-26 10:53:20 +0200476
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400477 } catch (Throwable e) {
478 currentBuild.result = 'FAILURE'
479 throw e
480 } finally {
Ales Komarek24097402017-05-22 16:28:10 +0200481
482
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400483 //
484 // Clean
485 //
Ales Komarek24097402017-05-22 16:28:10 +0200486
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200487 if (common.validInputParam('STACK_NAME')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400488 // send notification
489 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
490 }
491
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200492 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400493 stage('Trigger cleanup job') {
494 common.errorMsg('Stack cleanup job triggered')
495 build(job: STACK_CLEANUP_JOB, parameters: [
496 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
497 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
498 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
499 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
500 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
501 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
502 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
503 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
504 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
505 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
506 ])
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200507 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400508 } else {
509 if (currentBuild.result == 'FAILURE') {
510 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 +0200511
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200512 if (common.validInputParam('SALT_MASTER_URL')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400513 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
Ales Komarek24097402017-05-22 16:28:10 +0200514 }
515 }
516 }
517 }
518}