blob: 8f0d20f2d2c3a13a5c09f189545bacd8631ca43a [file] [log] [blame]
Tomáš Kukrálb9957b32017-02-28 14:49:00 +01001/**
2 *
3 * Launch heat stack with basic k8s
4 * Flow parameters:
5 * STACK_TYPE Orchestration engine: heat, ''
6 * INSTALL What should be installed (k8s, openstack, ...)
Tomáš Kukrál55357d02017-02-28 22:56:45 +01007 * TEST What should be tested (k8s, openstack, ...)
Tomáš Kukrálb9957b32017-02-28 14:49:00 +01008 *
9 * Expected parameters:
10 *
11 * required for STACK_TYPE=heat
12 * HEAT_TEMPLATE_URL URL to git repo with Heat templates
13 * HEAT_TEMPLATE_CREDENTIALS Credentials to the Heat templates repo
14 * HEAT_TEMPLATE_BRANCH Heat templates repo branch
15 * HEAT_STACK_TEMPLATE Heat stack HOT template
16 * HEAT_STACK_ENVIRONMENT Heat stack environmental parameters
17 * HEAT_STACK_ZONE Heat stack availability zone
18 * HEAT_STACK_PUBLIC_NET Heat stack floating IP pool
19 * HEAT_STACK_DELETE Delete Heat stack when finished (bool)
20 * HEAT_STACK_CLEANUP_JOB Name of job for deleting Heat stack
21 * HEAT_STACK_REUSE Reuse Heat stack (don't create one)
22 * OPENSTACK_API_URL OpenStack API address
23 * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
24 * OPENSTACK_API_PROJECT OpenStack project to connect to
25 * OPENSTACK_API_CLIENT Versions of OpenStack python clients
26 * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
27 *
28 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
29 *
30 * required for STACK_TYPE=NONE or empty string
31 * SALT_MASTER_URL URL of Salt-API
32
33 * K8S_API_SERVER Kubernetes API address
34 * K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
35 *
Victor Ryzhenkin5f3b7e62017-03-09 16:02:58 +040036 * TEMPEST_IMAGE_LINK Tempest image link
37 *
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010038 */
39
40git = new com.mirantis.mk.Git()
41openstack = new com.mirantis.mk.Openstack()
42salt = new com.mirantis.mk.Salt()
Tomáš Kukrál3e4029d2017-03-07 09:59:40 +010043common = new com.mirantis.mk.Common()
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010044
Tomáš Kukrále80680a2017-03-02 16:34:35 +010045
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +010046timestamps {
47 node {
Tomáš Kukrála18de112017-03-02 13:57:47 +010048 try {
Tomáš Kukrále80680a2017-03-02 16:34:35 +010049
50
Tomáš Kukrála18de112017-03-02 13:57:47 +010051 //
52 // Prepare machines
53 //
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010054
Tomáš Kukrála18de112017-03-02 13:57:47 +010055 stage ('Create infrastructure') {
56 if (STACK_TYPE == 'heat') {
57 // value defaults
58 def openstackCloud
59 def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty'
60 def openstackEnv = "${env.WORKSPACE}/venv"
Tomáš Kukrálb9957b32017-02-28 14:49:00 +010061
Filip Pytloun794ad952017-03-03 10:39:26 +010062 if (HEAT_STACK_REUSE.toBoolean() == true && HEAT_STACK_NAME == '') {
63 error("If you want to reuse existing stack you need to provide it's name")
64 }
65
66 if (HEAT_STACK_REUSE.toBoolean() == false) {
67 // Don't allow to set custom heat stack name
68 wrap([$class: 'BuildUser']) {
Tomáš Kukrál24d7fe62017-03-03 10:57:11 +010069 if (env.BUILD_USER_ID) {
70 HEAT_STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
71 } else {
72 HEAT_STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
73 }
Filip Pytloun794ad952017-03-03 10:39:26 +010074 currentBuild.description = HEAT_STACK_NAME
75 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +010076 }
Tomáš Kukrála18de112017-03-02 13:57:47 +010077
Tomáš Kukrálcbabec42017-03-02 16:24:04 +010078 // set description
Tomáš Kukrálaeb5c922017-03-02 17:00:48 +010079 currentBuild.description = "${HEAT_STACK_NAME}"
Tomáš Kukrálcbabec42017-03-02 16:24:04 +010080
Tomáš Kukrála18de112017-03-02 13:57:47 +010081 // get templates
82 git.checkoutGitRepository('template', HEAT_TEMPLATE_URL, HEAT_TEMPLATE_BRANCH, HEAT_TEMPLATE_CREDENTIALS)
83
84 // create openstack env
85 openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion)
86 openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT)
87 openstack.getKeystoneToken(openstackCloud, openstackEnv)
88
89 // launch stack
Filip Pytloun794ad952017-03-03 10:39:26 +010090 if (HEAT_STACK_REUSE.toBoolean() == false) {
Tomáš Kukrála18de112017-03-02 13:57:47 +010091 stage('Launch new Heat stack') {
92 // create stack
93 envParams = [
94 'instance_zone': HEAT_STACK_ZONE,
95 'public_net': HEAT_STACK_PUBLIC_NET
96 ]
97 openstack.createHeatStack(openstackCloud, HEAT_STACK_NAME, HEAT_STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, openstackEnv)
98 }
99 }
100
101 // get SALT_MASTER_URL
102 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, HEAT_STACK_NAME, 'salt_master_ip', openstackEnv)
Tomáš Kukrálaeb5c922017-03-02 17:00:48 +0100103 currentBuild.description = "${HEAT_STACK_NAME}: ${saltMasterHost}"
Tomáš Kukrál615aa9c2017-03-04 15:29:08 +0100104
105 if (INSTALL.toLowerCase().contains('kvm')) {
Tomáš Kukrál61509292017-03-04 16:27:07 +0100106 saltPort = 8088
Tomáš Kukrál615aa9c2017-03-04 15:29:08 +0100107 } else {
Tomáš Kukrál61509292017-03-04 16:27:07 +0100108 saltPort = 8000
Tomáš Kukrál615aa9c2017-03-04 15:29:08 +0100109 }
110
Tomáš Kukrál61509292017-03-04 16:27:07 +0100111 SALT_MASTER_URL = "http://${saltMasterHost}:${saltPort}"
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100112 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100113 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100114
Tomáš Kukrála18de112017-03-02 13:57:47 +0100115 //
116 // Connect to Salt master
117 //
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100118
Tomáš Kukrála18de112017-03-02 13:57:47 +0100119 def saltMaster
120 stage('Connect to Salt API') {
121 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
122 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100123
Tomáš Kukrála18de112017-03-02 13:57:47 +0100124 //
125 // Install
126 //
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100127
Tomáš Kukrála18de112017-03-02 13:57:47 +0100128 if (INSTALL.toLowerCase().contains('core')) {
129 stage('Install core infrastructure') {
130 // salt.master, reclass
131 // refresh_pillar
132 // sync_all
133 // linux,openssh,salt.minion.ntp
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100134
Tomáš Kukrála18de112017-03-02 13:57:47 +0100135 //orchestrate.installFoundationInfra(saltMaster)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100136 salt.enforceState(saltMaster, 'I@salt:master', ['salt.master', 'reclass'], true)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100137 salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.refresh_pillar', [], null, true)
138 salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.sync_all', [], null, true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100139 salt.enforceState(saltMaster, 'I@linux:system', ['linux', 'openssh', 'salt.minion', 'ntp'], true)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100140
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100141
Tomáš Kukrála18de112017-03-02 13:57:47 +0100142 if (INSTALL.toLowerCase().contains('kvm')) {
143 //orchestrate.installInfraKvm(saltMaster)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100144 salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.refresh_pillar', [], null, true)
145 salt.runSaltProcessStep(saltMaster, 'I@linux:system', 'saltutil.sync_all', [], null, true)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100146
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100147 salt.enforceState(saltMaster, 'I@salt:control', ['salt.minion', 'linux.system', 'linux.network', 'ntp'], true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100148 salt.enforceState(saltMaster, 'I@salt:control', 'libvirt', true)
149 salt.enforceState(saltMaster, 'I@salt:control', 'salt.control', true)
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100150
Tomáš Kukrál3e5c5bf2017-03-09 16:45:54 +0100151 sleep(600)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100152
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100153 salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'saltutil.refresh_pillar', [], null, true)
154 salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'saltutil.sync_all', [], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100155
156 // workaround - install apt-transport-https
Tomáš Kukrálbe9dfa52017-03-08 13:54:03 +0100157 //salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'cmd.run', ['apt-get update -y && apt-get install -y apt-transport-https'], null, true)
158 //salt.runSaltProcessStep(saltMaster, '* and not kvm*', 'pkg.install', ['apt-transport-https', 'refresh=True'], null, true)
159 salt.enforceState(saltMaster, 'I@linux:system', ['linux', 'salt.minion'], true)
160 salt.enforceState(saltMaster, 'I@linux:system', ['openssh', 'salt.minion', 'ntp'], true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100161 }
162
163 //orchestrate.validateFoundationInfra(saltMaster)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100164 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'cmd.run', ['salt-key'], null, true)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100165 salt.runSaltProcessStep(saltMaster, 'I@salt:minion', 'test.version', [], null, true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100166 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'cmd.run', ['reclass-salt --top'], null, true)
Tomáš Kukrál01f284a2017-03-02 23:14:20 +0100167 salt.runSaltProcessStep(saltMaster, 'I@reclass:storage', 'reclass.inventory', [], null, true)
168 salt.runSaltProcessStep(saltMaster, 'I@salt:minion', 'state.show_top', [], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100169 }
170 }
171
172 // install k8s
173 if (INSTALL.toLowerCase().contains('k8s')) {
174 stage('Install Kubernetes infra') {
175 //orchestrate.installOpenstackMcpInfra(saltMaster)
176
177 // Comment nameserver
178 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"])
179
180 // Install glusterfs
181 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.service'])
182
183 // Install keepalived
184 salt.runSaltProcessStep(saltMaster, 'ctl01*', 'state.sls', ['keepalived'])
185 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'state.sls', ['keepalived'])
186
187 // Check the keepalived VIPs
188 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
189
190 // Setup glusterfs
191 salt.runSaltProcessStep(saltMaster, 'ctl01*', 'state.sls', ['glusterfs.server.setup'])
192 salt.runSaltProcessStep(saltMaster, 'ctl02*', 'state.sls', ['glusterfs.server.setup'])
193 salt.runSaltProcessStep(saltMaster, 'ctl03*', 'state.sls', ['glusterfs.server.setup'])
194 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'])
195 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'])
196
197 // Install haproxy
198 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'state.sls', ['haproxy'])
199 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.status', ['haproxy'])
200
201 // Install docker
202 salt.runSaltProcessStep(saltMaster, 'I@docker:host', 'state.sls', ['docker.host'])
203 salt.runSaltProcessStep(saltMaster, 'I@docker:host', 'cmd.run', ['docker ps'])
204
205 // Install bird
206 salt.runSaltProcessStep(saltMaster, 'I@bird:server', 'state.sls', ['bird'])
207
208 // Install etcd
209 salt.runSaltProcessStep(saltMaster, 'I@etcd:server', 'state.sls', ['etcd.server.service'])
210 salt.runSaltProcessStep(saltMaster, 'I@etcd:server', 'cmd.run', ['etcdctl cluster-health'])
211
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100212 }
213
Tomáš Kukrála18de112017-03-02 13:57:47 +0100214 stage('Install Kubernetes control') {
215 //orchestrate.installOpenstackMcpControl(saltMaster)
Tomáš Kukrál06c27a92017-03-01 16:21:46 +0100216
Tomáš Kukrála18de112017-03-02 13:57:47 +0100217 // Install Kubernetes pool and Calico
218 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:pool', 'state.sls', ['kubernetes.pool'])
219 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:pool', 'cmd.run', ['calicoctl node status'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100220
Tomáš Kukrála18de112017-03-02 13:57:47 +0100221 // Setup etcd server
222 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:master', 'state.sls', ['etcd.server.setup'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100223
Tomáš Kukrála18de112017-03-02 13:57:47 +0100224 // Run k8s without master.setup
225 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:master', 'state.sls', ['kubernetes', 'exclude=kubernetes.master.setup'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100226
Tomáš Kukrála18de112017-03-02 13:57:47 +0100227 // Run k8s master setup
228 salt.runSaltProcessStep(saltMaster, 'ctl01*', 'state.sls', ['kubernetes.master.setup'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100229
Tomáš Kukrála18de112017-03-02 13:57:47 +0100230 // Revert comment nameserver
231 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 +0100232
Tomáš Kukrála18de112017-03-02 13:57:47 +0100233 // Set route
234 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 +0100235
Tomáš Kukrála18de112017-03-02 13:57:47 +0100236 // Restart kubelet
237 salt.runSaltProcessStep(saltMaster, 'I@kubernetes:pool', 'service.restart', ['kubelet'])
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100238 }
239
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100240 }
241
Tomáš Kukrála18de112017-03-02 13:57:47 +0100242 // install openstack
243 if (INSTALL.toLowerCase().contains('openstack')) {
244 // install Infra and control, tests, ...
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100245
Tomáš Kukrála18de112017-03-02 13:57:47 +0100246 stage('Install OpenStack infra') {
247 //orchestrate.installOpenstackMkInfra(saltMaster, physical)
248
249 // Install keepaliveds
250 //runSaltProcessStep(master, 'I@keepalived:cluster', 'state.sls', ['keepalived'], 1)
251 salt.enforceState(saltMaster, 'ctl01*', 'keepalived', true)
252 salt.enforceState(saltMaster, 'I@keepalived:cluster', 'keepalived', true)
253
254 // Check the keepalived VIPs
255 salt.runSaltProcessStep(saltMaster, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
256
257 // Install glusterfs
258 salt.enforceState(saltMaster, 'I@glusterfs:server', 'glusterfs.server.service', true)
259
260 //runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.setup'], 1)
261 if (INSTALL.toLowerCase().contains('kvm')) {
Tomáš Kukrála18de112017-03-02 13:57:47 +0100262 salt.enforceState(saltMaster, 'kvm01*', 'glusterfs.server.setup', true)
263 salt.enforceState(saltMaster, 'kvm02*', 'glusterfs.server.setup', true)
264 salt.enforceState(saltMaster, 'kvm03*', 'glusterfs.server.setup', true)
Tomáš Kukrálbad54bb2017-03-02 15:46:20 +0100265 } else {
266 salt.enforceState(saltMaster, 'ctl01*', 'glusterfs.server.setup', true)
267 salt.enforceState(saltMaster, 'ctl02*', 'glusterfs.server.setup', true)
268 salt.enforceState(saltMaster, 'ctl03*', 'glusterfs.server.setup', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100269 }
270
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100271 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'], null, true)
272 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100273
274 // Install rabbitmq
275 salt.enforceState(saltMaster, 'I@rabbitmq:server', 'rabbitmq', true)
276
277 // Check the rabbitmq status
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100278 salt.runSaltProcessStep(saltMaster, 'I@rabbitmq:server', 'cmd.run', ['rabbitmqctl cluster_status'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100279
280 // Install galera
281 salt.enforceState(saltMaster, 'I@galera:master', 'galera', true)
282 salt.enforceState(saltMaster, 'I@galera:slave', 'galera', true)
283
284 // Check galera status
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100285 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'mysql.status')
286 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'mysql.status')
Tomáš Kukrála18de112017-03-02 13:57:47 +0100287
Tomáš Kukrálaa8f5532017-03-07 13:34:39 +0100288 // Setup mysql client
Tomáš Kukrálbe9dfa52017-03-08 13:54:03 +0100289 salt.enforceState(saltMaster, 'I@mysql:client', 'mysql.client', true)
Tomáš Kukrálaa8f5532017-03-07 13:34:39 +0100290
Tomáš Kukrála18de112017-03-02 13:57:47 +0100291 // Install haproxy
292 salt.enforceState(saltMaster, 'I@haproxy:proxy', 'haproxy', true)
Ales Komarek96ff9ed2017-03-02 18:37:51 +0100293 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.status', ['haproxy'])
294 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'service.restart', ['rsyslog'])
Tomáš Kukrála18de112017-03-02 13:57:47 +0100295
296 // Install memcached
297 salt.enforceState(saltMaster, 'I@memcached:server', 'memcached', true)
298
Tomáš Kukrálc265e352017-03-02 11:45:11 +0100299 }
300
Tomáš Kukrála18de112017-03-02 13:57:47 +0100301 stage('Install OpenStack control') {
302 //orchestrate.installOpenstackMkControl(saltMaster)
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100303
Tomáš Kukrála18de112017-03-02 13:57:47 +0100304 // setup keystone service
305 //runSaltProcessStep(saltMaster, 'I@keystone:server', 'state.sls', ['keystone.server'], 1)
306 salt.enforceState(saltMaster, 'ctl01*', 'keystone.server', true)
307 salt.enforceState(saltMaster, 'I@keystone:server', 'keystone.server', true)
308 // populate keystone services/tenants/roles/users
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100309
Tomáš Kukrála18de112017-03-02 13:57:47 +0100310 // keystone:client must be called locally
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100311 salt.runSaltProcessStep(saltMaster, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
312 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; keystone service-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100313
314 // Install glance and ensure glusterfs clusters
315 //runSaltProcessStep(saltMaster, 'I@glance:server', 'state.sls', ['glance.server'], 1)
316 salt.enforceState(saltMaster, 'ctl01*', 'glance.server', true)
317 salt.enforceState(saltMaster, 'I@glance:server', 'glance.server', true)
318 salt.enforceState(saltMaster, 'I@glance:server', 'glusterfs.client', true)
319
320 // Update fernet tokens before doing request on keystone server
321 salt.enforceState(saltMaster, 'I@keystone:server', 'keystone.server', true)
322
323 // Check glance service
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100324 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; glance image-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100325
326 // Install and check nova service
327 //runSaltProcessStep(saltMaster, 'I@nova:controller', 'state.sls', ['nova'], 1)
328 salt.enforceState(saltMaster, 'ctl01*', 'nova', true)
329 salt.enforceState(saltMaster, 'I@nova:controller', 'nova', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100330 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova service-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100331
332 // Install and check cinder service
333 //runSaltProcessStep(saltMaster, 'I@cinder:controller', 'state.sls', ['cinder'], 1)
334 salt.enforceState(saltMaster, 'ctl01*', 'cinder', true)
335 salt.enforceState(saltMaster, 'I@cinder:controller', 'cinder', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100336 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; cinder list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100337
338 // Install neutron service
339 //runSaltProcessStep(saltMaster, 'I@neutron:server', 'state.sls', ['neutron'], 1)
Tomáš Kukrál575e38a2017-03-02 17:12:45 +0100340
Tomáš Kukrál35ba56b2017-03-08 19:18:50 +0100341 salt.enforceState(saltMaster, '*01* and I@neutron:server', 'neutron', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100342 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron agent-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100343
344 // Install heat service
345 //runSaltProcessStep(saltMaster, 'I@heat:server', 'state.sls', ['heat'], 1)
346 salt.enforceState(saltMaster, 'ctl01*', 'heat', true)
347 salt.enforceState(saltMaster, 'I@heat:server', 'heat', true)
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100348 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; heat resource-type-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100349
350 // Install horizon dashboard
351 salt.enforceState(saltMaster, 'I@horizon:server', 'horizon', true)
352 salt.enforceState(saltMaster, 'I@nginx:server', 'nginx', true)
353
354 }
355
356 stage('Install OpenStack network') {
357 //orchestrate.installOpenstackMkNetwork(saltMaster, physical)
358
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100359 if (INSTALL.toLowerCase().contains('contrail')) {
360 // Install opencontrail database services
361 //runSaltProcessStep(saltMaster, 'I@opencontrail:database', 'state.sls', ['opencontrail.database'], 1)
Tomáš Kukrálf8ac03b2017-03-10 15:08:22 +0100362 try {
363 salt.enforceState(saltMaster, 'ntw01*', 'opencontrail.database', true)
Tomáš Kukrál0dccc892017-03-10 15:42:44 +0100364 } catch (Exception e) {
Tomáš Kukrálf8ac03b2017-03-10 15:08:22 +0100365 print.warningMsg('Exception in state opencontrail.database on ntw01*')
366 }
367
368 try {
369 salt.enforceState(saltMaster, 'I@opencontrail:database', 'opencontrail.database', true)
Tomáš Kukrál0dccc892017-03-10 15:42:44 +0100370 } catch (Exception e) {
Tomáš Kukrálf8ac03b2017-03-10 15:08:22 +0100371 print.warningMsg('Exception in state opencontrail.database on I@opencontrail:database')
372 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100373
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100374 // Install opencontrail control services
375 //runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'state.sls', ['opencontrail'], 1)
376 salt.enforceState(saltMaster, 'ntw01*', 'opencontrail', true)
377 salt.enforceState(saltMaster, 'I@opencontrail:control', 'opencontrail', true)
378 salt.enforceState(saltMaster, 'I@opencontrail:collector', 'opencontrail', true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100379
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100380 // Provision opencontrail control services
381 if (INSTALL.toLowerCase().contains('kvm')) {
382 // psysical contrail (kvm)
383 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)
384 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)
385 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)
386 } else {
387 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)
388 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)
389 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)
390 }
391
392 // Test opencontrail
393 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'cmd.run', ['contrail-status'], null, true)
394 } else if (INSTALL.toLowerCase().contains('ovs')) {
395 // Apply gateway
396 salt.runSaltProcessStep(saltMaster, 'I@neutron:gateway', 'state.apply', [], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100397 }
398
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100399 // Pring information
Tomáš Kukrálcbdb1d02017-03-02 16:08:51 +0100400 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'], null, true)
401 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'], null, true)
Tomáš Kukrála18de112017-03-02 13:57:47 +0100402 }
403
404 stage('Install OpenStack compute') {
405 //orchestrate.installOpenstackMkCompute(saltMaster, physical)
406 // Configure compute nodes
Tomáš Kukrálda26d902017-03-02 22:19:00 +0100407 retry(2) {
Tomáš Kukrál02cda9f2017-03-02 22:32:57 +0100408 salt.runSaltProcessStep(saltMaster, 'I@nova:compute', 'state.apply', [], null, true)
Tomáš Kukrálda26d902017-03-02 22:19:00 +0100409 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100410
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100411 if (INSTALL.toLowerCase().contains('contrail')) {
412 // Provision opencontrail virtual routers
413 if (INSTALL.toLowerCase().contains('kvm')) {
414 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)
415 } else {
416 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)
417 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100418
Tomáš Kukráld5a40af2017-03-07 15:34:58 +0100419 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)
420 sleep(300)
421 }
Tomáš Kukrála18de112017-03-02 13:57:47 +0100422 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100423
Tomáš Kukrál00ed1302017-03-03 17:38:40 +0100424 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100425
Tomáš Kukrál00ed1302017-03-03 17:38:40 +0100426
427 if (INSTALL.toLowerCase().contains('stacklight')) {
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100428 stage('Install StackLight') {
429 // infra install
430 // Install the StackLight backends
431 salt.enforceState(saltMaster, '*01* and I@elasticsearch:server', 'elasticsearch.server', true)
432 salt.enforceState(saltMaster, 'I@elasticsearch:server', 'elasticsearch.server', true)
433
434 salt.enforceState(saltMaster, '*01* and I@influxdb:server', 'influxdb', true)
435 salt.enforceState(saltMaster, 'I@influxdb:server', 'influxdb', true)
436
437 salt.enforceState(saltMaster, '*01* and I@kibana:server', 'kibana.server', true)
438 salt.enforceState(saltMaster, 'I@kibana:server', 'kibana.server', true)
439
440 salt.enforceState(saltMaster, '*01* and I@grafana:server','grafana.server', true)
441 salt.enforceState(saltMaster, 'I@grafana:server','grafana.server', true)
442
443 salt.enforceState(saltMaster, 'I@nagios:server', 'nagios.server', true)
444 salt.enforceState(saltMaster, 'I@elasticsearch:client', 'elasticsearch.client.service', true)
445 salt.enforceState(saltMaster, 'I@kibana:client', 'kibana.client.service', true)
446 // nw salt.enforceState('I@kibana:client or I@elasticsearch:client' --async service.restart salt-minion
447
448 sleep(10)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100449
Marek Celoud3fd4ea92017-03-10 11:36:01 +0100450 salt.runSaltProcessStep(saltMaster, 'I@elasticsearch.client', 'cmd.run', ['salt-call state.sls elasticsearch.client'], null, true)
451 // salt.enforceState(saltMaster, 'I@elasticsearch:client', 'elasticsearch.client', true)
Marek Celoud481bc422017-03-10 12:13:19 +0100452 salt.runSaltProcessStep(saltMaster, 'I@kibana.client', 'cmd.run', ['salt-call state.sls kibana.client'], null, true)
453 // salt.enforceState(saltMaster, 'I@kibana:client', 'kibana.client', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100454
455 // install monitor
456 // Restart salt-minion to make sure that it uses the latest Jinja library
457 // no way: salt '*' --async service.restart salt-minion; sleep 15
458
459 // Start by flusing Salt Mine to make sure it is clean
460 // Also clean-up the grains files to make sure that we start from a clean state
461 // nw salt "*" mine.flush
462 // nw salt "*" file.remove /etc/salt/grains.d/collectd
463 // nw salt "*" file.remove /etc/salt/grains.d/grafana
464 // nw salt "*" file.remove /etc/salt/grains.d/heka
465 // nw salt "*" file.remove /etc/salt/grains.d/sensu
466 // nw salt "*" file.remove /etc/salt/grains
467
468 // Install collectd, heka and sensu services on the nodes, this will also
469 // generate the metadata that goes into the grains and eventually into Salt Mine
Tomáš Kukrál2aa3c472017-03-03 17:47:08 +0100470 salt.enforceState(saltMaster, '*', 'collectd', true)
Marek Celoudd6303412017-03-09 23:14:32 +0100471 salt.enforceState(saltMaster, '*', 'salt.minion', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100472 salt.enforceState(saltMaster, '*', 'heka', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100473
474 // Gather the Grafana metadata as grains
475 salt.enforceState(saltMaster, 'I@grafana:collector', 'grafana.collector', true)
476
477 // Update Salt Mine
478 salt.enforceState(saltMaster, '*', 'salt.minion.grains', true)
479 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_modules', [], null, true)
480 salt.runSaltProcessStep(saltMaster, '*', 'mine.update', [], null, true)
481
482 sleep(5)
483
484 // Update Heka
485 salt.enforceState(saltMaster, 'I@heka:aggregator:enabled:True or I@heka:remote_collector:enabled:True', 'heka', true)
486
487 // Update collectd
488 salt.enforceState(saltMaster, 'I@collectd:remote_client:enabled:True', 'collectd', true)
489
490 // Update Nagios
491 salt.enforceState(saltMaster, 'I@nagios:server', 'nagios', true)
492 // Stop the Nagios service because the package starts it by default and it will
493 // started later only on the node holding the VIP address
494 salt.runSaltProcessStep(saltMaster, 'I@nagios:server', 'service.stop', ['nagios3'], null, true)
495
496 // Update Sensu
Tomáš Kukrál1ef3da72017-03-06 14:44:00 +0100497 // TODO for stacklight team, should be fixed in model
498 //salt.enforceState(saltMaster, 'I@sensu:server', 'sensu', true)
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100499
500 // Finalize the configuration of Grafana (add the dashboards...)
501 salt.enforceState(saltMaster, 'I@grafana:client', 'grafana.client.service', true)
502 // nw salt -C 'I@grafana:client' --async service.restart salt-minion; sleep 10
503 salt.enforceState(saltMaster, 'I@grafana:client', 'grafana.client', true)
504
505 // Get the StackLight monitoring VIP addres
506 // TODO
507 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
508 //vip=${vip:=172.16.10.253}
Tomáš Kukrál6412a8c2017-03-07 14:03:47 +0100509 def pillar = salt.pillarGet(saltMaster, 'ctl01*', '_param:stacklight_monitor_address')
Tomáš Kukrál3e4029d2017-03-07 09:59:40 +0100510 print(pillar)
Tomáš Kukrálba73bcf2017-03-07 13:48:56 +0100511 def stacklight_vip = pillar['return'][0]['ctl01.nfv-lab.local']
512 common.infoMsg("restart services on node with IP: ${stacklight_vip}")
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100513
Tomáš Kukrál6412a8c2017-03-07 14:03:47 +0100514 if (stacklight_vip == "") {
515 throw new Exception("Missing stacklight_vip")
516 } else {
517 // (re)Start manually the services that are bound to the monitoring VIP
Tomáš Kukrál1b08c8c2017-03-07 16:51:49 +0100518 salt.runSaltProcessStep(saltMaster, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collectd'], null, true)
519 salt.runSaltProcessStep(saltMaster, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collector'], null, true)
520 salt.runSaltProcessStep(saltMaster, "G@ipv4:${stacklight_vip}", 'service.restart', ['aggregator'], null, true)
521 salt.runSaltProcessStep(saltMaster, "G@ipv4:${stacklight_vip}", 'service.restart', ['nagios3'], null, true)
Tomáš Kukrál6412a8c2017-03-07 14:03:47 +0100522 }
Tomáš Kukrál2b4c1282017-03-03 17:25:26 +0100523 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100524 }
525
Tomáš Kukrála18de112017-03-02 13:57:47 +0100526 //
527 // Test
528 //
529
530 if (TEST.toLowerCase().contains('k8s')) {
531 stage('Run k8s bootstrap tests') {
532 orchestrate.runConformanceTests(saltMaster, K8S_API_SERVER, 'tomkukral/k8s-scripts')
533 }
534
535 stage('Run k8s conformance e2e tests') {
536 orchestrate.runConformanceTests(saltMaster, K8S_API_SERVER, K8S_CONFORMANCE_IMAGE)
537 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100538 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100539
Victor Ryzhenkin5f3b7e62017-03-09 16:02:58 +0400540 if (TEST.toLowerCase().contains('openstack')) {
541 stage('Run OpenStack tests') {
542 test.runTempestTests(saltMaster, TEMPEST_IMAGE_LINK)
543 }
544
545 stage('Copy Tempest results to config node') {
546 test.copyTempestResults(saltMaster)
547 }
548 }
549
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100550
Tomáš Kukrála18de112017-03-02 13:57:47 +0100551 } catch (Throwable e) {
552 currentBuild.result = 'FAILURE'
553 throw e
Tomáš Kukrál65fb5fd2017-03-02 14:56:49 +0100554 } finally {
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100555
Tomáš Kukrál96b12d52017-03-07 22:43:37 +0100556 // send notification
557 common.sendNotification(currentBuild.result,HEAT_STACK_NAME,["slack"])
558
Tomáš Kukrála18de112017-03-02 13:57:47 +0100559 //
560 // Clean
561 //
562
Tomáš Kukrálc9a630a2017-03-07 17:28:53 +0100563 if (STACK_TYPE == 'heat') {
564 if (HEAT_STACK_DELETE.toBoolean() == true) {
565 common.errorMsg('Heat job cleanup triggered')
566 stage('Trigger cleanup job') {
567 build job: 'deploy-heat-cleanup', parameters: [[$class: 'StringParameterValue', name: 'HEAT_STACK_NAME', value: HEAT_STACK_NAME]]
568 }
569 } else {
Tomáš Kukrálbcc53ea2017-03-08 08:15:57 +0100570 if (currentBuild.result == 'FAILURE') {
571 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 +0100572
Tomáš Kukrálbcc53ea2017-03-08 08:15:57 +0100573 if (SALT_MASTER_URL) {
574 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
575 }
Tomáš Kukrálb908dac2017-03-07 18:58:35 +0100576 }
577
Tomáš Kukrála18de112017-03-02 13:57:47 +0100578 }
Tomáš Kukrál9e0fb732017-03-02 10:12:05 +0100579 }
Tomáš Kukrálb9957b32017-02-28 14:49:00 +0100580 }
581 }
582}