blob: 209cc2a0b85c745a41587172e4a989576d40aa5b [file] [log] [blame]
Jakub Josef79ecec32017-02-17 14:36:28 +01001package com.mirantis.mk
2/**
3 * Orchestration functions
4 *
5*/
6
7def validateFoundationInfra(master) {
8 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +02009
Jakub Josef432e9d92018-02-06 18:28:37 +010010 salt.cmdRun(master, 'I@salt:master' ,'salt-key')
11 salt.runSaltProcessStep(master, 'I@salt:minion', 'test.version')
12 salt.cmdRun(master, 'I@salt:master' ,'reclass-salt --top')
13 salt.runSaltProcessStep(master, 'I@reclass:storage', 'reclass.inventory')
14 salt.runSaltProcessStep(master, 'I@salt:minion', 'state.show_top')
Jakub Josef79ecec32017-02-17 14:36:28 +010015}
16
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +010017def installFoundationInfra(master, staticMgmtNet=false) {
Jakub Josef79ecec32017-02-17 14:36:28 +010018 def salt = new com.mirantis.mk.Salt()
Jiri Broulik037f8982018-04-23 17:07:16 +020019 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +020020
Vasyl Saienko0869b3a2017-11-22 14:37:57 +020021 // NOTE(vsaienko) Apply reclass first, it may update cluster model
22 // apply linux and salt.master salt.minion states afterwards to make sure
23 // correct cluster model is used.
Jakub Josef432e9d92018-02-06 18:28:37 +010024 salt.enforceState(master, 'I@salt:master', ['reclass'])
Tomáš Kukrálb4d75222017-06-06 10:36:02 +020025
Jakub Josef432e9d92018-02-06 18:28:37 +010026 salt.enforceState(master, 'I@salt:master', ['linux.system'])
Vasyl Saienko0869b3a2017-11-22 14:37:57 +020027 salt.enforceState(master, 'I@salt:master', ['salt.master'], true, false, null, false, 120, 2)
Jakub Josef432e9d92018-02-06 18:28:37 +010028 salt.fullRefresh(master, "*")
Tomáš Kukrálb4d75222017-06-06 10:36:02 +020029
Vasyl Saienkoe36ab7c2017-07-17 14:35:48 +030030 salt.enforceState(master, 'I@salt:master', ['salt.minion'], true, false, null, false, 60, 2)
Jakub Josef432e9d92018-02-06 18:28:37 +010031 salt.enforceState(master, 'I@salt:master', ['salt.minion'])
32 salt.fullRefresh(master, "*")
Ondrej Smolaa9b84662018-04-18 11:22:19 +020033 salt.enforceState(master, '*', ['linux.network.proxy'], true, false, null, false, 60, 2)
Jiri Broulik94fc2592018-04-20 13:47:51 +020034 try {
35 salt.enforceState(master, '*', ['salt.minion.base'], true, false, null, false, 60, 2)
36 sleep(5)
37 } catch (Throwable e) {
38 common.warningMsg('Salt state salt.minion.base is not present in the Salt-formula yet.')
39 }
Jiri Broulike3ace622018-06-07 10:51:02 +020040 common.retry(2,5){
41 salt.enforceState(master, '*', ['linux.system'])
42 }
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +010043 if (staticMgmtNet) {
44 salt.runSaltProcessStep(master, '*', 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], null, true, 60)
45 }
Jiri Broulik3740fb92018-04-27 11:52:38 +020046 salt.enforceState(master, 'I@linux:network:interface', ['linux.network.interface'])
Jiri Broulik94538462018-05-11 15:45:13 +020047 sleep(5)
Jiri Broulike3e7bc32018-02-26 10:50:07 +010048 salt.enforceState(master, 'I@linux:system', ['linux', 'openssh', 'ntp', 'rsyslog'])
Tomáš Kukrál7e767f92017-08-18 14:53:17 +020049 salt.enforceState(master, '*', ['salt.minion'], true, false, null, false, 60, 2)
Jakub Josef4f8f4df2017-09-01 14:32:42 +020050 sleep(5)
Victor Ryzhenkinf610c572018-05-15 15:22:52 +040051
52 salt.fullRefresh(master, "*")
vrovachevc4424a32018-03-15 17:35:57 +040053 salt.runSaltProcessStep(master, '*', 'mine.update', [], null, true)
Jakub Josef432e9d92018-02-06 18:28:37 +010054 salt.enforceState(master, '*', ['linux.network.host'])
Ivan Suzdal9a6bc392018-04-26 18:29:56 +040055
56 // Install and configure iptables
57 if (salt.testTarget(master, 'I@iptables:service')) {
58 salt.enforceState(master, 'I@iptables:service', 'iptables')
59 }
sgarbuzbb61e812018-05-03 16:58:40 +030060
61 // Install and configure logrotate
62 if (salt.testTarget(master, 'I@logrotate:server')) {
63 salt.enforceState(master, 'I@logrotate:server', 'logrotate')
64 }
Jakub Josef79ecec32017-02-17 14:36:28 +010065}
66
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +010067def installFoundationInfraOnTarget(master, target, staticMgmtNet=false) {
Jiri Broulik976bf6c2017-10-20 14:43:25 +020068 def salt = new com.mirantis.mk.Salt()
Jiri Broulik9fb138a2018-04-23 17:13:00 +020069 def common = new com.mirantis.mk.Common()
Jiri Broulik976bf6c2017-10-20 14:43:25 +020070
71 salt.enforceState(master, 'I@salt:master', ['reclass'], true, false, null, false, 120, 2)
Jakub Josef432e9d92018-02-06 18:28:37 +010072 salt.fullRefresh(master, target)
Ondrej Smolaa9b84662018-04-18 11:22:19 +020073 salt.enforceState(master, target, ['linux.network.proxy'], true, false, null, false, 60, 2)
Jiri Broulik94fc2592018-04-20 13:47:51 +020074 try {
75 salt.enforceState(master, target, ['salt.minion.base'], true, false, null, false, 60, 2)
76 sleep(5)
77 } catch (Throwable e) {
78 common.warningMsg('Salt state salt.minion.base is not present in the Salt-formula yet.')
79 }
Jiri Broulike3ace622018-06-07 10:51:02 +020080 common.retry(2,5){
81 salt.enforceState(master, target, ['linux.system'])
82 }
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +010083 if (staticMgmtNet) {
84 salt.runSaltProcessStep(master, target, 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], null, true, 60)
85 }
Jiri Broulik976bf6c2017-10-20 14:43:25 +020086 salt.enforceState(master, target, ['salt.minion'], true, false, null, false, 60, 2)
Jakub Josef432e9d92018-02-06 18:28:37 +010087 salt.enforceState(master, target, ['salt.minion'])
Jiri Broulik3740fb92018-04-27 11:52:38 +020088 salt.enforceState(master, target, ['linux.network.interface'])
Jiri Broulik94538462018-05-11 15:45:13 +020089 sleep(5)
Jiri Broulike3e7bc32018-02-26 10:50:07 +010090 salt.enforceState(master, target, ['linux', 'openssh', 'ntp', 'rsyslog'])
Jiri Broulik976bf6c2017-10-20 14:43:25 +020091 sleep(5)
Victor Ryzhenkinf610c572018-05-15 15:22:52 +040092
93 salt.fullRefresh(master, target)
vrovachevc4424a32018-03-15 17:35:57 +040094 salt.runSaltProcessStep(master, target, 'mine.update', [], null, true)
Jakub Josef432e9d92018-02-06 18:28:37 +010095 salt.enforceState(master, target, ['linux.network.host'])
Jiri Broulik976bf6c2017-10-20 14:43:25 +020096}
97
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +010098def installInfraKvm(master) {
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +020099 def common = new com.mirantis.mk.Common()
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +0100100 def salt = new com.mirantis.mk.Salt()
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200101 def infra_compound = 'I@salt:control'
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200102 def minions = []
103 def wait_timeout = 10
104 def retries = wait_timeout * 30
Ales Komarekef2bab62017-04-26 11:48:28 +0200105
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200106 salt.fullRefresh(master, 'I@linux:system')
Richard Felkl286f25f2017-07-26 14:23:55 +0200107 salt.enforceState(master, 'I@salt:control', ['salt.minion'], true, false, null, false, 60, 2)
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100108 salt.enforceState(master, 'I@salt:control', ['linux.system', 'linux.network', 'ntp', 'rsyslog'])
Jakub Josef432e9d92018-02-06 18:28:37 +0100109 salt.enforceState(master, 'I@salt:control', 'libvirt')
110 salt.enforceState(master, 'I@salt:control', 'salt.control')
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100111
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200112 common.infoMsg("Building minions list...")
113 if (salt.testTarget(master, infra_compound)) {
114 // Gathering minions
115 for ( infra_node in salt.getMinionsSorted(master, infra_compound) ) {
116 def pillar = salt.getPillar(master, infra_node, 'salt:control:cluster')
117 if ( !pillar['return'].isEmpty() ) {
118 for ( cluster in pillar['return'][0].values() ) {
119 def engine = cluster.values()[0]['engine']
120 def domain = cluster.values()[0]['domain']
121 def node = cluster.values()[0]['node']
122 if ( engine == "virt" ) {
123 def nodes = node.values()
124 if ( !nodes.isEmpty() ) {
125 for ( vm in nodes ) {
126 if ( vm['name'] != null ) {
127 def vm_fqdn = vm['name'] + '.' + domain
128 if ( !minions.contains(vm_fqdn) ) {
129 minions.add(vm_fqdn)
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200130 }
131 }
132 }
133 }
134 }
135 }
136 }
137 }
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200138 }
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100139
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200140 def minions_compound = minions.join(' or ')
141
142 common.infoMsg("Waiting for next minions to register within ${wait_timeout} minutes: " + minions_compound)
143 timeout(time: wait_timeout, unit: 'MINUTES') {
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200144 salt.minionsPresentFromList(master, 'I@salt:master', minions, true, null, true, retries, 1)
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200145 }
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200146
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200147 common.infoMsg('Waiting for minions to respond')
148 timeout(time: wait_timeout, unit: 'MINUTES') {
149 salt.minionsReachable(master, 'I@salt:master', minions_compound)
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200150 }
151
152 common.infoMsg("All minions are up.")
Jakub Josef432e9d92018-02-06 18:28:37 +0100153 salt.fullRefresh(master, '* and not kvm*')
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200154
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +0100155}
Jakub Josef79ecec32017-02-17 14:36:28 +0100156
vrovachev1c4770b2017-07-05 13:25:21 +0400157def installInfra(master) {
Jakub Josef61463c72018-02-13 16:10:56 +0100158 def common = new com.mirantis.mk.Common()
Jakub Josef79ecec32017-02-17 14:36:28 +0100159 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200160
Jakub Josef79ecec32017-02-17 14:36:28 +0100161 // Install glusterfs
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200162 if (salt.testTarget(master, 'I@glusterfs:server')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100163 salt.enforceState(master, 'I@glusterfs:server', 'glusterfs.server.service')
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100164
Jakub Josef432e9d92018-02-06 18:28:37 +0100165 salt.enforceState(master, 'I@glusterfs:server and *01*', 'glusterfs.server.setup', true, true, null, false, -1, 5)
Jakub Josef61463c72018-02-13 16:10:56 +0100166 sleep(10)
Jakub Josef432e9d92018-02-06 18:28:37 +0100167 salt.cmdRun(master, 'I@glusterfs:server', "gluster peer status; gluster volume status")
Alexander Noskov93acac42017-06-20 17:55:55 +0200168 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200169
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300170 // Ensure glusterfs clusters is ready
171 if (salt.testTarget(master, 'I@glusterfs:client')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100172 salt.enforceState(master, 'I@glusterfs:client', 'glusterfs.client')
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300173 }
174
Jakub Josef79ecec32017-02-17 14:36:28 +0100175 // Install galera
Richard Felklc0f163e2017-07-27 15:11:12 +0200176 if (salt.testTarget(master, 'I@galera:master') || salt.testTarget(master, 'I@galera:slave')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100177 salt.enforceState(master, 'I@galera:master', 'galera', true, true, null, false, -1, 2)
Jakub Josef9994ea72018-03-05 13:23:07 +0100178 salt.enforceState(master, 'I@galera:slave', 'galera', true, true, null, false, -1, 2)
vrovachev1c4770b2017-07-05 13:25:21 +0400179
180 // Check galera status
181 salt.runSaltProcessStep(master, 'I@galera:master', 'mysql.status')
182 salt.runSaltProcessStep(master, 'I@galera:slave', 'mysql.status')
Vasyl Saienkoc1fb9892017-07-13 14:54:13 +0300183 // If galera is not enabled check if we need to install mysql:server
184 } else if (salt.testTarget(master, 'I@mysql:server')){
Jakub Josef432e9d92018-02-06 18:28:37 +0100185 salt.enforceState(master, 'I@mysql:server', 'mysql.server')
Vasyl Saienkoc1fb9892017-07-13 14:54:13 +0300186 if (salt.testTarget(master, 'I@mysql:client')){
Jakub Josef432e9d92018-02-06 18:28:37 +0100187 salt.enforceState(master, 'I@mysql:client', 'mysql.client')
Vasyl Saienkoc1fb9892017-07-13 14:54:13 +0300188 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200189 }
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100190 installBackup(master, 'mysql')
Ales Komarekef2bab62017-04-26 11:48:28 +0200191
vrovachev1c4770b2017-07-05 13:25:21 +0400192 // Install docker
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200193 if (salt.testTarget(master, 'I@docker:host')) {
vrovachev1c4770b2017-07-05 13:25:21 +0400194 salt.enforceState(master, 'I@docker:host', 'docker.host')
Tomáš Kukrál0cf3ffb2017-09-03 10:18:18 +0200195 salt.cmdRun(master, 'I@docker:host', 'docker ps')
vrovachev1c4770b2017-07-05 13:25:21 +0400196 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200197
vrovachev1c4770b2017-07-05 13:25:21 +0400198 // Install keepalived
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200199 if (salt.testTarget(master, 'I@keepalived:cluster')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100200 salt.enforceState(master, 'I@keepalived:cluster and *01*', 'keepalived')
201 salt.enforceState(master, 'I@keepalived:cluster', 'keepalived')
vrovachev1c4770b2017-07-05 13:25:21 +0400202 }
203
204 // Install rabbitmq
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200205 if (salt.testTarget(master, 'I@rabbitmq:server')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100206 salt.enforceState(master, 'I@rabbitmq:server', 'rabbitmq', true, true, null, false, -1, 2)
vrovachev1c4770b2017-07-05 13:25:21 +0400207
208 // Check the rabbitmq status
Jakub Josef61463c72018-02-13 16:10:56 +0100209 common.retry(3,5){
210 salt.cmdRun(master, 'I@rabbitmq:server', 'rabbitmqctl cluster_status')
211 }
vrovachev1c4770b2017-07-05 13:25:21 +0400212 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200213
Jakub Josef79ecec32017-02-17 14:36:28 +0100214 // Install haproxy
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200215 if (salt.testTarget(master, 'I@haproxy:proxy')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100216 salt.enforceState(master, 'I@haproxy:proxy', 'haproxy')
vrovachev1c4770b2017-07-05 13:25:21 +0400217 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
218 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.restart', ['rsyslog'])
219 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200220
Jakub Josef79ecec32017-02-17 14:36:28 +0100221 // Install memcached
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200222 if (salt.testTarget(master, 'I@memcached:server')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100223 salt.enforceState(master, 'I@memcached:server', 'memcached')
vrovachev1c4770b2017-07-05 13:25:21 +0400224 }
225
226 // Install etcd
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200227 if (salt.testTarget(master, 'I@etcd:server')) {
vrovachev1c4770b2017-07-05 13:25:21 +0400228 salt.enforceState(master, 'I@etcd:server', 'etcd.server.service')
Jakub Josef61463c72018-02-13 16:10:56 +0100229 common.retry(3,5){
230 salt.cmdRun(master, 'I@etcd:server', '. /var/lib/etcd/configenv && etcdctl cluster-health')
231 }
vrovachev1c4770b2017-07-05 13:25:21 +0400232 }
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200233
234 // Install redis
235 if (salt.testTarget(master, 'I@redis:server')) {
236 if (salt.testTarget(master, 'I@redis:cluster:role:master')) {
237 salt.enforceState(master, 'I@redis:cluster:role:master', 'redis')
238 }
239 salt.enforceState(master, 'I@redis:server', 'redis')
240 }
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100241 installBackup(master, 'common')
vrovachev1c4770b2017-07-05 13:25:21 +0400242}
243
244def installOpenstackInfra(master) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100245 def common = new com.mirantis.mk.Common()
246 common.warningMsg("You calling orchestrate.installOpenstackInfra(). This function is deprecated please use orchestrate.installInfra() directly")
247 installInfra(master)
Jakub Josef79ecec32017-02-17 14:36:28 +0100248}
249
250
Ales Komarekef2bab62017-04-26 11:48:28 +0200251def installOpenstackControl(master) {
Jakub Josef79ecec32017-02-17 14:36:28 +0100252 def salt = new com.mirantis.mk.Salt()
Jakub Josef61463c72018-02-13 16:10:56 +0100253 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200254
255 // Install horizon dashboard
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300256 if (salt.testTarget(master, 'I@horizon:server')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100257 salt.enforceState(master, 'I@horizon:server', 'horizon')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300258 }
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100259 // Install sphinx server
260 if (salt.testTarget(master, 'I@sphinx:server')) {
261 salt.enforceState(master, 'I@sphinx:server', 'sphinx')
262 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300263 if (salt.testTarget(master, 'I@nginx:server')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100264 salt.enforceState(master, 'I@nginx:server', 'salt.minion')
265 salt.enforceState(master, 'I@nginx:server', 'nginx')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300266 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200267
Jakub Josef79ecec32017-02-17 14:36:28 +0100268 // setup keystone service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300269 if (salt.testTarget(master, 'I@keystone:server')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100270 salt.enforceState(master, 'I@keystone:server and *01*', 'keystone.server')
271 salt.enforceState(master, 'I@keystone:server', 'keystone.server')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300272 // populate keystone services/tenants/roles/users
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100273
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300274 // keystone:client must be called locally
275 //salt.runSaltProcessStep(master, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
276 salt.runSaltProcessStep(master, 'I@keystone:server', 'service.restart', ['apache2'])
277 sleep(30)
278 }
279 if (salt.testTarget(master, 'I@keystone:client')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100280 salt.enforceState(master, 'I@keystone:client and *01*', 'keystone.client')
281 salt.enforceState(master, 'I@keystone:client', 'keystone.client')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300282 }
283 if (salt.testTarget(master, 'I@keystone:server')) {
Jakub Josef61463c72018-02-13 16:10:56 +0100284 common.retry(3,5){
285 salt.cmdRun(master, 'I@keystone:server', '. /root/keystonercv3; openstack service list')
286 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300287 }
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100288
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300289 // Install glance
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300290 if (salt.testTarget(master, 'I@glance:server')) {
291 //runSaltProcessStep(master, 'I@glance:server', 'state.sls', ['glance.server'], 1)
Jakub Josef432e9d92018-02-06 18:28:37 +0100292 salt.enforceState(master, 'I@glance:server and *01*', 'glance.server')
293 salt.enforceState(master, 'I@glance:server', 'glance.server')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300294 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200295
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300296 // Check glance service
297 if (salt.testTarget(master, 'I@glance:server')){
Jakub Josef61463c72018-02-13 16:10:56 +0100298 common.retry(3,5){
Oleg Iurchenko01410f22018-02-22 22:18:21 +0200299 salt.cmdRun(master, 'I@keystone:server','. /root/keystonercv3; glance image-list')
Jakub Josef61463c72018-02-13 16:10:56 +0100300 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300301 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200302
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400303 // Create glance resources
304 if (salt.testTarget(master, 'I@glance:client')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100305 salt.enforceState(master, 'I@glance:client', 'glance.client')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400306 }
307
Jakub Josef79ecec32017-02-17 14:36:28 +0100308 // Install and check nova service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300309 if (salt.testTarget(master, 'I@nova:controller')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100310 // run on first node first
311 salt.enforceState(master, 'I@nova:controller and *01*', 'nova.controller')
312 salt.enforceState(master, 'I@nova:controller', 'nova.controller')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300313 if (salt.testTarget(master, 'I@keystone:server')) {
Jakub Josef61463c72018-02-13 16:10:56 +0100314 common.retry(3,5){
Oleg Iurchenko01410f22018-02-22 22:18:21 +0200315 salt.cmdRun(master, 'I@keystone:server', '. /root/keystonercv3; nova service-list')
Jakub Josef61463c72018-02-13 16:10:56 +0100316 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300317 }
318 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200319
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400320 // Create nova resources
321 if (salt.testTarget(master, 'I@nova:client')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100322 salt.enforceState(master, 'I@nova:client', 'nova.client')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400323 }
324
Jakub Josef79ecec32017-02-17 14:36:28 +0100325 // Install and check cinder service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300326 if (salt.testTarget(master, 'I@cinder:controller')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100327 // run on first node first
328 salt.enforceState(master, 'I@cinder:controller and *01*', 'cinder')
329 salt.enforceState(master, 'I@cinder:controller', 'cinder')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300330 if (salt.testTarget(master, 'I@keystone:server')) {
Jakub Josef61463c72018-02-13 16:10:56 +0100331 common.retry(3,5){
Oleg Iurchenko01410f22018-02-22 22:18:21 +0200332 salt.cmdRun(master, 'I@keystone:server', '. /root/keystonercv3; cinder list')
Jakub Josef61463c72018-02-13 16:10:56 +0100333 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300334 }
335 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200336
Jakub Josef79ecec32017-02-17 14:36:28 +0100337 // Install neutron service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300338 if (salt.testTarget(master, 'I@neutron:server')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100339 // run on first node first
340 salt.enforceState(master, 'I@neutron:server and *01*', 'neutron.server')
341 salt.enforceState(master, 'I@neutron:server', 'neutron.server')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300342 if (salt.testTarget(master, 'I@keystone:server')) {
Jakub Josef61463c72018-02-13 16:10:56 +0100343 common.retry(3,5){
Oleg Iurchenko01410f22018-02-22 22:18:21 +0200344 salt.cmdRun(master, 'I@keystone:server','. /root/keystonercv3; neutron agent-list')
Jakub Josef61463c72018-02-13 16:10:56 +0100345 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300346 }
347 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200348
Jakub Josef79ecec32017-02-17 14:36:28 +0100349 // Install heat service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300350 if (salt.testTarget(master, 'I@heat:server')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100351 // run on first node first
352 salt.enforceState(master, 'I@heat:server and *01*', 'heat')
353 salt.enforceState(master, 'I@heat:server', 'heat')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300354 if (salt.testTarget(master, 'I@keystone:server')) {
Jakub Josef61463c72018-02-13 16:10:56 +0100355 common.retry(3,5){
Oleg Iurchenko01410f22018-02-22 22:18:21 +0200356 salt.cmdRun(master, 'I@keystone:server', '. /root/keystonercv3; heat resource-type-list')
Jakub Josef61463c72018-02-13 16:10:56 +0100357 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300358 }
359 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200360
361 // Restart nova api
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300362 if (salt.testTarget(master, 'I@nova:controller')) {
363 salt.runSaltProcessStep(master, 'I@nova:controller', 'service.restart', ['nova-api'])
364 }
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300365
366 // Install ironic service
367 if (salt.testTarget(master, 'I@ironic:api')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100368 salt.enforceState(master, 'I@ironic:api and *01*', 'ironic.api')
369 salt.enforceState(master, 'I@ironic:api', 'ironic.api')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300370 }
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300371
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200372 // Install manila service
373 if (salt.testTarget(master, 'I@manila:api')) {
374 salt.enforceState(master, 'I@manila:api and *01*', 'manila.api')
375 salt.enforceState(master, 'I@manila:api', 'manila.api')
376 }
377 if (salt.testTarget(master, 'I@manila:scheduler')) {
378 salt.enforceState(master, 'I@manila:scheduler', 'manila.scheduler')
379 }
380
Oleh Hryhorova070fd02018-03-15 14:47:52 +0200381 // Install designate services
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300382 if (salt.testTarget(master, 'I@designate:server:enabled')) {
383 if (salt.testTarget(master, 'I@designate:server:backend:bind9')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100384 salt.enforceState(master, 'I@bind:server', 'bind.server')
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300385 }
386 if (salt.testTarget(master, 'I@designate:server:backend:pdns4')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100387 salt.enforceState(master, 'I@powerdns:server', 'powerdns.server')
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300388 }
Jakub Josef432e9d92018-02-06 18:28:37 +0100389 salt.enforceState(master, 'I@designate:server and *01*', 'designate.server')
Oleh Hryhorova070fd02018-03-15 14:47:52 +0200390 salt.enforceState(master, 'I@designate:server', 'designate')
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300391 }
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400392
393 // Install octavia api service
394 if (salt.testTarget(master, 'I@octavia:api')) {
Marcin Iwinskib1ac98e2018-02-08 10:16:49 +0100395 salt.enforceState(master, 'I@octavia:api and *01*', 'octavia')
Jakub Josef432e9d92018-02-06 18:28:37 +0100396 salt.enforceState(master, 'I@octavia:api', 'octavia')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400397 }
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200398
Oleg Iurchenkod0898c92017-12-14 14:28:44 +0200399 // Install DogTag server service
400 if (salt.testTarget(master, 'I@dogtag:server')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100401 salt.enforceState(master, 'I@dogtag:server and *01*', 'dogtag.server')
402 salt.enforceState(master, 'I@dogtag:server', 'dogtag.server')
Oleg Iurchenkod0898c92017-12-14 14:28:44 +0200403 }
404
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200405 // Install barbican server service
406 if (salt.testTarget(master, 'I@barbican:server')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100407 salt.enforceState(master, 'I@barbican:server and *01*', 'barbican.server')
408 salt.enforceState(master, 'I@barbican:server', 'barbican.server')
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200409 }
410 // Install barbican client
411 if (salt.testTarget(master, 'I@barbican:client')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100412 salt.enforceState(master, 'I@barbican:client', 'barbican.client')
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200413 }
Ondrej Smola5908ae62018-01-08 13:42:08 +0100414
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200415 // Install gnocchi server
416 if (salt.testTarget(master, 'I@gnocchi:server')) {
Mykyta Karpinf60f02f2018-03-14 19:24:51 +0200417 salt.enforceState(master, 'I@gnocchi:server and *01*', 'gnocchi.server')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200418 salt.enforceState(master, 'I@gnocchi:server', 'gnocchi.server')
419 }
420
421 // Install gnocchi statsd
422 if (salt.testTarget(master, 'I@gnocchi:statsd')) {
Mykyta Karpinf60f02f2018-03-14 19:24:51 +0200423 salt.enforceState(master, 'I@gnocchi:statsd and *01*', 'gnocchi.statsd')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200424 salt.enforceState(master, 'I@gnocchi:statsd', 'gnocchi.statsd')
425 }
426
427 // Install panko server
428 if (salt.testTarget(master, 'I@panko:server')) {
Mykyta Karpinf60f02f2018-03-14 19:24:51 +0200429 salt.enforceState(master, 'I@panko:server and *01*', 'panko')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200430 salt.enforceState(master, 'I@panko:server', 'panko')
431 }
432
Ondrej Smola5908ae62018-01-08 13:42:08 +0100433 // Install ceilometer server
434 if (salt.testTarget(master, 'I@ceilometer:server')) {
Mykyta Karpinf60f02f2018-03-14 19:24:51 +0200435 salt.enforceState(master, 'I@ceilometer:server and *01*', 'ceilometer')
Jakub Josef432e9d92018-02-06 18:28:37 +0100436 salt.enforceState(master, 'I@ceilometer:server', 'ceilometer')
Ondrej Smola5908ae62018-01-08 13:42:08 +0100437 }
438
439 // Install aodh server
440 if (salt.testTarget(master, 'I@aodh:server')) {
Mykyta Karpinf60f02f2018-03-14 19:24:51 +0200441 salt.enforceState(master, 'I@aodh:server and *01*', 'aodh')
Jakub Josef432e9d92018-02-06 18:28:37 +0100442 salt.enforceState(master, 'I@aodh:server', 'aodh')
Ondrej Smola5908ae62018-01-08 13:42:08 +0100443 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100444}
445
446
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300447def installIronicConductor(master){
448 def salt = new com.mirantis.mk.Salt()
449
450 if (salt.testTarget(master, 'I@ironic:conductor')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100451 salt.enforceState(master, 'I@ironic:conductor', 'ironic.conductor')
452 salt.enforceState(master, 'I@ironic:conductor', 'apache')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300453 }
454 if (salt.testTarget(master, 'I@tftpd_hpa:server')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100455 salt.enforceState(master, 'I@tftpd_hpa:server', 'tftpd_hpa')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300456 }
457
458 if (salt.testTarget(master, 'I@nova:compute')) {
459 salt.runSaltProcessStep(master, 'I@nova:compute', 'service.restart', ['nova-compute'])
460 }
461
462 if (salt.testTarget(master, 'I@baremetal_simulator:enabled')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100463 salt.enforceState(master, 'I@baremetal_simulator:enabled', 'baremetal_simulator')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300464 }
465 if (salt.testTarget(master, 'I@ironic:client')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100466 salt.enforceState(master, 'I@ironic:client', 'ironic.client')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300467 }
468}
469
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200470def installManilaShare(master){
471 def salt = new com.mirantis.mk.Salt()
472
473 if (salt.testTarget(master, 'I@manila:share')) {
474 salt.enforceState(master, 'I@manila:share', 'manila.share')
475 }
476 if (salt.testTarget(master, 'I@manila:data')) {
477 salt.enforceState(master, 'I@manila:data', 'manila.data')
478 }
479
480 if (salt.testTarget(master, 'I@manila:client')) {
481 salt.enforceState(master, 'I@manila:client', 'manila.client')
482 }
483}
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300484
485
Ales Komarekef2bab62017-04-26 11:48:28 +0200486def installOpenstackNetwork(master, physical = "false") {
Jakub Josef79ecec32017-02-17 14:36:28 +0100487 def salt = new com.mirantis.mk.Salt()
Oleksii Grudevc4a485e2018-04-20 14:25:03 +0300488 //run full neutron state on neutron.gateway - this will install
489 //neutron agents in addition to neutron server. Once neutron agents
490 //are up neutron resources can be created without hitting the situation when neutron resources are created
491 //prior to neutron agents which results in creating ports in non-usable state
492 if (salt.testTarget(master, 'I@neutron:gateway')) {
493 salt.enforceState(master, 'I@neutron:gateway', 'neutron')
494 }
495
496 // Create neutron resources - this step was moved here to ensure that
497 //neutron resources are created after neutron agens are up. In this case neutron ports will be in
498 //usable state. More information: https://bugs.launchpad.net/neutron/+bug/1399249
499 if (salt.testTarget(master, 'I@neutron:client')) {
500 salt.enforceState(master, 'I@neutron:client', 'neutron.client')
501 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200502
Jakub Josef432e9d92018-02-06 18:28:37 +0100503 salt.enforceHighstate(master, 'I@neutron:gateway')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400504
505 // install octavia manager services
506 if (salt.testTarget(master, 'I@octavia:manager')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100507 salt.runSaltProcessStep(master, 'I@salt:master', 'mine.update', ['*'])
508 salt.enforceState(master, 'I@octavia:manager', 'octavia')
509 salt.enforceState(master, 'I@octavia:manager', 'salt.minion.ca')
510 salt.enforceState(master, 'I@octavia:manager', 'salt.minion.cert')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400511 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200512}
513
514
515def installOpenstackCompute(master) {
516 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200517 // Configure compute nodes
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100518 def compute_compound = 'I@nova:compute'
519 if (salt.testTarget(master, compute_compound)) {
520 // In case if infrastructure nodes are used as nova computes too
521 def gluster_compound = 'I@glusterfs:server'
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200522 def salt_ca_compound = 'I@salt:minion:ca:salt_master_ca'
523 // Enforce highstate asynchronous only on compute nodes which are not glusterfs and not salt ca servers
Oleh Hryhorov73f9fa22018-05-02 17:36:58 +0300524 def hightstateTarget = "${compute_compound} and not ${gluster_compound} and not ${salt_ca_compound}"
525 if (salt.testTarget(master, hightstateTarget)) {
526 retry(2) {
527 salt.enforceHighstateWithExclude(master, hightstateTarget, 'opencontrail.client')
528 }
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200529 }
530 // Iterate through salt ca servers and check if they have compute role
531 // TODO: switch to batch once salt 2017.7+ would be used
532 for ( target in salt.getMinionsSorted(master, salt_ca_compound) ) {
533 for ( cmp_target in salt.getMinionsSorted(master, compute_compound) ) {
534 if ( target == cmp_target ) {
535 // Enforce highstate one by one on salt ca servers which are compute nodes
536 retry(2) {
537 salt.enforceHighstateWithExclude(master, target, 'opencontrail.client')
538 }
539 }
540 }
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100541 }
542 // Iterate through glusterfs servers and check if they have compute role
543 // TODO: switch to batch once salt 2017.7+ would be used
544 for ( target in salt.getMinionsSorted(master, gluster_compound) ) {
545 for ( cmp_target in salt.getMinionsSorted(master, compute_compound) ) {
546 if ( target == cmp_target ) {
547 // Enforce highstate one by one on glusterfs servers which are compute nodes
548 retry(2) {
549 salt.enforceHighstateWithExclude(master, target, 'opencontrail.client')
550 }
551 }
552 }
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200553 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200554 }
555}
556
557
558def installContrailNetwork(master) {
Martin Polreichfc9854c2017-06-30 11:17:36 +0200559 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200560 def salt = new com.mirantis.mk.Salt()
561
562
Jakub Josef79ecec32017-02-17 14:36:28 +0100563 // Install opencontrail database services
Jakub Josef432e9d92018-02-06 18:28:37 +0100564 salt.enforceState(master, 'I@opencontrail:database and *01*', 'opencontrail.database')
565 salt.enforceState(master, 'I@opencontrail:database', 'opencontrail.database')
Ales Komarekef2bab62017-04-26 11:48:28 +0200566
Jakub Josef79ecec32017-02-17 14:36:28 +0100567 // Install opencontrail control services
Jakub Josef432e9d92018-02-06 18:28:37 +0100568 salt.enforceStateWithExclude(master, "I@opencontrail:control and *01*", "opencontrail", "opencontrail.client")
569 salt.enforceStateWithExclude(master, "I@opencontrail:control", "opencontrail", "opencontrail.client")
570 salt.enforceStateWithExclude(master, "I@opencontrail:collector and *01*", "opencontrail", "opencontrail.client")
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100571
Marek Celoud443fb642017-11-22 15:07:12 +0100572 if (salt.testTarget(master, 'I@docker:client and I@opencontrail:control')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100573 salt.enforceState(master, 'I@opencontrail:control or I@opencontrail:collector', 'docker.client')
Marek Celoud443fb642017-11-22 15:07:12 +0100574 }
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100575 installBackup(master, 'contrail')
Jakub Josef79ecec32017-02-17 14:36:28 +0100576}
577
578
Ales Komarekef2bab62017-04-26 11:48:28 +0200579def installContrailCompute(master) {
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200580 def salt = new com.mirantis.mk.Salt()
vrovachev32f7f542017-08-25 16:17:25 +0400581 def common = new com.mirantis.mk.Common()
Jakub Josef79ecec32017-02-17 14:36:28 +0100582 // Configure compute nodes
Ales Komarekef2bab62017-04-26 11:48:28 +0200583 // Provision opencontrail control services
Jakub Josef432e9d92018-02-06 18:28:37 +0100584 salt.enforceState(master, 'I@opencontrail:database:id:1', 'opencontrail.client')
Jakub Josef79ecec32017-02-17 14:36:28 +0100585 // Provision opencontrail virtual routers
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100586
vrovachev4ff77302017-08-09 20:39:57 +0400587 // Generate script /usr/lib/contrail/if-vhost0 for up vhost0
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200588 if (salt.testTarget(master, 'I@opencontrail:compute')) {
589 salt.enforceStateWithExclude(master, "I@opencontrail:compute", "opencontrail", "opencontrail.client")
590 }
vrovachev4ff77302017-08-09 20:39:57 +0400591
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200592 if (salt.testTarget(master, 'I@nova:compute')) {
593 salt.cmdRun(master, 'I@nova:compute', 'exec 0>&-; exec 1>&-; exec 2>&-; nohup bash -c "ip link | grep vhost && echo no_reboot || sleep 5 && reboot & "', false)
594 }
vrovachev4ff77302017-08-09 20:39:57 +0400595
Jakub Josef61463c72018-02-13 16:10:56 +0100596 sleep(300)
vrovachev4ff77302017-08-09 20:39:57 +0400597 if (salt.testTarget(master, 'I@opencontrail:compute')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100598 salt.enforceState(master, 'I@opencontrail:compute', 'opencontrail.client')
599 salt.enforceState(master, 'I@opencontrail:compute', 'opencontrail')
vrovachev4ff77302017-08-09 20:39:57 +0400600 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100601}
602
603
Ales Komarekef2bab62017-04-26 11:48:28 +0200604def installKubernetesInfra(master) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100605 def common = new com.mirantis.mk.Common()
606 common.warningMsg("You calling orchestrate.installKubernetesInfra(). This function is deprecated please use orchestrate.installInfra() directly")
607 installInfra(master)
Jakub Josef79ecec32017-02-17 14:36:28 +0100608}
609
610
Tomáš Kukrálc1a1bbc2017-04-28 21:16:25 +0200611def installKubernetesControl(master) {
Jakub Josef79ecec32017-02-17 14:36:28 +0100612 def salt = new com.mirantis.mk.Salt()
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200613
Jakub Josef79ecec32017-02-17 14:36:28 +0100614 // Install Kubernetes pool and Calico
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200615 salt.enforceState(master, 'I@kubernetes:master', 'kubernetes.master.kube-addons')
616 salt.enforceState(master, 'I@kubernetes:pool', 'kubernetes.pool')
Jakub Josef79ecec32017-02-17 14:36:28 +0100617
Marek Celoud029391c2017-11-14 10:06:18 +0100618 if (salt.testTarget(master, 'I@etcd:server:setup')) {
619 // Setup etcd server
620 salt.enforceState(master, 'I@kubernetes:master and *01*', 'etcd.server.setup')
621 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100622
Victor Ryzhenkinfb5d1b52018-05-22 18:49:26 +0400623 // Run k8s master at *01* to simplify namespaces creation
624 salt.enforceStateWithExclude(master, 'I@kubernetes:master and *01*', "kubernetes.master", "kubernetes.master.setup")
625
Jakub Josef79ecec32017-02-17 14:36:28 +0100626 // Run k8s without master.setup
Jakub Josef432e9d92018-02-06 18:28:37 +0100627 salt.enforceStateWithExclude(master, 'I@kubernetes:master', "kubernetes", "kubernetes.master.setup")
Jakub Josef79ecec32017-02-17 14:36:28 +0100628
629 // Run k8s master setup
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200630 salt.enforceState(master, 'I@kubernetes:master and *01*', 'kubernetes.master.setup')
Jakub Josef79ecec32017-02-17 14:36:28 +0100631
632 // Restart kubelet
633 salt.runSaltProcessStep(master, 'I@kubernetes:pool', 'service.restart', ['kubelet'])
634}
635
636
Ales Komarekef2bab62017-04-26 11:48:28 +0200637def installKubernetesCompute(master) {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200638 def salt = new com.mirantis.mk.Salt()
Jakub Josef432e9d92018-02-06 18:28:37 +0100639 salt.fullRefresh(master, "*")
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200640
641 // Bootstrap all nodes
642 salt.enforceState(master, 'I@kubernetes:pool', 'linux')
643 salt.enforceState(master, 'I@kubernetes:pool', 'salt.minion')
644 salt.enforceState(master, 'I@kubernetes:pool', ['openssh', 'ntp'])
645
646 // Create and distribute SSL certificates for services using salt state
647 salt.enforceState(master, 'I@kubernetes:pool', 'salt.minion.cert')
648
649 // Install docker
650 salt.enforceState(master, 'I@docker:host', 'docker.host')
651
652 // Install Kubernetes and Calico
653 salt.enforceState(master, 'I@kubernetes:pool', 'kubernetes.pool')
654
Yuriy Taradayab564d72017-10-11 15:14:35 +0400655 // Install Tiller and all configured releases
656 if (salt.testTarget(master, 'I@helm:client')) {
657 salt.enforceState(master, 'I@helm:client', 'helm')
658 }
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200659}
660
661
Martin Polreich8663a342017-06-30 17:33:08 +0200662def installDockerSwarm(master) {
663 def salt = new com.mirantis.mk.Salt()
Jakub Josef79ecec32017-02-17 14:36:28 +0100664
vrovachev1c4770b2017-07-05 13:25:21 +0400665 //Install and Configure Docker
Martin Polreich8663a342017-06-30 17:33:08 +0200666 salt.enforceState(master, 'I@docker:swarm', 'docker.host')
Jakub Josef432e9d92018-02-06 18:28:37 +0100667 salt.enforceState(master, 'I@docker:swarm:role:master', 'docker.swarm')
668 salt.enforceState(master, 'I@docker:swarm', 'salt.minion.grains')
669 salt.runSaltProcessStep(master, 'I@docker:swarm', 'mine.update')
670 salt.runSaltProcessStep(master, 'I@docker:swarm', 'saltutil.refresh_modules')
Martin Polreich8663a342017-06-30 17:33:08 +0200671 sleep(5)
Jakub Josef432e9d92018-02-06 18:28:37 +0100672 salt.enforceState(master, 'I@docker:swarm:role:master', 'docker.swarm')
673 salt.enforceState(master, 'I@docker:swarm:role:manager', 'docker.swarm')
Jakub Josef61463c72018-02-13 16:10:56 +0100674 sleep(10)
Jakub Josef432e9d92018-02-06 18:28:37 +0100675 salt.cmdRun(master, 'I@docker:swarm:role:master', 'docker node ls')
Martin Polreich8663a342017-06-30 17:33:08 +0200676}
677
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200678
679def installCicd(master) {
680 def salt = new com.mirantis.mk.Salt()
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200681 def common = new com.mirantis.mk.Common()
682 def gerrit_compound = 'I@gerrit:client and ci*'
683 def jenkins_compound = 'I@jenkins:client and ci*'
684
685 salt.fullRefresh(master, gerrit_compound)
686 salt.fullRefresh(master, jenkins_compound)
Richard Felkl9d2cd922017-11-03 11:49:32 +0100687
Richard Felkl6de16762017-11-20 11:42:28 +0100688 salt.enforceState(master, 'I@docker:swarm:role:master and I@jenkins:client', 'docker.client', true, true, null, false, -1, 2)
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200689
690 // API timeout in minutes
691 def wait_timeout = 10
692
693 // Gerrit
694 def gerrit_master_url = salt.getPillar(master, gerrit_compound, '_param:gerrit_master_url')
695
696 if(!gerrit_master_url['return'].isEmpty()) {
697 gerrit_master_url = gerrit_master_url['return'][0].values()[0]
698 } else {
699 gerrit_master_url = ''
700 }
701
702 if (gerrit_master_url != '') {
703 common.infoMsg('Gerrit master url "' + gerrit_master_url + '" retrieved at _param:gerrit_master_url')
704 } else {
705
706 common.infoMsg('Gerrit master url could not be retrieved at _param:gerrit_master_url. Falling back to gerrit pillar')
707
708 def gerrit_host
709 def gerrit_http_port
710 def gerrit_http_scheme
711
712 def host_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:host')
713 gerrit_host = salt.getReturnValues(host_pillar)
714
715 def port_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:http_port')
716 gerrit_http_port = salt.getReturnValues(port_pillar)
717
718 def scheme_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:protocol')
719 gerrit_http_scheme = salt.getReturnValues(scheme_pillar)
720
721 gerrit_master_url = gerrit_http_scheme + '://' + gerrit_host + ':' + gerrit_http_port
722
723 }
724
725 timeout(wait_timeout) {
726 common.infoMsg('Waiting for Gerrit to come up..')
Dzmitry Stremkouski5440ffa2018-05-31 12:00:02 +0200727 def check_gerrit_cmd = 'while true; do curl -sI -m 3 -o /dev/null -w' + " '" + '%{http_code}' + "' " + gerrit_master_url + '/ | grep 200 && break || sleep 1; done'
728 salt.cmdRun(master, gerrit_compound, 'timeout ' + (wait_timeout*60+3) + ' /bin/sh -c -- ' + '"' + check_gerrit_cmd + '"')
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200729 }
730
731 // Jenkins
732 def jenkins_master_url_pillar = salt.getPillar(master, jenkins_compound, '_param:jenkins_master_url')
733 jenkins_master_url = salt.getReturnValues(jenkins_master_url_pillar)
734
735 timeout(wait_timeout) {
736 common.infoMsg('Waiting for Jenkins to come up..')
Dzmitry Stremkouski5440ffa2018-05-31 12:00:02 +0200737 def check_jenkins_cmd = 'while true; do curl -sI -m 3 -o /dev/null -w' + " '" + '%{http_code}' + "' " + jenkins_master_url + '/whoAmI/ | grep 200 && break || sleep 1; done'
738 salt.cmdRun(master, jenkins_compound, 'timeout ' + (wait_timeout*60+3) + ' /bin/sh -c -- ' + '"' + check_jenkins_cmd + '"')
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200739 }
Richard Felklc1aba9b2018-01-02 09:25:20 +0100740
Richard Felklc1aba9b2018-01-02 09:25:20 +0100741 if (salt.testTarget(master, 'I@openldap:client')) {
742 salt.enforceState(master, 'I@openldap:client', 'openldap', true, true, null, false, -1, 2)
743 }
Richard Felklb6fdec92017-09-26 10:52:36 +0200744
745 if (salt.testTarget(master, 'I@python:environment')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100746 salt.enforceState(master, 'I@python:environment', 'python')
Richard Felklb6fdec92017-09-26 10:52:36 +0200747 }
Richard Felklc1aba9b2018-01-02 09:25:20 +0100748
Richard Felkl6e208fc2017-12-08 10:18:44 +0100749 withEnv(['ASK_ON_ERROR=false']){
750 retry(2){
751 try{
Jakub Josef432e9d92018-02-06 18:28:37 +0100752 salt.enforceState(master, 'I@gerrit:client', 'gerrit')
Richard Felkl6e208fc2017-12-08 10:18:44 +0100753 }catch(e){
Jakub Josef432e9d92018-02-06 18:28:37 +0100754 salt.fullRefresh(master, 'I@gerrit:client')
Richard Felkl6e208fc2017-12-08 10:18:44 +0100755 throw e //rethrow for retry handler
756 }
757 }
758 retry(2){
759 try{
Jakub Josef432e9d92018-02-06 18:28:37 +0100760 salt.enforceState(master, 'I@jenkins:client', 'jenkins')
Richard Felkl6e208fc2017-12-08 10:18:44 +0100761 }catch(e){
Jakub Josef432e9d92018-02-06 18:28:37 +0100762 salt.fullRefresh(master, 'I@jenkins:client')
Richard Felkl6e208fc2017-12-08 10:18:44 +0100763 throw e //rethrow for retry handler
764 }
765 }
766 }
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200767}
768
769
Martin Polreich8663a342017-06-30 17:33:08 +0200770def installStacklight(master) {
771 def common = new com.mirantis.mk.Common()
772 def salt = new com.mirantis.mk.Salt()
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200773 def retries_wait = 20
774 def retries = 15
Martin Polreich8663a342017-06-30 17:33:08 +0200775
Simon Pasquieref4122c2017-08-25 15:52:07 +0200776 // Install core services for K8S environments:
777 // HAProxy, Nginx and lusterFS clients
778 // In case of OpenStack, those are already installed
Martin Polreich792f2662017-07-11 13:36:32 +0200779 if (common.checkContains('STACK_INSTALL', 'k8s')) {
780 salt.enforceState(master, 'I@haproxy:proxy', 'haproxy')
781 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
Simon Pasquieref4122c2017-08-25 15:52:07 +0200782
783 if (salt.testTarget(master, 'I@nginx:server')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100784 salt.enforceState(master, 'I@nginx:server', 'nginx')
Simon Pasquieref4122c2017-08-25 15:52:07 +0200785 }
786
787 if (salt.testTarget(master, 'I@glusterfs:client')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100788 salt.enforceState(master, 'I@glusterfs:client', 'glusterfs.client')
Simon Pasquieref4122c2017-08-25 15:52:07 +0200789 }
Martin Polreich792f2662017-07-11 13:36:32 +0200790 }
Jiri Broulike57a0242017-10-06 13:38:47 +0200791
Dmitry Kalashnik69ecb782018-05-21 17:36:50 +0400792 // Install MongoDB for Alerta
793 if (salt.testTarget(master, 'I@mongodb:server')) {
Ildar Svetlov829f94a2018-06-05 17:57:08 +0400794 salt.enforceState(master, 'I@mongodb:server', 'mongodb.server')
795
796 // Initialize mongodb replica set
797 common.retry(5,20){
798 salt.enforceState(master, 'I@mongodb:server', 'mongodb.cluster')
799 }
Dmitry Kalashnik69ecb782018-05-21 17:36:50 +0400800 }
801
Martin Polreich8663a342017-06-30 17:33:08 +0200802 //Install Telegraf
Jakub Josef432e9d92018-02-06 18:28:37 +0100803 salt.enforceState(master, 'I@telegraf:agent or I@telegraf:remote_agent', 'telegraf')
Martin Polreich8663a342017-06-30 17:33:08 +0200804
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400805 // Install Prometheus exporters
806 if (salt.testTarget(master, 'I@prometheus:exporters')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100807 salt.enforceState(master, 'I@prometheus:exporters', 'prometheus')
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400808 }
809
Martin Polreich8663a342017-06-30 17:33:08 +0200810 //Install Elasticsearch and Kibana
Jakub Josef432e9d92018-02-06 18:28:37 +0100811 salt.enforceState(master, '*01* and I@elasticsearch:server', 'elasticsearch.server')
812 salt.enforceState(master, 'I@elasticsearch:server', 'elasticsearch.server')
813 salt.enforceState(master, '*01* and I@kibana:server', 'kibana.server')
814 salt.enforceState(master, 'I@kibana:server', 'kibana.server')
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200815
816 // Check ES health cluster status
817 def pillar = salt.getPillar(master, 'I@elasticsearch:client', 'elasticsearch:client:server:host')
818 def elasticsearch_vip
819 if(!pillar['return'].isEmpty()) {
820 elasticsearch_vip = pillar['return'][0].values()[0]
821 } else {
822 common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved')
823 }
824 pillar = salt.getPillar(master, 'I@elasticsearch:client', 'elasticsearch:client:server:port')
825 def elasticsearch_port
826 if(!pillar['return'].isEmpty()) {
827 elasticsearch_port = pillar['return'][0].values()[0]
828 } else {
829 common.errorMsg('[ERROR] Elasticsearch VIP port could not be retrieved')
830 }
831 common.retry(retries,retries_wait) {
832 common.infoMsg('Waiting for Elasticsearch to become green..')
833 salt.cmdRun(master, 'I@elasticsearch:client', "curl -sf ${elasticsearch_vip}:${elasticsearch_port}/_cat/health | awk '{print \$4}' | grep green")
834 }
835
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200836 common.retry(retries,retries_wait) {
Mateusz Matuszkowiakb46fbc12018-06-08 10:52:15 +0200837 salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client')
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200838 }
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200839
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200840 common.retry(retries,retries_wait) {
Mateusz Matuszkowiakb46fbc12018-06-08 10:52:15 +0200841 salt.enforceState(master, 'I@kibana:client', 'kibana.client')
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200842 }
Dmitry Kalashnik53feda72018-03-16 16:06:10 +0400843
844 //Install InfluxDB
845 if (salt.testTarget(master, 'I@influxdb:server')) {
846 salt.enforceState(master, '*01* and I@influxdb:server', 'influxdb')
847 salt.enforceState(master, 'I@influxdb:server', 'influxdb')
848 }
849
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400850 // Install service for the log collection
851 if (salt.testTarget(master, 'I@fluentd:agent')) {
852 salt.enforceState(master, 'I@fluentd:agent', 'fluentd')
853 } else {
854 salt.enforceState(master, 'I@heka:log_collector', 'heka.log_collector')
855 }
Simon Pasquier6301ddd2017-09-05 11:56:58 +0200856
Ondrej Smola5908ae62018-01-08 13:42:08 +0100857 // Install heka ceilometer collector
858 if (salt.testTarget(master, 'I@heka:ceilometer_collector:enabled')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100859 salt.enforceState(master, 'I@heka:ceilometer_collector:enabled', 'heka.ceilometer_collector')
Ondrej Smola5908ae62018-01-08 13:42:08 +0100860 salt.runSaltProcessStep(master, 'I@heka:ceilometer_collector:enabled', 'service.restart', ['ceilometer_collector'], null, true)
861 }
862
Martin Polreich470925a2017-07-06 17:12:59 +0200863 // Install galera
Martin Polreich792f2662017-07-11 13:36:32 +0200864 if (common.checkContains('STACK_INSTALL', 'k8s')) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100865 salt.enforceState(master, 'I@galera:master', 'galera', true, true, null, false, -1, 2)
Jakub Josef9994ea72018-03-05 13:23:07 +0100866 salt.enforceState(master, 'I@galera:slave', 'galera', true, true, null, false, -1, 2)
Martin Polreich406f6462017-07-11 11:33:42 +0000867
Martin Polreich792f2662017-07-11 13:36:32 +0200868 // Check galera status
869 salt.runSaltProcessStep(master, 'I@galera:master', 'mysql.status')
870 salt.runSaltProcessStep(master, 'I@galera:slave', 'mysql.status')
871 }
Martin Polreich470925a2017-07-06 17:12:59 +0200872
Martin Polreich8663a342017-06-30 17:33:08 +0200873 //Collect Grains
Jakub Josef432e9d92018-02-06 18:28:37 +0100874 salt.enforceState(master, 'I@salt:minion', 'salt.minion.grains')
875 salt.runSaltProcessStep(master, 'I@salt:minion', 'saltutil.refresh_modules')
876 salt.runSaltProcessStep(master, 'I@salt:minion', 'mine.update')
Martin Polreich8663a342017-06-30 17:33:08 +0200877 sleep(5)
878
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400879 // Configure Prometheus in Docker Swarm
Oleg Basov162dd8a2018-03-13 01:27:50 +0100880 salt.enforceState(master, 'I@docker:swarm and I@prometheus:server', 'prometheus')
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400881
Ildar Svetlov0eec97d2018-02-15 10:06:40 +0400882 //Configure Remote Collector in Docker Swarm for Openstack deployments
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400883 if (!common.checkContains('STACK_INSTALL', 'k8s')) {
Ildar Svetlov0eec97d2018-02-15 10:06:40 +0400884 salt.enforceState(master, 'I@docker:swarm and I@prometheus:server', 'heka.remote_collector', true, false)
Martin Polreich8017f452017-08-21 16:01:42 +0200885 }
Martin Polreich8663a342017-06-30 17:33:08 +0200886
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400887 // Launch containers
888 salt.enforceState(master, 'I@docker:swarm:role:master and I@prometheus:server', 'docker.client')
889 salt.runSaltProcessStep(master, 'I@docker:swarm and I@prometheus:server', 'dockerng.ps')
890
891 //Install Prometheus LTS
892 if (salt.testTarget(master, 'I@prometheus:relay')) {
893 salt.enforceState(master, 'I@prometheus:relay', 'prometheus')
894 }
895
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100896 // Install sphinx server
897 if (salt.testTarget(master, 'I@sphinx:server')) {
898 salt.enforceState(master, 'I@sphinx:server', 'sphinx')
899 }
900
Martin Polreich8663a342017-06-30 17:33:08 +0200901 //Configure Grafana
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200902 pillar = salt.getPillar(master, 'ctl01*', '_param:stacklight_monitor_address')
Martin Polreich8663a342017-06-30 17:33:08 +0200903 common.prettyPrint(pillar)
Martin Polreich595baef2017-07-04 16:11:04 +0200904
Martin Polreich8663a342017-06-30 17:33:08 +0200905 def stacklight_vip
906 if(!pillar['return'].isEmpty()) {
907 stacklight_vip = pillar['return'][0].values()[0]
908 } else {
909 common.errorMsg('[ERROR] Stacklight VIP address could not be retrieved')
910 }
vrovachev1c4770b2017-07-05 13:25:21 +0400911
Martin Polreich305e2222017-07-06 11:33:00 +0200912 common.infoMsg("Waiting for service on http://${stacklight_vip}:15013/ to start")
Martin Polreichbd7ad222017-07-06 12:53:51 +0200913 sleep(120)
Jakub Josef432e9d92018-02-06 18:28:37 +0100914 salt.enforceState(master, 'I@grafana:client', 'grafana.client')
Martin Polreich8663a342017-06-30 17:33:08 +0200915}
916
917def installStacklightv1Control(master) {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200918 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200919
920 // infra install
921 // Install the StackLight backends
Jakub Josef432e9d92018-02-06 18:28:37 +0100922 salt.enforceState(master, '*01* and I@elasticsearch:server', 'elasticsearch.server')
923 salt.enforceState(master, 'I@elasticsearch:server', 'elasticsearch.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200924
Jakub Josef432e9d92018-02-06 18:28:37 +0100925 salt.enforceState(master, '*01* and I@influxdb:server', 'influxdb')
926 salt.enforceState(master, 'I@influxdb:server', 'influxdb')
Ales Komarekef2bab62017-04-26 11:48:28 +0200927
Jakub Josef432e9d92018-02-06 18:28:37 +0100928 salt.enforceState(master, '*01* and I@kibana:server', 'kibana.server')
929 salt.enforceState(master, 'I@kibana:server', 'kibana.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200930
Jakub Josef432e9d92018-02-06 18:28:37 +0100931 salt.enforceState(master, '*01* and I@grafana:server','grafana.server')
932 salt.enforceState(master, 'I@grafana:server','grafana.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200933
Kalynovskyi3e370112017-06-26 12:48:23 +0300934 def alarming_service_pillar = salt.getPillar(master, 'mon*01*', '_param:alarming_service')
935 def alarming_service = alarming_service_pillar['return'][0].values()[0]
936
937 switch (alarming_service) {
938 case 'sensu':
939 // Update Sensu
Jakub Josef432e9d92018-02-06 18:28:37 +0100940 salt.enforceState(master, 'I@sensu:server and I@rabbitmq:server', 'rabbitmq')
941 salt.enforceState(master, 'I@redis:cluster:role:master', 'redis')
942 salt.enforceState(master, 'I@redis:server', 'redis')
943 salt.enforceState(master, 'I@sensu:server', 'sensu')
Kalynovskyi3e370112017-06-26 12:48:23 +0300944 default:
945 // Update Nagios
Jakub Josef432e9d92018-02-06 18:28:37 +0100946 salt.enforceState(master, 'I@nagios:server', 'nagios.server')
Kalynovskyi3e370112017-06-26 12:48:23 +0300947 // Stop the Nagios service because the package starts it by default and it will
948 // started later only on the node holding the VIP address
949 salt.runSaltProcessStep(master, 'I@nagios:server', 'service.stop', ['nagios3'], null, true)
950 }
951
Jakub Josef432e9d92018-02-06 18:28:37 +0100952 salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client.service')
953 salt.enforceState(master, 'I@kibana:client', 'kibana.client')
Ales Komarekef2bab62017-04-26 11:48:28 +0200954
955 sleep(10)
956}
957
Martin Polreich8663a342017-06-30 17:33:08 +0200958def installStacklightv1Client(master) {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200959 def salt = new com.mirantis.mk.Salt()
960 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200961
Jakub Josef432e9d92018-02-06 18:28:37 +0100962 salt.cmdRun(master, 'I@elasticsearch:client', 'salt-call state.sls elasticsearch.client')
Ales Komarekef2bab62017-04-26 11:48:28 +0200963 // salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client', true)
Jakub Josef432e9d92018-02-06 18:28:37 +0100964 salt.cmdRun(master, 'I@kibana:client', 'salt-call state.sls kibana.client')
Ales Komarekef2bab62017-04-26 11:48:28 +0200965 // salt.enforceState(master, 'I@kibana:client', 'kibana.client', true)
966
967 // Install collectd, heka and sensu services on the nodes, this will also
968 // generate the metadata that goes into the grains and eventually into Salt Mine
Jakub Josef432e9d92018-02-06 18:28:37 +0100969 salt.enforceState(master, '*', 'collectd')
970 salt.enforceState(master, '*', 'salt.minion')
971 salt.enforceState(master, '*', 'heka')
Ales Komarekef2bab62017-04-26 11:48:28 +0200972
973 // Gather the Grafana metadata as grains
974 salt.enforceState(master, 'I@grafana:collector', 'grafana.collector', true)
975
976 // Update Salt Mine
Jakub Josef432e9d92018-02-06 18:28:37 +0100977 salt.enforceState(master, '*', 'salt.minion.grains')
978 salt.runSaltProcessStep(master, '*', 'saltutil.refresh_modules')
979 salt.runSaltProcessStep(master, '*', 'mine.update')
Ales Komarekef2bab62017-04-26 11:48:28 +0200980
981 sleep(5)
982
983 // Update Heka
Jakub Josef432e9d92018-02-06 18:28:37 +0100984 salt.enforceState(master, 'I@heka:aggregator:enabled:True or I@heka:remote_collector:enabled:True', 'heka')
Ales Komarekef2bab62017-04-26 11:48:28 +0200985
986 // Update collectd
Jakub Josef432e9d92018-02-06 18:28:37 +0100987 salt.enforceState(master, 'I@collectd:remote_client:enabled:True', 'collectd')
Ales Komarekef2bab62017-04-26 11:48:28 +0200988
Kalynovskyi3e370112017-06-26 12:48:23 +0300989 def alarming_service_pillar = salt.getPillar(master, 'mon*01*', '_param:alarming_service')
990 def alarming_service = alarming_service_pillar['return'][0].values()[0]
Ales Komarekef2bab62017-04-26 11:48:28 +0200991
Kalynovskyi3e370112017-06-26 12:48:23 +0300992 switch (alarming_service) {
993 case 'sensu':
994 // Update Sensu
995 // TODO for stacklight team, should be fixed in model
Jakub Josef432e9d92018-02-06 18:28:37 +0100996 salt.enforceState(master, 'I@sensu:client', 'sensu')
Kalynovskyi3e370112017-06-26 12:48:23 +0300997 default:
998 break
999 // Default is nagios, and was enforced in installStacklightControl()
1000 }
Ales Komarekef2bab62017-04-26 11:48:28 +02001001
Jakub Josef432e9d92018-02-06 18:28:37 +01001002 salt.cmdRun(master, 'I@grafana:client and *01*', 'salt-call state.sls grafana.client')
Ales Komarekef2bab62017-04-26 11:48:28 +02001003 // salt.enforceState(master, 'I@grafana:client and *01*', 'grafana.client', true)
1004
Marek Celoudd200cad2017-06-07 10:34:46 +02001005 // Finalize the configuration of Grafana (add the dashboards...)
Jakub Josef432e9d92018-02-06 18:28:37 +01001006 salt.enforceState(master, 'I@grafana:client and *01*', 'grafana.client')
1007 salt.enforceState(master, 'I@grafana:client and *02*', 'grafana.client')
1008 salt.enforceState(master, 'I@grafana:client and *03*', 'grafana.client')
Marek Celoudd200cad2017-06-07 10:34:46 +02001009 // nw salt -C 'I@grafana:client' --async service.restart salt-minion; sleep 10
1010
Ales Komarekef2bab62017-04-26 11:48:28 +02001011 // Get the StackLight monitoring VIP addres
1012 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
1013 //vip=${vip:=172.16.10.253}
1014 def pillar = salt.getPillar(master, 'ctl01*', '_param:stacklight_monitor_address')
Jakub Josefbceaa322017-06-13 18:28:27 +02001015 common.prettyPrint(pillar)
Ales Komarekef2bab62017-04-26 11:48:28 +02001016 def stacklight_vip = pillar['return'][0].values()[0]
1017
1018 if (stacklight_vip) {
1019 // (re)Start manually the services that are bound to the monitoring VIP
1020 common.infoMsg("restart services on node with IP: ${stacklight_vip}")
Jakub Josef432e9d92018-02-06 18:28:37 +01001021 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collectd'])
1022 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collector'])
1023 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['aggregator'])
1024 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['nagios3'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001025 } else {
1026 throw new Exception("Missing stacklight_vip")
1027 }
Tomáš Kukrálf06ca0f2017-02-27 15:18:50 +01001028}
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001029
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001030//
1031// backups
1032//
1033
1034def installBackup(master, component='common') {
1035 def salt = new com.mirantis.mk.Salt()
1036 if (component == 'common') {
1037 // Install Backupninja
1038 if (salt.testTarget(master, 'I@backupninja:client')) {
1039 salt.enforceState(master, 'I@backupninja:client', 'salt.minion.grains')
1040 salt.runSaltProcessStep(master, 'I@backupninja:client', 'saltutil.sync_grains')
Jiri Broulik9e578da2018-03-01 13:15:53 +01001041 salt.runSaltProcessStep(master, 'I@backupninja:client', 'mine.flush')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001042 salt.runSaltProcessStep(master, 'I@backupninja:client', 'mine.update')
Jiri Broulikbe6898c2018-03-01 13:01:48 +01001043 salt.enforceState(master, 'I@backupninja:client', 'backupninja')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001044 }
1045 if (salt.testTarget(master, 'I@backupninja:server')) {
Jiri Broulik9e578da2018-03-01 13:15:53 +01001046 salt.enforceState(master, 'I@backupninja:server', 'salt.minion.grains')
Jiri Broulikbe6898c2018-03-01 13:01:48 +01001047 salt.enforceState(master, 'I@backupninja:server', 'backupninja')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001048 }
1049 } else if (component == 'mysql') {
1050 // Install Xtrabackup
1051 if (salt.testTarget(master, 'I@xtrabackup:client')) {
1052 salt.enforceState(master, 'I@xtrabackup:client', 'salt.minion.grains')
1053 salt.runSaltProcessStep(master, 'I@xtrabackup:client', 'saltutil.sync_grains')
Jiri Broulik9e578da2018-03-01 13:15:53 +01001054 salt.runSaltProcessStep(master, 'I@xtrabackup:client', 'mine.flush')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001055 salt.runSaltProcessStep(master, 'I@xtrabackup:client', 'mine.update')
1056 salt.enforceState(master, 'I@xtrabackup:client', 'xtrabackup')
1057 }
1058 if (salt.testTarget(master, 'I@xtrabackup:server')) {
1059 salt.enforceState(master, 'I@xtrabackup:server', 'xtrabackup')
1060 }
1061 } else if (component == 'contrail') {
1062
1063 // Install Cassandra backup
1064 if (salt.testTarget(master, 'I@cassandra:backup:client')) {
1065 salt.enforceState(master, 'I@cassandra:backup:client', 'salt.minion.grains')
1066 salt.runSaltProcessStep(master, 'I@cassandra:backup:client', 'saltutil.sync_grains')
Jiri Broulik9e578da2018-03-01 13:15:53 +01001067 salt.runSaltProcessStep(master, 'I@cassandra:backup:client', 'mine.flush')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001068 salt.runSaltProcessStep(master, 'I@cassandra:backup:client', 'mine.update')
1069 salt.enforceState(master, 'I@cassandra:backup:client', 'cassandra.backup')
1070 }
1071 if (salt.testTarget(master, 'I@cassandra:backup:server')) {
1072 salt.enforceState(master, 'I@cassandra:backup:server', 'cassandra.backup')
1073 }
1074 // Install Zookeeper backup
1075 if (salt.testTarget(master, 'I@zookeeper:backup:client')) {
1076 salt.enforceState(master, 'I@zookeeper:backup:client', 'salt.minion.grains')
1077 salt.runSaltProcessStep(master, 'I@zookeeper:backup:client', 'saltutil.sync_grains')
Jiri Broulik9e578da2018-03-01 13:15:53 +01001078 salt.runSaltProcessStep(master, 'I@zookeeper:backup:client', 'mine.flush')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001079 salt.runSaltProcessStep(master, 'I@zookeeper:backup:client', 'mine.update')
1080 salt.enforceState(master, 'I@zookeeper:backup:client', 'zookeeper.backup')
1081 }
1082 if (salt.testTarget(master, 'I@zookeeper:backup:server')) {
1083 salt.enforceState(master, 'I@zookeeper:backup:server', 'zookeeper.backup')
1084 }
1085 } else if (component == 'ceph') {
1086 // Install Ceph backup
1087 if (salt.testTarget(master, 'I@ceph:backup:client')) {
1088 salt.enforceState(master, 'I@ceph:backup:client', 'salt.minion.grains')
1089 salt.runSaltProcessStep(master, 'I@ceph:backup:client', 'saltutil.sync_grains')
Jiri Broulik9e578da2018-03-01 13:15:53 +01001090 salt.runSaltProcessStep(master, 'I@ceph:backup:client', 'mine.flush')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001091 salt.runSaltProcessStep(master, 'I@ceph:backup:client', 'mine.update')
Jiri Broulikbe6898c2018-03-01 13:01:48 +01001092 salt.enforceState(master, 'I@ceph:backup:client', 'ceph.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001093 }
1094 if (salt.testTarget(master, 'I@ceph:backup:server')) {
Jiri Broulikbe6898c2018-03-01 13:01:48 +01001095 salt.enforceState(master, 'I@ceph:backup:server', 'ceph.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001096 }
1097 }
1098
1099}
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001100
1101//
1102// Ceph
1103//
1104
Tomáš Kukráled27a472017-08-29 10:26:25 +02001105def installCephMon(master, target='I@ceph:mon') {
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001106 def salt = new com.mirantis.mk.Salt()
1107
Jakub Josef432e9d92018-02-06 18:28:37 +01001108 salt.enforceState(master, 'I@ceph:common', 'salt.minion.grains')
Jiri Broulikbfc234f2017-10-17 15:45:38 +02001109
Jiri Broulike57a0242017-10-06 13:38:47 +02001110 // generate keyrings
1111 if (salt.testTarget(master, 'I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin')) {
Jakub Josef432e9d92018-02-06 18:28:37 +01001112 salt.enforceState(master, 'I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin', 'ceph.mon')
1113 salt.runSaltProcessStep(master, 'I@ceph:mon', 'saltutil.sync_grains')
1114 salt.runSaltProcessStep(master, 'I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin', 'mine.update')
Jiri Broulik3c75a6d2017-10-06 18:44:37 +02001115 sleep(5)
Jiri Broulike57a0242017-10-06 13:38:47 +02001116 }
Ondrej Smolafd5c2352017-08-11 14:25:39 +02001117 // install Ceph Mons
Jakub Josef432e9d92018-02-06 18:28:37 +01001118 salt.enforceState(master, target, 'ceph.mon')
Jiri Broulike57a0242017-10-06 13:38:47 +02001119 if (salt.testTarget(master, 'I@ceph:mgr')) {
Jakub Josef432e9d92018-02-06 18:28:37 +01001120 salt.enforceState(master, 'I@ceph:mgr', 'ceph.mgr')
Jiri Broulike57a0242017-10-06 13:38:47 +02001121 }
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001122}
1123
Tomáš Kukráled27a472017-08-29 10:26:25 +02001124def installCephOsd(master, target='I@ceph:osd', setup=true) {
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001125 def salt = new com.mirantis.mk.Salt()
1126
1127 // install Ceph OSDs
Jakub Josef432e9d92018-02-06 18:28:37 +01001128 salt.enforceState(master, target, 'ceph.osd')
1129 salt.runSaltProcessStep(master, 'I@ceph:osd', 'saltutil.sync_grains')
1130 salt.enforceState(master, target, 'ceph.osd.custom')
1131 salt.runSaltProcessStep(master, 'I@ceph:osd', 'saltutil.sync_grains')
1132 salt.runSaltProcessStep(master, 'I@ceph:osd', 'mine.update')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001133 installBackup(master, 'ceph')
Tomáš Kukráled27a472017-08-29 10:26:25 +02001134
Jiri Broulike57a0242017-10-06 13:38:47 +02001135 // setup pools, keyrings and maybe crush
Tomáš Kukráled27a472017-08-29 10:26:25 +02001136 if (salt.testTarget(master, 'I@ceph:setup') && setup) {
Jiri Broulik07f8de72017-10-09 14:12:17 +02001137 sleep(5)
Jakub Josef432e9d92018-02-06 18:28:37 +01001138 salt.enforceState(master, 'I@ceph:setup', 'ceph.setup')
Tomáš Kukráled27a472017-08-29 10:26:25 +02001139 }
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001140}
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001141
Tomáš Kukrál5836e3d2017-08-25 18:20:55 +02001142def installCephClient(master) {
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001143 def salt = new com.mirantis.mk.Salt()
1144
1145 // install Ceph Radosgw
Tomáš Kukrál5836e3d2017-08-25 18:20:55 +02001146 if (salt.testTarget(master, 'I@ceph:radosgw')) {
Jakub Josef432e9d92018-02-06 18:28:37 +01001147 salt.runSaltProcessStep(master, 'I@ceph:radosgw', 'saltutil.sync_grains')
1148 salt.enforceState(master, 'I@ceph:radosgw', 'ceph.radosgw')
Alexander Noskov229035f2017-12-06 00:10:20 +04001149 }
1150 // setup Keystone service and endpoints for swift or / and S3
1151 if (salt.testTarget(master, 'I@keystone:client')) {
Jakub Josef432e9d92018-02-06 18:28:37 +01001152 salt.enforceState(master, 'I@keystone:client', 'keystone.client')
Tomáš Kukrál5836e3d2017-08-25 18:20:55 +02001153 }
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001154}
Jiri Broulike57a0242017-10-06 13:38:47 +02001155
1156def connectCeph(master) {
1157 def salt = new com.mirantis.mk.Salt()
1158
1159 // connect Ceph to the env
1160 if (salt.testTarget(master, 'I@ceph:common and I@glance:server')) {
Jakub Josef432e9d92018-02-06 18:28:37 +01001161 salt.enforceState(master, 'I@ceph:common and I@glance:server', ['ceph.common', 'ceph.setup.keyring', 'glance'])
Dmitry Ukov8a344b72018-05-17 17:05:17 +04001162 salt.runSaltProcessStep(master, 'I@ceph:common and I@glance:server', 'service.restart', ['glance-api'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001163 }
1164 if (salt.testTarget(master, 'I@ceph:common and I@cinder:controller')) {
Jakub Josef432e9d92018-02-06 18:28:37 +01001165 salt.enforceState(master, 'I@ceph:common and I@cinder:controller', ['ceph.common', 'ceph.setup.keyring', 'cinder'])
Dmitry Ukov8a344b72018-05-17 17:05:17 +04001166 salt.runSaltProcessStep(master, 'I@ceph:common and I@cinder:controller', 'service.restart', ['cinder-volume'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001167 }
1168 if (salt.testTarget(master, 'I@ceph:common and I@nova:compute')) {
Jakub Josef432e9d92018-02-06 18:28:37 +01001169 salt.enforceState(master, 'I@ceph:common and I@nova:compute', ['ceph.common', 'ceph.setup.keyring'])
1170 salt.runSaltProcessStep(master, 'I@ceph:common and I@nova:compute', 'saltutil.sync_grains')
1171 salt.enforceState(master, 'I@ceph:common and I@nova:compute', ['nova'])
Dmitry Ukov8a344b72018-05-17 17:05:17 +04001172 salt.runSaltProcessStep(master, 'I@ceph:common and I@nova:compute', 'service.restart', ['nova-compute'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001173 }
1174}
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001175
1176def installOssInfra(master) {
1177 def common = new com.mirantis.mk.Common()
1178 def salt = new com.mirantis.mk.Salt()
1179
Mikhail Ivanov788996c2017-12-15 14:28:57 +04001180 if (!common.checkContains('STACK_INSTALL', 'k8s') || !common.checkContains('STACK_INSTALL', 'openstack')) {
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001181 def orchestrate = new com.mirantis.mk.Orchestrate()
1182 orchestrate.installInfra(master)
1183 }
1184
1185 if (salt.testTarget(master, 'I@devops_portal:config')) {
Jakub Josef432e9d92018-02-06 18:28:37 +01001186 salt.enforceState(master, 'I@devops_portal:config', 'devops_portal.config')
1187 salt.enforceState(master, 'I@rundeck:client', ['linux.system.user', 'openssh'])
1188 salt.enforceState(master, 'I@rundeck:server', 'rundeck.server')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001189 }
1190}
1191
1192def installOss(master) {
1193 def common = new com.mirantis.mk.Common()
1194 def salt = new com.mirantis.mk.Salt()
1195
1196 //Get oss VIP address
1197 def pillar = salt.getPillar(master, 'cfg01*', '_param:stacklight_monitor_address')
1198 common.prettyPrint(pillar)
1199
1200 def oss_vip
1201 if(!pillar['return'].isEmpty()) {
1202 oss_vip = pillar['return'][0].values()[0]
1203 } else {
1204 common.errorMsg('[ERROR] Oss VIP address could not be retrieved')
1205 }
1206
1207 // Postgres client - initialize OSS services databases
1208 timeout(120){
1209 common.infoMsg("Waiting for postgresql database to come up..")
Nikolas Britton4f62a092018-02-06 16:56:26 -06001210 salt.cmdRun(master, 'I@postgresql:client', 'while true; do if docker service logs postgresql_postgresql-db 2>&1 | grep "ready to accept"; then break; else sleep 5; fi; done')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001211 }
1212 // XXX: first run usually fails on some inserts, but we need to create databases at first
1213 salt.enforceState(master, 'I@postgresql:client', 'postgresql.client', true, false)
1214
1215 // Setup postgres database with integration between
1216 // Pushkin notification service and Security Monkey security audit service
1217 timeout(10) {
1218 common.infoMsg("Waiting for Pushkin to come up..")
1219 salt.cmdRun(master, 'I@postgresql:client', "while true; do curl -sf ${oss_vip}:8887/apps >/dev/null && break; done")
1220 }
Jakub Josef432e9d92018-02-06 18:28:37 +01001221 salt.enforceState(master, 'I@postgresql:client', 'postgresql.client')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001222
1223 // Rundeck
1224 timeout(10) {
1225 common.infoMsg("Waiting for Rundeck to come up..")
1226 salt.cmdRun(master, 'I@rundeck:client', "while true; do curl -sf ${oss_vip}:4440 >/dev/null && break; done")
1227 }
Jakub Josef432e9d92018-02-06 18:28:37 +01001228 salt.enforceState(master, 'I@rundeck:client', 'rundeck.client')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001229
1230 // Elasticsearch
Mikhail Ivanovfcd55d62017-12-19 16:51:35 +04001231 pillar = salt.getPillar(master, 'I@elasticsearch:client', 'elasticsearch:client:server:host')
1232 def elasticsearch_vip
1233 if(!pillar['return'].isEmpty()) {
1234 elasticsearch_vip = pillar['return'][0].values()[0]
1235 } else {
1236 common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved')
1237 }
1238
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001239 timeout(10) {
1240 common.infoMsg('Waiting for Elasticsearch to come up..')
Mikhail Ivanovfcd55d62017-12-19 16:51:35 +04001241 salt.cmdRun(master, 'I@elasticsearch:client', "while true; do curl -sf ${elasticsearch_vip}:9200 >/dev/null && break; done")
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001242 }
Jakub Josef432e9d92018-02-06 18:28:37 +01001243 salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001244}