blob: d051b30dc27e67822fb611b81fe5e184128d349a [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
Jiri Broulik61b3e5d2017-12-19 15:42:30 +010021 * STATIC_MGMT_NETWORK Check if model contains static IP address definitions for all nodes
Tomáš Kukrál74f92862017-06-05 19:18:43 +020022 *
Ales Komarek24097402017-05-22 16:28:10 +020023 * AWS_STACK_REGION CloudFormation AWS region
24 * AWS_API_CREDENTIALS AWS Access key ID with AWS secret access key
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020025 * AWS_SSH_KEY AWS key pair name (used for SSH access)
Ales Komarek24097402017-05-22 16:28:10 +020026 *
27 * HEAT_STACK_ENVIRONMENT Heat stack environmental parameters
28 * HEAT_STACK_ZONE Heat stack availability zone
29 * HEAT_STACK_PUBLIC_NET Heat stack floating IP pool
30 * OPENSTACK_API_URL OpenStack API address
31 * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
32 * OPENSTACK_API_PROJECT OpenStack project to connect to
33 * OPENSTACK_API_CLIENT Versions of OpenStack python clients
34 * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
Oleh Hryhorov9630a762017-10-24 14:33:25 +030035 * SLAVE_NODE Lable or node name where the job will be run
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020036
Ales Komarek24097402017-05-22 16:28:10 +020037 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
Tomáš Kukrál4691f682017-07-27 16:36:12 +020038 * required for STACK_TYPE=physical
Ales Komarek24097402017-05-22 16:28:10 +020039 * SALT_MASTER_URL URL of Salt master
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020040
Oleg Iurchenko9a8c3d72017-12-21 14:55:38 +020041 * BOOTSTRAP_EXTRA_REPO_PARAMS optional parameter to define a list of extra repos with parameters
42 * which have to be added during bootstrap.
43 * Format: repo 1, repo priority 1, repo pin 1; repo 2, repo priority 2, repo pin 2;
44
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020045 * Test settings:
46 * TEST_K8S_API_SERVER Kubernetes API address
47 * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
Ales Komarek24097402017-05-22 16:28:10 +020048 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020049 * TEST_DOCKER_INSTALL Install docker on the target if true
50 * TEST_TEMPEST_IMAGE Tempest image link
51 * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only
52 * TEST_TEMPEST_TARGET Salt target for tempest node
Ales Komarek24097402017-05-22 16:28:10 +020053 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020054 * optional parameters for overwriting soft params
55 * SALT_OVERRIDES YAML with overrides for Salt deployment
Ales Komarek24097402017-05-22 16:28:10 +020056 *
57 */
Tomáš Kukrál3a17dd62017-07-27 18:24:16 +020058
Ales Komarek24097402017-05-22 16:28:10 +020059common = new com.mirantis.mk.Common()
60git = new com.mirantis.mk.Git()
61openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020062aws = new com.mirantis.mk.Aws()
Ales Komarek24097402017-05-22 16:28:10 +020063orchestrate = new com.mirantis.mk.Orchestrate()
Mykyta Karpine016d7e2017-10-09 13:35:20 +030064python = new com.mirantis.mk.Python()
Ales Komarek24097402017-05-22 16:28:10 +020065salt = new com.mirantis.mk.Salt()
66test = new com.mirantis.mk.Test()
67
68_MAX_PERMITTED_STACKS = 2
69overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
70
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020071// Define global variables
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020072def venv
chnyda597fb032017-10-06 13:42:48 +020073def venvPepper
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020074def outputs = [:]
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020075
chnydae14058a2017-08-29 15:07:48 +020076def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
77
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020078if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020079 def aws_env_vars
Tomáš Kukrál8427ff52017-08-30 15:46:52 +020080} else if (STACK_TYPE == 'heat') {
81 def envParams
82 def openstackCloud
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020083}
84
Oleh Hryhorov9630a762017-10-24 14:33:25 +030085def slave_node = 'python'
86
Oleh Hryhorov54460512017-10-26 18:45:36 +030087if (common.validInputParam('SLAVE_NODE')) {
Oleh Hryhorov9630a762017-10-24 14:33:25 +030088 slave_node = SLAVE_NODE
89}
90
91node(slave_node) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040092 try {
93 // Set build-specific variables
94 venv = "${env.WORKSPACE}/venv"
chnyda597fb032017-10-06 13:42:48 +020095 venvPepper = "${env.WORKSPACE}/venvPepper"
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020096
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040097 //
98 // Prepare machines
99 //
100 stage ('Create infrastructure') {
Ales Komarek24097402017-05-22 16:28:10 +0200101
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200102 outputs.put('stack_type', STACK_TYPE)
103
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400104 if (STACK_TYPE == 'heat') {
105 // value defaults
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200106 envParams = [
107 'cluster_zone': HEAT_STACK_ZONE,
108 'cluster_public_net': HEAT_STACK_PUBLIC_NET
109 ]
Ales Komarek24097402017-05-22 16:28:10 +0200110
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400111 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
112 error("If you want to reuse existing stack you need to provide it's name")
113 }
114
115 if (STACK_REUSE.toBoolean() == false) {
116 // Don't allow to set custom heat stack name
117 wrap([$class: 'BuildUser']) {
118 if (env.BUILD_USER_ID) {
119 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
120 } else {
121 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
122 }
123 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200124 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400125 }
Ales Komarek24097402017-05-22 16:28:10 +0200126
Tomáš Kukrál86b9ab22017-09-05 16:55:58 +0200127 // no underscore in STACK_NAME
128 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Tomáš Kukrál77b1b5a2017-09-24 18:56:49 +0200129 outputs.put('stack_name', STACK_NAME)
Tomáš Kukrál86b9ab22017-09-05 16:55:58 +0200130
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400131 // set description
132 currentBuild.description = "${STACK_NAME}"
133
134 // get templates
135 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
136
137 // create openstack env
138 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
139 openstackCloud = openstack.createOpenstackEnv(
140 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
141 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
142 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
143 OPENSTACK_API_VERSION)
144 openstack.getKeystoneToken(openstackCloud, venv)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200145
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400146 //
147 // Verify possibility of create stack for given user and stack type
148 //
149 wrap([$class: 'BuildUser']) {
150 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
Oleh Hryhorov8e320ca2017-09-22 13:23:44 +0300151 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200152 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400153 STACK_DELETE = "false"
154 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
155 }
156 }
157 }
158 // launch stack
159 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400160
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200161 // set reclass repo in heat env
162 try {
163 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
164 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
165 } catch (MissingPropertyException e) {
166 common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400167 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200168
Mykyta Karpin8f961132017-09-22 12:06:44 +0300169 // put formulas revision - stable, testing or nightly
170 if (common.validInputParam('FORMULA_PKG_REVISION')) {
171 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
172 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
173 }
174
Oleg Iurchenko9a8c3d72017-12-21 14:55:38 +0200175 // put extra repo definitions
176 if (common.validInputParam('BOOTSTRAP_EXTRA_REPO_PARAMS')) {
177 common.infoMsg("Setting additional repo during bootstrap to ${BOOTSTRAP_EXTRA_REPO_PARAMS}")
178 envParams.put('cfg_bootstrap_extra_repo_params', BOOTSTRAP_EXTRA_REPO_PARAMS)
179 }
180
Mykyta Karpin0aa35d52017-08-28 11:44:42 +0300181 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400182 }
183
184 // get SALT_MASTER_URL
185 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
chnydae14058a2017-08-29 15:07:48 +0200186 // check that saltMasterHost is valid
187 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
188 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
189 throw new Exception("saltMasterHost is not a valid ip")
190 }
191
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400192 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
193
194 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
195
196 } else if (STACK_TYPE == 'aws') {
197
198 // setup environment
199 aws.setupVirtualEnv(venv)
200
201 // set aws_env_vars
202 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
203
204 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
205 error("If you want to reuse existing stack you need to provide it's name")
206 }
207
208 if (STACK_REUSE.toBoolean() == false) {
209 // Don't allow to set custom stack name
210 wrap([$class: 'BuildUser']) {
211 if (env.BUILD_USER_ID) {
212 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
213 } else {
214 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
Ales Komarek24097402017-05-22 16:28:10 +0200215 }
216 }
217
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400218 // no underscore in STACK_NAME
219 STACK_NAME = STACK_NAME.replaceAll('_', '-')
220 }
Ales Komarek24097402017-05-22 16:28:10 +0200221
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400222 // set description
223 currentBuild.description = STACK_NAME
Tomáš Kukrál77b1b5a2017-09-24 18:56:49 +0200224 outputs.put('stack_name', STACK_NAME)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400225
226 if (STACK_REUSE.toBoolean() == false) {
Ales Komarek24097402017-05-22 16:28:10 +0200227 // get templates
228 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
229
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400230 // start stack
231 def stack_params = [
232 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
233 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
234 ]
235 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
236 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200237 }
Ales Komarek24097402017-05-22 16:28:10 +0200238
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400239 // wait for stack to be ready
240 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
241
242 // get outputs
243 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200244
chnydae14058a2017-08-29 15:07:48 +0200245 // check that saltMasterHost is valid
246 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
247 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
248 throw new Exception("saltMasterHost is not a valid ip")
249 }
250
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200251 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400252 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
253
254 } else if (STACK_TYPE != 'physical') {
255 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
Ales Komarek24097402017-05-22 16:28:10 +0200256 }
257
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200258 outputs.put('salt_api', SALT_MASTER_URL)
259
chnyda597fb032017-10-06 13:42:48 +0200260 // Setup virtualenv for pepper
261 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400262 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200263
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400264
265 // Set up override params
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200266 if (common.validInputParam('SALT_OVERRIDES')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400267 stage('Set Salt overrides') {
chnyda597fb032017-10-06 13:42:48 +0200268 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES)
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200269 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400270 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200271
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400272 //
273 // Install
274 //
Ales Komarek24097402017-05-22 16:28:10 +0200275
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400276 if (common.checkContains('STACK_INSTALL', 'core')) {
277 stage('Install core infrastructure') {
Oleg Iurchenko2f234c22017-12-20 12:48:55 +0200278 def staticMgmtNetwork = false
279 if (common.validInputParam('STATIC_MGMT_NETWORK')) {
280 staticMgmtNetwork = STATIC_MGMT_NETWORK.toBoolean()
281 }
282 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400283
284 if (common.checkContains('STACK_INSTALL', 'kvm')) {
chnyda597fb032017-10-06 13:42:48 +0200285 orchestrate.installInfraKvm(venvPepper)
Oleg Iurchenko2f234c22017-12-20 12:48:55 +0200286 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400287 }
Ales Komarek24097402017-05-22 16:28:10 +0200288
chnyda597fb032017-10-06 13:42:48 +0200289 orchestrate.validateFoundationInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400290 }
291 }
Ales Komarek24097402017-05-22 16:28:10 +0200292
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200293 // install ceph
294 if (common.checkContains('STACK_INSTALL', 'ceph')) {
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200295 stage('Install Ceph MONs') {
chnyda597fb032017-10-06 13:42:48 +0200296 orchestrate.installCephMon(venvPepper)
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200297 }
298
299 stage('Install Ceph OSDs') {
chnyda597fb032017-10-06 13:42:48 +0200300 orchestrate.installCephOsd(venvPepper)
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200301 }
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200302
Tomáš Kukrál0cc01092017-08-28 18:25:00 +0200303
304 stage('Install Ceph clients') {
chnyda597fb032017-10-06 13:42:48 +0200305 orchestrate.installCephClient(venvPepper)
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200306 }
Jiri Broulik8c380032017-10-06 13:36:03 +0200307
308 stage('Connect Ceph') {
chnyda625f4b42017-10-11 14:10:31 +0200309 orchestrate.connectCeph(venvPepper)
Jiri Broulik8c380032017-10-06 13:36:03 +0200310 }
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200311 }
312
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400313 // install k8s
314 if (common.checkContains('STACK_INSTALL', 'k8s')) {
315
316 stage('Install Kubernetes infra') {
317 if (STACK_TYPE == 'aws') {
318 // configure kubernetes_control_address - save loadbalancer
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200319 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
Tomáš Kukrál685f3b82017-09-03 10:14:40 +0200320 common.prettyPrint(awsOutputs)
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200321 if (awsOutputs.containsKey('ControlLoadBalancer')) {
chnyda597fb032017-10-06 13:42:48 +0200322 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 +0200323 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
324 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400325 }
326
327 // ensure certificates are generated properly
chnyda597fb032017-10-06 13:42:48 +0200328 salt.runSaltProcessStep(venvPepper, '*', 'saltutil.refresh_pillar', [], null, true)
329 salt.enforceState(venvPepper, '*', ['salt.minion.cert'], true)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400330
chnyda597fb032017-10-06 13:42:48 +0200331 orchestrate.installKubernetesInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400332 }
333
334 if (common.checkContains('STACK_INSTALL', 'contrail')) {
335 stage('Install Contrail for Kubernetes') {
chnyda597fb032017-10-06 13:42:48 +0200336 orchestrate.installContrailNetwork(venvPepper)
337 orchestrate.installContrailCompute(venvPepper)
Ales Komarek24097402017-05-22 16:28:10 +0200338 }
339 }
340
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400341 stage('Install Kubernetes control') {
chnyda597fb032017-10-06 13:42:48 +0200342 orchestrate.installKubernetesControl(venvPepper)
Tomáš Kukrál7e487062017-08-31 11:20:08 +0200343
344 // collect artifacts (kubeconfig)
chnyda597fb032017-10-06 13:42:48 +0200345 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 +0200346 archiveArtifacts(artifacts: 'kubeconfig')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400347 }
348
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100349 stage('Install Kubernetes computes') {
350 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
351 if (STACK_COMPUTE_COUNT > 0) {
352 if (STACK_TYPE == 'aws') {
353 // get stack info
354 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400355
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100356 //update autoscaling group
357 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400358
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100359 // wait for computes to boot up
360 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
361 sleep(60)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200362
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100363 } else if (STACK_TYPE == 'heat') {
364 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200365
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100366 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
367 sleep(60)
368 }
369
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200370 }
Ales Komarek24097402017-05-22 16:28:10 +0200371 }
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100372
373 orchestrate.installKubernetesCompute(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400374 }
375 }
376
377 // install openstack
378 if (common.checkContains('STACK_INSTALL', 'openstack')) {
379 // install Infra and control, tests, ...
380
381 stage('Install OpenStack infra') {
chnyda597fb032017-10-06 13:42:48 +0200382 orchestrate.installOpenstackInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400383 }
384
385 stage('Install OpenStack control') {
chnyda597fb032017-10-06 13:42:48 +0200386 orchestrate.installOpenstackControl(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400387 }
388
389 stage('Install OpenStack network') {
Ales Komarek24097402017-05-22 16:28:10 +0200390
vrovachev7be1e962017-07-05 13:28:26 +0400391 if (common.checkContains('STACK_INSTALL', 'contrail')) {
chnyda597fb032017-10-06 13:42:48 +0200392 orchestrate.installContrailNetwork(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400393 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
chnyda597fb032017-10-06 13:42:48 +0200394 orchestrate.installOpenstackNetwork(venvPepper)
vrovachev7be1e962017-07-05 13:28:26 +0400395 }
396
chnyda597fb032017-10-06 13:42:48 +0200397 salt.runSaltProcessStep(venvPepper, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
398 salt.runSaltProcessStep(venvPepper, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400399 }
Ales Komarek24097402017-05-22 16:28:10 +0200400
chnyda597fb032017-10-06 13:42:48 +0200401 if (salt.testTarget(venvPepper, 'I@ironic:conductor')){
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400402 stage('Install OpenStack Ironic conductor') {
chnyda597fb032017-10-06 13:42:48 +0200403 orchestrate.installIronicConductor(venvPepper)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200404 }
Ales Komarek24097402017-05-22 16:28:10 +0200405 }
406
Ales Komarek24097402017-05-22 16:28:10 +0200407
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400408 stage('Install OpenStack compute') {
chnyda597fb032017-10-06 13:42:48 +0200409 orchestrate.installOpenstackCompute(venvPepper)
Ales Komarek24097402017-05-22 16:28:10 +0200410
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400411 if (common.checkContains('STACK_INSTALL', 'contrail')) {
chnyda597fb032017-10-06 13:42:48 +0200412 orchestrate.installContrailCompute(venvPepper)
Martin Polreich46971102017-07-11 12:56:40 +0200413 }
414 }
415
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400416 }
417
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400418 if (common.checkContains('STACK_INSTALL', 'oss')) {
419 stage('Install Oss infra') {
420 orchestrate.installOssInfra(venvPepper)
421 }
422 }
423
Jiri Broulikb27b4832017-09-05 16:41:03 +0200424 if (common.checkContains('STACK_INSTALL', 'cicd')) {
425 stage('Install Cicd') {
Vladimir Jigulinff3567c2017-12-11 15:31:11 +0400426 orchestrate.installInfra(venvPepper)
chnyda597fb032017-10-06 13:42:48 +0200427 orchestrate.installDockerSwarm(venvPepper)
428 orchestrate.installCicd(venvPepper)
Jiri Broulikb27b4832017-09-05 16:41:03 +0200429 }
430 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400431
432 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
433 stage('Install StackLight v1') {
chnyda597fb032017-10-06 13:42:48 +0200434 orchestrate.installStacklightv1Control(venvPepper)
435 orchestrate.installStacklightv1Client(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400436 }
437 }
438
439 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
440 stage('Install StackLight') {
chnyda597fb032017-10-06 13:42:48 +0200441 orchestrate.installDockerSwarm(venvPepper)
442 orchestrate.installStacklight(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400443 }
444 }
445
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400446 if (common.checkContains('STACK_INSTALL', 'oss')) {
447 stage('Install OSS') {
448 if (!common.checkContains('STACK_INSTALL', 'stacklight')) {
449 // In case if StackLightv2 enabled containers already started
450 orchestrate.installDockerSwarm(venvPepper)
451 salt.enforceState(venvPepper, 'I@docker:swarm:role:master and I@devops_portal:config', 'docker.client', true)
452 }
453 orchestrate.installOss(venvPepper)
454 }
455 }
456
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400457 //
458 // Test
459 //
460 def artifacts_dir = '_artifacts/'
461
462 if (common.checkContains('STACK_TEST', 'k8s')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400463 stage('Run k8s conformance e2e tests') {
Anna Babich12dd5b12017-08-21 18:01:35 +0300464 def image = TEST_K8S_CONFORMANCE_IMAGE
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400465 def output_file = image.replaceAll('/', '-') + '.output'
Ales Komarek24097402017-05-22 16:28:10 +0200466
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400467 // run image
chnyda597fb032017-10-06 13:42:48 +0200468 test.runConformanceTests(venvPepper, 'ctl01*', TEST_K8S_API_SERVER, image)
Ales Komarek24097402017-05-22 16:28:10 +0200469
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400470 // collect output
471 sh "mkdir -p ${artifacts_dir}"
chnyda597fb032017-10-06 13:42:48 +0200472 file_content = salt.getFileContent(venvPepper, 'ctl01*', '/tmp/' + output_file)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400473 writeFile file: "${artifacts_dir}${output_file}", text: file_content
474 sh "cat ${artifacts_dir}${output_file}"
Ales Komarek24097402017-05-22 16:28:10 +0200475
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400476 // collect artifacts
477 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
478 }
479 }
Ales Komarek24097402017-05-22 16:28:10 +0200480
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400481 if (common.checkContains('STACK_TEST', 'openstack')) {
482 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
chnyda597fb032017-10-06 13:42:48 +0200483 test.install_docker(venvPepper, TEST_TEMPEST_TARGET)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400484 }
485 stage('Run OpenStack tests') {
chnyda597fb032017-10-06 13:42:48 +0200486 test.runTempestTests(venvPepper, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
Ales Komarek24097402017-05-22 16:28:10 +0200487 }
488
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400489 stage('Copy Tempest results to config node') {
chnyda597fb032017-10-06 13:42:48 +0200490 test.copyTempestResults(venvPepper, TEST_TEMPEST_TARGET)
Ales Komarek24097402017-05-22 16:28:10 +0200491 }
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300492
493 stage('Archive rally artifacts') {
chnyda597fb032017-10-06 13:42:48 +0200494 test.archiveRallyArtifacts(venvPepper, TEST_TEMPEST_TARGET)
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300495 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400496 }
Ales Komarek24097402017-05-22 16:28:10 +0200497
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200498
499 if (common.checkContains('STACK_TEST', 'ceph')) {
Tomáš Kukrálf5798082017-08-21 22:37:41 +0200500 stage('Run infra tests') {
Tomáš Kukrál36d43972017-08-30 12:43:17 +0200501 sleep(120)
Tomáš Kukrál07ad0c92017-08-21 23:19:40 +0200502 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 +0200503 salt.cmdRun(venvPepper, 'I@salt:master', cmd, false)
504 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, 'I@salt:master', '/root/report.xml'))
Tomáš Kukrálc48456a2017-08-21 23:03:37 +0200505 junit(keepLongStdio: true, testResults: 'report.xml')
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200506 }
507 }
508
509
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200510 stage('Finalize') {
511 if (common.checkContains('STACK_INSTALL', 'finalize')) {
chnyda597fb032017-10-06 13:42:48 +0200512 salt.runSaltProcessStep(venvPepper, '*', 'state.apply', [], null, true)
Ales Komarek24097402017-05-22 16:28:10 +0200513 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200514
515 outputsPretty = common.prettify(outputs)
516 print(outputsPretty)
517 writeFile(file: 'outputs.json', text: outputsPretty)
518 archiveArtifacts(artifacts: 'outputs.json')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400519 }
Tomáš Kukrál53224c22017-07-26 10:53:20 +0200520
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400521 } catch (Throwable e) {
522 currentBuild.result = 'FAILURE'
523 throw e
524 } finally {
Ales Komarek24097402017-05-22 16:28:10 +0200525
526
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400527 //
528 // Clean
529 //
Ales Komarek24097402017-05-22 16:28:10 +0200530
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200531 if (common.validInputParam('STACK_NAME')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400532 // send notification
533 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
534 }
535
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200536 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400537 stage('Trigger cleanup job') {
538 common.errorMsg('Stack cleanup job triggered')
539 build(job: STACK_CLEANUP_JOB, parameters: [
540 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
541 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
542 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
543 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
544 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
545 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
546 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
547 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
548 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
549 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
550 ])
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200551 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400552 } else {
553 if (currentBuild.result == 'FAILURE') {
554 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 +0200555
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200556 if (common.validInputParam('SALT_MASTER_URL')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400557 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
Ales Komarek24097402017-05-22 16:28:10 +0200558 }
559 }
560 }
561 }
562}