Documentation
¶
Index ¶
- Constants
- func ArchitectureAlias(t ContainerDebianVersion) string
- func Artifact() testing.Precondition
- func ArtifactData() string
- func CreateVSHCommand(ctx context.Context, cid int, command string, args ...string) *testexec.Cmd
- func DefaultContainerCommand(ctx context.Context, ownerID string, vshArgs ...string) *testexec.Cmd
- func DeleteImages() error
- func DownloadStagingTermina(ctx context.Context) (string, error)
- func EnableCrostini(ctx context.Context, tconn *chrome.TestConn) error
- func ExtractTermina(ctx context.Context, artifactPath string) (string, error)
- func GetEncodedName(name string) string
- func Lock()
- func MountComponent(ctx context.Context, image string) error
- func RestartDefaultVMContainer(ctx context.Context, dir string, container *Container) error
- func ShrinkDefaultContainer(ctx context.Context, ownerID string) error
- func StopConcierge(ctx context.Context) error
- func TargetArch() string
- func TerminaImageExists() bool
- func Unlock()
- func UnmountComponent(ctx context.Context) error
- type ComponentType
- type Concierge
- type Container
- func (c *Container) CheckFileContent(ctx context.Context, filePath, testString string) error
- func (c *Container) CheckFileDoesNotExistInDir(ctx context.Context, path string, files ...string) error
- func (c *Container) CheckFilesExistInDir(ctx context.Context, path string, files ...string) error
- func (c *Container) Cleanup(ctx context.Context, path string) error
- func (c *Container) Command(ctx context.Context, vshArgs ...string) *testexec.Cmd
- func (c *Container) Connect(ctx context.Context, user string) error
- func (c *Container) Create(ctx context.Context, t ContainerType) error
- func (c *Container) GetFile(ctx context.Context, containerPath, localPath string) error
- func (c *Container) GetFileList(ctx context.Context, path string) (fileList []string, err error)
- func (c *Container) GetIPv4Address(ctx context.Context) (ip string, err error)
- func (c *Container) GetUsername(ctx context.Context) (string, error)
- func (c *Container) InstallPackage(ctx context.Context, path string) error
- func (c *Container) LinuxPackageInfo(ctx context.Context, path string) (packageID string, err error)
- func (c *Container) PushFile(ctx context.Context, localPath, containerPath string) error
- func (c *Container) ReadFile(ctx context.Context, filePath string) (content string, err error)
- func (c *Container) RemoveAll(ctx context.Context, path string) error
- func (c *Container) SetUpUser(ctx context.Context) error
- func (c *Container) StartAndWait(ctx context.Context, dir string) error
- func (c *Container) UninstallPackageOwningFile(ctx context.Context, desktopFileID string) error
- func (c *Container) WriteFile(ctx context.Context, filePath, fileContent string) error
- type ContainerArch
- type ContainerCreationWatcher
- type ContainerDebianVersion
- type ContainerImageType
- type ContainerType
- type Crosvm
- type CrosvmParams
- type LogReader
- type Option
- func DisableSandbox() Option
- func Disks(paths ...string) Option
- func KernelArgs(args ...string) Option
- func RWDisks(paths ...string) Option
- func Rootfs(path string) Option
- func SerialOutput(file string) Option
- func SharedDir(src, tag, fsType, cache string) Option
- func Socket(path string) Option
- func VhostUserNet(socket string) Option
- type PreData
- type StartupListenerServer
- type VM
- func (vm *VM) Command(ctx context.Context, vshArgs ...string) *testexec.Cmd
- func (vm *VM) LXCCommand(ctx context.Context, lxcArgs ...string) error
- func (vm *VM) Name() string
- func (vm *VM) ShareDownloadsPath(ctx context.Context, path string, writable bool) (string, error)
- func (vm *VM) Start(ctx context.Context) error
- func (vm *VM) StartLxd(ctx context.Context) error
- func (vm *VM) Stop(ctx context.Context) error
- func (vm *VM) UnshareDownloadsPath(ctx context.Context, path string) error
Constants ¶
const ( // TerminaComponentName is the name of the Chrome component for the VM kernel and rootfs. TerminaComponentName = "cros-termina" // TerminaMountDir is a path to the location where we will mount the termina component. TerminaMountDir = "/run/imageloader/cros-termina/99999.0.0" // ImageServerURLComponentName is the name of the Chrome component for the image server URL. ImageServerURLComponentName = "cros-crostini-image-server-url" )
const ( // DefaultVMName is the default crostini VM name. DefaultVMName = "termina" // DefaultContainerName is the default crostini container name. DefaultContainerName = "penguin" // DefaultDiskSize is the default disk size for VM. 2.5 GB by default. DefaultDiskSize = 5 * 512 * 1024 * 1024 // 2.5 GiB default disk size )
const (
TerminaImage = "/usr/local/cros-termina/image.ext4"
)
The directory where images will be downloaded/extracted to.
Variables ¶
This section is empty.
Functions ¶
func ArchitectureAlias ¶
func ArchitectureAlias(t ContainerDebianVersion) string
ArchitectureAlias returns the alias subpath of the chosen container architecture, i.e. part of the path used to compute the container's gsutil URL.
func Artifact ¶
func Artifact() testing.Precondition
Artifact returns a precondition that Crostini's artifact such as the guest kernel is available before the test runs.
When adding a test with this precondition, the return value of ArtifactData() must be included in Data:
testing.AddTest(&testing.Test{ ... Data: []string{vm.ArtifactData()}, Pre: vm.Artifact(), })
Later, in the main test function, the VM artifacts are available via PreData.
func ArtifactData ¶
func ArtifactData() string
ArtifactData returns the name of the data file that must be specified for tests using the Artifact() precondition.
func CreateVSHCommand ¶
CreateVSHCommand creates a command to be run in a VM over vsh. The command parameter is required followed by an optional variatic list of strings as args. The command object is returned.
func DefaultContainerCommand ¶
DefaultContainerCommand returns a testexec.Cmd with a vsh command that will run in the default termina/penguin container.
func DeleteImages ¶
func DeleteImages() error
DeleteImages deletes all images downloaded or extracted for the test by the other functions in this file.
func DownloadStagingTermina ¶
DownloadStagingTermina downloads the current staging termina image from Google Storage.
func EnableCrostini ¶
EnableCrostini sets the preference for Crostini being enabled as this is required for some of the Chrome integration tests to function properly.
func ExtractTermina ¶
ExtractTermina extracts the termina images from the artifact tarball.
func GetEncodedName ¶
GetEncodedName returns the encoded version of the user-chosen name which concierge uses to identify several pieces of the VM (its stateful image, log files, and ssh keys).
func Lock ¶
func Lock()
Lock prevents container creation/destruction until Unlock is called. It can only be called by preconditions and is idempotent.
func MountComponent ¶
MountComponent mounts a component image from the provided image path.
func RestartDefaultVMContainer ¶
RestartDefaultVMContainer restarts a VM and container that were previously shut down.
func ShrinkDefaultContainer ¶
ShrinkDefaultContainer deletes a lot of large files in the container to make the image size smaller. This makes a big speed difference on slow devices for backup and restore.
func StopConcierge ¶
StopConcierge stops the vm_concierge service, which stops all running VMs.
func TargetArch ¶
func TargetArch() string
TargetArch returns the name of the VM architecture that should be used
func TerminaImageExists ¶
func TerminaImageExists() bool
TerminaImageExists returns true if TerminaImage file exists and is readable.
func Unlock ¶
func Unlock()
Unlock allows container creation after an earlier call to Lock. It can only be called by preconditions and is idempotent.
func UnmountComponent ¶
UnmountComponent unmounts any active VM component.
Types ¶
type ComponentType ¶
type ComponentType int
ComponentType represents the VM component type.
const ( // ComponentUpdater indicates that the live component should be fetched from the component updater service. ComponentUpdater ComponentType = iota // StagingComponent indicates that the current staging component should be fetched from the GS component testing bucket. StagingComponent )
type Concierge ¶
type Concierge struct {
// contains filtered or unexported fields
}
Concierge interacts with the vm_concierge daemon, which starts, stops, and monitors VMs. It also interacts with the cicerone daemon, which interacts with containers inside those VMs.
func GetRunningConcierge ¶
GetRunningConcierge returns a concierge instance without restarting concierge service. Returns an error if concierge is not available.
func NewConcierge ¶
NewConcierge restarts the vm_concierge service, which stops all running VMs.
func (*Concierge) GetOwnerID ¶
GetOwnerID returns the cryptohome hash for the logged-in user.
func (*Concierge) GetVMDiskInfo ¶
GetVMDiskInfo returns a VmDiskInfo proto for the given VM via ListVmDisks
type Container ¶
type Container struct { // VM is the VM in which this container is running. VM *VM // contains filtered or unexported fields }
Container encapsulates a container running in a VM.
func DefaultContainer ¶
DefaultContainer returns a container object with default settings.
func GetRunningContainer ¶
GetRunningContainer returns a Container struct for a currently running container. This is useful when the container was started by some other means, eg the installer. Will return an error if no container is currently running.
func (*Container) CheckFileContent ¶
CheckFileContent checks that the content of the specified file equals to the given string. Returns error if fail to read content or the contest does not equal to the given string.
func (*Container) CheckFileDoesNotExistInDir ¶
func (c *Container) CheckFileDoesNotExistInDir(ctx context.Context, path string, files ...string) error
CheckFileDoesNotExistInDir checks files do not exist in the given path in container. Return error if any file exists or any other error.
func (*Container) CheckFilesExistInDir ¶
CheckFilesExistInDir checks files exist in the given path in container. Returns error if any file does not exist or any other error.
func (*Container) Command ¶
Command returns a testexec.Cmd with a vsh command that will run in this container.
func (*Container) Connect ¶
Connect connects the container to the running VM and cicerone instances.
func (*Container) Create ¶
func (c *Container) Create(ctx context.Context, t ContainerType) error
Create will create a Linux container in an existing VM. It returns without waiting for the creation to complete. One must listen on cicerone D-Bus signals to know the creation is done.
func (*Container) GetFileList ¶
GetFileList returns a list of the files in the given path in the container.
func (*Container) GetIPv4Address ¶
GetIPv4Address returns the IPv4 address of the container.
func (*Container) GetUsername ¶
GetUsername returns the default user in a container.
func (*Container) InstallPackage ¶
InstallPackage installs a Linux package file into the container.
func (*Container) LinuxPackageInfo ¶
func (c *Container) LinuxPackageInfo(ctx context.Context, path string) (packageID string, err error)
LinuxPackageInfo queries the container for information about a Linux package file. The packageID returned corresponds to the package ID for an installed package based on the PackageKit specification which is of the form 'package_id;version;arch;repository'.
func (*Container) ReadFile ¶
ReadFile reads the content of file using command cat and returns it as a string.
func (*Container) RemoveAll ¶
RemoveAll removes a path from the container's file system using 'rm -rf'.
func (*Container) StartAndWait ¶
StartAndWait starts up an already created container and waits for that startup to complete before returning. The directory dir may be used to store logs on failure.
func (*Container) UninstallPackageOwningFile ¶
UninstallPackageOwningFile uninstalls the package owning a particular desktop file in the container.
type ContainerArch ¶
type ContainerArch string
ContainerArch represents the architecture of the container
const ( // Amd64 indicates that the container is built for amd64 Amd64 ContainerArch = "amd64" // Arm indicates that the container is build for arm Arm ContainerArch = "arm" )
type ContainerCreationWatcher ¶
type ContainerCreationWatcher struct {
// contains filtered or unexported fields
}
ContainerCreationWatcher is a wrapper of SignalWatcher to trace container creation progress.
func NewContainerCreationWatcher ¶
func NewContainerCreationWatcher(ctx context.Context, cont *Container) (*ContainerCreationWatcher, error)
NewContainerCreationWatcher returns a ContainerCreationWatcher.
func (*ContainerCreationWatcher) Close ¶
func (c *ContainerCreationWatcher) Close(ctx context.Context)
Close cleans up the SignalWatcher.
func (*ContainerCreationWatcher) WaitForCreationComplete ¶
func (c *ContainerCreationWatcher) WaitForCreationComplete(ctx context.Context) error
WaitForCreationComplete waits for the container to be created.
func (*ContainerCreationWatcher) WaitForDownload ¶
func (c *ContainerCreationWatcher) WaitForDownload(ctx context.Context, pct int32) error
WaitForDownload waits for cicerone to send a container download notification. If pct is negative, this method returns after the next notification is received. Otherwise, it returns only after a notification with percent pct in [0, 100] is received. An error is returned if ctx's deadline is reached.
type ContainerDebianVersion ¶
type ContainerDebianVersion string
ContainerDebianVersion represents the OS version of the container's image.
const ( // DebianBuster refers to the "buster" distribution of debian (a.k.a. debian 10). DebianBuster ContainerDebianVersion = "buster" // DebianBullseye refers to the "bullseye" distribution of debian (a.k.a. debian 11). DebianBullseye ContainerDebianVersion = "bullseye" )
type ContainerImageType ¶
type ContainerImageType int
ContainerImageType represents the mechanism/bucket that we should use to get the container.
const ( // LiveImageServer indicates that the current live container image should be downloaded. LiveImageServer ContainerImageType = iota // StagingImageServer indicates that the current staging container image should be downloaded. StagingImageServer // Tarball indicates that the container image is available as tarball shared over 9P. Tarball )
type ContainerType ¶
type ContainerType struct { // Image is the image source for this container. Image ContainerImageType // DebianVersion is the version of debian that the image has. DebianVersion ContainerDebianVersion }
ContainerType defines the type of container.
type Crosvm ¶
type Crosvm struct {
// contains filtered or unexported fields
}
Crosvm holds info about a running instance of the crosvm command.
func NewCrosvm ¶
func NewCrosvm(ctx context.Context, params *CrosvmParams) (*Crosvm, error)
NewCrosvm starts a crosvm instance with the optional disk path as an additional disk.
func (*Crosvm) Stdin ¶
Stdin is attached to the crosvm process's stdin. It can be used to run commands.
func (*Crosvm) Stdout ¶
Stdout is attached to the crosvm process's stdout. It receives all console output.
func (*Crosvm) WaitForOutput ¶
WaitForOutput waits until a line matched by re has been written to stdout, crosvm's stdout is closed, or the deadline is reached. It returns the full line that was matched. This function will consume output from stdout until it returns.
type CrosvmParams ¶
type CrosvmParams struct {
// contains filtered or unexported fields
}
CrosvmParams - Parameters for starting a crosvm instance.
func NewCrosvmParams ¶
func NewCrosvmParams(kernel string, opts ...Option) *CrosvmParams
NewCrosvmParams constructs a set of crosvm parameters.
func (*CrosvmParams) ToArgs ¶
func (p *CrosvmParams) ToArgs() []string
ToArgs converts CrosvmParams to an array of strings that can be used as crosvm's command line flags.
type LogReader ¶
type LogReader struct {
// contains filtered or unexported fields
}
LogReader keeps a persistent view of the log files created by a VM, and can be used to save them to an output directory for tast.
func NewLogReaderForVM ¶
NewLogReaderForVM creates a new LogReader which can be used to save the daemon-store logs from a running VM.
type Option ¶
type Option func(s *CrosvmParams)
Option configures a CrosvmParams
func DisableSandbox ¶
func DisableSandbox() Option
DisableSandbox disables the sandbox (sandbox is enabled by default without this option)
func KernelArgs ¶
KernelArgs sets extra kernel command line arguments.
func SerialOutput ¶
SerialOutput sets a file that serial log will be written.
func VhostUserNet ¶
VhostUserNet sets a socket to be used by a vhost-user net device.
type PreData ¶
type PreData struct { Kernel string // Path to the guest kernel. Rootfs string // Path to the guest rootfs image. }
The PreData object is made available to users of this precondition via:
func DoSomething(ctx context.Context, s *testing.State) { d := s.PreValue().(vm.PreData) ... }
type StartupListenerServer ¶
type StartupListenerServer struct {
// contains filtered or unexported fields
}
StartupListenerServer is struct to manage an instance of a StartupListener gRPC server. It is designed to listen for a single VmReady call from a VM at the provided CID.
func NewStartupListenerServer ¶
func NewStartupListenerServer(vsockPort uint32) (*StartupListenerServer, error)
NewStartupListenerServer accepts a vsock port to listen on as a parameter, and returns a new StatupListenerServer struct. At this point the server has not been started.
func (*StartupListenerServer) Start ¶
func (s *StartupListenerServer) Start() error
Start creates the vsock port listener and starts the gRPC server in a goroutine.
func (*StartupListenerServer) Stop ¶
func (s *StartupListenerServer) Stop()
Stop will stop the gRPC server.
func (*StartupListenerServer) VmReady ¶
func (s *StartupListenerServer) VmReady(ctx context.Context, msg *vmtools.EmptyMessage) (*vmtools.EmptyMessage, error)
VmReady is the implementation of the StartupListenerServer gRPC stub. It sends a signal through an empty channel when a message is received. Note: golint flags this function because Vm is not fully capitalized, however this is due to the proto definition.
type VM ¶
type VM struct { // Concierge is the Concierge instance managing this VM. Concierge *Concierge ContextID int64 // cid for the crosvm process EnableGPU bool // hardware GPU support DiskPath string // the location of the stateful disk // contains filtered or unexported fields }
VM encapsulates a virtual machine managed by the concierge/cicerone daemons.
func GetRunningVM ¶
GetRunningVM creates a VM struct for the VM that is currently running.
func NewDefaultVM ¶
NewDefaultVM gets a default VM instance. enableGPU enabled the hardware gpu support for the VM. diskSize set the targeted disk size of the VM.
func (*VM) LXCCommand ¶
LXCCommand runs lxc inside the VM with the specified args.
func (*VM) Name ¶
Name returns the human-readable name of this VM (as opposed to the encoded one from vm.GetEncodedName()).
func (*VM) ShareDownloadsPath ¶
ShareDownloadsPath shares a path relative to Downloads with the VM.
func (*VM) StartLxd ¶
StartLxd starts the LXD daemon inside the VM. This is a required step before performing any container operations.