execs

package
v0.0.0-...-9994f1b Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package execs provides collection of execution functions for actions and ability to execute them.

Index

Constants

View Source
const (
	// This character separates the name and values for extra
	// arguments defined for actions.
	DefaultSplitter = ":"

	// This character demarcates the individual values among
	// multi-valued extra arguments defined for actions.
	MultiValueSplitter = ","
)

Variables

View Source
var (
	// Error tag to track error with request to start critical actions over.
	PlanStartOverTag = errors.BoolTag{Key: errors.NewTagKey("plan-start-over")}

	// Error tag to track error with request to stop execution of the current plan.
	PlanAbortTag = errors.BoolTag{Key: errors.NewTagKey("plan-abort")}
)
View Source
var (
	// TODO: need remove these errors to use them from components.
	ErrCodeTag                   = components.ErrCodeTag
	StdErrTag                    = components.StdErrTag
	SSHErrorCLINotFound          = components.SSHErrorCLINotFound
	SSHErrorLinuxTimeout         = components.SSHErrorLinuxTimeout
	GeneralError                 = components.GeneralError
	SSHErrorInternal             = components.SSHErrorInternal
	FailToCreateSSHErrorInternal = components.FailToCreateSSHErrorInternal
	NoExitStatusErrorInternal    = components.NoExitStatusErrorInternal
	OtherErrorInternal           = components.OtherErrorInternal
)

Functions

func Exist

func Exist(name string) bool

Exist check if exec function with name is present.

func Register

func Register(name string, f ExecFunction)

Register registers new exec function to be used with recovery engine. We panic if a name is reused.

func Run

func Run(ctx context.Context, ei *ExecInfo) (rErr error)

Run runs exec function provided by this package by name.

Types

type ExecFunction

type ExecFunction func(ctx context.Context, i *ExecInfo) error

ExecFunction represents an execution function of the action. The single exec can be associated with one or more actions.

type ExecInfo

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

ExecInfo holds all data required to run exec. The struct created every time new for each exec run.

func NewExecInfo

func NewExecInfo(runArgs *RunArgs, name string, actionArgs []string, actionTimeout time.Duration, metric *metrics.Action) *ExecInfo

NewExecInfo creates new instance of ExecInfo.

func (*ExecInfo) AddObservation

func (ei *ExecInfo) AddObservation(observation *metrics.Observation)

AddObservation adds observation to the metric assigned to the current exec.

func (*ExecInfo) CopyDirectoryFrom

func (ei *ExecInfo) CopyDirectoryFrom(ctx context.Context, resourceName, srcDir, destDir string) error

CopyDirectoryFrom copies a directory from resource to localhost.

func (*ExecInfo) CopyFrom

func (ei *ExecInfo) CopyFrom(ctx context.Context, resourceName, srcFile, destDir string) error

CopyFrom copies files from resource to localhost.

func (*ExecInfo) DefaultHostAccess

func (ei *ExecInfo) DefaultHostAccess() *hostAccess

DefaultHostAccess returns HostAccess for current resource name specified per plan.

func (*ExecInfo) DefaultPinger

func (ei *ExecInfo) DefaultPinger() components.Pinger

DefaultPinger returns pinger for current resource name specified per plan.

func (*ExecInfo) DefaultRunner

func (ei *ExecInfo) DefaultRunner() components.Runner

DefaultRunner returns runner for current resource name specified per plan.

func (*ExecInfo) GetAccess

func (ei *ExecInfo) GetAccess() tlw.Access

GetAccess returns access to main interface.

func (*ExecInfo) GetActionArgs

func (ei *ExecInfo) GetActionArgs(ctx context.Context) ParsedArgs

GetActionArgs returns parsed action arguments with default splitter.

func (*ExecInfo) GetActiveResource

func (ei *ExecInfo) GetActiveResource() string

GetActiveResource returns what is active resource.

