blob: 2b15a92c8365092c557a08c2df3e0d8a020925b0 [file] [log] [blame]
Jakub Josef79ecec32017-02-17 14:36:28 +01001package com.mirantis.mk
2/**
3 * Orchestration functions
4 *
5*/
6
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03007/**
8 * Function runs Salt states to check infra
9 * @param master Salt Connection object or pepperEnv
10 * @param extra_tgt Extra target - adds ability to address commands using extra targeting to different clouds, e.g.: salt -C 'I@keystone:server and *ogrudev-deploy-heat-os-ha-ovs-82*' ...
11 */
12def validateFoundationInfra(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +010013 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +020014
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030015 salt.cmdRun(master, "I@salt:master ${extra_tgt}" ,'salt-key')
16 salt.runSaltProcessStep(master, "I@salt:minion ${extra_tgt}", 'test.version')
17 salt.cmdRun(master, "I@salt:master ${extra_tgt}" ,'reclass-salt --top')
18 salt.runSaltProcessStep(master, "I@reclass:storage ${extra_tgt}", 'reclass.inventory')
19 salt.runSaltProcessStep(master, "I@salt:minion ${extra_tgt}", 'state.show_top')
Jakub Josef79ecec32017-02-17 14:36:28 +010020}
21
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030022def installFoundationInfra(master, staticMgmtNet=false, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +010023 def salt = new com.mirantis.mk.Salt()
Jiri Broulik037f8982018-04-23 17:07:16 +020024 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +020025
Vasyl Saienko0869b3a2017-11-22 14:37:57 +020026 // NOTE(vsaienko) Apply reclass first, it may update cluster model
27 // apply linux and salt.master salt.minion states afterwards to make sure
28 // correct cluster model is used.
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030029 salt.enforceState(master, "I@salt:master ${extra_tgt}", ['reclass'])
Tomáš Kukrálb4d75222017-06-06 10:36:02 +020030
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030031 salt.enforceState(master, "I@salt:master ${extra_tgt}", ['linux.system'])
32 salt.enforceState(master, "I@salt:master ${extra_tgt}", ['salt.master'], true, false, null, false, 120, 2)
33 salt.fullRefresh(master, "* ${extra_tgt}")
Tomáš Kukrálb4d75222017-06-06 10:36:02 +020034
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030035 salt.enforceState(master, "I@salt:master ${extra_tgt}", ['salt.minion'], true, false, null, false, 60, 2)
36 salt.enforceState(master, "I@salt:master ${extra_tgt}", ['salt.minion'])
37 salt.fullRefresh(master, "* ${extra_tgt}")
38 salt.enforceState(master, "* ${extra_tgt}", ['linux.network.proxy'], true, false, null, false, 60, 2)
iberezovskiy6394a8a2018-10-12 13:16:47 +040039 // Make sure all repositories are in place before proceeding with package installation from other states
40 salt.enforceState(master, "* ${extra_tgt}", ['linux.system.repo'], true, false, null, false, 60, 2)
Jiri Broulik94fc2592018-04-20 13:47:51 +020041 try {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030042 salt.enforceState(master, "* ${extra_tgt}", ['salt.minion.base'], true, false, null, false, 60, 2)
Jiri Broulik94fc2592018-04-20 13:47:51 +020043 sleep(5)
44 } catch (Throwable e) {
45 common.warningMsg('Salt state salt.minion.base is not present in the Salt-formula yet.')
46 }
Jiri Broulike3ace622018-06-07 10:51:02 +020047 common.retry(2,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030048 salt.enforceState(master, "* ${extra_tgt}", ['linux.system'])
Jiri Broulike3ace622018-06-07 10:51:02 +020049 }
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +010050 if (staticMgmtNet) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030051 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], null, true, 60)
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +010052 }
Ondrej Smola855dc1a2018-07-18 13:07:55 +020053 common.retry(2,5){
54 salt.enforceState(master, "I@linux:network:interface ${extra_tgt}", ['linux.network.interface'])
55 }
Jiri Broulik94538462018-05-11 15:45:13 +020056 sleep(5)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030057 salt.enforceState(master, "I@linux:system ${extra_tgt}", ['linux', 'openssh', 'ntp', 'rsyslog'])
Ann Taraday49059762018-10-25 17:04:58 +040058
Ann Kamyshnikova7c905792018-10-26 16:38:01 +040059 common.retry(3, 5) {
Ann Taraday49059762018-10-25 17:04:58 +040060 salt.enforceState(master, "* ${extra_tgt}", ['salt.minion'], true, false, null, false, 60, 2)
61 }
Jakub Josef4f8f4df2017-09-01 14:32:42 +020062 sleep(5)
Victor Ryzhenkinf610c572018-05-15 15:22:52 +040063
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030064 salt.fullRefresh(master, "* ${extra_tgt}")
65 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'mine.update', [], null, true)
66 salt.enforceState(master, "* ${extra_tgt}", ['linux.network.host'])
Ivan Suzdal9a6bc392018-04-26 18:29:56 +040067
68 // Install and configure iptables
Martin Polreich675dc942018-08-15 09:37:32 +020069 salt.enforceStateWithTest(master, "I@iptables:service ${extra_tgt}", 'iptables')
sgarbuzbb61e812018-05-03 16:58:40 +030070
71 // Install and configure logrotate
Martin Polreich675dc942018-08-15 09:37:32 +020072 salt.enforceStateWithTest(master, "I@logrotate:server ${extra_tgt}", 'logrotate')
Ivan Suzdal9f8f0e12018-06-21 13:16:21 +040073
74 // Install and configure auditd
Martin Polreich675dc942018-08-15 09:37:32 +020075 salt.enforceStateWithTest(master, "I@auditd:service ${extra_tgt}", 'auditd')
Ivan Suzdalca980912018-08-02 09:35:07 +040076
77 // Install and configure openscap
Martin Polreich675dc942018-08-15 09:37:32 +020078 salt.enforceStateWithTest(master, "I@openscap:service ${extra_tgt}", 'openscap')
Jakub Josef79ecec32017-02-17 14:36:28 +010079}
80
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030081def installFoundationInfraOnTarget(master, target, staticMgmtNet=false, extra_tgt = '') {
Jiri Broulik976bf6c2017-10-20 14:43:25 +020082 def salt = new com.mirantis.mk.Salt()
Jiri Broulik9fb138a2018-04-23 17:13:00 +020083 def common = new com.mirantis.mk.Common()
Jiri Broulik976bf6c2017-10-20 14:43:25 +020084
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030085 salt.enforceState(master, "I@salt:master ${extra_tgt}", ['reclass'], true, false, null, false, 120, 2)
Jakub Josef432e9d92018-02-06 18:28:37 +010086 salt.fullRefresh(master, target)
Ondrej Smolaa9b84662018-04-18 11:22:19 +020087 salt.enforceState(master, target, ['linux.network.proxy'], true, false, null, false, 60, 2)
Jiri Broulik94fc2592018-04-20 13:47:51 +020088 try {
89 salt.enforceState(master, target, ['salt.minion.base'], true, false, null, false, 60, 2)
90 sleep(5)
91 } catch (Throwable e) {
92 common.warningMsg('Salt state salt.minion.base is not present in the Salt-formula yet.')
93 }
Jiri Broulike3ace622018-06-07 10:51:02 +020094 common.retry(2,5){
95 salt.enforceState(master, target, ['linux.system'])
96 }
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +010097 if (staticMgmtNet) {
98 salt.runSaltProcessStep(master, target, 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], null, true, 60)
99 }
Jiri Broulik976bf6c2017-10-20 14:43:25 +0200100 salt.enforceState(master, target, ['salt.minion'], true, false, null, false, 60, 2)
Jakub Josef432e9d92018-02-06 18:28:37 +0100101 salt.enforceState(master, target, ['salt.minion'])
Jiri Broulik3740fb92018-04-27 11:52:38 +0200102 salt.enforceState(master, target, ['linux.network.interface'])
Jiri Broulik94538462018-05-11 15:45:13 +0200103 sleep(5)
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100104 salt.enforceState(master, target, ['linux', 'openssh', 'ntp', 'rsyslog'])
Jiri Broulik976bf6c2017-10-20 14:43:25 +0200105 sleep(5)
Victor Ryzhenkinf610c572018-05-15 15:22:52 +0400106
107 salt.fullRefresh(master, target)
vrovachevc4424a32018-03-15 17:35:57 +0400108 salt.runSaltProcessStep(master, target, 'mine.update', [], null, true)
Jakub Josef432e9d92018-02-06 18:28:37 +0100109 salt.enforceState(master, target, ['linux.network.host'])
Jiri Broulik976bf6c2017-10-20 14:43:25 +0200110}
111
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300112def installInfraKvm(master, extra_tgt = '') {
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200113 def common = new com.mirantis.mk.Common()
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +0100114 def salt = new com.mirantis.mk.Salt()
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300115 def infra_compound = "I@salt:control ${extra_tgt}"
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200116 def minions = []
117 def wait_timeout = 10
118 def retries = wait_timeout * 30
Ales Komarekef2bab62017-04-26 11:48:28 +0200119
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300120 salt.fullRefresh(master, "I@linux:system ${extra_tgt}")
121 salt.enforceState(master, "I@salt:control ${extra_tgt}", ['salt.minion'], true, false, null, false, 60, 2)
122 salt.enforceState(master, "I@salt:control ${extra_tgt}", ['linux.system', 'linux.network', 'ntp', 'rsyslog'])
123 salt.enforceState(master, "I@salt:control ${extra_tgt}", 'libvirt')
124 salt.enforceState(master, "I@salt:control ${extra_tgt}", 'salt.control')
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100125
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200126 common.infoMsg("Building minions list...")
127 if (salt.testTarget(master, infra_compound)) {
128 // Gathering minions
129 for ( infra_node in salt.getMinionsSorted(master, infra_compound) ) {
130 def pillar = salt.getPillar(master, infra_node, 'salt:control:cluster')
131 if ( !pillar['return'].isEmpty() ) {
132 for ( cluster in pillar['return'][0].values() ) {
133 def engine = cluster.values()[0]['engine']
134 def domain = cluster.values()[0]['domain']
135 def node = cluster.values()[0]['node']
136 if ( engine == "virt" ) {
137 def nodes = node.values()
138 if ( !nodes.isEmpty() ) {
139 for ( vm in nodes ) {
140 if ( vm['name'] != null ) {
141 def vm_fqdn = vm['name'] + '.' + domain
142 if ( !minions.contains(vm_fqdn) ) {
143 minions.add(vm_fqdn)
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200144 }
145 }
146 }
147 }
148 }
149 }
150 }
151 }
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200152 }
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100153
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200154 def minions_compound = minions.join(' or ')
155
156 common.infoMsg("Waiting for next minions to register within ${wait_timeout} minutes: " + minions_compound)
157 timeout(time: wait_timeout, unit: 'MINUTES') {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300158 salt.minionsPresentFromList(master, "I@salt:master ${extra_tgt}", minions, true, null, true, retries, 1)
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200159 }
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200160
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200161 common.infoMsg('Waiting for minions to respond')
162 timeout(time: wait_timeout, unit: 'MINUTES') {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300163 salt.minionsReachable(master, "I@salt:master ${extra_tgt}", minions_compound)
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200164 }
165
166 common.infoMsg("All minions are up.")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300167 salt.fullRefresh(master, "* and not kvm* ${extra_tgt}")
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200168
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +0100169}
Jakub Josef79ecec32017-02-17 14:36:28 +0100170
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300171def installInfra(master, extra_tgt = '') {
Jakub Josef61463c72018-02-13 16:10:56 +0100172 def common = new com.mirantis.mk.Common()
Jakub Josef79ecec32017-02-17 14:36:28 +0100173 def salt = new com.mirantis.mk.Salt()
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400174 def first_target
Ales Komarekef2bab62017-04-26 11:48:28 +0200175
Jakub Josef79ecec32017-02-17 14:36:28 +0100176 // Install glusterfs
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300177 if (salt.testTarget(master, "I@glusterfs:server ${extra_tgt}")) {
178 salt.enforceState(master, "I@glusterfs:server ${extra_tgt}", 'glusterfs.server.service')
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100179
Mykyta Karpin6475ea22018-09-13 11:12:58 +0300180 salt.enforceState(master, "I@glusterfs:server:role:primary ${extra_tgt}", 'glusterfs.server.setup', true, true, null, false, -1, 5)
Jakub Josef61463c72018-02-13 16:10:56 +0100181 sleep(10)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300182 salt.cmdRun(master, "I@glusterfs:server ${extra_tgt}", "gluster peer status; gluster volume status")
Alexander Noskov93acac42017-06-20 17:55:55 +0200183 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200184
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300185 // Ensure glusterfs clusters is ready
Martin Polreich2be0d4b2018-09-27 15:57:19 +0200186 salt.enforceStateWithTest(master, "I@glusterfs:client ${extra_tgt}", 'glusterfs.client', "", true, true, null, false, -1, 2)
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300187
Jakub Josef79ecec32017-02-17 14:36:28 +0100188 // Install galera
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300189 if (salt.testTarget(master, "I@galera:master ${extra_tgt}") || salt.testTarget(master, "I@galera:slave ${extra_tgt}")) {
190 salt.enforceState(master, "I@galera:master ${extra_tgt}", 'galera', true, true, null, false, -1, 2)
191 salt.enforceState(master, "I@galera:slave ${extra_tgt}", 'galera', true, true, null, false, -1, 2)
vrovachev1c4770b2017-07-05 13:25:21 +0400192
193 // Check galera status
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300194 salt.runSaltProcessStep(master, "I@galera:master ${extra_tgt}", 'mysql.status')
195 salt.runSaltProcessStep(master, "I@galera:slave ${extra_tgt}", 'mysql.status')
Vasyl Saienkoc1fb9892017-07-13 14:54:13 +0300196 // If galera is not enabled check if we need to install mysql:server
Martin Polreich675dc942018-08-15 09:37:32 +0200197 } else {
198 salt.enforceStateWithTest(master, "I@mysql:server ${extra_tgt}", 'mysql.server')
199 salt.enforceStateWithTest(master, "I@mysql:client ${extra_tgt}", 'mysql.client')
Ales Komarekef2bab62017-04-26 11:48:28 +0200200 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300201 installBackup(master, 'mysql', extra_tgt)
Ales Komarekef2bab62017-04-26 11:48:28 +0200202
vrovachev1c4770b2017-07-05 13:25:21 +0400203 // Install docker
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300204 if (salt.testTarget(master, "I@docker:host ${extra_tgt}")) {
Richard Felkl449b8ff2018-07-20 15:34:51 +0200205 salt.enforceState(master, "I@docker:host ${extra_tgt}", 'docker.host', true, true, null, false, -1, 3)
Pavel Cizinskyee34e312018-08-06 15:11:58 +0200206 salt.cmdRun(master, "I@docker:host and I@docker:host:enabled:true ${extra_tgt}", 'docker ps')
vrovachev1c4770b2017-07-05 13:25:21 +0400207 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200208
vrovachev1c4770b2017-07-05 13:25:21 +0400209 // Install keepalived
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300210 if (salt.testTarget(master, "I@keepalived:cluster ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400211 first_target = salt.getFirstMinion(master, "I@keepalived:cluster ${extra_tgt}")
212 salt.enforceState(master, "${first_target} ${extra_tgt}", 'keepalived')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300213 salt.enforceState(master, "I@keepalived:cluster ${extra_tgt}", 'keepalived')
vrovachev1c4770b2017-07-05 13:25:21 +0400214 }
215
216 // Install rabbitmq
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300217 if (salt.testTarget(master, "I@rabbitmq:server ${extra_tgt}")) {
218 salt.enforceState(master, "I@rabbitmq:server ${extra_tgt}", 'rabbitmq', true, true, null, false, -1, 2)
vrovachev1c4770b2017-07-05 13:25:21 +0400219
220 // Check the rabbitmq status
Jakub Josef61463c72018-02-13 16:10:56 +0100221 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300222 salt.cmdRun(master, "I@rabbitmq:server ${extra_tgt}", 'rabbitmqctl cluster_status')
Jakub Josef61463c72018-02-13 16:10:56 +0100223 }
vrovachev1c4770b2017-07-05 13:25:21 +0400224 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200225
Jakub Josef79ecec32017-02-17 14:36:28 +0100226 // Install haproxy
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300227 if (salt.testTarget(master, "I@haproxy:proxy ${extra_tgt}")) {
228 salt.enforceState(master, "I@haproxy:proxy ${extra_tgt}", 'haproxy')
229 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.status', ['haproxy'])
230 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.restart', ['rsyslog'])
vrovachev1c4770b2017-07-05 13:25:21 +0400231 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200232
Jakub Josef79ecec32017-02-17 14:36:28 +0100233 // Install memcached
Martin Polreich675dc942018-08-15 09:37:32 +0200234 salt.enforceStateWithTest(master, "I@memcached:server ${extra_tgt}", 'memcached')
vrovachev1c4770b2017-07-05 13:25:21 +0400235
236 // Install etcd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300237 if (salt.testTarget(master, "I@etcd:server ${extra_tgt}")) {
238 salt.enforceState(master, "I@etcd:server ${extra_tgt}", 'etcd.server.service')
Jakub Josef61463c72018-02-13 16:10:56 +0100239 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300240 salt.cmdRun(master, "I@etcd:server ${extra_tgt}", '. /var/lib/etcd/configenv && etcdctl cluster-health')
Jakub Josef61463c72018-02-13 16:10:56 +0100241 }
vrovachev1c4770b2017-07-05 13:25:21 +0400242 }
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200243
244 // Install redis
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300245 if (salt.testTarget(master, "I@redis:server ${extra_tgt}")) {
Martin Polreich675dc942018-08-15 09:37:32 +0200246 salt.enforceStateWithTest(master, "I@redis:cluster:role:master ${extra_tgt}", 'redis')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300247 salt.enforceState(master, "I@redis:server ${extra_tgt}", 'redis')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200248 }
Mykyta Karpin0a3dc8b2018-09-05 10:09:18 +0300249
250 // Install DNS services
251 if (salt.testTarget(master, "I@bind:server ${extra_tgt}")) {
252 salt.enforceState(master, "I@bind:server ${extra_tgt}", 'bind.server')
253 }
254 if (salt.testTarget(master, "I@powerdns:server ${extra_tgt}")) {
255 salt.enforceState(master, "I@powerdns:server ${extra_tgt}", 'powerdns.server')
256 }
257
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300258 installBackup(master, 'common', extra_tgt)
vrovachev1c4770b2017-07-05 13:25:21 +0400259}
260
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300261def installOpenstackInfra(master, extra_tgt = '') {
Jakub Josef432e9d92018-02-06 18:28:37 +0100262 def common = new com.mirantis.mk.Common()
263 common.warningMsg("You calling orchestrate.installOpenstackInfra(). This function is deprecated please use orchestrate.installInfra() directly")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300264 installInfra(master, extra_tgt)
Jakub Josef79ecec32017-02-17 14:36:28 +0100265}
266
267
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300268def installOpenstackControl(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100269 def salt = new com.mirantis.mk.Salt()
Jakub Josef61463c72018-02-13 16:10:56 +0100270 def common = new com.mirantis.mk.Common()
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400271 def first_target
Ales Komarekef2bab62017-04-26 11:48:28 +0200272
273 // Install horizon dashboard
Martin Polreich675dc942018-08-15 09:37:32 +0200274 salt.enforceStateWithTest(master, "I@horizon:server ${extra_tgt}", 'horizon')
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100275 // Install sphinx server
Martin Polreich675dc942018-08-15 09:37:32 +0200276 salt.enforceStateWithTest(master, "I@sphinx:server ${extra_tgt}", 'sphinx')
277 salt.enforceStateWithTest(master, "I@nginx:server ${extra_tgt}", 'salt.minion')
278 salt.enforceStateWithTest(master, "I@nginx:server ${extra_tgt}", 'nginx')
Ales Komarekef2bab62017-04-26 11:48:28 +0200279
Jakub Josef79ecec32017-02-17 14:36:28 +0100280 // setup keystone service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300281 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400282 salt.enforceState(master, "I@keystone:server:role:primary ${extra_tgt}", 'keystone.server')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300283 salt.enforceState(master, "I@keystone:server ${extra_tgt}", 'keystone.server')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300284 // populate keystone services/tenants/roles/users
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100285
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300286 // keystone:client must be called locally
287 //salt.runSaltProcessStep(master, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300288 salt.runSaltProcessStep(master, "I@keystone:server ${extra_tgt}", 'service.restart', ['apache2'])
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300289 sleep(30)
290 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300291 if (salt.testTarget(master, "I@keystone:client ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400292 first_target = salt.getFirstMinion(master, "I@keystone:client ${extra_tgt}")
293 salt.enforceState(master, "${first_target} ${extra_tgt}", 'keystone.client')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300294 salt.enforceState(master, "I@keystone:client ${extra_tgt}", 'keystone.client')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300295 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300296 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Jakub Josef61463c72018-02-13 16:10:56 +0100297 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300298 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack service list')
Jakub Josef61463c72018-02-13 16:10:56 +0100299 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300300 }
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100301
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300302 // Install glance
Martin Polreich675dc942018-08-15 09:37:32 +0200303 salt.enforceStateWithTest(master, "I@glance:server:role:primary ${extra_tgt}", 'glance.server', "I@glance:server ${extra_tgt}")
304 salt.enforceStateWithTest(master, "I@glance:server ${extra_tgt}", 'glance.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200305
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300306 // Check glance service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300307 if (salt.testTarget(master, "I@glance:server ${extra_tgt}")) {
Jakub Josef61463c72018-02-13 16:10:56 +0100308 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300309 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; glance image-list')
Jakub Josef61463c72018-02-13 16:10:56 +0100310 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300311 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200312
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400313 // Create glance resources
Martin Polreich675dc942018-08-15 09:37:32 +0200314 salt.enforceStateWithTest(master, "I@glance:client ${extra_tgt}", 'glance.client')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400315
Jakub Josef79ecec32017-02-17 14:36:28 +0100316 // Install and check nova service
Martin Polreich675dc942018-08-15 09:37:32 +0200317 // run on first node first
318 salt.enforceStateWithTest(master, "I@nova:controller:role:primary ${extra_tgt}", 'nova.controller', "I@nova:controller ${extra_tgt}")
319 salt.enforceStateWithTest(master, "I@nova:controller ${extra_tgt}", 'nova.controller')
320 if (salt.testTarget(master, "I@keystone:server and I@nova:controller ${extra_tgt}")) {
321 common.retry(3,5){
322 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; nova service-list')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300323 }
324 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200325
Martin Polreich675dc942018-08-15 09:37:32 +0200326
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400327 // Create nova resources
Martin Polreich675dc942018-08-15 09:37:32 +0200328 salt.enforceStateWithTest(master, "I@nova:client ${extra_tgt}", 'nova.client')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400329
Jakub Josef79ecec32017-02-17 14:36:28 +0100330 // Install and check cinder service
Martin Polreich675dc942018-08-15 09:37:32 +0200331 // run on first node first
332 salt.enforceStateWithTest(master, "I@cinder:controller:role:primary ${extra_tgt}", 'cinder', "I@cinder:controller ${extra_tgt}")
333 salt.enforceStateWithTest(master, "I@cinder:controller ${extra_tgt}", 'cinder')
334 if (salt.testTarget(master, "I@keystone:server and I@cinder:controller ${extra_tgt}")) {
335 common.retry(3,5){
336 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; cinder list')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300337 }
338 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200339
Jakub Josef79ecec32017-02-17 14:36:28 +0100340 // Install neutron service
Martin Polreich675dc942018-08-15 09:37:32 +0200341 // run on first node first
342 salt.enforceStateWithTest(master, "I@neutron:server:role:primary ${extra_tgt}", 'neutron.server', "I@neutron:server ${extra_tgt}")
343 salt.enforceStateWithTest(master, "I@neutron:server ${extra_tgt}", 'neutron.server')
344 if (salt.testTarget(master, "I@keystone:server and I@neutron:server ${extra_tgt}")) {
345 common.retry(3,5){
346 salt.cmdRun(master, "I@keystone:server ${extra_tgt}",'. /root/keystonercv3; neutron agent-list')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300347 }
348 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200349
Jakub Josef79ecec32017-02-17 14:36:28 +0100350 // Install heat service
Martin Polreich675dc942018-08-15 09:37:32 +0200351 salt.enforceStateWithTest(master, "I@heat:server:role:primary ${extra_tgt}", 'heat', "I@heat:server ${extra_tgt}")
352 salt.enforceStateWithTest(master, "I@heat:server ${extra_tgt}", 'heat')
353 if (salt.testTarget(master, "I@keystone:server and I@heat:server ${extra_tgt}")) {
354 common.retry(3,5){
355 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack orchestration resource type list')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300356 }
357 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200358
359 // Restart nova api
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300360 if (salt.testTarget(master, "I@nova:controller ${extra_tgt}")) {
361 salt.runSaltProcessStep(master, "I@nova:controller ${extra_tgt}", 'service.restart', ['nova-api'])
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300362 }
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300363
364 // Install ironic service
Martin Polreich675dc942018-08-15 09:37:32 +0200365 salt.enforceStateWithTest(master, "I@ironic:api:role:primary ${extra_tgt}", 'ironic.api', "I@ironic:api ${extra_tgt}")
366 salt.enforceStateWithTest(master, "I@ironic:api ${extra_tgt}", 'ironic.api')
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300367
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200368 // Install manila service
Martin Polreich675dc942018-08-15 09:37:32 +0200369 salt.enforceStateWithTest(master, "I@manila:api:role:primary ${extra_tgt}", 'manila.api', "I@manila:api ${extra_tgt}")
370 salt.enforceStateWithTest(master, "I@manila:api ${extra_tgt}", 'manila.api')
371 salt.enforceStateWithTest(master, "I@manila:scheduler ${extra_tgt}", 'manila.scheduler')
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200372
Oleh Hryhorova070fd02018-03-15 14:47:52 +0200373 // Install designate services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300374 if (salt.testTarget(master, "I@designate:server:enabled ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400375 salt.enforceState(master, "I@designate:server:role:primary ${extra_tgt}", 'designate.server')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300376 salt.enforceState(master, "I@designate:server ${extra_tgt}", 'designate')
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300377 }
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400378
379 // Install octavia api service
Martin Polreich675dc942018-08-15 09:37:32 +0200380 salt.enforceStateWithTest(master, "I@octavia:api:role:primary ${extra_tgt}", 'octavia.api', "I@octavia:api ${extra_tgt}")
381 salt.enforceStateWithTest(master, "I@octavia:api ${extra_tgt}", 'octavia.api')
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200382
Oleg Iurchenkod0898c92017-12-14 14:28:44 +0200383 // Install DogTag server service
Martin Polreich675dc942018-08-15 09:37:32 +0200384 salt.enforceStateWithTest(master, "I@dogtag:server:role:master ${extra_tgt}", 'dogtag.server', "I@dogtag:server ${extra_tgt}")
385 salt.enforceStateWithTest(master, "I@dogtag:server ${extra_tgt}", 'dogtag.server')
Oleg Iurchenkod0898c92017-12-14 14:28:44 +0200386
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200387 // Install barbican server service
Martin Polreich675dc942018-08-15 09:37:32 +0200388 salt.enforceStateWithTest(master, "I@barbican:server:role:primary ${extra_tgt}", 'barbican.server', "I@barbican:server ${extra_tgt}")
389 salt.enforceStateWithTest(master, "I@barbican:server ${extra_tgt}", 'barbican.server')
390
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200391 // Install barbican client
Martin Polreich675dc942018-08-15 09:37:32 +0200392 salt.enforceStateWithTest(master, "I@barbican:client ${extra_tgt}", 'barbican.client')
Ondrej Smola5908ae62018-01-08 13:42:08 +0100393
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200394 // Install gnocchi server
Martin Polreich675dc942018-08-15 09:37:32 +0200395 salt.enforceStateWithTest(master, "I@gnocchi:server:role:primary ${extra_tgt}", 'gnocchi.server', "I@gnocchi:server ${extra_tgt}")
396 salt.enforceStateWithTest(master, "I@gnocchi:server ${extra_tgt}", 'gnocchi.server')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200397
Mykyta Karpin4816e522018-06-15 16:00:03 +0300398 // Apply gnocchi client state to create gnocchi archive policies, due to possible
399 // races, apply on the first node initially
400 if (salt.testTarget(master, "I@gnocchi:client ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400401 first_target = salt.getFirstMinion(master, "I@gnocchi:client ${extra_tgt}")
402 salt.enforceState(master, "${first_target} ${extra_tgt}", 'gnocchi.client')
Mykyta Karpin4816e522018-06-15 16:00:03 +0300403 salt.enforceState(master, "I@gnocchi:client ${extra_tgt}", 'gnocchi.client')
404 }
405
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200406 // Install gnocchi statsd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300407 if (salt.testTarget(master, "I@gnocchi:statsd ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400408 first_target = salt.getFirstMinion(master, "I@gnocchi:statsd ${extra_tgt}")
409 salt.enforceState(master, "${first_target} ${extra_tgt}", 'gnocchi.statsd')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300410 salt.enforceState(master, "I@gnocchi:statsd ${extra_tgt}", 'gnocchi.statsd')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200411 }
412
413 // Install panko server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300414 if (salt.testTarget(master, "I@panko:server ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400415 first_target = salt.getFirstMinion(master, "I@panko:server ${extra_tgt}")
416 salt.enforceState(master, "${first_target} ${extra_tgt}", 'panko')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300417 salt.enforceState(master, "I@panko:server ${extra_tgt}", 'panko')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200418 }
419
Ondrej Smola5908ae62018-01-08 13:42:08 +0100420 // Install ceilometer server
Martin Polreich675dc942018-08-15 09:37:32 +0200421 salt.enforceStateWithTest(master, "I@ceilometer:server:role:primary ${extra_tgt}", 'ceilometer', "I@ceilometer:server ${extra_tgt}")
422 salt.enforceStateWithTest(master, "I@ceilometer:server ${extra_tgt}", 'ceilometer')
Ondrej Smola5908ae62018-01-08 13:42:08 +0100423
424 // Install aodh server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300425 if (salt.testTarget(master, "I@aodh:server ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400426 first_target = salt.getFirstMinion(master, "I@aodh:server ${extra_tgt}")
427 salt.enforceState(master, "${first_target} ${extra_tgt}", 'aodh')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300428 salt.enforceState(master, "I@aodh:server ${extra_tgt}", 'aodh')
Ondrej Smola5908ae62018-01-08 13:42:08 +0100429 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100430}
431
432
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300433def installIronicConductor(master, extra_tgt = ''){
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300434 def salt = new com.mirantis.mk.Salt()
435
Martin Polreich675dc942018-08-15 09:37:32 +0200436 salt.enforceStateWithTest(master, "I@ironic:conductor ${extra_tgt}", 'ironic.conductor')
437 salt.enforceStateWithTest(master, "I@ironic:conductor ${extra_tgt}", 'apache')
438 salt.enforceStateWithTest(master, "I@tftpd_hpa:server ${extra_tgt}", 'tftpd_hpa')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300439
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300440 if (salt.testTarget(master, "I@nova:compute ${extra_tgt}")) {
441 salt.runSaltProcessStep(master, "I@nova:compute ${extra_tgt}", 'service.restart', ['nova-compute'])
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300442 }
443
Martin Polreich675dc942018-08-15 09:37:32 +0200444 salt.enforceStateWithTest(master, "I@baremetal_simulator:enabled ${extra_tgt}", 'baremetal_simulator')
445 salt.enforceStateWithTest(master, "I@ironic:client ${extra_tgt}", 'ironic.client')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300446}
447
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300448def installManilaShare(master, extra_tgt = ''){
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200449 def salt = new com.mirantis.mk.Salt()
450
Martin Polreich675dc942018-08-15 09:37:32 +0200451 salt.enforceStateWithTest(master, "I@manila:share ${extra_tgt}", 'manila.share')
452 salt.enforceStateWithTest(master, "I@manila:data ${extra_tgt}", 'manila.data')
453 salt.enforceStateWithTest(master, "I@manila:client ${extra_tgt}", 'manila.client')
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200454}
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300455
456
Oleh Hryhorov37fbd0c2018-07-11 16:58:54 +0300457def installOpenstackNetwork(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100458 def salt = new com.mirantis.mk.Salt()
Ann Taradayea9848c2018-10-25 11:15:58 +0400459 def common = new com.mirantis.mk.Common()
Oleksii Grudevc4a485e2018-04-20 14:25:03 +0300460 //run full neutron state on neutron.gateway - this will install
461 //neutron agents in addition to neutron server. Once neutron agents
462 //are up neutron resources can be created without hitting the situation when neutron resources are created
463 //prior to neutron agents which results in creating ports in non-usable state
Martin Polreich675dc942018-08-15 09:37:32 +0200464 salt.enforceStateWithTest(master, "I@neutron:gateway ${extra_tgt}", 'neutron')
Oleksii Grudevc4a485e2018-04-20 14:25:03 +0300465
466 // Create neutron resources - this step was moved here to ensure that
467 //neutron resources are created after neutron agens are up. In this case neutron ports will be in
468 //usable state. More information: https://bugs.launchpad.net/neutron/+bug/1399249
Martin Polreich675dc942018-08-15 09:37:32 +0200469 salt.enforceStateWithTest(master, "I@neutron:client ${extra_tgt}", 'neutron.client')
Ales Komarekef2bab62017-04-26 11:48:28 +0200470
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300471 salt.enforceHighstate(master, "I@neutron:gateway ${extra_tgt}")
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400472
473 // install octavia manager services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300474 if (salt.testTarget(master, "I@octavia:manager ${extra_tgt}")) {
Anna Taraday82224102018-10-09 07:44:24 +0000475 salt.runSaltProcessStep(master, "I@neutron:client ${extra_tgt}", 'mine.update')
Anastasia Kuznetsova3c9fcf12018-08-22 15:10:05 +0400476 salt.enforceState(master, "I@octavia:manager ${extra_tgt}", 'octavia.manager')
Oleksii Grudev82808b22018-10-26 15:25:19 +0300477 common.retry(2) {
Ann Taradayea9848c2018-10-25 11:15:58 +0400478 salt.enforceState(master, "I@octavia:manager ${extra_tgt}", 'salt.minion.ca')
479 }
Oleksii Grudev82808b22018-10-26 15:25:19 +0300480 common.retry(2) {
Ann Taradayea9848c2018-10-25 11:15:58 +0400481 salt.enforceState(master, "I@octavia:manager ${extra_tgt}", 'salt.minion.cert')
482 }
Anna Taraday82224102018-10-09 07:44:24 +0000483 salt.enforceState(master, "I@octavia:client ${extra_tgt}", 'octavia.client')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400484 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200485}
486
487
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300488def installOpenstackCompute(master, extra_tgt = '') {
Ales Komarekef2bab62017-04-26 11:48:28 +0200489 def salt = new com.mirantis.mk.Salt()
Mykyta Karpin3ec78a22018-07-10 12:27:09 +0300490 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200491 // Configure compute nodes
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300492 def compute_compound = "I@nova:compute ${extra_tgt}"
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100493 if (salt.testTarget(master, compute_compound)) {
494 // In case if infrastructure nodes are used as nova computes too
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300495 def gluster_compound = "I@glusterfs:server ${extra_tgt}"
496 def salt_ca_compound = "I@salt:minion:ca:salt_master_ca ${extra_tgt}"
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200497 // Enforce highstate asynchronous only on compute nodes which are not glusterfs and not salt ca servers
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300498 def hightstateTarget = "${compute_compound} and not ${gluster_compound} and not ${salt_ca_compound}"
Oleh Hryhorov73f9fa22018-05-02 17:36:58 +0300499 if (salt.testTarget(master, hightstateTarget)) {
500 retry(2) {
Vasyl Saienko29b59b62018-09-14 18:45:45 +0300501 salt.enforceHighstate(master, hightstateTarget)
Oleh Hryhorov73f9fa22018-05-02 17:36:58 +0300502 }
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300503 } else {
504 common.infoMsg("No minions matching highstate target found for target ${hightstateTarget}")
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200505 }
506 // Iterate through salt ca servers and check if they have compute role
507 // TODO: switch to batch once salt 2017.7+ would be used
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300508 common.infoMsg("Checking whether ${salt_ca_compound} minions have ${compute_compound} compound")
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200509 for ( target in salt.getMinionsSorted(master, salt_ca_compound) ) {
510 for ( cmp_target in salt.getMinionsSorted(master, compute_compound) ) {
511 if ( target == cmp_target ) {
512 // Enforce highstate one by one on salt ca servers which are compute nodes
513 retry(2) {
Vasyl Saienko29b59b62018-09-14 18:45:45 +0300514 salt.enforceHighstate(master, target)
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200515 }
516 }
517 }
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100518 }
519 // Iterate through glusterfs servers and check if they have compute role
520 // TODO: switch to batch once salt 2017.7+ would be used
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300521 common.infoMsg("Checking whether ${gluster_compound} minions have ${compute_compound} compound")
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100522 for ( target in salt.getMinionsSorted(master, gluster_compound) ) {
523 for ( cmp_target in salt.getMinionsSorted(master, compute_compound) ) {
524 if ( target == cmp_target ) {
525 // Enforce highstate one by one on glusterfs servers which are compute nodes
526 retry(2) {
Vasyl Saienko29b59b62018-09-14 18:45:45 +0300527 salt.enforceHighstate(master, target)
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100528 }
529 }
530 }
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200531 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200532 }
Vasyl Saienko51144e42018-06-19 09:30:30 +0300533
534 // Run nova:controller to map cmp with cells
Martin Polreich675dc942018-08-15 09:37:32 +0200535 salt.enforceState(master, "I@nova:controller:role:primary ${extra_tgt}", 'nova.controller', "I@nova:controller ${extra_tgt}")
Ales Komarekef2bab62017-04-26 11:48:28 +0200536}
537
538
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300539def installContrailNetwork(master, extra_tgt = '') {
Martin Polreichfc9854c2017-06-30 11:17:36 +0200540 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200541 def salt = new com.mirantis.mk.Salt()
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400542 def first_target
Ales Komarekef2bab62017-04-26 11:48:28 +0200543
Jakub Josef79ecec32017-02-17 14:36:28 +0100544 // Install opencontrail database services
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400545 first_target = salt.getFirstMinion(master, "I@opencontrail:database ${extra_tgt}")
546 salt.enforceState(master, "${first_target} ${extra_tgt}", 'opencontrail.database')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300547 salt.enforceState(master, "I@opencontrail:database ${extra_tgt}", 'opencontrail.database')
Ales Komarekef2bab62017-04-26 11:48:28 +0200548
Jakub Josef79ecec32017-02-17 14:36:28 +0100549 // Install opencontrail control services
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400550 first_target = salt.getFirstMinion(master, "I@opencontrail:control ${extra_tgt}")
551 salt.enforceStateWithExclude(master, "${first_target} ${extra_tgt}", "opencontrail", "opencontrail.client")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300552 salt.enforceStateWithExclude(master, "I@opencontrail:control ${extra_tgt}", "opencontrail", "opencontrail.client")
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400553 first_target = salt.getFirstMinion(master, "I@opencontrail:collector ${extra_tgt}")
554 salt.enforceStateWithExclude(master, "${first_target} ${extra_tgt}", "opencontrail", "opencontrail.client")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300555 salt.enforceStateWithExclude(master, "I@opencontrail:collector ${extra_tgt}", "opencontrail", "opencontrail.client")
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100556
Martin Polreich675dc942018-08-15 09:37:32 +0200557 salt.enforceStateWithTest(master, "( I@opencontrail:control or I@opencontrail:collector ) ${extra_tgt}", 'docker.client', "I@docker:client and I@opencontrail:control ${extra_tgt}")
Inessa Vasilevskaya85ad1a92018-10-08 12:19:47 +0200558 // NOTE(ivasilevskaya) call to installBackup here has been removed as it breaks deployment if done before computes are deployed
Jakub Josef79ecec32017-02-17 14:36:28 +0100559}
560
561
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300562def installContrailCompute(master, extra_tgt = '') {
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200563 def salt = new com.mirantis.mk.Salt()
vrovachev32f7f542017-08-25 16:17:25 +0400564 def common = new com.mirantis.mk.Common()
Jakub Josef79ecec32017-02-17 14:36:28 +0100565 // Configure compute nodes
Ales Komarekef2bab62017-04-26 11:48:28 +0200566 // Provision opencontrail control services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300567 salt.enforceState(master, "I@opencontrail:database:id:1 ${extra_tgt}", 'opencontrail.client')
Jakub Josef79ecec32017-02-17 14:36:28 +0100568 // Provision opencontrail virtual routers
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100569
vrovachev4ff77302017-08-09 20:39:57 +0400570 // Generate script /usr/lib/contrail/if-vhost0 for up vhost0
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300571 if (salt.testTarget(master, "I@opencontrail:compute ${extra_tgt}")) {
572 salt.enforceStateWithExclude(master, "I@opencontrail:compute ${extra_tgt}", "opencontrail", "opencontrail.client")
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200573 }
vrovachev4ff77302017-08-09 20:39:57 +0400574
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300575 if (salt.testTarget(master, "I@nova:compute ${extra_tgt}")) {
576 salt.cmdRun(master, "I@nova:compute ${extra_tgt}", 'exec 0>&-; exec 1>&-; exec 2>&-; nohup bash -c "ip link | grep vhost && echo no_reboot || sleep 5 && reboot & "', false)
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200577 }
vrovachev4ff77302017-08-09 20:39:57 +0400578
Jakub Josef61463c72018-02-13 16:10:56 +0100579 sleep(300)
Martin Polreich675dc942018-08-15 09:37:32 +0200580 salt.enforceStateWithTest(master, "I@opencontrail:compute ${extra_tgt}", 'opencontrail.client')
581 salt.enforceStateWithTest(master, "I@opencontrail:compute ${extra_tgt}", 'opencontrail')
Jakub Josef79ecec32017-02-17 14:36:28 +0100582}
583
584
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300585def installKubernetesInfra(master, extra_tgt = '') {
Jakub Josef432e9d92018-02-06 18:28:37 +0100586 def common = new com.mirantis.mk.Common()
587 common.warningMsg("You calling orchestrate.installKubernetesInfra(). This function is deprecated please use orchestrate.installInfra() directly")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300588 installInfra(master, extra_tgt)
Jakub Josef79ecec32017-02-17 14:36:28 +0100589}
590
591
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300592def installKubernetesControl(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100593 def salt = new com.mirantis.mk.Salt()
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400594 def first_target
Victor Ryzhenkineb617412018-08-20 18:54:23 +0400595 salt.fullRefresh(master, "* ${extra_tgt}")
596
597 // Bootstrap all nodes
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400598 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", 'linux')
599 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", 'salt.minion')
600 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", ['openssh', 'ntp'])
Victor Ryzhenkineb617412018-08-20 18:54:23 +0400601
602 // Create and distribute SSL certificates for services using salt state
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400603 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", 'salt.minion.cert')
Victor Ryzhenkineb617412018-08-20 18:54:23 +0400604
605 // Install docker
606 salt.enforceState(master, "I@docker:host ${extra_tgt}", 'docker.host')
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200607
Svimba470b3312018-09-26 11:27:20 +0200608 // If network engine is not opencontrail, run addons state for kubernetes
609 if (!salt.getPillar(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes:master:network:opencontrail:enabled')) {
610 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes.master.kube-addons')
611 }
612
Jakub Josef79ecec32017-02-17 14:36:28 +0100613 // Install Kubernetes pool and Calico
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400614 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes.pool')
Jakub Josef79ecec32017-02-17 14:36:28 +0100615
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300616 if (salt.testTarget(master, "I@etcd:server:setup ${extra_tgt}")) {
Marek Celoud029391c2017-11-14 10:06:18 +0100617 // Setup etcd server
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400618 first_target = salt.getFirstMinion(master, "I@kubernetes:master ${extra_tgt}")
619 salt.enforceState(master, "${first_target} ${extra_tgt}", 'etcd.server.setup')
Marek Celoud029391c2017-11-14 10:06:18 +0100620 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100621
Victor Ryzhenkinfb5d1b52018-05-22 18:49:26 +0400622 // Run k8s master at *01* to simplify namespaces creation
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400623 first_target = salt.getFirstMinion(master, "I@kubernetes:master ${extra_tgt}")
Victor Ryzhenkinfb5d1b52018-05-22 18:49:26 +0400624
Svimba470b3312018-09-26 11:27:20 +0200625 // If network engine is opencontrail, run master state for kubernetes without kube-addons
626 // The kube-addons state will be called later only in case of opencontrail
627 if (salt.getPillar(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes:master:network:opencontrail:enabled')) {
628 // Run k8s on first node without master.setup and master.kube-addons
629 salt.enforceStateWithExclude(master, "${first_target} ${extra_tgt}", "kubernetes.master", "kubernetes.master.setup,kubernetes.master.kube-addons")
630 // Run k8s without master.setup and master.kube-addons
631 salt.enforceStateWithExclude(master, "I@kubernetes:master ${extra_tgt}", "kubernetes", "kubernetes.master.setup,kubernetes.master.kube-addons")
632 } else {
633 // Run k8s on first node without master.setup and master.kube-addons
634 salt.enforceStateWithExclude(master, "${first_target} ${extra_tgt}", "kubernetes.master", "kubernetes.master.setup")
635 // Run k8s without master.setup
636 salt.enforceStateWithExclude(master, "I@kubernetes:master ${extra_tgt}", "kubernetes", "kubernetes.master.setup")
637 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100638
639 // Run k8s master setup
Victor Ryzhenkin7655fa42018-10-02 20:52:08 +0400640 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes.master.setup')
Jakub Josef79ecec32017-02-17 14:36:28 +0100641
642 // Restart kubelet
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400643 salt.runSaltProcessStep(master, "I@kubernetes:master ${extra_tgt}", 'service.restart', ['kubelet'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100644}
645
646
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300647def installKubernetesCompute(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200648 def salt = new com.mirantis.mk.Salt()
Jakub Josef432e9d92018-02-06 18:28:37 +0100649 salt.fullRefresh(master, "*")
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200650
651 // Bootstrap all nodes
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400652 salt.enforceState(master, "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", 'linux')
653 salt.enforceState(master, "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", 'salt.minion')
654 salt.enforceState(master, "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", ['openssh', 'ntp'])
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200655
656 // Create and distribute SSL certificates for services using salt state
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400657 salt.enforceState(master, "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", 'salt.minion.cert')
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200658
659 // Install docker
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300660 salt.enforceState(master, "I@docker:host ${extra_tgt}", 'docker.host')
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200661
662 // Install Kubernetes and Calico
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400663 salt.enforceState(master, "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", 'kubernetes.pool')
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200664
Yuriy Taradayab564d72017-10-11 15:14:35 +0400665 // Install Tiller and all configured releases
Martin Polreich675dc942018-08-15 09:37:32 +0200666 salt.enforceStateWithTest(master, "I@helm:client ${extra_tgt}", 'helm')
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400667 salt.runSaltProcessStep(master, "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", 'service.restart', ['kubelet'])
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200668}
669
670
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300671def installDockerSwarm(master, extra_tgt = '') {
Martin Polreich8663a342017-06-30 17:33:08 +0200672 def salt = new com.mirantis.mk.Salt()
Jakub Josef79ecec32017-02-17 14:36:28 +0100673
vrovachev1c4770b2017-07-05 13:25:21 +0400674 //Install and Configure Docker
Martin Polreichc0bb4fd2018-08-06 11:34:43 +0200675 if (salt.testTarget(master, "I@docker:swarm ${extra_tgt}")) {
676 salt.enforceState(master, "I@docker:swarm ${extra_tgt}", 'docker.host')
677 salt.enforceState(master, "I@docker:swarm:role:master ${extra_tgt}", 'docker.swarm')
678 salt.enforceState(master, "I@docker:swarm ${extra_tgt}", 'salt.minion.grains')
679 salt.runSaltProcessStep(master, "I@docker:swarm ${extra_tgt}", 'mine.update')
680 salt.runSaltProcessStep(master, "I@docker:swarm ${extra_tgt}", 'saltutil.refresh_modules')
681 sleep(5)
682 salt.enforceState(master, "I@docker:swarm:role:master ${extra_tgt}", 'docker.swarm')
Martin Polreich675dc942018-08-15 09:37:32 +0200683 salt.enforceStateWithTest(master, "I@docker:swarm:role:manager ${extra_tgt}", 'docker.swarm')
Martin Polreichc0bb4fd2018-08-06 11:34:43 +0200684 sleep(10)
685 salt.cmdRun(master, "I@docker:swarm:role:master ${extra_tgt}", 'docker node ls')
Machi Hoshino87aa39d2018-07-26 20:41:53 +0900686 }
Martin Polreich8663a342017-06-30 17:33:08 +0200687}
688
Svimba470b3312018-09-26 11:27:20 +0200689// Setup addons for kubernetes - For OpenContrail network engine
690// Use after compute nodes are ready, because K8s addons like DNS should be placed on cmp nodes
691def setupKubeAddonForContrail(master, extra_tgt = '') {
692 def salt = new com.mirantis.mk.Salt()
693
694 if (salt.getPillar(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes:master:network:opencontrail:enabled')){
695 // Setup Addons for Kubernetes only in case of OpenContrail is used as neteork engine
696 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes.master.kube-addons')
697 }
698}
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200699
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300700def installCicd(master, extra_tgt = '') {
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200701 def salt = new com.mirantis.mk.Salt()
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200702 def common = new com.mirantis.mk.Common()
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300703 def gerrit_compound = "I@gerrit:client and ci* ${extra_tgt}"
704 def jenkins_compound = "I@jenkins:client and ci* ${extra_tgt}"
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200705
706 salt.fullRefresh(master, gerrit_compound)
707 salt.fullRefresh(master, jenkins_compound)
Richard Felkl9d2cd922017-11-03 11:49:32 +0100708
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300709 salt.enforceState(master, "I@docker:swarm:role:master and I@jenkins:client ${extra_tgt}", 'docker.client', true, true, null, false, -1, 2)
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200710
711 // API timeout in minutes
712 def wait_timeout = 10
713
714 // Gerrit
715 def gerrit_master_url = salt.getPillar(master, gerrit_compound, '_param:gerrit_master_url')
716
717 if(!gerrit_master_url['return'].isEmpty()) {
718 gerrit_master_url = gerrit_master_url['return'][0].values()[0]
719 } else {
720 gerrit_master_url = ''
721 }
722
723 if (gerrit_master_url != '') {
724 common.infoMsg('Gerrit master url "' + gerrit_master_url + '" retrieved at _param:gerrit_master_url')
725 } else {
726
727 common.infoMsg('Gerrit master url could not be retrieved at _param:gerrit_master_url. Falling back to gerrit pillar')
728
729 def gerrit_host
730 def gerrit_http_port
731 def gerrit_http_scheme
732
733 def host_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:host')
734 gerrit_host = salt.getReturnValues(host_pillar)
735
736 def port_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:http_port')
737 gerrit_http_port = salt.getReturnValues(port_pillar)
738
739 def scheme_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:protocol')
740 gerrit_http_scheme = salt.getReturnValues(scheme_pillar)
741
742 gerrit_master_url = gerrit_http_scheme + '://' + gerrit_host + ':' + gerrit_http_port
743
744 }
745
746 timeout(wait_timeout) {
747 common.infoMsg('Waiting for Gerrit to come up..')
Dzmitry Stremkouski5440ffa2018-05-31 12:00:02 +0200748 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'
749 salt.cmdRun(master, gerrit_compound, 'timeout ' + (wait_timeout*60+3) + ' /bin/sh -c -- ' + '"' + check_gerrit_cmd + '"')
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200750 }
751
752 // Jenkins
753 def jenkins_master_url_pillar = salt.getPillar(master, jenkins_compound, '_param:jenkins_master_url')
754 jenkins_master_url = salt.getReturnValues(jenkins_master_url_pillar)
755
756 timeout(wait_timeout) {
757 common.infoMsg('Waiting for Jenkins to come up..')
Dzmitry Stremkouski5440ffa2018-05-31 12:00:02 +0200758 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'
759 salt.cmdRun(master, jenkins_compound, 'timeout ' + (wait_timeout*60+3) + ' /bin/sh -c -- ' + '"' + check_jenkins_cmd + '"')
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200760 }
Richard Felklc1aba9b2018-01-02 09:25:20 +0100761
Martin Polreich675dc942018-08-15 09:37:32 +0200762 salt.enforceStateWithTest(master, "I@openldap:client ${extra_tgt}", 'openldap', "", true, true, null, false, -1, 2)
Richard Felklb6fdec92017-09-26 10:52:36 +0200763
Martin Polreich675dc942018-08-15 09:37:32 +0200764 salt.enforceStateWithTest(master, "I@python:environment ${extra_tgt}", 'python')
Richard Felklc1aba9b2018-01-02 09:25:20 +0100765
Richard Felkl6e208fc2017-12-08 10:18:44 +0100766 withEnv(['ASK_ON_ERROR=false']){
767 retry(2){
768 try{
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300769 salt.enforceState(master, "I@gerrit:client ${extra_tgt}", 'gerrit')
Richard Felkl6e208fc2017-12-08 10:18:44 +0100770 }catch(e){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300771 salt.fullRefresh(master, "I@gerrit:client ${extra_tgt}")
Richard Felkl6e208fc2017-12-08 10:18:44 +0100772 throw e //rethrow for retry handler
773 }
774 }
775 retry(2){
776 try{
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300777 salt.enforceState(master, "I@jenkins:client ${extra_tgt}", 'jenkins')
Richard Felkl6e208fc2017-12-08 10:18:44 +0100778 }catch(e){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300779 salt.fullRefresh(master, "I@jenkins:client ${extra_tgt}")
Richard Felkl6e208fc2017-12-08 10:18:44 +0100780 throw e //rethrow for retry handler
781 }
782 }
783 }
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200784}
785
786
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300787def installStacklight(master, extra_tgt = '') {
Martin Polreich8663a342017-06-30 17:33:08 +0200788 def common = new com.mirantis.mk.Common()
789 def salt = new com.mirantis.mk.Salt()
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200790 def retries_wait = 20
791 def retries = 15
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400792 def first_target
Martin Polreich8663a342017-06-30 17:33:08 +0200793
Simon Pasquieref4122c2017-08-25 15:52:07 +0200794 // Install core services for K8S environments:
795 // HAProxy, Nginx and lusterFS clients
796 // In case of OpenStack, those are already installed
Martin Polreich792f2662017-07-11 13:36:32 +0200797 if (common.checkContains('STACK_INSTALL', 'k8s')) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300798 salt.enforceState(master, "I@haproxy:proxy ${extra_tgt}", 'haproxy')
799 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.status', ['haproxy'])
Simon Pasquieref4122c2017-08-25 15:52:07 +0200800
Martin Polreich675dc942018-08-15 09:37:32 +0200801 salt.enforceStateWithTest(master, "I@nginx:server ${extra_tgt}", 'nginx')
Simon Pasquieref4122c2017-08-25 15:52:07 +0200802
Martin Polreich675dc942018-08-15 09:37:32 +0200803 salt.enforceStateWithTest(master, "I@glusterfs:client ${extra_tgt}", 'glusterfs.client', "", true, true, null, false, -1, 2)
Martin Polreich792f2662017-07-11 13:36:32 +0200804 }
Jiri Broulike57a0242017-10-06 13:38:47 +0200805
Dmitry Kalashnik69ecb782018-05-21 17:36:50 +0400806 // Install MongoDB for Alerta
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300807 if (salt.testTarget(master, "I@mongodb:server ${extra_tgt}")) {
808 salt.enforceState(master, "I@mongodb:server ${extra_tgt}", 'mongodb.server')
Ildar Svetlov829f94a2018-06-05 17:57:08 +0400809
810 // Initialize mongodb replica set
811 common.retry(5,20){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300812 salt.enforceState(master, "I@mongodb:server ${extra_tgt}", 'mongodb.cluster')
Ildar Svetlov829f94a2018-06-05 17:57:08 +0400813 }
Dmitry Kalashnik69ecb782018-05-21 17:36:50 +0400814 }
815
Martin Polreich8663a342017-06-30 17:33:08 +0200816 //Install Telegraf
Martin Polreich44331002018-08-13 11:27:06 +0200817 salt.enforceState(master, "( I@telegraf:agent or I@telegraf:remote_agent ) ${extra_tgt}", 'telegraf')
Martin Polreich8663a342017-06-30 17:33:08 +0200818
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400819 // Install Prometheus exporters
Martin Polreich675dc942018-08-15 09:37:32 +0200820 salt.enforceStateWithTest(master, "I@prometheus:exporters ${extra_tgt}", 'prometheus')
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400821
Martin Polreich8663a342017-06-30 17:33:08 +0200822 //Install Elasticsearch and Kibana
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400823 if (salt.testTarget(master, "I@elasticsearch:server:enabled:true ${extra_tgt}")) {
824 first_target = salt.getFirstMinion(master, "I@elasticsearch:server:enabled:true ${extra_tgt}")
825 salt.enforceState(master, "${first_target} ${extra_tgt}", 'elasticsearch.server')
Ramon Meleroae6e16a2018-08-07 13:42:16 -0500826 }
Martin Polreich675dc942018-08-15 09:37:32 +0200827 salt.enforceStateWithTest(master, "I@elasticsearch:server:enabled:true ${extra_tgt}", 'elasticsearch.server')
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400828 if (salt.testTarget(master, "I@kibana:server:enabled:true ${extra_tgt}")) {
829 first_target = salt.getFirstMinion(master, "I@kibana:server:enabled:true ${extra_tgt}")
830 salt.enforceState(master, "${first_target} ${extra_tgt}", 'kibana.server')
Ramon Meleroae6e16a2018-08-07 13:42:16 -0500831 }
Martin Polreich675dc942018-08-15 09:37:32 +0200832 salt.enforceStateWithTest(master, "I@kibana:server:enabled:true ${extra_tgt}", 'kibana.server')
833
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200834 // Check ES health cluster status
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300835 def pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:host')
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200836 def elasticsearch_vip
837 if(!pillar['return'].isEmpty()) {
838 elasticsearch_vip = pillar['return'][0].values()[0]
839 } else {
840 common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved')
841 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300842 pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:port')
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200843 def elasticsearch_port
844 if(!pillar['return'].isEmpty()) {
845 elasticsearch_port = pillar['return'][0].values()[0]
846 } else {
847 common.errorMsg('[ERROR] Elasticsearch VIP port could not be retrieved')
848 }
849 common.retry(retries,retries_wait) {
850 common.infoMsg('Waiting for Elasticsearch to become green..')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300851 salt.cmdRun(master, "I@elasticsearch:client ${extra_tgt}", "curl -sf ${elasticsearch_vip}:${elasticsearch_port}/_cat/health | awk '{print \$4}' | grep green")
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200852 }
853
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200854 common.retry(retries,retries_wait) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300855 salt.enforceState(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch.client')
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200856 }
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200857
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200858 common.retry(retries,retries_wait) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300859 salt.enforceState(master, "I@kibana:client ${extra_tgt}", 'kibana.client')
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200860 }
Dmitry Kalashnik53feda72018-03-16 16:06:10 +0400861
862 //Install InfluxDB
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300863 if (salt.testTarget(master, "I@influxdb:server ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400864 first_target = salt.getFirstMinion(master, "I@influxdb:server ${extra_tgt}")
865 salt.enforceState(master, "${first_target} ${extra_tgt}", 'influxdb')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300866 salt.enforceState(master, "I@influxdb:server ${extra_tgt}", 'influxdb')
Dmitry Kalashnik53feda72018-03-16 16:06:10 +0400867 }
868
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400869 // Install service for the log collection
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300870 if (salt.testTarget(master, "I@fluentd:agent ${extra_tgt}")) {
871 salt.enforceState(master, "I@fluentd:agent ${extra_tgt}", 'fluentd')
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400872 } else {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300873 salt.enforceState(master, "I@heka:log_collector ${extra_tgt}", 'heka.log_collector')
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400874 }
Simon Pasquier6301ddd2017-09-05 11:56:58 +0200875
Ondrej Smola5908ae62018-01-08 13:42:08 +0100876 // Install heka ceilometer collector
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300877 if (salt.testTarget(master, "I@heka:ceilometer_collector:enabled ${extra_tgt}")) {
878 salt.enforceState(master, "I@heka:ceilometer_collector:enabled ${extra_tgt}", 'heka.ceilometer_collector')
879 salt.runSaltProcessStep(master, "I@heka:ceilometer_collector:enabled ${extra_tgt}", 'service.restart', ['ceilometer_collector'], null, true)
Ondrej Smola5908ae62018-01-08 13:42:08 +0100880 }
881
Martin Polreich470925a2017-07-06 17:12:59 +0200882 // Install galera
Martin Polreich792f2662017-07-11 13:36:32 +0200883 if (common.checkContains('STACK_INSTALL', 'k8s')) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300884 salt.enforceState(master, "I@galera:master ${extra_tgt}", 'galera', true, true, null, false, -1, 2)
885 salt.enforceState(master, "I@galera:slave ${extra_tgt}", 'galera', true, true, null, false, -1, 2)
Martin Polreich406f6462017-07-11 11:33:42 +0000886
Martin Polreich792f2662017-07-11 13:36:32 +0200887 // Check galera status
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300888 salt.runSaltProcessStep(master, "I@galera:master ${extra_tgt}", 'mysql.status')
889 salt.runSaltProcessStep(master, "I@galera:slave ${extra_tgt}", 'mysql.status')
Martin Polreich792f2662017-07-11 13:36:32 +0200890 }
Martin Polreich470925a2017-07-06 17:12:59 +0200891
Martin Polreich8663a342017-06-30 17:33:08 +0200892 //Collect Grains
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300893 salt.enforceState(master, "I@salt:minion ${extra_tgt}", 'salt.minion.grains')
894 salt.runSaltProcessStep(master, "I@salt:minion ${extra_tgt}", 'saltutil.refresh_modules')
895 salt.runSaltProcessStep(master, "I@salt:minion ${extra_tgt}", 'mine.update')
Martin Polreich8663a342017-06-30 17:33:08 +0200896 sleep(5)
897
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400898 // Configure Prometheus in Docker Swarm
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300899 salt.enforceState(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}", 'prometheus')
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400900
Ildar Svetlov0eec97d2018-02-15 10:06:40 +0400901 //Configure Remote Collector in Docker Swarm for Openstack deployments
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400902 if (!common.checkContains('STACK_INSTALL', 'k8s')) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300903 salt.enforceState(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}", 'heka.remote_collector', true, false)
Martin Polreich8017f452017-08-21 16:01:42 +0200904 }
Martin Polreich8663a342017-06-30 17:33:08 +0200905
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400906 // Launch containers
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300907 salt.enforceState(master, "I@docker:swarm:role:master and I@prometheus:server ${extra_tgt}", 'docker.client')
908 salt.runSaltProcessStep(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}", 'dockerng.ps')
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400909
910 //Install Prometheus LTS
Martin Polreich675dc942018-08-15 09:37:32 +0200911 salt.enforceStateWithTest(master, "I@prometheus:relay ${extra_tgt}", 'prometheus')
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400912
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100913 // Install sphinx server
Martin Polreich675dc942018-08-15 09:37:32 +0200914 salt.enforceStateWithTest(master, "I@sphinx:server ${extra_tgt}", 'sphinx')
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100915
Martin Polreich8663a342017-06-30 17:33:08 +0200916 //Configure Grafana
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300917 pillar = salt.getPillar(master, "ctl01* ${extra_tgt}", '_param:stacklight_monitor_address')
Martin Polreich8663a342017-06-30 17:33:08 +0200918 common.prettyPrint(pillar)
Martin Polreich595baef2017-07-04 16:11:04 +0200919
Martin Polreich8663a342017-06-30 17:33:08 +0200920 def stacklight_vip
921 if(!pillar['return'].isEmpty()) {
922 stacklight_vip = pillar['return'][0].values()[0]
923 } else {
924 common.errorMsg('[ERROR] Stacklight VIP address could not be retrieved')
925 }
vrovachev1c4770b2017-07-05 13:25:21 +0400926
Martin Polreich305e2222017-07-06 11:33:00 +0200927 common.infoMsg("Waiting for service on http://${stacklight_vip}:15013/ to start")
Martin Polreichbd7ad222017-07-06 12:53:51 +0200928 sleep(120)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300929 salt.enforceState(master, "I@grafana:client ${extra_tgt}", 'grafana.client')
Martin Polreich8663a342017-06-30 17:33:08 +0200930}
931
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300932def installStacklightv1Control(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200933 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200934
935 // infra install
936 // Install the StackLight backends
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300937 salt.enforceState(master, "*01* and I@elasticsearch:server ${extra_tgt}", 'elasticsearch.server')
938 salt.enforceState(master, "I@elasticsearch:server ${extra_tgt}", 'elasticsearch.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200939
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300940 salt.enforceState(master, "*01* and I@influxdb:server ${extra_tgt}", 'influxdb')
941 salt.enforceState(master, "I@influxdb:server ${extra_tgt}", 'influxdb')
Ales Komarekef2bab62017-04-26 11:48:28 +0200942
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300943 salt.enforceState(master, "*01* and I@kibana:server ${extra_tgt}", 'kibana.server')
944 salt.enforceState(master, "I@kibana:server ${extra_tgt}", 'kibana.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200945
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300946 salt.enforceState(master, "*01* and I@grafana:server ${extra_tgt}",'grafana.server')
947 salt.enforceState(master, "I@grafana:server ${extra_tgt}",'grafana.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200948
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300949 def alarming_service_pillar = salt.getPillar(master, "mon*01* ${extra_tgt}", '_param:alarming_service')
Kalynovskyi3e370112017-06-26 12:48:23 +0300950 def alarming_service = alarming_service_pillar['return'][0].values()[0]
951
952 switch (alarming_service) {
953 case 'sensu':
954 // Update Sensu
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300955 salt.enforceState(master, "I@sensu:server and I@rabbitmq:server ${extra_tgt}", 'rabbitmq')
956 salt.enforceState(master, "I@redis:cluster:role:master ${extra_tgt}", 'redis')
957 salt.enforceState(master, "I@redis:server ${extra_tgt}", 'redis')
958 salt.enforceState(master, "I@sensu:server ${extra_tgt}", 'sensu')
Kalynovskyi3e370112017-06-26 12:48:23 +0300959 default:
960 // Update Nagios
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300961 salt.enforceState(master, "I@nagios:server ${extra_tgt}", 'nagios.server')
Kalynovskyi3e370112017-06-26 12:48:23 +0300962 // Stop the Nagios service because the package starts it by default and it will
963 // started later only on the node holding the VIP address
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300964 salt.runSaltProcessStep(master, "I@nagios:server ${extra_tgt}", 'service.stop', ['nagios3'], null, true)
Kalynovskyi3e370112017-06-26 12:48:23 +0300965 }
966
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300967 salt.enforceState(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch.client.service')
968 salt.enforceState(master, "I@kibana:client ${extra_tgt}", 'kibana.client')
Ales Komarekef2bab62017-04-26 11:48:28 +0200969
970 sleep(10)
971}
972
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300973def installStacklightv1Client(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200974 def salt = new com.mirantis.mk.Salt()
975 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200976
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300977 salt.cmdRun(master, "I@elasticsearch:client ${extra_tgt}", 'salt-call state.sls elasticsearch.client')
978 // salt.enforceState(master, "I@elasticsearch:client", 'elasticsearch.client", true)
979 salt.cmdRun(master, "I@kibana:client ${extra_tgt}", 'salt-call state.sls kibana.client')
980 // salt.enforceState(master, "I@kibana:client", 'kibana.client", true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200981
982 // Install collectd, heka and sensu services on the nodes, this will also
983 // generate the metadata that goes into the grains and eventually into Salt Mine
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300984 salt.enforceState(master, "* ${extra_tgt}", 'collectd')
985 salt.enforceState(master, "* ${extra_tgt}", 'salt.minion')
986 salt.enforceState(master, "* ${extra_tgt}", 'heka')
Ales Komarekef2bab62017-04-26 11:48:28 +0200987
988 // Gather the Grafana metadata as grains
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300989 salt.enforceState(master, "I@grafana:collector ${extra_tgt}", 'grafana.collector', true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200990
991 // Update Salt Mine
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300992 salt.enforceState(master, "* ${extra_tgt}", 'salt.minion.grains')
993 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'saltutil.refresh_modules')
994 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'mine.update')
Ales Komarekef2bab62017-04-26 11:48:28 +0200995
996 sleep(5)
997
998 // Update Heka
Martin Polreich44331002018-08-13 11:27:06 +0200999 salt.enforceState(master, "( I@heka:aggregator:enabled:True or I@heka:remote_collector:enabled:True ) ${extra_tgt}", 'heka')
Ales Komarekef2bab62017-04-26 11:48:28 +02001000
1001 // Update collectd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001002 salt.enforceState(master, "I@collectd:remote_client:enabled:True ${extra_tgt}", 'collectd')
Ales Komarekef2bab62017-04-26 11:48:28 +02001003
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001004 def alarming_service_pillar = salt.getPillar(master, "mon*01* ${extra_tgt}", '_param:alarming_service')
Kalynovskyi3e370112017-06-26 12:48:23 +03001005 def alarming_service = alarming_service_pillar['return'][0].values()[0]
Ales Komarekef2bab62017-04-26 11:48:28 +02001006
Kalynovskyi3e370112017-06-26 12:48:23 +03001007 switch (alarming_service) {
1008 case 'sensu':
1009 // Update Sensu
1010 // TODO for stacklight team, should be fixed in model
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001011 salt.enforceState(master, "I@sensu:client ${extra_tgt}", 'sensu')
Kalynovskyi3e370112017-06-26 12:48:23 +03001012 default:
1013 break
1014 // Default is nagios, and was enforced in installStacklightControl()
1015 }
Ales Komarekef2bab62017-04-26 11:48:28 +02001016
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001017 salt.cmdRun(master, "I@grafana:client and *01* ${extra_tgt}", 'salt-call state.sls grafana.client')
1018 // salt.enforceState(master, "I@grafana:client and *01*", 'grafana.client", true)
Ales Komarekef2bab62017-04-26 11:48:28 +02001019
Marek Celoudd200cad2017-06-07 10:34:46 +02001020 // Finalize the configuration of Grafana (add the dashboards...)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001021 salt.enforceState(master, "I@grafana:client and *01* ${extra_tgt}", 'grafana.client')
1022 salt.enforceState(master, "I@grafana:client and *02* ${extra_tgt}", 'grafana.client')
1023 salt.enforceState(master, "I@grafana:client and *03* ${extra_tgt}", 'grafana.client')
1024 // nw salt -C "I@grafana:client' --async service.restart salt-minion; sleep 10
Marek Celoudd200cad2017-06-07 10:34:46 +02001025
Ales Komarekef2bab62017-04-26 11:48:28 +02001026 // Get the StackLight monitoring VIP addres
1027 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
1028 //vip=${vip:=172.16.10.253}
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001029 def pillar = salt.getPillar(master, "ctl01* ${extra_tgt}", '_param:stacklight_monitor_address')
Jakub Josefbceaa322017-06-13 18:28:27 +02001030 common.prettyPrint(pillar)
Ales Komarekef2bab62017-04-26 11:48:28 +02001031 def stacklight_vip = pillar['return'][0].values()[0]
1032
1033 if (stacklight_vip) {
1034 // (re)Start manually the services that are bound to the monitoring VIP
1035 common.infoMsg("restart services on node with IP: ${stacklight_vip}")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001036 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['remote_collectd'])
1037 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['remote_collector'])
1038 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['aggregator'])
1039 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['nagios3'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001040 } else {
1041 throw new Exception("Missing stacklight_vip")
1042 }
Tomáš Kukrálf06ca0f2017-02-27 15:18:50 +01001043}
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001044
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001045//
1046// backups
1047//
1048
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001049def installBackup(master, component='common', extra_tgt = '') {
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001050 def salt = new com.mirantis.mk.Salt()
1051 if (component == 'common') {
1052 // Install Backupninja
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001053 if (salt.testTarget(master, "I@backupninja:client ${extra_tgt}")) {
1054 salt.enforceState(master, "I@backupninja:client ${extra_tgt}", 'salt.minion.grains')
1055 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'saltutil.sync_grains')
1056 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'mine.flush')
1057 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'mine.update')
1058 salt.enforceState(master, "I@backupninja:client ${extra_tgt}", 'backupninja')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001059 }
Martin Polreich675dc942018-08-15 09:37:32 +02001060 salt.enforceStateWithTest(master, "I@backupninja:server ${extra_tgt}", 'salt.minion.grains')
1061 salt.enforceStateWithTest(master, "I@backupninja:server ${extra_tgt}", 'backupninja')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001062 } else if (component == 'mysql') {
1063 // Install Xtrabackup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001064 if (salt.testTarget(master, "I@xtrabackup:client ${extra_tgt}")) {
1065 salt.enforceState(master, "I@xtrabackup:client ${extra_tgt}", 'salt.minion.grains')
1066 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'saltutil.sync_grains')
1067 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'mine.flush')
1068 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'mine.update')
1069 salt.enforceState(master, "I@xtrabackup:client ${extra_tgt}", 'xtrabackup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001070 }
Martin Polreich675dc942018-08-15 09:37:32 +02001071 salt.enforceStateWithTest(master, "I@xtrabackup:server ${extra_tgt}", 'xtrabackup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001072 } else if (component == 'contrail') {
1073
1074 // Install Cassandra backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001075 if (salt.testTarget(master, "I@cassandra:backup:client ${extra_tgt}")) {
1076 salt.enforceState(master, "I@cassandra:backup:client ${extra_tgt}", 'salt.minion.grains')
1077 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1078 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'mine.flush')
1079 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'mine.update')
1080 salt.enforceState(master, "I@cassandra:backup:client ${extra_tgt}", 'cassandra.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001081 }
Martin Polreich675dc942018-08-15 09:37:32 +02001082 salt.enforceStateWithTest(master, "I@cassandra:backup:server ${extra_tgt}", 'cassandra.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001083 // Install Zookeeper backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001084 if (salt.testTarget(master, "I@zookeeper:backup:client ${extra_tgt}")) {
1085 salt.enforceState(master, "I@zookeeper:backup:client ${extra_tgt}", 'salt.minion.grains')
1086 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1087 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'mine.flush')
1088 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'mine.update')
1089 salt.enforceState(master, "I@zookeeper:backup:client ${extra_tgt}", 'zookeeper.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001090 }
Martin Polreich675dc942018-08-15 09:37:32 +02001091 salt.enforceStateWithTest(master, "I@zookeeper:backup:server ${extra_tgt}", 'zookeeper.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001092 } else if (component == 'ceph') {
1093 // Install Ceph backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001094 if (salt.testTarget(master, "I@ceph:backup:client ${extra_tgt}")) {
1095 salt.enforceState(master, "I@ceph:backup:client ${extra_tgt}", 'salt.minion.grains')
1096 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1097 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'mine.flush')
1098 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'mine.update')
1099 salt.enforceState(master, "I@ceph:backup:client ${extra_tgt}", 'ceph.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001100 }
Martin Polreich675dc942018-08-15 09:37:32 +02001101 salt.enforceStateWithTest(master, "I@ceph:backup:server ${extra_tgt}", 'ceph.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001102 }
1103
1104}
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001105
1106//
1107// Ceph
1108//
1109
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001110def installCephMon(master, target="I@ceph:mon", extra_tgt = '') {
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001111 def salt = new com.mirantis.mk.Salt()
1112
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001113 salt.enforceState(master, "I@ceph:common ${extra_tgt}", 'salt.minion.grains')
Jiri Broulikbfc234f2017-10-17 15:45:38 +02001114
Jiri Broulike57a0242017-10-06 13:38:47 +02001115 // generate keyrings
Martin Polreich44331002018-08-13 11:27:06 +02001116 if (salt.testTarget(master, "( I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin ) ${extra_tgt}")) {
1117 salt.enforceState(master, "( I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin ) ${extra_tgt}", 'ceph.mon')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001118 salt.runSaltProcessStep(master, "I@ceph:mon ${extra_tgt}", 'saltutil.sync_grains')
Martin Polreich44331002018-08-13 11:27:06 +02001119 salt.runSaltProcessStep(master, "( I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin ) ${extra_tgt}", 'mine.update')
Jiri Broulik3c75a6d2017-10-06 18:44:37 +02001120 sleep(5)
Jiri Broulike57a0242017-10-06 13:38:47 +02001121 }
Ondrej Smolafd5c2352017-08-11 14:25:39 +02001122 // install Ceph Mons
Jakub Josef432e9d92018-02-06 18:28:37 +01001123 salt.enforceState(master, target, 'ceph.mon')
Martin Polreich675dc942018-08-15 09:37:32 +02001124 salt.enforceStateWithTest(master, "I@ceph:mgr ${extra_tgt}", 'ceph.mgr')
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001125}
1126
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001127def installCephOsd(master, target="I@ceph:osd", setup=true, extra_tgt = '') {
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001128 def salt = new com.mirantis.mk.Salt()
1129
1130 // install Ceph OSDs
Jakub Josef432e9d92018-02-06 18:28:37 +01001131 salt.enforceState(master, target, 'ceph.osd')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001132 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'saltutil.sync_grains')
Jakub Josef432e9d92018-02-06 18:28:37 +01001133 salt.enforceState(master, target, 'ceph.osd.custom')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001134 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'saltutil.sync_grains')
1135 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'mine.update')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001136 installBackup(master, 'ceph')
Tomáš Kukráled27a472017-08-29 10:26:25 +02001137
Jiri Broulike57a0242017-10-06 13:38:47 +02001138 // setup pools, keyrings and maybe crush
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001139 if (salt.testTarget(master, "I@ceph:setup ${extra_tgt}") && setup) {
Jiri Broulik07f8de72017-10-09 14:12:17 +02001140 sleep(5)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001141 salt.enforceState(master, "I@ceph:setup ${extra_tgt}", 'ceph.setup')
Tomáš Kukráled27a472017-08-29 10:26:25 +02001142 }
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001143}
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001144
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001145def installCephClient(master, extra_tgt = '') {
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001146 def salt = new com.mirantis.mk.Salt()
1147
1148 // install Ceph Radosgw
Martin Polreich675dc942018-08-15 09:37:32 +02001149 if (salt.testTarget(master, "I@ceph:radosgw ${extra_tgt} and I@node_role.openstack-control")) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001150 salt.runSaltProcessStep(master, "I@ceph:radosgw ${extra_tgt}", 'saltutil.sync_grains')
1151 salt.enforceState(master, "I@ceph:radosgw ${extra_tgt}", 'ceph.radosgw')
Alexander Noskov229035f2017-12-06 00:10:20 +04001152 }
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001153
1154 // setup keyring for Openstack services
Martin Polreich675dc942018-08-15 09:37:32 +02001155 salt.enforceStateWithTest(master, "I@ceph:common and I@glance:server ${extra_tgt}", ['ceph.common', 'ceph.setup.keyring'])
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001156
Martin Polreich675dc942018-08-15 09:37:32 +02001157 salt.enforceStateWithTest(master, "I@ceph:common and I@cinder:controller ${extra_tgt}", ['ceph.common', 'ceph.setup.keyring'])
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001158
1159 if (salt.testTarget(master, "I@ceph:common and I@nova:compute ${extra_tgt}")) {
1160 salt.enforceState(master, "I@ceph:common and I@nova:compute ${extra_tgt}", ['ceph.common', 'ceph.setup.keyring'])
1161 salt.runSaltProcessStep(master, "I@ceph:common and I@nova:compute ${extra_tgt}", 'saltutil.sync_grains')
1162 }
1163
Martin Polreich675dc942018-08-15 09:37:32 +02001164 salt.enforceStateWithTest(master, "I@ceph:common and I@gnocchi:server ${extra_tgt}", ['ceph.common', 'ceph.setup.keyring'])
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001165}
Jiri Broulike57a0242017-10-06 13:38:47 +02001166
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001167def connectCeph(master, extra_tgt = '') {
Jiri Broulike57a0242017-10-06 13:38:47 +02001168 def salt = new com.mirantis.mk.Salt()
1169
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001170 // setup Keystone service and endpoints for swift or / and S3
Martin Polreich675dc942018-08-15 09:37:32 +02001171 salt.enforceStateWithTest(master, "I@keystone:client ${extra_tgt}", 'keystone.client')
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001172
Jiri Broulike57a0242017-10-06 13:38:47 +02001173 // connect Ceph to the env
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001174 if (salt.testTarget(master, "I@ceph:common and I@glance:server ${extra_tgt}")) {
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001175 salt.enforceState(master, "I@ceph:common and I@glance:server ${extra_tgt}", ['glance'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001176 salt.runSaltProcessStep(master, "I@ceph:common and I@glance:server ${extra_tgt}", 'service.restart', ['glance-api'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001177 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001178 if (salt.testTarget(master, "I@ceph:common and I@cinder:controller ${extra_tgt}")) {
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001179 salt.enforceState(master, "I@ceph:common and I@cinder:controller ${extra_tgt}", ['cinder'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001180 salt.runSaltProcessStep(master, "I@ceph:common and I@cinder:controller ${extra_tgt}", 'service.restart', ['cinder-volume'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001181 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001182 if (salt.testTarget(master, "I@ceph:common and I@nova:compute ${extra_tgt}")) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001183 salt.enforceState(master, "I@ceph:common and I@nova:compute ${extra_tgt}", ['nova'])
1184 salt.runSaltProcessStep(master, "I@ceph:common and I@nova:compute ${extra_tgt}", 'service.restart', ['nova-compute'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001185 }
Mykyta Karpin0dec8b32018-09-19 09:37:45 +03001186 if (salt.testTarget(master, "I@ceph:common and I@gnocchi:server ${extra_tgt}")) {
Mykyta Karpin0dec8b32018-09-19 09:37:45 +03001187 salt.enforceState(master, "I@ceph:common and I@gnocchi:server:role:primary ${extra_tgt}", 'gnocchi.server')
1188 salt.enforceState(master, "I@ceph:common and I@gnocchi:server ${extra_tgt}", 'gnocchi.server')
1189 }
Jiri Broulike57a0242017-10-06 13:38:47 +02001190}
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001191
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001192def installOssInfra(master, extra_tgt = '') {
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001193 def common = new com.mirantis.mk.Common()
1194 def salt = new com.mirantis.mk.Salt()
1195
Martin Polreich675dc942018-08-15 09:37:32 +02001196 salt.enforceStateWithTest(master, "I@devops_portal:config ${extra_tgt}", 'devops_portal.config', )
1197 salt.enforceStateWithTest(master, "I@rundeck:client ${extra_tgt}", ['linux.system.user', 'openssh'], "I@devops_portal:config ${extra_tgt}")
1198 salt.enforceStateWithTest(master, "I@rundeck:server ${extra_tgt}", 'rundeck.server', "I@devops_portal:config ${extra_tgt}")
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001199}
1200
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001201def installOss(master, extra_tgt = '') {
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001202 def common = new com.mirantis.mk.Common()
1203 def salt = new com.mirantis.mk.Salt()
1204
1205 //Get oss VIP address
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001206 def pillar = salt.getPillar(master, "cfg01* ${extra_tgt}", '_param:stacklight_monitor_address')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001207 common.prettyPrint(pillar)
1208
1209 def oss_vip
1210 if(!pillar['return'].isEmpty()) {
1211 oss_vip = pillar['return'][0].values()[0]
1212 } else {
1213 common.errorMsg('[ERROR] Oss VIP address could not be retrieved')
1214 }
1215
1216 // Postgres client - initialize OSS services databases
1217 timeout(120){
1218 common.infoMsg("Waiting for postgresql database to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001219 salt.cmdRun(master, "I@postgresql:client ${extra_tgt}", '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 +04001220 }
1221 // XXX: first run usually fails on some inserts, but we need to create databases at first
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001222 salt.enforceState(master, "I@postgresql:client ${extra_tgt}", 'postgresql.client', true, false)
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001223
1224 // Setup postgres database with integration between
1225 // Pushkin notification service and Security Monkey security audit service
1226 timeout(10) {
1227 common.infoMsg("Waiting for Pushkin to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001228 salt.cmdRun(master, "I@postgresql:client ${extra_tgt}", "while true; do curl -sf ${oss_vip}:8887/apps >/dev/null && break; done")
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001229 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001230 salt.enforceState(master, "I@postgresql:client ${extra_tgt}", 'postgresql.client')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001231
1232 // Rundeck
1233 timeout(10) {
1234 common.infoMsg("Waiting for Rundeck to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001235 salt.cmdRun(master, "I@rundeck:client ${extra_tgt}", "while true; do curl -sf ${oss_vip}:4440 >/dev/null && break; done")
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001236 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001237 salt.enforceState(master, "I@rundeck:client ${extra_tgt}", 'rundeck.client')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001238
1239 // Elasticsearch
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001240 pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:host')
Mikhail Ivanovfcd55d62017-12-19 16:51:35 +04001241 def elasticsearch_vip
1242 if(!pillar['return'].isEmpty()) {
1243 elasticsearch_vip = pillar['return'][0].values()[0]
1244 } else {
1245 common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved')
1246 }
1247
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001248 timeout(10) {
1249 common.infoMsg('Waiting for Elasticsearch to come up..')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001250 salt.cmdRun(master, "I@elasticsearch:client ${extra_tgt}", "while true; do curl -sf ${elasticsearch_vip}:9200 >/dev/null && break; done")
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001251 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001252 salt.enforceState(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch.client')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001253}
Oleksii Grudev9e1d97a2018-06-29 16:04:30 +03001254
1255/**
1256 * Function receives connection string, target and configuration yaml pattern
1257 * and retrieves config fom salt minion according to pattern. After that it
1258 * sorts applications according to priorities and runs orchestration states
1259 * @param master Salt Connection object or pepperEnv
1260 * @param tgt Target
1261 * @param conf Configuration pattern
1262 */
1263def OrchestrateApplications(master, tgt, conf) {
1264 def salt = new com.mirantis.mk.Salt()
1265 def common = new com.mirantis.mk.Common()
1266 def _orch = salt.getConfig(master, tgt, conf)
1267 if ( !_orch['return'][0].values()[0].isEmpty() ) {
1268 Map<String,Integer> _orch_app = [:]
1269 for (k in _orch['return'][0].values()[0].keySet()) {
1270 _orch_app[k] = _orch['return'][0].values()[0][k].values()[0].toInteger()
1271 }
1272 def _orch_app_sorted = common.SortMapByValueAsc(_orch_app)
1273 common.infoMsg("Applications will be deployed in following order:"+_orch_app_sorted.keySet())
1274 for (app in _orch_app_sorted.keySet()) {
1275 salt.orchestrateSystem(master, ['expression': tgt, 'type': 'compound'], "${app}.orchestrate.deploy")
1276 }
1277 }
1278 else {
1279 common.infoMsg("No applications found for orchestration")
1280 }
Inessa Vasilevskaya85ad1a92018-10-08 12:19:47 +02001281}