blob: 99cbe23422b7fea3523182cd106270d181a0357f [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 }
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200283 }
284
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400285 // install k8s
286 if (common.checkContains('STACK_INSTALL', 'k8s')) {
287
288 stage('Install Kubernetes infra') {
289 if (STACK_TYPE == 'aws') {
290 // configure kubernetes_control_address - save loadbalancer
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200291 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
Tomáš Kukrál685f3b82017-09-03 10:14:40 +0200292 common.prettyPrint(awsOutputs)
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200293 if (awsOutputs.containsKey('ControlLoadBalancer')) {
294 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
295 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
296 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400297 }
298
299 // ensure certificates are generated properly
300 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true)
301 salt.enforceState(saltMaster, '*', ['salt.minion.cert'], true)
302
303 orchestrate.installKubernetesInfra(saltMaster)
304 }
305
306 if (common.checkContains('STACK_INSTALL', 'contrail')) {
307 stage('Install Contrail for Kubernetes') {
308 orchestrate.installContrailNetwork(saltMaster)
309 orchestrate.installContrailCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200310 }
311 }
312
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400313 stage('Install Kubernetes control') {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400314 orchestrate.installKubernetesControl(saltMaster)
Tomáš Kukrál7e487062017-08-31 11:20:08 +0200315
316 // collect artifacts (kubeconfig)
Tomáš Kukrál897b7a72017-08-31 11:54:33 +0200317 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 +0200318 archiveArtifacts(artifacts: 'kubeconfig')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400319 }
320
321 stage('Scale Kubernetes computes') {
322 if (STACK_COMPUTE_COUNT > 0) {
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200323 if (STACK_TYPE == 'aws') {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400324 // get stack info
325 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
326
327 //update autoscaling group
328 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
329
330 // wait for computes to boot up
331 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
332 sleep(60)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200333
334 } else if (STACK_TYPE == 'heat') {
335 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
336
337 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
338 sleep(60)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200339 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200340
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400341 orchestrate.installKubernetesCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200342 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400343 }
344 }
345
346 // install openstack
347 if (common.checkContains('STACK_INSTALL', 'openstack')) {
348 // install Infra and control, tests, ...
349
350 stage('Install OpenStack infra') {
351 orchestrate.installOpenstackInfra(saltMaster)
352 }
353
354 stage('Install OpenStack control') {
355 orchestrate.installOpenstackControl(saltMaster)
356 }
357
358 stage('Install OpenStack network') {
Ales Komarek24097402017-05-22 16:28:10 +0200359
vrovachev7be1e962017-07-05 13:28:26 +0400360 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400361 orchestrate.installContrailNetwork(saltMaster)
362 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
363 orchestrate.installOpenstackNetwork(saltMaster)
vrovachev7be1e962017-07-05 13:28:26 +0400364 }
365
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400366 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
367 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
368 }
Ales Komarek24097402017-05-22 16:28:10 +0200369
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400370 if (salt.testTarget(saltMaster, 'I@ironic:conductor')){
371 stage('Install OpenStack Ironic conductor') {
372 orchestrate.installIronicConductor(saltMaster)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200373 }
Ales Komarek24097402017-05-22 16:28:10 +0200374 }
375
Ales Komarek24097402017-05-22 16:28:10 +0200376
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400377 stage('Install OpenStack compute') {
378 orchestrate.installOpenstackCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200379
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400380 if (common.checkContains('STACK_INSTALL', 'contrail')) {
381 orchestrate.installContrailCompute(saltMaster)
Martin Polreich46971102017-07-11 12:56:40 +0200382 }
383 }
384
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400385 }
386
Jiri Broulikb27b4832017-09-05 16:41:03 +0200387 if (common.checkContains('STACK_INSTALL', 'cicd')) {
388 stage('Install Cicd') {
389 orchestrate.installDockerSwarm(saltMaster)
390 orchestrate.installCicd(saltMaster)
391 }
392 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400393
394 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
395 stage('Install StackLight v1') {
396 orchestrate.installStacklightv1Control(saltMaster)
397 orchestrate.installStacklightv1Client(saltMaster)
398 }
399 }
400
401 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
402 stage('Install StackLight') {
403 orchestrate.installDockerSwarm(saltMaster)
404 orchestrate.installStacklight(saltMaster)
405 }
406 }
407
408 //
409 // Test
410 //
411 def artifacts_dir = '_artifacts/'
412
413 if (common.checkContains('STACK_TEST', 'k8s')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400414 stage('Run k8s conformance e2e tests') {
Anna Babich12dd5b12017-08-21 18:01:35 +0300415 def image = TEST_K8S_CONFORMANCE_IMAGE
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400416 def output_file = image.replaceAll('/', '-') + '.output'
Ales Komarek24097402017-05-22 16:28:10 +0200417
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400418 // run image
Tetiana Korchak225abad2017-09-28 16:16:47 -0700419 test.runConformanceTests(saltMaster, 'ctl01*', TEST_K8S_API_SERVER, image)
Ales Komarek24097402017-05-22 16:28:10 +0200420
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400421 // collect output
422 sh "mkdir -p ${artifacts_dir}"
423 file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
424 writeFile file: "${artifacts_dir}${output_file}", text: file_content
425 sh "cat ${artifacts_dir}${output_file}"
Ales Komarek24097402017-05-22 16:28:10 +0200426
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400427 // collect artifacts
428 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
429 }
430 }
Ales Komarek24097402017-05-22 16:28:10 +0200431
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400432 if (common.checkContains('STACK_TEST', 'openstack')) {
433 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
434 test.install_docker(saltMaster, TEST_TEMPEST_TARGET)
435 }
436 stage('Run OpenStack tests') {
437 test.runTempestTests(saltMaster, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
Ales Komarek24097402017-05-22 16:28:10 +0200438 }
439
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400440 stage('Copy Tempest results to config node') {
441 test.copyTempestResults(saltMaster, TEST_TEMPEST_TARGET)
Ales Komarek24097402017-05-22 16:28:10 +0200442 }
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300443
444 stage('Archive rally artifacts') {
445 test.archiveRallyArtifacts(saltMaster, TEST_TEMPEST_TARGET)
446 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400447 }
Ales Komarek24097402017-05-22 16:28:10 +0200448
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200449
450 if (common.checkContains('STACK_TEST', 'ceph')) {
Tomáš Kukrálf5798082017-08-21 22:37:41 +0200451 stage('Run infra tests') {
Tomáš Kukrál36d43972017-08-30 12:43:17 +0200452 sleep(120)
Tomáš Kukrál07ad0c92017-08-21 23:19:40 +0200453 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 +0200454 salt.cmdRun(saltMaster, 'I@salt:master', cmd, false)
Tomáš Kukrál09d67cd2017-08-21 23:22:21 +0200455 writeFile(file: 'report.xml', text: salt.getFileContent(saltMaster, 'I@salt:master', '/root/report.xml'))
Tomáš Kukrálc48456a2017-08-21 23:03:37 +0200456 junit(keepLongStdio: true, testResults: 'report.xml')
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200457 }
458 }
459
460
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200461 stage('Finalize') {
462 if (common.checkContains('STACK_INSTALL', 'finalize')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400463 salt.runSaltProcessStep(saltMaster, '*', 'state.apply', [], null, true)
Ales Komarek24097402017-05-22 16:28:10 +0200464 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200465
466 outputsPretty = common.prettify(outputs)
467 print(outputsPretty)
468 writeFile(file: 'outputs.json', text: outputsPretty)
469 archiveArtifacts(artifacts: 'outputs.json')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400470 }
Tomáš Kukrál53224c22017-07-26 10:53:20 +0200471
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400472 } catch (Throwable e) {
473 currentBuild.result = 'FAILURE'
474 throw e
475 } finally {
Ales Komarek24097402017-05-22 16:28:10 +0200476
477
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400478 //
479 // Clean
480 //
Ales Komarek24097402017-05-22 16:28:10 +0200481
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200482 if (common.validInputParam('STACK_NAME')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400483 // send notification
484 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
485 }
486
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200487 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400488 stage('Trigger cleanup job') {
489 common.errorMsg('Stack cleanup job triggered')
490 build(job: STACK_CLEANUP_JOB, parameters: [
491 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
492 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
493 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
494 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
495 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
496 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
497 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
498 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
499 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
500 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
501 ])
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200502 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400503 } else {
504 if (currentBuild.result == 'FAILURE') {
505 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 +0200506
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200507 if (common.validInputParam('SALT_MASTER_URL')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400508 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
Ales Komarek24097402017-05-22 16:28:10 +0200509 }
510 }
511 }
512 }
513}