host

package
v0.58.0-rc.9 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package host provides a way to interact with an e2e remote host and capture its state.

Index

Constants

View Source
const (
	// Loaded is the load state of a systemd unit.
	Loaded LoadState = "loaded"
	// NotLoaded is the load state of a systemd unit.
	NotLoaded LoadState = "not-found"
	// Masked is the load state of a systemd unit.
	Masked LoadState = "masked"
	// Error is the load state of a systemd unit.
	Error LoadState = "error"

	// Running is the sub state of a systemd unit.
	Running SubState = "running"
	// Dead is the sub state of a systemd unit.
	Dead SubState = "dead"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeAgent

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

FakeAgent represents a fake Agent.

func (FakeAgent) SetExit0

func (f FakeAgent) SetExit0(agent string) FakeAgent

SetExit0 sets the fake Agent to exit with code 0.

func (FakeAgent) SetExit1

func (f FakeAgent) SetExit1(agent string) FakeAgent

SetExit1 sets the fake Agent to exit with code 1.

func (FakeAgent) SetStopWithSigkill

func (f FakeAgent) SetStopWithSigkill(agent string) FakeAgent

SetStopWithSigkill sets the fake Agent to stop with SIGKILL.

func (FakeAgent) SetStopWithSigterm

func (f FakeAgent) SetStopWithSigterm(agent string) FakeAgent

SetStopWithSigterm sets the fake Agent to stop with SIGTERM.

func (FakeAgent) SetStopWithSigtermExit0 added in v0.56.0

func (f FakeAgent) SetStopWithSigtermExit0(agent string) FakeAgent

SetStopWithSigtermExit0 sets the fake Agent to stop with SIGTERM and exit with code 0.

type FileInfo

type FileInfo struct {
	Name      string
	Size      int64
	Perms     fs.FileMode
	ModTime   time.Time
	IsDir     bool
	IsSymlink bool
	Link      string
	User      string
	Group     string
}

FileInfo struct mimics os.FileInfo

type Host

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

Host is a remote host environment.

func New

func New(t *testing.T, remote *components.RemoteHost, os e2eos.Descriptor, arch e2eos.Architecture, opts ...Option) *Host

New creates a new Host.

func (*Host) AgentRuntimeConfig

func (h *Host) AgentRuntimeConfig() (string, error)

AgentRuntimeConfig returns the runtime agent config on the host.

func (*Host) AgentStableVersion added in v0.57.0

func (h *Host) AgentStableVersion() string

AgentStableVersion returns the stable version of the agent on the host.

func (*Host) AssertPackageInstalledByInstaller

func (h *Host) AssertPackageInstalledByInstaller(pkgs ...string)

AssertPackageInstalledByInstaller checks if a package is installed by the installer on the host.

func (*Host) AssertPackageInstalledByPackageManager

func (h *Host) AssertPackageInstalledByPackageManager(pkgs ...string)

AssertPackageInstalledByPackageManager checks if a package is installed by the package manager on the host.

func (*Host) AssertPackageNotInstalledByPackageManager

func (h *Host) AssertPackageNotInstalledByPackageManager(pkgs ...string)

AssertPackageNotInstalledByPackageManager checks if a package is not installed by the package manager on the host.

func (*Host) AssertPackagePrefix added in v0.57.0

func (h *Host) AssertPackagePrefix(pkg string, semver string)

AssertPackagePrefix checks if a package is installed with a version with the prefix

func (*Host) AssertPackageVersion

func (h *Host) AssertPackageVersion(pkg string, version string)

AssertPackageVersion checks if a package is installed with the correct version

func (*Host) AssertSystemdEvents

func (h *Host) AssertSystemdEvents(since JournaldTimestamp, events SystemdEventSequence)

AssertSystemdEvents asserts that the systemd events have been logged since the given timestamp

func (*Host) AssertUnitProperty

func (h *Host) AssertUnitProperty(unit, property, value string)

AssertUnitProperty asserts that the given systemd unit has the given property

func (*Host) BootstraperVersion

func (h *Host) BootstraperVersion() string

BootstraperVersion returns the version of the bootstraper on the host.

func (*Host) CallExamplePythonApp

func (h *Host) CallExamplePythonApp(traceID string)

CallExamplePythonApp calls the example Python app

func (*Host) CallExamplePythonAppInDocker

func (h *Host) CallExamplePythonAppInDocker(traceID string)

CallExamplePythonAppInDocker calls the example Python app in Docker

func (*Host) DeletePath

func (h *Host) DeletePath(path string)

DeletePath deletes a path on the host.

func (*Host) FileExists

func (h *Host) FileExists(path string) (bool, error)

FileExists checks if a file exists on the host.

func (*Host) GetDockerRuntimePath

func (h *Host) GetDockerRuntimePath(runtime string) string

GetDockerRuntimePath returns the runtime path of a docker runtime

func (*Host) GetPkgManager

func (h *Host) GetPkgManager() string

GetPkgManager returns the package manager of the host.

func (*Host) InstallDocker

func (h *Host) InstallDocker()

InstallDocker installs Docker on the host if it is not already installed.

func (*Host) InstallerVersion

func (h *Host) InstallerVersion() string

InstallerVersion returns the version of the installer on the host.

func (*Host) LastJournaldTimestamp

func (h *Host) LastJournaldTimestamp() JournaldTimestamp

LastJournaldTimestamp returns the monotonic timestamp of the last journald log entry

func (*Host) ReadFile

func (h *Host) ReadFile(path string) ([]byte, error)

ReadFile reads a file from the host.

func (*Host) RemoveBrokenDockerConfig

func (h *Host) RemoveBrokenDockerConfig()

RemoveBrokenDockerConfig removes the broken configuration from the Docker daemon

func (*Host) Run

func (h *Host) Run(command string, env ...string) string

Run executes a command on the host.

func (*Host) SetBrokenDockerConfig

func (h *Host) SetBrokenDockerConfig()

SetBrokenDockerConfig injects a broken JSON in the Docker daemon configuration

func (*Host) SetBrokenDockerConfigAdditionalFields

func (h *Host) SetBrokenDockerConfigAdditionalFields()

SetBrokenDockerConfigAdditionalFields injects additional fields in the Docker daemon configuration these fields are not supported

func (*Host) SetUmask added in v0.57.0

func (h *Host) SetUmask(mask string) (oldmask string)

SetUmask set the default umask for commands

func (*Host) SetupFakeAgentExp

func (h *Host) SetupFakeAgentExp() FakeAgent

SetupFakeAgentExp sets up a fake Agent experiment with configurable options.

func (*Host) StartExamplePythonApp

func (h *Host) StartExamplePythonApp()

StartExamplePythonApp starts an example Python app

func (*Host) StartExamplePythonAppInDocker

func (h *Host) StartExamplePythonAppInDocker()

StartExamplePythonAppInDocker starts the example Python app in Docker

func (*Host) State

func (h *Host) State() State

State returns the state of the host.

func (*Host) StopExamplePythonApp

func (h *Host) StopExamplePythonApp()

StopExamplePythonApp stops the example Python app

func (*Host) StopExamplePythonAppInDocker

func (h *Host) StopExamplePythonAppInDocker()

StopExamplePythonAppInDocker stops the example Python app in Docker

func (*Host) WaitForFileExists added in v0.56.0

func (h *Host) WaitForFileExists(useSudo bool, filePaths ...string)

WaitForFileExists waits for a file to exist on the host

func (*Host) WaitForTraceAgentSocketReady added in v0.57.0

func (h *Host) WaitForTraceAgentSocketReady()

WaitForTraceAgentSocketReady waits for the trace agent to be ready to receive traces This is because of a race condition where the trace agent is not ready to receive traces and we send them meaning that the traces are lost

func (*Host) WaitForUnitActivating added in v0.56.0

func (h *Host) WaitForUnitActivating(units ...string)

WaitForUnitActivating waits for a systemd unit to be activating

func (*Host) WaitForUnitActive

func (h *Host) WaitForUnitActive(units ...string)

WaitForUnitActive waits for a systemd unit to be active

func (*Host) WriteFile added in v0.56.0

func (h *Host) WriteFile(path string, content []byte) error

WriteFile writes a file to the host.

type JournaldTimestamp

type JournaldTimestamp int64

JournaldTimestamp represents a monotonic timestamp of a journald log entry

type LoadState

type LoadState string

LoadState is the load state of a systemd unit.

type Option

type Option func(*testing.T, *Host)

Option is an option to configure a Host.

type State

type State struct {
	Users  []user.User
	Groups []user.Group
	FS     map[string]FileInfo
	Units  map[string]SystemdUnitInfo
	// contains filtered or unexported fields
}

State is the state of a remote host.

func (*State) AssertDirExists

func (s *State) AssertDirExists(path string, perms fs.FileMode, user string, group string)

AssertDirExists asserts that a directory exists on the host with the given perms, user, and group.

func (*State) AssertFileExists

func (s *State) AssertFileExists(path string, perms fs.FileMode, user string, group string)

AssertFileExists asserts that a file exists on the host with the given perms, user, and group.

func (*State) AssertFileExistsAnyUser added in v0.58.0

func (s *State) AssertFileExistsAnyUser(path string, perms fs.FileMode)

AssertFileExistsAnyUser asserts that a file exists on the host with the given perms.

func (*State) AssertGroupExists

func (s *State) AssertGroupExists(groupName string)

AssertGroupExists asserts that a group exists on the host.

func (*State) AssertPathDoesNotExist

func (s *State) AssertPathDoesNotExist(path string)

AssertPathDoesNotExist asserts that a path does not exist on the host.

func (*State) AssertSymlinkExists

func (s *State) AssertSymlinkExists(path string, target string, user string, group string)

AssertSymlinkExists asserts that a symlink exists on the host with the given target, user, and group.

func (*State) AssertUnitsDead

func (s *State) AssertUnitsDead(names ...string)

AssertUnitsDead asserts that a systemd unit is not running.

func (*State) AssertUnitsEnabled

func (s *State) AssertUnitsEnabled(names ...string)

AssertUnitsEnabled asserts that a systemd unit is not loaded.

func (*State) AssertUnitsLoaded

func (s *State) AssertUnitsLoaded(names ...string)

AssertUnitsLoaded asserts that units are enabled on the host.

func (*State) AssertUnitsNotEnabled

func (s *State) AssertUnitsNotEnabled(names ...string)

AssertUnitsNotEnabled asserts that a systemd unit is not enabled

func (*State) AssertUnitsNotLoaded

func (s *State) AssertUnitsNotLoaded(names ...string)

AssertUnitsNotLoaded asserts that a systemd unit is not loaded.

func (*State) AssertUnitsRunning

func (s *State) AssertUnitsRunning(names ...string)

AssertUnitsRunning asserts that a systemd unit is running.

func (*State) AssertUserExists

func (s *State) AssertUserExists(userName string)

AssertUserExists asserts that a user exists on the host.

func (*State) AssertUserHasGroup

func (s *State) AssertUserHasGroup(userName, groupName string)

AssertUserHasGroup asserts that a user has a group on the host.

func (*State) ListDirectory added in v0.57.0

func (s *State) ListDirectory(path string) []FileInfo

ListDirectory returns a list of entries in the directory and fails the test if it doesn't exist

func (*State) Stat added in v0.56.0

func (s *State) Stat(path string) (FileInfo, bool)

Stat returns the FileInfo of a path on the host.

type SubState

type SubState string

SubState is the sub state of a systemd unit.

type SystemdEvent

type SystemdEvent struct {
	Unit    string
	Pattern string
}

SystemdEvent represents a systemd event

type SystemdEventSequence

type SystemdEventSequence struct {
	Events [][]SystemdEvent
}

SystemdEventSequence represents a sequence of systemd events

func SystemdEvents

func SystemdEvents() SystemdEventSequence

SystemdEvents returns a new SystemdEventSequence

func (SystemdEventSequence) Failed

Failed adds a "Failed" event to the sequence

func (SystemdEventSequence) Sigkill

Sigkill adds a "Sigkill" event to the sequence

func (SystemdEventSequence) SigtermTimed

func (s SystemdEventSequence) SigtermTimed(unit string) SystemdEventSequence

SigtermTimed adds a "SigtermTimed" event to the sequence

func (SystemdEventSequence) Skipped

Skipped adds a "Skipped" event to the sequence

func (SystemdEventSequence) SkippedIf added in v0.58.0

func (s SystemdEventSequence) SkippedIf(unit string, condition bool) SystemdEventSequence

SkippedIf adds a "Skipped" event to the sequence if the condition is true

func (SystemdEventSequence) Started

Started adds a "Started" event to the sequence

func (SystemdEventSequence) Starting

Starting adds a "Starting" event to the sequence

func (SystemdEventSequence) Stopped

Stopped adds a "Stopped" event to the sequence

func (SystemdEventSequence) Stopping

Stopping adds a "Stopping" event to the sequence

func (SystemdEventSequence) Timed

Timed adds a "Timed" event to the sequence

func (SystemdEventSequence) Unordered

Unordered adds an unordered sequence of events to the sequence

type SystemdUnitInfo

type SystemdUnitInfo struct {
	Name      string
	Active    string
	Enabled   string
	SubState  SubState
	LoadState LoadState
}

SystemdUnitInfo is the info of a systemd unit.

Jump to

Keyboard shortcuts

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