blob: c98c3364a4fc185b48e8371366b80c6b4b60e9d6 [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
8 * CHECK_TIME_SYNC Set to true to check time synchronization accross selected nodes.
9 * VERIFICATION_RETRIES Number of restries to verify the restoration.
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()
17
18def pepperEnv = "pepperEnv"
19def resultCode = 99
20
Martin Polreich0d538262019-02-01 14:46:10 +010021askConfirmation = (env.getProperty('ASK_CONFIRMATION') ?: true).toBoolean()
22checkTimeSync = (env.getProperty('CHECK_TIME_SYNC') ?: true).toBoolean()
23if (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')
35 resultCode = openstack.verifyGaleraStatus(pepperEnv, false)
36 stage('Restore') {
37 if (resultCode == 128) {
38 common.errorMsg("Unable to connect to Galera Master. Trying slaves...")
39 resultCode = openstack.verifyGaleraStatus(pepperEnv, true)
40 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 }
50 if (resultCode == 1) {
51 common.warningMsg("There was a problem with parsing the status output or with determining it. Do you want to run a restore?")
52 } else if (resultCode > 1) {
53 common.warningMsg("There's something wrong with the cluster, do you want to run a restore?")
54 } else {
55 common.warningMsg("There seems to be everything alright with the cluster, do you still want to run a restore?")
56 }
57 input message: "Are you sure you want to run a restore? Click to confirm"
58 try {
59 openstack.restoreGaleraDb(pepperEnv)
60 } catch (Exception e) {
61 common.errorMsg("Restoration process has failed.")
62 }
63 }
Martin Polreichc9466c72019-01-18 14:17:52 +010064 stage('Verify restoration result') {
Martin Polreich0d538262019-02-01 14:46:10 +010065 common.retry(verificationRetries, 15) {
66 exitCode = openstack.verifyGaleraStatus(pepperEnv, false, false)
67 if (exitCode >= 1) {
68 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.")
69 } else {
70 common.infoMsg("Restoration procedure seems to be successful. See verification report to be sure.")
71 currentBuild.result = "SUCCESS"
72 }
Martin Polreichc9466c72019-01-18 14:17:52 +010073 }
74 }
Martin Polreichaae1b9d2018-12-05 11:12:23 +010075 }
76}