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