Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unprivileged upgrade testing for Windows. #4642

Merged
15 changes: 10 additions & 5 deletions testing/integration/upgrade_fleet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,19 @@ func testUpgradeFleetManagedElasticAgent(
require.NoError(t, err)

if unprivileged {
if startParsedVersion.Less(*upgradetest.Version_8_13_0) {
t.Skipf("Starting version %s is less than 8.13 and doesn't support --unprivileged", startParsedVersion.String())
if startParsedVersion.Less(*upgradetest.Version_8_13_0_SNAPSHOT) {
t.Skipf("Starting version %s is less than 8.13-SNAPSHOT and doesn't support --unprivileged", startParsedVersion.String())
}
if endParsedVersion.Less(*upgradetest.Version_8_13_0) {
t.Skipf("Ending version %s is less than 8.13 and doesn't support --unprivileged", endParsedVersion.String())
if endParsedVersion.Less(*upgradetest.Version_8_13_0_SNAPSHOT) {
t.Skipf("Ending version %s is less than 8.13-SNAPSHOT and doesn't support --unprivileged", endParsedVersion.String())
}
if runtime.GOOS != define.Linux {
t.Skip("Unprivileged mode is currently only supported on Linux")
if startParsedVersion.Less(*upgradetest.Version_8_14_0_SNAPSHOT) {
t.Skipf("Starting version %s is less than 8.14-SNAPSHOT and doesn't support --unprivileged on Windows", startParsedVersion.String())
}
if endParsedVersion.Less(*upgradetest.Version_8_14_0_SNAPSHOT) {
t.Skipf("Ending version %s is less than 8.14-SNAPSHOT and doesn't support --unprivileged on Windows", endParsedVersion.String())
}
}
}

Expand Down
15 changes: 7 additions & 8 deletions testing/integration/upgrade_standalone_same_commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ func TestStandaloneUpgradeSameCommit(t *testing.T) {
t.Skipf("Minimum version for running this test is %q, current version: %q", *upgradetest.Version_8_13_0_SNAPSHOT, currentVersion)
}

unprivilegedAvailable := true
if runtime.GOOS != define.Linux {
// only available on Linux at the moment
unprivilegedAvailable = false
}
unprivilegedAvailable := false
// This is probably redundant: see the skip statement above
if unprivilegedAvailable && currentVersion.Less(*upgradetest.Version_8_13_0) {
// only available if both versions are 8.13+
unprivilegedAvailable = false
if runtime.GOOS == define.Linux && !currentVersion.Less(*upgradetest.Version_8_13_0_SNAPSHOT) {
// only available if version is 8.13+ on Linux
unprivilegedAvailable = true
} else if !currentVersion.Less(*upgradetest.Version_8_14_0_SNAPSHOT) {
// 8.14+ its always available
unprivilegedAvailable = true
}

unPrivilegedString := "unprivileged"
Expand Down
15 changes: 7 additions & 8 deletions testing/integration/upgrade_standalone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ func TestStandaloneUpgrade(t *testing.T) {
require.NoError(t, err)

for _, startVersion := range versionList {
unprivilegedAvailable := true
if runtime.GOOS != define.Linux {
// only available on Linux at the moment
unprivilegedAvailable = false
}
if unprivilegedAvailable && (startVersion.Less(*upgradetest.Version_8_13_0) || endVersion.Less(*upgradetest.Version_8_13_0)) {
// only available if both versions are 8.13+
unprivilegedAvailable = false
unprivilegedAvailable := false
if runtime.GOOS == define.Linux && !startVersion.Less(*upgradetest.Version_8_13_0_SNAPSHOT) && !endVersion.Less(*upgradetest.Version_8_13_0_SNAPSHOT) {
// unprivileged available if both versions are 8.13+ on Linux
unprivilegedAvailable = true
} else if !startVersion.Less(*upgradetest.Version_8_14_0_SNAPSHOT) && !endVersion.Less(*upgradetest.Version_8_14_0_SNAPSHOT) {
// always available if both versions are 8.14+
unprivilegedAvailable = true
}
t.Run(fmt.Sprintf("Upgrade %s to %s (privileged)", startVersion, define.Version()), func(t *testing.T) {
testStandaloneUpgrade(t, startVersion, define.Version(), false)
Expand Down
13 changes: 9 additions & 4 deletions testing/upgradetest/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,13 @@ func PerformUpgrade(
// in the unprivileged is unset we adjust it to use unprivileged when the version allows it
// in the case that its explicitly set then we ensure the version supports it
if upgradeOpts.unprivileged == nil {
if !startVersion.Less(*Version_8_13_0) && !endVersion.Less(*Version_8_13_0) && runtime.GOOS == define.Linux {
// both version support --unprivileged
if !startVersion.Less(*Version_8_13_0_SNAPSHOT) && !endVersion.Less(*Version_8_13_0_SNAPSHOT) && runtime.GOOS == define.Linux {
// both version support --unprivileged on Linux
unprivileged := true
upgradeOpts.unprivileged = &unprivileged
logger.Logf("installation of Elastic Agent will use --unprivileged as both start and end version support --unprivileged mode on Linux")
} else if !startVersion.Less(*Version_8_14_0_SNAPSHOT) && !endVersion.Less(*Version_8_14_0_SNAPSHOT) {
// both version support --unprivileged on all platforms
unprivileged := true
upgradeOpts.unprivileged = &unprivileged
logger.Logf("installation of Elastic Agent will use --unprivileged as both start and end version support --unprivileged mode")
Expand All @@ -220,10 +225,10 @@ func PerformUpgrade(
upgradeOpts.unprivileged = &unprivileged
}
} else if *upgradeOpts.unprivileged {
if startVersion.Less(*Version_8_13_0) {
if startVersion.Less(*Version_8_13_0_SNAPSHOT) {
return errors.New("cannot install starting version with --unprivileged (which is default) because the it is older than 8.13")
}
if endVersion.Less(*Version_8_13_0) {
if endVersion.Less(*Version_8_13_0_SNAPSHOT) {
return errors.New("cannot upgrade to ending version as end version doesn't support running with --unprivileged (which is default) because it is older than 8.13")
}
}
Expand Down
4 changes: 2 additions & 2 deletions testing/upgradetest/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ var (
Version_8_11_0_SNAPSHOT = version.NewParsedSemVer(8, 11, 0, "SNAPSHOT", "")
// Version_8_13_0_SNAPSHOT is the minimum version for testing upgrading agent with the same hash
Version_8_13_0_SNAPSHOT = version.NewParsedSemVer(8, 13, 0, "SNAPSHOT", "")
// Version_8_13_0 is the minimum version for proper unprivileged execution
Version_8_13_0 = version.NewParsedSemVer(8, 13, 0, "", "")
// Version_8_14_0_SNAPSHOT is the minimum version for proper unprivileged execution on all platforms
Version_8_14_0_SNAPSHOT = version.NewParsedSemVer(8, 14, 0, "SNAPSHOT", "")

// ErrNoSnapshot is returned when a requested snapshot is not on the version list.
ErrNoSnapshot = errors.New("failed to find a snapshot on the version list")
Expand Down
Loading