internal

package
v0.0.0-...-6b2d232 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StdinPort represents vsock port to be used for stdin
	StdinPort = 11000
	// StdoutPort represents vsock port to be used for stdout
	StdoutPort = 11001
	// StderrPort represents vsock port to be used for stderr
	StderrPort = 11002
	// DefaultBufferSize represents buffer size in bytes to used for IO between runtime and agent
	DefaultBufferSize = 1024

	// FirecrackerSockName is the name of the Firecracker VMM API socket
	FirecrackerSockName = "firecracker.sock"
	// FirecrackerVSockName is the name of the Firecracker VSock unix path used for communication
	// between the runtime and the agent
	FirecrackerVSockName = "firecracker.vsock"
	// FirecrackerLogFifoName is the name of the Firecracker VMM log FIFO
	FirecrackerLogFifoName = "fc-logs.fifo"
	// FirecrackerMetricsFifoName is the name of the Firecracker VMM metrics FIFO
	FirecrackerMetricsFifoName = "fc-metrics.fifo"

	// ShimAddrFileName is the name of the file in which a shim's API address can be found, used by
	// containerd to reconnect after it restarts
	ShimAddrFileName = "address"

	// ShimLogFifoName is the name of the FIFO created by containerd for a shim to write its logs to
	ShimLogFifoName = "log"

	// OCIConfigName is the name of the OCI bundle's config field
	OCIConfigName = "config.json"

	// BundleRootfsName is the name of the bundle's directory for holding the container's rootfs
	BundleRootfsName = "rootfs"

	// VMIDEnvVarKey is the environment variable key used to provide a VMID to a shim process
	VMIDEnvVarKey = "FIRECRACKER_VM_ID"

	// FCSocketFDEnvKey is the environment variable key used to provide the FD of the fccontrol listening socket to a shim
	FCSocketFDEnvKey = "FCCONTROL_SOCKET_FD"

	// ShimBinaryName is the name of the runtime shim binary
	ShimBinaryName = "containerd-shim-aws-firecracker"
)

Variables

View Source
var MagicStubBytes = []byte{214, 244, 216, 245, 215, 177, 177, 177}

MagicStubBytes used to determine whether or not a drive is a stub drive

Functions

func AverageCPUDeltas

func AverageCPUDeltas(ctx context.Context, sampleInterval time.Duration) (*cpu.TimesStat, error)

AverageCPUDeltas returns the average CPU cycles consumed per sampleInterval, as calculated between the time this function is invoked and the time the provided ctx is cancelled.

func CreateBlockDevice

func CreateBlockDevice(ctx context.Context, t testing.TB) (string, func())

CreateBlockDevice creates a block device, or block special file for testing

func CreateFSImg

func CreateFSImg(ctx context.Context, t *testing.T, fsType string, testFiles ...FSImgFile) string

CreateFSImg will create a file containing a filesystem image of the provided type containing the provided files. It returns the path at which the image file can be found.

func GenerateStubContent

func GenerateStubContent(id string) (string, error)

GenerateStubContent will generate stub content using the magic stub bytes and a length encoded string

func IsStubDrive

func IsStubDrive(r io.Reader) bool

IsStubDrive will check to see if the io.Reader follows our stub drive format. In the event of an error, this will return false. This will only return true when the first n bytes read matches that of the magic stub bytes and where n is the length of magic bytes.

func ParseStubContent

func ParseStubContent(r io.Reader) (string, error)

ParseStubContent will parse the contents of an io.Reader and return the given id that was encoded

func RequiresIsolation

func RequiresIsolation(t testing.TB)

RequiresIsolation will ensure that tests that must be run in an isolated environment are being run with the explicit ENABLE_ISOLATED_TESTS env var. If the env var has not been set, the test will be skipped

func RequiresRoot

func RequiresRoot(t testing.TB)

RequiresRoot will ensure that tests that require root access are actually root. In addition, this will skip root tests if the DISABLE_ROOT_TESTS is set to true

func SupportCPUTemplate

func SupportCPUTemplate() (bool, error)

SupportCPUTemplate returns true if Firecracker supports CPU templates on the current architecture.

func WaitForPidToExit

func WaitForPidToExit(ctx context.Context, queryInterval time.Duration, pid int32) error

WaitForPidToExit queries running processes every `queryInterval` duration, blocking until the provided pid is found to not exist or the context is canceled.

func WaitForProcessToExist

func WaitForProcessToExist(
	ctx context.Context,
	queryInterval time.Duration,
	matcher func(context.Context, *process.Process) (bool, error),
) ([]*process.Process, error)

WaitForProcessToExist queries running processes every `queryInterval` duration, blocking until the provided matcher function returns true for at least one running process or the context is canceled. If a query returns multiple matching processes, all will be returned.

Types

type FSImgFile

type FSImgFile struct {
	Subpath  string
	Contents string
}

FSImgFile represents a file intended to be place in a filesystem image (at the provided subpath with the provided contents)

type LocalNetworkServices

type LocalNetworkServices interface {
	// DNSServerIP returns the IP address of the DNS server
	// (useful for seting resolv.conf)
	DNSServerIP() string

	// URL returns the full URL to use when querying the provided
	// subpath. i.e. if subpath is "foo/bar", this will return
	// something like "http://phony.domain.test/foo/bar"
	URL(subpath string) string

	// Serve will start the DNS and HTTP servers, blocking until
	// either of them shuts down.
	Serve(ctx context.Context) error
}

LocalNetworkServices provides a way of running bare-bones DNS and HTTP servers bound to the ip of a created device, which enables testing VM networking without relying on an external network.

func NewLocalNetworkServices

func NewLocalNetworkServices(t *testing.T, webpages map[string]string) (LocalNetworkServices, error)

NewLocalNetworkServices returns an implementation of LocalNetworkServices where the DNS server will bind to the ip of a created device and serve a single mapping from "domain" to that ip. The HTTP server will serve a pages at paths defined in the keys of "webpages", with the content set in the values of that map.

type MountInfo

type MountInfo struct {
	SourcePath string
	DestPath   string
	Type       string
	Options    []string
}

MountInfo holds data parsed from a line of /proc/mounts

func ParseProcMountLines

func ParseProcMountLines(lines ...string) ([]MountInfo, error)

ParseProcMountLines converts the provided strings, presumed to be lines read from /proc/mounts into MountInfo objects holding the parsed data about each mount.

Directories

Path Synopsis
Package bundle implements some helper functions for firecracker-containerd's interaction with bundle dirs, both inside the VM and outside on the host.
Package bundle implements some helper functions for firecracker-containerd's interaction with bundle dirs, both inside the VM and outside on the host.
cmd
test-bridged-tap
This is a bare-bones CNI plugin (with only ADD actually implemented, other methods are no-ops) used to setup a network bridge w/ tap in order to compare performance of a bridge-based VM network w/ a TC-based approach, such as that created by the tc-redirect-tap plugin.
This is a bare-bones CNI plugin (with only ADD actually implemented, other methods are no-ops) used to setup a network bridge w/ tap in order to compare performance of a bridge-based VM network w/ a TC-based approach, such as that created by the tc-redirect-tap plugin.

Jump to

Keyboard shortcuts

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