Martin Polreich | aae1b9d | 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]. |
Martin Polreich | 0d53826 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 7 | * ASK_CONFIRMATION Ask confirmation for restore |
Martin Polreich | 0d53826 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 8 | * VERIFICATION_RETRIES Number of restries to verify the restoration. |
Martin Polreich | aae1b9d | 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() |
| 16 | |
| 17 | def pepperEnv = "pepperEnv" |
| 18 | def resultCode = 99 |
| 19 | |
Martin Polreich | 0d53826 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 20 | askConfirmation = (env.getProperty('ASK_CONFIRMATION') ?: true).toBoolean() |
Martin Polreich | 0d53826 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 21 | if (common.validInputParam(VERIFICATION_RETRIES) && VERIFICATION_RETRIES.isInteger()) { |
| 22 | verificationRetries = VERIFICATION_RETRIES.toInteger() |
| 23 | } else { |
| 24 | verificationRetries = 5 |
| 25 | } |
| 26 | |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 27 | timeout(time: 12, unit: 'HOURS') { |
| 28 | node() { |
| 29 | stage('Setup virtualenv for Pepper') { |
| 30 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 31 | } |
| 32 | stage('Verify status') |
| 33 | resultCode = openstack.verifyGaleraStatus(pepperEnv, false) |
| 34 | stage('Restore') { |
| 35 | if (resultCode == 128) { |
| 36 | common.errorMsg("Unable to connect to Galera Master. Trying slaves...") |
| 37 | resultCode = openstack.verifyGaleraStatus(pepperEnv, true) |
| 38 | if (resultCode == 129) { |
| 39 | common.errorMsg("Unable to obtain Galera slave minions list". "Without fixing this issue, pipeline cannot continue in verification and restoration.") |
| 40 | currentBuild.result = "FAILURE" |
Martin Polreich | 0d53826 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 41 | return |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 42 | } else if (resultCode == 130) { |
| 43 | common.errorMsg("Neither master or slaves are reachable. Without fixing this issue, pipeline cannot continue in verification and restoration.") |
| 44 | currentBuild.result = "FAILURE" |
Martin Polreich | 0d53826 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 45 | return |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | if (resultCode == 1) { |
| 49 | common.warningMsg("There was a problem with parsing the status output or with determining it. Do you want to run a restore?") |
| 50 | } else if (resultCode > 1) { |
| 51 | common.warningMsg("There's something wrong with the cluster, do you want to run a restore?") |
| 52 | } else { |
| 53 | common.warningMsg("There seems to be everything alright with the cluster, do you still want to run a restore?") |
| 54 | } |
| 55 | input message: "Are you sure you want to run a restore? Click to confirm" |
| 56 | try { |
| 57 | openstack.restoreGaleraDb(pepperEnv) |
| 58 | } catch (Exception e) { |
| 59 | common.errorMsg("Restoration process has failed.") |
| 60 | } |
| 61 | } |
Martin Polreich | c9466c7 | 2019-01-18 14:17:52 +0100 | [diff] [blame] | 62 | stage('Verify restoration result') { |
Martin Polreich | 0d53826 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 63 | common.retry(verificationRetries, 15) { |
Martin Polreich | 394091a | 2019-03-18 14:24:12 +0100 | [diff] [blame] | 64 | exitCode = openstack.verifyGaleraStatus(pepperEnv, false) |
Martin Polreich | 0d53826 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 65 | if (exitCode >= 1) { |
| 66 | error("Verification attempt finished with an error. This may be caused by cluster not having enough time to come up or to sync. Next verification attempt in 5 seconds.") |
| 67 | } else { |
| 68 | common.infoMsg("Restoration procedure seems to be successful. See verification report to be sure.") |
| 69 | currentBuild.result = "SUCCESS" |
| 70 | } |
Martin Polreich | c9466c7 | 2019-01-18 14:17:52 +0100 | [diff] [blame] | 71 | } |
| 72 | } |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 73 | } |
| 74 | } |