Skip to content

Commit

Permalink
Merge branch 'master' into workspace-prop-for-scenario-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
harshanL committed Mar 15, 2018
2 parents 291abad + dfee11b commit 350bc0f
Show file tree
Hide file tree
Showing 24 changed files with 414 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ public class TestGridConstants {

public static final String TEST_LOG_FILE_NAME = "test-run.log";
public static final String PRODUCT_TEST_PLANS_DIR = "test-plans";

public static final String WORKSPACE = "workspace";
public static final String TESTGRID_JOB_DIR = "jobs";
public static final String TESTGRID_HOME_ENV = "TESTGRID_HOME";
public static final String TESTGRID_HOME_SYSTEM_PROPERTY = "testgrid.home";
public static final Path DEFAULT_TESTGRID_HOME = Paths.get(System.getProperty("user.home"), ".testgrid");

public static final String DEFAULT_DEPLOYMENT_PATTERN_NAME = "default";
public static final String TESTGRID_CONFIG_FILE = "config.properties";

public static final String WUM_USERNAME_PROPERTY = "WUMUsername";
public static final String WUM_PASSWORD_PROPERTY = "WUMPassword";

}
68 changes: 68 additions & 0 deletions common/src/main/java/org/wso2/testgrid/common/TimeOutBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.testgrid.common;

import java.util.concurrent.TimeUnit;

