blob: 524907239b8142ecac16846c5ae58d7e483a57b1 [file] [log] [blame]
Pavel Cizinskyade22482019-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()
4def pepperEnv = "pepperEnv"
Martin Polreich31618f92019-10-17 13:42:47 +02005def maasNodes = []
Martin Polreichf3094752019-09-26 16:54:43 +02006def restoreSaltMasterAndMaas = (env.getProperty('RESTORE_SALTMASTER_AND_MAAS') ?: true).toBoolean()
7def restoreDogtag = (env.getProperty('RESTORE_DOGTAG') ?: true).toBoolean()
Pavel Cizinskyade22482019-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 Polreichf3094752019-09-26 16:54:43 +020014 stage('Verify pillar for restore') {
15 if (restoreSaltMasterAndMaas) {
16 try {
17 def masterPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:master:initial_data')
18 if(masterPillar['return'].isEmpty()) {
19 throw new Exception("Problem with salt-master pillar on 'I@salt:master' node.")
20 }
21 def minionPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:minion:initial_data')
22 if(minionPillar['return'].isEmpty()) {
23 throw new Exception("Problem with salt-minion pillar on 'I@salt:master' node.")
24 }
Pavel Cizinskyade22482019-04-08 13:07:04 +020025 }
Martin Polreichf3094752019-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')
29 return
Pavel Cizinskyade22482019-04-08 13:07:04 +020030 }
Martin Polreichf3094752019-09-26 16:54:43 +020031 maasNodes = salt.getMinions(pepperEnv, 'I@maas:region')
Pavel Cizinskyade22482019-04-08 13:07:04 +020032 }
Martin Polreichf3094752019-09-26 16:54:43 +020033 if (!maasNodes.isEmpty()) {
Ivan Berezovskiy2219bf42019-07-22 16:54:06 +040034 try {
Ivan Berezovskiy8b903172019-08-09 19:19:40 +040035 def maaSPillar = salt.getPillar(pepperEnv, "I@maas:region", 'maas:region:database:initial_data')
Ivan Berezovskiy2219bf42019-07-22 16:54:06 +040036 if (maaSPillar['return'].isEmpty()) {
Martin Polreichf3094752019-09-26 16:54:43 +020037 throw new Exception("Problem with MaaS pillar on 'I@maas:region' node.")
Ivan Berezovskiy2219bf42019-07-22 16:54:06 +040038 }
Pavel Cizinskyade22482019-04-08 13:07:04 +020039 }
Ivan Berezovskiy2219bf42019-07-22 16:54:06 +040040 catch (Exception e) {
41 common.errorMsg(e.getMessage())
Martin Polreichf3094752019-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')
Ivan Berezovskiy2219bf42019-07-22 16:54:06 +040043 return
44 }
Martin Polreichf3094752019-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) {
49 try {
50 def dogtagPillar = salt.getPillar(pepperEnv, "I@dogtag:server:role:master", 'dogtag:server:initial_data')
51 if (dogtagPillar['return'].isEmpty()) {
52 throw new Exception("Problem with Dogtag pillar on 'I@dogtag:server:role:master' node.")
53 }
54 }
55 catch (Exception e) {
56 common.errorMsg(e.getMessage())
57 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')
58 return
59 }
60 }
61 }
62 stage('Restore') {
63 if (restoreSaltMasterAndMaas) {
64 common.infoMsg('Starting salt-master restore')
65 salt.enforceState(['saltId': pepperEnv, 'target': 'I@salt:master', 'state': 'salt.master.restore'])
66 salt.enforceState(['saltId': pepperEnv, 'target': 'I@salt:master', 'state': 'salt.minion.restore'])
67 salt.fullRefresh(pepperEnv, '*')
68 common.infoMsg('Validating output')
69 common.infoMsg('Salt-Keys')
70 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key")
71 common.infoMsg('Salt-master CA')
72 salt.cmdRun(pepperEnv, 'I@salt:master', "ls -la /etc/pki/ca/salt_master_ca/")
73 if (!maasNodes.isEmpty()) {
74 common.infoMsg('Starting MaaS restore')
75 salt.enforceState(['saltId': pepperEnv, 'target': 'I@maas:region', 'state': 'maas.region'])
76 }
77 }
78 if (restoreDogtag) {
79 salt.runSaltProcessStep(pepperEnv, 'I@dogtag:server:role:slave', 'service.stop', ['dirsrv@pki-tomcat.service'])
80 salt.enforceState(['saltId': pepperEnv, 'target': 'I@dogtag:server:role:master', 'state': 'dogtag.server.restore'])
81 salt.runSaltProcessStep(pepperEnv, 'I@dogtag:server:role:slave', 'service.start', ['dirsrv@pki-tomcat.service'])
82 }
83 }
84 stage('After restore steps') {
85 if (restoreSaltMasterAndMaas) {
86 common.infoMsg("No more steps for Salt Master and MaaS restore are required.")
87 }
88 if (restoreDogtag) {
89 salt.enforceState(['saltId': pepperEnv, 'target': 'I@salt:master', 'state': ['salt', 'reclass']])
90 salt.enforceState(['saltId': pepperEnv, 'target': 'I@dogtag:server:role:master', 'state': 'dogtag.server'])
91 salt.enforceState(['saltId': pepperEnv, 'target': 'I@dogtag:server', 'state': 'dogtag.server'])
92 salt.enforceState(['saltId': pepperEnv, 'target': 'I@haproxy:proxy', 'state': 'haproxy'])
93 salt.enforceState(['saltId': pepperEnv, 'target': 'I@barbican:server:role:primary', 'state': 'barbican.server'])
94 salt.enforceState(['saltId': pepperEnv, 'target': 'I@barbican:server', 'state': 'barbican.server'])
95 salt.cmdRun(pepperEnv, 'I@barbican:server', 'rm /etc/barbican/alias/*')
96 salt.runSaltProcessStep(pepperEnv, 'I@barbican:server', 'service.restart', 'apache2')
Pavel Cizinskyade22482019-04-08 13:07:04 +020097 }
Pavel Cizinskyade22482019-04-08 13:07:04 +020098 }
99 }
100}