blob: b4014b61e7dce3fb60bd810d45fd1cf066f979f4 [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 *
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010038 */
39
40git = new com.mirantis.mk.Git()
41openstack = new com.mirantis.mk.Openstack()
42salt = new com.mirantis.mk.Salt()
Tomáš Kukrál3e4029d2017-03-07 09:59:40 +010043common = new com.mirantis.mk.Common()
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010044
Tomáš Kukrále80680a2017-03-02 16:34:35 +010045
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +010046timestamps {
47 node {
Tomáš Kukrála18de112017-03-02 13:57:47 +010048 try {
49 //
50 // Prepare machines
51 //
Tomáš Kukrála18de112017-03-02 13:57:47 +010052 stage ('Create infrastructure') {
Tomáš Kukrál6d627d62017-03-23 17:39:07 +010053
Tomáš Kukrála18de112017-03-02 13:57:47 +010054 if (STACK_TYPE == 'heat') {
55 // value defaults
56 def openstackCloud
57 def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty'
58 def openstackEnv = "${env.WORKSPACE}/venv"
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010059
Filip Pytloun794ad952017-03-03 10:39:26 +010060 if (HEAT_STACK_REUSE.toBoolean() == true && HEAT_STACK_NAME == '') {
61 error("If you want to reuse existing stack you need to provide it's name")
62 }
63
64 if (HEAT_STACK_REUSE.toBoolean() == false) {
65 // Don't allow to set custom heat stack name
66 wrap([$class: 'BuildUser']) {
Tomáš Kukrál24d7fe62017-03-03 10:57:11 +010067 if (env.BUILD_USER_ID) {
68 HEAT_STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
69 } else {
70 HEAT_STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
71 }
Filip Pytloun794ad952017-03-03 10:39:26 +010072 currentBuild.description = HEAT_STACK_NAME
73 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +010074 }
Tomáš Kukrála18de112017-03-02 13:57:47 +010075
Tomáš Kukrálcbabec42017-03-02 16:24:04 +010076 // set description
Tomáš Kukrálaeb5c922017-03-02 17:00:48 +010077 currentBuild.description = "${HEAT_STACK_NAME}"
Tomáš Kukrálcbabec42017-03-02 16:24:04 +010078
Tomáš Kukrála18de112017-03-02 13:57:47 +010079 // get templates
80 git.checkoutGitRepository('template', HEAT_TEMPLATE_URL, HEAT_TEMPLATE_BRANCH, HEAT_TEMPLATE_CREDENTIALS)
81
82 // create openstack env
83 openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion)
84 openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT)
85 openstack.getKeystoneToken(openstackCloud, openstackEnv)
86
87 // launch stack
Filip Pytloun794ad952017-03-03 10:39:26 +010088 if (HEAT_STACK_REUSE.toBoolean() == false) {
Tomáš Kukrála18de112017-03-02 13:57:47 +010089 stage('Launch new Heat stack') {
90 // create stack
91 envParams = [
92 'instance_zone': HEAT_STACK_ZONE,
93 'public_net': HEAT_STACK_PUBLIC_NET
94 ]
95 openstack.createHeatStack(openstackCloud, HEAT_STACK_NAME, HEAT_STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, openstackEnv)
96 }
97 }
98
99 // get SALT_MASTER_URL
100 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, HEAT_STACK_NAME, 'salt_master_ip', openstackEnv)
Tomáš Kukrálaeb5c922017-03-02 17:00:48 +0100101 currentBuild.description = "${HEAT_STACK_NAME}: ${saltMasterHost}"
Tomáš Kukrál615aa9c2017-03-04 15:29:08 +0100102
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100103 if (common.checkContains('INSTALL', 'kvm')) {
Marek Celoud5e442a32017-03-16 10:15:53 +0100104 saltPort = 6969
Tomáš Kukrál615aa9c2017-03-04 15:29:08 +0100105 } else {
Marek Celoud5e442a32017-03-16 10:15:53 +0100106 saltPort = 6969
Tomáš Kukrál615aa9c2017-03-04 15:29:08 +0100107 }
108
Tomáš Kukrál61509292017-03-04 16:27:07 +0100109 SALT_MASTER_URL = "http://${saltMasterHost}:${saltPort}"
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') {
128 // salt.master, reclass
129 // refresh_pillar
130 // sync_all
131 // linux,openssh,salt.minion.ntp
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100132
Tomáš Kukrála18de112017-03-02 13:57:47 +0100133 //orchestrate.installFoundationInfra(saltMaster)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100134 salt.enforceState(saltMaster, 'I@salt:master', ['salt.master', 'reclass'], true)
Marek Celoud53292462017-03-23 23:34:18 +0100135 salt.enforceState(saltMaster, '*', ['linux.system'], true)
Marek Celoud1c1ecd12017-03-23 20:41:22 +0100136 salt.enforceState(saltMaster, '*', ['salt.minion'], true)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100137 salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.refresh_pillar', [], null, true)
138 salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.sync_all', [], null, true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100139 salt.enforceState(saltMaster, 'I@linux:system', ['linux', 'openssh', 'salt.minion', 'ntp'], true)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100140
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100141
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100142 if (common.checkContains('INSTALL', 'kvm')) {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100143 //orchestrate.installInfraKvm(saltMaster)
Marek Celoud1c1ecd12017-03-23 20:41:22 +0100144 //salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.refresh_pillar', [], null, true)
145 //salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.sync_all', [], null, true)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100146
Marek Celoud1c1ecd12017-03-23 20:41:22 +0100147 //salt.enforceState(saltMaster, 'I@salt:control', ['salt.minion', 'linux.system', 'linux.network', 'ntp'], true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100148 salt.enforceState(saltMaster, 'I@salt:control', 'libvirt', true)
149 salt.enforceState(saltMaster, 'I@salt:control', 'salt.control', true)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100150
Tomáš Kukrál3e5c5bf2017-03-09 16:45:54 +0100151 sleep(600)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100152
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100153 salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'saltutil.refresh_pillar', [], null, true)
154 salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'saltutil.sync_all', [], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100155
156 // workaround - install apt-transport-https
Tomáš Kukrálbe9dfa52017-03-08 13:54:03 +0100157 //salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'cmd.run', ['apt-get update -y && apt-get install -y apt-transport-https'], null, true)
158 //salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'pkg.install', ['apt-transport-https', 'refresh=True'], null, true)
Marek Celoudce2a28b2017-03-13 17:11:30 +0100159 salt.enforceState(saltMaster, 'I@linux:system', ['linux', 'salt.minion'], true, false)
160 salt.enforceState(saltMaster, 'I@linux:system', ['openssh', 'salt.minion', 'ntp'], true, false)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100161 }
162
163 //orchestrate.validateFoundationInfra(saltMaster)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100164 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'cmd.run', ['salt-key'], null, true)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100165 salt.runSaltProcessStep(saltMaster, 'I@salt:minion', 'test.version', [], null, true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100166 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'cmd.run', ['reclass-salt --top'], null, true)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100167 salt.runSaltProcessStep(saltMaster, 'I@reclass:storage', 'reclass.inventory', [], null, true)
168 salt.runSaltProcessStep(saltMaster, 'I@salt:minion', 'state.show_top', [], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100169 }
170 }
171
172 // install k8s
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100173 if (common.checkContains('INSTALL', 'k8s')) {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100174 stage('Install Kubernetes infra') {
175 //orchestrate.installOpenstackMcpInfra(saltMaster)
176
177 // Comment nameserver
178 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:master', 'cmd.run', ["sed -i 's/nameserver 10.254.0.10/#nameserver 10.254.0.10/g' /etc/resolv.conf"])
179
180 // Install glusterfs
181 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.service'])
182
183 // Install keepalived
Marek Celoudfeb67062017-03-13 11:01:43 +0100184 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster and *01*', 'state.sls', ['keepalived'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100185 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'state.sls', ['keepalived'])
186
187 // Check the keepalived VIPs
188 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
189
190 // Setup glusterfs
Marek Celoudfeb67062017-03-13 11:01:43 +0100191 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server and *01*', 'state.sls', ['glusterfs.server.setup'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100192 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'])
193 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'])
194
195 // Install haproxy
196 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'state.sls', ['haproxy'])
197 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.status', ['haproxy'])
198
199 // Install docker
200 salt.runSaltProcessStep(saltMaster, 'I@docker:host', 'state.sls', ['docker.host'])
201 salt.runSaltProcessStep(saltMaster, 'I@docker:host', 'cmd.run', ['docker ps'])
202
203 // Install bird
204 salt.runSaltProcessStep(saltMaster, 'I@bird:server', 'state.sls', ['bird'])
205
206 // Install etcd
207 salt.runSaltProcessStep(saltMaster, 'I@etcd:server', 'state.sls', ['etcd.server.service'])
208 salt.runSaltProcessStep(saltMaster, 'I@etcd:server', 'cmd.run', ['etcdctl cluster-health'])
209
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100210 }
211
Tomáš Kukrála18de112017-03-02 13:57:47 +0100212 stage('Install Kubernetes control') {
213 //orchestrate.installOpenstackMcpControl(saltMaster)
Tomáš Kukrál06c27a92017-03-01 16:21:46 +0100214
Tomáš Kukrála18de112017-03-02 13:57:47 +0100215 // Install Kubernetes pool and Calico
216 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:pool', 'state.sls', ['kubernetes.pool'])
217 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:pool', 'cmd.run', ['calicoctl node status'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100218
Tomáš Kukrála18de112017-03-02 13:57:47 +0100219 // Setup etcd server
220 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:master', 'state.sls', ['etcd.server.setup'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100221
Tomáš Kukrála18de112017-03-02 13:57:47 +0100222 // Run k8s without master.setup
223 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:master', 'state.sls', ['kubernetes', 'exclude=kubernetes.master.setup'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100224
Tomáš Kukrála18de112017-03-02 13:57:47 +0100225 // Run k8s master setup
Marek Celoudfeb67062017-03-13 11:01:43 +0100226 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:master and *01*', 'state.sls', ['kubernetes.master.setup'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100227
Tomáš Kukrála18de112017-03-02 13:57:47 +0100228 // Revert comment nameserver
229 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:master', 'cmd.run', ["sed -i 's/nameserver 10.254.0.10/#nameserver 10.254.0.10/g' /etc/resolv.conf"])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100230
Tomáš Kukrála18de112017-03-02 13:57:47 +0100231 // Set route
232 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:pool', 'cmd.run', ['ip r a 10.254.0.0/16 dev ens4'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100233
Tomáš Kukrála18de112017-03-02 13:57:47 +0100234 // Restart kubelet
235 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:pool', 'service.restart', ['kubelet'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100236 }
237
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100238 }
239
Tomáš Kukrála18de112017-03-02 13:57:47 +0100240 // install openstack
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100241 if (common.checkContains('INSTALL', 'openstack')) {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100242 // install Infra and control, tests, ...
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100243
Tomáš Kukrála18de112017-03-02 13:57:47 +0100244 stage('Install OpenStack infra') {
245 //orchestrate.installOpenstackMkInfra(saltMaster, physical)
246
Marek Celoud8db985f2017-03-14 17:41:19 +0100247 // Install glusterfs
248 salt.enforceState(saltMaster, 'I@glusterfs:server', 'glusterfs.server.service', true)
249
Tomáš Kukrála18de112017-03-02 13:57:47 +0100250 // Install keepaliveds
251 //runSaltProcessStep(master, 'I@keepalived:cluster', 'state.sls', ['keepalived'], 1)
Marek Celoudfeb67062017-03-13 11:01:43 +0100252 salt.enforceState(saltMaster, 'I@keepalived:cluster and *01*', 'keepalived', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100253 salt.enforceState(saltMaster, 'I@keepalived:cluster', 'keepalived', true)
254
255 // Check the keepalived VIPs
256 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
257
Marek Celoudfeb67062017-03-13 11:01:43 +0100258 salt.enforceState(saltMaster, 'I@glusterfs:server and *01*', 'glusterfs.server.setup', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100259
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100260 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'], null, true)
261 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100262
263 // Install rabbitmq
Marek Celoud88a79a22017-03-27 15:51:41 +0200264 withEnv(['ASK_ON_ERROR=false']){
265 retry(2) {
266 salt.enforceState(saltMaster, 'I@rabbitmq:server', 'rabbitmq', true)
267 }
268 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100269 // Check the rabbitmq status
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100270 salt.runSaltProcessStep(saltMaster, 'I@rabbitmq:server', 'cmd.run', ['rabbitmqctl cluster_status'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100271
272 // Install galera
Marek Celoud88a79a22017-03-27 15:51:41 +0200273 withEnv(['ASK_ON_ERROR=false']){
274 retry(2) {
275 salt.enforceState(saltMaster, 'I@galera:master', 'galera', true)
276 }
Marek Celoud7c84ef72017-03-15 17:32:32 +0100277 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100278 salt.enforceState(saltMaster, 'I@galera:slave', 'galera', true)
279
280 // Check galera status
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100281 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'mysql.status')
282 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'mysql.status')
Tomáš Kukrála18de112017-03-02 13:57:47 +0100283
Marek Celoudcabe5642017-03-15 18:16:38 +0100284 // // Setup mysql client
285 // salt.enforceState(saltMaster, 'I@mysql:client', 'mysql.client', true)
Tomáš Kukrálaa8f5532017-03-07 13:34:39 +0100286
Tomáš Kukrála18de112017-03-02 13:57:47 +0100287 // Install haproxy
288 salt.enforceState(saltMaster, 'I@haproxy:proxy', 'haproxy', true)
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100289 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.status', ['haproxy'])
290 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.restart', ['rsyslog'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100291
292 // Install memcached
293 salt.enforceState(saltMaster, 'I@memcached:server', 'memcached', true)
294
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100295 }
296
Tomáš Kukrála18de112017-03-02 13:57:47 +0100297 stage('Install OpenStack control') {
298 //orchestrate.installOpenstackMkControl(saltMaster)
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100299
Marek Celoud36d24b62017-03-21 15:07:07 +0100300 // Install horizon dashboard
301 salt.enforceState(saltMaster, 'I@horizon:server', 'horizon', true)
302 salt.enforceState(saltMaster, 'I@nginx:server', 'nginx', true)
303
Tomáš Kukrála18de112017-03-02 13:57:47 +0100304 // setup keystone service
305 //runSaltProcessStep(saltMaster, 'I@keystone:server', 'state.sls', ['keystone.server'], 1)
Marek Celoudfeb67062017-03-13 11:01:43 +0100306 salt.enforceState(saltMaster, 'I@keystone:server and *01*', 'keystone.server', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100307 salt.enforceState(saltMaster, 'I@keystone:server', 'keystone.server', true)
308 // populate keystone services/tenants/roles/users
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100309
Tomáš Kukrála18de112017-03-02 13:57:47 +0100310 // keystone:client must be called locally
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100311 salt.runSaltProcessStep(saltMaster, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
312 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; keystone service-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100313
314 // Install glance and ensure glusterfs clusters
315 //runSaltProcessStep(saltMaster, 'I@glance:server', 'state.sls', ['glance.server'], 1)
Marek Celoudfeb67062017-03-13 11:01:43 +0100316 salt.enforceState(saltMaster, 'I@glance:server and *01*', 'glance.server', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100317 salt.enforceState(saltMaster, 'I@glance:server', 'glance.server', true)
318 salt.enforceState(saltMaster, 'I@glance:server', 'glusterfs.client', true)
319
320 // Update fernet tokens before doing request on keystone server
321 salt.enforceState(saltMaster, 'I@keystone:server', 'keystone.server', true)
322
323 // Check glance service
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100324 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; glance image-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100325
326 // Install and check nova service
327 //runSaltProcessStep(saltMaster, 'I@nova:controller', 'state.sls', ['nova'], 1)
Marek Celoud396ba542017-03-21 11:02:50 +0100328 salt.enforceState(saltMaster, 'I@nova:controller and *01*', 'nova.controller', true)
329 salt.enforceState(saltMaster, 'I@nova:controller', 'nova.controller', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100330 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova service-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100331
332 // Install and check cinder service
333 //runSaltProcessStep(saltMaster, 'I@cinder:controller', 'state.sls', ['cinder'], 1)
Marek Celoudfeb67062017-03-13 11:01:43 +0100334 salt.enforceState(saltMaster, 'I@cinder:controller and *01*', 'cinder', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100335 salt.enforceState(saltMaster, 'I@cinder:controller', 'cinder', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100336 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; cinder list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100337
338 // Install neutron service
339 //runSaltProcessStep(saltMaster, 'I@neutron:server', 'state.sls', ['neutron'], 1)
Tomáš Kukrál575e38a2017-03-02 17:12:45 +0100340
Marek Celoud396ba542017-03-21 11:02:50 +0100341 salt.enforceState(saltMaster, 'I@neutron:server and *01*', 'neutron.server', true)
342 salt.enforceState(saltMaster, 'I@neutron:server', 'neutron.server', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100343 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron agent-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100344
345 // Install heat service
346 //runSaltProcessStep(saltMaster, 'I@heat:server', 'state.sls', ['heat'], 1)
Marek Celoudfeb67062017-03-13 11:01:43 +0100347 salt.enforceState(saltMaster, 'I@heat:server and *01*', 'heat', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100348 salt.enforceState(saltMaster, 'I@heat:server', 'heat', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100349 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; heat resource-type-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100350
Marek Celoudec7c0a92017-03-23 11:01:35 +0100351 // Restart nova api
352 salt.runSaltProcessStep(saltMaster, 'I@nova:controller', 'service.restart', ['nova-api'])
353
Tomáš Kukrála18de112017-03-02 13:57:47 +0100354 }
355
356 stage('Install OpenStack network') {
357 //orchestrate.installOpenstackMkNetwork(saltMaster, physical)
358
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100359 if (common.checkContains('INSTALL', 'contrail')) {
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100360 // Install opencontrail database services
361 //runSaltProcessStep(saltMaster, 'I@opencontrail:database', 'state.sls', ['opencontrail.database'], 1)
Tomáš Kukrálf8ac03b2017-03-10 15:08:22 +0100362 try {
Marek Celoudfeb67062017-03-13 11:01:43 +0100363 salt.enforceState(saltMaster, 'I@opencontrail:database and *01*', 'opencontrail.database', true)
Tomáš Kukrál0dccc892017-03-10 15:42:44 +0100364 } catch (Exception e) {
Jakub Josefc7190602017-03-14 10:43:56 +0100365 common.warningMsg('Exception in state opencontrail.database on I@opencontrail:database and *01*')
Tomáš Kukrálf8ac03b2017-03-10 15:08:22 +0100366 }
367
368 try {
369 salt.enforceState(saltMaster, 'I@opencontrail:database', 'opencontrail.database', true)
Tomáš Kukrál0dccc892017-03-10 15:42:44 +0100370 } catch (Exception e) {
Jakub Josefc7190602017-03-14 10:43:56 +0100371 common.warningMsg('Exception in state opencontrail.database on I@opencontrail:database')
Tomáš Kukrálf8ac03b2017-03-10 15:08:22 +0100372 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100373
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100374 // Install opencontrail control services
375 //runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'state.sls', ['opencontrail'], 1)
Marek Celoud1a489a62017-03-14 13:46:41 +0100376 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control and *01*', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Marek Celoud1465b542017-03-14 12:28:38 +0100377 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
378 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100379
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100380 // Test opencontrail
381 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'cmd.run', ['contrail-status'], null, true)
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100382 } else if (common.checkContains('INSTALL', 'ovs')) {
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100383 // Apply gateway
384 salt.runSaltProcessStep(saltMaster, 'I@neutron:gateway', 'state.apply', [], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100385 }
386
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100387 // Pring information
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100388 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'], null, true)
389 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100390 }
391
392 stage('Install OpenStack compute') {
393 //orchestrate.installOpenstackMkCompute(saltMaster, physical)
394 // Configure compute nodes
Tomáš Kukrálda26d902017-03-02 22:19:00 +0100395 retry(2) {
Tomáš Kukrál02cda9f2017-03-02 22:32:57 +0100396 salt.runSaltProcessStep(saltMaster, 'I@nova:compute', 'state.apply', [], null, true)
Tomáš Kukrálda26d902017-03-02 22:19:00 +0100397 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100398
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100399 if (common.checkContains('INSTALL', 'contrail')) {
Marek Celoudfeb67062017-03-13 11:01:43 +0100400 // Provision opencontrail control services
401 salt.enforceState(saltMaster, 'I@opencontrail:database:id:1', 'opencontrail.client', true)
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100402 // Provision opencontrail virtual routers
Marek Celoudfeb67062017-03-13 11:01:43 +0100403 salt.enforceState(saltMaster, 'I@opencontrail:compute', 'opencontrail.client', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100404
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100405 salt.runSaltProcessStep(saltMaster, 'I@nova:compute', 'cmd.run', ['exec 0>&-; exec 1>&-; exec 2>&-; nohup bash -c "ip link | grep vhost && echo no_reboot || sleep 5 && reboot & "'], null, true)
406 sleep(300)
407 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100408 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100409
Tomáš Kukrál00ed1302017-03-03 17:38:40 +0100410 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100411
Tomáš Kukrál00ed1302017-03-03 17:38:40 +0100412
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100413 if (common.checkContains('INSTALL', 'stacklight')) {
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100414 stage('Install StackLight') {
415 // infra install
416 // Install the StackLight backends
417 salt.enforceState(saltMaster, '*01* and I@elasticsearch:server', 'elasticsearch.server', true)
418 salt.enforceState(saltMaster, 'I@elasticsearch:server', 'elasticsearch.server', true)
419
420 salt.enforceState(saltMaster, '*01* and I@influxdb:server', 'influxdb', true)
421 salt.enforceState(saltMaster, 'I@influxdb:server', 'influxdb', true)
422
423 salt.enforceState(saltMaster, '*01* and I@kibana:server', 'kibana.server', true)
424 salt.enforceState(saltMaster, 'I@kibana:server', 'kibana.server', true)
425
426 salt.enforceState(saltMaster, '*01* and I@grafana:server','grafana.server', true)
427 salt.enforceState(saltMaster, 'I@grafana:server','grafana.server', true)
428
429 salt.enforceState(saltMaster, 'I@nagios:server', 'nagios.server', true)
430 salt.enforceState(saltMaster, 'I@elasticsearch:client', 'elasticsearch.client.service', true)
431 salt.enforceState(saltMaster, 'I@kibana:client', 'kibana.client.service', true)
432 // nw salt.enforceState('I@kibana:client or I@elasticsearch:client' --async service.restart salt-minion
433
434 sleep(10)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100435
Marek Celoud3fd4ea92017-03-10 11:36:01 +0100436 salt.runSaltProcessStep(saltMaster, 'I@elasticsearch.client', 'cmd.run', ['salt-call state.sls elasticsearch.client'], null, true)
437 // salt.enforceState(saltMaster, 'I@elasticsearch:client', 'elasticsearch.client', true)
Marek Celoud481bc422017-03-10 12:13:19 +0100438 salt.runSaltProcessStep(saltMaster, 'I@kibana.client', 'cmd.run', ['salt-call state.sls kibana.client'], null, true)
439 // salt.enforceState(saltMaster, 'I@kibana:client', 'kibana.client', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100440
441 // install monitor
442 // Restart salt-minion to make sure that it uses the latest Jinja library
443 // no way: salt '*' --async service.restart salt-minion; sleep 15
444
445 // Start by flusing Salt Mine to make sure it is clean
446 // Also clean-up the grains files to make sure that we start from a clean state
447 // nw salt "*" mine.flush
448 // nw salt "*" file.remove /etc/salt/grains.d/collectd
449 // nw salt "*" file.remove /etc/salt/grains.d/grafana
450 // nw salt "*" file.remove /etc/salt/grains.d/heka
451 // nw salt "*" file.remove /etc/salt/grains.d/sensu
452 // nw salt "*" file.remove /etc/salt/grains
453
454 // Install collectd, heka and sensu services on the nodes, this will also
455 // generate the metadata that goes into the grains and eventually into Salt Mine
Tomáš Kukrál2aa3c472017-03-03 17:47:08 +0100456 salt.enforceState(saltMaster, '*', 'collectd', true)
Marek Celoudd6303412017-03-09 23:14:32 +0100457 salt.enforceState(saltMaster, '*', 'salt.minion', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100458 salt.enforceState(saltMaster, '*', 'heka', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100459
460 // Gather the Grafana metadata as grains
461 salt.enforceState(saltMaster, 'I@grafana:collector', 'grafana.collector', true)
462
463 // Update Salt Mine
464 salt.enforceState(saltMaster, '*', 'salt.minion.grains', true)
465 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_modules', [], null, true)
466 salt.runSaltProcessStep(saltMaster, '*', 'mine.update', [], null, true)
467
468 sleep(5)
469
470 // Update Heka
471 salt.enforceState(saltMaster, 'I@heka:aggregator:enabled:True or I@heka:remote_collector:enabled:True', 'heka', true)
472
473 // Update collectd
474 salt.enforceState(saltMaster, 'I@collectd:remote_client:enabled:True', 'collectd', true)
475
476 // Update Nagios
477 salt.enforceState(saltMaster, 'I@nagios:server', 'nagios', true)
478 // Stop the Nagios service because the package starts it by default and it will
479 // started later only on the node holding the VIP address
480 salt.runSaltProcessStep(saltMaster, 'I@nagios:server', 'service.stop', ['nagios3'], null, true)
481
482 // Update Sensu
Tomáš Kukrál1ef3da72017-03-06 14:44:00 +0100483 // TODO for stacklight team, should be fixed in model
484 //salt.enforceState(saltMaster, 'I@sensu:server', 'sensu', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100485
486 // Finalize the configuration of Grafana (add the dashboards...)
487 salt.enforceState(saltMaster, 'I@grafana:client', 'grafana.client.service', true)
488 // nw salt -C 'I@grafana:client' --async service.restart salt-minion; sleep 10
Marek Celouda613ed02017-03-10 15:39:55 +0100489
490 salt.runSaltProcessStep(saltMaster, 'I@grafana.client and *01*', 'cmd.run', ['salt-call state.sls grafana.client'], null, true)
491 // salt.enforceState(saltMaster, 'I@grafana:client and *01*', 'grafana.client', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100492
493 // Get the StackLight monitoring VIP addres
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100494 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
495 //vip=${vip:=172.16.10.253}
Tomáš Kukráledbb24c2017-03-10 16:10:29 +0100496 def pillar = salt.getPillar(saltMaster, 'ctl01*', '_param:stacklight_monitor_address')
Jakub Joseffafd6592017-03-27 18:53:17 +0200497 print(common.prettyPrint(pillar))
Tomáš Kukrálaae889a2017-03-22 13:37:34 +0100498 def stacklight_vip = pillar['return'][0].values()[0]
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100499
Tomáš Kukrálaae889a2017-03-22 13:37:34 +0100500 if (stacklight_vip) {
Tomáš Kukrál6412a8c2017-03-07 14:03:47 +0100501 // (re)Start manually the services that are bound to the monitoring VIP
Tomáš Kukrálaae889a2017-03-22 13:37:34 +0100502 common.infoMsg("restart services on node with IP: ${stacklight_vip}")
Tomáš Kukrál1b08c8c2017-03-07 16:51:49 +0100503 salt.runSaltProcessStep(saltMaster, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collectd'], null, true)
504 salt.runSaltProcessStep(saltMaster, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collector'], null, true)
505 salt.runSaltProcessStep(saltMaster, "G@ipv4:${stacklight_vip}", 'service.restart', ['aggregator'], null, true)
506 salt.runSaltProcessStep(saltMaster, "G@ipv4:${stacklight_vip}", 'service.restart', ['nagios3'], null, true)
Tomáš Kukrálaae889a2017-03-22 13:37:34 +0100507 } else {
508 throw new Exception("Missing stacklight_vip")
Tomáš Kukrál6412a8c2017-03-07 14:03:47 +0100509 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100510 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100511 }
512
Tomáš Kukrála18de112017-03-02 13:57:47 +0100513 //
514 // Test
515 //
516
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100517 if (common.checkContains('TEST', 'k8s')) {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100518 stage('Run k8s bootstrap tests') {
519 orchestrate.runConformanceTests(saltMaster, K8S_API_SERVER, 'tomkukral/k8s-scripts')
520 }
521
522 stage('Run k8s conformance e2e tests') {
523 orchestrate.runConformanceTests(saltMaster, K8S_API_SERVER, K8S_CONFORMANCE_IMAGE)
524 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100525 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100526
Tomáš Kukrál6d627d62017-03-23 17:39:07 +0100527 if (common.checkContains('TEST', 'openstack')) {
Victor Ryzhenkin5f3b7e62017-03-09 16:02:58 +0400528 stage('Run OpenStack tests') {
529 test.runTempestTests(saltMaster, TEMPEST_IMAGE_LINK)
530 }
531
532 stage('Copy Tempest results to config node') {
533 test.copyTempestResults(saltMaster)
534 }
535 }
536
Tomáš Kukrál420d7ff2017-03-21 11:38:33 +0100537 stage('Finalize') {
538 try {
539 salt.runSaltProcessStep(saltMaster, '*', 'state.apply', [], null, true)
540 } catch (Exception e) {
541 common.warningMsg('State apply failed but we should continue to run')
542 }
543 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100544 } catch (Throwable e) {
545 currentBuild.result = 'FAILURE'
546 throw e
Tomáš Kukrál65fb5fd2017-03-02 14:56:49 +0100547 } finally {
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100548
Tomáš Kukrál96b12d52017-03-07 22:43:37 +0100549
Tomáš Kukrála18de112017-03-02 13:57:47 +0100550 //
551 // Clean
552 //
553
Tomáš Kukrálc9a630a2017-03-07 17:28:53 +0100554 if (STACK_TYPE == 'heat') {
Tomáš Kukrál4507c6a2017-03-23 19:00:39 +0100555 // send notification
556 common.sendNotification(currentBuild.result, HEAT_STACK_NAME, ["slack"])
557
Tomáš Kukrálc9a630a2017-03-07 17:28:53 +0100558 if (HEAT_STACK_DELETE.toBoolean() == true) {
559 common.errorMsg('Heat job cleanup triggered')
560 stage('Trigger cleanup job') {
561 build job: 'deploy-heat-cleanup', parameters: [[$class: 'StringParameterValue', name: 'HEAT_STACK_NAME', value: HEAT_STACK_NAME]]
562 }
563 } else {
Tomáš Kukrálbcc53ea2017-03-08 08:15:57 +0100564 if (currentBuild.result == 'FAILURE') {
565 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 +0100566
Tomáš Kukrálbcc53ea2017-03-08 08:15:57 +0100567 if (SALT_MASTER_URL) {
568 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
569 }
Tomáš Kukrálb908dac2017-03-07 18:58:35 +0100570 }
571
Tomáš Kukrála18de112017-03-02 13:57:47 +0100572 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100573 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100574 }
575 }
576}