blob: e65257a3981f4e93d71f8bd972b20cb4857adf1e [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()
15def openstack = new com.mirantis.mk.Openstack()
16def 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 Polreich2aa74402019-01-21 14:42:48 +010035 resultCode = openstack.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 Polreich2aa74402019-01-21 14:42:48 +010039 resultCode = openstack.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) {
51 common.errorMsg("Time desynced - Click proceed when the issue is fixed or abort.")
52 currentBuild.result = "FAILURE"
53 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010054 if (resultCode == 1) {
Sergeyc8a8a792019-01-15 17:27:59 +040055 if(askConfirmation){
56 common.warningMsg("There was a problem with parsing the status output or with determining it. Do you want to run a restore?")
57 } else {
58 common.warningMsg("There was a problem with parsing the status output or with determining it. Try to restore.")
59 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010060 } else if (resultCode > 1) {
Sergeyc8a8a792019-01-15 17:27:59 +040061 if(askConfirmation){
62 common.warningMsg("There's something wrong with the cluster, do you want to run a restore?")
63 } else {
64 common.warningMsg("There's something wrong with the cluster, try to restore.")
65 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010066 } else {
Sergeyc8a8a792019-01-15 17:27:59 +040067 if(askConfirmation){
68 common.warningMsg("There seems to be everything alright with the cluster, do you still want to run a restore?")
69 } else {
70 common.warningMsg("There seems to be everything alright with the cluster, do nothing")
71 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010072 }
Sergeyc8a8a792019-01-15 17:27:59 +040073 if(askConfirmation){
74 input message: "Are you sure you want to run a restore? Click to confirm"
75 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010076 try {
Sergeyc8a8a792019-01-15 17:27:59 +040077 if((!askConfirmation && resultCode > 0) || askConfirmation){
78 openstack.restoreGaleraDb(pepperEnv)
79 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010080 } catch (Exception e) {
81 common.errorMsg("Restoration process has failed.")
82 }
83 }
Martin Polreichc9466c72019-01-18 14:17:52 +010084 stage('Verify restoration result') {
Martin Polreich0d538262019-02-01 14:46:10 +010085 common.retry(verificationRetries, 15) {
Martin Polreich394091a2019-03-18 14:24:12 +010086 exitCode = openstack.verifyGaleraStatus(pepperEnv, false)
Martin Polreich0d538262019-02-01 14:46:10 +010087 if (exitCode >= 1) {
88 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.")
89 } else {
90 common.infoMsg("Restoration procedure seems to be successful. See verification report to be sure.")
91 currentBuild.result = "SUCCESS"
92 }
Martin Polreichc9466c72019-01-18 14:17:52 +010093 }
94 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010095 }
96}