common_utils

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: 16 Imported by: 0

Documentation

Overview

DLC constants and helpers

Firmware constants and common types

Common helper methods

Partition constants and helpers

Service interfaces bases for state-machine construction

General utility related bits for provisioning.

Index

Constants

View Source
const (
	DlcCacheDir    = "/var/cache/dlc"
	DlcImage       = "dlc.img"
	DlcLibDir      = "/var/lib/dlcservice/dlc"
	DlcPackage     = "package"
	DlcVerified    = "verified"
	DlcserviceUtil = "dlcservice_util"
)
View Source
const (
	FirmwareUpdaterPath              = "/usr/sbin/chromeos-firmwareupdate"
	CrossystemCurrentFirmwareSlotKey = "mainfw_act"
	CrossystemNextFirmwareSlotKey    = "fw_try_next"
)
View Source
const (
	LaCrOSRootComponentPath = "/var/lib/imageloader/lacros"
	LaCrOSPageSize          = 4096
)
View Source
const (
	PartitionNumStateful = "1"
	PartitionNumKernelA  = "2"
	PartitionNumKernelB  = "4"
	PartitionNumRootA    = "3"
	PartitionNumRootB    = "5"
	PartitionNumMiniOSA  = "9"
	PartitionNumMiniOSB  = "10"
)
View Source
const (
	StatefulPath           = "/mnt/stateful_partition"
	UpdateStatefulFilePath = StatefulPath + "/.update_available"
	// ProvisionMarker - This file acts as a flag to signal failed provisions.
	// As we create the file in stateful, that means that if provision
	// is successful it will be overwritten, meaning that the fact it exists
	// beyond a provision run means it must have failed.
	// This file should be created on every OS provision start.
	ProvisionMarker = "/var/tmp/provision_failed"
)
View Source
const (
	KvmDevicePath = "/dev/kvm"
)
View Source
const (
	MiniOSUnsupportedGUIDPartition = "09845860-705F-4BB5-B16C-8A8A099CAF52"
)

Variables

View Source
var ActiveDlcMap = map[string]string{PartitionNumRootA: dlcSlotA, PartitionNumRootB: dlcSlotA}
View Source
var InactiveDlcMap = map[string]string{PartitionNumRootA: dlcSlotB, PartitionNumRootB: dlcSlotB}

Functions

func BucketJoin

func BucketJoin(bucket string, append string) string

BucketJoin is equivalent to Path.Join(), but for gs buckets. This is necessary as the BUF removes double-slashes, which mangles the URI. Returns the bucket and append as a formed bucket URI.

func CreateLogFile

func CreateLogFile(fullPath string) (*os.File, error)

CreateLogFile creates a file and its parent directory for logging purpose.

func ExecuteStateMachine

func ExecuteStateMachine(ctx context.Context, cs ServiceState, log *log.Logger) (api.InstallResponse_Status, *anypb.Any, error)

ExecuteStateMachine runs a specific state machine

func GetMiniOSPartitions

func GetMiniOSPartitions() []string

GetMiniOSPartitions returns the partition numbers for miniOS

func NewLogger

func NewLogger(logFile *os.File) *log.Logger

NewLogger creates a logger. Using go default logger for now.

func ParseAndroidProvisionRequest

func ParseAndroidProvisionRequest(path string) (*api.AndroidProvisionRequest, error)

ParseAndroidProvisionRequest parses AndroidProvisionRequest input request data from the input file.

func ParseCrosProvisionRequest

func ParseCrosProvisionRequest(path string) (*api.CrosProvisionRequest, error)

ParseCrosProvisionRequest parses CrosProvisionRequest input request data from the input file.

func ParseInstallRequest

func ParseInstallRequest(path string) (*api.InstallRequest, error)

ParseInstallRequest parses InstallRequest input request data from the input file.

func ParseProvisionStartupRequest

func ParseProvisionStartupRequest(path string) (*api.ProvisionStartupRequest, error)

ParseProvisionStartupRequest parses ProvisionStartupRequest input request data from the input file.

Types

type CommandInterface

type CommandInterface interface {
	//Execute runs the command
	Execute(log *log.Logger) error

	// Revert reverts the command
	Revert() error

	// GetErrorMessage returns a crafted error message in case of failure
	GetErrorMessage() string

	// GetStatus returns the proto status response for the message
	GetStatus() api.InstallResponse_Status
}

CommandInterface executes a specific step in a state. Note commands are

intended to interact with a ServiceInterface and as such will have
side-effects.

type FirmwareManifest

type FirmwareManifest map[string]FirmwareManifestData

type FirmwareManifestData

type FirmwareManifestData struct {
	Host struct {
		Versions struct {
			Ro string `json:"ro"`
			Rw string `json:"rw"`
		} `json:"versions"`
		Keys struct {
			Root     string `json:"root"`
			Recovery string `json:"recovery"`
		} `json:"keys"`
		Image string `json:"image"`
	} `json:"host"`
	Ec struct {
		Versions struct {
			Ro string `json:"ro"`
			Rw string `json:"rw"`
		} `json:"versions"`
		Image string `json:"image"`
	} `json:"ec"`
	SignatureId string `json:"signature_id"`
}

type PartitionInfo

type PartitionInfo struct {
	// The active + inactive kernel device partitions (e.g. /dev/nvme0n1p2).
	ActiveKernel      string
	ActiveKernelNum   string
	InactiveKernel    string
	InactiveKernelNum string
	// The active + inactive root device partitions (e.g. /dev/nvme0n1p3).
	ActiveRoot   string
	InactiveRoot string
	// The A + B miniOS device partitions.
	MiniOSA string
	MiniOSB string
	// The stateful partition path.
	Stateful string
}

partitionsInfo holds active/inactive root + kernel partition information.

func GetPartitionInfo

func GetPartitionInfo(root string, rootDisk string, rootPartNum string) PartitionInfo

GetPartitionInfo retrieves relevant kernel and root info for a specific root

type ServiceAdapter

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

func NewServiceAdapter

func NewServiceAdapter(dutClient api.DutServiceClient, noReboot bool) ServiceAdapter

func (ServiceAdapter) CopyData

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

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

func (ServiceAdapter) CreateDirectories

func (s ServiceAdapter) 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 (ServiceAdapter) DeleteDirectory

func (s ServiceAdapter) 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 (ServiceAdapter) FetchFile

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

FetchFile downloads a file from the DUT.

func (ServiceAdapter) ForceReconnectWithBackoff

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

ForceReconnectWithBackoff is a thin wrapper around DUT service's ForceReconnectWithBackoff.

func (ServiceAdapter) PathExists

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

PathExists determines if a path exists in a DUT

func (ServiceAdapter) PipeData

func (s ServiceAdapter) 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 (ServiceAdapter) Restart

func (s ServiceAdapter) Restart(ctx context.Context) error

Restart restarts a DUT

func (ServiceAdapter) RunCmd

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

RunCmd runs a command in a remote DUT

type ServiceAdapterInterface

type ServiceAdapterInterface interface {
	// 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
	// FetchFile downloads a file from the DUT.
	FetchFile(ctx context.Context, path string) (io.ReadCloser, error)
	// ForceReconnectWithBackoff waits for the DUT to come back up/reconnect.
	ForceReconnectWithBackoff(ctx context.Context) error
}

ServiceAdapters are used to interface with a DUT All methods here are proxies to cros-dut (with some additions for simplicity)

type ServiceInterface

type ServiceInterface interface {
	// GetFirstState returns the first state in this state machine
	GetFirstState() ServiceState

	// CleanupOnFailure "undoes" the service execution to the extent possible,
	// removing temporary files, and, if feasible, reverting the run commands.
	// CleanupOnFailure function will be called if any ServiceState returns an
	// error when running Execute().
	// |states| will include all ServiceStates that were run; naturally, all of
	// them but last one would have succeeded to Execute().
	// |executionErr| is the error returned by Execute() of the last (failed)
	// ServiceState.
	CleanupOnFailure(states []ServiceState, executionErr error) error
}

ServiceInterface represents the state machine for this specific service installation. It holds installation metadata and provides helpers, including the generator of the first state for that installation.

type ServiceState

type ServiceState interface {
	// Execute Runs the state
	Execute(ctx context.Context, log *log.Logger) (*anypb.Any, api.InstallResponse_Status, error)
	// Next gets the next state in the state machine
	Next() ServiceState
	// Name gets the fully qualified name of this state
	Name() string
}

ServiceState is a single state representation.

Directories

Path Synopsis
Plain Old Go Object repo for machine metadata
Plain Old Go Object repo for machine metadata
Executor defines a state initializer for each state.
Executor defines a state initializer for each state.

Jump to

Keyboard shortcuts

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