blob: a6efaca57c58fb277b43ea228296f349582af1f8 [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') {
53 if (STACK_TYPE == 'heat') {
54 // value defaults
55 def openstackCloud
56 def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty'
57 def openstackEnv = "${env.WORKSPACE}/venv"
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010058
Filip Pytloun794ad952017-03-03 10:39:26 +010059 if (HEAT_STACK_REUSE.toBoolean() == true && HEAT_STACK_NAME == '') {
60 error("If you want to reuse existing stack you need to provide it's name")
61 }
62
63 if (HEAT_STACK_REUSE.toBoolean() == false) {
64 // Don't allow to set custom heat stack name
65 wrap([$class: 'BuildUser']) {
Tomáš Kukrál24d7fe62017-03-03 10:57:11 +010066 if (env.BUILD_USER_ID) {
67 HEAT_STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
68 } else {
69 HEAT_STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
70 }
Filip Pytloun794ad952017-03-03 10:39:26 +010071 currentBuild.description = HEAT_STACK_NAME
72 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +010073 }
Tomáš Kukrála18de112017-03-02 13:57:47 +010074
Tomáš Kukrálcbabec42017-03-02 16:24:04 +010075 // set description
Tomáš Kukrálaeb5c922017-03-02 17:00:48 +010076 currentBuild.description = "${HEAT_STACK_NAME}"
Tomáš Kukrálcbabec42017-03-02 16:24:04 +010077
Tomáš Kukrála18de112017-03-02 13:57:47 +010078 // get templates
79 git.checkoutGitRepository('template', HEAT_TEMPLATE_URL, HEAT_TEMPLATE_BRANCH, HEAT_TEMPLATE_CREDENTIALS)
80
81 // create openstack env
82 openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion)
83 openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT)
84 openstack.getKeystoneToken(openstackCloud, openstackEnv)
85
86 // launch stack
Filip Pytloun794ad952017-03-03 10:39:26 +010087 if (HEAT_STACK_REUSE.toBoolean() == false) {
Tomáš Kukrála18de112017-03-02 13:57:47 +010088 stage('Launch new Heat stack') {
89 // create stack
90 envParams = [
91 'instance_zone': HEAT_STACK_ZONE,
92 'public_net': HEAT_STACK_PUBLIC_NET
93 ]
94 openstack.createHeatStack(openstackCloud, HEAT_STACK_NAME, HEAT_STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, openstackEnv)
95 }
96 }
97
98 // get SALT_MASTER_URL
99 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, HEAT_STACK_NAME, 'salt_master_ip', openstackEnv)
Tomáš Kukrálaeb5c922017-03-02 17:00:48 +0100100 currentBuild.description = "${HEAT_STACK_NAME}: ${saltMasterHost}"
Tomáš Kukrál615aa9c2017-03-04 15:29:08 +0100101
102 if (INSTALL.toLowerCase().contains('kvm')) {
Marek Celoud5e442a32017-03-16 10:15:53 +0100103 saltPort = 6969
Tomáš Kukrál615aa9c2017-03-04 15:29:08 +0100104 } else {
Marek Celoud5e442a32017-03-16 10:15:53 +0100105 saltPort = 6969
Tomáš Kukrál615aa9c2017-03-04 15:29:08 +0100106 }
107
Tomáš Kukrál61509292017-03-04 16:27:07 +0100108 SALT_MASTER_URL = "http://${saltMasterHost}:${saltPort}"
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100109 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100110 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100111
Tomáš Kukrála18de112017-03-02 13:57:47 +0100112 //
113 // Connect to Salt master
114 //
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100115
Tomáš Kukrála18de112017-03-02 13:57:47 +0100116 def saltMaster
117 stage('Connect to Salt API') {
118 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
119 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100120
Tomáš Kukrála18de112017-03-02 13:57:47 +0100121 //
122 // Install
123 //
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100124
Tomáš Kukrála18de112017-03-02 13:57:47 +0100125 if (INSTALL.toLowerCase().contains('core')) {
126 stage('Install core infrastructure') {
127 // salt.master, reclass
128 // refresh_pillar
129 // sync_all
130 // linux,openssh,salt.minion.ntp
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100131
Tomáš Kukrála18de112017-03-02 13:57:47 +0100132 //orchestrate.installFoundationInfra(saltMaster)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100133 salt.enforceState(saltMaster, 'I@salt:master', ['salt.master', 'reclass'], true)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100134 salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.refresh_pillar', [], null, true)
135 salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.sync_all', [], null, true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100136 salt.enforceState(saltMaster, 'I@linux:system', ['linux', 'openssh', 'salt.minion', 'ntp'], true)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100137
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100138
Tomáš Kukrála18de112017-03-02 13:57:47 +0100139 if (INSTALL.toLowerCase().contains('kvm')) {
140 //orchestrate.installInfraKvm(saltMaster)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100141 salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.refresh_pillar', [], null, true)
142 salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.sync_all', [], null, true)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100143
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100144 salt.enforceState(saltMaster, 'I@salt:control', ['salt.minion', 'linux.system', 'linux.network', 'ntp'], true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100145 salt.enforceState(saltMaster, 'I@salt:control', 'libvirt', true)
146 salt.enforceState(saltMaster, 'I@salt:control', 'salt.control', true)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100147
Tomáš Kukrál3e5c5bf2017-03-09 16:45:54 +0100148 sleep(600)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100149
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100150 salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'saltutil.refresh_pillar', [], null, true)
151 salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'saltutil.sync_all', [], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100152
153 // workaround - install apt-transport-https
Tomáš Kukrálbe9dfa52017-03-08 13:54:03 +0100154 //salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'cmd.run', ['apt-get update -y && apt-get install -y apt-transport-https'], null, true)
155 //salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'pkg.install', ['apt-transport-https', 'refresh=True'], null, true)
Marek Celoudce2a28b2017-03-13 17:11:30 +0100156 salt.enforceState(saltMaster, 'I@linux:system', ['linux', 'salt.minion'], true, false)
157 salt.enforceState(saltMaster, 'I@linux:system', ['openssh', 'salt.minion', 'ntp'], true, false)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100158 }
159
160 //orchestrate.validateFoundationInfra(saltMaster)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100161 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'cmd.run', ['salt-key'], null, true)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100162 salt.runSaltProcessStep(saltMaster, 'I@salt:minion', 'test.version', [], null, true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100163 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'cmd.run', ['reclass-salt --top'], null, true)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100164 salt.runSaltProcessStep(saltMaster, 'I@reclass:storage', 'reclass.inventory', [], null, true)
165 salt.runSaltProcessStep(saltMaster, 'I@salt:minion', 'state.show_top', [], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100166 }
167 }
168
169 // install k8s
170 if (INSTALL.toLowerCase().contains('k8s')) {
171 stage('Install Kubernetes infra') {
172 //orchestrate.installOpenstackMcpInfra(saltMaster)
173
174 // Comment nameserver
175 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"])
176
177 // Install glusterfs
178 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.service'])
179
180 // Install keepalived
Marek Celoudfeb67062017-03-13 11:01:43 +0100181 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster and *01*', 'state.sls', ['keepalived'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100182 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'state.sls', ['keepalived'])
183
184 // Check the keepalived VIPs
185 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
186
187 // Setup glusterfs
Marek Celoudfeb67062017-03-13 11:01:43 +0100188 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server and *01*', 'state.sls', ['glusterfs.server.setup'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100189 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'])
190 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'])
191
192 // Install haproxy
193 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'state.sls', ['haproxy'])
194 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.status', ['haproxy'])
195
196 // Install docker
197 salt.runSaltProcessStep(saltMaster, 'I@docker:host', 'state.sls', ['docker.host'])
198 salt.runSaltProcessStep(saltMaster, 'I@docker:host', 'cmd.run', ['docker ps'])
199
200 // Install bird
201 salt.runSaltProcessStep(saltMaster, 'I@bird:server', 'state.sls', ['bird'])
202
203 // Install etcd
204 salt.runSaltProcessStep(saltMaster, 'I@etcd:server', 'state.sls', ['etcd.server.service'])
205 salt.runSaltProcessStep(saltMaster, 'I@etcd:server', 'cmd.run', ['etcdctl cluster-health'])
206
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100207 }
208
Tomáš Kukrála18de112017-03-02 13:57:47 +0100209 stage('Install Kubernetes control') {
210 //orchestrate.installOpenstackMcpControl(saltMaster)
Tomáš Kukrál06c27a92017-03-01 16:21:46 +0100211
Tomáš Kukrála18de112017-03-02 13:57:47 +0100212 // Install Kubernetes pool and Calico
213 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:pool', 'state.sls', ['kubernetes.pool'])
214 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:pool', 'cmd.run', ['calicoctl node status'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100215
Tomáš Kukrála18de112017-03-02 13:57:47 +0100216 // Setup etcd server
217 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:master', 'state.sls', ['etcd.server.setup'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100218
Tomáš Kukrála18de112017-03-02 13:57:47 +0100219 // Run k8s without master.setup
220 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:master', 'state.sls', ['kubernetes', 'exclude=kubernetes.master.setup'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100221
Tomáš Kukrála18de112017-03-02 13:57:47 +0100222 // Run k8s master setup
Marek Celoudfeb67062017-03-13 11:01:43 +0100223 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:master and *01*', 'state.sls', ['kubernetes.master.setup'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100224
Tomáš Kukrála18de112017-03-02 13:57:47 +0100225 // Revert comment nameserver
226 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 +0100227
Tomáš Kukrála18de112017-03-02 13:57:47 +0100228 // Set route
229 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 +0100230
Tomáš Kukrála18de112017-03-02 13:57:47 +0100231 // Restart kubelet
232 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:pool', 'service.restart', ['kubelet'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100233 }
234
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100235 }
236
Tomáš Kukrála18de112017-03-02 13:57:47 +0100237 // install openstack
238 if (INSTALL.toLowerCase().contains('openstack')) {
239 // install Infra and control, tests, ...
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100240
Tomáš Kukrála18de112017-03-02 13:57:47 +0100241 stage('Install OpenStack infra') {
242 //orchestrate.installOpenstackMkInfra(saltMaster, physical)
243
Marek Celoud8db985f2017-03-14 17:41:19 +0100244 // Install glusterfs
245 salt.enforceState(saltMaster, 'I@glusterfs:server', 'glusterfs.server.service', true)
246
Tomáš Kukrála18de112017-03-02 13:57:47 +0100247 // Install keepaliveds
248 //runSaltProcessStep(master, 'I@keepalived:cluster', 'state.sls', ['keepalived'], 1)
Marek Celoudfeb67062017-03-13 11:01:43 +0100249 salt.enforceState(saltMaster, 'I@keepalived:cluster and *01*', 'keepalived', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100250 salt.enforceState(saltMaster, 'I@keepalived:cluster', 'keepalived', true)
251
252 // Check the keepalived VIPs
253 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
254
Marek Celoudfeb67062017-03-13 11:01:43 +0100255 salt.enforceState(saltMaster, 'I@glusterfs:server and *01*', 'glusterfs.server.setup', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100256
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100257 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'], null, true)
258 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100259
260 // Install rabbitmq
Marek Celoud1465b542017-03-14 12:28:38 +0100261 salt.enforceState(saltMaster, 'I@rabbitmq:server', 'rabbitmq', true, false)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100262
263 // Check the rabbitmq status
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100264 salt.runSaltProcessStep(saltMaster, 'I@rabbitmq:server', 'cmd.run', ['rabbitmqctl cluster_status'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100265
266 // Install galera
Marek Celoud7c84ef72017-03-15 17:32:32 +0100267 retry(2) {
268 salt.enforceState(saltMaster, 'I@galera:master', 'galera', true)
269 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100270 salt.enforceState(saltMaster, 'I@galera:slave', 'galera', true)
271
272 // Check galera status
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100273 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'mysql.status')
274 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'mysql.status')
Tomáš Kukrála18de112017-03-02 13:57:47 +0100275
Marek Celoudcabe5642017-03-15 18:16:38 +0100276 // // Setup mysql client
277 // salt.enforceState(saltMaster, 'I@mysql:client', 'mysql.client', true)
Tomáš Kukrálaa8f5532017-03-07 13:34:39 +0100278
Tomáš Kukrála18de112017-03-02 13:57:47 +0100279 // Install haproxy
280 salt.enforceState(saltMaster, 'I@haproxy:proxy', 'haproxy', true)
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100281 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.status', ['haproxy'])
282 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.restart', ['rsyslog'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100283
284 // Install memcached
285 salt.enforceState(saltMaster, 'I@memcached:server', 'memcached', true)
286
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100287 }
288
Tomáš Kukrála18de112017-03-02 13:57:47 +0100289 stage('Install OpenStack control') {
290 //orchestrate.installOpenstackMkControl(saltMaster)
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100291
Marek Celoud36d24b62017-03-21 15:07:07 +0100292 // Install horizon dashboard
293 salt.enforceState(saltMaster, 'I@horizon:server', 'horizon', true)
294 salt.enforceState(saltMaster, 'I@nginx:server', 'nginx', true)
295
Tomáš Kukrála18de112017-03-02 13:57:47 +0100296 // setup keystone service
297 //runSaltProcessStep(saltMaster, 'I@keystone:server', 'state.sls', ['keystone.server'], 1)
Marek Celoudfeb67062017-03-13 11:01:43 +0100298 salt.enforceState(saltMaster, 'I@keystone:server and *01*', 'keystone.server', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100299 salt.enforceState(saltMaster, 'I@keystone:server', 'keystone.server', true)
300 // populate keystone services/tenants/roles/users
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100301
Tomáš Kukrála18de112017-03-02 13:57:47 +0100302 // keystone:client must be called locally
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100303 salt.runSaltProcessStep(saltMaster, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
304 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; keystone service-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100305
306 // Install glance and ensure glusterfs clusters
307 //runSaltProcessStep(saltMaster, 'I@glance:server', 'state.sls', ['glance.server'], 1)
Marek Celoudfeb67062017-03-13 11:01:43 +0100308 salt.enforceState(saltMaster, 'I@glance:server and *01*', 'glance.server', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100309 salt.enforceState(saltMaster, 'I@glance:server', 'glance.server', true)
310 salt.enforceState(saltMaster, 'I@glance:server', 'glusterfs.client', true)
311
312 // Update fernet tokens before doing request on keystone server
313 salt.enforceState(saltMaster, 'I@keystone:server', 'keystone.server', true)
314
315 // Check glance service
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100316 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; glance image-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100317
318 // Install and check nova service
319 //runSaltProcessStep(saltMaster, 'I@nova:controller', 'state.sls', ['nova'], 1)
Marek Celoud396ba542017-03-21 11:02:50 +0100320 salt.enforceState(saltMaster, 'I@nova:controller and *01*', 'nova.controller', true)
321 salt.enforceState(saltMaster, 'I@nova:controller', 'nova.controller', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100322 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova service-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100323
324 // Install and check cinder service
325 //runSaltProcessStep(saltMaster, 'I@cinder:controller', 'state.sls', ['cinder'], 1)
Marek Celoudfeb67062017-03-13 11:01:43 +0100326 salt.enforceState(saltMaster, 'I@cinder:controller and *01*', 'cinder', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100327 salt.enforceState(saltMaster, 'I@cinder:controller', 'cinder', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100328 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; cinder list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100329
330 // Install neutron service
331 //runSaltProcessStep(saltMaster, 'I@neutron:server', 'state.sls', ['neutron'], 1)
Tomáš Kukrál575e38a2017-03-02 17:12:45 +0100332
Marek Celoud396ba542017-03-21 11:02:50 +0100333 salt.enforceState(saltMaster, 'I@neutron:server and *01*', 'neutron.server', true)
334 salt.enforceState(saltMaster, 'I@neutron:server', 'neutron.server', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100335 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron agent-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100336
337 // Install heat service
338 //runSaltProcessStep(saltMaster, 'I@heat:server', 'state.sls', ['heat'], 1)
Marek Celoudfeb67062017-03-13 11:01:43 +0100339 salt.enforceState(saltMaster, 'I@heat:server and *01*', 'heat', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100340 salt.enforceState(saltMaster, 'I@heat:server', 'heat', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100341 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; heat resource-type-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100342
Marek Celoudec7c0a92017-03-23 11:01:35 +0100343 // Restart nova api
344 salt.runSaltProcessStep(saltMaster, 'I@nova:controller', 'service.restart', ['nova-api'])
345
Tomáš Kukrála18de112017-03-02 13:57:47 +0100346 }
347
348 stage('Install OpenStack network') {
349 //orchestrate.installOpenstackMkNetwork(saltMaster, physical)
350
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100351 if (INSTALL.toLowerCase().contains('contrail')) {
352 // Install opencontrail database services
353 //runSaltProcessStep(saltMaster, 'I@opencontrail:database', 'state.sls', ['opencontrail.database'], 1)
Tomáš Kukrálf8ac03b2017-03-10 15:08:22 +0100354 try {
Marek Celoudfeb67062017-03-13 11:01:43 +0100355 salt.enforceState(saltMaster, 'I@opencontrail:database and *01*', 'opencontrail.database', true)
Tomáš Kukrál0dccc892017-03-10 15:42:44 +0100356 } catch (Exception e) {
Jakub Josefc7190602017-03-14 10:43:56 +0100357 common.warningMsg('Exception in state opencontrail.database on I@opencontrail:database and *01*')
Tomáš Kukrálf8ac03b2017-03-10 15:08:22 +0100358 }
359
360 try {
361 salt.enforceState(saltMaster, 'I@opencontrail:database', 'opencontrail.database', true)
Tomáš Kukrál0dccc892017-03-10 15:42:44 +0100362 } catch (Exception e) {
Jakub Josefc7190602017-03-14 10:43:56 +0100363 common.warningMsg('Exception in state opencontrail.database on I@opencontrail:database')
Tomáš Kukrálf8ac03b2017-03-10 15:08:22 +0100364 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100365
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100366 // Install opencontrail control services
367 //runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'state.sls', ['opencontrail'], 1)
Marek Celoud1a489a62017-03-14 13:46:41 +0100368 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control and *01*', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Marek Celoud1465b542017-03-14 12:28:38 +0100369 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
370 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100371
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100372 // Test opencontrail
373 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'cmd.run', ['contrail-status'], null, true)
374 } else if (INSTALL.toLowerCase().contains('ovs')) {
375 // Apply gateway
376 salt.runSaltProcessStep(saltMaster, 'I@neutron:gateway', 'state.apply', [], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100377 }
378
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100379 // Pring information
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100380 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'], null, true)
381 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100382 }
383
384 stage('Install OpenStack compute') {
385 //orchestrate.installOpenstackMkCompute(saltMaster, physical)
386 // Configure compute nodes
Tomáš Kukrálda26d902017-03-02 22:19:00 +0100387 retry(2) {
Tomáš Kukrál02cda9f2017-03-02 22:32:57 +0100388 salt.runSaltProcessStep(saltMaster, 'I@nova:compute', 'state.apply', [], null, true)
Tomáš Kukrálda26d902017-03-02 22:19:00 +0100389 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100390
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100391 if (INSTALL.toLowerCase().contains('contrail')) {
Marek Celoudfeb67062017-03-13 11:01:43 +0100392 // Provision opencontrail control services
393 salt.enforceState(saltMaster, 'I@opencontrail:database:id:1', 'opencontrail.client', true)
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100394 // Provision opencontrail virtual routers
Marek Celoudfeb67062017-03-13 11:01:43 +0100395 salt.enforceState(saltMaster, 'I@opencontrail:compute', 'opencontrail.client', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100396
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100397 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)
398 sleep(300)
399 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100400 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100401
Tomáš Kukrál00ed1302017-03-03 17:38:40 +0100402 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100403
Tomáš Kukrál00ed1302017-03-03 17:38:40 +0100404
405 if (INSTALL.toLowerCase().contains('stacklight')) {
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100406 stage('Install StackLight') {
407 // infra install
408 // Install the StackLight backends
409 salt.enforceState(saltMaster, '*01* and I@elasticsearch:server', 'elasticsearch.server', true)
410 salt.enforceState(saltMaster, 'I@elasticsearch:server', 'elasticsearch.server', true)
411
412 salt.enforceState(saltMaster, '*01* and I@influxdb:server', 'influxdb', true)
413 salt.enforceState(saltMaster, 'I@influxdb:server', 'influxdb', true)
414
415 salt.enforceState(saltMaster, '*01* and I@kibana:server', 'kibana.server', true)
416 salt.enforceState(saltMaster, 'I@kibana:server', 'kibana.server', true)
417
418 salt.enforceState(saltMaster, '*01* and I@grafana:server','grafana.server', true)
419 salt.enforceState(saltMaster, 'I@grafana:server','grafana.server', true)
420
421 salt.enforceState(saltMaster, 'I@nagios:server', 'nagios.server', true)
422 salt.enforceState(saltMaster, 'I@elasticsearch:client', 'elasticsearch.client.service', true)
423 salt.enforceState(saltMaster, 'I@kibana:client', 'kibana.client.service', true)
424 // nw salt.enforceState('I@kibana:client or I@elasticsearch:client' --async service.restart salt-minion
425
426 sleep(10)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100427
Marek Celoud3fd4ea92017-03-10 11:36:01 +0100428 salt.runSaltProcessStep(saltMaster, 'I@elasticsearch.client', 'cmd.run', ['salt-call state.sls elasticsearch.client'], null, true)
429 // salt.enforceState(saltMaster, 'I@elasticsearch:client', 'elasticsearch.client', true)
Marek Celoud481bc422017-03-10 12:13:19 +0100430 salt.runSaltProcessStep(saltMaster, 'I@kibana.client', 'cmd.run', ['salt-call state.sls kibana.client'], null, true)
431 // salt.enforceState(saltMaster, 'I@kibana:client', 'kibana.client', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100432
433 // install monitor
434 // Restart salt-minion to make sure that it uses the latest Jinja library
435 // no way: salt '*' --async service.restart salt-minion; sleep 15
436
437 // Start by flusing Salt Mine to make sure it is clean
438 // Also clean-up the grains files to make sure that we start from a clean state
439 // nw salt "*" mine.flush
440 // nw salt "*" file.remove /etc/salt/grains.d/collectd
441 // nw salt "*" file.remove /etc/salt/grains.d/grafana
442 // nw salt "*" file.remove /etc/salt/grains.d/heka
443 // nw salt "*" file.remove /etc/salt/grains.d/sensu
444 // nw salt "*" file.remove /etc/salt/grains
445
446 // Install collectd, heka and sensu services on the nodes, this will also
447 // generate the metadata that goes into the grains and eventually into Salt Mine
Tomáš Kukrál2aa3c472017-03-03 17:47:08 +0100448 salt.enforceState(saltMaster, '*', 'collectd', true)
Marek Celoudd6303412017-03-09 23:14:32 +0100449 salt.enforceState(saltMaster, '*', 'salt.minion', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100450 salt.enforceState(saltMaster, '*', 'heka', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100451
452 // Gather the Grafana metadata as grains
453 salt.enforceState(saltMaster, 'I@grafana:collector', 'grafana.collector', true)
454
455 // Update Salt Mine
456 salt.enforceState(saltMaster, '*', 'salt.minion.grains', true)
457 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_modules', [], null, true)
458 salt.runSaltProcessStep(saltMaster, '*', 'mine.update', [], null, true)
459
460 sleep(5)
461
462 // Update Heka
463 salt.enforceState(saltMaster, 'I@heka:aggregator:enabled:True or I@heka:remote_collector:enabled:True', 'heka', true)
464
465 // Update collectd
466 salt.enforceState(saltMaster, 'I@collectd:remote_client:enabled:True', 'collectd', true)
467
468 // Update Nagios
469 salt.enforceState(saltMaster, 'I@nagios:server', 'nagios', true)
470 // Stop the Nagios service because the package starts it by default and it will
471 // started later only on the node holding the VIP address
472 salt.runSaltProcessStep(saltMaster, 'I@nagios:server', 'service.stop', ['nagios3'], null, true)
473
474 // Update Sensu
Tomáš Kukrál1ef3da72017-03-06 14:44:00 +0100475 // TODO for stacklight team, should be fixed in model
476 //salt.enforceState(saltMaster, 'I@sensu:server', 'sensu', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100477
478 // Finalize the configuration of Grafana (add the dashboards...)
479 salt.enforceState(saltMaster, 'I@grafana:client', 'grafana.client.service', true)
480 // nw salt -C 'I@grafana:client' --async service.restart salt-minion; sleep 10
Marek Celouda613ed02017-03-10 15:39:55 +0100481
482 salt.runSaltProcessStep(saltMaster, 'I@grafana.client and *01*', 'cmd.run', ['salt-call state.sls grafana.client'], null, true)
483 // salt.enforceState(saltMaster, 'I@grafana:client and *01*', 'grafana.client', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100484
485 // Get the StackLight monitoring VIP addres
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100486 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
487 //vip=${vip:=172.16.10.253}
Tomáš Kukráledbb24c2017-03-10 16:10:29 +0100488 def pillar = salt.getPillar(saltMaster, 'ctl01*', '_param:stacklight_monitor_address')
Jakub Joseffafd6592017-03-27 18:53:17 +0200489 print(common.prettyPrint(pillar))
Tomáš Kukrálaae889a2017-03-22 13:37:34 +0100490 def stacklight_vip = pillar['return'][0].values()[0]
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100491
Tomáš Kukrálaae889a2017-03-22 13:37:34 +0100492 if (stacklight_vip) {
Tomáš Kukrál6412a8c2017-03-07 14:03:47 +0100493 // (re)Start manually the services that are bound to the monitoring VIP
Tomáš Kukrálaae889a2017-03-22 13:37:34 +0100494 common.infoMsg("restart services on node with IP: ${stacklight_vip}")
Tomáš Kukrál1b08c8c2017-03-07 16:51:49 +0100495 salt.runSaltProcessStep(saltMaster, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collectd'], null, true)
496 salt.runSaltProcessStep(saltMaster, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collector'], null, true)
497 salt.runSaltProcessStep(saltMaster, "G@ipv4:${stacklight_vip}", 'service.restart', ['aggregator'], null, true)
498 salt.runSaltProcessStep(saltMaster, "G@ipv4:${stacklight_vip}", 'service.restart', ['nagios3'], null, true)
Tomáš Kukrálaae889a2017-03-22 13:37:34 +0100499 } else {
500 throw new Exception("Missing stacklight_vip")
Tomáš Kukrál6412a8c2017-03-07 14:03:47 +0100501 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100502 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100503 }
504
Tomáš Kukrála18de112017-03-02 13:57:47 +0100505 //
506 // Test
507 //
508
509 if (TEST.toLowerCase().contains('k8s')) {
510 stage('Run k8s bootstrap tests') {
511 orchestrate.runConformanceTests(saltMaster, K8S_API_SERVER, 'tomkukral/k8s-scripts')
512 }
513
514 stage('Run k8s conformance e2e tests') {
515 orchestrate.runConformanceTests(saltMaster, K8S_API_SERVER, K8S_CONFORMANCE_IMAGE)
516 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100517 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100518
Victor Ryzhenkin5f3b7e62017-03-09 16:02:58 +0400519 if (TEST.toLowerCase().contains('openstack')) {
520 stage('Run OpenStack tests') {
521 test.runTempestTests(saltMaster, TEMPEST_IMAGE_LINK)
522 }
523
524 stage('Copy Tempest results to config node') {
525 test.copyTempestResults(saltMaster)
526 }
527 }
528
Tomáš Kukrál420d7ff2017-03-21 11:38:33 +0100529 stage('Finalize') {
530 try {
531 salt.runSaltProcessStep(saltMaster, '*', 'state.apply', [], null, true)
532 } catch (Exception e) {
533 common.warningMsg('State apply failed but we should continue to run')
534 }
535 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100536 } catch (Throwable e) {
537 currentBuild.result = 'FAILURE'
538 throw e
Tomáš Kukrál65fb5fd2017-03-02 14:56:49 +0100539 } finally {
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100540
Tomáš Kukrál96b12d52017-03-07 22:43:37 +0100541 // send notification
542 common.sendNotification(currentBuild.result,HEAT_STACK_NAME,["slack"])
543
Tomáš Kukrála18de112017-03-02 13:57:47 +0100544 //
545 // Clean
546 //
547
Tomáš Kukrálc9a630a2017-03-07 17:28:53 +0100548 if (STACK_TYPE == 'heat') {
549 if (HEAT_STACK_DELETE.toBoolean() == true) {
550 common.errorMsg('Heat job cleanup triggered')
551 stage('Trigger cleanup job') {
552 build job: 'deploy-heat-cleanup', parameters: [[$class: 'StringParameterValue', name: 'HEAT_STACK_NAME', value: HEAT_STACK_NAME]]
553 }
554 } else {
Tomáš Kukrálbcc53ea2017-03-08 08:15:57 +0100555 if (currentBuild.result == 'FAILURE') {
556 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 +0100557
Tomáš Kukrálbcc53ea2017-03-08 08:15:57 +0100558 if (SALT_MASTER_URL) {
559 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
560 }
Tomáš Kukrálb908dac2017-03-07 18:58:35 +0100561 }
562
Tomáš Kukrála18de112017-03-02 13:57:47 +0100563 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100564 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100565 }
566 }
567}