blob: 7a63858181b0bd52c10bfbdbba753c4c48d47a2e [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()
16
17def pepperEnv = "pepperEnv"
18def resultCode = 99
19
Martin Polreich0d538262019-02-01 14:46:10 +010020askConfirmation = (env.getProperty('ASK_CONFIRMATION') ?: true).toBoolean()
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) {
49 common.warningMsg("There was a problem with parsing the status output or with determining it. Do you want to run a restore?")
50 } else if (resultCode > 1) {
51 common.warningMsg("There's something wrong with the cluster, do you want to run a restore?")
52 } else {
53 common.warningMsg("There seems to be everything alright with the cluster, do you still want to run a restore?")
54 }
55 input message: "Are you sure you want to run a restore? Click to confirm"
56 try {
57 openstack.restoreGaleraDb(pepperEnv)
58 } catch (Exception e) {
59 common.errorMsg("Restoration process has failed.")
60 }
61 }
Martin Polreichc9466c72019-01-18 14:17:52 +010062 stage('Verify restoration result') {
Martin Polreich0d538262019-02-01 14:46:10 +010063 common.retry(verificationRetries, 15) {
Martin Polreich394091a2019-03-18 14:24:12 +010064 exitCode = openstack.verifyGaleraStatus(pepperEnv, false)
Martin Polreich0d538262019-02-01 14:46:10 +010065 if (exitCode >= 1) {
66 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.")
67 } else {
68 common.infoMsg("Restoration procedure seems to be successful. See verification report to be sure.")
69 currentBuild.result = "SUCCESS"
70 }
Martin Polreichc9466c72019-01-18 14:17:52 +010071 }
72 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010073 }
74}