blob: f617f1bb19be279cefe5cef24ccd1bde59812f2b [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()
Pavel Cizinsky2051e982019-04-08 13:07:04 +02008
9timeout(time: 12, unit: 'HOURS') {
10 node() {
Ivan Berezovskiy4f746f72019-10-30 18:56:02 +040011 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 Cizinsky2051e982019-04-08 13:07:04 +020015 stage('Setup virtualenv for Pepper') {
16 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
17 }
Martin Polreichf3fe83f2019-09-26 16:54:43 +020018 stage('Verify pillar for restore') {
19 if (restoreSaltMasterAndMaas) {
20 try {
Denis Egorenkoad3e8302019-10-31 16:41:53 +040021 def masterPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:master:initial_data').get('return')[0].values()[0]
22 if(masterPillar.isEmpty()) {
Martin Polreichf3fe83f2019-09-26 16:54:43 +020023 throw new Exception("Problem with salt-master pillar on 'I@salt:master' node.")
24 }
Denis Egorenkoad3e8302019-10-31 16:41:53 +040025 def minionPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:minion:initial_data').get('return')[0].values()[0]
26 if(minionPillar.isEmpty()) {
Martin Polreichf3fe83f2019-09-26 16:54:43 +020027 throw new Exception("Problem with salt-minion pillar on 'I@salt:master' node.")
28 }
Pavel Cizinsky2051e982019-04-08 13:07:04 +020029 }
Martin Polreichf3fe83f2019-09-26 16:54:43 +020030 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 Egorenkoad3e8302019-10-31 16:41:53 +040033 throw e
Pavel Cizinsky2051e982019-04-08 13:07:04 +020034 }
Martin Polreichf3fe83f2019-09-26 16:54:43 +020035 maasNodes = salt.getMinions(pepperEnv, 'I@maas:region')
Pavel Cizinsky2051e982019-04-08 13:07:04 +020036 }
Martin Polreichf3fe83f2019-09-26 16:54:43 +020037 if (!maasNodes.isEmpty()) {
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +040038 try {
Denis Egorenkoad3e8302019-10-31 16:41:53 +040039 def maaSPillar = salt.getPillar(pepperEnv, "I@maas:region", 'maas:region:database:initial_data').get('return')[0].values()[0]
40 if (maaSPillar.isEmpty()) {
Martin Polreichf3fe83f2019-09-26 16:54:43 +020041 throw new Exception("Problem with MaaS pillar on 'I@maas:region' node.")
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +040042 }
Pavel Cizinsky2051e982019-04-08 13:07:04 +020043 }
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +040044 catch (Exception e) {
45 common.errorMsg(e.getMessage())
Martin Polreichf3fe83f2019-09-26 16:54:43 +020046 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 +040047 throw e
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +040048 }
Martin Polreichf3fe83f2019-09-26 16:54:43 +020049 } 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 Egorenkoad3e8302019-10-31 16:41:53 +040054 def dogtagPillar = salt.getPillar(pepperEnv, "I@dogtag:server:role:master", 'dogtag:server:initial_data').get('return')[0].values()[0]
55 if (dogtagPillar.isEmpty()) {
Martin Polreichf3fe83f2019-09-26 16:54:43 +020056 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 Egorenkoad3e8302019-10-31 16:41:53 +040062 throw e
Martin Polreichf3fe83f2019-09-26 16:54:43 +020063 }
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 Cizinsky2051e982019-04-08 13:07:04 +0200101 }
Pavel Cizinsky2051e982019-04-08 13:07:04 +0200102 }
103 }
104}