Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastest/elastest-torm
Browse files Browse the repository at this point in the history
  • Loading branch information
nordri committed Feb 2, 2018
2 parents 88edee8 + 25ef382 commit fefcac8
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 76 deletions.
6 changes: 5 additions & 1 deletion docker/services/rabbitmq/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
FROM rabbitmq:3-management
FROM rabbitmq:3.6.6-management-alpine

ADD rabbitmq.config /etc/rabbitmq/
ADD definitions.json /etc/rabbitmq/
RUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config /etc/rabbitmq/definitions.json

# Add script to create default users / vhosts
ADD init.sh /init.sh
Expand Down
32 changes: 32 additions & 0 deletions docker/services/rabbitmq/definitions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"rabbit_version": "3.7.3",
"users": [
{
"name": "elastest-etm",
"password": "elastest-etm",
"tags": "administrator"
}
],
"vhosts": [
{
"name": "\/elastest-etm"
},
{
"name": "\/vhost2"
}
],
"permissions": [
{
"user": "elastest-etm",
"vhost": "\/elastest-etm",
"configure": ".*",
"write": ".*",
"read": ".*"
}
],
"parameters": [],
"policies": [],
"queues": [],
"exchanges": [],
"bindings": []
}
41 changes: 2 additions & 39 deletions docker/services/rabbitmq/init.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,5 @@
#!/bin/sh

# Create Default RabbitMQ setup
(
# Create users
# rabbitmqctl add_user <username> <password>
rabbitmqctl add_user elastest-etm elastest-etm ; \
CREATED=$?; \
rabbitmq-plugins enable rabbitmq_stomp;
exec rabbitmq-server;

while [ $CREATED -ne 0 ]; do
echo "ET_LOG: RabbitMQ is not ready yet. Sleeping for 2s" ; \
sleep 2; \
echo "ET_LOG: Retrying to create user" ; \
rabbitmqctl add_user elastest-etm elastest-etm ; \
CREATED=$?; \
done

# Set user rights
# rabbitmqctl set_user_tags <username> <tag>
rabbitmqctl set_user_tags elastest-etm administrator ; \

# Create vhosts
# rabbitmqctl add_vhost <vhostname>
echo "ET_LOG: Creating vhost" ; \
rabbitmqctl add_vhost /elastest-etm ; \
CREATED=$?; \

while [ $CREATED -ne 0 ]; do
echo "ET_LOG: Error on create vhost. Sleeping for 2s" ; \
sleep 2; \
echo "ET_LOG: Retrying to create vhost" ; \
rabbitmqctl add_vhost /elastest-etm ; \
CREATED=$?; \
done

# Set vhost permissions
# rabbitmqctl set_permissions -p <vhostname> <username> ".*" ".*" ".*"
rabbitmqctl set_permissions -p /elastest-etm elastest-etm ".*" ".*" ".*" ; \

rabbitmq-plugins enable rabbitmq_stomp; \
) &
rabbitmq-server $@
8 changes: 8 additions & 0 deletions docker/services/rabbitmq/rabbitmq.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{rabbit, [
{loopback_users, []}
]},
{rabbitmq_management, [
{load_definitions, "/etc/rabbitmq/definitions.json"}
]}
].
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export class ExecutionFormComponent implements OnInit, OnChanges, AfterViewCheck

