Skip to content

Commit

Permalink
pkg/machine/e2e: Remove unnecessary copy of machine image.
Browse files Browse the repository at this point in the history
Stop copying the pre-pulled uncompressed machine disk into the individual test dir. The machine pull code already makes a copy of the disk into the test's HOMEDIR/.local/share/containers/podman/machine, and works off that copy.

Before the change: TESTDIR/<image> is copied to TESTDIR/podman_test/<image> by the test, and then podman machine copies the image to TESTDIR/podman_test/.local/share/containers/podman/machine/provider/<image>

After the change: TESTDIR/<image> is copied to TESTDIR/podman_test/.local/share/containers/podman/machine/provider/<image> by podman machine

The image that is actually run is at TESTDIR/podman_test/.local/share/containers/podman/machine/provider/<image> in both instances.

Signed-off-by: Ashley Cui <[email protected]>
  • Loading branch information
ashley-cui committed Jun 21, 2024
1 parent 9ffac33 commit 4dc98e3
Showing 1 changed file with 1 addition and 34 deletions.
35 changes: 1 addition & 34 deletions pkg/machine/e2e/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package e2e_test
import (
"errors"
"fmt"
"io"
"os"
"path/filepath"
"runtime"
"strings"
"testing"

"github.com/containers/common/pkg/config"
"github.com/containers/podman/v5/pkg/machine/compression"
"github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/provider"
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
Expand Down Expand Up @@ -126,26 +124,7 @@ func setup() (string, *machineTestBuilder) {
Fail(fmt.Sprintf("failed to close src reader %q: %q", src.Name(), err))
}
}()
mb.imagePath = filepath.Join(homeDir, suiteImageName)
dest, err := os.Create(mb.imagePath)
if err != nil {
Fail(fmt.Sprintf("failed to create file %s: %q", mb.imagePath, err))
}
defer func() {
if err := dest.Close(); err != nil {
Fail(fmt.Sprintf("failed to close destination file %q: %q\n", dest.Name(), err))
}
}()
fmt.Printf("--> copying %q to %q\n", src.Name(), dest.Name())
if runtime.GOOS != "darwin" {
if _, err := io.Copy(dest, src); err != nil {
Fail(fmt.Sprintf("failed to copy %ss to %s: %q", fqImageName, mb.imagePath, err))
}
} else {
if err := copySparse(dest, src); err != nil {
Fail(fmt.Sprintf("failed to copy %q to %q: %q", src.Name(), dest.Name(), err))
}
}
mb.imagePath = fqImageName
return homeDir, mb
}

Expand All @@ -171,18 +150,6 @@ func teardown(origHomeDir string, testDir string, mb *machineTestBuilder) {
}
}

// copySparse is a helper method for tests only; caller is responsible for closures
func copySparse(dst io.WriteSeeker, src io.Reader) (retErr error) {
spWriter := compression.NewSparseWriter(dst)
defer func() {
if err := spWriter.Close(); err != nil && retErr == nil {
retErr = err
}
}()
_, err := io.Copy(spWriter, src)
return err
}

func setTmpDir(value string) (string, error) {
switch {
case runtime.GOOS != "darwin":
Expand Down

0 comments on commit 4dc98e3

Please sign in to comment.