func (*ExecInfo) GetAdditionalMetrics

func (ei *ExecInfo) GetAdditionalMetrics() []*metrics.Action

GetAdditionalMetrics returns additional metrics created by execs.

func (*ExecInfo) GetAndroid

func (ei *ExecInfo) GetAndroid() *tlw.Android

GetAndroid returns Android device from DUT.

func (*ExecInfo) GetChromeos

func (ei *ExecInfo) GetChromeos() *tlw.ChromeOS

GetChromeos returns ChromeOS device from DUT.

func (*ExecInfo) GetDeviceName

func (ei *ExecInfo) GetDeviceName(code string) (string, error)

GetDeviceName returns name of the devices requested by code.

func (*ExecInfo) GetDut

func (ei *ExecInfo) GetDut() *tlw.Dut

GetDut returns Dut.

func (*ExecInfo) GetExecArgs

func (ei *ExecInfo) GetExecArgs() []string

GetExecArgs returns list of arguments provided for an exec.

func (*ExecInfo) GetExecTimeout

func (ei *ExecInfo) GetExecTimeout() time.Duration

GetExecTimeout returns timeout specified for an exec.

func (*ExecInfo) GetLogRoot

func (ei *ExecInfo) GetLogRoot() string

GetLogRoot returns path to logs directory.

func (*ExecInfo) GetMetrics

func (ei *ExecInfo) GetMetrics() metrics.Metrics

GetMetrics returns Metrics.

func (*ExecInfo) NewBackgroundRunner

func (ei *ExecInfo) NewBackgroundRunner(host string) components.Runner

NewBackgroundRunner returns runner for requested resource specified per plan.

TODO(b/222698101): At this time this method is a placeholder. This will eventually be replaced with an implementation that will submit a command for background execution, and will return without waiting for it to complete.

func (*ExecInfo) NewHostAccess

func (ei *ExecInfo) NewHostAccess(host string) *hostAccess

NewHostAccess creates new instance of HostAccess.

func (*ExecInfo) NewLogger

func (ei *ExecInfo) NewLogger() logger.Logger

NewLogger returns logger.

func (*ExecInfo) NewMetric

func (ei *ExecInfo) NewMetric(kind string) *metrics.Action

NewMetric creates a new custom metric.

func (*ExecInfo) NewPinger

func (ei *ExecInfo) NewPinger(resource string) components.Pinger

NewPinger returns pinger for requested resource.

func (*ExecInfo) NewRunner

func (ei *ExecInfo) NewRunner(host string) components.Runner

NewRunner returns a function of type Runner that executes a command on a host and returns the results as a single line. This function defines the specific host on which the command will be executed. Examples of such specific hosts can be the DUT, or the servo-host etc.

func (*ExecInfo) NewServod

func (ei *ExecInfo) NewServod() components.Servod

NewServod returns a struct of type components.Servod that allowes communication with servod service.

func (*ExecInfo) RPMAction

func (ei *ExecInfo) RPMAction(ctx context.Context, hostname string, o *tlw.RPMOutlet, action tlw.RunRPMActionRequest_Action) error

RPMAction perform RPM action on RPM outlet. If the outlet missing the state will set to missing config state.

type ParsedArgs

type ParsedArgs map[string]string

ParsedArgs is the map representing key-value pairs parsed from extra args in the configuration.

func ParseActionArgs

func ParseActionArgs(ctx context.Context, actionArgs []string, splitter string) ParsedArgs

ParseActionArgs parses the action arguments using the splitter, and returns ParsedArgs object containing key and values in the action arguments. If any mal-formed action arguments are found their value is set to empty string.

func (ParsedArgs) AsBool

func (parsedArgs ParsedArgs) AsBool(ctx context.Context, key string, defaultValue bool) bool

AsBool returns the value for the passed key as a boolean. If the key does not exist in the parsed arguments, the passed defaultValue is returned.

func (ParsedArgs) AsDuration

