Merge pull request #19972 from baude/hypervenablee2e

Plumbing to run machine tests with hyperv
This commit is contained in:
OpenShift Merge Robot
2023-09-15 10:16:45 +02:00
committed by GitHub
21 changed files with 86 additions and 71 deletions

View File

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

View File

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

View File

@ -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`,
@ -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 {

View File

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

View File

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

View File

@ -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"
@ -39,6 +40,9 @@ var (
RunE: validate.SubCommandExists,
}
)
var (
provider machine.VirtProvider
)
func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
@ -46,6 +50,15 @@ func init() {
})
}
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 {
@ -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
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

19
pkg/machine/e2e/README.md Normal file
View File

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

View File

@ -0,0 +1,3 @@
package e2e_test
const podmanBinary = "../../../bin/podman-remote"

View File

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

View File

@ -0,0 +1,3 @@
package e2e_test
const podmanBinary = "../../../bin/windows/podman.exe"

View File

@ -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"
)
@ -26,7 +26,7 @@ const (
)
var (
tmpDir = "/var/tmp"
tmpDir = os.TempDir()
fqImageName string
suiteImageName string
)
@ -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 testProvider")
}
downloadLocation := os.Getenv("MACHINE_IMAGE")
dd, err := testProvider.NewDownload("")
if err != nil {
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")
}
suiteImageName = strings.TrimSuffix(path.Base(fcd.Location), ".xz")
downloadLocation = fcd.Location
}
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 {

View File

@ -1,6 +1,6 @@
//go:build (amd64 && !windows && amd64 && !darwin) || (arm64 && !windows && arm64 && !darwin) || (amd64 && darwin)
package machine
package provider
import (
"fmt"
@ -12,7 +12,7 @@ import (
"github.com/sirupsen/logrus"
)
func GetSystemProvider() (machine.VirtProvider, error) {
func Get() (machine.VirtProvider, error) {
cfg, err := config.Default()
if err != nil {
return nil, err

View File

@ -1,6 +1,6 @@
//go:build darwin && arm64
package machine
package provider
import (
"fmt"
@ -13,7 +13,7 @@ import (
"github.com/sirupsen/logrus"
)
func GetSystemProvider() (machine.VirtProvider, error) {
func Get() (machine.VirtProvider, error) {
cfg, err := config.Default()
if err != nil {
return nil, err

View File

@ -1,4 +1,4 @@
package machine
package provider
import (
"fmt"
@ -11,7 +11,7 @@ import (
"github.com/sirupsen/logrus"
)
func GetSystemProvider() (machine.VirtProvider, error) {
func Get() (machine.VirtProvider, error) {
cfg, err := config.Default()
if err != nil {
return nil, err