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

Commit 15d2db5

Browse files
authored
Merge pull request #179 from mdelapenya/177-download-agent-once
feat: download the agent once, mounting it as a volume
2 parents 6c23879 + 6a7e6a7 commit 15d2db5

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
@@ -28,12 +28,14 @@ const ingestManagerDataStreamsURL = kibanaBaseURL + "/api/ingest_manager/data_st
2828

2929
// FleetTestSuite represents the scenarios for Fleet-mode
3030
type FleetTestSuite struct {
31-
EnrolledAgentID string // will be used to store current agent
32-
BoxType string // we currently support Linux
33-
Cleanup bool
34-
ConfigID string // will be used to manage tokens
35-
CurrentToken string // current enrollment token
36-
CurrentTokenID string // current enrollment tokenID
31+
AgentDownloadName string // the name for the binary
32+
AgentDownloadPath string // the path where the agent for the binary is installed
33+
EnrolledAgentID string // will be used to store current agent
34+
BoxType string // we currently support Linux
35+
Cleanup bool
36+
ConfigID string // will be used to manage tokens
37+
CurrentToken string // current enrollment token
38+
CurrentTokenID string // current enrollment tokenID
3739
}
3840

3941
func (fts *FleetTestSuite) contributeSteps(s *godog.Suite) {
@@ -56,7 +58,7 @@ func (fts *FleetTestSuite) anAgentIsDeployedToFleet() error {
5658
containerName := profile + "_" + serviceName + "_1" // name of the container
5759
serviceTag := "7" // docker tag of the service
5860

59-
err := deployAgentToFleet(profile, fts.BoxType, serviceTag, containerName)
61+
err := deployAgentToFleet(profile, fts.BoxType, serviceTag, containerName, fts.AgentDownloadPath, fts.AgentDownloadName)
6062
if err != nil {
6163
return err
6264
}
@@ -87,6 +89,25 @@ func (fts *FleetTestSuite) anAgentIsDeployedToFleet() error {
8789
return err
8890
}
8991

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

@@ -345,7 +366,7 @@ func (fts *FleetTestSuite) anAttemptToEnrollANewAgentFails() error {
345366

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

348-
err := deployAgentToFleet(profile, fts.BoxType, serviceTag, containerName)
369+
err := deployAgentToFleet(profile, fts.BoxType, serviceTag, containerName, fts.AgentDownloadPath, fts.AgentDownloadName)
349370
if err != nil {
350371
return err
351372
}
@@ -522,11 +543,14 @@ func createFleetToken(name string, configID string) (*gabs.Container, error) {
522543
return tokenItem, nil
523544
}
524545

525-
func deployAgentToFleet(profile string, service string, serviceTag string, containerName string) error {
546+
func deployAgentToFleet(profile string, service string, serviceTag string, containerName string, agentBinaryPath string, agentBinaryName string) error {
526547
// let's start with Centos 7
527548
profileEnv[service+"Tag"] = serviceTag
528549
// we are setting the container name because Centos service could be reused by any other test suite
529550
profileEnv[service+"ContainerName"] = containerName
551+
// define paths where the binary will be mounted
552+
profileEnv[service+"AgentBinarySrcPath"] = agentBinaryPath
553+
profileEnv[service+"AgentBinaryTargetPath"] = "/" + agentBinaryName
530554

531555
serviceManager := services.NewServiceManager()
532556

@@ -539,34 +563,17 @@ func deployAgentToFleet(profile string, service string, serviceTag string, conta
539563
return err
540564
}
541565

542-
// install the agent in the box
566+
// extract the agent in the box, as it's mounted as a volume
543567
artifact := "elastic-agent"
544568
version := "8.0.0-SNAPSHOT"
545569
os := "linux"
546570
arch := "x86_64"
547571
extension := "tar.gz"
548572

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

569-
cmd = []string{"tar", "xzvf", tarFile}
576+
cmd := []string{"tar", "xzvf", tarFile}
570577
err = execCommandInService(profile, service, cmd, false)
571578
if err != nil {
572579
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
@@ -88,6 +88,13 @@ func IngestManagerFeatureContext(s *godog.Suite) {
8888
imts.Fleet.setup()
8989

9090
imts.StandAlone.RuntimeDependenciesStartDate = time.Now().UTC()
91+
92+
err = imts.Fleet.downloadAgentBinary()
93+
if err != nil {
94+
log.WithFields(log.Fields{
95+
"error": err,
96+
}).Fatal("The Elastic Agent could not be downloaded")
97+
}
9198
})
9299
s.BeforeScenario(func(*messages.Pickle) {
93100
log.Debug("Before Ingest Manager scenario")
@@ -105,6 +112,20 @@ func IngestManagerFeatureContext(s *godog.Suite) {
105112
"profile": profile,
106113
}).Warn("Could not destroy the runtime dependencies for the profile.")
107114
}
115+
116+
if _, err := os.Stat(imts.Fleet.AgentDownloadPath); err == nil {
117+
err = os.Remove(imts.Fleet.AgentDownloadPath)
118+
if err != nil {
119+
log.WithFields(log.Fields{
120+
"err": err,
121+
"path": imts.Fleet.AgentDownloadPath,
122+
}).Warn("Elastic Agent binary could not be removed.")
123+
} else {
124+
log.WithFields(log.Fields{
125+
"path": imts.Fleet.AgentDownloadPath,
126+
}).Debug("Elastic Agent binary was removed.")
127+
}
128+
}
108129
})
109130
s.AfterScenario(func(*messages.Pickle, error) {
110131
log.Debug("After Ingest Manager scenario")

0 commit comments

Comments
 (0)