mirror of
https://github.com/containers/podman.git
synced 2025-07-03 09:17:15 +08:00
Merge pull request #21666 from n1hility/reenable-wsl-tests
Reenable wsl tests
This commit is contained in:
@ -795,8 +795,8 @@ podman_machine_windows_task:
|
|||||||
platform: windows
|
platform: windows
|
||||||
env: *winenv
|
env: *winenv
|
||||||
matrix:
|
matrix:
|
||||||
#- env:
|
- env:
|
||||||
# TEST_FLAVOR: "machine-wsl"
|
TEST_FLAVOR: "machine-wsl"
|
||||||
- env:
|
- env:
|
||||||
TEST_FLAVOR: "machine-hyperv"
|
TEST_FLAVOR: "machine-hyperv"
|
||||||
clone_script: *winclone
|
clone_script: *winclone
|
||||||
|
@ -48,7 +48,7 @@ func installWslKernel() error {
|
|||||||
)
|
)
|
||||||
backoff := 500 * time.Millisecond
|
backoff := 500 * time.Millisecond
|
||||||
for i := 1; i < 6; i++ {
|
for i := 1; i < 6; i++ {
|
||||||
err = wutil.SilentExec("wsl", "--update")
|
err = wutil.SilentExec(wutil.FindWSL(), "--update")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ func inspect(cmd *cobra.Command, args []string) error {
|
|||||||
Resources: mc.Resources,
|
Resources: mc.Resources,
|
||||||
SSHConfig: mc.SSH,
|
SSHConfig: mc.SSH,
|
||||||
State: state,
|
State: state,
|
||||||
UserModeNetworking: false,
|
UserModeNetworking: provider.UserModeNetworkEnabled(mc),
|
||||||
// TODO I think this should be the HostUser
|
// TODO I think this should be the HostUser
|
||||||
Rootful: mc.HostUser.Rootful,
|
Rootful: mc.HostUser.Rootful,
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/Microsoft/go-winio/vhd"
|
"github.com/Microsoft/go-winio/vhd"
|
||||||
"github.com/containers/libhvee/pkg/hypervctl"
|
"github.com/containers/libhvee/pkg/hypervctl"
|
||||||
"github.com/containers/podman/v5/pkg/machine/define"
|
"github.com/containers/podman/v5/pkg/machine/define"
|
||||||
|
"github.com/containers/podman/v5/pkg/machine/wsl/wutil"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
. "github.com/onsi/gomega/gexec"
|
. "github.com/onsi/gomega/gexec"
|
||||||
@ -36,6 +37,18 @@ var _ = Describe("podman machine init - windows only", func() {
|
|||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(session).To(Exit(0))
|
Expect(session).To(Exit(0))
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
_, err := runSystemCommand(wutil.FindWSL(), []string{"--terminate", "podman-net-usermode"}, defaultTimeout, true)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("unable to terminate podman-net-usermode")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = runSystemCommand(wutil.FindWSL(), []string{"--unregister", "podman-net-usermode"}, defaultTimeout, true)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("unable to unregister podman-net-usermode")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
inspect := new(inspectMachine)
|
inspect := new(inspectMachine)
|
||||||
inspect = inspect.withFormat("{{.UserModeNetworking}}")
|
inspect = inspect.withFormat("{{.UserModeNetworking}}")
|
||||||
inspectSession, err := mb.setName(name).setCmd(inspect).run()
|
inspectSession, err := mb.setName(name).setCmd(inspect).run()
|
||||||
@ -81,10 +94,6 @@ var _ = Describe("podman machine init - windows only", func() {
|
|||||||
It("init should not overwrite existing WSL vms", func() {
|
It("init should not overwrite existing WSL vms", func() {
|
||||||
skipIfNotVmtype(define.WSLVirt, "WSL test only")
|
skipIfNotVmtype(define.WSLVirt, "WSL test only")
|
||||||
|
|
||||||
var (
|
|
||||||
wsl string = "wsl"
|
|
||||||
)
|
|
||||||
|
|
||||||
name := randomString()
|
name := randomString()
|
||||||
distName := fmt.Sprintf("podman-%s", name)
|
distName := fmt.Sprintf("podman-%s", name)
|
||||||
exportedPath := filepath.Join(testDir, "bogus.tar")
|
exportedPath := filepath.Join(testDir, "bogus.tar")
|
||||||
@ -102,17 +111,17 @@ var _ = Describe("podman machine init - windows only", func() {
|
|||||||
// a vm outside the context of podman-machine and also
|
// a vm outside the context of podman-machine and also
|
||||||
// so we dont have to download a distribution from microsoft
|
// so we dont have to download a distribution from microsoft
|
||||||
// servers
|
// servers
|
||||||
exportSession, err := runSystemCommand(wsl, []string{"--export", "podman-foobarexport", exportedPath}, defaultTimeout, true)
|
exportSession, err := runSystemCommand(wutil.FindWSL(), []string{"--export", "podman-foobarexport", exportedPath}, defaultTimeout, true)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(exportSession).To(Exit(0))
|
Expect(exportSession).To(Exit(0))
|
||||||
|
|
||||||
// importing the machine and creating a vm
|
// importing the machine and creating a vm
|
||||||
importSession, err := runSystemCommand(wsl, []string{"--import", distName, distrDir, exportedPath}, defaultTimeout, true)
|
importSession, err := runSystemCommand(wutil.FindWSL(), []string{"--import", distName, distrDir, exportedPath}, defaultTimeout, true)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(importSession).To(Exit(0))
|
Expect(importSession).To(Exit(0))
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
_, err := runSystemCommand(wsl, []string{"--unregister", distName}, defaultTimeout, true)
|
_, err := runSystemCommand(wutil.FindWSL(), []string{"--unregister", distName}, defaultTimeout, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("unable to remove bogus wsl instance")
|
fmt.Println("unable to remove bogus wsl instance")
|
||||||
}
|
}
|
||||||
|
@ -200,6 +200,7 @@ func teardown(origHomeDir string, testDir string, mb *machineTestBuilder) {
|
|||||||
GinkgoWriter.Printf("error occurred rm'ing machine: %q\n", err)
|
GinkgoWriter.Printf("error occurred rm'ing machine: %q\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := utils.GuardedRemoveAll(testDir); err != nil {
|
if err := utils.GuardedRemoveAll(testDir); err != nil {
|
||||||
Fail(fmt.Sprintf("failed to remove test dir: %q", err))
|
Fail(fmt.Sprintf("failed to remove test dir: %q", err))
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ func List(vmstubbers []vmconfigs.VMProvider, _ machine.ListOptions) ([]*machine.
|
|||||||
Port: mc.SSH.Port,
|
Port: mc.SSH.Port,
|
||||||
RemoteUsername: mc.SSH.RemoteUsername,
|
RemoteUsername: mc.SSH.RemoteUsername,
|
||||||
IdentityPath: mc.SSH.IdentityPath,
|
IdentityPath: mc.SSH.IdentityPath,
|
||||||
UserModeNetworking: false, // TODO Need to plumb this for WSL
|
UserModeNetworking: s.UserModeNetworkEnabled(mc),
|
||||||
}
|
}
|
||||||
lrs = append(lrs, &lr)
|
lrs = append(lrs, &lr)
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func provisionWSLDist(name string, imagePath string, prompt string) (string, err
|
|||||||
|
|
||||||
dist := machine.ToDist(name)
|
dist := machine.ToDist(name)
|
||||||
fmt.Println(prompt)
|
fmt.Println(prompt)
|
||||||
if err = runCmdPassThrough("wsl", "--import", dist, distTarget, imagePath, "--version", "2"); err != nil {
|
if err = runCmdPassThrough(wutil.FindWSL(), "--import", dist, distTarget, imagePath, "--version", "2"); err != nil {
|
||||||
return "", fmt.Errorf("the WSL import of guest OS failed: %w", err)
|
return "", fmt.Errorf("the WSL import of guest OS failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,7 +446,7 @@ func installWslKernel() error {
|
|||||||
|
|
||||||
backoff := 500 * time.Millisecond
|
backoff := 500 * time.Millisecond
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
err = runCmdPassThroughTee(log, "wsl", "--update")
|
err = runCmdPassThroughTee(log, wutil.FindWSL(), "--update")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -556,17 +556,17 @@ func withUser(s string, user string) string {
|
|||||||
func wslInvoke(dist string, arg ...string) error {
|
func wslInvoke(dist string, arg ...string) error {
|
||||||
newArgs := []string{"-u", "root", "-d", dist}
|
newArgs := []string{"-u", "root", "-d", dist}
|
||||||
newArgs = append(newArgs, arg...)
|
newArgs = append(newArgs, arg...)
|
||||||
return runCmdPassThrough("wsl", newArgs...)
|
return runCmdPassThrough(wutil.FindWSL(), newArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func wslPipe(input string, dist string, arg ...string) error {
|
func wslPipe(input string, dist string, arg ...string) error {
|
||||||
newArgs := []string{"-u", "root", "-d", dist}
|
newArgs := []string{"-u", "root", "-d", dist}
|
||||||
newArgs = append(newArgs, arg...)
|
newArgs = append(newArgs, arg...)
|
||||||
return pipeCmdPassThrough("wsl", input, newArgs...)
|
return pipeCmdPassThrough(wutil.FindWSL(), input, newArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func wslCreateKeys(identityPath string, dist string) (string, error) {
|
func wslCreateKeys(identityPath string, dist string) (string, error) {
|
||||||
return machine.CreateSSHKeysPrefix(identityPath, true, true, "wsl", "-u", "root", "-d", dist)
|
return machine.CreateSSHKeysPrefix(identityPath, true, true, wutil.FindWSL(), "-u", "root", "-d", dist)
|
||||||
}
|
}
|
||||||
|
|
||||||
func runCmdPassThrough(name string, arg ...string) error {
|
func runCmdPassThrough(name string, arg ...string) error {
|
||||||
@ -631,7 +631,7 @@ func obtainGlobalConfigLock() (*fileLock, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsWSLFeatureEnabled() bool {
|
func IsWSLFeatureEnabled() bool {
|
||||||
return wutil.SilentExec("wsl", "--set-default-version", "2") == nil
|
return wutil.SilentExec(wutil.FindWSL(), "--set-default-version", "2") == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func isWSLRunning(dist string) (bool, error) {
|
func isWSLRunning(dist string) (bool, error) {
|
||||||
@ -657,7 +657,7 @@ func getAllWSLDistros(running bool) (map[string]struct{}, error) {
|
|||||||
if running {
|
if running {
|
||||||
args = append(args, "--running")
|
args = append(args, "--running")
|
||||||
}
|
}
|
||||||
cmd := exec.Command("wsl", args...)
|
cmd := exec.Command(wutil.FindWSL(), args...)
|
||||||
out, err := cmd.StdoutPipe()
|
out, err := cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -681,7 +681,7 @@ func getAllWSLDistros(running bool) (map[string]struct{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isSystemdRunning(dist string) (bool, error) {
|
func isSystemdRunning(dist string) (bool, error) {
|
||||||
cmd := exec.Command("wsl", "-u", "root", "-d", dist, "sh")
|
cmd := exec.Command(wutil.FindWSL(), "-u", "root", "-d", dist, "sh")
|
||||||
cmd.Stdin = strings.NewReader(sysdpid + "\necho $SYSDPID\n")
|
cmd.Stdin = strings.NewReader(sysdpid + "\necho $SYSDPID\n")
|
||||||
out, err := cmd.StdoutPipe()
|
out, err := cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -706,12 +706,12 @@ func isSystemdRunning(dist string) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func terminateDist(dist string) error {
|
func terminateDist(dist string) error {
|
||||||
cmd := exec.Command("wsl", "--terminate", dist)
|
cmd := exec.Command(wutil.FindWSL(), "--terminate", dist)
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func unregisterDist(dist string) error {
|
func unregisterDist(dist string) error {
|
||||||
cmd := exec.Command("wsl", "--unregister", dist)
|
cmd := exec.Command(wutil.FindWSL(), "--unregister", dist)
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -753,7 +753,7 @@ func getCPUs(name string) (uint64, error) {
|
|||||||
if run, _ := isWSLRunning(dist); !run {
|
if run, _ := isWSLRunning(dist); !run {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
cmd := exec.Command("wsl", "-u", "root", "-d", dist, "nproc")
|
cmd := exec.Command(wutil.FindWSL(), "-u", "root", "-d", dist, "nproc")
|
||||||
out, err := cmd.StdoutPipe()
|
out, err := cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -777,7 +777,7 @@ func getMem(name string) (uint64, error) {
|
|||||||
if run, _ := isWSLRunning(dist); !run {
|
if run, _ := isWSLRunning(dist); !run {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
cmd := exec.Command("wsl", "-u", "root", "-d", dist, "cat", "/proc/meminfo")
|
cmd := exec.Command(wutil.FindWSL(), "-u", "root", "-d", dist, "cat", "/proc/meminfo")
|
||||||
out, err := cmd.StdoutPipe()
|
out, err := cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/containers/podman/v5/pkg/machine/ocipull"
|
"github.com/containers/podman/v5/pkg/machine/ocipull"
|
||||||
"github.com/containers/podman/v5/pkg/machine/stdpull"
|
"github.com/containers/podman/v5/pkg/machine/stdpull"
|
||||||
|
"github.com/containers/podman/v5/pkg/machine/wsl/wutil"
|
||||||
|
|
||||||
gvproxy "github.com/containers/gvisor-tap-vsock/pkg/types"
|
gvproxy "github.com/containers/gvisor-tap-vsock/pkg/types"
|
||||||
"github.com/containers/podman/v5/pkg/machine"
|
"github.com/containers/podman/v5/pkg/machine"
|
||||||
@ -105,7 +106,7 @@ func (w WSLStubber) Remove(mc *vmconfigs.MachineConfig) ([]string, func() error,
|
|||||||
// below if we wanted to hard error on the wsl unregister
|
// below if we wanted to hard error on the wsl unregister
|
||||||
// of the vm
|
// of the vm
|
||||||
wslRemoveFunc := func() error {
|
wslRemoveFunc := func() error {
|
||||||
if err := runCmdPassThrough("wsl", "--unregister", machine.ToDist(mc.Name)); err != nil {
|
if err := runCmdPassThrough(wutil.FindWSL(), "--unregister", machine.ToDist(mc.Name)); err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
return machine.ReleaseMachinePort(mc.SSH.Port)
|
return machine.ReleaseMachinePort(mc.SSH.Port)
|
||||||
@ -266,13 +267,13 @@ func (w WSLStubber) StopVM(mc *vmconfigs.MachineConfig, hardStop bool) error {
|
|||||||
fmt.Fprintf(os.Stderr, "Could not stop API forwarding service (win-sshproxy.exe): %s\n", err.Error())
|
fmt.Fprintf(os.Stderr, "Could not stop API forwarding service (win-sshproxy.exe): %s\n", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command("wsl", "-u", "root", "-d", dist, "sh")
|
cmd := exec.Command(wutil.FindWSL(), "-u", "root", "-d", dist, "sh")
|
||||||
cmd.Stdin = strings.NewReader(waitTerm)
|
cmd.Stdin = strings.NewReader(waitTerm)
|
||||||
if err = cmd.Start(); err != nil {
|
if err = cmd.Start(); err != nil {
|
||||||
return fmt.Errorf("executing wait command: %w", err)
|
return fmt.Errorf("executing wait command: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
exitCmd := exec.Command("wsl", "-u", "root", "-d", dist, "/usr/local/bin/enterns", "systemctl", "exit", "0")
|
exitCmd := exec.Command(wutil.FindWSL(), "-u", "root", "-d", dist, "/usr/local/bin/enterns", "systemctl", "exit", "0")
|
||||||
if err = exitCmd.Run(); err != nil {
|
if err = exitCmd.Run(); err != nil {
|
||||||
return fmt.Errorf("stopping sysd: %w", err)
|
return fmt.Errorf("stopping sysd: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -5,14 +5,69 @@ package wutil
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"golang.org/x/text/encoding/unicode"
|
"golang.org/x/text/encoding/unicode"
|
||||||
"golang.org/x/text/transform"
|
"golang.org/x/text/transform"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
once sync.Once
|
||||||
|
wslPath string
|
||||||
|
)
|
||||||
|
|
||||||
|
func FindWSL() string {
|
||||||
|
// At the time of this writing, a defect appeared in the OS preinstalled WSL executable
|
||||||
|
// where it no longer reliably locates the preferred Windows App Store variant.
|
||||||
|
//
|
||||||
|
// Manually discover (and cache) the wsl.exe location to bypass the problem
|
||||||
|
once.Do(func() {
|
||||||
|
var locs []string
|
||||||
|
|
||||||
|
// Prefer Windows App Store version
|
||||||
|
if localapp := getLocalAppData(); localapp != "" {
|
||||||
|
locs = append(locs, filepath.Join(localapp, "Microsoft", "WindowsApps", "wsl.exe"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, the common location for the legacy system version
|
||||||
|
root := os.Getenv("SystemRoot")
|
||||||
|
if root == "" {
|
||||||
|
root = `C:\Windows`
|
||||||
|
}
|
||||||
|
locs = append(locs, filepath.Join(root, "System32", "wsl.exe"))
|
||||||
|
|
||||||
|
for _, loc := range locs {
|
||||||
|
if _, err := os.Stat(loc); err == nil {
|
||||||
|
wslPath = loc
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hope for the best
|
||||||
|
wslPath = "wsl"
|
||||||
|
})
|
||||||
|
|
||||||
|
return wslPath
|
||||||
|
}
|
||||||
|
|
||||||
|
func getLocalAppData() string {
|
||||||
|
localapp := os.Getenv("LOCALAPPDATA")
|
||||||
|
if localapp != "" {
|
||||||
|
return localapp
|
||||||
|
}
|
||||||
|
|
||||||
|
if user := os.Getenv("USERPROFILE"); user != "" {
|
||||||
|
return filepath.Join(user, "AppData", "Local")
|
||||||
|
}
|
||||||
|
|
||||||
|
return localapp
|
||||||
|
}
|
||||||
|
|
||||||
func SilentExec(command string, args ...string) error {
|
func SilentExec(command string, args ...string) error {
|
||||||
cmd := exec.Command(command, args...)
|
cmd := exec.Command(command, args...)
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: 0x08000000}
|
cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: 0x08000000}
|
||||||
@ -28,7 +83,7 @@ func SilentExecCmd(command string, args ...string) *exec.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsWSLInstalled() bool {
|
func IsWSLInstalled() bool {
|
||||||
cmd := SilentExecCmd("wsl", "--status")
|
cmd := SilentExecCmd(FindWSL(), "--status")
|
||||||
out, err := cmd.StdoutPipe()
|
out, err := cmd.StdoutPipe()
|
||||||
cmd.Stderr = nil
|
cmd.Stderr = nil
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -48,7 +103,7 @@ func IsWSLInstalled() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsWSLStoreVersionInstalled() bool {
|
func IsWSLStoreVersionInstalled() bool {
|
||||||
cmd := SilentExecCmd("wsl", "--version")
|
cmd := SilentExecCmd(FindWSL(), "--version")
|
||||||
cmd.Stdout = nil
|
cmd.Stdout = nil
|
||||||
cmd.Stderr = nil
|
cmd.Stderr = nil
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
|
Reference in New Issue
Block a user