blob: cbd1f43633e9b3877fb6f5e20f97cd84321d8dec [file] [log] [blame]
Pavel Cizinsky2051e982019-04-08 13:07:04 +02001def common = new com.mirantis.mk.Common()
2def salt = new com.mirantis.mk.Salt()
3def python = new com.mirantis.mk.Python()
Pavel Cizinsky32d8bc82019-04-24 10:24:30 +02004def pepperEnv = "pepperEnv"
Martin Polreichd1029172019-10-17 13:40:33 +02005def maasNodes = []
Martin Polreichf3fe83f2019-09-26 16:54:43 +02006def restoreSaltMasterAndMaas = (env.getProperty('RESTORE_SALTMASTER_AND_MAAS') ?: true).toBoolean()
7def restoreDogtag = (env.getProperty('RESTORE_DOGTAG') ?: true).toBoolean()
Oleksii Molchanov8d8bf172020-11-10 21:31:15 +02008def restoreKeystone = (env.getProperty('RESTORE_KEYSTONE_CREDENTIAL_KEYS') ?: true).toBoolean()
Pavel Cizinsky2051e982019-04-08 13:07:04 +02009
10timeout(time: 12, unit: 'HOURS') {
11 node() {
12 stage('Setup virtualenv for Pepper') {
13 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
14 }
Martin Polreichf3fe83f2019-09-26 16:54:43 +020015 stage('Verify pillar for restore') {
16 if (restoreSaltMasterAndMaas) {
17 try {
Denis Egorenkoad3e8302019-10-31 16:41:53 +040018 def masterPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:master:initial_data').get('return')[0].values()[0]
19 if(masterPillar.isEmpty()) {
Martin Polreichf3fe83f2019-09-26 16:54:43 +020020 throw new Exception("Problem with salt-master pillar on 'I@salt:master' node.")
21 }
Denis Egorenkoad3e8302019-10-31 16:41:53 +040022 def minionPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:minion:initial_data').get('return')[0].values()[0]
23 if(minionPillar.isEmpty()) {
Martin Polreichf3fe83f2019-09-26 16:54:43 +020024 throw new Exception("Problem with salt-minion pillar on 'I@salt:master' node.")
25 }
Pavel Cizinsky2051e982019-04-08 13:07:04 +020026 }
Martin Polreichf3fe83f2019-09-26 16:54:43 +020027 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 Egorenkoad3e8302019-10-31 16:41:53 +040030 throw e
Pavel Cizinsky2051e982019-04-08 13:07:04 +020031 }
Martin Polreichf3fe83f2019-09-26 16:54:43 +020032 maasNodes = salt.getMinions(pepperEnv, 'I@maas:region')
Pavel Cizinsky2051e982019-04-08 13:07:04 +020033 }
Martin Polreichf3fe83f2019-09-26 16:54:43 +020034 if (!maasNodes.isEmpty()) {
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +040035 try {
Denis Egorenkoad3e8302019-10-31 16:41:53 +040036 def maaSPillar = salt.getPillar(pepperEnv, "I@maas:region", 'maas:region:database:initial_data').get('return')[0].values()[0]
37 if (maaSPillar.isEmpty()) {
Martin Polreichf3fe83f2019-09-26 16:54:43 +020038 throw new Exception("Problem with MaaS pillar on 'I@maas:region' node.")
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +040039 }
Pavel Cizinsky2051e982019-04-08 13:07:04 +020040 }
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +040041 catch (Exception e) {
42 common.errorMsg(e.getMessage())
Martin Polreichf3fe83f2019-09-26 16:54:43 +020043 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 Egorenkoad3e8302019-10-31 16:41:53 +040044 throw e
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +040045 }
Martin Polreichf3fe83f2019-09-26 16:54:43 +020046 } 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 Egorenko5b6cdd92019-11-07 15:48:43 +040050 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 Egorenkodfc63642019-11-05 17:24:43 +040057 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 Polreichf3fe83f2019-09-26 16:54:43 +020061 }
Denis Egorenko5b6cdd92019-11-07 15:48:43 +040062 catch (Exception e) {
63 common.errorMsg(e.getMessage())
Denis Egorenkodfc63642019-11-05 17:24:43 +040064 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 Egorenko5b6cdd92019-11-07 15:48:43 +040065 throw e
66 }
67 } else {
68 restoreDogtag = false
69 common.warningMsg('Restore for Dogtag is enabled, but service itself is not present. Skipping...')
Martin Polreichf3fe83f2019-09-26 16:54:43 +020070 }
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 Molchanov8d8bf172020-11-10 21:31:15 +020094 if (restoreKeystone) {
95 salt.enforceState(['saltId': pepperEnv, 'target': 'I@keystone:server:role:primary', 'state': 'keystone.restore'])
96 }
Martin Polreichf3fe83f2019-09-26 16:54:43 +020097 }
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 Polreichf3fe83f2019-09-26 16:54:43 +0200103 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 Polreichf3fe83f2019-09-26 16:54:43 +0200105 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 Egorenkodfc63642019-11-05 17:24:43 +0400107 salt.cmdRun(pepperEnv, 'I@barbican:server', 'rm -rf /etc/barbican/alias')
Martin Polreichf3fe83f2019-09-26 16:54:43 +0200108 salt.runSaltProcessStep(pepperEnv, 'I@barbican:server', 'service.restart', 'apache2')
Pavel Cizinsky2051e982019-04-08 13:07:04 +0200109 }
Pavel Cizinsky2051e982019-04-08 13:07:04 +0200110 }
111 }
112}