blob: 1b736cdc53baa8fe45220020f6b7f5d76147aff3 [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)
Jiri Broulik94fc2592018-04-20 13:47:51 +020039 try {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030040 salt.enforceState(master, "* ${extra_tgt}", ['salt.minion.base'], true, false, null, false, 60, 2)
Jiri Broulik94fc2592018-04-20 13:47:51 +020041 sleep(5)
42 } catch (Throwable e) {
43 common.warningMsg('Salt state salt.minion.base is not present in the Salt-formula yet.')
44 }
Jiri Broulike3ace622018-06-07 10:51:02 +020045 common.retry(2,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030046 salt.enforceState(master, "* ${extra_tgt}", ['linux.system'])
Jiri Broulike3ace622018-06-07 10:51:02 +020047 }
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +010048 if (staticMgmtNet) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030049 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 +010050 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030051 salt.enforceState(master, "I@linux:network:interface ${extra_tgt}", ['linux.network.interface'])
Jiri Broulik94538462018-05-11 15:45:13 +020052 sleep(5)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030053 salt.enforceState(master, "I@linux:system ${extra_tgt}", ['linux', 'openssh', 'ntp', 'rsyslog'])
54 salt.enforceState(master, "* ${extra_tgt}", ['salt.minion'], true, false, null, false, 60, 2)
Jakub Josef4f8f4df2017-09-01 14:32:42 +020055 sleep(5)
Victor Ryzhenkinf610c572018-05-15 15:22:52 +040056
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030057 salt.fullRefresh(master, "* ${extra_tgt}")
58 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'mine.update', [], null, true)
59 salt.enforceState(master, "* ${extra_tgt}", ['linux.network.host'])
Ivan Suzdal9a6bc392018-04-26 18:29:56 +040060
61 // Install and configure iptables
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030062 if (salt.testTarget(master, "I@iptables:service ${extra_tgt}")) {
63 salt.enforceState(master, "I@iptables:service ${extra_tgt}", 'iptables')
Ivan Suzdal9a6bc392018-04-26 18:29:56 +040064 }
sgarbuzbb61e812018-05-03 16:58:40 +030065
66 // Install and configure logrotate
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030067 if (salt.testTarget(master, "I@logrotate:server ${extra_tgt}")) {
68 salt.enforceState(master, "I@logrotate:server ${extra_tgt}", 'logrotate')
sgarbuzbb61e812018-05-03 16:58:40 +030069 }
Ivan Suzdal9f8f0e12018-06-21 13:16:21 +040070
71 // Install and configure auditd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030072 if (salt.testTarget(master, "I@auditd:service ${extra_tgt}")) {
73 salt.enforceState(master, "I@auditd:service ${extra_tgt}", 'auditd')
Ivan Suzdal9f8f0e12018-06-21 13:16:21 +040074 }
Jakub Josef79ecec32017-02-17 14:36:28 +010075}
76
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030077def installFoundationInfraOnTarget(master, target, staticMgmtNet=false, extra_tgt = '') {
Jiri Broulik976bf6c2017-10-20 14:43:25 +020078 def salt = new com.mirantis.mk.Salt()
Jiri Broulik9fb138a2018-04-23 17:13:00 +020079 def common = new com.mirantis.mk.Common()
Jiri Broulik976bf6c2017-10-20 14:43:25 +020080
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030081 salt.enforceState(master, "I@salt:master ${extra_tgt}", ['reclass'], true, false, null, false, 120, 2)
Jakub Josef432e9d92018-02-06 18:28:37 +010082 salt.fullRefresh(master, target)
Ondrej Smolaa9b84662018-04-18 11:22:19 +020083 salt.enforceState(master, target, ['linux.network.proxy'], true, false, null, false, 60, 2)
Jiri Broulik94fc2592018-04-20 13:47:51 +020084 try {
85 salt.enforceState(master, target, ['salt.minion.base'], true, false, null, false, 60, 2)
86 sleep(5)
87 } catch (Throwable e) {
88 common.warningMsg('Salt state salt.minion.base is not present in the Salt-formula yet.')
89 }
Jiri Broulike3ace622018-06-07 10:51:02 +020090 common.retry(2,5){
91 salt.enforceState(master, target, ['linux.system'])
92 }
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +010093 if (staticMgmtNet) {
94 salt.runSaltProcessStep(master, target, 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], null, true, 60)
95 }
Jiri Broulik976bf6c2017-10-20 14:43:25 +020096 salt.enforceState(master, target, ['salt.minion'], true, false, null, false, 60, 2)
Jakub Josef432e9d92018-02-06 18:28:37 +010097 salt.enforceState(master, target, ['salt.minion'])
Jiri Broulik3740fb92018-04-27 11:52:38 +020098 salt.enforceState(master, target, ['linux.network.interface'])
Jiri Broulik94538462018-05-11 15:45:13 +020099 sleep(5)
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100100 salt.enforceState(master, target, ['linux', 'openssh', 'ntp', 'rsyslog'])
Jiri Broulik976bf6c2017-10-20 14:43:25 +0200101 sleep(5)
Victor Ryzhenkinf610c572018-05-15 15:22:52 +0400102
103 salt.fullRefresh(master, target)
vrovachevc4424a32018-03-15 17:35:57 +0400104 salt.runSaltProcessStep(master, target, 'mine.update', [], null, true)
Jakub Josef432e9d92018-02-06 18:28:37 +0100105 salt.enforceState(master, target, ['linux.network.host'])
Jiri Broulik976bf6c2017-10-20 14:43:25 +0200106}
107
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300108def installInfraKvm(master, extra_tgt = '') {
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200109 def common = new com.mirantis.mk.Common()
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +0100110 def salt = new com.mirantis.mk.Salt()
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300111 def infra_compound = "I@salt:control ${extra_tgt}"
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200112 def minions = []
113 def wait_timeout = 10
114 def retries = wait_timeout * 30
Ales Komarekef2bab62017-04-26 11:48:28 +0200115
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300116 salt.fullRefresh(master, "I@linux:system ${extra_tgt}")
117 salt.enforceState(master, "I@salt:control ${extra_tgt}", ['salt.minion'], true, false, null, false, 60, 2)
118 salt.enforceState(master, "I@salt:control ${extra_tgt}", ['linux.system', 'linux.network', 'ntp', 'rsyslog'])
119 salt.enforceState(master, "I@salt:control ${extra_tgt}", 'libvirt')
120 salt.enforceState(master, "I@salt:control ${extra_tgt}", 'salt.control')
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100121
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200122 common.infoMsg("Building minions list...")
123 if (salt.testTarget(master, infra_compound)) {
124 // Gathering minions
125 for ( infra_node in salt.getMinionsSorted(master, infra_compound) ) {
126 def pillar = salt.getPillar(master, infra_node, 'salt:control:cluster')
127 if ( !pillar['return'].isEmpty() ) {
128 for ( cluster in pillar['return'][0].values() ) {
129 def engine = cluster.values()[0]['engine']
130 def domain = cluster.values()[0]['domain']
131 def node = cluster.values()[0]['node']
132 if ( engine == "virt" ) {
133 def nodes = node.values()
134 if ( !nodes.isEmpty() ) {
135 for ( vm in nodes ) {
136 if ( vm['name'] != null ) {
137 def vm_fqdn = vm['name'] + '.' + domain
138 if ( !minions.contains(vm_fqdn) ) {
139 minions.add(vm_fqdn)
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200140 }
141 }
142 }
143 }
144 }
145 }
146 }
147 }
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200148 }
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100149
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200150 def minions_compound = minions.join(' or ')
151
152 common.infoMsg("Waiting for next minions to register within ${wait_timeout} minutes: " + minions_compound)
153 timeout(time: wait_timeout, unit: 'MINUTES') {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300154 salt.minionsPresentFromList(master, "I@salt:master ${extra_tgt}", minions, true, null, true, retries, 1)
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200155 }
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200156
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200157 common.infoMsg('Waiting for minions to respond')
158 timeout(time: wait_timeout, unit: 'MINUTES') {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300159 salt.minionsReachable(master, "I@salt:master ${extra_tgt}", minions_compound)
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200160 }
161
162 common.infoMsg("All minions are up.")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300163 salt.fullRefresh(master, "* and not kvm* ${extra_tgt}")
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200164
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +0100165}
Jakub Josef79ecec32017-02-17 14:36:28 +0100166
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300167def installInfra(master, extra_tgt = '') {
Jakub Josef61463c72018-02-13 16:10:56 +0100168 def common = new com.mirantis.mk.Common()
Jakub Josef79ecec32017-02-17 14:36:28 +0100169 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200170
Jakub Josef79ecec32017-02-17 14:36:28 +0100171 // Install glusterfs
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300172 if (salt.testTarget(master, "I@glusterfs:server ${extra_tgt}")) {
173 salt.enforceState(master, "I@glusterfs:server ${extra_tgt}", 'glusterfs.server.service')
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100174
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300175 salt.enforceState(master, "I@glusterfs:server and *01* ${extra_tgt}", 'glusterfs.server.setup', true, true, null, false, -1, 5)
Jakub Josef61463c72018-02-13 16:10:56 +0100176 sleep(10)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300177 salt.cmdRun(master, "I@glusterfs:server ${extra_tgt}", "gluster peer status; gluster volume status")
Alexander Noskov93acac42017-06-20 17:55:55 +0200178 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200179
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300180 // Ensure glusterfs clusters is ready
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300181 if (salt.testTarget(master, "I@glusterfs:client ${extra_tgt}")) {
182 salt.enforceState(master, "I@glusterfs:client ${extra_tgt}", 'glusterfs.client', true, true, null, false, -1, 2)
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300183 }
184
Jakub Josef79ecec32017-02-17 14:36:28 +0100185 // Install galera
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300186 if (salt.testTarget(master, "I@galera:master ${extra_tgt}") || salt.testTarget(master, "I@galera:slave ${extra_tgt}")) {
187 salt.enforceState(master, "I@galera:master ${extra_tgt}", 'galera', true, true, null, false, -1, 2)
188 salt.enforceState(master, "I@galera:slave ${extra_tgt}", 'galera', true, true, null, false, -1, 2)
vrovachev1c4770b2017-07-05 13:25:21 +0400189
190 // Check galera status
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300191 salt.runSaltProcessStep(master, "I@galera:master ${extra_tgt}", 'mysql.status')
192 salt.runSaltProcessStep(master, "I@galera:slave ${extra_tgt}", 'mysql.status')
Vasyl Saienkoc1fb9892017-07-13 14:54:13 +0300193 // If galera is not enabled check if we need to install mysql:server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300194 } else if (salt.testTarget(master, "I@mysql:server ${extra_tgt}")){
195 salt.enforceState(master, "I@mysql:server ${extra_tgt}", 'mysql.server')
196 if (salt.testTarget(master, "I@mysql:client ${extra_tgt}")){
197 salt.enforceState(master, "I@mysql:client ${extra_tgt}", 'mysql.client')
Vasyl Saienkoc1fb9892017-07-13 14:54:13 +0300198 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200199 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300200 installBackup(master, 'mysql', extra_tgt)
Ales Komarekef2bab62017-04-26 11:48:28 +0200201
vrovachev1c4770b2017-07-05 13:25:21 +0400202 // Install docker
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300203 if (salt.testTarget(master, "I@docker:host ${extra_tgt}")) {
204 salt.enforceState(master, "I@docker:host ${extra_tgt}", 'docker.host')
205 salt.cmdRun(master, "I@docker:host ${extra_tgt}", 'docker ps')
vrovachev1c4770b2017-07-05 13:25:21 +0400206 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200207
vrovachev1c4770b2017-07-05 13:25:21 +0400208 // Install keepalived
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300209 if (salt.testTarget(master, "I@keepalived:cluster ${extra_tgt}")) {
210 salt.enforceState(master, "I@keepalived:cluster and *01* ${extra_tgt}", 'keepalived')
211 salt.enforceState(master, "I@keepalived:cluster ${extra_tgt}", 'keepalived')
vrovachev1c4770b2017-07-05 13:25:21 +0400212 }
213
214 // Install rabbitmq
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300215 if (salt.testTarget(master, "I@rabbitmq:server ${extra_tgt}")) {
216 salt.enforceState(master, "I@rabbitmq:server ${extra_tgt}", 'rabbitmq', true, true, null, false, -1, 2)
vrovachev1c4770b2017-07-05 13:25:21 +0400217
218 // Check the rabbitmq status
Jakub Josef61463c72018-02-13 16:10:56 +0100219 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300220 salt.cmdRun(master, "I@rabbitmq:server ${extra_tgt}", 'rabbitmqctl cluster_status')
Jakub Josef61463c72018-02-13 16:10:56 +0100221 }
vrovachev1c4770b2017-07-05 13:25:21 +0400222 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200223
Jakub Josef79ecec32017-02-17 14:36:28 +0100224 // Install haproxy
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300225 if (salt.testTarget(master, "I@haproxy:proxy ${extra_tgt}")) {
226 salt.enforceState(master, "I@haproxy:proxy ${extra_tgt}", 'haproxy')
227 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.status', ['haproxy'])
228 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.restart', ['rsyslog'])
vrovachev1c4770b2017-07-05 13:25:21 +0400229 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200230
Jakub Josef79ecec32017-02-17 14:36:28 +0100231 // Install memcached
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300232 if (salt.testTarget(master, "I@memcached:server ${extra_tgt}")) {
233 salt.enforceState(master, "I@memcached:server ${extra_tgt}", 'memcached')
vrovachev1c4770b2017-07-05 13:25:21 +0400234 }
235
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}")) {
246 if (salt.testTarget(master, "I@redis:cluster:role:master ${extra_tgt}")) {
247 salt.enforceState(master, "I@redis:cluster:role:master ${extra_tgt}", 'redis')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200248 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300249 salt.enforceState(master, "I@redis:server ${extra_tgt}", 'redis')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200250 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300251 installBackup(master, 'common', extra_tgt)
vrovachev1c4770b2017-07-05 13:25:21 +0400252}
253
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300254def installOpenstackInfra(master, extra_tgt = '') {
Jakub Josef432e9d92018-02-06 18:28:37 +0100255 def common = new com.mirantis.mk.Common()
256 common.warningMsg("You calling orchestrate.installOpenstackInfra(). This function is deprecated please use orchestrate.installInfra() directly")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300257 installInfra(master, extra_tgt)
Jakub Josef79ecec32017-02-17 14:36:28 +0100258}
259
260
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300261def installOpenstackControl(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100262 def salt = new com.mirantis.mk.Salt()
Jakub Josef61463c72018-02-13 16:10:56 +0100263 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200264
265 // Install horizon dashboard
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300266 if (salt.testTarget(master, "I@horizon:server ${extra_tgt}")) {
267 salt.enforceState(master, "I@horizon:server ${extra_tgt}", 'horizon')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300268 }
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100269 // Install sphinx server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300270 if (salt.testTarget(master, "I@sphinx:server ${extra_tgt}")) {
271 salt.enforceState(master, "I@sphinx:server ${extra_tgt}", 'sphinx')
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100272 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300273 if (salt.testTarget(master, "I@nginx:server ${extra_tgt}")) {
274 salt.enforceState(master, "I@nginx:server ${extra_tgt}", 'salt.minion')
275 salt.enforceState(master, "I@nginx:server ${extra_tgt}", 'nginx')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300276 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200277
Jakub Josef79ecec32017-02-17 14:36:28 +0100278 // setup keystone service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300279 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
280 salt.enforceState(master, "I@keystone:server and *01* ${extra_tgt}", 'keystone.server')
281 salt.enforceState(master, "I@keystone:server ${extra_tgt}", 'keystone.server')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300282 // populate keystone services/tenants/roles/users
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100283
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300284 // keystone:client must be called locally
285 //salt.runSaltProcessStep(master, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300286 salt.runSaltProcessStep(master, "I@keystone:server ${extra_tgt}", 'service.restart', ['apache2'])
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300287 sleep(30)
288 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300289 if (salt.testTarget(master, "I@keystone:client ${extra_tgt}")) {
290 salt.enforceState(master, "I@keystone:client and *01* ${extra_tgt}", 'keystone.client')
291 salt.enforceState(master, "I@keystone:client ${extra_tgt}", 'keystone.client')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300292 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300293 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Jakub Josef61463c72018-02-13 16:10:56 +0100294 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300295 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack service list')
Jakub Josef61463c72018-02-13 16:10:56 +0100296 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300297 }
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100298
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300299 // Install glance
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300300 if (salt.testTarget(master, "I@glance:server ${extra_tgt}")) {
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300301 //runSaltProcessStep(master, 'I@glance:server', 'state.sls', ['glance.server'], 1)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300302 salt.enforceState(master, "I@glance:server and *01* ${extra_tgt}", 'glance.server')
303 salt.enforceState(master, "I@glance:server ${extra_tgt}", 'glance.server')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300304 }
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
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300314 if (salt.testTarget(master, "I@glance:client ${extra_tgt}")) {
315 salt.enforceState(master, "I@glance:client ${extra_tgt}", 'glance.client')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400316 }
317
Jakub Josef79ecec32017-02-17 14:36:28 +0100318 // Install and check nova service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300319 if (salt.testTarget(master, "I@nova:controller ${extra_tgt}")) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100320 // run on first node first
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300321 salt.enforceState(master, "I@nova:controller and *01* ${extra_tgt}", 'nova.controller')
322 salt.enforceState(master, "I@nova:controller ${extra_tgt}", 'nova.controller')
323 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Jakub Josef61463c72018-02-13 16:10:56 +0100324 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300325 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; nova service-list')
Jakub Josef61463c72018-02-13 16:10:56 +0100326 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300327 }
328 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200329
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400330 // Create nova resources
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300331 if (salt.testTarget(master, "I@nova:client ${extra_tgt}")) {
332 salt.enforceState(master, "I@nova:client ${extra_tgt}", 'nova.client')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400333 }
334
Jakub Josef79ecec32017-02-17 14:36:28 +0100335 // Install and check cinder service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300336 if (salt.testTarget(master, "I@cinder:controller ${extra_tgt}")) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100337 // run on first node first
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300338 salt.enforceState(master, "I@cinder:controller and *01* ${extra_tgt}", 'cinder')
339 salt.enforceState(master, "I@cinder:controller ${extra_tgt}", 'cinder')
340 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Jakub Josef61463c72018-02-13 16:10:56 +0100341 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300342 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; cinder list')
Jakub Josef61463c72018-02-13 16:10:56 +0100343 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300344 }
345 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200346
Jakub Josef79ecec32017-02-17 14:36:28 +0100347 // Install neutron service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300348 if (salt.testTarget(master, "I@neutron:server ${extra_tgt}")) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100349 // run on first node first
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300350 salt.enforceState(master, "I@neutron:server and *01* ${extra_tgt}", 'neutron.server')
351 salt.enforceState(master, "I@neutron:server ${extra_tgt}", 'neutron.server')
352 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Jakub Josef61463c72018-02-13 16:10:56 +0100353 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300354 salt.cmdRun(master, "I@keystone:server ${extra_tgt}",'. /root/keystonercv3; neutron agent-list')
Jakub Josef61463c72018-02-13 16:10:56 +0100355 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300356 }
357 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200358
Jakub Josef79ecec32017-02-17 14:36:28 +0100359 // Install heat service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300360 if (salt.testTarget(master, "I@heat:server ${extra_tgt}")) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100361 // run on first node first
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300362 salt.enforceState(master, "I@heat:server and *01* ${extra_tgt}", 'heat')
363 salt.enforceState(master, "I@heat:server ${extra_tgt}", 'heat')
364 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Jakub Josef61463c72018-02-13 16:10:56 +0100365 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300366 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; heat resource-type-list')
Jakub Josef61463c72018-02-13 16:10:56 +0100367 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300368 }
369 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200370
371 // Restart nova api
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300372 if (salt.testTarget(master, "I@nova:controller ${extra_tgt}")) {
373 salt.runSaltProcessStep(master, "I@nova:controller ${extra_tgt}", 'service.restart', ['nova-api'])
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300374 }
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300375
376 // Install ironic service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300377 if (salt.testTarget(master, "I@ironic:api ${extra_tgt}")) {
378 salt.enforceState(master, "I@ironic:api and *01* ${extra_tgt}", 'ironic.api')
379 salt.enforceState(master, "I@ironic:api ${extra_tgt}", 'ironic.api')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300380 }
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300381
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200382 // Install manila service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300383 if (salt.testTarget(master, "I@manila:api ${extra_tgt}")) {
384 salt.enforceState(master, "I@manila:api and *01* ${extra_tgt}", 'manila.api')
385 salt.enforceState(master, "I@manila:api ${extra_tgt}", 'manila.api')
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200386 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300387 if (salt.testTarget(master, "I@manila:scheduler ${extra_tgt}")) {
388 salt.enforceState(master, "I@manila:scheduler ${extra_tgt}", 'manila.scheduler')
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200389 }
390
Oleh Hryhorova070fd02018-03-15 14:47:52 +0200391 // Install designate services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300392 if (salt.testTarget(master, "I@designate:server:enabled ${extra_tgt}")) {
393 if (salt.testTarget(master, "I@designate:server:backend:bind9 ${extra_tgt}")) {
394 salt.enforceState(master, "I@bind:server ${extra_tgt}", 'bind.server')
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300395 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300396 if (salt.testTarget(master, "I@designate:server:backend:pdns4 ${extra_tgt}")) {
397 salt.enforceState(master, "I@powerdns:server ${extra_tgt}", 'powerdns.server')
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300398 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300399 salt.enforceState(master, "I@designate:server and *01* ${extra_tgt}", 'designate.server')
400 salt.enforceState(master, "I@designate:server ${extra_tgt}", 'designate')
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300401 }
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400402
403 // Install octavia api service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300404 if (salt.testTarget(master, "I@octavia:api ${extra_tgt}")) {
405 salt.enforceState(master, "I@octavia:api and *01* ${extra_tgt}", 'octavia')
406 salt.enforceState(master, "I@octavia:api ${extra_tgt}", 'octavia')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400407 }
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200408
Oleg Iurchenkod0898c92017-12-14 14:28:44 +0200409 // Install DogTag server service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300410 if (salt.testTarget(master, "I@dogtag:server ${extra_tgt}")) {
411 salt.enforceState(master, "I@dogtag:server and *01* ${extra_tgt}", 'dogtag.server')
412 salt.enforceState(master, "I@dogtag:server ${extra_tgt}", 'dogtag.server')
Oleg Iurchenkod0898c92017-12-14 14:28:44 +0200413 }
414
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200415 // Install barbican server service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300416 if (salt.testTarget(master, "I@barbican:server ${extra_tgt}")) {
417 salt.enforceState(master, "I@barbican:server and *01* ${extra_tgt}", 'barbican.server')
418 salt.enforceState(master, "I@barbican:server ${extra_tgt}", 'barbican.server')
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200419 }
420 // Install barbican client
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300421 if (salt.testTarget(master, "I@barbican:client ${extra_tgt}")) {
422 salt.enforceState(master, "I@barbican:client ${extra_tgt}", 'barbican.client')
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200423 }
Ondrej Smola5908ae62018-01-08 13:42:08 +0100424
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200425 // Install gnocchi server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300426 if (salt.testTarget(master, "I@gnocchi:server ${extra_tgt}")) {
427 salt.enforceState(master, "I@gnocchi:server and *01* ${extra_tgt}", 'gnocchi.server')
428 salt.enforceState(master, "I@gnocchi:server ${extra_tgt}", 'gnocchi.server')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200429 }
430
431 // Install gnocchi statsd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300432 if (salt.testTarget(master, "I@gnocchi:statsd ${extra_tgt}")) {
433 salt.enforceState(master, "I@gnocchi:statsd and *01* ${extra_tgt}", 'gnocchi.statsd')
434 salt.enforceState(master, "I@gnocchi:statsd ${extra_tgt}", 'gnocchi.statsd')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200435 }
436
437 // Install panko server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300438 if (salt.testTarget(master, "I@panko:server ${extra_tgt}")) {
439 salt.enforceState(master, "I@panko:server and *01* ${extra_tgt}", 'panko')
440 salt.enforceState(master, "I@panko:server ${extra_tgt}", 'panko')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200441 }
442
Ondrej Smola5908ae62018-01-08 13:42:08 +0100443 // Install ceilometer server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300444 if (salt.testTarget(master, "I@ceilometer:server ${extra_tgt}")) {
445 salt.enforceState(master, "I@ceilometer:server and *01* ${extra_tgt}", 'ceilometer')
446 salt.enforceState(master, "I@ceilometer:server ${extra_tgt}", 'ceilometer')
Ondrej Smola5908ae62018-01-08 13:42:08 +0100447 }
448
449 // Install aodh server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300450 if (salt.testTarget(master, "I@aodh:server ${extra_tgt}")) {
451 salt.enforceState(master, "I@aodh:server and *01* ${extra_tgt}", 'aodh')
452 salt.enforceState(master, "I@aodh:server ${extra_tgt}", 'aodh')
Ondrej Smola5908ae62018-01-08 13:42:08 +0100453 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100454}
455
456
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300457def installIronicConductor(master, extra_tgt = ''){
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300458 def salt = new com.mirantis.mk.Salt()
459
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300460 if (salt.testTarget(master, "I@ironic:conductor ${extra_tgt}")) {
461 salt.enforceState(master, "I@ironic:conductor ${extra_tgt}", 'ironic.conductor')
462 salt.enforceState(master, "I@ironic:conductor ${extra_tgt}", 'apache')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300463 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300464 if (salt.testTarget(master, "I@tftpd_hpa:server ${extra_tgt}")) {
465 salt.enforceState(master, "I@tftpd_hpa:server ${extra_tgt}", 'tftpd_hpa')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300466 }
467
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300468 if (salt.testTarget(master, "I@nova:compute ${extra_tgt}")) {
469 salt.runSaltProcessStep(master, "I@nova:compute ${extra_tgt}", 'service.restart', ['nova-compute'])
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300470 }
471
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300472 if (salt.testTarget(master, "I@baremetal_simulator:enabled ${extra_tgt}")) {
473 salt.enforceState(master, "I@baremetal_simulator:enabled ${extra_tgt}", 'baremetal_simulator')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300474 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300475 if (salt.testTarget(master, "I@ironic:client ${extra_tgt}")) {
476 salt.enforceState(master, "I@ironic:client ${extra_tgt}", 'ironic.client')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300477 }
478}
479
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300480def installManilaShare(master, extra_tgt = ''){
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200481 def salt = new com.mirantis.mk.Salt()
482
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300483 if (salt.testTarget(master, "I@manila:share ${extra_tgt}")) {
484 salt.enforceState(master, "I@manila:share ${extra_tgt}", 'manila.share')
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200485 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300486 if (salt.testTarget(master, "I@manila:data ${extra_tgt}")) {
487 salt.enforceState(master, "I@manila:data ${extra_tgt}", 'manila.data')
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200488 }
489
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300490 if (salt.testTarget(master, "I@manila:client ${extra_tgt}")) {
491 salt.enforceState(master, "I@manila:client ${extra_tgt}", 'manila.client')
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200492 }
493}
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300494
495
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300496def installOpenstackNetwork(master, physical = "false", extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100497 def salt = new com.mirantis.mk.Salt()
Oleksii Grudevc4a485e2018-04-20 14:25:03 +0300498 //run full neutron state on neutron.gateway - this will install
499 //neutron agents in addition to neutron server. Once neutron agents
500 //are up neutron resources can be created without hitting the situation when neutron resources are created
501 //prior to neutron agents which results in creating ports in non-usable state
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300502 if (salt.testTarget(master, "I@neutron:gateway ${extra_tgt}")) {
503 salt.enforceState(master, "I@neutron:gateway ${extra_tgt}", 'neutron')
Oleksii Grudevc4a485e2018-04-20 14:25:03 +0300504 }
505
506 // Create neutron resources - this step was moved here to ensure that
507 //neutron resources are created after neutron agens are up. In this case neutron ports will be in
508 //usable state. More information: https://bugs.launchpad.net/neutron/+bug/1399249
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300509 if (salt.testTarget(master, "I@neutron:client ${extra_tgt}")) {
510 salt.enforceState(master, "I@neutron:client ${extra_tgt}", 'neutron.client')
Oleksii Grudevc4a485e2018-04-20 14:25:03 +0300511 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200512
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300513 salt.enforceHighstate(master, "I@neutron:gateway ${extra_tgt}")
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400514
515 // install octavia manager services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300516 if (salt.testTarget(master, "I@octavia:manager ${extra_tgt}")) {
517 salt.runSaltProcessStep(master, "I@salt:master ${extra_tgt}", 'mine.update', ['*'])
518 salt.enforceState(master, "I@octavia:manager ${extra_tgt}", 'octavia')
519 salt.enforceState(master, "I@octavia:manager ${extra_tgt}", 'salt.minion.ca')
520 salt.enforceState(master, "I@octavia:manager ${extra_tgt}", 'salt.minion.cert')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400521 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200522}
523
524
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300525def installOpenstackCompute(master, extra_tgt = '') {
Ales Komarekef2bab62017-04-26 11:48:28 +0200526 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200527 // Configure compute nodes
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300528 def compute_compound = "I@nova:compute ${extra_tgt}"
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100529 if (salt.testTarget(master, compute_compound)) {
530 // In case if infrastructure nodes are used as nova computes too
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300531 def gluster_compound = "I@glusterfs:server ${extra_tgt}"
532 def salt_ca_compound = "I@salt:minion:ca:salt_master_ca ${extra_tgt}"
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200533 // Enforce highstate asynchronous only on compute nodes which are not glusterfs and not salt ca servers
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300534 def hightstateTarget = "${compute_compound} and not (${gluster_compound}) and not (${salt_ca_compound})"
Oleh Hryhorov73f9fa22018-05-02 17:36:58 +0300535 if (salt.testTarget(master, hightstateTarget)) {
536 retry(2) {
537 salt.enforceHighstateWithExclude(master, hightstateTarget, 'opencontrail.client')
538 }
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200539 }
540 // Iterate through salt ca servers and check if they have compute role
541 // TODO: switch to batch once salt 2017.7+ would be used
542 for ( target in salt.getMinionsSorted(master, salt_ca_compound) ) {
543 for ( cmp_target in salt.getMinionsSorted(master, compute_compound) ) {
544 if ( target == cmp_target ) {
545 // Enforce highstate one by one on salt ca servers which are compute nodes
546 retry(2) {
547 salt.enforceHighstateWithExclude(master, target, 'opencontrail.client')
548 }
549 }
550 }
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100551 }
552 // Iterate through glusterfs servers and check if they have compute role
553 // TODO: switch to batch once salt 2017.7+ would be used
554 for ( target in salt.getMinionsSorted(master, gluster_compound) ) {
555 for ( cmp_target in salt.getMinionsSorted(master, compute_compound) ) {
556 if ( target == cmp_target ) {
557 // Enforce highstate one by one on glusterfs servers which are compute nodes
558 retry(2) {
559 salt.enforceHighstateWithExclude(master, target, 'opencontrail.client')
560 }
561 }
562 }
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200563 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200564 }
Vasyl Saienko51144e42018-06-19 09:30:30 +0300565
566 // Run nova:controller to map cmp with cells
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300567 if (salt.testTarget(master, "I@nova:controller ${extra_tgt}")) {
568 salt.enforceState(master, "I@nova:controller and *01* ${extra_tgt}", 'nova.controller')
Vasyl Saienko51144e42018-06-19 09:30:30 +0300569 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200570}
571
572
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300573def installContrailNetwork(master, extra_tgt = '') {
Martin Polreichfc9854c2017-06-30 11:17:36 +0200574 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200575 def salt = new com.mirantis.mk.Salt()
576
577
Jakub Josef79ecec32017-02-17 14:36:28 +0100578 // Install opencontrail database services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300579 salt.enforceState(master, "I@opencontrail:database and *01* ${extra_tgt}", 'opencontrail.database')
580 salt.enforceState(master, "I@opencontrail:database ${extra_tgt}", 'opencontrail.database')
Ales Komarekef2bab62017-04-26 11:48:28 +0200581
Jakub Josef79ecec32017-02-17 14:36:28 +0100582 // Install opencontrail control services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300583 salt.enforceStateWithExclude(master, "I@opencontrail:control and *01* ${extra_tgt}", "opencontrail", "opencontrail.client")
584 salt.enforceStateWithExclude(master, "I@opencontrail:control ${extra_tgt}", "opencontrail", "opencontrail.client")
585 salt.enforceStateWithExclude(master, "I@opencontrail:collector and *01* ${extra_tgt}", "opencontrail", "opencontrail.client")
586 salt.enforceStateWithExclude(master, "I@opencontrail:collector ${extra_tgt}", "opencontrail", "opencontrail.client")
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100587
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300588 if (salt.testTarget(master, "I@docker:client and I@opencontrail:control ${extra_tgt}")) {
589 salt.enforceState(master, "I@opencontrail:control or I@opencontrail:collector ${extra_tgt}", 'docker.client')
Marek Celoud443fb642017-11-22 15:07:12 +0100590 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300591 installBackup(master, 'contrail', extra_tgt)
Jakub Josef79ecec32017-02-17 14:36:28 +0100592}
593
594
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300595def installContrailCompute(master, extra_tgt = '') {
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200596 def salt = new com.mirantis.mk.Salt()
vrovachev32f7f542017-08-25 16:17:25 +0400597 def common = new com.mirantis.mk.Common()
Jakub Josef79ecec32017-02-17 14:36:28 +0100598 // Configure compute nodes
Ales Komarekef2bab62017-04-26 11:48:28 +0200599 // Provision opencontrail control services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300600 salt.enforceState(master, "I@opencontrail:database:id:1 ${extra_tgt}", 'opencontrail.client')
Jakub Josef79ecec32017-02-17 14:36:28 +0100601 // Provision opencontrail virtual routers
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100602
vrovachev4ff77302017-08-09 20:39:57 +0400603 // Generate script /usr/lib/contrail/if-vhost0 for up vhost0
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300604 if (salt.testTarget(master, "I@opencontrail:compute ${extra_tgt}")) {
605 salt.enforceStateWithExclude(master, "I@opencontrail:compute ${extra_tgt}", "opencontrail", "opencontrail.client")
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200606 }
vrovachev4ff77302017-08-09 20:39:57 +0400607
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300608 if (salt.testTarget(master, "I@nova:compute ${extra_tgt}")) {
609 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 +0200610 }
vrovachev4ff77302017-08-09 20:39:57 +0400611
Jakub Josef61463c72018-02-13 16:10:56 +0100612 sleep(300)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300613 if (salt.testTarget(master, "I@opencontrail:compute ${extra_tgt}")) {
614 salt.enforceState(master, "I@opencontrail:compute ${extra_tgt}", 'opencontrail.client')
615 salt.enforceState(master, "I@opencontrail:compute ${extra_tgt}", 'opencontrail')
vrovachev4ff77302017-08-09 20:39:57 +0400616 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100617}
618
619
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300620def installKubernetesInfra(master, extra_tgt = '') {
Jakub Josef432e9d92018-02-06 18:28:37 +0100621 def common = new com.mirantis.mk.Common()
622 common.warningMsg("You calling orchestrate.installKubernetesInfra(). This function is deprecated please use orchestrate.installInfra() directly")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300623 installInfra(master, extra_tgt)
Jakub Josef79ecec32017-02-17 14:36:28 +0100624}
625
626
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300627def installKubernetesControl(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100628 def salt = new com.mirantis.mk.Salt()
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200629
Jakub Josef79ecec32017-02-17 14:36:28 +0100630 // Install Kubernetes pool and Calico
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300631 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes.master.kube-addons')
632 salt.enforceState(master, "I@kubernetes:pool ${extra_tgt}", 'kubernetes.pool')
Jakub Josef79ecec32017-02-17 14:36:28 +0100633
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300634 if (salt.testTarget(master, "I@etcd:server:setup ${extra_tgt}")) {
Marek Celoud029391c2017-11-14 10:06:18 +0100635 // Setup etcd server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300636 salt.enforceState(master, "I@kubernetes:master and *01* ${extra_tgt}", 'etcd.server.setup')
Marek Celoud029391c2017-11-14 10:06:18 +0100637 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100638
Victor Ryzhenkinfb5d1b52018-05-22 18:49:26 +0400639 // Run k8s master at *01* to simplify namespaces creation
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300640 salt.enforceStateWithExclude(master, "I@kubernetes:master and *01* ${extra_tgt}", "kubernetes.master", "kubernetes.master.setup")
Victor Ryzhenkinfb5d1b52018-05-22 18:49:26 +0400641
Jakub Josef79ecec32017-02-17 14:36:28 +0100642 // Run k8s without master.setup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300643 salt.enforceStateWithExclude(master, "I@kubernetes:master ${extra_tgt}", "kubernetes", "kubernetes.master.setup")
Jakub Josef79ecec32017-02-17 14:36:28 +0100644
645 // Run k8s master setup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300646 salt.enforceState(master, "I@kubernetes:master and *01* ${extra_tgt}", 'kubernetes.master.setup')
Jakub Josef79ecec32017-02-17 14:36:28 +0100647
648 // Restart kubelet
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300649 salt.runSaltProcessStep(master, "I@kubernetes:pool ${extra_tgt}", 'service.restart', ['kubelet'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100650}
651
652
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300653def installKubernetesCompute(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200654 def salt = new com.mirantis.mk.Salt()
Jakub Josef432e9d92018-02-06 18:28:37 +0100655 salt.fullRefresh(master, "*")
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200656
657 // Bootstrap all nodes
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300658 salt.enforceState(master, "I@kubernetes:pool ${extra_tgt}", 'linux')
659 salt.enforceState(master, "I@kubernetes:pool ${extra_tgt}", 'salt.minion')
660 salt.enforceState(master, "I@kubernetes:pool ${extra_tgt}", ['openssh', 'ntp'])
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200661
662 // Create and distribute SSL certificates for services using salt state
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300663 salt.enforceState(master, "I@kubernetes:pool ${extra_tgt}", 'salt.minion.cert')
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200664
665 // Install docker
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300666 salt.enforceState(master, "I@docker:host ${extra_tgt}", 'docker.host')
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200667
668 // Install Kubernetes and Calico
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300669 salt.enforceState(master, "I@kubernetes:pool ${extra_tgt}", 'kubernetes.pool')
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200670
Yuriy Taradayab564d72017-10-11 15:14:35 +0400671 // Install Tiller and all configured releases
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300672 if (salt.testTarget(master, "I@helm:client ${extra_tgt}")) {
673 salt.enforceState(master, "I@helm:client ${extra_tgt}", 'helm')
Yuriy Taradayab564d72017-10-11 15:14:35 +0400674 }
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200675}
676
677
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300678def installDockerSwarm(master, extra_tgt = '') {
Martin Polreich8663a342017-06-30 17:33:08 +0200679 def salt = new com.mirantis.mk.Salt()
Jakub Josef79ecec32017-02-17 14:36:28 +0100680
vrovachev1c4770b2017-07-05 13:25:21 +0400681 //Install and Configure Docker
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300682 salt.enforceState(master, "I@docker:swarm ${extra_tgt}", 'docker.host')
683 salt.enforceState(master, "I@docker:swarm:role:master ${extra_tgt}", 'docker.swarm')
684 salt.enforceState(master, "I@docker:swarm ${extra_tgt}", 'salt.minion.grains')
685 salt.runSaltProcessStep(master, "I@docker:swarm ${extra_tgt}", 'mine.update')
686 salt.runSaltProcessStep(master, "I@docker:swarm ${extra_tgt}", 'saltutil.refresh_modules')
Martin Polreich8663a342017-06-30 17:33:08 +0200687 sleep(5)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300688 salt.enforceState(master, "I@docker:swarm:role:master ${extra_tgt}", 'docker.swarm')
689 salt.enforceState(master, "I@docker:swarm:role:manager ${extra_tgt}", 'docker.swarm')
Jakub Josef61463c72018-02-13 16:10:56 +0100690 sleep(10)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300691 salt.cmdRun(master, "I@docker:swarm:role:master ${extra_tgt}", 'docker node ls')
Martin Polreich8663a342017-06-30 17:33:08 +0200692}
693
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200694
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300695def installCicd(master, extra_tgt = '') {
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200696 def salt = new com.mirantis.mk.Salt()
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200697 def common = new com.mirantis.mk.Common()
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300698 def gerrit_compound = "I@gerrit:client and ci* ${extra_tgt}"
699 def jenkins_compound = "I@jenkins:client and ci* ${extra_tgt}"
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200700
701 salt.fullRefresh(master, gerrit_compound)
702 salt.fullRefresh(master, jenkins_compound)
Richard Felkl9d2cd922017-11-03 11:49:32 +0100703
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300704 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 +0200705
706 // API timeout in minutes
707 def wait_timeout = 10
708
709 // Gerrit
710 def gerrit_master_url = salt.getPillar(master, gerrit_compound, '_param:gerrit_master_url')
711
712 if(!gerrit_master_url['return'].isEmpty()) {
713 gerrit_master_url = gerrit_master_url['return'][0].values()[0]
714 } else {
715 gerrit_master_url = ''
716 }
717
718 if (gerrit_master_url != '') {
719 common.infoMsg('Gerrit master url "' + gerrit_master_url + '" retrieved at _param:gerrit_master_url')
720 } else {
721
722 common.infoMsg('Gerrit master url could not be retrieved at _param:gerrit_master_url. Falling back to gerrit pillar')
723
724 def gerrit_host
725 def gerrit_http_port
726 def gerrit_http_scheme
727
728 def host_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:host')
729 gerrit_host = salt.getReturnValues(host_pillar)
730
731 def port_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:http_port')
732 gerrit_http_port = salt.getReturnValues(port_pillar)
733
734 def scheme_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:protocol')
735 gerrit_http_scheme = salt.getReturnValues(scheme_pillar)
736
737 gerrit_master_url = gerrit_http_scheme + '://' + gerrit_host + ':' + gerrit_http_port
738
739 }
740
741 timeout(wait_timeout) {
742 common.infoMsg('Waiting for Gerrit to come up..')
Dzmitry Stremkouski5440ffa2018-05-31 12:00:02 +0200743 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'
744 salt.cmdRun(master, gerrit_compound, 'timeout ' + (wait_timeout*60+3) + ' /bin/sh -c -- ' + '"' + check_gerrit_cmd + '"')
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200745 }
746
747 // Jenkins
748 def jenkins_master_url_pillar = salt.getPillar(master, jenkins_compound, '_param:jenkins_master_url')
749 jenkins_master_url = salt.getReturnValues(jenkins_master_url_pillar)
750
751 timeout(wait_timeout) {
752 common.infoMsg('Waiting for Jenkins to come up..')
Dzmitry Stremkouski5440ffa2018-05-31 12:00:02 +0200753 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'
754 salt.cmdRun(master, jenkins_compound, 'timeout ' + (wait_timeout*60+3) + ' /bin/sh -c -- ' + '"' + check_jenkins_cmd + '"')
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200755 }
Richard Felklc1aba9b2018-01-02 09:25:20 +0100756
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300757 if (salt.testTarget(master, "I@openldap:client ${extra_tgt}")) {
758 salt.enforceState(master, "I@openldap:client ${extra_tgt}", 'openldap', true, true, null, false, -1, 2)
Richard Felklc1aba9b2018-01-02 09:25:20 +0100759 }
Richard Felklb6fdec92017-09-26 10:52:36 +0200760
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300761 if (salt.testTarget(master, "I@python:environment ${extra_tgt}")) {
762 salt.enforceState(master, "I@python:environment ${extra_tgt}", 'python')
Richard Felklb6fdec92017-09-26 10:52:36 +0200763 }
Richard Felklc1aba9b2018-01-02 09:25:20 +0100764
Richard Felkl6e208fc2017-12-08 10:18:44 +0100765 withEnv(['ASK_ON_ERROR=false']){
766 retry(2){
767 try{
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300768 salt.enforceState(master, "I@gerrit:client ${extra_tgt}", 'gerrit')
Richard Felkl6e208fc2017-12-08 10:18:44 +0100769 }catch(e){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300770 salt.fullRefresh(master, "I@gerrit:client ${extra_tgt}")
Richard Felkl6e208fc2017-12-08 10:18:44 +0100771 throw e //rethrow for retry handler
772 }
773 }
774 retry(2){
775 try{
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300776 salt.enforceState(master, "I@jenkins:client ${extra_tgt}", 'jenkins')
Richard Felkl6e208fc2017-12-08 10:18:44 +0100777 }catch(e){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300778 salt.fullRefresh(master, "I@jenkins:client ${extra_tgt}")
Richard Felkl6e208fc2017-12-08 10:18:44 +0100779 throw e //rethrow for retry handler
780 }
781 }
782 }
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200783}
784
785
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300786def installStacklight(master, extra_tgt = '') {
Martin Polreich8663a342017-06-30 17:33:08 +0200787 def common = new com.mirantis.mk.Common()
788 def salt = new com.mirantis.mk.Salt()
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200789 def retries_wait = 20
790 def retries = 15
Martin Polreich8663a342017-06-30 17:33:08 +0200791
Simon Pasquieref4122c2017-08-25 15:52:07 +0200792 // Install core services for K8S environments:
793 // HAProxy, Nginx and lusterFS clients
794 // In case of OpenStack, those are already installed
Martin Polreich792f2662017-07-11 13:36:32 +0200795 if (common.checkContains('STACK_INSTALL', 'k8s')) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300796 salt.enforceState(master, "I@haproxy:proxy ${extra_tgt}", 'haproxy')
797 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.status', ['haproxy'])
Simon Pasquieref4122c2017-08-25 15:52:07 +0200798
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300799 if (salt.testTarget(master, "I@nginx:server ${extra_tgt}")) {
800 salt.enforceState(master, "I@nginx:server ${extra_tgt}", 'nginx')
Simon Pasquieref4122c2017-08-25 15:52:07 +0200801 }
802
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300803 if (salt.testTarget(master, "I@glusterfs:client ${extra_tgt}")) {
804 salt.enforceState(master, "I@glusterfs:client ${extra_tgt}", 'glusterfs.client', true, true, null, false, -1, 2)
Simon Pasquieref4122c2017-08-25 15:52:07 +0200805 }
Martin Polreich792f2662017-07-11 13:36:32 +0200806 }
Jiri Broulike57a0242017-10-06 13:38:47 +0200807
Dmitry Kalashnik69ecb782018-05-21 17:36:50 +0400808 // Install MongoDB for Alerta
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300809 if (salt.testTarget(master, "I@mongodb:server ${extra_tgt}")) {
810 salt.enforceState(master, "I@mongodb:server ${extra_tgt}", 'mongodb.server')
Ildar Svetlov829f94a2018-06-05 17:57:08 +0400811
812 // Initialize mongodb replica set
813 common.retry(5,20){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300814 salt.enforceState(master, "I@mongodb:server ${extra_tgt}", 'mongodb.cluster')
Ildar Svetlov829f94a2018-06-05 17:57:08 +0400815 }
Dmitry Kalashnik69ecb782018-05-21 17:36:50 +0400816 }
817
Martin Polreich8663a342017-06-30 17:33:08 +0200818 //Install Telegraf
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300819 salt.enforceState(master, "I@telegraf:agent or I@telegraf:remote_agent ${extra_tgt}", 'telegraf')
Martin Polreich8663a342017-06-30 17:33:08 +0200820
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400821 // Install Prometheus exporters
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300822 if (salt.testTarget(master, "I@prometheus:exporters ${extra_tgt}")) {
823 salt.enforceState(master, "I@prometheus:exporters ${extra_tgt}", 'prometheus')
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400824 }
825
Martin Polreich8663a342017-06-30 17:33:08 +0200826 //Install Elasticsearch and Kibana
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300827 salt.enforceState(master, "*01* and I@elasticsearch:server ${extra_tgt}", 'elasticsearch.server')
828 salt.enforceState(master, "I@elasticsearch:server ${extra_tgt}", 'elasticsearch.server')
829 salt.enforceState(master, "*01* and I@kibana:server ${extra_tgt}", 'kibana.server')
830 salt.enforceState(master, "I@kibana:server ${extra_tgt}", 'kibana.server')
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200831
832 // Check ES health cluster status
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300833 def pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:host')
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200834 def elasticsearch_vip
835 if(!pillar['return'].isEmpty()) {
836 elasticsearch_vip = pillar['return'][0].values()[0]
837 } else {
838 common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved')
839 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300840 pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:port')
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200841 def elasticsearch_port
842 if(!pillar['return'].isEmpty()) {
843 elasticsearch_port = pillar['return'][0].values()[0]
844 } else {
845 common.errorMsg('[ERROR] Elasticsearch VIP port could not be retrieved')
846 }
847 common.retry(retries,retries_wait) {
848 common.infoMsg('Waiting for Elasticsearch to become green..')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300849 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 +0200850 }
851
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200852 common.retry(retries,retries_wait) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300853 salt.enforceState(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch.client')
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200854 }
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200855
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200856 common.retry(retries,retries_wait) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300857 salt.enforceState(master, "I@kibana:client ${extra_tgt}", 'kibana.client')
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200858 }
Dmitry Kalashnik53feda72018-03-16 16:06:10 +0400859
860 //Install InfluxDB
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300861 if (salt.testTarget(master, "I@influxdb:server ${extra_tgt}")) {
862 salt.enforceState(master, "*01* and I@influxdb:server ${extra_tgt}", 'influxdb')
863 salt.enforceState(master, "I@influxdb:server ${extra_tgt}", 'influxdb')
Dmitry Kalashnik53feda72018-03-16 16:06:10 +0400864 }
865
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400866 // Install service for the log collection
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300867 if (salt.testTarget(master, "I@fluentd:agent ${extra_tgt}")) {
868 salt.enforceState(master, "I@fluentd:agent ${extra_tgt}", 'fluentd')
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400869 } else {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300870 salt.enforceState(master, "I@heka:log_collector ${extra_tgt}", 'heka.log_collector')
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400871 }
Simon Pasquier6301ddd2017-09-05 11:56:58 +0200872
Ondrej Smola5908ae62018-01-08 13:42:08 +0100873 // Install heka ceilometer collector
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300874 if (salt.testTarget(master, "I@heka:ceilometer_collector:enabled ${extra_tgt}")) {
875 salt.enforceState(master, "I@heka:ceilometer_collector:enabled ${extra_tgt}", 'heka.ceilometer_collector')
876 salt.runSaltProcessStep(master, "I@heka:ceilometer_collector:enabled ${extra_tgt}", 'service.restart', ['ceilometer_collector'], null, true)
Ondrej Smola5908ae62018-01-08 13:42:08 +0100877 }
878
Martin Polreich470925a2017-07-06 17:12:59 +0200879 // Install galera
Martin Polreich792f2662017-07-11 13:36:32 +0200880 if (common.checkContains('STACK_INSTALL', 'k8s')) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300881 salt.enforceState(master, "I@galera:master ${extra_tgt}", 'galera', true, true, null, false, -1, 2)
882 salt.enforceState(master, "I@galera:slave ${extra_tgt}", 'galera', true, true, null, false, -1, 2)
Martin Polreich406f6462017-07-11 11:33:42 +0000883
Martin Polreich792f2662017-07-11 13:36:32 +0200884 // Check galera status
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300885 salt.runSaltProcessStep(master, "I@galera:master ${extra_tgt}", 'mysql.status')
886 salt.runSaltProcessStep(master, "I@galera:slave ${extra_tgt}", 'mysql.status')
Martin Polreich792f2662017-07-11 13:36:32 +0200887 }
Martin Polreich470925a2017-07-06 17:12:59 +0200888
Martin Polreich8663a342017-06-30 17:33:08 +0200889 //Collect Grains
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300890 salt.enforceState(master, "I@salt:minion ${extra_tgt}", 'salt.minion.grains')
891 salt.runSaltProcessStep(master, "I@salt:minion ${extra_tgt}", 'saltutil.refresh_modules')
892 salt.runSaltProcessStep(master, "I@salt:minion ${extra_tgt}", 'mine.update')
Martin Polreich8663a342017-06-30 17:33:08 +0200893 sleep(5)
894
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400895 // Configure Prometheus in Docker Swarm
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300896 salt.enforceState(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}", 'prometheus')
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400897
Ildar Svetlov0eec97d2018-02-15 10:06:40 +0400898 //Configure Remote Collector in Docker Swarm for Openstack deployments
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400899 if (!common.checkContains('STACK_INSTALL', 'k8s')) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300900 salt.enforceState(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}", 'heka.remote_collector', true, false)
Martin Polreich8017f452017-08-21 16:01:42 +0200901 }
Martin Polreich8663a342017-06-30 17:33:08 +0200902
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400903 // Launch containers
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300904 salt.enforceState(master, "I@docker:swarm:role:master and I@prometheus:server ${extra_tgt}", 'docker.client')
905 salt.runSaltProcessStep(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}", 'dockerng.ps')
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400906
907 //Install Prometheus LTS
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300908 if (salt.testTarget(master, "I@prometheus:relay ${extra_tgt}")) {
909 salt.enforceState(master, "I@prometheus:relay ${extra_tgt}", 'prometheus')
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400910 }
911
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100912 // Install sphinx server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300913 if (salt.testTarget(master, "I@sphinx:server ${extra_tgt}")) {
914 salt.enforceState(master, "I@sphinx:server ${extra_tgt}", 'sphinx')
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100915 }
916
Martin Polreich8663a342017-06-30 17:33:08 +0200917 //Configure Grafana
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300918 pillar = salt.getPillar(master, "ctl01* ${extra_tgt}", '_param:stacklight_monitor_address')
Martin Polreich8663a342017-06-30 17:33:08 +0200919 common.prettyPrint(pillar)
Martin Polreich595baef2017-07-04 16:11:04 +0200920
Martin Polreich8663a342017-06-30 17:33:08 +0200921 def stacklight_vip
922 if(!pillar['return'].isEmpty()) {
923 stacklight_vip = pillar['return'][0].values()[0]
924 } else {
925 common.errorMsg('[ERROR] Stacklight VIP address could not be retrieved')
926 }
vrovachev1c4770b2017-07-05 13:25:21 +0400927
Martin Polreich305e2222017-07-06 11:33:00 +0200928 common.infoMsg("Waiting for service on http://${stacklight_vip}:15013/ to start")
Martin Polreichbd7ad222017-07-06 12:53:51 +0200929 sleep(120)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300930 salt.enforceState(master, "I@grafana:client ${extra_tgt}", 'grafana.client')
Martin Polreich8663a342017-06-30 17:33:08 +0200931}
932
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300933def installStacklightv1Control(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200934 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200935
936 // infra install
937 // Install the StackLight backends
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300938 salt.enforceState(master, "*01* and I@elasticsearch:server ${extra_tgt}", 'elasticsearch.server')
939 salt.enforceState(master, "I@elasticsearch:server ${extra_tgt}", 'elasticsearch.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200940
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300941 salt.enforceState(master, "*01* and I@influxdb:server ${extra_tgt}", 'influxdb')
942 salt.enforceState(master, "I@influxdb:server ${extra_tgt}", 'influxdb')
Ales Komarekef2bab62017-04-26 11:48:28 +0200943
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300944 salt.enforceState(master, "*01* and I@kibana:server ${extra_tgt}", 'kibana.server')
945 salt.enforceState(master, "I@kibana:server ${extra_tgt}", 'kibana.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200946
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300947 salt.enforceState(master, "*01* and I@grafana:server ${extra_tgt}",'grafana.server')
948 salt.enforceState(master, "I@grafana:server ${extra_tgt}",'grafana.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200949
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300950 def alarming_service_pillar = salt.getPillar(master, "mon*01* ${extra_tgt}", '_param:alarming_service')
Kalynovskyi3e370112017-06-26 12:48:23 +0300951 def alarming_service = alarming_service_pillar['return'][0].values()[0]
952
953 switch (alarming_service) {
954 case 'sensu':
955 // Update Sensu
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300956 salt.enforceState(master, "I@sensu:server and I@rabbitmq:server ${extra_tgt}", 'rabbitmq')
957 salt.enforceState(master, "I@redis:cluster:role:master ${extra_tgt}", 'redis')
958 salt.enforceState(master, "I@redis:server ${extra_tgt}", 'redis')
959 salt.enforceState(master, "I@sensu:server ${extra_tgt}", 'sensu')
Kalynovskyi3e370112017-06-26 12:48:23 +0300960 default:
961 // Update Nagios
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300962 salt.enforceState(master, "I@nagios:server ${extra_tgt}", 'nagios.server')
Kalynovskyi3e370112017-06-26 12:48:23 +0300963 // Stop the Nagios service because the package starts it by default and it will
964 // started later only on the node holding the VIP address
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300965 salt.runSaltProcessStep(master, "I@nagios:server ${extra_tgt}", 'service.stop', ['nagios3'], null, true)
Kalynovskyi3e370112017-06-26 12:48:23 +0300966 }
967
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300968 salt.enforceState(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch.client.service')
969 salt.enforceState(master, "I@kibana:client ${extra_tgt}", 'kibana.client')
Ales Komarekef2bab62017-04-26 11:48:28 +0200970
971 sleep(10)
972}
973
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300974def installStacklightv1Client(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200975 def salt = new com.mirantis.mk.Salt()
976 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200977
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300978 salt.cmdRun(master, "I@elasticsearch:client ${extra_tgt}", 'salt-call state.sls elasticsearch.client')
979 // salt.enforceState(master, "I@elasticsearch:client", 'elasticsearch.client", true)
980 salt.cmdRun(master, "I@kibana:client ${extra_tgt}", 'salt-call state.sls kibana.client')
981 // salt.enforceState(master, "I@kibana:client", 'kibana.client", true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200982
983 // Install collectd, heka and sensu services on the nodes, this will also
984 // generate the metadata that goes into the grains and eventually into Salt Mine
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300985 salt.enforceState(master, "* ${extra_tgt}", 'collectd')
986 salt.enforceState(master, "* ${extra_tgt}", 'salt.minion')
987 salt.enforceState(master, "* ${extra_tgt}", 'heka')
Ales Komarekef2bab62017-04-26 11:48:28 +0200988
989 // Gather the Grafana metadata as grains
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300990 salt.enforceState(master, "I@grafana:collector ${extra_tgt}", 'grafana.collector', true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200991
992 // Update Salt Mine
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300993 salt.enforceState(master, "* ${extra_tgt}", 'salt.minion.grains')
994 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'saltutil.refresh_modules')
995 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'mine.update')
Ales Komarekef2bab62017-04-26 11:48:28 +0200996
997 sleep(5)
998
999 // Update Heka
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001000 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 +02001001
1002 // Update collectd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001003 salt.enforceState(master, "I@collectd:remote_client:enabled:True ${extra_tgt}", 'collectd')
Ales Komarekef2bab62017-04-26 11:48:28 +02001004
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001005 def alarming_service_pillar = salt.getPillar(master, "mon*01* ${extra_tgt}", '_param:alarming_service')
Kalynovskyi3e370112017-06-26 12:48:23 +03001006 def alarming_service = alarming_service_pillar['return'][0].values()[0]
Ales Komarekef2bab62017-04-26 11:48:28 +02001007
Kalynovskyi3e370112017-06-26 12:48:23 +03001008 switch (alarming_service) {
1009 case 'sensu':
1010 // Update Sensu
1011 // TODO for stacklight team, should be fixed in model
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001012 salt.enforceState(master, "I@sensu:client ${extra_tgt}", 'sensu')
Kalynovskyi3e370112017-06-26 12:48:23 +03001013 default:
1014 break
1015 // Default is nagios, and was enforced in installStacklightControl()
1016 }
Ales Komarekef2bab62017-04-26 11:48:28 +02001017
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001018 salt.cmdRun(master, "I@grafana:client and *01* ${extra_tgt}", 'salt-call state.sls grafana.client')
1019 // salt.enforceState(master, "I@grafana:client and *01*", 'grafana.client", true)
Ales Komarekef2bab62017-04-26 11:48:28 +02001020
Marek Celoudd200cad2017-06-07 10:34:46 +02001021 // Finalize the configuration of Grafana (add the dashboards...)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001022 salt.enforceState(master, "I@grafana:client and *01* ${extra_tgt}", 'grafana.client')
1023 salt.enforceState(master, "I@grafana:client and *02* ${extra_tgt}", 'grafana.client')
1024 salt.enforceState(master, "I@grafana:client and *03* ${extra_tgt}", 'grafana.client')
1025 // nw salt -C "I@grafana:client' --async service.restart salt-minion; sleep 10
Marek Celoudd200cad2017-06-07 10:34:46 +02001026
Ales Komarekef2bab62017-04-26 11:48:28 +02001027 // Get the StackLight monitoring VIP addres
1028 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
1029 //vip=${vip:=172.16.10.253}
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001030 def pillar = salt.getPillar(master, "ctl01* ${extra_tgt}", '_param:stacklight_monitor_address')
Jakub Josefbceaa322017-06-13 18:28:27 +02001031 common.prettyPrint(pillar)
Ales Komarekef2bab62017-04-26 11:48:28 +02001032 def stacklight_vip = pillar['return'][0].values()[0]
1033
1034 if (stacklight_vip) {
1035 // (re)Start manually the services that are bound to the monitoring VIP
1036 common.infoMsg("restart services on node with IP: ${stacklight_vip}")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001037 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['remote_collectd'])
1038 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['remote_collector'])
1039 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['aggregator'])
1040 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['nagios3'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001041 } else {
1042 throw new Exception("Missing stacklight_vip")
1043 }
Tomáš Kukrálf06ca0f2017-02-27 15:18:50 +01001044}
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001045
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001046//
1047// backups
1048//
1049
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001050def installBackup(master, component='common', extra_tgt = '') {
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001051 def salt = new com.mirantis.mk.Salt()
1052 if (component == 'common') {
1053 // Install Backupninja
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001054 if (salt.testTarget(master, "I@backupninja:client ${extra_tgt}")) {
1055 salt.enforceState(master, "I@backupninja:client ${extra_tgt}", 'salt.minion.grains')
1056 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'saltutil.sync_grains')
1057 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'mine.flush')
1058 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'mine.update')
1059 salt.enforceState(master, "I@backupninja:client ${extra_tgt}", 'backupninja')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001060 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001061 if (salt.testTarget(master, "I@backupninja:server ${extra_tgt}")) {
1062 salt.enforceState(master, "I@backupninja:server ${extra_tgt}", 'salt.minion.grains')
1063 salt.enforceState(master, "I@backupninja:server ${extra_tgt}", 'backupninja')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001064 }
1065 } else if (component == 'mysql') {
1066 // Install Xtrabackup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001067 if (salt.testTarget(master, "I@xtrabackup:client ${extra_tgt}")) {
1068 salt.enforceState(master, "I@xtrabackup:client ${extra_tgt}", 'salt.minion.grains')
1069 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'saltutil.sync_grains')
1070 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'mine.flush')
1071 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'mine.update')
1072 salt.enforceState(master, "I@xtrabackup:client ${extra_tgt}", 'xtrabackup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001073 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001074 if (salt.testTarget(master, "I@xtrabackup:server ${extra_tgt}")) {
1075 salt.enforceState(master, "I@xtrabackup:server ${extra_tgt}", 'xtrabackup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001076 }
1077 } else if (component == 'contrail') {
1078
1079 // Install Cassandra backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001080 if (salt.testTarget(master, "I@cassandra:backup:client ${extra_tgt}")) {
1081 salt.enforceState(master, "I@cassandra:backup:client ${extra_tgt}", 'salt.minion.grains')
1082 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1083 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'mine.flush')
1084 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'mine.update')
1085 salt.enforceState(master, "I@cassandra:backup:client ${extra_tgt}", 'cassandra.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001086 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001087 if (salt.testTarget(master, "I@cassandra:backup:server ${extra_tgt}")) {
1088 salt.enforceState(master, "I@cassandra:backup:server ${extra_tgt}", 'cassandra.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001089 }
1090 // Install Zookeeper backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001091 if (salt.testTarget(master, "I@zookeeper:backup:client ${extra_tgt}")) {
1092 salt.enforceState(master, "I@zookeeper:backup:client ${extra_tgt}", 'salt.minion.grains')
1093 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1094 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'mine.flush')
1095 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'mine.update')
1096 salt.enforceState(master, "I@zookeeper:backup:client ${extra_tgt}", 'zookeeper.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001097 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001098 if (salt.testTarget(master, "I@zookeeper:backup:server ${extra_tgt}")) {
1099 salt.enforceState(master, "I@zookeeper:backup:server ${extra_tgt}", 'zookeeper.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001100 }
1101 } else if (component == 'ceph') {
1102 // Install Ceph backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001103 if (salt.testTarget(master, "I@ceph:backup:client ${extra_tgt}")) {
1104 salt.enforceState(master, "I@ceph:backup:client ${extra_tgt}", 'salt.minion.grains')
1105 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1106 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'mine.flush')
1107 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'mine.update')
1108 salt.enforceState(master, "I@ceph:backup:client ${extra_tgt}", 'ceph.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001109 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001110 if (salt.testTarget(master, "I@ceph:backup:server ${extra_tgt}")) {
1111 salt.enforceState(master, "I@ceph:backup:server ${extra_tgt}", 'ceph.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001112 }
1113 }
1114
1115}
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001116
1117//
1118// Ceph
1119//
1120
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001121def installCephMon(master, target="I@ceph:mon", extra_tgt = '') {
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001122 def salt = new com.mirantis.mk.Salt()
1123
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001124 salt.enforceState(master, "I@ceph:common ${extra_tgt}", 'salt.minion.grains')
Jiri Broulikbfc234f2017-10-17 15:45:38 +02001125
Jiri Broulike57a0242017-10-06 13:38:47 +02001126 // generate keyrings
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001127 if (salt.testTarget(master, "I@ceph:mon:keyring:mon ${extra_tgt} or I@ceph:common:keyring:admin ${extra_tgt}")) {
1128 salt.enforceState(master, "I@ceph:mon:keyring:mon ${extra_tgt} or I@ceph:common:keyring:admin ${extra_tgt}", 'ceph.mon')
1129 salt.runSaltProcessStep(master, "I@ceph:mon ${extra_tgt}", 'saltutil.sync_grains')
1130 salt.runSaltProcessStep(master, "I@ceph:mon:keyring:mon ${extra_tgt} or I@ceph:common:keyring:admin ${extra_tgt}", 'mine.update')
Jiri Broulik3c75a6d2017-10-06 18:44:37 +02001131 sleep(5)
Jiri Broulike57a0242017-10-06 13:38:47 +02001132 }
Ondrej Smolafd5c2352017-08-11 14:25:39 +02001133 // install Ceph Mons
Jakub Josef432e9d92018-02-06 18:28:37 +01001134 salt.enforceState(master, target, 'ceph.mon')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001135 if (salt.testTarget(master, "I@ceph:mgr ${extra_tgt}")) {
1136 salt.enforceState(master, "I@ceph:mgr ${extra_tgt}", 'ceph.mgr')
Jiri Broulike57a0242017-10-06 13:38:47 +02001137 }
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001138}
1139
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001140def installCephOsd(master, target="I@ceph:osd", setup=true, extra_tgt = '') {
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001141 def salt = new com.mirantis.mk.Salt()
1142
1143 // install Ceph OSDs
Jakub Josef432e9d92018-02-06 18:28:37 +01001144 salt.enforceState(master, target, 'ceph.osd')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001145 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'saltutil.sync_grains')
Jakub Josef432e9d92018-02-06 18:28:37 +01001146 salt.enforceState(master, target, 'ceph.osd.custom')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001147 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'saltutil.sync_grains')
1148 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'mine.update')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001149 installBackup(master, 'ceph')
Tomáš Kukráled27a472017-08-29 10:26:25 +02001150
Jiri Broulike57a0242017-10-06 13:38:47 +02001151 // setup pools, keyrings and maybe crush
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001152 if (salt.testTarget(master, "I@ceph:setup ${extra_tgt}") && setup) {
Jiri Broulik07f8de72017-10-09 14:12:17 +02001153 sleep(5)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001154 salt.enforceState(master, "I@ceph:setup ${extra_tgt}", 'ceph.setup')
Tomáš Kukráled27a472017-08-29 10:26:25 +02001155 }
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001156}
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001157
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001158def installCephClient(master, extra_tgt = '') {
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001159 def salt = new com.mirantis.mk.Salt()
1160
1161 // install Ceph Radosgw
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001162 if (salt.testTarget(master, "I@ceph:radosgw ${extra_tgt}")) {
1163 salt.runSaltProcessStep(master, "I@ceph:radosgw ${extra_tgt}", 'saltutil.sync_grains')
1164 salt.enforceState(master, "I@ceph:radosgw ${extra_tgt}", 'ceph.radosgw')
Alexander Noskov229035f2017-12-06 00:10:20 +04001165 }
1166 // setup Keystone service and endpoints for swift or / and S3
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001167 if (salt.testTarget(master, "I@keystone:client ${extra_tgt}")) {
1168 salt.enforceState(master, "I@keystone:client ${extra_tgt}", 'keystone.client')
Tomáš Kukrál5836e3d2017-08-25 18:20:55 +02001169 }
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001170}
Jiri Broulike57a0242017-10-06 13:38:47 +02001171
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001172def connectCeph(master, extra_tgt = '') {
Jiri Broulike57a0242017-10-06 13:38:47 +02001173 def salt = new com.mirantis.mk.Salt()
1174
1175 // connect Ceph to the env
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001176 if (salt.testTarget(master, "I@ceph:common and I@glance:server ${extra_tgt}")) {
1177 salt.enforceState(master, "I@ceph:common and I@glance:server ${extra_tgt}", ['ceph.common', 'ceph.setup.keyring', 'glance'])
1178 salt.runSaltProcessStep(master, "I@ceph:common and I@glance:server ${extra_tgt}", 'service.restart', ['glance-api'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001179 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001180 if (salt.testTarget(master, "I@ceph:common and I@cinder:controller ${extra_tgt}")) {
1181 salt.enforceState(master, "I@ceph:common and I@cinder:controller ${extra_tgt}", ['ceph.common', 'ceph.setup.keyring', 'cinder'])
1182 salt.runSaltProcessStep(master, "I@ceph:common and I@cinder:controller ${extra_tgt}", 'service.restart', ['cinder-volume'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001183 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001184 if (salt.testTarget(master, "I@ceph:common and I@nova:compute ${extra_tgt}")) {
1185 salt.enforceState(master, "I@ceph:common and I@nova:compute ${extra_tgt}", ['ceph.common', 'ceph.setup.keyring'])
1186 salt.runSaltProcessStep(master, "I@ceph:common and I@nova:compute ${extra_tgt}", 'saltutil.sync_grains')
1187 salt.enforceState(master, "I@ceph:common and I@nova:compute ${extra_tgt}", ['nova'])
1188 salt.runSaltProcessStep(master, "I@ceph:common and I@nova:compute ${extra_tgt}", 'service.restart', ['nova-compute'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001189 }
1190}
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
Mikhail Ivanov788996c2017-12-15 14:28:57 +04001196 if (!common.checkContains('STACK_INSTALL', 'k8s') || !common.checkContains('STACK_INSTALL', 'openstack')) {
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001197 def orchestrate = new com.mirantis.mk.Orchestrate()
1198 orchestrate.installInfra(master)
1199 }
1200
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001201 if (salt.testTarget(master, "I@devops_portal:config ${extra_tgt}")) {
1202 salt.enforceState(master, "I@devops_portal:config ${extra_tgt}", 'devops_portal.config')
1203 salt.enforceState(master, "I@rundeck:client ${extra_tgt}", ['linux.system.user', 'openssh'])
1204 salt.enforceState(master, "I@rundeck:server ${extra_tgt}", 'rundeck.server')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001205 }
1206}
1207
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001208def installOss(master, extra_tgt = '') {
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001209 def common = new com.mirantis.mk.Common()
1210 def salt = new com.mirantis.mk.Salt()
1211
1212 //Get oss VIP address
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001213 def pillar = salt.getPillar(master, "cfg01* ${extra_tgt}", '_param:stacklight_monitor_address')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001214 common.prettyPrint(pillar)
1215
1216 def oss_vip
1217 if(!pillar['return'].isEmpty()) {
1218 oss_vip = pillar['return'][0].values()[0]
1219 } else {
1220 common.errorMsg('[ERROR] Oss VIP address could not be retrieved')
1221 }
1222
1223 // Postgres client - initialize OSS services databases
1224 timeout(120){
1225 common.infoMsg("Waiting for postgresql database to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001226 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 +04001227 }
1228 // XXX: first run usually fails on some inserts, but we need to create databases at first
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001229 salt.enforceState(master, "I@postgresql:client ${extra_tgt}", 'postgresql.client', true, false)
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001230
1231 // Setup postgres database with integration between
1232 // Pushkin notification service and Security Monkey security audit service
1233 timeout(10) {
1234 common.infoMsg("Waiting for Pushkin to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001235 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 +04001236 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001237 salt.enforceState(master, "I@postgresql:client ${extra_tgt}", 'postgresql.client')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001238
1239 // Rundeck
1240 timeout(10) {
1241 common.infoMsg("Waiting for Rundeck to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001242 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 +04001243 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001244 salt.enforceState(master, "I@rundeck:client ${extra_tgt}", 'rundeck.client')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001245
1246 // Elasticsearch
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001247 pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:host')
Mikhail Ivanovfcd55d62017-12-19 16:51:35 +04001248 def elasticsearch_vip
1249 if(!pillar['return'].isEmpty()) {
1250 elasticsearch_vip = pillar['return'][0].values()[0]
1251 } else {
1252 common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved')
1253 }
1254
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001255 timeout(10) {
1256 common.infoMsg('Waiting for Elasticsearch to come up..')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001257 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 +04001258 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001259 salt.enforceState(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch.client')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001260}