fix usermode test

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
This commit is contained in:
Jason T. Greene
2024-02-14 17:22:04 -06:00
parent 4fffa78eec
commit f036476cfa
4 changed files with 19 additions and 9 deletions

View File

@@ -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,
} }

View File

@@ -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")
} }

View File

@@ -201,6 +201,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))
} }

View File

@@ -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)
} }