blob: ce9e6907dfd4c4d6ca3a9874504fecd8dd0aee9c [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('_', '-')
Tomáš Kukrál77b1b5a2017-09-24 18:56:49 +0200115 outputs.put('stack_name', STACK_NAME)
Tomáš Kukrál86b9ab22017-09-05 16:55:58 +0200116
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400117 // set description
118 currentBuild.description = "${STACK_NAME}"
119
120 // get templates
121 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
122
123 // create openstack env
124 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
125 openstackCloud = openstack.createOpenstackEnv(
126 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
127 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
128 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
129 OPENSTACK_API_VERSION)
130 openstack.getKeystoneToken(openstackCloud, venv)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200131
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400132 //
133 // Verify possibility of create stack for given user and stack type
134 //
135 wrap([$class: 'BuildUser']) {
136 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
Oleh Hryhorov8e320ca2017-09-22 13:23:44 +0300137 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200138 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400139 STACK_DELETE = "false"
140 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
141 }
142 }
143 }
144 // launch stack
145 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400146
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200147 // set reclass repo in heat env
148 try {
149 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
150 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
151 } catch (MissingPropertyException e) {
152 common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400153 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200154
Mykyta Karpin8f961132017-09-22 12:06:44 +0300155 // put formulas revision - stable, testing or nightly
156 if (common.validInputParam('FORMULA_PKG_REVISION')) {
157 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
158 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
159 }
160
Mykyta Karpin0aa35d52017-08-28 11:44:42 +0300161 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400162 }
163
164 // get SALT_MASTER_URL
165 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
chnydae14058a2017-08-29 15:07:48 +0200166 // check that saltMasterHost is valid
167 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
168 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
169 throw new Exception("saltMasterHost is not a valid ip")
170 }
171
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400172 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
173
174 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
175
176 } else if (STACK_TYPE == 'aws') {
177
178 // setup environment
179 aws.setupVirtualEnv(venv)
180
181 // set aws_env_vars
182 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
183
184 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
185 error("If you want to reuse existing stack you need to provide it's name")
186 }
187
188 if (STACK_REUSE.toBoolean() == false) {
189 // Don't allow to set custom stack name
190 wrap([$class: 'BuildUser']) {
191 if (env.BUILD_USER_ID) {
192 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
193 } else {
194 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
Ales Komarek24097402017-05-22 16:28:10 +0200195 }
196 }
197
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400198 // no underscore in STACK_NAME
199 STACK_NAME = STACK_NAME.replaceAll('_', '-')
200 }
Ales Komarek24097402017-05-22 16:28:10 +0200201
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400202 // set description
203 currentBuild.description = STACK_NAME
Tomáš Kukrál77b1b5a2017-09-24 18:56:49 +0200204 outputs.put('stack_name', STACK_NAME)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400205
206 if (STACK_REUSE.toBoolean() == false) {
Ales Komarek24097402017-05-22 16:28:10 +0200207 // get templates
208 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
209
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400210 // start stack
211 def stack_params = [
212 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
213 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
214 ]
215 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
216 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200217 }
Ales Komarek24097402017-05-22 16:28:10 +0200218
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400219 // wait for stack to be ready
220 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
221
222 // get outputs
223 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200224
chnydae14058a2017-08-29 15:07:48 +0200225 // check that saltMasterHost is valid
226 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
227 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
228 throw new Exception("saltMasterHost is not a valid ip")
229 }
230
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200231 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400232 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
233
234 } else if (STACK_TYPE != 'physical') {
235 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
Ales Komarek24097402017-05-22 16:28:10 +0200236 }
237
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200238 outputs.put('salt_api', SALT_MASTER_URL)
239
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400240 // Connect to Salt master
241 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
242 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200243
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400244
245 // Set up override params
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200246 if (common.validInputParam('SALT_OVERRIDES')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400247 stage('Set Salt overrides') {
248 salt.setSaltOverrides(saltMaster, SALT_OVERRIDES)
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200249 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400250 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200251
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400252 //
253 // Install
254 //
Ales Komarek24097402017-05-22 16:28:10 +0200255
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400256 if (common.checkContains('STACK_INSTALL', 'core')) {
257 stage('Install core infrastructure') {
258 orchestrate.installFoundationInfra(saltMaster)
259
260 if (common.checkContains('STACK_INSTALL', 'kvm')) {
261 orchestrate.installInfraKvm(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200262 orchestrate.installFoundationInfra(saltMaster)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400263 }
Ales Komarek24097402017-05-22 16:28:10 +0200264
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400265 orchestrate.validateFoundationInfra(saltMaster)
266 }
267 }
Ales Komarek24097402017-05-22 16:28:10 +0200268
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200269 // install ceph
270 if (common.checkContains('STACK_INSTALL', 'ceph')) {
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200271 stage('Install Ceph MONs') {
272 orchestrate.installCephMon(saltMaster)
273 }
274
275 stage('Install Ceph OSDs') {
276 orchestrate.installCephOsd(saltMaster)
277 }
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200278
Tomáš Kukrál0cc01092017-08-28 18:25:00 +0200279
280 stage('Install Ceph clients') {
281 orchestrate.installCephClient(saltMaster)
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200282 }
Jiri Broulik8c380032017-10-06 13:36:03 +0200283
284 stage('Connect Ceph') {
285 orchestrate.connectCeph(saltMaster)
286 }
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200287 }
288
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400289 // install k8s
290 if (common.checkContains('STACK_INSTALL', 'k8s')) {
291
292 stage('Install Kubernetes infra') {
293 if (STACK_TYPE == 'aws') {
294 // configure kubernetes_control_address - save loadbalancer
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200295 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
Tomáš Kukrál685f3b82017-09-03 10:14:40 +0200296 common.prettyPrint(awsOutputs)
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200297 if (awsOutputs.containsKey('ControlLoadBalancer')) {
298 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
299 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
300 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400301 }
302
303 // ensure certificates are generated properly
304 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true)
305 salt.enforceState(saltMaster, '*', ['salt.minion.cert'], true)
306
307 orchestrate.installKubernetesInfra(saltMaster)
308 }
309
310 if (common.checkContains('STACK_INSTALL', 'contrail')) {
311 stage('Install Contrail for Kubernetes') {
312 orchestrate.installContrailNetwork(saltMaster)
313 orchestrate.installContrailCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200314 }
315 }
316
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400317 stage('Install Kubernetes control') {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400318 orchestrate.installKubernetesControl(saltMaster)
Tomáš Kukrál7e487062017-08-31 11:20:08 +0200319
320 // collect artifacts (kubeconfig)
Tomáš Kukrál897b7a72017-08-31 11:54:33 +0200321 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 +0200322 archiveArtifacts(artifacts: 'kubeconfig')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400323 }
324
325 stage('Scale Kubernetes computes') {
326 if (STACK_COMPUTE_COUNT > 0) {
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200327 if (STACK_TYPE == 'aws') {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400328 // get stack info
329 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
330
331 //update autoscaling group
332 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
333
334 // wait for computes to boot up
335 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
336 sleep(60)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200337
338 } else if (STACK_TYPE == 'heat') {
339 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
340
341 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
342 sleep(60)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200343 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200344
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400345 orchestrate.installKubernetesCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200346 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400347 }
348 }
349
350 // install openstack
351 if (common.checkContains('STACK_INSTALL', 'openstack')) {
352 // install Infra and control, tests, ...
353
354 stage('Install OpenStack infra') {
355 orchestrate.installOpenstackInfra(saltMaster)
356 }
357
358 stage('Install OpenStack control') {
359 orchestrate.installOpenstackControl(saltMaster)
360 }
361
362 stage('Install OpenStack network') {
Ales Komarek24097402017-05-22 16:28:10 +0200363
vrovachev7be1e962017-07-05 13:28:26 +0400364 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400365 orchestrate.installContrailNetwork(saltMaster)
366 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
367 orchestrate.installOpenstackNetwork(saltMaster)
vrovachev7be1e962017-07-05 13:28:26 +0400368 }
369
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400370 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
371 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
372 }
Ales Komarek24097402017-05-22 16:28:10 +0200373
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400374 if (salt.testTarget(saltMaster, 'I@ironic:conductor')){
375 stage('Install OpenStack Ironic conductor') {
376 orchestrate.installIronicConductor(saltMaster)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200377 }
Ales Komarek24097402017-05-22 16:28:10 +0200378 }
379
Ales Komarek24097402017-05-22 16:28:10 +0200380
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400381 stage('Install OpenStack compute') {
382 orchestrate.installOpenstackCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200383
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400384 if (common.checkContains('STACK_INSTALL', 'contrail')) {
385 orchestrate.installContrailCompute(saltMaster)
Martin Polreich46971102017-07-11 12:56:40 +0200386 }
387 }
388
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400389 }
390
Jiri Broulikb27b4832017-09-05 16:41:03 +0200391 if (common.checkContains('STACK_INSTALL', 'cicd')) {
392 stage('Install Cicd') {
393 orchestrate.installDockerSwarm(saltMaster)
394 orchestrate.installCicd(saltMaster)
395 }
396 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400397
398 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
399 stage('Install StackLight v1') {
400 orchestrate.installStacklightv1Control(saltMaster)
401 orchestrate.installStacklightv1Client(saltMaster)
402 }
403 }
404
405 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
406 stage('Install StackLight') {
407 orchestrate.installDockerSwarm(saltMaster)
408 orchestrate.installStacklight(saltMaster)
409 }
410 }
411
412 //
413 // Test
414 //
415 def artifacts_dir = '_artifacts/'
416
417 if (common.checkContains('STACK_TEST', 'k8s')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400418 stage('Run k8s conformance e2e tests') {
Anna Babich12dd5b12017-08-21 18:01:35 +0300419 def image = TEST_K8S_CONFORMANCE_IMAGE
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400420 def output_file = image.replaceAll('/', '-') + '.output'
Ales Komarek24097402017-05-22 16:28:10 +0200421
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400422 // run image
Tetiana Korchak225abad2017-09-28 16:16:47 -0700423 test.runConformanceTests(saltMaster, 'ctl01*', TEST_K8S_API_SERVER, image)
Ales Komarek24097402017-05-22 16:28:10 +0200424
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400425 // collect output
426 sh "mkdir -p ${artifacts_dir}"
427 file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
428 writeFile file: "${artifacts_dir}${output_file}", text: file_content
429 sh "cat ${artifacts_dir}${output_file}"
Ales Komarek24097402017-05-22 16:28:10 +0200430
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400431 // collect artifacts
432 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
433 }
434 }
Ales Komarek24097402017-05-22 16:28:10 +0200435
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400436 if (common.checkContains('STACK_TEST', 'openstack')) {
437 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
438 test.install_docker(saltMaster, TEST_TEMPEST_TARGET)
439 }
440 stage('Run OpenStack tests') {
441 test.runTempestTests(saltMaster, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
Ales Komarek24097402017-05-22 16:28:10 +0200442 }
443
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400444 stage('Copy Tempest results to config node') {
445 test.copyTempestResults(saltMaster, TEST_TEMPEST_TARGET)
Ales Komarek24097402017-05-22 16:28:10 +0200446 }
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300447
448 stage('Archive rally artifacts') {
449 test.archiveRallyArtifacts(saltMaster, TEST_TEMPEST_TARGET)
450 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400451 }
Ales Komarek24097402017-05-22 16:28:10 +0200452
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200453
454 if (common.checkContains('STACK_TEST', 'ceph')) {
Tomáš Kukrálf5798082017-08-21 22:37:41 +0200455 stage('Run infra tests') {
Tomáš Kukrál36d43972017-08-30 12:43:17 +0200456 sleep(120)
Tomáš Kukrál07ad0c92017-08-21 23:19:40 +0200457 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 +0200458 salt.cmdRun(saltMaster, 'I@salt:master', cmd, false)
Tomáš Kukrál09d67cd2017-08-21 23:22:21 +0200459 writeFile(file: 'report.xml', text: salt.getFileContent(saltMaster, 'I@salt:master', '/root/report.xml'))
Tomáš Kukrálc48456a2017-08-21 23:03:37 +0200460 junit(keepLongStdio: true, testResults: 'report.xml')
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200461 }
462 }
463
464
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200465 stage('Finalize') {
466 if (common.checkContains('STACK_INSTALL', 'finalize')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400467 salt.runSaltProcessStep(saltMaster, '*', 'state.apply', [], null, true)
Ales Komarek24097402017-05-22 16:28:10 +0200468 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200469
470 outputsPretty = common.prettify(outputs)
471 print(outputsPretty)
472 writeFile(file: 'outputs.json', text: outputsPretty)
473 archiveArtifacts(artifacts: 'outputs.json')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400474 }
Tomáš Kukrál53224c22017-07-26 10:53:20 +0200475
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400476 } catch (Throwable e) {
477 currentBuild.result = 'FAILURE'
478 throw e
479 } finally {
Ales Komarek24097402017-05-22 16:28:10 +0200480
481
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400482 //
483 // Clean
484 //
Ales Komarek24097402017-05-22 16:28:10 +0200485
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200486 if (common.validInputParam('STACK_NAME')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400487 // send notification
488 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
489 }
490
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200491 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400492 stage('Trigger cleanup job') {
493 common.errorMsg('Stack cleanup job triggered')
494 build(job: STACK_CLEANUP_JOB, parameters: [
495 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
496 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
497 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
498 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
499 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
500 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
501 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
502 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
503 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
504 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
505 ])
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200506 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400507 } else {
508 if (currentBuild.result == 'FAILURE') {
509 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 +0200510
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200511 if (common.validInputParam('SALT_MASTER_URL')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400512 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
Ales Komarek24097402017-05-22 16:28:10 +0200513 }
514 }
515 }
516 }
517}