Fix pillar check conditions for backupninja pipelines

Also throw error in try-catch block instead of return.

Change-Id: I3646a50a7736f6721125ee82ccdafb27e82c2b23
Related-Prod: PROD-33911
diff --git a/backupninja-backup-pipeline.groovy b/backupninja-backup-pipeline.groovy
index 1fdd181..74f38e6 100644
--- a/backupninja-backup-pipeline.groovy
+++ b/backupninja-backup-pipeline.groovy
@@ -44,32 +44,32 @@
         stage('Verify pillar for backups') {
             if (backupSaltMasterAndMaas) {
                 try {
-                    def masterPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:master:initial_data')
-                    if (masterPillar['return'].isEmpty()) {
+                    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')
-                    if (minionPillar['return'].isEmpty()) {
+                    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.html')
-                    return
+                    throw e
                 }
             }
             if (backupDogtag) {
                 try {
-                    def dogtagPillar = salt.getPillar(pepperEnv, "I@salt:master", "dogtag:server")
-                    if (dogtagPillar['return'].isEmpty()) {
+                    def dogtagPillar = salt.getPillar(pepperEnv, "I@dogtag:server", "dogtag:server").get('return')[0].values()[0]
+                    if (dogtagPillar.isEmpty()) {
                         throw new Exception("Problem with dogtag pillar on I@dogtag:server node.")
                     }
                 }
                 catch (Exception e) {
                     common.errorMsg(e.getMessage())
                     common.errorMsg("Looks like dogtag pillar is not defined. Fix your pillar or disable dogtag backup by setting the BACKUP_DOGTAG parameter to False if you're using different barbican backend.")
-                    return
+                    throw e
                 }
             }
         }
@@ -83,7 +83,7 @@
                     common.errorMsg(e.getMessage())
                     common.errorMsg("Pipeline wasn't able to detect backupninja:client pillar on Salt master node or the minion is not reachable")
                     currentBuild.result = "FAILURE"
-                    return
+                    throw e
                 }
 
                 def maasNodes = salt.getMinions(pepperEnv, 'I@maas:region')
@@ -124,7 +124,7 @@
                     common.errorMsg(e.getMessage())
                     common.errorMsg("Pipeline wasn't able to detect node with backupninja:client and dogtag:server pillars defined or the minion is not reachable")
                     currentBuild.result = "FAILURE"
-                    return
+                    throw e
                 }
             }
 
@@ -136,7 +136,7 @@
                 common.errorMsg(e.getMessage())
                 common.errorMsg("Pipeline wasn't able to detect backupninja:server pillar or the minion is not reachable")
                 currentBuild.result = "FAILURE"
-                return
+                throw e
             }
         }
         stage('Prepare for backup') {
diff --git a/backupninja-restore-pipeline.groovy b/backupninja-restore-pipeline.groovy
index 6deb919..f617f1b 100644
--- a/backupninja-restore-pipeline.groovy
+++ b/backupninja-restore-pipeline.groovy
@@ -18,48 +18,48 @@
         stage('Verify pillar for restore') {
             if (restoreSaltMasterAndMaas) {
                 try {
-                    def masterPillar = salt.getPillar(pepperEnv, "I@salt:master", 'salt:master:initial_data')
-                    if(masterPillar['return'].isEmpty()) {
+                    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')
-                    if(minionPillar['return'].isEmpty()) {
+                    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')
-                    return
+                    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')
-                    if (maaSPillar['return'].isEmpty()) {
+                    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')
-                    return
+                    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) {
                 try {
-                    def dogtagPillar = salt.getPillar(pepperEnv, "I@dogtag:server:role:master", 'dogtag:server:initial_data')
-                    if (dogtagPillar['return'].isEmpty()) {
+                    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.")
                     }
                 }
                 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/dogtag/restore-dogtag.html')
-                    return
+                    throw e
                 }
             }
         }