blob: e1e8cfb04dcdf1ab8255463c75b38795efdd696b [file] [log] [blame]
Martin Polreichf7a1bb02018-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].
Sergey6579de62019-01-15 17:27:59 +04007 * ASK_CONFIRMATION Ask confirmation for restore
Martin Polreich721b7252019-01-21 14:42:48 +01008 * CHECK_TIME_SYNC Set to true to check time synchronization accross selected nodes.
Martin Polreichf7889b52019-02-01 14:46:10 +01009 * VERIFICATION_RETRIES Number of restries to verify the restoration.
Martin Polreichf7a1bb02018-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 Polreichf7a1bb02018-12-05 11:12:23 +010017def pepperEnv = "pepperEnv"
18def resultCode = 99
19
Sergey6579de62019-01-15 17:27:59 +040020askConfirmation = (env.getProperty('ASK_CONFIRMATION') ?: true).toBoolean()
Martin Polreich721b7252019-01-21 14:42:48 +010021checkTimeSync = (env.getProperty('CHECK_TIME_SYNC') ?: true).toBoolean()
Martin Polreichf7889b52019-02-01 14:46:10 +010022if (common.validInputParam(VERIFICATION_RETRIES) && VERIFICATION_RETRIES.isInteger()) {
23 verificationRetries = VERIFICATION_RETRIES.toInteger()
24} else {
25 verificationRetries = 5
26}
Sergey6579de62019-01-15 17:27:59 +040027
Martin Polreichf7a1bb02018-12-05 11:12:23 +010028timeout(time: 12, unit: 'HOURS') {
29 node() {
30 stage('Setup virtualenv for Pepper') {
31 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
32 }
33 stage('Verify status')
Martin Polreich721b7252019-01-21 14:42:48 +010034 resultCode = openstack.verifyGaleraStatus(pepperEnv, false, checkTimeSync)
Martin Polreichf7a1bb02018-12-05 11:12:23 +010035 stage('Restore') {
36 if (resultCode == 128) {
37 common.errorMsg("Unable to connect to Galera Master. Trying slaves...")
Martin Polreich721b7252019-01-21 14:42:48 +010038 resultCode = openstack.verifyGaleraStatus(pepperEnv, true, checkTimeSync)
Martin Polreichf7a1bb02018-12-05 11:12:23 +010039 if (resultCode == 129) {
40 common.errorMsg("Unable to obtain Galera slave minions list". "Without fixing this issue, pipeline cannot continue in verification and restoration.")
41 currentBuild.result = "FAILURE"
Martin Polreichf7889b52019-02-01 14:46:10 +010042 return
Martin Polreichf7a1bb02018-12-05 11:12:23 +010043 } else if (resultCode == 130) {
44 common.errorMsg("Neither master or slaves are reachable. Without fixing this issue, pipeline cannot continue in verification and restoration.")
45 currentBuild.result = "FAILURE"
Martin Polreichf7889b52019-02-01 14:46:10 +010046 return
Martin Polreichf7a1bb02018-12-05 11:12:23 +010047 }
48 }
Martin Polreich721b7252019-01-21 14:42:48 +010049 if (resultCode == 131) {
50 common.errorMsg("Time desynced - Click proceed when the issue is fixed or abort.")
51 currentBuild.result = "FAILURE"
52 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010053 if (resultCode == 1) {
Sergey6579de62019-01-15 17:27:59 +040054 if(askConfirmation){
55 common.warningMsg("There was a problem with parsing the status output or with determining it. Do you want to run a restore?")
56 } else {
57 common.warningMsg("There was a problem with parsing the status output or with determining it. Try to restore.")
58 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010059 } else if (resultCode > 1) {
Sergey6579de62019-01-15 17:27:59 +040060 if(askConfirmation){
61 common.warningMsg("There's something wrong with the cluster, do you want to run a restore?")
62 } else {
63 common.warningMsg("There's something wrong with the cluster, try to restore.")
64 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010065 } else {
Sergey6579de62019-01-15 17:27:59 +040066 if(askConfirmation){
67 common.warningMsg("There seems to be everything alright with the cluster, do you still want to run a restore?")
68 } else {
69 common.warningMsg("There seems to be everything alright with the cluster, do nothing")
70 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010071 }
Sergey6579de62019-01-15 17:27:59 +040072 if(askConfirmation){
73 input message: "Are you sure you want to run a restore? Click to confirm"
74 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010075 try {
Sergey6579de62019-01-15 17:27:59 +040076 if((!askConfirmation && resultCode > 0) || askConfirmation){
77 openstack.restoreGaleraDb(pepperEnv)
78 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010079 } catch (Exception e) {
80 common.errorMsg("Restoration process has failed.")
81 }
82 }
Martin Polreich7bc654c2019-01-18 14:17:52 +010083 stage('Verify restoration result') {
Martin Polreichf7889b52019-02-01 14:46:10 +010084 common.retry(verificationRetries, 15) {
85 exitCode = openstack.verifyGaleraStatus(pepperEnv, false, false)
86 if (exitCode >= 1) {
87 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.")
88 } else {
89 common.infoMsg("Restoration procedure seems to be successful. See verification report to be sure.")
90 currentBuild.result = "SUCCESS"
91 }
Martin Polreich7bc654c2019-01-18 14:17:52 +010092 }
93 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010094 }
95}