Skip to content

Commit

Permalink
integration test runner should upload sha512 on remote
Browse files Browse the repository at this point in the history
  • Loading branch information
pchila committed Jul 13, 2023
1 parent 6e048ce commit 7dfff4e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
30 changes: 16 additions & 14 deletions pkg/testing/runner/debian.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
type DebianRunner struct{}

// Prepare the test
func (DebianRunner) Prepare(ctx context.Context, sshClient *ssh.Client, logger Logger, arch string, goVersion string, repoArchive string, buildPath string) error {
func (DebianRunner) Prepare(ctx context.Context, sshClient *ssh.Client, logger Logger, arch string, goVersion string, repoArchive string, buildPaths []string) error {
// prepare build-essential and unzip
//
// apt-get update and install are so terrible that we have to place this in a loop, because in some cases the
Expand Down Expand Up @@ -106,19 +106,21 @@ func (DebianRunner) Prepare(ctx context.Context, sshClient *ssh.Client, logger L
}

// place the build for the agent on the host
logger.Logf("Copying agent build %s", filepath.Base(buildPath))
err = sshSCP(sshClient, buildPath, filepath.Base(buildPath))
if err != nil {
return fmt.Errorf("failed to SCP build %s: %w", filepath.Base(buildPath), err)
}
insideAgentDir := filepath.Join("agent", buildPath)
stdOut, errOut, err = sshRunCommand(ctx, sshClient, "mkdir", []string{"-p", filepath.Dir(insideAgentDir)}, nil)
if err != nil {
return fmt.Errorf("failed to create %s directory: %w (stdout: %s, stderr: %s)", filepath.Dir(insideAgentDir), err, stdOut, errOut)
}
stdOut, errOut, err = sshRunCommand(ctx, sshClient, "mv", []string{filepath.Base(buildPath), insideAgentDir}, nil)
if err != nil {
return fmt.Errorf("failed to move %s to %s: %w (stdout: %s, stderr: %s)", filepath.Base(buildPath), insideAgentDir, err, stdOut, errOut)
for _, buildPath := range buildPaths {
logger.Logf("Copying agent build %s", filepath.Base(buildPath))
err = sshSCP(sshClient, buildPath, filepath.Base(buildPath))
if err != nil {
return fmt.Errorf("failed to SCP build %s: %w", filepath.Base(buildPath), err)
}
insideAgentDir := filepath.Join("agent", buildPath)
stdOut, errOut, err = sshRunCommand(ctx, sshClient, "mkdir", []string{"-p", filepath.Dir(insideAgentDir)}, nil)
if err != nil {
return fmt.Errorf("failed to create %s directory: %w (stdout: %s, stderr: %s)", filepath.Dir(insideAgentDir), err, stdOut, errOut)
}
stdOut, errOut, err = sshRunCommand(ctx, sshClient, "mv", []string{filepath.Base(buildPath), insideAgentDir}, nil)
if err != nil {
return fmt.Errorf("failed to move %s to %s: %w (stdout: %s, stderr: %s)", filepath.Base(buildPath), insideAgentDir, err, stdOut, errOut)
}
}

return nil
Expand Down
17 changes: 11 additions & 6 deletions pkg/testing/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type OSRunnerResult struct {
// OSRunner provides an interface to run the tests on the OS.
type OSRunner interface {
// Prepare prepares the runner to actual run on the host.
Prepare(ctx context.Context, c *ssh.Client, logger Logger, arch string, goVersion string, repoArchive string, buildPath string) error
Prepare(ctx context.Context, c *ssh.Client, logger Logger, arch string, goVersion string, repoArchive string, buildPaths []string) error
// Run runs the actual tests and provides the result.
Run(ctx context.Context, verbose bool, c *ssh.Client, logger Logger, agentVersion string, prefix string, batch define.Batch, env map[string]string) (OSRunnerResult, error)
}
Expand Down Expand Up @@ -303,9 +303,11 @@ func (r *Runner) validate() error {
var requiredFiles []string
for _, b := range r.batches {
if !b.Skip {
buildPath := r.getBuildPath(b)
if !slices.Contains(requiredFiles, buildPath) {
requiredFiles = append(requiredFiles, buildPath)
buildPaths := r.getBuildPath(b)
for _, buildPath := range buildPaths {
if !slices.Contains(requiredFiles, buildPath) {
requiredFiles = append(requiredFiles, buildPath)
}
}
}
}
Expand All @@ -325,7 +327,7 @@ func (r *Runner) validate() error {
}

// getBuildPath returns the path of the build required for the test.
func (r *Runner) getBuildPath(b LayoutBatch) string {
func (r *Runner) getBuildPath(b LayoutBatch) []string {
arch := b.LayoutOS.OS.Arch
if arch == define.AMD64 {
arch = "x86_64"
Expand All @@ -334,7 +336,10 @@ func (r *Runner) getBuildPath(b LayoutBatch) string {
if b.LayoutOS.OS.Type == define.Windows {
ext = "zip"
}
return filepath.Join(r.cfg.BuildDir, fmt.Sprintf("elastic-agent-%s-%s-%s.%s", r.cfg.AgentVersion, b.LayoutOS.OS.Type, arch, ext))
hashExt := ".sha512"
packageName := filepath.Join(r.cfg.BuildDir, fmt.Sprintf("elastic-agent-%s-%s-%s.%s", r.cfg.AgentVersion, b.LayoutOS.OS.Type, arch, ext))
packageHashName := packageName + hashExt
return []string{packageName, packageHashName}
}

// prepare prepares for the runner to run.
Expand Down

0 comments on commit 7dfff4e

Please sign in to comment.