Skip to content

Commit

Permalink
Skip error uninstalling system package (#1315)
Browse files Browse the repository at this point in the history
Skip errors uninstalling system package in the system and asset
testrunners (tear down process). For other packages failing during
this uninstallation process, a warning message is logged.
  • Loading branch information
mrodm authored Jun 21, 2023
1 parent 5f65dc2 commit 3b3dc09
Show file tree
Hide file tree
Showing 126 changed files with 45,205 additions and 7 deletions.
21 changes: 17 additions & 4 deletions internal/testrunner/runners/asset/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (r runner) CanRunPerDataStream() bool {
}

// Run runs the asset loading tests
func (r runner) Run(options testrunner.TestOptions) ([]testrunner.TestResult, error) {
func (r *runner) Run(options testrunner.TestOptions) ([]testrunner.TestResult, error) {
r.testFolder = options.TestFolder
r.packageRootPath = options.PackageRootPath

Expand Down Expand Up @@ -82,7 +82,11 @@ func (r *runner) run() ([]testrunner.TestResult, error) {
if err != nil {
return result.WithError(errors.Wrap(err, "could not create kibana client"))
}
packageInstaller, err := installer.CreateForManifest(kibanaClient, r.packageRootPath)
packageInstaller, err := installer.NewForPackage(installer.Options{
Kibana: kibanaClient,
RootPath: r.packageRootPath,
SkipValidation: true,
})
if err != nil {
return result.WithError(errors.Wrap(err, "can't create the package installer"))
}
Expand All @@ -92,9 +96,18 @@ func (r *runner) run() ([]testrunner.TestResult, error) {
}

r.removePackageHandler = func() error {
pkgManifest, err := packages.ReadPackageManifestFromPackageRoot(r.packageRootPath)
if err != nil {
return fmt.Errorf("reading package manifest failed: %w", err)
}

logger.Debug("removing package...")
if err := packageInstaller.Uninstall(); err != nil {
return errors.Wrap(err, "error cleaning up package")
err = packageInstaller.Uninstall()

// by default system package is part of an agent policy and it cannot be uninstalled
// https://github.com/elastic/elastic-package/blob/5f65dc29811c57454bc7142aaf73725b6d4dc8e6/internal/stack/_static/kibana.yml.tmpl#L62
if err != nil && pkgManifest.Name != "system" {
logger.Warnf("failed to uninstall package %q: %s", pkgManifest.Name, err.Error())
}
return nil
}
Expand Down
9 changes: 7 additions & 2 deletions internal/testrunner/runners/system/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,13 @@ func (r *runner) runTest(config *testConfig, ctxt servicedeployer.ServiceContext
}
r.deletePackageHandler = func() error {
err := installer.Uninstall()
if err != nil {
return fmt.Errorf("failed to uninstall package: %v", err)

// by default system package is part of an agent policy and it cannot be uninstalled
// https://github.com/elastic/elastic-package/blob/5f65dc29811c57454bc7142aaf73725b6d4dc8e6/internal/stack/_static/kibana.yml.tmpl#L62
if err != nil && pkgManifest.Name != "system" {
// logging the error as a warning and not returning it since there could be other reasons that could make fail this process
// for instance being defined a test agent policy where this package is used for debugging purposes
logger.Warnf("failed to uninstall package %q: %s", pkgManifest.Name, err.Error())
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/testrunner/testrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func Run(testType TestType, options TestOptions) ([]TestResult, error) {
return nil, errors.Wrap(err, "could not complete test run")
}
if tdErr != nil {
return results, errors.Wrap(err, "could not teardown test runner")
return results, errors.Wrap(tdErr, "could not teardown test runner")
}
return results, nil
}
Expand Down
1 change: 1 addition & 0 deletions scripts/links_table.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
links:
elastic-main: "https://www.elastic.co/guide"
getting-started-observability: "https://www.elastic.co/guide/en/welcome-to-elastic/current/getting-started-observability.html"
3 changes: 3 additions & 0 deletions test/packages/parallel/system/_dev/build/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies:
ecs:
reference: [email protected]
Loading

0 comments on commit 3b3dc09

Please sign in to comment.