blob: ecbafc52db46a2c0c496dbcb53e12705cfb682d5 [file] [log] [blame]
Martin Polreichaae1b9d2018-12-05 11:12:23 +01001/**
2 * Verify and restore Galera cluster
3 *
4 * Expected parameters:
5 * SALT_MASTER_CREDENTIALS Credentials to the Salt API.
6 * SALT_MASTER_URL Full Salt API address [http://10.10.10.1:8000].
Martin Polreich0d538262019-02-01 14:46:10 +01007 * ASK_CONFIRMATION Ask confirmation for restore
Martin Polreich0d538262019-02-01 14:46:10 +01008 * VERIFICATION_RETRIES Number of restries to verify the restoration.
Martin Polreich2aa74402019-01-21 14:42:48 +01009 * CHECK_TIME_SYNC Set to true to check time synchronization accross selected nodes.
Martin Polreichaae1b9d2018-12-05 11:12:23 +010010 *
11**/
12
13def common = new com.mirantis.mk.Common()
14def salt = new com.mirantis.mk.Salt()
Martin Polreich71a08db2019-02-15 10:09:10 +010015def galera = new com.mirantis.mk.Galera()
Martin Polreichaae1b9d2018-12-05 11:12:23 +010016def python = new com.mirantis.mk.Python()
Martin Polreichaae1b9d2018-12-05 11:12:23 +010017def pepperEnv = "pepperEnv"
18def resultCode = 99
19
Martin Polreich0d538262019-02-01 14:46:10 +010020askConfirmation = (env.getProperty('ASK_CONFIRMATION') ?: true).toBoolean()
Martin Polreich2aa74402019-01-21 14:42:48 +010021checkTimeSync = (env.getProperty('CHECK_TIME_SYNC') ?: true).toBoolean()
Sergeyc8a8a792019-01-15 17:27:59 +040022
Martin Polreich0d538262019-02-01 14:46:10 +010023if (common.validInputParam(VERIFICATION_RETRIES) && VERIFICATION_RETRIES.isInteger()) {
24 verificationRetries = VERIFICATION_RETRIES.toInteger()
25} else {
26 verificationRetries = 5
27}
28
Martin Polreichaae1b9d2018-12-05 11:12:23 +010029timeout(time: 12, unit: 'HOURS') {
30 node() {
31 stage('Setup virtualenv for Pepper') {
32 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
33 }
34 stage('Verify status')
Martin Polreich71a08db2019-02-15 10:09:10 +010035 resultCode = galera.verifyGaleraStatus(pepperEnv, false, checkTimeSync)
Martin Polreichaae1b9d2018-12-05 11:12:23 +010036 stage('Restore') {
37 if (resultCode == 128) {
38 common.errorMsg("Unable to connect to Galera Master. Trying slaves...")
Martin Polreich71a08db2019-02-15 10:09:10 +010039 resultCode = galera.verifyGaleraStatus(pepperEnv, true, checkTimeSync)
Martin Polreichaae1b9d2018-12-05 11:12:23 +010040 if (resultCode == 129) {
41 common.errorMsg("Unable to obtain Galera slave minions list". "Without fixing this issue, pipeline cannot continue in verification and restoration.")
42 currentBuild.result = "FAILURE"
Martin Polreich0d538262019-02-01 14:46:10 +010043 return
Martin Polreichaae1b9d2018-12-05 11:12:23 +010044 } else if (resultCode == 130) {
45 common.errorMsg("Neither master or slaves are reachable. Without fixing this issue, pipeline cannot continue in verification and restoration.")
46 currentBuild.result = "FAILURE"
Martin Polreich0d538262019-02-01 14:46:10 +010047 return
Martin Polreichaae1b9d2018-12-05 11:12:23 +010048 }
49 }
Martin Polreich2aa74402019-01-21 14:42:48 +010050 if (resultCode == 131) {
Martin Polreich323ffde2019-05-07 15:56:38 +020051 common.errorMsg("Time desynced - Please fix this issue and rerun the pipeline.")
Martin Polreich2aa74402019-01-21 14:42:48 +010052 currentBuild.result = "FAILURE"
Martin Polreich323ffde2019-05-07 15:56:38 +020053 return
54 }
55 if (resultCode == 140 || resultCode == 141) {
56 common.errorMsg("Disk utilization check failed - Please fix this issue and rerun the pipeline.")
57 currentBuild.result = "FAILURE"
58 return
Martin Polreich2aa74402019-01-21 14:42:48 +010059 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010060 if (resultCode == 1) {
Sergeyc8a8a792019-01-15 17:27:59 +040061 if(askConfirmation){
62 common.warningMsg("There was a problem with parsing the status output or with determining it. Do you want to run a restore?")
63 } else {
64 common.warningMsg("There was a problem with parsing the status output or with determining it. Try to restore.")
65 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010066 } else if (resultCode > 1) {
Sergeyc8a8a792019-01-15 17:27:59 +040067 if(askConfirmation){
68 common.warningMsg("There's something wrong with the cluster, do you want to run a restore?")
69 } else {
70 common.warningMsg("There's something wrong with the cluster, try to restore.")
71 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010072 } else {
Sergeyc8a8a792019-01-15 17:27:59 +040073 if(askConfirmation){
74 common.warningMsg("There seems to be everything alright with the cluster, do you still want to run a restore?")
75 } else {
76 common.warningMsg("There seems to be everything alright with the cluster, do nothing")
77 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010078 }
Sergeyc8a8a792019-01-15 17:27:59 +040079 if(askConfirmation){
80 input message: "Are you sure you want to run a restore? Click to confirm"
81 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010082 try {
Sergeyc8a8a792019-01-15 17:27:59 +040083 if((!askConfirmation && resultCode > 0) || askConfirmation){
Martin Polreich71a08db2019-02-15 10:09:10 +010084 galera.restoreGaleraDb(pepperEnv)
Sergeyc8a8a792019-01-15 17:27:59 +040085 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010086 } catch (Exception e) {
87 common.errorMsg("Restoration process has failed.")
88 }
89 }
Martin Polreichc9466c72019-01-18 14:17:52 +010090 stage('Verify restoration result') {
Martin Polreich0d538262019-02-01 14:46:10 +010091 common.retry(verificationRetries, 15) {
Martin Polreich71a08db2019-02-15 10:09:10 +010092 exitCode = galera.verifyGaleraStatus(pepperEnv, false, false)
Martin Polreich0d538262019-02-01 14:46:10 +010093 if (exitCode >= 1) {
94 error("Verification attempt finished with an error. This may be caused by cluster not having enough time to come up or to sync. Next verification attempt in 5 seconds.")
95 } else {
96 common.infoMsg("Restoration procedure seems to be successful. See verification report to be sure.")
97 currentBuild.result = "SUCCESS"
98 }
Martin Polreichc9466c72019-01-18 14:17:52 +010099 }
100 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +0100101 }
102}