vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 1 | /** |
| 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 | |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame] | 15 | common = new com.mirantis.mk.Common() |
| 16 | salt = new com.mirantis.mk.Salt() |
| 17 | python = new com.mirantis.mk.Python() |
| 18 | command = 'cmd.run' |
| 19 | pepperEnv = "pepperEnv" |
| 20 | errorOccured = false |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 21 | |
| 22 | def upgrade(master, target, service, pckg, state) { |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame] | 23 | stage("Upgrade ${service}") { |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 24 | salt.runSaltProcessStep(master, "${target}", 'saltutil.refresh_pillar', [], null, true) |
vitalygusev | 00826aa | 2018-12-24 13:44:47 +0400 | [diff] [blame] | 25 | salt.enforceState([saltId: master, target: "${target}", state: 'linux.system.repo', output: true, failOnError: true]) |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 26 | common.infoMsg("Upgrade ${service} package(s)") |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 27 | try { |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 28 | salt.runSaltProcessStep(master, "${target}", command, ["apt-get install -y -o Dpkg::Options::=\"--force-confold\" ${pckg}"], null, true) |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 29 | } catch (Exception er) { |
| 30 | errorOccured = true |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 31 | common.errorMsg("[ERROR] ${pckg} package(s) was not upgraded.") |
| 32 | throw er |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 33 | } |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame] | 34 | common.infoMsg("Run ${state} state on ${target} nodes") |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 35 | try { |
vitalygusev | 00826aa | 2018-12-24 13:44:47 +0400 | [diff] [blame] | 36 | salt.enforceState([saltId: master, target: "${target}", state: ["${state}"], output: true, failOnError: true]) |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 37 | } catch (Exception er) { |
| 38 | errorOccured = true |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame] | 39 | common.errorMsg("[ERROR] ${state} state was executed and failed. Please fix it manually.") |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 40 | throw er |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 41 | } |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 42 | 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 | |
| 49 | def 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 |
| 54 | def elasticsearch_vip |
| 55 | def pillar = salt.getPillar(master, "I@elasticsearch:client", 'elasticsearch:client:server:host') |
| 56 | if(!pillar['return'].isEmpty()) { |
| 57 | elasticsearch_vip = pillar['return'][0].values()[0] |
| 58 | } else { |
| 59 | errorOccured = true |
| 60 | common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved') |
| 61 | } |
| 62 | pillar = salt.getPillar(master, "I@elasticsearch:client", 'elasticsearch:client:server:port') |
| 63 | def elasticsearch_port |
| 64 | if(!pillar['return'].isEmpty()) { |
| 65 | elasticsearch_port = pillar['return'][0].values()[0] |
| 66 | } else { |
| 67 | errorOccured = true |
| 68 | common.errorMsg('[ERROR] Elasticsearch VIP port could not be retrieved') |
| 69 | } |
Dmitry Kalashnik | b5763f9 | 2019-05-23 10:11:42 +0400 | [diff] [blame^] | 70 | pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:scheme') |
| 71 | def elasticsearch_scheme |
| 72 | if(!pillar['return'].isEmpty()) { |
| 73 | elasticsearch_scheme = pillar['return'][0].values()[0] |
| 74 | } else { |
| 75 | common.infoMsg('No pillar with Elasticsearch server scheme, using http') |
| 76 | elasticsearch_scheme = "http" |
| 77 | } |
| 78 | |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 79 | common.retry(retries,retries_wait) { |
| 80 | common.infoMsg('Waiting for Elasticsearch to become green..') |
Dmitry Kalashnik | b5763f9 | 2019-05-23 10:11:42 +0400 | [diff] [blame^] | 81 | salt.cmdRun(master, "I@elasticsearch:client", "curl -sfk ${elasticsearch_scheme}://${elasticsearch_vip}:${elasticsearch_port}/_cat/health | awk '{print \$4}' | grep green") |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 82 | } |
| 83 | } catch (Exception er) { |
| 84 | errorOccured = true |
| 85 | common.errorMsg("[ERROR] Elasticsearch cluster status is not \'green\'. Please fix it manually.") |
| 86 | throw er |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 87 | } |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | def upgrade_es_kibana(master) { |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 91 | def elasticsearch_version |
| 92 | def es_pillar = salt.getPillar(master, "I@elasticsearch:client", '_param:elasticsearch_version') |
| 93 | if(!es_pillar['return'].isEmpty()) { |
| 94 | elasticsearch_version = es_pillar['return'][0].values()[0] |
| 95 | } |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame] | 96 | stage('Upgrade elasticsearch') { |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 97 | if (elasticsearch_version == '5') { |
| 98 | try { |
| 99 | common.infoMsg('Upgrade the Elasticsearch package') |
| 100 | salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["systemctl stop elasticsearch"], null, true) |
| 101 | salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["apt-get --only-upgrade install elasticsearch"], null, true) |
| 102 | salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["systemctl daemon-reload"], null, true) |
| 103 | salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["systemctl start elasticsearch"], null, true) |
| 104 | salt.runSaltProcessStep(master, '*', 'saltutil.sync_all', [], null, true) |
| 105 | verify_es_is_green(master) |
| 106 | } catch (Exception er) { |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 107 | errorOccured = true |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 108 | common.errorMsg("[ERROR] Elasticsearch upgrade failed. Please fix it manually.") |
| 109 | throw er |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 110 | } |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 111 | } else { |
| 112 | try { |
| 113 | salt.runSaltProcessStep(master, "*", 'saltutil.refresh_pillar', [], null, true) |
vitalygusev | 00826aa | 2018-12-24 13:44:47 +0400 | [diff] [blame] | 114 | salt.enforceState([saltId: master, target: "I@elasticsearch:server", state: 'linux.system.repo', output: true, failOnError: true]) |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 115 | salt.runSaltProcessStep(master, 'I@elasticsearch:client', command, ["apt-get install -y -o Dpkg::Options::=\"--force-confold\" python-elasticsearch"], null, true) |
vitalygusev | 00826aa | 2018-12-24 13:44:47 +0400 | [diff] [blame] | 116 | salt.enforceState([saltId: master, target: "I@elasticsearch:server", state: 'salt.minion', output: true, failOnError: true]) |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 117 | salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["systemctl stop elasticsearch"], null, true) |
| 118 | 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) |
vitalygusev | 00826aa | 2018-12-24 13:44:47 +0400 | [diff] [blame] | 119 | salt.enforceState([saltId: master, target: "I@elasticsearch:server", state: 'elasticsearch.server', output: true, failOnError: true]) |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 120 | verify_es_is_green(master) |
vitalygusev | 00826aa | 2018-12-24 13:44:47 +0400 | [diff] [blame] | 121 | salt.enforceState([saltId: master, target: "I@elasticsearch:client", state: 'elasticsearch.client.update_index_templates', output: true, failOnError: true]) |
| 122 | salt.enforceState([saltId: master, target: "I@elasticsearch:client", state: 'elasticsearch.client', output: true, failOnError: true]) |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 123 | } catch (Exception er) { |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 124 | errorOccured = true |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 125 | common.errorMsg("[ERROR] Elasticsearch upgrade failed. Please fix it manually.") |
| 126 | throw er |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 127 | } |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 128 | } |
| 129 | } |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame] | 130 | stage('Upgrade kibana') { |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 131 | def kibana_version |
| 132 | def kibana_pillar = salt.getPillar(master, "I@kibana:client", '_param:kibana_version') |
| 133 | if(!kibana_pillar['return'].isEmpty()) { |
| 134 | kibana_version = kibana_pillar['return'][0].values()[0] |
| 135 | } |
| 136 | if (kibana_version == '5') { |
| 137 | try { |
| 138 | common.infoMsg('Upgrade the Kibana package') |
| 139 | salt.runSaltProcessStep(master, 'I@kibana:server', command, ["systemctl stop kibana"], null, true) |
| 140 | salt.runSaltProcessStep(master, 'I@kibana:server', command, ["apt-get --only-upgrade install kibana"], null, true) |
| 141 | salt.runSaltProcessStep(master, 'I@kibana:server', command, ["systemctl start kibana"], null, true) |
| 142 | } catch (Exception er) { |
| 143 | errorOccured = true |
| 144 | common.errorMsg("[ERROR] Kibana upgrade failed. Please fix it manually.") |
| 145 | throw er |
| 146 | } |
| 147 | } else { |
| 148 | try { |
| 149 | salt.runSaltProcessStep(master, 'I@kibana:server', command, ["systemctl stop kibana"], null, true) |
vitalygusev | 00826aa | 2018-12-24 13:44:47 +0400 | [diff] [blame] | 150 | salt.enforceStateWithExclude([saltId: master, target: "I@kibana:server", state: "kibana.server", excludedStates: "[{'id': 'kibana_service'}]"]) |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 151 | salt.runSaltProcessStep(master, 'I@kibana:server', command, ["apt-get install -y -o Dpkg::Options::=\"--force-confold\" kibana"], null, true) |
vitalygusev | 00826aa | 2018-12-24 13:44:47 +0400 | [diff] [blame] | 152 | salt.enforceState([saltId: master, target: "I@kibana:server", state: 'kibana.server', output: true, failOnError: true]) |
| 153 | salt.enforceState([saltId: master, target: "I@kibana:client", state: 'kibana.client', output: true, failOnError: true]) |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 154 | } catch (Exception er) { |
| 155 | errorOccured = true |
| 156 | common.errorMsg("[ERROR] Kibana upgrade failed. Please fix it manually.") |
| 157 | throw er |
| 158 | } |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 159 | } |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 160 | |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame] | 161 | common.infoMsg("Check kibana status on the target nodes") |
| 162 | salt.runSaltProcessStep(master, "I@kibana:server", "service.status", ["kibana"], null, true) |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | timeout(time: 12, unit: 'HOURS') { |
| 166 | node("python") { |
| 167 | |
| 168 | stage('Setup virtualenv for Pepper') { |
| 169 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 170 | } |
| 171 | |
vitalygusev | 00826aa | 2018-12-24 13:44:47 +0400 | [diff] [blame] | 172 | stage('Update grains and mine') { |
| 173 | salt.enforceState([saltId: pepperEnv, target: '*', state: 'salt.minion.grains']) |
| 174 | salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.refresh_modules') |
| 175 | salt.runSaltProcessStep(pepperEnv, '*', 'mine.update') |
| 176 | sleep(30) |
| 177 | } |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 178 | |
vitalygusev | 00826aa | 2018-12-24 13:44:47 +0400 | [diff] [blame] | 179 | if (salt.testTarget(pepperEnv, "I@ceph:mon")) { |
| 180 | stage('Enable Ceph prometheus plugin') { |
| 181 | salt.enforceState([saltId: pepperEnv, target: 'I@ceph:mon', state: "ceph.mgr", output: true, failOnError: true]) |
| 182 | } |
| 183 | } |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 184 | |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 185 | if (STAGE_UPGRADE_SYSTEM_PART.toBoolean() == true && !errorOccured) { |
| 186 | upgrade(pepperEnv, "I@telegraf:agent or I@telegraf:remote_agent", "telegraf", "telegraf", "telegraf") |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame] | 187 | upgrade(pepperEnv, "I@fluentd:agent", "td-agent", "td-agent td-agent-additional-plugins", "fluentd") |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 188 | if (salt.testTarget(pepperEnv, "I@prometheus:relay")) { |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 189 | upgrade(pepperEnv, "I@prometheus:relay", "prometheus prometheus-relay", "prometheus-bin prometheus-relay", "prometheus") |
| 190 | salt.runSaltProcessStep(pepperEnv, "I@prometheus:relay", "service.restart", "prometheus", null, true) |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 191 | } |
| 192 | if (salt.testTarget(pepperEnv, "I@prometheus:exporters:libvirt")) { |
| 193 | upgrade(pepperEnv, "I@prometheus:exporters:libvirt", "libvirt-exporter", "libvirt-exporter", "prometheus") |
| 194 | } |
| 195 | if (salt.testTarget(pepperEnv, "I@prometheus:exporters:jmx")) { |
| 196 | upgrade(pepperEnv, "I@prometheus:exporters:jmx", "jmx-exporter", "jmx-exporter", "prometheus") |
| 197 | } |
vitalygusev | 2532889 | 2018-10-17 11:40:27 +0400 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | if (STAGE_UPGRADE_ES_KIBANA.toBoolean() == true && !errorOccured) { |
| 201 | upgrade_es_kibana(pepperEnv) |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | if (STAGE_UPGRADE_DOCKER_COMPONENTS.toBoolean() == true && !errorOccured) { |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame] | 205 | stage('Upgrade docker components') { |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 206 | try { |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame] | 207 | common.infoMsg('Disable and remove the previous versions of monitoring services') |
| 208 | salt.runSaltProcessStep(pepperEnv, 'I@docker:swarm:role:master and I@prometheus:server', command, ["docker stack rm monitoring"], null, true) |
| 209 | common.infoMsg('Rebuild the Prometheus configuration') |
vitalygusev | 00826aa | 2018-12-24 13:44:47 +0400 | [diff] [blame] | 210 | salt.enforceState([saltId: pepperEnv, target: 'I@docker:swarm and I@prometheus:server', state: 'prometheus']) |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame] | 211 | common.infoMsg('Disable and remove the previous version of Grafana') |
| 212 | salt.runSaltProcessStep(pepperEnv, 'I@docker:swarm:role:master and I@prometheus:server', command, ["docker stack rm dashboard"], null, true) |
| 213 | common.infoMsg('Start the monitoring services') |
vitalygusev | 00826aa | 2018-12-24 13:44:47 +0400 | [diff] [blame] | 214 | salt.enforceState([saltId: pepperEnv, target: 'I@docker:swarm:role:master and I@prometheus:server', state: 'docker']) |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 215 | salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.sync_all', [], null, true) |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame] | 216 | common.infoMsg('Refresh the Grafana dashboards') |
vitalygusev | 00826aa | 2018-12-24 13:44:47 +0400 | [diff] [blame] | 217 | salt.enforceState([saltId: pepperEnv, target: 'I@grafana:client', state: 'grafana.client']) |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 218 | } catch (Exception er) { |
| 219 | errorOccured = true |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame] | 220 | common.errorMsg("[ERROR] Upgrade of docker components failed. Please fix it manually.") |
vitalygusev | 25872e1 | 2018-12-14 18:45:29 +0400 | [diff] [blame] | 221 | throw er |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | } |