view src/org/thermostat/qa2/framework/ThermostatQAConfig.java @ 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
line wrap: on
line source

/*
 ThermostatQA - test framework for Thermostat Monitoring Tool

 Copyright 2015 Red Hat, Inc.

 This file is part of ThermostatQA

 ThermostatQA is distributed under the GNU General Public License,
 version 2 or any later version (with a special exception described
 below, commonly known as the "Classpath Exception").

 A copy of GNU General Public License (GPL) is included in this
 distribution, in the file COPYING.

 Linking ThermostatQA code with other modules is making a combined work
 based on ThermostatQA.  Thus, the terms and conditions of the GPL
 cover the whole combination.

 As a special exception, the copyright holders of ThermostatQA give you
 permission to link this code with independent modules to produce an
 executable, regardless of the license terms of these independent
 modules, and to copy and distribute the resulting executable under
 terms of your choice, provided that you also meet, for each linked
 independent module, the terms and conditions of the license of that
 module.  An independent module is a module which is not derived from
 or based on ThermostatQA code.  If you modify ThermostatQA, you may
 extend this exception to your version of the software, but you are
 not obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version.
 */
package org.thermostat.qa2.framework;

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;

/**
 *
 * @author Zdeněk Žamberský
 */
public class ThermostatQAConfig {

    public static PrintStream logStream = System.out;
    public static String tomcatHome;
    public static int mongoPort = 27518;
    public static int agentPort = 12000;
    public static int webStoragePort;
    public static String gnomeKeyringConfigDir;
    public static String backupDir;
    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");

    public static Login agentBadLogin = new Login("doctor-evil", "mini-me");
    public static Login clientBadLogin = new Login("time-for-tea", "aaargh");

    ///////////////////////
    // tested thermostat //
    ///////////////////////
    public static String thermostatHome;
    public static String thermostatUserHome;
    public static String thermostatVersion;
    public static boolean thermostatPackaged;
    public static boolean useCollection;
    public static String collectionName = "thermostat1";

    //////////////////////
    // other thermostat //
    //////////////////////
    public static String thermostatOtherHome;
    //static String ThermostatOtherUserHome;
    public static String thermostatOtherVersion;
    public static String thermostatOtherWebAppDir;

    static {
        tomcatHome = System.getProperty("tomcat.home");

        thermostatUserHome = System.getProperty("thermostat.user.home");
        thermostatVersion = System.getProperty("thermostat.version");
        thermostatHome = System.getProperty("thermostat.home");

        String webPortVal = System.getProperty("thermostat.webstorage.port");
        if (webPortVal != null) {
            webStoragePort = Integer.parseInt(webPortVal);
        }

        thermostatOtherVersion = System.getProperty("thermostat.other.version");
        thermostatOtherHome = System.getProperty("thermostat.other.home");

        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");
        reportDir = System.getProperty("reports.dir");

        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() {
        return "." + File.separator + "patterns" + File.separator + "1.1.0" + File.separator + "noAA";
    }

    // true -> tested, false -> other
    static boolean getTargetAsBoolean(String target) {
        if (target.equals("tested")) {
            return true;
        } else if (target.equals("other")) {
            return false;
        } else {
            throw new IllegalArgumentException("Invalid target thermostat: " + target);
        }
    }

    // true -> web, false -> mongo
    static boolean getStorageTypeAsBoolean(String storageType) {
        if (storageType.equals("web")) {
            return true;
        } else if (storageType.equals("mongo")) {
            return false;
        } else {
            throw new IllegalArgumentException("Invalid storage type: " + storageType);
        }
    }

    public static String getTomcatHome() {
        return tomcatHome;
    }

    public static String getWebAppPath(String target) {
        return getThermostatHome(target) + File.separator + "webapp";
    }

    public static String getThermostatHome(String target) {
        return getTargetAsBoolean(target) ? thermostatHome : thermostatOtherHome;
    }

    public static String getThermostatUserHome() {
        return getThermostatUserHome("tested");
    }

    public static String getThermostatUserHome(String target) {
        return thermostatUserHome;
    }

    public static String getThermostatVersion(String target) {
        return getTargetAsBoolean(target) ? thermostatVersion : thermostatOtherVersion;
    }

    public static String getThermostatExecutablePath() {
        return getThermostatExecutablePath("tested");
    }

    public static String getThermostatExecutablePath(String target) {
        return getThermostatBinDir(target) + File.separator + "thermostat";
    }

    public static String getThermostatBinDir(String target) {
        return getThermostatHome(target) + File.separator + "bin";
    }

    public static String getThermostatEtcDir(String target) throws IOException {
        return FileUtilities.getCanonicalPath(getThermostatHome(target) + File.separator + "etc");
    }

    public static String getThermostatOutputTextsDir() {
        return "." + File.separator + "outputtexts" + File.separator + thermostatVersion;
    }

    public static boolean isThermostatPackaged(String target) {
        return getTargetAsBoolean(target) ? thermostatPackaged : false;
    }

    public static String getBackupDir() {
        return backupDir;
    }

    public static boolean isCompatibilityTesting() {
        return thermostatOtherVersion != null;
    }

    public static Login getMongoLogin() {
        return mongoLogin;
    }

    public static Login getAgentLogin(boolean web) {
        return web ? agentLogin : mongoLogin;
    }

    public static Login getAgentLogin() {
        return getAgentLogin(ThermostatUtilities.isWebStorageConfigured());
    }

    public static Login getClientLogin(boolean web) {
        return web ? clientLogin : mongoLogin;
    }

    public static Login getClientLogin() {
        return getClientLogin(ThermostatUtilities.isWebStorageConfigured());
    }

    public static Login getCommandChannelLogin() {
        return ThermostatUtilities.isWebStorageConfigured() ? clientLogin : mongoLogin;
    }

    public static Login getAgentBadLogin() {
        return agentBadLogin;
    }

    public static Login getClientBadLogin() {
        return clientBadLogin;
    }

    public static String getStroageUrl(boolean web) {
        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;
        String password;

        public Login(String username, String password) {
            this.username = username;
            this.password = password;
        }

        public String getUsername() {
            return username;
        }

        public String getPassword() {
            return password;
        }

    }

}