blob: ebb5782615aab12886e8b3b9b93688e7b4876905 [file] [log] [blame]
Jakub Josef79ecec32017-02-17 14:36:28 +01001package com.mirantis.mk
2/**
3 * Orchestration functions
4 *
5*/
6
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03007/**
8 * Function runs Salt states to check infra
9 * @param master Salt Connection object or pepperEnv
10 * @param extra_tgt Extra target - adds ability to address commands using extra targeting to different clouds, e.g.: salt -C 'I@keystone:server and *ogrudev-deploy-heat-os-ha-ovs-82*' ...
11 */
12def validateFoundationInfra(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +010013 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +020014
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030015 salt.cmdRun(master, "I@salt:master ${extra_tgt}" ,'salt-key')
16 salt.runSaltProcessStep(master, "I@salt:minion ${extra_tgt}", 'test.version')
17 salt.cmdRun(master, "I@salt:master ${extra_tgt}" ,'reclass-salt --top')
18 salt.runSaltProcessStep(master, "I@reclass:storage ${extra_tgt}", 'reclass.inventory')
19 salt.runSaltProcessStep(master, "I@salt:minion ${extra_tgt}", 'state.show_top')
Jakub Josef79ecec32017-02-17 14:36:28 +010020}
21
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030022def installFoundationInfra(master, staticMgmtNet=false, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +010023 def salt = new com.mirantis.mk.Salt()
Jiri Broulik037f8982018-04-23 17:07:16 +020024 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +020025
Vasyl Saienko0869b3a2017-11-22 14:37:57 +020026 // NOTE(vsaienko) Apply reclass first, it may update cluster model
27 // apply linux and salt.master salt.minion states afterwards to make sure
28 // correct cluster model is used.
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030029 salt.enforceState(master, "I@salt:master ${extra_tgt}", ['reclass'])
Tomáš Kukrálb4d75222017-06-06 10:36:02 +020030
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030031 salt.enforceState(master, "I@salt:master ${extra_tgt}", ['linux.system'])
32 salt.enforceState(master, "I@salt:master ${extra_tgt}", ['salt.master'], true, false, null, false, 120, 2)
33 salt.fullRefresh(master, "* ${extra_tgt}")
Tomáš Kukrálb4d75222017-06-06 10:36:02 +020034
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030035 salt.enforceState(master, "I@salt:master ${extra_tgt}", ['salt.minion'], true, false, null, false, 60, 2)
36 salt.enforceState(master, "I@salt:master ${extra_tgt}", ['salt.minion'])
37 salt.fullRefresh(master, "* ${extra_tgt}")
38 salt.enforceState(master, "* ${extra_tgt}", ['linux.network.proxy'], true, false, null, false, 60, 2)
iberezovskiy6394a8a2018-10-12 13:16:47 +040039 // Make sure all repositories are in place before proceeding with package installation from other states
40 salt.enforceState(master, "* ${extra_tgt}", ['linux.system.repo'], true, false, null, false, 60, 2)
Jiri Broulik94fc2592018-04-20 13:47:51 +020041 try {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030042 salt.enforceState(master, "* ${extra_tgt}", ['salt.minion.base'], true, false, null, false, 60, 2)
Jiri Broulik94fc2592018-04-20 13:47:51 +020043 sleep(5)
44 } catch (Throwable e) {
45 common.warningMsg('Salt state salt.minion.base is not present in the Salt-formula yet.')
46 }
Jiri Broulike3ace622018-06-07 10:51:02 +020047 common.retry(2,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030048 salt.enforceState(master, "* ${extra_tgt}", ['linux.system'])
Jiri Broulike3ace622018-06-07 10:51:02 +020049 }
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +010050 if (staticMgmtNet) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030051 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], null, true, 60)
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +010052 }
Ondrej Smola855dc1a2018-07-18 13:07:55 +020053 common.retry(2,5){
54 salt.enforceState(master, "I@linux:network:interface ${extra_tgt}", ['linux.network.interface'])
55 }
Jiri Broulik94538462018-05-11 15:45:13 +020056 sleep(5)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030057 salt.enforceState(master, "I@linux:system ${extra_tgt}", ['linux', 'openssh', 'ntp', 'rsyslog'])
58 salt.enforceState(master, "* ${extra_tgt}", ['salt.minion'], true, false, null, false, 60, 2)
Jakub Josef4f8f4df2017-09-01 14:32:42 +020059 sleep(5)
Victor Ryzhenkinf610c572018-05-15 15:22:52 +040060
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030061 salt.fullRefresh(master, "* ${extra_tgt}")
62 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'mine.update', [], null, true)
63 salt.enforceState(master, "* ${extra_tgt}", ['linux.network.host'])
Ivan Suzdal9a6bc392018-04-26 18:29:56 +040064
65 // Install and configure iptables
Martin Polreich675dc942018-08-15 09:37:32 +020066 salt.enforceStateWithTest(master, "I@iptables:service ${extra_tgt}", 'iptables')
sgarbuzbb61e812018-05-03 16:58:40 +030067
68 // Install and configure logrotate
Martin Polreich675dc942018-08-15 09:37:32 +020069 salt.enforceStateWithTest(master, "I@logrotate:server ${extra_tgt}", 'logrotate')
Ivan Suzdal9f8f0e12018-06-21 13:16:21 +040070
71 // Install and configure auditd
Martin Polreich675dc942018-08-15 09:37:32 +020072 salt.enforceStateWithTest(master, "I@auditd:service ${extra_tgt}", 'auditd')
Ivan Suzdalca980912018-08-02 09:35:07 +040073
74 // Install and configure openscap
Martin Polreich675dc942018-08-15 09:37:32 +020075 salt.enforceStateWithTest(master, "I@openscap:service ${extra_tgt}", 'openscap')
Jakub Josef79ecec32017-02-17 14:36:28 +010076}
77
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030078def installFoundationInfraOnTarget(master, target, staticMgmtNet=false, extra_tgt = '') {
Jiri Broulik976bf6c2017-10-20 14:43:25 +020079 def salt = new com.mirantis.mk.Salt()
Jiri Broulik9fb138a2018-04-23 17:13:00 +020080 def common = new com.mirantis.mk.Common()
Jiri Broulik976bf6c2017-10-20 14:43:25 +020081
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030082 salt.enforceState(master, "I@salt:master ${extra_tgt}", ['reclass'], true, false, null, false, 120, 2)
Jakub Josef432e9d92018-02-06 18:28:37 +010083 salt.fullRefresh(master, target)
Ondrej Smolaa9b84662018-04-18 11:22:19 +020084 salt.enforceState(master, target, ['linux.network.proxy'], true, false, null, false, 60, 2)
Jiri Broulik94fc2592018-04-20 13:47:51 +020085 try {
86 salt.enforceState(master, target, ['salt.minion.base'], true, false, null, false, 60, 2)
87 sleep(5)
88 } catch (Throwable e) {
89 common.warningMsg('Salt state salt.minion.base is not present in the Salt-formula yet.')
90 }
Jiri Broulike3ace622018-06-07 10:51:02 +020091 common.retry(2,5){
92 salt.enforceState(master, target, ['linux.system'])
93 }
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +010094 if (staticMgmtNet) {
95 salt.runSaltProcessStep(master, target, 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], null, true, 60)
96 }
Jiri Broulik976bf6c2017-10-20 14:43:25 +020097 salt.enforceState(master, target, ['salt.minion'], true, false, null, false, 60, 2)
Jakub Josef432e9d92018-02-06 18:28:37 +010098 salt.enforceState(master, target, ['salt.minion'])
Jiri Broulik3740fb92018-04-27 11:52:38 +020099 salt.enforceState(master, target, ['linux.network.interface'])
Jiri Broulik94538462018-05-11 15:45:13 +0200100 sleep(5)
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100101 salt.enforceState(master, target, ['linux', 'openssh', 'ntp', 'rsyslog'])
Jiri Broulik976bf6c2017-10-20 14:43:25 +0200102 sleep(5)
Victor Ryzhenkinf610c572018-05-15 15:22:52 +0400103
104 salt.fullRefresh(master, target)
vrovachevc4424a32018-03-15 17:35:57 +0400105 salt.runSaltProcessStep(master, target, 'mine.update', [], null, true)
Jakub Josef432e9d92018-02-06 18:28:37 +0100106 salt.enforceState(master, target, ['linux.network.host'])
Jiri Broulik976bf6c2017-10-20 14:43:25 +0200107}
108
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300109def installInfraKvm(master, extra_tgt = '') {
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200110 def common = new com.mirantis.mk.Common()
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +0100111 def salt = new com.mirantis.mk.Salt()
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300112 def infra_compound = "I@salt:control ${extra_tgt}"
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200113 def minions = []
114 def wait_timeout = 10
115 def retries = wait_timeout * 30
Ales Komarekef2bab62017-04-26 11:48:28 +0200116
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300117 salt.fullRefresh(master, "I@linux:system ${extra_tgt}")
118 salt.enforceState(master, "I@salt:control ${extra_tgt}", ['salt.minion'], true, false, null, false, 60, 2)
119 salt.enforceState(master, "I@salt:control ${extra_tgt}", ['linux.system', 'linux.network', 'ntp', 'rsyslog'])
120 salt.enforceState(master, "I@salt:control ${extra_tgt}", 'libvirt')
121 salt.enforceState(master, "I@salt:control ${extra_tgt}", 'salt.control')
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100122
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200123 common.infoMsg("Building minions list...")
124 if (salt.testTarget(master, infra_compound)) {
125 // Gathering minions
126 for ( infra_node in salt.getMinionsSorted(master, infra_compound) ) {
127 def pillar = salt.getPillar(master, infra_node, 'salt:control:cluster')
128 if ( !pillar['return'].isEmpty() ) {
129 for ( cluster in pillar['return'][0].values() ) {
130 def engine = cluster.values()[0]['engine']
131 def domain = cluster.values()[0]['domain']
132 def node = cluster.values()[0]['node']
133 if ( engine == "virt" ) {
134 def nodes = node.values()
135 if ( !nodes.isEmpty() ) {
136 for ( vm in nodes ) {
137 if ( vm['name'] != null ) {
138 def vm_fqdn = vm['name'] + '.' + domain
139 if ( !minions.contains(vm_fqdn) ) {
140 minions.add(vm_fqdn)
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200141 }
142 }
143 }
144 }
145 }
146 }
147 }
148 }
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200149 }
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100150
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200151 def minions_compound = minions.join(' or ')
152
153 common.infoMsg("Waiting for next minions to register within ${wait_timeout} minutes: " + minions_compound)
154 timeout(time: wait_timeout, unit: 'MINUTES') {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300155 salt.minionsPresentFromList(master, "I@salt:master ${extra_tgt}", minions, true, null, true, retries, 1)
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200156 }
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200157
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200158 common.infoMsg('Waiting for minions to respond')
159 timeout(time: wait_timeout, unit: 'MINUTES') {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300160 salt.minionsReachable(master, "I@salt:master ${extra_tgt}", minions_compound)
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200161 }
162
163 common.infoMsg("All minions are up.")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300164 salt.fullRefresh(master, "* and not kvm* ${extra_tgt}")
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200165
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +0100166}
Jakub Josef79ecec32017-02-17 14:36:28 +0100167
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300168def installInfra(master, extra_tgt = '') {
Jakub Josef61463c72018-02-13 16:10:56 +0100169 def common = new com.mirantis.mk.Common()
Jakub Josef79ecec32017-02-17 14:36:28 +0100170 def salt = new com.mirantis.mk.Salt()
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400171 def first_target
Ales Komarekef2bab62017-04-26 11:48:28 +0200172
Jakub Josef79ecec32017-02-17 14:36:28 +0100173 // Install glusterfs
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300174 if (salt.testTarget(master, "I@glusterfs:server ${extra_tgt}")) {
175 salt.enforceState(master, "I@glusterfs:server ${extra_tgt}", 'glusterfs.server.service')
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100176
Mykyta Karpin6475ea22018-09-13 11:12:58 +0300177 salt.enforceState(master, "I@glusterfs:server:role:primary ${extra_tgt}", 'glusterfs.server.setup', true, true, null, false, -1, 5)
Jakub Josef61463c72018-02-13 16:10:56 +0100178 sleep(10)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300179 salt.cmdRun(master, "I@glusterfs:server ${extra_tgt}", "gluster peer status; gluster volume status")
Alexander Noskov93acac42017-06-20 17:55:55 +0200180 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200181
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300182 // Ensure glusterfs clusters is ready
Martin Polreich2be0d4b2018-09-27 15:57:19 +0200183 salt.enforceStateWithTest(master, "I@glusterfs:client ${extra_tgt}", 'glusterfs.client', "", true, true, null, false, -1, 2)
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300184
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
Martin Polreich675dc942018-08-15 09:37:32 +0200194 } else {
195 salt.enforceStateWithTest(master, "I@mysql:server ${extra_tgt}", 'mysql.server')
196 salt.enforceStateWithTest(master, "I@mysql:client ${extra_tgt}", 'mysql.client')
Ales Komarekef2bab62017-04-26 11:48:28 +0200197 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300198 installBackup(master, 'mysql', extra_tgt)
Ales Komarekef2bab62017-04-26 11:48:28 +0200199
vrovachev1c4770b2017-07-05 13:25:21 +0400200 // Install docker
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300201 if (salt.testTarget(master, "I@docker:host ${extra_tgt}")) {
Richard Felkl449b8ff2018-07-20 15:34:51 +0200202 salt.enforceState(master, "I@docker:host ${extra_tgt}", 'docker.host', true, true, null, false, -1, 3)
Pavel Cizinskyee34e312018-08-06 15:11:58 +0200203 salt.cmdRun(master, "I@docker:host and I@docker:host:enabled:true ${extra_tgt}", 'docker ps')
vrovachev1c4770b2017-07-05 13:25:21 +0400204 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200205
vrovachev1c4770b2017-07-05 13:25:21 +0400206 // Install keepalived
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300207 if (salt.testTarget(master, "I@keepalived:cluster ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400208 first_target = salt.getFirstMinion(master, "I@keepalived:cluster ${extra_tgt}")
209 salt.enforceState(master, "${first_target} ${extra_tgt}", 'keepalived')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300210 salt.enforceState(master, "I@keepalived:cluster ${extra_tgt}", 'keepalived')
vrovachev1c4770b2017-07-05 13:25:21 +0400211 }
212
213 // Install rabbitmq
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300214 if (salt.testTarget(master, "I@rabbitmq:server ${extra_tgt}")) {
215 salt.enforceState(master, "I@rabbitmq:server ${extra_tgt}", 'rabbitmq', true, true, null, false, -1, 2)
vrovachev1c4770b2017-07-05 13:25:21 +0400216
217 // Check the rabbitmq status
Jakub Josef61463c72018-02-13 16:10:56 +0100218 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300219 salt.cmdRun(master, "I@rabbitmq:server ${extra_tgt}", 'rabbitmqctl cluster_status')
Jakub Josef61463c72018-02-13 16:10:56 +0100220 }
vrovachev1c4770b2017-07-05 13:25:21 +0400221 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200222
Jakub Josef79ecec32017-02-17 14:36:28 +0100223 // Install haproxy
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300224 if (salt.testTarget(master, "I@haproxy:proxy ${extra_tgt}")) {
225 salt.enforceState(master, "I@haproxy:proxy ${extra_tgt}", 'haproxy')
226 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.status', ['haproxy'])
227 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.restart', ['rsyslog'])
vrovachev1c4770b2017-07-05 13:25:21 +0400228 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200229
Jakub Josef79ecec32017-02-17 14:36:28 +0100230 // Install memcached
Martin Polreich675dc942018-08-15 09:37:32 +0200231 salt.enforceStateWithTest(master, "I@memcached:server ${extra_tgt}", 'memcached')
vrovachev1c4770b2017-07-05 13:25:21 +0400232
233 // Install etcd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300234 if (salt.testTarget(master, "I@etcd:server ${extra_tgt}")) {
235 salt.enforceState(master, "I@etcd:server ${extra_tgt}", 'etcd.server.service')
Jakub Josef61463c72018-02-13 16:10:56 +0100236 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300237 salt.cmdRun(master, "I@etcd:server ${extra_tgt}", '. /var/lib/etcd/configenv && etcdctl cluster-health')
Jakub Josef61463c72018-02-13 16:10:56 +0100238 }
vrovachev1c4770b2017-07-05 13:25:21 +0400239 }
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200240
241 // Install redis
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300242 if (salt.testTarget(master, "I@redis:server ${extra_tgt}")) {
Martin Polreich675dc942018-08-15 09:37:32 +0200243 salt.enforceStateWithTest(master, "I@redis:cluster:role:master ${extra_tgt}", 'redis')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300244 salt.enforceState(master, "I@redis:server ${extra_tgt}", 'redis')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200245 }
Mykyta Karpin0a3dc8b2018-09-05 10:09:18 +0300246
247 // Install DNS services
248 if (salt.testTarget(master, "I@bind:server ${extra_tgt}")) {
249 salt.enforceState(master, "I@bind:server ${extra_tgt}", 'bind.server')
250 }
251 if (salt.testTarget(master, "I@powerdns:server ${extra_tgt}")) {
252 salt.enforceState(master, "I@powerdns:server ${extra_tgt}", 'powerdns.server')
253 }
254
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300255 installBackup(master, 'common', extra_tgt)
vrovachev1c4770b2017-07-05 13:25:21 +0400256}
257
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300258def installOpenstackInfra(master, extra_tgt = '') {
Jakub Josef432e9d92018-02-06 18:28:37 +0100259 def common = new com.mirantis.mk.Common()
260 common.warningMsg("You calling orchestrate.installOpenstackInfra(). This function is deprecated please use orchestrate.installInfra() directly")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300261 installInfra(master, extra_tgt)
Jakub Josef79ecec32017-02-17 14:36:28 +0100262}
263
264
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300265def installOpenstackControl(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100266 def salt = new com.mirantis.mk.Salt()
Jakub Josef61463c72018-02-13 16:10:56 +0100267 def common = new com.mirantis.mk.Common()
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400268 def first_target
Ales Komarekef2bab62017-04-26 11:48:28 +0200269
270 // Install horizon dashboard
Martin Polreich675dc942018-08-15 09:37:32 +0200271 salt.enforceStateWithTest(master, "I@horizon:server ${extra_tgt}", 'horizon')
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100272 // Install sphinx server
Martin Polreich675dc942018-08-15 09:37:32 +0200273 salt.enforceStateWithTest(master, "I@sphinx:server ${extra_tgt}", 'sphinx')
274 salt.enforceStateWithTest(master, "I@nginx:server ${extra_tgt}", 'salt.minion')
275 salt.enforceStateWithTest(master, "I@nginx:server ${extra_tgt}", 'nginx')
Ales Komarekef2bab62017-04-26 11:48:28 +0200276
Jakub Josef79ecec32017-02-17 14:36:28 +0100277 // setup keystone service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300278 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400279 salt.enforceState(master, "I@keystone:server:role:primary ${extra_tgt}", 'keystone.server')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300280 salt.enforceState(master, "I@keystone:server ${extra_tgt}", 'keystone.server')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300281 // populate keystone services/tenants/roles/users
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100282
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300283 // keystone:client must be called locally
284 //salt.runSaltProcessStep(master, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300285 salt.runSaltProcessStep(master, "I@keystone:server ${extra_tgt}", 'service.restart', ['apache2'])
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300286 sleep(30)
287 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300288 if (salt.testTarget(master, "I@keystone:client ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400289 first_target = salt.getFirstMinion(master, "I@keystone:client ${extra_tgt}")
290 salt.enforceState(master, "${first_target} ${extra_tgt}", 'keystone.client')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300291 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
Martin Polreich675dc942018-08-15 09:37:32 +0200300 salt.enforceStateWithTest(master, "I@glance:server:role:primary ${extra_tgt}", 'glance.server', "I@glance:server ${extra_tgt}")
301 salt.enforceStateWithTest(master, "I@glance:server ${extra_tgt}", 'glance.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200302
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300303 // Check glance service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300304 if (salt.testTarget(master, "I@glance:server ${extra_tgt}")) {
Jakub Josef61463c72018-02-13 16:10:56 +0100305 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300306 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; glance image-list')
Jakub Josef61463c72018-02-13 16:10:56 +0100307 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300308 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200309
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400310 // Create glance resources
Martin Polreich675dc942018-08-15 09:37:32 +0200311 salt.enforceStateWithTest(master, "I@glance:client ${extra_tgt}", 'glance.client')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400312
Jakub Josef79ecec32017-02-17 14:36:28 +0100313 // Install and check nova service
Martin Polreich675dc942018-08-15 09:37:32 +0200314 // run on first node first
315 salt.enforceStateWithTest(master, "I@nova:controller:role:primary ${extra_tgt}", 'nova.controller', "I@nova:controller ${extra_tgt}")
316 salt.enforceStateWithTest(master, "I@nova:controller ${extra_tgt}", 'nova.controller')
317 if (salt.testTarget(master, "I@keystone:server and I@nova:controller ${extra_tgt}")) {
318 common.retry(3,5){
319 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; nova service-list')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300320 }
321 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200322
Martin Polreich675dc942018-08-15 09:37:32 +0200323
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400324 // Create nova resources
Martin Polreich675dc942018-08-15 09:37:32 +0200325 salt.enforceStateWithTest(master, "I@nova:client ${extra_tgt}", 'nova.client')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400326
Jakub Josef79ecec32017-02-17 14:36:28 +0100327 // Install and check cinder service
Martin Polreich675dc942018-08-15 09:37:32 +0200328 // run on first node first
329 salt.enforceStateWithTest(master, "I@cinder:controller:role:primary ${extra_tgt}", 'cinder', "I@cinder:controller ${extra_tgt}")
330 salt.enforceStateWithTest(master, "I@cinder:controller ${extra_tgt}", 'cinder')
331 if (salt.testTarget(master, "I@keystone:server and I@cinder:controller ${extra_tgt}")) {
332 common.retry(3,5){
333 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; cinder list')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300334 }
335 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200336
Jakub Josef79ecec32017-02-17 14:36:28 +0100337 // Install neutron service
Martin Polreich675dc942018-08-15 09:37:32 +0200338 // run on first node first
339 salt.enforceStateWithTest(master, "I@neutron:server:role:primary ${extra_tgt}", 'neutron.server', "I@neutron:server ${extra_tgt}")
340 salt.enforceStateWithTest(master, "I@neutron:server ${extra_tgt}", 'neutron.server')
341 if (salt.testTarget(master, "I@keystone:server and I@neutron:server ${extra_tgt}")) {
342 common.retry(3,5){
343 salt.cmdRun(master, "I@keystone:server ${extra_tgt}",'. /root/keystonercv3; neutron agent-list')
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 heat service
Martin Polreich675dc942018-08-15 09:37:32 +0200348 salt.enforceStateWithTest(master, "I@heat:server:role:primary ${extra_tgt}", 'heat', "I@heat:server ${extra_tgt}")
349 salt.enforceStateWithTest(master, "I@heat:server ${extra_tgt}", 'heat')
350 if (salt.testTarget(master, "I@keystone:server and I@heat:server ${extra_tgt}")) {
351 common.retry(3,5){
352 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack orchestration resource type list')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300353 }
354 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200355
356 // Restart nova api
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300357 if (salt.testTarget(master, "I@nova:controller ${extra_tgt}")) {
358 salt.runSaltProcessStep(master, "I@nova:controller ${extra_tgt}", 'service.restart', ['nova-api'])
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300359 }
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300360
361 // Install ironic service
Martin Polreich675dc942018-08-15 09:37:32 +0200362 salt.enforceStateWithTest(master, "I@ironic:api:role:primary ${extra_tgt}", 'ironic.api', "I@ironic:api ${extra_tgt}")
363 salt.enforceStateWithTest(master, "I@ironic:api ${extra_tgt}", 'ironic.api')
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300364
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200365 // Install manila service
Martin Polreich675dc942018-08-15 09:37:32 +0200366 salt.enforceStateWithTest(master, "I@manila:api:role:primary ${extra_tgt}", 'manila.api', "I@manila:api ${extra_tgt}")
367 salt.enforceStateWithTest(master, "I@manila:api ${extra_tgt}", 'manila.api')
368 salt.enforceStateWithTest(master, "I@manila:scheduler ${extra_tgt}", 'manila.scheduler')
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200369
Oleh Hryhorova070fd02018-03-15 14:47:52 +0200370 // Install designate services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300371 if (salt.testTarget(master, "I@designate:server:enabled ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400372 salt.enforceState(master, "I@designate:server:role:primary ${extra_tgt}", 'designate.server')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300373 salt.enforceState(master, "I@designate:server ${extra_tgt}", 'designate')
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300374 }
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400375
376 // Install octavia api service
Martin Polreich675dc942018-08-15 09:37:32 +0200377 salt.enforceStateWithTest(master, "I@octavia:api:role:primary ${extra_tgt}", 'octavia.api', "I@octavia:api ${extra_tgt}")
378 salt.enforceStateWithTest(master, "I@octavia:api ${extra_tgt}", 'octavia.api')
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200379
Oleg Iurchenkod0898c92017-12-14 14:28:44 +0200380 // Install DogTag server service
Martin Polreich675dc942018-08-15 09:37:32 +0200381 salt.enforceStateWithTest(master, "I@dogtag:server:role:master ${extra_tgt}", 'dogtag.server', "I@dogtag:server ${extra_tgt}")
382 salt.enforceStateWithTest(master, "I@dogtag:server ${extra_tgt}", 'dogtag.server')
Oleg Iurchenkod0898c92017-12-14 14:28:44 +0200383
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200384 // Install barbican server service
Martin Polreich675dc942018-08-15 09:37:32 +0200385 salt.enforceStateWithTest(master, "I@barbican:server:role:primary ${extra_tgt}", 'barbican.server', "I@barbican:server ${extra_tgt}")
386 salt.enforceStateWithTest(master, "I@barbican:server ${extra_tgt}", 'barbican.server')
387
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200388 // Install barbican client
Martin Polreich675dc942018-08-15 09:37:32 +0200389 salt.enforceStateWithTest(master, "I@barbican:client ${extra_tgt}", 'barbican.client')
Ondrej Smola5908ae62018-01-08 13:42:08 +0100390
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200391 // Install gnocchi server
Martin Polreich675dc942018-08-15 09:37:32 +0200392 salt.enforceStateWithTest(master, "I@gnocchi:server:role:primary ${extra_tgt}", 'gnocchi.server', "I@gnocchi:server ${extra_tgt}")
393 salt.enforceStateWithTest(master, "I@gnocchi:server ${extra_tgt}", 'gnocchi.server')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200394
Mykyta Karpin4816e522018-06-15 16:00:03 +0300395 // Apply gnocchi client state to create gnocchi archive policies, due to possible
396 // races, apply on the first node initially
397 if (salt.testTarget(master, "I@gnocchi:client ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400398 first_target = salt.getFirstMinion(master, "I@gnocchi:client ${extra_tgt}")
399 salt.enforceState(master, "${first_target} ${extra_tgt}", 'gnocchi.client')
Mykyta Karpin4816e522018-06-15 16:00:03 +0300400 salt.enforceState(master, "I@gnocchi:client ${extra_tgt}", 'gnocchi.client')
401 }
402
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200403 // Install gnocchi statsd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300404 if (salt.testTarget(master, "I@gnocchi:statsd ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400405 first_target = salt.getFirstMinion(master, "I@gnocchi:statsd ${extra_tgt}")
406 salt.enforceState(master, "${first_target} ${extra_tgt}", 'gnocchi.statsd')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300407 salt.enforceState(master, "I@gnocchi:statsd ${extra_tgt}", 'gnocchi.statsd')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200408 }
409
410 // Install panko server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300411 if (salt.testTarget(master, "I@panko:server ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400412 first_target = salt.getFirstMinion(master, "I@panko:server ${extra_tgt}")
413 salt.enforceState(master, "${first_target} ${extra_tgt}", 'panko')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300414 salt.enforceState(master, "I@panko:server ${extra_tgt}", 'panko')
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200415 }
416
Ondrej Smola5908ae62018-01-08 13:42:08 +0100417 // Install ceilometer server
Martin Polreich675dc942018-08-15 09:37:32 +0200418 salt.enforceStateWithTest(master, "I@ceilometer:server:role:primary ${extra_tgt}", 'ceilometer', "I@ceilometer:server ${extra_tgt}")
419 salt.enforceStateWithTest(master, "I@ceilometer:server ${extra_tgt}", 'ceilometer')
Ondrej Smola5908ae62018-01-08 13:42:08 +0100420
421 // Install aodh server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300422 if (salt.testTarget(master, "I@aodh:server ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400423 first_target = salt.getFirstMinion(master, "I@aodh:server ${extra_tgt}")
424 salt.enforceState(master, "${first_target} ${extra_tgt}", 'aodh')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300425 salt.enforceState(master, "I@aodh:server ${extra_tgt}", 'aodh')
Ondrej Smola5908ae62018-01-08 13:42:08 +0100426 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100427}
428
429
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300430def installIronicConductor(master, extra_tgt = ''){
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300431 def salt = new com.mirantis.mk.Salt()
432
Martin Polreich675dc942018-08-15 09:37:32 +0200433 salt.enforceStateWithTest(master, "I@ironic:conductor ${extra_tgt}", 'ironic.conductor')
434 salt.enforceStateWithTest(master, "I@ironic:conductor ${extra_tgt}", 'apache')
435 salt.enforceStateWithTest(master, "I@tftpd_hpa:server ${extra_tgt}", 'tftpd_hpa')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300436
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300437 if (salt.testTarget(master, "I@nova:compute ${extra_tgt}")) {
438 salt.runSaltProcessStep(master, "I@nova:compute ${extra_tgt}", 'service.restart', ['nova-compute'])
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300439 }
440
Martin Polreich675dc942018-08-15 09:37:32 +0200441 salt.enforceStateWithTest(master, "I@baremetal_simulator:enabled ${extra_tgt}", 'baremetal_simulator')
442 salt.enforceStateWithTest(master, "I@ironic:client ${extra_tgt}", 'ironic.client')
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300443}
444
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300445def installManilaShare(master, extra_tgt = ''){
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200446 def salt = new com.mirantis.mk.Salt()
447
Martin Polreich675dc942018-08-15 09:37:32 +0200448 salt.enforceStateWithTest(master, "I@manila:share ${extra_tgt}", 'manila.share')
449 salt.enforceStateWithTest(master, "I@manila:data ${extra_tgt}", 'manila.data')
450 salt.enforceStateWithTest(master, "I@manila:client ${extra_tgt}", 'manila.client')
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200451}
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300452
453
Oleh Hryhorov37fbd0c2018-07-11 16:58:54 +0300454def installOpenstackNetwork(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100455 def salt = new com.mirantis.mk.Salt()
Oleksii Grudevc4a485e2018-04-20 14:25:03 +0300456 //run full neutron state on neutron.gateway - this will install
457 //neutron agents in addition to neutron server. Once neutron agents
458 //are up neutron resources can be created without hitting the situation when neutron resources are created
459 //prior to neutron agents which results in creating ports in non-usable state
Martin Polreich675dc942018-08-15 09:37:32 +0200460 salt.enforceStateWithTest(master, "I@neutron:gateway ${extra_tgt}", 'neutron')
Oleksii Grudevc4a485e2018-04-20 14:25:03 +0300461
462 // Create neutron resources - this step was moved here to ensure that
463 //neutron resources are created after neutron agens are up. In this case neutron ports will be in
464 //usable state. More information: https://bugs.launchpad.net/neutron/+bug/1399249
Martin Polreich675dc942018-08-15 09:37:32 +0200465 salt.enforceStateWithTest(master, "I@neutron:client ${extra_tgt}", 'neutron.client')
Ales Komarekef2bab62017-04-26 11:48:28 +0200466
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300467 salt.enforceHighstate(master, "I@neutron:gateway ${extra_tgt}")
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400468
469 // install octavia manager services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300470 if (salt.testTarget(master, "I@octavia:manager ${extra_tgt}")) {
471 salt.runSaltProcessStep(master, "I@salt:master ${extra_tgt}", 'mine.update', ['*'])
Anastasia Kuznetsova3c9fcf12018-08-22 15:10:05 +0400472 salt.enforceState(master, "I@octavia:manager ${extra_tgt}", 'octavia.manager')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300473 salt.enforceState(master, "I@octavia:manager ${extra_tgt}", 'salt.minion.ca')
474 salt.enforceState(master, "I@octavia:manager ${extra_tgt}", 'salt.minion.cert')
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400475 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200476}
477
478
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300479def installOpenstackCompute(master, extra_tgt = '') {
Ales Komarekef2bab62017-04-26 11:48:28 +0200480 def salt = new com.mirantis.mk.Salt()
Mykyta Karpin3ec78a22018-07-10 12:27:09 +0300481 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200482 // Configure compute nodes
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300483 def compute_compound = "I@nova:compute ${extra_tgt}"
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100484 if (salt.testTarget(master, compute_compound)) {
485 // In case if infrastructure nodes are used as nova computes too
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300486 def gluster_compound = "I@glusterfs:server ${extra_tgt}"
487 def salt_ca_compound = "I@salt:minion:ca:salt_master_ca ${extra_tgt}"
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200488 // Enforce highstate asynchronous only on compute nodes which are not glusterfs and not salt ca servers
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300489 def hightstateTarget = "${compute_compound} and not ${gluster_compound} and not ${salt_ca_compound}"
Oleh Hryhorov73f9fa22018-05-02 17:36:58 +0300490 if (salt.testTarget(master, hightstateTarget)) {
491 retry(2) {
Vasyl Saienko29b59b62018-09-14 18:45:45 +0300492 salt.enforceHighstate(master, hightstateTarget)
Oleh Hryhorov73f9fa22018-05-02 17:36:58 +0300493 }
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300494 } else {
495 common.infoMsg("No minions matching highstate target found for target ${hightstateTarget}")
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200496 }
497 // Iterate through salt ca servers and check if they have compute role
498 // TODO: switch to batch once salt 2017.7+ would be used
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300499 common.infoMsg("Checking whether ${salt_ca_compound} minions have ${compute_compound} compound")
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200500 for ( target in salt.getMinionsSorted(master, salt_ca_compound) ) {
501 for ( cmp_target in salt.getMinionsSorted(master, compute_compound) ) {
502 if ( target == cmp_target ) {
503 // Enforce highstate one by one on salt ca servers which are compute nodes
504 retry(2) {
Vasyl Saienko29b59b62018-09-14 18:45:45 +0300505 salt.enforceHighstate(master, target)
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200506 }
507 }
508 }
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100509 }
510 // Iterate through glusterfs servers and check if they have compute role
511 // TODO: switch to batch once salt 2017.7+ would be used
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300512 common.infoMsg("Checking whether ${gluster_compound} minions have ${compute_compound} compound")
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100513 for ( target in salt.getMinionsSorted(master, gluster_compound) ) {
514 for ( cmp_target in salt.getMinionsSorted(master, compute_compound) ) {
515 if ( target == cmp_target ) {
516 // Enforce highstate one by one on glusterfs servers which are compute nodes
517 retry(2) {
Vasyl Saienko29b59b62018-09-14 18:45:45 +0300518 salt.enforceHighstate(master, target)
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100519 }
520 }
521 }
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200522 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200523 }
Vasyl Saienko51144e42018-06-19 09:30:30 +0300524
525 // Run nova:controller to map cmp with cells
Martin Polreich675dc942018-08-15 09:37:32 +0200526 salt.enforceState(master, "I@nova:controller:role:primary ${extra_tgt}", 'nova.controller', "I@nova:controller ${extra_tgt}")
Ales Komarekef2bab62017-04-26 11:48:28 +0200527}
528
529
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300530def installContrailNetwork(master, extra_tgt = '') {
Martin Polreichfc9854c2017-06-30 11:17:36 +0200531 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200532 def salt = new com.mirantis.mk.Salt()
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400533 def first_target
Ales Komarekef2bab62017-04-26 11:48:28 +0200534
Jakub Josef79ecec32017-02-17 14:36:28 +0100535 // Install opencontrail database services
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400536 first_target = salt.getFirstMinion(master, "I@opencontrail:database ${extra_tgt}")
537 salt.enforceState(master, "${first_target} ${extra_tgt}", 'opencontrail.database')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300538 salt.enforceState(master, "I@opencontrail:database ${extra_tgt}", 'opencontrail.database')
Ales Komarekef2bab62017-04-26 11:48:28 +0200539
Jakub Josef79ecec32017-02-17 14:36:28 +0100540 // Install opencontrail control services
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400541 first_target = salt.getFirstMinion(master, "I@opencontrail:control ${extra_tgt}")
542 salt.enforceStateWithExclude(master, "${first_target} ${extra_tgt}", "opencontrail", "opencontrail.client")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300543 salt.enforceStateWithExclude(master, "I@opencontrail:control ${extra_tgt}", "opencontrail", "opencontrail.client")
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400544 first_target = salt.getFirstMinion(master, "I@opencontrail:collector ${extra_tgt}")
545 salt.enforceStateWithExclude(master, "${first_target} ${extra_tgt}", "opencontrail", "opencontrail.client")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300546 salt.enforceStateWithExclude(master, "I@opencontrail:collector ${extra_tgt}", "opencontrail", "opencontrail.client")
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100547
Martin Polreich675dc942018-08-15 09:37:32 +0200548 salt.enforceStateWithTest(master, "( I@opencontrail:control or I@opencontrail:collector ) ${extra_tgt}", 'docker.client', "I@docker:client and I@opencontrail:control ${extra_tgt}")
Inessa Vasilevskaya85ad1a92018-10-08 12:19:47 +0200549 // NOTE(ivasilevskaya) call to installBackup here has been removed as it breaks deployment if done before computes are deployed
Jakub Josef79ecec32017-02-17 14:36:28 +0100550}
551
552
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300553def installContrailCompute(master, extra_tgt = '') {
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200554 def salt = new com.mirantis.mk.Salt()
vrovachev32f7f542017-08-25 16:17:25 +0400555 def common = new com.mirantis.mk.Common()
Jakub Josef79ecec32017-02-17 14:36:28 +0100556 // Configure compute nodes
Ales Komarekef2bab62017-04-26 11:48:28 +0200557 // Provision opencontrail control services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300558 salt.enforceState(master, "I@opencontrail:database:id:1 ${extra_tgt}", 'opencontrail.client')
Jakub Josef79ecec32017-02-17 14:36:28 +0100559 // Provision opencontrail virtual routers
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100560
vrovachev4ff77302017-08-09 20:39:57 +0400561 // Generate script /usr/lib/contrail/if-vhost0 for up vhost0
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300562 if (salt.testTarget(master, "I@opencontrail:compute ${extra_tgt}")) {
563 salt.enforceStateWithExclude(master, "I@opencontrail:compute ${extra_tgt}", "opencontrail", "opencontrail.client")
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200564 }
vrovachev4ff77302017-08-09 20:39:57 +0400565
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300566 if (salt.testTarget(master, "I@nova:compute ${extra_tgt}")) {
567 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 +0200568 }
vrovachev4ff77302017-08-09 20:39:57 +0400569
Jakub Josef61463c72018-02-13 16:10:56 +0100570 sleep(300)
Martin Polreich675dc942018-08-15 09:37:32 +0200571 salt.enforceStateWithTest(master, "I@opencontrail:compute ${extra_tgt}", 'opencontrail.client')
572 salt.enforceStateWithTest(master, "I@opencontrail:compute ${extra_tgt}", 'opencontrail')
Jakub Josef79ecec32017-02-17 14:36:28 +0100573}
574
575
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300576def installKubernetesInfra(master, extra_tgt = '') {
Jakub Josef432e9d92018-02-06 18:28:37 +0100577 def common = new com.mirantis.mk.Common()
578 common.warningMsg("You calling orchestrate.installKubernetesInfra(). This function is deprecated please use orchestrate.installInfra() directly")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300579 installInfra(master, extra_tgt)
Jakub Josef79ecec32017-02-17 14:36:28 +0100580}
581
582
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300583def installKubernetesControl(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100584 def salt = new com.mirantis.mk.Salt()
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400585 def first_target
Victor Ryzhenkineb617412018-08-20 18:54:23 +0400586 salt.fullRefresh(master, "* ${extra_tgt}")
587
588 // Bootstrap all nodes
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400589 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", 'linux')
590 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", 'salt.minion')
591 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", ['openssh', 'ntp'])
Victor Ryzhenkineb617412018-08-20 18:54:23 +0400592
593 // Create and distribute SSL certificates for services using salt state
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400594 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", 'salt.minion.cert')
Victor Ryzhenkineb617412018-08-20 18:54:23 +0400595
596 // Install docker
597 salt.enforceState(master, "I@docker:host ${extra_tgt}", 'docker.host')
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200598
Svimba470b3312018-09-26 11:27:20 +0200599 // If network engine is not opencontrail, run addons state for kubernetes
600 if (!salt.getPillar(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes:master:network:opencontrail:enabled')) {
601 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes.master.kube-addons')
602 }
603
Jakub Josef79ecec32017-02-17 14:36:28 +0100604 // Install Kubernetes pool and Calico
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400605 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes.pool')
Jakub Josef79ecec32017-02-17 14:36:28 +0100606
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300607 if (salt.testTarget(master, "I@etcd:server:setup ${extra_tgt}")) {
Marek Celoud029391c2017-11-14 10:06:18 +0100608 // Setup etcd server
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400609 first_target = salt.getFirstMinion(master, "I@kubernetes:master ${extra_tgt}")
610 salt.enforceState(master, "${first_target} ${extra_tgt}", 'etcd.server.setup')
Marek Celoud029391c2017-11-14 10:06:18 +0100611 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100612
Victor Ryzhenkinfb5d1b52018-05-22 18:49:26 +0400613 // Run k8s master at *01* to simplify namespaces creation
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400614 first_target = salt.getFirstMinion(master, "I@kubernetes:master ${extra_tgt}")
Victor Ryzhenkinfb5d1b52018-05-22 18:49:26 +0400615
Svimba470b3312018-09-26 11:27:20 +0200616 // If network engine is opencontrail, run master state for kubernetes without kube-addons
617 // The kube-addons state will be called later only in case of opencontrail
618 if (salt.getPillar(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes:master:network:opencontrail:enabled')) {
619 // Run k8s on first node without master.setup and master.kube-addons
620 salt.enforceStateWithExclude(master, "${first_target} ${extra_tgt}", "kubernetes.master", "kubernetes.master.setup,kubernetes.master.kube-addons")
621 // Run k8s without master.setup and master.kube-addons
622 salt.enforceStateWithExclude(master, "I@kubernetes:master ${extra_tgt}", "kubernetes", "kubernetes.master.setup,kubernetes.master.kube-addons")
623 } else {
624 // Run k8s on first node without master.setup and master.kube-addons
625 salt.enforceStateWithExclude(master, "${first_target} ${extra_tgt}", "kubernetes.master", "kubernetes.master.setup")
626 // Run k8s without master.setup
627 salt.enforceStateWithExclude(master, "I@kubernetes:master ${extra_tgt}", "kubernetes", "kubernetes.master.setup")
628 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100629
630 // Run k8s master setup
Victor Ryzhenkin7655fa42018-10-02 20:52:08 +0400631 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes.master.setup')
Jakub Josef79ecec32017-02-17 14:36:28 +0100632
633 // Restart kubelet
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400634 salt.runSaltProcessStep(master, "I@kubernetes:master ${extra_tgt}", 'service.restart', ['kubelet'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100635}
636
637
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300638def installKubernetesCompute(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200639 def salt = new com.mirantis.mk.Salt()
Jakub Josef432e9d92018-02-06 18:28:37 +0100640 salt.fullRefresh(master, "*")
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200641
642 // Bootstrap all nodes
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400643 salt.enforceState(master, "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", 'linux')
644 salt.enforceState(master, "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", 'salt.minion')
645 salt.enforceState(master, "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", ['openssh', 'ntp'])
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200646
647 // Create and distribute SSL certificates for services using salt state
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400648 salt.enforceState(master, "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", 'salt.minion.cert')
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200649
650 // Install docker
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300651 salt.enforceState(master, "I@docker:host ${extra_tgt}", 'docker.host')
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200652
653 // Install Kubernetes and Calico
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400654 salt.enforceState(master, "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", 'kubernetes.pool')
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200655
Yuriy Taradayab564d72017-10-11 15:14:35 +0400656 // Install Tiller and all configured releases
Martin Polreich675dc942018-08-15 09:37:32 +0200657 salt.enforceStateWithTest(master, "I@helm:client ${extra_tgt}", 'helm')
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400658 salt.runSaltProcessStep(master, "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", 'service.restart', ['kubelet'])
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200659}
660
661
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300662def installDockerSwarm(master, extra_tgt = '') {
Martin Polreich8663a342017-06-30 17:33:08 +0200663 def salt = new com.mirantis.mk.Salt()
Jakub Josef79ecec32017-02-17 14:36:28 +0100664
vrovachev1c4770b2017-07-05 13:25:21 +0400665 //Install and Configure Docker
Martin Polreichc0bb4fd2018-08-06 11:34:43 +0200666 if (salt.testTarget(master, "I@docker:swarm ${extra_tgt}")) {
667 salt.enforceState(master, "I@docker:swarm ${extra_tgt}", 'docker.host')
668 salt.enforceState(master, "I@docker:swarm:role:master ${extra_tgt}", 'docker.swarm')
669 salt.enforceState(master, "I@docker:swarm ${extra_tgt}", 'salt.minion.grains')
670 salt.runSaltProcessStep(master, "I@docker:swarm ${extra_tgt}", 'mine.update')
671 salt.runSaltProcessStep(master, "I@docker:swarm ${extra_tgt}", 'saltutil.refresh_modules')
672 sleep(5)
673 salt.enforceState(master, "I@docker:swarm:role:master ${extra_tgt}", 'docker.swarm')
Martin Polreich675dc942018-08-15 09:37:32 +0200674 salt.enforceStateWithTest(master, "I@docker:swarm:role:manager ${extra_tgt}", 'docker.swarm')
Martin Polreichc0bb4fd2018-08-06 11:34:43 +0200675 sleep(10)
676 salt.cmdRun(master, "I@docker:swarm:role:master ${extra_tgt}", 'docker node ls')
Machi Hoshino87aa39d2018-07-26 20:41:53 +0900677 }
Martin Polreich8663a342017-06-30 17:33:08 +0200678}
679
Svimba470b3312018-09-26 11:27:20 +0200680// Setup addons for kubernetes - For OpenContrail network engine
681// Use after compute nodes are ready, because K8s addons like DNS should be placed on cmp nodes
682def setupKubeAddonForContrail(master, extra_tgt = '') {
683 def salt = new com.mirantis.mk.Salt()
684
685 if (salt.getPillar(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes:master:network:opencontrail:enabled')){
686 // Setup Addons for Kubernetes only in case of OpenContrail is used as neteork engine
687 salt.enforceState(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes.master.kube-addons')
688 }
689}
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200690
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300691def installCicd(master, extra_tgt = '') {
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200692 def salt = new com.mirantis.mk.Salt()
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200693 def common = new com.mirantis.mk.Common()
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300694 def gerrit_compound = "I@gerrit:client and ci* ${extra_tgt}"
695 def jenkins_compound = "I@jenkins:client and ci* ${extra_tgt}"
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200696
697 salt.fullRefresh(master, gerrit_compound)
698 salt.fullRefresh(master, jenkins_compound)
Richard Felkl9d2cd922017-11-03 11:49:32 +0100699
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300700 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 +0200701
702 // API timeout in minutes
703 def wait_timeout = 10
704
705 // Gerrit
706 def gerrit_master_url = salt.getPillar(master, gerrit_compound, '_param:gerrit_master_url')
707
708 if(!gerrit_master_url['return'].isEmpty()) {
709 gerrit_master_url = gerrit_master_url['return'][0].values()[0]
710 } else {
711 gerrit_master_url = ''
712 }
713
714 if (gerrit_master_url != '') {
715 common.infoMsg('Gerrit master url "' + gerrit_master_url + '" retrieved at _param:gerrit_master_url')
716 } else {
717
718 common.infoMsg('Gerrit master url could not be retrieved at _param:gerrit_master_url. Falling back to gerrit pillar')
719
720 def gerrit_host
721 def gerrit_http_port
722 def gerrit_http_scheme
723
724 def host_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:host')
725 gerrit_host = salt.getReturnValues(host_pillar)
726
727 def port_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:http_port')
728 gerrit_http_port = salt.getReturnValues(port_pillar)
729
730 def scheme_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:protocol')
731 gerrit_http_scheme = salt.getReturnValues(scheme_pillar)
732
733 gerrit_master_url = gerrit_http_scheme + '://' + gerrit_host + ':' + gerrit_http_port
734
735 }
736
737 timeout(wait_timeout) {
738 common.infoMsg('Waiting for Gerrit to come up..')
Dzmitry Stremkouski5440ffa2018-05-31 12:00:02 +0200739 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'
740 salt.cmdRun(master, gerrit_compound, 'timeout ' + (wait_timeout*60+3) + ' /bin/sh -c -- ' + '"' + check_gerrit_cmd + '"')
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200741 }
742
743 // Jenkins
744 def jenkins_master_url_pillar = salt.getPillar(master, jenkins_compound, '_param:jenkins_master_url')
745 jenkins_master_url = salt.getReturnValues(jenkins_master_url_pillar)
746
747 timeout(wait_timeout) {
748 common.infoMsg('Waiting for Jenkins to come up..')
Dzmitry Stremkouski5440ffa2018-05-31 12:00:02 +0200749 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'
750 salt.cmdRun(master, jenkins_compound, 'timeout ' + (wait_timeout*60+3) + ' /bin/sh -c -- ' + '"' + check_jenkins_cmd + '"')
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200751 }
Richard Felklc1aba9b2018-01-02 09:25:20 +0100752
Martin Polreich675dc942018-08-15 09:37:32 +0200753 salt.enforceStateWithTest(master, "I@openldap:client ${extra_tgt}", 'openldap', "", true, true, null, false, -1, 2)
Richard Felklb6fdec92017-09-26 10:52:36 +0200754
Martin Polreich675dc942018-08-15 09:37:32 +0200755 salt.enforceStateWithTest(master, "I@python:environment ${extra_tgt}", 'python')
Richard Felklc1aba9b2018-01-02 09:25:20 +0100756
Richard Felkl6e208fc2017-12-08 10:18:44 +0100757 withEnv(['ASK_ON_ERROR=false']){
758 retry(2){
759 try{
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300760 salt.enforceState(master, "I@gerrit:client ${extra_tgt}", 'gerrit')
Richard Felkl6e208fc2017-12-08 10:18:44 +0100761 }catch(e){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300762 salt.fullRefresh(master, "I@gerrit:client ${extra_tgt}")
Richard Felkl6e208fc2017-12-08 10:18:44 +0100763 throw e //rethrow for retry handler
764 }
765 }
766 retry(2){
767 try{
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300768 salt.enforceState(master, "I@jenkins:client ${extra_tgt}", 'jenkins')
Richard Felkl6e208fc2017-12-08 10:18:44 +0100769 }catch(e){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300770 salt.fullRefresh(master, "I@jenkins:client ${extra_tgt}")
Richard Felkl6e208fc2017-12-08 10:18:44 +0100771 throw e //rethrow for retry handler
772 }
773 }
774 }
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200775}
776
777
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300778def installStacklight(master, extra_tgt = '') {
Martin Polreich8663a342017-06-30 17:33:08 +0200779 def common = new com.mirantis.mk.Common()
780 def salt = new com.mirantis.mk.Salt()
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200781 def retries_wait = 20
782 def retries = 15
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400783 def first_target
Martin Polreich8663a342017-06-30 17:33:08 +0200784
Simon Pasquieref4122c2017-08-25 15:52:07 +0200785 // Install core services for K8S environments:
786 // HAProxy, Nginx and lusterFS clients
787 // In case of OpenStack, those are already installed
Martin Polreich792f2662017-07-11 13:36:32 +0200788 if (common.checkContains('STACK_INSTALL', 'k8s')) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300789 salt.enforceState(master, "I@haproxy:proxy ${extra_tgt}", 'haproxy')
790 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.status', ['haproxy'])
Simon Pasquieref4122c2017-08-25 15:52:07 +0200791
Martin Polreich675dc942018-08-15 09:37:32 +0200792 salt.enforceStateWithTest(master, "I@nginx:server ${extra_tgt}", 'nginx')
Simon Pasquieref4122c2017-08-25 15:52:07 +0200793
Martin Polreich675dc942018-08-15 09:37:32 +0200794 salt.enforceStateWithTest(master, "I@glusterfs:client ${extra_tgt}", 'glusterfs.client', "", true, true, null, false, -1, 2)
Martin Polreich792f2662017-07-11 13:36:32 +0200795 }
Jiri Broulike57a0242017-10-06 13:38:47 +0200796
Dmitry Kalashnik69ecb782018-05-21 17:36:50 +0400797 // Install MongoDB for Alerta
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300798 if (salt.testTarget(master, "I@mongodb:server ${extra_tgt}")) {
799 salt.enforceState(master, "I@mongodb:server ${extra_tgt}", 'mongodb.server')
Ildar Svetlov829f94a2018-06-05 17:57:08 +0400800
801 // Initialize mongodb replica set
802 common.retry(5,20){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300803 salt.enforceState(master, "I@mongodb:server ${extra_tgt}", 'mongodb.cluster')
Ildar Svetlov829f94a2018-06-05 17:57:08 +0400804 }
Dmitry Kalashnik69ecb782018-05-21 17:36:50 +0400805 }
806
Martin Polreich8663a342017-06-30 17:33:08 +0200807 //Install Telegraf
Martin Polreich44331002018-08-13 11:27:06 +0200808 salt.enforceState(master, "( I@telegraf:agent or I@telegraf:remote_agent ) ${extra_tgt}", 'telegraf')
Martin Polreich8663a342017-06-30 17:33:08 +0200809
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400810 // Install Prometheus exporters
Martin Polreich675dc942018-08-15 09:37:32 +0200811 salt.enforceStateWithTest(master, "I@prometheus:exporters ${extra_tgt}", 'prometheus')
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400812
Martin Polreich8663a342017-06-30 17:33:08 +0200813 //Install Elasticsearch and Kibana
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400814 if (salt.testTarget(master, "I@elasticsearch:server:enabled:true ${extra_tgt}")) {
815 first_target = salt.getFirstMinion(master, "I@elasticsearch:server:enabled:true ${extra_tgt}")
816 salt.enforceState(master, "${first_target} ${extra_tgt}", 'elasticsearch.server')
Ramon Meleroae6e16a2018-08-07 13:42:16 -0500817 }
Martin Polreich675dc942018-08-15 09:37:32 +0200818 salt.enforceStateWithTest(master, "I@elasticsearch:server:enabled:true ${extra_tgt}", 'elasticsearch.server')
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400819 if (salt.testTarget(master, "I@kibana:server:enabled:true ${extra_tgt}")) {
820 first_target = salt.getFirstMinion(master, "I@kibana:server:enabled:true ${extra_tgt}")
821 salt.enforceState(master, "${first_target} ${extra_tgt}", 'kibana.server')
Ramon Meleroae6e16a2018-08-07 13:42:16 -0500822 }
Martin Polreich675dc942018-08-15 09:37:32 +0200823 salt.enforceStateWithTest(master, "I@kibana:server:enabled:true ${extra_tgt}", 'kibana.server')
824
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200825 // Check ES health cluster status
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300826 def pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:host')
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200827 def elasticsearch_vip
828 if(!pillar['return'].isEmpty()) {
829 elasticsearch_vip = pillar['return'][0].values()[0]
830 } else {
831 common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved')
832 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300833 pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:port')
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200834 def elasticsearch_port
835 if(!pillar['return'].isEmpty()) {
836 elasticsearch_port = pillar['return'][0].values()[0]
837 } else {
838 common.errorMsg('[ERROR] Elasticsearch VIP port could not be retrieved')
839 }
840 common.retry(retries,retries_wait) {
841 common.infoMsg('Waiting for Elasticsearch to become green..')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300842 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 +0200843 }
844
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200845 common.retry(retries,retries_wait) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300846 salt.enforceState(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch.client')
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200847 }
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200848
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200849 common.retry(retries,retries_wait) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300850 salt.enforceState(master, "I@kibana:client ${extra_tgt}", 'kibana.client')
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200851 }
Dmitry Kalashnik53feda72018-03-16 16:06:10 +0400852
853 //Install InfluxDB
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300854 if (salt.testTarget(master, "I@influxdb:server ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400855 first_target = salt.getFirstMinion(master, "I@influxdb:server ${extra_tgt}")
856 salt.enforceState(master, "${first_target} ${extra_tgt}", 'influxdb')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300857 salt.enforceState(master, "I@influxdb:server ${extra_tgt}", 'influxdb')
Dmitry Kalashnik53feda72018-03-16 16:06:10 +0400858 }
859
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400860 // Install service for the log collection
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300861 if (salt.testTarget(master, "I@fluentd:agent ${extra_tgt}")) {
862 salt.enforceState(master, "I@fluentd:agent ${extra_tgt}", 'fluentd')
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400863 } else {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300864 salt.enforceState(master, "I@heka:log_collector ${extra_tgt}", 'heka.log_collector')
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400865 }
Simon Pasquier6301ddd2017-09-05 11:56:58 +0200866
Ondrej Smola5908ae62018-01-08 13:42:08 +0100867 // Install heka ceilometer collector
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300868 if (salt.testTarget(master, "I@heka:ceilometer_collector:enabled ${extra_tgt}")) {
869 salt.enforceState(master, "I@heka:ceilometer_collector:enabled ${extra_tgt}", 'heka.ceilometer_collector')
870 salt.runSaltProcessStep(master, "I@heka:ceilometer_collector:enabled ${extra_tgt}", 'service.restart', ['ceilometer_collector'], null, true)
Ondrej Smola5908ae62018-01-08 13:42:08 +0100871 }
872
Martin Polreich470925a2017-07-06 17:12:59 +0200873 // Install galera
Martin Polreich792f2662017-07-11 13:36:32 +0200874 if (common.checkContains('STACK_INSTALL', 'k8s')) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300875 salt.enforceState(master, "I@galera:master ${extra_tgt}", 'galera', true, true, null, false, -1, 2)
876 salt.enforceState(master, "I@galera:slave ${extra_tgt}", 'galera', true, true, null, false, -1, 2)
Martin Polreich406f6462017-07-11 11:33:42 +0000877
Martin Polreich792f2662017-07-11 13:36:32 +0200878 // Check galera status
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300879 salt.runSaltProcessStep(master, "I@galera:master ${extra_tgt}", 'mysql.status')
880 salt.runSaltProcessStep(master, "I@galera:slave ${extra_tgt}", 'mysql.status')
Martin Polreich792f2662017-07-11 13:36:32 +0200881 }
Martin Polreich470925a2017-07-06 17:12:59 +0200882
Martin Polreich8663a342017-06-30 17:33:08 +0200883 //Collect Grains
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300884 salt.enforceState(master, "I@salt:minion ${extra_tgt}", 'salt.minion.grains')
885 salt.runSaltProcessStep(master, "I@salt:minion ${extra_tgt}", 'saltutil.refresh_modules')
886 salt.runSaltProcessStep(master, "I@salt:minion ${extra_tgt}", 'mine.update')
Martin Polreich8663a342017-06-30 17:33:08 +0200887 sleep(5)
888
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400889 // Configure Prometheus in Docker Swarm
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300890 salt.enforceState(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}", 'prometheus')
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400891
Ildar Svetlov0eec97d2018-02-15 10:06:40 +0400892 //Configure Remote Collector in Docker Swarm for Openstack deployments
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400893 if (!common.checkContains('STACK_INSTALL', 'k8s')) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300894 salt.enforceState(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}", 'heka.remote_collector', true, false)
Martin Polreich8017f452017-08-21 16:01:42 +0200895 }
Martin Polreich8663a342017-06-30 17:33:08 +0200896
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400897 // Launch containers
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300898 salt.enforceState(master, "I@docker:swarm:role:master and I@prometheus:server ${extra_tgt}", 'docker.client')
899 salt.runSaltProcessStep(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}", 'dockerng.ps')
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400900
901 //Install Prometheus LTS
Martin Polreich675dc942018-08-15 09:37:32 +0200902 salt.enforceStateWithTest(master, "I@prometheus:relay ${extra_tgt}", 'prometheus')
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400903
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100904 // Install sphinx server
Martin Polreich675dc942018-08-15 09:37:32 +0200905 salt.enforceStateWithTest(master, "I@sphinx:server ${extra_tgt}", 'sphinx')
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100906
Martin Polreich8663a342017-06-30 17:33:08 +0200907 //Configure Grafana
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300908 pillar = salt.getPillar(master, "ctl01* ${extra_tgt}", '_param:stacklight_monitor_address')
Martin Polreich8663a342017-06-30 17:33:08 +0200909 common.prettyPrint(pillar)
Martin Polreich595baef2017-07-04 16:11:04 +0200910
Martin Polreich8663a342017-06-30 17:33:08 +0200911 def stacklight_vip
912 if(!pillar['return'].isEmpty()) {
913 stacklight_vip = pillar['return'][0].values()[0]
914 } else {
915 common.errorMsg('[ERROR] Stacklight VIP address could not be retrieved')
916 }
vrovachev1c4770b2017-07-05 13:25:21 +0400917
Martin Polreich305e2222017-07-06 11:33:00 +0200918 common.infoMsg("Waiting for service on http://${stacklight_vip}:15013/ to start")
Martin Polreichbd7ad222017-07-06 12:53:51 +0200919 sleep(120)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300920 salt.enforceState(master, "I@grafana:client ${extra_tgt}", 'grafana.client')
Martin Polreich8663a342017-06-30 17:33:08 +0200921}
922
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300923def installStacklightv1Control(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200924 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200925
926 // infra install
927 // Install the StackLight backends
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300928 salt.enforceState(master, "*01* and I@elasticsearch:server ${extra_tgt}", 'elasticsearch.server')
929 salt.enforceState(master, "I@elasticsearch:server ${extra_tgt}", 'elasticsearch.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200930
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300931 salt.enforceState(master, "*01* and I@influxdb:server ${extra_tgt}", 'influxdb')
932 salt.enforceState(master, "I@influxdb:server ${extra_tgt}", 'influxdb')
Ales Komarekef2bab62017-04-26 11:48:28 +0200933
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300934 salt.enforceState(master, "*01* and I@kibana:server ${extra_tgt}", 'kibana.server')
935 salt.enforceState(master, "I@kibana:server ${extra_tgt}", 'kibana.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200936
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300937 salt.enforceState(master, "*01* and I@grafana:server ${extra_tgt}",'grafana.server')
938 salt.enforceState(master, "I@grafana:server ${extra_tgt}",'grafana.server')
Ales Komarekef2bab62017-04-26 11:48:28 +0200939
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300940 def alarming_service_pillar = salt.getPillar(master, "mon*01* ${extra_tgt}", '_param:alarming_service')
Kalynovskyi3e370112017-06-26 12:48:23 +0300941 def alarming_service = alarming_service_pillar['return'][0].values()[0]
942
943 switch (alarming_service) {
944 case 'sensu':
945 // Update Sensu
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300946 salt.enforceState(master, "I@sensu:server and I@rabbitmq:server ${extra_tgt}", 'rabbitmq')
947 salt.enforceState(master, "I@redis:cluster:role:master ${extra_tgt}", 'redis')
948 salt.enforceState(master, "I@redis:server ${extra_tgt}", 'redis')
949 salt.enforceState(master, "I@sensu:server ${extra_tgt}", 'sensu')
Kalynovskyi3e370112017-06-26 12:48:23 +0300950 default:
951 // Update Nagios
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300952 salt.enforceState(master, "I@nagios:server ${extra_tgt}", 'nagios.server')
Kalynovskyi3e370112017-06-26 12:48:23 +0300953 // Stop the Nagios service because the package starts it by default and it will
954 // started later only on the node holding the VIP address
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300955 salt.runSaltProcessStep(master, "I@nagios:server ${extra_tgt}", 'service.stop', ['nagios3'], null, true)
Kalynovskyi3e370112017-06-26 12:48:23 +0300956 }
957
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300958 salt.enforceState(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch.client.service')
959 salt.enforceState(master, "I@kibana:client ${extra_tgt}", 'kibana.client')
Ales Komarekef2bab62017-04-26 11:48:28 +0200960
961 sleep(10)
962}
963
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300964def installStacklightv1Client(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200965 def salt = new com.mirantis.mk.Salt()
966 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200967
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300968 salt.cmdRun(master, "I@elasticsearch:client ${extra_tgt}", 'salt-call state.sls elasticsearch.client')
969 // salt.enforceState(master, "I@elasticsearch:client", 'elasticsearch.client", true)
970 salt.cmdRun(master, "I@kibana:client ${extra_tgt}", 'salt-call state.sls kibana.client')
971 // salt.enforceState(master, "I@kibana:client", 'kibana.client", true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200972
973 // Install collectd, heka and sensu services on the nodes, this will also
974 // generate the metadata that goes into the grains and eventually into Salt Mine
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300975 salt.enforceState(master, "* ${extra_tgt}", 'collectd')
976 salt.enforceState(master, "* ${extra_tgt}", 'salt.minion')
977 salt.enforceState(master, "* ${extra_tgt}", 'heka')
Ales Komarekef2bab62017-04-26 11:48:28 +0200978
979 // Gather the Grafana metadata as grains
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300980 salt.enforceState(master, "I@grafana:collector ${extra_tgt}", 'grafana.collector', true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200981
982 // Update Salt Mine
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300983 salt.enforceState(master, "* ${extra_tgt}", 'salt.minion.grains')
984 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'saltutil.refresh_modules')
985 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'mine.update')
Ales Komarekef2bab62017-04-26 11:48:28 +0200986
987 sleep(5)
988
989 // Update Heka
Martin Polreich44331002018-08-13 11:27:06 +0200990 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 +0200991
992 // Update collectd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300993 salt.enforceState(master, "I@collectd:remote_client:enabled:True ${extra_tgt}", 'collectd')
Ales Komarekef2bab62017-04-26 11:48:28 +0200994
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300995 def alarming_service_pillar = salt.getPillar(master, "mon*01* ${extra_tgt}", '_param:alarming_service')
Kalynovskyi3e370112017-06-26 12:48:23 +0300996 def alarming_service = alarming_service_pillar['return'][0].values()[0]
Ales Komarekef2bab62017-04-26 11:48:28 +0200997
Kalynovskyi3e370112017-06-26 12:48:23 +0300998 switch (alarming_service) {
999 case 'sensu':
1000 // Update Sensu
1001 // TODO for stacklight team, should be fixed in model
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001002 salt.enforceState(master, "I@sensu:client ${extra_tgt}", 'sensu')
Kalynovskyi3e370112017-06-26 12:48:23 +03001003 default:
1004 break
1005 // Default is nagios, and was enforced in installStacklightControl()
1006 }
Ales Komarekef2bab62017-04-26 11:48:28 +02001007
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001008 salt.cmdRun(master, "I@grafana:client and *01* ${extra_tgt}", 'salt-call state.sls grafana.client')
1009 // salt.enforceState(master, "I@grafana:client and *01*", 'grafana.client", true)
Ales Komarekef2bab62017-04-26 11:48:28 +02001010
Marek Celoudd200cad2017-06-07 10:34:46 +02001011 // Finalize the configuration of Grafana (add the dashboards...)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001012 salt.enforceState(master, "I@grafana:client and *01* ${extra_tgt}", 'grafana.client')
1013 salt.enforceState(master, "I@grafana:client and *02* ${extra_tgt}", 'grafana.client')
1014 salt.enforceState(master, "I@grafana:client and *03* ${extra_tgt}", 'grafana.client')
1015 // nw salt -C "I@grafana:client' --async service.restart salt-minion; sleep 10
Marek Celoudd200cad2017-06-07 10:34:46 +02001016
Ales Komarekef2bab62017-04-26 11:48:28 +02001017 // Get the StackLight monitoring VIP addres
1018 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
1019 //vip=${vip:=172.16.10.253}
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001020 def pillar = salt.getPillar(master, "ctl01* ${extra_tgt}", '_param:stacklight_monitor_address')
Jakub Josefbceaa322017-06-13 18:28:27 +02001021 common.prettyPrint(pillar)
Ales Komarekef2bab62017-04-26 11:48:28 +02001022 def stacklight_vip = pillar['return'][0].values()[0]
1023
1024 if (stacklight_vip) {
1025 // (re)Start manually the services that are bound to the monitoring VIP
1026 common.infoMsg("restart services on node with IP: ${stacklight_vip}")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001027 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['remote_collectd'])
1028 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['remote_collector'])
1029 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['aggregator'])
1030 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['nagios3'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001031 } else {
1032 throw new Exception("Missing stacklight_vip")
1033 }
Tomáš Kukrálf06ca0f2017-02-27 15:18:50 +01001034}
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001035
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001036//
1037// backups
1038//
1039
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001040def installBackup(master, component='common', extra_tgt = '') {
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001041 def salt = new com.mirantis.mk.Salt()
1042 if (component == 'common') {
1043 // Install Backupninja
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001044 if (salt.testTarget(master, "I@backupninja:client ${extra_tgt}")) {
1045 salt.enforceState(master, "I@backupninja:client ${extra_tgt}", 'salt.minion.grains')
1046 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'saltutil.sync_grains')
1047 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'mine.flush')
1048 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'mine.update')
1049 salt.enforceState(master, "I@backupninja:client ${extra_tgt}", 'backupninja')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001050 }
Martin Polreich675dc942018-08-15 09:37:32 +02001051 salt.enforceStateWithTest(master, "I@backupninja:server ${extra_tgt}", 'salt.minion.grains')
1052 salt.enforceStateWithTest(master, "I@backupninja:server ${extra_tgt}", 'backupninja')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001053 } else if (component == 'mysql') {
1054 // Install Xtrabackup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001055 if (salt.testTarget(master, "I@xtrabackup:client ${extra_tgt}")) {
1056 salt.enforceState(master, "I@xtrabackup:client ${extra_tgt}", 'salt.minion.grains')
1057 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'saltutil.sync_grains')
1058 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'mine.flush')
1059 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'mine.update')
1060 salt.enforceState(master, "I@xtrabackup:client ${extra_tgt}", 'xtrabackup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001061 }
Martin Polreich675dc942018-08-15 09:37:32 +02001062 salt.enforceStateWithTest(master, "I@xtrabackup:server ${extra_tgt}", 'xtrabackup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001063 } else if (component == 'contrail') {
1064
1065 // Install Cassandra backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001066 if (salt.testTarget(master, "I@cassandra:backup:client ${extra_tgt}")) {
1067 salt.enforceState(master, "I@cassandra:backup:client ${extra_tgt}", 'salt.minion.grains')
1068 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1069 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'mine.flush')
1070 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'mine.update')
1071 salt.enforceState(master, "I@cassandra:backup:client ${extra_tgt}", 'cassandra.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001072 }
Martin Polreich675dc942018-08-15 09:37:32 +02001073 salt.enforceStateWithTest(master, "I@cassandra:backup:server ${extra_tgt}", 'cassandra.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001074 // Install Zookeeper backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001075 if (salt.testTarget(master, "I@zookeeper:backup:client ${extra_tgt}")) {
1076 salt.enforceState(master, "I@zookeeper:backup:client ${extra_tgt}", 'salt.minion.grains')
1077 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1078 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'mine.flush')
1079 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'mine.update')
1080 salt.enforceState(master, "I@zookeeper:backup:client ${extra_tgt}", 'zookeeper.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001081 }
Martin Polreich675dc942018-08-15 09:37:32 +02001082 salt.enforceStateWithTest(master, "I@zookeeper:backup:server ${extra_tgt}", 'zookeeper.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001083 } else if (component == 'ceph') {
1084 // Install Ceph backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001085 if (salt.testTarget(master, "I@ceph:backup:client ${extra_tgt}")) {
1086 salt.enforceState(master, "I@ceph:backup:client ${extra_tgt}", 'salt.minion.grains')
1087 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1088 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'mine.flush')
1089 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'mine.update')
1090 salt.enforceState(master, "I@ceph:backup:client ${extra_tgt}", 'ceph.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001091 }
Martin Polreich675dc942018-08-15 09:37:32 +02001092 salt.enforceStateWithTest(master, "I@ceph:backup:server ${extra_tgt}", 'ceph.backup')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001093 }
1094
1095}
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001096
1097//
1098// Ceph
1099//
1100
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001101def installCephMon(master, target="I@ceph:mon", extra_tgt = '') {
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001102 def salt = new com.mirantis.mk.Salt()
1103
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001104 salt.enforceState(master, "I@ceph:common ${extra_tgt}", 'salt.minion.grains')
Jiri Broulikbfc234f2017-10-17 15:45:38 +02001105
Jiri Broulike57a0242017-10-06 13:38:47 +02001106 // generate keyrings
Martin Polreich44331002018-08-13 11:27:06 +02001107 if (salt.testTarget(master, "( I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin ) ${extra_tgt}")) {
1108 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 +03001109 salt.runSaltProcessStep(master, "I@ceph:mon ${extra_tgt}", 'saltutil.sync_grains')
Martin Polreich44331002018-08-13 11:27:06 +02001110 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 +02001111 sleep(5)
Jiri Broulike57a0242017-10-06 13:38:47 +02001112 }
Ondrej Smolafd5c2352017-08-11 14:25:39 +02001113 // install Ceph Mons
Jakub Josef432e9d92018-02-06 18:28:37 +01001114 salt.enforceState(master, target, 'ceph.mon')
Martin Polreich675dc942018-08-15 09:37:32 +02001115 salt.enforceStateWithTest(master, "I@ceph:mgr ${extra_tgt}", 'ceph.mgr')
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001116}
1117
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001118def installCephOsd(master, target="I@ceph:osd", setup=true, extra_tgt = '') {
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001119 def salt = new com.mirantis.mk.Salt()
1120
1121 // install Ceph OSDs
Jakub Josef432e9d92018-02-06 18:28:37 +01001122 salt.enforceState(master, target, 'ceph.osd')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001123 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'saltutil.sync_grains')
Jakub Josef432e9d92018-02-06 18:28:37 +01001124 salt.enforceState(master, target, 'ceph.osd.custom')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001125 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'saltutil.sync_grains')
1126 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'mine.update')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001127 installBackup(master, 'ceph')
Tomáš Kukráled27a472017-08-29 10:26:25 +02001128
Jiri Broulike57a0242017-10-06 13:38:47 +02001129 // setup pools, keyrings and maybe crush
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001130 if (salt.testTarget(master, "I@ceph:setup ${extra_tgt}") && setup) {
Jiri Broulik07f8de72017-10-09 14:12:17 +02001131 sleep(5)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001132 salt.enforceState(master, "I@ceph:setup ${extra_tgt}", 'ceph.setup')
Tomáš Kukráled27a472017-08-29 10:26:25 +02001133 }
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001134}
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001135
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001136def installCephClient(master, extra_tgt = '') {
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001137 def salt = new com.mirantis.mk.Salt()
1138
1139 // install Ceph Radosgw
Martin Polreich675dc942018-08-15 09:37:32 +02001140 if (salt.testTarget(master, "I@ceph:radosgw ${extra_tgt} and I@node_role.openstack-control")) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001141 salt.runSaltProcessStep(master, "I@ceph:radosgw ${extra_tgt}", 'saltutil.sync_grains')
1142 salt.enforceState(master, "I@ceph:radosgw ${extra_tgt}", 'ceph.radosgw')
Alexander Noskov229035f2017-12-06 00:10:20 +04001143 }
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001144
1145 // setup keyring for Openstack services
Martin Polreich675dc942018-08-15 09:37:32 +02001146 salt.enforceStateWithTest(master, "I@ceph:common and I@glance:server ${extra_tgt}", ['ceph.common', 'ceph.setup.keyring'])
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001147
Martin Polreich675dc942018-08-15 09:37:32 +02001148 salt.enforceStateWithTest(master, "I@ceph:common and I@cinder:controller ${extra_tgt}", ['ceph.common', 'ceph.setup.keyring'])
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001149
1150 if (salt.testTarget(master, "I@ceph:common and I@nova:compute ${extra_tgt}")) {
1151 salt.enforceState(master, "I@ceph:common and I@nova:compute ${extra_tgt}", ['ceph.common', 'ceph.setup.keyring'])
1152 salt.runSaltProcessStep(master, "I@ceph:common and I@nova:compute ${extra_tgt}", 'saltutil.sync_grains')
1153 }
1154
Martin Polreich675dc942018-08-15 09:37:32 +02001155 salt.enforceStateWithTest(master, "I@ceph:common and I@gnocchi:server ${extra_tgt}", ['ceph.common', 'ceph.setup.keyring'])
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001156}
Jiri Broulike57a0242017-10-06 13:38:47 +02001157
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001158def connectCeph(master, extra_tgt = '') {
Jiri Broulike57a0242017-10-06 13:38:47 +02001159 def salt = new com.mirantis.mk.Salt()
1160
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001161 // setup Keystone service and endpoints for swift or / and S3
Martin Polreich675dc942018-08-15 09:37:32 +02001162 salt.enforceStateWithTest(master, "I@keystone:client ${extra_tgt}", 'keystone.client')
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001163
Jiri Broulike57a0242017-10-06 13:38:47 +02001164 // connect Ceph to the env
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001165 if (salt.testTarget(master, "I@ceph:common and I@glance:server ${extra_tgt}")) {
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001166 salt.enforceState(master, "I@ceph:common and I@glance:server ${extra_tgt}", ['glance'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001167 salt.runSaltProcessStep(master, "I@ceph:common and I@glance:server ${extra_tgt}", 'service.restart', ['glance-api'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001168 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001169 if (salt.testTarget(master, "I@ceph:common and I@cinder:controller ${extra_tgt}")) {
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001170 salt.enforceState(master, "I@ceph:common and I@cinder:controller ${extra_tgt}", ['cinder'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001171 salt.runSaltProcessStep(master, "I@ceph:common and I@cinder:controller ${extra_tgt}", 'service.restart', ['cinder-volume'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001172 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001173 if (salt.testTarget(master, "I@ceph:common and I@nova:compute ${extra_tgt}")) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001174 salt.enforceState(master, "I@ceph:common and I@nova:compute ${extra_tgt}", ['nova'])
1175 salt.runSaltProcessStep(master, "I@ceph:common and I@nova:compute ${extra_tgt}", 'service.restart', ['nova-compute'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001176 }
Mykyta Karpin0dec8b32018-09-19 09:37:45 +03001177 if (salt.testTarget(master, "I@ceph:common and I@gnocchi:server ${extra_tgt}")) {
Mykyta Karpin0dec8b32018-09-19 09:37:45 +03001178 salt.enforceState(master, "I@ceph:common and I@gnocchi:server:role:primary ${extra_tgt}", 'gnocchi.server')
1179 salt.enforceState(master, "I@ceph:common and I@gnocchi:server ${extra_tgt}", 'gnocchi.server')
1180 }
Jiri Broulike57a0242017-10-06 13:38:47 +02001181}
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001182
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001183def installOssInfra(master, extra_tgt = '') {
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001184 def common = new com.mirantis.mk.Common()
1185 def salt = new com.mirantis.mk.Salt()
1186
Martin Polreich675dc942018-08-15 09:37:32 +02001187 salt.enforceStateWithTest(master, "I@devops_portal:config ${extra_tgt}", 'devops_portal.config', )
1188 salt.enforceStateWithTest(master, "I@rundeck:client ${extra_tgt}", ['linux.system.user', 'openssh'], "I@devops_portal:config ${extra_tgt}")
1189 salt.enforceStateWithTest(master, "I@rundeck:server ${extra_tgt}", 'rundeck.server', "I@devops_portal:config ${extra_tgt}")
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001190}
1191
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001192def installOss(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
1196 //Get oss VIP address
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001197 def pillar = salt.getPillar(master, "cfg01* ${extra_tgt}", '_param:stacklight_monitor_address')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001198 common.prettyPrint(pillar)
1199
1200 def oss_vip
1201 if(!pillar['return'].isEmpty()) {
1202 oss_vip = pillar['return'][0].values()[0]
1203 } else {
1204 common.errorMsg('[ERROR] Oss VIP address could not be retrieved')
1205 }
1206
1207 // Postgres client - initialize OSS services databases
1208 timeout(120){
1209 common.infoMsg("Waiting for postgresql database to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001210 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 +04001211 }
1212 // XXX: first run usually fails on some inserts, but we need to create databases at first
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001213 salt.enforceState(master, "I@postgresql:client ${extra_tgt}", 'postgresql.client', true, false)
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001214
1215 // Setup postgres database with integration between
1216 // Pushkin notification service and Security Monkey security audit service
1217 timeout(10) {
1218 common.infoMsg("Waiting for Pushkin to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001219 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 +04001220 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001221 salt.enforceState(master, "I@postgresql:client ${extra_tgt}", 'postgresql.client')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001222
1223 // Rundeck
1224 timeout(10) {
1225 common.infoMsg("Waiting for Rundeck to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001226 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 +04001227 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001228 salt.enforceState(master, "I@rundeck:client ${extra_tgt}", 'rundeck.client')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001229
1230 // Elasticsearch
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001231 pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:host')
Mikhail Ivanovfcd55d62017-12-19 16:51:35 +04001232 def elasticsearch_vip
1233 if(!pillar['return'].isEmpty()) {
1234 elasticsearch_vip = pillar['return'][0].values()[0]
1235 } else {
1236 common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved')
1237 }
1238
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001239 timeout(10) {
1240 common.infoMsg('Waiting for Elasticsearch to come up..')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001241 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 +04001242 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001243 salt.enforceState(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch.client')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001244}
Oleksii Grudev9e1d97a2018-06-29 16:04:30 +03001245
1246/**
1247 * Function receives connection string, target and configuration yaml pattern
1248 * and retrieves config fom salt minion according to pattern. After that it
1249 * sorts applications according to priorities and runs orchestration states
1250 * @param master Salt Connection object or pepperEnv
1251 * @param tgt Target
1252 * @param conf Configuration pattern
1253 */
1254def OrchestrateApplications(master, tgt, conf) {
1255 def salt = new com.mirantis.mk.Salt()
1256 def common = new com.mirantis.mk.Common()
1257 def _orch = salt.getConfig(master, tgt, conf)
1258 if ( !_orch['return'][0].values()[0].isEmpty() ) {
1259 Map<String,Integer> _orch_app = [:]
1260 for (k in _orch['return'][0].values()[0].keySet()) {
1261 _orch_app[k] = _orch['return'][0].values()[0][k].values()[0].toInteger()
1262 }
1263 def _orch_app_sorted = common.SortMapByValueAsc(_orch_app)
1264 common.infoMsg("Applications will be deployed in following order:"+_orch_app_sorted.keySet())
1265 for (app in _orch_app_sorted.keySet()) {
1266 salt.orchestrateSystem(master, ['expression': tgt, 'type': 'compound'], "${app}.orchestrate.deploy")
1267 }
1268 }
1269 else {
1270 common.infoMsg("No applications found for orchestration")
1271 }
Inessa Vasilevskaya85ad1a92018-10-08 12:19:47 +02001272}