blob: 08cddf6b01ac3962eeab0f823ae50854201eef3b [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álb9957b32017-02-28 14:49:00 +010041
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +010042timestamps {
43 node {
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010044
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +010045 //
46 // Prepare machines
47 //
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010048
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +010049 stage ('Create infrastructure') {
50 if (STACK_TYPE == 'heat') {
51 // value defaults
52 def openstackCloud
53 def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty'
54 def openstackEnv = "${env.WORKSPACE}/venv"
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010055
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +010056 if (HEAT_STACK_NAME == '') {
57 HEAT_STACK_NAME = BUILD_TAG
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010058 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +010059
60 // get templates
61 git.checkoutGitRepository('template', HEAT_TEMPLATE_URL, HEAT_TEMPLATE_BRANCH, HEAT_TEMPLATE_CREDENTIALS)
62
63 // create openstack env
64 openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion)
65 openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT)
66 openstack.getKeystoneToken(openstackCloud, openstackEnv)
67
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +010068 // launch stack
69 if (HEAT_STACK_REUSE == 'false') {
70 stage('Launch new Heat stack') {
71 // create stack
72 envParams = [
73 'instance_zone': HEAT_STACK_ZONE,
74 'public_net': HEAT_STACK_PUBLIC_NET
75 ]
76 openstack.createHeatStack(openstackCloud, HEAT_STACK_NAME, HEAT_STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, openstackEnv)
77 }
78 }
79
80 // get SALT_MASTER_URL
81 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, HEAT_STACK_NAME, 'salt_master_ip', openstackEnv)
82 SALT_MASTER_URL = "http://${saltMasterHost}:8088"
83 }
84 }
85
86 //
87 // Connect to Salt master
88 //
89
90 def saltMaster
91 stage('Connect to Salt API') {
92 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
93 }
94
95 //
96 // Install
97 //
98
Tomáš Kukrálc265e352017-03-02 11:45:11 +010099 if (INSTALL.toLowerCase().contains('core')) {
100 stage('Install core infrastructure') {
101 // salt.master, reclass
102 // refresh_pillar
103 // sync_all
104 // linux,openssh,salt.minion.ntp
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100105
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100106 //orchestrate.installFoundationInfra(saltMaster)
107 salt.runSaltProcessStep(master, 'I@salt:master', 'state.sls', ['salt.master,reclass'])
108 salt.runSaltProcessStep(master, 'I@linux:system', 'saltutil.refresh_pillar')
109 salt.runSaltProcessStep(master, 'I@linux:system', 'saltutil.sync_all')
110 salt.runSaltProcessStep(master, 'I@linux:system', 'state.sls', ['linux,openssh,salt.minion,ntp'])
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100111
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100112
113 if (INSTALL.toLowerCase().contains('kvm')) {
114 //orchestrate.installInfraKvm(saltMaster)
115 salt.runSaltProcessStep(master, 'I@linux:system', 'saltutil.refresh_pillar')
116 salt.runSaltProcessStep(master, 'I@linux:system', 'saltutil.sync_all')
117
118 salt.runSaltProcessStep(master, 'I@salt:control', 'state.sls', ['salt.minion,linux.system,linux.network,ntp'])
119 salt.enforceState(master, 'I@salt:control', 'libvirt', true)
120 salt.enforceState(master, 'I@salt:control', 'salt.control', true)
121
122 sleep(300)
123
124 salt.runSaltProcessStep(master, '* and not kvm*', 'saltutil.refresh_pillar')
125 salt.runSaltProcessStep(master, '* and not kvm*', 'saltutil.sync_all')
126
127 // workaround - install apt-transport-https
128 salt.runSaltProcessStep(master, '* and not kvm*', 'pkg.install', ['apt-transport-https'])
129 salt.runSaltProcessStep(master, '* and not kvm*', 'state.sls', ['linux,openssh,salt.minion,ntp'])
130 }
131
132 //orchestrate.validateFoundationInfra(saltMaster)
133 salt.runSaltProcessStep(master, 'I@salt:master', 'cmd.run', ['salt-key'])
134 salt.runSaltProcessStep(master, 'I@salt:minion', 'test.version')
135 salt.runSaltProcessStep(master, 'I@salt:master', 'cmd.run', ['reclass-salt --top'])
136 salt.runSaltProcessStep(master, 'I@reclass:storage', 'reclass.inventory')
137 salt.runSaltProcessStep(master, 'I@salt:minion', 'state.show_top')
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100138 }
Tomáš Kukrál06c27a92017-03-01 16:21:46 +0100139 }
140
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100141 // install k8s
142 if (INSTALL.toLowerCase().contains('k8s')) {
143 stage('Install Kubernetes infra') {
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100144 //orchestrate.installOpenstackMcpInfra(saltMaster)
145
146 // Comment nameserver
147 salt.runSaltProcessStep(master, 'I@kubernetes:master', 'cmd.run', ["sed -i 's/nameserver 10.254.0.10/#nameserver 10.254.0.10/g' /etc/resolv.conf"])
148
149 // Install glusterfs
150 salt.runSaltProcessStep(master, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.service'])
151
152 // Install keepalived
153 salt.runSaltProcessStep(master, 'ctl01*', 'state.sls', ['keepalived'])
154 salt.runSaltProcessStep(master, 'I@keepalived:cluster', 'state.sls', ['keepalived'])
155
156 // Check the keepalived VIPs
157 salt.runSaltProcessStep(master, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
158
159 // Setup glusterfs
160 salt.runSaltProcessStep(master, 'ctl01*', 'state.sls', ['glusterfs.server.setup'])
161 salt.runSaltProcessStep(master, 'ctl02*', 'state.sls', ['glusterfs.server.setup'])
162 salt.runSaltProcessStep(master, 'ctl03*', 'state.sls', ['glusterfs.server.setup'])
163 salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'])
164 salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'])
165
166 // Install haproxy
167 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'state.sls', ['haproxy'])
168 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
169
170 // Install docker
171 salt.runSaltProcessStep(master, 'I@docker:host', 'state.sls', ['docker.host'])
172 salt.runSaltProcessStep(master, 'I@docker:host', 'cmd.run', ['docker ps'])
173
174 // Install bird
175 salt.runSaltProcessStep(master, 'I@bird:server', 'state.sls', ['bird'])
176
177 // Install etcd
178 salt.runSaltProcessStep(master, 'I@etcd:server', 'state.sls', ['etcd.server.service'])
179 salt.runSaltProcessStep(master, 'I@etcd:server', 'cmd.run', ['etcdctl cluster-health'])
180
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100181 }
182
183 stage('Install Kubernetes control') {
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100184 //orchestrate.installOpenstackMcpControl(saltMaster)
185
186 // Install Kubernetes pool and Calico
187 salt.runSaltProcessStep(master, 'I@kubernetes:pool', 'state.sls', ['kubernetes.pool'])
188 salt.runSaltProcessStep(master, 'I@kubernetes:pool', 'cmd.run', ['calicoctl node status'])
189
190 // Setup etcd server
191 salt.runSaltProcessStep(master, 'I@kubernetes:master', 'state.sls', ['etcd.server.setup'])
192
193 // Run k8s without master.setup
194 salt.runSaltProcessStep(master, 'I@kubernetes:master', 'state.sls', ['kubernetes', 'exclude=kubernetes.master.setup'])
195
196 // Run k8s master setup
197 salt.runSaltProcessStep(master, 'ctl01*', 'state.sls', ['kubernetes.master.setup'])
198
199 // Revert comment nameserver
200 salt.runSaltProcessStep(master, 'I@kubernetes:master', 'cmd.run', ["sed -i 's/nameserver 10.254.0.10/#nameserver 10.254.0.10/g' /etc/resolv.conf"])
201
202 // Set route
203 salt.runSaltProcessStep(master, 'I@kubernetes:pool', 'cmd.run', ['ip r a 10.254.0.0/16 dev ens4'])
204
205 // Restart kubelet
206 salt.runSaltProcessStep(master, 'I@kubernetes:pool', 'service.restart', ['kubelet'])
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100207 }
208
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100209 }
210
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100211 // install openstack
212 if (INSTALL.toLowerCase().contains('openstack')) {
213 // install Infra and control, tests, ...
214
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100215 stage('Install OpenStack infra') {
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100216 //orchestrate.installOpenstackMkInfra(saltMaster, physical)
217
218 // Install keepaliveds
219 //runSaltProcessStep(master, 'I@keepalived:cluster', 'state.sls', ['keepalived'], 1)
220 salt.enforceState(master, 'ctl01*', 'keepalived', true)
221 salt.enforceState(master, 'I@keepalived:cluster', 'keepalived', true)
222
223 // Check the keepalived VIPs
224 salt.runSaltProcessStep(master, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
225
226 // Install glusterfs
227 salt.enforceState(master, 'I@glusterfs:server', 'glusterfs.server.service', true)
228
229 //runSaltProcessStep(master, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.setup'], 1)
230 if (INSTALL.toLowerCase().contains('kvm')) {
231 salt.enforceState(master, 'ctl01*', 'glusterfs.server.setup', true)
232 salt.enforceState(master, 'ctl02*', 'glusterfs.server.setup', true)
233 salt.enforceState(master, 'ctl03*', 'glusterfs.server.setup', true)
234 } else {
235 salt.enforceState(master, 'kvm01*', 'glusterfs.server.setup', true)
236 salt.enforceState(master, 'kvm02*', 'glusterfs.server.setup', true)
237 salt.enforceState(master, 'kvm03*', 'glusterfs.server.setup', true)
238 }
239 salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'])
240 salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'])
241
242 // Install rabbitmq
243 salt.enforceState(master, 'I@rabbitmq:server', 'rabbitmq', true)
244
245 // Check the rabbitmq status
246 salt.runSaltProcessStep(master, 'I@rabbitmq:server', 'cmd.run', ['rabbitmqctl cluster_status'])
247
248 // Install galera
249 salt.enforceState(master, 'I@galera:master', 'galera', true)
250 salt.enforceState(master, 'I@galera:slave', 'galera', true)
251
252 // Check galera status
253 salt.runSaltProcessStep(master, 'I@galera:master', 'mysql.status')
254 salt.runSaltProcessStep(master, 'I@galera:slave', 'mysql.status')
255
256 // Install haproxy
257 salt.enforceState(master, 'I@haproxy:proxy', 'haproxy', true)
258 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
259 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.restart', ['rsyslog'])
260
261 // Install memcached
262 salt.enforceState(master, 'I@memcached:server', 'memcached', true)
263
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100264 }
265
266 stage('Install OpenStack control') {
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100267 //orchestrate.installOpenstackMkControl(saltMaster)
268
269 // setup keystone service
270 //runSaltProcessStep(master, 'I@keystone:server', 'state.sls', ['keystone.server'], 1)
271 salt.enforceState(master, 'ctl01*', 'keystone.server', true)
272 salt.enforceState(master, 'I@keystone:server', 'keystone.server', true)
273 // populate keystone services/tenants/roles/users
274
275 // keystone:client must be called locally
276 salt.runSaltProcessStep(master, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'])
277 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; keystone service-list'])
278
279 // Install glance and ensure glusterfs clusters
280 //runSaltProcessStep(master, 'I@glance:server', 'state.sls', ['glance.server'], 1)
281 salt.enforceState(master, 'ctl01*', 'glance.server', true)
282 salt.enforceState(master, 'I@glance:server', 'glance.server', true)
283 salt.enforceState(master, 'I@glance:server', 'glusterfs.client', true)
284
285 // Update fernet tokens before doing request on keystone server
286 salt.enforceState(master, 'I@keystone:server', 'keystone.server', true)
287
288 // Check glance service
289 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; glance image-list'])
290
291 // Install and check nova service
292 //runSaltProcessStep(master, 'I@nova:controller', 'state.sls', ['nova'], 1)
293 salt.enforceState(master, 'ctl01*', 'nova', true)
294 salt.enforceState(master, 'I@nova:controller', 'nova', true)
295 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova service-list'])
296
297 // Install and check cinder service
298 //runSaltProcessStep(master, 'I@cinder:controller', 'state.sls', ['cinder'], 1)
299 salt.enforceState(master, 'ctl01*', 'cinder', true)
300 salt.enforceState(master, 'I@cinder:controller', 'cinder', true)
301 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; cinder list'])
302
303 // Install neutron service
304 //runSaltProcessStep(master, 'I@neutron:server', 'state.sls', ['neutron'], 1)
305 salt.enforceState(master, 'ctl01*', 'neutron', true)
306 salt.enforceState(master, 'I@neutron:server', 'neutron', true)
307 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron agent-list'])
308
309 // Install heat service
310 //runSaltProcessStep(master, 'I@heat:server', 'state.sls', ['heat'], 1)
311 salt.enforceState(master, 'ctl01*', 'heat', true)
312 salt.enforceState(master, 'I@heat:server', 'heat', true)
313 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; heat resource-type-list'])
314
315 // Install horizon dashboard
316 salt.enforceState(master, 'I@horizon:server', 'horizon', true)
317 salt.enforceState(master, 'I@nginx:server', 'nginx', true)
318
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100319 }
320
321 stage('Install OpenStack network') {
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100322 //orchestrate.installOpenstackMkNetwork(saltMaster, physical)
323
324 // Install opencontrail database services
325 //runSaltProcessStep(master, 'I@opencontrail:database', 'state.sls', ['opencontrail.database'], 1)
326 salt.enforceState(master, 'ntw01*', 'opencontrail.database', true)
327 salt.enforceState(master, 'I@opencontrail:database', 'opencontrail.database', true)
328
329 // Install opencontrail control services
330 //runSaltProcessStep(master, 'I@opencontrail:control', 'state.sls', ['opencontrail'], 1)
331 salt.enforceState(master, 'ntw01*', 'opencontrail', true)
332 salt.enforceState(master, 'I@opencontrail:control', 'opencontrail', true)
333
334 // Provision opencontrail control services
335 if (INSTALL.toLowerCase().contains('kvm')) {
336 salt.runSaltProcessStep(master, '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'])
337 salt.runSaltProcessStep(master, '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'])
338 salt.runSaltProcessStep(master, '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'])
339 }
340
341 // Test opencontrail
342 salt.runSaltProcessStep(master, 'I@opencontrail:control', 'cmd.run', ['contrail-status'])
343 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
344 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100345 }
346
347 stage('Install OpenStack compute') {
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100348 //orchestrate.installOpenstackMkCompute(saltMaster, physical)
349 // Configure compute nodes
350 salt.runSaltProcessStep(master, 'I@nova:compute', 'state.apply')
351 salt.runSaltProcessStep(master, 'I@nova:compute', 'state.apply')
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100352
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100353 // Provision opencontrail virtual routers
354 if (INSTALL.toLowerCase().contains('kvm')) {
355 salt.runSaltProcessStep(master, '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'])
356 }
357
358 salt.runSaltProcessStep(master, 'I@nova:compute', 'system.reboot')
359 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100360 }
361
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100362 //
363 // Test
364 //
365
366 if (TEST.toLowerCase().contains('k8s')) {
367 stage('Run k8s bootstrap tests') {
368 orchestrate.runConformanceTests(saltMaster, K8S_API_SERVER, 'tomkukral/k8s-scripts')
369 }
370
371 stage('Run k8s conformance e2e tests') {
372 orchestrate.runConformanceTests(saltMaster, K8S_API_SERVER, K8S_CONFORMANCE_IMAGE)
373 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100374 }
375
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100376
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100377 //
378 // Clean
379 //
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100380
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100381 if (HEAT_STACK_DELETE == 'true' && STACK_TYPE == 'heat') {
382 stage('Trigger cleanup job') {
383 build job: 'deploy_heat_cleanup', parameters: [[$class: 'StringParameterValue', name: 'HEAT_STACK_NAME', value: HEAT_STACK_NAME]]
384 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100385 }
386 }
387}