blob: b81ef978895596f4243cc42bc6eebbe11bac5efd [file] [log] [blame]
vitalygusev22701372018-09-25 17:27:35 +04001/**
2 *
3 * Upgrade Stacklight packages and components
4 *
5 * Requred parameters:
6 * SALT_MASTER_URL URL of Salt master
7 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
8 *
9 * STAGE_UPGRADE_SYSTEM_PART Set to True if upgrade of system part (telegraf, fluentd, prometheus-relay) is desired
10 * STAGE_UPGRADE_ES_KIBANA Set to True if Elasticsearch and Kibana upgrade is desired
11 * STAGE_UPGRADE_DOCKER_COMPONENTS Set to True if upgrade for components running in Docker Swarm is desired
12 *
13 */
14
vitalygusev4b331fa2018-12-04 19:03:47 +040015common = new com.mirantis.mk.Common()
16salt = new com.mirantis.mk.Salt()
17python = new com.mirantis.mk.Python()
18command = 'cmd.run'
19pepperEnv = "pepperEnv"
20errorOccured = false
vitalygusev22701372018-09-25 17:27:35 +040021
22def upgrade(master, target, service, pckg, state) {
vitalygusev4b331fa2018-12-04 19:03:47 +040023 stage("Upgrade ${service}") {
vitalygusev25872e12018-12-14 18:45:29 +040024 salt.runSaltProcessStep(master, "${target}", 'saltutil.refresh_pillar', [], null, true)
vitalygusev00826aa2018-12-24 13:44:47 +040025 salt.enforceState([saltId: master, target: "${target}", state: 'linux.system.repo', output: true, failOnError: true])
vitalygusev25872e12018-12-14 18:45:29 +040026 common.infoMsg("Upgrade ${service} package(s)")
vitalygusev22701372018-09-25 17:27:35 +040027 try {
vitalygusev25872e12018-12-14 18:45:29 +040028 salt.runSaltProcessStep(master, "${target}", command, ["apt-get install -y -o Dpkg::Options::=\"--force-confold\" ${pckg}"], null, true)
vitalygusev22701372018-09-25 17:27:35 +040029 } catch (Exception er) {
30 errorOccured = true
vitalygusev25872e12018-12-14 18:45:29 +040031 common.errorMsg("[ERROR] ${pckg} package(s) was not upgraded.")
32 throw er
vitalygusev22701372018-09-25 17:27:35 +040033 }
vitalygusev4b331fa2018-12-04 19:03:47 +040034 common.infoMsg("Run ${state} state on ${target} nodes")
vitalygusev22701372018-09-25 17:27:35 +040035 try {
vitalygusev00826aa2018-12-24 13:44:47 +040036 salt.enforceState([saltId: master, target: "${target}", state: ["${state}"], output: true, failOnError: true])
vitalygusev22701372018-09-25 17:27:35 +040037 } catch (Exception er) {
38 errorOccured = true
vitalygusev4b331fa2018-12-04 19:03:47 +040039 common.errorMsg("[ERROR] ${state} state was executed and failed. Please fix it manually.")
vitalygusev25872e12018-12-14 18:45:29 +040040 throw er
vitalygusev22701372018-09-25 17:27:35 +040041 }
vitalygusev25872e12018-12-14 18:45:29 +040042 common.infoMsg("Check ${service} service(s) status on the target nodes")
43 for (s in service.split(" ")){
44 salt.runSaltProcessStep(master, "${target}", "service.status", "${s}", null, true)
45 }
46 }
47}
48
49def verify_es_is_green(master) {
50 common.infoMsg('Verify that the Elasticsearch cluster status is green')
51 try {
52 def retries_wait = 20
53 def retries = 15
Dmitry Kalashnik066740c2019-05-27 15:47:35 +040054
vitalygusev25872e12018-12-14 18:45:29 +040055 def elasticsearch_vip
Dmitry Kalashnik066740c2019-05-27 15:47:35 +040056 def pillar = salt.getReturnValues(salt.getPillar(master, "I@elasticsearch:client", 'elasticsearch:client:server:host'))
Dmitry Kalashnikaa4dcdc2019-05-27 16:43:04 +040057 if(pillar) {
Dmitry Kalashnik066740c2019-05-27 15:47:35 +040058 elasticsearch_vip = pillar
vitalygusev25872e12018-12-14 18:45:29 +040059 } else {
60 errorOccured = true
61 common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved')
62 }
Dmitry Kalashnik066740c2019-05-27 15:47:35 +040063
64 pillar = salt.getReturnValues(salt.getPillar(master, "I@elasticsearch:client", 'elasticsearch:client:server:port'))
vitalygusev25872e12018-12-14 18:45:29 +040065 def elasticsearch_port
Dmitry Kalashnikaa4dcdc2019-05-27 16:43:04 +040066 if(pillar) {
Dmitry Kalashnik066740c2019-05-27 15:47:35 +040067 elasticsearch_port = pillar
vitalygusev25872e12018-12-14 18:45:29 +040068 } else {
69 errorOccured = true
70 common.errorMsg('[ERROR] Elasticsearch VIP port could not be retrieved')
71 }
Dmitry Kalashnik066740c2019-05-27 15:47:35 +040072
73 pillar = salt.getReturnValues(salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:scheme'))
Dmitry Kalashnikb5763f92019-05-23 10:11:42 +040074 def elasticsearch_scheme
Dmitry Kalashnikaa4dcdc2019-05-27 16:43:04 +040075 if(pillar) {
Dmitry Kalashnik066740c2019-05-27 15:47:35 +040076 elasticsearch_scheme = pillar
77 common.infoMsg("[INFO] Using elasticsearch scheme: ${elasticsearch_scheme}")
Dmitry Kalashnikb5763f92019-05-23 10:11:42 +040078 } else {
Dmitry Kalashnik066740c2019-05-27 15:47:35 +040079 common.infoMsg('[INFO] No pillar with Elasticsearch server scheme, using scheme: http')
Dmitry Kalashnikb5763f92019-05-23 10:11:42 +040080 elasticsearch_scheme = "http"
81 }
82
vitalygusev25872e12018-12-14 18:45:29 +040083 common.retry(retries,retries_wait) {
84 common.infoMsg('Waiting for Elasticsearch to become green..')
Dmitry Kalashnikb5763f92019-05-23 10:11:42 +040085 salt.cmdRun(master, "I@elasticsearch:client", "curl -sfk ${elasticsearch_scheme}://${elasticsearch_vip}:${elasticsearch_port}/_cat/health | awk '{print \$4}' | grep green")
vitalygusev25872e12018-12-14 18:45:29 +040086 }
87 } catch (Exception er) {
88 errorOccured = true
89 common.errorMsg("[ERROR] Elasticsearch cluster status is not \'green\'. Please fix it manually.")
90 throw er
vitalygusev22701372018-09-25 17:27:35 +040091 }
vitalygusev22701372018-09-25 17:27:35 +040092}
93
94def upgrade_es_kibana(master) {
vitalygusev25872e12018-12-14 18:45:29 +040095 def elasticsearch_version
96 def es_pillar = salt.getPillar(master, "I@elasticsearch:client", '_param:elasticsearch_version')
97 if(!es_pillar['return'].isEmpty()) {
98 elasticsearch_version = es_pillar['return'][0].values()[0]
99 }
vitalygusev4b331fa2018-12-04 19:03:47 +0400100 stage('Upgrade elasticsearch') {
vitalygusev25872e12018-12-14 18:45:29 +0400101 if (elasticsearch_version == '5') {
102 try {
103 common.infoMsg('Upgrade the Elasticsearch package')
104 salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["systemctl stop elasticsearch"], null, true)
105 salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["apt-get --only-upgrade install elasticsearch"], null, true)
106 salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["systemctl daemon-reload"], null, true)
107 salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["systemctl start elasticsearch"], null, true)
108 salt.runSaltProcessStep(master, '*', 'saltutil.sync_all', [], null, true)
109 verify_es_is_green(master)
110 } catch (Exception er) {
vitalygusev22701372018-09-25 17:27:35 +0400111 errorOccured = true
vitalygusev25872e12018-12-14 18:45:29 +0400112 common.errorMsg("[ERROR] Elasticsearch upgrade failed. Please fix it manually.")
113 throw er
vitalygusev22701372018-09-25 17:27:35 +0400114 }
vitalygusev25872e12018-12-14 18:45:29 +0400115 } else {
116 try {
117 salt.runSaltProcessStep(master, "*", 'saltutil.refresh_pillar', [], null, true)
vitalygusev00826aa2018-12-24 13:44:47 +0400118 salt.enforceState([saltId: master, target: "I@elasticsearch:server", state: 'linux.system.repo', output: true, failOnError: true])
vitalygusev25872e12018-12-14 18:45:29 +0400119 salt.runSaltProcessStep(master, 'I@elasticsearch:client', command, ["apt-get install -y -o Dpkg::Options::=\"--force-confold\" python-elasticsearch"], null, true)
vitalygusev00826aa2018-12-24 13:44:47 +0400120 salt.enforceState([saltId: master, target: "I@elasticsearch:server", state: 'salt.minion', output: true, failOnError: true])
vitalygusev25872e12018-12-14 18:45:29 +0400121 salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["systemctl stop elasticsearch"], null, true)
122 salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["export ES_PATH_CONF=/etc/elasticsearch; apt-get install -y -o Dpkg::Options::=\"--force-confold\" elasticsearch"], null, true)
vitalygusev00826aa2018-12-24 13:44:47 +0400123 salt.enforceState([saltId: master, target: "I@elasticsearch:server", state: 'elasticsearch.server', output: true, failOnError: true])
vitalygusev25872e12018-12-14 18:45:29 +0400124 verify_es_is_green(master)
vitalygusev00826aa2018-12-24 13:44:47 +0400125 salt.enforceState([saltId: master, target: "I@elasticsearch:client", state: 'elasticsearch.client.update_index_templates', output: true, failOnError: true])
126 salt.enforceState([saltId: master, target: "I@elasticsearch:client", state: 'elasticsearch.client', output: true, failOnError: true])
vitalygusev25872e12018-12-14 18:45:29 +0400127 } catch (Exception er) {
vitalygusev22701372018-09-25 17:27:35 +0400128 errorOccured = true
vitalygusev25872e12018-12-14 18:45:29 +0400129 common.errorMsg("[ERROR] Elasticsearch upgrade failed. Please fix it manually.")
130 throw er
vitalygusev22701372018-09-25 17:27:35 +0400131 }
vitalygusev22701372018-09-25 17:27:35 +0400132 }
133 }
vitalygusev4b331fa2018-12-04 19:03:47 +0400134 stage('Upgrade kibana') {
vitalygusev25872e12018-12-14 18:45:29 +0400135 def kibana_version
136 def kibana_pillar = salt.getPillar(master, "I@kibana:client", '_param:kibana_version')
137 if(!kibana_pillar['return'].isEmpty()) {
138 kibana_version = kibana_pillar['return'][0].values()[0]
139 }
140 if (kibana_version == '5') {
141 try {
142 common.infoMsg('Upgrade the Kibana package')
143 salt.runSaltProcessStep(master, 'I@kibana:server', command, ["systemctl stop kibana"], null, true)
144 salt.runSaltProcessStep(master, 'I@kibana:server', command, ["apt-get --only-upgrade install kibana"], null, true)
145 salt.runSaltProcessStep(master, 'I@kibana:server', command, ["systemctl start kibana"], null, true)
146 } catch (Exception er) {
147 errorOccured = true
148 common.errorMsg("[ERROR] Kibana upgrade failed. Please fix it manually.")
149 throw er
150 }
151 } else {
152 try {
153 salt.runSaltProcessStep(master, 'I@kibana:server', command, ["systemctl stop kibana"], null, true)
vitalygusev00826aa2018-12-24 13:44:47 +0400154 salt.enforceStateWithExclude([saltId: master, target: "I@kibana:server", state: "kibana.server", excludedStates: "[{'id': 'kibana_service'}]"])
vitalygusev25872e12018-12-14 18:45:29 +0400155 salt.runSaltProcessStep(master, 'I@kibana:server', command, ["apt-get install -y -o Dpkg::Options::=\"--force-confold\" kibana"], null, true)
vitalygusev00826aa2018-12-24 13:44:47 +0400156 salt.enforceState([saltId: master, target: "I@kibana:server", state: 'kibana.server', output: true, failOnError: true])
157 salt.enforceState([saltId: master, target: "I@kibana:client", state: 'kibana.client', output: true, failOnError: true])
vitalygusev25872e12018-12-14 18:45:29 +0400158 } catch (Exception er) {
159 errorOccured = true
160 common.errorMsg("[ERROR] Kibana upgrade failed. Please fix it manually.")
161 throw er
162 }
vitalygusev22701372018-09-25 17:27:35 +0400163 }
vitalygusev22701372018-09-25 17:27:35 +0400164
vitalygusev4b331fa2018-12-04 19:03:47 +0400165 common.infoMsg("Check kibana status on the target nodes")
166 salt.runSaltProcessStep(master, "I@kibana:server", "service.status", ["kibana"], null, true)
vitalygusev22701372018-09-25 17:27:35 +0400167 }
168}
169timeout(time: 12, unit: 'HOURS') {
170 node("python") {
171
172 stage('Setup virtualenv for Pepper') {
173 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
174 }
175
vitalygusev00826aa2018-12-24 13:44:47 +0400176 stage('Update grains and mine') {
177 salt.enforceState([saltId: pepperEnv, target: '*', state: 'salt.minion.grains'])
178 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.refresh_modules')
179 salt.runSaltProcessStep(pepperEnv, '*', 'mine.update')
180 sleep(30)
181 }
vitalygusev25872e12018-12-14 18:45:29 +0400182
vitalygusev00826aa2018-12-24 13:44:47 +0400183 if (salt.testTarget(pepperEnv, "I@ceph:mon")) {
184 stage('Enable Ceph prometheus plugin') {
185 salt.enforceState([saltId: pepperEnv, target: 'I@ceph:mon', state: "ceph.mgr", output: true, failOnError: true])
186 }
187 }
vitalygusev25872e12018-12-14 18:45:29 +0400188
vitalygusev22701372018-09-25 17:27:35 +0400189 if (STAGE_UPGRADE_SYSTEM_PART.toBoolean() == true && !errorOccured) {
190 upgrade(pepperEnv, "I@telegraf:agent or I@telegraf:remote_agent", "telegraf", "telegraf", "telegraf")
vitalygusev4b331fa2018-12-04 19:03:47 +0400191 upgrade(pepperEnv, "I@fluentd:agent", "td-agent", "td-agent td-agent-additional-plugins", "fluentd")
vitalygusev22701372018-09-25 17:27:35 +0400192 if (salt.testTarget(pepperEnv, "I@prometheus:relay")) {
vitalygusev25872e12018-12-14 18:45:29 +0400193 upgrade(pepperEnv, "I@prometheus:relay", "prometheus prometheus-relay", "prometheus-bin prometheus-relay", "prometheus")
194 salt.runSaltProcessStep(pepperEnv, "I@prometheus:relay", "service.restart", "prometheus", null, true)
vitalygusev22701372018-09-25 17:27:35 +0400195 }
196 if (salt.testTarget(pepperEnv, "I@prometheus:exporters:libvirt")) {
197 upgrade(pepperEnv, "I@prometheus:exporters:libvirt", "libvirt-exporter", "libvirt-exporter", "prometheus")
198 }
199 if (salt.testTarget(pepperEnv, "I@prometheus:exporters:jmx")) {
200 upgrade(pepperEnv, "I@prometheus:exporters:jmx", "jmx-exporter", "jmx-exporter", "prometheus")
201 }
vitalygusev25328892018-10-17 11:40:27 +0400202 }
203
204 if (STAGE_UPGRADE_ES_KIBANA.toBoolean() == true && !errorOccured) {
205 upgrade_es_kibana(pepperEnv)
vitalygusev22701372018-09-25 17:27:35 +0400206 }
207
208 if (STAGE_UPGRADE_DOCKER_COMPONENTS.toBoolean() == true && !errorOccured) {
vitalygusev4b331fa2018-12-04 19:03:47 +0400209 stage('Upgrade docker components') {
vitalygusev22701372018-09-25 17:27:35 +0400210 try {
vitalygusev4b331fa2018-12-04 19:03:47 +0400211 common.infoMsg('Disable and remove the previous versions of monitoring services')
212 salt.runSaltProcessStep(pepperEnv, 'I@docker:swarm:role:master and I@prometheus:server', command, ["docker stack rm monitoring"], null, true)
213 common.infoMsg('Rebuild the Prometheus configuration')
vitalygusev00826aa2018-12-24 13:44:47 +0400214 salt.enforceState([saltId: pepperEnv, target: 'I@docker:swarm and I@prometheus:server', state: 'prometheus'])
vitalygusev4b331fa2018-12-04 19:03:47 +0400215 common.infoMsg('Disable and remove the previous version of Grafana')
216 salt.runSaltProcessStep(pepperEnv, 'I@docker:swarm:role:master and I@prometheus:server', command, ["docker stack rm dashboard"], null, true)
217 common.infoMsg('Start the monitoring services')
vitalygusev00826aa2018-12-24 13:44:47 +0400218 salt.enforceState([saltId: pepperEnv, target: 'I@docker:swarm:role:master and I@prometheus:server', state: 'docker'])
vitalygusev22701372018-09-25 17:27:35 +0400219 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.sync_all', [], null, true)
vitalygusev4b331fa2018-12-04 19:03:47 +0400220 common.infoMsg('Refresh the Grafana dashboards')
vitalygusev00826aa2018-12-24 13:44:47 +0400221 salt.enforceState([saltId: pepperEnv, target: 'I@grafana:client', state: 'grafana.client'])
vitalygusev22701372018-09-25 17:27:35 +0400222 } catch (Exception er) {
223 errorOccured = true
vitalygusev4b331fa2018-12-04 19:03:47 +0400224 common.errorMsg("[ERROR] Upgrade of docker components failed. Please fix it manually.")
vitalygusev25872e12018-12-14 18:45:29 +0400225 throw er
vitalygusev22701372018-09-25 17:27:35 +0400226 }
227 }
228 }
229 }
230}