From 4dc98e3a5a040d4af65f909a816e53af10d02a9c Mon Sep 17 00:00:00 2001 From: Ashley Cui Date: Fri, 21 Jun 2024 10:24:39 -0400 Subject: [PATCH] pkg/machine/e2e: Remove unnecessary copy of machine image. 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/ is copied to TESTDIR/podman_test/ by the test, and then podman machine copies the image to TESTDIR/podman_test/.local/share/containers/podman/machine/provider/ After the change: TESTDIR/ is copied to TESTDIR/podman_test/.local/share/containers/podman/machine/provider/ by podman machine The image that is actually run is at TESTDIR/podman_test/.local/share/containers/podman/machine/provider/ in both instances. Signed-off-by: Ashley Cui --- pkg/machine/e2e/machine_test.go | 35 +-------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/pkg/machine/e2e/machine_test.go b/pkg/machine/e2e/machine_test.go index 6a3d60b6bb4d..7ff0fee2cd0e 100644 --- a/pkg/machine/e2e/machine_test.go +++ b/pkg/machine/e2e/machine_test.go @@ -3,7 +3,6 @@ package e2e_test import ( "errors" "fmt" - "io" "os" "path/filepath" "runtime" @@ -11,7 +10,6 @@ import ( "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" @@ -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 } @@ -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":