view src/org/thermostat/qa/testsuites/CommandChannelWebStorageTest.java @ 152:1191b3a92ad1

miscellaneous smaller modifications
author Jana Fabrikova <jfabriko@redhat.com>
date Tue, 01 Apr 2014 15:42:00 +0200
parents 23e9bbe04876
children
line wrap: on
line source

/*

    ThermostatQA - test framework for Thermostat Monitoring Tool

    Copyright 2013 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.qa.testsuites;



import java.io.IOException;
import java.util.List;



import org.thermostat.qa.annotations.StorageType;
import org.thermostat.qa.annotations.StorageTypes;
import org.thermostat.qa.annotations.TestType;
import org.thermostat.qa.annotations.TestTypes;
import org.thermostat.qa.framework.Assert;
import org.thermostat.qa.framework.ThermostatTest;
import org.thermostat.qa.annotations.TillVersion;
import org.thermostat.qa.annotations.SinceVersion;


/**
 * Class CommandChannelSmokeTest
 *  
 *
 */
@StorageType(StorageTypes.WEBTOMCAT_STORAGE)
public class CommandChannelWebStorageTest extends ThermostatTest
{
    private String[] patternRunningAgent;
    private String[] patternStoppedAgent;
    
    @Override
    protected void setUp()
    {
        patternRunningAgent = new String[] {
                            "Please enter username for storage at http://127.0.0.1:8080/thermostat/storage:cmdc-tester",
                            "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"
                        };
        
        patternStoppedAgent = new String[] {
                            "Please enter username for storage at http://127.0.0.1:8080/thermostat/storage:cmdc-tester",
                            "Please enter password for storage at http://127.0.0.1:8080/thermostat/storage:",
                            "Queuing ping request.  Destination: /127.0.0.1:12000",
                            "Error received from: /127.0.0.1:12000"
                        };
        try
        {
            prepareWebStorageConfigFiles();
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Override
    protected void tearDown()
    {
        try
        {
            restoreNormalStorageConfigFiles();
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    /**
     * Method stopAllThermostatAgents
     * kills all processes that are thermostat agents by running script
     * <a href="scripts/stop_all_therm_agents.sh">stop_all_therm_agents.sh</a> 
     * 
     * @throws IOException
     */
    private void stopAllThermostatAgents() throws IOException
    {
        List<String> output = runHelperBashScript("stop_all_therm_agents.sh");
        Assert.assertNotNull(output, "error running script 'list_all_therm_agents.sh'");        
    }

    /**
     * 
     * @throws IOException
     */
    @TillVersion("0.18.0")
    public void testPingAgent2() throws IOException
    {
        //thermostat storage --start
        startStorage();
        
        //thermostat agent
        runThermostatInNewProcess("agent");
        sleep(ONE_SEC);
        
        //jps ... find Thermostat agent pid
        List<String> agentLines = runHelperBashScript("list_agent_pids.sh");
        sleep(3*ONE_SEC);
        for(String s : agentLines)
        {
            logInfo("agentPid", s);
        }
        
        //thermostat list-vms ... find the line with pid, extract host_id
        List<String> vmList = runCommandsInThermostatShell("list-vms_therm_shell.txt");
        String hostId = "";
        for(String s : vmList)
        {
            System.out.println(s);
            for(String a : agentLines)
            {
                if(s.contains(a) && s.contains("RUNNING"))
                {
                    String[] parts = s.split(" ");
                    hostId = parts[0];
                }
            }
            logInfo("hostId", hostId);
        }

        //thermostat ping host_id with empty login and password
        List<String> out1 = thermostatPingHost(hostId);
        
        //stop agent
        stopAllThermostatAgents();
        //wait
        sleep(ONE_SEC);
        
        //thermostat ping host_id
        List<String> out2 = thermostatPingHost(hostId);
        
        //stop the storage
        stopStorage();
        
        //check output of first ping
        for (String message : out1)
        {
            logInfo("Ping exist", message);
        }
        
        //check output of second ping
        for (String message : out2)
        {
            logInfo("Ping nonexist", message);
        }
        
        Assert.assertTrue(checkPresenceOfPatterns(out1, patternRunningAgent), "output for running agent ping");
        Assert.assertTrue(checkPresenceOfPatterns(out2, patternStoppedAgent), "output for stopped agent ping");
    }
    
    
    /**
     * 
     * @throws IOException
     */
    @SinceVersion("0.18.1")
    public void testPingAgent() throws IOException
    {
        //thermostat storage --start
        startWebStorage();
        
        //thermostat agent
        runThermostatInNewProcess("agent");
        sleep(ONE_SEC);
        
        //jps ... find Thermostat agent pid
        List<String> agentLines = runHelperBashScript("list_agent_pids.sh");
        for(String s : agentLines)
        {
            logInfo("agentPid", s);
        }
        sleep(8*ONE_SEC);        
        
        //thermostat list-vms ... find the line with pid, extract host_id
        List<String> vmList = runCommandsInThermostatShell("list-vms_therm_shell3.txt");
        String hostId = "";
        for(String s : vmList)
        {
            System.out.println(s);
            for(String a : agentLines)
            {
                if(s.contains(a) && s.contains("RUNNING"))
                {
                    String[] parts = s.split(" ");
                    hostId = parts[0];
                }
            }
            logInfo("hostId", hostId);
        }

        //thermostat ping host_id with empty login and password
        List<String> out1 = thermostatPingHost(hostId, "cmdc-tester", "heslo3");
        
        //stop agent
        stopAllThermostatAgents();
        //wait
        sleep(ONE_SEC);
        
        //thermostat ping host_id
        List<String> out2 = thermostatPingHost(hostId, "cmdc-tester", "heslo3");
        
        //stop the storage
        stopWebStorage();
        
        //check output of first ping
        for (String message : out1)
        {
            logInfo("Ping exist", message);
        }
        
        //check output of second ping
        for (String message : out2)
        {
            logInfo("Ping nonexist", message);
        }
        
        Assert.assertTrue(checkPresenceOfPatterns(out1, patternRunningAgent), "output for running agent ping");
        Assert.assertTrue(checkPresenceOfPatterns(out2, patternStoppedAgent), "output for stopped agent ping");

    }
    
    /*
     * output for client-tester:
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping exist: Please enter username for storage at http://127.0.0.1:8080/thermostat/storage:client-tester
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping exist: Please enter password for storage at http://127.0.0.1:8080/thermostat/storage:
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping exist: Queuing ping request.  Destination: /127.0.0.1:12000
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping exist: The server refused to ping due to authentication/authorization issues.
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping exist: 
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping nonexist: Please enter username for storage at http://127.0.0.1:8080/thermostat/storage:client-tester
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping nonexist: Please enter password for storage at http://127.0.0.1:8080/thermostat/storage:
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping nonexist: Queuing ping request.  Destination: /127.0.0.1:12000
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping nonexist: The server refused to ping due to authentication/authorization issues.
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping nonexist: 

output for cmdc-tester:
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping exist: Please enter username for storage at http://127.0.0.1:8080/thermostat/storage:cmdc-tester
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping exist: Please enter password for storage at http://127.0.0.1:8080/thermostat/storage:
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping exist: Queuing ping request.  Destination: /127.0.0.1:12000
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping exist: Response received from: /127.0.0.1:12000
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping exist: 
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping nonexist: Please enter username for storage at http://127.0.0.1:8080/thermostat/storage:cmdc-tester
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping nonexist: Please enter password for storage at http://127.0.0.1:8080/thermostat/storage:
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping nonexist: Queuing ping request.  Destination: /127.0.0.1:12000
INFO: org.thermostat.qa.testsuites.CommandChannelWebStorageTest.Ping nonexist: Error received from: /127.0.0.1:12000

     */
    
    public static void main(String[] args)
    {
        new CommandChannelWebStorageTest().doTests(args);
    }

}