Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI:MACHINE] e2emachineisolatedraft #21034

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions pkg/machine/e2e/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var _ = Describe("run basic podman commands", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down Expand Up @@ -53,6 +54,21 @@ var _ = Describe("run basic podman commands", func() {
rmCon, err := mb.setCmd(bm.withPodmanCommand([]string{"rm", "-a"})).run()
Expect(err).ToNot(HaveOccurred())
Expect(rmCon).To(Exit(0))

// make sure gvproxy is running
before, beforeErr := pgrep(gvproxyBinaryName)
Expect(beforeErr).ToNot(HaveOccurred())
Expect(before).To(ContainSubstring(gvproxyBinaryName))

rm := rmMachine{}
removeSession, err := mb.setCmd(rm.withForce()).run()
Expect(err).ToNot(HaveOccurred())
Expect(removeSession).To(Exit(0))

// Make sure machine rm -f stopped gvproxy
after, afterError := pgrep(gvproxyBinaryName)
Expect(afterError).To(HaveOccurred())
Expect(after).ToNot(ContainSubstring(gvproxyBinaryName))
})

It("Podman ops with port forwarding and gvproxy", func() {
Expand All @@ -74,7 +90,8 @@ var _ = Describe("run basic podman commands", func() {
Expect(err).ToNot(HaveOccurred())
Expect(exec).To(Exit(0))

out, err := pgrep("gvproxy")
// make sure gvproxy is running
out, err := pgrep(gvproxyBinaryName)
Expect(err).ToNot(HaveOccurred())
Expect(out).ToNot(BeEmpty())

Expand All @@ -89,8 +106,8 @@ var _ = Describe("run basic podman commands", func() {
Expect(stopSession).To(Exit(0))

// gxproxy should exit after machine is stopped
out, _ = pgrep("gvproxy")
Expect(out).ToNot(ContainSubstring("gvproxy"))
out, _ = pgrep(gvproxyBinaryName)
Expect(out).ToNot(ContainSubstring(gvproxyBinaryName))
})

})
Expand Down
2 changes: 2 additions & 0 deletions pkg/machine/e2e/config_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/containers/podman/v4/pkg/machine"
)

var gvproxyBinaryName string = "gvproxy"

func getDownloadLocation(p machine.VirtProvider) string {
return getFCOSDownloadLocation(p)
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/machine/e2e/config_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

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

var gvproxyBinaryName string = "gvproxy.exe"

func getDownloadLocation(p machine.VirtProvider) string {
if p.VMType() == machine.HyperVVirt {
return getFCOSDownloadLocation(p)
Expand All @@ -33,7 +35,9 @@ func pgrep(n string) (string, error) {
}
strOut := string(out)
// in pgrep, if no running process is found, it exits 1 and the output is zilch
if strings.Contains(strOut, "INFO: No tasks are running which match the specified search") {
// also, originally in windows, the following substring had an append of "search" but it looks
// like some windows implementations use "criteria". removed the append all-together
if strings.Contains(strOut, "INFO: No tasks are running which match the specified") {
return "", fmt.Errorf("no task found")
}
return strOut, nil
Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var _ = Describe("podman machine info", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var _ = Describe("podman machine init", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var _ = Describe("podman inspect stop", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var _ = Describe("podman machine list", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
55 changes: 54 additions & 1 deletion pkg/machine/e2e/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func setup() (string, *machineTestBuilder) {
if err := os.MkdirAll(filepath.Join(homeDir, ".ssh"), 0700); err != nil {
Fail(fmt.Sprintf("failed to create ssh dir: %q", err))
}
cConfDir := filepath.Join(homeDir, "containers")
if err := os.MkdirAll(cConfDir, 0755); err != nil {
Fail(fmt.Sprintf("failed to create %q: %s", cConfDir, err.Error()))
}

sshConfig, err := os.Create(filepath.Join(homeDir, ".ssh", "config"))
if err != nil {
Fail(fmt.Sprintf("failed to create ssh config: %q", err))
Expand All @@ -115,12 +120,44 @@ func setup() (string, *machineTestBuilder) {
if err := os.Setenv("HOME", homeDir); err != nil {
Fail("failed to set home dir")
}

fmt.Println("Set HOME to:", homeDir)
if err := os.Setenv("USERPROFILE", homeDir); err != nil {
Fail("failed to set USERPROFILE dir")
}

fmt.Println("Set USERPROFILE to:", homeDir)

if err := os.Setenv("XDG_RUNTIME_DIR", homeDir); err != nil {
Fail("failed to set xdg_runtime dir")
Fail("failed to set xdg_runtime_dir")
}

if err := os.Setenv("XDG_CONFIG_HOME", homeDir); err != nil {
Fail("failed to set xdg_CONFIG_HOME")
}

fmt.Println("Set XDG_CONFIG_HOME to ", homeDir)

cConf := filepath.Join(cConfDir, "containers.conf")
cc, err := os.Create(cConf)
if err != nil {
Fail("failed to create test container.conf")
}

if err := cc.Close(); err != nil {
Fail(fmt.Sprintf("unable to close file %q: %s", cConf, err.Error()))
}

if err := os.Setenv("CONTAINERS_CONF", cConf); err != nil {
Fail("failed to set CONTAINERS_CONF environment var")
}

fmt.Println("set CONTAINERS_CONF to ", cConf)

if err := os.Unsetenv("SSH_AUTH_SOCK"); err != nil {
Fail("unable to unset SSH_AUTH_SOCK")
}

mb, err := newMB()
if err != nil {
Fail(fmt.Sprintf("failed to create machine test: %q", err))
Expand All @@ -140,6 +177,7 @@ func setup() (string, *machineTestBuilder) {
if err := n.Close(); err != nil {
Fail(fmt.Sprintf("failed to close image copy handler: %q", err))
}

return homeDir, mb
}

Expand All @@ -158,3 +196,18 @@ func teardown(origHomeDir string, testDir string, mb *machineTestBuilder) {
Fail("failed to set home dir")
}
}

// dumpDebug is called after each test and can be used to display useful debug information
// about the environment
func dumpDebug(mb *machineTestBuilder, testDir string, sr SpecReport) {
if !sr.Failed() {
return
}
fmt.Println("///////// DEBUG FOR FAILURE")
fmt.Println("test dir was: ", testDir)
debugMachine := basicMachine{}
// List connections
_, _ = mb.setCmd(debugMachine.withPodmanCommand([]string{"system", "connection", "ls"})).run()
// List machines
_, _ = mb.setCmd(debugMachine.withPodmanCommand([]string{"machine", "ls"})).run()
}
1 change: 1 addition & 0 deletions pkg/machine/e2e/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var _ = Describe("podman machine proxy settings propagation", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/rm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var _ = Describe("podman machine rm", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var _ = Describe("podman machine set", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var _ = Describe("podman machine ssh", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var _ = Describe("podman machine start", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var _ = Describe("podman machine stop", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
4 changes: 2 additions & 2 deletions pkg/machine/hyperv/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ func (v HyperVVirtualization) RemoveAndCleanMachines() error {
if err != nil {
prevErr = handlePrevError(err, prevErr)
}

// using the mm stop so gvproxy will also be torn down
if vm.State() != hypervctl.Disabled {
if err := vm.StopWithForce(); err != nil {
if err := mm.stop(vm, true); err != nil {
prevErr = handlePrevError(err, prevErr)
}
}
Expand Down
30 changes: 20 additions & 10 deletions pkg/machine/hyperv/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ func (m *HyperVMachine) Remove(_ string, opts machine.RemoveOptions) (string, fu
return "", nil, &machine.ErrVMRunningCannotDestroyed{Name: m.Name}
}
// force stop bc we are destroying
if err := vm.StopWithForce(); err != nil {
return "", nil, fmt.Errorf("stopping virtual machine: %w", err)
if err := m.stop(vm, true); err != nil {
return "", nil, err
}

// Update state on the VM by pulling its info again
Expand Down Expand Up @@ -649,29 +649,39 @@ func (m *HyperVMachine) State(_ bool) (define.Status, error) {
return define.Stopped, nil
}

func (m *HyperVMachine) Stop(name string, opts machine.StopOptions) error {
func (m *HyperVMachine) Stop(name string, _ machine.StopOptions) error {
m.lock.Lock()
defer m.lock.Unlock()

vmm := hypervctl.NewVirtualMachineManager()
vm, err := vmm.GetMachine(m.Name)
if err != nil {
return fmt.Errorf("getting virtual machine: %w", err)
}
return m.stop(vm, false)
}

// stop turns a machine off with optional bool for force stop. the machine should be locked
// by the caller
func (m *HyperVMachine) stop(vm *hypervctl.VirtualMachine, hardStop bool) error {
vmState := vm.State()
if vm.State() == hypervctl.Disabled {
return nil
}
if vmState != hypervctl.Enabled { // more states could be provided as well
return hypervctl.ErrMachineStateInvalid
}

if err := machine.CleanupGVProxy(m.GvProxyPid); err != nil {
logrus.Error(err)
}

if err := vm.Stop(); err != nil {
return fmt.Errorf("stopping virtual machine: %w", err)
// the vm is not disabled (stopped) and not enabled (running), we need to use
// force stop here
if vmState != hypervctl.Enabled || hardStop {
if err := vm.StopWithForce(); err != nil {
return err
}
} else {
// the vm is just regular old enabled (running)
if err := vm.Stop(); err != nil {
return fmt.Errorf("stopping virtual machine: %w", err)
}
}

// keep track of last up
Expand Down