Moved pretty-printing to own function
Change-Id: I641fed7801975b04dcfc36b773d0f3b5900afb0d
diff --git a/src/com/mirantis/mk/Common.groovy b/src/com/mirantis/mk/Common.groovy
index b8e9756..fe82185 100644
--- a/src/com/mirantis/mk/Common.groovy
+++ b/src/com/mirantis/mk/Common.groovy
@@ -1,5 +1,7 @@
package com.mirantis.mk
+import static groovy.json.JsonOutput.prettyPrint
+import static groovy.json.JsonOutput.toJson
/**
*
* Common functions
@@ -87,6 +89,15 @@
}
/**
+ * Return pretty-printed string representation of given item
+ * @param item item to be pretty-printed (list, map, whatever)
+ * @return pretty-printed string
+ */
+def prettyPrint(item){
+ return prettyPrint(toJson(item)).replace('\\n', System.getProperty('line.separator'))
+}
+
+/**
* Print informational message
*
* @param msg
diff --git a/src/com/mirantis/mk/Salt.groovy b/src/com/mirantis/mk/Salt.groovy
index 149d938..4b83d33 100644
--- a/src/com/mirantis/mk/Salt.groovy
+++ b/src/com/mirantis/mk/Salt.groovy
@@ -1,8 +1,5 @@
package com.mirantis.mk
-import static groovy.json.JsonOutput.prettyPrint
-import static groovy.json.JsonOutput.toJson
-
/**
* Salt functions
*
@@ -302,7 +299,7 @@
common.debugMsg("checkResult: checking resource: ${resource}")
if(resource instanceof String || !resource["result"] || (resource["result"] instanceof String && resource["result"] != "true")){
if(askOnError){
- def prettyResource = prettyPrint(toJson(resource)).replace('\\n', System.getProperty('line.separator'));
+ def prettyResource = common.prettyPrint(resource)
timeout(time:1, unit:'HOURS') {
input message: "False result on ${nodeKey} found, resource ${prettyResource}. \nDo you want to continue?"
}
@@ -366,21 +363,21 @@
if(!resource["result"] || (resource["result"] instanceof String && resource["result"] != "true")){
if(resource["result"] != null){
- common.errorMsg(String.format("Resource: %s\n%s", resKey, prettyPrint(toJson(resource)).replace('\\n', System.getProperty('line.separator'))))
+ common.errorMsg(String.format("Resource: %s\n%s", resKey, common.prettyPrint(resource)))
}else{
- common.warningMsg(String.format("Resource: %s\n%s", resKey, prettyPrint(toJson(resource)).replace('\\n', System.getProperty('line.separator'))))
+ common.warningMsg(String.format("Resource: %s\n%s", resKey, common.prettyPrint(resource)))
}
}else{
if(!onlyChanges || resource.changes.size() > 0){
- common.successMsg(String.format("Resource: %s\n%s", resKey, prettyPrint(toJson(resource)).replace('\\n', System.getProperty('line.separator'))))
+ common.successMsg(String.format("Resource: %s\n%s", resKey, common.prettyPrint(resource)))
}
}
}else{
- common.infoMsg(String.format("Resource: %s\n%s", resKey, prettyPrint(toJson(resource)).replace('\\n', System.getProperty('line.separator'))))
+ common.infoMsg(String.format("Resource: %s\n%s", resKey, common.prettyPrint(resource)))
}
}
}else{
- common.infoMsg(prettyPrint(toJson(node)))
+ common.infoMsg(common.prettyPrint(node))
}
}
}
@@ -407,7 +404,7 @@
common.debugMsg("printSaltCommandResult: printing salt command entry: ${entry}")
def nodeKey = entry.keySet()[j]
def node=entry[nodeKey]
- common.infoMsg(String.format("Node %s changes:\n%s",nodeKey,prettyPrint(toJson(node)).replace('\\n', System.getProperty('line.separator'))))
+ common.infoMsg(String.format("Node %s changes:\n%s",nodeKey, common.prettyPrint(node)))
}
}
}else{