blob: c69f3643361b4940fab624b5ab9963a099caf306 [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ále80680a2017-03-02 16:34:35 +010042
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +010043timestamps {
44 node {
Tomáš Kukrála18de112017-03-02 13:57:47 +010045 try {
Tomáš Kukrále80680a2017-03-02 16:34:35 +010046
47
Tomáš Kukrála18de112017-03-02 13:57:47 +010048 //
49 // Prepare machines
50 //
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010051
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')) {
Tomáš Kukrál576ac252017-03-04 15:55:43 +0100103 saltPort = '8088'
Tomáš Kukrál615aa9c2017-03-04 15:29:08 +0100104 } else {
Tomáš Kukrál576ac252017-03-04 15:55:43 +0100105 saltPort = '8000'
Tomáš Kukrál615aa9c2017-03-04 15:29:08 +0100106 }
107
108 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ála18de112017-03-02 13:57:47 +0100148 sleep(300)
149
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ál5c837882017-03-03 00:54:13 +0100154 salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'cmd.run', ['apt-get update -y && apt-get install -y apt-transport-https'], null, true)
Tomáš Kukrál677b4232017-03-02 23:31:12 +0100155 salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'pkg.install', ['apt-transport-https', 'refresh=True'], null, true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100156 salt.enforceState(saltMaster, 'I@linux:system', ['linux', 'openssh', 'salt.minion', 'ntp'], true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100157 }
158
159 //orchestrate.validateFoundationInfra(saltMaster)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100160 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'cmd.run', ['salt-key'], null, true)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100161 salt.runSaltProcessStep(saltMaster, 'I@salt:minion', 'test.version', [], null, true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100162 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'cmd.run', ['reclass-salt --top'], null, true)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100163 salt.runSaltProcessStep(saltMaster, 'I@reclass:storage', 'reclass.inventory', [], null, true)
164 salt.runSaltProcessStep(saltMaster, 'I@salt:minion', 'state.show_top', [], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100165 }
166 }
167
168 // install k8s
169 if (INSTALL.toLowerCase().contains('k8s')) {
170 stage('Install Kubernetes infra') {
171 //orchestrate.installOpenstackMcpInfra(saltMaster)
172
173 // Comment nameserver
174 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"])
175
176 // Install glusterfs
177 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.service'])
178
179 // Install keepalived
180 salt.runSaltProcessStep(saltMaster, 'ctl01*', 'state.sls', ['keepalived'])
181 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'state.sls', ['keepalived'])
182
183 // Check the keepalived VIPs
184 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
185
186 // Setup glusterfs
187 salt.runSaltProcessStep(saltMaster, 'ctl01*', 'state.sls', ['glusterfs.server.setup'])
188 salt.runSaltProcessStep(saltMaster, 'ctl02*', 'state.sls', ['glusterfs.server.setup'])
189 salt.runSaltProcessStep(saltMaster, 'ctl03*', 'state.sls', ['glusterfs.server.setup'])
190 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'])
191 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'])
192
193 // Install haproxy
194 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'state.sls', ['haproxy'])
195 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.status', ['haproxy'])
196
197 // Install docker
198 salt.runSaltProcessStep(saltMaster, 'I@docker:host', 'state.sls', ['docker.host'])
199 salt.runSaltProcessStep(saltMaster, 'I@docker:host', 'cmd.run', ['docker ps'])
200
201 // Install bird
202 salt.runSaltProcessStep(saltMaster, 'I@bird:server', 'state.sls', ['bird'])
203
204 // Install etcd
205 salt.runSaltProcessStep(saltMaster, 'I@etcd:server', 'state.sls', ['etcd.server.service'])
206 salt.runSaltProcessStep(saltMaster, 'I@etcd:server', 'cmd.run', ['etcdctl cluster-health'])
207
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100208 }
209
Tomáš Kukrála18de112017-03-02 13:57:47 +0100210 stage('Install Kubernetes control') {
211 //orchestrate.installOpenstackMcpControl(saltMaster)
Tomáš Kukrál06c27a92017-03-01 16:21:46 +0100212
Tomáš Kukrála18de112017-03-02 13:57:47 +0100213 // Install Kubernetes pool and Calico
214 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:pool', 'state.sls', ['kubernetes.pool'])
215 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:pool', 'cmd.run', ['calicoctl node status'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100216
Tomáš Kukrála18de112017-03-02 13:57:47 +0100217 // Setup etcd server
218 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:master', 'state.sls', ['etcd.server.setup'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100219
Tomáš Kukrála18de112017-03-02 13:57:47 +0100220 // Run k8s without master.setup
221 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:master', 'state.sls', ['kubernetes', 'exclude=kubernetes.master.setup'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100222
Tomáš Kukrála18de112017-03-02 13:57:47 +0100223 // Run k8s master setup
224 salt.runSaltProcessStep(saltMaster, 'ctl01*', 'state.sls', ['kubernetes.master.setup'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100225
Tomáš Kukrála18de112017-03-02 13:57:47 +0100226 // Revert comment nameserver
227 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 +0100228
Tomáš Kukrála18de112017-03-02 13:57:47 +0100229 // Set route
230 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 +0100231
Tomáš Kukrála18de112017-03-02 13:57:47 +0100232 // Restart kubelet
233 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:pool', 'service.restart', ['kubelet'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100234 }
235
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100236 }
237
Tomáš Kukrála18de112017-03-02 13:57:47 +0100238 // install openstack
239 if (INSTALL.toLowerCase().contains('openstack')) {
240 // install Infra and control, tests, ...
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100241
Tomáš Kukrála18de112017-03-02 13:57:47 +0100242 stage('Install OpenStack infra') {
243 //orchestrate.installOpenstackMkInfra(saltMaster, physical)
244
245 // Install keepaliveds
246 //runSaltProcessStep(master, 'I@keepalived:cluster', 'state.sls', ['keepalived'], 1)
247 salt.enforceState(saltMaster, 'ctl01*', 'keepalived', true)
248 salt.enforceState(saltMaster, 'I@keepalived:cluster', 'keepalived', true)
249
250 // Check the keepalived VIPs
251 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
252
253 // Install glusterfs
254 salt.enforceState(saltMaster, 'I@glusterfs:server', 'glusterfs.server.service', true)
255
256 //runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.setup'], 1)
257 if (INSTALL.toLowerCase().contains('kvm')) {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100258 salt.enforceState(saltMaster, 'kvm01*', 'glusterfs.server.setup', true)
259 salt.enforceState(saltMaster, 'kvm02*', 'glusterfs.server.setup', true)
260 salt.enforceState(saltMaster, 'kvm03*', 'glusterfs.server.setup', true)
Tomáš Kukrálbad54bb2017-03-02 15:46:20 +0100261 } else {
262 salt.enforceState(saltMaster, 'ctl01*', 'glusterfs.server.setup', true)
263 salt.enforceState(saltMaster, 'ctl02*', 'glusterfs.server.setup', true)
264 salt.enforceState(saltMaster, 'ctl03*', 'glusterfs.server.setup', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100265 }
266
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100267 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'], null, true)
268 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100269
270 // Install rabbitmq
271 salt.enforceState(saltMaster, 'I@rabbitmq:server', 'rabbitmq', true)
272
273 // Check the rabbitmq status
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100274 salt.runSaltProcessStep(saltMaster, 'I@rabbitmq:server', 'cmd.run', ['rabbitmqctl cluster_status'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100275
276 // Install galera
277 salt.enforceState(saltMaster, 'I@galera:master', 'galera', true)
278 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
284 // Install haproxy
285 salt.enforceState(saltMaster, 'I@haproxy:proxy', 'haproxy', true)
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100286 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.status', ['haproxy'])
287 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.restart', ['rsyslog'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100288
289 // Install memcached
290 salt.enforceState(saltMaster, 'I@memcached:server', 'memcached', true)
291
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100292 }
293
Tomáš Kukrála18de112017-03-02 13:57:47 +0100294 stage('Install OpenStack control') {
295 //orchestrate.installOpenstackMkControl(saltMaster)
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100296
Tomáš Kukrála18de112017-03-02 13:57:47 +0100297 // setup keystone service
298 //runSaltProcessStep(saltMaster, 'I@keystone:server', 'state.sls', ['keystone.server'], 1)
299 salt.enforceState(saltMaster, 'ctl01*', 'keystone.server', true)
300 salt.enforceState(saltMaster, 'I@keystone:server', 'keystone.server', true)
301 // populate keystone services/tenants/roles/users
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100302
Tomáš Kukrála18de112017-03-02 13:57:47 +0100303 // keystone:client must be called locally
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100304 salt.runSaltProcessStep(saltMaster, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
305 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; keystone service-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100306
307 // Install glance and ensure glusterfs clusters
308 //runSaltProcessStep(saltMaster, 'I@glance:server', 'state.sls', ['glance.server'], 1)
309 salt.enforceState(saltMaster, 'ctl01*', 'glance.server', true)
310 salt.enforceState(saltMaster, 'I@glance:server', 'glance.server', true)
311 salt.enforceState(saltMaster, 'I@glance:server', 'glusterfs.client', true)
312
313 // Update fernet tokens before doing request on keystone server
314 salt.enforceState(saltMaster, 'I@keystone:server', 'keystone.server', true)
315
316 // Check glance service
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100317 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; glance image-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100318
319 // Install and check nova service
320 //runSaltProcessStep(saltMaster, 'I@nova:controller', 'state.sls', ['nova'], 1)
321 salt.enforceState(saltMaster, 'ctl01*', 'nova', true)
322 salt.enforceState(saltMaster, 'I@nova:controller', 'nova', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100323 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova service-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100324
325 // Install and check cinder service
326 //runSaltProcessStep(saltMaster, 'I@cinder:controller', 'state.sls', ['cinder'], 1)
327 salt.enforceState(saltMaster, 'ctl01*', 'cinder', true)
328 salt.enforceState(saltMaster, 'I@cinder:controller', 'cinder', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100329 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; cinder list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100330
331 // Install neutron service
332 //runSaltProcessStep(saltMaster, 'I@neutron:server', 'state.sls', ['neutron'], 1)
Tomáš Kukrál575e38a2017-03-02 17:12:45 +0100333 if (INSTALL.toLowerCase().contains('kvm')) {
334 salt.enforceState(saltMaster, 'ntw01*', 'neutron', true)
335 } else {
336 salt.enforceState(saltMaster, 'ctl01*', 'neutron', true)
337 }
338
Tomáš Kukrála18de112017-03-02 13:57:47 +0100339 salt.enforceState(saltMaster, 'I@neutron:server', 'neutron', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100340 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron agent-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100341
342 // Install heat service
343 //runSaltProcessStep(saltMaster, 'I@heat:server', 'state.sls', ['heat'], 1)
344 salt.enforceState(saltMaster, 'ctl01*', 'heat', true)
345 salt.enforceState(saltMaster, 'I@heat:server', 'heat', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100346 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; heat resource-type-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100347
348 // Install horizon dashboard
349 salt.enforceState(saltMaster, 'I@horizon:server', 'horizon', true)
350 salt.enforceState(saltMaster, 'I@nginx:server', 'nginx', true)
351
352 }
353
354 stage('Install OpenStack network') {
355 //orchestrate.installOpenstackMkNetwork(saltMaster, physical)
356
357 // Install opencontrail database services
358 //runSaltProcessStep(saltMaster, 'I@opencontrail:database', 'state.sls', ['opencontrail.database'], 1)
359 salt.enforceState(saltMaster, 'ntw01*', 'opencontrail.database', true)
360 salt.enforceState(saltMaster, 'I@opencontrail:database', 'opencontrail.database', true)
361
362 // Install opencontrail control services
363 //runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'state.sls', ['opencontrail'], 1)
364 salt.enforceState(saltMaster, 'ntw01*', 'opencontrail', true)
365 salt.enforceState(saltMaster, 'I@opencontrail:control', 'opencontrail', true)
Tomáš Kukrál3b8ad5e2017-03-02 23:03:27 +0100366 salt.enforceState(saltMaster, 'I@opencontrail:collector', 'opencontrail', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100367
368 // Provision opencontrail control services
369 if (INSTALL.toLowerCase().contains('kvm')) {
Tomáš Kukrál575e38a2017-03-02 17:12:45 +0100370 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)
371 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)
372 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)
373 } else {
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100374 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)
375 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)
376 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)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100377 }
378
379 // Test opencontrail
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100380 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'cmd.run', ['contrail-status'], null, true)
381 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'], null, true)
382 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100383 }
384
385 stage('Install OpenStack compute') {
386 //orchestrate.installOpenstackMkCompute(saltMaster, physical)
387 // Configure compute nodes
Tomáš Kukrálda26d902017-03-02 22:19:00 +0100388 retry(2) {
Tomáš Kukrál02cda9f2017-03-02 22:32:57 +0100389 salt.runSaltProcessStep(saltMaster, 'I@nova:compute', 'state.apply', [], null, true)
Tomáš Kukrálda26d902017-03-02 22:19:00 +0100390 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100391
392 // Provision opencontrail virtual routers
393 if (INSTALL.toLowerCase().contains('kvm')) {
Tomáš Kukrál834fe212017-03-02 22:50:49 +0100394 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)
Tomáš Kukrál575e38a2017-03-02 17:12:45 +0100395 } else {
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100396 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)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100397 }
398
Tomáš Kukrálc39610c2017-03-02 22:56:06 +0100399 salt.runSaltProcessStep(saltMaster, 'I@nova:compute', 'system.reboot', [], null, true)
Tomáš Kukrál3b8ad5e2017-03-02 23:03:27 +0100400 sleep(10)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100401 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100402
Tomáš Kukrál00ed1302017-03-03 17:38:40 +0100403 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100404
Tomáš Kukrál00ed1302017-03-03 17:38:40 +0100405
406 if (INSTALL.toLowerCase().contains('stacklight')) {
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100407 stage('Install StackLight') {
408 // infra install
409 // Install the StackLight backends
410 salt.enforceState(saltMaster, '*01* and I@elasticsearch:server', 'elasticsearch.server', true)
411 salt.enforceState(saltMaster, 'I@elasticsearch:server', 'elasticsearch.server', true)
412
413 salt.enforceState(saltMaster, '*01* and I@influxdb:server', 'influxdb', true)
414 salt.enforceState(saltMaster, 'I@influxdb:server', 'influxdb', true)
415
416 salt.enforceState(saltMaster, '*01* and I@kibana:server', 'kibana.server', true)
417 salt.enforceState(saltMaster, 'I@kibana:server', 'kibana.server', true)
418
419 salt.enforceState(saltMaster, '*01* and I@grafana:server','grafana.server', true)
420 salt.enforceState(saltMaster, 'I@grafana:server','grafana.server', true)
421
422 salt.enforceState(saltMaster, 'I@nagios:server', 'nagios.server', true)
423 salt.enforceState(saltMaster, 'I@elasticsearch:client', 'elasticsearch.client.service', true)
424 salt.enforceState(saltMaster, 'I@kibana:client', 'kibana.client.service', true)
425 // nw salt.enforceState('I@kibana:client or I@elasticsearch:client' --async service.restart salt-minion
426
427 sleep(10)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100428
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100429 salt.enforceState(saltMaster, 'I@elasticsearch:client', 'elasticsearch.client', true)
430 salt.enforceState(saltMaster, 'I@kibana:client', 'kibana.client', true)
431
432 // install monitor
433 // Restart salt-minion to make sure that it uses the latest Jinja library
434 // no way: salt '*' --async service.restart salt-minion; sleep 15
435
436 // Start by flusing Salt Mine to make sure it is clean
437 // Also clean-up the grains files to make sure that we start from a clean state
438 // nw salt "*" mine.flush
439 // nw salt "*" file.remove /etc/salt/grains.d/collectd
440 // nw salt "*" file.remove /etc/salt/grains.d/grafana
441 // nw salt "*" file.remove /etc/salt/grains.d/heka
442 // nw salt "*" file.remove /etc/salt/grains.d/sensu
443 // nw salt "*" file.remove /etc/salt/grains
444
445 // Install collectd, heka and sensu services on the nodes, this will also
446 // generate the metadata that goes into the grains and eventually into Salt Mine
Tomáš Kukrál2aa3c472017-03-03 17:47:08 +0100447 salt.enforceState(saltMaster, '*', 'collectd', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100448 salt.enforceState(saltMaster, '*', 'heka', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100449
450 // Gather the Grafana metadata as grains
451 salt.enforceState(saltMaster, 'I@grafana:collector', 'grafana.collector', true)
452
453 // Update Salt Mine
454 salt.enforceState(saltMaster, '*', 'salt.minion.grains', true)
455 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_modules', [], null, true)
456 salt.runSaltProcessStep(saltMaster, '*', 'mine.update', [], null, true)
457
458 sleep(5)
459
460 // Update Heka
461 salt.enforceState(saltMaster, 'I@heka:aggregator:enabled:True or I@heka:remote_collector:enabled:True', 'heka', true)
462
463 // Update collectd
464 salt.enforceState(saltMaster, 'I@collectd:remote_client:enabled:True', 'collectd', true)
465
466 // Update Nagios
467 salt.enforceState(saltMaster, 'I@nagios:server', 'nagios', true)
468 // Stop the Nagios service because the package starts it by default and it will
469 // started later only on the node holding the VIP address
470 salt.runSaltProcessStep(saltMaster, 'I@nagios:server', 'service.stop', ['nagios3'], null, true)
471
472 // Update Sensu
473 salt.enforceState(saltMaster, 'I@sensu:server', 'sensu', true)
474
475 // Finalize the configuration of Grafana (add the dashboards...)
476 salt.enforceState(saltMaster, 'I@grafana:client', 'grafana.client.service', true)
477 // nw salt -C 'I@grafana:client' --async service.restart salt-minion; sleep 10
478 salt.enforceState(saltMaster, 'I@grafana:client', 'grafana.client', true)
479
480 // Get the StackLight monitoring VIP addres
481 // TODO
482 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
483 //vip=${vip:=172.16.10.253}
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100484 def tmp = salt.pillarGet(saltMaster, 'ctl01*', '_param:stacklight_monitor_address')
485 print(tmp)
486
487 // (re)Start manually the services that are bound to the monitoring VIP
488 //salt.runSaltProcessStep(saltMaster, "ipv4:${stacklight_vip}", 'service.restart', ['remote_collectd'], true)
489 //salt.runSaltProcessStep(saltMaster, "ipv4:${stacklight_vip}", 'service.restart', ['remote_collector'], true)
490 //salt.runSaltProcessStep(saltMaster, "ipv4:${stacklight_vip}", 'service.restart', ['aggregator'], true)
491 //salt.runSaltProcessStep(saltMaster, "ipv4:${stacklight_vip}", 'service.restart', ['nagios3'], true), true)
492 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100493 }
494
Tomáš Kukrála18de112017-03-02 13:57:47 +0100495 //
496 // Test
497 //
498
499 if (TEST.toLowerCase().contains('k8s')) {
500 stage('Run k8s bootstrap tests') {
501 orchestrate.runConformanceTests(saltMaster, K8S_API_SERVER, 'tomkukral/k8s-scripts')
502 }
503
504 stage('Run k8s conformance e2e tests') {
505 orchestrate.runConformanceTests(saltMaster, K8S_API_SERVER, K8S_CONFORMANCE_IMAGE)
506 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100507 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100508
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100509
Tomáš Kukrála18de112017-03-02 13:57:47 +0100510 } catch (Throwable e) {
511 currentBuild.result = 'FAILURE'
512 throw e
Tomáš Kukrál65fb5fd2017-03-02 14:56:49 +0100513 } finally {
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100514
Tomáš Kukrála18de112017-03-02 13:57:47 +0100515 //
516 // Clean
517 //
518
Filip Pytloun794ad952017-03-03 10:39:26 +0100519 if (HEAT_STACK_DELETE.toBoolean() == true && STACK_TYPE == 'heat') {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100520 stage('Trigger cleanup job') {
Tomáš Kukrál3fee50a2017-03-03 00:46:30 +0100521 build job: 'deploy-heat-cleanup', parameters: [[$class: 'StringParameterValue', name: 'HEAT_STACK_NAME', value: HEAT_STACK_NAME]]
Tomáš Kukrála18de112017-03-02 13:57:47 +0100522 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100523 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100524 }
525 }
526}