blob: 7e5c20b5e52926cb8386659d894b7a2e247f2bb4 [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 Polreichf7a1bb02018-12-05 11:12:23 +01008 *
9**/
10
11def common = new com.mirantis.mk.Common()
12def salt = new com.mirantis.mk.Salt()
13def openstack = new com.mirantis.mk.Openstack()
14def python = new com.mirantis.mk.Python()
Martin Polreichf7a1bb02018-12-05 11:12:23 +010015def pepperEnv = "pepperEnv"
16def resultCode = 99
17
Sergey6579de62019-01-15 17:27:59 +040018askConfirmation = (env.getProperty('ASK_CONFIRMATION') ?: true).toBoolean()
19
Martin Polreichf7a1bb02018-12-05 11:12:23 +010020timeout(time: 12, unit: 'HOURS') {
21 node() {
22 stage('Setup virtualenv for Pepper') {
23 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
24 }
25 stage('Verify status')
26 resultCode = openstack.verifyGaleraStatus(pepperEnv, false)
27 stage('Restore') {
28 if (resultCode == 128) {
29 common.errorMsg("Unable to connect to Galera Master. Trying slaves...")
30 resultCode = openstack.verifyGaleraStatus(pepperEnv, true)
31 if (resultCode == 129) {
32 common.errorMsg("Unable to obtain Galera slave minions list". "Without fixing this issue, pipeline cannot continue in verification and restoration.")
33 currentBuild.result = "FAILURE"
Martin Polreichf7a1bb02018-12-05 11:12:23 +010034 } else if (resultCode == 130) {
35 common.errorMsg("Neither master or slaves are reachable. Without fixing this issue, pipeline cannot continue in verification and restoration.")
36 currentBuild.result = "FAILURE"
Martin Polreichf7a1bb02018-12-05 11:12:23 +010037 }
38 }
39 if (resultCode == 1) {
Sergey6579de62019-01-15 17:27:59 +040040 if(askConfirmation){
41 common.warningMsg("There was a problem with parsing the status output or with determining it. Do you want to run a restore?")
42 } else {
43 common.warningMsg("There was a problem with parsing the status output or with determining it. Try to restore.")
44 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010045 } else if (resultCode > 1) {
Sergey6579de62019-01-15 17:27:59 +040046 if(askConfirmation){
47 common.warningMsg("There's something wrong with the cluster, do you want to run a restore?")
48 } else {
49 common.warningMsg("There's something wrong with the cluster, try to restore.")
50 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010051 } else {
Sergey6579de62019-01-15 17:27:59 +040052 if(askConfirmation){
53 common.warningMsg("There seems to be everything alright with the cluster, do you still want to run a restore?")
54 } else {
55 common.warningMsg("There seems to be everything alright with the cluster, do nothing")
56 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010057 }
Sergey6579de62019-01-15 17:27:59 +040058 if(askConfirmation){
59 input message: "Are you sure you want to run a restore? Click to confirm"
60 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010061 try {
Sergey6579de62019-01-15 17:27:59 +040062 if((!askConfirmation && resultCode > 0) || askConfirmation){
63 openstack.restoreGaleraDb(pepperEnv)
64 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010065 } catch (Exception e) {
66 common.errorMsg("Restoration process has failed.")
67 }
68 }
Martin Polreich7bc654c2019-01-18 14:17:52 +010069 stage('Verify restoration result') {
70 exitCode = openstack.verifyGaleraStatus(pepperEnv, false)
71 if (exitCode >= 1) {
72 common.errorMsg("Restoration procedure was probably not successful. See verification report for more information.")
73 currentBuild.result = "FAILURE"
74 } else {
75 common.infoMsg("Restoration procedure seems to be successful. See verification report to be sure.")
76 currentBuild.result = "SUCCESS"
77 }
78 }
Martin Polreichf7a1bb02018-12-05 11:12:23 +010079 }
80}