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() { |
Ivan Berezovskiy | 4f746f7 | 2019-10-30 18:56:02 +0400 | [diff] [blame] | 11 | if (restoreDogtag) { |
| 12 | common.warningMsg("Dogtag restore does not work and disabled by default. For more information check the docs https://docs.mirantis.com/mcp/q4-18/mcp-operations-guide/backup-restore.html") |
| 13 | } |
| 14 | restoreDogtag = false |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 15 | stage('Setup virtualenv for Pepper') { |
| 16 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 17 | } |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 18 | stage('Verify pillar for restore') { |
| 19 | if (restoreSaltMasterAndMaas) { |
| 20 | try { |
Denis Egorenko | ad3e830 | 2019-10-31 16:41:53 +0400 | [diff] [blame^] | 21 | def masterPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:master:initial_data').get('return')[0].values()[0] |
| 22 | if(masterPillar.isEmpty()) { |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 23 | throw new Exception("Problem with salt-master pillar on 'I@salt:master' node.") |
| 24 | } |
Denis Egorenko | ad3e830 | 2019-10-31 16:41:53 +0400 | [diff] [blame^] | 25 | def minionPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:minion:initial_data').get('return')[0].values()[0] |
| 26 | if(minionPillar.isEmpty()) { |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 27 | throw new Exception("Problem with salt-minion pillar on 'I@salt:master' node.") |
| 28 | } |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 29 | } |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 30 | catch (Exception e){ |
| 31 | common.errorMsg(e.getMessage()) |
| 32 | 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^] | 33 | throw e |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 34 | } |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 35 | maasNodes = salt.getMinions(pepperEnv, 'I@maas:region') |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 36 | } |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 37 | if (!maasNodes.isEmpty()) { |
Ivan Berezovskiy | 8428b8d | 2019-07-22 16:54:06 +0400 | [diff] [blame] | 38 | try { |
Denis Egorenko | ad3e830 | 2019-10-31 16:41:53 +0400 | [diff] [blame^] | 39 | def maaSPillar = salt.getPillar(pepperEnv, "I@maas:region", 'maas:region:database:initial_data').get('return')[0].values()[0] |
| 40 | if (maaSPillar.isEmpty()) { |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 41 | throw new Exception("Problem with MaaS pillar on 'I@maas:region' node.") |
Ivan Berezovskiy | 8428b8d | 2019-07-22 16:54:06 +0400 | [diff] [blame] | 42 | } |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 43 | } |
Ivan Berezovskiy | 8428b8d | 2019-07-22 16:54:06 +0400 | [diff] [blame] | 44 | catch (Exception e) { |
| 45 | common.errorMsg(e.getMessage()) |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 46 | 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^] | 47 | throw e |
Ivan Berezovskiy | 8428b8d | 2019-07-22 16:54:06 +0400 | [diff] [blame] | 48 | } |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 49 | } else { |
| 50 | 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") |
| 51 | } |
| 52 | if (restoreDogtag) { |
| 53 | try { |
Denis Egorenko | ad3e830 | 2019-10-31 16:41:53 +0400 | [diff] [blame^] | 54 | def dogtagPillar = salt.getPillar(pepperEnv, "I@dogtag:server:role:master", 'dogtag:server:initial_data').get('return')[0].values()[0] |
| 55 | if (dogtagPillar.isEmpty()) { |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 56 | throw new Exception("Problem with Dogtag pillar on 'I@dogtag:server:role:master' node.") |
| 57 | } |
| 58 | } |
| 59 | catch (Exception e) { |
| 60 | common.errorMsg(e.getMessage()) |
| 61 | common.errorMsg('Please fix your pillar. For more information check docs: https://docs.mirantis.com/mcp/latest/mcp-operations-guide/backup-restore/dogtag/restore-dogtag.html') |
Denis Egorenko | ad3e830 | 2019-10-31 16:41:53 +0400 | [diff] [blame^] | 62 | throw e |
Martin Polreich | f3fe83f | 2019-09-26 16:54:43 +0200 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | } |
| 66 | stage('Restore') { |
| 67 | if (restoreSaltMasterAndMaas) { |
| 68 | common.infoMsg('Starting salt-master restore') |
| 69 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@salt:master', 'state': 'salt.master.restore']) |
| 70 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@salt:master', 'state': 'salt.minion.restore']) |
| 71 | salt.fullRefresh(pepperEnv, '*') |
| 72 | common.infoMsg('Validating output') |
| 73 | common.infoMsg('Salt-Keys') |
| 74 | salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key") |
| 75 | common.infoMsg('Salt-master CA') |
| 76 | salt.cmdRun(pepperEnv, 'I@salt:master', "ls -la /etc/pki/ca/salt_master_ca/") |
| 77 | if (!maasNodes.isEmpty()) { |
| 78 | common.infoMsg('Starting MaaS restore') |
| 79 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@maas:region', 'state': 'maas.region']) |
| 80 | } |
| 81 | } |
| 82 | if (restoreDogtag) { |
| 83 | salt.runSaltProcessStep(pepperEnv, 'I@dogtag:server:role:slave', 'service.stop', ['dirsrv@pki-tomcat.service']) |
| 84 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@dogtag:server:role:master', 'state': 'dogtag.server.restore']) |
| 85 | salt.runSaltProcessStep(pepperEnv, 'I@dogtag:server:role:slave', 'service.start', ['dirsrv@pki-tomcat.service']) |
| 86 | } |
| 87 | } |
| 88 | stage('After restore steps') { |
| 89 | if (restoreSaltMasterAndMaas) { |
| 90 | common.infoMsg("No more steps for Salt Master and MaaS restore are required.") |
| 91 | } |
| 92 | if (restoreDogtag) { |
| 93 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@salt:master', 'state': ['salt', 'reclass']]) |
| 94 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@dogtag:server:role:master', 'state': 'dogtag.server']) |
| 95 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@dogtag:server', 'state': 'dogtag.server']) |
| 96 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@haproxy:proxy', 'state': 'haproxy']) |
| 97 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@barbican:server:role:primary', 'state': 'barbican.server']) |
| 98 | salt.enforceState(['saltId': pepperEnv, 'target': 'I@barbican:server', 'state': 'barbican.server']) |
| 99 | salt.cmdRun(pepperEnv, 'I@barbican:server', 'rm /etc/barbican/alias/*') |
| 100 | salt.runSaltProcessStep(pepperEnv, 'I@barbican:server', 'service.restart', 'apache2') |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 101 | } |
Pavel Cizinsky | 2051e98 | 2019-04-08 13:07:04 +0200 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | } |