blob: 7b79f4c740c249cc22ea86431229a6f6dc652c76 [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
15def common = new com.mirantis.mk.Common()
16def salt = new com.mirantis.mk.Salt()
17def python = new com.mirantis.mk.Python()
18
19def pepperEnv = "pepperEnv"
20def targetLiveSubset
21def targetLiveAll
22def minions
23def result
24def args
25def commandKwargs
26def probe = 1
27def errorOccured = false
vitalygusev22701372018-09-25 17:27:35 +040028
29def upgrade(master, target, service, pckg, state) {
vitalygusev25328892018-10-17 11:40:27 +040030 def common = new com.mirantis.mk.Common()
31 def salt = new com.mirantis.mk.Salt()
32 def command = 'cmd.run'
vitalygusev22701372018-09-25 17:27:35 +040033 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 }
vitalygusev25328892018-10-17 11:40:27 +040047 stage("Run ${state} state on ${target} nodes") {
vitalygusev22701372018-09-25 17:27:35 +040048 try {
vitalygusev25328892018-10-17 11:40:27 +040049 salt.enforceState(master, "${target}", ["${state}"], true)
vitalygusev22701372018-09-25 17:27:35 +040050 } catch (Exception er) {
51 errorOccured = true
vitalygusev25328892018-10-17 11:40:27 +040052 common.errorMsg("${state} state was executed and failed. Please fix it manually.")
vitalygusev22701372018-09-25 17:27:35 +040053 }
54 }
vitalygusev25328892018-10-17 11:40:27 +040055 out = salt.runSaltCommand(master, 'local', ['expression': "${target}", 'type': 'compound'], command, null, "systemctl status ${service}.service", null)
vitalygusev22701372018-09-25 17:27:35 +040056 salt.printSaltCommandResult(out)
57
vitalygusev25328892018-10-17 11:40:27 +040058 common.warningMsg("Please check \'systemctl status ${service}.service\' on ${target} nodes if ${service} is running.")
vitalygusev22701372018-09-25 17:27:35 +040059 return
60}
61
62def upgrade_es_kibana(master) {
vitalygusev25328892018-10-17 11:40:27 +040063 def common = new com.mirantis.mk.Common()
64 def salt = new com.mirantis.mk.Salt()
65 def command = 'cmd.run'
vitalygusev22701372018-09-25 17:27:35 +040066 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
vitalygusev25328892018-10-17 11:40:27 +040084 def pillar = salt.getPillar(master, "I@elasticsearch:client", 'elasticsearch:client:server:host')
vitalygusev22701372018-09-25 17:27:35 +040085 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}
126timeout(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 }
vitalygusev25328892018-10-17 11:40:27 +0400145 }
146
147 if (STAGE_UPGRADE_ES_KIBANA.toBoolean() == true && !errorOccured) {
148 upgrade_es_kibana(pepperEnv)
vitalygusev22701372018-09-25 17:27:35 +0400149 }
150
151 if (STAGE_UPGRADE_DOCKER_COMPONENTS.toBoolean() == true && !errorOccured) {
152
153 stage('Docker components upgrade') {
154
155 try {
vitalygusev25328892018-10-17 11:40:27 +0400156 salt.runSaltProcessStep(pepperEnv, 'I@docker:swarm:role:master and I@prometheus:server', 'cmd.run', ["docker stack rm monitoring"], null, true)
vitalygusev22701372018-09-25 17:27:35 +0400157 salt.enforceState(pepperEnv, 'I@docker:swarm and I@prometheus:server', 'prometheus')
vitalygusev25328892018-10-17 11:40:27 +0400158 salt.runSaltProcessStep(pepperEnv, 'I@docker:swarm:role:master and I@prometheus:server', 'cmd.run', ["docker stack rm dashboard"], null, true)
vitalygusev22701372018-09-25 17:27:35 +0400159 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}