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 | 721b725 | 2019-01-21 14:42:48 +0100 | [diff] [blame] | 8 | * CHECK_TIME_SYNC Set to true to check time synchronization accross selected nodes. |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 9 | * |
| 10 | **/ |
| 11 | |
| 12 | def common = new com.mirantis.mk.Common() |
| 13 | def salt = new com.mirantis.mk.Salt() |
| 14 | def openstack = new com.mirantis.mk.Openstack() |
| 15 | def python = new com.mirantis.mk.Python() |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 16 | def pepperEnv = "pepperEnv" |
| 17 | def resultCode = 99 |
| 18 | |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 19 | askConfirmation = (env.getProperty('ASK_CONFIRMATION') ?: true).toBoolean() |
Martin Polreich | 721b725 | 2019-01-21 14:42:48 +0100 | [diff] [blame] | 20 | checkTimeSync = (env.getProperty('CHECK_TIME_SYNC') ?: true).toBoolean() |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 21 | |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 22 | timeout(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 Polreich | 721b725 | 2019-01-21 14:42:48 +0100 | [diff] [blame] | 28 | resultCode = openstack.verifyGaleraStatus(pepperEnv, false, checkTimeSync) |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 29 | stage('Restore') { |
| 30 | if (resultCode == 128) { |
| 31 | common.errorMsg("Unable to connect to Galera Master. Trying slaves...") |
Martin Polreich | 721b725 | 2019-01-21 14:42:48 +0100 | [diff] [blame] | 32 | resultCode = openstack.verifyGaleraStatus(pepperEnv, true, checkTimeSync) |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 33 | 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 Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 36 | } 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 Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 39 | } |
| 40 | } |
Martin Polreich | 721b725 | 2019-01-21 14:42:48 +0100 | [diff] [blame] | 41 | if (resultCode == 131) { |
| 42 | common.errorMsg("Time desynced - Click proceed when the issue is fixed or abort.") |
| 43 | currentBuild.result = "FAILURE" |
| 44 | } |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 45 | if (resultCode == 1) { |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 46 | 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 Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 51 | } else if (resultCode > 1) { |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 52 | 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 Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 57 | } else { |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 58 | 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 Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 63 | } |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 64 | if(askConfirmation){ |
| 65 | input message: "Are you sure you want to run a restore? Click to confirm" |
| 66 | } |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 67 | try { |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 68 | if((!askConfirmation && resultCode > 0) || askConfirmation){ |
| 69 | openstack.restoreGaleraDb(pepperEnv) |
| 70 | } |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 71 | } catch (Exception e) { |
| 72 | common.errorMsg("Restoration process has failed.") |
| 73 | } |
| 74 | } |
Martin Polreich | 7bc654c | 2019-01-18 14:17:52 +0100 | [diff] [blame] | 75 | stage('Verify restoration result') { |
Martin Polreich | 721b725 | 2019-01-21 14:42:48 +0100 | [diff] [blame] | 76 | exitCode = openstack.verifyGaleraStatus(pepperEnv, false, false) |
Martin Polreich | 7bc654c | 2019-01-18 14:17:52 +0100 | [diff] [blame] | 77 | 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 Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 85 | } |
| 86 | } |