Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 6a7e6a7

Browse files
committed
feat: download the agent once, mounting it as a volume
1 parent c17e637 commit 6a7e6a7

File tree

3 files changed

+58
-28
lines changed

3 files changed

+58
-28
lines changed

cli/config/compose/services/centos/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ services:
44
image: centos:${centosTag:-7}
55
container_name: ${centosContainerName}
66
entrypoint: tail -f /dev/null
7+
volumes:
8+
- ${centosAgentBinarySrcPath:-.}:${centosAgentBinaryTargetPath:-/tmp}

e2e/_suites/ingest-manager/fleet.go

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ const ingestManagerDataStreamsURL = kibanaBaseURL + "/api/ingest_manager/data_st
2424

2525
// FleetTestSuite represents the scenarios for Fleet-mode
2626
type FleetTestSuite struct {
27-
EnrolledAgentID string // will be used to store current agent
28-
BoxType string // we currently support Linux
29-
Cleanup bool
30-
ConfigID string // will be used to manage tokens
31-
CurrentToken string // current enrollment token
32-
CurrentTokenID string // current enrollment tokenID
27+
AgentDownloadName string // the name for the binary
28+
AgentDownloadPath string // the path where the agent for the binary is installed
29+
EnrolledAgentID string // will be used to store current agent
30+
BoxType string // we currently support Linux
31+
Cleanup bool
32+
ConfigID string // will be used to manage tokens
33+
CurrentToken string // current enrollment token
34+
CurrentTokenID string // current enrollment tokenID
3335
}
3436

