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" |
Martin Polreich | d102917 | 2019-10-17 13:40:33 +0200 | [diff] [blame] | 5 | def maasNodes = [] |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 6 | def restoreSaltMasterAndMaas = (env.getProperty('RESTORE_SALTMASTER_AND_MAAS') ?: true).toBoolean() |
| 7 | def restoreDogtag = (env.getProperty('RESTORE_DOGTAG') ?: true).toBoolean() |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 8 | |
| 9 | timeout(time: 12, unit: 'HOURS') { |
| 10 | node() { |
| 11 | stage('Setup virtualenv for Pepper') { |
| 12 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 13 | } |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 14 | stage('Verify pillar for restore') { |
| 15 | if (restoreSaltMasterAndMaas) { |
| 16 | try { |
Denis Egorenko | ad3e830 | 2019-10-31 16:41:53 +0400 | [diff] [blame] | 17 | def masterPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:master:initial_data').get('return')[0].values()[0] |
| 18 | if(masterPillar.isEmpty()) { |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 19 | throw new Exception("Problem with salt-master pillar on 'I@salt:master' node.") |
| 20 | } |
Denis Egorenko | ad3e830 | 2019-10-31 16:41:53 +0400 | [diff] [blame] | 21 | def minionPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:minion:initial_data').get('return')[0].values()[0] |
| 22 | if(minionPillar.isEmpty()) { |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 23 | throw new Exception("Problem with salt-minion pillar on 'I@salt:master' node.") |
| 24 | } |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 25 | } |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 26 | catch (Exception e){ |
| 27 | common.errorMsg(e.getMessage()) |
| 28 | 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') |
Denis Egorenko | ad3e830 | 2019-10-31 16:41:53 +0400 | [diff] [blame] | 29 | throw e |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 30 | } |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 31 | maasNodes = salt.getMinions(pepperEnv, 'I@maas:region') |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 32 | } |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 33 | if (!maasNodes.isEmpty()) { |
Ivan Berezovskiy | 8428b8d | 2019-07-22 16:54:06 +0400 | [diff] [blame] | 34 | try { |
Denis Egorenko | ad3e830 | 2019-10-31 16:41:53 +0400 | [diff] [blame] | 35 | def maaSPillar = salt.getPillar(pepperEnv, "I@maas:region", 'maas:region:database:initial_data').get('return')[0].values()[0] |
| 36 | if (maaSPillar.isEmpty()) { |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 37 | throw new Exception("Problem with MaaS pillar on 'I@maas:region' node.") |
Ivan Berezovskiy | 8428b8d | 2019-07-22 16:54:06 +0400 | [diff] [blame] | 38 | } |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 39 | } |
Ivan Berezovskiy | 8428b8d | 2019-07-22 16:54:06 +0400 | [diff] [blame] | 40 | catch (Exception e) { |
| 41 | common.errorMsg(e.getMessage()) |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 42 | common.errorMsg('Please fix your pillar. For more information check docs: https://docs.mirantis.com/mcp/latest/mcp-operations-guide/backup-restore/maas-postgresql/backupninja-postgresql-restore.html') |
Denis Egorenko | ad3e830 | 2019-10-31 16:41:53 +0400 | [diff] [blame] | 43 | throw e |
Ivan Berezovskiy | 8428b8d | 2019-07-22 16:54:06 +0400 | [diff] [blame] | 44 | } |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 45 | } else { |
| 46 | common.warningMsg("No MaaS Pillar was found. You can ignore this if it's expected. Otherwise you should fix you pillar. Check: https://docs.mirantis.com/mcp/latest/mcp-operations-guide/backup-restore/maas-postgresql/backupninja-postgresql-restore.html") |
| 47 | } |
| 48 | if (restoreDogtag) { |
Denis Egorenko | 5b6cdd9 | 2019-11-07 15:48:43 +0400 | [diff] [blame] | 49 | def barbicanBackendPresent = salt.getPillar(pepperEnv, "I@salt:master", "_param:barbican_backend").get('return')[0].values()[0] |
| 50 | if (barbicanBackendPresent == 'dogtag') { |
| 51 | try { |
| 52 | def dogtagPillar = salt.getPillar(pepperEnv, "I@dogtag:server:role:master", 'dogtag:server:initial_data').get('return')[0].values()[0] |
| 53 | if (dogtagPillar.isEmpty()) { |
| 54 | throw new Exception("Problem with Dogtag pillar on 'I@dogtag:server:role:master' node.") |
| 55 | } |
Denis Egorenko | dfc6364 | 2019-11-05 17:24:43 +0400 | [diff] [blame] | 56 | def mineCertPresent = salt.runSaltProcessStep(pepperEnv, "I@dogtag:server:role:master", 'mine.get', ['*', 'dogtag_admin_cert'], null, false).get('return')[0].values()[0] |
| 57 | if (mineCertPresent.isEmpty()) { |
| 58 | throw new Exception("Problem with Dogtag Admin cert mine data on 'I@dogtag:server:role:master' node.") |
| 59 | } |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 60 | } |
Denis Egorenko | 5b6cdd9 | 2019-11-07 15:48:43 +0400 | [diff] [blame] | 61 | catch (Exception e) { |
| 62 | common.errorMsg(e.getMessage()) |
Denis Egorenko | dfc6364 | 2019-11-05 17:24:43 +0400 | [diff] [blame] | 63 | common.errorMsg('Please fix your pillar or missed mine data. For more information check docs: https://docs.mirantis.com/mcp/latest/mcp-operations-guide/backup-restore/dogtag/2.6-and-newer/restore-dogtag.html') |
Denis Egorenko | 5b6cdd9 | 2019-11-07 15:48:43 +0400 | [diff] [blame] | 64 | throw e |
| 65 | } |
| 66 | } else { |
| 67 | restoreDogtag = false |
| 68 | common.warningMsg('Restore for Dogtag is enabled, but service itself is not present. Skipping...') |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | } |
| 72 | stage('Restore') { |
| 73 | if (restoreSaltMasterAndMaas) { |
| 74 | common.infoMsg('Starting salt-master restore') |
| 75 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@salt:master', 'state': 'salt.master.restore']) |
| 76 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@salt:master', 'state': 'salt.minion.restore']) |
| 77 | salt.fullRefresh(pepperEnv, '*') |
| 78 | common.infoMsg('Validating output') |
| 79 | common.infoMsg('Salt-Keys') |
| 80 | salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key") |
| 81 | common.infoMsg('Salt-master CA') |
| 82 | salt.cmdRun(pepperEnv, 'I@salt:master', "ls -la /etc/pki/ca/salt_master_ca/") |
| 83 | if (!maasNodes.isEmpty()) { |
| 84 | common.infoMsg('Starting MaaS restore') |
| 85 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@maas:region', 'state': 'maas.region']) |
| 86 | } |
| 87 | } |
| 88 | if (restoreDogtag) { |
| 89 | salt.runSaltProcessStep(pepperEnv, 'I@dogtag:server:role:slave', 'service.stop', ['dirsrv@pki-tomcat.service']) |
| 90 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@dogtag:server:role:master', 'state': 'dogtag.server.restore']) |
| 91 | salt.runSaltProcessStep(pepperEnv, 'I@dogtag:server:role:slave', 'service.start', ['dirsrv@pki-tomcat.service']) |
| 92 | } |
| 93 | } |
| 94 | stage('After restore steps') { |
| 95 | if (restoreSaltMasterAndMaas) { |
| 96 | common.infoMsg("No more steps for Salt Master and MaaS restore are required.") |
| 97 | } |
| 98 | if (restoreDogtag) { |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 99 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@dogtag:server:role:master', 'state': 'dogtag.server']) |
| 100 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@dogtag:server', 'state': 'dogtag.server']) |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 101 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@barbican:server:role:primary', 'state': 'barbican.server']) |
| 102 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@barbican:server', 'state': 'barbican.server']) |
Denis Egorenko | dfc6364 | 2019-11-05 17:24:43 +0400 | [diff] [blame] | 103 | salt.cmdRun(pepperEnv, 'I@barbican:server', 'rm -rf /etc/barbican/alias') |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 104 | salt.runSaltProcessStep(pepperEnv, 'I@barbican:server', 'service.restart', 'apache2') |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 105 | } |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | } |