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 | |
| 15 | def common = new com.mirantis.mk.Common() |
| 16 | def salt = new com.mirantis.mk.Salt() |
| 17 | def python = new com.mirantis.mk.Python() |
| 18 | |
| 19 | def pepperEnv = "pepperEnv" |
| 20 | def targetLiveSubset |
| 21 | def targetLiveAll |
| 22 | def minions |
| 23 | def result |
| 24 | def args |
| 25 | def commandKwargs |
| 26 | def probe = 1 |
| 27 | def errorOccured = false |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 28 | |
| 29 | def upgrade(master, target, service, pckg, state) { |
vitalygusev | 2532889 | 2018-10-17 11:40:27 +0400 | [diff] [blame] | 30 | def common = new com.mirantis.mk.Common() |
| 31 | def salt = new com.mirantis.mk.Salt() |
| 32 | def command = 'cmd.run' |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 33 | stage("Change ${target} repos") { |
| 34 | salt.runSaltProcessStep(master, "${target}", 'saltutil.refresh_pillar', [], null, true, 5) |
| 35 | salt.enforceState(master, "${target}", 'linux.system.repo', true) |
| 36 | } |
| 37 | stage("Update ${pckg} package") { |
| 38 | common.infoMsg("Upgrade ${service} package") |
| 39 | try { |
| 40 | salt.runSaltProcessStep(master, "${target}", command, ["apt-get install --only-upgrade ${pckg}"], null, true) |
| 41 | } catch (Exception er) { |
| 42 | errorOccured = true |
| 43 | common.errorMsg("${pckg} package is not upgraded.") |
| 44 | return |
| 45 | } |
| 46 | } |
vitalygusev | 2532889 | 2018-10-17 11:40:27 +0400 | [diff] [blame] | 47 | stage("Run ${state} state on ${target} nodes") { |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 48 | try { |
vitalygusev | 2532889 | 2018-10-17 11:40:27 +0400 | [diff] [blame] | 49 | salt.enforceState(master, "${target}", ["${state}"], true) |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 50 | } catch (Exception er) { |
| 51 | errorOccured = true |
vitalygusev | 2532889 | 2018-10-17 11:40:27 +0400 | [diff] [blame] | 52 | common.errorMsg("${state} state was executed and failed. Please fix it manually.") |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 53 | } |
| 54 | } |
vitalygusev | 2532889 | 2018-10-17 11:40:27 +0400 | [diff] [blame] | 55 | out = salt.runSaltCommand(master, 'local', ['expression': "${target}", 'type': 'compound'], command, null, "systemctl status ${service}.service", null) |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 56 | salt.printSaltCommandResult(out) |
| 57 | |
vitalygusev | 2532889 | 2018-10-17 11:40:27 +0400 | [diff] [blame] | 58 | common.warningMsg("Please check \'systemctl status ${service}.service\' on ${target} nodes if ${service} is running.") |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 59 | return |
| 60 | } |
| 61 | |
| 62 | def upgrade_es_kibana(master) { |
vitalygusev | 2532889 | 2018-10-17 11:40:27 +0400 | [diff] [blame] | 63 | def common = new com.mirantis.mk.Common() |
| 64 | def salt = new com.mirantis.mk.Salt() |
| 65 | def command = 'cmd.run' |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 66 | stage('Elasticsearch upgrade') { |
| 67 | try { |
| 68 | salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["systemctl stop elasticsearch"], null, true) |
| 69 | salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["apt-get --only-upgrade install elasticsearch"], null, true) |
| 70 | salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["systemctl daemon-reload"], null, true) |
| 71 | salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["systemctl start elasticsearch"], null, true) |
| 72 | salt.runSaltProcessStep(master, '*', 'saltutil.sync_all', [], null, true) |
| 73 | } catch (Exception er) { |
| 74 | errorOccured = true |
| 75 | common.errorMsg("Elasticsearch upgrade failed. Please fix it manually.") |
| 76 | return |
| 77 | } |
| 78 | } |
| 79 | stage('Verify that the Elasticsearch cluster status is green') { |
| 80 | try { |
| 81 | def retries_wait = 20 |
| 82 | def retries = 15 |
| 83 | def elasticsearch_vip |
vitalygusev | 2532889 | 2018-10-17 11:40:27 +0400 | [diff] [blame] | 84 | def pillar = salt.getPillar(master, "I@elasticsearch:client", 'elasticsearch:client:server:host') |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 85 | if(!pillar['return'].isEmpty()) { |
| 86 | elasticsearch_vip = pillar['return'][0].values()[0] |
| 87 | } else { |
| 88 | errorOccured = true |
| 89 | common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved') |
| 90 | } |
| 91 | pillar = salt.getPillar(master, "I@elasticsearch:client", 'elasticsearch:client:server:port') |
| 92 | def elasticsearch_port |
| 93 | if(!pillar['return'].isEmpty()) { |
| 94 | elasticsearch_port = pillar['return'][0].values()[0] |
| 95 | } else { |
| 96 | errorOccured = true |
| 97 | common.errorMsg('[ERROR] Elasticsearch VIP port could not be retrieved') |
| 98 | } |
| 99 | common.retry(retries,retries_wait) { |
| 100 | common.infoMsg('Waiting for Elasticsearch to become green..') |
| 101 | salt.cmdRun(master, "I@elasticsearch:client", "curl -sf ${elasticsearch_vip}:${elasticsearch_port}/_cat/health | awk '{print \$4}' | grep green") |
| 102 | } |
| 103 | } catch (Exception er) { |
| 104 | errorOccured = true |
| 105 | common.errorMsg("Elasticsearch cluster status is not \'green\'. Please fix it manually.") |
| 106 | return |
| 107 | } |
| 108 | } |
| 109 | stage('Kibana upgrade') { |
| 110 | try { |
| 111 | salt.runSaltProcessStep(master, 'I@kibana:server', command, ["systemctl stop kibana"], null, true) |
| 112 | salt.runSaltProcessStep(master, 'I@kibana:server', command, ["apt-get --only-upgrade install kibana"], null, true) |
| 113 | salt.runSaltProcessStep(master, 'I@kibana:server', command, ["systemctl start kibana"], null, true) |
| 114 | } catch (Exception er) { |
| 115 | errorOccured = true |
| 116 | common.errorMsg("Kibana upgrade failed. Please fix it manually.") |
| 117 | return |
| 118 | } |
| 119 | out = salt.runSaltCommand(master, 'local', ['expression': 'I@kibana:server', 'type': 'compound'], command, null, 'systemctl status kibana.service', null) |
| 120 | salt.printSaltCommandResult(out) |
| 121 | |
| 122 | common.warningMsg('Please check if kibana service is running.') |
| 123 | return |
| 124 | } |
| 125 | } |
| 126 | timeout(time: 12, unit: 'HOURS') { |
| 127 | node("python") { |
| 128 | |
| 129 | stage('Setup virtualenv for Pepper') { |
| 130 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 131 | } |
| 132 | |
| 133 | if (STAGE_UPGRADE_SYSTEM_PART.toBoolean() == true && !errorOccured) { |
| 134 | upgrade(pepperEnv, "I@telegraf:agent or I@telegraf:remote_agent", "telegraf", "telegraf", "telegraf") |
| 135 | upgrade(pepperEnv, "I@fluentd:agent", "td-agent", "td-agent", "fluentd") |
| 136 | if (salt.testTarget(pepperEnv, "I@prometheus:relay")) { |
| 137 | upgrade(pepperEnv, "I@prometheus:relay", "prometheus-relay", "prometheus-relay", "prometheus") |
| 138 | } |
| 139 | if (salt.testTarget(pepperEnv, "I@prometheus:exporters:libvirt")) { |
| 140 | upgrade(pepperEnv, "I@prometheus:exporters:libvirt", "libvirt-exporter", "libvirt-exporter", "prometheus") |
| 141 | } |
| 142 | if (salt.testTarget(pepperEnv, "I@prometheus:exporters:jmx")) { |
| 143 | upgrade(pepperEnv, "I@prometheus:exporters:jmx", "jmx-exporter", "jmx-exporter", "prometheus") |
| 144 | } |
vitalygusev | 2532889 | 2018-10-17 11:40:27 +0400 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | if (STAGE_UPGRADE_ES_KIBANA.toBoolean() == true && !errorOccured) { |
| 148 | upgrade_es_kibana(pepperEnv) |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | if (STAGE_UPGRADE_DOCKER_COMPONENTS.toBoolean() == true && !errorOccured) { |
| 152 | |
| 153 | stage('Docker components upgrade') { |
| 154 | |
| 155 | try { |
vitalygusev | 2532889 | 2018-10-17 11:40:27 +0400 | [diff] [blame] | 156 | salt.runSaltProcessStep(pepperEnv, 'I@docker:swarm:role:master and I@prometheus:server', 'cmd.run', ["docker stack rm monitoring"], null, true) |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 157 | salt.enforceState(pepperEnv, 'I@docker:swarm and I@prometheus:server', 'prometheus') |
vitalygusev | 2532889 | 2018-10-17 11:40:27 +0400 | [diff] [blame] | 158 | salt.runSaltProcessStep(pepperEnv, 'I@docker:swarm:role:master and I@prometheus:server', 'cmd.run', ["docker stack rm dashboard"], null, true) |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 159 | salt.enforceState(pepperEnv, 'I@docker:swarm:role:master and I@prometheus:server', 'docker') |
| 160 | salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.sync_all', [], null, true) |
| 161 | salt.enforceState(pepperEnv, 'I@grafana:client', 'grafana.client') |
| 162 | } catch (Exception er) { |
| 163 | errorOccured = true |
| 164 | common.errorMsg("Upgrade of docker components failed. Please fix it manually.") |
| 165 | return |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | } |