Skip to content

Commit

Permalink
Review tear down test system handlers (#2252)
Browse files Browse the repository at this point in the history
When using independent Elastic Agents, those agents created are
going to be removed/uninstalled at the end of the test run, so there
is no need to run those two handlers. There is a special case where
it needs to be kept the reassignment of the policy when using the
"--no-provision" flag in system tests.
  • Loading branch information
mrodm authored Dec 9, 2024
1 parent 6926cc8 commit 562c59e
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions internal/testrunner/runners/system/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,14 @@ func (r *tester) prepareScenario(ctx context.Context, config *testConfig, svcInf
// triggered with the flags for running spolicyToAssignDatastreamTestsetup stage (--setup)
return nil
}

// RunTestOnly step (--no-provision) should also reassign back the previous (original) policy
// even with with independent Elastic Agents, since this step creates a new test policy each execution
// Moreover, ensure there is no agent service deployer (deprecated) being used
if scenario.agent != nil && r.runIndependentElasticAgent && !r.runTestsOnly {
return nil
}

logger.Debug("reassigning original policy back to agent...")
if err := r.kibanaClient.AssignPolicyToAgent(ctx, agent, origPolicy); err != nil {
return fmt.Errorf("error reassigning original policy to agent: %w", err)
Expand All @@ -1151,9 +1159,17 @@ func (r *tester) prepareScenario(ctx context.Context, config *testConfig, svcInf
}
}
r.resetAgentLogLevelHandler = func(ctx context.Context) error {
if r.runTestsOnly {
if r.runTestsOnly || r.runSetup {
return nil
}

// No need to reset agent log level when running independent Elastic Agents
// since the Elastic Agent is going to be removed/uninstalled
// Morevoer, ensure there is no agent service deployer (deprecated) being used
if scenario.agent != nil && r.runIndependentElasticAgent {
return nil
}

logger.Debugf("reassigning original log level %q back to agent...", origLogLevel)

if err := r.kibanaClient.SetAgentLogLevel(ctx, agent.ID, origLogLevel); err != nil {
Expand Down Expand Up @@ -1302,7 +1318,7 @@ func (r *tester) setupService(ctx context.Context, config *testConfig, serviceOp
svcInfo.AgentNetworkName = agentInfo.NetworkName
}

// Set the right folder for logs execpt for custom agents that are still deployed using "servicedeployer"
// Set the right folder for logs except for custom agents that are still deployed using "servicedeployer"
if r.runIndependentElasticAgent && agentDeployed != nil {
svcInfo.Logs.Folder.Local = agentInfo.Logs.Folder.Local
}
Expand Down

0 comments on commit 562c59e

Please sign in to comment.