blob: 297cf9b67d52e2616f7513bcfe0797cb8a8bc012 [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 *
36 */
37
38git = new com.mirantis.mk.Git()
39openstack = new com.mirantis.mk.Openstack()
40salt = new com.mirantis.mk.Salt()
Tomáš Kukrál3e4029d2017-03-07 09:59:40 +010041common = new com.mirantis.mk.Common()
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010042
Tomáš Kukrále80680a2017-03-02 16:34:35 +010043
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +010044timestamps {
45 node {
Tomáš Kukrála18de112017-03-02 13:57:47 +010046 try {
Tomáš Kukrále80680a2017-03-02 16:34:35 +010047
48
Tomáš Kukrála18de112017-03-02 13:57:47 +010049 //
50 // Prepare machines
51 //
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010052
Tomáš Kukrála18de112017-03-02 13:57:47 +010053 stage ('Create infrastructure') {
54 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
103 if (INSTALL.toLowerCase().contains('kvm')) {
Tomáš Kukrál61509292017-03-04 16:27:07 +0100104 saltPort = 8088
Tomáš Kukrál615aa9c2017-03-04 15:29:08 +0100105 } else {
Tomáš Kukrál61509292017-03-04 16:27:07 +0100106 saltPort = 8000
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ála18de112017-03-02 13:57:47 +0100126 if (INSTALL.toLowerCase().contains('core')) {
127 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)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100135 salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.refresh_pillar', [], null, true)
136 salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.sync_all', [], null, true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100137 salt.enforceState(saltMaster, 'I@linux:system', ['linux', 'openssh', 'salt.minion', 'ntp'], true)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100138
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100139
Tomáš Kukrála18de112017-03-02 13:57:47 +0100140 if (INSTALL.toLowerCase().contains('kvm')) {
141 //orchestrate.installInfraKvm(saltMaster)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100142 salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.refresh_pillar', [], null, true)
143 salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.sync_all', [], null, true)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100144
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100145 salt.enforceState(saltMaster, 'I@salt:control', ['salt.minion', 'linux.system', 'linux.network', 'ntp'], true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100146 salt.enforceState(saltMaster, 'I@salt:control', 'libvirt', true)
147 salt.enforceState(saltMaster, 'I@salt:control', 'salt.control', true)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100148
Tomáš Kukrála18de112017-03-02 13:57:47 +0100149 sleep(300)
150
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100151 salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'saltutil.refresh_pillar', [], null, true)
152 salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'saltutil.sync_all', [], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100153
154 // workaround - install apt-transport-https
Tomáš Kukrálbe9dfa52017-03-08 13:54:03 +0100155 //salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'cmd.run', ['apt-get update -y && apt-get install -y apt-transport-https'], null, true)
156 //salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'pkg.install', ['apt-transport-https', 'refresh=True'], null, true)
157 salt.enforceState(saltMaster, 'I@linux:system', ['linux', 'salt.minion'], true)
158 salt.enforceState(saltMaster, 'I@linux:system', ['openssh', 'salt.minion', 'ntp'], true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100159 }
160
161 //orchestrate.validateFoundationInfra(saltMaster)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100162 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'cmd.run', ['salt-key'], null, true)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100163 salt.runSaltProcessStep(saltMaster, 'I@salt:minion', 'test.version', [], null, true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100164 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'cmd.run', ['reclass-salt --top'], null, true)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100165 salt.runSaltProcessStep(saltMaster, 'I@reclass:storage', 'reclass.inventory', [], null, true)
166 salt.runSaltProcessStep(saltMaster, 'I@salt:minion', 'state.show_top', [], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100167 }
168 }
169
170 // install k8s
171 if (INSTALL.toLowerCase().contains('k8s')) {
172 stage('Install Kubernetes infra') {
173 //orchestrate.installOpenstackMcpInfra(saltMaster)
174
175 // Comment nameserver
176 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"])
177
178 // Install glusterfs
179 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.service'])
180
181 // Install keepalived
182 salt.runSaltProcessStep(saltMaster, 'ctl01*', 'state.sls', ['keepalived'])
183 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'state.sls', ['keepalived'])
184
185 // Check the keepalived VIPs
186 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
187
188 // Setup glusterfs
189 salt.runSaltProcessStep(saltMaster, 'ctl01*', 'state.sls', ['glusterfs.server.setup'])
190 salt.runSaltProcessStep(saltMaster, 'ctl02*', 'state.sls', ['glusterfs.server.setup'])
191 salt.runSaltProcessStep(saltMaster, 'ctl03*', 'state.sls', ['glusterfs.server.setup'])
192 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
226 salt.runSaltProcessStep(saltMaster, 'ctl01*', '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
241 if (INSTALL.toLowerCase().contains('openstack')) {
242 // 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
247 // Install keepaliveds
248 //runSaltProcessStep(master, 'I@keepalived:cluster', 'state.sls', ['keepalived'], 1)
249 salt.enforceState(saltMaster, 'ctl01*', 'keepalived', true)
250 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
255 // Install glusterfs
256 salt.enforceState(saltMaster, 'I@glusterfs:server', 'glusterfs.server.service', true)
257
258 //runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.setup'], 1)
259 if (INSTALL.toLowerCase().contains('kvm')) {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100260 salt.enforceState(saltMaster, 'kvm01*', 'glusterfs.server.setup', true)
261 salt.enforceState(saltMaster, 'kvm02*', 'glusterfs.server.setup', true)
262 salt.enforceState(saltMaster, 'kvm03*', 'glusterfs.server.setup', true)
Tomáš Kukrálbad54bb2017-03-02 15:46:20 +0100263 } else {
264 salt.enforceState(saltMaster, 'ctl01*', 'glusterfs.server.setup', true)
265 salt.enforceState(saltMaster, 'ctl02*', 'glusterfs.server.setup', true)
266 salt.enforceState(saltMaster, 'ctl03*', 'glusterfs.server.setup', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100267 }
268
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100269 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'], null, true)
270 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100271
272 // Install rabbitmq
273 salt.enforceState(saltMaster, 'I@rabbitmq:server', 'rabbitmq', true)
274
275 // Check the rabbitmq status
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100276 salt.runSaltProcessStep(saltMaster, 'I@rabbitmq:server', 'cmd.run', ['rabbitmqctl cluster_status'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100277
278 // Install galera
279 salt.enforceState(saltMaster, 'I@galera:master', 'galera', true)
280 salt.enforceState(saltMaster, 'I@galera:slave', 'galera', true)
281
282 // Check galera status
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100283 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'mysql.status')
284 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'mysql.status')
Tomáš Kukrála18de112017-03-02 13:57:47 +0100285
Tomáš Kukrálaa8f5532017-03-07 13:34:39 +0100286 // Setup mysql client
Tomáš Kukrálbe9dfa52017-03-08 13:54:03 +0100287 salt.enforceState(saltMaster, 'I@mysql:client', 'mysql.client', true)
Tomáš Kukrálaa8f5532017-03-07 13:34:39 +0100288
Tomáš Kukrála18de112017-03-02 13:57:47 +0100289 // Install haproxy
290 salt.enforceState(saltMaster, 'I@haproxy:proxy', 'haproxy', true)
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100291 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.status', ['haproxy'])
292 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.restart', ['rsyslog'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100293
294 // Install memcached
295 salt.enforceState(saltMaster, 'I@memcached:server', 'memcached', true)
296
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100297 }
298
Tomáš Kukrála18de112017-03-02 13:57:47 +0100299 stage('Install OpenStack control') {
300 //orchestrate.installOpenstackMkControl(saltMaster)
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100301
Tomáš Kukrála18de112017-03-02 13:57:47 +0100302 // setup keystone service
303 //runSaltProcessStep(saltMaster, 'I@keystone:server', 'state.sls', ['keystone.server'], 1)
304 salt.enforceState(saltMaster, 'ctl01*', 'keystone.server', true)
305 salt.enforceState(saltMaster, 'I@keystone:server', 'keystone.server', true)
306 // populate keystone services/tenants/roles/users
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100307
Tomáš Kukrála18de112017-03-02 13:57:47 +0100308 // keystone:client must be called locally
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100309 salt.runSaltProcessStep(saltMaster, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
310 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; keystone service-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100311
312 // Install glance and ensure glusterfs clusters
313 //runSaltProcessStep(saltMaster, 'I@glance:server', 'state.sls', ['glance.server'], 1)
314 salt.enforceState(saltMaster, 'ctl01*', 'glance.server', true)
315 salt.enforceState(saltMaster, 'I@glance:server', 'glance.server', true)
316 salt.enforceState(saltMaster, 'I@glance:server', 'glusterfs.client', true)
317
318 // Update fernet tokens before doing request on keystone server
319 salt.enforceState(saltMaster, 'I@keystone:server', 'keystone.server', true)
320
321 // Check glance service
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100322 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; glance image-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100323
324 // Install and check nova service
325 //runSaltProcessStep(saltMaster, 'I@nova:controller', 'state.sls', ['nova'], 1)
326 salt.enforceState(saltMaster, 'ctl01*', 'nova', true)
327 salt.enforceState(saltMaster, 'I@nova:controller', 'nova', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100328 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova service-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100329
330 // Install and check cinder service
331 //runSaltProcessStep(saltMaster, 'I@cinder:controller', 'state.sls', ['cinder'], 1)
332 salt.enforceState(saltMaster, 'ctl01*', 'cinder', true)
333 salt.enforceState(saltMaster, 'I@cinder:controller', 'cinder', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100334 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; cinder list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100335
336 // Install neutron service
337 //runSaltProcessStep(saltMaster, 'I@neutron:server', 'state.sls', ['neutron'], 1)
Tomáš Kukrál575e38a2017-03-02 17:12:45 +0100338 if (INSTALL.toLowerCase().contains('kvm')) {
339 salt.enforceState(saltMaster, 'ntw01*', 'neutron', true)
340 } else {
341 salt.enforceState(saltMaster, 'ctl01*', 'neutron', true)
342 }
343
Tomáš Kukrála18de112017-03-02 13:57:47 +0100344 salt.enforceState(saltMaster, 'I@neutron:server', 'neutron', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100345 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron agent-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100346
347 // Install heat service
348 //runSaltProcessStep(saltMaster, 'I@heat:server', 'state.sls', ['heat'], 1)
349 salt.enforceState(saltMaster, 'ctl01*', 'heat', true)
350 salt.enforceState(saltMaster, 'I@heat:server', 'heat', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100351 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; heat resource-type-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100352
353 // Install horizon dashboard
354 salt.enforceState(saltMaster, 'I@horizon:server', 'horizon', true)
355 salt.enforceState(saltMaster, 'I@nginx:server', 'nginx', true)
356
357 }
358
359 stage('Install OpenStack network') {
360 //orchestrate.installOpenstackMkNetwork(saltMaster, physical)
361
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100362 if (INSTALL.toLowerCase().contains('contrail')) {
363 // Install opencontrail database services
364 //runSaltProcessStep(saltMaster, 'I@opencontrail:database', 'state.sls', ['opencontrail.database'], 1)
365 salt.enforceState(saltMaster, 'ntw01*', 'opencontrail.database', true)
366 salt.enforceState(saltMaster, 'I@opencontrail:database', 'opencontrail.database', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100367
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100368 // Install opencontrail control services
369 //runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'state.sls', ['opencontrail'], 1)
370 salt.enforceState(saltMaster, 'ntw01*', 'opencontrail', true)
371 salt.enforceState(saltMaster, 'I@opencontrail:control', 'opencontrail', true)
372 salt.enforceState(saltMaster, 'I@opencontrail:collector', 'opencontrail', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100373
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100374 // Provision opencontrail control services
375 if (INSTALL.toLowerCase().contains('kvm')) {
376 // psysical contrail (kvm)
377 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control:id:1', 'cmd.run', ['/usr/share/contrail-utils/provision_control.py --api_server_ip 10.167.4.20 --api_server_port 8082 --host_name ntw01 --host_ip 10.167.4.21 --router_asn 64512 --admin_password password --admin_user admin --admin_tenant_name admin --oper add'], null, true)
378 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control:id:1', 'cmd.run', ['/usr/share/contrail-utils/provision_control.py --api_server_ip 10.167.4.20 --api_server_port 8082 --host_name ntw02 --host_ip 10.167.4.22 --router_asn 64512 --admin_password password --admin_user admin --admin_tenant_name admin --oper add'], null, true)
379 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control:id:1', 'cmd.run', ['/usr/share/contrail-utils/provision_control.py --api_server_ip 10.167.4.20 --api_server_port 8082 --host_name ntw03 --host_ip 10.167.4.23 --router_asn 64512 --admin_password password --admin_user admin --admin_tenant_name admin --oper add'], null, true)
380 } else {
381 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control:id:1', 'cmd.run', ['/usr/share/contrail-utils/provision_control.py --api_server_ip 172.16.10.254 --api_server_port 8082 --host_name ctl01 --host_ip 172.16.10.101 --router_asn 64512 --admin_password workshop --admin_user admin --admin_tenant_name admin --oper add'], null, true)
382 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control:id:1', 'cmd.run', ['/usr/share/contrail-utils/provision_control.py --api_server_ip 172.16.10.254 --api_server_port 8082 --host_name ctl02 --host_ip 172.16.10.102 --router_asn 64512 --admin_password workshop --admin_user admin --admin_tenant_name admin --oper add'], null, true)
383 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control:id:1', 'cmd.run', ['/usr/share/contrail-utils/provision_control.py --api_server_ip 172.16.10.254 --api_server_port 8082 --host_name ctl03 --host_ip 172.16.10.103 --router_asn 64512 --admin_password workshop --admin_user admin --admin_tenant_name admin --oper add'], null, true)
384 }
385
386 // Test opencontrail
387 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'cmd.run', ['contrail-status'], null, true)
388 } else if (INSTALL.toLowerCase().contains('ovs')) {
389 // Apply gateway
390 salt.runSaltProcessStep(saltMaster, 'I@neutron:gateway', 'state.apply', [], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100391 }
392
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100393 // Pring information
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100394 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'], null, true)
395 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100396 }
397
398 stage('Install OpenStack compute') {
399 //orchestrate.installOpenstackMkCompute(saltMaster, physical)
400 // Configure compute nodes
Tomáš Kukrálda26d902017-03-02 22:19:00 +0100401 retry(2) {
Tomáš Kukrál02cda9f2017-03-02 22:32:57 +0100402 salt.runSaltProcessStep(saltMaster, 'I@nova:compute', 'state.apply', [], null, true)
Tomáš Kukrálda26d902017-03-02 22:19:00 +0100403 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100404
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100405 if (INSTALL.toLowerCase().contains('contrail')) {
406 // Provision opencontrail virtual routers
407 if (INSTALL.toLowerCase().contains('kvm')) {
408 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control:id:1', 'cmd.run', ['/usr/share/contrail-utils/provision_vrouter.py --host_name cmp001 --host_ip 10.167.4.101 --api_server_ip 10.167.4.20 --oper add --admin_user admin --admin_password password --admin_tenant_name admin'], null, true)
409 } else {
410 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control:id:1', 'cmd.run', ['/usr/share/contrail-utils/provision_vrouter.py --host_name cmp01 --host_ip 172.16.10.105 --api_server_ip 172.16.10.254 --oper add --admin_user admin --admin_password workshop --admin_tenant_name admin'], null, true)
411 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100412
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100413 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)
414 sleep(300)
415 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100416 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100417
Tomáš Kukrál00ed1302017-03-03 17:38:40 +0100418 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100419
Tomáš Kukrál00ed1302017-03-03 17:38:40 +0100420
421 if (INSTALL.toLowerCase().contains('stacklight')) {
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100422 stage('Install StackLight') {
423 // infra install
424 // Install the StackLight backends
425 salt.enforceState(saltMaster, '*01* and I@elasticsearch:server', 'elasticsearch.server', true)
426 salt.enforceState(saltMaster, 'I@elasticsearch:server', 'elasticsearch.server', true)
427
428 salt.enforceState(saltMaster, '*01* and I@influxdb:server', 'influxdb', true)
429 salt.enforceState(saltMaster, 'I@influxdb:server', 'influxdb', true)
430
431 salt.enforceState(saltMaster, '*01* and I@kibana:server', 'kibana.server', true)
432 salt.enforceState(saltMaster, 'I@kibana:server', 'kibana.server', true)
433
434 salt.enforceState(saltMaster, '*01* and I@grafana:server','grafana.server', true)
435 salt.enforceState(saltMaster, 'I@grafana:server','grafana.server', true)
436
437 salt.enforceState(saltMaster, 'I@nagios:server', 'nagios.server', true)
438 salt.enforceState(saltMaster, 'I@elasticsearch:client', 'elasticsearch.client.service', true)
439 salt.enforceState(saltMaster, 'I@kibana:client', 'kibana.client.service', true)
440 // nw salt.enforceState('I@kibana:client or I@elasticsearch:client' --async service.restart salt-minion
441
442 sleep(10)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100443
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100444 salt.enforceState(saltMaster, 'I@elasticsearch:client', 'elasticsearch.client', true)
445 salt.enforceState(saltMaster, 'I@kibana:client', 'kibana.client', true)
446
447 // install monitor
448 // Restart salt-minion to make sure that it uses the latest Jinja library
449 // no way: salt '*' --async service.restart salt-minion; sleep 15
450
451 // Start by flusing Salt Mine to make sure it is clean
452 // Also clean-up the grains files to make sure that we start from a clean state
453 // nw salt "*" mine.flush
454 // nw salt "*" file.remove /etc/salt/grains.d/collectd
455 // nw salt "*" file.remove /etc/salt/grains.d/grafana
456 // nw salt "*" file.remove /etc/salt/grains.d/heka
457 // nw salt "*" file.remove /etc/salt/grains.d/sensu
458 // nw salt "*" file.remove /etc/salt/grains
459
460 // Install collectd, heka and sensu services on the nodes, this will also
461 // generate the metadata that goes into the grains and eventually into Salt Mine
Tomáš Kukrál2aa3c472017-03-03 17:47:08 +0100462 salt.enforceState(saltMaster, '*', 'collectd', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100463 salt.enforceState(saltMaster, '*', 'heka', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100464
465 // Gather the Grafana metadata as grains
466 salt.enforceState(saltMaster, 'I@grafana:collector', 'grafana.collector', true)
467
468 // Update Salt Mine
469 salt.enforceState(saltMaster, '*', 'salt.minion.grains', true)
470 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_modules', [], null, true)
471 salt.runSaltProcessStep(saltMaster, '*', 'mine.update', [], null, true)
472
473 sleep(5)
474
475 // Update Heka
476 salt.enforceState(saltMaster, 'I@heka:aggregator:enabled:True or I@heka:remote_collector:enabled:True', 'heka', true)
477
478 // Update collectd
479 salt.enforceState(saltMaster, 'I@collectd:remote_client:enabled:True', 'collectd', true)
480
481 // Update Nagios
482 salt.enforceState(saltMaster, 'I@nagios:server', 'nagios', true)
483 // Stop the Nagios service because the package starts it by default and it will
484 // started later only on the node holding the VIP address
485 salt.runSaltProcessStep(saltMaster, 'I@nagios:server', 'service.stop', ['nagios3'], null, true)
486
487 // Update Sensu
Tomáš Kukrál1ef3da72017-03-06 14:44:00 +0100488 // TODO for stacklight team, should be fixed in model
489 //salt.enforceState(saltMaster, 'I@sensu:server', 'sensu', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100490
491 // Finalize the configuration of Grafana (add the dashboards...)
492 salt.enforceState(saltMaster, 'I@grafana:client', 'grafana.client.service', true)
493 // nw salt -C 'I@grafana:client' --async service.restart salt-minion; sleep 10
494 salt.enforceState(saltMaster, 'I@grafana:client', 'grafana.client', true)
495
496 // Get the StackLight monitoring VIP addres
497 // TODO
498 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
499 //vip=${vip:=172.16.10.253}
Tomáš Kukrál6412a8c2017-03-07 14:03:47 +0100500 def pillar = salt.pillarGet(saltMaster, 'ctl01*', '_param:stacklight_monitor_address')
Tomáš Kukrál3e4029d2017-03-07 09:59:40 +0100501 print(pillar)
Tomáš Kukrálba73bcf2017-03-07 13:48:56 +0100502 def stacklight_vip = pillar['return'][0]['ctl01.nfv-lab.local']
503 common.infoMsg("restart services on node with IP: ${stacklight_vip}")
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100504
Tomáš Kukrál6412a8c2017-03-07 14:03:47 +0100505 if (stacklight_vip == "") {
506 throw new Exception("Missing stacklight_vip")
507 } else {
508 // (re)Start manually the services that are bound to the monitoring VIP
Tomáš Kukrál1b08c8c2017-03-07 16:51:49 +0100509 salt.runSaltProcessStep(saltMaster, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collectd'], null, true)
510 salt.runSaltProcessStep(saltMaster, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collector'], null, true)
511 salt.runSaltProcessStep(saltMaster, "G@ipv4:${stacklight_vip}", 'service.restart', ['aggregator'], null, true)
512 salt.runSaltProcessStep(saltMaster, "G@ipv4:${stacklight_vip}", 'service.restart', ['nagios3'], null, true)
Tomáš Kukrál6412a8c2017-03-07 14:03:47 +0100513 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100514 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100515 }
516
Tomáš Kukrála18de112017-03-02 13:57:47 +0100517 //
518 // Test
519 //
520
521 if (TEST.toLowerCase().contains('k8s')) {
522 stage('Run k8s bootstrap tests') {
523 orchestrate.runConformanceTests(saltMaster, K8S_API_SERVER, 'tomkukral/k8s-scripts')
524 }
525
526 stage('Run k8s conformance e2e tests') {
527 orchestrate.runConformanceTests(saltMaster, K8S_API_SERVER, K8S_CONFORMANCE_IMAGE)
528 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100529 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100530
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100531
Tomáš Kukrála18de112017-03-02 13:57:47 +0100532 } catch (Throwable e) {
533 currentBuild.result = 'FAILURE'
534 throw e
Tomáš Kukrál65fb5fd2017-03-02 14:56:49 +0100535 } finally {
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100536
Tomáš Kukrál96b12d52017-03-07 22:43:37 +0100537 // send notification
538 common.sendNotification(currentBuild.result,HEAT_STACK_NAME,["slack"])
539
Tomáš Kukrála18de112017-03-02 13:57:47 +0100540 //
541 // Clean
542 //
543
Tomáš Kukrálc9a630a2017-03-07 17:28:53 +0100544 if (STACK_TYPE == 'heat') {
545 if (HEAT_STACK_DELETE.toBoolean() == true) {
546 common.errorMsg('Heat job cleanup triggered')
547 stage('Trigger cleanup job') {
548 build job: 'deploy-heat-cleanup', parameters: [[$class: 'StringParameterValue', name: 'HEAT_STACK_NAME', value: HEAT_STACK_NAME]]
549 }
550 } else {
Tomáš Kukrálbcc53ea2017-03-08 08:15:57 +0100551 if (currentBuild.result == 'FAILURE') {
552 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 +0100553
Tomáš Kukrálbcc53ea2017-03-08 08:15:57 +0100554 if (SALT_MASTER_URL) {
555 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
556 }
Tomáš Kukrálb908dac2017-03-07 18:58:35 +0100557 }
558
Tomáš Kukrála18de112017-03-02 13:57:47 +0100559 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100560 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100561 }
562 }
563}