servoadapter

package
v0.0.0-...-19f3ddf Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

README

ServoHostAdapter

ServoHostAdapter will be deleted whenever cros-servod starts working on non-labstation devices, and replaced with RPC calls.

ServoHostAdapter is a lightweight adapter that expands ExecCmder interface with servod-related functionality.

Given following interface

ExecCmd(ctx context.Context, in *api.ExecCmdRequest, opts ...grpc.CallOption) (*api.ExecCmdResponse, error)

ServoHostAdapter implements the functionality of services.ServiceAdapterInterface, which currently includes following functions:

	// RunCmd takes a command and argument and executes it remotely in the DUT,
	// returning the stdout as the string result and any execution error as the error.
	RunCmd(ctx context.Context, cmd string, args []string) (string, error)
	// Restart restarts a DUT (allowing cros-dut to reconnect for connection caching).
	Restart(ctx context.Context) error
	// PathExists is a simple wrapper for RunCmd for the sake of simplicity. If
	// the path exists True is returned, else False. An error implies a
	// a communication failure.
	PathExists(ctx context.Context, path string) (bool, error)
	// PipeData uses the caching infrastructure to bring an image into the lab.
	// Contrary to CopyData, the data here is pipeable to whatever is fed into
	// pipeCommand, rather than directly placed locally.
	PipeData(ctx context.Context, sourceUrl string, pipeCommand string) error
	// CopyData uses the caching infrastructure to copy a remote image to
	// the local path specified by destPath.
	CopyData(ctx context.Context, sourceUrl string, destPath string) error
	// DeleteDirectory is a simple wrapper for RunCmd for the sake of simplicity.
	DeleteDirectory(ctx context.Context, dir string) error
	// CreateDirectory is a simple wrapper for RunCmd for the sake of simplicity.
	// All directories specified in the array will be created.
	// As this uses "-p" option, subdirs are created regardless of whether parents
	// exist or not.
	CreateDirectories(ctx context.Context, dirs []string) error

and adds following additional servod-related functions:

	// Returns value of a variable, requested with dut-control.
	GetVariable(ctx context.Context, varName string) (string, error)
	// Runs a single dut-control command with |args| as its arguments.
	RunDutControl(ctx context.Context, args []string) error
	// Runs an array of dut-control commands.
	RunAllDutControls(ctx context.Context, cmdFragments [][]string) error

	GetBoard(ctx context.Context) string
	GetModel(ctx context.Context) string

Documentation

Overview

Copyright 2022 The ChromiumOS Authors Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

View Source
const CurlWithRetriesArgs = "-S -s -v -# -C - --retry 3 --retry-delay 60"

Variables

View Source
var ErrNotImplemented = errors.New("LocalAdapter: not implemented")

Functions

This section is empty.

Types

type ExecCmder

type ExecCmder interface {
	// ExecCmd executes a system command that is provided through the command
	// parameter in the request. It allows the user to execute arbitrary commands
	// that can't be handled by calling servod (e.g. update firmware through
	// "futility", remote file copy through "scp").
	ExecCmd(ctx context.Context, in *api.ExecCmdRequest, opts ...grpc.CallOption) (*api.ExecCmdResponse, error)
}

ServodServiceClient minus unused functionality.

type ServoHostAdapter

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

func (ServoHostAdapter) CopyData

func (s ServoHostAdapter) CopyData(ctx context.Context, sourceUrl string, destPath string) error

CopyData caches a file for a DUT locally from a GS url.

func (ServoHostAdapter) CreateDirectories

func (s ServoHostAdapter) CreateDirectories(ctx context.Context, dirs []string) error

Create directories is a thin wrapper around an mkdir command. Done here as it is expected to be reused often by many services.

func (ServoHostAdapter) DeleteDirectory

func (s ServoHostAdapter) DeleteDirectory(ctx context.Context, dir string) error

DeleteDirectory is a thin wrapper around an rm command. Done here as it is expected to be reused often by many services.

func (*ServoHostAdapter) FetchFile

func (s *ServoHostAdapter) FetchFile(ctx context.Context, path string) (io.ReadCloser, error)

FetchFile downloads a file from the servo host.

func (ServoHostAdapter) ForceReconnectWithBackoff

func (s ServoHostAdapter) ForceReconnectWithBackoff(ctx context.Context) error

func (*ServoHostAdapter) GetBoard

func (s *ServoHostAdapter) GetBoard(ctx context.Context) string

func (*ServoHostAdapter) GetModel

func (s *ServoHostAdapter) GetModel(ctx context.Context) string

func (*ServoHostAdapter) GetVariable

func (s *ServoHostAdapter) GetVariable(ctx context.Context, varName string) (string, error)

GetVariable reads value of varName from servo.

func (ServoHostAdapter) PathExists

func (s ServoHostAdapter) PathExists(ctx context.Context, path string) (bool, error)

PathExists determines if a path exists in a DUT

func (ServoHostAdapter) PipeData

func (s ServoHostAdapter) PipeData(ctx context.Context, sourceUrl string, pipeCommand string) error

PipeData uses the caching infrastructure to bring a file locally, allowing a user to pipe the result to any desired application.

func (*ServoHostAdapter) Restart

func (s *ServoHostAdapter) Restart(ctx context.Context) error

func (*ServoHostAdapter) RunAllDutControls

func (s *ServoHostAdapter) RunAllDutControls(ctx context.Context, cmdFragments [][]string) error

RunAllCmd sequentially runs all cmdFragments as dut-control commands.

func (*ServoHostAdapter) RunCmd

func (s *ServoHostAdapter) RunCmd(ctx context.Context, cmd string, args []string) (string, error)

RunCmd takes a command and argument and executes it remotely on the ServoHost by transforming the request to api.ExecCmdRequest, sending the request out, and transforming the response from api.ExecCmdResponse to (string, error). Returns the stdout as the string result and any execution error as the error.

func (*ServoHostAdapter) RunDutControl

func (s *ServoHostAdapter) RunDutControl(ctx context.Context, args []string) error

RunDutControl runs a dut-control command with provided arguments.

type ServoHostInterface

type ServoHostInterface interface {
	services.ServiceAdapterInterface

	// Returns value of a variable, requested with dut-control.
	GetVariable(ctx context.Context, varName string) (string, error)
	// Runs a single dut-control command with |args| as its arguments.
	RunDutControl(ctx context.Context, args []string) error
	// Runs an array of dut-control commands.
	RunAllDutControls(ctx context.Context, cmdFragments [][]string) error

	GetBoard(ctx context.Context) string
	GetModel(ctx context.Context) string

	// FetchFile downloads a file from the servo host. Not implemented.
	FetchFile(ctx context.Context, path string) (io.ReadCloser, error)
}

ServoHostInterface is used to interface with a ServoHost

func NewServoHostAdapterFromExecCmder

func NewServoHostAdapterFromExecCmder(board, model string, port int, execCmder ExecCmder) ServoHostInterface

NewServoHostAdapterFromExecCmder adds extra functions to the ExecCmder.

Jump to

Keyboard shortcuts

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