diff --git a/cmd/podman/machine/inspect.go b/cmd/podman/machine/inspect.go index 89a1d4503a..81699268d0 100644 --- a/cmd/podman/machine/inspect.go +++ b/cmd/podman/machine/inspect.go @@ -89,7 +89,7 @@ func inspect(cmd *cobra.Command, args []string) error { Resources: mc.Resources, SSHConfig: mc.SSH, State: state, - UserModeNetworking: false, + UserModeNetworking: provider.UserModeNetworkEnabled(mc), // TODO I think this should be the HostUser Rootful: mc.HostUser.Rootful, } diff --git a/pkg/machine/e2e/init_windows_test.go b/pkg/machine/e2e/init_windows_test.go index e19b4a53b0..92acd7f8d4 100644 --- a/pkg/machine/e2e/init_windows_test.go +++ b/pkg/machine/e2e/init_windows_test.go @@ -8,6 +8,7 @@ import ( "github.com/Microsoft/go-winio/vhd" "github.com/containers/libhvee/pkg/hypervctl" "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/gomega" . "github.com/onsi/gomega/gexec" @@ -36,6 +37,18 @@ var _ = Describe("podman machine init - windows only", func() { Expect(err).ToNot(HaveOccurred()) 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 = inspect.withFormat("{{.UserModeNetworking}}") 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() { skipIfNotVmtype(define.WSLVirt, "WSL test only") - var ( - wsl string = "wsl" - ) - name := randomString() distName := fmt.Sprintf("podman-%s", name) 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 // so we dont have to download a distribution from microsoft // 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(exportSession).To(Exit(0)) // 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(importSession).To(Exit(0)) defer func() { - _, err := runSystemCommand(wsl, []string{"--unregister", distName}, defaultTimeout, true) + _, err := runSystemCommand(wutil.FindWSL(), []string{"--unregister", distName}, defaultTimeout, true) if err != nil { fmt.Println("unable to remove bogus wsl instance") } diff --git a/pkg/machine/e2e/machine_test.go b/pkg/machine/e2e/machine_test.go index f7af93ad17..35267ebe6d 100644 --- a/pkg/machine/e2e/machine_test.go +++ b/pkg/machine/e2e/machine_test.go @@ -201,6 +201,7 @@ func teardown(origHomeDir string, testDir string, mb *machineTestBuilder) { GinkgoWriter.Printf("error occurred rm'ing machine: %q\n", err) } } + if err := utils.GuardedRemoveAll(testDir); err != nil { Fail(fmt.Sprintf("failed to remove test dir: %q", err)) } diff --git a/pkg/machine/shim/host.go b/pkg/machine/shim/host.go index ea62c5d90b..f4de604711 100644 --- a/pkg/machine/shim/host.go +++ b/pkg/machine/shim/host.go @@ -50,7 +50,7 @@ func List(vmstubbers []vmconfigs.VMProvider, _ machine.ListOptions) ([]*machine. Port: mc.SSH.Port, RemoteUsername: mc.SSH.RemoteUsername, IdentityPath: mc.SSH.IdentityPath, - UserModeNetworking: false, // TODO Need to plumb this for WSL + UserModeNetworking: s.UserModeNetworkEnabled(mc), } lrs = append(lrs, &lr) }