Documentation ¶
Overview ¶
Package qemu adds support for the TEST_QEMU_IMAGE env variable to test binaries and manages the virtual machine instance(s) for tests. If TEST_QEMU_IMAGE is a symlink to a file of the format <base name>.0.img, then all other images with the same base name will also be started. SPDK is only set up for the first node.
Index ¶
- func Finalize() error
- func Init(options ...Option) error
- func KubeConfig() (string, error)
- func SimpleInit() error
- type Option
- type StartError
- type VirtualMachine
- func (vm *VirtualMachine) ForwardPort(logger log.Logger, from interface{}, to interface{}, cmd ...string) (io.Closer, <-chan interface{}, error)
- func (vm *VirtualMachine) Install(path string, data io.Reader, mode os.FileMode) error
- func (vm *VirtualMachine) Running() bool
- func (vm *VirtualMachine) SSH(args ...string) (string, error)
- func (vm *VirtualMachine) StopQEMU() error
- func (vm *VirtualMachine) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Finalize ¶
func Finalize() error
Finalize frees any resources allocated by Init. Safe to call without Init or after Init failure.
func Init ¶
Init creates the virtual machine, if possible with VHost SCSI controller. Must be matched by a Finalize call, even after a failure.
func KubeConfig ¶
KubeConfig returns the full path for the Kubernetes cluster.
func SimpleInit ¶
func SimpleInit() error
SimpleInit is meant to be used in a parallel Ginkgo test suite where some other node called Init. SimpleInit then sets up VM so that running SSH commands work. Finalize must not be called.
Types ¶
type Option ¶
type Option func(*opts)
Option is the parameter type accepted By New.
func WithKubernetes ¶
func WithKubernetes() Option
WithKubernetes enables the starting of Kubernetes inside the VM.
type StartError ¶
type StartError struct { // Args has the QEMU parameters. Args []string // Stderr is the combined stdout/stderr. Stderr string // ProcessState has the exit status. ProcessState *os.ProcessState // ExitError is the result of the Wait call for the process. ExitError error // OtherError is an error that occcured while starting the process. OtherError error }
StartError is the error returned when starting the VM fails.
type VirtualMachine ¶
type VirtualMachine struct {
// contains filtered or unexported fields
}
VirtualMachine handles interaction with a QEMU virtual machine.
var ( // VM is the master virtual machine instance used for testing. VM *VirtualMachine )
func StartQEMU ¶
func StartQEMU(image string, qemuOptions ...string) (*VirtualMachine, error)
StartQEMU returns a VM pointer if a virtual machine could be started, and error when starting failed, and nil for both when no image is configured and thus nothing can be started.
func UseQEMU ¶
func UseQEMU(image string) (*VirtualMachine, error)
UseQEMU sets up a VM instance so that SSH commands can be issued. The machine must be started separately.
func (*VirtualMachine) ForwardPort ¶
func (vm *VirtualMachine) ForwardPort(logger log.Logger, from interface{}, to interface{}, cmd ...string) (io.Closer, <-chan interface{}, error)
ForwardPort activates port forwarding from a listen socket on the current host to another port inside the virtual machine. Errors can occur while setting up forwarding as well as later, in which case the returned channel will be closed. To stop port forwarding, call the io.Closer.
The to and from specification can be ints (for ports) or strings (for Unix domaain sockets).
Optionally a command can be run. If none is given, ssh is invoked with -N.
func (*VirtualMachine) Install ¶
Install transfers the content to the virtual machine and creates the file with the chosen mode.
func (*VirtualMachine) Running ¶
func (vm *VirtualMachine) Running() bool
Running returns true if the virtual machine instance is currently active.
func (*VirtualMachine) SSH ¶
func (vm *VirtualMachine) SSH(args ...string) (string, error)
SSH executes a shell command inside the virtual machine via ssh, using the helper script of the machine image. It returns the commands combined output and any exit error. Beware that (as usual) ssh will cocatenate the arguments and run the result in a shell, so complex scripts may break.
func (*VirtualMachine) StopQEMU ¶
func (vm *VirtualMachine) StopQEMU() error
StopQEMU ensures that the virtual machine powers down cleanly and all resources are freed. Can be called more than once.
func (*VirtualMachine) String ¶
func (vm *VirtualMachine) String() string