blob: 6f6e015be1996c86908eff9d1cdc2e2e68ef93a8 [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
41 * Test settings:
42 * TEST_K8S_API_SERVER Kubernetes API address
43 * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
Ales Komarek24097402017-05-22 16:28:10 +020044 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020045 * TEST_DOCKER_INSTALL Install docker on the target if true
46 * TEST_TEMPEST_IMAGE Tempest image link
47 * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only
48 * TEST_TEMPEST_TARGET Salt target for tempest node
Ales Komarek24097402017-05-22 16:28:10 +020049 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020050 * optional parameters for overwriting soft params
51 * SALT_OVERRIDES YAML with overrides for Salt deployment
Ales Komarek24097402017-05-22 16:28:10 +020052 *
53 */
Tomáš Kukrál3a17dd62017-07-27 18:24:16 +020054
Ales Komarek24097402017-05-22 16:28:10 +020055common = new com.mirantis.mk.Common()
56git = new com.mirantis.mk.Git()
57openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020058aws = new com.mirantis.mk.Aws()
Ales Komarek24097402017-05-22 16:28:10 +020059orchestrate = new com.mirantis.mk.Orchestrate()
Mykyta Karpine016d7e2017-10-09 13:35:20 +030060python = new com.mirantis.mk.Python()
Ales Komarek24097402017-05-22 16:28:10 +020061salt = new com.mirantis.mk.Salt()
62test = new com.mirantis.mk.Test()
63
64_MAX_PERMITTED_STACKS = 2
65overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
66
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020067// Define global variables
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020068def venv
chnyda597fb032017-10-06 13:42:48 +020069def venvPepper
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020070def outputs = [:]
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020071
chnydae14058a2017-08-29 15:07:48 +020072def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
73
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020074if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020075 def aws_env_vars
Tomáš Kukrál8427ff52017-08-30 15:46:52 +020076} else if (STACK_TYPE == 'heat') {
77 def envParams
78 def openstackCloud
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020079}
80
Oleh Hryhorov9630a762017-10-24 14:33:25 +030081def slave_node = 'python'
82
Oleh Hryhorov54460512017-10-26 18:45:36 +030083if (common.validInputParam('SLAVE_NODE')) {
Oleh Hryhorov9630a762017-10-24 14:33:25 +030084 slave_node = SLAVE_NODE
85}
86
87node(slave_node) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040088 try {
89 // Set build-specific variables
90 venv = "${env.WORKSPACE}/venv"
chnyda597fb032017-10-06 13:42:48 +020091 venvPepper = "${env.WORKSPACE}/venvPepper"
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020092
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040093 //
94 // Prepare machines
95 //
96 stage ('Create infrastructure') {
Ales Komarek24097402017-05-22 16:28:10 +020097
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020098 outputs.put('stack_type', STACK_TYPE)
99
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400100 if (STACK_TYPE == 'heat') {
101 // value defaults
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200102 envParams = [
103 'cluster_zone': HEAT_STACK_ZONE,
104 'cluster_public_net': HEAT_STACK_PUBLIC_NET
105 ]
Ales Komarek24097402017-05-22 16:28:10 +0200106
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400107 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
108 error("If you want to reuse existing stack you need to provide it's name")
109 }
110
111 if (STACK_REUSE.toBoolean() == false) {
112 // Don't allow to set custom heat stack name
113 wrap([$class: 'BuildUser']) {
114 if (env.BUILD_USER_ID) {
115 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
116 } else {
117 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
118 }
119 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200120 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400121 }
Ales Komarek24097402017-05-22 16:28:10 +0200122
Tomáš Kukrál86b9ab22017-09-05 16:55:58 +0200123 // no underscore in STACK_NAME
124 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Tomáš Kukrál77b1b5a2017-09-24 18:56:49 +0200125 outputs.put('stack_name', STACK_NAME)
Tomáš Kukrál86b9ab22017-09-05 16:55:58 +0200126
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400127 // set description
128 currentBuild.description = "${STACK_NAME}"
129
130 // get templates
131 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
132
133 // create openstack env
134 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
135 openstackCloud = openstack.createOpenstackEnv(
136 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
137 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
138 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
139 OPENSTACK_API_VERSION)
140 openstack.getKeystoneToken(openstackCloud, venv)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200141
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400142 //
143 // Verify possibility of create stack for given user and stack type
144 //
145 wrap([$class: 'BuildUser']) {
146 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
Oleh Hryhorov8e320ca2017-09-22 13:23:44 +0300147 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200148 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400149 STACK_DELETE = "false"
150 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
151 }
152 }
153 }
154 // launch stack
155 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400156
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200157 // set reclass repo in heat env
158 try {
159 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
160 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
161 } catch (MissingPropertyException e) {
162 common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400163 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200164
Mykyta Karpin8f961132017-09-22 12:06:44 +0300165 // put formulas revision - stable, testing or nightly
166 if (common.validInputParam('FORMULA_PKG_REVISION')) {
167 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
168 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
169 }
170
Mykyta Karpin0aa35d52017-08-28 11:44:42 +0300171 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400172 }
173
174 // get SALT_MASTER_URL
175 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
chnydae14058a2017-08-29 15:07:48 +0200176 // check that saltMasterHost is valid
177 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
178 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
179 throw new Exception("saltMasterHost is not a valid ip")
180 }
181
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400182 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
183
184 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
185
186 } else if (STACK_TYPE == 'aws') {
187
188 // setup environment
189 aws.setupVirtualEnv(venv)
190
191 // set aws_env_vars
192 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
193
194 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
195 error("If you want to reuse existing stack you need to provide it's name")
196 }
197
198 if (STACK_REUSE.toBoolean() == false) {
199 // Don't allow to set custom stack name
200 wrap([$class: 'BuildUser']) {
201 if (env.BUILD_USER_ID) {
202 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
203 } else {
204 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
Ales Komarek24097402017-05-22 16:28:10 +0200205 }
206 }
207
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400208 // no underscore in STACK_NAME
209 STACK_NAME = STACK_NAME.replaceAll('_', '-')
210 }
Ales Komarek24097402017-05-22 16:28:10 +0200211
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400212 // set description
213 currentBuild.description = STACK_NAME
Tomáš Kukrál77b1b5a2017-09-24 18:56:49 +0200214 outputs.put('stack_name', STACK_NAME)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400215
216 if (STACK_REUSE.toBoolean() == false) {
Ales Komarek24097402017-05-22 16:28:10 +0200217 // get templates
218 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
219
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400220 // start stack
221 def stack_params = [
222 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
223 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
224 ]
225 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
226 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200227 }
Ales Komarek24097402017-05-22 16:28:10 +0200228
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400229 // wait for stack to be ready
230 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
231
232 // get outputs
233 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200234
chnydae14058a2017-08-29 15:07:48 +0200235 // check that saltMasterHost is valid
236 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
237 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
238 throw new Exception("saltMasterHost is not a valid ip")
239 }
240
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200241 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400242 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
243
244 } else if (STACK_TYPE != 'physical') {
245 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
Ales Komarek24097402017-05-22 16:28:10 +0200246 }
247
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200248 outputs.put('salt_api', SALT_MASTER_URL)
249
chnyda597fb032017-10-06 13:42:48 +0200250 // Setup virtualenv for pepper
251 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400252 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200253
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400254
255 // Set up override params
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200256 if (common.validInputParam('SALT_OVERRIDES')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400257 stage('Set Salt overrides') {
chnyda597fb032017-10-06 13:42:48 +0200258 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES)
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200259 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400260 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200261
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400262 //
263 // Install
264 //
Ales Komarek24097402017-05-22 16:28:10 +0200265
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400266 if (common.checkContains('STACK_INSTALL', 'core')) {
267 stage('Install core infrastructure') {
Jiri Broulik61b3e5d2017-12-19 15:42:30 +0100268 orchestrate.installFoundationInfra(venvPepper, STATIC_MGMT_NETWORK.toBoolean())
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400269
270 if (common.checkContains('STACK_INSTALL', 'kvm')) {
chnyda597fb032017-10-06 13:42:48 +0200271 orchestrate.installInfraKvm(venvPepper)
Jiri Broulik61b3e5d2017-12-19 15:42:30 +0100272 orchestrate.installFoundationInfra(venvPepper, STATIC_MGMT_NETWORK.toBoolean())
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400273 }
Ales Komarek24097402017-05-22 16:28:10 +0200274
chnyda597fb032017-10-06 13:42:48 +0200275 orchestrate.validateFoundationInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400276 }
277 }
Ales Komarek24097402017-05-22 16:28:10 +0200278
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200279 // install ceph
280 if (common.checkContains('STACK_INSTALL', 'ceph')) {
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200281 stage('Install Ceph MONs') {
chnyda597fb032017-10-06 13:42:48 +0200282 orchestrate.installCephMon(venvPepper)
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200283 }
284
285 stage('Install Ceph OSDs') {
chnyda597fb032017-10-06 13:42:48 +0200286 orchestrate.installCephOsd(venvPepper)
Tomáš Kukrál7b949ea2017-08-19 10:08:39 +0200287 }
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200288
Tomáš Kukrál0cc01092017-08-28 18:25:00 +0200289
290 stage('Install Ceph clients') {
chnyda597fb032017-10-06 13:42:48 +0200291 orchestrate.installCephClient(venvPepper)
Tomáš Kukrála77caa92017-08-25 18:19:52 +0200292 }
Jiri Broulik8c380032017-10-06 13:36:03 +0200293
294 stage('Connect Ceph') {
chnyda625f4b42017-10-11 14:10:31 +0200295 orchestrate.connectCeph(venvPepper)
Jiri Broulik8c380032017-10-06 13:36:03 +0200296 }
Tomáš Kukrálb6777fa2017-08-11 10:36:30 +0200297 }
298
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400299 // install k8s
300 if (common.checkContains('STACK_INSTALL', 'k8s')) {
301
302 stage('Install Kubernetes infra') {
303 if (STACK_TYPE == 'aws') {
304 // configure kubernetes_control_address - save loadbalancer
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200305 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
Tomáš Kukrál685f3b82017-09-03 10:14:40 +0200306 common.prettyPrint(awsOutputs)
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200307 if (awsOutputs.containsKey('ControlLoadBalancer')) {
chnyda597fb032017-10-06 13:42:48 +0200308 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 +0200309 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
310 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400311 }
312
313 // ensure certificates are generated properly
chnyda597fb032017-10-06 13:42:48 +0200314 salt.runSaltProcessStep(venvPepper, '*', 'saltutil.refresh_pillar', [], null, true)
315 salt.enforceState(venvPepper, '*', ['salt.minion.cert'], true)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400316
chnyda597fb032017-10-06 13:42:48 +0200317 orchestrate.installKubernetesInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400318 }
319
320 if (common.checkContains('STACK_INSTALL', 'contrail')) {
321 stage('Install Contrail for Kubernetes') {
chnyda597fb032017-10-06 13:42:48 +0200322 orchestrate.installContrailNetwork(venvPepper)
323 orchestrate.installContrailCompute(venvPepper)
Ales Komarek24097402017-05-22 16:28:10 +0200324 }
325 }
326
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400327 stage('Install Kubernetes control') {
chnyda597fb032017-10-06 13:42:48 +0200328 orchestrate.installKubernetesControl(venvPepper)
Tomáš Kukrál7e487062017-08-31 11:20:08 +0200329
330 // collect artifacts (kubeconfig)
chnyda597fb032017-10-06 13:42:48 +0200331 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 +0200332 archiveArtifacts(artifacts: 'kubeconfig')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400333 }
334
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100335 stage('Install Kubernetes computes') {
336 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
337 if (STACK_COMPUTE_COUNT > 0) {
338 if (STACK_TYPE == 'aws') {
339 // get stack info
340 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400341
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100342 //update autoscaling group
343 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400344
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100345 // wait for computes to boot up
346 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
347 sleep(60)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200348
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100349 } else if (STACK_TYPE == 'heat') {
350 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
Tomáš Kukrál8427ff52017-08-30 15:46:52 +0200351
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100352 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
353 sleep(60)
354 }
355
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200356 }
Ales Komarek24097402017-05-22 16:28:10 +0200357 }
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100358
359 orchestrate.installKubernetesCompute(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400360 }
361 }
362
363 // install openstack
364 if (common.checkContains('STACK_INSTALL', 'openstack')) {
365 // install Infra and control, tests, ...
366
367 stage('Install OpenStack infra') {
chnyda597fb032017-10-06 13:42:48 +0200368 orchestrate.installOpenstackInfra(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400369 }
370
371 stage('Install OpenStack control') {
chnyda597fb032017-10-06 13:42:48 +0200372 orchestrate.installOpenstackControl(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400373 }
374
375 stage('Install OpenStack network') {
Ales Komarek24097402017-05-22 16:28:10 +0200376
vrovachev7be1e962017-07-05 13:28:26 +0400377 if (common.checkContains('STACK_INSTALL', 'contrail')) {
chnyda597fb032017-10-06 13:42:48 +0200378 orchestrate.installContrailNetwork(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400379 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
chnyda597fb032017-10-06 13:42:48 +0200380 orchestrate.installOpenstackNetwork(venvPepper)
vrovachev7be1e962017-07-05 13:28:26 +0400381 }
382
chnyda597fb032017-10-06 13:42:48 +0200383 salt.runSaltProcessStep(venvPepper, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
384 salt.runSaltProcessStep(venvPepper, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400385 }
Ales Komarek24097402017-05-22 16:28:10 +0200386
chnyda597fb032017-10-06 13:42:48 +0200387 if (salt.testTarget(venvPepper, 'I@ironic:conductor')){
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400388 stage('Install OpenStack Ironic conductor') {
chnyda597fb032017-10-06 13:42:48 +0200389 orchestrate.installIronicConductor(venvPepper)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200390 }
Ales Komarek24097402017-05-22 16:28:10 +0200391 }
392
Ales Komarek24097402017-05-22 16:28:10 +0200393
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400394 stage('Install OpenStack compute') {
chnyda597fb032017-10-06 13:42:48 +0200395 orchestrate.installOpenstackCompute(venvPepper)
Ales Komarek24097402017-05-22 16:28:10 +0200396
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400397 if (common.checkContains('STACK_INSTALL', 'contrail')) {
chnyda597fb032017-10-06 13:42:48 +0200398 orchestrate.installContrailCompute(venvPepper)
Martin Polreich46971102017-07-11 12:56:40 +0200399 }
400 }
401
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400402 }
403
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400404 if (common.checkContains('STACK_INSTALL', 'oss')) {
405 stage('Install Oss infra') {
406 orchestrate.installOssInfra(venvPepper)
407 }
408 }
409
Jiri Broulikb27b4832017-09-05 16:41:03 +0200410 if (common.checkContains('STACK_INSTALL', 'cicd')) {
411 stage('Install Cicd') {
Vladimir Jigulinff3567c2017-12-11 15:31:11 +0400412 orchestrate.installInfra(venvPepper)
chnyda597fb032017-10-06 13:42:48 +0200413 orchestrate.installDockerSwarm(venvPepper)
414 orchestrate.installCicd(venvPepper)
Jiri Broulikb27b4832017-09-05 16:41:03 +0200415 }
416 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400417
418 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
419 stage('Install StackLight v1') {
chnyda597fb032017-10-06 13:42:48 +0200420 orchestrate.installStacklightv1Control(venvPepper)
421 orchestrate.installStacklightv1Client(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400422 }
423 }
424
425 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
426 stage('Install StackLight') {
chnyda597fb032017-10-06 13:42:48 +0200427 orchestrate.installDockerSwarm(venvPepper)
428 orchestrate.installStacklight(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400429 }
430 }
431
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400432 if (common.checkContains('STACK_INSTALL', 'oss')) {
433 stage('Install OSS') {
434 if (!common.checkContains('STACK_INSTALL', 'stacklight')) {
435 // In case if StackLightv2 enabled containers already started
436 orchestrate.installDockerSwarm(venvPepper)
437 salt.enforceState(venvPepper, 'I@docker:swarm:role:master and I@devops_portal:config', 'docker.client', true)
438 }
439 orchestrate.installOss(venvPepper)
440 }
441 }
442
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400443 //
444 // Test
445 //
446 def artifacts_dir = '_artifacts/'
447
448 if (common.checkContains('STACK_TEST', 'k8s')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400449 stage('Run k8s conformance e2e tests') {
Anna Babich12dd5b12017-08-21 18:01:35 +0300450 def image = TEST_K8S_CONFORMANCE_IMAGE
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400451 def output_file = image.replaceAll('/', '-') + '.output'
Ales Komarek24097402017-05-22 16:28:10 +0200452
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400453 // run image
chnyda597fb032017-10-06 13:42:48 +0200454 test.runConformanceTests(venvPepper, 'ctl01*', TEST_K8S_API_SERVER, image)
Ales Komarek24097402017-05-22 16:28:10 +0200455
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400456 // collect output
457 sh "mkdir -p ${artifacts_dir}"
chnyda597fb032017-10-06 13:42:48 +0200458 file_content = salt.getFileContent(venvPepper, 'ctl01*', '/tmp/' + output_file)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400459 writeFile file: "${artifacts_dir}${output_file}", text: file_content
460 sh "cat ${artifacts_dir}${output_file}"
Ales Komarek24097402017-05-22 16:28:10 +0200461
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400462 // collect artifacts
463 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
464 }
465 }
Ales Komarek24097402017-05-22 16:28:10 +0200466
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400467 if (common.checkContains('STACK_TEST', 'openstack')) {
468 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
chnyda597fb032017-10-06 13:42:48 +0200469 test.install_docker(venvPepper, TEST_TEMPEST_TARGET)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400470 }
471 stage('Run OpenStack tests') {
chnyda597fb032017-10-06 13:42:48 +0200472 test.runTempestTests(venvPepper, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
Ales Komarek24097402017-05-22 16:28:10 +0200473 }
474
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400475 stage('Copy Tempest results to config node') {
chnyda597fb032017-10-06 13:42:48 +0200476 test.copyTempestResults(venvPepper, TEST_TEMPEST_TARGET)
Ales Komarek24097402017-05-22 16:28:10 +0200477 }
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300478
479 stage('Archive rally artifacts') {
chnyda597fb032017-10-06 13:42:48 +0200480 test.archiveRallyArtifacts(venvPepper, TEST_TEMPEST_TARGET)
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300481 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400482 }
Ales Komarek24097402017-05-22 16:28:10 +0200483
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200484
485 if (common.checkContains('STACK_TEST', 'ceph')) {
Tomáš Kukrálf5798082017-08-21 22:37:41 +0200486 stage('Run infra tests') {
Tomáš Kukrál36d43972017-08-30 12:43:17 +0200487 sleep(120)
Tomáš Kukrál07ad0c92017-08-21 23:19:40 +0200488 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 +0200489 salt.cmdRun(venvPepper, 'I@salt:master', cmd, false)
490 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, 'I@salt:master', '/root/report.xml'))
Tomáš Kukrálc48456a2017-08-21 23:03:37 +0200491 junit(keepLongStdio: true, testResults: 'report.xml')
Tomáš Kukrál4b6b4d32017-08-21 20:29:21 +0200492 }
493 }
494
495
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200496 stage('Finalize') {
497 if (common.checkContains('STACK_INSTALL', 'finalize')) {
chnyda597fb032017-10-06 13:42:48 +0200498 salt.runSaltProcessStep(venvPepper, '*', 'state.apply', [], null, true)
Ales Komarek24097402017-05-22 16:28:10 +0200499 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200500
501 outputsPretty = common.prettify(outputs)
502 print(outputsPretty)
503 writeFile(file: 'outputs.json', text: outputsPretty)
504 archiveArtifacts(artifacts: 'outputs.json')
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400505 }
Tomáš Kukrál53224c22017-07-26 10:53:20 +0200506
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400507 } catch (Throwable e) {
508 currentBuild.result = 'FAILURE'
509 throw e
510 } finally {
Ales Komarek24097402017-05-22 16:28:10 +0200511
512
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400513 //
514 // Clean
515 //
Ales Komarek24097402017-05-22 16:28:10 +0200516
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200517 if (common.validInputParam('STACK_NAME')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400518 // send notification
519 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
520 }
521
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200522 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400523 stage('Trigger cleanup job') {
524 common.errorMsg('Stack cleanup job triggered')
525 build(job: STACK_CLEANUP_JOB, parameters: [
526 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
527 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
528 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
529 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
530 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
531 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
532 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
533 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
534 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
535 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
536 ])
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200537 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400538 } else {
539 if (currentBuild.result == 'FAILURE') {
540 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 +0200541
Jakub Josefeb15f0b2017-08-03 18:22:06 +0200542 if (common.validInputParam('SALT_MASTER_URL')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400543 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
Ales Komarek24097402017-05-22 16:28:10 +0200544 }
545 }
546 }
547 }
548}