| 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', ['dirsrv@pki-tomcat.service']) |
| salt.enforceState(['saltId': pepperEnv, 'target': 'I@dogtag:server:role:master', 'state': 'dogtag.server.restore']) |
| salt.runSaltProcessStep(pepperEnv, 'I@dogtag:server:role:slave', 'service.start', ['dirsrv@pki-tomcat.service']) |
| } |
| 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') |
| } |
| } |
| } |
| } |