Skip to content

Commit

Permalink
fixed run from Alm Lab Management task
Browse files Browse the repository at this point in the history
  • Loading branch information
Anda Laakso committed May 20, 2019
1 parent 73eae82 commit a54f023
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 30 deletions.
2 changes: 1 addition & 1 deletion HpToolsLauncher/HpToolsLauncherTests/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void TestQcTestRun()
100000,
QcRunMode.RUN_LOCAL,
null,
new List<string> { "Aaron\\Amit" }, false, "", new List<string> { "Failed", "Blocked" }, false);
new List<string> { "Aaron\\Amit" }, false, "", new List<string> { "Failed", "Blocked" }, false, TestStorageType.Alm);

if (runner.Connected)
runner.Run();
Expand Down
50 changes: 45 additions & 5 deletions HpToolsLauncher/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public enum CIName
Hudson,
Jenkins,
TFS,
CCNET,
CCNET
}

public class McConnectionInfo
Expand Down Expand Up @@ -349,9 +349,48 @@ public void Run()
IAssetRunner CreateRunner(TestStorageType runType, JavaProperties ciParams, bool initialTestRun)
{
IAssetRunner runner = null;

switch (runType)
{
case TestStorageType.AlmLabManagement:
List<string> testSetsList = GetParamsWithPrefix("almEntityId");

string filterByName = (_ciParams.ContainsKey("FilterByName") ? _ciParams["FilterByName"] : "");

string statuses = (_ciParams.ContainsKey("FilterByStatus") ? _ciParams["FilterByStatus"] : "");

List<string> filterByStatuses = new List<string>();

if (statuses != "")
{
if (statuses.Contains(","))
{
filterByStatuses = statuses.Split(',').ToList();
}
else
{
filterByStatuses.Add(statuses);
}
}
//create an Alm runner
runner = new AlmTestSetsRunner(_ciParams["almServerUrl"],
_ciParams["almUserName"],
Decrypt(_ciParams["almPassword"], secretkey),
_ciParams["almDomain"],
_ciParams["almProject"],
Convert.ToDouble(_ciParams["almTimeout"]),
QcRunMode.RUN_LOCAL,
"",
testSetsList,
false,
filterByName,
filterByStatuses,
initialTestRun,
TestStorageType.AlmLabManagement);
break;

case TestStorageType.Alm:
Console.WriteLine("runtype is alm");
//check that all required parameters exist
foreach (string param1 in requiredParamsForQcRun)
{
Expand Down Expand Up @@ -402,11 +441,11 @@ IAssetRunner CreateRunner(TestStorageType runType, JavaProperties ciParams, bool
isFilterSelected = Convert.ToBoolean(filter.ToLower());
}

string filterByName = (_ciParams.ContainsKey("FilterByName") ? _ciParams["FilterByName"] : "");
filterByName = (_ciParams.ContainsKey("FilterByName") ? _ciParams["FilterByName"] : "");

string statuses = (_ciParams.ContainsKey("FilterByStatus") ? _ciParams["FilterByStatus"] : "");
statuses = (_ciParams.ContainsKey("FilterByStatus") ? _ciParams["FilterByStatus"] : "");

List<string> filterByStatuses = new List<string>();
filterByStatuses = new List<string>();

if (statuses != "")
{
Expand All @@ -432,7 +471,8 @@ IAssetRunner CreateRunner(TestStorageType runType, JavaProperties ciParams, bool
isFilterSelected,
filterByName,
filterByStatuses,
initialTestRun);
initialTestRun,
TestStorageType.Alm);
break;
case TestStorageType.FileSystem:
//Get displayController var
Expand Down
1 change: 1 addition & 0 deletions HpToolsLauncher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace HpToolsLauncher
public enum TestStorageType
{
Alm,
AlmLabManagement,
FileSystem,
LoadRunner,
Unknown
Expand Down
73 changes: 64 additions & 9 deletions HpToolsLauncher/Runners/AlmTestSetsRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class AlmTestSetsRunner : RunnerBase, IDisposable
double m_timeout = -1;
bool m_blnConnected = false;
ITDConnection2 tdConnection = null;
TestStorageType storage = TestStorageType.Unknown;
List<string> colTestSets = new List<string>();
string m_runHost = null;
string m_qcServer = null;
Expand Down Expand Up @@ -84,6 +85,12 @@ public string RunHost
set { m_runHost = value; }
}

public TestStorageType StorageType
{
get { return storage; }
set { storage = value; }
}

public ITDConnection2 TdConnection
{
get
Expand Down Expand Up @@ -121,7 +128,8 @@ public ITDConnection2 TdConnection
bool isFilterSelected,
string filterByName,
List<string> filterByStatuses,
bool initialTestRun)
bool initialTestRun,
TestStorageType testStorageType)
{
Timeout = intQcTimeout;
RunMode = enmQcRunMode;
Expand All @@ -139,6 +147,7 @@ public ITDConnection2 TdConnection
//if sso enable use the Jenkins credentials
Connected = ConnectToProject(qcServer, qcUser, qcPassword, qcDomain, qcProject);
TestSets = qcTestSets;
StorageType = testStorageType;
if (!Connected)
{
Environment.Exit((int)Launcher.ExitCodeEnum.Failed);
Expand All @@ -160,7 +169,7 @@ public ITDConnection2 TdConnection
/// <returns></returns>
public override TestSuiteRunResults Run()
{

if (!Connected)
return null;
TestSuiteRunResults activeRunDesc = new TestSuiteRunResults();
Expand Down Expand Up @@ -213,8 +222,8 @@ public override TestSuiteRunResults Run()
}
}

Console.WriteLine("Run on host: "+ RunHost);
TestSuiteRunResults desc = RunTestSet(tsDir, tsName, testParameters, Timeout, RunMode, RunHost, m_qcFilterSelected, m_qcFilterByName, m_qcFilterByStatuses);

TestSuiteRunResults desc = RunTestSet(tsDir, tsName, testParameters, Timeout, RunMode, RunHost, m_qcFilterSelected, m_qcFilterByName, m_qcFilterByStatuses, StorageType);
if (desc != null)
activeRunDesc.AppendResults(desc);
}
Expand All @@ -240,7 +249,7 @@ private void CreateTdConnection()
{
object conn = Activator.CreateInstance(type);
this.tdConnection = conn as ITDConnection2;
this.tdConnection.KeepConnection = true;
//this.tdConnection.KeepConnection = true;
// set credentials


Expand Down Expand Up @@ -316,6 +325,36 @@ private List<string> GetAllTestSetsFromDirTree(ITestSetFolder tsFolder)
return retVal;
}

private string GetTestSetByID(ITestSetFolder tsFolder, int testSetID, ref string testSuiteName)
{
List children = tsFolder.FindChildren("");
List testSets = tsFolder.FindTestSets("");

if (testSets != null)
{
foreach (ITestSet childSet in testSets)
{
if (childSet.ID == testSetID)
{
string tsPath = childSet.TestSetFolder.Path;
tsPath = tsPath.Substring(5).Trim("\\".ToCharArray());
string tsFullPath = tsPath + "\\" + childSet.Name;
testSuiteName = childSet.Name;
return tsFullPath.TrimEnd();
}
}
}

if (children != null)
{
foreach (ITestSetFolder childFolder in children)
{
GetAllTestSetsFromDirTree(childFolder);
}
}
return "";
}


/// <summary>
/// get a QC folder
Expand Down Expand Up @@ -432,8 +471,9 @@ private string GetTestInstancesString(ITestSet set)
/// <param name="runHost">if run on remote machine - remote machine name</param>
/// <returns></returns>
public TestSuiteRunResults RunTestSet(string tsFolderName, string tsName, string testParameters, double timeout, QcRunMode runMode, string runHost,
bool isFilterSelected, string filterByName, List<string> filterByStatuses)
bool isFilterSelected, string filterByName, List<string> filterByStatuses, TestStorageType testStorageType)
{

string currentTestSetInstances = "";
TestSuiteRunResults runDesc = new TestSuiteRunResults();
TestRunResults activeTestDesc = null;
Expand All @@ -446,10 +486,20 @@ private string GetTestInstancesString(ITestSet set)
bool isTestPath = false;
string testName = "";
string testSuiteName = tsName.TrimEnd();
string testSet = "";

try
{
tsFolder = (ITestSetFolder)tsTreeManager.get_NodeByPath(tsPath);
if (testStorageType.Equals(TestStorageType.AlmLabManagement))
{
tsFolder = (ITestSetFolder)tsTreeManager.get_NodeByPath("Root");
testSet = GetTestSetByID(tsFolder, Convert.ToInt32(tsName), ref testSuiteName);
}
else
{
tsFolder = (ITestSetFolder)tsTreeManager.get_NodeByPath(tsPath);
}

isTestPath = false;
}
catch (COMException ex)
Expand Down Expand Up @@ -489,8 +539,14 @@ private string GetTestInstancesString(ITestSet set)
}
else
{
tsList = tsFolder.FindTestSets(testSuiteName);

if ((testStorageType.Equals(TestStorageType.AlmLabManagement) && !testSet.Equals(""))
|| testStorageType.Equals(TestStorageType.Alm))
{
tsList = tsFolder.FindTestSets(testSuiteName);
}
}

if (tsList == null)
{
ConsoleWriter.WriteLine(string.Format(Resources.AlmRunnerCantFindTest, testSuiteName));
Expand Down Expand Up @@ -840,7 +896,6 @@ private string GetTestInstancesString(ITestSet set)
//close last test
if (prevTest != null)
{
Console.WriteLine("Close last test");
WriteTestRunSummary(prevTest);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import com.microfocus.application.automation.tools.EncryptionUtils;
import hudson.EnvVars;
import hudson.util.Secret;
import hudson.util.VariableResolver;
import org.kohsuke.stapler.DataBoundConstructor;

/**
Expand All @@ -36,6 +42,7 @@ public class SseModel {
public static final String TEST_SET = "TEST_SET";
public static final String BVS = "BVS";
public static final String PC = "PC";
public static final String RUN_MODE = "Run locally";

public static final String COLLATE = "Collate";
public static final String COLLATE_ANALYZE = "CollateAndAnalyze";
Expand Down Expand Up @@ -201,4 +208,49 @@ public String getPostRunAction() {

return _postRunAction;
}

private Properties createProperties() {
Properties props = new Properties();

props.put("almRunHost", getAlmServerName());
props.put("almServerUrl", getAlmServerUrl());
props.put("almUserName", getAlmUserName());

String encAlmPass = "";
try {

encAlmPass =
EncryptionUtils.Encrypt(
getAlmPassword(),
EncryptionUtils.getSecretKey());
}catch (Exception e){

}

props.put("almPassword", encAlmPass);
props.put("almDomain", getAlmDomain());
props.put("almProject", getAlmProject());
props.put("clientType", getClientType());
props.put("almRunType", getRunType());
props.put("almEntityId1", getAlmEntityId());
props.put("almTimeout", getTimeslotDuration());
props.put("description", getDescription());
props.put("environmentConfigurationId", getEnvironmentConfigurationId());
if(getCdaDetails() != null){
props.put("deploymentAction", getCdaDetails().getDeploymentAction());
props.put("deployedEnvironmentName", getCdaDetails().getDeployedEnvironmentName());
props.put("deprovisioningAction", getCdaDetails().getDeprovisioningAction());
}

props.put("almRunMode", RUN_MODE);

return props;

}

public Properties getProperties() {
return createProperties();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class AlmRunTypes {

public enum RunType {
Alm, FileSystem, LoadRunner
Alm, AlmLabManagement, FileSystem, LoadRunner
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -249,28 +249,28 @@ public void perform(Run<?, ?> build, FilePath workspace, Launcher launcher,

// Get the URL to the Script used to run the test, which is bundled
// in the plugin

URL cmdExeUrl =
Hudson.getInstance().pluginManager.uberClassLoader.getResource(HpToolsLauncher_SCRIPT_NAME);
if (cmdExeUrl == null) {
listener.fatalError(HpToolsLauncher_SCRIPT_NAME + " not found in resources");
return;
}

FilePath propsFileName = projectWS.child(ParamFileName);
FilePath CmdLineExe = projectWS.child(HpToolsLauncher_SCRIPT_NAME);

try {
// create a file for the properties file, and save the properties
propsFileName.copyFrom(propsStream);

// Copy the script to the project workspace
CmdLineExe.copyFrom(cmdExeUrl);
} catch (IOException e1) {
build.setResult(Result.FAILURE);
// TODO Auto-generated catch block
e1.printStackTrace();
}

try {
// Run the HpToolsLauncher.exe
AlmToolsUtils.runOnBuildEnv(build, launcher, listener, CmdLineExe, ParamFileName);
Expand Down

0 comments on commit a54f023

Please sign in to comment.