changeset 191:2650531d6d93

Reflecting shell parameter changes done in thermostat
author Zdenek Zambersky <zzambers@redhat.com>
date Tue, 14 Jul 2015 18:53:20 +0200
parents 7ffc366993b5
children 5d335809cd51
files src/org/thermostat/qa2/framework/utils/ThermostatUtilities.java
diffstat 1 files changed, 45 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/thermostat/qa2/framework/utils/ThermostatUtilities.java	Tue Jul 14 18:50:43 2015 +0200
+++ b/src/org/thermostat/qa2/framework/utils/ThermostatUtilities.java	Tue Jul 14 18:53:20 2015 +0200
@@ -266,6 +266,41 @@
         ProcessUtilities.shellRun("mv " + deployDir + File.separator + name + " " + deployedAppPath);
     }
 
+    /* Zero, negative or positive value is returned for first version equal to,
+       lower or higher than second */
+    public static int compareVersions(String version1, String version2) {
+        String version1lc = version1.toLowerCase();
+        String version2lc = version2.toLowerCase();
+
+        int index1;
+        int index2;
+        int index1Old = -1;
+        int index2Old = -1;
+        String component1;
+        String component2;
+        do {
+            index1 = version1.indexOf(".", index1Old + 1);
+            index2 = version2.indexOf(".", index2Old + 1);
+            component1 = index1 >= 0 ? version1lc.substring(index1Old + 1, index1) : version1lc.substring(index1Old + 1);
+            component2 = index2 >= 0 ? version2lc.substring(index2Old + 1, index2) : version2lc.substring(index2Old + 1);
+            if (!component1.equals(component2)) {
+                if (component1.equals("head")) {
+                    return 1;
+                }
+                if (component2.equals("head")) {
+                    return -1;
+                }
+                int sub = Integer.valueOf(component1) - Integer.valueOf(component2);
+                if (sub != 0) {
+                    return sub;
+                }
+            }
+            index1Old = index1;
+            index2Old = index2;
+        } while (index1 >= 0 && index2 >= 0);
+        return 0;
+    }
+
     /* Starts thermostat shell executes requested command in it,
      writes username/password, exits shell and returns output as line list */
     public static List<String> getShellCommandOutput(String target, String command) throws Exception {
@@ -354,7 +389,11 @@
     }
 
     public static List<String> killVm(String hostId, String vmId) throws Exception {
-        return getShellCommandOutput("tested", "kill-vm --vmId " + vmId + " --hostId " + hostId);
+        if (compareVersions(ThermostatQAConfig.getThermostatVersion("tested"), "head") == 0) {
+            return getShellCommandOutput("tested", "kill-vm --vmId " + vmId);
+        } else {
+            return getShellCommandOutput("tested", "kill-vm --vmId " + vmId + " --hostId " + hostId);
+        }
     }
 
     public static String getHeapDumpLine(String hostId, String vmId) throws Exception {
@@ -391,7 +430,11 @@
     }
 
     public static void dumpHeap(String target, String hostId, String vmId) throws Exception {
-        getShellCommandOutput(target, "dump-heap --hostId " + hostId + " --vmId " + vmId);
+        if (compareVersions(ThermostatQAConfig.getThermostatVersion(target), "head") == 0) {
+            getShellCommandOutput(target, "dump-heap --vmId " + vmId);
+        } else {
+            getShellCommandOutput(target, "dump-heap --hostId " + hostId + " --vmId " + vmId);
+        }
     }
 
     public static List<String> saveHeapDumpToFile(String heapId, String file) throws Exception {