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