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

Commit

Permalink
Unify fleet and stand-alone suites (#1112)
Browse files Browse the repository at this point in the history
* fix agent uninstall

* unify fleet and stand alone suites

* move things around a bit more

* fixe bad merge

* simplify some things

(cherry picked from commit 77a2c55)

# Conflicts:
#	e2e/_suites/fleet/features/apm_integration.feature
#	e2e/_suites/fleet/fleet.go
#	e2e/_suites/fleet/stand-alone.go
#	e2e/_suites/fleet/world.go
  • Loading branch information
jalvz authored and mergify-bot committed May 5, 2021
1 parent 6598655 commit 9781df0
Show file tree
Hide file tree
Showing 5 changed files with 292 additions and 120 deletions.
30 changes: 30 additions & 0 deletions e2e/_suites/fleet/features/apm_integration.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@apm_server
Feature: APM Integration
Scenarios for APM

@install
Scenario Outline: Deploying a <image> stand-alone agent with fleet server mode
Given a "<image>" stand-alone agent is deployed with fleet server mode
And the stand-alone agent is listed in Fleet as "online"
When the "Elastic APM" integration is added in the policy
Then the "Elastic APM" datasource is shown in the policy as added
And the "apm-server" process is in the "started" state on the host


@default
Examples: default
| image |
| default |



@cloud
Scenario Outline: Deploying a <image> stand-alone agent with fleet server mode on cloud
When a "<image>" stand-alone agent is deployed with fleet server mode on cloud
Then the "apm-server" process is in the "started" state on the host


@default
Examples: default
| image |
| default |
149 changes: 145 additions & 4 deletions e2e/_suites/fleet/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const actionREMOVED = "removed"
// FleetTestSuite represents the scenarios for Fleet-mode
type FleetTestSuite struct {
// integrations
Cleanup bool
StandAlone bool
CurrentToken string // current enrollment token
CurrentTokenID string // current enrollment tokenID
ElasticAgentStopped bool // will be used to signal when the agent process can be called again in the tear-down stage
Expand All @@ -45,12 +45,20 @@ type FleetTestSuite struct {
PolicyUpdatedAt string // the moment the policy was updated
Version string // current elastic-agent version
kibanaClient *kibana.Client
<<<<<<< HEAD
=======
// fleet server
FleetServerHostname string // hostname of the fleet server. If empty, it means the agent is the first one, bootstrapping fleet server
// date controls for queries
AgentStoppedDate time.Time
RuntimeDependenciesStartDate time.Time
>>>>>>> 77a2c554... Unify fleet and stand-alone suites (#1112)
}

// afterScenario destroys the state created by a scenario
func (fts *FleetTestSuite) afterScenario() {
serviceManager := compose.NewServiceManager()

<<<<<<< HEAD
serviceName := fts.Image

if log.IsLevelEnabled(log.DebugLevel) {
Expand All @@ -64,13 +72,33 @@ func (fts *FleetTestSuite) afterScenario() {
}).Warn("Could not get agent logs in the container")
}

=======
serviceName := common.ElasticAgentServiceName
serviceManager := compose.NewServiceManager()

if !fts.StandAlone {
agentInstaller := fts.getInstaller()
serviceName = fts.getServiceName(agentInstaller)

if log.IsLevelEnabled(log.DebugLevel) {
err := agentInstaller.PrintLogsFn(fts.Hostname)
if err != nil {
log.WithFields(log.Fields{
"containerName": fts.Hostname,
"error": err,
}).Warn("Could not get agent logs in the container")
}
}
>>>>>>> 77a2c554... Unify fleet and stand-alone suites (#1112)
// only call it when the elastic-agent is present
if !fts.ElasticAgentStopped {
err := agentInstaller.UninstallFn()
if err != nil {
log.Warnf("Could not uninstall the agent after the scenario: %v", err)
}
}
} else if log.IsLevelEnabled(log.DebugLevel) {
_ = fts.getContainerLogs()
}

err := fts.unenrollHostname()
Expand Down Expand Up @@ -122,11 +150,16 @@ func (fts *FleetTestSuite) afterScenario() {
fts.CurrentToken = ""
fts.Image = ""
fts.Hostname = ""
<<<<<<< HEAD
=======
fts.FleetServerHostname = ""
fts.StandAlone = false
>>>>>>> 77a2c554... Unify fleet and stand-alone suites (#1112)
}

// beforeScenario creates the state needed by a scenario
func (fts *FleetTestSuite) beforeScenario() {
fts.Cleanup = false
fts.StandAlone = false
fts.ElasticAgentStopped = false

fts.Version = common.AgentVersion
Expand Down Expand Up @@ -177,8 +210,45 @@ func (fts *FleetTestSuite) contributeSteps(s *godog.ScenarioContext) {
s.Step(`^the policy is updated to have "([^"]*)" in "([^"]*)" mode$`, fts.thePolicyIsUpdatedToHaveMode)
s.Step(`^the policy will reflect the change in the Security App$`, fts.thePolicyWillReflectTheChangeInTheSecurityApp)

<<<<<<< HEAD
// fleet server steps
s.Step(`^a "([^"]*)" agent is deployed to Fleet with "([^"]*)" installer in fleet-server mode$`, fts.anAgentIsDeployedToFleetWithInstallerInFleetMode)
=======
// stand-alone only steps
s.Step(`^a "([^"]*)" stand-alone agent is deployed$`, fts.aStandaloneAgentIsDeployed)
s.Step(`^a "([^"]*)" stand-alone agent is deployed with fleet server mode$`, fts.bootstrapFleetServerFromAStandaloneAgent)
s.Step(`^a "([^"]*)" stand-alone agent is deployed with fleet server mode on cloud$`, fts.aStandaloneAgentIsDeployedWithFleetServerModeOnCloud)
s.Step(`^there is new data in the index from agent$`, fts.thereIsNewDataInTheIndexFromAgent)
s.Step(`^the "([^"]*)" docker container is stopped$`, fts.theDockerContainerIsStopped)
s.Step(`^there is no new data in the index after agent shuts down$`, fts.thereIsNoNewDataInTheIndexAfterAgentShutsDown)
s.Step(`^the stand-alone agent is listed in Fleet as "([^"]*)"$`, fts.theStandaloneAgentIsListedInFleetWithStatus)
}

func (fts *FleetTestSuite) theStandaloneAgentIsListedInFleetWithStatus(desiredStatus string) error {
waitForAgents := func() error {
agents, err := fts.kibanaClient.ListAgents()
if err != nil {
return err
}

if len(agents) == 0 {
return errors.New("No agents found")
}

agentZero := agents[0]
hostname := agentZero.LocalMetadata.Host.HostName

return theAgentIsListedInFleetWithStatus(desiredStatus, hostname)
}
maxTimeout := time.Duration(common.TimeoutFactor) * time.Minute * 2
exp := common.GetExponentialBackOff(maxTimeout)

err := backoff.Retry(waitForAgents, exp)
if err != nil {
return err
}
return nil
>>>>>>> 77a2c554... Unify fleet and stand-alone suites (#1112)
}

func (fts *FleetTestSuite) anStaleAgentIsDeployedToFleetWithInstaller(image, version, installerType string) error {
Expand Down Expand Up @@ -327,7 +397,6 @@ func (fts *FleetTestSuite) anAgentIsDeployedToFleetWithInstallerAndFleetServer(i
var fleetConfig *kibana.FleetConfig
fleetConfig, err = deployAgentToFleet(agentInstaller, containerName, fts.CurrentToken, bootstrapFleetServer)

fts.Cleanup = true
if err != nil {
return err
}
Expand Down Expand Up @@ -678,6 +747,7 @@ func (fts *FleetTestSuite) theEnrollmentTokenIsRevoked() error {
return nil
}

<<<<<<< HEAD
func (fts *FleetTestSuite) thePolicyShowsTheDatasourceAdded(packageName string) error {
log.WithFields(log.Fields{
"policyID": fts.FleetPolicy.ID,
Expand Down Expand Up @@ -714,6 +784,8 @@ func (fts *FleetTestSuite) thePolicyShowsTheDatasourceAdded(packageName string)
return nil
}

=======
>>>>>>> 77a2c554... Unify fleet and stand-alone suites (#1112)
func (fts *FleetTestSuite) theIntegrationIsOperatedInThePolicy(packageName string, action string) error {
log.WithFields(log.Fields{
"action": action,
Expand Down Expand Up @@ -1220,3 +1292,72 @@ func deployAgentToFleet(agentInstaller installer.ElasticAgentInstaller, containe

return cfg, agentInstaller.PostInstallFn()
}
<<<<<<< HEAD
=======

func inputs(integration string) []kibana.Input {
switch integration {
case "apm":
return []kibana.Input{
{
Type: "apm",
Enabled: true,
Streams: []interface{}{},
Vars: map[string]kibana.Var{
"apm-server": {
Value: "host",
Type: "localhost:8200",
},
},
},
}
case "linux":
return []kibana.Input{
{
Type: "linux/metrics",
Enabled: true,
Streams: []interface{}{
map[string]interface{}{
"id": "linux/metrics-linux.memory-" + uuid.New().String(),
"enabled": true,
"data_stream": map[string]interface{}{
"dataset": "linux.memory",
"type": "metrics",
},
},
},
Vars: map[string]kibana.Var{
"period": {
Value: "1s",
Type: "string",
},
},
},
}
}
return []kibana.Input{}
}

func (fts *FleetTestSuite) getContainerLogs() error {
serviceManager := compose.NewServiceManager()

profile := common.FleetProfileName
serviceName := common.ElasticAgentServiceName

composes := []string{
profile, // profile name
serviceName, // agent service
}
err := serviceManager.RunCommand(profile, composes, []string{"logs", serviceName}, common.ProfileEnv)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"service": serviceName,
}).Error("Could not retrieve Elastic Agent logs")

return err
}

return nil
}
>>>>>>> 77a2c554... Unify fleet and stand-alone suites (#1112)
18 changes: 2 additions & 16 deletions e2e/_suites/fleet/ingest_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,37 +89,23 @@ func setUpSuite() {
kibanaClient: kibanaClient,
Installers: map[string]installer.ElasticAgentInstaller{}, // do not pre-initialise the map
},
StandAlone: &StandAloneTestSuite{
kibanaClient: kibanaClient,
},
}
}

func InitializeIngestManagerTestScenario(ctx *godog.ScenarioContext) {
ctx.BeforeScenario(func(*messages.Pickle) {
log.Trace("Before Fleet scenario")

imts.StandAlone.Cleanup = false

imts.Fleet.beforeScenario()
})

ctx.AfterScenario(func(*messages.Pickle, error) {
log.Trace("After Fleet scenario")

if imts.StandAlone.Cleanup {
imts.StandAlone.afterScenario()
}

if imts.Fleet.Cleanup {
imts.Fleet.afterScenario()
}
imts.Fleet.afterScenario()
})

ctx.Step(`^the "([^"]*)" process is in the "([^"]*)" state on the host$`, imts.processStateOnTheHost)

imts.Fleet.contributeSteps(ctx)
imts.StandAlone.contributeSteps(ctx)
}

func InitializeIngestManagerTestSuite(ctx *godog.TestSuiteContext) {
Expand Down Expand Up @@ -175,7 +161,7 @@ func InitializeIngestManagerTestSuite(ctx *godog.TestSuiteContext) {

imts.Fleet.setup()

imts.StandAlone.RuntimeDependenciesStartDate = time.Now().UTC()
imts.Fleet.RuntimeDependenciesStartDate = time.Now().UTC()
})

ctx.AfterSuite(func() {
Expand Down
Loading

0 comments on commit 9781df0

Please sign in to comment.