From 562c59ea714046cac830a8706c8ce93ee1a5ffd4 Mon Sep 17 00:00:00 2001 From: Mario Rodriguez Molins Date: Mon, 9 Dec 2024 11:29:38 +0100 Subject: [PATCH] Review tear down test system handlers (#2252) 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. --- internal/testrunner/runners/system/tester.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/internal/testrunner/runners/system/tester.go b/internal/testrunner/runners/system/tester.go index 3096360073..ddab187d86 100644 --- a/internal/testrunner/runners/system/tester.go +++ b/internal/testrunner/runners/system/tester.go @@ -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) @@ -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 { @@ -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 }