Several fixes for backupninja pipelines
* Do not fail if maas is not enabled
* Add backup server to known_hosts, so scp will not fail
* Additional checks for pillar data
PROD-30107
PROD-30108
Change-Id: Id5043717220de80c25f9d80761c1ddfa0910b083
(cherry picked from commit 8428b8d59b5aa325892b177e94923b99f7172c1d)
diff --git a/backupninja-restore-pipeline.groovy b/backupninja-restore-pipeline.groovy
index b38cd6a..e412c96 100644
--- a/backupninja-restore-pipeline.groovy
+++ b/backupninja-restore-pipeline.groovy
@@ -2,6 +2,7 @@
def salt = new com.mirantis.mk.Salt()
def python = new com.mirantis.mk.Python()
def pepperEnv = "pepperEnv"
+def maasNodes
timeout(time: 12, unit: 'HOURS') {
node() {
@@ -11,7 +12,7 @@
stage('Salt-Master restore') {
common.infoMsg('Verify pillar for salt-master backups')
try {
- def masterPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:minion:initial_data')
+ def masterPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:master:initial_data')
if(masterPillar['return'].isEmpty()) {
throw new Exception('Problem with salt-master pillar.')
}
@@ -25,6 +26,7 @@
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')
return
}
+ maasNodes = salt.getMinions(pepperEnv, 'I@maas:server')
common.infoMsg('Performing 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'])
@@ -36,20 +38,22 @@
common.infoMsg('Salt-master CA')
salt.cmdRun(pepperEnv, 'I@salt:master', "ls -la /etc/pki/ca/salt_master_ca/")
}
- stage('MAAS Restore') {
- common.infoMsg('Verify pillar for MaaS backup')
- try {
- def maaSPillar = salt.getPillar(pepperEnv, "I@maas:server", 'maas:region:database:initial_data')
- if(maaSPillar['return'].isEmpty()) {
- throw new Exception('Problem with MaaS pillar.')
+ if (!maasNodes.isEmpty()) {
+ stage('MAAS Restore') {
+ common.infoMsg('Verify pillar for MaaS backup')
+ try {
+ def maaSPillar = salt.getPillar(pepperEnv, "I@maas:server", 'maas:region:database:initial_data')
+ if (maaSPillar['return'].isEmpty()) {
+ throw new Exception('Problem with MaaS pillar.')
+ }
}
+ 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/backupninja-postgresql/backupninja-postgresql-restore.html')
+ return
+ }
+ salt.enforceState(['saltId': pepperEnv, 'target': 'I@maas:region', 'state': 'maas.region'])
}
- 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/backupninja-postgresql/backupninja-postgresql-restore.html')
- return
- }
- salt.enforceState(['saltId': pepperEnv, 'target': 'I@maas:region', 'state': 'maas.region'])
}
}
}