blob: 4c1d63a4b9d756bcfb0e8c2243542532554c4f28 [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 Polreichaae1b9d2018-12-05 11:12:23 +01009 *
10**/
11
12def common = new com.mirantis.mk.Common()
13def salt = new com.mirantis.mk.Salt()
14def openstack = new com.mirantis.mk.Openstack()
15def python = new com.mirantis.mk.Python()
Martin Polreichaae1b9d2018-12-05 11:12:23 +010016def pepperEnv = "pepperEnv"
17def resultCode = 99
18
Martin Polreich0d538262019-02-01 14:46:10 +010019askConfirmation = (env.getProperty('ASK_CONFIRMATION') ?: true).toBoolean()
Sergeyc8a8a792019-01-15 17:27:59 +040020
Martin Polreich0d538262019-02-01 14:46:10 +010021if (common.validInputParam(VERIFICATION_RETRIES) && VERIFICATION_RETRIES.isInteger()) {
22 verificationRetries = VERIFICATION_RETRIES.toInteger()
23} else {
24 verificationRetries = 5
25}
26
Martin Polreichaae1b9d2018-12-05 11:12:23 +010027timeout(time: 12, unit: 'HOURS') {
28 node() {
29 stage('Setup virtualenv for Pepper') {
30 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
31 }
32 stage('Verify status')
33 resultCode = openstack.verifyGaleraStatus(pepperEnv, false)
34 stage('Restore') {
35 if (resultCode == 128) {
36 common.errorMsg("Unable to connect to Galera Master. Trying slaves...")
37 resultCode = openstack.verifyGaleraStatus(pepperEnv, true)
38 if (resultCode == 129) {
39 common.errorMsg("Unable to obtain Galera slave minions list". "Without fixing this issue, pipeline cannot continue in verification and restoration.")
40 currentBuild.result = "FAILURE"
Martin Polreich0d538262019-02-01 14:46:10 +010041 return
Martin Polreichaae1b9d2018-12-05 11:12:23 +010042 } else if (resultCode == 130) {
43 common.errorMsg("Neither master or slaves are reachable. Without fixing this issue, pipeline cannot continue in verification and restoration.")
44 currentBuild.result = "FAILURE"
Martin Polreich0d538262019-02-01 14:46:10 +010045 return
Martin Polreichaae1b9d2018-12-05 11:12:23 +010046 }
47 }
48 if (resultCode == 1) {
Sergeyc8a8a792019-01-15 17:27:59 +040049 if(askConfirmation){
50 common.warningMsg("There was a problem with parsing the status output or with determining it. Do you want to run a restore?")
51 } else {
52 common.warningMsg("There was a problem with parsing the status output or with determining it. Try to restore.")
53 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010054 } else if (resultCode > 1) {
Sergeyc8a8a792019-01-15 17:27:59 +040055 if(askConfirmation){
56 common.warningMsg("There's something wrong with the cluster, do you want to run a restore?")
57 } else {
58 common.warningMsg("There's something wrong with the cluster, try to restore.")
59 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010060 } else {
Sergeyc8a8a792019-01-15 17:27:59 +040061 if(askConfirmation){
62 common.warningMsg("There seems to be everything alright with the cluster, do you still want to run a restore?")
63 } else {
64 common.warningMsg("There seems to be everything alright with the cluster, do nothing")
65 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010066 }
Sergeyc8a8a792019-01-15 17:27:59 +040067 if(askConfirmation){
68 input message: "Are you sure you want to run a restore? Click to confirm"
69 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010070 try {
Sergeyc8a8a792019-01-15 17:27:59 +040071 if((!askConfirmation && resultCode > 0) || askConfirmation){
72 openstack.restoreGaleraDb(pepperEnv)
73 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010074 } catch (Exception e) {
75 common.errorMsg("Restoration process has failed.")
76 }
77 }
Martin Polreichc9466c72019-01-18 14:17:52 +010078 stage('Verify restoration result') {
Martin Polreich0d538262019-02-01 14:46:10 +010079 common.retry(verificationRetries, 15) {
Martin Polreich394091a2019-03-18 14:24:12 +010080 exitCode = openstack.verifyGaleraStatus(pepperEnv, false)
Martin Polreich0d538262019-02-01 14:46:10 +010081 if (exitCode >= 1) {
82 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.")
83 } else {
84 common.infoMsg("Restoration procedure seems to be successful. See verification report to be sure.")
85 currentBuild.result = "SUCCESS"
86 }
Martin Polreichc9466c72019-01-18 14:17:52 +010087 }
88 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010089 }
90}