From a5de3206e87310dfc56954e97d78f75c838967ef Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 29 Oct 2024 17:46:09 -0700 Subject: [PATCH] Revert forcing Agent version to be 8.16.0 (#5617) * Revert forcing Agent version to be 8.16.0 * Update version in .package-version file * Return latest minor of previous version if current version is first release of a new major * Remove debugging statement --- .buildkite/scripts/steps/beats_tests.sh | 2 +- .../scripts/steps/integration-package.sh | 2 +- .buildkite/scripts/steps/integration_tests.sh | 2 +- .../scripts/steps/k8s-extended-tests.sh | 4 ++-- .../upgrade_broken_package_test.go | 2 -- testing/upgradetest/versions.go | 18 +++++++++++++-- testing/upgradetest/versions_test.go | 22 +++++++++++++++---- 7 files changed, 39 insertions(+), 13 deletions(-) diff --git a/.buildkite/scripts/steps/beats_tests.sh b/.buildkite/scripts/steps/beats_tests.sh index d2dde8d4031..05fb5b47e2a 100755 --- a/.buildkite/scripts/steps/beats_tests.sh +++ b/.buildkite/scripts/steps/beats_tests.sh @@ -28,7 +28,7 @@ run_test_for_beat(){ export WORKSPACE=$(pwd) set +e - AGENT_STACK_VERSION="8.16.0-SNAPSHOT" TEST_INTEG_CLEAN_ON_EXIT=true TEST_PLATFORMS="linux/amd64" STACK_PROVISIONER="$STACK_PROVISIONER" SNAPSHOT=true mage integration:testBeatServerless $beat_name + TEST_INTEG_CLEAN_ON_EXIT=true TEST_PLATFORMS="linux/amd64" STACK_PROVISIONER="$STACK_PROVISIONER" SNAPSHOT=true mage integration:testBeatServerless $beat_name TESTS_EXIT_STATUS=$? set -e diff --git a/.buildkite/scripts/steps/integration-package.sh b/.buildkite/scripts/steps/integration-package.sh index 92afbd8aa55..623a67573bc 100644 --- a/.buildkite/scripts/steps/integration-package.sh +++ b/.buildkite/scripts/steps/integration-package.sh @@ -3,4 +3,4 @@ set -euo pipefail source .buildkite/scripts/common.sh -AGENT_PACKAGE_VERSION=8.16.0 PACKAGES=tar.gz,zip,rpm,deb PLATFORMS=linux/amd64,linux/arm64,windows/amd64 SNAPSHOT=true EXTERNAL=true mage package +PACKAGES=tar.gz,zip,rpm,deb PLATFORMS=linux/amd64,linux/arm64,windows/amd64 SNAPSHOT=true EXTERNAL=true mage package diff --git a/.buildkite/scripts/steps/integration_tests.sh b/.buildkite/scripts/steps/integration_tests.sh index d909f8ad555..834da1cd4c6 100755 --- a/.buildkite/scripts/steps/integration_tests.sh +++ b/.buildkite/scripts/steps/integration_tests.sh @@ -19,7 +19,7 @@ fi # Run integration tests set +e -AGENT_VERSION="8.16.0-SNAPSHOT" AGENT_STACK_VERSION="${STACK_VERSION}" TEST_INTEG_CLEAN_ON_EXIT=true STACK_PROVISIONER="$STACK_PROVISIONER" SNAPSHOT=true mage $MAGE_TARGET $MAGE_SUBTARGET +AGENT_STACK_VERSION="${STACK_VERSION}" TEST_INTEG_CLEAN_ON_EXIT=true STACK_PROVISIONER="$STACK_PROVISIONER" SNAPSHOT=true mage $MAGE_TARGET $MAGE_SUBTARGET TESTS_EXIT_STATUS=$? set -e diff --git a/.buildkite/scripts/steps/k8s-extended-tests.sh b/.buildkite/scripts/steps/k8s-extended-tests.sh index b3ac8d69f2e..8eba5ea667f 100644 --- a/.buildkite/scripts/steps/k8s-extended-tests.sh +++ b/.buildkite/scripts/steps/k8s-extended-tests.sh @@ -25,8 +25,8 @@ else exit 10 fi -AGENT_PACKAGE_VERSION="8.16.0" SNAPSHOT=true EXTERNAL=true PACKAGES=docker mage -v package -AGENT_VERSION="8.16.0-SNAPSHOT" TEST_INTEG_CLEAN_ON_EXIT=true INSTANCE_PROVISIONER=kind STACK_PROVISIONER=stateful SNAPSHOT=true mage integration:kubernetesMatrix +SNAPSHOT=true EXTERNAL=true PACKAGES=docker mage -v package +TEST_INTEG_CLEAN_ON_EXIT=true INSTANCE_PROVISIONER=kind STACK_PROVISIONER=stateful SNAPSHOT=true mage integration:kubernetesMatrix TESTS_EXIT_STATUS=$? set -e diff --git a/testing/integration/upgrade_broken_package_test.go b/testing/integration/upgrade_broken_package_test.go index c1413c2575b..5ece19ddbd8 100644 --- a/testing/integration/upgrade_broken_package_test.go +++ b/testing/integration/upgrade_broken_package_test.go @@ -32,8 +32,6 @@ func TestUpgradeBrokenPackageVersion(t *testing.T) { Sudo: true, // requires Agent installation }) - t.Skip("This test cannot succeed with a AGENT_PACKAGE_VERSION override. Check contents of .buildkite/scripts/steps/beats_tests.sh") - ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute)) defer cancel() diff --git a/testing/upgradetest/versions.go b/testing/upgradetest/versions.go index b2da0962c0b..c82af1c259b 100644 --- a/testing/upgradetest/versions.go +++ b/testing/upgradetest/versions.go @@ -129,7 +129,8 @@ func getAgentVersions() (*AgentVersions, error) { return &versionFile, nil } -// FetchUpgradableVersions returns the versions list from the agent version file. +// GetUpgradableVersions returns the versions list from the agent version file. The list +// is sorted in descending order (newer versions first). func GetUpgradableVersions() ([]*version.ParsedSemVer, error) { parsedVersions := make([]*version.ParsedSemVer, 0, len(agentVersions.TestVersions)) for _, v := range agentVersions.TestVersions { @@ -143,7 +144,8 @@ func GetUpgradableVersions() ([]*version.ParsedSemVer, error) { return parsedVersions, nil } -// FetchUpgradableVersions returns a list of versions that meet the specified requirements. +// FetchUpgradableVersions returns a list of versions that meet the specified requirements, sorted +// in descending order (newer versions first). // // Every version on the resulting list will meet the given requirements (by OR condition). // However, it's not guaranteed that the list contains the amount of versions per requirement. @@ -240,6 +242,18 @@ func PreviousMinor() (*version.ParsedSemVer, error) { if err != nil { return nil, fmt.Errorf("failed to parse the current version %s: %w", define.Version(), err) } + + // Special case: if we are in the first release of a new major (so vX.0.0), we should + // return the latest release from the previous major. + if current.Minor() == 0 && current.Patch() == 0 { + // Since the current version is the first release of a new major (vX.0.0), there + // will be no minor versions in the versions list from the same major (vX). The list + // will only contain minors from the previous major (vX-1). Further, since the + // version list is sorted in descending order (newer versions first), we can return the + // first item from the list as it will be the newest minor of the previous major. + return versions[0], nil + } + for _, v := range versions { if v.Prerelease() != "" || v.BuildMetadata() != "" { continue diff --git a/testing/upgradetest/versions_test.go b/testing/upgradetest/versions_test.go index 96df75238ad..34aa276e54d 100644 --- a/testing/upgradetest/versions_test.go +++ b/testing/upgradetest/versions_test.go @@ -91,13 +91,27 @@ func TestPreviousMinor(t *testing.T) { currentParsed, err := version.ParseVersion(bversion.Agent) require.NoError(t, err) - if currentParsed.Minor() == 0 { - t.Skipf("skipping TestPreviousMinor as current major version (%v) don't have previous minor", bversion.Agent) - } - v, err := PreviousMinor() require.NoError(t, err) t.Logf("previous minor: %s", v.String()) + + // Special case: the current Agent version is the first release of a new + // major (vX.0.0). In this case we expect the previous minor to be the + // latest minor of the previous major. + if currentParsed.Minor() == 0 && currentParsed.Patch() == 0 { + require.Equal(t, currentParsed.Major()-1, v.Major()) + + // The list of versions returned by GetUpgradableVersions will not contain any + // versions with the same major as the current version as the current version is + // the first release of the major. Further, since this list is sorted in + // descending order (newer versions first), we should expect the first item in the + // list to be the latest minor of the previous major. + versions, err := GetUpgradableVersions() + require.NoError(t, err) + require.Equal(t, versions[0], v) + return + } + assert.Truef(t, currentParsed.Major() == v.Major() && currentParsed.Minor() > v.Minor(), "%s is not previous minor for %s", v, bversion.Agent) assert.Empty(t, v.Prerelease()) assert.Empty(t, v.BuildMetadata())