blob: fb99f249ed3b574d4a15f9b4c13093a5e62e0c95 [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ála18de112017-03-02 13:57:47 +0100101 SALT_MASTER_URL = "http://${saltMasterHost}:8088"
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100102 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100103 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100104
Tomáš Kukrála18de112017-03-02 13:57:47 +0100105 //
106 // Connect to Salt master
107 //
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100108
Tomáš Kukrála18de112017-03-02 13:57:47 +0100109 def saltMaster
110 stage('Connect to Salt API') {
111 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
112 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100113
Tomáš Kukrála18de112017-03-02 13:57:47 +0100114 //
115 // Install
116 //
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100117
Tomáš Kukrála18de112017-03-02 13:57:47 +0100118 if (INSTALL.toLowerCase().contains('core')) {
119 stage('Install core infrastructure') {
120 // salt.master, reclass
121 // refresh_pillar
122 // sync_all
123 // linux,openssh,salt.minion.ntp
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100124
Tomáš Kukrála18de112017-03-02 13:57:47 +0100125 //orchestrate.installFoundationInfra(saltMaster)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100126 salt.enforceState(saltMaster, 'I@salt:master', ['salt.master', 'reclass'], true)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100127 salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.refresh_pillar', [], null, true)
128 salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.sync_all', [], null, true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100129 salt.enforceState(saltMaster, 'I@linux:system', ['linux', 'openssh', 'salt.minion', 'ntp'], true)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100130
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100131
Tomáš Kukrála18de112017-03-02 13:57:47 +0100132 if (INSTALL.toLowerCase().contains('kvm')) {
133 //orchestrate.installInfraKvm(saltMaster)
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álc265e352017-03-02 11:45:11 +0100136
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100137 salt.enforceState(saltMaster, 'I@salt:control', ['salt.minion', 'linux.system', 'linux.network', 'ntp'], true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100138 salt.enforceState(saltMaster, 'I@salt:control', 'libvirt', true)
139 salt.enforceState(saltMaster, 'I@salt:control', 'salt.control', true)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100140
Tomáš Kukrála18de112017-03-02 13:57:47 +0100141 sleep(300)
142
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100143 salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'saltutil.refresh_pillar', [], null, true)
144 salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'saltutil.sync_all', [], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100145
146 // workaround - install apt-transport-https
Tomáš Kukrál5c837882017-03-03 00:54:13 +0100147 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 +0100148 salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'pkg.install', ['apt-transport-https', 'refresh=True'], null, true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100149 salt.enforceState(saltMaster, 'I@linux:system', ['linux', 'openssh', 'salt.minion', 'ntp'], true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100150 }
151
152 //orchestrate.validateFoundationInfra(saltMaster)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100153 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'cmd.run', ['salt-key'], null, true)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100154 salt.runSaltProcessStep(saltMaster, 'I@salt:minion', 'test.version', [], null, true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100155 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'cmd.run', ['reclass-salt --top'], null, true)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100156 salt.runSaltProcessStep(saltMaster, 'I@reclass:storage', 'reclass.inventory', [], null, true)
157 salt.runSaltProcessStep(saltMaster, 'I@salt:minion', 'state.show_top', [], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100158 }
159 }
160
161 // install k8s
162 if (INSTALL.toLowerCase().contains('k8s')) {
163 stage('Install Kubernetes infra') {
164 //orchestrate.installOpenstackMcpInfra(saltMaster)
165
166 // Comment nameserver
167 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"])
168
169 // Install glusterfs
170 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.service'])
171
172 // Install keepalived
173 salt.runSaltProcessStep(saltMaster, 'ctl01*', 'state.sls', ['keepalived'])
174 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'state.sls', ['keepalived'])
175
176 // Check the keepalived VIPs
177 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
178
179 // Setup glusterfs
180 salt.runSaltProcessStep(saltMaster, 'ctl01*', 'state.sls', ['glusterfs.server.setup'])
181 salt.runSaltProcessStep(saltMaster, 'ctl02*', 'state.sls', ['glusterfs.server.setup'])
182 salt.runSaltProcessStep(saltMaster, 'ctl03*', 'state.sls', ['glusterfs.server.setup'])
183 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'])
184 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'])
185
186 // Install haproxy
187 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'state.sls', ['haproxy'])
188 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.status', ['haproxy'])
189
190 // Install docker
191 salt.runSaltProcessStep(saltMaster, 'I@docker:host', 'state.sls', ['docker.host'])
192 salt.runSaltProcessStep(saltMaster, 'I@docker:host', 'cmd.run', ['docker ps'])
193
194 // Install bird
195 salt.runSaltProcessStep(saltMaster, 'I@bird:server', 'state.sls', ['bird'])
196
197 // Install etcd
198 salt.runSaltProcessStep(saltMaster, 'I@etcd:server', 'state.sls', ['etcd.server.service'])
199 salt.runSaltProcessStep(saltMaster, 'I@etcd:server', 'cmd.run', ['etcdctl cluster-health'])
200
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100201 }
202
Tomáš Kukrála18de112017-03-02 13:57:47 +0100203 stage('Install Kubernetes control') {
204 //orchestrate.installOpenstackMcpControl(saltMaster)
Tomáš Kukrál06c27a92017-03-01 16:21:46 +0100205
Tomáš Kukrála18de112017-03-02 13:57:47 +0100206 // Install Kubernetes pool and Calico
207 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:pool', 'state.sls', ['kubernetes.pool'])
208 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:pool', 'cmd.run', ['calicoctl node status'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100209
Tomáš Kukrála18de112017-03-02 13:57:47 +0100210 // Setup etcd server
211 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:master', 'state.sls', ['etcd.server.setup'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100212
Tomáš Kukrála18de112017-03-02 13:57:47 +0100213 // Run k8s without master.setup
214 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:master', 'state.sls', ['kubernetes', 'exclude=kubernetes.master.setup'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100215
Tomáš Kukrála18de112017-03-02 13:57:47 +0100216 // Run k8s master setup
217 salt.runSaltProcessStep(saltMaster, 'ctl01*', 'state.sls', ['kubernetes.master.setup'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100218
Tomáš Kukrála18de112017-03-02 13:57:47 +0100219 // Revert comment nameserver
220 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 +0100221
Tomáš Kukrála18de112017-03-02 13:57:47 +0100222 // Set route
223 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 +0100224
Tomáš Kukrála18de112017-03-02 13:57:47 +0100225 // Restart kubelet
226 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:pool', 'service.restart', ['kubelet'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100227 }
228
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100229 }
230
Tomáš Kukrála18de112017-03-02 13:57:47 +0100231 // install openstack
232 if (INSTALL.toLowerCase().contains('openstack')) {
233 // install Infra and control, tests, ...
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100234
Tomáš Kukrála18de112017-03-02 13:57:47 +0100235 stage('Install OpenStack infra') {
236 //orchestrate.installOpenstackMkInfra(saltMaster, physical)
237
238 // Install keepaliveds
239 //runSaltProcessStep(master, 'I@keepalived:cluster', 'state.sls', ['keepalived'], 1)
240 salt.enforceState(saltMaster, 'ctl01*', 'keepalived', true)
241 salt.enforceState(saltMaster, 'I@keepalived:cluster', 'keepalived', true)
242
243 // Check the keepalived VIPs
244 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
245
246 // Install glusterfs
247 salt.enforceState(saltMaster, 'I@glusterfs:server', 'glusterfs.server.service', true)
248
249 //runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.setup'], 1)
250 if (INSTALL.toLowerCase().contains('kvm')) {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100251 salt.enforceState(saltMaster, 'kvm01*', 'glusterfs.server.setup', true)
252 salt.enforceState(saltMaster, 'kvm02*', 'glusterfs.server.setup', true)
253 salt.enforceState(saltMaster, 'kvm03*', 'glusterfs.server.setup', true)
Tomáš Kukrálbad54bb2017-03-02 15:46:20 +0100254 } else {
255 salt.enforceState(saltMaster, 'ctl01*', 'glusterfs.server.setup', true)
256 salt.enforceState(saltMaster, 'ctl02*', 'glusterfs.server.setup', true)
257 salt.enforceState(saltMaster, 'ctl03*', 'glusterfs.server.setup', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100258 }
259
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100260 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'], null, true)
261 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100262
263 // Install rabbitmq
264 salt.enforceState(saltMaster, 'I@rabbitmq:server', 'rabbitmq', true)
265
266 // Check the rabbitmq status
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100267 salt.runSaltProcessStep(saltMaster, 'I@rabbitmq:server', 'cmd.run', ['rabbitmqctl cluster_status'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100268
269 // Install galera
270 salt.enforceState(saltMaster, 'I@galera:master', 'galera', true)
271 salt.enforceState(saltMaster, 'I@galera:slave', 'galera', true)
272
273 // Check galera status
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100274 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'mysql.status')
275 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'mysql.status')
Tomáš Kukrála18de112017-03-02 13:57:47 +0100276
277 // Install haproxy
278 salt.enforceState(saltMaster, 'I@haproxy:proxy', 'haproxy', true)
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100279 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.status', ['haproxy'])
280 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.restart', ['rsyslog'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100281
282 // Install memcached
283 salt.enforceState(saltMaster, 'I@memcached:server', 'memcached', true)
284
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100285 }
286
Tomáš Kukrála18de112017-03-02 13:57:47 +0100287 stage('Install OpenStack control') {
288 //orchestrate.installOpenstackMkControl(saltMaster)
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100289
Tomáš Kukrála18de112017-03-02 13:57:47 +0100290 // setup keystone service
291 //runSaltProcessStep(saltMaster, 'I@keystone:server', 'state.sls', ['keystone.server'], 1)
292 salt.enforceState(saltMaster, 'ctl01*', 'keystone.server', true)
293 salt.enforceState(saltMaster, 'I@keystone:server', 'keystone.server', true)
294 // populate keystone services/tenants/roles/users
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100295
Tomáš Kukrála18de112017-03-02 13:57:47 +0100296 // keystone:client must be called locally
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100297 salt.runSaltProcessStep(saltMaster, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
298 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; keystone service-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100299
300 // Install glance and ensure glusterfs clusters
301 //runSaltProcessStep(saltMaster, 'I@glance:server', 'state.sls', ['glance.server'], 1)
302 salt.enforceState(saltMaster, 'ctl01*', 'glance.server', true)
303 salt.enforceState(saltMaster, 'I@glance:server', 'glance.server', true)
304 salt.enforceState(saltMaster, 'I@glance:server', 'glusterfs.client', true)
305
306 // Update fernet tokens before doing request on keystone server
307 salt.enforceState(saltMaster, 'I@keystone:server', 'keystone.server', true)
308
309 // Check glance service
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100310 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; glance image-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100311
312 // Install and check nova service
313 //runSaltProcessStep(saltMaster, 'I@nova:controller', 'state.sls', ['nova'], 1)
314 salt.enforceState(saltMaster, 'ctl01*', 'nova', true)
315 salt.enforceState(saltMaster, 'I@nova:controller', 'nova', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100316 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova service-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100317
318 // Install and check cinder service
319 //runSaltProcessStep(saltMaster, 'I@cinder:controller', 'state.sls', ['cinder'], 1)
320 salt.enforceState(saltMaster, 'ctl01*', 'cinder', true)
321 salt.enforceState(saltMaster, 'I@cinder:controller', 'cinder', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100322 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; cinder list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100323
324 // Install neutron service
325 //runSaltProcessStep(saltMaster, 'I@neutron:server', 'state.sls', ['neutron'], 1)
Tomáš Kukrál575e38a2017-03-02 17:12:45 +0100326 if (INSTALL.toLowerCase().contains('kvm')) {
327 salt.enforceState(saltMaster, 'ntw01*', 'neutron', true)
328 } else {
329 salt.enforceState(saltMaster, 'ctl01*', 'neutron', true)
330 }
331
Tomáš Kukrála18de112017-03-02 13:57:47 +0100332 salt.enforceState(saltMaster, 'I@neutron:server', 'neutron', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100333 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron agent-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100334
335 // Install heat service
336 //runSaltProcessStep(saltMaster, 'I@heat:server', 'state.sls', ['heat'], 1)
337 salt.enforceState(saltMaster, 'ctl01*', 'heat', true)
338 salt.enforceState(saltMaster, 'I@heat:server', 'heat', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100339 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; heat resource-type-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100340
341 // Install horizon dashboard
342 salt.enforceState(saltMaster, 'I@horizon:server', 'horizon', true)
343 salt.enforceState(saltMaster, 'I@nginx:server', 'nginx', true)
344
345 }
346
347 stage('Install OpenStack network') {
348 //orchestrate.installOpenstackMkNetwork(saltMaster, physical)
349
350 // Install opencontrail database services
351 //runSaltProcessStep(saltMaster, 'I@opencontrail:database', 'state.sls', ['opencontrail.database'], 1)
352 salt.enforceState(saltMaster, 'ntw01*', 'opencontrail.database', true)
353 salt.enforceState(saltMaster, 'I@opencontrail:database', 'opencontrail.database', true)
354
355 // Install opencontrail control services
356 //runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'state.sls', ['opencontrail'], 1)
357 salt.enforceState(saltMaster, 'ntw01*', 'opencontrail', true)
358 salt.enforceState(saltMaster, 'I@opencontrail:control', 'opencontrail', true)
Tomáš Kukrál3b8ad5e2017-03-02 23:03:27 +0100359 salt.enforceState(saltMaster, 'I@opencontrail:collector', 'opencontrail', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100360
361 // Provision opencontrail control services
362 if (INSTALL.toLowerCase().contains('kvm')) {
Tomáš Kukrál575e38a2017-03-02 17:12:45 +0100363 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)
364 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)
365 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)
366 } else {
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100367 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)
368 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)
369 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 +0100370 }
371
372 // Test opencontrail
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100373 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'cmd.run', ['contrail-status'], null, true)
374 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'], null, true)
375 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100376 }
377
378 stage('Install OpenStack compute') {
379 //orchestrate.installOpenstackMkCompute(saltMaster, physical)
380 // Configure compute nodes
Tomáš Kukrálda26d902017-03-02 22:19:00 +0100381 retry(2) {
Tomáš Kukrál02cda9f2017-03-02 22:32:57 +0100382 salt.runSaltProcessStep(saltMaster, 'I@nova:compute', 'state.apply', [], null, true)
Tomáš Kukrálda26d902017-03-02 22:19:00 +0100383 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100384
385 // Provision opencontrail virtual routers
386 if (INSTALL.toLowerCase().contains('kvm')) {
Tomáš Kukrál834fe212017-03-02 22:50:49 +0100387 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 +0100388 } else {
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100389 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 +0100390 }
391
Tomáš Kukrálc39610c2017-03-02 22:56:06 +0100392 salt.runSaltProcessStep(saltMaster, 'I@nova:compute', 'system.reboot', [], null, true)
Tomáš Kukrál3b8ad5e2017-03-02 23:03:27 +0100393 sleep(10)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100394 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100395
Tomáš Kukrál00ed1302017-03-03 17:38:40 +0100396 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100397
Tomáš Kukrál00ed1302017-03-03 17:38:40 +0100398
399 if (INSTALL.toLowerCase().contains('stacklight')) {
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100400 stage('Install StackLight') {
401 // infra install
402 // Install the StackLight backends
403 salt.enforceState(saltMaster, '*01* and I@elasticsearch:server', 'elasticsearch.server', true)
404 salt.enforceState(saltMaster, 'I@elasticsearch:server', 'elasticsearch.server', true)
405
406 salt.enforceState(saltMaster, '*01* and I@influxdb:server', 'influxdb', true)
407 salt.enforceState(saltMaster, 'I@influxdb:server', 'influxdb', true)
408
409 salt.enforceState(saltMaster, '*01* and I@kibana:server', 'kibana.server', true)
410 salt.enforceState(saltMaster, 'I@kibana:server', 'kibana.server', true)
411
412 salt.enforceState(saltMaster, '*01* and I@grafana:server','grafana.server', true)
413 salt.enforceState(saltMaster, 'I@grafana:server','grafana.server', true)
414
415 salt.enforceState(saltMaster, 'I@nagios:server', 'nagios.server', true)
416 salt.enforceState(saltMaster, 'I@elasticsearch:client', 'elasticsearch.client.service', true)
417 salt.enforceState(saltMaster, 'I@kibana:client', 'kibana.client.service', true)
418 // nw salt.enforceState('I@kibana:client or I@elasticsearch:client' --async service.restart salt-minion
419
420 sleep(10)
421 salt.enforceState(saltMaster, 'I@redis:cluster:role:master', 'redis', true)
422 salt.enforceState(saltMaster, 'I@redis:cluster:role:slave', 'redis', true)
423
424 salt.enforceState(saltMaster, '*01 and I@sensu:server', 'sensu', true)
425 salt.enforceState(saltMaster, 'I@sensu:server', 'sensu', true)
426
427 salt.enforceState(saltMaster, 'I@elasticsearch:client', 'elasticsearch.client', true)
428 salt.enforceState(saltMaster, 'I@kibana:client', 'kibana.client', true)
429
430 // install monitor
431 // Restart salt-minion to make sure that it uses the latest Jinja library
432 // no way: salt '*' --async service.restart salt-minion; sleep 15
433
434 // Start by flusing Salt Mine to make sure it is clean
435 // Also clean-up the grains files to make sure that we start from a clean state
436 // nw salt "*" mine.flush
437 // nw salt "*" file.remove /etc/salt/grains.d/collectd
438 // nw salt "*" file.remove /etc/salt/grains.d/grafana
439 // nw salt "*" file.remove /etc/salt/grains.d/heka
440 // nw salt "*" file.remove /etc/salt/grains.d/sensu
441 // nw salt "*" file.remove /etc/salt/grains
442
443 // Install collectd, heka and sensu services on the nodes, this will also
444 // generate the metadata that goes into the grains and eventually into Salt Mine
445 salt.enforceState(saltMaster, '*', 'collectd, true)
446 salt.enforceState(saltMaster, '*', 'heka', true)
447 salt.enforceState(saltMaster, 'I@sensu:client', 'sensu', true)
448
449 // Gather the Grafana metadata as grains
450 salt.enforceState(saltMaster, 'I@grafana:collector', 'grafana.collector', true)
451
452 // Update Salt Mine
453 salt.enforceState(saltMaster, '*', 'salt.minion.grains', true)
454 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_modules', [], null, true)
455 salt.runSaltProcessStep(saltMaster, '*', 'mine.update', [], null, true)
456
457 sleep(5)
458
459 // Update Heka
460 salt.enforceState(saltMaster, 'I@heka:aggregator:enabled:True or I@heka:remote_collector:enabled:True', 'heka', true)
461
462 // Update collectd
463 salt.enforceState(saltMaster, 'I@collectd:remote_client:enabled:True', 'collectd', true)
464
465 // Update Nagios
466 salt.enforceState(saltMaster, 'I@nagios:server', 'nagios', true)
467 // Stop the Nagios service because the package starts it by default and it will
468 // started later only on the node holding the VIP address
469 salt.runSaltProcessStep(saltMaster, 'I@nagios:server', 'service.stop', ['nagios3'], null, true)
470
471 // Update Sensu
472 salt.enforceState(saltMaster, 'I@sensu:server', 'sensu', true)
473
474 // Finalize the configuration of Grafana (add the dashboards...)
475 salt.enforceState(saltMaster, 'I@grafana:client', 'grafana.client.service', true)
476 // nw salt -C 'I@grafana:client' --async service.restart salt-minion; sleep 10
477 salt.enforceState(saltMaster, 'I@grafana:client', 'grafana.client', true)
478
479 // Get the StackLight monitoring VIP addres
480 // TODO
481 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
482 //vip=${vip:=172.16.10.253}
483 salt.runSaltProcessStep(saltMaster, cmd.run
484 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}