-
Notifications
You must be signed in to change notification settings - Fork 46
/
backupninja-restore-pipeline.groovy
112 lines (111 loc) · 6.9 KB
/
backupninja-restore-pipeline.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
def common = new com.mirantis.mk.Common()
def salt = new com.mirantis.mk.Salt()
def python = new com.mirantis.mk.Python()
def pepperEnv = "pepperEnv"
def maasNodes = []
def restoreSaltMasterAndMaas = (env.getProperty('RESTORE_SALTMASTER_AND_MAAS') ?: true).toBoolean()
def restoreDogtag = (env.getProperty('RESTORE_DOGTAG') ?: true).toBoolean()
def restoreKeystone = (env.getProperty('RESTORE_KEYSTONE_CREDENTIAL_KEYS') ?: true).toBoolean()
timeout(time: 12, unit: 'HOURS') {
node() {
stage('Setup virtualenv for Pepper') {
python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
}
stage('Verify pillar for restore') {
if (restoreSaltMasterAndMaas) {
try {
def masterPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:master:initial_data').get('return')[0].values()[0]
if(masterPillar.isEmpty()) {
throw new Exception("Problem with salt-master pillar on 'I@salt:master' node.")
}
def minionPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:minion:initial_data').get('return')[0].values()[0]
if(minionPillar.isEmpty()) {
throw new Exception("Problem with salt-minion pillar on 'I@salt:master' node.")
}
}
catch (Exception e){
common.errorMsg(e.getMessage())
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')
throw e
}
maasNodes = salt.getMinions(pepperEnv, 'I@maas:region')
}
if (!maasNodes.isEmpty()) {
try {
def maaSPillar = salt.getPillar(pepperEnv, "I@maas:region", 'maas:region:database:initial_data').get('return')[0].values()[0]
if (maaSPillar.isEmpty()) {
throw new Exception("Problem with MaaS pillar on 'I@maas:region' node.")
}
}
catch (Exception e) {
common.errorMsg(e.getMessage())
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')
throw e
}
} else {
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")
}
if (restoreDogtag) {
def barbicanBackendPresent = salt.getPillar(pepperEnv, "I@salt:master", "_param:barbican_backend").get('return')[0].values()[0]
if (barbicanBackendPresent == 'dogtag') {
try {
def dogtagPillar = salt.getPillar(pepperEnv, "I@dogtag:server:role:master", 'dogtag:server:initial_data').get('return')[0].values()[0]
if (dogtagPillar.isEmpty()) {
throw new Exception("Problem with Dogtag pillar on 'I@dogtag:server:role:master' node.")
}
def mineCertPresent = salt.runSaltProcessStep(pepperEnv, "I@dogtag:server:role:master", 'mine.get', ['*', 'dogtag_admin_cert'], null, false).get('return')[0].values()[0]
if (mineCertPresent.isEmpty()) {
throw new Exception("Problem with Dogtag Admin cert mine data on 'I@dogtag:server:role:master' node.")
}
}
catch (Exception e) {
common.errorMsg(e.getMessage())
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')
throw e
}
} else {
restoreDogtag = false
common.warningMsg('Restore for Dogtag is enabled, but service itself is not present. Skipping...')
}
}
}
stage('Restore') {
if (restoreSaltMasterAndMaas) {
common.infoMsg('Starting salt-master restore')
salt.enforceState(['saltId': pepperEnv, 'target': 'I@salt:master', 'state': 'salt.master.restore'])
salt.enforceState(['saltId': pepperEnv, 'target': 'I@salt:master', 'state': 'salt.minion.restore'])
salt.fullRefresh(pepperEnv, '*')
common.infoMsg('Validating output')
common.infoMsg('Salt-Keys')
salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key")
common.infoMsg('Salt-master CA')
salt.cmdRun(pepperEnv, 'I@salt:master', "ls -la /etc/pki/ca/salt_master_ca/")
if (!maasNodes.isEmpty()) {
common.infoMsg('Starting MaaS restore')
salt.enforceState(['saltId': pepperEnv, 'target': 'I@maas:region', 'state': 'maas.region'])
}
}
if (restoreDogtag) {
salt.runSaltProcessStep(pepperEnv, 'I@dogtag:server:role:slave', 'service.stop', ['[email protected]'])
salt.enforceState(['saltId': pepperEnv, 'target': 'I@dogtag:server:role:master', 'state': 'dogtag.server.restore'])
salt.runSaltProcessStep(pepperEnv, 'I@dogtag:server:role:slave', 'service.start', ['[email protected]'])
}
if (restoreKeystone) {
salt.enforceState(['saltId': pepperEnv, 'target': 'I@keystone:server:role:primary', 'state': 'keystone.restore'])
}
}
stage('After restore steps') {
if (restoreSaltMasterAndMaas) {
common.infoMsg("No more steps for Salt Master and MaaS restore are required.")
}
if (restoreDogtag) {
salt.enforceState(['saltId': pepperEnv, 'target': 'I@dogtag:server:role:master', 'state': 'dogtag.server'])
salt.enforceState(['saltId': pepperEnv, 'target': 'I@dogtag:server', 'state': 'dogtag.server'])
salt.enforceState(['saltId': pepperEnv, 'target': 'I@barbican:server:role:primary', 'state': 'barbican.server'])
salt.enforceState(['saltId': pepperEnv, 'target': 'I@barbican:server', 'state': 'barbican.server'])
salt.cmdRun(pepperEnv, 'I@barbican:server', 'rm -rf /etc/barbican/alias')
salt.runSaltProcessStep(pepperEnv, 'I@barbican:server', 'service.restart', 'apache2')
}
}
}
}