blob: 94c684191542bfaa1babfb3a6102c8abdb8bd9da [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.
Martin Polreich80fa3182018-10-22 15:16:53 +020029 salt.enforceState([saltId: master, target: "I@salt:master ${extra_tgt}", state: ['reclass']])
Tomáš Kukrálb4d75222017-06-06 10:36:02 +020030
Martin Polreich80fa3182018-10-22 15:16:53 +020031 salt.enforceState([saltId: master, target: "I@salt:master ${extra_tgt}", state: ['linux.system']])
32 salt.enforceState([saltId: master, target: "I@salt:master ${extra_tgt}", state: ['salt.master'], failOnError: false, read_timeout: 120, retries: 2])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030033 salt.fullRefresh(master, "* ${extra_tgt}")
Tomáš Kukrálb4d75222017-06-06 10:36:02 +020034
Martin Polreich80fa3182018-10-22 15:16:53 +020035 salt.enforceState([saltId: master, target: "I@salt:master ${extra_tgt}", state: ['salt.minion'], failOnError: false, read_timeout: 60, retries: 2])
36 salt.enforceState([saltId: master, target: "I@salt:master ${extra_tgt}", state: ['salt.minion']])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030037 salt.fullRefresh(master, "* ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +020038 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: ['linux.network.proxy'], failOnError: false, read_timeout: 60, retries: 2])
iberezovskiy6394a8a2018-10-12 13:16:47 +040039 // Make sure all repositories are in place before proceeding with package installation from other states
Martin Polreich80fa3182018-10-22 15:16:53 +020040 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: ['linux.system.repo'], failOnError: false, read_timeout: 60, retries: 2])
Jiri Broulik94fc2592018-04-20 13:47:51 +020041 try {
Martin Polreich80fa3182018-10-22 15:16:53 +020042 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: ['salt.minion.base'], failOnError: false, read_timeout: 60, retries: 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){
Martin Polreich80fa3182018-10-22 15:16:53 +020048 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: ['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){
Martin Polreich80fa3182018-10-22 15:16:53 +020054 salt.enforceState([saltId: master, target: "I@linux:network:interface ${extra_tgt}", state: ['linux.network.interface']])
Ondrej Smola855dc1a2018-07-18 13:07:55 +020055 }
Jiri Broulik94538462018-05-11 15:45:13 +020056 sleep(5)
Martin Polreich80fa3182018-10-22 15:16:53 +020057 salt.enforceState([saltId: master, target: "I@linux:system ${extra_tgt}", state: ['linux', 'openssh', 'ntp', 'rsyslog']])
Ann Taraday49059762018-10-25 17:04:58 +040058
Ann Taradayfb2d4372018-10-30 17:17:09 +040059
Martin Polreich80fa3182018-10-22 15:16:53 +020060 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: ['salt.minion'], failOnError: false, read_timeout: 60, retries: 2])
Ann Taradayfb2d4372018-10-30 17:17:09 +040061
Jakub Josef4f8f4df2017-09-01 14:32:42 +020062 sleep(5)
Victor Ryzhenkinf610c572018-05-15 15:22:52 +040063
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030064 salt.fullRefresh(master, "* ${extra_tgt}")
65 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'mine.update', [], null, true)
Martin Polreich80fa3182018-10-22 15:16:53 +020066 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: ['linux.network.host']])
Ivan Suzdal9a6bc392018-04-26 18:29:56 +040067
68 // Install and configure iptables
Martin Polreich80fa3182018-10-22 15:16:53 +020069 salt.enforceStateWithTest([saltId: master, target: "I@iptables:service ${extra_tgt}", state: 'iptables'])
sgarbuzbb61e812018-05-03 16:58:40 +030070
71 // Install and configure logrotate
Martin Polreich80fa3182018-10-22 15:16:53 +020072 salt.enforceStateWithTest([saltId: master, target: "I@logrotate:server ${extra_tgt}", state: 'logrotate'])
Ivan Suzdal9f8f0e12018-06-21 13:16:21 +040073
74 // Install and configure auditd
Martin Polreich80fa3182018-10-22 15:16:53 +020075 salt.enforceStateWithTest([saltId: master, target: "I@auditd:service ${extra_tgt}", state: 'auditd'])
Ivan Suzdalca980912018-08-02 09:35:07 +040076
77 // Install and configure openscap
Martin Polreich80fa3182018-10-22 15:16:53 +020078 salt.enforceStateWithTest([saltId: master, target: "I@openscap:service ${extra_tgt}", state: 'openscap'])
Jakub Josef79ecec32017-02-17 14:36:28 +010079}
80
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030081def installFoundationInfraOnTarget(master, target, staticMgmtNet=false, extra_tgt = '') {
Jiri Broulik976bf6c2017-10-20 14:43:25 +020082 def salt = new com.mirantis.mk.Salt()
Jiri Broulik9fb138a2018-04-23 17:13:00 +020083 def common = new com.mirantis.mk.Common()
Jiri Broulik976bf6c2017-10-20 14:43:25 +020084
Martin Polreich80fa3182018-10-22 15:16:53 +020085 salt.enforceState([saltId: master, target: "I@salt:master ${extra_tgt}", state: ['reclass'], failOnError: false, read_timeout: 120, retries: 2])
Jakub Josef432e9d92018-02-06 18:28:37 +010086 salt.fullRefresh(master, target)
Martin Polreich80fa3182018-10-22 15:16:53 +020087 salt.enforceState([saltId: master, target: target, state: ['linux.network.proxy'], failOnError: false, read_timeout: 60, retries: 2])
Jiri Broulik94fc2592018-04-20 13:47:51 +020088 try {
Martin Polreich80fa3182018-10-22 15:16:53 +020089 salt.enforceState([saltId: master, target: target, state: ['salt.minion.base'], failOnError: false, read_timeout: 60, retries: 2])
Jiri Broulik94fc2592018-04-20 13:47:51 +020090 sleep(5)
91 } catch (Throwable e) {
92 common.warningMsg('Salt state salt.minion.base is not present in the Salt-formula yet.')
93 }
Jiri Broulike3ace622018-06-07 10:51:02 +020094 common.retry(2,5){
Martin Polreich80fa3182018-10-22 15:16:53 +020095 salt.enforceState([saltId: master, target: target, state: ['linux.system']])
Jiri Broulike3ace622018-06-07 10:51:02 +020096 }
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +010097 if (staticMgmtNet) {
98 salt.runSaltProcessStep(master, target, 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], null, true, 60)
99 }
Martin Polreich80fa3182018-10-22 15:16:53 +0200100 salt.enforceState([saltId: master, target: target, state: ['salt.minion'], failOnError: false, read_timeout: 60, retries: 2])
101 salt.enforceState([saltId: master, target: target, state: ['salt.minion']])
102 salt.enforceState([saltId: master, target: target, state: ['linux.network.interface']])
Jiri Broulik94538462018-05-11 15:45:13 +0200103 sleep(5)
Martin Polreich80fa3182018-10-22 15:16:53 +0200104 salt.enforceState([saltId: master, target: target, state: ['linux', 'openssh', 'ntp', 'rsyslog']])
Jiri Broulik976bf6c2017-10-20 14:43:25 +0200105 sleep(5)
Victor Ryzhenkinf610c572018-05-15 15:22:52 +0400106
107 salt.fullRefresh(master, target)
vrovachevc4424a32018-03-15 17:35:57 +0400108 salt.runSaltProcessStep(master, target, 'mine.update', [], null, true)
Martin Polreich80fa3182018-10-22 15:16:53 +0200109 salt.enforceState([saltId: master, target: target, state: ['linux.network.host']])
Jiri Broulik976bf6c2017-10-20 14:43:25 +0200110}
111
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300112def installInfraKvm(master, extra_tgt = '') {
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200113 def common = new com.mirantis.mk.Common()
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +0100114 def salt = new com.mirantis.mk.Salt()
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300115 def infra_compound = "I@salt:control ${extra_tgt}"
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200116 def minions = []
117 def wait_timeout = 10
118 def retries = wait_timeout * 30
Ales Komarekef2bab62017-04-26 11:48:28 +0200119
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300120 salt.fullRefresh(master, "I@linux:system ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200121 salt.enforceState([saltId: master, target: "I@salt:control ${extra_tgt}", state: ['salt.minion'], failOnError: false, read_timeout: 60, retries: 2])
122 salt.enforceState([saltId: master, target: "I@salt:control ${extra_tgt}", state: ['linux.system', 'linux.network', 'ntp', 'rsyslog']])
123 salt.enforceState([saltId: master, target: "I@salt:control ${extra_tgt}", state: 'libvirt'])
124 salt.enforceState([saltId: master, target: "I@salt:control ${extra_tgt}", state: 'salt.control'])
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100125
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200126 common.infoMsg("Building minions list...")
127 if (salt.testTarget(master, infra_compound)) {
128 // Gathering minions
129 for ( infra_node in salt.getMinionsSorted(master, infra_compound) ) {
130 def pillar = salt.getPillar(master, infra_node, 'salt:control:cluster')
131 if ( !pillar['return'].isEmpty() ) {
132 for ( cluster in pillar['return'][0].values() ) {
133 def engine = cluster.values()[0]['engine']
134 def domain = cluster.values()[0]['domain']
135 def node = cluster.values()[0]['node']
136 if ( engine == "virt" ) {
137 def nodes = node.values()
138 if ( !nodes.isEmpty() ) {
139 for ( vm in nodes ) {
140 if ( vm['name'] != null ) {
141 def vm_fqdn = vm['name'] + '.' + domain
142 if ( !minions.contains(vm_fqdn) ) {
143 minions.add(vm_fqdn)
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200144 }
145 }
146 }
147 }
148 }
149 }
150 }
151 }
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200152 }
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100153
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200154 def minions_compound = minions.join(' or ')
155
156 common.infoMsg("Waiting for next minions to register within ${wait_timeout} minutes: " + minions_compound)
157 timeout(time: wait_timeout, unit: 'MINUTES') {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300158 salt.minionsPresentFromList(master, "I@salt:master ${extra_tgt}", minions, true, null, true, retries, 1)
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200159 }
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200160
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200161 common.infoMsg('Waiting for minions to respond')
162 timeout(time: wait_timeout, unit: 'MINUTES') {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300163 salt.minionsReachable(master, "I@salt:master ${extra_tgt}", minions_compound)
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200164 }
165
166 common.infoMsg("All minions are up.")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300167 salt.fullRefresh(master, "* and not kvm* ${extra_tgt}")
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200168
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +0100169}
Jakub Josef79ecec32017-02-17 14:36:28 +0100170
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300171def installInfra(master, extra_tgt = '') {
Jakub Josef61463c72018-02-13 16:10:56 +0100172 def common = new com.mirantis.mk.Common()
Jakub Josef79ecec32017-02-17 14:36:28 +0100173 def salt = new com.mirantis.mk.Salt()
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400174 def first_target
Ales Komarekef2bab62017-04-26 11:48:28 +0200175
Jakub Josef79ecec32017-02-17 14:36:28 +0100176 // Install glusterfs
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300177 if (salt.testTarget(master, "I@glusterfs:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200178 salt.enforceState([saltId: master, target: "I@glusterfs:server ${extra_tgt}", state: 'glusterfs.server.service'])
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100179
Martin Polreich80fa3182018-10-22 15:16:53 +0200180 salt.enforceState([saltId: master, target: "I@glusterfs:server:role:primary ${extra_tgt}", state: 'glusterfs.server.setup', retries: 5])
Jakub Josef61463c72018-02-13 16:10:56 +0100181 sleep(10)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300182 salt.cmdRun(master, "I@glusterfs:server ${extra_tgt}", "gluster peer status; gluster volume status")
Alexander Noskov93acac42017-06-20 17:55:55 +0200183 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200184
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300185 // Ensure glusterfs clusters is ready
Martin Polreich80fa3182018-10-22 15:16:53 +0200186 salt.enforceStateWithTest([saltId: master, target: "I@glusterfs:client ${extra_tgt}", state: 'glusterfs.client', retries: 2])
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300187
Jakub Josef79ecec32017-02-17 14:36:28 +0100188 // Install galera
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300189 if (salt.testTarget(master, "I@galera:master ${extra_tgt}") || salt.testTarget(master, "I@galera:slave ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200190 salt.enforceState([saltId: master, target: "I@galera:master ${extra_tgt}", state: 'galera', retries: 2])
191 salt.enforceStateWithTest([saltId: master, target: "I@galera:slave ${extra_tgt}", state: 'galera', retries: 2])
vrovachev1c4770b2017-07-05 13:25:21 +0400192
193 // Check galera status
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300194 salt.runSaltProcessStep(master, "I@galera:master ${extra_tgt}", 'mysql.status')
Dzmitry Stremkouskidf727b22018-10-29 17:19:55 +0100195 if (salt.testTarget(master, "I@galera:slave ${extra_tgt}")) {
196 salt.runSaltProcessStep(master, "I@galera:slave ${extra_tgt}", 'mysql.status')
197 }
198
Vasyl Saienkoc1fb9892017-07-13 14:54:13 +0300199 // If galera is not enabled check if we need to install mysql:server
Martin Polreich675dc942018-08-15 09:37:32 +0200200 } else {
Dzmitry Stremkouskidf727b22018-10-29 17:19:55 +0100201
Martin Polreich80fa3182018-10-22 15:16:53 +0200202 salt.enforceStateWithTest([saltId: master, target: "I@mysql:server ${extra_tgt}", state: 'mysql.server'])
203 salt.enforceStateWithTest([saltId: master, target: "I@mysql:client ${extra_tgt}", state: 'mysql.client'])
Dzmitry Stremkouskidf727b22018-10-29 17:19:55 +0100204
Ales Komarekef2bab62017-04-26 11:48:28 +0200205 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300206 installBackup(master, 'mysql', extra_tgt)
Ales Komarekef2bab62017-04-26 11:48:28 +0200207
vrovachev1c4770b2017-07-05 13:25:21 +0400208 // Install docker
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300209 if (salt.testTarget(master, "I@docker:host ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200210 salt.enforceState([saltId: master, target: "I@docker:host ${extra_tgt}", state: 'docker.host', retries: 3])
Pavel Cizinskyee34e312018-08-06 15:11:58 +0200211 salt.cmdRun(master, "I@docker:host and I@docker:host:enabled:true ${extra_tgt}", 'docker ps')
vrovachev1c4770b2017-07-05 13:25:21 +0400212 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200213
vrovachev1c4770b2017-07-05 13:25:21 +0400214 // Install keepalived
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300215 if (salt.testTarget(master, "I@keepalived:cluster ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400216 first_target = salt.getFirstMinion(master, "I@keepalived:cluster ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200217 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'keepalived'])
218 salt.enforceState([saltId: master, target: "I@keepalived:cluster ${extra_tgt}", state: 'keepalived'])
vrovachev1c4770b2017-07-05 13:25:21 +0400219 }
220
221 // Install rabbitmq
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300222 if (salt.testTarget(master, "I@rabbitmq:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200223 salt.enforceState([saltId: master, target: "I@rabbitmq:server ${extra_tgt}", state: 'rabbitmq', retries: 2])
vrovachev1c4770b2017-07-05 13:25:21 +0400224
225 // Check the rabbitmq status
Jakub Josef61463c72018-02-13 16:10:56 +0100226 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300227 salt.cmdRun(master, "I@rabbitmq:server ${extra_tgt}", 'rabbitmqctl cluster_status')
Jakub Josef61463c72018-02-13 16:10:56 +0100228 }
vrovachev1c4770b2017-07-05 13:25:21 +0400229 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200230
Jakub Josef79ecec32017-02-17 14:36:28 +0100231 // Install haproxy
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300232 if (salt.testTarget(master, "I@haproxy:proxy ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200233 salt.enforceState([saltId: master, target: "I@haproxy:proxy ${extra_tgt}", state: 'haproxy'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300234 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.status', ['haproxy'])
235 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.restart', ['rsyslog'])
vrovachev1c4770b2017-07-05 13:25:21 +0400236 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200237
Jakub Josef79ecec32017-02-17 14:36:28 +0100238 // Install memcached
Martin Polreich80fa3182018-10-22 15:16:53 +0200239 salt.enforceStateWithTest([saltId: master, target: "I@memcached:server ${extra_tgt}", state: 'memcached'])
vrovachev1c4770b2017-07-05 13:25:21 +0400240
241 // Install etcd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300242 if (salt.testTarget(master, "I@etcd:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200243 salt.enforceState([saltId: master, target: "I@etcd:server ${extra_tgt}", state: 'etcd.server.service'])
Jakub Josef61463c72018-02-13 16:10:56 +0100244 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300245 salt.cmdRun(master, "I@etcd:server ${extra_tgt}", '. /var/lib/etcd/configenv && etcdctl cluster-health')
Jakub Josef61463c72018-02-13 16:10:56 +0100246 }
vrovachev1c4770b2017-07-05 13:25:21 +0400247 }
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200248
249 // Install redis
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300250 if (salt.testTarget(master, "I@redis:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200251 salt.enforceStateWithTest([saltId: master, target: "I@redis:cluster:role:master ${extra_tgt}", state: 'redis'])
252 salt.enforceState([saltId: master, target: "I@redis:server ${extra_tgt}", state: 'redis'])
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200253 }
Mykyta Karpin0a3dc8b2018-09-05 10:09:18 +0300254
255 // Install DNS services
256 if (salt.testTarget(master, "I@bind:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200257 salt.enforceState([saltId: master, target: "I@bind:server ${extra_tgt}", state: 'bind.server'])
Mykyta Karpin0a3dc8b2018-09-05 10:09:18 +0300258 }
259 if (salt.testTarget(master, "I@powerdns:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200260 salt.enforceState([saltId: master, target: "I@powerdns:server ${extra_tgt}", state: 'powerdns.server'])
Mykyta Karpin0a3dc8b2018-09-05 10:09:18 +0300261 }
262
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300263 installBackup(master, 'common', extra_tgt)
vrovachev1c4770b2017-07-05 13:25:21 +0400264}
265
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300266def installOpenstackInfra(master, extra_tgt = '') {
Jakub Josef432e9d92018-02-06 18:28:37 +0100267 def common = new com.mirantis.mk.Common()
268 common.warningMsg("You calling orchestrate.installOpenstackInfra(). This function is deprecated please use orchestrate.installInfra() directly")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300269 installInfra(master, extra_tgt)
Jakub Josef79ecec32017-02-17 14:36:28 +0100270}
271
272
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300273def installOpenstackControl(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100274 def salt = new com.mirantis.mk.Salt()
Jakub Josef61463c72018-02-13 16:10:56 +0100275 def common = new com.mirantis.mk.Common()
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400276 def first_target
Ales Komarekef2bab62017-04-26 11:48:28 +0200277
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100278 // Install sphinx server
Martin Polreich80fa3182018-10-22 15:16:53 +0200279 salt.enforceStateWithTest([saltId: master, target: "I@sphinx:server ${extra_tgt}", state: 'sphinx'])
Mykyta Karpin014131a2018-12-18 17:35:38 +0200280 // Running minion states in a batch to avoid races related to certificates which are placed on glusterfs
281 // Details on races: https://mirantis.jira.com/browse/PROD-25796
282 // TODO: Run in parallel when glusterfs for certificates is dropped in cookiecutter
Martin Polreich80fa3182018-10-22 15:16:53 +0200283 salt.enforceStateWithTest([saltId: master, target: "I@nginx:server ${extra_tgt}", state: 'salt.minion', batch: 1])
284 salt.enforceStateWithTest([saltId: master, target: "I@nginx:server ${extra_tgt}", state: 'nginx'])
Ales Komarekef2bab62017-04-26 11:48:28 +0200285
Jakub Josef79ecec32017-02-17 14:36:28 +0100286 // setup keystone service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300287 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200288 salt.enforceState([saltId: master, target: "I@keystone:server:role:primary ${extra_tgt}", state: 'keystone.server'])
289 salt.enforceState([saltId: master, target: "I@keystone:server ${extra_tgt}", state: 'keystone.server'])
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300290 // populate keystone services/tenants/roles/users
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100291
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300292 // keystone:client must be called locally
293 //salt.runSaltProcessStep(master, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300294 salt.runSaltProcessStep(master, "I@keystone:server ${extra_tgt}", 'service.restart', ['apache2'])
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300295 sleep(30)
296 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300297 if (salt.testTarget(master, "I@keystone:client ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400298 first_target = salt.getFirstMinion(master, "I@keystone:client ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200299 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'keystone.client'])
300 salt.enforceState([saltId: master, target: "I@keystone:client ${extra_tgt}", state: 'keystone.client'])
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300301 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300302 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Jakub Josef61463c72018-02-13 16:10:56 +0100303 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300304 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack service list')
Jakub Josef61463c72018-02-13 16:10:56 +0100305 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300306 }
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100307
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300308 // Install glance
Martin Polreich80fa3182018-10-22 15:16:53 +0200309 salt.enforceStateWithTest([saltId: master, target: "I@glance:server:role:primary ${extra_tgt}", state: 'glance.server', testTargetMatcher: "I@glance:server ${extra_tgt}"])
310 salt.enforceStateWithTest([saltId: master, target: "I@glance:server ${extra_tgt}", state: 'glance.server'])
Ales Komarekef2bab62017-04-26 11:48:28 +0200311
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300312 // Check glance service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300313 if (salt.testTarget(master, "I@glance:server ${extra_tgt}")) {
Mykyta Karpinfc169b72018-11-19 09:57:07 +0200314 common.retry(10,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300315 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; glance image-list')
Jakub Josef61463c72018-02-13 16:10:56 +0100316 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300317 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200318
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400319 // Create glance resources
Martin Polreich80fa3182018-10-22 15:16:53 +0200320 salt.enforceStateWithTest([saltId: master, target: "I@glance:client ${extra_tgt}", state: 'glance.client'])
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400321
Jakub Josef79ecec32017-02-17 14:36:28 +0100322 // Install and check nova service
Martin Polreich675dc942018-08-15 09:37:32 +0200323 // run on first node first
Martin Polreich80fa3182018-10-22 15:16:53 +0200324 salt.enforceStateWithTest([saltId: master, target: "I@nova:controller:role:primary ${extra_tgt}", state: 'nova.controller', testTargetMatcher: "I@nova:controller ${extra_tgt}"])
325 salt.enforceStateWithTest([saltId: master, target: "I@nova:controller ${extra_tgt}", state: 'nova.controller'])
Martin Polreich675dc942018-08-15 09:37:32 +0200326 if (salt.testTarget(master, "I@keystone:server and I@nova:controller ${extra_tgt}")) {
327 common.retry(3,5){
328 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; nova service-list')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300329 }
330 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200331
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400332 // Create nova resources
Martin Polreich80fa3182018-10-22 15:16:53 +0200333 salt.enforceStateWithTest([saltId: master, target: "I@nova:client ${extra_tgt}", state: 'nova.client'])
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400334
Jakub Josef79ecec32017-02-17 14:36:28 +0100335 // Install and check cinder service
Martin Polreich675dc942018-08-15 09:37:32 +0200336 // run on first node first
Martin Polreich80fa3182018-10-22 15:16:53 +0200337 salt.enforceStateWithTest([saltId: master, target: "I@cinder:controller:role:primary ${extra_tgt}", state: 'cinder', testTargetMatcher: "I@cinder:controller ${extra_tgt}"])
338 salt.enforceStateWithTest([saltId: master, target: "I@cinder:controller ${extra_tgt}", state: 'cinder'])
Martin Polreich675dc942018-08-15 09:37:32 +0200339 if (salt.testTarget(master, "I@keystone:server and I@cinder:controller ${extra_tgt}")) {
340 common.retry(3,5){
341 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; cinder list')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300342 }
343 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200344
Jakub Josef79ecec32017-02-17 14:36:28 +0100345 // Install neutron service
Martin Polreich675dc942018-08-15 09:37:32 +0200346 // run on first node first
Martin Polreich80fa3182018-10-22 15:16:53 +0200347 salt.enforceStateWithTest([saltId: master, target: "I@neutron:server:role:primary ${extra_tgt}", state: 'neutron.server', testTargetMatcher: "I@neutron:server ${extra_tgt}"])
348 salt.enforceStateWithTest([saltId: master, target: "I@neutron:server ${extra_tgt}", state: 'neutron.server'])
Martin Polreich675dc942018-08-15 09:37:32 +0200349 if (salt.testTarget(master, "I@keystone:server and I@neutron:server ${extra_tgt}")) {
Vasyl Saienko0b86a4f2018-11-16 14:02:34 +0200350 common.retry(10,5){
Martin Polreich675dc942018-08-15 09:37:32 +0200351 salt.cmdRun(master, "I@keystone:server ${extra_tgt}",'. /root/keystonercv3; neutron agent-list')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300352 }
353 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200354
Jakub Josef79ecec32017-02-17 14:36:28 +0100355 // Install heat service
Martin Polreich80fa3182018-10-22 15:16:53 +0200356 salt.enforceStateWithTest([saltId: master, target: "I@heat:server:role:primary ${extra_tgt}", state: 'heat', testTargetMatcher: "I@heat:server ${extra_tgt}"])
357 salt.enforceStateWithTest([saltId: master, target: "I@heat:server ${extra_tgt}", state: 'heat'])
Martin Polreich675dc942018-08-15 09:37:32 +0200358 if (salt.testTarget(master, "I@keystone:server and I@heat:server ${extra_tgt}")) {
Mykyta Karpina678da62018-12-20 17:26:51 +0200359 common.retry(10,5){
Martin Polreich675dc942018-08-15 09:37:32 +0200360 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack orchestration resource type list')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300361 }
362 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200363
364 // Restart nova api
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300365 if (salt.testTarget(master, "I@nova:controller ${extra_tgt}")) {
366 salt.runSaltProcessStep(master, "I@nova:controller ${extra_tgt}", 'service.restart', ['nova-api'])
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300367 }
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300368
369 // Install ironic service
Martin Polreich80fa3182018-10-22 15:16:53 +0200370 salt.enforceStateWithTest([saltId: master, target: "I@ironic:api:role:primary ${extra_tgt}", state: 'ironic.api', testTargetMatcher: "I@ironic:api ${extra_tgt}"])
371 salt.enforceStateWithTest([saltId: master, target: "I@ironic:api ${extra_tgt}", state: 'ironic.api'])
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300372
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200373 // Install manila service
Martin Polreich80fa3182018-10-22 15:16:53 +0200374 salt.enforceStateWithTest([saltId: master, target: "I@manila:api:role:primary ${extra_tgt}", state: 'manila.api', testTargetMatcher: "I@manila:api ${extra_tgt}"])
375 salt.enforceStateWithTest([saltId: master, target: "I@manila:api ${extra_tgt}", state: 'manila.api'])
376 salt.enforceStateWithTest([saltId: master, target: "I@manila:scheduler ${extra_tgt}", state: 'manila.scheduler'])
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200377
Oleh Hryhorova070fd02018-03-15 14:47:52 +0200378 // Install designate services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300379 if (salt.testTarget(master, "I@designate:server:enabled ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200380 salt.enforceState([saltId: master, target: "I@designate:server:role:primary ${extra_tgt}", state: 'designate.server'])
381 salt.enforceState([saltId: master, target: "I@designate:server ${extra_tgt}", state: 'designate'])
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300382 }
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400383
384 // Install octavia api service
Martin Polreich80fa3182018-10-22 15:16:53 +0200385 salt.enforceStateWithTest([saltId: master, target: "I@octavia:api:role:primary ${extra_tgt}", state: 'octavia.api', testTargetMatcher: "I@octavia:api ${extra_tgt}"])
386 salt.enforceStateWithTest([saltId: master, target: "I@octavia:api ${extra_tgt}", state: 'octavia.api'])
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200387
Oleg Iurchenkod0898c92017-12-14 14:28:44 +0200388 // Install DogTag server service
Martin Polreich80fa3182018-10-22 15:16:53 +0200389 salt.enforceStateWithTest([saltId: master, target: "I@dogtag:server:role:master ${extra_tgt}", state: 'dogtag.server', testTargetMatcher: "I@dogtag:server ${extra_tgt}"])
390 salt.enforceStateWithTest([saltId: master, target: "I@dogtag:server ${extra_tgt}", state: 'dogtag.server'])
Oleg Iurchenkod0898c92017-12-14 14:28:44 +0200391
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200392 // Install barbican server service
Martin Polreich80fa3182018-10-22 15:16:53 +0200393 salt.enforceStateWithTest([saltId: master, target: "I@barbican:server:role:primary ${extra_tgt}", state: 'barbican.server', testTargetMatcher: "I@barbican:server ${extra_tgt}"])
394 salt.enforceStateWithTest([saltId: master, target: "I@barbican:server ${extra_tgt}", state: 'barbican.server'])
Martin Polreich675dc942018-08-15 09:37:32 +0200395
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200396 // Install barbican client
Martin Polreich80fa3182018-10-22 15:16:53 +0200397 salt.enforceStateWithTest([saltId: master, target: "I@barbican:client ${extra_tgt}", state: 'barbican.client'])
Ondrej Smola5908ae62018-01-08 13:42:08 +0100398
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200399 // Install gnocchi server
Martin Polreich80fa3182018-10-22 15:16:53 +0200400 salt.enforceStateWithTest([saltId: master, target: "I@gnocchi:server:role:primary ${extra_tgt}", state: 'gnocchi.server', testTargetMatcher: "I@gnocchi:server ${extra_tgt}"])
401 salt.enforceStateWithTest([saltId: master, target: "I@gnocchi:server ${extra_tgt}", state: 'gnocchi.server'])
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200402
Mykyta Karpin4816e522018-06-15 16:00:03 +0300403 // Apply gnocchi client state to create gnocchi archive policies, due to possible
404 // races, apply on the first node initially
405 if (salt.testTarget(master, "I@gnocchi:client ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400406 first_target = salt.getFirstMinion(master, "I@gnocchi:client ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200407 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'gnocchi.client'])
408 salt.enforceState([saltId: master, target: "I@gnocchi:client ${extra_tgt}", state: 'gnocchi.client'])
Mykyta Karpin4816e522018-06-15 16:00:03 +0300409 }
410
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200411 // Install gnocchi statsd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300412 if (salt.testTarget(master, "I@gnocchi:statsd ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400413 first_target = salt.getFirstMinion(master, "I@gnocchi:statsd ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200414 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'gnocchi.statsd'])
415 salt.enforceState([saltId: master, target: "I@gnocchi:statsd ${extra_tgt}", state: 'gnocchi.statsd'])
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200416 }
417
418 // Install panko server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300419 if (salt.testTarget(master, "I@panko:server ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400420 first_target = salt.getFirstMinion(master, "I@panko:server ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200421 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'panko'])
422 salt.enforceState([saltId: master, target: "I@panko:server ${extra_tgt}", state: 'panko'])
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200423 }
424
Ondrej Smola5908ae62018-01-08 13:42:08 +0100425 // Install ceilometer server
Martin Polreich80fa3182018-10-22 15:16:53 +0200426 salt.enforceStateWithTest([saltId: master, target: "I@ceilometer:server:role:primary ${extra_tgt}", state: 'ceilometer', testTargetMatcher: "I@ceilometer:server ${extra_tgt}"])
427 salt.enforceStateWithTest([saltId: master, target: "I@ceilometer:server ${extra_tgt}", state: 'ceilometer'])
Ondrej Smola5908ae62018-01-08 13:42:08 +0100428
429 // Install aodh server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300430 if (salt.testTarget(master, "I@aodh:server ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400431 first_target = salt.getFirstMinion(master, "I@aodh:server ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200432 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'aodh'])
433 salt.enforceState([saltId: master, target: "I@aodh:server ${extra_tgt}", state: 'aodh'])
Ondrej Smola5908ae62018-01-08 13:42:08 +0100434 }
Oleksandr Bryndzii642cb252018-11-08 12:24:42 +0200435
436 // Install horizon dashboard
Martin Polreich80fa3182018-10-22 15:16:53 +0200437 salt.enforceStateWithTest([saltId: master, target: "I@horizon:server ${extra_tgt}", state: 'horizon'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100438}
439
440
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300441def installIronicConductor(master, extra_tgt = ''){
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300442 def salt = new com.mirantis.mk.Salt()
443
Martin Polreich80fa3182018-10-22 15:16:53 +0200444 salt.enforceStateWithTest([saltId: master, target: "I@ironic:conductor ${extra_tgt}", state: 'ironic.conductor'])
445 salt.enforceStateWithTest([saltId: master, target: "I@ironic:conductor ${extra_tgt}", state: 'apache'])
446 salt.enforceStateWithTest([saltId: master, target: "I@tftpd_hpa:server ${extra_tgt}", state: 'tftpd_hpa'])
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300447
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300448 if (salt.testTarget(master, "I@nova:compute ${extra_tgt}")) {
449 salt.runSaltProcessStep(master, "I@nova:compute ${extra_tgt}", 'service.restart', ['nova-compute'])
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300450 }
451
Martin Polreich80fa3182018-10-22 15:16:53 +0200452 salt.enforceStateWithTest([saltId: master, target: "I@baremetal_simulator:enabled ${extra_tgt}", state: 'baremetal_simulator'])
453 salt.enforceStateWithTest([saltId: master, target: "I@ironic:client ${extra_tgt}", state: 'ironic.client'])
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300454}
455
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300456def installManilaShare(master, extra_tgt = ''){
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200457 def salt = new com.mirantis.mk.Salt()
458
Martin Polreich80fa3182018-10-22 15:16:53 +0200459 salt.enforceStateWithTest([saltId: master, target: "I@manila:share ${extra_tgt}", state: 'manila.share'])
460 salt.enforceStateWithTest([saltId: master, target: "I@manila:data ${extra_tgt}", state: 'manila.data'])
461 salt.enforceStateWithTest([saltId: master, target: "I@manila:client ${extra_tgt}", state: 'manila.client'])
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200462}
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300463
464
Oleh Hryhorov37fbd0c2018-07-11 16:58:54 +0300465def installOpenstackNetwork(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100466 def salt = new com.mirantis.mk.Salt()
Ann Taradayea9848c2018-10-25 11:15:58 +0400467 def common = new com.mirantis.mk.Common()
Dzmitry Stremkouskidf727b22018-10-29 17:19:55 +0100468
Oleksii Grudevc4a485e2018-04-20 14:25:03 +0300469 //run full neutron state on neutron.gateway - this will install
470 //neutron agents in addition to neutron server. Once neutron agents
471 //are up neutron resources can be created without hitting the situation when neutron resources are created
472 //prior to neutron agents which results in creating ports in non-usable state
Martin Polreich80fa3182018-10-22 15:16:53 +0200473 salt.enforceStateWithTest([saltId: master, target: "I@neutron:gateway ${extra_tgt}", state: 'neutron'])
Oleksii Grudevc4a485e2018-04-20 14:25:03 +0300474
475 // Create neutron resources - this step was moved here to ensure that
476 //neutron resources are created after neutron agens are up. In this case neutron ports will be in
477 //usable state. More information: https://bugs.launchpad.net/neutron/+bug/1399249
Martin Polreich80fa3182018-10-22 15:16:53 +0200478 salt.enforceStateWithTest([saltId: master, target: "I@neutron:client ${extra_tgt}", state: 'neutron.client'])
Ales Komarekef2bab62017-04-26 11:48:28 +0200479
Dzmitry Stremkouskidf727b22018-10-29 17:19:55 +0100480 if (salt.testTarget(master, "I@neutron:gateway ${extra_tgt}")) {
481 salt.enforceHighstate(master, "I@neutron:gateway ${extra_tgt}")
482 }
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400483
484 // install octavia manager services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300485 if (salt.testTarget(master, "I@octavia:manager ${extra_tgt}")) {
Anna Taraday82224102018-10-09 07:44:24 +0000486 salt.runSaltProcessStep(master, "I@neutron:client ${extra_tgt}", 'mine.update')
Martin Polreich80fa3182018-10-22 15:16:53 +0200487 salt.enforceState([saltId: master, target: "I@octavia:manager ${extra_tgt}", state: 'octavia.manager'])
488 salt.enforceState([saltId: master, target: "I@octavia:client ${extra_tgt}", state: 'octavia.client'])
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400489 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200490}
491
492
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300493def installOpenstackCompute(master, extra_tgt = '') {
Ales Komarekef2bab62017-04-26 11:48:28 +0200494 def salt = new com.mirantis.mk.Salt()
Mykyta Karpin3ec78a22018-07-10 12:27:09 +0300495 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200496 // Configure compute nodes
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300497 def compute_compound = "I@nova:compute ${extra_tgt}"
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100498 if (salt.testTarget(master, compute_compound)) {
499 // In case if infrastructure nodes are used as nova computes too
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300500 def gluster_compound = "I@glusterfs:server ${extra_tgt}"
501 def salt_ca_compound = "I@salt:minion:ca:salt_master_ca ${extra_tgt}"
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200502 // Enforce highstate asynchronous only on compute nodes which are not glusterfs and not salt ca servers
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300503 def hightstateTarget = "${compute_compound} and not ${gluster_compound} and not ${salt_ca_compound}"
Oleh Hryhorov73f9fa22018-05-02 17:36:58 +0300504 if (salt.testTarget(master, hightstateTarget)) {
505 retry(2) {
Vasyl Saienkobe599d12018-11-10 06:42:50 +0000506 salt.enforceHighstate(master, hightstateTarget)
Oleh Hryhorov73f9fa22018-05-02 17:36:58 +0300507 }
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300508 } else {
509 common.infoMsg("No minions matching highstate target found for target ${hightstateTarget}")
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200510 }
511 // Iterate through salt ca servers and check if they have compute role
512 // TODO: switch to batch once salt 2017.7+ would be used
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300513 common.infoMsg("Checking whether ${salt_ca_compound} minions have ${compute_compound} compound")
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200514 for ( target in salt.getMinionsSorted(master, salt_ca_compound) ) {
515 for ( cmp_target in salt.getMinionsSorted(master, compute_compound) ) {
516 if ( target == cmp_target ) {
517 // Enforce highstate one by one on salt ca servers which are compute nodes
518 retry(2) {
Vasyl Saienkobe599d12018-11-10 06:42:50 +0000519 salt.enforceHighstate(master, target)
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200520 }
521 }
522 }
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100523 }
524 // Iterate through glusterfs servers and check if they have compute role
525 // TODO: switch to batch once salt 2017.7+ would be used
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300526 common.infoMsg("Checking whether ${gluster_compound} minions have ${compute_compound} compound")
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100527 for ( target in salt.getMinionsSorted(master, gluster_compound) ) {
528 for ( cmp_target in salt.getMinionsSorted(master, compute_compound) ) {
529 if ( target == cmp_target ) {
530 // Enforce highstate one by one on glusterfs servers which are compute nodes
531 retry(2) {
Vasyl Saienkobe599d12018-11-10 06:42:50 +0000532 salt.enforceHighstate(master, target)
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100533 }
534 }
535 }
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200536 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200537 }
Vasyl Saienko51144e42018-06-19 09:30:30 +0300538
539 // Run nova:controller to map cmp with cells
Martin Polreich80fa3182018-10-22 15:16:53 +0200540 salt.enforceStateWithTest([saltId: master, target: "I@nova:controller:role:primary ${extra_tgt}", state: 'nova.controller', testTargetMatcher: "I@nova:controller ${extra_tgt}"])
Ales Komarekef2bab62017-04-26 11:48:28 +0200541}
542
543
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300544def installContrailNetwork(master, extra_tgt = '') {
Martin Polreichfc9854c2017-06-30 11:17:36 +0200545 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200546 def salt = new com.mirantis.mk.Salt()
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400547 def first_target
Ales Komarekef2bab62017-04-26 11:48:28 +0200548
Jakub Josef79ecec32017-02-17 14:36:28 +0100549 // Install opencontrail database services
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400550 first_target = salt.getFirstMinion(master, "I@opencontrail:database ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200551 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'opencontrail.database'])
552 salt.enforceState([saltId: master, target: "I@opencontrail:database ${extra_tgt}", state: 'opencontrail.database'])
Ales Komarekef2bab62017-04-26 11:48:28 +0200553
Jakub Josef79ecec32017-02-17 14:36:28 +0100554 // Install opencontrail control services
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400555 first_target = salt.getFirstMinion(master, "I@opencontrail:control ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200556 salt.enforceStateWithExclude([saltId: master, target: "${first_target} ${extra_tgt}", state: "opencontrail", excludedStates: "opencontrail.client"])
557 salt.enforceStateWithExclude([saltId: master, target: "I@opencontrail:control ${extra_tgt}", state: "opencontrail", excludedStates: "opencontrail.client"])
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400558 first_target = salt.getFirstMinion(master, "I@opencontrail:collector ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200559 salt.enforceStateWithExclude([saltId: master, target: "${first_target} ${extra_tgt}", state: "opencontrail", excludedStates: "opencontrail.client"])
560 salt.enforceStateWithExclude([saltId: master, target: "I@opencontrail:collector ${extra_tgt}", state: "opencontrail", excludedStates: "opencontrail.client"])
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100561
Martin Polreich80fa3182018-10-22 15:16:53 +0200562 salt.enforceStateWithTest([saltId: master, target: "( I@opencontrail:control or I@opencontrail:collector ) ${extra_tgt}", state: 'docker.client', testTargetMatcher: "I@docker:client and I@opencontrail:control ${extra_tgt}"])
Inessa Vasilevskaya85ad1a92018-10-08 12:19:47 +0200563 // 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 +0100564}
565
566
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300567def installContrailCompute(master, extra_tgt = '') {
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200568 def salt = new com.mirantis.mk.Salt()
vrovachev32f7f542017-08-25 16:17:25 +0400569 def common = new com.mirantis.mk.Common()
Jakub Josef79ecec32017-02-17 14:36:28 +0100570 // Configure compute nodes
Ales Komarekef2bab62017-04-26 11:48:28 +0200571 // Provision opencontrail control services
Martin Polreich80fa3182018-10-22 15:16:53 +0200572 salt.enforceState([saltId: master, target: "I@opencontrail:database:id:1 ${extra_tgt}", state: 'opencontrail.client'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100573 // Provision opencontrail virtual routers
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100574
vrovachev4ff77302017-08-09 20:39:57 +0400575 // Generate script /usr/lib/contrail/if-vhost0 for up vhost0
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300576 if (salt.testTarget(master, "I@opencontrail:compute ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200577 salt.enforceStateWithExclude([saltId: master, target: "I@opencontrail:compute ${extra_tgt}", state: "opencontrail", excludedStates: "opencontrail.client"])
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200578 }
vrovachev4ff77302017-08-09 20:39:57 +0400579
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300580 if (salt.testTarget(master, "I@nova:compute ${extra_tgt}")) {
581 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 +0200582 }
vrovachev4ff77302017-08-09 20:39:57 +0400583
Jakub Josef61463c72018-02-13 16:10:56 +0100584 sleep(300)
Martin Polreich80fa3182018-10-22 15:16:53 +0200585 salt.enforceStateWithTest([saltId: master, target: "I@opencontrail:compute ${extra_tgt}", state: 'opencontrail.client'])
586 salt.enforceStateWithTest([saltId: master, target: "I@opencontrail:compute ${extra_tgt}", state: 'opencontrail'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100587}
588
589
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300590def installKubernetesInfra(master, extra_tgt = '') {
Jakub Josef432e9d92018-02-06 18:28:37 +0100591 def common = new com.mirantis.mk.Common()
592 common.warningMsg("You calling orchestrate.installKubernetesInfra(). This function is deprecated please use orchestrate.installInfra() directly")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300593 installInfra(master, extra_tgt)
Jakub Josef79ecec32017-02-17 14:36:28 +0100594}
595
596
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300597def installKubernetesControl(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100598 def salt = new com.mirantis.mk.Salt()
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400599 def first_target
Victor Ryzhenkineb617412018-08-20 18:54:23 +0400600 salt.fullRefresh(master, "* ${extra_tgt}")
601
602 // Bootstrap all nodes
Martin Polreich80fa3182018-10-22 15:16:53 +0200603 salt.enforceState([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: 'linux'])
604 salt.enforceState([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: 'salt.minion'])
605 salt.enforceState([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: ['openssh', 'ntp']])
Victor Ryzhenkineb617412018-08-20 18:54:23 +0400606
607 // Create and distribute SSL certificates for services using salt state
Martin Polreich80fa3182018-10-22 15:16:53 +0200608 salt.enforceState([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: 'salt.minion.cert'])
Victor Ryzhenkineb617412018-08-20 18:54:23 +0400609
610 // Install docker
Martin Polreich80fa3182018-10-22 15:16:53 +0200611 salt.enforceState([saltId: master, target: "I@docker:host ${extra_tgt}", state: 'docker.host'])
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200612
Svimba470b3312018-09-26 11:27:20 +0200613 // If network engine is not opencontrail, run addons state for kubernetes
614 if (!salt.getPillar(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes:master:network:opencontrail:enabled')) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200615 salt.enforceState([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: 'kubernetes.master.kube-addons'])
Svimba470b3312018-09-26 11:27:20 +0200616 }
617
Jakub Josef79ecec32017-02-17 14:36:28 +0100618 // Install Kubernetes pool and Calico
Martin Polreich80fa3182018-10-22 15:16:53 +0200619 salt.enforceState([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: 'kubernetes.pool'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100620
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300621 if (salt.testTarget(master, "I@etcd:server:setup ${extra_tgt}")) {
Marek Celoud029391c2017-11-14 10:06:18 +0100622 // Setup etcd server
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400623 first_target = salt.getFirstMinion(master, "I@kubernetes:master ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200624 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'etcd.server.setup'])
Marek Celoud029391c2017-11-14 10:06:18 +0100625 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100626
Victor Ryzhenkinfb5d1b52018-05-22 18:49:26 +0400627 // Run k8s master at *01* to simplify namespaces creation
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400628 first_target = salt.getFirstMinion(master, "I@kubernetes:master ${extra_tgt}")
Victor Ryzhenkinfb5d1b52018-05-22 18:49:26 +0400629
Svimba470b3312018-09-26 11:27:20 +0200630 // If network engine is opencontrail, run master state for kubernetes without kube-addons
631 // The kube-addons state will be called later only in case of opencontrail
632 if (salt.getPillar(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes:master:network:opencontrail:enabled')) {
633 // Run k8s on first node without master.setup and master.kube-addons
Martin Polreich80fa3182018-10-22 15:16:53 +0200634 salt.enforceStateWithExclude([saltId: master, target: "${first_target} ${extra_tgt}", state: "kubernetes.master", excludedStates: "kubernetes.master.setup,kubernetes.master.kube-addons"])
Svimba470b3312018-09-26 11:27:20 +0200635 // Run k8s without master.setup and master.kube-addons
Martin Polreich80fa3182018-10-22 15:16:53 +0200636 salt.enforceStateWithExclude([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: "kubernetes", excludedStates: "kubernetes.master.setup,kubernetes.master.kube-addons"])
Svimba470b3312018-09-26 11:27:20 +0200637 } else {
638 // Run k8s on first node without master.setup and master.kube-addons
Martin Polreich80fa3182018-10-22 15:16:53 +0200639 salt.enforceStateWithExclude([saltId: master, target: "${first_target} ${extra_tgt}", state: "kubernetes.master", excludedStates: "kubernetes.master.setup"])
Svimba470b3312018-09-26 11:27:20 +0200640 // Run k8s without master.setup
Martin Polreich80fa3182018-10-22 15:16:53 +0200641 salt.enforceStateWithExclude([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: "kubernetes", excludedStates: "kubernetes.master.setup"])
Svimba470b3312018-09-26 11:27:20 +0200642 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100643
644 // Run k8s master setup
Martin Polreich80fa3182018-10-22 15:16:53 +0200645 salt.enforceState([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: 'kubernetes.master.setup'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100646
647 // Restart kubelet
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400648 salt.runSaltProcessStep(master, "I@kubernetes:master ${extra_tgt}", 'service.restart', ['kubelet'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100649}
650
651
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300652def installKubernetesCompute(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200653 def salt = new com.mirantis.mk.Salt()
Jakub Josef432e9d92018-02-06 18:28:37 +0100654 salt.fullRefresh(master, "*")
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200655
656 // Bootstrap all nodes
Martin Polreich80fa3182018-10-22 15:16:53 +0200657 salt.enforceState([saltId: master, target: "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", state: 'linux'])
658 salt.enforceState([saltId: master, target: "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", state: 'salt.minion'])
659 salt.enforceState([saltId: master, target: "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", state: ['openssh', 'ntp']])
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200660
661 // Create and distribute SSL certificates for services using salt state
Martin Polreich80fa3182018-10-22 15:16:53 +0200662 salt.enforceState([saltId: master, target: "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", state: 'salt.minion.cert'])
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200663
664 // Install docker
Martin Polreich80fa3182018-10-22 15:16:53 +0200665 salt.enforceState([saltId: master, target: "I@docker:host ${extra_tgt}", state: 'docker.host'])
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200666
667 // Install Kubernetes and Calico
Martin Polreich80fa3182018-10-22 15:16:53 +0200668 salt.enforceState([saltId: master, target: "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", state: 'kubernetes.pool'])
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200669
Yuriy Taradayab564d72017-10-11 15:14:35 +0400670 // Install Tiller and all configured releases
Martin Polreich80fa3182018-10-22 15:16:53 +0200671 salt.enforceStateWithTest([saltId: master, target: "I@helm:client ${extra_tgt}", state: 'helm'])
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400672 salt.runSaltProcessStep(master, "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", 'service.restart', ['kubelet'])
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200673}
674
675
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300676def installDockerSwarm(master, extra_tgt = '') {
Martin Polreich8663a342017-06-30 17:33:08 +0200677 def salt = new com.mirantis.mk.Salt()
Jakub Josef79ecec32017-02-17 14:36:28 +0100678
vrovachev1c4770b2017-07-05 13:25:21 +0400679 //Install and Configure Docker
Martin Polreichc0bb4fd2018-08-06 11:34:43 +0200680 if (salt.testTarget(master, "I@docker:swarm ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200681 salt.enforceState([saltId: master, target: "I@docker:swarm ${extra_tgt}", state: 'docker.host'])
682 salt.enforceState([saltId: master, target: "I@docker:swarm:role:master ${extra_tgt}", state: 'docker.swarm'])
683 salt.enforceState([saltId: master, target: "I@docker:swarm ${extra_tgt}", state: 'salt.minion.grains'])
Martin Polreichc0bb4fd2018-08-06 11:34:43 +0200684 salt.runSaltProcessStep(master, "I@docker:swarm ${extra_tgt}", 'mine.update')
685 salt.runSaltProcessStep(master, "I@docker:swarm ${extra_tgt}", 'saltutil.refresh_modules')
686 sleep(5)
Martin Polreich80fa3182018-10-22 15:16:53 +0200687 salt.enforceState([saltId: master, target: "I@docker:swarm:role:master ${extra_tgt}", state: 'docker.swarm'])
688 salt.enforceStateWithTest([saltId: master, target: "I@docker:swarm:role:manager ${extra_tgt}", state: 'docker.swarm'])
Martin Polreichc0bb4fd2018-08-06 11:34:43 +0200689 sleep(10)
690 salt.cmdRun(master, "I@docker:swarm:role:master ${extra_tgt}", 'docker node ls')
Machi Hoshino87aa39d2018-07-26 20:41:53 +0900691 }
Martin Polreich8663a342017-06-30 17:33:08 +0200692}
693
Svimba470b3312018-09-26 11:27:20 +0200694// Setup addons for kubernetes - For OpenContrail network engine
695// Use after compute nodes are ready, because K8s addons like DNS should be placed on cmp nodes
696def setupKubeAddonForContrail(master, extra_tgt = '') {
697 def salt = new com.mirantis.mk.Salt()
698
699 if (salt.getPillar(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes:master:network:opencontrail:enabled')){
700 // Setup Addons for Kubernetes only in case of OpenContrail is used as neteork engine
Martin Polreich80fa3182018-10-22 15:16:53 +0200701 salt.enforceState([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: 'kubernetes.master.kube-addons'])
Svimba470b3312018-09-26 11:27:20 +0200702 }
703}
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200704
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300705def installCicd(master, extra_tgt = '') {
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200706 def salt = new com.mirantis.mk.Salt()
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200707 def common = new com.mirantis.mk.Common()
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300708 def gerrit_compound = "I@gerrit:client and ci* ${extra_tgt}"
709 def jenkins_compound = "I@jenkins:client and ci* ${extra_tgt}"
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200710
711 salt.fullRefresh(master, gerrit_compound)
712 salt.fullRefresh(master, jenkins_compound)
Richard Felkl9d2cd922017-11-03 11:49:32 +0100713
Ivan Berezovskiy3aa91f52018-11-28 18:47:34 +0400714 // Temporary exclude cfg node from docker.client state (PROD-24934)
715 def dockerClientExclude = !salt.getPillar(master, 'I@salt:master', 'docker:client:stack:jenkins').isEmpty() ? 'and not I@salt:master' : ''
Martin Polreich80fa3182018-10-22 15:16:53 +0200716 salt.enforceState([saltId: master, target: "I@docker:swarm:role:master and I@jenkins:client ${dockerClientExclude} ${extra_tgt}", state: 'docker.client', retries: 2])
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200717
718 // API timeout in minutes
719 def wait_timeout = 10
720
721 // Gerrit
722 def gerrit_master_url = salt.getPillar(master, gerrit_compound, '_param:gerrit_master_url')
723
724 if(!gerrit_master_url['return'].isEmpty()) {
725 gerrit_master_url = gerrit_master_url['return'][0].values()[0]
726 } else {
727 gerrit_master_url = ''
728 }
729
730 if (gerrit_master_url != '') {
731 common.infoMsg('Gerrit master url "' + gerrit_master_url + '" retrieved at _param:gerrit_master_url')
732 } else {
733
734 common.infoMsg('Gerrit master url could not be retrieved at _param:gerrit_master_url. Falling back to gerrit pillar')
735
736 def gerrit_host
737 def gerrit_http_port
738 def gerrit_http_scheme
739
740 def host_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:host')
741 gerrit_host = salt.getReturnValues(host_pillar)
742
743 def port_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:http_port')
744 gerrit_http_port = salt.getReturnValues(port_pillar)
745
746 def scheme_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:protocol')
747 gerrit_http_scheme = salt.getReturnValues(scheme_pillar)
748
749 gerrit_master_url = gerrit_http_scheme + '://' + gerrit_host + ':' + gerrit_http_port
750
751 }
752
753 timeout(wait_timeout) {
754 common.infoMsg('Waiting for Gerrit to come up..')
Dzmitry Stremkouski5440ffa2018-05-31 12:00:02 +0200755 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'
756 salt.cmdRun(master, gerrit_compound, 'timeout ' + (wait_timeout*60+3) + ' /bin/sh -c -- ' + '"' + check_gerrit_cmd + '"')
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200757 }
758
759 // Jenkins
760 def jenkins_master_url_pillar = salt.getPillar(master, jenkins_compound, '_param:jenkins_master_url')
761 jenkins_master_url = salt.getReturnValues(jenkins_master_url_pillar)
762
763 timeout(wait_timeout) {
764 common.infoMsg('Waiting for Jenkins to come up..')
Dzmitry Stremkouski5440ffa2018-05-31 12:00:02 +0200765 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'
766 salt.cmdRun(master, jenkins_compound, 'timeout ' + (wait_timeout*60+3) + ' /bin/sh -c -- ' + '"' + check_jenkins_cmd + '"')
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200767 }
Richard Felklc1aba9b2018-01-02 09:25:20 +0100768
Martin Polreich80fa3182018-10-22 15:16:53 +0200769 salt.enforceStateWithTest([saltId: master, target: "I@openldap:client ${extra_tgt}", state: 'openldap', retries: 2])
Richard Felklb6fdec92017-09-26 10:52:36 +0200770
Martin Polreich80fa3182018-10-22 15:16:53 +0200771 salt.enforceStateWithTest([saltId: master, target: "I@python:environment ${extra_tgt}", state: 'python'])
Richard Felklc1aba9b2018-01-02 09:25:20 +0100772
Richard Felkl6e208fc2017-12-08 10:18:44 +0100773 withEnv(['ASK_ON_ERROR=false']){
774 retry(2){
775 try{
Martin Polreich80fa3182018-10-22 15:16:53 +0200776 salt.enforceState([saltId: master, target: "I@gerrit:client ${extra_tgt}", state: 'gerrit'])
Richard Felkl6e208fc2017-12-08 10:18:44 +0100777 }catch(e){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300778 salt.fullRefresh(master, "I@gerrit:client ${extra_tgt}")
Richard Felkl6e208fc2017-12-08 10:18:44 +0100779 throw e //rethrow for retry handler
780 }
781 }
782 retry(2){
783 try{
Martin Polreich80fa3182018-10-22 15:16:53 +0200784 salt.enforceState([saltId: master, target: "I@jenkins:client ${extra_tgt}", state: 'jenkins'])
Richard Felkl6e208fc2017-12-08 10:18:44 +0100785 }catch(e){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300786 salt.fullRefresh(master, "I@jenkins:client ${extra_tgt}")
Richard Felkl6e208fc2017-12-08 10:18:44 +0100787 throw e //rethrow for retry handler
788 }
789 }
790 }
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200791}
792
793
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300794def installStacklight(master, extra_tgt = '') {
Martin Polreich8663a342017-06-30 17:33:08 +0200795 def common = new com.mirantis.mk.Common()
796 def salt = new com.mirantis.mk.Salt()
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200797 def retries_wait = 20
798 def retries = 15
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400799 def first_target
Martin Polreich8663a342017-06-30 17:33:08 +0200800
Simon Pasquieref4122c2017-08-25 15:52:07 +0200801 // Install core services for K8S environments:
azvyagintsev833b4772018-11-21 22:30:59 +0200802 // HAProxy, Nginx and glusterFS clients.
803 // glusterFS clients must be first one, since nginx should store certs on it.
Simon Pasquieref4122c2017-08-25 15:52:07 +0200804 // In case of OpenStack, those are already installed
Martin Polreich792f2662017-07-11 13:36:32 +0200805 if (common.checkContains('STACK_INSTALL', 'k8s')) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200806 salt.enforceStateWithTest([saltId: master, target: "I@glusterfs:client ${extra_tgt}", state: 'glusterfs.client', retries: 2])
azvyagintsev833b4772018-11-21 22:30:59 +0200807 common.retry(3, 5){
Martin Polreich80fa3182018-10-22 15:16:53 +0200808 salt.enforceState([saltId: master, target: "I@nginx:server ${extra_tgt}", state: 'salt.minion.cert'])
azvyagintsev833b4772018-11-21 22:30:59 +0200809 }
810
Martin Polreich80fa3182018-10-22 15:16:53 +0200811 salt.enforceState([saltId: master, target: "I@haproxy:proxy ${extra_tgt}", state: 'haproxy'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300812 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.status', ['haproxy'])
Simon Pasquieref4122c2017-08-25 15:52:07 +0200813
Martin Polreich80fa3182018-10-22 15:16:53 +0200814 salt.enforceStateWithTest([saltId: master, target: "I@nginx:server ${extra_tgt}", state: 'nginx'])
Martin Polreich792f2662017-07-11 13:36:32 +0200815 }
Jiri Broulike57a0242017-10-06 13:38:47 +0200816
Dmitry Kalashnik69ecb782018-05-21 17:36:50 +0400817 // Install MongoDB for Alerta
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300818 if (salt.testTarget(master, "I@mongodb:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200819 salt.enforceState([saltId: master, target: "I@mongodb:server ${extra_tgt}", state: 'mongodb.server'])
Ildar Svetlov829f94a2018-06-05 17:57:08 +0400820
821 // Initialize mongodb replica set
822 common.retry(5,20){
Martin Polreich80fa3182018-10-22 15:16:53 +0200823 salt.enforceState([saltId: master, target: "I@mongodb:server ${extra_tgt}", state: 'mongodb.cluster'])
Ildar Svetlov829f94a2018-06-05 17:57:08 +0400824 }
Dmitry Kalashnik69ecb782018-05-21 17:36:50 +0400825 }
826
Martin Polreich8663a342017-06-30 17:33:08 +0200827 //Install Telegraf
Martin Polreich80fa3182018-10-22 15:16:53 +0200828 salt.enforceState([saltId: master, target: "( I@telegraf:agent or I@telegraf:remote_agent ) ${extra_tgt}", state: 'telegraf'])
Martin Polreich8663a342017-06-30 17:33:08 +0200829
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400830 // Install Prometheus exporters
Martin Polreich80fa3182018-10-22 15:16:53 +0200831 salt.enforceStateWithTest([saltId: master, target: "I@prometheus:exporters ${extra_tgt}", state: 'prometheus'])
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400832
Martin Polreich8663a342017-06-30 17:33:08 +0200833 //Install Elasticsearch and Kibana
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400834 if (salt.testTarget(master, "I@elasticsearch:server:enabled:true ${extra_tgt}")) {
835 first_target = salt.getFirstMinion(master, "I@elasticsearch:server:enabled:true ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200836 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'elasticsearch.server'])
Ramon Meleroae6e16a2018-08-07 13:42:16 -0500837 }
Martin Polreich80fa3182018-10-22 15:16:53 +0200838 salt.enforceStateWithTest([saltId: master, target: "I@elasticsearch:server:enabled:true ${extra_tgt}", state: 'elasticsearch.server'])
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400839 if (salt.testTarget(master, "I@kibana:server:enabled:true ${extra_tgt}")) {
840 first_target = salt.getFirstMinion(master, "I@kibana:server:enabled:true ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200841 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'kibana.server'])
Ramon Meleroae6e16a2018-08-07 13:42:16 -0500842 }
Martin Polreich80fa3182018-10-22 15:16:53 +0200843 salt.enforceStateWithTest([saltId: master, target: "I@kibana:server:enabled:true ${extra_tgt}", state: 'kibana.server'])
Martin Polreich675dc942018-08-15 09:37:32 +0200844
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200845 // Check ES health cluster status
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300846 def pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:host')
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200847 def elasticsearch_vip
848 if(!pillar['return'].isEmpty()) {
849 elasticsearch_vip = pillar['return'][0].values()[0]
850 } else {
851 common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved')
852 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300853 pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:port')
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200854 def elasticsearch_port
855 if(!pillar['return'].isEmpty()) {
856 elasticsearch_port = pillar['return'][0].values()[0]
857 } else {
858 common.errorMsg('[ERROR] Elasticsearch VIP port could not be retrieved')
859 }
860 common.retry(retries,retries_wait) {
861 common.infoMsg('Waiting for Elasticsearch to become green..')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300862 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 +0200863 }
864
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200865 common.retry(retries,retries_wait) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200866 salt.enforceState([saltId: master, target: "I@elasticsearch:client ${extra_tgt}", state: 'elasticsearch.client'])
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200867 }
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200868
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200869 common.retry(retries,retries_wait) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200870 salt.enforceState([saltId: master, target: "I@kibana:client ${extra_tgt}", state: 'kibana.client'])
Mateusz Matuszkowiakae2ccbc2018-06-07 09:18:57 +0200871 }
Dmitry Kalashnik53feda72018-03-16 16:06:10 +0400872
873 //Install InfluxDB
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300874 if (salt.testTarget(master, "I@influxdb:server ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400875 first_target = salt.getFirstMinion(master, "I@influxdb:server ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200876 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'influxdb'])
877 salt.enforceState([saltId: master, target: "I@influxdb:server ${extra_tgt}", state: 'influxdb'])
Dmitry Kalashnik53feda72018-03-16 16:06:10 +0400878 }
879
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400880 // Install service for the log collection
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300881 if (salt.testTarget(master, "I@fluentd:agent ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200882 salt.enforceState([saltId: master, target: "I@fluentd:agent ${extra_tgt}", state: 'fluentd'])
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400883 } else {
Martin Polreich80fa3182018-10-22 15:16:53 +0200884 salt.enforceState([saltId: master, target: "I@heka:log_collector ${extra_tgt}", state: 'heka.log_collector'])
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400885 }
Simon Pasquier6301ddd2017-09-05 11:56:58 +0200886
Ondrej Smola5908ae62018-01-08 13:42:08 +0100887 // Install heka ceilometer collector
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300888 if (salt.testTarget(master, "I@heka:ceilometer_collector:enabled ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200889 salt.enforceState([saltId: master, target: "I@heka:ceilometer_collector:enabled ${extra_tgt}", state: 'heka.ceilometer_collector'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300890 salt.runSaltProcessStep(master, "I@heka:ceilometer_collector:enabled ${extra_tgt}", 'service.restart', ['ceilometer_collector'], null, true)
Ondrej Smola5908ae62018-01-08 13:42:08 +0100891 }
892
Martin Polreich470925a2017-07-06 17:12:59 +0200893 // Install galera
Martin Polreich792f2662017-07-11 13:36:32 +0200894 if (common.checkContains('STACK_INSTALL', 'k8s')) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200895 salt.enforceState([saltId: master, target: "I@galera:master ${extra_tgt}", state: 'galera', retries: 2])
896 salt.enforceState([saltId: master, target: "I@galera:slave ${extra_tgt}", state: 'galera', retries: 2])
Martin Polreich406f6462017-07-11 11:33:42 +0000897
Martin Polreich792f2662017-07-11 13:36:32 +0200898 // Check galera status
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300899 salt.runSaltProcessStep(master, "I@galera:master ${extra_tgt}", 'mysql.status')
900 salt.runSaltProcessStep(master, "I@galera:slave ${extra_tgt}", 'mysql.status')
Martin Polreich792f2662017-07-11 13:36:32 +0200901 }
Martin Polreich470925a2017-07-06 17:12:59 +0200902
Martin Polreich8663a342017-06-30 17:33:08 +0200903 //Collect Grains
Martin Polreich80fa3182018-10-22 15:16:53 +0200904 salt.enforceState([saltId: master, target: "I@salt:minion ${extra_tgt}", state: 'salt.minion.grains'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300905 salt.runSaltProcessStep(master, "I@salt:minion ${extra_tgt}", 'saltutil.refresh_modules')
906 salt.runSaltProcessStep(master, "I@salt:minion ${extra_tgt}", 'mine.update')
Martin Polreich8663a342017-06-30 17:33:08 +0200907 sleep(5)
908
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400909 // Configure Prometheus in Docker Swarm
Martin Polreich80fa3182018-10-22 15:16:53 +0200910 salt.enforceState([saltId: master, target: "I@docker:swarm and I@prometheus:server ${extra_tgt}", state: 'prometheus'])
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400911
Ildar Svetlov0eec97d2018-02-15 10:06:40 +0400912 //Configure Remote Collector in Docker Swarm for Openstack deployments
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400913 if (!common.checkContains('STACK_INSTALL', 'k8s')) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200914 salt.enforceState([saltId: master, target: "I@docker:swarm and I@prometheus:server ${extra_tgt}", state: 'heka.remote_collector', failOnError: false])
Martin Polreich8017f452017-08-21 16:01:42 +0200915 }
Martin Polreich8663a342017-06-30 17:33:08 +0200916
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400917 // Launch containers
Ivan Berezovskiye59448c2018-12-25 18:47:29 +0400918 // Pull images first if any
919 def listMinions = salt.getMinions(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}")
920 for (int i = 0; i < listMinions.size(); i++) {
921 if (!salt.getReturnValues(salt.getPillar(master, listMinions[i], 'docker:client:images')).isEmpty()) {
922 salt.enforceState([saltId: master, target: listMinions[i], state: 'docker.client.images', retries: 2])
923 }
924 }
Martin Polreich80fa3182018-10-22 15:16:53 +0200925 salt.enforceState([saltId: master, target: "I@docker:swarm:role:master and I@prometheus:server ${extra_tgt}", state: 'docker.client'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300926 salt.runSaltProcessStep(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}", 'dockerng.ps')
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400927
928 //Install Prometheus LTS
Martin Polreich80fa3182018-10-22 15:16:53 +0200929 salt.enforceStateWithTest([saltId: master, target: "I@prometheus:relay ${extra_tgt}", state: 'prometheus'])
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400930
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100931 // Install sphinx server
Martin Polreich80fa3182018-10-22 15:16:53 +0200932 salt.enforceStateWithTest([saltId: master, target: "I@sphinx:server ${extra_tgt}", state: 'sphinx'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100933
Martin Polreich8663a342017-06-30 17:33:08 +0200934 //Configure Grafana
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300935 pillar = salt.getPillar(master, "ctl01* ${extra_tgt}", '_param:stacklight_monitor_address')
Martin Polreich8663a342017-06-30 17:33:08 +0200936 common.prettyPrint(pillar)
Martin Polreich595baef2017-07-04 16:11:04 +0200937
Martin Polreich8663a342017-06-30 17:33:08 +0200938 def stacklight_vip
939 if(!pillar['return'].isEmpty()) {
940 stacklight_vip = pillar['return'][0].values()[0]
941 } else {
942 common.errorMsg('[ERROR] Stacklight VIP address could not be retrieved')
943 }
vrovachev1c4770b2017-07-05 13:25:21 +0400944
Martin Polreich305e2222017-07-06 11:33:00 +0200945 common.infoMsg("Waiting for service on http://${stacklight_vip}:15013/ to start")
Martin Polreichbd7ad222017-07-06 12:53:51 +0200946 sleep(120)
Martin Polreich80fa3182018-10-22 15:16:53 +0200947 salt.enforceState([saltId: master, target: "I@grafana:client ${extra_tgt}", state: 'grafana.client'])
Martin Polreich8663a342017-06-30 17:33:08 +0200948}
949
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300950def installStacklightv1Control(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200951 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200952
953 // infra install
954 // Install the StackLight backends
Martin Polreich80fa3182018-10-22 15:16:53 +0200955 salt.enforceState([saltId: master, target: "*01* and I@elasticsearch:server ${extra_tgt}", state: 'elasticsearch.server'])
956 salt.enforceState([saltId: master, target: "I@elasticsearch:server ${extra_tgt}", state: 'elasticsearch.server'])
Ales Komarekef2bab62017-04-26 11:48:28 +0200957
Martin Polreich80fa3182018-10-22 15:16:53 +0200958 salt.enforceState([saltId: master, target: "*01* and I@influxdb:server ${extra_tgt}", state: 'influxdb'])
959 salt.enforceState([saltId: master, target: "I@influxdb:server ${extra_tgt}", state: 'influxdb'])
Ales Komarekef2bab62017-04-26 11:48:28 +0200960
Martin Polreich80fa3182018-10-22 15:16:53 +0200961 salt.enforceState([saltId: master, target: "*01* and I@kibana:server ${extra_tgt}", state: 'kibana.server'])
962 salt.enforceState([saltId: master, target: "I@kibana:server ${extra_tgt}", state: 'kibana.server'])
Ales Komarekef2bab62017-04-26 11:48:28 +0200963
Martin Polreich80fa3182018-10-22 15:16:53 +0200964 salt.enforceState([saltId: master, target: "*01* and I@grafana:server ${extra_tgt}",state: 'grafana.server'])
965 salt.enforceState([saltId: master, target: "I@grafana:server ${extra_tgt}", state: 'grafana.server'])
Ales Komarekef2bab62017-04-26 11:48:28 +0200966
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300967 def alarming_service_pillar = salt.getPillar(master, "mon*01* ${extra_tgt}", '_param:alarming_service')
Kalynovskyi3e370112017-06-26 12:48:23 +0300968 def alarming_service = alarming_service_pillar['return'][0].values()[0]
969
970 switch (alarming_service) {
971 case 'sensu':
972 // Update Sensu
Martin Polreich80fa3182018-10-22 15:16:53 +0200973 salt.enforceState([saltId: master, target: "I@sensu:server and I@rabbitmq:server ${extra_tgt}", state: 'rabbitmq'])
974 salt.enforceState([saltId: master, target: "I@redis:cluster:role:master ${extra_tgt}", state: 'redis'])
975 salt.enforceState([saltId: master, target: "I@redis:server ${extra_tgt}", state: 'redis'])
976 salt.enforceState([saltId: master, target: "I@sensu:server ${extra_tgt}", state: 'sensu'])
Kalynovskyi3e370112017-06-26 12:48:23 +0300977 default:
978 // Update Nagios
Martin Polreich80fa3182018-10-22 15:16:53 +0200979 salt.enforceState([saltId: master, target: "I@nagios:server ${extra_tgt}", state: 'nagios.server'])
Kalynovskyi3e370112017-06-26 12:48:23 +0300980 // Stop the Nagios service because the package starts it by default and it will
981 // started later only on the node holding the VIP address
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300982 salt.runSaltProcessStep(master, "I@nagios:server ${extra_tgt}", 'service.stop', ['nagios3'], null, true)
Kalynovskyi3e370112017-06-26 12:48:23 +0300983 }
984
Martin Polreich80fa3182018-10-22 15:16:53 +0200985 salt.enforceState([saltId: master, target: "I@elasticsearch:client ${extra_tgt}", state: 'elasticsearch.client.service'])
986 salt.enforceState([saltId: master, target: "I@kibana:client ${extra_tgt}", state: 'kibana.client'])
Ales Komarekef2bab62017-04-26 11:48:28 +0200987
988 sleep(10)
989}
990
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300991def installStacklightv1Client(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200992 def salt = new com.mirantis.mk.Salt()
993 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200994
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300995 salt.cmdRun(master, "I@elasticsearch:client ${extra_tgt}", 'salt-call state.sls elasticsearch.client')
Martin Polreich80fa3182018-10-22 15:16:53 +0200996 // salt.enforceState([saltId: master, target: "I@elasticsearch:client", state: 'elasticsearch.client", true])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300997 salt.cmdRun(master, "I@kibana:client ${extra_tgt}", 'salt-call state.sls kibana.client')
Martin Polreich80fa3182018-10-22 15:16:53 +0200998 // salt.enforceState([saltId: master, target: "I@kibana:client", state: 'kibana.client", true])
Ales Komarekef2bab62017-04-26 11:48:28 +0200999
1000 // Install collectd, heka and sensu services on the nodes, this will also
1001 // generate the metadata that goes into the grains and eventually into Salt Mine
Martin Polreich80fa3182018-10-22 15:16:53 +02001002 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: 'collectd'])
1003 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: 'salt.minion'])
1004 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: 'heka'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001005
1006 // Gather the Grafana metadata as grains
Martin Polreich80fa3182018-10-22 15:16:53 +02001007 salt.enforceState([saltId: master, target: "I@grafana:collector ${extra_tgt}", state: 'grafana.collector'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001008
1009 // Update Salt Mine
Martin Polreich80fa3182018-10-22 15:16:53 +02001010 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: 'salt.minion.grains'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001011 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'saltutil.refresh_modules')
1012 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'mine.update')
Ales Komarekef2bab62017-04-26 11:48:28 +02001013
1014 sleep(5)
1015
1016 // Update Heka
Martin Polreich80fa3182018-10-22 15:16:53 +02001017 salt.enforceState([saltId: master, target: "( I@heka:aggregator:enabled:True or I@heka:remote_collector:enabled:True ) ${extra_tgt}", state: 'heka'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001018
1019 // Update collectd
Martin Polreich80fa3182018-10-22 15:16:53 +02001020 salt.enforceState([saltId: master, target: "I@collectd:remote_client:enabled:True ${extra_tgt}", state: 'collectd'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001021
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001022 def alarming_service_pillar = salt.getPillar(master, "mon*01* ${extra_tgt}", '_param:alarming_service')
Kalynovskyi3e370112017-06-26 12:48:23 +03001023 def alarming_service = alarming_service_pillar['return'][0].values()[0]
Ales Komarekef2bab62017-04-26 11:48:28 +02001024
Kalynovskyi3e370112017-06-26 12:48:23 +03001025 switch (alarming_service) {
1026 case 'sensu':
1027 // Update Sensu
1028 // TODO for stacklight team, should be fixed in model
Martin Polreich80fa3182018-10-22 15:16:53 +02001029 salt.enforceState([saltId: master, target: "I@sensu:client ${extra_tgt}", state: 'sensu'])
Kalynovskyi3e370112017-06-26 12:48:23 +03001030 default:
1031 break
1032 // Default is nagios, and was enforced in installStacklightControl()
1033 }
Ales Komarekef2bab62017-04-26 11:48:28 +02001034
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001035 salt.cmdRun(master, "I@grafana:client and *01* ${extra_tgt}", 'salt-call state.sls grafana.client')
Martin Polreich80fa3182018-10-22 15:16:53 +02001036 // salt.enforceState([saltId: master, target: "I@grafana:client and *01*", state: 'grafana.client"])
Ales Komarekef2bab62017-04-26 11:48:28 +02001037
Marek Celoudd200cad2017-06-07 10:34:46 +02001038 // Finalize the configuration of Grafana (add the dashboards...)
Martin Polreich80fa3182018-10-22 15:16:53 +02001039 salt.enforceState([saltId: master, target: "I@grafana:client and *01* ${extra_tgt}", state: 'grafana.client'])
1040 salt.enforceState([saltId: master, target: "I@grafana:client and *02* ${extra_tgt}", state: 'grafana.client'])
1041 salt.enforceState([saltId: master, target: "I@grafana:client and *03* ${extra_tgt}", state: 'grafana.client'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001042 // nw salt -C "I@grafana:client' --async service.restart salt-minion; sleep 10
Marek Celoudd200cad2017-06-07 10:34:46 +02001043
Ales Komarekef2bab62017-04-26 11:48:28 +02001044 // Get the StackLight monitoring VIP addres
1045 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
1046 //vip=${vip:=172.16.10.253}
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001047 def pillar = salt.getPillar(master, "ctl01* ${extra_tgt}", '_param:stacklight_monitor_address')
Jakub Josefbceaa322017-06-13 18:28:27 +02001048 common.prettyPrint(pillar)
Ales Komarekef2bab62017-04-26 11:48:28 +02001049 def stacklight_vip = pillar['return'][0].values()[0]
1050
1051 if (stacklight_vip) {
1052 // (re)Start manually the services that are bound to the monitoring VIP
1053 common.infoMsg("restart services on node with IP: ${stacklight_vip}")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001054 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['remote_collectd'])
1055 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['remote_collector'])
1056 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['aggregator'])
1057 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['nagios3'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001058 } else {
1059 throw new Exception("Missing stacklight_vip")
1060 }
Tomáš Kukrálf06ca0f2017-02-27 15:18:50 +01001061}
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001062
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001063//
1064// backups
1065//
1066
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001067def installBackup(master, component='common', extra_tgt = '') {
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001068 def salt = new com.mirantis.mk.Salt()
1069 if (component == 'common') {
1070 // Install Backupninja
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001071 if (salt.testTarget(master, "I@backupninja:client ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001072 salt.enforceState([saltId: master, target: "I@backupninja:client ${extra_tgt}", state: 'salt.minion.grains'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001073 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'saltutil.sync_grains')
1074 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'mine.flush')
1075 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'mine.update')
Martin Polreich80fa3182018-10-22 15:16:53 +02001076 salt.enforceState([saltId: master, target: "I@backupninja:client ${extra_tgt}", state: 'backupninja'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001077 }
Martin Polreich80fa3182018-10-22 15:16:53 +02001078 salt.enforceStateWithTest([saltId: master, target: "I@backupninja:server ${extra_tgt}", state: 'salt.minion.grains'])
1079 salt.enforceStateWithTest([saltId: master, target: "I@backupninja:server ${extra_tgt}", state: 'backupninja'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001080 } else if (component == 'mysql') {
1081 // Install Xtrabackup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001082 if (salt.testTarget(master, "I@xtrabackup:client ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001083 salt.enforceState([saltId: master, target: "I@xtrabackup:client ${extra_tgt}", state: 'salt.minion.grains'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001084 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'saltutil.sync_grains')
1085 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'mine.flush')
1086 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'mine.update')
Martin Polreich80fa3182018-10-22 15:16:53 +02001087 salt.enforceState([saltId: master, target: "I@xtrabackup:client ${extra_tgt}", state: 'xtrabackup'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001088 }
Martin Polreich80fa3182018-10-22 15:16:53 +02001089 salt.enforceStateWithTest([saltId: master, target: "I@xtrabackup:server ${extra_tgt}", state: 'xtrabackup'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001090 } else if (component == 'contrail') {
1091
1092 // Install Cassandra backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001093 if (salt.testTarget(master, "I@cassandra:backup:client ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001094 salt.enforceState([saltId: master, target: "I@cassandra:backup:client ${extra_tgt}", state: 'salt.minion.grains'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001095 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1096 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'mine.flush')
1097 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'mine.update')
Martin Polreich80fa3182018-10-22 15:16:53 +02001098 salt.enforceState([saltId: master, target: "I@cassandra:backup:client ${extra_tgt}", state: 'cassandra.backup'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001099 }
Martin Polreich80fa3182018-10-22 15:16:53 +02001100 salt.enforceStateWithTest([saltId: master, target: "I@cassandra:backup:server ${extra_tgt}", state: 'cassandra.backup'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001101 // Install Zookeeper backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001102 if (salt.testTarget(master, "I@zookeeper:backup:client ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001103 salt.enforceState([saltId: master, target: "I@zookeeper:backup:client ${extra_tgt}", state: 'salt.minion.grains'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001104 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1105 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'mine.flush')
1106 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'mine.update')
Martin Polreich80fa3182018-10-22 15:16:53 +02001107 salt.enforceState([saltId: master, target: "I@zookeeper:backup:client ${extra_tgt}", state: 'zookeeper.backup'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001108 }
Martin Polreich80fa3182018-10-22 15:16:53 +02001109 salt.enforceStateWithTest([saltId: master, target: "I@zookeeper:backup:server ${extra_tgt}", state: 'zookeeper.backup'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001110 } else if (component == 'ceph') {
1111 // Install Ceph backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001112 if (salt.testTarget(master, "I@ceph:backup:client ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001113 salt.enforceState([saltId: master, target: "I@ceph:backup:client ${extra_tgt}", state: 'salt.minion.grains'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001114 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1115 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'mine.flush')
1116 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'mine.update')
Martin Polreich80fa3182018-10-22 15:16:53 +02001117 salt.enforceState([saltId: master, target: "I@ceph:backup:client ${extra_tgt}", state: 'ceph.backup'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001118 }
Martin Polreich80fa3182018-10-22 15:16:53 +02001119 salt.enforceStateWithTest([saltId: master, target: "I@ceph:backup:server ${extra_tgt}", state: 'ceph.backup'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001120 }
1121
1122}
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001123
1124//
1125// Ceph
1126//
1127
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001128def installCephMon(master, target="I@ceph:mon", extra_tgt = '') {
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001129 def salt = new com.mirantis.mk.Salt()
1130
Martin Polreich80fa3182018-10-22 15:16:53 +02001131 salt.enforceState([saltId: master, target: "I@ceph:common ${extra_tgt}", state: 'salt.minion.grains'])
Jiri Broulikbfc234f2017-10-17 15:45:38 +02001132
Jiri Broulike57a0242017-10-06 13:38:47 +02001133 // generate keyrings
Martin Polreich44331002018-08-13 11:27:06 +02001134 if (salt.testTarget(master, "( I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin ) ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001135 salt.enforceState([saltId: master, target: "( I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin ) ${extra_tgt}", state: 'ceph.mon'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001136 salt.runSaltProcessStep(master, "I@ceph:mon ${extra_tgt}", 'saltutil.sync_grains')
Martin Polreich44331002018-08-13 11:27:06 +02001137 salt.runSaltProcessStep(master, "( I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin ) ${extra_tgt}", 'mine.update')
Vasyl Saienko03ed4e72018-11-14 11:35:29 +02001138
1139 // on target nodes mine is used to get pillar from 'ceph:common:keyring:admin' via grain.items
1140 // we need to refresh all pillar/grains to make data sharing work correctly
1141 salt.fullRefresh(master, "( I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin ) ${extra_tgt}")
1142
Jiri Broulik3c75a6d2017-10-06 18:44:37 +02001143 sleep(5)
Jiri Broulike57a0242017-10-06 13:38:47 +02001144 }
Ondrej Smolafd5c2352017-08-11 14:25:39 +02001145 // install Ceph Mons
Martin Polreich80fa3182018-10-22 15:16:53 +02001146 salt.enforceState([saltId: master, target: target, state: 'ceph.mon'])
1147 salt.enforceStateWithTest([saltId: master, target: "I@ceph:mgr ${extra_tgt}", state: 'ceph.mgr'])
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001148}
1149
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001150def installCephOsd(master, target="I@ceph:osd", setup=true, extra_tgt = '') {
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001151 def salt = new com.mirantis.mk.Salt()
1152
1153 // install Ceph OSDs
Martin Polreich80fa3182018-10-22 15:16:53 +02001154 salt.enforceState([saltId: master, target: target, state: 'ceph.osd'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001155 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'saltutil.sync_grains')
Martin Polreich80fa3182018-10-22 15:16:53 +02001156 salt.enforceState([saltId: master, target: target, state: 'ceph.osd.custom'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001157 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'saltutil.sync_grains')
1158 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'mine.update')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001159 installBackup(master, 'ceph')
Tomáš Kukráled27a472017-08-29 10:26:25 +02001160
Jiri Broulike57a0242017-10-06 13:38:47 +02001161 // setup pools, keyrings and maybe crush
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001162 if (salt.testTarget(master, "I@ceph:setup ${extra_tgt}") && setup) {
Jiri Broulik07f8de72017-10-09 14:12:17 +02001163 sleep(5)
Martin Polreich80fa3182018-10-22 15:16:53 +02001164 salt.enforceState([saltId: master, target: "I@ceph:setup ${extra_tgt}", state: 'ceph.setup'])
Tomáš Kukráled27a472017-08-29 10:26:25 +02001165 }
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001166}
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001167
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001168def installCephClient(master, extra_tgt = '') {
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001169 def salt = new com.mirantis.mk.Salt()
1170
1171 // install Ceph Radosgw
Mykyta Karpinf7a714c2018-11-06 14:22:36 +02001172 if (salt.testTarget(master, "I@ceph:radosgw ${extra_tgt}")) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001173 salt.runSaltProcessStep(master, "I@ceph:radosgw ${extra_tgt}", 'saltutil.sync_grains')
Martin Polreich80fa3182018-10-22 15:16:53 +02001174 salt.enforceState([saltId: master, target: "I@ceph:radosgw ${extra_tgt}", state: 'ceph.radosgw'])
Alexander Noskov229035f2017-12-06 00:10:20 +04001175 }
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001176
1177 // setup keyring for Openstack services
Martin Polreich80fa3182018-10-22 15:16:53 +02001178 salt.enforceStateWithTest([saltId: master, target: "I@ceph:common and I@glance:server ${extra_tgt}", state: ['ceph.common', 'ceph.setup.keyring']])
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001179
Martin Polreich80fa3182018-10-22 15:16:53 +02001180 salt.enforceStateWithTest([saltId: master, target: "I@ceph:common and I@cinder:controller ${extra_tgt}", state: ['ceph.common', 'ceph.setup.keyring']])
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001181
1182 if (salt.testTarget(master, "I@ceph:common and I@nova:compute ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001183 salt.enforceState([saltId: master, target: "I@ceph:common and I@nova:compute ${extra_tgt}", state: ['ceph.common', 'ceph.setup.keyring']])
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001184 salt.runSaltProcessStep(master, "I@ceph:common and I@nova:compute ${extra_tgt}", 'saltutil.sync_grains')
1185 }
1186
Martin Polreich80fa3182018-10-22 15:16:53 +02001187 salt.enforceStateWithTest([saltId: master, target: "I@ceph:common and I@gnocchi:server ${extra_tgt}", state: ['ceph.common', 'ceph.setup.keyring']])
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001188}
Jiri Broulike57a0242017-10-06 13:38:47 +02001189
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001190def connectCeph(master, extra_tgt = '') {
Jiri Broulike57a0242017-10-06 13:38:47 +02001191 def salt = new com.mirantis.mk.Salt()
1192
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001193 // setup Keystone service and endpoints for swift or / and S3
Martin Polreich80fa3182018-10-22 15:16:53 +02001194 salt.enforceStateWithTest([saltId: master, target: "I@keystone:client ${extra_tgt}", state: 'keystone.client'])
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001195
Jiri Broulike57a0242017-10-06 13:38:47 +02001196 // connect Ceph to the env
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001197 if (salt.testTarget(master, "I@ceph:common and I@glance:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001198 salt.enforceState([saltId: master, target: "I@ceph:common and I@glance:server ${extra_tgt}", state: ['glance']])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001199 salt.runSaltProcessStep(master, "I@ceph:common and I@glance:server ${extra_tgt}", 'service.restart', ['glance-api'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001200 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001201 if (salt.testTarget(master, "I@ceph:common and I@cinder:controller ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001202 salt.enforceState([saltId: master, target: "I@ceph:common and I@cinder:controller ${extra_tgt}", state: ['cinder']])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001203 salt.runSaltProcessStep(master, "I@ceph:common and I@cinder:controller ${extra_tgt}", 'service.restart', ['cinder-volume'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001204 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001205 if (salt.testTarget(master, "I@ceph:common and I@nova:compute ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001206 salt.enforceState([saltId: master, target: "I@ceph:common and I@nova:compute ${extra_tgt}", state: ['nova']])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001207 salt.runSaltProcessStep(master, "I@ceph:common and I@nova:compute ${extra_tgt}", 'service.restart', ['nova-compute'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001208 }
Mykyta Karpin0dec8b32018-09-19 09:37:45 +03001209 if (salt.testTarget(master, "I@ceph:common and I@gnocchi:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001210 salt.enforceState([saltId: master, target: "I@ceph:common and I@gnocchi:server:role:primary ${extra_tgt}", state: 'gnocchi.server'])
1211 salt.enforceState([saltId: master, target: "I@ceph:common and I@gnocchi:server ${extra_tgt}", state: 'gnocchi.server'])
Mykyta Karpin0dec8b32018-09-19 09:37:45 +03001212 }
Jiri Broulike57a0242017-10-06 13:38:47 +02001213}
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001214
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001215def installOssInfra(master, extra_tgt = '') {
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001216 def common = new com.mirantis.mk.Common()
1217 def salt = new com.mirantis.mk.Salt()
1218
Martin Polreich80fa3182018-10-22 15:16:53 +02001219 salt.enforceStateWithTest([saltId: master, target: "I@devops_portal:config ${extra_tgt}", state: 'devops_portal.config'])
1220 salt.enforceStateWithTest([saltId: master, target: "I@rundeck:client ${extra_tgt}", state: ['linux.system.user', 'openssh'], testTargetMatcher: "I@devops_portal:config ${extra_tgt}"])
1221 salt.enforceStateWithTest([saltId: master, target: "I@rundeck:server ${extra_tgt}", state: 'rundeck.server', testTargetMatcher: "I@devops_portal:config ${extra_tgt}"])
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001222}
1223
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001224def installOss(master, extra_tgt = '') {
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001225 def common = new com.mirantis.mk.Common()
1226 def salt = new com.mirantis.mk.Salt()
1227
1228 //Get oss VIP address
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001229 def pillar = salt.getPillar(master, "cfg01* ${extra_tgt}", '_param:stacklight_monitor_address')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001230 common.prettyPrint(pillar)
1231
1232 def oss_vip
1233 if(!pillar['return'].isEmpty()) {
1234 oss_vip = pillar['return'][0].values()[0]
1235 } else {
1236 common.errorMsg('[ERROR] Oss VIP address could not be retrieved')
1237 }
1238
1239 // Postgres client - initialize OSS services databases
1240 timeout(120){
1241 common.infoMsg("Waiting for postgresql database to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001242 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 +04001243 }
1244 // XXX: first run usually fails on some inserts, but we need to create databases at first
Martin Polreich80fa3182018-10-22 15:16:53 +02001245 salt.enforceState([saltId: master, target: "I@postgresql:client ${extra_tgt}", state: 'postgresql.client', failOnError: false])
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001246
1247 // Setup postgres database with integration between
1248 // Pushkin notification service and Security Monkey security audit service
1249 timeout(10) {
1250 common.infoMsg("Waiting for Pushkin to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001251 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 +04001252 }
Martin Polreich80fa3182018-10-22 15:16:53 +02001253 salt.enforceState([saltId: master, target: "I@postgresql:client ${extra_tgt}", state: 'postgresql.client'])
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001254
1255 // Rundeck
1256 timeout(10) {
1257 common.infoMsg("Waiting for Rundeck to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001258 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 +04001259 }
Martin Polreich80fa3182018-10-22 15:16:53 +02001260 salt.enforceState([saltId: master, target: "I@rundeck:client ${extra_tgt}", state: 'rundeck.client'])
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001261
1262 // Elasticsearch
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001263 pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:host')
Mikhail Ivanovfcd55d62017-12-19 16:51:35 +04001264 def elasticsearch_vip
1265 if(!pillar['return'].isEmpty()) {
1266 elasticsearch_vip = pillar['return'][0].values()[0]
1267 } else {
1268 common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved')
1269 }
1270
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001271 timeout(10) {
1272 common.infoMsg('Waiting for Elasticsearch to come up..')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001273 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 +04001274 }
Martin Polreich80fa3182018-10-22 15:16:53 +02001275 salt.enforceState([saltId: master, target: "I@elasticsearch:client ${extra_tgt}", state: 'elasticsearch.client'])
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001276}
Oleksii Grudev9e1d97a2018-06-29 16:04:30 +03001277
1278/**
1279 * Function receives connection string, target and configuration yaml pattern
1280 * and retrieves config fom salt minion according to pattern. After that it
1281 * sorts applications according to priorities and runs orchestration states
1282 * @param master Salt Connection object or pepperEnv
1283 * @param tgt Target
1284 * @param conf Configuration pattern
1285 */
1286def OrchestrateApplications(master, tgt, conf) {
1287 def salt = new com.mirantis.mk.Salt()
1288 def common = new com.mirantis.mk.Common()
1289 def _orch = salt.getConfig(master, tgt, conf)
1290 if ( !_orch['return'][0].values()[0].isEmpty() ) {
1291 Map<String,Integer> _orch_app = [:]
1292 for (k in _orch['return'][0].values()[0].keySet()) {
1293 _orch_app[k] = _orch['return'][0].values()[0][k].values()[0].toInteger()
1294 }
1295 def _orch_app_sorted = common.SortMapByValueAsc(_orch_app)
1296 common.infoMsg("Applications will be deployed in following order:"+_orch_app_sorted.keySet())
1297 for (app in _orch_app_sorted.keySet()) {
1298 salt.orchestrateSystem(master, ['expression': tgt, 'type': 'compound'], "${app}.orchestrate.deploy")
1299 }
1300 }
1301 else {
1302 common.infoMsg("No applications found for orchestration")
1303 }
Inessa Vasilevskaya85ad1a92018-10-08 12:19:47 +02001304}