Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 1 | def common = new com.mirantis.mk.Common() |
| 2 | def salt = new com.mirantis.mk.Salt() |
| 3 | def python = new com.mirantis.mk.Python() |
Pavel Cizinsky | 32d8bc8 | 2019-04-24 10:24:30 +0200 | [diff] [blame] | 4 | def pepperEnv = "pepperEnv" |
Ivan Berezovskiy | 8428b8d | 2019-07-22 16:54:06 +0400 | [diff] [blame^] | 5 | def maasNodes |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 6 | |
| 7 | timeout(time: 12, unit: 'HOURS') { |
| 8 | node() { |
| 9 | stage('Setup virtualenv for Pepper') { |
| 10 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 11 | } |
| 12 | stage('Salt-Master restore') { |
| 13 | common.infoMsg('Verify pillar for salt-master backups') |
| 14 | try { |
Ivan Berezovskiy | 8428b8d | 2019-07-22 16:54:06 +0400 | [diff] [blame^] | 15 | def masterPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:master:initial_data') |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 16 | if(masterPillar['return'].isEmpty()) { |
| 17 | throw new Exception('Problem with salt-master pillar.') |
| 18 | } |
| 19 | def minionPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:minion:initial_data') |
| 20 | if(minionPillar['return'].isEmpty()) { |
| 21 | throw new Exception('Problem with salt-minion pillar.') |
| 22 | } |
| 23 | } |
| 24 | catch (Exception e){ |
| 25 | common.errorMsg(e.getMessage()) |
| 26 | common.errorMsg('Please fix your pillar. For more information check docs: https://docs.mirantis.com/mcp/latest/mcp-operations-guide/backup-restore/salt-master/salt-master-restore.html') |
| 27 | return |
| 28 | } |
Ivan Berezovskiy | 8428b8d | 2019-07-22 16:54:06 +0400 | [diff] [blame^] | 29 | maasNodes = salt.getMinions(pepperEnv, 'I@maas:server') |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 30 | common.infoMsg('Performing restore') |
| 31 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@salt:master', 'state': 'salt.master.restore']) |
| 32 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@salt:master', 'state': 'salt.minion.restore']) |
| 33 | salt.fullRefresh(pepperEnv, '*') |
| 34 | |
| 35 | common.infoMsg('Validating output') |
| 36 | common.infoMsg('Salt-Keys') |
| 37 | salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key") |
| 38 | common.infoMsg('Salt-master CA') |
| 39 | salt.cmdRun(pepperEnv, 'I@salt:master', "ls -la /etc/pki/ca/salt_master_ca/") |
| 40 | } |
Ivan Berezovskiy | 8428b8d | 2019-07-22 16:54:06 +0400 | [diff] [blame^] | 41 | if (!maasNodes.isEmpty()) { |
| 42 | stage('MAAS Restore') { |
| 43 | common.infoMsg('Verify pillar for MaaS backup') |
| 44 | try { |
| 45 | def maaSPillar = salt.getPillar(pepperEnv, "I@maas:server", 'maas:region:database:initial_data') |
| 46 | if (maaSPillar['return'].isEmpty()) { |
| 47 | throw new Exception('Problem with MaaS pillar.') |
| 48 | } |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 49 | } |
Ivan Berezovskiy | 8428b8d | 2019-07-22 16:54:06 +0400 | [diff] [blame^] | 50 | catch (Exception e) { |
| 51 | common.errorMsg(e.getMessage()) |
| 52 | common.errorMsg('Please fix your pillar. For more information check docs: https://docs.mirantis.com/mcp/latest/mcp-operations-guide/backup-restore/backupninja-postgresql/backupninja-postgresql-restore.html') |
| 53 | return |
| 54 | } |
| 55 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@maas:region', 'state': 'maas.region']) |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 56 | } |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | } |