blob: 4799596fa793227ebc1068e679510840318a64ee [file] [log] [blame]
Tomáš Kukrálb9957b32017-02-28 14:49:00 +01001/**
2 *
3 * Launch heat stack with basic k8s
4 * Flow parameters:
Jakub Josef3c7915f2017-05-24 11:23:57 +02005 * STACK_NAME Heat stack name
6 * STACK_TYPE Orchestration engine: heat, ''
7 * STACK_INSTALL What should be installed (k8s, openstack, ...)
8 * STACK_TEST What should be tested (k8s, openstack, ...)
9 *
10 * STACK_TEMPLATE_URL URL to git repo with stack templates
11 * STACK_TEMPLATE_BRANCH Stack templates repo branch
12 * STACK_TEMPLATE_CREDENTIALS Credentials to the stack templates repo
13 * STACK_TEMPLATE Heat stack HOT template
14 * STACK_DELETE Delete stack when finished (bool)
15 * STACK_REUSE Reuse stack (don't create one)
16 * STACK_CLEANUP_JOB Name of job for deleting Heat stack
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010017 *
18 * Expected parameters:
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010019 * required for STACK_TYPE=heat
Matthew Mosesohn59fc6482017-06-01 18:53:10 +030020 * HEAT_STACK_ENVIRONMENT Heat stack environmental parameters
21 * HEAT_STACK_ZONE Heat stack availability zone
22 * HEAT_STACK_PUBLIC_NET Heat stack floating IP pool
23 * OPENSTACK_API_URL OpenStack API address
24 * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
25 * OPENSTACK_API_PROJECT OpenStack project to connect to
26 * OPENSTACK_API_PROJECT_DOMAIN Domain for OpenStack project
27 * OPENSTACK_API_PROJECT_ID ID for OpenStack project
28 * OPENSTACK_API_USER_DOMAIN Domain for OpenStack user
29 * OPENSTACK_API_CLIENT Versions of OpenStack python clients
30 * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010031 *
32 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
33 *
34 * required for STACK_TYPE=NONE or empty string
35 * SALT_MASTER_URL URL of Salt-API
36
37 * K8S_API_SERVER Kubernetes API address
38 * K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
39 *
Tatyana Leontovicha6c02912017-07-10 20:02:18 +030040 * TEMPEST_IMAGE Tempest image link
41 * TARGET_TEST_NODE Node to run tests
42 * DOCKER_INSTALL Install docker on the target if tue
43 * PATTERN If not false, run tests matched to pattern only
Victor Ryzhenkin5f3b7e62017-03-09 16:02:58 +040044 *
Matthew Mosesohna85f24e2017-04-28 13:45:19 +030045 * optional parameters for overwriting soft params
Matthew Mosesohn13933442017-07-04 21:20:08 +030046 * SALT_OVERRIDES YAML with overrides for Salt deployment
Matthew Mosesohna85f24e2017-04-28 13:45:19 +030047 * KUBERNETES_HYPERKUBE_IMAGE Docker repository and tag for hyperkube image
Matthew Mosesohnd00a8f52017-05-22 17:07:19 +030048 * CALICO_CNI_IMAGE Docker repository and tag for calico CNI image
49 * CALICO_NODE_IMAGE Docker repository and tag for calico node image
50 * CALICOCTL_IMAGE Docker repository and tag for calicoctl image
Matthew Mosesohn21a0e8e2017-06-06 16:35:08 +030051 * MTU MTU for Calico
Matthew Mosesohn3f2e10a2017-05-24 17:25:37 +030052 * NETCHECKER_AGENT_IMAGE Docker repository and tag for netchecker agent image
Matthew Mosesohn21a0e8e2017-06-06 16:35:08 +030053 * NETCHECKER_SERVER_IMAGE Docker repository and tag for netchecker server image
Matthew Mosesohna85f24e2017-04-28 13:45:19 +030054 *
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010055 */
56
Tomáš Kukrál1f8b5012017-04-28 21:07:10 +020057common = new com.mirantis.mk.Common()
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010058git = new com.mirantis.mk.Git()
59openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál1f8b5012017-04-28 21:07:10 +020060orchestrate = new com.mirantis.mk.Orchestrate()
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010061salt = new com.mirantis.mk.Salt()
Ondrej Smola8f35e482017-03-30 14:04:36 +020062test = new com.mirantis.mk.Test()
Tomáš Kukrál1f8b5012017-04-28 21:07:10 +020063
Tomáš Kukrálab2f3702017-05-11 09:17:43 +020064_MAX_PERMITTED_STACKS = 2
Tomáš Kukrále80680a2017-03-02 16:34:35 +010065
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +010066timestamps {
67 node {
Jakub Josef96ec3aa2017-05-29 17:53:56 +020068 // try to get STACK_INSTALL or fallback to INSTALL if exists
69 try {
70 def temporary = STACK_INSTALL
71 } catch (MissingPropertyException e) {
72 try {
73 STACK_INSTALL = INSTALL
74 env['STACK_INSTALL'] = INSTALL
75 } catch (MissingPropertyException e2) {
76 common.errorMsg("Property STACK_INSTALL or INSTALL not found!")
77 }
78 }
Tomáš Kukrála18de112017-03-02 13:57:47 +010079 try {
80 //
81 // Prepare machines
82 //
Tomáš Kukrála18de112017-03-02 13:57:47 +010083 stage ('Create infrastructure') {
Tomáš Kukrál6d627d62017-03-23 17:39:07 +010084
Tomáš Kukrála18de112017-03-02 13:57:47 +010085 if (STACK_TYPE == 'heat') {
86 // value defaults
87 def openstackCloud
88 def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty'
89 def openstackEnv = "${env.WORKSPACE}/venv"
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010090
Jakub Josef3c7915f2017-05-24 11:23:57 +020091 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
Filip Pytloun794ad952017-03-03 10:39:26 +010092 error("If you want to reuse existing stack you need to provide it's name")
93 }
94
Jakub Josef3c7915f2017-05-24 11:23:57 +020095 if (STACK_REUSE.toBoolean() == false) {
Filip Pytloun794ad952017-03-03 10:39:26 +010096 // Don't allow to set custom heat stack name
97 wrap([$class: 'BuildUser']) {
Tomáš Kukrál24d7fe62017-03-03 10:57:11 +010098 if (env.BUILD_USER_ID) {
Jakub Josef3c7915f2017-05-24 11:23:57 +020099 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
Tomáš Kukrál24d7fe62017-03-03 10:57:11 +0100100 } else {
Jakub Josef3c7915f2017-05-24 11:23:57 +0200101 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
Tomáš Kukrál24d7fe62017-03-03 10:57:11 +0100102 }
Jakub Josef3c7915f2017-05-24 11:23:57 +0200103 currentBuild.description = STACK_NAME
Filip Pytloun794ad952017-03-03 10:39:26 +0100104 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100105 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100106
Tomáš Kukrálcbabec42017-03-02 16:24:04 +0100107 // set description
Jakub Josef3c7915f2017-05-24 11:23:57 +0200108 currentBuild.description = "${STACK_NAME}"
Tomáš Kukrálcbabec42017-03-02 16:24:04 +0100109
Tomáš Kukrála18de112017-03-02 13:57:47 +0100110 // get templates
Jakub Josef3c7915f2017-05-24 11:23:57 +0200111 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100112
113 // create openstack env
114 openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion)
Matthew Mosesohnbd7976b2017-05-29 19:35:44 +0300115 openstackCloud = openstack.createOpenstackEnv(
116 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
Matthew Mosesohn59fc6482017-06-01 18:53:10 +0300117 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
118 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
Matthew Mosesohnbd7976b2017-05-29 19:35:44 +0300119 OPENSTACK_API_VERSION)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100120 openstack.getKeystoneToken(openstackCloud, openstackEnv)
Jakub Josef458913d2017-05-10 15:37:56 +0200121 //
122 // Verify possibility of create stack for given user and stack type
123 //
124 wrap([$class: 'BuildUser']) {
chnydaf23f46b2017-06-05 14:54:27 +0200125 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !env.BUILD_USER_ID.equals("mceloud") && !STACK_REUSE.toBoolean()) {
Jakub Josef78c3f8b2017-05-10 15:45:29 +0200126 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}", openstackEnv)
127 if(existingStacks.size() >= _MAX_PERMITTED_STACKS){
Jakub Josef3c7915f2017-05-24 11:23:57 +0200128 STACK_DELETE = "false"
Jakub Josef78c3f8b2017-05-10 15:45:29 +0200129 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
130 }
Jakub Josef458913d2017-05-10 15:37:56 +0200131 }
132 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100133 // launch stack
Jakub Josef3c7915f2017-05-24 11:23:57 +0200134 if (STACK_REUSE.toBoolean() == false) {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100135 stage('Launch new Heat stack') {
136 // create stack
137 envParams = [
138 'instance_zone': HEAT_STACK_ZONE,
139 'public_net': HEAT_STACK_PUBLIC_NET
140 ]
Jakub Josef3c7915f2017-05-24 11:23:57 +0200141 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, openstackEnv)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100142 }
143 }
144
145 // get SALT_MASTER_URL
Jakub Josef3c7915f2017-05-24 11:23:57 +0200146 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', openstackEnv)
147 currentBuild.description = "${STACK_NAME}: ${saltMasterHost}"
Tomáš Kukrál615aa9c2017-03-04 15:29:08 +0100148
Ales Komarek47a29f12017-04-26 12:05:47 +0200149 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100150 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100151 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100152
Tomáš Kukrála18de112017-03-02 13:57:47 +0100153 //
154 // Connect to Salt master
155 //
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100156
Tomáš Kukrála18de112017-03-02 13:57:47 +0100157 def saltMaster
158 stage('Connect to Salt API') {
159 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
160 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100161
Matthew Mosesohn13933442017-07-04 21:20:08 +0300162 // Set up override params
163 if (env.getEnvironment().containsKey('SALT_OVERRIDES')) {
164 stage('Set Salt overrides') {
165 salt.setSaltOverrides(saltMaster, SALT_OVERRIDES)
166 }
167 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100168 //
169 // Install
170 //
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100171
Jakub Josef3c7915f2017-05-24 11:23:57 +0200172 if (common.checkContains('STACK_INSTALL', 'core')) {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100173 stage('Install core infrastructure') {
Ales Komarek47a29f12017-04-26 12:05:47 +0200174 orchestrate.installFoundationInfra(saltMaster)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100175
Jakub Josef3c7915f2017-05-24 11:23:57 +0200176 if (common.checkContains('STACK_INSTALL', 'kvm')) {
Ales Komarek47a29f12017-04-26 12:05:47 +0200177 orchestrate.installInfraKvm(saltMaster)
178 orchestrate.installFoundationInfra(saltMaster)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100179 }
180
Ales Komarek47a29f12017-04-26 12:05:47 +0200181 orchestrate.validateFoundationInfra(saltMaster)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100182 }
183 }
184
185 // install k8s
Jakub Josef3c7915f2017-05-24 11:23:57 +0200186 if (common.checkContains('STACK_INSTALL', 'k8s')) {
vrovachev48ea8622017-06-28 10:28:56 +0400187
Matthew Mosesohn13933442017-07-04 21:20:08 +0300188 // Deprecated stage. Use SALT_OVERRIDES instead.
vrovachev48ea8622017-06-28 10:28:56 +0400189 stage('Overwrite Kubernetes parameters') {
190
191 // Overwrite Kubernetes vars if specified
192 if (env.getEnvironment().containsKey('KUBERNETES_HYPERKUBE_IMAGE')) {
193 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_hyperkube_image', KUBERNETES_HYPERKUBE_IMAGE])
194 }
195 if (env.getEnvironment().containsKey('MTU')) {
196 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_mtu', MTU])
197 }
198
199 // Overwrite Calico vars if specified
200 if (env.getEnvironment().containsKey('CALICO_CNI_IMAGE')) {
201 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_calico_cni_image', CALICO_CNI_IMAGE])
202 }
203 if (env.getEnvironment().containsKey('CALICO_NODE_IMAGE')) {
204 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_calico_image', CALICO_NODE_IMAGE])
205 }
206 if (env.getEnvironment().containsKey('CALICOCTL_IMAGE')) {
207 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_calicoctl_image', CALICOCTL_IMAGE])
208 }
209 if (env.getEnvironment().containsKey('CALICO_POLICY_IMAGE')) {
210 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_calico_policy_image', CALICO_POLICY_IMAGE])
211 }
212
213 // Overwrite Virtlet image if specified
214 if (env.getEnvironment().containsKey('VIRTLET_IMAGE')) {
215 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_virtlet_image', VIRTLET_IMAGE])
216 }
217
218 // Overwrite netchecker vars if specified
219 if (env.getEnvironment().containsKey('NETCHECKER_AGENT_IMAGE')) {
220 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_netchecker_agent_image', NETCHECKER_AGENT_IMAGE])
221 }
222 if (env.getEnvironment().containsKey('NETCHECKER_SERVER_IMAGE')) {
223 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_netchecker_server_image', NETCHECKER_SERVER_IMAGE])
224 }
225
226 // Overwrite docker version if specified
227 if (env.getEnvironment().containsKey('DOCKER_ENGINE')) {
228 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_docker_package', DOCKER_ENGINE])
229 }
230
231 // Overwrite addons vars if specified
232 if (env.getEnvironment().containsKey('HELM_ENABLED')) {
233 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_helm_enabled', HELM_ENABLED])
234 }
235 if (env.getEnvironment().containsKey('NETCHECKER_ENABLED')) {
236 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_netchecker_enabled', NETCHECKER_ENABLED])
237 }
238 if (env.getEnvironment().containsKey('CALICO_POLICY_ENABLED')) {
239 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_calico_policy_enabled', CALICO_POLICY_ENABLED])
240 }
241 if (env.getEnvironment().containsKey('VIRTLET_ENABLED')) {
242 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_virtlet_enabled', VIRTLET_ENABLED])
243 }
244 if (env.getEnvironment().containsKey('KUBE_NET_MANAGER_ENABLED')) {
245 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_kube_network_manager_enabled', KUBE_NET_MANAGER_ENABLED])
246 }
247 }
248
249 // If k8s install with contrail network manager then contrail need to be install first
250 if (common.checkContains('STACK_INSTALL', 'contrail')) {
251 stage('Install Contrail for Kubernetes') {
252 orchestrate.installContrailNetwork(saltMaster)
253 orchestrate.installContrailCompute(saltMaster)
254 orchestrate.installKubernetesContrailCompute(saltMaster)
255 }
256 }
257
Tomáš Kukrála18de112017-03-02 13:57:47 +0100258 stage('Install Kubernetes infra') {
Ales Komarek47a29f12017-04-26 12:05:47 +0200259 orchestrate.installKubernetesInfra(saltMaster)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100260 }
261
Tomáš Kukrála18de112017-03-02 13:57:47 +0100262 stage('Install Kubernetes control') {
Ales Komarek47a29f12017-04-26 12:05:47 +0200263 orchestrate.installKubernetesControl(saltMaster)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100264 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100265 }
266
Tomáš Kukrála18de112017-03-02 13:57:47 +0100267 // install openstack
Jakub Josef3c7915f2017-05-24 11:23:57 +0200268 if (common.checkContains('STACK_INSTALL', 'openstack')) {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100269 // install Infra and control, tests, ...
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100270
Tomáš Kukrála18de112017-03-02 13:57:47 +0100271 stage('Install OpenStack infra') {
Ales Komarek47a29f12017-04-26 12:05:47 +0200272 orchestrate.installOpenstackInfra(saltMaster)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100273 }
274
Tomáš Kukrála18de112017-03-02 13:57:47 +0100275 stage('Install OpenStack control') {
Ales Komarek47a29f12017-04-26 12:05:47 +0200276 orchestrate.installOpenstackControl(saltMaster)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100277 }
278
279 stage('Install OpenStack network') {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100280
Jakub Josef3c7915f2017-05-24 11:23:57 +0200281 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Ales Komarek47a29f12017-04-26 12:05:47 +0200282 orchestrate.installContrailNetwork(saltMaster)
Jakub Josef3c7915f2017-05-24 11:23:57 +0200283 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
Ales Komarek47a29f12017-04-26 12:05:47 +0200284 orchestrate.installOpenstackNetwork(saltMaster)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100285 }
286
Tomáš Kukrálfbb98322017-05-02 10:38:05 +0200287 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
288 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100289 }
290
291 stage('Install OpenStack compute') {
Ales Komarek47a29f12017-04-26 12:05:47 +0200292 orchestrate.installOpenstackCompute(saltMaster)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100293
Jakub Josef3c7915f2017-05-24 11:23:57 +0200294 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Ales Komarek47a29f12017-04-26 12:05:47 +0200295 orchestrate.installContrailCompute(saltMaster)
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100296 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100297 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100298
Tomáš Kukrál00ed1302017-03-03 17:38:40 +0100299 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100300
Tomáš Kukrál00ed1302017-03-03 17:38:40 +0100301
Martin Polreichbb6f5752017-06-30 12:37:41 +0200302 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
303 stage('Install StackLight v1') {
304 orchestrate.installStacklightv1Control(saltMaster)
305 orchestrate.installStacklightv1Client(saltMaster)
306 }
307 }
308
Jakub Josef3c7915f2017-05-24 11:23:57 +0200309 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100310 stage('Install StackLight') {
Martin Polreichbb6f5752017-06-30 12:37:41 +0200311 orchestrate.installDockerSwarm(saltMaster)
312 orchestrate.installStacklight(saltMaster)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100313 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100314 }
315
Tomáš Kukrála18de112017-03-02 13:57:47 +0100316 //
317 // Test
318 //
Tomáš Kukrál695d6462017-04-21 16:31:52 +0200319 def artifacts_dir = '_artifacts/'
Tomáš Kukrála18de112017-03-02 13:57:47 +0100320
Jakub Josef3c7915f2017-05-24 11:23:57 +0200321 if (common.checkContains('STACK_TEST', 'k8s')) {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100322 stage('Run k8s bootstrap tests') {
Tomáš Kukrál695d6462017-04-21 16:31:52 +0200323 def image = 'tomkukral/k8s-scripts'
Tomáš Kukrál44ca7fe2017-04-21 16:44:19 +0200324 def output_file = image.replaceAll('/', '-') + '.output'
Tomáš Kukrál695d6462017-04-21 16:31:52 +0200325
Tomáš Kukrálb22826d2017-04-21 16:38:00 +0200326 // run image
327 test.runConformanceTests(saltMaster, K8S_API_SERVER, image)
Tomáš Kukrálf56beed2017-04-21 16:21:06 +0200328
329 // collect output
Tomáš Kukrálf56beed2017-04-21 16:21:06 +0200330 sh "mkdir -p ${artifacts_dir}"
Tomáš Kukrálb22826d2017-04-21 16:38:00 +0200331 file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
Tomáš Kukrálf56beed2017-04-21 16:21:06 +0200332 writeFile file: "${artifacts_dir}${output_file}", text: file_content
Tomáš Kukrálf56beed2017-04-21 16:21:06 +0200333 sh "cat ${artifacts_dir}${output_file}"
334
335 // collect artifacts
336 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
Tomáš Kukrála18de112017-03-02 13:57:47 +0100337 }
338
Tomáš Kukrálb22826d2017-04-21 16:38:00 +0200339 stage('Run k8s conformance e2e tests') {
340 //test.runConformanceTests(saltMaster, K8S_API_SERVER, K8S_CONFORMANCE_IMAGE)
341
342 def image = K8S_CONFORMANCE_IMAGE
Tomáš Kukrál44ca7fe2017-04-21 16:44:19 +0200343 def output_file = image.replaceAll('/', '-') + '.output'
Tomáš Kukrálb22826d2017-04-21 16:38:00 +0200344
345 // run image
346 test.runConformanceTests(saltMaster, K8S_API_SERVER, image)
347
348 // collect output
349 sh "mkdir -p ${artifacts_dir}"
350 file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
351 writeFile file: "${artifacts_dir}${output_file}", text: file_content
352 sh "cat ${artifacts_dir}${output_file}"
353
354 // collect artifacts
355 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
356 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100357 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100358
Jakub Josef3c7915f2017-05-24 11:23:57 +0200359 if (common.checkContains('STACK_TEST', 'openstack')) {
Tatyana Leontovicha6c02912017-07-10 20:02:18 +0300360 if (common.checkContains('DOCKER_INSTALL', 'true')) {
361 test.install_docker(saltMaster, TARGET)
362 }
Victor Ryzhenkin5f3b7e62017-03-09 16:02:58 +0400363 stage('Run OpenStack tests') {
Tatyana Leontovicha6c02912017-07-10 20:02:18 +0300364 test.runTempestTests(saltMaster, TEMPEST_IMAGE, TARGET, PATTERN)
Victor Ryzhenkin5f3b7e62017-03-09 16:02:58 +0400365 }
366
367 stage('Copy Tempest results to config node') {
Tatyana Leontovicha6c02912017-07-10 20:02:18 +0300368 test.copyTempestResults(saltMaster, TARGET)
Victor Ryzhenkin5f3b7e62017-03-09 16:02:58 +0400369 }
370 }
371
Tomáš Kukrál420d7ff2017-03-21 11:38:33 +0100372 stage('Finalize') {
Jakub Josef3c7915f2017-05-24 11:23:57 +0200373 if (STACK_INSTALL != '') {
Tomáš Kukrál38ab6bb2017-04-21 21:29:31 +0200374 try {
375 salt.runSaltProcessStep(saltMaster, '*', 'state.apply', [], null, true)
376 } catch (Exception e) {
377 common.warningMsg('State apply failed but we should continue to run')
Jakub Josefa6904f12017-05-22 16:37:27 +0200378 throw e
Tomáš Kukrál38ab6bb2017-04-21 21:29:31 +0200379 }
Tomáš Kukrál420d7ff2017-03-21 11:38:33 +0100380 }
381 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100382 } catch (Throwable e) {
383 currentBuild.result = 'FAILURE'
384 throw e
Tomáš Kukrál65fb5fd2017-03-02 14:56:49 +0100385 } finally {
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100386
Tomáš Kukrál96b12d52017-03-07 22:43:37 +0100387
Tomáš Kukrála18de112017-03-02 13:57:47 +0100388 //
389 // Clean
390 //
391
Tomáš Kukrálc9a630a2017-03-07 17:28:53 +0100392 if (STACK_TYPE == 'heat') {
Tomáš Kukrál4507c6a2017-03-23 19:00:39 +0100393 // send notification
Jakub Josef3c7915f2017-05-24 11:23:57 +0200394 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
Tomáš Kukrál4507c6a2017-03-23 19:00:39 +0100395
Jakub Josef3c7915f2017-05-24 11:23:57 +0200396 if (STACK_DELETE.toBoolean() == true) {
Tomáš Kukrálc9a630a2017-03-07 17:28:53 +0100397 common.errorMsg('Heat job cleanup triggered')
398 stage('Trigger cleanup job') {
Tomáš Kukrálea079922017-06-22 09:12:15 +0200399 build(job: STACK_CLEANUP_JOB, parameters: [
400 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
401 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
402 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
403 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
404 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
405 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
406 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
407 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
408 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
409 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
410 ])
Tomáš Kukrálc9a630a2017-03-07 17:28:53 +0100411 }
412 } else {
Tomáš Kukrálbcc53ea2017-03-08 08:15:57 +0100413 if (currentBuild.result == 'FAILURE') {
414 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 +0100415
Tomáš Kukrálbcc53ea2017-03-08 08:15:57 +0100416 if (SALT_MASTER_URL) {
417 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
418 }
Tomáš Kukrálb908dac2017-03-07 18:58:35 +0100419 }
420
Tomáš Kukrála18de112017-03-02 13:57:47 +0100421 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100422 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100423 }
424 }
425}