/**
* A TimeOut Builder for awaitality usages.
*/
public class TimeOutBuilder {

private int timeOut;
private TimeUnit timeOutUnit;
private int pollInterval;
private TimeUnit pollUnit;

/**
* Constructs a timeout object with defined timeouts and time units.
*
* @param timeout timeout for waiting
* @param timeOutUnit time unit of timeout
* @param pollInterval polling interval
* @param pollUnit time unit of polling interval
*/
public TimeOutBuilder(int timeout, TimeUnit timeOutUnit, int pollInterval, TimeUnit pollUnit) {

this.timeOut = timeout;
this.timeOutUnit = timeOutUnit;
this.pollInterval = pollInterval;
this.pollUnit = pollUnit;
}

public int getTimeOut() {

return timeOut;
}

public TimeUnit getTimeOutUnit() {

return timeOutUnit;
}

public int getPollInterval() {

return pollInterval;
}

public TimeUnit getPollUnit() {

return pollUnit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;

/**
Expand All @@ -42,7 +41,7 @@ public class ConfigurationContext {
static {
try {
properties = new Properties();
Path configPath = Paths.get(TestGridUtil.getTestGridHomePath(), TestGridConstants.TESTGRID_CONFIG_FILE);
Path configPath = TestGridUtil.getConfigFilePath();
try (InputStream inputStream = Files.newInputStream(configPath)) {
properties.load(inputStream);
}
Expand Down Expand Up @@ -104,7 +103,17 @@ public enum ConfigurationProperties {
/**
* AWS Region of TestGrid deployment
*/
AWS_REGION_NAME("AWS_REGION_NAME");
AWS_REGION_NAME("AWS_REGION_NAME"),

/**
* WUM Username of TestGrid deployment
*/
WUM_USERNAME("WUM_USERNAME"),

/**
* WUM user password of TestGrid deployment
*/
WUM_PASSWORD("WUM_PASSWORD");

private String propertyName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.wso2.testgrid.common.config;

import org.apache.commons.collections4.ListUtils;
import org.wso2.testgrid.common.TestGridError;

import java.io.Serializable;
import java.util.List;
Expand All @@ -32,7 +33,7 @@
*
* @since 1.0.0
*/
public class InfrastructureConfig implements Serializable {
public class InfrastructureConfig implements Serializable, Cloneable {

private static final long serialVersionUID = -1660815137752094462L;

Expand Down Expand Up @@ -169,4 +170,21 @@ public String toString() {
public static class Provisioner extends DeploymentConfig.DeploymentPattern {
private static final long serialVersionUID = -3937792864579403430L;
}

@Override
public InfrastructureConfig clone() {
try {
InfrastructureConfig infrastructureConfig = (InfrastructureConfig) super.clone();
infrastructureConfig.setProvisioners(provisioners);
infrastructureConfig.setParameters(parameters);
infrastructureConfig.setContainerOrchestrationEngine(containerOrchestrationEngine);
infrastructureConfig.setIacProvider(iacProvider);
infrastructureConfig.setInfrastructureProvider(infrastructureProvider);

return infrastructureConfig;
} catch (CloneNotSupportedException e) {
throw new TestGridError("Since the super class of this object is java.lang.Object that supports " +
"cloning this failure condition should never happen unless a serious system error occurred.", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,14 @@ public static String getDeploymentPatternName(TestPlan testPlan) {

return TestGridConstants.DEFAULT_DEPLOYMENT_PATTERN_NAME;
}

/**
* Returns the path of config.properties.
*
* @return path of <TESTGRID_HOME>/config.properties
* @throws IOException for interrupted I/O operations
*/
public static Path getConfigFilePath() throws IOException {
return Paths.get(TestGridUtil.getTestGridHomePath(), TestGridConstants.TESTGRID_CONFIG_FILE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ private InfrastructureProvisionResult provisionInfrastructure(InfrastructureConf
InfrastructureProvider infrastructureProvider = InfrastructureProviderFactory
.getInfrastructureProvider(infrastructureConfig);
infrastructureProvider.init();
InfrastructureProvisionResult provisionResult = infrastructureProvider
.provision(testPlan);
InfrastructureProvisionResult provisionResult = infrastructureProvider.provision(testPlan);

provisionResult.setName(infrastructureConfig.getProvisioners().get(0).getName());
//TODO: remove. deploymentScriptsDir is deprecated now in favor of DeploymentConfig.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import java.util.Set;

import static org.wso2.testgrid.common.TestGridConstants.PRODUCT_TEST_PLANS_DIR;
import static org.wso2.testgrid.common.TestGridConstants.TESTGRID_JOB_DIR;

/**
* Responsible for generating the infrastructure plan and persisting them in the file system.
Expand Down Expand Up @@ -472,7 +473,7 @@ private List<TestPlan> generateTestPlans(Set<InfrastructureCombination> infrastr
setUniqueNamesFor(provisioner.getScripts());

TestPlan testPlan = new TestPlan();
testPlan.setInfrastructureConfig(testgridYaml.getInfrastructureConfig());
testPlan.setInfrastructureConfig(testgridYaml.getInfrastructureConfig().clone());
testPlan.getInfrastructureConfig().setProvisioners(Collections.singletonList(provisioner));
deploymentPattern.ifPresent(dp -> {
setUniqueNamesFor(dp.getScripts());
Expand All @@ -482,7 +483,6 @@ private List<TestPlan> generateTestPlans(Set<InfrastructureCombination> infrastr
combination.getParameters());
testPlan.getInfrastructureConfig().setParameters(configAwareInfraCombination);
testPlan.setScenarioConfig(testgridYaml.getScenarioConfig());
testPlan.setInfrastructureConfig(testgridYaml.getInfrastructureConfig());

testPlan.setInfrastructureRepository(testgridYaml.getInfrastructureRepository());
testPlan.setDeploymentRepository(testgridYaml.getDeploymentRepository());
Expand Down Expand Up @@ -558,7 +558,8 @@ private String createTestPlanGenDirectory(Product product) throws CommandExecuti
try {
String directoryName = product.getName();
String testGridHome = TestGridUtil.getTestGridHomePath();
Path directory = Paths.get(testGridHome, directoryName, PRODUCT_TEST_PLANS_DIR).toAbsolutePath();
Path directory = Paths.
get(testGridHome, TESTGRID_JOB_DIR, directoryName, PRODUCT_TEST_PLANS_DIR).toAbsolutePath();

// if the directory exists, remove it
removeDirectories(directory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public void init() throws Exception {
deploymentPattern.setName("default-" + random);
deploymentPattern.setProduct(product);

actualTestPlanFileLocation = Paths.get("target", "testgrid-home", product.getName(), "test-plans",
"test-plan-01.yaml").toString();
actualTestPlanFileLocation = Paths.get("target", "testgrid-home", TestGridConstants.TESTGRID_JOB_DIR,
product.getName(), TestGridConstants.PRODUCT_TEST_PLANS_DIR, "test-plan-01.yaml").toString();
}

@Test(dataProvider = "getJobConfigData")
Expand Down Expand Up @@ -146,8 +146,8 @@ public void testExecute(String jobConfigFile, String workingDir) throws Exceptio

@AfterMethod
public void tearDown() throws Exception {
Path testPlanPath = Paths.get(TESTGRID_HOME, product.getName(), TestGridConstants.PRODUCT_TEST_PLANS_DIR,
"test-plan-01.yaml");
Path testPlanPath = Paths.get(TESTGRID_HOME, TestGridConstants.TESTGRID_JOB_DIR, product.getName(),
TestGridConstants.PRODUCT_TEST_PLANS_DIR, "test-plan-01.yaml");
if (Files.exists(testPlanPath)) {
FileUtils.forceDelete(testPlanPath.toFile());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public class RunTestPlanCommandTest extends PowerMockTestCase {
public void init() throws Exception {
final String randomStr = StringUtil.generateRandomString(5);
String productName = "wso2-" + randomStr;
actualTestPlanFileLocation = Paths.get("target", "testgrid-home", productName, "test-plans",
"test-plan-01.yaml").toString();
actualTestPlanFileLocation = Paths.get("target", "testgrid-home", TestGridConstants.TESTGRID_JOB_DIR,
productName, TestGridConstants.PRODUCT_TEST_PLANS_DIR, "test-plan-01.yaml").toString();
runTestPlanCommand = new RunTestPlanCommand(productName, actualTestPlanFileLocation);
System.setProperty(TestGridConstants.TESTGRID_HOME_SYSTEM_PROPERTY, TESTGRID_HOME);

Expand Down Expand Up @@ -195,8 +195,8 @@ private void doMock() throws TestGridDAOException, TestAutomationException {

@AfterMethod
public void tearDown() throws Exception {
Path testPlanPath = Paths.get(TESTGRID_HOME, product.getName(), TestGridConstants.PRODUCT_TEST_PLANS_DIR,
"test-plan-01.yaml");
Path testPlanPath = Paths.get(TESTGRID_HOME, TestGridConstants.TESTGRID_JOB_DIR, product.getName(),
TestGridConstants.PRODUCT_TEST_PLANS_DIR, "test-plan-01.yaml");
if (Files.exists(testPlanPath)) {
FileUtils.forceDelete(testPlanPath.toFile());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public static DeploymentCreationResult getDeploymentCreationResult(String testPl
throws TestGridDeployerException {

ObjectMapper mapper = new ObjectMapper();
File file = new File(Paths.get(testPlanLocation, DeployerConstants.PRODUCT_IS_DIR,
DeployerConstants.DEPLOYMENT_FILE).toString());
File file = new File(Paths.get(testPlanLocation, DeployerConstants.DEPLOYMENT_FILE).toString());
try {
return mapper.readValue(file, DeploymentCreationResult.class);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.wso2.testgrid.deployment;

import org.awaitility.Awaitility;
import org.wso2.testgrid.common.TimeOutBuilder;
import org.wso2.testgrid.common.exception.TestGridDeployerException;
import java.io.IOException;
import java.net.HttpURLConnection;
Expand All @@ -28,7 +29,6 @@
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
Expand All @@ -47,15 +47,12 @@ public class DeploymentValidator {
* Wait on the Url response untile the defined timeout.
*
* @param url The URL endpoint of deployment.
* @param timeout Time to wait upon the desired response.
* @param timeoutTimeUnit TimeUnit of timeout value.
* @param pollInterval Time interval to perform polling.
* @param pollTimeUnit TimeUnit of pollInterval.
* @param timeOutBuilder timeOut object
*/
public void waitForDeployment(String url, int timeout, TimeUnit timeoutTimeUnit, int pollInterval,
TimeUnit pollTimeUnit) {
Awaitility.with().pollInterval(pollInterval, pollTimeUnit).await().
atMost(timeout, timeoutTimeUnit).until(isDeploymentSuccessful(url));
public void waitForDeployment(String url, TimeOutBuilder timeOutBuilder) {
Awaitility.with().pollInterval(timeOutBuilder.getPollInterval(), timeOutBuilder.getPollUnit()).await().
atMost(timeOutBuilder.getTimeOut(), timeOutBuilder.getTimeOutUnit())
.until(isDeploymentSuccessful(url));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.wso2.testgrid.common.Host;
import org.wso2.testgrid.common.InfrastructureProvisionResult;
import org.wso2.testgrid.common.TestPlan;
import org.wso2.testgrid.common.TimeOutBuilder;
import org.wso2.testgrid.common.config.DeploymentConfig;
import org.wso2.testgrid.common.exception.TestGridDeployerException;
import org.wso2.testgrid.common.util.StringUtil;
Expand Down Expand Up @@ -74,7 +75,8 @@ public DeploymentCreationResult deploy(TestPlan testPlan,
"hence skipping to next value.."));
continue;
}
validator.waitForDeployment(host.getIp(), TIMEOUT, TIMEOUT_UNIT, POLL_INTERVAL, POLL_UNIT);
TimeOutBuilder deploymentTimeOut = new TimeOutBuilder(TIMEOUT, TIMEOUT_UNIT, POLL_INTERVAL, POLL_UNIT);
validator.waitForDeployment(host.getIp(), deploymentTimeOut);
}
} catch (ConditionTimeoutException ex) {
throw new TestGridDeployerException(StringUtil.concatStrings("Timeout occurred while waiting for pattern : "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.slf4j.LoggerFactory;
import org.wso2.testgrid.common.Deployer;
import org.wso2.testgrid.common.DeploymentCreationResult;
import org.wso2.testgrid.common.Host;
import org.wso2.testgrid.common.InfrastructureProvisionResult;
import org.wso2.testgrid.common.ShellExecutor;
import org.wso2.testgrid.common.TestPlan;
Expand All @@ -31,10 +32,13 @@
import org.wso2.testgrid.common.exception.TestGridException;
import org.wso2.testgrid.common.util.StringUtil;
import org.wso2.testgrid.common.util.TestGridUtil;
import org.wso2.testgrid.deployment.DeploymentUtil;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import static org.wso2.testgrid.common.TestGridConstants.WORKSPACE;
Expand Down Expand Up @@ -62,7 +66,6 @@ public DeploymentCreationResult deploy(TestPlan testPlan,
DeploymentConfig.DeploymentPattern deploymentPatternConfig = testPlan.getDeploymentConfig()
.getDeploymentPatterns().get(0);
logger.info("Performing the Deployment " + deploymentPatternConfig.getName());
DeploymentCreationResult result = new DeploymentCreationResult();
try {
Script deployment = getScriptToExecute(testPlan.getDeploymentConfig(), Script.Phase.CREATE);
logger.info("Performing the Deployment " + deployment.getName());
Expand All @@ -80,14 +83,30 @@ public DeploymentCreationResult deploy(TestPlan testPlan,
if (exitCode > 0) {
logger.error(StringUtil.concatStrings("Error occurred while executing the deploy-provision script. ",
"Script exited with a status code of ", exitCode));
DeploymentCreationResult result = new DeploymentCreationResult();
result.setName(deploymentPatternConfig.getName());
result.setSuccess(false);
return result;
}
} catch (CommandExecutionException e) {
throw new TestGridDeployerException(e);
}

DeploymentCreationResult result = DeploymentUtil.getDeploymentCreationResult(infrastructureProvisionResult
.getDeploymentScriptsDir());
result.setName(deploymentPatternConfig.getName());
result.setHosts(infrastructureProvisionResult.getHosts());

List<Host> hosts = new ArrayList<>();
Host tomcatHost = new Host();
tomcatHost.setLabel("tomcatHost");
tomcatHost.setIp("ec2-52-54-230-106.compute-1.amazonaws.com");
Host tomcatPort = new Host();
tomcatPort.setLabel("tomcatPort");
tomcatPort.setIp("8080");
hosts.add(tomcatHost);
hosts.add(tomcatPort);

hosts.addAll(result.getHosts());
result.setHosts(hosts);
return result;
}

Expand Down
Loading

0 comments on commit 350bc0f

Please sign in to comment.