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