ngOnChanges(changes: SimpleChanges) {
if (changes.data) {
this.ngOnInit();
this.alreadyFocused = false;
this.ngOnInit();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,10 @@ private void provideServices(String tJobServices, TJobExecution tJobExec) {
resultMsg + service.get("name").toString()
.replaceAll("\"", ""));

String instanceId = esmService.provisionTJobExecServiceInstanceSync(
service.get("id").toString().replaceAll("\"", ""),
tJobExec);
String instanceId = esmService
.provisionTJobExecServiceInstanceSync(service
.get("id").toString().replaceAll("\"", ""),
tJobExec);

tJobExec.getServicesInstances().add(instanceId);
}
Expand Down Expand Up @@ -371,7 +372,8 @@ public void deprovideServices(TJobExecution tJobExec) {
logger.debug("TSS list size: {}", esmService
.gettSSIByTJobExecAssociated().get(tJobExec.getId()).size());
for (String instanceId : instancesAux) {
esmService.deprovisionTJobExecServiceInstance(instanceId, tJobExec.getId());
esmService.deprovisionTJobExecServiceInstance(instanceId,
tJobExec.getId());
logger.debug("TSS Instance id to deprovide: {}", instanceId);
}

Expand Down Expand Up @@ -499,7 +501,7 @@ public void startSutByDockerCompose(DockerExecution dockerExec)

// TMP replace sut exec and logstash sut tcp
String dockerComposeYml = sut.getSpecification();
dockerComposeYml = setLoggingToDockerComposeYml(dockerComposeYml,
dockerComposeYml = setElasTestConfigToDockerComposeYml(dockerComposeYml,
composeProjectName, dockerExec);
// Environment variables (optional)
ArrayList<String> envList = new ArrayList<>();
Expand Down Expand Up @@ -530,14 +532,6 @@ public void startSutByDockerCompose(DockerExecution dockerExec)
String containerId = dockerService
.getContainerIdByName(container.getName(), dockerExec);

try {
// Insert into ElasTest network
dockerService.insertIntoNetwork(dockerExec.getNetwork(),
containerId);
} catch (Exception e) {
logger.warn("Cannot insert container {} into network {}",
containerId, dockerExec.getNetwork(), e);
}
// Insert container into containers list
dockerService.insertCreatedContainer(containerId,
container.getName());
Expand All @@ -556,7 +550,7 @@ public void startSutByDockerCompose(DockerExecution dockerExec)

}

public String setLoggingToDockerComposeYml(String dockerComposeYml,
public String setElasTestConfigToDockerComposeYml(String dockerComposeYml,
String composeProjectName, DockerExecution dockerExec)
throws Exception {
YAMLFactory yf = new YAMLFactory();
Expand All @@ -565,31 +559,22 @@ public String setLoggingToDockerComposeYml(String dockerComposeYml,
try {
object = mapper.readValue(dockerComposeYml, Object.class);

Map<String, HashMap<String, HashMap<String, HashMap>>> dockerComposeMap = (HashMap) object;
Map<String, HashMap<String, HashMap>> servicesMap = dockerComposeMap
.get("services");
for (HashMap.Entry<String, HashMap<String, HashMap>> service : servicesMap
Map<String, HashMap<String, HashMap>> dockerComposeMap = (HashMap) object;
Map<String, HashMap> servicesMap = dockerComposeMap.get("services");
for (HashMap.Entry<String, HashMap> service : servicesMap
.entrySet()) {
// Set Logging
service = this.setLoggingToDockerComposeYmlService(service,
composeProjectName, dockerExec);

HashMap<String, HashMap> serviceContent = service.getValue();
String loggingKey = "logging";
if (serviceContent.containsKey(loggingKey)) {
serviceContent.remove(loggingKey);
}
HashMap<String, Object> loggingContent = new HashMap<String, Object>();
loggingContent.put("driver", "syslog");

HashMap<String, Object> loggingOptionsContent = new HashMap<String, Object>();
loggingOptionsContent.put("syslog-address", "tcp://"
+ dockerService.getLogstashHost(dockerExec) + ":5000");
loggingOptionsContent.put("tag",
composeProjectName + "_" + service.getKey() + "_exec");

loggingContent.put("options", loggingOptionsContent);

serviceContent.put(loggingKey, loggingContent);
// Set Elastest Network
service = this.setNetworkToDockerComposeYmlService(service,
composeProjectName, dockerExec);
}

dockerComposeMap = this.setNetworkToDockerComposeYmlRoot(
dockerComposeMap, composeProjectName, dockerExec);

StringWriter writer = new StringWriter();

yf.createGenerator(writer).writeObject(object);
Expand All @@ -605,6 +590,70 @@ public String setLoggingToDockerComposeYml(String dockerComposeYml,
return dockerComposeYml;
}

private Map<String, HashMap<String, HashMap>> setNetworkToDockerComposeYmlRoot(
Map<String, HashMap<String, HashMap>> dockerComposeMap,
String composeProjectName, DockerExecution dockerExec) {

String networksKey = "networks";
// If service has networks, remove it
if (dockerComposeMap.containsKey(networksKey)) {
dockerComposeMap.remove(networksKey);
}

HashMap<String, HashMap> networkMap = new HashMap();
HashMap<String, Boolean> networkOptions = new HashMap<>();
networkOptions.put("external", true);

networkMap.put("elastest_elastest", networkOptions);
dockerComposeMap.put(networksKey, networkMap);

return dockerComposeMap;

}

public HashMap.Entry<String, HashMap> setLoggingToDockerComposeYmlService(
HashMap.Entry<String, HashMap> service, String composeProjectName,
DockerExecution dockerExec) {
HashMap<String, HashMap> serviceContent = service.getValue();
String loggingKey = "logging";
// If service has logging, remove it
if (serviceContent.containsKey(loggingKey)) {
serviceContent.remove(loggingKey);
}
HashMap<String, Object> loggingContent = new HashMap<String, Object>();
loggingContent.put("driver", "syslog");

HashMap<String, Object> loggingOptionsContent = new HashMap<String, Object>();
loggingOptionsContent.put("syslog-address",
"tcp://" + dockerService.getLogstashHost(dockerExec) + ":5000");
loggingOptionsContent.put("tag",
composeProjectName + "_" + service.getKey() + "_exec");

loggingContent.put("options", loggingOptionsContent);

serviceContent.put(loggingKey, loggingContent);

return service;
}

public HashMap.Entry<String, HashMap> setNetworkToDockerComposeYmlService(
HashMap.Entry<String, HashMap> service, String composeProjectName,
DockerExecution dockerExec) {

HashMap serviceContent = service.getValue();
String networksKey = "networks";
// If service has networks, remove it
if (serviceContent.containsKey(networksKey)) {
serviceContent.remove(networksKey);
}

List<String> networksList = new ArrayList<>();
networksList.add("elastest_elastest");
serviceContent.put(networksKey, networksList);

return service;
}

public void endSutExec(DockerExecution dockerExec) throws Exception {
SutSpecification sut = dockerExec.gettJobexec().getTjob().getSut();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,13 @@ public TestCase getFullDetailedTestCase(TestCase testCase) {

public ReportTCResultResponse saveExecution(Execution execution,
Integer testCaseId) {
// Save TestCase Execution in Testlink
ReportTCResultResponse response = this.executeTest(testCaseId,
execution.getTestPlanId(), execution.getBuildId(),
execution.getNotes(), execution.getStatus());
execution.setId(response.getExecutionId());

// Get Associated ExternalTestCase And Save ExternalTestCaseExecution
ExternalTestCase externalTestCase = this.externalTestCaseRepository
.findByExternalIdAndExternalSystemId(testCaseId.toString(),
this.getSystemId());
Expand Down

0 comments on commit fefcac8

Please sign in to comment.