blob: 5a26ba55014f256b8436a956be75347f08d8bb99 [file] [log] [blame]
Tomáš Kukrálb9957b32017-02-28 14:49:00 +01001/**
2 *
3 * Launch heat stack with basic k8s
4 * Flow parameters:
5 * STACK_TYPE Orchestration engine: heat, ''
6 * INSTALL What should be installed (k8s, openstack, ...)
Tomáš Kukrál55357d02017-02-28 22:56:45 +01007 * TEST What should be tested (k8s, openstack, ...)
Tomáš Kukrálb9957b32017-02-28 14:49:00 +01008 *
9 * Expected parameters:
10 *
11 * required for STACK_TYPE=heat
12 * HEAT_TEMPLATE_URL URL to git repo with Heat templates
13 * HEAT_TEMPLATE_CREDENTIALS Credentials to the Heat templates repo
14 * HEAT_TEMPLATE_BRANCH Heat templates repo branch
15 * HEAT_STACK_TEMPLATE Heat stack HOT template
16 * HEAT_STACK_ENVIRONMENT Heat stack environmental parameters
17 * HEAT_STACK_ZONE Heat stack availability zone
18 * HEAT_STACK_PUBLIC_NET Heat stack floating IP pool
19 * HEAT_STACK_DELETE Delete Heat stack when finished (bool)
20 * HEAT_STACK_CLEANUP_JOB Name of job for deleting Heat stack
21 * HEAT_STACK_REUSE Reuse Heat stack (don't create one)
22 * OPENSTACK_API_URL OpenStack API address
23 * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
24 * OPENSTACK_API_PROJECT OpenStack project to connect to
25 * OPENSTACK_API_CLIENT Versions of OpenStack python clients
26 * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
27 *
28 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
29 *
30 * required for STACK_TYPE=NONE or empty string
31 * SALT_MASTER_URL URL of Salt-API
32
33 * K8S_API_SERVER Kubernetes API address
34 * K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
35 *
Victor Ryzhenkin5f3b7e62017-03-09 16:02:58 +040036 * TEMPEST_IMAGE_LINK Tempest image link
37 *
Matthew Mosesohna85f24e2017-04-28 13:45:19 +030038 * optional parameters for overwriting soft params
39 * KUBERNETES_HYPERKUBE_IMAGE Docker repository and tag for hyperkube image
40 *
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010041 */
42
Tomáš Kukrál1f8b5012017-04-28 21:07:10 +020043common = new com.mirantis.mk.Common()
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010044git = new com.mirantis.mk.Git()
45openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál1f8b5012017-04-28 21:07:10 +020046orchestrate = new com.mirantis.mk.Orchestrate()
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010047salt = new com.mirantis.mk.Salt()
Ondrej Smola8f35e482017-03-30 14:04:36 +020048test = new com.mirantis.mk.Test()
Tomáš Kukrál1f8b5012017-04-28 21:07:10 +020049
Matthew Mosesohna85f24e2017-04-28 13:45:19 +030050overwriteFile = "/srv/salt/reclass/classes/cluster/overwrite.yml"
Tomáš Kukrále80680a2017-03-02 16:34:35 +010051
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +010052timestamps {
53 node {
Tomáš Kukrála18de112017-03-02 13:57:47 +010054 try {
55 //
56 // Prepare machines
57 //
Tomáš Kukrála18de112017-03-02 13:57:47 +010058 stage ('Create infrastructure') {
Tomáš Kukrál6d627d62017-03-23 17:39:07 +010059
Tomáš Kukrála18de112017-03-02 13:57:47 +010060 if (STACK_TYPE == 'heat') {
61 // value defaults
62 def openstackCloud
63 def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty'
64 def openstackEnv = "${env.WORKSPACE}/venv"
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010065
Filip Pytloun794ad952017-03-03 10:39:26 +010066 if (HEAT_STACK_REUSE.toBoolean() == true && HEAT_STACK_NAME == '') {
67 error("If you want to reuse existing stack you need to provide it's name")
68 }
69
70 if (HEAT_STACK_REUSE.toBoolean() == false) {
71 // Don't allow to set custom heat stack name
72 wrap([$class: 'BuildUser']) {
Tomáš Kukrál24d7fe62017-03-03 10:57:11 +010073 if (env.BUILD_USER_ID) {
74 HEAT_STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
75 } else {
76 HEAT_STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
77 }
Filip Pytloun794ad952017-03-03 10:39:26 +010078 currentBuild.description = HEAT_STACK_NAME
79 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +010080 }
Tomáš Kukrála18de112017-03-02 13:57:47 +010081
Tomáš Kukrálcbabec42017-03-02 16:24:04 +010082 // set description
Tomáš Kukrálaeb5c922017-03-02 17:00:48 +010083 currentBuild.description = "${HEAT_STACK_NAME}"
Tomáš Kukrálcbabec42017-03-02 16:24:04 +010084
Tomáš Kukrála18de112017-03-02 13:57:47 +010085 // get templates
86 git.checkoutGitRepository('template', HEAT_TEMPLATE_URL, HEAT_TEMPLATE_BRANCH, HEAT_TEMPLATE_CREDENTIALS)
87
88 // create openstack env
89 openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion)
90 openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT)
91 openstack.getKeystoneToken(openstackCloud, openstackEnv)
92
93 // launch stack
Filip Pytloun794ad952017-03-03 10:39:26 +010094 if (HEAT_STACK_REUSE.toBoolean() == false) {
Tomáš Kukrála18de112017-03-02 13:57:47 +010095 stage('Launch new Heat stack') {
96 // create stack
97 envParams = [
98 'instance_zone': HEAT_STACK_ZONE,
99 'public_net': HEAT_STACK_PUBLIC_NET
100 ]
101 openstack.createHeatStack(openstackCloud, HEAT_STACK_NAME, HEAT_STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, openstackEnv)
102 }
103 }
104
105 // get SALT_MASTER_URL
106 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, HEAT_STACK_NAME, 'salt_master_ip', openstackEnv)
Tomáš Kukrálaeb5c922017-03-02 17:00:48 +0100107 currentBuild.description = "${HEAT_STACK_NAME}: ${saltMasterHost}"
Tomáš Kukrál615aa9c2017-03-04 15:29:08 +0100108
Ales Komarek47a29f12017-04-26 12:05:47 +0200109 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100110 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100111 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100112
Tomáš Kukrála18de112017-03-02 13:57:47 +0100113 //
114 // Connect to Salt master
115 //
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100116
Tomáš Kukrála18de112017-03-02 13:57:47 +0100117 def saltMaster
118 stage('Connect to Salt API') {
119 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
120 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100121
Tomáš Kukrála18de112017-03-02 13:57:47 +0100122 //
123 // Install
124 //
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100125
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100126 if (common.checkContains('INSTALL', 'core')) {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100127 stage('Install core infrastructure') {
Ales Komarek47a29f12017-04-26 12:05:47 +0200128 orchestrate.installFoundationInfra(saltMaster)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100129
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100130 if (common.checkContains('INSTALL', 'kvm')) {
Ales Komarek47a29f12017-04-26 12:05:47 +0200131 orchestrate.installInfraKvm(saltMaster)
132 orchestrate.installFoundationInfra(saltMaster)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100133 }
134
Ales Komarek47a29f12017-04-26 12:05:47 +0200135 orchestrate.validateFoundationInfra(saltMaster)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100136 }
137 }
138
139 // install k8s
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100140 if (common.checkContains('INSTALL', 'k8s')) {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100141 stage('Install Kubernetes infra') {
Ales Komarek47a29f12017-04-26 12:05:47 +0200142 orchestrate.installKubernetesInfra(saltMaster)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100143 }
144
Tomáš Kukrála18de112017-03-02 13:57:47 +0100145 stage('Install Kubernetes control') {
Tomáš Kukrál06c27a92017-03-01 16:21:46 +0100146
Ales Komarek47a29f12017-04-26 12:05:47 +0200147 // Overwrite Kubernetes vars if specified
148 if (env.getEnvironment().containsKey("KUBERNETES_HYPERKUBE_IMAGE")) {
Tomáš Kukrálfbb98322017-05-02 10:38:05 +0200149 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'file.append', overwriteFile, " kubernetes_hyperkube_image: ${KUBERNETES_HYPERKUBE_IMAGE}")
Ales Komarek47a29f12017-04-26 12:05:47 +0200150 }
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100151
Ales Komarek47a29f12017-04-26 12:05:47 +0200152 orchestrate.installKubernetesControl(saltMaster)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100153 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100154 }
155
Tomáš Kukrála18de112017-03-02 13:57:47 +0100156 // install openstack
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100157 if (common.checkContains('INSTALL', 'openstack')) {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100158 // install Infra and control, tests, ...
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100159
Tomáš Kukrála18de112017-03-02 13:57:47 +0100160 stage('Install OpenStack infra') {
Ales Komarek47a29f12017-04-26 12:05:47 +0200161 orchestrate.installOpenstackInfra(saltMaster)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100162 }
163
Tomáš Kukrála18de112017-03-02 13:57:47 +0100164 stage('Install OpenStack control') {
Ales Komarek47a29f12017-04-26 12:05:47 +0200165 orchestrate.installOpenstackControl(saltMaster)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100166 }
167
168 stage('Install OpenStack network') {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100169
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100170 if (common.checkContains('INSTALL', 'contrail')) {
Ales Komarek47a29f12017-04-26 12:05:47 +0200171 orchestrate.installContrailNetwork(saltMaster)
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100172 } else if (common.checkContains('INSTALL', 'ovs')) {
Ales Komarek47a29f12017-04-26 12:05:47 +0200173 orchestrate.installOpenstackNetwork(saltMaster)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100174 }
175
Tomáš Kukrálfbb98322017-05-02 10:38:05 +0200176 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
177 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100178 }
179
180 stage('Install OpenStack compute') {
Ales Komarek47a29f12017-04-26 12:05:47 +0200181 orchestrate.installOpenstackCompute(saltMaster)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100182
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100183 if (common.checkContains('INSTALL', 'contrail')) {
Ales Komarek47a29f12017-04-26 12:05:47 +0200184 orchestrate.installContrailCompute(saltMaster)
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100185 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100186 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100187
Tomáš Kukrál00ed1302017-03-03 17:38:40 +0100188 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100189
Tomáš Kukrál00ed1302017-03-03 17:38:40 +0100190
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100191 if (common.checkContains('INSTALL', 'stacklight')) {
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100192 stage('Install StackLight') {
Ales Komarek47a29f12017-04-26 12:05:47 +0200193 orchestrate.installStacklightControl(saltMaster)
194 orchestrate.installStacklightClient(saltMaster)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100195 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100196 }
197
Tomáš Kukrála18de112017-03-02 13:57:47 +0100198 //
199 // Test
200 //
Tomáš Kukrál695d6462017-04-21 16:31:52 +0200201 def artifacts_dir = '_artifacts/'
Tomáš Kukrála18de112017-03-02 13:57:47 +0100202
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100203 if (common.checkContains('TEST', 'k8s')) {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100204 stage('Run k8s bootstrap tests') {
Tomáš Kukrál695d6462017-04-21 16:31:52 +0200205 def image = 'tomkukral/k8s-scripts'
Tomáš Kukrál44ca7fe2017-04-21 16:44:19 +0200206 def output_file = image.replaceAll('/', '-') + '.output'
Tomáš Kukrál695d6462017-04-21 16:31:52 +0200207
Tomáš Kukrálb22826d2017-04-21 16:38:00 +0200208 // run image
209 test.runConformanceTests(saltMaster, K8S_API_SERVER, image)
Tomáš Kukrálf56beed2017-04-21 16:21:06 +0200210
211 // collect output
Tomáš Kukrálf56beed2017-04-21 16:21:06 +0200212 sh "mkdir -p ${artifacts_dir}"
Tomáš Kukrálb22826d2017-04-21 16:38:00 +0200213 file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
Tomáš Kukrálf56beed2017-04-21 16:21:06 +0200214 writeFile file: "${artifacts_dir}${output_file}", text: file_content
Tomáš Kukrálf56beed2017-04-21 16:21:06 +0200215 sh "cat ${artifacts_dir}${output_file}"
216
217 // collect artifacts
218 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
Tomáš Kukrála18de112017-03-02 13:57:47 +0100219 }
220
Tomáš Kukrálb22826d2017-04-21 16:38:00 +0200221 stage('Run k8s conformance e2e tests') {
222 //test.runConformanceTests(saltMaster, K8S_API_SERVER, K8S_CONFORMANCE_IMAGE)
223
224 def image = K8S_CONFORMANCE_IMAGE
Tomáš Kukrál44ca7fe2017-04-21 16:44:19 +0200225 def output_file = image.replaceAll('/', '-') + '.output'
Tomáš Kukrálb22826d2017-04-21 16:38:00 +0200226
227 // run image
228 test.runConformanceTests(saltMaster, K8S_API_SERVER, image)
229
230 // collect output
231 sh "mkdir -p ${artifacts_dir}"
232 file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
233 writeFile file: "${artifacts_dir}${output_file}", text: file_content
234 sh "cat ${artifacts_dir}${output_file}"
235
236 // collect artifacts
237 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
238 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100239 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100240
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100241 if (common.checkContains('TEST', 'openstack')) {
Victor Ryzhenkin5f3b7e62017-03-09 16:02:58 +0400242 stage('Run OpenStack tests') {
243 test.runTempestTests(saltMaster, TEMPEST_IMAGE_LINK)
244 }
245
246 stage('Copy Tempest results to config node') {
247 test.copyTempestResults(saltMaster)
248 }
249 }
250
Tomáš Kukrál420d7ff2017-03-21 11:38:33 +0100251 stage('Finalize') {
Tomáš Kukrál38ab6bb2017-04-21 21:29:31 +0200252 if (INSTALL != '') {
253 try {
254 salt.runSaltProcessStep(saltMaster, '*', 'state.apply', [], null, true)
255 } catch (Exception e) {
256 common.warningMsg('State apply failed but we should continue to run')
257 }
Tomáš Kukrál420d7ff2017-03-21 11:38:33 +0100258 }
259 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100260 } catch (Throwable e) {
261 currentBuild.result = 'FAILURE'
262 throw e
Tomáš Kukrál65fb5fd2017-03-02 14:56:49 +0100263 } finally {
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100264
Tomáš Kukrál96b12d52017-03-07 22:43:37 +0100265
Tomáš Kukrála18de112017-03-02 13:57:47 +0100266 //
267 // Clean
268 //
269
Tomáš Kukrálc9a630a2017-03-07 17:28:53 +0100270 if (STACK_TYPE == 'heat') {
Tomáš Kukrál4507c6a2017-03-23 19:00:39 +0100271 // send notification
272 common.sendNotification(currentBuild.result, HEAT_STACK_NAME, ["slack"])
273
Tomáš Kukrálc9a630a2017-03-07 17:28:53 +0100274 if (HEAT_STACK_DELETE.toBoolean() == true) {
275 common.errorMsg('Heat job cleanup triggered')
276 stage('Trigger cleanup job') {
277 build job: 'deploy-heat-cleanup', parameters: [[$class: 'StringParameterValue', name: 'HEAT_STACK_NAME', value: HEAT_STACK_NAME]]
278 }
279 } else {
Tomáš Kukrálbcc53ea2017-03-08 08:15:57 +0100280 if (currentBuild.result == 'FAILURE') {
281 common.errorMsg("Deploy job FAILED and was not deleted. Please fix the problem and delete stack on you own.")
Tomáš Kukrálc9a630a2017-03-07 17:28:53 +0100282
Tomáš Kukrálbcc53ea2017-03-08 08:15:57 +0100283 if (SALT_MASTER_URL) {
284 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
285 }
Tomáš Kukrálb908dac2017-03-07 18:58:35 +0100286 }
287
Tomáš Kukrála18de112017-03-02 13:57:47 +0100288 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100289 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100290 }
291 }
292}