Skip to content

Commit

Permalink
Update system testrunner to allow parallel executions (#1838)
Browse files Browse the repository at this point in the history
Update system test runner as a preparation to allow parallel
execution of these tests. Among other changes, it has been
required to update Compose project names used to create the
Elastic Agent as well as the services configured in the package.
It has also been added a service alias between Service container
and Elastic Agent container.
  • Loading branch information
mrodm authored May 20, 2024
1 parent 3aee4ad commit 99ad2d6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion internal/agentdeployer/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (d *DockerComposeAgentDeployer) SetUp(ctx context.Context, agentInfo AgentI
return nil, fmt.Errorf("could not create resources for custom agent: %w", err)
}

composeProjectName := fmt.Sprintf("elastic-package-agent-%s", d.agentName())
composeProjectName := fmt.Sprintf("elastic-package-agent-%s-%s", d.agentName(), agentInfo.Test.RunID)

agent := dockerComposeDeployedAgent{
ymlPaths: []string{filepath.Join(configDir, dockerTestAgentDockerCompose)},
Expand Down
11 changes: 10 additions & 1 deletion internal/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,16 @@ func InspectNetwork(network string) ([]NetworkDescription, error) {

// ConnectToNetwork function connects the container to the selected Docker network.
func ConnectToNetwork(containerID, network string) error {
cmd := exec.Command("docker", "network", "connect", network, containerID)
return ConnectToNetworkWithAlias(containerID, network, "")
}

// ConnectToNetworkWithAlias function connects the container to the selected Docker network.
func ConnectToNetworkWithAlias(containerID, network, alias string) error {
args := []string{"network", "connect", network, containerID}
if alias != "" {
args = append(args, "--alias", alias)
}
cmd := exec.Command("docker", args...)
errOutput := new(bytes.Buffer)
cmd.Stderr = errOutput

Expand Down
4 changes: 2 additions & 2 deletions internal/servicedeployer/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (d *DockerComposeServiceDeployer) SetUp(ctx context.Context, svcInfo Servic
logger.Debug("setting up service using Docker Compose service deployer")
service := dockerComposeDeployedService{
ymlPaths: d.ymlPaths,
project: "elastic-package-service",
project: fmt.Sprintf("elastic-package-service-%s", svcInfo.Test.RunID),
variant: d.variant,
env: []string{
fmt.Sprintf("%s=%s", serviceLogsDirEnv, svcInfo.Logs.Folder.Local),
Expand Down Expand Up @@ -141,7 +141,7 @@ func (d *DockerComposeServiceDeployer) SetUp(ctx context.Context, svcInfo Servic
} else {
if d.deployIndependentAgent {
// Connect service network with agent network
err = docker.ConnectToNetwork(p.ContainerName(serviceName), svcInfo.AgentNetworkName)
err = docker.ConnectToNetworkWithAlias(p.ContainerName(serviceName), svcInfo.AgentNetworkName, svcInfo.Name)
if err != nil {
return nil, fmt.Errorf("can't attach service container to the agent network: %w", err)
}
Expand Down
13 changes: 8 additions & 5 deletions internal/testrunner/runners/system/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ func (r *runner) prepareScenario(ctx context.Context, config *testConfig, svcInf
scenario.startTestTime = time.Now()

logger.Debug("adding package data stream to test policy...")
ds := createPackageDatastream(*policyToTest, *scenario.pkgManifest, policyTemplate, *scenario.dataStreamManifest, *config)
ds := createPackageDatastream(*policyToTest, *scenario.pkgManifest, policyTemplate, *scenario.dataStreamManifest, *config, svcInfo.Test.RunID)
if r.options.RunTearDown || r.options.RunTestsOnly {
logger.Debug("Skip adding data stream config to policy")
} else {
Expand Down Expand Up @@ -1547,11 +1547,12 @@ func createPackageDatastream(
policyTemplate packages.PolicyTemplate,
ds packages.DataStreamManifest,
config testConfig,
suffix string,
) kibana.PackageDataStream {
if pkg.Type == "input" {
return createInputPackageDatastream(kibanaPolicy, pkg, policyTemplate, config)
return createInputPackageDatastream(kibanaPolicy, pkg, policyTemplate, config, suffix)
}
return createIntegrationPackageDatastream(kibanaPolicy, pkg, policyTemplate, ds, config)
return createIntegrationPackageDatastream(kibanaPolicy, pkg, policyTemplate, ds, config, suffix)
}

func createIntegrationPackageDatastream(
Expand All @@ -1560,9 +1561,10 @@ func createIntegrationPackageDatastream(
policyTemplate packages.PolicyTemplate,
ds packages.DataStreamManifest,
config testConfig,
suffix string,
) kibana.PackageDataStream {
r := kibana.PackageDataStream{
Name: fmt.Sprintf("%s-%s", pkg.Name, ds.Name),
Name: fmt.Sprintf("%s-%s-%s", pkg.Name, ds.Name, suffix),
Namespace: "ep",
PolicyID: kibanaPolicy.ID,
Enabled: true,
Expand Down Expand Up @@ -1613,9 +1615,10 @@ func createInputPackageDatastream(
pkg packages.PackageManifest,
policyTemplate packages.PolicyTemplate,
config testConfig,
suffix string,
) kibana.PackageDataStream {
r := kibana.PackageDataStream{
Name: fmt.Sprintf("%s-%s", pkg.Name, policyTemplate.Name),
Name: fmt.Sprintf("%s-%s-%s", pkg.Name, policyTemplate.Name, suffix),
Namespace: "ep",
PolicyID: kibanaPolicy.ID,
Enabled: true,
Expand Down
7 changes: 4 additions & 3 deletions scripts/test-system-test-flags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ trap cleanup EXIT

container_ids() {
local container="$1"
docker ps --format "{{ .ID}} {{ .Names}}" | grep "${container}" | awk '{print $1}'
docker ps --format "{{ .ID}} {{ .Names}}" | grep -E "${container}" | awk '{print $1}'
}

is_network_created() {
Expand Down Expand Up @@ -288,14 +288,15 @@ FOLDER_PATH="${HOME}/.elastic-package/profiles/default/stack/state"
# Check also if independent Elastic Agents are running too
# depending on the environment variable
service_deployer_type="docker"
service_preffix='elastic-package-service-[0-9]{5}'
if [[ "${ELASTIC_PACKAGE_TEST_ENABLE_INDEPENDENT_AGENT:-"false"}" == "true" ]]; then
service_deployer_type="agent"
fi

# docker service deployer
if ! run_tests_for_package \
"test/packages/parallel/nginx" \
"elastic-package-service-nginx" \
"${service_preffix}-nginx" \
"data_stream/access/_dev/test/system/test-default-config.yml" \
"no variant" \
"${service_deployer_type}" ; then
Expand All @@ -305,7 +306,7 @@ fi

if ! run_tests_for_package \
"test/packages/parallel/sql_input" \
"elastic-package-service-sql_input" \
"${service_preffix}-sql_input" \
"_dev/test/system/test-default-config.yml" \
"mysql_8_0_13" \
"${service_deployer_type}" ; then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
vars:
hosts:
- "oracle://sys:Oradoc_db1@elastic-package-service-oracle-1:1521/ORCLCDB.localdomain?sysdba=1"
- "oracle://sys:Oradoc_db1@{{Hostname}}:{{Port}}/ORCLCDB.localdomain?sysdba=1"
agent:
runtime: docker
provisioning_script:
Expand Down

0 comments on commit 99ad2d6

Please sign in to comment.