blob: c0652e9e299ada2b84394905e73c376315c360e2 [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)
Oleh Hryhorov9630a762017-10-24 14:33:25 +030034 * SLAVE_NODE Lable or node name where the job will be run
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020035
Ales Komarek24097402017-05-22 16:28:10 +020036 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
Tomáš Kukrál4691f682017-07-27 16:36:12 +020037 * required for STACK_TYPE=physical
Ales Komarek24097402017-05-22 16:28:10 +020038 * SALT_MASTER_URL URL of Salt master
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020039
40 * Test settings:
41 * TEST_K8S_API_SERVER Kubernetes API address
42 * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
Ales Komarek24097402017-05-22 16:28:10 +020043 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020044 * TEST_DOCKER_INSTALL Install docker on the target if true
45 * TEST_TEMPEST_IMAGE Tempest image link
46 * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only
47 * TEST_TEMPEST_TARGET Salt target for tempest node
Ales Komarek24097402017-05-22 16:28:10 +020048 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020049 * optional parameters for overwriting soft params
50 * SALT_OVERRIDES YAML with overrides for Salt deployment
Ales Komarek24097402017-05-22 16:28:10 +020051 *
52 */
Tomáš Kukrál3a17dd62017-07-27 18:24:16 +020053
Ales Komarek24097402017-05-22 16:28:10 +020054common = new com.mirantis.mk.Common()
55git = new com.mirantis.mk.Git()
56openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020057aws = new com.mirantis.mk.Aws()
Ales Komarek24097402017-05-22 16:28:10 +020058orchestrate = new com.mirantis.mk.Orchestrate()
Mykyta Karpine016d7e2017-10-09 13:35:20 +030059python = new com.mirantis.mk.Python()
Ales Komarek24097402017-05-22 16:28:10 +020060salt = new com.mirantis.mk.Salt()
61test = new com.mirantis.mk.Test()
62
63_MAX_PERMITTED_STACKS = 2
64overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
65
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020066// Define global variables
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020067def venv
chnyda597fb032017-10-06 13:42:48 +020068def venvPepper
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020069def outputs = [:]
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020070
chnydae14058a2017-08-29 15:07:48 +020071def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
72
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020073if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020074 def aws_env_vars
Tomáš Kukrál8427ff52017-08-30 15:46:52 +020075} else if (STACK_TYPE == 'heat') {
76 def envParams
77 def openstackCloud
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020078}
79
Oleh Hryhorov9630a762017-10-24 14:33:25 +030080def slave_node = 'python'
81
Oleh Hryhorov54460512017-10-26 18:45:36 +030082if (common.validInputParam('SLAVE_NODE')) {
Oleh Hryhorov9630a762017-10-24 14:33:25 +030083 slave_node = SLAVE_NODE
84}
85
86node(slave_node) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040087 try {
88 // Set build-specific variables
89 venv = "${env.WORKSPACE}/venv"
chnyda597fb032017-10-06 13:42:48 +020090 venvPepper = "${env.WORKSPACE}/venvPepper"
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020091
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040092 //
93 // Prepare machines
94 //
95 stage ('Create infrastructure') {
Ales Komarek24097402017-05-22 16:28:10 +020096
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020097 outputs.put('stack_type', STACK_TYPE)
98
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040099 if (STACK_TYPE == 'heat') {
100 // value defaults
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200101 envParams = [
102 'cluster_zone': HEAT_STACK_ZONE,
103 'cluster_public_net': HEAT_STACK_PUBLIC_NET
104 ]
Ales Komarek24097402017-05-22 16:28:10 +0200105
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400106 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
107 error("If you want to reuse existing stack you need to provide it's name")
108 }
109
110 if (STACK_REUSE.toBoolean() == false) {
111 // Don't allow to set custom heat stack name
112 wrap([$class: 'BuildUser']) {
113 if (env.BUILD_USER_ID) {
114 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
115 } else {
116 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
117 }
118 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200119 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400120 }
Ales Komarek24097402017-05-22 16:28:10 +0200121
Tomáš Kukrál86b9ab22017-09-05 16:55:58 +0200122 // no underscore in STACK_NAME
123 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Tomáš Kukrál77b1b5a2017-09-24 18:56:49 +0200124 outputs.put('stack_name', STACK_NAME)
Tomáš Kukrál86b9ab22017-09-05 16:55:58 +0200125
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400126 // set description
127 currentBuild.description = "${STACK_NAME}"
128
129 // get templates
130 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
131
132 // create openstack env
133 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
134 openstackCloud = openstack.createOpenstackEnv(
135 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
136 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
137 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
138 OPENSTACK_API_VERSION)
139 openstack.getKeystoneToken(openstackCloud, venv)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200140
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400141 //
142 // Verify possibility of create stack for given user and stack type
143 //
144 wrap([$class: 'BuildUser']) {
145 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
Oleh Hryhorov8e320ca2017-09-22 13:23:44 +0300146 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200147 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400148 STACK_DELETE = "false"
149 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
150 }
151 }
152 }
153 // launch stack
154 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400155
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200156 // set reclass repo in heat env
157 try {
158 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
159 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
160 } catch (MissingPropertyException e) {
161 common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400162 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200163
Mykyta Karpin8f961132017-09-22 12:06:44 +0300164 // put formulas revision - stable, testing or nightly
165 if (common.validInputParam('FORMULA_PKG_REVISION')) {
166 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
167 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
168 }
169
Mykyta Karpin0aa35d52017-08-28 11:44:42 +0300170 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400171 }
172
173 // get SALT_MASTER_URL
174 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
chnydae14058a2017-08-29 15:07:48 +0200175 // check that saltMasterHost is valid
176 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
177 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
178 throw new Exception("saltMasterHost is not a valid ip")
179 }
180
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400181 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
182
183 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
184
185 } else if (STACK_TYPE == 'aws') {
186
187 // setup environment
188 aws.setupVirtualEnv(venv)
189
190 // set aws_env_vars
191 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
192
193 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
194 error("If you want to reuse existing stack you need to provide it's name")
195 }
196
197 if (STACK_REUSE.toBoolean() == false) {
198 // Don't allow to set custom stack name
199 wrap([$class: 'BuildUser']) {
200 if (env.BUILD_USER_ID) {
201 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
202 } else {
203 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
Ales Komarek24097402017-05-22 16:28:10 +0200204 }
205 }
206
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400207 // no underscore in STACK_NAME
208 STACK_NAME = STACK_NAME.replaceAll('_', '-')
209 }
Ales Komarek24097402017-05-22 16:28:10 +0200210
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400211 // set description
212 currentBuild.description = STACK_NAME
Tomáš Kukrál77b1b5a2017-09-24 18:56:49 +0200213 outputs.put('stack_name', STACK_NAME)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400214
215 if (STACK_REUSE.toBoolean() == false) {
Ales Komarek24097402017-05-22 16:28:10 +0200216 // get templates
217 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
218
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400219 // start stack
220 def stack_params = [
221 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
222 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
223 ]
224 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
225 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200226 }
Ales Komarek24097402017-05-22 16:28:10 +0200227
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400228 // wait for stack to be ready
229 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
230
231 // get outputs
232 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200233
chnydae14058a2017-08-29 15:07:48 +0200234 // check that saltMasterHost is valid
235 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
236 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
237 throw new Exception("saltMasterHost is not a valid ip")
238 }
239
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200240 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400241 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
242
243 } else if (STACK_TYPE != 'physical') {
244 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
Ales Komarek24097402017-05-22 16:28:10 +0200245 }
246
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200247 outputs.put('salt_api', SALT_MASTER_URL)
248
chnyda597fb032017-10-06 13:42:48 +0200249 // Setup virtualenv for pepper
250 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
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 // Set up override params
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200255 if (common.validInputParam('SALT_OVERRIDES')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400256 stage('Set Salt overrides') {
chnyda597fb032017-10-06 13:42:48 +0200257 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES)
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200258 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400259 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200260
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400261 //
262 // Install
263 //
Ales Komarek24097402017-05-22 16:28:10 +0200264
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400265 if (common.checkContains('STACK_INSTALL', 'core')) {
266 stage('Install core infrastructure') {
chnyda597fb032017-10-06 13:42:48 +0200267 orchestrate.installFoundationInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400268
269 if (common.checkContains('STACK_INSTALL', 'kvm')) {
chnyda597fb032017-10-06 13:42:48 +0200270 orchestrate.installInfraKvm(venvPepper)
271 orchestrate.installFoundationInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400272 }
Ales Komarek24097402017-05-22 16:28:10 +0200273
chnyda597fb032017-10-06 13:42:48 +0200274 orchestrate.validateFoundationInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400275 }
276 }
Ales Komarek24097402017-05-22 16:28:10 +0200277
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200278 // install ceph
279 if (common.checkContains('STACK_INSTALL', 'ceph')) {
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200280 stage('Install Ceph MONs') {
chnyda597fb032017-10-06 13:42:48 +0200281 orchestrate.installCephMon(venvPepper)
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200282 }
283
284 stage('Install Ceph OSDs') {
chnyda597fb032017-10-06 13:42:48 +0200285 orchestrate.installCephOsd(venvPepper)
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200286 }
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200287
Tomáš Kukrál0cc01092017-08-28 18:25:00 +0200288
289 stage('Install Ceph clients') {
chnyda597fb032017-10-06 13:42:48 +0200290 orchestrate.installCephClient(venvPepper)
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200291 }
Jiri Broulik8c380032017-10-06 13:36:03 +0200292
293 stage('Connect Ceph') {
chnyda625f4b42017-10-11 14:10:31 +0200294 orchestrate.connectCeph(venvPepper)
Jiri Broulik8c380032017-10-06 13:36:03 +0200295 }
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200296 }
297
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400298 // install k8s
299 if (common.checkContains('STACK_INSTALL', 'k8s')) {
300
301 stage('Install Kubernetes infra') {
302 if (STACK_TYPE == 'aws') {
303 // configure kubernetes_control_address - save loadbalancer
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200304 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
Tomáš Kukrál685f3b82017-09-03 10:14:40 +0200305 common.prettyPrint(awsOutputs)
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200306 if (awsOutputs.containsKey('ControlLoadBalancer')) {
chnyda597fb032017-10-06 13:42:48 +0200307 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 +0200308 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
309 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400310 }
311
312 // ensure certificates are generated properly
chnyda597fb032017-10-06 13:42:48 +0200313 salt.runSaltProcessStep(venvPepper, '*', 'saltutil.refresh_pillar', [], null, true)
314 salt.enforceState(venvPepper, '*', ['salt.minion.cert'], true)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400315
chnyda597fb032017-10-06 13:42:48 +0200316 orchestrate.installKubernetesInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400317 }
318
319 if (common.checkContains('STACK_INSTALL', 'contrail')) {
320 stage('Install Contrail for Kubernetes') {
chnyda597fb032017-10-06 13:42:48 +0200321 orchestrate.installContrailNetwork(venvPepper)
322 orchestrate.installContrailCompute(venvPepper)
Ales Komarek24097402017-05-22 16:28:10 +0200323 }
324 }
325
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400326 stage('Install Kubernetes control') {
chnyda597fb032017-10-06 13:42:48 +0200327 orchestrate.installKubernetesControl(venvPepper)
Tomáš Kukrál7e487062017-08-31 11:20:08 +0200328
329 // collect artifacts (kubeconfig)
chnyda597fb032017-10-06 13:42:48 +0200330 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 +0200331 archiveArtifacts(artifacts: 'kubeconfig')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400332 }
333
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100334 stage('Install Kubernetes computes') {
335 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
336 if (STACK_COMPUTE_COUNT > 0) {
337 if (STACK_TYPE == 'aws') {
338 // get stack info
339 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400340
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100341 //update autoscaling group
342 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400343
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100344 // wait for computes to boot up
345 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
346 sleep(60)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200347
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100348 } else if (STACK_TYPE == 'heat') {
349 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200350
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100351 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
352 sleep(60)
353 }
354
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200355 }
Ales Komarek24097402017-05-22 16:28:10 +0200356 }
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100357
358 orchestrate.installKubernetesCompute(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400359 }
360 }
361
362 // install openstack
363 if (common.checkContains('STACK_INSTALL', 'openstack')) {
364 // install Infra and control, tests, ...
365
366 stage('Install OpenStack infra') {
chnyda597fb032017-10-06 13:42:48 +0200367 orchestrate.installOpenstackInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400368 }
369
370 stage('Install OpenStack control') {
chnyda597fb032017-10-06 13:42:48 +0200371 orchestrate.installOpenstackControl(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400372 }
373
374 stage('Install OpenStack network') {
Ales Komarek24097402017-05-22 16:28:10 +0200375
vrovachev7be1e962017-07-05 13:28:26 +0400376 if (common.checkContains('STACK_INSTALL', 'contrail')) {
chnyda597fb032017-10-06 13:42:48 +0200377 orchestrate.installContrailNetwork(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400378 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
chnyda597fb032017-10-06 13:42:48 +0200379 orchestrate.installOpenstackNetwork(venvPepper)
vrovachev7be1e962017-07-05 13:28:26 +0400380 }
381
chnyda597fb032017-10-06 13:42:48 +0200382 salt.runSaltProcessStep(venvPepper, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
383 salt.runSaltProcessStep(venvPepper, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400384 }
Ales Komarek24097402017-05-22 16:28:10 +0200385
chnyda597fb032017-10-06 13:42:48 +0200386 if (salt.testTarget(venvPepper, 'I@ironic:conductor')){
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400387 stage('Install OpenStack Ironic conductor') {
chnyda597fb032017-10-06 13:42:48 +0200388 orchestrate.installIronicConductor(venvPepper)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200389 }
Ales Komarek24097402017-05-22 16:28:10 +0200390 }
391
Ales Komarek24097402017-05-22 16:28:10 +0200392
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400393 stage('Install OpenStack compute') {
chnyda597fb032017-10-06 13:42:48 +0200394 orchestrate.installOpenstackCompute(venvPepper)
Ales Komarek24097402017-05-22 16:28:10 +0200395
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400396 if (common.checkContains('STACK_INSTALL', 'contrail')) {
chnyda597fb032017-10-06 13:42:48 +0200397 orchestrate.installContrailCompute(venvPepper)
Martin Polreich46971102017-07-11 12:56:40 +0200398 }
399 }
400
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400401 }
402
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400403 if (common.checkContains('STACK_INSTALL', 'oss')) {
404 stage('Install Oss infra') {
405 orchestrate.installOssInfra(venvPepper)
406 }
407 }
408
Jiri Broulikb27b4832017-09-05 16:41:03 +0200409 if (common.checkContains('STACK_INSTALL', 'cicd')) {
410 stage('Install Cicd') {
chnyda597fb032017-10-06 13:42:48 +0200411 orchestrate.installDockerSwarm(venvPepper)
412 orchestrate.installCicd(venvPepper)
Jiri Broulikb27b4832017-09-05 16:41:03 +0200413 }
414 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400415
416 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
417 stage('Install StackLight v1') {
chnyda597fb032017-10-06 13:42:48 +0200418 orchestrate.installStacklightv1Control(venvPepper)
419 orchestrate.installStacklightv1Client(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400420 }
421 }
422
423 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
424 stage('Install StackLight') {
chnyda597fb032017-10-06 13:42:48 +0200425 orchestrate.installDockerSwarm(venvPepper)
426 orchestrate.installStacklight(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400427 }
428 }
429
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400430 if (common.checkContains('STACK_INSTALL', 'oss')) {
431 stage('Install OSS') {
432 if (!common.checkContains('STACK_INSTALL', 'stacklight')) {
433 // In case if StackLightv2 enabled containers already started
434 orchestrate.installDockerSwarm(venvPepper)
435 salt.enforceState(venvPepper, 'I@docker:swarm:role:master and I@devops_portal:config', 'docker.client', true)
436 }
437 orchestrate.installOss(venvPepper)
438 }
439 }
440
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400441 //
442 // Test
443 //
444 def artifacts_dir = '_artifacts/'
445
446 if (common.checkContains('STACK_TEST', 'k8s')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400447 stage('Run k8s conformance e2e tests') {
Anna Babich12dd5b12017-08-21 18:01:35 +0300448 def image = TEST_K8S_CONFORMANCE_IMAGE
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400449 def output_file = image.replaceAll('/', '-') + '.output'
Ales Komarek24097402017-05-22 16:28:10 +0200450
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400451 // run image
chnyda597fb032017-10-06 13:42:48 +0200452 test.runConformanceTests(venvPepper, 'ctl01*', TEST_K8S_API_SERVER, image)
Ales Komarek24097402017-05-22 16:28:10 +0200453
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400454 // collect output
455 sh "mkdir -p ${artifacts_dir}"
chnyda597fb032017-10-06 13:42:48 +0200456 file_content = salt.getFileContent(venvPepper, 'ctl01*', '/tmp/' + output_file)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400457 writeFile file: "${artifacts_dir}${output_file}", text: file_content
458 sh "cat ${artifacts_dir}${output_file}"
Ales Komarek24097402017-05-22 16:28:10 +0200459
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400460 // collect artifacts
461 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
462 }
463 }
Ales Komarek24097402017-05-22 16:28:10 +0200464
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400465 if (common.checkContains('STACK_TEST', 'openstack')) {
466 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
chnyda597fb032017-10-06 13:42:48 +0200467 test.install_docker(venvPepper, TEST_TEMPEST_TARGET)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400468 }
469 stage('Run OpenStack tests') {
chnyda597fb032017-10-06 13:42:48 +0200470 test.runTempestTests(venvPepper, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
Ales Komarek24097402017-05-22 16:28:10 +0200471 }
472
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400473 stage('Copy Tempest results to config node') {
chnyda597fb032017-10-06 13:42:48 +0200474 test.copyTempestResults(venvPepper, TEST_TEMPEST_TARGET)
Ales Komarek24097402017-05-22 16:28:10 +0200475 }
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300476
477 stage('Archive rally artifacts') {
chnyda597fb032017-10-06 13:42:48 +0200478 test.archiveRallyArtifacts(venvPepper, TEST_TEMPEST_TARGET)
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300479 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400480 }
Ales Komarek24097402017-05-22 16:28:10 +0200481
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200482
483 if (common.checkContains('STACK_TEST', 'ceph')) {
Tomáš Kukrálf5798082017-08-21 22:37:41 +0200484 stage('Run infra tests') {
Tomáš Kukrál36d43972017-08-30 12:43:17 +0200485 sleep(120)
Tomáš Kukrál07ad0c92017-08-21 23:19:40 +0200486 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 +0200487 salt.cmdRun(venvPepper, 'I@salt:master', cmd, false)
488 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, 'I@salt:master', '/root/report.xml'))
Tomáš Kukrálc48456a2017-08-21 23:03:37 +0200489 junit(keepLongStdio: true, testResults: 'report.xml')
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200490 }
491 }
492
493
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200494 stage('Finalize') {
495 if (common.checkContains('STACK_INSTALL', 'finalize')) {
chnyda597fb032017-10-06 13:42:48 +0200496 salt.runSaltProcessStep(venvPepper, '*', 'state.apply', [], null, true)
Ales Komarek24097402017-05-22 16:28:10 +0200497 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200498
499 outputsPretty = common.prettify(outputs)
500 print(outputsPretty)
501 writeFile(file: 'outputs.json', text: outputsPretty)
502 archiveArtifacts(artifacts: 'outputs.json')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400503 }
Tomáš Kukrál53224c22017-07-26 10:53:20 +0200504
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400505 } catch (Throwable e) {
506 currentBuild.result = 'FAILURE'
507 throw e
508 } finally {
Ales Komarek24097402017-05-22 16:28:10 +0200509
510
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400511 //
512 // Clean
513 //
Ales Komarek24097402017-05-22 16:28:10 +0200514
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200515 if (common.validInputParam('STACK_NAME')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400516 // send notification
517 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
518 }
519
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200520 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400521 stage('Trigger cleanup job') {
522 common.errorMsg('Stack cleanup job triggered')
523 build(job: STACK_CLEANUP_JOB, parameters: [
524 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
525 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
526 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
527 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
528 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
529 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
530 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
531 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
532 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
533 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
534 ])
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200535 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400536 } else {
537 if (currentBuild.result == 'FAILURE') {
538 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 +0200539
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200540 if (common.validInputParam('SALT_MASTER_URL')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400541 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
Ales Komarek24097402017-05-22 16:28:10 +0200542 }
543 }
544 }
545 }
546}