3537
func (fts *FleetTestSuite) contributeSteps(s *godog.Suite) {
@@ -52,7 +54,7 @@ func (fts *FleetTestSuite) anAgentIsDeployedToFleet() error {
5254
containerName := profile + "_" + serviceName + "_1" // name of the container
5355
serviceTag := "7" // docker tag of the service
5456

55-
err := deployAgentToFleet(profile, fts.BoxType, serviceTag, containerName)
57+
err := deployAgentToFleet(profile, fts.BoxType, serviceTag, containerName, fts.AgentDownloadPath, fts.AgentDownloadName)
5658
if err != nil {
5759
return err
5860
}
@@ -83,6 +85,25 @@ func (fts *FleetTestSuite) anAgentIsDeployedToFleet() error {
8385
return err
8486
}
8587

88+
// downloadAgentBinary it downloads the binary and stores the location of the downloaded file
89+
// into the Fleet struct, to be used else where
90+
func (fts *FleetTestSuite) downloadAgentBinary() error {
91+
artifact := "elastic-agent"
92+
version := "8.0.0-SNAPSHOT"
93+
os := "linux"
94+
arch := "x86_64"
95+
extension := "tar.gz"
96+
97+
downloadURL, err := e2e.GetElasticArtifactURL(artifact, version, os, arch, extension)
98+
if err != nil {
99+
return err
100+
}
101+
102+
fts.AgentDownloadName = fmt.Sprintf("%s-%s-%s-%s.%s", artifact, version, os, arch, extension)
103+
fts.AgentDownloadPath, err = e2e.DownloadFile(downloadURL)
104+
return err
105+
}
106+
86107
func (fts *FleetTestSuite) setup() error {
87108
log.Debug("Creating Fleet setup")
88109

@@ -341,7 +362,7 @@ func (fts *FleetTestSuite) anAttemptToEnrollANewAgentFails() error {
341362

342363
containerName := profile + "_" + fts.BoxType + "_2" // name of the new container
343364

344-
err := deployAgentToFleet(profile, fts.BoxType, serviceTag, containerName)
365+
err := deployAgentToFleet(profile, fts.BoxType, serviceTag, containerName, fts.AgentDownloadPath, fts.AgentDownloadName)
345366
if err != nil {
346367
return err
347368
}
@@ -518,11 +539,14 @@ func createFleetToken(name string, configID string) (*gabs.Container, error) {
518539
return tokenItem, nil
519540
}
520541

521-
func deployAgentToFleet(profile string, service string, serviceTag string, containerName string) error {
542+
func deployAgentToFleet(profile string, service string, serviceTag string, containerName string, agentBinaryPath string, agentBinaryName string) error {
522543
// let's start with Centos 7
523544
profileEnv[service+"Tag"] = serviceTag
524545
// we are setting the container name because Centos service could be reused by any other test suite
525546
profileEnv[service+"ContainerName"] = containerName
547+
// define paths where the binary will be mounted
548+
profileEnv[service+"AgentBinarySrcPath"] = agentBinaryPath
549+
profileEnv[service+"AgentBinaryTargetPath"] = "/" + agentBinaryName
526550

527551
serviceManager := services.NewServiceManager()
528552

@@ -535,34 +559,17 @@ func deployAgentToFleet(profile string, service string, serviceTag string, conta
535559
return err
536560
}
537561

538-
// install the agent in the box
562+
// extract the agent in the box, as it's mounted as a volume
539563
artifact := "elastic-agent"
540564
version := "8.0.0-SNAPSHOT"
541565
os := "linux"
542566
arch := "x86_64"
543567
extension := "tar.gz"
544568

545-
downloadURL, err := e2e.GetElasticArtifactURL(artifact, version, os, arch, extension)
546-
if err != nil {
547-
return err
548-
}
549-
550-
cmd := []string{"curl", "-L", "-O", downloadURL}
551-
err = execCommandInService(profile, service, cmd, false)
552-
if err != nil {
553-
log.WithFields(log.Fields{
554-
"command": cmd,
555-
"error": err,
556-
"service": service,
557-
}).Error("Could not download agent in box")
558-
559-
return err
560-
}
561-
562569
extractedDir := fmt.Sprintf("%s-%s-%s-%s", artifact, version, os, arch)
563570
tarFile := fmt.Sprintf("%s.%s", extractedDir, extension)
564571

565-
cmd = []string{"tar", "xzvf", tarFile}
572+
cmd := []string{"tar", "xzvf", tarFile}
566573
err = execCommandInService(profile, service, cmd, false)
567574
if err != nil {
568575
log.WithFields(log.Fields{

e2e/_suites/ingest-manager/ingest-manager_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ func IngestManagerFeatureContext(s *godog.Suite) {
8484
imts.Fleet.setup()
8585

8686
imts.StandAlone.RuntimeDependenciesStartDate = time.Now().UTC()
87+
88+
err = imts.Fleet.downloadAgentBinary()
89+
if err != nil {
90+
log.WithFields(log.Fields{
91+
"error": err,
92+
}).Fatal("The Elastic Agent could not be downloaded")
93+
}
8794
})
8895
s.BeforeScenario(func(*messages.Pickle) {
8996
log.Debug("Before Ingest Manager scenario")
@@ -101,6 +108,20 @@ func IngestManagerFeatureContext(s *godog.Suite) {
101108
"profile": profile,
102109
}).Warn("Could not destroy the runtime dependencies for the profile.")
103110
}
111+
112+
if _, err := os.Stat(imts.Fleet.AgentDownloadPath); err == nil {
113+
err = os.Remove(imts.Fleet.AgentDownloadPath)
114+
if err != nil {
115+
log.WithFields(log.Fields{
116+
"err": err,
117+
"path": imts.Fleet.AgentDownloadPath,
118+
}).Warn("Elastic Agent binary could not be removed.")
119+
} else {
120+
log.WithFields(log.Fields{
121+
"path": imts.Fleet.AgentDownloadPath,
122+
}).Debug("Elastic Agent binary was removed.")
123+
}
124+
}
104125
})
105126
s.AfterScenario(func(*messages.Pickle, error) {
106127
log.Debug("After Ingest Manager scenario")

0 commit comments

Comments
 (0)