blob: 32f3962a401f7ab2b81b647216bf20bec9736fbe [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() {
11 stage('Setup virtualenv for Pepper') {
12 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
13 }
Martin Polreichf3fe83f2019-09-26 16:54:43 +020014 stage('Verify pillar for restore') {
15 if (restoreSaltMasterAndMaas) {
16 try {
Denis Egorenkoad3e8302019-10-31 16:41:53 +040017 def masterPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:master:initial_data').get('return')[0].values()[0]
18 if(masterPillar.isEmpty()) {
Martin Polreichf3fe83f2019-09-26 16:54:43 +020019 throw new Exception("Problem with salt-master pillar on 'I@salt:master' node.")
20 }
Denis Egorenkoad3e8302019-10-31 16:41:53 +040021 def minionPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:minion:initial_data').get('return')[0].values()[0]
22 if(minionPillar.isEmpty()) {
Martin Polreichf3fe83f2019-09-26 16:54:43 +020023 throw new Exception("Problem with salt-minion pillar on 'I@salt:master' node.")
24 }
Pavel Cizinsky2051e982019-04-08 13:07:04 +020025 }
Martin Polreichf3fe83f2019-09-26 16:54:43 +020026 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 Egorenkoad3e8302019-10-31 16:41:53 +040029 throw e
Pavel Cizinsky2051e982019-04-08 13:07:04 +020030 }
Martin Polreichf3fe83f2019-09-26 16:54:43 +020031 maasNodes = salt.getMinions(pepperEnv, 'I@maas:region')
Pavel Cizinsky2051e982019-04-08 13:07:04 +020032 }
Martin Polreichf3fe83f2019-09-26 16:54:43 +020033 if (!maasNodes.isEmpty()) {
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +040034 try {
Denis Egorenkoad3e8302019-10-31 16:41:53 +040035 def maaSPillar = salt.getPillar(pepperEnv, "I@maas:region", 'maas:region:database:initial_data').get('return')[0].values()[0]
36 if (maaSPillar.isEmpty()) {
Martin Polreichf3fe83f2019-09-26 16:54:43 +020037 throw new Exception("Problem with MaaS pillar on 'I@maas:region' node.")
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +040038 }
Pavel Cizinsky2051e982019-04-08 13:07:04 +020039 }
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +040040 catch (Exception e) {
41 common.errorMsg(e.getMessage())
Martin Polreichf3fe83f2019-09-26 16:54:43 +020042 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 +040043 throw e
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +040044 }
Martin Polreichf3fe83f2019-09-26 16:54:43 +020045 } 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 Egorenko5b6cdd92019-11-07 15:48:43 +040049 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 Egorenkodfc63642019-11-05 17:24:43 +040056 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 Polreichf3fe83f2019-09-26 16:54:43 +020060 }
Denis Egorenko5b6cdd92019-11-07 15:48:43 +040061 catch (Exception e) {
62 common.errorMsg(e.getMessage())
Denis Egorenkodfc63642019-11-05 17:24:43 +040063 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 +040064 throw e
65 }
66 } else {
67 restoreDogtag = false
68 common.warningMsg('Restore for Dogtag is enabled, but service itself is not present. Skipping...')
Martin Polreichf3fe83f2019-09-26 16:54:43 +020069 }
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 Polreichf3fe83f2019-09-26 16:54:43 +020099 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 Polreichf3fe83f2019-09-26 16:54:43 +0200101 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 Egorenkodfc63642019-11-05 17:24:43 +0400103 salt.cmdRun(pepperEnv, 'I@barbican:server', 'rm -rf /etc/barbican/alias')
Martin Polreichf3fe83f2019-09-26 16:54:43 +0200104 salt.runSaltProcessStep(pepperEnv, 'I@barbican:server', 'service.restart', 'apache2')
Pavel Cizinsky2051e982019-04-08 13:07:04 +0200105 }
Pavel Cizinsky2051e982019-04-08 13:07:04 +0200106 }
107 }
108}