Move yaml helpers to common module

Change-Id: I99ca47817b9d6913cd240d1533d68f74916a342c
diff --git a/src/com/mirantis/mcp/Calico.groovy b/src/com/mirantis/mcp/Calico.groovy
index 165eaf7..834ccd8 100644
--- a/src/com/mirantis/mcp/Calico.groovy
+++ b/src/com/mirantis/mcp/Calico.groovy
@@ -1,21 +1,5 @@
 package com.mirantis.mcp
 
-@Grab(group='org.yaml', module='snakeyaml', version='1.17')
-import org.yaml.snakeyaml.Yaml
-
-
-@NonCPS
-def loadYaml(String rawYaml) {
-  def yaml = new Yaml()
-  return yaml.load(rawYaml)
-}
-
-@NonCPS
-def dumpYaml(Map yamlMap) {
-  def yaml = new Yaml()
-  return yaml.dump(yamlMap)
-}
-
 
 /**
  * Checkout Calico repository stage
@@ -361,6 +345,7 @@
  *
  */
 def switchCalicoToDownstreamLibcalicoGo(String libCalicoGoCommit, String host, String glideLockFilePath) {
+  def common = new com.mirantis.mcp.Common()
   def git = new com.mirantis.mcp.Git()
 
   stage ('Switch to downstream libcalico-go') {
@@ -377,7 +362,7 @@
 
     sh "cp ${glideLockFilePath} ${glideLockFilePath}.bak"
     def glideLockFileContent = readFile file: glideLockFilePath
-    def glideMap = loadYaml(glideLockFileContent)
+    def glideMap = common.loadYAML(glideLockFileContent)
 
     for (goImport in glideMap['imports']) {
       if (goImport['name'].contains('libcalico-go')) {
@@ -386,7 +371,7 @@
       }
     }
 
-    writeFile file: glideLockFilePath, text: dumpYaml(glideMap)
+    writeFile file: glideLockFilePath, text: common.dumpYAML(glideMap)
 
     sh "LIBCALICOGO_PATH=${libcalicogo_path} make vendor"
   }
diff --git a/src/com/mirantis/mcp/Common.groovy b/src/com/mirantis/mcp/Common.groovy
index cc48fdc..597809c 100644
--- a/src/com/mirantis/mcp/Common.groovy
+++ b/src/com/mirantis/mcp/Common.groovy
@@ -1,5 +1,8 @@
 package com.mirantis.mcp
 
+@Grab(group='org.yaml', module='snakeyaml', version='1.17')
+import org.yaml.snakeyaml.Yaml
+
 /**
  * https://issues.jenkins-ci.org/browse/JENKINS-26481
  * fix groovy List.collect()
@@ -32,6 +35,26 @@
 }
 
 /**
+ * Convert YAML document to Map object
+ * @param data YAML string
+ */
+@NonCPS
+def loadYAML(String data) {
+  def yaml = new Yaml()
+  return yaml.load(data)
+}
+
+/**
+ * Convert Map object to YAML string
+ * @param map Map object
+ */
+@NonCPS
+def dumpYAML(Map map) {
+  def yaml = new Yaml()
+  return yaml.dump(map)
+}
+
+/**
  * Run function on k8s cluster
  *
  * @param config LinkedHashMap