Skip to content

Commit 4a48e17

Browse files
committed
fake images: windows hyperv
this pr is a follow on to #27493. it adds support for hyperv "fake" images and suggests a benefit in terms of test speed. for hyperv, we create a generic 4MB vhdx and stick it into the temp dir. this saves us from any image copy or compression. i also followed up on a few comments Paul made about using windows|unix instead of each platform. Signed-off-by: Brent Baude <[email protected]>
1 parent f23367f commit 4a48e17

File tree

6 files changed

+55
-35
lines changed

6 files changed

+55
-35
lines changed
Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
11
package e2e_test
22

3-
import "os"
4-
53
const podmanBinary = "../../../bin/darwin/podman"
6-
7-
var (
8-
fakeImagePath string = os.DevNull
9-
)
10-
11-
func (i *initMachine) withFakeImage(_ *machineTestBuilder) *initMachine {
12-
i.image = fakeImagePath
13-
return i
14-
}
Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
11
package e2e_test
22

3-
import "os"
4-
53
const podmanBinary = "../../../bin/podman-remote"
6-
7-
var (
8-
fakeImagePath string = os.DevNull
9-
)
10-
11-
func (i *initMachine) withFakeImage(_ *machineTestBuilder) *initMachine {
12-
i.image = fakeImagePath
13-
return i
14-
}
Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
11
package e2e_test
22

3-
import "os"
4-
53
const podmanBinary = "../../../bin/podman-remote"
6-
7-
var (
8-
fakeImagePath string = os.DevNull
9-
)
10-
11-
func (i *initMachine) withFakeImage(_ *machineTestBuilder) *initMachine {
12-
i.image = fakeImagePath
13-
return i
14-
}

pkg/machine/e2e/config_unix_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,25 @@
33
package e2e_test
44

55
import (
6+
"os"
67
"os/exec"
78
)
89

10+
var (
11+
fakeImagePath string = os.DevNull
12+
)
13+
914
func pgrep(_ string) (string, error) {
1015
out, err := exec.Command("pgrep", "gvproxy").Output()
1116
return string(out), err
1217
}
18+
19+
func initPlatform() {}
20+
21+
// withFakeImage should be used in tests where the machine is
22+
// initialized (or not) but never started. It is intended
23+
// to speed up CI by not processing our large machine files.
24+
func (i *initMachine) withFakeImage(_ *machineTestBuilder) *initMachine {
25+
i.image = fakeImagePath
26+
return i
27+
}

pkg/machine/e2e/config_windows_test.go

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,39 @@ package e2e_test
33
import (
44
"fmt"
55
"os/exec"
6+
"path/filepath"
67
"strings"
78

9+
"github.com/containers/libhvee/pkg/hypervctl"
10+
"github.com/containers/podman/v6/pkg/machine/define"
811
. "github.com/onsi/ginkgo/v2"
912
. "github.com/onsi/gomega/gexec"
1013
)
1114

1215
const podmanBinary = "../../../bin/windows/podman.exe"
1316

17+
var (
18+
// fakeImagePath string = "C:\\Users\\Baude\\fakedisk.vhdx"
19+
fakeImagePath string = ""
20+
)
21+
22+
func initPlatform() {
23+
switch testProvider.VMType().String() {
24+
case define.HyperVVirt.String():
25+
vmm := hypervctl.NewVirtualMachineManager()
26+
fullFileName := filepath.Join(tmpDir, randomString()) + ".vhdx"
27+
if err := vmm.CreateVhdxFile(fullFileName, 15*1024*1024); err != nil {
28+
Fail(fmt.Sprintf("Failed to create file %s %q", fullFileName, err))
29+
}
30+
fakeImagePath = fullFileName
31+
fmt.Println("Created fake disk image: " + fakeImagePath)
32+
case define.WSLVirt.String():
33+
fmt.Println("Nothing yet, tbd")
34+
default:
35+
Fail(fmt.Sprintf("unknown Windows provider: %q", testProvider.VMType().String()))
36+
}
37+
}
38+
1439
// pgrep emulates the pgrep linux command
1540
func pgrep(n string) (string, error) {
1641
// add filter to find the process and do no display a header
@@ -41,7 +66,17 @@ func runWslCommand(cmdArgs []string) (*machineSession, error) {
4166
return &ms, nil
4267
}
4368

44-
func (i *initMachine) withFakeImage(_ *machineTestBuilder) *initMachine {
45-
i.image = mb.imagePath
69+
// withFakeImage should be used in tests where the machine is
70+
// initialized (or not) but never started. It is intended
71+
// to speed up CI by not processing our large machine files.
72+
func (i *initMachine) withFakeImage(mb *machineTestBuilder) *initMachine {
73+
switch testProvider.VMType() {
74+
case define.HyperVVirt:
75+
i.image = fakeImagePath
76+
case define.WSLVirt:
77+
i.image = mb.imagePath
78+
default:
79+
Fail(fmt.Sprintf("unknown Windows provider: %q", testProvider.VMType().String()))
80+
}
4681
return i
4782
}

pkg/machine/e2e/machine_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ var _ = BeforeSuite(func() {
7272
if pullError != nil {
7373
Fail(fmt.Sprintf("failed to pull disk: %q", pullError))
7474
}
75+
76+
fmt.Println("Running platform specific set-up")
77+
initPlatform()
7578
})
7679

7780
type timing struct {

0 commit comments

Comments
 (0)