-
Notifications
You must be signed in to change notification settings - Fork 42
chore: refactor Fleet upgrade tests #671
Changes from all commits
f2e5de8
616ca2c
5d13bff
5403a8d
b7cdb50
ceb1325
d408bf6
5ee04e5
1827ee2
2566126
2af8884
81953d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ var agentVersion = agentVersionBase | |
|
||
// agentStaleVersion is the version of the agent to use as a base during upgrade | ||
// It can be overriden by ELASTIC_AGENT_STALE_VERSION env var. Using latest GA as a default. | ||
var agentStaleVersion = "7.10.0" | ||
var agentStaleVersion = "7.10.2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pairing version with Jenkinsfile |
||
|
||
// stackVersion is the version of the stack to use | ||
// It can be overriden by STACK_VERSION env var | ||
|
@@ -83,6 +83,11 @@ func setUpSuite() { | |
agentVersion = shell.GetEnv("ELASTIC_AGENT_VERSION", agentVersionBase) | ||
agentStaleVersion = shell.GetEnv("ELASTIC_AGENT_STALE_VERSION", agentStaleVersion) | ||
|
||
useCISnapshots := shell.GetEnvBool("BEATS_USE_CI_SNAPSHOTS") | ||
if useCISnapshots && !strings.HasSuffix(agentStaleVersion, "-SNAPSHOT") { | ||
agentStaleVersion += "-SNAPSHOT" | ||
} | ||
|
||
// check if version is an alias | ||
agentVersion = e2e.GetElasticArtifactVersion(agentVersion) | ||
|
||
|
@@ -91,10 +96,10 @@ func setUpSuite() { | |
imts = IngestManagerTestSuite{ | ||
Fleet: &FleetTestSuite{ | ||
Installers: map[string]ElasticAgentInstaller{ | ||
"centos-systemd": GetElasticAgentInstaller("centos", "systemd"), | ||
"centos-tar": GetElasticAgentInstaller("centos", "tar"), | ||
"debian-systemd": GetElasticAgentInstaller("debian", "systemd"), | ||
"debian-tar": GetElasticAgentInstaller("debian", "tar"), | ||
"centos-systemd-" + agentVersion: GetElasticAgentInstaller("centos", "systemd", agentVersion, false), | ||
"centos-tar-" + agentVersion: GetElasticAgentInstaller("centos", "tar", agentVersion, false), | ||
"debian-systemd-" + agentVersion: GetElasticAgentInstaller("debian", "systemd", agentVersion, false), | ||
"debian-tar-" + agentVersion: GetElasticAgentInstaller("debian", "tar", agentVersion, false), | ||
}, | ||
}, | ||
StandAlone: &StandAloneTestSuite{}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,6 +157,7 @@ type TARPackage struct { | |
arch string | ||
artifact string | ||
OS string | ||
stale bool | ||
version string | ||
} | ||
|
||
|
@@ -214,25 +215,40 @@ func (i *TARPackage) Preinstall() error { | |
return err | ||
} | ||
|
||
version := checkElasticAgentVersion(i.version) | ||
version := i.version | ||
if !i.stale { | ||
version = checkElasticAgentVersion(i.version) | ||
} | ||
|
||
// simplify layout | ||
cmds := []string{"mv", fmt.Sprintf("/%s-%s-%s-%s", i.artifact, version, i.OS, i.arch), "/elastic-agent"} | ||
err = execCommandInService(i.profile, i.image, i.service, cmds, false) | ||
if err != nil { | ||
log.WithFields(log.Fields{ | ||
"command": cmds, | ||
"error": err, | ||
"image": i.image, | ||
"service": i.service, | ||
}).Error("Could not extract agent package in the box") | ||
|
||
return err | ||
cmds := [][]string{ | ||
[]string{"rm", "-fr", "/elastic-agent"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When running all Fleet tests in my local machine, I saw multiple errors when moving the agent, because It does not happen on CI but in my local machine happens after multiple runs. I'm adding it defensively, as it's harmless. |
||
[]string{"mv", fmt.Sprintf("/%s-%s-%s-%s", i.artifact, version, i.OS, i.arch), "/elastic-agent"}, | ||
} | ||
for _, cmd := range cmds { | ||
err = execCommandInService(i.profile, i.image, i.service, cmd, false) | ||
if err != nil { | ||
log.WithFields(log.Fields{ | ||
"command": cmd, | ||
"error": err, | ||
"image": i.image, | ||
"service": i.service, | ||
"version": version, | ||
}).Error("Could not extract agent package in the box") | ||
|
||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Stale sets the stale state | ||
func (i *TARPackage) Stale(stale bool) *TARPackage { | ||
i.stale = stale | ||
return i | ||
} | ||
|
||
// Uninstall uninstalls a TAR package | ||
func (i *TARPackage) Uninstall() error { | ||
args := []string{"-f"} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,7 +163,7 @@ func runElasticAgentCommand(profile string, image string, service string, proces | |
// be defined by that value | ||
// Else, if the environment variable BEATS_USE_CI_SNAPSHOTS is set, then the artifact | ||
// to be downloaded will be defined by the latest snapshot produced by the Beats CI. | ||
func downloadAgentBinary(artifact string, version string, OS string, arch string, extension string) (string, string, error) { | ||
func downloadAgentBinary(artifact string, version string, OS string, arch string, extension string, stale bool) (string, string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As an improvement in a follow-up PR, I'm interested in creating a BinaryRequest struct to hold the references needed to download the binary, which would simplify the signature of the method. |
||
fileName := fmt.Sprintf("%s-%s-%s.%s", artifact, version, arch, extension) | ||
|
||
handleDownload := func(URL string, fileName string) (string, string, error) { | ||
|
@@ -196,7 +196,7 @@ func downloadAgentBinary(artifact string, version string, OS string, arch string | |
if useCISnapshots { | ||
log.Debug("Using CI snapshots for the Elastic Agent") | ||
|
||
bucketFileName, bucket, prefix, object := getGCPBucketCoordinates(fileName, artifact, version, OS, arch, extension) | ||
bucketFileName, bucket, prefix, object := getGCPBucketCoordinates(fileName, artifact, version, OS, arch, extension, stale) | ||
|
||
maxTimeout := time.Duration(timeoutFactor) * time.Minute | ||
|
||
|
@@ -208,7 +208,12 @@ func downloadAgentBinary(artifact string, version string, OS string, arch string | |
return handleDownload(downloadURL, bucketFileName) | ||
} | ||
|
||
downloadURL, err = e2e.GetElasticArtifactURL(artifact, checkElasticAgentVersion(version), OS, arch, extension) | ||
downloadVersion := version | ||
if !stale { | ||
downloadVersion = checkElasticAgentVersion(version) | ||
} | ||
|
||
downloadURL, err = e2e.GetElasticArtifactURL(artifact, downloadVersion, OS, arch, extension) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
|
@@ -217,7 +222,7 @@ func downloadAgentBinary(artifact string, version string, OS string, arch string | |
} | ||
|
||
// GetElasticAgentInstaller returns an installer from a docker image | ||
func GetElasticAgentInstaller(image string, installerType string) ElasticAgentInstaller { | ||
func GetElasticAgentInstaller(image string, installerType string, version string, stale bool) ElasticAgentInstaller { | ||
log.WithFields(log.Fields{ | ||
"image": image, | ||
"installer": installerType, | ||
|
@@ -226,13 +231,13 @@ func GetElasticAgentInstaller(image string, installerType string) ElasticAgentIn | |
var installer ElasticAgentInstaller | ||
var err error | ||
if "centos" == image && "tar" == installerType { | ||
installer, err = newTarInstaller("centos", "latest") | ||
installer, err = newTarInstaller("centos", "latest", version, stale) | ||
} else if "centos" == image && "systemd" == installerType { | ||
installer, err = newCentosInstaller("centos", "latest") | ||
installer, err = newCentosInstaller("centos", "latest", version, stale) | ||
} else if "debian" == image && "tar" == installerType { | ||
installer, err = newTarInstaller("debian", "stretch") | ||
installer, err = newTarInstaller("debian", "stretch", version, stale) | ||
} else if "debian" == image && "systemd" == installerType { | ||
installer, err = newDebianInstaller("debian", "stretch") | ||
installer, err = newDebianInstaller("debian", "stretch", version, stale) | ||
} else { | ||
log.WithFields(log.Fields{ | ||
"image": image, | ||
|
@@ -252,7 +257,7 @@ func GetElasticAgentInstaller(image string, installerType string) ElasticAgentIn | |
} | ||
|
||
// getGCPBucketCoordinates it calculates the bucket path in GCP | ||
func getGCPBucketCoordinates(fileName string, artifact string, version string, OS string, arch string, extension string) (string, string, string, string) { | ||
func getGCPBucketCoordinates(fileName string, artifact string, version string, OS string, arch string, extension string, stale bool) (string, string, string, string) { | ||
if extension == "tar.gz" { | ||
fileName = fmt.Sprintf("%s-%s-%s-%s.%s", artifact, version, OS, arch, extension) | ||
} | ||
|
@@ -286,27 +291,31 @@ func getGCPBucketCoordinates(fileName string, artifact string, version string, O | |
object = fmt.Sprintf("%s/%s", artifact, newFileName) | ||
} | ||
|
||
if stale { | ||
prefix = fmt.Sprintf("snapshots/%s", artifact) | ||
object = newFileName | ||
} | ||
|
||
return newFileName, bucket, prefix, object | ||
} | ||
|
||
func isSystemdBased(image string) bool { | ||
return strings.HasSuffix(image, "-systemd") | ||
} | ||
|
||
// newCentosInstaller returns an instance of the Centos installer | ||
func newCentosInstaller(image string, tag string) (ElasticAgentInstaller, error) { | ||
// newCentosInstaller returns an instance of the Centos installer for a specific version | ||
func newCentosInstaller(image string, tag string, version string, stale bool) (ElasticAgentInstaller, error) { | ||
image = image + "-systemd" // we want to consume systemd boxes | ||
service := image | ||
profile := FleetProfileName | ||
|
||
// extract the agent in the box, as it's mounted as a volume | ||
artifact := "elastic-agent" | ||
version := agentVersion | ||
os := "linux" | ||
arch := "x86_64" | ||
extension := "rpm" | ||
|
||
binaryName, binaryPath, err := downloadAgentBinary(artifact, version, os, arch, extension) | ||
binaryName, binaryPath, err := downloadAgentBinary(artifact, version, os, arch, extension, stale) | ||
if err != nil { | ||
log.WithFields(log.Fields{ | ||
"artifact": artifact, | ||
|
@@ -358,20 +367,19 @@ func newCentosInstaller(image string, tag string) (ElasticAgentInstaller, error) | |
}, nil | ||
} | ||
|
||
// newDebianInstaller returns an instance of the Debian installer | ||
func newDebianInstaller(image string, tag string) (ElasticAgentInstaller, error) { | ||
// newDebianInstaller returns an instance of the Debian installer for a specific version | ||
func newDebianInstaller(image string, tag string, version string, stale bool) (ElasticAgentInstaller, error) { | ||
image = image + "-systemd" // we want to consume systemd boxes | ||
service := image | ||
profile := FleetProfileName | ||
|
||
// extract the agent in the box, as it's mounted as a volume | ||
artifact := "elastic-agent" | ||
version := agentVersion | ||
os := "linux" | ||
arch := "amd64" | ||
extension := "deb" | ||
|
||
binaryName, binaryPath, err := downloadAgentBinary(artifact, version, os, arch, extension) | ||
binaryName, binaryPath, err := downloadAgentBinary(artifact, version, os, arch, extension, stale) | ||
if err != nil { | ||
log.WithFields(log.Fields{ | ||
"artifact": artifact, | ||
|
@@ -423,20 +431,19 @@ func newDebianInstaller(image string, tag string) (ElasticAgentInstaller, error) | |
}, nil | ||
} | ||
|
||
// newTarInstaller returns an instance of the Debian installer | ||
func newTarInstaller(image string, tag string) (ElasticAgentInstaller, error) { | ||
// newTarInstaller returns an instance of the Debian installer for a specific version | ||
func newTarInstaller(image string, tag string, version string, stale bool) (ElasticAgentInstaller, error) { | ||
image = image + "-systemd" // we want to consume systemd boxes | ||
service := image | ||
profile := FleetProfileName | ||
|
||
// extract the agent in the box, as it's mounted as a volume | ||
artifact := "elastic-agent" | ||
version := agentVersion | ||
os := "linux" | ||
arch := "x86_64" | ||
extension := "tar.gz" | ||
|
||
tarFile, binaryPath, err := downloadAgentBinary(artifact, version, os, arch, extension) | ||
tarFile, binaryPath, err := downloadAgentBinary(artifact, version, os, arch, extension, stale) | ||
if err != nil { | ||
log.WithFields(log.Fields{ | ||
"artifact": artifact, | ||
|
@@ -461,6 +468,7 @@ func newTarInstaller(image string, tag string) (ElasticAgentInstaller, error) { | |
|
||
// | ||
installerPackage := NewTARPackage(tarFile, profile, image, service). | ||
Stale(stale). | ||
WithArch(arch). | ||
WithArtifact(artifact). | ||
WithOS(os). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i like that