blob: de8ce6874068ac66b34b2063072bdaab73db1c5c [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
Martin Polreichf7976952019-03-04 10:06:11 +010022def installFoundationInfra(master, staticMgmtNet=false, extra_tgt = '', batch=20) {
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])
Denis Meltsaykin214bf402020-05-05 16:07:45 +000033 salt.fullRefresh(master, "* ${extra_tgt}", batch)
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']])
Denis Meltsaykin214bf402020-05-05 16:07:45 +000037 salt.fullRefresh(master, "* ${extra_tgt}", batch)
Martin Polreichf7976952019-03-04 10:06:11 +010038 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: ['linux.network.proxy'], batch: batch, failOnError: false, read_timeout: 180, 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 Polreichf7976952019-03-04 10:06:11 +010040 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: ['linux.system.repo'], batch: batch, failOnError: false, read_timeout: 180, retries: 2])
Jiri Broulik94fc2592018-04-20 13:47:51 +020041 try {
Martin Polreichf7976952019-03-04 10:06:11 +010042 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: ['salt.minion.base'], batch: batch, failOnError: false, read_timeout: 180, 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 }
Martin Polreichf7976952019-03-04 10:06:11 +010047 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: ['linux.system'], batch: batch, retries: 2])
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +010048 if (staticMgmtNet) {
Martin Polreichf7976952019-03-04 10:06:11 +010049 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], batch, true, 180)
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +010050 }
Martin Polreichf7976952019-03-04 10:06:11 +010051 salt.enforceState([saltId: master, target: "I@linux:network:interface ${extra_tgt}", state: ['linux.network.interface'], batch: batch, retries: 2])
Jiri Broulik94538462018-05-11 15:45:13 +020052 sleep(5)
Martin Polreichf7976952019-03-04 10:06:11 +010053 salt.enforceState([saltId: master, target: "I@linux:system ${extra_tgt}", state: ['linux', 'openssh', 'ntp', 'rsyslog'], batch: batch])
Ann Taraday49059762018-10-25 17:04:58 +040054
Denis Meltsaykin214bf402020-05-05 16:07:45 +000055
56 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: ['salt.minion'], failOnError: false, batch: batch, read_timeout: 180, retries: 2])
57
Jakub Josef4f8f4df2017-09-01 14:32:42 +020058 sleep(5)
Victor Ryzhenkinf610c572018-05-15 15:22:52 +040059
Denis Meltsaykin214bf402020-05-05 16:07:45 +000060 salt.fullRefresh(master, "* ${extra_tgt}", batch)
Martin Polreichf7976952019-03-04 10:06:11 +010061 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'mine.update', [], batch, true)
62 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: ['linux.network.host'], batch: batch])
Denis Egorenko2f9eec72019-11-01 18:04:02 +040063 // WA for PROD-33911
64 salt.enforceState([saltId: master, target: "I@linux:system ${extra_tgt}", state: ['openssh'], batch: batch])
Ivan Suzdal9a6bc392018-04-26 18:29:56 +040065
66 // Install and configure iptables
Martin Polreichf7976952019-03-04 10:06:11 +010067 salt.enforceStateWithTest([saltId: master, target: "I@iptables:service ${extra_tgt}", state: 'iptables', batch: batch])
sgarbuzbb61e812018-05-03 16:58:40 +030068
69 // Install and configure logrotate
Martin Polreichf7976952019-03-04 10:06:11 +010070 salt.enforceStateWithTest([saltId: master, target: "I@logrotate:server ${extra_tgt}", state: 'logrotate', batch: batch])
Ivan Suzdal9f8f0e12018-06-21 13:16:21 +040071
72 // Install and configure auditd
Martin Polreichf7976952019-03-04 10:06:11 +010073 salt.enforceStateWithTest([saltId: master, target: "I@auditd:service ${extra_tgt}", state: 'auditd', batch: batch])
Ivan Suzdalca980912018-08-02 09:35:07 +040074
75 // Install and configure openscap
Martin Polreichf7976952019-03-04 10:06:11 +010076 salt.enforceStateWithTest([saltId: master, target: "I@openscap:service ${extra_tgt}", state: 'openscap', batch: batch])
Jakub Josef79ecec32017-02-17 14:36:28 +010077}
78
Oleh Hryhorov5f96e092018-06-22 18:37:08 +030079def installFoundationInfraOnTarget(master, target, staticMgmtNet=false, extra_tgt = '') {
Jiri Broulik976bf6c2017-10-20 14:43:25 +020080 def salt = new com.mirantis.mk.Salt()
Jiri Broulik9fb138a2018-04-23 17:13:00 +020081 def common = new com.mirantis.mk.Common()
Jiri Broulik976bf6c2017-10-20 14:43:25 +020082
Martin Polreich80fa3182018-10-22 15:16:53 +020083 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 +010084 salt.fullRefresh(master, target)
Martin Polreich80fa3182018-10-22 15:16:53 +020085 salt.enforceState([saltId: master, target: target, state: ['linux.network.proxy'], failOnError: false, read_timeout: 60, retries: 2])
Valeriy Sakharov0f6c2712020-10-12 13:34:25 +040086 // Make sure all repositories are in place before proceeding with package installation from other states
87 salt.enforceState([saltId: master, target: target, state: ['linux.system.repo'], batch: batch, failOnError: false, read_timeout: 180, 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 }
Martin Polreich331f2b62019-02-08 10:16:52 +010094 salt.enforceState([saltId: master, target: target, state: ['linux.system'], retries: 2])
Jiri Broulik8e1f1fe2017-12-13 11:54:06 +010095 if (staticMgmtNet) {
96 salt.runSaltProcessStep(master, target, 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], null, true, 60)
97 }
Martin Polreich80fa3182018-10-22 15:16:53 +020098 salt.enforceState([saltId: master, target: target, state: ['salt.minion'], failOnError: false, read_timeout: 60, retries: 2])
99 salt.enforceState([saltId: master, target: target, state: ['salt.minion']])
100 salt.enforceState([saltId: master, target: target, state: ['linux.network.interface']])
Jiri Broulik94538462018-05-11 15:45:13 +0200101 sleep(5)
Martin Polreich80fa3182018-10-22 15:16:53 +0200102 salt.enforceState([saltId: master, target: target, state: ['linux', 'openssh', 'ntp', 'rsyslog']])
Jiri Broulik976bf6c2017-10-20 14:43:25 +0200103 sleep(5)
Victor Ryzhenkinf610c572018-05-15 15:22:52 +0400104
105 salt.fullRefresh(master, target)
vrovachevc4424a32018-03-15 17:35:57 +0400106 salt.runSaltProcessStep(master, target, 'mine.update', [], null, true)
Martin Polreich80fa3182018-10-22 15:16:53 +0200107 salt.enforceState([saltId: master, target: target, state: ['linux.network.host']])
Jiri Broulik976bf6c2017-10-20 14:43:25 +0200108}
109
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300110def installInfraKvm(master, extra_tgt = '') {
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200111 def common = new com.mirantis.mk.Common()
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +0100112 def salt = new com.mirantis.mk.Salt()
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300113 def infra_compound = "I@salt:control ${extra_tgt}"
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200114 def minions = []
115 def wait_timeout = 10
116 def retries = wait_timeout * 30
Ales Komarekef2bab62017-04-26 11:48:28 +0200117
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300118 salt.fullRefresh(master, "I@linux:system ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200119 salt.enforceState([saltId: master, target: "I@salt:control ${extra_tgt}", state: ['salt.minion'], failOnError: false, read_timeout: 60, retries: 2])
120 salt.enforceState([saltId: master, target: "I@salt:control ${extra_tgt}", state: ['linux.system', 'linux.network', 'ntp', 'rsyslog']])
121 salt.enforceState([saltId: master, target: "I@salt:control ${extra_tgt}", state: 'libvirt'])
122 salt.enforceState([saltId: master, target: "I@salt:control ${extra_tgt}", state: 'salt.control'])
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100123
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200124 common.infoMsg("Building minions list...")
125 if (salt.testTarget(master, infra_compound)) {
126 // Gathering minions
127 for ( infra_node in salt.getMinionsSorted(master, infra_compound) ) {
128 def pillar = salt.getPillar(master, infra_node, 'salt:control:cluster')
129 if ( !pillar['return'].isEmpty() ) {
130 for ( cluster in pillar['return'][0].values() ) {
131 def engine = cluster.values()[0]['engine']
132 def domain = cluster.values()[0]['domain']
133 def node = cluster.values()[0]['node']
134 if ( engine == "virt" ) {
135 def nodes = node.values()
136 if ( !nodes.isEmpty() ) {
137 for ( vm in nodes ) {
138 if ( vm['name'] != null ) {
139 def vm_fqdn = vm['name'] + '.' + domain
140 if ( !minions.contains(vm_fqdn) ) {
141 minions.add(vm_fqdn)
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200142 }
143 }
144 }
145 }
146 }
147 }
148 }
149 }
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200150 }
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100151
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200152 def minions_compound = minions.join(' or ')
153
154 common.infoMsg("Waiting for next minions to register within ${wait_timeout} minutes: " + minions_compound)
155 timeout(time: wait_timeout, unit: 'MINUTES') {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300156 salt.minionsPresentFromList(master, "I@salt:master ${extra_tgt}", minions, true, null, true, retries, 1)
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200157 }
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200158
Dzmitry Stremkouski5425d232018-06-07 00:46:00 +0200159 common.infoMsg('Waiting for minions to respond')
160 timeout(time: wait_timeout, unit: 'MINUTES') {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300161 salt.minionsReachable(master, "I@salt:master ${extra_tgt}", minions_compound)
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200162 }
163
164 common.infoMsg("All minions are up.")
Denis Egorenko8006cce2019-08-26 13:16:23 +0400165 salt.fullRefresh(master, "* and not I@salt:control ${extra_tgt}")
Dzmitry Stremkouski8a8d56b2018-05-01 12:20:04 +0200166
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +0100167}
Jakub Josef79ecec32017-02-17 14:36:28 +0100168
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300169def installInfra(master, extra_tgt = '') {
Jakub Josef61463c72018-02-13 16:10:56 +0100170 def common = new com.mirantis.mk.Common()
Jakub Josef79ecec32017-02-17 14:36:28 +0100171 def salt = new com.mirantis.mk.Salt()
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400172 def first_target
Ales Komarekef2bab62017-04-26 11:48:28 +0200173
Jakub Josef79ecec32017-02-17 14:36:28 +0100174 // Install glusterfs
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300175 if (salt.testTarget(master, "I@glusterfs:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200176 salt.enforceState([saltId: master, target: "I@glusterfs:server ${extra_tgt}", state: 'glusterfs.server.service'])
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100177
Martin Polreich80fa3182018-10-22 15:16:53 +0200178 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 +0100179 sleep(10)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300180 salt.cmdRun(master, "I@glusterfs:server ${extra_tgt}", "gluster peer status; gluster volume status")
Alexander Noskov93acac42017-06-20 17:55:55 +0200181 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200182
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300183 // Ensure glusterfs clusters is ready
Martin Polreich80fa3182018-10-22 15:16:53 +0200184 salt.enforceStateWithTest([saltId: master, target: "I@glusterfs:client ${extra_tgt}", state: 'glusterfs.client', retries: 2])
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300185
Jakub Josef79ecec32017-02-17 14:36:28 +0100186 // Install galera
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300187 if (salt.testTarget(master, "I@galera:master ${extra_tgt}") || salt.testTarget(master, "I@galera:slave ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200188 salt.enforceState([saltId: master, target: "I@galera:master ${extra_tgt}", state: 'galera', retries: 2])
189 salt.enforceStateWithTest([saltId: master, target: "I@galera:slave ${extra_tgt}", state: 'galera', retries: 2])
vrovachev1c4770b2017-07-05 13:25:21 +0400190
191 // Check galera status
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300192 salt.runSaltProcessStep(master, "I@galera:master ${extra_tgt}", 'mysql.status')
Dzmitry Stremkouskidf727b22018-10-29 17:19:55 +0100193 if (salt.testTarget(master, "I@galera:slave ${extra_tgt}")) {
194 salt.runSaltProcessStep(master, "I@galera:slave ${extra_tgt}", 'mysql.status')
195 }
196
Vasyl Saienkoc1fb9892017-07-13 14:54:13 +0300197 // If galera is not enabled check if we need to install mysql:server
Martin Polreich675dc942018-08-15 09:37:32 +0200198 } else {
Ivan Berezovskiyd6d341d2020-01-27 14:22:10 +0400199 salt.enforceStateWithTest([saltId: master, target: "I@mysql:server ${extra_tgt}", state: 'mysql.server'])
200 salt.enforceStateWithTest([saltId: master, target: "I@mysql:client ${extra_tgt}", state: 'mysql.client'])
Ales Komarekef2bab62017-04-26 11:48:28 +0200201 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300202 installBackup(master, 'mysql', extra_tgt)
Ales Komarekef2bab62017-04-26 11:48:28 +0200203
vrovachev1c4770b2017-07-05 13:25:21 +0400204 // Install docker
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300205 if (salt.testTarget(master, "I@docker:host ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200206 salt.enforceState([saltId: master, target: "I@docker:host ${extra_tgt}", state: 'docker.host', retries: 3])
Pavel Cizinskyee34e312018-08-06 15:11:58 +0200207 salt.cmdRun(master, "I@docker:host and I@docker:host:enabled:true ${extra_tgt}", 'docker ps')
vrovachev1c4770b2017-07-05 13:25:21 +0400208 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200209
vrovachev1c4770b2017-07-05 13:25:21 +0400210 // Install keepalived
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300211 if (salt.testTarget(master, "I@keepalived:cluster ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400212 first_target = salt.getFirstMinion(master, "I@keepalived:cluster ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200213 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'keepalived'])
214 salt.enforceState([saltId: master, target: "I@keepalived:cluster ${extra_tgt}", state: 'keepalived'])
vrovachev1c4770b2017-07-05 13:25:21 +0400215 }
216
217 // Install rabbitmq
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300218 if (salt.testTarget(master, "I@rabbitmq:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200219 salt.enforceState([saltId: master, target: "I@rabbitmq:server ${extra_tgt}", state: 'rabbitmq', retries: 2])
vrovachev1c4770b2017-07-05 13:25:21 +0400220
221 // Check the rabbitmq status
Jakub Josef61463c72018-02-13 16:10:56 +0100222 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300223 salt.cmdRun(master, "I@rabbitmq:server ${extra_tgt}", 'rabbitmqctl cluster_status')
Jakub Josef61463c72018-02-13 16:10:56 +0100224 }
vrovachev1c4770b2017-07-05 13:25:21 +0400225 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200226
Jakub Josef79ecec32017-02-17 14:36:28 +0100227 // Install haproxy
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300228 if (salt.testTarget(master, "I@haproxy:proxy ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200229 salt.enforceState([saltId: master, target: "I@haproxy:proxy ${extra_tgt}", state: 'haproxy'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300230 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.status', ['haproxy'])
231 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.restart', ['rsyslog'])
vrovachev1c4770b2017-07-05 13:25:21 +0400232 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200233
Jakub Josef79ecec32017-02-17 14:36:28 +0100234 // Install memcached
Martin Polreich80fa3182018-10-22 15:16:53 +0200235 salt.enforceStateWithTest([saltId: master, target: "I@memcached:server ${extra_tgt}", state: 'memcached'])
vrovachev1c4770b2017-07-05 13:25:21 +0400236
237 // Install etcd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300238 if (salt.testTarget(master, "I@etcd:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200239 salt.enforceState([saltId: master, target: "I@etcd:server ${extra_tgt}", state: 'etcd.server.service'])
Jakub Josef61463c72018-02-13 16:10:56 +0100240 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300241 salt.cmdRun(master, "I@etcd:server ${extra_tgt}", '. /var/lib/etcd/configenv && etcdctl cluster-health')
Jakub Josef61463c72018-02-13 16:10:56 +0100242 }
vrovachev1c4770b2017-07-05 13:25:21 +0400243 }
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200244
245 // Install redis
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300246 if (salt.testTarget(master, "I@redis:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200247 salt.enforceStateWithTest([saltId: master, target: "I@redis:cluster:role:master ${extra_tgt}", state: 'redis'])
248 salt.enforceState([saltId: master, target: "I@redis:server ${extra_tgt}", state: 'redis'])
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200249 }
Mykyta Karpin0a3dc8b2018-09-05 10:09:18 +0300250
251 // Install DNS services
252 if (salt.testTarget(master, "I@bind:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200253 salt.enforceState([saltId: master, target: "I@bind:server ${extra_tgt}", state: 'bind.server'])
Mykyta Karpin0a3dc8b2018-09-05 10:09:18 +0300254 }
255 if (salt.testTarget(master, "I@powerdns:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200256 salt.enforceState([saltId: master, target: "I@powerdns:server ${extra_tgt}", state: 'powerdns.server'])
Mykyta Karpin0a3dc8b2018-09-05 10:09:18 +0300257 }
258
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300259 installBackup(master, 'common', extra_tgt)
vrovachev1c4770b2017-07-05 13:25:21 +0400260}
261
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300262def installOpenstackInfra(master, extra_tgt = '') {
Jakub Josef432e9d92018-02-06 18:28:37 +0100263 def common = new com.mirantis.mk.Common()
264 common.warningMsg("You calling orchestrate.installOpenstackInfra(). This function is deprecated please use orchestrate.installInfra() directly")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300265 installInfra(master, extra_tgt)
Jakub Josef79ecec32017-02-17 14:36:28 +0100266}
267
268
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300269def installOpenstackControl(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100270 def salt = new com.mirantis.mk.Salt()
Jakub Josef61463c72018-02-13 16:10:56 +0100271 def common = new com.mirantis.mk.Common()
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400272 def first_target
Ales Komarekef2bab62017-04-26 11:48:28 +0200273
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100274 // Install sphinx server
Martin Polreich80fa3182018-10-22 15:16:53 +0200275 salt.enforceStateWithTest([saltId: master, target: "I@sphinx:server ${extra_tgt}", state: 'sphinx'])
Mykyta Karpin014131a2018-12-18 17:35:38 +0200276 // Running minion states in a batch to avoid races related to certificates which are placed on glusterfs
277 // Details on races: https://mirantis.jira.com/browse/PROD-25796
278 // TODO: Run in parallel when glusterfs for certificates is dropped in cookiecutter
azvyagintseve9beda32019-06-07 15:20:52 +0300279 salt.enforceStateWithTest([saltId: master, target: "I@nginx:server ${extra_tgt}", state: 'salt.minion', batch: 1, failOnError: false, retries: 2])
azvyagintsev4b8f4022019-06-10 14:12:38 +0300280 salt.enforceStateWithTest([saltId: master, target: "I@nginx:server ${extra_tgt}", state: 'salt.minion', batch: 1, failOnError: true, retries: 1])
azvyagintseve9beda32019-06-07 15:20:52 +0300281
Martin Polreich80fa3182018-10-22 15:16:53 +0200282 salt.enforceStateWithTest([saltId: master, target: "I@nginx:server ${extra_tgt}", state: 'nginx'])
Ales Komarekef2bab62017-04-26 11:48:28 +0200283
Jakub Josef79ecec32017-02-17 14:36:28 +0100284 // setup keystone service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300285 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200286 salt.enforceState([saltId: master, target: "I@keystone:server:role:primary ${extra_tgt}", state: 'keystone.server'])
287 salt.enforceState([saltId: master, target: "I@keystone:server ${extra_tgt}", state: 'keystone.server'])
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300288 // populate keystone services/tenants/roles/users
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100289
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300290 // keystone:client must be called locally
291 //salt.runSaltProcessStep(master, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300292 salt.runSaltProcessStep(master, "I@keystone:server ${extra_tgt}", 'service.restart', ['apache2'])
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300293 sleep(30)
294 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300295 if (salt.testTarget(master, "I@keystone:client ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400296 first_target = salt.getFirstMinion(master, "I@keystone:client ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200297 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'keystone.client'])
298 salt.enforceState([saltId: master, target: "I@keystone:client ${extra_tgt}", state: 'keystone.client'])
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300299 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300300 if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
Jakub Josef61463c72018-02-13 16:10:56 +0100301 common.retry(3,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300302 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack service list')
Jakub Josef61463c72018-02-13 16:10:56 +0100303 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300304 }
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100305
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300306 // Install glance
Martin Polreich80fa3182018-10-22 15:16:53 +0200307 salt.enforceStateWithTest([saltId: master, target: "I@glance:server:role:primary ${extra_tgt}", state: 'glance.server', testTargetMatcher: "I@glance:server ${extra_tgt}"])
308 salt.enforceStateWithTest([saltId: master, target: "I@glance:server ${extra_tgt}", state: 'glance.server'])
Ales Komarekef2bab62017-04-26 11:48:28 +0200309
Oleg Grigorov26c8a6c2017-08-17 18:54:02 +0300310 // Check glance service
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300311 if (salt.testTarget(master, "I@glance:server ${extra_tgt}")) {
Mykyta Karpinfc169b72018-11-19 09:57:07 +0200312 common.retry(10,5){
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300313 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; glance image-list')
Jakub Josef61463c72018-02-13 16:10:56 +0100314 }
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300315 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200316
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400317 // Create glance resources
Martin Polreich80fa3182018-10-22 15:16:53 +0200318 salt.enforceStateWithTest([saltId: master, target: "I@glance:client ${extra_tgt}", state: 'glance.client'])
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400319
Jakub Josef79ecec32017-02-17 14:36:28 +0100320 // Install and check nova service
Martin Polreich675dc942018-08-15 09:37:32 +0200321 // run on first node first
Martin Polreich80fa3182018-10-22 15:16:53 +0200322 salt.enforceStateWithTest([saltId: master, target: "I@nova:controller:role:primary ${extra_tgt}", state: 'nova.controller', testTargetMatcher: "I@nova:controller ${extra_tgt}"])
323 salt.enforceStateWithTest([saltId: master, target: "I@nova:controller ${extra_tgt}", state: 'nova.controller'])
Martin Polreich675dc942018-08-15 09:37:32 +0200324 if (salt.testTarget(master, "I@keystone:server and I@nova:controller ${extra_tgt}")) {
325 common.retry(3,5){
326 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; nova service-list')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300327 }
328 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200329
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400330 // Create nova resources
Martin Polreich80fa3182018-10-22 15:16:53 +0200331 salt.enforceStateWithTest([saltId: master, target: "I@nova:client ${extra_tgt}", state: 'nova.client'])
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400332
Jakub Josef79ecec32017-02-17 14:36:28 +0100333 // Install and check cinder service
Martin Polreich675dc942018-08-15 09:37:32 +0200334 // run on first node first
Martin Polreich80fa3182018-10-22 15:16:53 +0200335 salt.enforceStateWithTest([saltId: master, target: "I@cinder:controller:role:primary ${extra_tgt}", state: 'cinder', testTargetMatcher: "I@cinder:controller ${extra_tgt}"])
336 salt.enforceStateWithTest([saltId: master, target: "I@cinder:controller ${extra_tgt}", state: 'cinder'])
Martin Polreich675dc942018-08-15 09:37:32 +0200337 if (salt.testTarget(master, "I@keystone:server and I@cinder:controller ${extra_tgt}")) {
338 common.retry(3,5){
339 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; cinder list')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300340 }
341 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200342
Jakub Josef79ecec32017-02-17 14:36:28 +0100343 // Install neutron service
Martin Polreich675dc942018-08-15 09:37:32 +0200344 // run on first node first
Martin Polreich80fa3182018-10-22 15:16:53 +0200345 salt.enforceStateWithTest([saltId: master, target: "I@neutron:server:role:primary ${extra_tgt}", state: 'neutron.server', testTargetMatcher: "I@neutron:server ${extra_tgt}"])
346 salt.enforceStateWithTest([saltId: master, target: "I@neutron:server ${extra_tgt}", state: 'neutron.server'])
Martin Polreich675dc942018-08-15 09:37:32 +0200347 if (salt.testTarget(master, "I@keystone:server and I@neutron:server ${extra_tgt}")) {
Vasyl Saienko0b86a4f2018-11-16 14:02:34 +0200348 common.retry(10,5){
Martin Polreich675dc942018-08-15 09:37:32 +0200349 salt.cmdRun(master, "I@keystone:server ${extra_tgt}",'. /root/keystonercv3; neutron agent-list')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300350 }
351 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200352
Jakub Josef79ecec32017-02-17 14:36:28 +0100353 // Install heat service
Martin Polreich80fa3182018-10-22 15:16:53 +0200354 salt.enforceStateWithTest([saltId: master, target: "I@heat:server:role:primary ${extra_tgt}", state: 'heat', testTargetMatcher: "I@heat:server ${extra_tgt}"])
355 salt.enforceStateWithTest([saltId: master, target: "I@heat:server ${extra_tgt}", state: 'heat'])
Martin Polreich675dc942018-08-15 09:37:32 +0200356 if (salt.testTarget(master, "I@keystone:server and I@heat:server ${extra_tgt}")) {
Mykyta Karpina678da62018-12-20 17:26:51 +0200357 common.retry(10,5){
Martin Polreich675dc942018-08-15 09:37:32 +0200358 salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack orchestration resource type list')
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300359 }
360 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200361
362 // Restart nova api
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300363 if (salt.testTarget(master, "I@nova:controller ${extra_tgt}")) {
364 salt.runSaltProcessStep(master, "I@nova:controller ${extra_tgt}", 'service.restart', ['nova-api'])
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300365 }
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300366
367 // Install ironic service
Martin Polreich80fa3182018-10-22 15:16:53 +0200368 salt.enforceStateWithTest([saltId: master, target: "I@ironic:api:role:primary ${extra_tgt}", state: 'ironic.api', testTargetMatcher: "I@ironic:api ${extra_tgt}"])
369 salt.enforceStateWithTest([saltId: master, target: "I@ironic:api ${extra_tgt}", state: 'ironic.api'])
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300370
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200371 // Install manila service
Martin Polreich80fa3182018-10-22 15:16:53 +0200372 salt.enforceStateWithTest([saltId: master, target: "I@manila:api:role:primary ${extra_tgt}", state: 'manila.api', testTargetMatcher: "I@manila:api ${extra_tgt}"])
373 salt.enforceStateWithTest([saltId: master, target: "I@manila:api ${extra_tgt}", state: 'manila.api'])
374 salt.enforceStateWithTest([saltId: master, target: "I@manila:scheduler ${extra_tgt}", state: 'manila.scheduler'])
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200375
Oleh Hryhorova070fd02018-03-15 14:47:52 +0200376 // Install designate services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300377 if (salt.testTarget(master, "I@designate:server:enabled ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200378 salt.enforceState([saltId: master, target: "I@designate:server:role:primary ${extra_tgt}", state: 'designate.server'])
379 salt.enforceState([saltId: master, target: "I@designate:server ${extra_tgt}", state: 'designate'])
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300380 }
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400381
382 // Install octavia api service
Martin Polreich80fa3182018-10-22 15:16:53 +0200383 salt.enforceStateWithTest([saltId: master, target: "I@octavia:api:role:primary ${extra_tgt}", state: 'octavia.api', testTargetMatcher: "I@octavia:api ${extra_tgt}"])
384 salt.enforceStateWithTest([saltId: master, target: "I@octavia:api ${extra_tgt}", state: 'octavia.api'])
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200385
Oleg Iurchenkod0898c92017-12-14 14:28:44 +0200386 // Install DogTag server service
Martin Polreich80fa3182018-10-22 15:16:53 +0200387 salt.enforceStateWithTest([saltId: master, target: "I@dogtag:server:role:master ${extra_tgt}", state: 'dogtag.server', testTargetMatcher: "I@dogtag:server ${extra_tgt}"])
Vasyl Saienko6f83b6b2019-02-01 11:55:52 +0200388 // Run dogtag state on slaves in serial to avoid races during replications PROD-26810
389 salt.enforceStateWithTest([saltId: master, target: "I@dogtag:server ${extra_tgt}", state: 'dogtag.server', batch: 1])
Oleg Iurchenkod0898c92017-12-14 14:28:44 +0200390
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200391 // Install barbican server service
Martin Polreich80fa3182018-10-22 15:16:53 +0200392 salt.enforceStateWithTest([saltId: master, target: "I@barbican:server:role:primary ${extra_tgt}", state: 'barbican.server', testTargetMatcher: "I@barbican:server ${extra_tgt}"])
393 salt.enforceStateWithTest([saltId: master, target: "I@barbican:server ${extra_tgt}", state: 'barbican.server'])
Martin Polreich675dc942018-08-15 09:37:32 +0200394
Vasyl Saienkoa96a7662019-02-04 14:29:19 +0200395 if (salt.testTarget(master, "I@barbican:server ${extra_tgt}")) {
396 // Restart apache to make sure we don't have races between barbican-api and barbican-worker on db init.
397 // For more info please see PROD-26988
398 // The permanent fix is prepared to barbican formula https://gerrit.mcp.mirantis.com/#/c/35097/ but due to rush in release
399 // add this workaround here as well.
400 // TODO(vsaienko): cleanup once release passed in favor of permanent fix.
401 salt.runSaltProcessStep(master, "I@barbican:server ${extra_tgt}", 'service.restart', ['apache2'])
402 sleep(30)
403 }
404
Marek Celoudc9dd50f2017-08-28 13:54:40 +0200405 // Install barbican client
Martin Polreich80fa3182018-10-22 15:16:53 +0200406 salt.enforceStateWithTest([saltId: master, target: "I@barbican:client ${extra_tgt}", state: 'barbican.client'])
Ondrej Smola5908ae62018-01-08 13:42:08 +0100407
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200408 // Install gnocchi server
Martin Polreich80fa3182018-10-22 15:16:53 +0200409 salt.enforceStateWithTest([saltId: master, target: "I@gnocchi:server:role:primary ${extra_tgt}", state: 'gnocchi.server', testTargetMatcher: "I@gnocchi:server ${extra_tgt}"])
410 salt.enforceStateWithTest([saltId: master, target: "I@gnocchi:server ${extra_tgt}", state: 'gnocchi.server'])
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200411
Mykyta Karpin4816e522018-06-15 16:00:03 +0300412 // Apply gnocchi client state to create gnocchi archive policies, due to possible
413 // races, apply on the first node initially
414 if (salt.testTarget(master, "I@gnocchi:client ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400415 first_target = salt.getFirstMinion(master, "I@gnocchi:client ${extra_tgt}")
Vasyl Saienkoa55e3772019-07-24 15:31:00 +0300416 // TODO(vsaienko) remove retries when they are moved to gnocchiv1 salt module. Related-Prod: PROD-32186
417 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'gnocchi.client', retries: 3])
418 salt.enforceState([saltId: master, target: "I@gnocchi:client ${extra_tgt}", state: 'gnocchi.client', retries: 3])
Mykyta Karpin4816e522018-06-15 16:00:03 +0300419 }
420
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200421 // Install gnocchi statsd
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300422 if (salt.testTarget(master, "I@gnocchi:statsd ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400423 first_target = salt.getFirstMinion(master, "I@gnocchi:statsd ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200424 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'gnocchi.statsd'])
425 salt.enforceState([saltId: master, target: "I@gnocchi:statsd ${extra_tgt}", state: 'gnocchi.statsd'])
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200426 }
427
428 // Install panko server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300429 if (salt.testTarget(master, "I@panko:server ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400430 first_target = salt.getFirstMinion(master, "I@panko:server ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200431 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'panko'])
432 salt.enforceState([saltId: master, target: "I@panko:server ${extra_tgt}", state: 'panko'])
Mykyta Karpin8185e4a2018-02-23 19:15:48 +0200433 }
434
Ondrej Smola5908ae62018-01-08 13:42:08 +0100435 // Install ceilometer server
Martin Polreich80fa3182018-10-22 15:16:53 +0200436 salt.enforceStateWithTest([saltId: master, target: "I@ceilometer:server:role:primary ${extra_tgt}", state: 'ceilometer', testTargetMatcher: "I@ceilometer:server ${extra_tgt}"])
437 salt.enforceStateWithTest([saltId: master, target: "I@ceilometer:server ${extra_tgt}", state: 'ceilometer'])
Ondrej Smola5908ae62018-01-08 13:42:08 +0100438
439 // Install aodh server
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300440 if (salt.testTarget(master, "I@aodh:server ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400441 first_target = salt.getFirstMinion(master, "I@aodh:server ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200442 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'aodh'])
443 salt.enforceState([saltId: master, target: "I@aodh:server ${extra_tgt}", state: 'aodh'])
Ondrej Smola5908ae62018-01-08 13:42:08 +0100444 }
Oleksandr Bryndzii642cb252018-11-08 12:24:42 +0200445
446 // Install horizon dashboard
Martin Polreichc3e9d5d2019-11-27 16:24:04 +0100447 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'mine.update')
Martin Polreich80fa3182018-10-22 15:16:53 +0200448 salt.enforceStateWithTest([saltId: master, target: "I@horizon:server ${extra_tgt}", state: 'horizon'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100449}
450
451
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300452def installIronicConductor(master, extra_tgt = ''){
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300453 def salt = new com.mirantis.mk.Salt()
454
Martin Polreich80fa3182018-10-22 15:16:53 +0200455 salt.enforceStateWithTest([saltId: master, target: "I@ironic:conductor ${extra_tgt}", state: 'ironic.conductor'])
456 salt.enforceStateWithTest([saltId: master, target: "I@ironic:conductor ${extra_tgt}", state: 'apache'])
457 salt.enforceStateWithTest([saltId: master, target: "I@tftpd_hpa:server ${extra_tgt}", state: 'tftpd_hpa'])
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300458
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300459 if (salt.testTarget(master, "I@nova:compute ${extra_tgt}")) {
460 salt.runSaltProcessStep(master, "I@nova:compute ${extra_tgt}", 'service.restart', ['nova-compute'])
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300461 }
462
Martin Polreich80fa3182018-10-22 15:16:53 +0200463 salt.enforceStateWithTest([saltId: master, target: "I@baremetal_simulator:enabled ${extra_tgt}", state: 'baremetal_simulator'])
464 salt.enforceStateWithTest([saltId: master, target: "I@ironic:client ${extra_tgt}", state: 'ironic.client'])
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300465}
466
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300467def installManilaShare(master, extra_tgt = ''){
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200468 def salt = new com.mirantis.mk.Salt()
469
Martin Polreich80fa3182018-10-22 15:16:53 +0200470 salt.enforceStateWithTest([saltId: master, target: "I@manila:share ${extra_tgt}", state: 'manila.share'])
471 salt.enforceStateWithTest([saltId: master, target: "I@manila:data ${extra_tgt}", state: 'manila.data'])
472 salt.enforceStateWithTest([saltId: master, target: "I@manila:client ${extra_tgt}", state: 'manila.client'])
Vasyl Saienkob7e4cdf2018-02-21 18:33:17 +0200473}
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300474
475
Oleh Hryhorov37fbd0c2018-07-11 16:58:54 +0300476def installOpenstackNetwork(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100477 def salt = new com.mirantis.mk.Salt()
Ann Taradayea9848c2018-10-25 11:15:58 +0400478 def common = new com.mirantis.mk.Common()
Dzmitry Stremkouskidf727b22018-10-29 17:19:55 +0100479
Oleksii Grudevc4a485e2018-04-20 14:25:03 +0300480 //run full neutron state on neutron.gateway - this will install
481 //neutron agents in addition to neutron server. Once neutron agents
482 //are up neutron resources can be created without hitting the situation when neutron resources are created
483 //prior to neutron agents which results in creating ports in non-usable state
Martin Polreich80fa3182018-10-22 15:16:53 +0200484 salt.enforceStateWithTest([saltId: master, target: "I@neutron:gateway ${extra_tgt}", state: 'neutron'])
Oleksii Grudevc4a485e2018-04-20 14:25:03 +0300485
486 // Create neutron resources - this step was moved here to ensure that
487 //neutron resources are created after neutron agens are up. In this case neutron ports will be in
488 //usable state. More information: https://bugs.launchpad.net/neutron/+bug/1399249
Martin Polreich80fa3182018-10-22 15:16:53 +0200489 salt.enforceStateWithTest([saltId: master, target: "I@neutron:client ${extra_tgt}", state: 'neutron.client'])
Ales Komarekef2bab62017-04-26 11:48:28 +0200490
Dzmitry Stremkouskidf727b22018-10-29 17:19:55 +0100491 if (salt.testTarget(master, "I@neutron:gateway ${extra_tgt}")) {
492 salt.enforceHighstate(master, "I@neutron:gateway ${extra_tgt}")
493 }
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400494
495 // install octavia manager services
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300496 if (salt.testTarget(master, "I@octavia:manager ${extra_tgt}")) {
Anna Taraday82224102018-10-09 07:44:24 +0000497 salt.runSaltProcessStep(master, "I@neutron:client ${extra_tgt}", 'mine.update')
Martin Polreich80fa3182018-10-22 15:16:53 +0200498 salt.enforceState([saltId: master, target: "I@octavia:manager ${extra_tgt}", state: 'octavia.manager'])
499 salt.enforceState([saltId: master, target: "I@octavia:client ${extra_tgt}", state: 'octavia.client'])
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400500 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200501}
502
503
Martin Polreichf7976952019-03-04 10:06:11 +0100504def installOpenstackCompute(master, extra_tgt = '', batch=20) {
Ales Komarekef2bab62017-04-26 11:48:28 +0200505 def salt = new com.mirantis.mk.Salt()
Mykyta Karpin3ec78a22018-07-10 12:27:09 +0300506 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200507 // Configure compute nodes
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300508 def compute_compound = "I@nova:compute ${extra_tgt}"
Martin Polreichf7976952019-03-04 10:06:11 +0100509 if (salt.testTarget(master, compute_compound, batch)) {
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100510 // In case if infrastructure nodes are used as nova computes too
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300511 def gluster_compound = "I@glusterfs:server ${extra_tgt}"
512 def salt_ca_compound = "I@salt:minion:ca:salt_master_ca ${extra_tgt}"
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200513 // Enforce highstate asynchronous only on compute nodes which are not glusterfs and not salt ca servers
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300514 def hightstateTarget = "${compute_compound} and not ${gluster_compound} and not ${salt_ca_compound}"
Martin Polreichf7976952019-03-04 10:06:11 +0100515 if (salt.testTarget(master, hightstateTarget, batch)) {
Oleh Hryhorov73f9fa22018-05-02 17:36:58 +0300516 retry(2) {
Martin Polreichf7976952019-03-04 10:06:11 +0100517 salt.enforceHighstate(master, hightstateTarget, false, true, batch)
Oleh Hryhorov73f9fa22018-05-02 17:36:58 +0300518 }
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300519 } else {
520 common.infoMsg("No minions matching highstate target found for target ${hightstateTarget}")
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200521 }
522 // Iterate through salt ca servers and check if they have compute role
523 // TODO: switch to batch once salt 2017.7+ would be used
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300524 common.infoMsg("Checking whether ${salt_ca_compound} minions have ${compute_compound} compound")
Martin Polreichf7976952019-03-04 10:06:11 +0100525 for ( target in salt.getMinionsSorted(master, salt_ca_compound, batch) ) {
526 for ( cmp_target in salt.getMinionsSorted(master, compute_compound, batch) ) {
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200527 if ( target == cmp_target ) {
528 // Enforce highstate one by one on salt ca servers which are compute nodes
529 retry(2) {
Vasyl Saienkobe599d12018-11-10 06:42:50 +0000530 salt.enforceHighstate(master, target)
Dzmitry Stremkouski7eca99d2018-04-25 18:44:26 +0200531 }
532 }
533 }
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100534 }
535 // Iterate through glusterfs servers and check if they have compute role
536 // TODO: switch to batch once salt 2017.7+ would be used
Mykyta Karpinb1eaba92018-07-10 10:09:37 +0300537 common.infoMsg("Checking whether ${gluster_compound} minions have ${compute_compound} compound")
Martin Polreichf7976952019-03-04 10:06:11 +0100538 for ( target in salt.getMinionsSorted(master, gluster_compound, batch) ) {
539 for ( cmp_target in salt.getMinionsSorted(master, compute_compound, batch) ) {
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100540 if ( target == cmp_target ) {
541 // Enforce highstate one by one on glusterfs servers which are compute nodes
542 retry(2) {
Vasyl Saienkobe599d12018-11-10 06:42:50 +0000543 salt.enforceHighstate(master, target)
Dzmitry Stremkouskifeb8ce92018-03-21 18:03:28 +0100544 }
545 }
546 }
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200547 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200548 }
Vasyl Saienko51144e42018-06-19 09:30:30 +0300549
550 // Run nova:controller to map cmp with cells
Martin Polreich80fa3182018-10-22 15:16:53 +0200551 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 +0200552}
553
554
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300555def installContrailNetwork(master, extra_tgt = '') {
Martin Polreichfc9854c2017-06-30 11:17:36 +0200556 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200557 def salt = new com.mirantis.mk.Salt()
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400558 def first_target
Ales Komarekef2bab62017-04-26 11:48:28 +0200559
Jakub Josef79ecec32017-02-17 14:36:28 +0100560 // Install opencontrail database services
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400561 first_target = salt.getFirstMinion(master, "I@opencontrail:database ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200562 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'opencontrail.database'])
563 salt.enforceState([saltId: master, target: "I@opencontrail:database ${extra_tgt}", state: 'opencontrail.database'])
Ales Komarekef2bab62017-04-26 11:48:28 +0200564
Jakub Josef79ecec32017-02-17 14:36:28 +0100565 // Install opencontrail control services
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400566 first_target = salt.getFirstMinion(master, "I@opencontrail:control ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200567 salt.enforceStateWithExclude([saltId: master, target: "${first_target} ${extra_tgt}", state: "opencontrail", excludedStates: "opencontrail.client"])
568 salt.enforceStateWithExclude([saltId: master, target: "I@opencontrail:control ${extra_tgt}", state: "opencontrail", excludedStates: "opencontrail.client"])
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400569 first_target = salt.getFirstMinion(master, "I@opencontrail:collector ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200570 salt.enforceStateWithExclude([saltId: master, target: "${first_target} ${extra_tgt}", state: "opencontrail", excludedStates: "opencontrail.client"])
571 salt.enforceStateWithExclude([saltId: master, target: "I@opencontrail:collector ${extra_tgt}", state: "opencontrail", excludedStates: "opencontrail.client"])
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100572
Martin Polreich80fa3182018-10-22 15:16:53 +0200573 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}"])
Anton Samoylov328a5722019-01-23 17:37:33 +0400574}
Svimbafb242db2019-01-09 17:27:20 +0100575
Anton Samoylov328a5722019-01-23 17:37:33 +0400576
577def checkContrailApiReadiness(master, extra_tgt = '') {
578 def common = new com.mirantis.mk.Common()
579 def salt = new com.mirantis.mk.Salt()
580
Anton Samoylovaf569b52019-01-25 14:49:52 +0400581 def apiCheckResult = salt.getReturnValues(salt.runSaltProcessStep(master, "I@opencontrail:control:role:primary ${extra_tgt}", 'contrail_health.get_api_status', ['wait_for=900', 'tries=50']))
Anton Samoylov37b58292019-01-22 15:28:31 +0400582 if (!apiCheckResult){
583 throw new Exception("Contrail is not working after deployment: contrail-api service is not in healthy state")
Anton Samoylov328a5722019-01-23 17:37:33 +0400584 } else {
585 common.infoMsg('Contrail API is ready to service requests')
Anton Samoylov37b58292019-01-22 15:28:31 +0400586 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100587}
588
589
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300590def installContrailCompute(master, extra_tgt = '') {
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200591 def salt = new com.mirantis.mk.Salt()
vrovachev32f7f542017-08-25 16:17:25 +0400592 def common = new com.mirantis.mk.Common()
Jakub Josef79ecec32017-02-17 14:36:28 +0100593 // Configure compute nodes
Ales Komarekef2bab62017-04-26 11:48:28 +0200594 // Provision opencontrail control services
Martin Polreich80fa3182018-10-22 15:16:53 +0200595 salt.enforceState([saltId: master, target: "I@opencontrail:database:id:1 ${extra_tgt}", state: 'opencontrail.client'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100596 // Provision opencontrail virtual routers
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100597
vrovachev4ff77302017-08-09 20:39:57 +0400598 // Generate script /usr/lib/contrail/if-vhost0 for up vhost0
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300599 if (salt.testTarget(master, "I@opencontrail:compute ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200600 salt.enforceStateWithExclude([saltId: master, target: "I@opencontrail:compute ${extra_tgt}", state: "opencontrail", excludedStates: "opencontrail.client"])
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200601 }
vrovachev4ff77302017-08-09 20:39:57 +0400602
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300603 if (salt.testTarget(master, "I@nova:compute ${extra_tgt}")) {
Anton Samoylov817b0df2018-12-11 19:00:28 +0400604 salt.cmdRun(master, "I@nova:compute ${extra_tgt}", 'exec 0>&-; exec 1>&-; exec 2>&-; nohup bash -c "ip link | grep vhost && echo no_reboot || reboot & "', false)
Sergio Lystopadcd5b2772018-02-09 14:37:10 +0200605 }
vrovachev4ff77302017-08-09 20:39:57 +0400606
Jakub Josef61463c72018-02-13 16:10:56 +0100607 sleep(300)
Martin Polreich80fa3182018-10-22 15:16:53 +0200608 salt.enforceStateWithTest([saltId: master, target: "I@opencontrail:compute ${extra_tgt}", state: 'opencontrail.client'])
609 salt.enforceStateWithTest([saltId: master, target: "I@opencontrail:compute ${extra_tgt}", state: 'opencontrail'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100610}
611
612
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300613def installKubernetesInfra(master, extra_tgt = '') {
Jakub Josef432e9d92018-02-06 18:28:37 +0100614 def common = new com.mirantis.mk.Common()
615 common.warningMsg("You calling orchestrate.installKubernetesInfra(). This function is deprecated please use orchestrate.installInfra() directly")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300616 installInfra(master, extra_tgt)
Jakub Josef79ecec32017-02-17 14:36:28 +0100617}
618
619
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300620def installKubernetesControl(master, extra_tgt = '') {
Jakub Josef79ecec32017-02-17 14:36:28 +0100621 def salt = new com.mirantis.mk.Salt()
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400622 def first_target
Victor Ryzhenkineb617412018-08-20 18:54:23 +0400623 salt.fullRefresh(master, "* ${extra_tgt}")
624
625 // Bootstrap all nodes
Martin Polreich80fa3182018-10-22 15:16:53 +0200626 salt.enforceState([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: 'linux'])
627 salt.enforceState([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: 'salt.minion'])
628 salt.enforceState([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: ['openssh', 'ntp']])
Victor Ryzhenkineb617412018-08-20 18:54:23 +0400629
630 // Create and distribute SSL certificates for services using salt state
Martin Polreich80fa3182018-10-22 15:16:53 +0200631 salt.enforceState([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: 'salt.minion.cert'])
Victor Ryzhenkineb617412018-08-20 18:54:23 +0400632
633 // Install docker
Victor Ryzhenkindbb39862019-01-09 18:24:16 +0400634 salt.enforceStateWithTest([saltId: master, target: "I@docker:host ${extra_tgt}", state: 'docker.host'])
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200635
Svimba470b3312018-09-26 11:27:20 +0200636 // If network engine is not opencontrail, run addons state for kubernetes
Stanislav Riazanovbae038c2019-04-16 17:18:12 +0400637 if (!salt.getReturnValues(salt.getPillar(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes:master:network:opencontrail:enabled'))) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200638 salt.enforceState([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: 'kubernetes.master.kube-addons'])
Svimba470b3312018-09-26 11:27:20 +0200639 }
640
Jakub Josef79ecec32017-02-17 14:36:28 +0100641 // Install Kubernetes pool and Calico
Martin Polreich80fa3182018-10-22 15:16:53 +0200642 salt.enforceState([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: 'kubernetes.pool'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100643
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300644 if (salt.testTarget(master, "I@etcd:server:setup ${extra_tgt}")) {
Marek Celoud029391c2017-11-14 10:06:18 +0100645 // Setup etcd server
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400646 first_target = salt.getFirstMinion(master, "I@kubernetes:master ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200647 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'etcd.server.setup'])
Marek Celoud029391c2017-11-14 10:06:18 +0100648 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100649
Victor Ryzhenkinfb5d1b52018-05-22 18:49:26 +0400650 // Run k8s master at *01* to simplify namespaces creation
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400651 first_target = salt.getFirstMinion(master, "I@kubernetes:master ${extra_tgt}")
Victor Ryzhenkinfb5d1b52018-05-22 18:49:26 +0400652
Svimba470b3312018-09-26 11:27:20 +0200653 // If network engine is opencontrail, run master state for kubernetes without kube-addons
654 // The kube-addons state will be called later only in case of opencontrail
Stanislav Riazanovbae038c2019-04-16 17:18:12 +0400655 if (salt.getReturnValues(salt.getPillar(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes:master:network:opencontrail:enabled'))) {
Svimba470b3312018-09-26 11:27:20 +0200656 // Run k8s on first node without master.setup and master.kube-addons
Martin Polreich80fa3182018-10-22 15:16:53 +0200657 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 +0200658 // Run k8s without master.setup and master.kube-addons
Vasyl Saienkod96805b2019-03-05 10:48:34 +0200659 salt.enforceStateWithExclude([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: "kubernetes", excludedStates: "kubernetes.master.setup,kubernetes.master.kube-addons,kubernetes.client"])
Svimba470b3312018-09-26 11:27:20 +0200660 } else {
661 // Run k8s on first node without master.setup and master.kube-addons
Stanislav Riazanovbae038c2019-04-16 17:18:12 +0400662 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 +0200663 // Run k8s without master.setup
Stanislav Riazanovbae038c2019-04-16 17:18:12 +0400664 salt.enforceStateWithExclude([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: "kubernetes", excludedStates: "kubernetes.master.setup,kubernetes.client,kubernetes.control*"])
665 // Run k8s control on first node only
666 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'kubernetes.control'])
Svimba470b3312018-09-26 11:27:20 +0200667 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100668
669 // Run k8s master setup
Martin Polreich80fa3182018-10-22 15:16:53 +0200670 salt.enforceState([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: 'kubernetes.master.setup'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100671
672 // Restart kubelet
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400673 salt.runSaltProcessStep(master, "I@kubernetes:master ${extra_tgt}", 'service.restart', ['kubelet'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100674}
675
676
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300677def installKubernetesCompute(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200678 def salt = new com.mirantis.mk.Salt()
Jakub Josef432e9d92018-02-06 18:28:37 +0100679 salt.fullRefresh(master, "*")
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200680
681 // Bootstrap all nodes
Martin Polreich80fa3182018-10-22 15:16:53 +0200682 salt.enforceState([saltId: master, target: "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", state: 'linux'])
683 salt.enforceState([saltId: master, target: "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", state: 'salt.minion'])
684 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 +0200685
686 // Create and distribute SSL certificates for services using salt state
Martin Polreich80fa3182018-10-22 15:16:53 +0200687 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 +0200688
689 // Install docker
Victor Ryzhenkindbb39862019-01-09 18:24:16 +0400690 salt.enforceStateWithTest([saltId: master, target: "I@docker:host ${extra_tgt}", state: 'docker.host'])
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200691
692 // Install Kubernetes and Calico
Martin Polreich80fa3182018-10-22 15:16:53 +0200693 salt.enforceState([saltId: master, target: "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", state: 'kubernetes.pool'])
Victor Ryzhenkinc8d5f8f2018-09-10 16:55:13 +0400694 salt.runSaltProcessStep(master, "I@kubernetes:pool and not I@kubernetes:master ${extra_tgt}", 'service.restart', ['kubelet'])
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200695}
696
Vasyl Saienko0cf55df2019-03-05 10:51:22 +0200697def installKubernetesClient(master, extra_tgt = '') {
698 def salt = new com.mirantis.mk.Salt()
699
700 // Install kubernetes client
701 salt.enforceStateWithTest([saltId: master, target: "I@kubernetes:client ${extra_tgt}", state: 'kubernetes.client'])
702}
703
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200704
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300705def installDockerSwarm(master, extra_tgt = '') {
Martin Polreich8663a342017-06-30 17:33:08 +0200706 def salt = new com.mirantis.mk.Salt()
Jakub Josef79ecec32017-02-17 14:36:28 +0100707
vrovachev1c4770b2017-07-05 13:25:21 +0400708 //Install and Configure Docker
Martin Polreichc0bb4fd2018-08-06 11:34:43 +0200709 if (salt.testTarget(master, "I@docker:swarm ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200710 salt.enforceState([saltId: master, target: "I@docker:swarm ${extra_tgt}", state: 'docker.host'])
711 salt.enforceState([saltId: master, target: "I@docker:swarm:role:master ${extra_tgt}", state: 'docker.swarm'])
712 salt.enforceState([saltId: master, target: "I@docker:swarm ${extra_tgt}", state: 'salt.minion.grains'])
Martin Polreichc0bb4fd2018-08-06 11:34:43 +0200713 salt.runSaltProcessStep(master, "I@docker:swarm ${extra_tgt}", 'mine.update')
714 salt.runSaltProcessStep(master, "I@docker:swarm ${extra_tgt}", 'saltutil.refresh_modules')
715 sleep(5)
Martin Polreich80fa3182018-10-22 15:16:53 +0200716 salt.enforceState([saltId: master, target: "I@docker:swarm:role:master ${extra_tgt}", state: 'docker.swarm'])
717 salt.enforceStateWithTest([saltId: master, target: "I@docker:swarm:role:manager ${extra_tgt}", state: 'docker.swarm'])
Martin Polreichc0bb4fd2018-08-06 11:34:43 +0200718 sleep(10)
719 salt.cmdRun(master, "I@docker:swarm:role:master ${extra_tgt}", 'docker node ls')
Machi Hoshino87aa39d2018-07-26 20:41:53 +0900720 }
Martin Polreich8663a342017-06-30 17:33:08 +0200721}
722
Svimba470b3312018-09-26 11:27:20 +0200723// Setup addons for kubernetes - For OpenContrail network engine
724// Use after compute nodes are ready, because K8s addons like DNS should be placed on cmp nodes
725def setupKubeAddonForContrail(master, extra_tgt = '') {
726 def salt = new com.mirantis.mk.Salt()
727
728 if (salt.getPillar(master, "I@kubernetes:master ${extra_tgt}", 'kubernetes:master:network:opencontrail:enabled')){
729 // Setup Addons for Kubernetes only in case of OpenContrail is used as neteork engine
Martin Polreich80fa3182018-10-22 15:16:53 +0200730 salt.enforceState([saltId: master, target: "I@kubernetes:master ${extra_tgt}", state: 'kubernetes.master.kube-addons'])
Svimba470b3312018-09-26 11:27:20 +0200731 }
732}
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200733
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300734def installCicd(master, extra_tgt = '') {
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200735 def salt = new com.mirantis.mk.Salt()
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200736 def common = new com.mirantis.mk.Common()
Stanislav Riazanovcfc4ac52019-03-04 17:44:06 +0400737 def gerrit_compound = "I@gerrit:client ${extra_tgt}"
738 def jenkins_compound = "I@jenkins:client ${extra_tgt}"
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200739
740 salt.fullRefresh(master, gerrit_compound)
741 salt.fullRefresh(master, jenkins_compound)
Richard Felkl9d2cd922017-11-03 11:49:32 +0100742
Ivan Berezovskiy3aa91f52018-11-28 18:47:34 +0400743 // Temporary exclude cfg node from docker.client state (PROD-24934)
744 def dockerClientExclude = !salt.getPillar(master, 'I@salt:master', 'docker:client:stack:jenkins').isEmpty() ? 'and not I@salt:master' : ''
Ivan Berezovskiy2d6b3d52018-12-24 18:31:39 +0400745 // Pull images first if any
Stanislav Riazanovcfc4ac52019-03-04 17:44:06 +0400746 def listCIMinions = salt.getMinions(master, "* ${dockerClientExclude} ${extra_tgt}")
Ivan Berezovskiy2d6b3d52018-12-24 18:31:39 +0400747 for (int i = 0; i < listCIMinions.size(); i++) {
748 if (!salt.getReturnValues(salt.getPillar(master, listCIMinions[i], 'docker:client:images')).isEmpty()) {
Stanislav Riazanovcfc4ac52019-03-04 17:44:06 +0400749 salt.enforceStateWithTest([saltId: master, target: listCIMinions[i], state: 'docker.client.images', retries: 2])
Ivan Berezovskiy2d6b3d52018-12-24 18:31:39 +0400750 }
751 }
Stanislav Riazanovcfc4ac52019-03-04 17:44:06 +0400752 salt.enforceStateWithTest([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 +0200753
754 // API timeout in minutes
755 def wait_timeout = 10
756
757 // Gerrit
758 def gerrit_master_url = salt.getPillar(master, gerrit_compound, '_param:gerrit_master_url')
759
760 if(!gerrit_master_url['return'].isEmpty()) {
761 gerrit_master_url = gerrit_master_url['return'][0].values()[0]
762 } else {
763 gerrit_master_url = ''
764 }
765
766 if (gerrit_master_url != '') {
767 common.infoMsg('Gerrit master url "' + gerrit_master_url + '" retrieved at _param:gerrit_master_url')
768 } else {
769
770 common.infoMsg('Gerrit master url could not be retrieved at _param:gerrit_master_url. Falling back to gerrit pillar')
771
772 def gerrit_host
773 def gerrit_http_port
774 def gerrit_http_scheme
Stanislav Riazanovcfc4ac52019-03-04 17:44:06 +0400775 def gerrit_http_prefix
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200776
777 def host_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:host')
778 gerrit_host = salt.getReturnValues(host_pillar)
779
780 def port_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:http_port')
781 gerrit_http_port = salt.getReturnValues(port_pillar)
782
783 def scheme_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:protocol')
784 gerrit_http_scheme = salt.getReturnValues(scheme_pillar)
785
Stanislav Riazanovcfc4ac52019-03-04 17:44:06 +0400786 def prefix_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:url_prefix')
787 gerrit_http_prefix = salt.getReturnValues(prefix_pillar)
788
789 gerrit_master_url = gerrit_http_scheme + '://' + gerrit_host + ':' + gerrit_http_port + gerrit_http_prefix
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200790
791 }
792
793 timeout(wait_timeout) {
794 common.infoMsg('Waiting for Gerrit to come up..')
Dzmitry Stremkouski5440ffa2018-05-31 12:00:02 +0200795 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'
796 salt.cmdRun(master, gerrit_compound, 'timeout ' + (wait_timeout*60+3) + ' /bin/sh -c -- ' + '"' + check_gerrit_cmd + '"')
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200797 }
798
799 // Jenkins
Ivan Berezovskiy5f8e64c2019-05-21 16:18:51 +0400800 def jenkins_master_host = salt.getReturnValues(salt.getPillar(master, jenkins_compound, '_param:jenkins_master_host'))
801 def jenkins_master_port = salt.getReturnValues(salt.getPillar(master, jenkins_compound, '_param:jenkins_master_port'))
802 def jenkins_master_protocol = salt.getReturnValues(salt.getPillar(master, jenkins_compound, '_param:jenkins_master_protocol'))
803 def jenkins_master_url_prefix = salt.getReturnValues(salt.getPillar(master, jenkins_compound, '_param:jenkins_master_url_prefix'))
804 jenkins_master_url = "${jenkins_master_protocol}://${jenkins_master_host}:${jenkins_master_port}${jenkins_master_url_prefix}"
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200805
806 timeout(wait_timeout) {
807 common.infoMsg('Waiting for Jenkins to come up..')
Dzmitry Stremkouski5440ffa2018-05-31 12:00:02 +0200808 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'
809 salt.cmdRun(master, jenkins_compound, 'timeout ' + (wait_timeout*60+3) + ' /bin/sh -c -- ' + '"' + check_jenkins_cmd + '"')
Dzmitry Stremkouskif8a873e2018-05-05 22:15:27 +0200810 }
Richard Felklc1aba9b2018-01-02 09:25:20 +0100811
Martin Polreich80fa3182018-10-22 15:16:53 +0200812 salt.enforceStateWithTest([saltId: master, target: "I@openldap:client ${extra_tgt}", state: 'openldap', retries: 2])
Richard Felklb6fdec92017-09-26 10:52:36 +0200813
Denis Egorenkoc6df9fc2020-01-15 17:59:34 +0400814 salt.enforceStateWithTest([saltId: master, target: "( I@keycloak:server or I@keycloak:proxy ) ${extra_tgt}", state: 'keycloak', retries: 2])
815
Martin Polreich80fa3182018-10-22 15:16:53 +0200816 salt.enforceStateWithTest([saltId: master, target: "I@python:environment ${extra_tgt}", state: 'python'])
Richard Felklc1aba9b2018-01-02 09:25:20 +0100817
Ivan Berezovskiy45cb6c02020-04-01 16:30:29 +0400818 // Workaround for PROD-35056: jeepyb package may trigger update of requests and urllib3 packages
819 // which are actively used by salt-minion, so salt-minion has to be restart to apply changes
820 salt.upgradePackageAndRestartSaltMinion(master, jenkins_compound, 'python-requests')
821 salt.upgradePackageAndRestartSaltMinion(master, jenkins_compound, 'python-urllib3')
822 withEnv(['ASK_ON_ERROR=false']) {
823 retry(2) {
824 try {
825 salt.enforceStateWithTest([saltId: master, target: gerrit_compound, state: 'gerrit'])
826 } catch (e) {
827 salt.restartSaltMinion(master, gerrit_compound)
828 salt.fullRefresh(master, gerrit_compound)
Richard Felkl6e208fc2017-12-08 10:18:44 +0100829 throw e //rethrow for retry handler
830 }
831 }
Ivan Berezovskiy45cb6c02020-04-01 16:30:29 +0400832 retry(2) {
833 try {
834 salt.enforceStateWithTest([saltId: master, target: jenkins_compound, state: 'jenkins'])
835 } catch (e) {
836 salt.restartSaltMinion(master, jenkins_compound)
837 salt.fullRefresh(master, jenkins_compound)
Richard Felkl6e208fc2017-12-08 10:18:44 +0100838 throw e //rethrow for retry handler
839 }
840 }
841 }
Jiri Broulikb9a0c592017-09-05 16:41:48 +0200842}
843
844
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300845def installStacklight(master, extra_tgt = '') {
Martin Polreich8663a342017-06-30 17:33:08 +0200846 def common = new com.mirantis.mk.Common()
847 def salt = new com.mirantis.mk.Salt()
Martin Polreich331f2b62019-02-08 10:16:52 +0100848 def step_retries_wait = 20
849 def step_retries = 15
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400850 def first_target
Martin Polreich8663a342017-06-30 17:33:08 +0200851
Simon Pasquieref4122c2017-08-25 15:52:07 +0200852 // Install core services for K8S environments:
azvyagintsev833b4772018-11-21 22:30:59 +0200853 // HAProxy, Nginx and glusterFS clients.
854 // glusterFS clients must be first one, since nginx should store certs on it.
Simon Pasquieref4122c2017-08-25 15:52:07 +0200855 // In case of OpenStack, those are already installed
Martin Polreich792f2662017-07-11 13:36:32 +0200856 if (common.checkContains('STACK_INSTALL', 'k8s')) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200857 salt.enforceStateWithTest([saltId: master, target: "I@glusterfs:client ${extra_tgt}", state: 'glusterfs.client', retries: 2])
Martin Polreich331f2b62019-02-08 10:16:52 +0100858 salt.enforceState([saltId: master, target: "I@nginx:server ${extra_tgt}", state: 'salt.minion.cert', retries: 3])
azvyagintsev833b4772018-11-21 22:30:59 +0200859
Martin Polreich80fa3182018-10-22 15:16:53 +0200860 salt.enforceState([saltId: master, target: "I@haproxy:proxy ${extra_tgt}", state: 'haproxy'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300861 salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.status', ['haproxy'])
Simon Pasquieref4122c2017-08-25 15:52:07 +0200862
Martin Polreich80fa3182018-10-22 15:16:53 +0200863 salt.enforceStateWithTest([saltId: master, target: "I@nginx:server ${extra_tgt}", state: 'nginx'])
Martin Polreich792f2662017-07-11 13:36:32 +0200864 }
Jiri Broulike57a0242017-10-06 13:38:47 +0200865
Dmitry Kalashnik69ecb782018-05-21 17:36:50 +0400866 // Install MongoDB for Alerta
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300867 if (salt.testTarget(master, "I@mongodb:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200868 salt.enforceState([saltId: master, target: "I@mongodb:server ${extra_tgt}", state: 'mongodb.server'])
Ildar Svetlov829f94a2018-06-05 17:57:08 +0400869
870 // Initialize mongodb replica set
Martin Polreich331f2b62019-02-08 10:16:52 +0100871 salt.enforceState([saltId: master, target: "I@mongodb:server ${extra_tgt}", state: 'mongodb.cluster', retries: 5, retries_wait: 20])
Dmitry Kalashnik69ecb782018-05-21 17:36:50 +0400872 }
873
Martin Polreich8663a342017-06-30 17:33:08 +0200874 //Install Telegraf
Martin Polreich80fa3182018-10-22 15:16:53 +0200875 salt.enforceState([saltId: master, target: "( I@telegraf:agent or I@telegraf:remote_agent ) ${extra_tgt}", state: 'telegraf'])
Martin Polreich8663a342017-06-30 17:33:08 +0200876
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400877 // Install Prometheus exporters
Martin Polreich80fa3182018-10-22 15:16:53 +0200878 salt.enforceStateWithTest([saltId: master, target: "I@prometheus:exporters ${extra_tgt}", state: 'prometheus'])
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400879
Martin Polreich8663a342017-06-30 17:33:08 +0200880 //Install Elasticsearch and Kibana
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400881 if (salt.testTarget(master, "I@elasticsearch:server:enabled:true ${extra_tgt}")) {
882 first_target = salt.getFirstMinion(master, "I@elasticsearch:server:enabled:true ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200883 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'elasticsearch.server'])
Ramon Meleroae6e16a2018-08-07 13:42:16 -0500884 }
Martin Polreich80fa3182018-10-22 15:16:53 +0200885 salt.enforceStateWithTest([saltId: master, target: "I@elasticsearch:server:enabled:true ${extra_tgt}", state: 'elasticsearch.server'])
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400886 if (salt.testTarget(master, "I@kibana:server:enabled:true ${extra_tgt}")) {
887 first_target = salt.getFirstMinion(master, "I@kibana:server:enabled:true ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200888 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'kibana.server'])
Ramon Meleroae6e16a2018-08-07 13:42:16 -0500889 }
Martin Polreich80fa3182018-10-22 15:16:53 +0200890 salt.enforceStateWithTest([saltId: master, target: "I@kibana:server:enabled:true ${extra_tgt}", state: 'kibana.server'])
Martin Polreich675dc942018-08-15 09:37:32 +0200891
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200892 // Check ES health cluster status
Dmitry Kalashnik73e43a42019-05-27 15:44:17 +0400893 def pillar = salt.getReturnValues(salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:host'))
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200894 def elasticsearch_vip
Dmitry Kalashnikb34cb7c2019-05-27 16:38:03 +0400895 if(pillar) {
Dmitry Kalashnik73e43a42019-05-27 15:44:17 +0400896 elasticsearch_vip = pillar
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200897 } else {
898 common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved')
899 }
Dmitry Kalashnik73e43a42019-05-27 15:44:17 +0400900
901 pillar = salt.getReturnValues(salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:port'))
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200902 def elasticsearch_port
Dmitry Kalashnikb34cb7c2019-05-27 16:38:03 +0400903 if(pillar) {
Dmitry Kalashnik73e43a42019-05-27 15:44:17 +0400904 elasticsearch_port = pillar
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200905 } else {
906 common.errorMsg('[ERROR] Elasticsearch VIP port could not be retrieved')
907 }
Dmitry Kalashnik73e43a42019-05-27 15:44:17 +0400908
909 pillar = salt.getReturnValues(salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:scheme'))
Dmitry Kalashnik22b03e82019-05-23 10:06:28 +0400910 def elasticsearch_scheme
Dmitry Kalashnikb34cb7c2019-05-27 16:38:03 +0400911 if(pillar) {
Dmitry Kalashnik73e43a42019-05-27 15:44:17 +0400912 elasticsearch_scheme = pillar
913 common.infoMsg("[INFO] Using elasticsearch scheme: ${elasticsearch_scheme}")
Dmitry Kalashnik22b03e82019-05-23 10:06:28 +0400914 } else {
Dmitry Kalashnik73e43a42019-05-27 15:44:17 +0400915 common.infoMsg('[INFO] No pillar with Elasticsearch server scheme, using scheme: http')
Dmitry Kalashnik22b03e82019-05-23 10:06:28 +0400916 elasticsearch_scheme = "http"
917 }
918
Martin Polreich331f2b62019-02-08 10:16:52 +0100919 common.retry(step_retries,step_retries_wait) {
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200920 common.infoMsg('Waiting for Elasticsearch to become green..')
Dmitry Kalashnik22b03e82019-05-23 10:06:28 +0400921 salt.cmdRun(master, "I@elasticsearch:client ${extra_tgt}", "curl -skf ${elasticsearch_scheme}://${elasticsearch_vip}:${elasticsearch_port}/_cat/health | awk '{print \$4}' | grep green")
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200922 }
923
Martin Polreich331f2b62019-02-08 10:16:52 +0100924 salt.enforceState([saltId: master, target: "I@elasticsearch:client ${extra_tgt}", state: 'elasticsearch.client', retries: step_retries, retries_wait: step_retries_wait])
Mateusz Matuszkowiak018a3902018-06-06 11:54:15 +0200925
Martin Polreich331f2b62019-02-08 10:16:52 +0100926 salt.enforceState([saltId: master, target: "I@kibana:client ${extra_tgt}", state: 'kibana.client', retries: step_retries, retries_wait: step_retries_wait])
Dmitry Kalashnik53feda72018-03-16 16:06:10 +0400927
928 //Install InfluxDB
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300929 if (salt.testTarget(master, "I@influxdb:server ${extra_tgt}")) {
Dmitry Ukov8d50e182018-08-27 17:25:34 +0400930 first_target = salt.getFirstMinion(master, "I@influxdb:server ${extra_tgt}")
Martin Polreich80fa3182018-10-22 15:16:53 +0200931 salt.enforceState([saltId: master, target: "${first_target} ${extra_tgt}", state: 'influxdb'])
932 salt.enforceState([saltId: master, target: "I@influxdb:server ${extra_tgt}", state: 'influxdb'])
Dmitry Kalashnik53feda72018-03-16 16:06:10 +0400933 }
934
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400935 // Install service for the log collection
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300936 if (salt.testTarget(master, "I@fluentd:agent ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200937 salt.enforceState([saltId: master, target: "I@fluentd:agent ${extra_tgt}", state: 'fluentd'])
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400938 } else {
Martin Polreich80fa3182018-10-22 15:16:53 +0200939 salt.enforceState([saltId: master, target: "I@heka:log_collector ${extra_tgt}", state: 'heka.log_collector'])
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400940 }
Simon Pasquier6301ddd2017-09-05 11:56:58 +0200941
Ondrej Smola5908ae62018-01-08 13:42:08 +0100942 // Install heka ceilometer collector
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300943 if (salt.testTarget(master, "I@heka:ceilometer_collector:enabled ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200944 salt.enforceState([saltId: master, target: "I@heka:ceilometer_collector:enabled ${extra_tgt}", state: 'heka.ceilometer_collector'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300945 salt.runSaltProcessStep(master, "I@heka:ceilometer_collector:enabled ${extra_tgt}", 'service.restart', ['ceilometer_collector'], null, true)
Ondrej Smola5908ae62018-01-08 13:42:08 +0100946 }
947
Martin Polreich470925a2017-07-06 17:12:59 +0200948 // Install galera
Martin Polreich792f2662017-07-11 13:36:32 +0200949 if (common.checkContains('STACK_INSTALL', 'k8s')) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200950 salt.enforceState([saltId: master, target: "I@galera:master ${extra_tgt}", state: 'galera', retries: 2])
951 salt.enforceState([saltId: master, target: "I@galera:slave ${extra_tgt}", state: 'galera', retries: 2])
Martin Polreich406f6462017-07-11 11:33:42 +0000952
Martin Polreich792f2662017-07-11 13:36:32 +0200953 // Check galera status
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300954 salt.runSaltProcessStep(master, "I@galera:master ${extra_tgt}", 'mysql.status')
955 salt.runSaltProcessStep(master, "I@galera:slave ${extra_tgt}", 'mysql.status')
Martin Polreich792f2662017-07-11 13:36:32 +0200956 }
Martin Polreich470925a2017-07-06 17:12:59 +0200957
Martin Polreich8663a342017-06-30 17:33:08 +0200958 //Collect Grains
Martin Polreich80fa3182018-10-22 15:16:53 +0200959 salt.enforceState([saltId: master, target: "I@salt:minion ${extra_tgt}", state: 'salt.minion.grains'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +0300960 salt.runSaltProcessStep(master, "I@salt:minion ${extra_tgt}", 'saltutil.refresh_modules')
961 salt.runSaltProcessStep(master, "I@salt:minion ${extra_tgt}", 'mine.update')
Martin Polreich8663a342017-06-30 17:33:08 +0200962 sleep(5)
963
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400964 // Configure Prometheus in Docker Swarm
Martin Polreich80fa3182018-10-22 15:16:53 +0200965 salt.enforceState([saltId: master, target: "I@docker:swarm and I@prometheus:server ${extra_tgt}", state: 'prometheus'])
Ildar Svetlov794f89e2018-02-14 16:28:53 +0400966
Ildar Svetlov0eec97d2018-02-15 10:06:40 +0400967 //Configure Remote Collector in Docker Swarm for Openstack deployments
Dmitry Kalashnikb7f023a2019-05-27 20:01:37 +0400968 if (salt.testTarget(master, "I@heka:remote_collector ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +0200969 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 +0200970 }
Martin Polreich8663a342017-06-30 17:33:08 +0200971
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400972 // Launch containers
Ivan Berezovskiye59448c2018-12-25 18:47:29 +0400973 // Pull images first if any
974 def listMinions = salt.getMinions(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}")
975 for (int i = 0; i < listMinions.size(); i++) {
976 if (!salt.getReturnValues(salt.getPillar(master, listMinions[i], 'docker:client:images')).isEmpty()) {
977 salt.enforceState([saltId: master, target: listMinions[i], state: 'docker.client.images', retries: 2])
978 }
979 }
Martin Polreich80fa3182018-10-22 15:16:53 +0200980 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 +0300981 salt.runSaltProcessStep(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}", 'dockerng.ps')
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400982
983 //Install Prometheus LTS
Martin Polreich80fa3182018-10-22 15:16:53 +0200984 salt.enforceStateWithTest([saltId: master, target: "I@prometheus:relay ${extra_tgt}", state: 'prometheus'])
Ildar Svetlov225fb6c2018-06-06 14:59:31 +0400985
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100986 // Install sphinx server
Martin Polreich80fa3182018-10-22 15:16:53 +0200987 salt.enforceStateWithTest([saltId: master, target: "I@sphinx:server ${extra_tgt}", state: 'sphinx'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +0100988
Martin Polreich8663a342017-06-30 17:33:08 +0200989 //Configure Grafana
Denis Egorenko8006cce2019-08-26 13:16:23 +0400990 pillar = salt.getPillar(master, "I@keystone:server:role:primary ${extra_tgt}", '_param:stacklight_monitor_address')
Martin Polreich8663a342017-06-30 17:33:08 +0200991 common.prettyPrint(pillar)
Martin Polreich595baef2017-07-04 16:11:04 +0200992
Martin Polreich8663a342017-06-30 17:33:08 +0200993 def stacklight_vip
994 if(!pillar['return'].isEmpty()) {
995 stacklight_vip = pillar['return'][0].values()[0]
996 } else {
997 common.errorMsg('[ERROR] Stacklight VIP address could not be retrieved')
998 }
vrovachev1c4770b2017-07-05 13:25:21 +0400999
Martin Polreich305e2222017-07-06 11:33:00 +02001000 common.infoMsg("Waiting for service on http://${stacklight_vip}:15013/ to start")
Martin Polreichbd7ad222017-07-06 12:53:51 +02001001 sleep(120)
Mateusz Matuszkowiak0a6f9b52019-05-07 11:23:52 +02001002
1003 salt.enforceState([saltId: master, target: "I@grafana:client ${extra_tgt}", state: 'grafana.client', retries: step_retries, retries_wait: step_retries_wait])
Martin Polreich8663a342017-06-30 17:33:08 +02001004}
1005
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001006def installStacklightv1Control(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +02001007 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +02001008
1009 // infra install
1010 // Install the StackLight backends
Martin Polreich80fa3182018-10-22 15:16:53 +02001011 salt.enforceState([saltId: master, target: "*01* and I@elasticsearch:server ${extra_tgt}", state: 'elasticsearch.server'])
1012 salt.enforceState([saltId: master, target: "I@elasticsearch:server ${extra_tgt}", state: 'elasticsearch.server'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001013
Martin Polreich80fa3182018-10-22 15:16:53 +02001014 salt.enforceState([saltId: master, target: "*01* and I@influxdb:server ${extra_tgt}", state: 'influxdb'])
1015 salt.enforceState([saltId: master, target: "I@influxdb:server ${extra_tgt}", state: 'influxdb'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001016
Martin Polreich80fa3182018-10-22 15:16:53 +02001017 salt.enforceState([saltId: master, target: "*01* and I@kibana:server ${extra_tgt}", state: 'kibana.server'])
1018 salt.enforceState([saltId: master, target: "I@kibana:server ${extra_tgt}", state: 'kibana.server'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001019
Martin Polreich80fa3182018-10-22 15:16:53 +02001020 salt.enforceState([saltId: master, target: "*01* and I@grafana:server ${extra_tgt}",state: 'grafana.server'])
1021 salt.enforceState([saltId: master, target: "I@grafana:server ${extra_tgt}", state: 'grafana.server'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001022
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001023 def alarming_service_pillar = salt.getPillar(master, "mon*01* ${extra_tgt}", '_param:alarming_service')
Kalynovskyi3e370112017-06-26 12:48:23 +03001024 def alarming_service = alarming_service_pillar['return'][0].values()[0]
1025
1026 switch (alarming_service) {
1027 case 'sensu':
1028 // Update Sensu
Martin Polreich80fa3182018-10-22 15:16:53 +02001029 salt.enforceState([saltId: master, target: "I@sensu:server and I@rabbitmq:server ${extra_tgt}", state: 'rabbitmq'])
1030 salt.enforceState([saltId: master, target: "I@redis:cluster:role:master ${extra_tgt}", state: 'redis'])
1031 salt.enforceState([saltId: master, target: "I@redis:server ${extra_tgt}", state: 'redis'])
1032 salt.enforceState([saltId: master, target: "I@sensu:server ${extra_tgt}", state: 'sensu'])
Kalynovskyi3e370112017-06-26 12:48:23 +03001033 default:
1034 // Update Nagios
Martin Polreich80fa3182018-10-22 15:16:53 +02001035 salt.enforceState([saltId: master, target: "I@nagios:server ${extra_tgt}", state: 'nagios.server'])
Kalynovskyi3e370112017-06-26 12:48:23 +03001036 // Stop the Nagios service because the package starts it by default and it will
1037 // started later only on the node holding the VIP address
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001038 salt.runSaltProcessStep(master, "I@nagios:server ${extra_tgt}", 'service.stop', ['nagios3'], null, true)
Kalynovskyi3e370112017-06-26 12:48:23 +03001039 }
1040
Martin Polreich80fa3182018-10-22 15:16:53 +02001041 salt.enforceState([saltId: master, target: "I@elasticsearch:client ${extra_tgt}", state: 'elasticsearch.client.service'])
1042 salt.enforceState([saltId: master, target: "I@kibana:client ${extra_tgt}", state: 'kibana.client'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001043
1044 sleep(10)
1045}
1046
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001047def installStacklightv1Client(master, extra_tgt = '') {
Tomáš Kukrála53b5352017-05-04 11:45:53 +02001048 def salt = new com.mirantis.mk.Salt()
1049 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +02001050
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001051 salt.cmdRun(master, "I@elasticsearch:client ${extra_tgt}", 'salt-call state.sls elasticsearch.client')
Martin Polreich80fa3182018-10-22 15:16:53 +02001052 // salt.enforceState([saltId: master, target: "I@elasticsearch:client", state: 'elasticsearch.client", true])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001053 salt.cmdRun(master, "I@kibana:client ${extra_tgt}", 'salt-call state.sls kibana.client')
Martin Polreich80fa3182018-10-22 15:16:53 +02001054 // salt.enforceState([saltId: master, target: "I@kibana:client", state: 'kibana.client", true])
Ales Komarekef2bab62017-04-26 11:48:28 +02001055
1056 // Install collectd, heka and sensu services on the nodes, this will also
1057 // generate the metadata that goes into the grains and eventually into Salt Mine
Martin Polreich80fa3182018-10-22 15:16:53 +02001058 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: 'collectd'])
Denis Meltsaykin214bf402020-05-05 16:07:45 +00001059 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: 'salt.minion', retries: 2])
Martin Polreich80fa3182018-10-22 15:16:53 +02001060 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: 'heka'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001061
1062 // Gather the Grafana metadata as grains
Martin Polreich80fa3182018-10-22 15:16:53 +02001063 salt.enforceState([saltId: master, target: "I@grafana:collector ${extra_tgt}", state: 'grafana.collector'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001064
1065 // Update Salt Mine
Martin Polreich80fa3182018-10-22 15:16:53 +02001066 salt.enforceState([saltId: master, target: "* ${extra_tgt}", state: 'salt.minion.grains'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001067 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'saltutil.refresh_modules')
1068 salt.runSaltProcessStep(master, "* ${extra_tgt}", 'mine.update')
Ales Komarekef2bab62017-04-26 11:48:28 +02001069
1070 sleep(5)
1071
1072 // Update Heka
Martin Polreich80fa3182018-10-22 15:16:53 +02001073 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 +02001074
1075 // Update collectd
Martin Polreich80fa3182018-10-22 15:16:53 +02001076 salt.enforceState([saltId: master, target: "I@collectd:remote_client:enabled:True ${extra_tgt}", state: 'collectd'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001077
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001078 def alarming_service_pillar = salt.getPillar(master, "mon*01* ${extra_tgt}", '_param:alarming_service')
Kalynovskyi3e370112017-06-26 12:48:23 +03001079 def alarming_service = alarming_service_pillar['return'][0].values()[0]
Ales Komarekef2bab62017-04-26 11:48:28 +02001080
Kalynovskyi3e370112017-06-26 12:48:23 +03001081 switch (alarming_service) {
1082 case 'sensu':
1083 // Update Sensu
1084 // TODO for stacklight team, should be fixed in model
Martin Polreich80fa3182018-10-22 15:16:53 +02001085 salt.enforceState([saltId: master, target: "I@sensu:client ${extra_tgt}", state: 'sensu'])
Kalynovskyi3e370112017-06-26 12:48:23 +03001086 default:
1087 break
1088 // Default is nagios, and was enforced in installStacklightControl()
1089 }
Ales Komarekef2bab62017-04-26 11:48:28 +02001090
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001091 salt.cmdRun(master, "I@grafana:client and *01* ${extra_tgt}", 'salt-call state.sls grafana.client')
Martin Polreich80fa3182018-10-22 15:16:53 +02001092 // salt.enforceState([saltId: master, target: "I@grafana:client and *01*", state: 'grafana.client"])
Ales Komarekef2bab62017-04-26 11:48:28 +02001093
Marek Celoudd200cad2017-06-07 10:34:46 +02001094 // Finalize the configuration of Grafana (add the dashboards...)
Martin Polreich80fa3182018-10-22 15:16:53 +02001095 salt.enforceState([saltId: master, target: "I@grafana:client and *01* ${extra_tgt}", state: 'grafana.client'])
1096 salt.enforceState([saltId: master, target: "I@grafana:client and *02* ${extra_tgt}", state: 'grafana.client'])
1097 salt.enforceState([saltId: master, target: "I@grafana:client and *03* ${extra_tgt}", state: 'grafana.client'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001098 // nw salt -C "I@grafana:client' --async service.restart salt-minion; sleep 10
Marek Celoudd200cad2017-06-07 10:34:46 +02001099
Ales Komarekef2bab62017-04-26 11:48:28 +02001100 // Get the StackLight monitoring VIP addres
1101 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
1102 //vip=${vip:=172.16.10.253}
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001103 def pillar = salt.getPillar(master, "ctl01* ${extra_tgt}", '_param:stacklight_monitor_address')
Jakub Josefbceaa322017-06-13 18:28:27 +02001104 common.prettyPrint(pillar)
Ales Komarekef2bab62017-04-26 11:48:28 +02001105 def stacklight_vip = pillar['return'][0].values()[0]
1106
1107 if (stacklight_vip) {
1108 // (re)Start manually the services that are bound to the monitoring VIP
1109 common.infoMsg("restart services on node with IP: ${stacklight_vip}")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001110 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['remote_collectd'])
1111 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['remote_collector'])
1112 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['aggregator'])
1113 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['nagios3'])
Ales Komarekef2bab62017-04-26 11:48:28 +02001114 } else {
1115 throw new Exception("Missing stacklight_vip")
1116 }
Tomáš Kukrálf06ca0f2017-02-27 15:18:50 +01001117}
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001118
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001119//
1120// backups
1121//
1122
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001123def installBackup(master, component='common', extra_tgt = '') {
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001124 def salt = new com.mirantis.mk.Salt()
1125 if (component == 'common') {
1126 // Install Backupninja
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001127 if (salt.testTarget(master, "I@backupninja:client ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001128 salt.enforceState([saltId: master, target: "I@backupninja:client ${extra_tgt}", state: 'salt.minion.grains'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001129 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'saltutil.sync_grains')
1130 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'mine.flush')
1131 salt.runSaltProcessStep(master, "I@backupninja:client ${extra_tgt}", 'mine.update')
Martin Polreich80fa3182018-10-22 15:16:53 +02001132 salt.enforceState([saltId: master, target: "I@backupninja:client ${extra_tgt}", state: 'backupninja'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001133 }
Martin Polreich80fa3182018-10-22 15:16:53 +02001134 salt.enforceStateWithTest([saltId: master, target: "I@backupninja:server ${extra_tgt}", state: 'salt.minion.grains'])
1135 salt.enforceStateWithTest([saltId: master, target: "I@backupninja:server ${extra_tgt}", state: 'backupninja'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001136 } else if (component == 'mysql') {
1137 // Install Xtrabackup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001138 if (salt.testTarget(master, "I@xtrabackup:client ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001139 salt.enforceState([saltId: master, target: "I@xtrabackup:client ${extra_tgt}", state: 'salt.minion.grains'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001140 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'saltutil.sync_grains')
1141 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'mine.flush')
1142 salt.runSaltProcessStep(master, "I@xtrabackup:client ${extra_tgt}", 'mine.update')
Martin Polreich80fa3182018-10-22 15:16:53 +02001143 salt.enforceState([saltId: master, target: "I@xtrabackup:client ${extra_tgt}", state: 'xtrabackup'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001144 }
Martin Polreich80fa3182018-10-22 15:16:53 +02001145 salt.enforceStateWithTest([saltId: master, target: "I@xtrabackup:server ${extra_tgt}", state: 'xtrabackup'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001146 } else if (component == 'contrail') {
1147
1148 // Install Cassandra backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001149 if (salt.testTarget(master, "I@cassandra:backup:client ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001150 salt.enforceState([saltId: master, target: "I@cassandra:backup:client ${extra_tgt}", state: 'salt.minion.grains'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001151 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1152 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'mine.flush')
1153 salt.runSaltProcessStep(master, "I@cassandra:backup:client ${extra_tgt}", 'mine.update')
Martin Polreich80fa3182018-10-22 15:16:53 +02001154 salt.enforceState([saltId: master, target: "I@cassandra:backup:client ${extra_tgt}", state: 'cassandra.backup'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001155 }
Martin Polreich80fa3182018-10-22 15:16:53 +02001156 salt.enforceStateWithTest([saltId: master, target: "I@cassandra:backup:server ${extra_tgt}", state: 'cassandra.backup'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001157 // Install Zookeeper backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001158 if (salt.testTarget(master, "I@zookeeper:backup:client ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001159 salt.enforceState([saltId: master, target: "I@zookeeper:backup:client ${extra_tgt}", state: 'salt.minion.grains'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001160 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1161 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'mine.flush')
1162 salt.runSaltProcessStep(master, "I@zookeeper:backup:client ${extra_tgt}", 'mine.update')
Martin Polreich80fa3182018-10-22 15:16:53 +02001163 salt.enforceState([saltId: master, target: "I@zookeeper:backup:client ${extra_tgt}", state: 'zookeeper.backup'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001164 }
Martin Polreich80fa3182018-10-22 15:16:53 +02001165 salt.enforceStateWithTest([saltId: master, target: "I@zookeeper:backup:server ${extra_tgt}", state: 'zookeeper.backup'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001166 } else if (component == 'ceph') {
1167 // Install Ceph backup
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001168 if (salt.testTarget(master, "I@ceph:backup:client ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001169 salt.enforceState([saltId: master, target: "I@ceph:backup:client ${extra_tgt}", state: 'salt.minion.grains'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001170 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'saltutil.sync_grains')
1171 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'mine.flush')
1172 salt.runSaltProcessStep(master, "I@ceph:backup:client ${extra_tgt}", 'mine.update')
Martin Polreich80fa3182018-10-22 15:16:53 +02001173 salt.enforceState([saltId: master, target: "I@ceph:backup:client ${extra_tgt}", state: 'ceph.backup'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001174 }
Martin Polreich80fa3182018-10-22 15:16:53 +02001175 salt.enforceStateWithTest([saltId: master, target: "I@ceph:backup:server ${extra_tgt}", state: 'ceph.backup'])
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001176 }
1177
1178}
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001179
1180//
1181// Ceph
1182//
1183
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001184def installCephMon(master, target="I@ceph:mon", extra_tgt = '') {
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001185 def salt = new com.mirantis.mk.Salt()
1186
Martin Polreich80fa3182018-10-22 15:16:53 +02001187 salt.enforceState([saltId: master, target: "I@ceph:common ${extra_tgt}", state: 'salt.minion.grains'])
Jiri Broulikbfc234f2017-10-17 15:45:38 +02001188
Jiri Broulike57a0242017-10-06 13:38:47 +02001189 // generate keyrings
Martin Polreich44331002018-08-13 11:27:06 +02001190 if (salt.testTarget(master, "( I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin ) ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001191 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 +03001192 salt.runSaltProcessStep(master, "I@ceph:mon ${extra_tgt}", 'saltutil.sync_grains')
Martin Polreich44331002018-08-13 11:27:06 +02001193 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 +02001194
1195 // on target nodes mine is used to get pillar from 'ceph:common:keyring:admin' via grain.items
1196 // we need to refresh all pillar/grains to make data sharing work correctly
1197 salt.fullRefresh(master, "( I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin ) ${extra_tgt}")
1198
Jiri Broulik3c75a6d2017-10-06 18:44:37 +02001199 sleep(5)
Jiri Broulike57a0242017-10-06 13:38:47 +02001200 }
Ondrej Smolafd5c2352017-08-11 14:25:39 +02001201 // install Ceph Mons
Martin Polreich80fa3182018-10-22 15:16:53 +02001202 salt.enforceState([saltId: master, target: target, state: 'ceph.mon'])
1203 salt.enforceStateWithTest([saltId: master, target: "I@ceph:mgr ${extra_tgt}", state: 'ceph.mgr'])
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001204}
1205
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001206def installCephOsd(master, target="I@ceph:osd", setup=true, extra_tgt = '') {
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001207 def salt = new com.mirantis.mk.Salt()
1208
1209 // install Ceph OSDs
Martin Polreich80fa3182018-10-22 15:16:53 +02001210 salt.enforceState([saltId: master, target: target, state: 'ceph.osd'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001211 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'saltutil.sync_grains')
Martin Polreich80fa3182018-10-22 15:16:53 +02001212 salt.enforceState([saltId: master, target: target, state: 'ceph.osd.custom'])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001213 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'saltutil.sync_grains')
1214 salt.runSaltProcessStep(master, "I@ceph:osd ${extra_tgt}", 'mine.update')
Jiri Broulike3e7bc32018-02-26 10:50:07 +01001215 installBackup(master, 'ceph')
Tomáš Kukráled27a472017-08-29 10:26:25 +02001216
Jiri Broulike57a0242017-10-06 13:38:47 +02001217 // setup pools, keyrings and maybe crush
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001218 if (salt.testTarget(master, "I@ceph:setup ${extra_tgt}") && setup) {
Jiri Broulik07f8de72017-10-09 14:12:17 +02001219 sleep(5)
Martin Polreich80fa3182018-10-22 15:16:53 +02001220 salt.enforceState([saltId: master, target: "I@ceph:setup ${extra_tgt}", state: 'ceph.setup'])
Tomáš Kukráled27a472017-08-29 10:26:25 +02001221 }
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +02001222}
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001223
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001224def installCephClient(master, extra_tgt = '') {
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +02001225 def salt = new com.mirantis.mk.Salt()
1226
1227 // install Ceph Radosgw
Mykyta Karpinf7a714c2018-11-06 14:22:36 +02001228 if (salt.testTarget(master, "I@ceph:radosgw ${extra_tgt}")) {
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001229 salt.runSaltProcessStep(master, "I@ceph:radosgw ${extra_tgt}", 'saltutil.sync_grains')
Martin Polreich80fa3182018-10-22 15:16:53 +02001230 salt.enforceState([saltId: master, target: "I@ceph:radosgw ${extra_tgt}", state: 'ceph.radosgw'])
Alexander Noskov229035f2017-12-06 00:10:20 +04001231 }
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001232
1233 // setup keyring for Openstack services
Martin Polreich80fa3182018-10-22 15:16:53 +02001234 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 +03001235
Martin Polreich80fa3182018-10-22 15:16:53 +02001236 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 +03001237
1238 if (salt.testTarget(master, "I@ceph:common and I@nova:compute ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001239 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 +03001240 salt.runSaltProcessStep(master, "I@ceph:common and I@nova:compute ${extra_tgt}", 'saltutil.sync_grains')
1241 }
1242
Martin Polreich80fa3182018-10-22 15:16:53 +02001243 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 +02001244}
Jiri Broulike57a0242017-10-06 13:38:47 +02001245
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001246def connectCeph(master, extra_tgt = '') {
Jiri Broulike57a0242017-10-06 13:38:47 +02001247 def salt = new com.mirantis.mk.Salt()
1248
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001249 // setup Keystone service and endpoints for swift or / and S3
Martin Polreich80fa3182018-10-22 15:16:53 +02001250 salt.enforceStateWithTest([saltId: master, target: "I@keystone:client ${extra_tgt}", state: 'keystone.client'])
Mykyta Karpin9b8beab2018-09-11 17:52:35 +03001251
Jiri Broulike57a0242017-10-06 13:38:47 +02001252 // connect Ceph to the env
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001253 if (salt.testTarget(master, "I@ceph:common and I@glance:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001254 salt.enforceState([saltId: master, target: "I@ceph:common and I@glance:server ${extra_tgt}", state: ['glance']])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001255 salt.runSaltProcessStep(master, "I@ceph:common and I@glance:server ${extra_tgt}", 'service.restart', ['glance-api'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001256 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001257 if (salt.testTarget(master, "I@ceph:common and I@cinder:controller ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001258 salt.enforceState([saltId: master, target: "I@ceph:common and I@cinder:controller ${extra_tgt}", state: ['cinder']])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001259 salt.runSaltProcessStep(master, "I@ceph:common and I@cinder:controller ${extra_tgt}", 'service.restart', ['cinder-volume'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001260 }
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001261 if (salt.testTarget(master, "I@ceph:common and I@nova:compute ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001262 salt.enforceState([saltId: master, target: "I@ceph:common and I@nova:compute ${extra_tgt}", state: ['nova']])
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001263 salt.runSaltProcessStep(master, "I@ceph:common and I@nova:compute ${extra_tgt}", 'service.restart', ['nova-compute'])
Jiri Broulike57a0242017-10-06 13:38:47 +02001264 }
Mykyta Karpin0dec8b32018-09-19 09:37:45 +03001265 if (salt.testTarget(master, "I@ceph:common and I@gnocchi:server ${extra_tgt}")) {
Martin Polreich80fa3182018-10-22 15:16:53 +02001266 salt.enforceState([saltId: master, target: "I@ceph:common and I@gnocchi:server:role:primary ${extra_tgt}", state: 'gnocchi.server'])
1267 salt.enforceState([saltId: master, target: "I@ceph:common and I@gnocchi:server ${extra_tgt}", state: 'gnocchi.server'])
Mykyta Karpin0dec8b32018-09-19 09:37:45 +03001268 }
Jiri Broulike57a0242017-10-06 13:38:47 +02001269}
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001270
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001271def installOssInfra(master, extra_tgt = '') {
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001272 def common = new com.mirantis.mk.Common()
1273 def salt = new com.mirantis.mk.Salt()
1274
Martin Polreich80fa3182018-10-22 15:16:53 +02001275 salt.enforceStateWithTest([saltId: master, target: "I@devops_portal:config ${extra_tgt}", state: 'devops_portal.config'])
1276 salt.enforceStateWithTest([saltId: master, target: "I@rundeck:client ${extra_tgt}", state: ['linux.system.user', 'openssh'], testTargetMatcher: "I@devops_portal:config ${extra_tgt}"])
1277 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 +04001278}
1279
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001280def installOss(master, extra_tgt = '') {
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001281 def common = new com.mirantis.mk.Common()
1282 def salt = new com.mirantis.mk.Salt()
1283
1284 //Get oss VIP address
Denis Egorenko8006cce2019-08-26 13:16:23 +04001285 def pillar = salt.getPillar(master, "I@salt:master ${extra_tgt}", '_param:stacklight_monitor_address')
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001286 common.prettyPrint(pillar)
1287
1288 def oss_vip
1289 if(!pillar['return'].isEmpty()) {
1290 oss_vip = pillar['return'][0].values()[0]
1291 } else {
1292 common.errorMsg('[ERROR] Oss VIP address could not be retrieved')
1293 }
1294
1295 // Postgres client - initialize OSS services databases
1296 timeout(120){
1297 common.infoMsg("Waiting for postgresql database to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001298 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 +04001299 }
1300 // XXX: first run usually fails on some inserts, but we need to create databases at first
Martin Polreich80fa3182018-10-22 15:16:53 +02001301 salt.enforceState([saltId: master, target: "I@postgresql:client ${extra_tgt}", state: 'postgresql.client', failOnError: false])
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001302
1303 // Setup postgres database with integration between
1304 // Pushkin notification service and Security Monkey security audit service
1305 timeout(10) {
1306 common.infoMsg("Waiting for Pushkin to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001307 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 +04001308 }
Martin Polreich80fa3182018-10-22 15:16:53 +02001309 salt.enforceState([saltId: master, target: "I@postgresql:client ${extra_tgt}", state: 'postgresql.client'])
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001310
1311 // Rundeck
1312 timeout(10) {
1313 common.infoMsg("Waiting for Rundeck to come up..")
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001314 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 +04001315 }
Martin Polreich80fa3182018-10-22 15:16:53 +02001316 salt.enforceState([saltId: master, target: "I@rundeck:client ${extra_tgt}", state: 'rundeck.client'])
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001317
1318 // Elasticsearch
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001319 pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:host')
Mikhail Ivanovfcd55d62017-12-19 16:51:35 +04001320 def elasticsearch_vip
1321 if(!pillar['return'].isEmpty()) {
1322 elasticsearch_vip = pillar['return'][0].values()[0]
1323 } else {
1324 common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved')
1325 }
1326
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001327 timeout(10) {
1328 common.infoMsg('Waiting for Elasticsearch to come up..')
Oleh Hryhorov5f96e092018-06-22 18:37:08 +03001329 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 +04001330 }
Martin Polreich80fa3182018-10-22 15:16:53 +02001331 salt.enforceState([saltId: master, target: "I@elasticsearch:client ${extra_tgt}", state: 'elasticsearch.client'])
Mikhail Ivanov5312d1f2017-12-06 17:36:36 +04001332}
Oleksii Grudev9e1d97a2018-06-29 16:04:30 +03001333
1334/**
1335 * Function receives connection string, target and configuration yaml pattern
1336 * and retrieves config fom salt minion according to pattern. After that it
1337 * sorts applications according to priorities and runs orchestration states
1338 * @param master Salt Connection object or pepperEnv
1339 * @param tgt Target
1340 * @param conf Configuration pattern
1341 */
1342def OrchestrateApplications(master, tgt, conf) {
1343 def salt = new com.mirantis.mk.Salt()
1344 def common = new com.mirantis.mk.Common()
1345 def _orch = salt.getConfig(master, tgt, conf)
1346 if ( !_orch['return'][0].values()[0].isEmpty() ) {
1347 Map<String,Integer> _orch_app = [:]
1348 for (k in _orch['return'][0].values()[0].keySet()) {
1349 _orch_app[k] = _orch['return'][0].values()[0][k].values()[0].toInteger()
1350 }
1351 def _orch_app_sorted = common.SortMapByValueAsc(_orch_app)
1352 common.infoMsg("Applications will be deployed in following order:"+_orch_app_sorted.keySet())
1353 for (app in _orch_app_sorted.keySet()) {
1354 salt.orchestrateSystem(master, ['expression': tgt, 'type': 'compound'], "${app}.orchestrate.deploy")
1355 }
1356 }
1357 else {
1358 common.infoMsg("No applications found for orchestration")
1359 }
Inessa Vasilevskaya85ad1a92018-10-08 12:19:47 +02001360}