changeset 203:a74aa91ab44c

Fixed setup/gnome-keyring/collections + added debugging changes: org.thermostat.qa2.framework.services.GnomeKeyring: - changed way how gnome-keyring is started (+ now encrypted) org.thermostat.qa2.framework.services.ShellService: - fix for arguments with spaces org.thermostat.qa2.framework.services.ThermostatAgent: org.thermostat.qa2.framework.services.ThermostatGui: org.thermostat.qa2.framework.services.ThermostatService: org.thermostat.qa2.framework.services.ThermostatStorage: - thermostat is now started with collection enabled when configured. org.thermostat.qa2.framework.utils.FileUtilities: - copyFile method now operates recursively on directories org.thermostat.qa2.framework.utils.ProcessUtilities: - new helper functions to run command witch collection enabled, handle arguments with spaces org.thermostat.qa2.framework.utils.ThermostatUtilities: - fixed method performing thermostat setup - new helper functions to get thermostat command line, passing of credentials removed from shell helper function org.thermostat.qa2.framework.NativeProcess: - logging of command which has arguments with spaces fixed org.thermostat.qa2.framework.TestRunner: - changes related to thermostat setup, gnome-keyring startup - added support for debugging org.thermostat.qa2.framework.ThermostatQAConfig: Makefile: - support of new properties required for debugging, gnome-keyring, collections support org.thermostat.qa2.framework.tests.*: - changes to tests which operate on thermostat shell, credentials no longer needed (use keyring)
author Zdenek Zambersky <zzambers@redhat.com>
date Mon, 30 Nov 2015 19:08:04 +0100
parents b82b8bc167ed
children 1b447165fbd0
files Makefile src/org/thermostat/qa2/framework/NativeProcess.java src/org/thermostat/qa2/framework/TestRunner.java src/org/thermostat/qa2/framework/ThermostatQAConfig.java src/org/thermostat/qa2/framework/annotations/SetupStorage.java src/org/thermostat/qa2/framework/services/GnomeKeyring.java src/org/thermostat/qa2/framework/services/ShellService.java src/org/thermostat/qa2/framework/services/ThermostatAgent.java src/org/thermostat/qa2/framework/services/ThermostatGui.java src/org/thermostat/qa2/framework/services/ThermostatService.java src/org/thermostat/qa2/framework/services/ThermostatStorage.java src/org/thermostat/qa2/framework/utils/FileUtilities.java src/org/thermostat/qa2/framework/utils/ProcessUtilities.java src/org/thermostat/qa2/framework/utils/ThermostatUtilities.java src/org/thermostat/qa2/tests/CliClientAgentInfoTest.java src/org/thermostat/qa2/tests/CliClientDBModifWebStorageTest.java src/org/thermostat/qa2/tests/CliClientDBModificationsSmokeTest.java src/org/thermostat/qa2/tests/CommandChannelSmokeTest.java src/org/thermostat/qa2/tests/CommandChannelWebStorageTest.java src/org/thermostat/qa2/tests/ShellCommandsTest.java
diffstat 20 files changed, 318 insertions(+), 122 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Tue Sep 22 18:43:48 2015 +0200
+++ b/Makefile	Mon Nov 30 19:08:04 2015 +0100
@@ -46,6 +46,7 @@
 THERMOSTAT_HOME_DIR=$(THERMOSTAT_DIR)/distribution/target/image
 THERMOSTAT_WEB_DEPLOY_DIR=$(TOMCAT_DIR)/webapps/thermostat
 THERMOSTAT_PACKAGED=false
+THERMOSTAT_COLLECTION=false
 THERMOSTAT_WEBSTORAGE_PORT=8080
 
 # refers to thermostat against which compatibility is tested
@@ -68,6 +69,9 @@
 KILL_DAEMONS=0
 
 DATE=`date +%Y-%0m-%0d`
+
+DEBUG=false
+DEBUG_DIR=debug
 	
 # all *.java files in src directory
 ALL_SOURCES = $(shell find src -name *.java | tr '\n' ' ')
@@ -126,16 +130,22 @@
 	mkdir -p $(SCREENSHOTS_DIR)
 	mkdir -p $(LOGS_DIR)
 	mkdir -p $(LOGS_DIR)/$(DATE)
+	if [ $(DEBUG) = true ] ; then \
+		mkdir -p $(DEBUG_DIR)/$@ ; \
+	fi ; \
 	USER_THERMOSTAT_HOME=$(THERMOSTAT_USER_DIR) \
 	$(JAVA) -cp $(CLASSES_DIR) \
 	-Dthermostat.user.home=$(THERMOSTAT_USER_DIR) \
 	-Dthermostat.version=$(THERMOSTAT_VERSION) \
 	-Dthermostat.home=$(THERMOSTAT_HOME_DIR) \
 	-Dthermostat.packaged=$(THERMOSTAT_PACKAGED) \
+	-Dthermostat.collection=$(THERMOSTAT_COLLECTION) \
 	-Dthermostat.webstorage.port=$(THERMOSTAT_WEBSTORAGE_PORT) \
 	-Dtomcat.home=$(TOMCAT_DIR) \
 	-Dgnome-keyring.config.dir=$(GNOME_KEYRING_USER_DATA_DIR) \
 	-Dbackup.dir=$(BUILD_DIR)/backup \
+	-Dtqa.debug=$(DEBUG) \
+	-Dtqa.debug.dir=$(DEBUG_DIR)/$@ \
 	org.thermostat.qa2.framework.TestRunner org.thermostat.qa2.tests.$@ 2>&1 | tee $(LOGS_DIR)/$(DATE)/$@.log
 
 .PHONY: run-compatibility-tests
@@ -154,6 +164,7 @@
 	-Dthermostat.version=$(THERMOSTAT_VERSION) \
 	-Dthermostat.home=$(THERMOSTAT_HOME_DIR) \
 	-Dthermostat.packaged=$(THERMOSTAT_PACKAGED) \
