Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 1 | /** |
| 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]. |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame^] | 7 | * ASK_CONFIRMATION Ask confirmation for restore |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 8 | * |
| 9 | **/ |
| 10 | |
| 11 | def common = new com.mirantis.mk.Common() |
| 12 | def salt = new com.mirantis.mk.Salt() |
| 13 | def openstack = new com.mirantis.mk.Openstack() |
| 14 | def python = new com.mirantis.mk.Python() |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 15 | def pepperEnv = "pepperEnv" |
| 16 | def resultCode = 99 |
| 17 | |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame^] | 18 | askConfirmation = (env.getProperty('ASK_CONFIRMATION') ?: true).toBoolean() |
| 19 | |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 20 | timeout(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 Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 34 | } 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 Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | if (resultCode == 1) { |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame^] | 40 | 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 Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 45 | } else if (resultCode > 1) { |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame^] | 46 | 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 Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 51 | } else { |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame^] | 52 | 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 Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 57 | } |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame^] | 58 | if(askConfirmation){ |
| 59 | input message: "Are you sure you want to run a restore? Click to confirm" |
| 60 | } |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 61 | try { |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame^] | 62 | if((!askConfirmation && resultCode > 0) || askConfirmation){ |
| 63 | openstack.restoreGaleraDb(pepperEnv) |
| 64 | } |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 65 | } catch (Exception e) { |
| 66 | common.errorMsg("Restoration process has failed.") |
| 67 | } |
| 68 | } |
Martin Polreich | 7bc654c | 2019-01-18 14:17:52 +0100 | [diff] [blame] | 69 | 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 Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 79 | } |
| 80 | } |