| Pavel Cizinsky | aa2d21b | 2019-03-19 11:08:05 +0100 | [diff] [blame^] | 1 | def common = new com.mirantis.mk.Common() | 
 | 2 | def salt = new com.mirantis.mk.Salt() | 
 | 3 | def python = new com.mirantis.mk.Python() | 
 | 4 |  | 
 | 5 | timeout(time: 12, unit: 'HOURS') { | 
 | 6 |     node() { | 
 | 7 |         stage('Setup virtualenv for Pepper') { | 
 | 8 |             python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) | 
 | 9 |         } | 
 | 10 |         stage('Check backup location') { | 
 | 11 |             try{ | 
 | 12 |               backupNode = salt.getMinions(pepperEnv, "I@backupninja:client")[0] | 
 | 13 |               salt.minionsReachable(pepperEnv, "I@salt:master", backupNode) | 
 | 14 |             } | 
 | 15 |             catch (Exception e) { | 
 | 16 |                 common.errorMsg(e.getMessage()) | 
 | 17 |                 common.errorMsg("Pipeline wasn't able to detect backupninja:client pillar or the minion is not reachable") | 
 | 18 |                 currentBuild.result = "FAILURE" | 
 | 19 |                 return | 
 | 20 |             } | 
 | 21 |             try{ | 
 | 22 |               backupServer = salt.getMinions(pepperEnv, "I@backupninja:server")[0] | 
 | 23 |               salt.minionsReachable(pepperEnv, "I@salt:master", backupServer) | 
 | 24 |             } | 
 | 25 |             catch (Exception e) { | 
 | 26 |                 common.errorMsg(e.getMessage()) | 
 | 27 |                 common.errorMsg("Pipeline wasn't able to detect backupninja:server pillar or the minion is not reachable") | 
 | 28 |                 currentBuild.result = "FAILURE" | 
 | 29 |                 return | 
 | 30 |             } | 
 | 31 |         } | 
 | 32 |         stage ('Prepare for backup') { | 
 | 33 |                 salt.enforceState(['saltId': pepperEnv, 'target': 'I@backupninja:server', 'state': 'backupninja']) | 
 | 34 |                 salt.enforceState(['saltId': pepperEnv, 'target': 'I@backupninja:client', 'state': 'backupninja']) | 
 | 35 |         } | 
 | 36 |         stage('Backup') { | 
 | 37 |             output = salt.getReturnValues(salt.cmdRun(pepperEnv, backupNode, "su root -c 'backupninja --now -d'")).readLines()[-2] | 
 | 38 |             def outputPattern = java.util.regex.Pattern.compile("\\d+") | 
 | 39 |             def outputMatcher = outputPattern.matcher(output) | 
 | 40 |               if (outputMatcher.find()) { | 
 | 41 |                   try{ | 
 | 42 |                   result = outputMatcher.getAt([0,1,2,3]) | 
 | 43 |                   } | 
 | 44 |                   catch (Exception e){ | 
 | 45 |                     common.errorMsg(e.getMessage()) | 
 | 46 |                     common.errorMsg("Parsing failed.") | 
 | 47 |                     currentBuild.result = "FAILURE" | 
 | 48 |                     return | 
 | 49 |                   } | 
 | 50 |             } | 
 | 51 |             if (result[1] == 0 || result == ""){ | 
 | 52 |                 common.errorMsg("Backup failed.") | 
 | 53 |                 currentBuild.result = "FAILURE" | 
 | 54 |                 return | 
 | 55 |             } | 
 | 56 |             else { | 
 | 57 |               common.successMsg("Backup successfully finished " + result[1] + " fatals, " + result[2] + " errors " + result[3] +" warnings") | 
 | 58 |             } | 
 | 59 |         } | 
 | 60 |     } | 
 | 61 | } |