blob: 1157083bcd7519733416f26785ed527e81f242f2 [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 }
Ondrej Smola855dc1a2018-07-18 13:07:55 +020051 common.retry(2,5){
52 salt.enforceState(master, "I@linux:network:interface ${extra_tgt}", ['linux.network.interface'])
53 }
Jiri Broulik94538462018-05-11 15:45:13 +020054 sleep(5)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030055 salt.enforceState(master, "I@linux:system ${extra_tgt}", ['linux', 'openssh', 'ntp', 'rsyslog'])
56 salt.enforceState(master, "* ${extra_tgt}", ['salt.minion'], true, false, null, false, 60, 2)
Jakub Josef4f8f4df2017-09-01 14:32:42 +020057 sleep(5)
Victor Ryzhenkinf610c572018-05-15 15:22:52 +040058
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030059 salt.fullRefresh(master, "* ${extra_tgt}")
60 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'mine.update', [], null, true)
61 salt.enforceState(master, "* ${extra_tgt}", ['linux.network.host'])
Ivan Suzdal9a6bc392018-04-26 18:29:56 +040062
63 // Install and configure iptables
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030064 if (salt.testTarget(master, "I@iptables:service ${extra_tgt}")) {
65 salt.enforceState(master, "I@iptables:service ${extra_tgt}", 'iptables')
Ivan Suzdal9a6bc392018-04-26 18:29:56 +040066 }
sgarbuzbb61e812018-05-03 16:58:40 +030067
68 // Install and configure logrotate
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030069 if (salt.testTarget(master, "I@logrotate:server ${extra_tgt}")) {
70 salt.enforceState(master, "I@logrotate:server ${extra_tgt}", 'logrotate')
sgarbuzbb61e812018-05-03 16:58:40 +030071 }
Ivan Suzdal9f8f0e12018-06-21 13:16:21 +040072
73 // Install and configure auditd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030074 if (salt.testTarget(master, "I@auditd:service ${extra_tgt}")) {
75 salt.enforceState(master, "I@auditd:service ${extra_tgt}", 'auditd')
Ivan Suzdal9f8f0e12018-06-21 13:16:21 +040076 }
Ivan Suzdalca980912018-08-02 09:35:07 +040077
78 // Install and configure openscap
79 if (salt.testTarget(master, "I@openscap:service ${extra_tgt}")) {
80 salt.enforceState(master, "I@openscap:service ${extra_tgt}", 'openscap')
81 }
Jakub Josef79ecec32017-02-17 14:36:28 +010082}
83
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030084def installFoundationInfraOnTarget(master, target, staticMgmtNet=false, extra_tgt = '') {
Jiri Broulik976bf6c2017-10-20 14:43:25 +020085 def salt = new com.mirantis.mk.Salt()
Jiri Broulik9fb138a2018-04-23 17:13:00 +020086 def common = new com.mirantis.mk.Common()
Jiri Broulik976bf6c2017-10-20 14:43:25 +020087
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030088 salt.enforceState(master, "I@salt:master ${extra_tgt}", ['reclass'], true, false, null, false, 120, 2)
Jakub Josef432e9d92018-02-06 18:28:37 +010089 salt.fullRefresh(master, target)
Ondrej Smolaa9b84662018-04-18 11:22:19 +020090 salt.enforceState(master, target, ['linux.network.proxy'], true, false, null, false, 60, 2)
Jiri Broulik94fc2592018-04-20 13:47:51 +020091 try {
92 salt.enforceState(master, target, ['salt.minion.base'], true, false, null, false, 60, 2)
93 sleep(5)
94 } catch (Throwable e) {
95 common.warningMsg('Salt state salt.minion.base is not present in the Salt-formula yet.')
96 }
Jiri Broulike3ace622018-06-07 10:51:02 +020097 common.retry(2,5){
98 salt.enforceState(master, target, ['linux.system'])
99 }
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +0100100 if (staticMgmtNet) {
101 salt.runSaltProcessStep(master, target, 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], null, true, 60)
102 }
Jiri Broulik976bf6c2017-10-20 14:43:25 +0200103 salt.enforceState(master, target, ['salt.minion'], true, false, null, false, 60, 2)
Jakub Josef432e9d92018-02-06 18:28:37 +0100104 salt.enforceState(master, target, ['salt.minion'])
Jiri Broulik3740fb92018-04-27 11:52:38 +0200105 salt.enforceState(master, target, ['linux.network.interface'])
Jiri Broulik94538462018-05-11 15:45:13 +0200106 sleep(5)
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100107 salt.enforceState(master, target, ['linux', 'openssh', 'ntp', 'rsyslog'])
Jiri Broulik976bf6c2017-10-20 14:43:25 +0200108 sleep(5)
Victor Ryzhenkinf610c572018-05-15 15:22:52 +0400109
110 salt.fullRefresh(master, target)
vrovachevc4424a32018-03-15 17:35:57 +0400111 salt.runSaltProcessStep(master, target, 'mine.update', [], null, true)
Jakub Josef432e9d92018-02-06 18:28:37 +0100112 salt.enforceState(master, target, ['linux.network.host'])
Jiri Broulik976bf6c2017-10-20 14:43:25 +0200113}
114
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300115def installInfraKvm(master, extra_tgt = '') {
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200116 def common = new com.mirantis.mk.Common()
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +0100117 def salt = new com.mirantis.mk.Salt()
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300118 def infra_compound = "I@salt:control ${extra_tgt}"
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200119 def minions = []
120 def wait_timeout = 10
121 def retries = wait_timeout * 30
Ales Komarekef2bab62017-04-26 11:48:28 +0200122
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300123 salt.fullRefresh(master, "I@linux:system ${extra_tgt}")
124 salt.enforceState(master, "I@salt:control ${extra_tgt}", ['salt.minion'], true, false, null, false, 60, 2)
125 salt.enforceState(master, "I@salt:control ${extra_tgt}", ['linux.system', 'linux.network', 'ntp', 'rsyslog'])
126 salt.enforceState(master, "I@salt:control ${extra_tgt}", 'libvirt')
127 salt.enforceState(master, "I@salt:control ${extra_tgt}", 'salt.control')
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100128
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200129 common.infoMsg("Building minions list...")
130 if (salt.testTarget(master, infra_compound)) {
131 // Gathering minions
132 for ( infra_node in salt.getMinionsSorted(master, infra_compound) ) {
133 def pillar = salt.getPillar(master, infra_node, 'salt:control:cluster')
134 if ( !pillar['return'].isEmpty() ) {
135 for ( cluster in pillar['return'][0].values() ) {
136 def engine = cluster.values()[0]['engine']
137 def domain = cluster.values()[0]['domain']
138 def node = cluster.values()[0]['node']
139 if ( engine == "virt" ) {
140 def nodes = node.values()
141 if ( !nodes.isEmpty() ) {
142 for ( vm in nodes ) {
143 if ( vm['name'] != null ) {
144 def vm_fqdn = vm['name'] + '.' + domain
145 if ( !minions.contains(vm_fqdn) ) {
146 minions.add(vm_fqdn)
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200147 }
148 }
149 }
150 }
151 }
152 }
153 }
154 }
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200155 }
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100156
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200157 def minions_compound = minions.join(' or ')
158
159 common.infoMsg("Waiting for next minions to register within ${wait_timeout} minutes: " + minions_compound)
160 timeout(time: wait_timeout, unit: 'MINUTES') {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300161 salt.minionsPresentFromList(master, "I@salt:master ${extra_tgt}", minions, true, null, true, retries, 1)
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200162 }
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200163
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200164 common.infoMsg('Waiting for minions to respond')
165 timeout(time: wait_timeout, unit: 'MINUTES') {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300166 salt.minionsReachable(master, "I@salt:master ${extra_tgt}", minions_compound)
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200167 }
168
169 common.infoMsg("All minions are up.")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300170 salt.fullRefresh(master, "* and not kvm* ${extra_tgt}")
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200171
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +0100172}
Jakub Josef79ecec32017-02-17 14:36:28 +0100173
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300174def installInfra(master, extra_tgt = '') {
Jakub Josef61463c72018-02-13 16:10:56 +0100175 def common = new com.mirantis.mk.Common()
Jakub Josef79ecec32017-02-17 14:36:28 +0100176 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200177
Jakub Josef79ecec32017-02-17 14:36:28 +0100178 // Install glusterfs
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300179 if (salt.testTarget(master, "I@glusterfs:server ${extra_tgt}")) {
180 salt.enforceState(master, "I@glusterfs:server ${extra_tgt}", 'glusterfs.server.service')
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100181
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300182 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 +0100183 sleep(10)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300184 salt.cmdRun(master, "I@glusterfs:server ${extra_tgt}", "gluster peer status; gluster volume status")
Alexander Noskov93acac42017-06-20 17:55:55 +0200185 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200186
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300187 // Ensure glusterfs clusters is ready
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300188 if (salt.testTarget(master, "I@glusterfs:client ${extra_tgt}")) {
189 salt.enforceState(master, "I@glusterfs:client ${extra_tgt}", 'glusterfs.client', true, true, null, false, -1, 2)
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300190 }
191
Jakub Josef79ecec32017-02-17 14:36:28 +0100192 // Install galera
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300193 if (salt.testTarget(master, "I@galera:master ${extra_tgt}") || salt.testTarget(master, "I@galera:slave ${extra_tgt}")) {
194 salt.enforceState(master, "I@galera:master ${extra_tgt}", 'galera', true, true, null, false, -1, 2)
195 salt.enforceState(master, "I@galera:slave ${extra_tgt}", 'galera', true, true, null, false, -1, 2)
vrovachev1c4770b2017-07-05 13:25:21 +0400196
197 // Check galera status
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300198 salt.runSaltProcessStep(master, "I@galera:master ${extra_tgt}", 'mysql.status')
199 salt.runSaltProcessStep(master, "I@galera:slave ${extra_tgt}", 'mysql.status')
Vasyl Saienkoc1fb9892017-07-13 14:54:13 +0300200 // If galera is not enabled check if we need to install mysql:server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300201 } else if (salt.testTarget(master, "I@mysql:server ${extra_tgt}")){
202 salt.enforceState(master, "I@mysql:server ${extra_tgt}", 'mysql.server')
203 if (salt.testTarget(master, "I@mysql:client ${extra_tgt}")){
204 salt.enforceState(master, "I@mysql:client ${extra_tgt}", 'mysql.client')
Vasyl Saienkoc1fb9892017-07-13 14:54:13 +0300205 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200206 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300207 installBackup(master, 'mysql', extra_tgt)
Ales Komarekef2bab62017-04-26 11:48:28 +0200208
vrovachev1c4770b2017-07-05 13:25:21 +0400209 // Install docker
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300210 if (salt.testTarget(master, "I@docker:host ${extra_tgt}")) {
Richard Felkl449b8ff2018-07-20 15:34:51 +0200211 salt.enforceState(master, "I@docker:host ${extra_tgt}", 'docker.host', true, true, null, false, -1, 3)
Pavel Cizinskyee34e312018-08-06 15:11:58 +0200212 salt.cmdRun(master, "I@docker:host and I@docker:host:enabled:true ${extra_tgt}", 'docker ps')
vrovachev1c4770b2017-07-05 13:25:21 +0400213 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200214
vrovachev1c4770b2017-07-05 13:25:21 +0400215 // Install keepalived
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300216 if (salt.testTarget(master, "I@keepalived:cluster ${extra_tgt}")) {
217 salt.enforceState(master, "I@keepalived:cluster and *01* ${extra_tgt}", 'keepalived')
218 salt.enforceState(master, "I@keepalived:cluster ${extra_tgt}", 'keepalived')
vrovachev1c4770b2017-07-05 13:25:21 +0400219 }
220
221 // Install rabbitmq
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300222 if (salt.testTarget(master, "I@rabbitmq:server ${extra_tgt}")) {
223 salt.enforceState(master, "I@rabbitmq:server ${extra_tgt}", 'rabbitmq', true, true, null, false, -1, 2)
vrovachev1c4770b2017-07-05 13:25:21 +0400224
225 // Check the rabbitmq status
Jakub Josef61463c72018-02-13 16:10:56 +0100226 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300227 salt.cmdRun(master, "I@rabbitmq:server ${extra_tgt}", 'rabbitmqctl cluster_status')
Jakub Josef61463c72018-02-13 16:10:56 +0100228 }
vrovachev1c4770b2017-07-05 13:25:21 +0400229 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200230
Jakub Josef79ecec32017-02-17 14:36:28 +0100231 // Install haproxy
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300232 if (salt.testTarget(master, "I@haproxy:proxy ${extra_tgt}")) {
233 salt.enforceState(master, "I@haproxy:proxy ${extra_tgt}", 'haproxy')
234 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.status', ['haproxy'])
235 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.restart', ['rsyslog'])
vrovachev1c4770b2017-07-05 13:25:21 +0400236 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200237
Jakub Josef79ecec32017-02-17 14:36:28 +0100238 // Install memcached
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300239 if (salt.testTarget(master, "I@memcached:server ${extra_tgt}")) {
240 salt.enforceState(master, "I@memcached:server ${extra_tgt}", 'memcached')
vrovachev1c4770b2017-07-05 13:25:21 +0400241 }
242
243 // Install etcd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300244 if (salt.testTarget(master, "I@etcd:server ${extra_tgt}")) {
245 salt.enforceState(master, "I@etcd:server ${extra_tgt}", 'etcd.server.service')
Jakub Josef61463c72018-02-13 16:10:56 +0100246 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300247 salt.cmdRun(master, "I@etcd:server ${extra_tgt}", '. /var/lib/etcd/configenv && etcdctl cluster-health')
Jakub Josef61463c72018-02-13 16:10:56 +0100248 }
vrovachev1c4770b2017-07-05 13:25:21 +0400249 }
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200250
251 // Install redis
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300252 if (salt.testTarget(master, "I@redis:server ${extra_tgt}")) {
253 if (salt.testTarget(master, "I@redis:cluster:role:master ${extra_tgt}")) {
254 salt.enforceState(master, "I@redis:cluster:role:master ${extra_tgt}", 'redis')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200255 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300256 salt.enforceState(master, "I@redis:server ${extra_tgt}", 'redis')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200257 }
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()
Ales Komarekef2bab62017-04-26 11:48:28 +0200271
272 // Install horizon dashboard
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300273 if (salt.testTarget(master, "I@horizon:server ${extra_tgt}")) {
274 salt.enforceState(master, "I@horizon:server ${extra_tgt}", 'horizon')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300275 }
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100276 // Install sphinx server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300277 if (salt.testTarget(master, "I@sphinx:server ${extra_tgt}")) {
278 salt.enforceState(master, "I@sphinx:server ${extra_tgt}", 'sphinx')
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100279 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300280 if (salt.testTarget(master, "I@nginx:server ${extra_tgt}")) {
281 salt.enforceState(master, "I@nginx:server ${extra_tgt}", 'salt.minion')
282 salt.enforceState(master, "I@nginx:server ${extra_tgt}", 'nginx')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300283 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200284
Jakub Josef79ecec32017-02-17 14:36:28 +0100285 // setup keystone service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300286 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
287 salt.enforceState(master, "I@keystone:server and *01* ${extra_tgt}", 'keystone.server')
288 salt.enforceState(master, "I@keystone:server ${extra_tgt}", 'keystone.server')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300289 // populate keystone services/tenants/roles/users
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100290
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300291 // keystone:client must be called locally
292 //salt.runSaltProcessStep(master, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300293 salt.runSaltProcessStep(master, "I@keystone:server ${extra_tgt}", 'service.restart', ['apache2'])
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300294 sleep(30)
295 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300296 if (salt.testTarget(master, "I@keystone:client ${extra_tgt}")) {
297 salt.enforceState(master, "I@keystone:client and *01* ${extra_tgt}", 'keystone.client')
298 salt.enforceState(master, "I@keystone:client ${extra_tgt}", 'keystone.client')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300299 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300300 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Jakub Josef61463c72018-02-13 16:10:56 +0100301 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300302 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack service list')
Jakub Josef61463c72018-02-13 16:10:56 +0100303 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300304 }
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100305
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300306 // Install glance
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300307 if (salt.testTarget(master, "I@glance:server ${extra_tgt}")) {
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300308 //runSaltProcessStep(master, 'I@glance:server', 'state.sls', ['glance.server'], 1)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300309 salt.enforceState(master, "I@glance:server and *01* ${extra_tgt}", 'glance.server')
310 salt.enforceState(master, "I@glance:server ${extra_tgt}", 'glance.server')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300311 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200312
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300313 // Check glance service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300314 if (salt.testTarget(master, "I@glance:server ${extra_tgt}")) {
Jakub Josef61463c72018-02-13 16:10:56 +0100315 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300316 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; glance image-list')
Jakub Josef61463c72018-02-13 16:10:56 +0100317 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300318 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200319
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400320 // Create glance resources
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300321 if (salt.testTarget(master, "I@glance:client ${extra_tgt}")) {
322 salt.enforceState(master, "I@glance:client ${extra_tgt}", 'glance.client')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400323 }
324
Jakub Josef79ecec32017-02-17 14:36:28 +0100325 // Install and check nova service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300326 if (salt.testTarget(master, "I@nova:controller ${extra_tgt}")) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100327 // run on first node first
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300328 salt.enforceState(master, "I@nova:controller and *01* ${extra_tgt}", 'nova.controller')
329 salt.enforceState(master, "I@nova:controller ${extra_tgt}", 'nova.controller')
330 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Jakub Josef61463c72018-02-13 16:10:56 +0100331 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300332 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; nova service-list')
Jakub Josef61463c72018-02-13 16:10:56 +0100333 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300334 }
335 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200336
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400337 // Create nova resources
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300338 if (salt.testTarget(master, "I@nova:client ${extra_tgt}")) {
339 salt.enforceState(master, "I@nova:client ${extra_tgt}", 'nova.client')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400340 }
341
Jakub Josef79ecec32017-02-17 14:36:28 +0100342 // Install and check cinder service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300343 if (salt.testTarget(master, "I@cinder:controller ${extra_tgt}")) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100344 // run on first node first
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300345 salt.enforceState(master, "I@cinder:controller and *01* ${extra_tgt}", 'cinder')
346 salt.enforceState(master, "I@cinder:controller ${extra_tgt}", 'cinder')
347 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Jakub Josef61463c72018-02-13 16:10:56 +0100348 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300349 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; cinder list')
Jakub Josef61463c72018-02-13 16:10:56 +0100350 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300351 }
352 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200353
Jakub Josef79ecec32017-02-17 14:36:28 +0100354 // Install neutron service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300355 if (salt.testTarget(master, "I@neutron:server ${extra_tgt}")) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100356 // run on first node first
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300357 salt.enforceState(master, "I@neutron:server and *01* ${extra_tgt}", 'neutron.server')
358 salt.enforceState(master, "I@neutron:server ${extra_tgt}", 'neutron.server')
359 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Jakub Josef61463c72018-02-13 16:10:56 +0100360 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300361 salt.cmdRun(master, "I@keystone:server ${extra_tgt}",'. /root/keystonercv3; neutron agent-list')
Jakub Josef61463c72018-02-13 16:10:56 +0100362 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300363 }
364 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200365
Jakub Josef79ecec32017-02-17 14:36:28 +0100366 // Install heat service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300367 if (salt.testTarget(master, "I@heat:server ${extra_tgt}")) {
Jakub Josef432e9d92018-02-06 18:28:37 +0100368 // run on first node first
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300369 salt.enforceState(master, "I@heat:server and *01* ${extra_tgt}", 'heat')
370 salt.enforceState(master, "I@heat:server ${extra_tgt}", 'heat')
371 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Jakub Josef61463c72018-02-13 16:10:56 +0100372 common.retry(3,5){
Oleh Hryhorov82634482018-08-09 16:11:50 +0300373 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack orchestration resource type list')
Jakub Josef61463c72018-02-13 16:10:56 +0100374 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300375 }
376 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200377
378 // Restart nova api
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300379 if (salt.testTarget(master, "I@nova:controller ${extra_tgt}")) {
380 salt.runSaltProcessStep(master, "I@nova:controller ${extra_tgt}", 'service.restart', ['nova-api'])
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300381 }
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300382
383 // Install ironic service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300384 if (salt.testTarget(master, "I@ironic:api ${extra_tgt}")) {
385 salt.enforceState(master, "I@ironic:api and *01* ${extra_tgt}", 'ironic.api')
386 salt.enforceState(master, "I@ironic:api ${extra_tgt}", 'ironic.api')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300387 }
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300388
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200389 // Install manila service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300390 if (salt.testTarget(master, "I@manila:api ${extra_tgt}")) {
391 salt.enforceState(master, "I@manila:api and *01* ${extra_tgt}", 'manila.api')
392 salt.enforceState(master, "I@manila:api ${extra_tgt}", 'manila.api')
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200393 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300394 if (salt.testTarget(master, "I@manila:scheduler ${extra_tgt}")) {
395 salt.enforceState(master, "I@manila:scheduler ${extra_tgt}", 'manila.scheduler')
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200396 }
397
Oleh Hryhorova070fd02018-03-15 14:47:52 +0200398 // Install designate services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300399 if (salt.testTarget(master, "I@designate:server:enabled ${extra_tgt}")) {
400 if (salt.testTarget(master, "I@designate:server:backend:bind9 ${extra_tgt}")) {
401 salt.enforceState(master, "I@bind:server ${extra_tgt}", 'bind.server')
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300402 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300403 if (salt.testTarget(master, "I@designate:server:backend:pdns4 ${extra_tgt}")) {
404 salt.enforceState(master, "I@powerdns:server ${extra_tgt}", 'powerdns.server')
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300405 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300406 salt.enforceState(master, "I@designate:server and *01* ${extra_tgt}", 'designate.server')
407 salt.enforceState(master, "I@designate:server ${extra_tgt}", 'designate')
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300408 }
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400409
410 // Install octavia api service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300411 if (salt.testTarget(master, "I@octavia:api ${extra_tgt}")) {
412 salt.enforceState(master, "I@octavia:api and *01* ${extra_tgt}", 'octavia')
413 salt.enforceState(master, "I@octavia:api ${extra_tgt}", 'octavia')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400414 }
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200415
Oleg Iurchenkod0898c92017-12-14 14:28:44 +0200416 // Install DogTag server service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300417 if (salt.testTarget(master, "I@dogtag:server ${extra_tgt}")) {
418 salt.enforceState(master, "I@dogtag:server and *01* ${extra_tgt}", 'dogtag.server')
419 salt.enforceState(master, "I@dogtag:server ${extra_tgt}", 'dogtag.server')
Oleg Iurchenkod0898c92017-12-14 14:28:44 +0200420 }
421
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200422 // Install barbican server service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300423 if (salt.testTarget(master, "I@barbican:server ${extra_tgt}")) {
424 salt.enforceState(master, "I@barbican:server and *01* ${extra_tgt}", 'barbican.server')
425 salt.enforceState(master, "I@barbican:server ${extra_tgt}", 'barbican.server')
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200426 }
427 // Install barbican client
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300428 if (salt.testTarget(master, "I@barbican:client ${extra_tgt}")) {
429 salt.enforceState(master, "I@barbican:client ${extra_tgt}", 'barbican.client')
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200430 }
Ondrej Smola5908ae62018-01-08 13:42:08 +0100431
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200432 // Install gnocchi server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300433 if (salt.testTarget(master, "I@gnocchi:server ${extra_tgt}")) {
434 salt.enforceState(master, "I@gnocchi:server and *01* ${extra_tgt}", 'gnocchi.server')
435 salt.enforceState(master, "I@gnocchi:server ${extra_tgt}", 'gnocchi.server')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200436 }
437
Mykyta Karpin4816e522018-06-15 16:00:03 +0300438 // Apply gnocchi client state to create gnocchi archive policies, due to possible
439 // races, apply on the first node initially
440 if (salt.testTarget(master, "I@gnocchi:client ${extra_tgt}")) {
441 salt.enforceState(master, "I@gnocchi:client and *01* ${extra_tgt}", 'gnocchi.client')
442 salt.enforceState(master, "I@gnocchi:client ${extra_tgt}", 'gnocchi.client')
443 }
444
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200445 // Install gnocchi statsd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300446 if (salt.testTarget(master, "I@gnocchi:statsd ${extra_tgt}")) {
447 salt.enforceState(master, "I@gnocchi:statsd and *01* ${extra_tgt}", 'gnocchi.statsd')
448 salt.enforceState(master, "I@gnocchi:statsd ${extra_tgt}", 'gnocchi.statsd')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200449 }
450
451 // Install panko server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300452 if (salt.testTarget(master, "I@panko:server ${extra_tgt}")) {
453 salt.enforceState(master, "I@panko:server and *01* ${extra_tgt}", 'panko')
454 salt.enforceState(master, "I@panko:server ${extra_tgt}", 'panko')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200455 }
456
Ondrej Smola5908ae62018-01-08 13:42:08 +0100457 // Install ceilometer server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300458 if (salt.testTarget(master, "I@ceilometer:server ${extra_tgt}")) {
459 salt.enforceState(master, "I@ceilometer:server and *01* ${extra_tgt}", 'ceilometer')
460 salt.enforceState(master, "I@ceilometer:server ${extra_tgt}", 'ceilometer')
Ondrej Smola5908ae62018-01-08 13:42:08 +0100461 }
462
463 // Install aodh server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300464 if (salt.testTarget(master, "I@aodh:server ${extra_tgt}")) {
465 salt.enforceState(master, "I@aodh:server and *01* ${extra_tgt}", 'aodh')
466 salt.enforceState(master, "I@aodh:server ${extra_tgt}", 'aodh')
Ondrej Smola5908ae62018-01-08 13:42:08 +0100467 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100468}
469
470
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300471def installIronicConductor(master, extra_tgt = ''){
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300472 def salt = new com.mirantis.mk.Salt()
473
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300474 if (salt.testTarget(master, "I@ironic:conductor ${extra_tgt}")) {
475 salt.enforceState(master, "I@ironic:conductor ${extra_tgt}", 'ironic.conductor')
476 salt.enforceState(master, "I@ironic:conductor ${extra_tgt}", 'apache')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300477 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300478 if (salt.testTarget(master, "I@tftpd_hpa:server ${extra_tgt}")) {
479 salt.enforceState(master, "I@tftpd_hpa:server ${extra_tgt}", 'tftpd_hpa')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300480 }
481
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300482 if (salt.testTarget(master, "I@nova:compute ${extra_tgt}")) {
483 salt.runSaltProcessStep(master, "I@nova:compute ${extra_tgt}", 'service.restart', ['nova-compute'])
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300484 }
485
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300486 if (salt.testTarget(master, "I@baremetal_simulator:enabled ${extra_tgt}")) {
487 salt.enforceState(master, "I@baremetal_simulator:enabled ${extra_tgt}", 'baremetal_simulator')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300488 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300489 if (salt.testTarget(master, "I@ironic:client ${extra_tgt}")) {
490 salt.enforceState(master, "I@ironic:client ${extra_tgt}", 'ironic.client')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300491 }
492}
493
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300494def installManilaShare(master, extra_tgt = ''){
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200495 def salt = new com.mirantis.mk.Salt()
496
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300497 if (salt.testTarget(master, "I@manila:share ${extra_tgt}")) {
498 salt.enforceState(master, "I@manila:share ${extra_tgt}", 'manila.share')
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200499 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300500 if (salt.testTarget(master, "I@manila:data ${extra_tgt}")) {
501 salt.enforceState(master, "I@manila:data ${extra_tgt}", 'manila.data')
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200502 }
503
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300504 if (salt.testTarget(master, "I@manila:client ${extra_tgt}")) {
505 salt.enforceState(master, "I@manila:client ${extra_tgt}", 'manila.client')
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200506 }
507}
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300508
509
Oleh Hryhorov37fbd0c2018-07-11 16:58:54 +0300510def installOpenstackNetwork(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100511 def salt = new com.mirantis.mk.Salt()
Oleksii Grudevc4a485e2018-04-20 14:25:03 +0300512 //run full neutron state on neutron.gateway - this will install
513 //neutron agents in addition to neutron server. Once neutron agents
514 //are up neutron resources can be created without hitting the situation when neutron resources are created
515 //prior to neutron agents which results in creating ports in non-usable state
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300516 if (salt.testTarget(master, "I@neutron:gateway ${extra_tgt}")) {
517 salt.enforceState(master, "I@neutron:gateway ${extra_tgt}", 'neutron')
Oleksii Grudevc4a485e2018-04-20 14:25:03 +0300518 }
519
520 // Create neutron resources - this step was moved here to ensure that
521 //neutron resources are created after neutron agens are up. In this case neutron ports will be in
522 //usable state. More information: https://bugs.launchpad.net/neutron/+bug/1399249
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300523 if (salt.testTarget(master, "I@neutron:client ${extra_tgt}")) {
524 salt.enforceState(master, "I@neutron:client ${extra_tgt}", 'neutron.client')
Oleksii Grudevc4a485e2018-04-20 14:25:03 +0300525 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200526
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300527 salt.enforceHighstate(master, "I@neutron:gateway ${extra_tgt}")
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400528
529 // install octavia manager services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300530 if (salt.testTarget(master, "I@octavia:manager ${extra_tgt}")) {
531 salt.runSaltProcessStep(master, "I@salt:master ${extra_tgt}", 'mine.update', ['*'])
532 salt.enforceState(master, "I@octavia:manager ${extra_tgt}", 'octavia')
533 salt.enforceState(master, "I@octavia:manager ${extra_tgt}", 'salt.minion.ca')
534 salt.enforceState(master, "I@octavia:manager ${extra_tgt}", 'salt.minion.cert')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400535 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200536}
537
538
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300539def installOpenstackCompute(master, extra_tgt = '') {
Ales Komarekef2bab62017-04-26 11:48:28 +0200540 def salt = new com.mirantis.mk.Salt()
Mykyta Karpin3ec78a22018-07-10 12:27:09 +0300541 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200542 // Configure compute nodes
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300543 def compute_compound = "I@nova:compute ${extra_tgt}"
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100544 if (salt.testTarget(master, compute_compound)) {
545 // In case if infrastructure nodes are used as nova computes too
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300546 def gluster_compound = "I@glusterfs:server ${extra_tgt}"
547 def salt_ca_compound = "I@salt:minion:ca:salt_master_ca ${extra_tgt}"
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200548 // Enforce highstate asynchronous only on compute nodes which are not glusterfs and not salt ca servers
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300549 def hightstateTarget = "${compute_compound} and not ${gluster_compound} and not ${salt_ca_compound}"
Oleh Hryhorov73f9fa22018-05-02 17:36:58 +0300550 if (salt.testTarget(master, hightstateTarget)) {
551 retry(2) {
552 salt.enforceHighstateWithExclude(master, hightstateTarget, 'opencontrail.client')
553 }
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300554 } else {
555 common.infoMsg("No minions matching highstate target found for target ${hightstateTarget}")
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200556 }
557 // Iterate through salt ca servers and check if they have compute role
558 // TODO: switch to batch once salt 2017.7+ would be used
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300559 common.infoMsg("Checking whether ${salt_ca_compound} minions have ${compute_compound} compound")
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200560 for ( target in salt.getMinionsSorted(master, salt_ca_compound) ) {
561 for ( cmp_target in salt.getMinionsSorted(master, compute_compound) ) {
562 if ( target == cmp_target ) {
563 // Enforce highstate one by one on salt ca servers which are compute nodes
564 retry(2) {
565 salt.enforceHighstateWithExclude(master, target, 'opencontrail.client')
566 }
567 }
568 }
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100569 }
570 // Iterate through glusterfs servers and check if they have compute role
571 // TODO: switch to batch once salt 2017.7+ would be used
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300572 common.infoMsg("Checking whether ${gluster_compound} minions have ${compute_compound} compound")
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100573 for ( target in salt.getMinionsSorted(master, gluster_compound) ) {
574 for ( cmp_target in salt.getMinionsSorted(master, compute_compound) ) {
575 if ( target == cmp_target ) {
576 // Enforce highstate one by one on glusterfs servers which are compute nodes
577 retry(2) {
578 salt.enforceHighstateWithExclude(master, target, 'opencontrail.client')
579 }
580 }
581 }
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200582 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200583 }
Vasyl Saienko51144e42018-06-19 09:30:30 +0300584
585 // Run nova:controller to map cmp with cells
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300586 if (salt.testTarget(master, "I@nova:controller ${extra_tgt}")) {
587 salt.enforceState(master, "I@nova:controller and *01* ${extra_tgt}", 'nova.controller')
Vasyl Saienko51144e42018-06-19 09:30:30 +0300588 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200589}
590
591
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300592def installContrailNetwork(master, extra_tgt = '') {
Martin Polreichfc9854c2017-06-30 11:17:36 +0200593 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200594 def salt = new com.mirantis.mk.Salt()
595
596
Jakub Josef79ecec32017-02-17 14:36:28 +0100597 // Install opencontrail database services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300598 salt.enforceState(master, "I@opencontrail:database and *01* ${extra_tgt}", 'opencontrail.database')
599 salt.enforceState(master, "I@opencontrail:database ${extra_tgt}", 'opencontrail.database')
Ales Komarekef2bab62017-04-26 11:48:28 +0200600
Jakub Josef79ecec32017-02-17 14:36:28 +0100601 // Install opencontrail control services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300602 salt.enforceStateWithExclude(master, "I@opencontrail:control and *01* ${extra_tgt}", "opencontrail", "opencontrail.client")
603 salt.enforceStateWithExclude(master, "I@opencontrail:control ${extra_tgt}", "opencontrail", "opencontrail.client")
604 salt.enforceStateWithExclude(master, "I@opencontrail:collector and *01* ${extra_tgt}", "opencontrail", "opencontrail.client")
605 salt.enforceStateWithExclude(master, "I@opencontrail:collector ${extra_tgt}", "opencontrail", "opencontrail.client")
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100606
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300607 if (salt.testTarget(master, "I@docker:client and I@opencontrail:control ${extra_tgt}")) {
Martin Polreich44331002018-08-13 11:27:06 +0200608 salt.enforceState(master, "( I@opencontrail:control or I@opencontrail:collector ) ${extra_tgt}", 'docker.client')
Marek Celoud443fb642017-11-22 15:07:12 +0100609 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300610 installBackup(master, 'contrail', extra_tgt)
Jakub Josef79ecec32017-02-17 14:36:28 +0100611}
612
613
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300614def installContrailCompute(master, extra_tgt = '') {
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200615 def salt = new com.mirantis.mk.Salt()
vrovachev32f7f542017-08-25 16:17:25 +0400616 def common = new com.mirantis.mk.Common()
Jakub Josef79ecec32017-02-17 14:36:28 +0100617 // Configure compute nodes
Ales Komarekef2bab62017-04-26 11:48:28 +0200618 // Provision opencontrail control services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300619 salt.enforceState(master, "I@opencontrail:database:id:1 ${extra_tgt}", 'opencontrail.client')
Jakub Josef79ecec32017-02-17 14:36:28 +0100620 // Provision opencontrail virtual routers
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100621
vrovachev4ff77302017-08-09 20:39:57 +0400622 // Generate script /usr/lib/contrail/if-vhost0 for up vhost0
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300623 if (salt.testTarget(master, "I@opencontrail:compute ${extra_tgt}")) {
624 salt.enforceStateWithExclude(master, "I@opencontrail:compute ${extra_tgt}", "opencontrail", "opencontrail.client")
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200625 }
vrovachev4ff77302017-08-09 20:39:57 +0400626
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300627 if (salt.testTarget(master, "I@nova:compute ${extra_tgt}")) {
628 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 +0200629 }
vrovachev4ff77302017-08-09 20:39:57 +0400630
Jakub Josef61463c72018-02-13 16:10:56 +0100631 sleep(300)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300632 if (salt.testTarget(master, "I@opencontrail:compute ${extra_tgt}")) {
633 salt.enforceState(master, "I@opencontrail:compute ${extra_tgt}", 'opencontrail.client')
634 salt.enforceState(master, "I@opencontrail:compute ${extra_tgt}", 'opencontrail')
vrovachev4ff77302017-08-09 20:39:57 +0400635 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100636}
637
638
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300639def installKubernetesInfra(master, extra_tgt = '') {
Jakub Josef432e9d92018-02-06 18:28:37 +0100640 def common = new com.mirantis.mk.Common()
641 common.warningMsg("You calling orchestrate.installKubernetesInfra(). This function is deprecated please use orchestrate.installInfra() directly")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300642 installInfra(master, extra_tgt)
Jakub Josef79ecec32017-02-17 14:36:28 +0100643}
644
645
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300646def installKubernetesControl(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100647 def salt = new com.mirantis.mk.Salt()
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200648
Jakub Josef79ecec32017-02-17 14:36:28 +0100649 // Install Kubernetes pool and Calico
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300650 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes.master.kube-addons')
651 salt.enforceState(master, "I@kubernetes:pool ${extra_tgt}", 'kubernetes.pool')
Jakub Josef79ecec32017-02-17 14:36:28 +0100652
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300653 if (salt.testTarget(master, "I@etcd:server:setup ${extra_tgt}")) {
Marek Celoud029391c2017-11-14 10:06:18 +0100654 // Setup etcd server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300655 salt.enforceState(master, "I@kubernetes:master and *01* ${extra_tgt}", 'etcd.server.setup')
Marek Celoud029391c2017-11-14 10:06:18 +0100656 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100657
Victor Ryzhenkinfb5d1b52018-05-22 18:49:26 +0400658 // Run k8s master at *01* to simplify namespaces creation
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300659 salt.enforceStateWithExclude(master, "I@kubernetes:master and *01* ${extra_tgt}", "kubernetes.master", "kubernetes.master.setup")
Victor Ryzhenkinfb5d1b52018-05-22 18:49:26 +0400660
Jakub Josef79ecec32017-02-17 14:36:28 +0100661 // Run k8s without master.setup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300662 salt.enforceStateWithExclude(master, "I@kubernetes:master ${extra_tgt}", "kubernetes", "kubernetes.master.setup")
Jakub Josef79ecec32017-02-17 14:36:28 +0100663
664 // Run k8s master setup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300665 salt.enforceState(master, "I@kubernetes:master and *01* ${extra_tgt}", 'kubernetes.master.setup')
Jakub Josef79ecec32017-02-17 14:36:28 +0100666
667 // Restart kubelet
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300668 salt.runSaltProcessStep(master, "I@kubernetes:pool ${extra_tgt}", 'service.restart', ['kubelet'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100669}
670
671
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300672def installKubernetesCompute(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200673 def salt = new com.mirantis.mk.Salt()
Jakub Josef432e9d92018-02-06 18:28:37 +0100674 salt.fullRefresh(master, "*")
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200675
676 // Bootstrap all nodes
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300677 salt.enforceState(master, "I@kubernetes:pool ${extra_tgt}", 'linux')
678 salt.enforceState(master, "I@kubernetes:pool ${extra_tgt}", 'salt.minion')
679 salt.enforceState(master, "I@kubernetes:pool ${extra_tgt}", ['openssh', 'ntp'])
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200680
681 // Create and distribute SSL certificates for services using salt state
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300682 salt.enforceState(master, "I@kubernetes:pool ${extra_tgt}", 'salt.minion.cert')
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200683
684 // Install docker
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300685 salt.enforceState(master, "I@docker:host ${extra_tgt}", 'docker.host')
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200686
687 // Install Kubernetes and Calico
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300688 salt.enforceState(master, "I@kubernetes:pool ${extra_tgt}", 'kubernetes.pool')
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200689
Yuriy Taradayab564d72017-10-11 15:14:35 +0400690 // Install Tiller and all configured releases
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300691 if (salt.testTarget(master, "I@helm:client ${extra_tgt}")) {
692 salt.enforceState(master, "I@helm:client ${extra_tgt}", 'helm')
Yuriy Taradayab564d72017-10-11 15:14:35 +0400693 }
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200694}
695
696
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300697def installDockerSwarm(master, extra_tgt = '') {
Martin Polreich8663a342017-06-30 17:33:08 +0200698 def salt = new com.mirantis.mk.Salt()
Jakub Josef79ecec32017-02-17 14:36:28 +0100699
vrovachev1c4770b2017-07-05 13:25:21 +0400700 //Install and Configure Docker
Martin Polreichc0bb4fd2018-08-06 11:34:43 +0200701 if (salt.testTarget(master, "I@docker:swarm ${extra_tgt}")) {
702 salt.enforceState(master, "I@docker:swarm ${extra_tgt}", 'docker.host')
703 salt.enforceState(master, "I@docker:swarm:role:master ${extra_tgt}", 'docker.swarm')
704 salt.enforceState(master, "I@docker:swarm ${extra_tgt}", 'salt.minion.grains')
705 salt.runSaltProcessStep(master, "I@docker:swarm ${extra_tgt}", 'mine.update')
706 salt.runSaltProcessStep(master, "I@docker:swarm ${extra_tgt}", 'saltutil.refresh_modules')
707 sleep(5)
708 salt.enforceState(master, "I@docker:swarm:role:master ${extra_tgt}", 'docker.swarm')
709 if (salt.testTarget(master, "I@docker:swarm:role:manager ${extra_tgt}")){
710 salt.enforceState(master, "I@docker:swarm:role:manager ${extra_tgt}", 'docker.swarm')
711 }
712 sleep(10)
713 salt.cmdRun(master, "I@docker:swarm:role:master ${extra_tgt}", 'docker node ls')
Machi Hoshino87aa39d2018-07-26 20:41:53 +0900714 }
Martin Polreich8663a342017-06-30 17:33:08 +0200715}
716
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200717
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300718def installCicd(master, extra_tgt = '') {
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200719 def salt = new com.mirantis.mk.Salt()
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200720 def common = new com.mirantis.mk.Common()
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300721 def gerrit_compound = "I@gerrit:client and ci* ${extra_tgt}"
722 def jenkins_compound = "I@jenkins:client and ci* ${extra_tgt}"
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200723
724 salt.fullRefresh(master, gerrit_compound)
725 salt.fullRefresh(master, jenkins_compound)
Richard Felkl9d2cd922017-11-03 11:49:32 +0100726
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300727 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 +0200728
729 // API timeout in minutes
730 def wait_timeout = 10
731
732 // Gerrit
733 def gerrit_master_url = salt.getPillar(master, gerrit_compound, '_param:gerrit_master_url')
734
735 if(!gerrit_master_url['return'].isEmpty()) {
736 gerrit_master_url = gerrit_master_url['return'][0].values()[0]
737 } else {
738 gerrit_master_url = ''
739 }
740
741 if (gerrit_master_url != '') {
742 common.infoMsg('Gerrit master url "' + gerrit_master_url + '" retrieved at _param:gerrit_master_url')
743 } else {
744
745 common.infoMsg('Gerrit master url could not be retrieved at _param:gerrit_master_url. Falling back to gerrit pillar')
746
747 def gerrit_host
748 def gerrit_http_port
749 def gerrit_http_scheme
750
751 def host_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:host')
752 gerrit_host = salt.getReturnValues(host_pillar)
753
754 def port_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:http_port')
755 gerrit_http_port = salt.getReturnValues(port_pillar)
756
757 def scheme_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:protocol')
758 gerrit_http_scheme = salt.getReturnValues(scheme_pillar)
759
760 gerrit_master_url = gerrit_http_scheme + '://' + gerrit_host + ':' + gerrit_http_port
761
762 }
763
764 timeout(wait_timeout) {
765 common.infoMsg('Waiting for Gerrit to come up..')
Dzmitry Stremkouski5440ffa2018-05-31 12:00:02 +0200766 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'
767 salt.cmdRun(master, gerrit_compound, 'timeout ' + (wait_timeout*60+3) + ' /bin/sh -c -- ' + '"' + check_gerrit_cmd + '"')
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200768 }
769
770 // Jenkins
771 def jenkins_master_url_pillar = salt.getPillar(master, jenkins_compound, '_param:jenkins_master_url')
772 jenkins_master_url = salt.getReturnValues(jenkins_master_url_pillar)
773
774 timeout(wait_timeout) {
775 common.infoMsg('Waiting for Jenkins to come up..')
Dzmitry Stremkouski5440ffa2018-05-31 12:00:02 +0200776 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'
777 salt.cmdRun(master, jenkins_compound, 'timeout ' + (wait_timeout*60+3) + ' /bin/sh -c -- ' + '"' + check_jenkins_cmd + '"')
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200778 }
Richard Felklc1aba9b2018-01-02 09:25:20 +0100779
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300780 if (salt.testTarget(master, "I@openldap:client ${extra_tgt}")) {
781 salt.enforceState(master, "I@openldap:client ${extra_tgt}", 'openldap', true, true, null, false, -1, 2)
Richard Felklc1aba9b2018-01-02 09:25:20 +0100782 }
Richard Felklb6fdec92017-09-26 10:52:36 +0200783
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300784 if (salt.testTarget(master, "I@python:environment ${extra_tgt}")) {
785 salt.enforceState(master, "I@python:environment ${extra_tgt}", 'python')
Richard Felklb6fdec92017-09-26 10:52:36 +0200786 }
Richard Felklc1aba9b2018-01-02 09:25:20 +0100787
Richard Felkl6e208fc2017-12-08 10:18:44 +0100788 withEnv(['ASK_ON_ERROR=false']){
789 retry(2){
790 try{
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300791 salt.enforceState(master, "I@gerrit:client ${extra_tgt}", 'gerrit')
Richard Felkl6e208fc2017-12-08 10:18:44 +0100792 }catch(e){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300793 salt.fullRefresh(master, "I@gerrit:client ${extra_tgt}")
Richard Felkl6e208fc2017-12-08 10:18:44 +0100794 throw e //rethrow for retry handler
795 }
796 }
797 retry(2){
798 try{
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300799 salt.enforceState(master, "I@jenkins:client ${extra_tgt}", 'jenkins')
Richard Felkl6e208fc2017-12-08 10:18:44 +0100800 }catch(e){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300801 salt.fullRefresh(master, "I@jenkins:client ${extra_tgt}")
Richard Felkl6e208fc2017-12-08 10:18:44 +0100802 throw e //rethrow for retry handler
803 }
804 }
805 }
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200806}
807
808
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300809def installStacklight(master, extra_tgt = '') {
Martin Polreich8663a342017-06-30 17:33:08 +0200810 def common = new com.mirantis.mk.Common()
811 def salt = new com.mirantis.mk.Salt()
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200812 def retries_wait = 20
813 def retries = 15
Martin Polreich8663a342017-06-30 17:33:08 +0200814
Simon Pasquieref4122c2017-08-25 15:52:07 +0200815 // Install core services for K8S environments:
816 // HAProxy, Nginx and lusterFS clients
817 // In case of OpenStack, those are already installed
Martin Polreich792f2662017-07-11 13:36:32 +0200818 if (common.checkContains('STACK_INSTALL', 'k8s')) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300819 salt.enforceState(master, "I@haproxy:proxy ${extra_tgt}", 'haproxy')
820 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.status', ['haproxy'])
Simon Pasquieref4122c2017-08-25 15:52:07 +0200821
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300822 if (salt.testTarget(master, "I@nginx:server ${extra_tgt}")) {
823 salt.enforceState(master, "I@nginx:server ${extra_tgt}", 'nginx')
Simon Pasquieref4122c2017-08-25 15:52:07 +0200824 }
825
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300826 if (salt.testTarget(master, "I@glusterfs:client ${extra_tgt}")) {
827 salt.enforceState(master, "I@glusterfs:client ${extra_tgt}", 'glusterfs.client', true, true, null, false, -1, 2)
Simon Pasquieref4122c2017-08-25 15:52:07 +0200828 }
Martin Polreich792f2662017-07-11 13:36:32 +0200829 }
Jiri Broulike57a0242017-10-06 13:38:47 +0200830
Dmitry Kalashnik69ecb782018-05-21 17:36:50 +0400831 // Install MongoDB for Alerta
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300832 if (salt.testTarget(master, "I@mongodb:server ${extra_tgt}")) {
833 salt.enforceState(master, "I@mongodb:server ${extra_tgt}", 'mongodb.server')
Ildar Svetlov829f94a2018-06-05 17:57:08 +0400834
835 // Initialize mongodb replica set
836 common.retry(5,20){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300837 salt.enforceState(master, "I@mongodb:server ${extra_tgt}", 'mongodb.cluster')
Ildar Svetlov829f94a2018-06-05 17:57:08 +0400838 }
Dmitry Kalashnik69ecb782018-05-21 17:36:50 +0400839 }
840
Martin Polreich8663a342017-06-30 17:33:08 +0200841 //Install Telegraf
Martin Polreich44331002018-08-13 11:27:06 +0200842 salt.enforceState(master, "( I@telegraf:agent or I@telegraf:remote_agent ) ${extra_tgt}", 'telegraf')
Martin Polreich8663a342017-06-30 17:33:08 +0200843
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400844 // Install Prometheus exporters
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300845 if (salt.testTarget(master, "I@prometheus:exporters ${extra_tgt}")) {
846 salt.enforceState(master, "I@prometheus:exporters ${extra_tgt}", 'prometheus')
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400847 }
848
Martin Polreich8663a342017-06-30 17:33:08 +0200849 //Install Elasticsearch and Kibana
Ramon Meleroae6e16a2018-08-07 13:42:16 -0500850 if (salt.testTarget(master, "*01* and I@elasticsearch:server:enabled:true ${extra_tgt}")) {
851 salt.enforceState(master, "*01* and I@elasticsearch:server:enabled:true ${extra_tgt}", 'elasticsearch.server')
852 }
853 if (salt.testTarget(master, "I@elasticsearch:server:enabled:true ${extra_tgt}")) {
854 salt.enforceState(master, "I@elasticsearch:server:enabled:true ${extra_tgt}", 'elasticsearch.server')
855 }
856 if (salt.testTarget(master, "*01* and I@kibana:server:enabled:true ${extra_tgt}")) {
857 salt.enforceState(master, "*01* and I@kibana:server:enabled:true ${extra_tgt}", 'kibana.server')
858 }
859 if (salt.testTarget(master, "I@kibana:server:enabled:true ${extra_tgt}")) {
860 salt.enforceState(master, "I@kibana:server:enabled:true ${extra_tgt}", 'kibana.server')
861 }
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200862 // Check ES health cluster status
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300863 def pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:host')
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200864 def elasticsearch_vip
865 if(!pillar['return'].isEmpty()) {
866 elasticsearch_vip = pillar['return'][0].values()[0]
867 } else {
868 common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved')
869 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300870 pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:port')
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200871 def elasticsearch_port
872 if(!pillar['return'].isEmpty()) {
873 elasticsearch_port = pillar['return'][0].values()[0]
874 } else {
875 common.errorMsg('[ERROR] Elasticsearch VIP port could not be retrieved')
876 }
877 common.retry(retries,retries_wait) {
878 common.infoMsg('Waiting for Elasticsearch to become green..')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300879 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 +0200880 }
881
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200882 common.retry(retries,retries_wait) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300883 salt.enforceState(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch.client')
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200884 }
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200885
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200886 common.retry(retries,retries_wait) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300887 salt.enforceState(master, "I@kibana:client ${extra_tgt}", 'kibana.client')
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200888 }
Dmitry Kalashnik53feda72018-03-16 16:06:10 +0400889
890 //Install InfluxDB
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300891 if (salt.testTarget(master, "I@influxdb:server ${extra_tgt}")) {
892 salt.enforceState(master, "*01* and I@influxdb:server ${extra_tgt}", 'influxdb')
893 salt.enforceState(master, "I@influxdb:server ${extra_tgt}", 'influxdb')
Dmitry Kalashnik53feda72018-03-16 16:06:10 +0400894 }
895
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400896 // Install service for the log collection
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300897 if (salt.testTarget(master, "I@fluentd:agent ${extra_tgt}")) {
898 salt.enforceState(master, "I@fluentd:agent ${extra_tgt}", 'fluentd')
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400899 } else {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300900 salt.enforceState(master, "I@heka:log_collector ${extra_tgt}", 'heka.log_collector')
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400901 }
Simon Pasquier6301ddd2017-09-05 11:56:58 +0200902
Ondrej Smola5908ae62018-01-08 13:42:08 +0100903 // Install heka ceilometer collector
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300904 if (salt.testTarget(master, "I@heka:ceilometer_collector:enabled ${extra_tgt}")) {
905 salt.enforceState(master, "I@heka:ceilometer_collector:enabled ${extra_tgt}", 'heka.ceilometer_collector')
906 salt.runSaltProcessStep(master, "I@heka:ceilometer_collector:enabled ${extra_tgt}", 'service.restart', ['ceilometer_collector'], null, true)
Ondrej Smola5908ae62018-01-08 13:42:08 +0100907 }
908
Martin Polreich470925a2017-07-06 17:12:59 +0200909 // Install galera
Martin Polreich792f2662017-07-11 13:36:32 +0200910 if (common.checkContains('STACK_INSTALL', 'k8s')) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300911 salt.enforceState(master, "I@galera:master ${extra_tgt}", 'galera', true, true, null, false, -1, 2)
912 salt.enforceState(master, "I@galera:slave ${extra_tgt}", 'galera', true, true, null, false, -1, 2)
Martin Polreich406f6462017-07-11 11:33:42 +0000913
Martin Polreich792f2662017-07-11 13:36:32 +0200914 // Check galera status
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300915 salt.runSaltProcessStep(master, "I@galera:master ${extra_tgt}", 'mysql.status')
916 salt.runSaltProcessStep(master, "I@galera:slave ${extra_tgt}", 'mysql.status')
Martin Polreich792f2662017-07-11 13:36:32 +0200917 }
Martin Polreich470925a2017-07-06 17:12:59 +0200918
Martin Polreich8663a342017-06-30 17:33:08 +0200919 //Collect Grains
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300920 salt.enforceState(master, "I@salt:minion ${extra_tgt}", 'salt.minion.grains')
921 salt.runSaltProcessStep(master, "I@salt:minion ${extra_tgt}", 'saltutil.refresh_modules')
922 salt.runSaltProcessStep(master, "I@salt:minion ${extra_tgt}", 'mine.update')
Martin Polreich8663a342017-06-30 17:33:08 +0200923 sleep(5)
924
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400925 // Configure Prometheus in Docker Swarm
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300926 salt.enforceState(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}", 'prometheus')
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400927
Ildar Svetlov0eec97d2018-02-15 10:06:40 +0400928 //Configure Remote Collector in Docker Swarm for Openstack deployments
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400929 if (!common.checkContains('STACK_INSTALL', 'k8s')) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300930 salt.enforceState(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}", 'heka.remote_collector', true, false)
Martin Polreich8017f452017-08-21 16:01:42 +0200931 }
Martin Polreich8663a342017-06-30 17:33:08 +0200932
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400933 // Launch containers
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300934 salt.enforceState(master, "I@docker:swarm:role:master and I@prometheus:server ${extra_tgt}", 'docker.client')
935 salt.runSaltProcessStep(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}", 'dockerng.ps')
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400936
937 //Install Prometheus LTS
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300938 if (salt.testTarget(master, "I@prometheus:relay ${extra_tgt}")) {
939 salt.enforceState(master, "I@prometheus:relay ${extra_tgt}", 'prometheus')
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400940 }
941
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100942 // Install sphinx server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300943 if (salt.testTarget(master, "I@sphinx:server ${extra_tgt}")) {
944 salt.enforceState(master, "I@sphinx:server ${extra_tgt}", 'sphinx')
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100945 }
946
Martin Polreich8663a342017-06-30 17:33:08 +0200947 //Configure Grafana
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300948 pillar = salt.getPillar(master, "ctl01* ${extra_tgt}", '_param:stacklight_monitor_address')
Martin Polreich8663a342017-06-30 17:33:08 +0200949 common.prettyPrint(pillar)
Martin Polreich595baef2017-07-04 16:11:04 +0200950
Martin Polreich8663a342017-06-30 17:33:08 +0200951 def stacklight_vip
952 if(!pillar['return'].isEmpty()) {
953 stacklight_vip = pillar['return'][0].values()[0]
954 } else {
955 common.errorMsg('[ERROR] Stacklight VIP address could not be retrieved')
956 }
vrovachev1c4770b2017-07-05 13:25:21 +0400957
Martin Polreich305e2222017-07-06 11:33:00 +0200958 common.infoMsg("Waiting for service on http://${stacklight_vip}:15013/ to start")
Martin Polreichbd7ad222017-07-06 12:53:51 +0200959 sleep(120)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300960 salt.enforceState(master, "I@grafana:client ${extra_tgt}", 'grafana.client')
Martin Polreich8663a342017-06-30 17:33:08 +0200961}
962
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300963def installStacklightv1Control(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200964 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200965
966 // infra install
967 // Install the StackLight backends
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300968 salt.enforceState(master, "*01* and I@elasticsearch:server ${extra_tgt}", 'elasticsearch.server')
969 salt.enforceState(master, "I@elasticsearch:server ${extra_tgt}", 'elasticsearch.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200970
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300971 salt.enforceState(master, "*01* and I@influxdb:server ${extra_tgt}", 'influxdb')
972 salt.enforceState(master, "I@influxdb:server ${extra_tgt}", 'influxdb')
Ales Komarekef2bab62017-04-26 11:48:28 +0200973
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300974 salt.enforceState(master, "*01* and I@kibana:server ${extra_tgt}", 'kibana.server')
975 salt.enforceState(master, "I@kibana:server ${extra_tgt}", 'kibana.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200976
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300977 salt.enforceState(master, "*01* and I@grafana:server ${extra_tgt}",'grafana.server')
978 salt.enforceState(master, "I@grafana:server ${extra_tgt}",'grafana.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200979
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300980 def alarming_service_pillar = salt.getPillar(master, "mon*01* ${extra_tgt}", '_param:alarming_service')
Kalynovskyi3e370112017-06-26 12:48:23 +0300981 def alarming_service = alarming_service_pillar['return'][0].values()[0]
982
983 switch (alarming_service) {
984 case 'sensu':
985 // Update Sensu
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300986 salt.enforceState(master, "I@sensu:server and I@rabbitmq:server ${extra_tgt}", 'rabbitmq')
987 salt.enforceState(master, "I@redis:cluster:role:master ${extra_tgt}", 'redis')
988 salt.enforceState(master, "I@redis:server ${extra_tgt}", 'redis')
989 salt.enforceState(master, "I@sensu:server ${extra_tgt}", 'sensu')
Kalynovskyi3e370112017-06-26 12:48:23 +0300990 default:
991 // Update Nagios
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300992 salt.enforceState(master, "I@nagios:server ${extra_tgt}", 'nagios.server')
Kalynovskyi3e370112017-06-26 12:48:23 +0300993 // Stop the Nagios service because the package starts it by default and it will
994 // started later only on the node holding the VIP address
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300995 salt.runSaltProcessStep(master, "I@nagios:server ${extra_tgt}", 'service.stop', ['nagios3'], null, true)
Kalynovskyi3e370112017-06-26 12:48:23 +0300996 }
997
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300998 salt.enforceState(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch.client.service')
999 salt.enforceState(master, "I@kibana:client ${extra_tgt}", 'kibana.client')
Ales Komarekef2bab62017-04-26 11:48:28 +02001000
1001 sleep(10)
1002}
1003
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001004def installStacklightv1Client(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +02001005 def salt = new com.mirantis.mk.Salt()
1006 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +02001007
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001008 salt.cmdRun(master, "I@elasticsearch:client ${extra_tgt}", 'salt-call state.sls elasticsearch.client')
1009 // salt.enforceState(master, "I@elasticsearch:client", 'elasticsearch.client", true)
1010 salt.cmdRun(master, "I@kibana:client ${extra_tgt}", 'salt-call state.sls kibana.client')
1011 // salt.enforceState(master, "I@kibana:client", 'kibana.client", true)
Ales Komarekef2bab62017-04-26 11:48:28 +02001012
1013 // Install collectd, heka and sensu services on the nodes, this will also
1014 // generate the metadata that goes into the grains and eventually into Salt Mine
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001015 salt.enforceState(master, "* ${extra_tgt}", 'collectd')
1016 salt.enforceState(master, "* ${extra_tgt}", 'salt.minion')
1017 salt.enforceState(master, "* ${extra_tgt}", 'heka')
Ales Komarekef2bab62017-04-26 11:48:28 +02001018
1019 // Gather the Grafana metadata as grains
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001020 salt.enforceState(master, "I@grafana:collector ${extra_tgt}", 'grafana.collector', true)
Ales Komarekef2bab62017-04-26 11:48:28 +02001021
1022 // Update Salt Mine
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001023 salt.enforceState(master, "* ${extra_tgt}", 'salt.minion.grains')
1024 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'saltutil.refresh_modules')
1025 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'mine.update')
Ales Komarekef2bab62017-04-26 11:48:28 +02001026
1027 sleep(5)
1028
1029 // Update Heka
Martin Polreich44331002018-08-13 11:27:06 +02001030 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 +02001031
1032 // Update collectd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001033 salt.enforceState(master, "I@collectd:remote_client:enabled:True ${extra_tgt}", 'collectd')
Ales Komarekef2bab62017-04-26 11:48:28 +02001034
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001035 def alarming_service_pillar = salt.getPillar(master, "mon*01* ${extra_tgt}", '_param:alarming_service')
Kalynovskyi3e370112017-06-26 12:48:23 +03001036 def alarming_service = alarming_service_pillar['return'][0].values()[0]
Ales Komarekef2bab62017-04-26 11:48:28 +02001037
Kalynovskyi3e370112017-06-26 12:48:23 +03001038 switch (alarming_service) {
1039 case 'sensu':
1040 // Update Sensu
1041 // TODO for stacklight team, should be fixed in model
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001042 salt.enforceState(master, "I@sensu:client ${extra_tgt}", 'sensu')
Kalynovskyi3e370112017-06-26 12:48:23 +03001043 default:
1044 break
1045 // Default is nagios, and was enforced in installStacklightControl()
1046 }
Ales Komarekef2bab62017-04-26 11:48:28 +02001047
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001048 salt.cmdRun(master, "I@grafana:client and *01* ${extra_tgt}", 'salt-call state.sls grafana.client')
1049 // salt.enforceState(master, "I@grafana:client and *01*", 'grafana.client", true)
Ales Komarekef2bab62017-04-26 11:48:28 +02001050
Marek Celoudd200cad2017-06-07 10:34:46 +02001051 // Finalize the configuration of Grafana (add the dashboards...)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001052 salt.enforceState(master, "I@grafana:client and *01* ${extra_tgt}", 'grafana.client')
1053 salt.enforceState(master, "I@grafana:client and *02* ${extra_tgt}", 'grafana.client')
1054 salt.enforceState(master, "I@grafana:client and *03* ${extra_tgt}", 'grafana.client')
1055 // nw salt -C "I@grafana:client' --async service.restart salt-minion; sleep 10
Marek Celoudd200cad2017-06-07 10:34:46 +02001056
Ales Komarekef2bab62017-04-26 11:48:28 +02001057 // Get the StackLight monitoring VIP addres
1058 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
1059 //vip=${vip:=172.16.10.253}
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001060 def pillar = salt.getPillar(master, "ctl01* ${extra_tgt}", '_param:stacklight_monitor_address')
Jakub Josefbceaa322017-06-13 18:28:27 +02001061 common.prettyPrint(pillar)
Ales Komarekef2bab62017-04-26 11:48:28 +02001062 def stacklight_vip = pillar['return'][0].values()[0]
1063
1064 if (stacklight_vip) {
1065 // (re)Start manually the services that are bound to the monitoring VIP
1066 common.infoMsg("restart services on node with IP: ${stacklight_vip}")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001067 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['remote_collectd'])
1068 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['remote_collector'])
1069 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['aggregator'])
1070 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['nagios3'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001071 } else {
1072 throw new Exception("Missing stacklight_vip")
1073 }
Tomáš Kukrálf06ca0f2017-02-27 15:18:50 +01001074}
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001075
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001076//
1077// backups
1078//
1079
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001080def installBackup(master, component='common', extra_tgt = '') {
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001081 def salt = new com.mirantis.mk.Salt()
1082 if (component == 'common') {
1083 // Install Backupninja
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001084 if (salt.testTarget(master, "I@backupninja:client ${extra_tgt}")) {
1085 salt.enforceState(master, "I@backupninja:client ${extra_tgt}", 'salt.minion.grains')
1086 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'saltutil.sync_grains')
1087 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'mine.flush')
1088 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'mine.update')
1089 salt.enforceState(master, "I@backupninja:client ${extra_tgt}", 'backupninja')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001090 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001091 if (salt.testTarget(master, "I@backupninja:server ${extra_tgt}")) {
1092 salt.enforceState(master, "I@backupninja:server ${extra_tgt}", 'salt.minion.grains')
1093 salt.enforceState(master, "I@backupninja:server ${extra_tgt}", 'backupninja')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001094 }
1095 } else if (component == 'mysql') {
1096 // Install Xtrabackup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001097 if (salt.testTarget(master, "I@xtrabackup:client ${extra_tgt}")) {
1098 salt.enforceState(master, "I@xtrabackup:client ${extra_tgt}", 'salt.minion.grains')
1099 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'saltutil.sync_grains')
1100 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'mine.flush')
1101 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'mine.update')
1102 salt.enforceState(master, "I@xtrabackup:client ${extra_tgt}", 'xtrabackup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001103 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001104 if (salt.testTarget(master, "I@xtrabackup:server ${extra_tgt}")) {
1105 salt.enforceState(master, "I@xtrabackup:server ${extra_tgt}", 'xtrabackup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001106 }
1107 } else if (component == 'contrail') {
1108
1109 // Install Cassandra backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001110 if (salt.testTarget(master, "I@cassandra:backup:client ${extra_tgt}")) {
1111 salt.enforceState(master, "I@cassandra:backup:client ${extra_tgt}", 'salt.minion.grains')
1112 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1113 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'mine.flush')
1114 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'mine.update')
1115 salt.enforceState(master, "I@cassandra:backup:client ${extra_tgt}", 'cassandra.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001116 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001117 if (salt.testTarget(master, "I@cassandra:backup:server ${extra_tgt}")) {
1118 salt.enforceState(master, "I@cassandra:backup:server ${extra_tgt}", 'cassandra.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001119 }
1120 // Install Zookeeper backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001121 if (salt.testTarget(master, "I@zookeeper:backup:client ${extra_tgt}")) {
1122 salt.enforceState(master, "I@zookeeper:backup:client ${extra_tgt}", 'salt.minion.grains')
1123 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1124 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'mine.flush')
1125 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'mine.update')
1126 salt.enforceState(master, "I@zookeeper:backup:client ${extra_tgt}", 'zookeeper.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001127 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001128 if (salt.testTarget(master, "I@zookeeper:backup:server ${extra_tgt}")) {
1129 salt.enforceState(master, "I@zookeeper:backup:server ${extra_tgt}", 'zookeeper.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001130 }
1131 } else if (component == 'ceph') {
1132 // Install Ceph backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001133 if (salt.testTarget(master, "I@ceph:backup:client ${extra_tgt}")) {
1134 salt.enforceState(master, "I@ceph:backup:client ${extra_tgt}", 'salt.minion.grains')
1135 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1136 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'mine.flush')
1137 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'mine.update')
1138 salt.enforceState(master, "I@ceph:backup:client ${extra_tgt}", 'ceph.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001139 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001140 if (salt.testTarget(master, "I@ceph:backup:server ${extra_tgt}")) {
1141 salt.enforceState(master, "I@ceph:backup:server ${extra_tgt}", 'ceph.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001142 }
1143 }
1144
1145}
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001146
1147//
1148// Ceph
1149//
1150
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001151def installCephMon(master, target="I@ceph:mon", extra_tgt = '') {
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001152 def salt = new com.mirantis.mk.Salt()
1153
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001154 salt.enforceState(master, "I@ceph:common ${extra_tgt}", 'salt.minion.grains')
Jiri Broulikbfc234f2017-10-17 15:45:38 +02001155
Jiri Broulike57a0242017-10-06 13:38:47 +02001156 // generate keyrings
Martin Polreich44331002018-08-13 11:27:06 +02001157 if (salt.testTarget(master, "( I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin ) ${extra_tgt}")) {
1158 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 +03001159 salt.runSaltProcessStep(master, "I@ceph:mon ${extra_tgt}", 'saltutil.sync_grains')
Martin Polreich44331002018-08-13 11:27:06 +02001160 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 +02001161 sleep(5)
Jiri Broulike57a0242017-10-06 13:38:47 +02001162 }
Ondrej Smolafd5c2352017-08-11 14:25:39 +02001163 // install Ceph Mons
Jakub Josef432e9d92018-02-06 18:28:37 +01001164 salt.enforceState(master, target, 'ceph.mon')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001165 if (salt.testTarget(master, "I@ceph:mgr ${extra_tgt}")) {
1166 salt.enforceState(master, "I@ceph:mgr ${extra_tgt}", 'ceph.mgr')
Jiri Broulike57a0242017-10-06 13:38:47 +02001167 }
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001168}
1169
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001170def installCephOsd(master, target="I@ceph:osd", setup=true, extra_tgt = '') {
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001171 def salt = new com.mirantis.mk.Salt()
1172
1173 // install Ceph OSDs
Jakub Josef432e9d92018-02-06 18:28:37 +01001174 salt.enforceState(master, target, 'ceph.osd')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001175 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'saltutil.sync_grains')
Jakub Josef432e9d92018-02-06 18:28:37 +01001176 salt.enforceState(master, target, 'ceph.osd.custom')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001177 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'saltutil.sync_grains')
1178 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'mine.update')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001179 installBackup(master, 'ceph')
Tomáš Kukráled27a472017-08-29 10:26:25 +02001180
Jiri Broulike57a0242017-10-06 13:38:47 +02001181 // setup pools, keyrings and maybe crush
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001182 if (salt.testTarget(master, "I@ceph:setup ${extra_tgt}") && setup) {
Jiri Broulik07f8de72017-10-09 14:12:17 +02001183 sleep(5)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001184 salt.enforceState(master, "I@ceph:setup ${extra_tgt}", 'ceph.setup')
Tomáš Kukráled27a472017-08-29 10:26:25 +02001185 }
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001186}
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001187
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001188def installCephClient(master, extra_tgt = '') {
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001189 def salt = new com.mirantis.mk.Salt()
1190
1191 // install Ceph Radosgw
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001192 if (salt.testTarget(master, "I@ceph:radosgw ${extra_tgt}")) {
1193 salt.runSaltProcessStep(master, "I@ceph:radosgw ${extra_tgt}", 'saltutil.sync_grains')
1194 salt.enforceState(master, "I@ceph:radosgw ${extra_tgt}", 'ceph.radosgw')
Alexander Noskov229035f2017-12-06 00:10:20 +04001195 }
1196 // setup Keystone service and endpoints for swift or / and S3
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001197 if (salt.testTarget(master, "I@keystone:client ${extra_tgt}")) {
1198 salt.enforceState(master, "I@keystone:client ${extra_tgt}", 'keystone.client')
Tomáš Kukrál5836e3d2017-08-25 18:20:55 +02001199 }
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001200}
Jiri Broulike57a0242017-10-06 13:38:47 +02001201
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001202def connectCeph(master, extra_tgt = '') {
Jiri Broulike57a0242017-10-06 13:38:47 +02001203 def salt = new com.mirantis.mk.Salt()
1204
1205 // connect Ceph to the env
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001206 if (salt.testTarget(master, "I@ceph:common and I@glance:server ${extra_tgt}")) {
1207 salt.enforceState(master, "I@ceph:common and I@glance:server ${extra_tgt}", ['ceph.common', 'ceph.setup.keyring', 'glance'])
1208 salt.runSaltProcessStep(master, "I@ceph:common and I@glance:server ${extra_tgt}", 'service.restart', ['glance-api'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001209 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001210 if (salt.testTarget(master, "I@ceph:common and I@cinder:controller ${extra_tgt}")) {
1211 salt.enforceState(master, "I@ceph:common and I@cinder:controller ${extra_tgt}", ['ceph.common', 'ceph.setup.keyring', 'cinder'])
1212 salt.runSaltProcessStep(master, "I@ceph:common and I@cinder:controller ${extra_tgt}", 'service.restart', ['cinder-volume'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001213 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001214 if (salt.testTarget(master, "I@ceph:common and I@nova:compute ${extra_tgt}")) {
1215 salt.enforceState(master, "I@ceph:common and I@nova:compute ${extra_tgt}", ['ceph.common', 'ceph.setup.keyring'])
1216 salt.runSaltProcessStep(master, "I@ceph:common and I@nova:compute ${extra_tgt}", 'saltutil.sync_grains')
1217 salt.enforceState(master, "I@ceph:common and I@nova:compute ${extra_tgt}", ['nova'])
1218 salt.runSaltProcessStep(master, "I@ceph:common and I@nova:compute ${extra_tgt}", 'service.restart', ['nova-compute'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001219 }
1220}
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001221
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001222def installOssInfra(master, extra_tgt = '') {
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001223 def common = new com.mirantis.mk.Common()
1224 def salt = new com.mirantis.mk.Salt()
1225
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001226 if (salt.testTarget(master, "I@devops_portal:config ${extra_tgt}")) {
1227 salt.enforceState(master, "I@devops_portal:config ${extra_tgt}", 'devops_portal.config')
1228 salt.enforceState(master, "I@rundeck:client ${extra_tgt}", ['linux.system.user', 'openssh'])
1229 salt.enforceState(master, "I@rundeck:server ${extra_tgt}", 'rundeck.server')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001230 }
1231}
1232
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001233def installOss(master, extra_tgt = '') {
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001234 def common = new com.mirantis.mk.Common()
1235 def salt = new com.mirantis.mk.Salt()
1236
1237 //Get oss VIP address
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001238 def pillar = salt.getPillar(master, "cfg01* ${extra_tgt}", '_param:stacklight_monitor_address')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001239 common.prettyPrint(pillar)
1240
1241 def oss_vip
1242 if(!pillar['return'].isEmpty()) {
1243 oss_vip = pillar['return'][0].values()[0]
1244 } else {
1245 common.errorMsg('[ERROR] Oss VIP address could not be retrieved')
1246 }
1247
1248 // Postgres client - initialize OSS services databases
1249 timeout(120){
1250 common.infoMsg("Waiting for postgresql database to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001251 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 +04001252 }
1253 // XXX: first run usually fails on some inserts, but we need to create databases at first
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001254 salt.enforceState(master, "I@postgresql:client ${extra_tgt}", 'postgresql.client', true, false)
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001255
1256 // Setup postgres database with integration between
1257 // Pushkin notification service and Security Monkey security audit service
1258 timeout(10) {
1259 common.infoMsg("Waiting for Pushkin to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001260 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 +04001261 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001262 salt.enforceState(master, "I@postgresql:client ${extra_tgt}", 'postgresql.client')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001263
1264 // Rundeck
1265 timeout(10) {
1266 common.infoMsg("Waiting for Rundeck to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001267 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 +04001268 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001269 salt.enforceState(master, "I@rundeck:client ${extra_tgt}", 'rundeck.client')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001270
1271 // Elasticsearch
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001272 pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:host')
Mikhail Ivanovfcd55d62017-12-19 16:51:35 +04001273 def elasticsearch_vip
1274 if(!pillar['return'].isEmpty()) {
1275 elasticsearch_vip = pillar['return'][0].values()[0]
1276 } else {
1277 common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved')
1278 }
1279
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001280 timeout(10) {
1281 common.infoMsg('Waiting for Elasticsearch to come up..')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001282 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 +04001283 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001284 salt.enforceState(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch.client')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001285}
Oleksii Grudev9e1d97a2018-06-29 16:04:30 +03001286
1287/**
1288 * Function receives connection string, target and configuration yaml pattern
1289 * and retrieves config fom salt minion according to pattern. After that it
1290 * sorts applications according to priorities and runs orchestration states
1291 * @param master Salt Connection object or pepperEnv
1292 * @param tgt Target
1293 * @param conf Configuration pattern
1294 */
1295def OrchestrateApplications(master, tgt, conf) {
1296 def salt = new com.mirantis.mk.Salt()
1297 def common = new com.mirantis.mk.Common()
1298 def _orch = salt.getConfig(master, tgt, conf)
1299 if ( !_orch['return'][0].values()[0].isEmpty() ) {
1300 Map<String,Integer> _orch_app = [:]
1301 for (k in _orch['return'][0].values()[0].keySet()) {
1302 _orch_app[k] = _orch['return'][0].values()[0][k].values()[0].toInteger()
1303 }
1304 def _orch_app_sorted = common.SortMapByValueAsc(_orch_app)
1305 common.infoMsg("Applications will be deployed in following order:"+_orch_app_sorted.keySet())
1306 for (app in _orch_app_sorted.keySet()) {
1307 salt.orchestrateSystem(master, ['expression': tgt, 'type': 'compound'], "${app}.orchestrate.deploy")
1308 }
1309 }
1310 else {
1311 common.infoMsg("No applications found for orchestration")
1312 }
1313}