Skip to content

Commit

Permalink
fixes for pkg/machine/e2e on hyperv
Browse files Browse the repository at this point in the history
some problems were found in machine tests on hyperv.

in the case of rootful, it is currently not implemented.  an issue #20092 has been
created for that problem.

there also seems to be a timezone issue between ignition and fcos right
now.  inquiries are in for that but no issue generated for that.  this
problem is not exclusive to hyperv by any means.

both of the above have been skipped or commented out.

otherwise, this fixes machine state reporting for consistency.

Signed-off-by: Brent Baude <[email protected]>
  • Loading branch information
baude committed Sep 21, 2023
1 parent 935a6d1 commit c66aa3b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
4 changes: 3 additions & 1 deletion pkg/machine/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const (
// Stopped indicates the vm has stopped.
Stopped Status = "stopped"
// Starting indicated the vm is in the process of starting
Starting Status = "starting"
Starting Status = "starting"
// Unknown means the state is not known
Unknown Status = "unknown"
DefaultMachineName string = "podman-machine-default"
apiUpTimeout = 20 * time.Second
)
Expand Down
24 changes: 17 additions & 7 deletions pkg/machine/e2e/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,19 @@ var _ = Describe("podman machine init", func() {
Expect(foundMemory).To(BeNumerically(">", 3800000))
Expect(foundMemory).To(BeNumerically("<", 4200000))

sshTimezone := sshMachine{}
timezoneSession, err := mb.setName(name).setCmd(sshTimezone.withSSHCommand([]string{"date"})).run()
Expect(err).ToNot(HaveOccurred())
Expect(timezoneSession).To(Exit(0))
Expect(timezoneSession.outputToString()).To(ContainSubstring("HST"))
// TODO timezone setting is broken in FCOS rn. It is either ignition or a change in fedora.
// sshTimezone := sshMachine{}
// timezoneSession, err := mb.setName(name).setCmd(sshTimezone.withSSHCommand([]string{"date"})).run()
// Expect(err).ToNot(HaveOccurred())
// Expect(timezoneSession).To(Exit(0))
// Expect(timezoneSession.outputToString()).To(ContainSubstring("HST"))
})

It("machine init with volume", func() {
if testProvider.VMType() == machine.HyperVVirt {
Skip("volumes are not supported on hyperv yet")
}

tmpDir, err := os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())
_, err = os.CreateTemp(tmpDir, "example")
Expand All @@ -164,6 +169,10 @@ var _ = Describe("podman machine init", func() {
})

It("machine init rootless docker.sock check", func() {
if testProvider.VMType() == machine.HyperVVirt {
//https://github.com/containers/podman/issues/20092
Skip("rootless is broken with hyperv")
}
i := initMachine{}
name := randomString()
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
Expand Down Expand Up @@ -214,8 +223,9 @@ var _ = Describe("podman machine init", func() {
})

It("init with user mode networking ", func() {
SkipIfNotWindows("setting user mode networking is only honored on Windows")

if testProvider.VMType() != machine.WSLVirt {
Skip("test is only supported by WSL")
}
i := new(initMachine)
name := randomString()
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath).withUserModeNetworking(true)).run()
Expand Down
6 changes: 4 additions & 2 deletions pkg/machine/e2e/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ func TestMachine(t *testing.T) {
RunSpecs(t, "Podman Machine tests")
}

var _ = BeforeSuite(func() {
var testProvider machine.VirtProvider

testProvider, err := provider.Get()
var _ = BeforeSuite(func() {
var err error
testProvider, err = provider.Get()
if err != nil {
Fail("unable to create testProvider")
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/machine/hyperv/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package hyperv
import (
"encoding/json"
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
Expand Down Expand Up @@ -284,3 +285,15 @@ func handlePrevError(e, prevErr error) error {
}
return e
}

func stateConversion(s hypervctl.EnabledState) (machine.Status, error) {
switch s {
case hypervctl.Enabled:
return machine.Running, nil
case hypervctl.Disabled:
return machine.Stopped, nil
case hypervctl.Starting:
return machine.Starting, nil
}
return machine.Unknown, fmt.Errorf("unknown state: %q", s.String())
}
7 changes: 6 additions & 1 deletion pkg/machine/hyperv/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ func (m *HyperVMachine) Inspect() (*machine.InspectInfo, error) {
return nil, err
}

vmState, err := stateConversion(vm.State())
if err != nil {
return nil, err
}

return &machine.InspectInfo{
ConfigPath: m.ConfigPath,
ConnectionInfo: machine.ConnectionConfig{},
Expand All @@ -300,7 +305,7 @@ func (m *HyperVMachine) Inspect() (*machine.InspectInfo, error) {
Memory: cfg.Hardware.Memory,
},
SSHConfig: m.SSHConfig,
State: vm.State().String(),
State: string(vmState),
Rootful: m.Rootful,
}, nil
}
Expand Down

0 comments on commit c66aa3b

Please sign in to comment.