util

package
v0.0.0-...-09d837b Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LifecycleActionNone does nothing
	LifecycleActionNone = 0
	// LifecycleActionCreate creates a container
	LifecycleActionCreate = 1 << iota
	// LifecycleActionStart starts a container
	LifecycleActionStart
	// LifecycleActionDelete deletes a container
	LifecycleActionDelete
)
View Source
const (
	// LifecycleStatusCreating "creating"
	LifecycleStatusCreating = 1 << iota
	// LifecycleStatusCreated "created"
	LifecycleStatusCreated
	// LifecycleStatusRunning "running"
	LifecycleStatusRunning
	// LifecycleStatusStopped "stopped"
	LifecycleStatusStopped
)
View Source
const (
	// CPUCgroupPrefix is default path prefix where CPU cgroups are created
	CPUCgroupPrefix string = "/sys/fs/cgroup/cpu,cpuacct"
)
View Source
const DefaultSignal = "TERM"

DefaultSignal represents the default signal sends to a container

Variables

View Source
var ProcNamespaces = []string{
	"cgroup",
	"ipc",
	"mnt",
	"net",
	"pid",
	"user",
	"uts",
}

ProcNamespaces defines a list of namespaces to be found under /proc/*/ns/. NOTE: it is not the same as generate.Namespaces, because of naming mismatches like "mnt" vs "mount" or "net" vs "network".

View Source
var (
	// RuntimeCommand is the default runtime command.
	RuntimeCommand = "runc"
)

Functions

func Fatal

func Fatal(err error)

Fatal prints a warning to stderr and exits.

func GetDefaultGenerator

func GetDefaultGenerator() (*generate.Generator, error)

GetDefaultGenerator creates a default configuration generator.

func GetRuntimeToolsNamespace

func GetRuntimeToolsNamespace(ns string) string

GetRuntimeToolsNamespace converts a namespace type string for /proc into a string for runtime-tools. It deals with exceptional cases of "net" and "mnt", because those strings cannot be recognized by mapStrToNamespace(), which actually expects "network" and "mount" respectively.

func PrepareBundle

func PrepareBundle() (string, error)

PrepareBundle creates a test bundle in a temporary directory.

func RuntimeInsideValidate

func RuntimeInsideValidate(g *generate.Generator, t *tap.T, f PreFunc) (err error)

RuntimeInsideValidate runs runtimetest inside a container.

func RuntimeLifecycleValidate

func RuntimeLifecycleValidate(config LifecycleConfig) error

RuntimeLifecycleValidate validates runtime lifecycle.

func RuntimeOutsideValidate

func RuntimeOutsideValidate(g *generate.Generator, t *tap.T, f AfterFunc) error

RuntimeOutsideValidate validate runtime outside a container.

func Skip

func Skip(message string, diagnostic interface{})

Skip skips a full TAP suite.

func SpecErrorOK

func SpecErrorOK(t *tap.T, expected bool, specErr error, detailedErr error)

SpecErrorOK generates TAP output indicating whether a spec code test passed or failed.

func ValidateLinuxResourcesBlockIO

func ValidateLinuxResourcesBlockIO(config *rspec.Spec, t *tap.T, state *rspec.State) error

ValidateLinuxResourcesBlockIO validates linux.resources.blockIO.

func ValidateLinuxResourcesCPU

func ValidateLinuxResourcesCPU(config *rspec.Spec, t *tap.T, state *rspec.State) error

ValidateLinuxResourcesCPU validates if Linux.Resources.CPU is set to correct values, the same as given values in the config.

func ValidateLinuxResourcesCPUEmpty

func ValidateLinuxResourcesCPUEmpty(config *rspec.Spec, t *tap.T, state *rspec.State) error

ValidateLinuxResourcesCPUEmpty validates Linux.Resources.CPU is set to correct values, when each value are set to the default ones.

func ValidateLinuxResourcesDevices

func ValidateLinuxResourcesDevices(config *rspec.Spec, t *tap.T, state *rspec.State) error

ValidateLinuxResourcesDevices validates linux.resources.devices.

func ValidateLinuxResourcesMemory

func ValidateLinuxResourcesMemory(config *rspec.Spec, t *tap.T, state *rspec.State) error

ValidateLinuxResourcesMemory validates linux.resources.memory.

func ValidateLinuxResourcesNetwork

func ValidateLinuxResourcesNetwork(config *rspec.Spec, t *tap.T, state *rspec.State) error

ValidateLinuxResourcesNetwork validates linux.resources.network.

func ValidateLinuxResourcesPids

func ValidateLinuxResourcesPids(config *rspec.Spec, t *tap.T, state *rspec.State) error

ValidateLinuxResourcesPids validates linux.resources.pids.

func WaitingForStatus

func WaitingForStatus(r Runtime, status LifecycleStatus, retryTimeout time.Duration, pollInterval time.Duration) error

WaitingForStatus waits an expected runtime status, return error if 1. fail to query the status 2. timeout

Types

type AfterFunc

type AfterFunc func(config *rspec.Spec, t *tap.T, state *rspec.State) error

AfterFunc validate container's outside environment after created

type LifecycleAction

type LifecycleAction int

LifecycleAction defines the phases will be called.

type LifecycleConfig

type LifecycleConfig struct {
	Config     *generate.Generator
	BundleDir  string
	Actions    LifecycleAction
	PreCreate  func(runtime *Runtime) error
	PostCreate func(runtime *Runtime) error
	PreDelete  func(runtime *Runtime) error
	PostDelete func(runtime *Runtime) error
}

LifecycleConfig includes 1. Config to set the 'config.json' 2. BundleDir to set the bundle directory 3. Actions to define the default running lifecycles 4. Four phases for user to add his/her own operations

type PreFunc

type PreFunc func(string) error

PreFunc initializes the test environment after preparing the bundle but before creating the container.

type Runtime

type Runtime struct {
	RuntimeCommand string
	BundleDir      string
	PidFile        string
	ID             string
	// contains filtered or unexported fields
}

Runtime represents the basic requirement of a container runtime

func NewRuntime

func NewRuntime(runtimeCommand string, bundleDir string) (Runtime, error)

NewRuntime create a runtime by command and the bundle directory

func (*Runtime) Clean

func (r *Runtime) Clean(removeBundle bool, forceRemoveBundle bool) error

Clean deletes the container. If removeBundle is set, the bundle directory is removed after the container is deleted successfully or, if forceRemoveBundle is true, after the deletion attempt regardless of whether it was successful or not.

func (*Runtime) Create

func (r *Runtime) Create() (err error)

Create a container

func (*Runtime) Delete

func (r *Runtime) Delete() (err error)

Delete a container

func (*Runtime) Kill

func (r *Runtime) Kill(sig string) (err error)

Kill a container

func (*Runtime) ReadStandardStreams

func (r *Runtime) ReadStandardStreams() (stdout []byte, stderr []byte, err error)

ReadStandardStreams collects content from the stdout and stderr buffers.

func (*Runtime) SetConfig

func (r *Runtime) SetConfig(g *generate.Generator) error

SetConfig creates a 'config.json' by the generator

func (*Runtime) SetID

func (r *Runtime) SetID(id string)

SetID sets the container ID

func (*Runtime) Start

func (r *Runtime) Start() (err error)

Start a container

func (*Runtime) State

func (r *Runtime) State() (rspecs.State, error)

State a container information

Jump to

Keyboard shortcuts

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