-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and fix all upgrade integration tests (#3477)
* Fix all upgrade tests. * Fix imports and headers. * Update notice. * Exclude testing/** from sonar. * Fix comments from code review. * Add extra error information in the artifact fetcher. * Fixes from code review. * Add upgrade uninstall kill watcher test. * Remove go replace. Regenerate notice. Fix lint. * Import WithSourceURI logic. Fix fleet test to not skip if the versions are different and the commits are the same. * More test fixes. * Fix imports. * Re-add TestStandaloneUpgradeFailsWhenUpgradeIsInProgress. Fix code review. (cherry picked from commit 6201e19) # Conflicts: # sonar-project.properties # testing/integration/upgrade_test.go
- Loading branch information
1 parent
d1a0420
commit f2f0417
Showing
19 changed files
with
1,709 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
//go:build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
atesting "github.com/elastic/elastic-agent/pkg/testing" | ||
"github.com/elastic/elastic-agent/pkg/testing/define" | ||
"github.com/elastic/elastic-agent/testing/upgradetest" | ||
agtversion "github.com/elastic/elastic-agent/version" | ||
) | ||
|
||
func TestUpgradeBrokenPackageVersion(t *testing.T) { | ||
define.Require(t, define.Requirements{ | ||
Local: false, // requires Agent installation | ||
Sudo: true, // requires Agent installation | ||
}) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
// Start at the build version as we want to test the retry | ||
// logic that is in the build. | ||
startFixture, err := define.NewFixture(t, define.Version()) | ||
require.NoError(t, err) | ||
|
||
// Upgrade to an old build. | ||
upgradeToVersion, err := upgradetest.PreviousMinor(ctx, define.Version()) | ||
require.NoError(t, err) | ||
endFixture, err := atesting.NewFixture( | ||
t, | ||
upgradeToVersion, | ||
atesting.WithFetcher(atesting.ArtifactFetcher()), | ||
) | ||
require.NoError(t, err) | ||
|
||
// Pre-upgrade remove the package version files. | ||
preUpgradeHook := func() error { | ||
// get rid of the package version files in the installed directory | ||
return removePackageVersionFiles(t, startFixture) | ||
} | ||
|
||
t.Logf("Testing Elastic Agent upgrade from %s to %s...", define.Version(), upgradeToVersion) | ||
|
||
err = upgradetest.PerformUpgrade(ctx, startFixture, endFixture, t, upgradetest.WithPreUpgradeHook(preUpgradeHook)) | ||
assert.NoError(t, err) | ||
} | ||
|
||
func removePackageVersionFiles(t *testing.T, f *atesting.Fixture) error { | ||
installFS := os.DirFS(f.WorkDir()) | ||
matches := []string{} | ||
|
||
err := fs.WalkDir(installFS, ".", func(path string, d fs.DirEntry, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if d.Name() == agtversion.PackageVersionFileName { | ||
matches = append(matches, path) | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
t.Logf("package version files found: %v", matches) | ||
|
||
// the version files should have been removed from the other test, we just make sure | ||
for _, m := range matches { | ||
vFile := filepath.Join(f.WorkDir(), m) | ||
t.Logf("removing package version file %q", vFile) | ||
err = os.Remove(vFile) | ||
if err != nil { | ||
return fmt.Errorf("error removing package version file %q: %w", vFile, err) | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.