-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…#3495) * 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 * Fix merge. --------- Co-authored-by: Blake Rouse <blake.rouse@elastic.co>
- Loading branch information
1 parent
7ae7e8f
commit 045c84e
Showing
24 changed files
with
1,756 additions
and
1,115 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
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,45 @@ | ||
// 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. | ||
|
||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/elastic/elastic-agent-system-metrics/metric/system/process" | ||
) | ||
|
||
// GetWatcherPIDs returns the PID's of any running `elastic-agent watch` process. | ||
func GetWatcherPIDs() ([]int, error) { | ||
procStats := process.Stats{ | ||
// filtering with '.*elastic-agent' or '^.*elastic-agent$' doesn't | ||
// seem to work as expected, filtering is done in the for loop below | ||
Procs: []string{".*"}, | ||
} | ||
err := procStats.Init() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to initialize process.Stats: %w", err) | ||
} | ||
pidMap, _, err := procStats.FetchPids() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to fetch pids: %w", err) | ||
} | ||
var pids []int | ||
for pid, state := range pidMap { | ||
if len(state.Args) < 2 { | ||
// must have at least 2 args "elastic-agent[.exe] watch" | ||
continue | ||
} | ||
// instead of matching on Windows using the specific '.exe' suffix, this ensures | ||
// that even if the watcher is spawned without the '.exe' suffix (which Windows will allow and supports) | ||
// it always results in the watch process being killed | ||
if strings.TrimSuffix(filepath.Base(state.Args[0]), ".exe") == "elastic-agent" && state.Args[1] == "watch" { | ||
// it is a watch subprocess | ||
pids = append(pids, pid) | ||
} | ||
} | ||
return pids, nil | ||
} |
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.