[system test] Add remove agent handler just after setting up agent #2449
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Relates #2039
Follows #2409
Ensure Elastic Agent created when using Independent Agents (default method via
r.setupAgent) is removed even if the service exists with error.Example of Buildkite build where service containers fails (e.g. mysql) and the agent is not removed:
https://buildkite.com/elastic/integrations/builds/22965
One example of this scenario is when the service container cannot started (it exits with failure). In that case, the new Elastic Agent created was not removed in the tear down process and therefore the corresponding Agent policies were not able to be deleted.
This PR duplicates the call to
checkEnrolledAgentsjust after setting up the Elastic Agent so even in the casesetupServicefails, the new Elastic Agent can be deleted in the tear down process.It needs to be duplicated this call since
r.setupServicecould create new agents in case of the kubernetes service deployer or the custom agents deployer (the latter is deprecated) if the Elastic Agent of the stack is used (disabled Independent Elastic Agents).In this buildkite build (with the changes of this PR),
mysqlnow reports the container exit as error in xUnit files:https://buildkite.com/elastic/integrations/builds/22973