+	-Dthermostat.collection=$(THERMOSTAT_COLLECTION) \
 	-Dthermostat.other.version=$(THERMOSTAT_OTHER_VERSION) \
 	-Dthermostat.other.home=$(THERMOSTAT_OTHER_HOME_DIR) \
 	-Dthermostat.webstorage.port=$(THERMOSTAT_WEBSTORAGE_PORT) \
@@ -173,6 +184,7 @@
 	-Dthermostat.version=$(THERMOSTAT_VERSION) \
 	-Dthermostat.home=$(THERMOSTAT_HOME_DIR) \
 	-Dthermostat.packaged=$(THERMOSTAT_PACKAGED) \
+	-Dthermostat.collection=$(THERMOSTAT_COLLECTION) \
 	-Dthermostat.webstorage.port=$(THERMOSTAT_WEBSTORAGE_PORT) \
 	-Dtomcat.home=$(TOMCAT_DIR) \
 	-Dgnome-keyring.config.dir=$(GNOME_KEYRING_USER_DATA_DIR) \
--- a/src/org/thermostat/qa2/framework/NativeProcess.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/framework/NativeProcess.java	Mon Nov 30 19:08:04 2015 +0100
@@ -40,6 +40,7 @@
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import org.thermostat.qa2.framework.utils.ProcessUtilities;
 
 /**
  *
@@ -112,7 +113,7 @@
         } else {
             logger.setPrefix(label);
         }
-        logger.log(commands);
+        logger.log(ProcessUtilities.getArgsString(commands));
         process = processBuilder.start();
         startLogging();
     }
--- a/src/org/thermostat/qa2/framework/TestRunner.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/framework/TestRunner.java	Mon Nov 30 19:08:04 2015 +0100
@@ -30,16 +30,20 @@
  */
 package org.thermostat.qa2.framework;
 
+import java.io.File;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import org.thermostat.qa2.framework.ThermostatQAConfig.Login;
 import org.thermostat.qa2.framework.annotations.*;
 import org.thermostat.qa2.framework.services.*;
 import org.thermostat.qa2.framework.utils.AnnotationUtilities;
 import org.thermostat.qa2.framework.utils.CommonUtilities;
+import org.thermostat.qa2.framework.utils.FileUtilities;
+import org.thermostat.qa2.framework.utils.ProcessUtilities;
 import org.thermostat.qa2.framework.utils.ThermostatUtilities;
 
 /**
@@ -135,6 +139,21 @@
                         System.out.println("INFO: thrown: " + e);
                         result = afterSetup ? TestResult.FAILED : TestResult.ERROR;
                     } finally {
+                        if (ThermostatQAConfig.isDebugMode()) {
+                            try {
+                                if (ThermostatUtilities.isWebStorageConfigured()) {
+                                    // save thermostat logs
+                                    String tomcatLogsDir = ThermostatQAConfig.getTomcatHome() + File.separator + "logs";
+                                    if (new File(tomcatLogsDir).exists()) {
+                                        debugStore(m, tomcatLogsDir, "tomcat-logs");
+                                    }
+                                }
+                                // save keyring configuration
+                                String keyringDir = ThermostatQAConfig.getGnomeKeyringConfigDir() + File.separator + "keyrings";
+                                debugStore(m, keyringDir, "keyrings");
+                            } catch (Exception e) {
+                            }
+                        }
                         CommonUtilities.printHeading("Running automatic cleanup: ...");
                         runServiceCleanups();
                     }
@@ -194,6 +213,14 @@
 
         String setupTarget = setupTargetA.value();
 
+        // start gnome keyring
+        if (startGnomeKeyring) {
+            String keyringDir = ThermostatQAConfig.getGnomeKeyringConfigDir() + File.separator + "keyrings";
+            FileUtilities.removeFile(keyringDir);
+            ProcessUtilities.run("mkdir", "-p", keyringDir);
+            GnomeKeyring keyring = new GnomeKeyring();
+            keyring.start();
+        }
         // setup storage
         if (setupStorage) {
             String storageType = setupStorageA.type();
@@ -202,8 +229,21 @@
             boolean badClientLogin = setupStorageA.badClientLogin();
             boolean agentSaveOnExit = setupStorageA.agentSaveOnExit();
             ThermostatUtilities.setupThermostat(setupTarget, web, badAgentLogin, badClientLogin, agentSaveOnExit, true, false);
+
+            if (ThermostatQAConfig.isDebugMode()) {
+                try {
+                    // save thermostat user home and etc dirs
+                    debugStore(testMethod, ThermostatQAConfig.getThermostatUserHome(), "thermostat-user-home");
+                    debugStore(testMethod, ThermostatQAConfig.getThermostatHome(setupTarget) + File.separator + "etc", "etc");
+                    // remove db from saved thermostat user home as it has ~160MB
+                    FileUtilities.removeFile(ThermostatQAConfig.getDebugDir() + File.separator
+                            + testMethod.getName() + File.separator
+                            + "thermostat-user-home" + File.separator
+                            + "data" + File.separator + "db");
+                } catch (Exception e) {
+                }
+            }
         }
-        
         // start storage
         if (startStorage) {
             String storageType = setupStorageA.type();
@@ -220,11 +260,6 @@
             ThermostatAgent agent = new ThermostatAgent(setupTarget);
             agent.start();
         }
-        // start gnome keyring
-        if (startGnomeKeyring) {
-            GnomeKeyring keyring = new GnomeKeyring();
-            keyring.start();
-        }
         // start gui
         if (startGui) {
             ThermostatGui gui = new ThermostatGui(setupTarget);
@@ -232,6 +267,13 @@
         }
     }
 
+    public static void debugStore(Method m, String src, String name) throws Exception {
+        String methodName = m.getName();
+        String debugDir = ThermostatQAConfig.getDebugDir() + File.separator + methodName;
+        ProcessUtilities.run("mkdir", "-p", debugDir);
+        FileUtilities.copyFile(src, debugDir + File.separator + name);
+    }
+
     public static void registerServiceCleanup(Service service) {
         services.add(service);
     }
--- a/src/org/thermostat/qa2/framework/ThermostatQAConfig.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/framework/ThermostatQAConfig.java	Mon Nov 30 19:08:04 2015 +0100
@@ -33,6 +33,9 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
+import org.thermostat.qa2.framework.utils.CommonUtilities;
 import org.thermostat.qa2.framework.utils.FileUtilities;
 import org.thermostat.qa2.framework.utils.ThermostatUtilities;
 
@@ -52,6 +55,9 @@
     public static String logsDir;
     public static String reportDir;
 
+    public static boolean debug;
+    public static String debugDir;
+
     public static Login mongoLogin = new Login("mongodevuser", "mongodevpassword");
     public static Login agentLogin = new Login("agent-tester", "heslo1");
     public static Login clientLogin = new Login("client-tester", "heslo2");
@@ -66,6 +72,8 @@
     public static String thermostatUserHome;
     public static String thermostatVersion;
     public static boolean thermostatPackaged;
+    public static boolean useCollection;
+    public static String collectionName = "thermostat1";
 
     //////////////////////
     // other thermostat //
@@ -90,7 +98,11 @@
         thermostatOtherVersion = System.getProperty("thermostat.other.version");
         thermostatOtherHome = System.getProperty("thermostat.other.home");
 
-        gnomeKeyringConfigDir = System.getProperty("gnome-keyring.config.dir");
+        if (isRhel6()) {
+            gnomeKeyringConfigDir = System.getProperty("user.home") + File.separator + ".gnome2";
+        } else {
+            gnomeKeyringConfigDir = System.getProperty("gnome-keyring.config.dir");
+        }
         backupDir = System.getProperty("backup.dir");
 
         logsDir = System.getProperty("logs.dir");
@@ -98,6 +110,14 @@
 
         String packaged = System.getProperty("thermostat.packaged");
         thermostatPackaged = packaged != null && packaged.toLowerCase().equals("true");
+
+        String collection = System.getProperty("thermostat.collection");
+        useCollection = collection != null && collection.toLowerCase().equals("true");
+
+        String debugString = System.getProperty("tqa.debug");
+        debug = debugString != null && debugString.toLowerCase().equals("true");
+
+        debugDir = System.getProperty("tqa.debug.dir");
     }
 
     static String getPatternsDir() {
@@ -218,6 +238,40 @@
         return web ? "http://127.0.0.1:" + webStoragePort + "/thermostat/storage" : "mongodb://127.0.0.1:" + mongoPort;
     }
 
+    public static boolean isCollectionUsed() {
+        return useCollection;
+    }
+
+    public static String getCollectionName() {
+        return collectionName;
+    }
+
+    public static boolean isDebugMode() {
+        return debug;
+    }
+
+    public static String getDebugDir() {
+        return debugDir;
+    }
+
+    public static String getGnomeKeyringConfigDir() {
+        return gnomeKeyringConfigDir;
+    }
+
+    public static List<String> getReleaseLines() {
+        List<String> lines = new ArrayList();
+        try {
+            FileUtilities.addLinesFromFileToList(lines, "/etc/system-release");
+        } catch (IOException ex) {
+        }
+        return lines;
+    }
+
+    public static boolean isRhel6() {
+        return CommonUtilities.findInLineList(getReleaseLines(), "Red Hat Enterprise Linux", false)
+                && CommonUtilities.findInLineList(getReleaseLines(), "release 6", false);
+    }
+
     public static class Login {
 
         String username;
--- a/src/org/thermostat/qa2/framework/annotations/SetupStorage.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/framework/annotations/SetupStorage.java	Mon Nov 30 19:08:04 2015 +0100
@@ -37,13 +37,14 @@
  *
  * @author Zdeněk Žamberský
  */
