vm

package
v0.0.0-...-b79a0d8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2022 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package vm contains utility functions used in integ tests with qemu VMs.

Index

Constants

This section is empty.

Variables

View Source
var LogAddrFmt string = "10.0.2.2:%d"

default remotelog addr format, for pblog

Functions

func AddDevs

func AddDevs(devs ...qemu.Device) func(o *qemu.Options) error

func CheckForbidden

func CheckForbidden(t gtst.TB, lsrv rlog.MockSrvr, uefi bool, strs []string)

func CheckFormattingErrs

func CheckFormattingErrs(t gtst.TB, lsrv rlog.MockSrvr, uefi bool)

Look for indications of extra or wrong formatting verbs or args to printf and friends

%!d(string=there) %!(EXTRA <nil>) %!s(MISSING) etc

func CopyOutput

func CopyOutput(t *testing.T) (*bytes.Buffer, io.WriteCloser)

Returns a buffer and a WriteCloser. Data written to wc is written to t and copied to buf. Must use testing.T because TestLineWriter requires that.

func CreateQcow

func CreateQcow(path string, siz uint64) error

Create qcow-formatted file at path, with given size in bytes.

func DisableLDD

func DisableLDD(u *uroot.Opts) error

func Find9p

func Find9p(t gtst.TB, tmpdir, glob string) []byte

returns content of a file written by an integ test via 9p typically used in call(s) to RequireTxt9p()

func MultiNet

func MultiNet(opts *vmtest.Options, n int)

Adds N adapters, all on a new vm-only network. Only useful if you need multiple NICs to show up - not able to communicate with the outside world.

func NopCloserW

func NopCloserW(w io.Writer) io.WriteCloser

func Ram

func Ram(i int) qemu.Device

func Ram5120

func Ram5120(o *qemu.Options) error

func Rawpath

func Rawpath(tmpdir string, uefi bool) string

func RequireRE

func RequireRE(t gtst.TB, vm *qemu.VM, reLines ...string)

wait for vm to produce lines matching given regular expressions

func RequireTxt

func RequireTxt(t gtst.TB, vm *qemu.VM, lines ...string)

wait for vm to produce lines matching given lines of plaintext

func RequireTxt9p

func RequireTxt9p(t gtst.TB, p9log []byte, items ...string)

look for items in a []byte, typically file content found by Find9p

func SerNum

func SerNum(uefi bool) string

func Wait

func Wait(t gtst.TB, vm *qemu.VM, dly time.Duration)

waits for vm to exit or for the given time to elapse

Types

type ArbitraryKArgs

type ArbitraryKArgs []string

func (ArbitraryKArgs) Cmdline

func (a ArbitraryKArgs) Cmdline() []string

func (ArbitraryKArgs) KArgs

func (a ArbitraryKArgs) KArgs() []string

type Attachment

type Attachment int
const (
	UnknownAttach Attachment = iota
	UsbAttach                //usb2
	UsbXhciAttach            //usb3. shows as usb device (necessary for recovery), but faster.
	IdeAttach                //called 'ide-hd' but looks like sata in vm

)

type BlockDev

type BlockDev struct {
	// attachment method - usb, usb3, ide, ...
	Attachment Attachment

	// size _in bytes_
	Size uint64

	// number of drives, must be > 0
	Count int

	// optional model. known to work with ide.
	Model string

	// filename prefix, to which an (optional) index and extn are added
	// index is only used when Count > 1 and dev # > 1
	// e.g. /abs/path/to/block.qcow, /abs/path/to/block2.qcow, /abs/path/to/block3.qcow, ...
	//
	// if empty, prefix is generated, MustExist must be false.
	//
	// if value is "null", indicates qemu should use the null-copy back end
	// which reports the desired size, but reads as zeros and discards writes.
	FilePfx string

	// if true, file(s) must already exist. if false, will use found files or create new.
	MustExist bool

	// Used for file location if FilePfx is empty; a dir is created if this is empty
	TmpDir string

	// If non-zero, appended to the device to influence boot order.
	// Implies no '-kernel'. used for recovery.
	BootIndex uint64

	// Arbitrary string that can be used to identify devices in code later on.
	// Not passed to qemu.
	Id string
}

func (*BlockDev) Cmdline

func (bd *BlockDev) Cmdline() []string

func (*BlockDev) KArgs

func (bd *BlockDev) KArgs() []string

func (*BlockDev) UniqueId

func (bd *BlockDev) UniqueId() string

Derives a unique sequence from the bd pointer's value. Something unique is needed to differentiate between devices, and this suffices. Encoded to increase the effective bits-per-byte. Must be safe for use as a file name or qemu device id, so we encode Base32 rather than Base64 etc.

type Bmc

type Bmc struct{}

func (Bmc) Cmdline

func (b Bmc) Cmdline() []string

func (Bmc) KArgs

func (b Bmc) KArgs() []string

type Mockinfra

type Mockinfra struct {
	LSrvr rlog.MockSrvr

	MfgUrl         string
	BootKernelPath string

	TmplData TmplData
	// contains filtered or unexported fields
}

data used to populate manufData json and to serve other files used by mfg

func MockInfra

func MockInfra(tb gtst.TB, tmpDir, krnl string, createUpd bool, updPath, sn string, mem, cpus int) *Mockinfra

Set up log server and webserver, and create fake update. Returns struct for mfg json url, log port, cleanup func, etc

func (*Mockinfra) Cleanup

func (mi *Mockinfra) Cleanup()

func (*Mockinfra) LogUrl

func (mi *Mockinfra) LogUrl() string

func (*Mockinfra) ServeHTTP

func (m *Mockinfra) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Mockinfra) Setup

func (m *Mockinfra) Setup()

type NoReboot

type NoReboot struct{}

func (NoReboot) Cmdline

func (NoReboot) Cmdline() []string

func (NoReboot) KArgs

func (NoReboot) KArgs() []string

type OUINic

type OUINic struct {
	// contains filtered or unexported fields
}

func (OUINic) Cmdline

func (i OUINic) Cmdline() []string

func (OUINic) KArgs

func (i OUINic) KArgs() []string

type SmBios

type SmBios struct {
	Raw string
}

func SmBios1

func SmBios1(uefi bool) *SmBios

func SmBios1p9

func SmBios1p9(uefi bool) *SmBios

func (SmBios) Cmdline

func (sb SmBios) Cmdline() []string

func (SmBios) KArgs

func (sb SmBios) KArgs() []string

type TmplData

type TmplData struct {
	Mem, CPUs              int
	FPort                  int
	CredEP                 string
	LAddr                  string
	KName, StashName       string
	CmdSum                 string
	StashSum, UpdSum, KSum string
	UpdName                string
}

data that is available to template

type UefiFw

type UefiFw struct {
	Code, Vars string
}

func UefiFwSetup

func UefiFwSetup(tb gtst.TB, tmpdir string) *UefiFw

func (UefiFw) Cmdline

func (u UefiFw) Cmdline() []string

func (UefiFw) KArgs

func (u UefiFw) KArgs() []string

type UsbPassthrough

type UsbPassthrough struct {
	Hostbus, Hostport string
}

func (*UsbPassthrough) Cmdline

func (up *UsbPassthrough) Cmdline() []string

func (*UsbPassthrough) KArgs

func (up *UsbPassthrough) KArgs() []string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL