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

Commit a286c90

Browse files
jalvzmergify-bot
authored andcommitted
Add a standalone test scenario for fleet server mode (#978)
(cherry picked from commit 83ace74)
1 parent 5426d19 commit a286c90

4 files changed

Lines changed: 45 additions & 4 deletions

File tree

cli/config/compose/services/elastic-agent/docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ services:
1010
condition: service_healthy
1111
environment:
1212
- "KIBANA_HOST=http://${kibanaHost:-kibana}:${kibanaPort:-5601}"
13+
- "FLEET_SERVER_ENABLE=${fleetServerMode:-0}"
14+
- "FLEET_SERVER_INSECURE_HTTP=${fleetServerMode:-0}"
15+
- "KIBANA_FLEET_SETUP=${fleetServerMode:-0}"
16+
- "FLEET_SERVER_HOST=0.0.0.0"
17+
- "KIBANA_USERNAME=elastic"
18+
- "KIBANA_PASSWORD=changeme"
1319
platform: ${elasticAgentPlatform:-linux/amd64}
20+
ports:
21+
- "127.0.0.1:8220:8220"
1422
volumes:
1523
- "${elasticAgentConfigFile}:/usr/share/elastic-agent/elastic-agent.yml"

e2e/_suites/fleet/features/stand_alone_agent.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,13 @@ Examples: default
5050
Examples: Ubi8
5151
| image |
5252
| ubi8 |
53+
54+
@run_fleet_server
55+
Scenario Outline: Deploying a <image> stand-alone agent with fleet server mode
56+
When a "<image>" stand-alone agent is deployed with fleet server mode
57+
Then the agent is listed in Fleet as "online"
58+
59+
@default
60+
Examples: default
61+
| image |
62+
| default |

e2e/_suites/fleet/fleet.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ func (fts *FleetTestSuite) setup() error {
406406
}
407407

408408
func (fts *FleetTestSuite) theAgentIsListedInFleetWithStatus(desiredStatus string) error {
409+
return theAgentIsListedInFleetWithStatus(desiredStatus, fts.Hostname)
410+
}
411+
412+
func theAgentIsListedInFleetWithStatus(desiredStatus, hostname string) error {
409413
log.Tracef("Checking if agent is listed in Fleet as %s", desiredStatus)
410414

411415
maxTimeout := time.Duration(timeoutFactor) * time.Minute * 2
@@ -414,7 +418,7 @@ func (fts *FleetTestSuite) theAgentIsListedInFleetWithStatus(desiredStatus strin
414418
exp := e2e.GetExponentialBackOff(maxTimeout)
415419

416420
agentOnlineFn := func() error {
417-
agentID, err := getAgentID(fts.Hostname)
421+
agentID, err := getAgentID(hostname)
418422
if err != nil {
419423
retryCount++
420424
return err
@@ -425,7 +429,7 @@ func (fts *FleetTestSuite) theAgentIsListedInFleetWithStatus(desiredStatus strin
425429
if desiredStatus == "offline" || desiredStatus == "inactive" {
426430
log.WithFields(log.Fields{
427431
"elapsedTime": exp.GetElapsedTime(),
428-
"hostname": fts.Hostname,
432+
"hostname": hostname,
429433
"retries": retryCount,
430434
"status": desiredStatus,
431435
}).Info("The Agent is not present in Fleet, as expected")
@@ -446,7 +450,7 @@ func (fts *FleetTestSuite) theAgentIsListedInFleetWithStatus(desiredStatus strin
446450
"agentID": agentID,
447451
"isAgentInStatus": isAgentInStatus,
448452
"elapsedTime": exp.GetElapsedTime(),
449-
"hostname": fts.Hostname,
453+
"hostname": hostname,
450454
"retry": retryCount,
451455
"status": desiredStatus,
452456
}).Warn(err.Error())
@@ -459,7 +463,7 @@ func (fts *FleetTestSuite) theAgentIsListedInFleetWithStatus(desiredStatus strin
459463
log.WithFields(log.Fields{
460464
"isAgentInStatus": isAgentInStatus,
461465
"elapsedTime": exp.GetElapsedTime(),
462-
"hostname": fts.Hostname,
466+
"hostname": hostname,
463467
"retries": retryCount,
464468
"status": desiredStatus,
465469
}).Info("The Agent is in the desired status")

e2e/_suites/fleet/stand-alone.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,27 @@ func (sats *StandAloneTestSuite) afterScenario() {
6464

6565
func (sats *StandAloneTestSuite) contributeSteps(s *godog.ScenarioContext) {
6666
s.Step(`^a "([^"]*)" stand-alone agent is deployed$`, sats.aStandaloneAgentIsDeployed)
67+
s.Step(`^a "([^"]*)" stand-alone agent is deployed with fleet server mode$`, sats.aStandaloneAgentIsDeployedWithFleetServerMode)
6768
s.Step(`^there is new data in the index from agent$`, sats.thereIsNewDataInTheIndexFromAgent)
6869
s.Step(`^the "([^"]*)" docker container is stopped$`, sats.theDockerContainerIsStopped)
6970
s.Step(`^there is no new data in the index after agent shuts down$`, sats.thereIsNoNewDataInTheIndexAfterAgentShutsDown)
71+
s.Step(`^the agent is listed in Fleet as "([^"]*)"$`, sats.theAgentIsListedInFleetWithStatus)
72+
}
73+
74+
func (sats *StandAloneTestSuite) theAgentIsListedInFleetWithStatus(desiredStatus string) error {
75+
return theAgentIsListedInFleetWithStatus(desiredStatus, sats.Hostname)
76+
}
77+
78+
func (sats *StandAloneTestSuite) aStandaloneAgentIsDeployedWithFleetServerMode(image string) error {
79+
return sats.startAgent(image, map[string]string{"fleetServerMode": "1"})
7080
}
7181

7282
func (sats *StandAloneTestSuite) aStandaloneAgentIsDeployed(image string) error {
83+
return sats.startAgent(image, nil)
84+
}
85+
86+
func (sats *StandAloneTestSuite) startAgent(image string, env map[string]string) error {
87+
7388
log.Trace("Deploying an agent to Fleet")
7489

7590
dockerImageTag := agentVersion
@@ -110,6 +125,10 @@ func (sats *StandAloneTestSuite) aStandaloneAgentIsDeployed(image string) error
110125
profileEnv["elasticAgentPlatform"] = "linux/amd64"
111126
profileEnv["elasticAgentTag"] = dockerImageTag
112127

128+
for k, v := range env {
129+
profileEnv[k] = v
130+
}
131+
113132
err = serviceManager.AddServicesToCompose(context.Background(), FleetProfileName, []string{ElasticAgentServiceName}, profileEnv)
114133
if err != nil {
115134
log.Error("Could not deploy the elastic-agent")

0 commit comments

Comments
 (0)