+@RunGnomeKeyring
 @SetupThermostat
 @InheritAnnotations
 @Retention(RetentionPolicy.RUNTIME)
 public @interface SetupStorage {
 
     String type();
-
+    
     boolean badAgentLogin() default false;
 
     boolean badClientLogin() default false;
--- a/src/org/thermostat/qa2/framework/services/GnomeKeyring.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/framework/services/GnomeKeyring.java	Mon Nov 30 19:08:04 2015 +0100
@@ -30,6 +30,9 @@
  */
 package org.thermostat.qa2.framework.services;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import org.thermostat.qa2.framework.NativeProcess;
 import org.thermostat.qa2.framework.ThermostatQAConfig;
 import org.thermostat.qa2.framework.utils.CommonUtilities;
@@ -41,7 +44,8 @@
 public class GnomeKeyring extends AbstractService {
 
     public String configurationDirectory;
-    NativeProcess process;
+    public String keyringPassword = "123";
+    public HashMap<String, String> defaultEnvironment = new HashMap();
 
     public GnomeKeyring() {
         this(ThermostatQAConfig.gnomeKeyringConfigDir);
@@ -59,21 +63,65 @@
     @Override
     public void startServiceImpl() throws Exception {
         setRunning(true);
-        process = new NativeProcess("gnome-keyring-daemon");
+        NativeProcess process;
+
+        boolean oldKeyring = ThermostatQAConfig.isRhel6();
+        process = new NativeProcess("bash", "-c", "echo -n " + keyringPassword + " | gnome-keyring-daemon --daemonize --login");
         process.setLabel(getServiceName());
-        process.setEnvironmentVariable("XDG_DATA_HOME", configurationDirectory);
+        process.setStdOutMode(NativeProcess.MODE_LOG_AND_BUFFER);
+        if (!oldKeyring) {
+            process.setEnvironmentVariable("XDG_DATA_HOME", configurationDirectory);
+        }
+        process.start();
+        process.waitFor();
+        readEnvars(process.getStdoutLines());
+
+        process = new NativeProcess("gnome-keyring-daemon", "--start");
+        process.setLabel(getServiceName());
+        process.setStdOutMode(NativeProcess.MODE_LOG_AND_BUFFER);
+        if (!oldKeyring) {
+            process.setEnvironmentVariable("XDG_DATA_HOME", configurationDirectory);
+        }
+        setEnvvars(process, defaultEnvironment);
         process.start();
         process.waitFor();
+        readEnvars(process.getStdoutLines());
+
+        process = new NativeProcess("bash", "-c", "echo -n " + keyringPassword + " | gnome-keyring-daemon --unlock");
+        process.setLabel(getServiceName());
+        process.setStdOutMode(NativeProcess.MODE_LOG_AND_BUFFER);
+        setEnvvars(process, defaultEnvironment);
+        if (!oldKeyring) {
+            process.setEnvironmentVariable("XDG_DATA_HOME", configurationDirectory);
+        }
+        process.start();
+        process.waitFor();
+
         CommonUtilities.sleep(2000);
     }
 
+    public void readEnvars(List<String> lines) {
+        for (String line : lines) {
+            if (line.contains("=")) {
+                String[] segments = line.split("=");
+                defaultEnvironment.put(segments[0], segments[1]);
+            }
+        }
+    }
+
+    public void setEnvvars(NativeProcess process, HashMap<String, String> environment) {
+        for (Map.Entry<String, String> entry : environment.entrySet()) {
+            process.setEnvironmentVariable(entry.getKey(), entry.getValue());
+        }
+    }
+
     @Override
     public void stopServiceImpl() throws Exception {
         setRunning(false);
-        process = new NativeProcess("killall", "gnome-keyring-daemon");
+        NativeProcess process = new NativeProcess("killall", "gnome-keyring-daemon");
         process.setLabel(getServiceName());
         process.start();
-        process.waitFor(); 
+        process.waitFor();
     }
 
 }
--- a/src/org/thermostat/qa2/framework/services/ShellService.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/framework/services/ShellService.java	Mon Nov 30 19:08:04 2015 +0100
@@ -39,6 +39,7 @@
 import org.thermostat.qa2.framework.Shell;
 import org.thermostat.qa2.framework.utils.CommonUtilities;
 import org.thermostat.qa2.framework.utils.FileUtilities;
+import org.thermostat.qa2.framework.utils.ProcessUtilities;
 
 /**
  *
@@ -51,10 +52,7 @@
     String pidFile;
 
     public ShellService(String... commands) {
-        this.commands = "";
-        for (String command : commands) {
-            this.commands += command + " ";
-        }
+        this.commands = ProcessUtilities.getArgsString(commands);
     }
 
     public void addEnvVariable(String name, String value) {
--- a/src/org/thermostat/qa2/framework/services/ThermostatAgent.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/framework/services/ThermostatAgent.java	Mon Nov 30 19:08:04 2015 +0100
@@ -32,6 +32,7 @@
 
 import org.thermostat.qa2.framework.ThermostatQAConfig;
 import org.thermostat.qa2.framework.utils.CommonUtilities;
+import org.thermostat.qa2.framework.utils.ThermostatUtilities;
 
 /**
  *
@@ -44,12 +45,8 @@
     }
 
     public ThermostatAgent(String targetThermostat) {
-        this(ThermostatQAConfig.getThermostatExecutablePath(targetThermostat), ThermostatQAConfig.getThermostatUserHome(targetThermostat));
-    }
-
-    public ThermostatAgent(String thermostatExecutable, String thermostatUserHome) {
-        super(thermostatExecutable, "agent");
-        addEnvVariable("USER_THERMOSTAT_HOME", thermostatUserHome);
+        super(ThermostatUtilities.getThermostatCommandLineTargeted(targetThermostat, "agent"));
+        addEnvVariable("USER_THERMOSTAT_HOME", ThermostatQAConfig.getThermostatUserHome(targetThermostat));
     }
 
     @Override
--- a/src/org/thermostat/qa2/framework/services/ThermostatGui.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/framework/services/ThermostatGui.java	Mon Nov 30 19:08:04 2015 +0100
@@ -33,6 +33,7 @@
 import org.thermostat.qa2.framework.NativeProcess;
 import org.thermostat.qa2.framework.ThermostatQAConfig;
 import org.thermostat.qa2.framework.utils.CommonUtilities;
+import org.thermostat.qa2.framework.utils.ThermostatUtilities;
 
 /**
  *
@@ -45,12 +46,8 @@
     }
 
     public ThermostatGui(String targetThermostat) {
-        this(ThermostatQAConfig.getThermostatExecutablePath(targetThermostat), ThermostatQAConfig.getThermostatUserHome(targetThermostat));
-    }
-
-    public ThermostatGui(String thermostatExecutable, String thermostatUserHome) {
-        super(thermostatExecutable, "gui", "-J-Dawt.useSystemAAFontSettings=false", "-J-Dswing.aatext=false");
-        addEnvVariable("USER_THERMOSTAT_HOME", thermostatUserHome);
+        super(ThermostatUtilities.getThermostatCommandLineTargeted(targetThermostat, "gui", "-J-Dawt.useSystemAAFontSettings=false", "-J-Dswing.aatext=false"));
+        addEnvVariable("USER_THERMOSTAT_HOME", ThermostatQAConfig.getThermostatUserHome(targetThermostat));
     }
 
     @Override
--- a/src/org/thermostat/qa2/framework/services/ThermostatService.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/framework/services/ThermostatService.java	Mon Nov 30 19:08:04 2015 +0100
@@ -31,6 +31,7 @@
 package org.thermostat.qa2.framework.services;
 
 import org.thermostat.qa2.framework.ThermostatQAConfig;
+import org.thermostat.qa2.framework.utils.ThermostatUtilities;
 
 /**
  *
@@ -43,12 +44,8 @@
     }
 
     public ThermostatService(String targetThermostat) {
-        this(ThermostatQAConfig.getThermostatExecutablePath(targetThermostat), ThermostatQAConfig.getThermostatUserHome(targetThermostat));
-    }
-
-    public ThermostatService(String thermostatExecutable, String thermostatUserHome) {
-        super(thermostatExecutable, "service");
-        addEnvVariable("USER_THERMOSTAT_HOME", thermostatUserHome);
+        super(ThermostatUtilities.getThermostatCommandLineTargeted(targetThermostat, "service"));
+        addEnvVariable("USER_THERMOSTAT_HOME", ThermostatQAConfig.getThermostatUserHome(targetThermostat));
     }
 
     @Override
--- a/src/org/thermostat/qa2/framework/services/ThermostatStorage.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/framework/services/ThermostatStorage.java	Mon Nov 30 19:08:04 2015 +0100
@@ -35,6 +35,7 @@
 import org.thermostat.qa2.framework.NativeProcess;
 import org.thermostat.qa2.framework.ThermostatQAConfig;
 import org.thermostat.qa2.framework.utils.CommonUtilities;
+import org.thermostat.qa2.framework.utils.ThermostatUtilities;
 
 /**
  *
@@ -42,20 +43,14 @@
  */
 public class ThermostatStorage extends AbstractService {
 
-    public String thermostatExecutable;
-    public String thermostatUserHome;
+    public String target;
 
     public ThermostatStorage() {
         this("tested");
     }
 
     public ThermostatStorage(String targetThermostat) {
-        this(ThermostatQAConfig.getThermostatExecutablePath(targetThermostat), ThermostatQAConfig.getThermostatUserHome(targetThermostat));
-    }
-
-    public ThermostatStorage(String thermostatExecutable, String thermostatUserHome) {
-        this.thermostatExecutable = thermostatExecutable;
-        this.thermostatUserHome = thermostatUserHome;
+        this.target = targetThermostat;
     }
 
     @Override
@@ -69,9 +64,10 @@
     @Override
     public void startServiceImpl() throws Exception {
         setRunning(true);
-        startProcess = new NativeProcess(thermostatExecutable, "storage", "--start");
+        String[] cmds = ThermostatUtilities.getThermostatCommandLineTargeted(target, "storage", "--start");
+        startProcess = new NativeProcess(cmds);
         startProcess.setLabel(getServiceName());
-        startProcess.setEnvironmentVariable("USER_THERMOSTAT_HOME", thermostatUserHome);
+        startProcess.setEnvironmentVariable("USER_THERMOSTAT_HOME", ThermostatQAConfig.getThermostatUserHome(target));
         //if (startStdoutBuffering) {
         startProcess.setStdOutMode(NativeProcess.MODE_LOG_AND_BUFFER);
         //}
@@ -88,9 +84,10 @@
     @Override
     public void stopServiceImpl() throws Exception {
         setRunning(false);
-        stopProcess = new NativeProcess(thermostatExecutable, "storage", "--stop");
+        String[] cmds = ThermostatUtilities.getThermostatCommandLineTargeted(target, "storage", "--stop");
+        stopProcess = new NativeProcess(cmds);
         stopProcess.setLabel(getServiceName());
-        stopProcess.setEnvironmentVariable("USER_THERMOSTAT_HOME", thermostatUserHome);
+        stopProcess.setEnvironmentVariable("USER_THERMOSTAT_HOME", ThermostatQAConfig.getThermostatUserHome(target));
         if (stopStdoutBuffering) {
             stopProcess.setStdOutMode(NativeProcess.MODE_LOG_AND_BUFFER);
         }
--- a/src/org/thermostat/qa2/framework/utils/FileUtilities.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/framework/utils/FileUtilities.java	Mon Nov 30 19:08:04 2015 +0100
@@ -72,7 +72,7 @@
     }
 
     public static void copyFile(String src, String dest) throws Exception {
-        ProcessUtilities.run("cp", "--", src, dest);
+        ProcessUtilities.run("cp", "-r", "--", src, dest);
     }
 
     public static void removeFile(String file) throws Exception {
--- a/src/org/thermostat/qa2/framework/utils/ProcessUtilities.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/framework/utils/ProcessUtilities.java	Mon Nov 30 19:08:04 2015 +0100
@@ -110,4 +110,41 @@
         return thermostat;
     }
 
+    public static String[] getCommandlineWithCollection(String... args) {
+        String[] cmds = new String[4];
+        cmds[0] = "scl";
+        cmds[1] = "enable";
+        cmds[2] = ThermostatQAConfig.getCollectionName();
+        cmds[3] = getArgsString(args);
+        return cmds;
+    }
+
+    public static String getArgsString(String... args) {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < args.length; ++i) {
+            String arg = args[i];
+            boolean whitespace = containsWhitespace(arg);
+            if (whitespace) {
+                sb.append("\"");
+            }
+            sb.append(arg.replace("\\", "\\\\").replace("\"", "\\\""));
+            if (whitespace) {
+                sb.append("\"");
+            }
+            if (i != args.length - 1) {
+                sb.append(" ");
+            }
+        }
+        return sb.toString();
+    }
+
+    public static boolean containsWhitespace(String s) {
+        for (int i = 0; i < s.length(); ++i) {
+            if (Character.isWhitespace(s.charAt(i))) {
+                return true;
+            }
+        }
+        return false;
+    }
+
 }
--- a/src/org/thermostat/qa2/framework/utils/ThermostatUtilities.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/framework/utils/ThermostatUtilities.java	Mon Nov 30 19:08:04 2015 +0100
@@ -52,7 +52,15 @@
     public static void setupThermostat(String setupTarget, boolean web, boolean badAgentLogin, boolean badClientLogin, boolean agentSaveOnExit, boolean backupThermostatConfig, boolean backupUserHome) throws Exception {
         String thermostatHome = ThermostatQAConfig.getThermostatHome(setupTarget);
         String thermostatUserHome = ThermostatQAConfig.getThermostatUserHome(setupTarget);
-        boolean needsRoot = ThermostatQAConfig.isThermostatPackaged(setupTarget);
+        boolean packagedThermostat = ThermostatQAConfig.isThermostatPackaged(setupTarget);
+        boolean needsRoot = packagedThermostat;
+
+        if (web && !packagedThermostat) {
+            deployThermostatWebApp(setupTarget);
+            String tomcatHome = ThermostatQAConfig.getTomcatHome();
+            CommonUtilities.printHeading("Cleaning up tomcat logs");
+            ProcessUtilities.shellRun("rm -rf -- \"" + tomcatHome + File.separator + "logs" + File.separator + "\"" + "*");
+        }
 
         if (backupThermostatConfig) {
             BackupService backupService = new BackupService(ThermostatQAConfig.getThermostatEtcDir(setupTarget));
@@ -68,40 +76,54 @@
             ProcessUtilities.run("rm", "-rf", "--", thermostatUserHome);
         }
 
+        if (!web) {
+            String webappPath = ThermostatQAConfig.getThermostatHome("tested") + File.separator + "webapp";
+            BackupService backupService = new BackupService(webappPath);
+            backupService.setRunAsRoot(needsRoot);
+            backupService.start();
+            if (needsRoot) {
+                ProcessUtilities.runRaw("sudo", "-n", "rm", "-rf", webappPath);
+            } else {
+                ProcessUtilities.runRaw("rm", "-rf", webappPath);
+            }
+        }
+
         CommonUtilities.printHeading("Running Thermostat setup ...");
         String binDir = ThermostatQAConfig.getThermostatBinDir(setupTarget);
         String setupPath = binDir + File.separator + "thermostat-setup";
         NativeProcess process;
         Login mongoLogin = ThermostatQAConfig.getMongoLogin();
-        Login clientLogin = ThermostatQAConfig.getClientLogin(true);
-        Login agentLogin = ThermostatQAConfig.getAgentLogin(true);
+
+        String users = mongoLogin.getUsername() + "\\n"
+                + mongoLogin.getPassword() + "\\n" + mongoLogin.getPassword() + "\\n";
+        if (web) {
+            Login clientLogin = ThermostatQAConfig.getClientLogin(true);
+            Login agentLogin = ThermostatQAConfig.getAgentLogin(true);
 
-        process = new NativeProcess("bash", "-c", "echo -e \"yes\\n"
-                + mongoLogin.getUsername() + "\\n"
-                + mongoLogin.getPassword() + "\\n" + mongoLogin.getPassword() + "\\n"
-                + clientLogin.getUsername() + "\\n"
-                + clientLogin.getPassword() + "\\n" + clientLogin.getPassword() + "\\n"
-                + agentLogin.getUsername() + "\\n"
-                + agentLogin.getPassword() + "\\n" + agentLogin.getPassword()
-                + "\\n\" | " + setupPath);
+            users += clientLogin.getUsername() + "\\n"
+                    + clientLogin.getPassword() + "\\n" + clientLogin.getPassword() + "\\n"
+                    + agentLogin.getUsername() + "\\n"
+                    + agentLogin.getPassword() + "\\n" + agentLogin.getPassword();
+        }
+
+        String[] cmds = {"bash", "-c", "echo -e \"yes\\n"
+            + users
+            + "\\n\" | " + setupPath};
+
+        if (ThermostatQAConfig.isCollectionUsed()) {
+            cmds = ProcessUtilities.getCommandlineWithCollection(cmds);
+        }
+
+        process = new NativeProcess(cmds);
         process.setLabel("Thermostat setup");
         process.setEnvironmentVariable("USER_THERMOSTAT_HOME", thermostatUserHome);
         process.start();
         process.waitFor();
 
-        Login agentBadLogin = badAgentLogin ? ThermostatQAConfig.getAgentBadLogin() : ThermostatQAConfig.getAgentLogin(web);
-        String agentAuthFile = thermostatUserHome + File.separator + "etc" + File.separator + "agent.auth";
-        changeConfigProperty(agentAuthFile, "username", agentBadLogin.getUsername());
-        changeConfigProperty(agentAuthFile, "password", agentBadLogin.getPassword());
-
-        String clientPropertiesFile = thermostatUserHome + File.separator + "etc" + File.separator + "client.properties";
-        changeConfigProperty(clientPropertiesFile, "connection-url", ThermostatQAConfig.getStroageUrl(web));
-
-        Login clientBadLogin = badClientLogin ? ThermostatQAConfig.getClientBadLogin() : ThermostatQAConfig.getClientLogin(web);
-        changeConfigProperty(clientPropertiesFile, "username", clientBadLogin.getUsername());
-        changeConfigProperty(clientPropertiesFile, "password", clientBadLogin.getPassword());
-
-        String agentPropertiesFile = thermostatHome + File.separator + "etc" + File.separator + "agent.properties";
+        String agentPropertiesFile = thermostatUserHome + File.separator + "etc" + File.separator + "agent.properties";
+        if (!new File(agentPropertiesFile).exists()) {
+            agentPropertiesFile = thermostatHome + File.separator + "etc" + File.separator + "agent.properties";
+        }
         changeConfigProperty(agentPropertiesFile, "SAVE_ON_EXIT", agentSaveOnExit ? "true" : "false", needsRoot);
         changeConfigProperty(agentPropertiesFile, "DB_URL", ThermostatQAConfig.getStroageUrl(web), needsRoot);
 
@@ -339,7 +361,7 @@
     }
 
     /* Zero, negative or positive value is returned for first version equal to,
-       lower or higher than second */
+     lower or higher than second */
     public static int compareVersions(String version1, String version2) {
         String version1lc = version1.toLowerCase();
         String version2lc = version2.toLowerCase();
@@ -374,20 +396,18 @@
     }
 
     /* Starts thermostat shell executes requested command in it,
-     writes username/password, exits shell and returns output as line list */
+     exits shell and returns output as line list */
     public static List<String> getShellCommandOutput(String target, String command) throws Exception {
         ThermostatQAConfig.Login login = ThermostatQAConfig.getClientLogin();
         String username = login.getUsername();
         String password = login.getPassword();
 
-        String[] thermostatCmds = {ThermostatQAConfig.getThermostatExecutablePath(target), "shell"};
+        String[] thermostatCmds = ThermostatUtilities.getThermostatCommandLineTargeted(target, "shell");
         Shell thermostat = new Shell(thermostatCmds);
         thermostat.setEnvironmentVariable("USER_THERMOSTAT_HOME", ThermostatQAConfig.getThermostatUserHome(target));
         thermostat.setStdOutMode(NativeProcess.MODE_LOG_AND_BUFFER);
         thermostat.start();
         thermostat.writeln(command);
-        thermostat.writeln(username);
-        thermostat.writeln(password);
         thermostat.writeln("exit");
         thermostat.waitFor();
         return thermostat.getStdoutLines();
@@ -517,4 +537,32 @@
         return getShellCommandOutput(target, "profile-vm --hostId " + hostId + " --vmId " + vmId + " " + action);
     }
 
+    public static String[] getThermostatCommandLine(String... args) {
+        return getThermostatCommandLineTargeted("tested", args);
+    }
+
+    public static String[] getThermostatCommandLineTargeted(String target, String... args) {
+        String[] cmds;
+        if (target.equals("tested") && ThermostatQAConfig.isCollectionUsed()) {
+            cmds = new String[4];
+            cmds[0] = "scl";
+            cmds[1] = "enable";
+            cmds[2] = ThermostatQAConfig.getCollectionName();
+            StringBuilder sb = new StringBuilder();
+            sb.append(ThermostatQAConfig.getThermostatExecutablePath());
+            for (int i = 0; i < args.length; ++i) {
+                sb.append(" ");
+                sb.append(args[i]);
+            }
+            cmds[3] = sb.toString();
+        } else {
+            cmds = new String[args.length + 1];
+            cmds[0] = ThermostatQAConfig.getThermostatExecutablePath(target);
+            for (int i = 0; i < args.length; ++i) {
+                cmds[i + 1] = args[i];
+            }
+        }
+        return cmds;
+    }
+
 }
--- a/src/org/thermostat/qa2/tests/CliClientAgentInfoTest.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/tests/CliClientAgentInfoTest.java	Mon Nov 30 19:08:04 2015 +0100
@@ -58,8 +58,6 @@
     String[] patternListAgents = {
             "Thermostat version ",
             "Thermostat - > list-agents",
-            "Please enter username for storage at ",
-            "Please enter password for storage at ",
             "Agent ID",
             "Command Channel",
             "Address",
@@ -70,8 +68,6 @@
     String[] patternAgentInfo = {
             "Thermostat version ",
             "Thermostat - > agent-info -a ",
-            "Please enter username for storage at ",
-            "Please enter password for storage at ",
             "Agent ID ",
             "Command Channel Address ",
             "Start Time ",
@@ -93,10 +89,6 @@
 
    
     public String getAgentIdFromListAgents() throws Exception{
-
-        ThermostatQAConfig.Login login = ThermostatQAConfig.getClientLogin();
-        String name = login.getUsername();
-        String passwd = login.getPassword();
         
         //shell list agents
         Shell thermostat = ProcessUtilities.createThermostatShell();
@@ -104,8 +96,6 @@
         thermostat.setStdOutMode(NativeProcess.MODE_LOG_AND_BUFFER);
         thermostat.start();
         thermostat.writeln("list-agents");
-        thermostat.writeln(name);
-        thermostat.writeln(passwd);
         thermostat.writeln("exit");
         thermostat.waitFor();
 
@@ -120,15 +110,12 @@
     }
     
     public void checkAgentInfo(String agentId) throws Exception {
-        ThermostatQAConfig.Login login = ThermostatQAConfig.getClientLogin();
         
         Shell thermostat = ProcessUtilities.createThermostatShell();
         thermostat.setEnvironmentVariable("USER_THERMOSTAT_HOME", ThermostatQAConfig.getThermostatUserHome());
         thermostat.setStdOutMode(NativeProcess.MODE_LOG_AND_BUFFER);
         thermostat.start();
         thermostat.writeln("agent-info -a "+agentId);
-        thermostat.writeln(login.getUsername());
-        thermostat.writeln(login.getPassword());
         thermostat.writeln("exit");
         thermostat.waitFor();
         
--- a/src/org/thermostat/qa2/tests/CliClientDBModifWebStorageTest.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/tests/CliClientDBModifWebStorageTest.java	Mon Nov 30 19:08:04 2015 +0100
@@ -39,17 +39,18 @@
  * Test class ported from old framework
  * @author Zdeněk Žamberský
  */
-@SetupStorage(type = "web")
 @RunGnomeKeyring
 @RunStorage
 public class CliClientDBModifWebStorageTest {
 
     @Test
+    @SetupStorage(type = "web", badClientLogin = true)
     public void badLogin() throws Exception {
         CliClientDBModificationsSmokeTest.cliDBTestBadLogin();
     }
 
     @Test
+    @SetupStorage(type = "web")
     public void addVMandSeeItInShellWeb() throws Exception {
         CliClientDBModificationsSmokeTest.cliDBTest();
     }
--- a/src/org/thermostat/qa2/tests/CliClientDBModificationsSmokeTest.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/tests/CliClientDBModificationsSmokeTest.java	Mon Nov 30 19:08:04 2015 +0100
@@ -43,7 +43,6 @@
  *
  * @author Zdeněk Žamberský
  */
-@SetupStorage(type = "mongo")
 @RunGnomeKeyring
 @RunStorage
 public class CliClientDBModificationsSmokeTest {
@@ -70,14 +69,6 @@
         thermostat.setStdOutMode(NativeProcess.MODE_LOG_AND_BUFFER);
         thermostat.start();
         thermostat.writeln("list-vms");
-        if (badLogin) {
-            thermostat.writeln("baduser");
-            thermostat.writeln("badpassword");
-        } else {
-            ThermostatQAConfig.Login login = ThermostatQAConfig.getClientLogin();
-            thermostat.writeln(login.getUsername());
-            thermostat.writeln(login.getPassword());
-        }
         thermostat.writeln("exit");
         thermostat.waitFor();
         List<String> stdoutLines = thermostat.getStdoutLines();
@@ -99,11 +90,13 @@
     }
 
     @Test
+    @SetupStorage(type = "mongo")
     public void addVMandSeeItInShell() throws Exception {
         cliDBTest();
     }
 
     @Test
+    @SetupStorage(type = "mongo", badClientLogin = true)
     public void badLogin() throws Exception {
         cliDBTestBadLogin();
     }
--- a/src/org/thermostat/qa2/tests/CommandChannelSmokeTest.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/tests/CommandChannelSmokeTest.java	Mon Nov 30 19:08:04 2015 +0100
@@ -51,33 +51,27 @@
 public class CommandChannelSmokeTest {
 
     static final String[] patternRunningAgent = new String[]{
-        "Please enter username for storage at mongodb://127.0.0.1:",
-        "Please enter password for storage at mongodb://127.0.0.1:",
         "Queuing ping request.  Destination: /127.0.0.1:12000",
         "Response received from: /127.0.0.1:12000"
     };
 
     static final String[] patternStoppedAgent = new String[]{
-        "Please enter username for storage at mongodb://127.0.0.1:",
-        "Please enter password for storage at mongodb://127.0.0.1:",
         "Invalid host ID or agent no longer running." // new
     //"Queuing ping request.  Destination: /127.0.0.1:12000",
     //"Error received from: /127.0.0.1:12000"
     };
 
-    public static List<String> pingHost(String hostId, String username, String password) throws Exception {
+    public static List<String> pingHost(String hostId) throws Exception {
         String[] pingCmds = {ThermostatQAConfig.getThermostatExecutablePath(), "ping", hostId};
         Shell ping = new Shell(pingCmds);
         ping.setEnvironmentVariable("USER_THERMOSTAT_HOME", ThermostatQAConfig.getThermostatUserHome());
         ping.setStdOutMode(NativeProcess.MODE_LOG_AND_BUFFER);
         ping.start();
-        ping.writeln(username);
-        ping.writeln(password);
         ping.waitFor();
         return ping.getStdoutLines();
     }
 
-    public static void pingAgentImpl(String username, String password, String[] patternsRunning, String[] patternsStopped) throws Exception {
+    public static void pingAgentImpl(String[] patternsRunning, String[] patternsStopped) throws Exception {
         ThermostatAgent agent = new ThermostatAgent();
         agent.start();
         Assert.assertRuns(agent, "Agent should be running");
@@ -97,9 +91,9 @@
         }
         assertTrue(hostId != null, "hostId of agent was not found");
 
-        List<String> ping1Lines = pingHost(hostId, username, password);
+        List<String> ping1Lines = pingHost(hostId);
         agent.stop();
-        List<String> ping2Lines = pingHost(hostId, username, password);
+        List<String> ping2Lines = pingHost(hostId);
 
         assertContainsPatterns(ping1Lines, patternsRunning);
         assertContainsPatterns(ping2Lines, patternsStopped);
@@ -111,7 +105,7 @@
     @RunGnomeKeyring
     public void pingAgent() throws Exception {
         ThermostatQAConfig.Login login = ThermostatQAConfig.getClientLogin();
-        pingAgentImpl(login.getUsername(), login.getPassword(), patternRunningAgent, patternStoppedAgent);
+        pingAgentImpl(patternRunningAgent, patternStoppedAgent);
     }
 
 }
--- a/src/org/thermostat/qa2/tests/CommandChannelWebStorageTest.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/tests/CommandChannelWebStorageTest.java	Mon Nov 30 19:08:04 2015 +0100
@@ -44,15 +44,11 @@
 public class CommandChannelWebStorageTest {
 
     String[] patternRunningAgent = new String[]{
-        "Please enter username for storage at http://127.0.0.1:8080/thermostat/storage:",
-        "Please enter password for storage at http://127.0.0.1:8080/thermostat/storage:",
         "Queuing ping request.  Destination: /127.0.0.1:12000",
         "Response received from: /127.0.0.1:12000"
     };
 
     String[] patternStoppedAgent = new String[]{
-        "Please enter username for storage at http://127.0.0.1:8080/thermostat/storage:",
-        "Please enter password for storage at http://127.0.0.1:8080/thermostat/storage:",
         "Invalid host ID or agent no longer running." // new
         //"Queuing ping request.  Destination: /127.0.0.1:12000",
         //"Error received from: /127.0.0.1:12000"
@@ -64,7 +60,7 @@
     @RunGnomeKeyring
     public void pingAgent() throws Exception {
         Login login = ThermostatQAConfig.getCommandChannelLogin();
-        CommandChannelSmokeTest.pingAgentImpl(login.getUsername(), login.getPassword(), patternRunningAgent, patternStoppedAgent);
+        CommandChannelSmokeTest.pingAgentImpl(patternRunningAgent, patternStoppedAgent);
     }
 
 }
--- a/src/org/thermostat/qa2/tests/ShellCommandsTest.java	Tue Sep 22 18:43:48 2015 +0200
+++ b/src/org/thermostat/qa2/tests/ShellCommandsTest.java	Mon Nov 30 19:08:04 2015 +0100
@@ -37,7 +37,6 @@
 import org.thermostat.qa2.framework.NativeProcess;
 import org.thermostat.qa2.framework.Shell;
 import org.thermostat.qa2.framework.ThermostatQAConfig;
-import org.thermostat.qa2.framework.ThermostatQAConfig.Login;
 import org.thermostat.qa2.framework.annotations.RunAgent;
 import org.thermostat.qa2.framework.annotations.RunGnomeKeyring;
 import org.thermostat.qa2.framework.annotations.RunStorage;
@@ -104,10 +103,7 @@
     }
 
     public static void connect(Shell shell) throws IOException {
-        shell.writeln("connect -d " + ThermostatQAConfig.getStroageUrl(false));
-        Login login = ThermostatQAConfig.getClientLogin();
-        shell.writeln(login.getUsername());
-        shell.writeln(login.getPassword());
+        shell.writeln("connect -d " + ThermostatQAConfig.getStroageUrl(ThermostatUtilities.isWebStorageConfigured()));
     }
 
     public static final String testRunnerClassName = "org.thermostat.qa2.framework.TestRunner";