Skip to content

Commit

Permalink
Merge pull request #19972 from baude/hypervenablee2e
Browse files Browse the repository at this point in the history
Plumbing to run machine tests with hyperv
  • Loading branch information
openshift-merge-robot authored Sep 15, 2023
2 parents e106d6e + 919dce1 commit 04b8576
Show file tree
Hide file tree
Showing 21 changed files with 86 additions and 71 deletions.
4 changes: 2 additions & 2 deletions cmd/podman/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"text/template"

"github.com/containers/common/pkg/config"
cmdMachine "github.com/containers/podman/v4/cmd/podman/machine"
"github.com/containers/podman/v4/cmd/podman/registry"
"github.com/containers/podman/v4/pkg/machine"
"github.com/containers/podman/v4/pkg/machine/provider"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -155,7 +155,7 @@ func composeDockerHost() (string, error) {
return strings.TrimSuffix(connection.URI, parsedConnection.Path), nil
}

machineProvider, err := cmdMachine.GetSystemProvider()
machineProvider, err := provider.Get()
if err != nil {
return "", fmt.Errorf("getting machine provider: %w", err)
}
Expand Down
6 changes: 1 addition & 5 deletions cmd/podman/machine/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var (
Use: "info [options]",
Short: "Display machine host info",
Long: infoDescription,
PersistentPreRunE: rootlessOnly,
PersistentPreRunE: machinePreRunE,
RunE: info,
Args: validate.NoArgs,
ValidArgsFunction: completion.AutocompleteNone,
Expand Down Expand Up @@ -101,10 +101,6 @@ func hostInfo() (*entities.MachineHostInfo, error) {
host.Arch = runtime.GOARCH
host.OS = runtime.GOOS

provider, err := GetSystemProvider()
if err != nil {
return nil, err
}
var listOpts machine.ListOptions
listResponse, err := provider.List(listOpts)
if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions cmd/podman/machine/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
Use: "init [options] [NAME]",
Short: "Initialize a virtual machine",
Long: "Initialize a virtual machine",
PersistentPreRunE: rootlessOnly,
PersistentPreRunE: machinePreRunE,
RunE: initMachine,
Args: cobra.MaximumNArgs(1),
Example: `podman machine init podman-machine-default`,
Expand Down Expand Up @@ -128,10 +128,6 @@ func initMachine(cmd *cobra.Command, args []string) error {
vm machine.VM
)

provider, err := GetSystemProvider()
if err != nil {
return err
}
initOpts.Name = defaultMachineName
if len(args) > 0 {
if len(args[0]) > maxMachineNameSize {
Expand Down
7 changes: 2 additions & 5 deletions cmd/podman/machine/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
Use: "inspect [options] [MACHINE...]",
Short: "Inspect an existing machine",
Long: "Provide details on a managed virtual machine",
PersistentPreRunE: rootlessOnly,
PersistentPreRunE: machinePreRunE,
RunE: inspect,
Example: `podman machine inspect myvm`,
ValidArgsFunction: autocompleteMachine,
Expand Down Expand Up @@ -51,10 +51,7 @@ func inspect(cmd *cobra.Command, args []string) error {
args = append(args, defaultMachineName)
}
vms := make([]machine.InspectInfo, 0, len(args))
provider, err := GetSystemProvider()
if err != nil {
return err
}

for _, vmName := range args {
vm, err := provider.LoadVMByName(vmName)
if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions cmd/podman/machine/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var (
Aliases: []string{"ls"},
Short: "List machines",
Long: "List managed virtual machines.",
PersistentPreRunE: rootlessOnly,
PersistentPreRunE: machinePreRunE,
RunE: list,
Args: validate.NoArgs,
ValidArgsFunction: completion.AutocompleteNone,
Expand Down Expand Up @@ -66,10 +66,6 @@ func list(cmd *cobra.Command, args []string) error {
err error
)

provider, err := GetSystemProvider()
if err != nil {
return err
}
listResponse, err = provider.List(opts)
if err != nil {
return fmt.Errorf("listing vms: %w", err)
Expand Down
15 changes: 14 additions & 1 deletion cmd/podman/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/containers/podman/v4/cmd/podman/validate"
"github.com/containers/podman/v4/libpod/events"
"github.com/containers/podman/v4/pkg/machine"
provider2 "github.com/containers/podman/v4/pkg/machine/provider"
"github.com/containers/podman/v4/pkg/util"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -39,13 +40,25 @@ var (
RunE: validate.SubCommandExists,
}
)
var (
provider machine.VirtProvider
)

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Command: machineCmd,
})
}

func machinePreRunE(c *cobra.Command, args []string) error {
var err error
provider, err = provider2.Get()
if err != nil {
return err
}
return rootlessOnly(c, args)
}

// autocompleteMachineSSH - Autocomplete machine ssh command.
func autocompleteMachineSSH(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 0 {
Expand All @@ -64,7 +77,7 @@ func autocompleteMachine(cmd *cobra.Command, args []string, toComplete string) (

func getMachines(toComplete string) ([]string, cobra.ShellCompDirective) {
suggestions := []string{}
provider, err := GetSystemProvider()
provider, err := provider2.Get()
if err != nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/podman/machine/os/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"strings"

machineconfig "github.com/containers/common/pkg/machine"
"github.com/containers/podman/v4/cmd/podman/machine"
pkgMachine "github.com/containers/podman/v4/pkg/machine"
pkgOS "github.com/containers/podman/v4/pkg/machine/os"
"github.com/containers/podman/v4/pkg/machine/provider"
)

type ManagerOpts struct {
Expand Down Expand Up @@ -48,11 +48,11 @@ func machineOSManager(opts ManagerOpts) (pkgOS.Manager, error) {
if opts.VMName == "" {
vmName = pkgMachine.DefaultMachineName
}
provider, err := machine.GetSystemProvider()
p, err := provider.Get()
if err != nil {
return nil, err
}
vm, err := provider.LoadVMByName(vmName)
vm, err := p.LoadVMByName(vmName)
if err != nil {
return nil, err
}
Expand Down
6 changes: 1 addition & 5 deletions cmd/podman/machine/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
Use: "rm [options] [MACHINE]",
Short: "Remove an existing machine",
Long: "Remove a managed virtual machine ",
PersistentPreRunE: rootlessOnly,
PersistentPreRunE: machinePreRunE,
RunE: rm,
Args: cobra.MaximumNArgs(1),
Example: `podman machine rm podman-machine-default`,
Expand Down Expand Up @@ -62,10 +62,6 @@ func rm(_ *cobra.Command, args []string) error {
vmName = args[0]
}

provider, err := GetSystemProvider()
if err != nil {
return err
}
vm, err = provider.LoadVMByName(vmName)
if err != nil {
return err
Expand Down
7 changes: 2 additions & 5 deletions cmd/podman/machine/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
Use: "set [options] [NAME]",
Short: "Set a virtual machine setting",
Long: "Set an updatable virtual machine setting",
PersistentPreRunE: rootlessOnly,
PersistentPreRunE: machinePreRunE,
RunE: setMachine,
Args: cobra.MaximumNArgs(1),
Example: `podman machine set --rootful=false`,
Expand Down Expand Up @@ -89,10 +89,7 @@ func setMachine(cmd *cobra.Command, args []string) error {
if len(args) > 0 && len(args[0]) > 0 {
vmName = args[0]
}
provider, err := GetSystemProvider()
if err != nil {
return err
}

vm, err = provider.LoadVMByName(vmName)
if err != nil {
return err
Expand Down
6 changes: 1 addition & 5 deletions cmd/podman/machine/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
Use: "ssh [options] [NAME] [COMMAND [ARG ...]]",
Short: "SSH into an existing machine",
Long: "SSH into a managed virtual machine ",
PersistentPreRunE: rootlessOnly,
PersistentPreRunE: machinePreRunE,
RunE: ssh,
Example: `podman machine ssh podman-machine-default
podman machine ssh myvm echo hello`,
Expand Down Expand Up @@ -53,10 +53,6 @@ func ssh(cmd *cobra.Command, args []string) error {

// Set the VM to default
vmName := defaultMachineName
provider, err := GetSystemProvider()
if err != nil {
return err
}

// If len is greater than 0, it means we may have been
// provided the VM name. If so, we check. The VM name,
Expand Down
7 changes: 1 addition & 6 deletions cmd/podman/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
Use: "start [options] [MACHINE]",
Short: "Start an existing machine",
Long: "Start a managed virtual machine ",
PersistentPreRunE: rootlessOnly,
PersistentPreRunE: machinePreRunE,
RunE: start,
Args: cobra.MaximumNArgs(1),
Example: `podman machine start podman-machine-default`,
Expand Down Expand Up @@ -53,11 +53,6 @@ func start(_ *cobra.Command, args []string) error {
vmName = args[0]
}

provider, err := GetSystemProvider()
if err != nil {
return err
}

vm, err = provider.LoadVMByName(vmName)
if err != nil {
return err
Expand Down
7 changes: 2 additions & 5 deletions cmd/podman/machine/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
Use: "stop [MACHINE]",
Short: "Stop an existing machine",
Long: "Stop a managed virtual machine ",
PersistentPreRunE: rootlessOnly,
PersistentPreRunE: machinePreRunE,
RunE: stop,
Args: cobra.MaximumNArgs(1),
Example: `podman machine stop podman-machine-default`,
Expand All @@ -42,10 +42,7 @@ func stop(cmd *cobra.Command, args []string) error {
if len(args) > 0 && len(args[0]) > 0 {
vmName = args[0]
}
provider, err := GetSystemProvider()
if err != nil {
return err
}

vm, err = provider.LoadVMByName(vmName)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/system/reset_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
package system

import (
cmdMach "github.com/containers/podman/v4/cmd/podman/machine"
p "github.com/containers/podman/v4/pkg/machine/provider"
)

func resetMachine() error {
provider, err := cmdMach.GetSystemProvider()
provider, err := p.Get()
if err != nil {
return err
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/machine/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Working README for running the machine tests


## Linux

### QEMU

`make localmachine`

## Microsoft Windows

### HyperV

1. Open a powershell as admin
2. $env:CONTAINERS_MACHINE_PROVIDER="hyperv"
3. $env:MACHINE_IMAGE="https://fedorapeople.org/groups/podman/testing/hyperv/fedora-coreos-38.20230830.dev.0-hyperv.x86_64.vhdx.zip"
4. `./test/tools/build/ginkgo.exe -vv --tags "remote exclude_graphdriver_btrfs btrfs_noversion exclude_graphdriver_devicemapper containers_image_openpgp remote" -timeout=90m --trace --no-color pkg/machine/e2e/. `

Note: Add `--focus-file "basic_test.go" ` to only run basic test
3 changes: 3 additions & 0 deletions pkg/machine/e2e/config_linux_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package e2e_test

const podmanBinary = "../../../bin/podman-remote"
2 changes: 1 addition & 1 deletion pkg/machine/e2e/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func newMB() (*machineTestBuilder, error) {
if err != nil {
return nil, err
}
mb.podmanBinary = filepath.Join(cwd, "../../../bin/podman-remote")
mb.podmanBinary = filepath.Join(cwd, podmanBinary)
if os.Getenv("PODMAN_BINARY") != "" {
mb.podmanBinary = os.Getenv("PODMAN_BINARY")
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/machine/e2e/config_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package e2e_test

const podmanBinary = "../../../bin/windows/podman.exe"
31 changes: 21 additions & 10 deletions pkg/machine/e2e/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"

"github.com/containers/podman/v4/pkg/machine"
"github.com/containers/podman/v4/pkg/machine/qemu"
"github.com/containers/podman/v4/pkg/machine/provider"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand All @@ -26,7 +26,7 @@ const (
)

var (
tmpDir = "/var/tmp"
tmpDir = os.TempDir()
fqImageName string
suiteImageName string
)
Expand All @@ -44,28 +44,39 @@ func TestMachine(t *testing.T) {
}

var _ = BeforeSuite(func() {
dd, err := qemu.VirtualizationProvider().NewDownload("")
testProvider, err := provider.Get()
if err != nil {
Fail("unable to create new download")
Fail("unable to create testProvider")
}
fcd, err := dd.GetFCOSDownload(defaultStream)

downloadLocation := os.Getenv("MACHINE_IMAGE")

dd, err := testProvider.NewDownload("")
if err != nil {
Fail("unable to get virtual machine image")
Fail("unable to create new download")
}
if len(downloadLocation) < 1 {
fcd, err := dd.GetFCOSDownload(defaultStream)
if err != nil {
Fail("unable to get virtual machine image")
}
downloadLocation = fcd.Location
}
suiteImageName = strings.TrimSuffix(path.Base(fcd.Location), ".xz")
compressionExtension := fmt.Sprintf(".%s", testProvider.Compression().String())
suiteImageName = strings.TrimSuffix(path.Base(downloadLocation), compressionExtension)
fqImageName = filepath.Join(tmpDir, suiteImageName)
if _, err := os.Stat(fqImageName); err != nil {
if os.IsNotExist(err) {
getMe, err := url2.Parse(fcd.Location)
getMe, err := url2.Parse(downloadLocation)
if err != nil {
Fail(fmt.Sprintf("unable to create url for download: %q", err))
}
now := time.Now()
if err := machine.DownloadVMImage(getMe, suiteImageName, fqImageName+".xz"); err != nil {
if err := machine.DownloadVMImage(getMe, suiteImageName, fqImageName+compressionExtension); err != nil {
Fail(fmt.Sprintf("unable to download machine image: %q", err))
}
GinkgoWriter.Println("Download took: ", time.Since(now).String())
if err := machine.Decompress(fqImageName+".xz", fqImageName); err != nil {
if err := machine.Decompress(fqImageName+compressionExtension, fqImageName); err != nil {
Fail(fmt.Sprintf("unable to decompress image file: %q", err))
}
} else {
Expand Down
Loading

0 comments on commit 04b8576

Please sign in to comment.