func (parsedArgs ParsedArgs) AsDuration(ctx context.Context, key string, defaultValue int, unit time.Duration) time.Duration

AsDuration returns the value of the passed key as type: time.Duration. If the value cannot be interpreted as int, then the passed defaultValue is returned.

@params unit: the unit of the time Duration, can be Nanosecond, Mircrosecond, Millisecond, Second, Minute

func (ParsedArgs) AsFloat64

func (parsedArgs ParsedArgs) AsFloat64(ctx context.Context, key string, defaultValue float64) float64

AsFloat64 returns the value for the passed key as a float64. If the value cannot be interpreted as int, then the passed defaultValue is returned.

func (ParsedArgs) AsInt

func (parsedArgs ParsedArgs) AsInt(ctx context.Context, key string, defaultValue int) int

AsInt returns the value for the passed key as a int. If the value cannot be interpreted as int, then the passed defaultValue is returned.

func (ParsedArgs) AsString

func (parsedArgs ParsedArgs) AsString(ctx context.Context, key, defaultValue string) string

AsString returns the value for the passed key as a string. If the key does not exist in the parsed arguments, the passed defaultValue is returned.

func (ParsedArgs) AsStringSlice

func (parsedArgs ParsedArgs) AsStringSlice(ctx context.Context, key string, defaultValue []string) []string

AsStringSlice returns the value for the passed key as a slice of string. If the key does not exist in the parsed arguments, an empty slice is returned.

func (ParsedArgs) Has

func (parsedArgs ParsedArgs) Has(key string) bool

Has returns true if key is found.

type RunArgs

type RunArgs struct {
	// Resource name targeted by plan.
	ResourceName string
	DUT          *tlw.Dut
	Access       tlw.Access
	// Logger prints message to the logs.
	Logger logger.Logger
	// Provide option to stop use steps.
	ShowSteps bool
	// Metrics records actions and observations.
	Metrics metrics.Metrics
	// EnableRecovery tells if recovery actions are enabled.
	EnableRecovery bool
	// SwarmingTaskID is the ID of the swarming task we're running under.
	SwarmingTaskID string
	// BuildbucketID is the ID of the buildbucket build we're running under.
	BuildbucketID string
	// LogRoot is an absolute path to a directory that contains logs.
	LogRoot string
}

RunArgs holds plan input arguments.

Keep this type up to date with recovery.go:RunArgs . Also update recovery.go:runDUTPlans .

func (*RunArgs) NewMetricsAction

func (a *RunArgs) NewMetricsAction(kind string) *metrics.Action

NewMetricsAction creates a new metric.

type Runner

type Runner = components.Runner

Runner defines the type for a function that will execute a command on a host, and returns the result as a single line. TODO: Remove as we do not need extra type.

Directories

Path Synopsis
Package amt contains execs used by the AMTManager peripheral.
Package amt contains execs used by the AMTManager peripheral.
Package btpeer contains execs meant to be run on btpeer peripherals.
Package btpeer contains execs meant to be run on btpeer peripherals.
CBI corruption detection and repair logic.
CBI corruption detection and repair logic.
Package ctr contains functions with cros-tool-runner.
Package ctr contains functions with cros-tool-runner.
Package dolos implements execs for dolos devices.
Package dolos implements execs for dolos devices.
Package dut provides execs to work with proto data only.
Package dut provides execs to work with proto data only.
Package env provide exec which based on environment variables.
Package env provide exec which based on environment variables.
Package wifirouter initializes execs to be used with wifi routers.
Package wifirouter initializes execs to be used with wifi routers.
controller
Package controller defines a common router controller class and implementations of this class per router type.
Package controller defines a common router controller class and implementations of this class per router type.
ssh
Package ssh is a collection of ssh utilities for executing remote ssh commands on hosts.
Package ssh is a collection of ssh utilities for executing remote ssh commands on hosts.
ssh/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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