add checkContains
This function can be used to simple checking if variables contains
keywords. It can handle situation when variable isn't defined or isn't
a string.
Change-Id: If6b667c2f86d353d6e0a7d0110fc5b3682ee996e
diff --git a/src/com/mirantis/mk/Common.groovy b/src/com/mirantis/mk/Common.groovy
index 768e180..c356da8 100644
--- a/src/com/mirantis/mk/Common.groovy
+++ b/src/com/mirantis/mk/Common.groovy
@@ -370,3 +370,25 @@
common.errorMsg("Failed to execute cmd: ${cmd}\n output: ${output}")
}
}
+
+/**
+ * Check variable contains keyword
+ * @param variable keywork is searched (contains) here
+ * @param keyword string to look for
+ * @return True if variable contains keyword (case insensitive), False if do not contains or any of input isn't a string
+ */
+
+def checkContains(variable, keyword) {
+ if (binding.variables.containsKey(variable)) {
+ v = binding.variables[variable]
+
+ if (v instanceof String && keyword instanceof String) {
+ return v.toLowerCase().contains(keyword.toLowerCase())
+ } else {
+ return False
+ }
+
+ } else {
+ return False
+ }
+}