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]. |
| 7 | * |
| 8 | **/ |
| 9 | |
| 10 | def common = new com.mirantis.mk.Common() |
| 11 | def salt = new com.mirantis.mk.Salt() |
| 12 | def openstack = new com.mirantis.mk.Openstack() |
| 13 | def python = new com.mirantis.mk.Python() |
| 14 | |
| 15 | def pepperEnv = "pepperEnv" |
| 16 | def resultCode = 99 |
| 17 | |
| 18 | timeout(time: 12, unit: 'HOURS') { |
| 19 | node() { |
| 20 | stage('Setup virtualenv for Pepper') { |
| 21 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 22 | } |
| 23 | stage('Verify status') |
| 24 | resultCode = openstack.verifyGaleraStatus(pepperEnv, false) |
| 25 | stage('Restore') { |
| 26 | if (resultCode == 128) { |
| 27 | common.errorMsg("Unable to connect to Galera Master. Trying slaves...") |
| 28 | resultCode = openstack.verifyGaleraStatus(pepperEnv, true) |
| 29 | if (resultCode == 129) { |
| 30 | common.errorMsg("Unable to obtain Galera slave minions list". "Without fixing this issue, pipeline cannot continue in verification and restoration.") |
| 31 | currentBuild.result = "FAILURE" |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 32 | } else if (resultCode == 130) { |
| 33 | common.errorMsg("Neither master or slaves are reachable. Without fixing this issue, pipeline cannot continue in verification and restoration.") |
| 34 | currentBuild.result = "FAILURE" |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | if (resultCode == 1) { |
| 38 | common.warningMsg("There was a problem with parsing the status output or with determining it. Do you want to run a restore?") |
| 39 | } else if (resultCode > 1) { |
| 40 | common.warningMsg("There's something wrong with the cluster, do you want to run a restore?") |
| 41 | } else { |
| 42 | common.warningMsg("There seems to be everything alright with the cluster, do you still want to run a restore?") |
| 43 | } |
| 44 | input message: "Are you sure you want to run a restore? Click to confirm" |
| 45 | try { |
| 46 | openstack.restoreGaleraDb(pepperEnv) |
| 47 | } catch (Exception e) { |
| 48 | common.errorMsg("Restoration process has failed.") |
| 49 | } |
| 50 | } |
Martin Polreich | 7bc654c | 2019-01-18 14:17:52 +0100 | [diff] [blame] | 51 | stage('Verify restoration result') { |
| 52 | exitCode = openstack.verifyGaleraStatus(pepperEnv, false) |
| 53 | if (exitCode >= 1) { |
| 54 | common.errorMsg("Restoration procedure was probably not successful. See verification report for more information.") |
| 55 | currentBuild.result = "FAILURE" |
| 56 | } else { |
| 57 | common.infoMsg("Restoration procedure seems to be successful. See verification report to be sure.") |
| 58 | currentBuild.result = "SUCCESS" |
| 59 | } |
| 60 | } |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 61 | } |
| 62 | } |