blob: e412c966d16ad9f6cb6a34058918b0bef1c67c85 [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"
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +04005def maasNodes
Pavel Cizinsky2051e982019-04-08 13:07:04 +02006
7timeout(time: 12, unit: 'HOURS') {
8 node() {
9 stage('Setup virtualenv for Pepper') {
10 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
11 }
12 stage('Salt-Master restore') {
13 common.infoMsg('Verify pillar for salt-master backups')
14 try {
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +040015 def masterPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:master:initial_data')
Pavel Cizinsky2051e982019-04-08 13:07:04 +020016 if(masterPillar['return'].isEmpty()) {
17 throw new Exception('Problem with salt-master pillar.')
18 }
19 def minionPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:minion:initial_data')
20 if(minionPillar['return'].isEmpty()) {
21 throw new Exception('Problem with salt-minion pillar.')
22 }
23 }
24 catch (Exception e){
25 common.errorMsg(e.getMessage())
26 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')
27 return
28 }
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +040029 maasNodes = salt.getMinions(pepperEnv, 'I@maas:server')
Pavel Cizinsky2051e982019-04-08 13:07:04 +020030 common.infoMsg('Performing restore')
31 salt.enforceState(['saltId': pepperEnv, 'target': 'I@salt:master', 'state': 'salt.master.restore'])
32 salt.enforceState(['saltId': pepperEnv, 'target': 'I@salt:master', 'state': 'salt.minion.restore'])
33 salt.fullRefresh(pepperEnv, '*')
34
35 common.infoMsg('Validating output')
36 common.infoMsg('Salt-Keys')
37 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key")
38 common.infoMsg('Salt-master CA')
39 salt.cmdRun(pepperEnv, 'I@salt:master', "ls -la /etc/pki/ca/salt_master_ca/")
40 }
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +040041 if (!maasNodes.isEmpty()) {
42 stage('MAAS Restore') {
43 common.infoMsg('Verify pillar for MaaS backup')
44 try {
45 def maaSPillar = salt.getPillar(pepperEnv, "I@maas:server", 'maas:region:database:initial_data')
46 if (maaSPillar['return'].isEmpty()) {
47 throw new Exception('Problem with MaaS pillar.')
48 }
Pavel Cizinsky2051e982019-04-08 13:07:04 +020049 }
Ivan Berezovskiy8428b8d2019-07-22 16:54:06 +040050 catch (Exception e) {
51 common.errorMsg(e.getMessage())
52 common.errorMsg('Please fix your pillar. For more information check docs: https://docs.mirantis.com/mcp/latest/mcp-operations-guide/backup-restore/backupninja-postgresql/backupninja-postgresql-restore.html')
53 return
54 }
55 salt.enforceState(['saltId': pepperEnv, 'target': 'I@maas:region', 'state': 'maas.region'])
Pavel Cizinsky2051e982019-04-08 13:07:04 +020056 }
Pavel Cizinsky2051e982019-04-08 13:07:04 +020057 }
58 }
59}