Skip to content

Commit

Permalink
[8.9](backport #2955) Introduce upgrade tests from released versions (#…
Browse files Browse the repository at this point in the history
…3173)

This is an automatic backport of pull request #2955 done by
[Mergify](https://mergify.com).
---------

Co-authored-by: Paolo Chilà <paolo.chila@elastic.co>
  • Loading branch information
mergify[bot] and pchila authored Aug 4, 2023
1 parent 8f49f9f commit 2cc98b8
Show file tree
Hide file tree
Showing 4 changed files with 333 additions and 94 deletions.
13 changes: 12 additions & 1 deletion pkg/testing/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ type Fixture struct {
allowErrs bool
connectTimout time.Duration

workDir string
srcPackage string
workDir string

installed bool
installOpts *InstallOpts
Expand Down Expand Up @@ -153,6 +154,7 @@ func (f *Fixture) Prepare(ctx context.Context, components ...UsableComponent) er
if err != nil {
return err
}
f.srcPackage = src
filename := filepath.Base(src)
name, _, err := splitFileType(filename)
if err != nil {
Expand Down Expand Up @@ -191,6 +193,15 @@ func (f *Fixture) WorkDir() string {
return f.workDir
}

// SrcPackage returns the location on disk of the elastic agent package used by this fixture.
func (f *Fixture) SrcPackage(ctx context.Context) (string, error) {
err := f.ensurePrepared(ctx)
if err != nil {
return "", err
}
return f.srcPackage, nil
}

func ExtractArtifact(l Logger, artifactFile, outputDir string) error {
filename := filepath.Base(artifactFile)
_, ext, err := splitFileType(filename)
Expand Down
10 changes: 1 addition & 9 deletions pkg/testing/tools/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ import (
)

// InstallAgent force install the Elastic Agent through agentFixture.
func InstallAgent(fleetUrl string, enrollmentToken string, agentFixture *atesting.Fixture) ([]byte, error) {
installOpts := atesting.InstallOpts{
NonInteractive: true,
Force: true,
EnrollOpts: atesting.EnrollOpts{
URL: fleetUrl,
EnrollmentToken: enrollmentToken,
},
}
func InstallAgent(installOpts atesting.InstallOpts, agentFixture *atesting.Fixture) ([]byte, error) {
return agentFixture.Install(context.Background(), &installOpts)
}

Expand Down
13 changes: 12 additions & 1 deletion pkg/testing/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/elastic/elastic-agent-libs/kibana"

atesting "github.com/elastic/elastic-agent/pkg/testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -79,7 +80,17 @@ func InstallAgentWithPolicy(t *testing.T, agentFixture *atesting.Fixture, kibCli

// Enroll agent
t.Logf("Unpacking and installing Elastic Agent")
output, err := InstallAgent(fleetServerURL, enrollmentToken.APIKey, agentFixture)
// this is a partial backport of https://github.com/elastic/elastic-agent/pull/3114
// normally the installOpts are passed as parameter, and we just add URL and Enrollment Token
installOpts := atesting.InstallOpts{
NonInteractive: true,
Force: true,
}
installOpts.EnrollOpts = atesting.EnrollOpts{
URL: fleetServerURL,
EnrollmentToken: enrollmentToken.APIKey,
}
output, err := InstallAgent(installOpts, agentFixture)
if err != nil {
t.Log(string(output))
return nil, fmt.Errorf("unable to enroll Elastic Agent: %w", err)
Expand Down
Loading

0 comments on commit 2cc98b8

Please sign in to comment.