blob: 0e374912fc5dfdb0869c3456a7ecdec52416d92b [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 Polreichf7a1bb02018-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 Polreichf7a1bb02018-12-05 11:12:23 +010016def pepperEnv = "pepperEnv"
17def resultCode = 99
18
Sergey6579de62019-01-15 17:27:59 +040019askConfirmation = (env.getProperty('ASK_CONFIRMATION') ?: true).toBoolean()
Martin Polreich721b7252019-01-21 14:42:48 +010020checkTimeSync = (env.getProperty('CHECK_TIME_SYNC') ?: true).toBoolean()
Sergey6579de62019-01-15 17:27:59 +040021
Martin Polreichf7a1bb02018-12-05 11:12:23 +010022timeout(time: 12, unit: 'HOURS') {
23 node() {
24 stage('Setup virtualenv for Pepper') {
25 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
26 }
27 stage('Verify status')
Martin Polreich721b7252019-01-21 14:42:48 +010028 resultCode = openstack.verifyGaleraStatus(pepperEnv, false, checkTimeSync)
Martin Polreichf7a1bb02018-12-05 11:12:23 +010029 stage('Restore') {
30 if (resultCode == 128) {
31 common.errorMsg("Unable to connect to Galera Master. Trying slaves...")
Martin Polreich721b7252019-01-21 14:42:48 +010032 resultCode = openstack.verifyGaleraStatus(pepperEnv, true, checkTimeSync)
Martin Polreichf7a1bb02018-12-05 11:12:23 +010033 if (resultCode == 129) {
34 common.errorMsg("Unable to obtain Galera slave minions list". "Without fixing this issue, pipeline cannot continue in verification and restoration.")
35 currentBuild.result = "FAILURE"
Martin Polreichf7a1bb02018-12-05 11:12:23 +010036 } else if (resultCode == 130) {
37 common.errorMsg("Neither master or slaves are reachable. Without fixing this issue, pipeline cannot continue in verification and restoration.")
38 currentBuild.result = "FAILURE"
Martin Polreichf7a1bb02018-12-05 11:12:23 +010039 }
40 }
Martin Polreich721b7252019-01-21 14:42:48 +010041 if (resultCode == 131) {
42 common.errorMsg("Time desynced - Click proceed when the issue is fixed or abort.")
43 currentBuild.result = "FAILURE"
44 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010045 if (resultCode == 1) {
Sergey6579de62019-01-15 17:27:59 +040046 if(askConfirmation){
47 common.warningMsg("There was a problem with parsing the status output or with determining it. Do you want to run a restore?")
48 } else {
49 common.warningMsg("There was a problem with parsing the status output or with determining it. Try to restore.")
50 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010051 } else if (resultCode > 1) {
Sergey6579de62019-01-15 17:27:59 +040052 if(askConfirmation){
53 common.warningMsg("There's something wrong with the cluster, do you want to run a restore?")
54 } else {
55 common.warningMsg("There's something wrong with the cluster, try to restore.")
56 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010057 } else {
Sergey6579de62019-01-15 17:27:59 +040058 if(askConfirmation){
59 common.warningMsg("There seems to be everything alright with the cluster, do you still want to run a restore?")
60 } else {
61 common.warningMsg("There seems to be everything alright with the cluster, do nothing")
62 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010063 }
Sergey6579de62019-01-15 17:27:59 +040064 if(askConfirmation){
65 input message: "Are you sure you want to run a restore? Click to confirm"
66 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010067 try {
Sergey6579de62019-01-15 17:27:59 +040068 if((!askConfirmation && resultCode > 0) || askConfirmation){
69 openstack.restoreGaleraDb(pepperEnv)
70 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010071 } catch (Exception e) {
72 common.errorMsg("Restoration process has failed.")
73 }
74 }
Martin Polreich7bc654c2019-01-18 14:17:52 +010075 stage('Verify restoration result') {
Martin Polreich721b7252019-01-21 14:42:48 +010076 exitCode = openstack.verifyGaleraStatus(pepperEnv, false, false)
Martin Polreich7bc654c2019-01-18 14:17:52 +010077 if (exitCode >= 1) {
78 common.errorMsg("Restoration procedure was probably not successful. See verification report for more information.")
79 currentBuild.result = "FAILURE"
80 } else {
81 common.infoMsg("Restoration procedure seems to be successful. See verification report to be sure.")
82 currentBuild.result = "SUCCESS"
83 }
84 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010085 }
86}