common

package
v0.0.0-...-f4b31ea Latest Latest
Warning

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

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

Documentation

Overview

Code generated file. Code is copied from http://gpaste/6461300373979136 and then modified to make sure the imports work with bare minimum of structs needed.

Package common implements an interface for all firestore API actions.

Index

Constants

View Source
const (
	ServiceConnectionTimeout               = 30 * time.Minute
	CtrCipdPackage                         = "chromiumos/infra/cros-tool-runner/${platform}"
	ContainerDefaultNetwork                = "host"
	LabDockerKeyFileLocation               = "/creds/service_accounts/skylab-drone.json"
	VMLabDockerKeyFileLocation             = "/creds/service_accounts/service-account-chromeos.json"
	VMLabDutHostName                       = "vm"
	GceProject                             = "chromeos-gce-tests"
	GceNetwork                             = "global/networks/chromeos-gce-tests"
	GceMachineTypeN14                      = "n1-standard-4"
	GceMachineTypeN18                      = "n1-standard-8"
	GceMinCPUPlatform                      = "Intel Haswell"
	DockerImagePathShaFmt                  = "%s/%s/%s@%s"
	DockerImageCacheServer                 = "us-docker.pkg.dev/cros-registry/test-services/cacheserver:prod"
	DefaultDockerHost                      = "us-docker.pkg.dev"
	DefaultDockerProject                   = "cros-registry/test-services"
	PartnerDockerProject                   = "cros-registry/partner-test-services"
	LroTimeout                             = 1 * time.Minute
	GcsPublishTestArtifactsDir             = "/tmp/gcs-publish-test-artifacts/"
	TKOPublishTestArtifactsDir             = "/tmp/tko-publish-test-artifacts/"
	CpconPublishTestArtifactsDir           = "/tmp/cpcon-publish-test-artifacts/"
	RdbPublishTestArtifactDir              = "/tmp/rdb-publish-test-artifacts/"
	CrosTestCqLight                        = "cros-test-cq-light"
	TesthausURLPrefix                      = "https://tests.chromeos.goog/p/chromeos/logs/unified/"
	GcsURLPrefix                           = "https://pantheon.corp.google.com/storage/browser/"
	HwTestCtrInputPropertyName             = "$chromeos/cros_tool_runner"
	HwTestTrInputPropertyName              = "$chromeos/cros_test_runner"
	HwTestCtpv2InputPropertyName           = "$chromeos/ctpv2"
	CftServiceMetadataFileName             = ".cftmeta"
	CftServiceMetadataLineContentSeparator = "="
	CftServiceMetadataServicePortKey       = "SERVICE_PORT"
	TestDidNotRunErr                       = "Test did not run"
	CtrCancelingCmdErrString               = "canceling Cmd"
	UfsServiceURL                          = "ufs.api.cr.dev"
	TkoParseScriptPath                     = "/usr/local/autotest/tko/parse"
	DutConnectionPort                      = 22
	VMLeaserExperimentStr                  = "chromeos.cros_infra_config.vmleaser.launch"
	VMLabMachineTypeExperiment             = "chromeos.cros_infra_config.vmlab.machine_type_n1"
	SwarmingBasePath                       = "https://chromeos-swarming.appspot.com/_ah/api/swarming/v1/"
	SwarmingMaxLimitForEachQuery           = 1000
	ContainerMetadataPath                  = "/metadata/containers.jsonpb"
	TestPlatformDataProjectID              = "chromeos-test-platform-data"
	TestPlatformFireStore                  = "test-platform-store"
	PartnerTestPlatformFireStore           = "partner-test-platform-store"
	FireStoreContainersStagingCollection   = "containers-staging"
	FireStoreContainersProdCollection      = "containers-prod"
	LabelStaging                           = "staging"
	LabelProd                              = "prod"
	LabelPool                              = "label-pool"
	LabelSuite                             = "label-suite"
	Suite                                  = "suite"
	AnalyticsName                          = "analytics_name"
	BotParamsRejectedErrKey                = "Bot Params Rejected"
	EnumerationErrKey                      = "Enumeration Error"
	SuiteLimitsErrKey                      = "Suite Limits Cancellation"
	OtherErrKey                            = "Other Error"
	CTPBucket                              = "testplatform"
	CTPBucketShadow                        = "testplatform.shadow"
	AndroidBuildPrefix                     = "android-build/build_explorer/artifacts_list/"
	AndroidBuildPathFormat                 = AndroidBuildPrefix + "%s/%s/%s-ota-%s.zip"
	InvocationDataFlag                     = "invocation-data"
	CbIngestionValue                       = "invocation-property=crystalball_ingest:yes"
	AncestorsPropName                      = "ancestor_buildbucket_ids"
	CbPropName                             = "crystalball_ingest"
	CbMetricsPropName                      = "crystalball_has_data"
	// SourceMetadataPath is the path in the build output directory that
	// details the code sources compiled into the build. The path is
	// specified relative to the root of the build output directory.
	SourceMetadataPath = "/metadata/sources.jsonpb"
	// OS file constants
	// OWNER: Execute, Read, Write
	// GROUP: Execute, Read
	// OTHER: Execute, Read
	DirPermission = 0755
	// OWNER: Read, Write
	// GROUP: Read
	// OTHER: Read
	FilePermission = 0644

	// Experiments
	DynamicExperiment = "chromeos.cros_infra_config.dynamic_trv2"
)

All common constants used throughout the service.

View Source
const (
	ATPSupportedTimeFormat         = "2006-01-02T15:04:05.000000"
	ATPSwitcherProjectIDAlpha      = "google.com:atp-switcher-alpha"
	ATPSwitcherProjectIDStaging    = "google.com:atp-switcher-staging"
	ATPSwitcherProjectIDProd       = "google.com:atp-switcher"
	ATPSwitcherTestJobEventTopicID = "test_job_event"

	TaskCanceledState  = "CANCELED"
	TaskCompletedState = "COMPLETED"
	TaskErrorState     = "ERROR"
	TaskFatalState     = "FATAL"
	TaskQueuedState    = "QUEUED"
	TaskRunningState   = "RUNNING"
	TaskUnknownState   = "UNKNOWN"
)

AL related constants

View Source
const (
	// Base task identifiers and image metadata keys.
	CrosProvision    = "cros-provision"
	AndroidProvision = "android-provision"
	FwProvision      = "cros-fw-provision"
	CrosDut          = "cros-dut"
	CrosTest         = "cros-test"
	CrosPublish      = "cros-publish"
	RdbPublish       = "rdb-publish"
	GcsPublish       = "gcs-publish"
	CpconPublish     = "cpcon-publish"
	PostProcess      = "post-process"
	ServoNexus       = "servo-nexus"

	// Device base identifiers.
	Primary   = "primary"
	Companion = "companion"

	// Commonly used Dynamic Dependecy keys.
	ServiceAddress                      = "serviceAddress"
	CrosDutCacheServer                  = "crosDut.cacheServer"
	CrosDutDutAddress                   = "crosDut.dutAddress"
	CrosProvisionMetadataUpdateFirmware = "installRequest.metadata.updateFirmware"
	ProvisionStartupDut                 = "startupRequest.dut"
	ProvisionStartupDutServer           = "startupRequest.dutServer"
	TestRequestTestSuites               = "testRequest.testSuites"
	TestRequestPrimary                  = "testRequest.primary"
	TestRequestCompanions               = "testRequest.companions"
	RequestTestSuites                   = "req.params.testSuites"
	CacheServer                         = "cache-server"
	TestDynamicDeps                     = "test.dynamicDeps"
	HostIP                              = "host-ip"
	PcqQsAccount                        = "pcq"

	ATILink = "https://android-build.corp.google.com/test_investigate/invocation"

	// Build Experiments
	EnableXTSArchiverExperiment = "chromeos.cros_infra_config.enable_xts_archiver"

	// Injectables
	XTSArchiverResultsGCS = "xts-archiver-results-gcs"
	XTSArchiverAPFEGCS    = "xts-archiver-apfe-gcs"
)

Constants relating to dynamic dependency storage.

View Source
const (
	DefaultCrosFwProvisionSha = "36c32627ae54429d861d0df0fbc4d883170f01d83976ef5be9a0b4e719111aa0"
	DefaultPostProcessSha     = "e790463305397ba157cdfd836a23fc385d37cf9a72709f511a7e1973f64291c2"
)
View Source
const (
	GceMetadataHost = "GCE_METADATA_HOST"
	GceMetadataIP   = "GCE_METADATA_IP"
	GceMetadataRoot = "GCE_METADATA_ROOT"
)

GCE Metadata server environment variables.

View Source
const (
	ATPBlockingQuotaAccount = "atp-blocking"

	// DefaultQuotaPool is the main Swarming pool, and the default for leases.
	DefaultQuotaPool = "DUT_POOL_QUOTA"

	OSType = "os_type"
	// SchedukeTaskRequestKey is the key all Scheduke tasks are launched with.
	// Scheduke supports batch task creation, but we send individually for now, so
	// we use this key.
	SchedukeTaskRequestKey int64 = 1
)
View Source
const PlaceholderRegex = `\${[\w\d\-_.]+}`

PlaceholderRegex provides the format for how to find placeholders within the dynamic updates. Placeholders take the form of `${<placeholder>}` in which the named placeholder is wrapped by `${}`

The only valid characters for the placeholder will be a combination of any letter, any number, and the `-` and `_` special characters.

View Source
const (

	// SchedukeDevPool is the pool that the Scheduke dev instance schedules on.
	SchedukeDevPool = "schedukeTest"
)
View Source
const (

	// SchedukeTaskKey is the key used for a singleton Scheduke task request in
	// request/response protos.
	SchedukeTaskKey = 1
)
View Source
const StdFormat = `[%{level:.1s}%{time:2006-01-02T15:04:05.000000Z07:00} ` +
	`%{pid} 0 %{shortfile}] %{message}`

StdFormat is a preferred logging format to use.

It is compatible with logging format used by luci-py. The zero after %{pid} is "thread ID" which is unavailable in go.

View Source
const StdFormatWithColor = `%{color}[%{level:.1s}%{time:2006-01-02T15:04:05.000000Z07:00} ` +
	`%{pid} 0 %{shortfile}]%{color:reset} %{message}`

StdFormatWithColor is same as StdFormat, except with fancy colors.

Use it when logging to terminal. Note that StdConfig will pick it automatically if it detects that given io.Writer is an os.File and it is a terminal. See PickStdFormat().

View Source
const (
	StepKey = "build.step"
)

Variables

View Source
var (
	PrimaryDevice            = NewPrimaryDeviceIdentifier().GetDevice()
	CompanionDevices         = NewCompanionDeviceIdentifier("all").GetDevice()
	CompanionDevicesMetadata = NewCompanionDeviceIdentifier("all").GetDeviceMetadata()
)
View Source
var (
	TtcpContainerName                    = "cros-ddd-filter" // ttcp-demo
	LegacyHWContainerName                = "cros-legacy-hw-filter"
	ProvisionContainerName               = "provision-filter"
	TestFinderContainerName              = "cros-test-finder"
	UseFlagFilterContainerName           = "use_flag_filter"
	PreProcessFilterContainerName        = "pre_process_filter"
	AutoVMTestShifterFilterContainerName = "autovm_test_shifter_filter"
	PartnerStagingContainerName          = "partner-staging"

	// DefaultKarbonFilterNames defines Default karbon filters (SetDefaultFilters may add/remove)
	DefaultKarbonFilterNames = []string{TestFinderContainerName, ProvisionContainerName, hwPlaceHolder}

	// DefaultKoffeeFilterNames defines Default koffee filters (SetDefaultFilters may add/remove)
	// Deprecated: Falls under KarbonFilters.
	DefaultKoffeeFilterNames = []string{}
)
View Source
var (
	AnyRegex = regexp.MustCompile(`^ANY\((?<type>.+)\)=`)
)
View Source
var BotCountCache sync.Map
View Source
var ContainerMetadataCache sync.Map

ContainerMetadataCache already fetched container metadata info from gcs

View Source
var ErrBucketNotExist = errors.New("bucket does not exist")
View Source
var ErrObjectNotExist = errors.New("object does not exist")

GerritAuthScopes provides auth scopes to authorize to Gerrit.

View Source
var (
	GlobalNonInfraError error
)
View Source
var GlobalTempDir = os.Getenv("TEMPDIR")

Functions

func Abandon

func Abandon(ctx context.Context, authOpts auth.Options, deviceNames []string, taskStateIDs []int64, dev bool) error

Abandon sends a cancellation request to Scheduke for the given device names, releasing all leased devices for the current user if no devices are specified.

func AddFileContentsToLog

func AddFileContentsToLog(
	ctx context.Context,
	fileName string,
	rootDir string,
	msgToAdd string,
	writer io.Writer) error

AddFileContentsToLog adds contents of the file of fileName to log

func AddLinksToStepSummaryMarkdown

func AddLinksToStepSummaryMarkdown(
	step *build.Step,
	testhausURL, gcsLink, antsInvocationID string, isProd bool)

AddLinksToStepSummaryMarkdown adds provided links to provided step summary.

func AddTestServiceContainerToImages

func AddTestServiceContainerToImages(images map[string]*buildapi.ContainerImageInfo, name, digest string)

AddTestServiceContainerToImages Set name within images to be a test service container with given name and digest.

func AnyStringInGerritList

func AnyStringInGerritList(ctx context.Context, c clientThatSendsRequests, list []string, listURL string, pools []string) (bool, error)

AnyStringInGerritList checks for any overlap between the given list of strings, and the list at the given Gerrit URL.

func BBUrl

func BBUrl(builderID *buildbucketpb.BuilderID, bbID int64) string

BBUrl returns the Buildbucket URL of the task.

func BatchSet

func BatchSet(ctx context.Context, collection *firestore.CollectionRef, client *firestore.Client, items []*FirestoreItem, opts ...firestore.SetOption) ([]*firestore.BulkWriterJob, error)

func CIPDPackageDef

func CIPDPackageDef(packageTemplate, version string) ensure.PackageDef

func CheckIfFieldDefinitionExists

func CheckIfFieldDefinitionExists(msg proto.Message, fieldName string) (bool, error)

CheckIfFieldDefinitionExists checks if a field definition exist in the provided msg type

func CheckIfFileExists

func CheckIfFileExists(filePath string) error

CheckIfFileExists checks if file exists at the provided path.

func ConnectWithService

func ConnectWithService(ctx context.Context, serverAddress string) (*grpc.ClientConn, error)

ConnectWithService connects with the service at the provided server address.

func ConstructCtpFilters

func ConstructCtpFilters(ctx context.Context, defaultFilterNames []string, contMetadataMap map[string]*buildapi.ContainerImageInfo, filtersToAdd []*api.CTPFilter, build int) ([]*api.CTPFilter, error)

ConstructCtpFilters constructs default and non-default ctp filters.

func ConstructKey

func ConstructKey(board string, model string, variant string) string

func ConvertBuilderNameToVM

func ConvertBuilderNameToVM(originalBuilderName string) string

ConvertBuilderNameToVM converts the original test runner name to corresponding name of the VMLab version. See configs at http://shortn/_86vxOQ0XC6 test_runner[-env] -> test_runner_gce[-env]

func CreateAuthClient

func CreateAuthClient(
	ctx context.Context,
	authOpts auth.Options) (*http.Client, error)

CreateAuthClient creates new auth client.

func CreateCIPDClient

func CreateCIPDClient(
	ctx context.Context,
	authOpts auth.Options,
	host string,
	root string) (cipd.Client, error)

CreateCIPDClient creates new cipd client.

func CreateCTPDefaultWithContainerName

func CreateCTPDefaultWithContainerName(name string, digest string, build int) (*api.CTPFilter, error)

func CreateCTPFilterWithContainerName

func CreateCTPFilterWithContainerName(ctx context.Context, name string, contMetadataMap map[string]*buildapi.ContainerImageInfo, build int, buildCheck bool) (*api.CTPFilter, error)

CreateCTPFilterWithContainerName creates ctp filter for provided container name through provided container metadata.

func CreateContainerRequest

func CreateContainerRequest(requestedFilter *api.CTPFilter, build int) *api.ContainerRequest

CreateContainerRequest creates container request from provided ctp filter.

func CreateImagePath

func CreateImagePath(i *buildapi.ContainerImageInfo) (string, error)

CreateImagePath creates image path from container image info. Ex: us-docker.pkg.dev/cros-registry/test-services/cros-provision:<tag>

func CreateNewSwarmingService

func CreateNewSwarmingService(ctx context.Context) (*swarm_v1.Service, error)

CreateNewSwarmingService creates new swarming service.

func CreateRegistryName

func CreateRegistryName(i *buildapi.ContainerImageInfo) (string, error)

CreateRegistryName creates the Registry name used for authing to docker.

func CreateStepWithStatus

func CreateStepWithStatus(
	ctx context.Context,
	stepName string,
	summary string,
	isFailure bool,
	failParentStep bool) (err error)

CreateStepWithStatus creates a new step and sets step status based on provided flags. If failParent is true, the returned error will have build failure status attached to it for caller to bubble up appropriately.

func CreateTTCPContainerRequest

func CreateTTCPContainerRequest(requestedFilter *api.CTPFilter) *api.ContainerRequest

CreateTTCPContainerRequest creates container request from provided ctp filter. TODO (azrahman): Merge this into a generic container request creator that will work for all containers.

func CreateTempDir

func CreateTempDir(ctx context.Context, tempDirPattern string) (tempDir string, err error)

CreateTempDir creates temp dir in global TEMPDIR(luci for builders) location.

func CreateTestServicesContainer

func CreateTestServicesContainer(name, digest string) *buildapi.ContainerImageInfo

CreateTestServicesContainer create container with provided name and digest, setting repository to the hostname `us-docker.pkg.dev` and project `cros-registry/test-services`.

func CreateUniquePrefixedName

func CreateUniquePrefixedName(pattern string) string

CreateUniquePrefixedName creates a unique name with provided pattern

func Decompress

func Decompress(from string) ([]byte, error)

func DockerEnvVarsToPreserve

func DockerEnvVarsToPreserve() []string

DockerEnvVarsToPreserve gets all env vars that are required for hw test execution configs.

func DownloadFile

func DownloadFile(ctx context.Context, client *storage.Client, gsURL, destLocalPath string) error

DownloadFile downloads a file from a designated gsURL to a given path on the local file system. If the bucket does not exist, returns ErrBucketNotExist. If the object does not exist, returns ErrObjectNotExist.

func DownloadGcsFileAsLocalFile

func DownloadGcsFileAsLocalFile(ctx context.Context, gcsPath string, localFilePath string, clientOpts ...option.ClientOption) error

DownloadGcsFileAsLocalFile downloads gcs file as specific local file if it doesn't exist.

func DownloadGcsFileToLocal

func DownloadGcsFileToLocal(ctx context.Context, gcsPath string, tempRootDir string) (string, error)

DownloadGcsFileToLocal downloads gcs file to local if it doesn't exist.

func DutModelFromDut

func DutModelFromDut(dut *labapi.Dut) *labapi.DutModel

DutModelFromDut gets dutModel from provided dut.

func EncodeAnyObj

func EncodeAnyObj(anyObj any) (string, error)

EncodeAnyObj encodes any type object using URL-safe base64 json encoding

func EnsureCIPDPackage

func EnsureCIPDPackage(
	ctx context.Context,
	client cipd.Client,
	authOpts auth.Options,
	host string,
	packageTemplate string,
	version string,
	subdir string) (*cipd.Actions, error)

EnsureCIPDPackage ensures the provided cipd package.

func EnsureCIPDPackages

func EnsureCIPDPackages(
	ctx context.Context,
	client cipd.Client,
	authOpts auth.Options,
	host string,
	subdir string,
	cipdPackages ...ensure.PackageDef) (*cipd.Actions, error)

func EstablishFirestoreConnection

func EstablishFirestoreConnection(ctx context.Context, firestoreDatabaseName, creds string) (client *firestore.Client, err error)

EstablishFirestoreConnection uses provided credentials to establish a connection to the test platform firestore database.

func ExtractBuildRNumber

func ExtractBuildRNumber(buildStr string) int

ExtractBuildRNumber takes any build string and extracts the major digits found within the R#. If no R number match found, return -1.

func ExtractModulesIfSubModulesProvided

func ExtractModulesIfSubModulesProvided(testCases []string) []string

func ExtractPrefixUntilDelimiter

func ExtractPrefixUntilDelimiter(str string, delimiter string) string

ExtractPrefixUntilDelimiter Extracts a prefix until a delimiter is found.

func FetchContainerInfoFromFirestore

func FetchContainerInfoFromFirestore(ctx context.Context, firestoreDatabaseName, creds, tag, name string) (containerInfo *api.ContainerInfo, err error)

func FetchContainerMetadata

func FetchContainerMetadata(ctx context.Context, containerGcsPath string) (*buildapi.ContainerMetadata, error)

FetchContainerMetadata retrieves the container metadata from the provided gcs path.

func FetchFilterFromFirestore

func FetchFilterFromFirestore(ctx context.Context, firestoreDatabaseName, creds, tag, name string) (filter *api.CTPFilter, err error)

func FetchFiltersFromFirestore

func FetchFiltersFromFirestore(ctx context.Context, creds, tag string) (filters []*api.CTPFilter, err error)

FetchFiltersFromFirestore grabs every filter stored within the the firestore database.

func FetchImageData

func FetchImageData(ctx context.Context, board string, gcsPath string) (map[string]*api.ContainerImageInfo, error)

FetchImageData fetches container image metadata from provided gcs path

func FindDirWithPrefix

func FindDirWithPrefix(dirPath, prefix string) (string, error)

FindDirWithPrefix walks the dirPath until it finds a dir with prefix.

func FindFile

func FindFile(ctx context.Context, fileName string, rootDir string) (string, error)

FindFile finds file path in rootDir of fileName

func FormatSwarmingTaskID

func FormatSwarmingTaskID(swarmingTaskID string) string

FormatSwarmingTaskID does... # A swarming task may have multiple attempts ("runs"). # The swarming task ID always ends in "0", e.g. "123456789abcdef0". # The corresponding runs will have IDs ending in "1", "2", etc., e.g. "123456789abcdef1". # All attempts should be recorded under same job ending with 0.

func GCPHTTPClient

func GCPHTTPClient(ctx context.Context, rpcOpts ...luciauth.RPCOption) (*http.Client, error)

GCPHTTPClient initializes an HTTP client for use in a GCP environment.

func GceMetadataEnvVars

func GceMetadataEnvVars() []string

GceMetadataEnvVars returns environment variables related to the GCE Metadata server. These should be set when making GCP requests from containers.

func GetAtpProjectID

func GetAtpProjectID(builderID *buildbucketpb.BuilderID) string

func GetBoardModelDims

func GetBoardModelDims(unit *api.SchedulingUnit) []string

GetBoardModelDims gets board, model dims from scheduling unit.

func GetBotCount

func GetBotCount(ctx context.Context, dims []string, swarmingService *swarm_v1.Service) (int64, error)

GetBotCount gets total bot count for provided dims. dims example: {"label-board:zork", "label-model:morphius", "dut_state:ready"}

func GetBotList

func GetBotList(ctx context.Context, dims []string, swarmingService *swarm_v1.Service, isBuysVal string, isDeadVal string, inMaintenanceVal string, quarantinedVal string) ([]*swarm_v1.SwarmingRpcsBotInfo, error)

GetBotList gets bot list for provided dims and properties. dims example: {"label-board:zork", "label-model:morphius", "dut_state:ready"}

func GetCftLocalServerAddress

func GetCftLocalServerAddress(ctx context.Context, metadataFilePath string, fileLog io.Writer) (string, error)

GetCftLocalServerAddress waits for the service metadata file and retrieves server address for localhost.

func GetCftServiceMetadataFromFile

func GetCftServiceMetadataFromFile(ctx context.Context, metadataFilePath string, fileLog io.Writer) (map[string]string, error)

GetCftServiceMetadataFromFile waits for the service metadata and returns metadata if found.

func GetContainerImageFromMap

func GetContainerImageFromMap(key string, imageMap map[string]*buildapi.ContainerImageInfo) (string, error)

GetContainerImageFromMap retrieves the container image from provided map.

func GetDefaultFilterContainerImageInfosMap

func GetDefaultFilterContainerImageInfosMap(ctx context.Context, creds, ctpVersion string, defaultFilterNames []string, contMetadataMap map[string]*buildapi.ContainerImageInfo, build int, firestoreDBName string) map[string]*buildapi.ContainerImageInfo

func GetDefaultFilters

func GetDefaultFilters(ctx context.Context, defaultFilterNames []string, contMetadataMap map[string]*buildapi.ContainerImageInfo, build int) ([]*api.CTPFilter, error)

GetDefaultFilters constructs ctp filters for provided default filters.

func GetFileContents

func GetFileContents(ctx context.Context, fileName string, rootDir string) ([]byte, error)

GetFileContents finds the file and return the file contents.

func GetFileContentsInMap

func GetFileContentsInMap(ctx context.Context, filePath string, contentSeparator string, writer io.Writer) (map[string]string, error)

GetFileContentsInMap returns a map of file contents where the contents on each line is separated by provided separator. Will return error if each line is not formatted like 'key<separator>value'. If writer provided, file contents will be written to writer simultaneously.

func GetFirestoreCollection

func GetFirestoreCollection(tag string) string

GetFirestoreCollection returns the collection name based on whether its the prod or staging environment.

func GetFlattenedTestCases

func GetFlattenedTestCases(ctpTestCases []*api.TestCase_Id) []string

func GetFreePort

func GetFreePort() uint16

GetFreePort finds an available port on the running OS to prevent collisions between services

func GetGcsClickableLink(gsURL string) string

GetGcsClickableLink constructs the gcs cliclable link from provided gs url.

func GetGcsURL

func GetGcsURL(gsRoot string) string

GetGcsURL gets gcs url where all the artifacts will be uploaded.

func GetHostIP

func GetHostIP() (string, error)

GetHostIP returns the IP address that is accessible from outside the host

func GetIPEndpoint

func GetIPEndpoint(serverAddress string) (*labapi.IpEndpoint, error)

GetIPEndpoint creates IpEndpoint from provided server address. Server address example: (address:port) -> localhost:8080.

func GetMajorBuildFromGCSPath

func GetMajorBuildFromGCSPath(gcsPath string) string

GetMajorBuildFromGCSPath parses the major build from gcs path

func GetMockedTestResultProto

func GetMockedTestResultProto() *artifactpb.TestResult

GetMockedTestResultProto returns a mock result proto that can be used for testing.

func GetPoolsFromURL

func GetPoolsFromURL(ctx context.Context, c clientThatSendsRequests, listURL string) ([]string, error)

GetPoolsFromURL fetches a gerrit url having csv pool values and returns the array of pools

func GetPrefixBasedOnDelim

func GetPrefixBasedOnDelim(str, delim string) string

func GetProductName

func GetProductName(dutModel *labapi.DutModel, botDims []*buildbucketpb.StringPair, build string) string

GetProductName gets the product/device name in the following format: <board>.<model>-<board_variant> expected by the XTS result pipeline. The board and model info is obtained from dutModel falling back to labels in botDims, and the board variant is extracted from the build. If any of the properties is missing, it will be left out of the product. TODO: b/379711782 - Verify and update this logic for AL

func GetServerAddress

func GetServerAddress(endpoint *labapi.IpEndpoint) string

GetServerAddress creates a string from provided IpEndpoint. Example: IpEndpoint{Address:localhost, port:8080} -> localhost:8080.

func GetServerAddressFromGetContResponse

func GetServerAddressFromGetContResponse(resp *testapi.GetContainerResponse) (string, error)

GetServerAddressFromGetContResponse gets the server address from get container response.

func GetTautoTestCaseNameOrDefault

func GetTautoTestCaseNameOrDefault(tcs []*skylab_test_runner.Result_Autotest_TestCase, defaultName string) string

func GetTesthausURL

func GetTesthausURL(invocationName string, gcsURL string) string

GetTesthausURL gets testhaus log viewer url based on the invocation name. If invocation name is empty, it constructs the URL based on gcs URL instead.

func GetURLPath

func GetURLPath(gsURL string) (string, error)

func GetValueFromRequestKeyvals

func GetValueFromRequestKeyvals(ctx context.Context, cftReq *skylab_test_runner.CFTTestRequest, ctrrReq *testapi.CrosTestRunnerDynamicRequest, key string) string

GetValueFromRequestKeyvals gets value from provided keyvals based on key.

func HTTPClient

func HTTPClient(ctx context.Context) (*http.Client, error)

HTTPClient creates a http client.

func IgnoreCancel

func IgnoreCancel(parent context.Context) context.Context

IgnoreCancel returns a new Context that takes its values from parent but ignores any cancelation or deadline on parent.

IgnoreCancel must only be used synchronously. To detach a Context for use in an asynchronous API, use Go instead.

You can create fail-safe cleanup functions in case the parent context is cancelled. Example:

func New(ctx context.Context, id string) (*Publisher, error) {
  client := buildClient(ctx)

  if err := validate(id); err != nil {
    client.Close(detach.IgnoreCancel(ctx))
    return nil, err
  }

  return &Publisher{client: client}, nil
}

func InitClient

func InitClient(ctx context.Context, projectID, databaseID string, opts ...option.ClientOption) (*firestore.Client, error)

InitClient returns a firestore client set to access the given project and database. A databaseID is required as the default database (default) requires a separate process.

func Inject

func Inject(receiver protoreflect.ProtoMessage, injectionPoint string, storage *InjectableStorage, injectionKey string) (err error)

Inject implements the logic for which Dependency Injection is based on. Dependency injection is the process in which an incoming ProtoMessage can have a placeholder replaced with a value found within some provided map[string]interface{} which contains all the exposed values for dependency injection.

Functionality: * Keys are split by "." * Keys should be camelCase * Keys can be a string or a number. Numbers would represent indexing an array. * If the injection_point is an array and the injectable is also an array of the same type, then it will override the array. * If the injection_point is an array and the injectable is not an array of the same type, then it will append into the array.

Example:

message Example {
	IpEndpoint endpoint = 1;
}

injectables := map[string]interface{}
injectables["example_endpoint"] = IpEndpoint {
	address: "localhost",
	port: 12345
}

receiver := Example {endpoint: {address: "localhost"}}

Inject(receiever, "endpoint.port", injectables, "example_endpoint.port")

func InjectDependencies

func InjectDependencies(receiver protoreflect.ProtoMessage, storage *InjectableStorage, deps []*api.DynamicDep) error

InjectDependencies handles loading the storage's injectables and injecting the dependencies into the receiver.

func InvocationSealed

func InvocationSealed(inv *androidbuildinternal.Invocation) bool

func IsAndroid

func IsAndroid(board string) bool

func IsAndroidURL

func IsAndroidURL(gsURL string) bool

func IsAnyTestFailure

func IsAnyTestFailure(testResults []*testapi.TestCaseResult) bool

IsAnyTestFailure returns if there is any failed tests in test results

func IsCqRun

func IsCqRun(testSuite []*testapi.TestSuite) bool

IsCqRun determines if the current execution is a CQ run

func IsCros

func IsCros(board string) bool

func IsDev

func IsDev(builderID *buildbucketpb.BuilderID) bool

func IsDevBoard

func IsDevBoard(board string) bool

func IsLedRun

func IsLedRun(builderID *buildbucketpb.BuilderID) bool

func IsProd

func IsProd(builderID *buildbucketpb.BuilderID) bool

func IsStaging

func IsStaging(builderID *buildbucketpb.BuilderID) bool

func IsSupportedVMBoard

func IsSupportedVMBoard(board string) bool

func ListToJSON

func ListToJSON(list *list.List) []byte

ListToJSON creates json bytes from provided list.

func LocateFile

func LocateFile(candidates []string) (string, error)

LocateFile locates file from multiple possible locations where the file may exist. Return the located file as soon as the first one is found, or an error if none of the candidates exists.

func LogExecutionDetails

func LogExecutionDetails(ctx context.Context, step *build.Step, cmds []string)

LogExecutionDetails logs provided cmds to build step.

func LogWarningIfErr

func LogWarningIfErr(ctx context.Context, err error)

func MakeDefaultFilters

func MakeDefaultFilters(ctx context.Context, suiteReq *api.SuiteRequest, experiments []string, isPartner, isAlRun bool) []string

MakeDefaultFilters sets/appends proper default filters; in their required order.

func NewBBClient

func NewBBClient(ctx context.Context) (buildbucketpb.BuildsClient, error)

NewBBClient creates new bb client.

func NewStorageClientWithDefaultAccount

func NewStorageClientWithDefaultAccount(ctx context.Context, clientOpts ...option.ClientOption) (*storage.Client, error)

func PatchContainerMetadata

func PatchContainerMetadata(images map[string]*buildapi.ContainerImageInfo, buildStr string)

func PickStdFormat

func PickStdFormat(w io.Writer) string

PickStdFormat returns StdFormat for non terminal-backed files or StdFormatWithColor for io.Writers that are io.Files backed by a terminal.

Used by default StdConfig.

func ProcessContainerPath

func ProcessContainerPath(ctx context.Context, commonParams *server.CommonFilterParams, creds, path, firestoreName string) (processedPath string, err error)

ProcessContainerPath processes a provided path and determines whether it needs to pull from the firestoreDatabase provided.

func ProcessDoneLro

func ProcessDoneLro(ctx context.Context, lro *longrunning.Operation) (*anypb.Any, error)

ProcessDoneLro process a long running operation that is done and parses the result to a proto. Don't use this, use WaitLro instead.

func PublishToPubSub

func PublishToPubSub(ctx context.Context, client *pubsub.Client, topicID string, msgBytes []byte) (string, error)

PublishToPubSub publishes provided input to provided topic and client

func PublishToTestJobEventPubSub

func PublishToTestJobEventPubSub(ctx context.Context, client *pubsub.Client, msg *TestJobEventMessage) (string, error)

PublishToTestJobEventPubSub publishes provided test job event msg to ATP pubsub

func Read

func Read(ctx context.Context, client *storage.Client, gsObject GSObject, destFilePath string) (retErr error)

Read downloads a file from GCS to the given local path. If the bucket does not exist in GCS, the method returns ErrBucketNotExist. If the object does not exist in GCS, the method returns ErrObjectNotExist.

func ReadProtoJSONFile

func ReadProtoJSONFile(ctx context.Context, filePath string, outputProto proto.Message) (retErr error)

ReadProtoJSONFile reads a protocol buffer from the given file.

func ResolvePlaceholders

func ResolvePlaceholders(str string, lookup PlaceholderLookup) string

ResolvePlaceholders searches the provided string for any placeholders and replaces them with the values corresponding in the lookup table.

Placeholders should be a combination of letters, digits, hyphens, and underscores.

func RunCommand

func RunCommand(ctx context.Context, cmd *exec.Cmd, cmdName string, input proto.Message, block bool) (stdout string, stderr string, err error)

RunCommand supports running any cli command

func RunCommandWithCustomWriter

func RunCommandWithCustomWriter(ctx context.Context, cmd *exec.Cmd, cmdName string, writer io.Writer) error

RunCommandWithCustomWriter runs a command with custom writer

func SanitizeGCSPrefix

func SanitizeGCSPrefix(prefix string) string

SanitizeGCSPrefix sanitizes the GCS path prefix to ensure it does not contain trailing "/".

func ShortBBUrl

func ShortBBUrl(bbID int64) string

func ShouldUseDM

func ShouldUseDM(ctx context.Context, c clientThatSendsRequests, pool string, dmPools ...string) (bool, error)

ShouldUseDM returns a bool indicating whether a task request with the given pool should enable the Device Manager experiment.

func ShouldUseScheduke

func ShouldUseScheduke(ctx context.Context, pool string, authOpts auth.Options) (bool, error)

ShouldUseScheduke returns a bool indicating whether a lease request in the pool should use this Scheduke API.

func SilentLoginHTTPClient

func SilentLoginHTTPClient(ctx context.Context, authOpts auth.Options) (*http.Client, error)

SilentLoginHTTPClient initializes a silent-login HTTP client with the given auth options. It is not compatible with code running in an App Engine environment.

func StreamLogAsync

func StreamLogAsync(ctx context.Context, rootDir string, writer io.Writer) (chan<- bool, *sync.WaitGroup, error)

StreamLogAsync starts an async reading of log file.

func TestRunnerBuilderID

func TestRunnerBuilderID(conf *config.Config) *buildbucketpb.BuilderID

TestRunnerBuilderID returns builderid for test_runner.

func TranslateSliceToInterface

func TranslateSliceToInterface(slice interface{}) []interface{}

TranslateSliceToInterface expects a slice object in. The slice then gets forcefully casted into []interface{} which is a generic slice form that can be interacted with by dependency injection.

func ValidateTestPlans

func ValidateTestPlans(input *api.InternalTestplan, output *api.InternalTestplan) error

func WaitDutVMBoot

func WaitDutVMBoot(ctx context.Context, ip string)

WaitDutVMBoot uses a blocking SSH call to wait for a DUT VM to become ready. It doesn't care about the output. If the connection is successful, it executes `true` that returns nothing. If permission denied, it means SSH is ready. If timeout, we leave it to the following step to detect the error.

func WaitLro

WaitLro waits for a long running operation to complete and parses the result to a proto

func WriteAnyObjectToStepLog

func WriteAnyObjectToStepLog(ctx context.Context, step *build.Step, obj any, logText string)

WriteAnyObjectToStepLog writes provided obj to build step.

func WriteContainerLogToStepLog

func WriteContainerLogToStepLog(ctx context.Context, container interfaces.ContainerInterface, step *build.Step, logTitle string) error

WriteContainerLogToStepLog writes container log contents to step log.

func WriteFileContentsToStepLog

func WriteFileContentsToStepLog(ctx context.Context, step *build.Step, fileName string, rootDir string, logText string) error

WriteFileContentsToStepLog writes provided fileName contents at rootDir to build step log.

func WriteFromFile

func WriteFromFile(
	ctx context.Context,
	fi *os.File,
	writer io.Writer,
	taskDone <-chan bool,
	wg *sync.WaitGroup,
	poll time.Duration)

WriteFromFile writes contents from a file to a provided writer.

func WriteProtoToJSONFile

func WriteProtoToJSONFile(
	ctx context.Context,
	dirPath string,
	fileName string,
	inputProto proto.Message) (string, error)

WriteProtoToJSONFile writes provided proto to a json file.

func WriteProtoToStepLog

func WriteProtoToStepLog(ctx context.Context, step *build.Step, proto proto.Message, logText string)

WriteProtoToStepLog writes provided proto to build step.

func WriteStringToStepLog

func WriteStringToStepLog(ctx context.Context, step *build.Step, data, logText string)

WriteStringToStepLog writes provided string to build step.

func WriteToExistingFile

func WriteToExistingFile(ctx context.Context, filePath string, contents string) error

WriteToExistingFile writes provided contents to existing file.

Types

type BuildMessage

type BuildMessage struct {
	AttemptId         string `json:"attemptId,omitempty"`
	Branch            string `json:"branch,omitempty"`
	BuildAlias        string `json:"buildAlias,omitempty"`
	BuildFlavor       string `json:"buildFlavor,omitempty"`
	BuildId           string `json:"buildId,omitempty"`
	BuildOs           string `json:"buildOs,omitempty"`
	BuildPlatform     string `json:"buildPlatform,omitempty"`
	BuildTarget       string `json:"buildTarget,omitempty"`
	BuildType         string `json:"buildType,omitempty"`
	CreationTimestamp string `json:"creationTimestamp,omitempty"`
	// ForceSendFields is a list of field names (e.g. "AttemptId") to
	// unconditionally include in API requests. By default, fields with empty or
	// default values are omitted from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
	// details.
	ForceSendFields []string `json:"-"`
	// NullFields is a list of field names (e.g. "AttemptId") to include in API
	// requests with the JSON null value. By default, fields with empty values are
	// omitted from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
	NullFields []string `json:"-"`
}

BuildMessage: Build message. This is a map to the build info comes from the build pubsub. It includes a build's information.

func (*BuildMessage) MarshalJSON

func (s *BuildMessage) MarshalJSON() ([]byte, error)

type ContainerInfoItem

type ContainerInfoItem struct {
	TimeRecord         time.Time
	RepositoryHostname string
	RepositoryProject  string
	Digest             string
	ContainerName      string
}

ContainerInfoItem represents an Uprev record for containers built during this program's execution.

func FetchContainerInfoFromFirestoreDoc

func FetchContainerInfoFromFirestoreDoc(ctx context.Context, docRef *firestore.DocumentRef) []*ContainerInfoItem

FetchContainerInfoFromFirestoreDoc grabs the ContainerInfoItems from the provided firestore document reference.

func NewContainerInfoItem

func NewContainerInfoItem(host, project, digest, name string) *ContainerInfoItem

type DeviceIdentifier

type DeviceIdentifier struct {
	ID string
}

func DeviceIdentifierFromString

func DeviceIdentifierFromString(str string) *DeviceIdentifier

func NewCompanionDeviceIdentifier

func NewCompanionDeviceIdentifier(board string) *DeviceIdentifier

func NewPrimaryDeviceIdentifier

func NewPrimaryDeviceIdentifier() *DeviceIdentifier

func (*DeviceIdentifier) AddPostfix

func (id *DeviceIdentifier) AddPostfix(postfix string) *DeviceIdentifier

func (*DeviceIdentifier) GetCrosDutServer

func (id *DeviceIdentifier) GetCrosDutServer() string

func (*DeviceIdentifier) GetDevice

func (id *DeviceIdentifier) GetDevice(innerValueCallChain ...string) string

func (*DeviceIdentifier) GetDeviceMetadata

func (id *DeviceIdentifier) GetDeviceMetadata(innerValueCallChain ...string) string

func (*DeviceIdentifier) GetUpdateFirmware

func (id *DeviceIdentifier) GetUpdateFirmware() string

type DeviceInfo

type DeviceInfo struct {
	Name     string
	LabSetup *ufspb.MachineLSE
	Machine  *ufspb.Machine
}

DeviceInfo contains details about the physical lab setup and machine of a particular Swarming device.

func UFSDeviceInfo

func UFSDeviceInfo(ctx context.Context, deviceName string, authOpts auth.Options) (*DeviceInfo, error)

UFSDeviceInfo returns device information from UFS for the device with the given name.

type Environment

type Environment int
const (
	Unknown Environment = iota
	Prod
	Staging
	Dev
)

func GetCTPEnvironment

func GetCTPEnvironment(builderID *buildbucketpb.BuilderID) Environment

func (Environment) String

func (e Environment) String() string

type FirestoreItem

type FirestoreItem struct {
	DocName string
	Datum   interface{}
}

FirestoreItem wraps the interface item with it's intended document name.

type GSObject

type GSObject struct {
	Bucket string
	Object string
}

GSObject is a storage metadata for remote file

func ParseGSURL

func ParseGSURL(gsURL string) (GSObject, error)

type InjectablePlaceholderLookup

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

func (*InjectablePlaceholderLookup) Get

func (lookup *InjectablePlaceholderLookup) Get(key string) (val string, ok bool)

type InjectableStorage

type InjectableStorage struct {

	// Cached Injectables map
	Injectables map[string]interface{}
	// contains filtered or unexported fields
}

InjectableStorage is an object that dictates how to interact with the dictionary of injectable objects for dependency injection.

func NewInjectableStorage

func NewInjectableStorage() *InjectableStorage

func (*InjectableStorage) Get

func (storage *InjectableStorage) Get(key string) (interface{}, error)

Get searches through the Storage and returns an error if the object is not found.

func (*InjectableStorage) LoadInjectables

func (storage *InjectableStorage) LoadInjectables() error

LoadInjectables takes the dictionary of injectable objects and converts them into json interactable `interface{}`s.

func (*InjectableStorage) LogStorageToBuild

func (storage *InjectableStorage) LogStorageToBuild(ctx context.Context, buildState *build.State)

LogStorageToBuild writes the json structure of the storage as a log in a step.

func (*InjectableStorage) Set

func (storage *InjectableStorage) Set(key string, obj interface{}) error

Set stores any proto workable object into the storage.

type KeyValuesMessage

type KeyValuesMessage struct {
	Key    string   `json:"key,omitempty"`
	Values []string `json:"values,omitempty"`
	// ForceSendFields is a list of field names (e.g. "Key") to unconditionally
	// include in API requests. By default, fields with empty or default values are
	// omitted from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
	// details.
	ForceSendFields []string `json:"-"`
	// NullFields is a list of field names (e.g. "Key") to include in API requests
	// with the JSON null value. By default, fields with empty values are omitted
	// from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
	NullFields []string `json:"-"`
}

KeyValuesMessage: Key values message.

func (*KeyValuesMessage) MarshalJSON

func (s *KeyValuesMessage) MarshalJSON() ([]byte, error)

type LeaseInfo

type LeaseInfo struct {
	Device *DeviceInfo
	Build  *buildbucketpb.Build
}

LeaseInfo contains details about a particular lease of a Swarming device.

func Lease

func Lease(ctx context.Context, authOpts auth.Options, dims map[string][]string, mins int64, leaseIDChan chan int64) (*LeaseInfo, bool, error)

Lease leases a device from Scheduke and returns information about the device, and a bool indicating whether full device information was retrieved.

func Leases

func Leases(ctx context.Context, authOpts auth.Options, dev bool) ([]*LeaseInfo, bool, error)

Leases retrieves device information for each in-flight lease for the current user, and a bool indicating whether full device information was retrieved.

type LoggerConfig

type LoggerConfig struct {
	Out    io.Writer   // where to write the log to, required
	Format string      // how to format the log, default is PickStdFormat(Out)
	Logger *gol.Logger // if set, will be used as is, overrides everything else
	// contains filtered or unexported fields
}

func (*LoggerConfig) DumpStepsToFolder

func (lc *LoggerConfig) DumpStepsToFolder(basePath string)

DumpStepsToFolder cleans and writes the step information gathered during execution to a designated path.

func (*LoggerConfig) NewLogger

func (lc *LoggerConfig) NewLogger(c context.Context, lctx *logging.LogContext) logging.Logger

NewLogger returns new go-logging based logger bound to the given context.

func (*LoggerConfig) Use

Use registers go-logging based logger as default logger of the context.

type PlaceholderLookup

type PlaceholderLookup interface {
	Get(key string) (val string, ok bool)
}

PlaceholderLookup defines an interface for getting a value that resolves the placeholder key.

type ResourceUsage

type ResourceUsage struct {
	// Possible values:
	//   "CPU"
	//   "DEVICE"
	//   "DISK_IO"
	//   "UNKNOWN"
	Measure string `json:"measure,omitempty"`
	Value   int64  `json:"value,omitempty"`
	// ForceSendFields is a list of field names (e.g. "Measure") to unconditionally
	// include in API requests. By default, fields with empty or default values are
	// omitted from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
	// details.
	ForceSendFields []string `json:"-"`
	// NullFields is a list of field names (e.g. "Measure") to include in API
	// requests with the JSON null value. By default, fields with empty values are
	// omitted from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
	NullFields []string `json:"-"`
}

ResourceUsage: ResourceUsage message. It contains information regarding the usage of a specific resource.

func (*ResourceUsage) MarshalJSON

func (s *ResourceUsage) MarshalJSON() ([]byte, error)

type SchedukeClient

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

func NewSchedukeClientForCLI

func NewSchedukeClientForCLI(ctx context.Context, dev bool, authOpts auth.Options) (*SchedukeClient, error)

NewSchedukeClientForCLI returns a Scheduke client that can be called from a CLI that talks to the given Scheduke environment (dev/prod), and uses the given auth info to determine whether the CLI is being used by a human or not.

func NewSchedukeClientForGCP

func NewSchedukeClientForGCP(ctx context.Context, pool string) (*SchedukeClient, error)

NewSchedukeClientForGCP returns a Scheduke client that can be called from a GCP environment.

func NewSchedukeClientForLUCIExe

func NewSchedukeClientForLUCIExe(ctx context.Context, pool string) (*SchedukeClient, error)

NewSchedukeClientForLUCIExe returns a Scheduke client that can be called from luciexe code running on a Buildbucket build.

func (*SchedukeClient) AdminTaskReqToSchedukeReq

func (s *SchedukeClient) AdminTaskReqToSchedukeReq(bbReq *buildbucketpb.ScheduleBuildRequest, deviceName, pool string) (*schedukeapi.KeyedTaskRequestEvents, error)

AdminTaskReqToSchedukeReq converts a ScheduleBuildRequest for a lab admin task BB build to a Scheduke request.

func (*SchedukeClient) CancelTasks

func (s *SchedukeClient) CancelTasks(taskStateIDs []int64, users, deviceNames []string) error

CancelTasks calls Scheduke to cancel tasks for the given task state IDs, users, and/or device names.

func (*SchedukeClient) LeaseRequest

func (s *SchedukeClient) LeaseRequest(schedukeDims *schedukeapi.SwarmingDimensions, pool, deviceName, user string, mins int64, t time.Time) (*schedukeapi.KeyedTaskRequestEvents, error)

LeaseRequest constructs a keyed TaskRequestEvent to request a lease from Scheduke with the given dimensions and lease length in minutes, for the given user, at the given time.

func (*SchedukeClient) ReadTaskStates

func (s *SchedukeClient) ReadTaskStates(taskStateIDs []int64, users, deviceNames []string) (*schedukeapi.ReadTaskStatesResponse, error)

ReadTaskStates calls Scheduke to read task states for the given task state IDs, users, and/or device names.

func (*SchedukeClient) ScheduleExecution

ScheduleExecution will schedule TR executions via scheduke.

func (*SchedukeClient) TestRunnerBBReqToSchedukeReq

func (s *SchedukeClient) TestRunnerBBReqToSchedukeReq(bbReq *buildbucketpb.ScheduleBuildRequest) (*schedukeapi.KeyedTaskRequestEvents, error)

TestRunnerBBReqToSchedukeReq converts a ScheduleBuildRequest for a test_runner BB build to a Scheduke request.

type Step

type Step struct {
	Name     string
	Order    int
	Depth    int
	Status   string
	Logs     map[string]*StepLog
	SubSteps map[string]*Step
	Parent   *Step
}

type StepLog

type StepLog struct {
	Name string
	Log  *bytes.Buffer
}

type SwarmingBotProvider

type SwarmingBotProvider string

SwarmingBotProvider is the host that runs a swarming bot, e.g. GCE or Drone.

const (

	// List of supported SwarmingBotProvider types.
	// TODO(mingkong): consider moving these values to a proto enum
	BotProviderGce     SwarmingBotProvider = "GCE"
	BotProviderDrone   SwarmingBotProvider = "Drone"
	BotProviderPVS     SwarmingBotProvider = "PVS"
	BotProviderUnknown SwarmingBotProvider = "Unknown"
)

func GetBotProvider

func GetBotProvider() SwarmingBotProvider

GetBotProvider detects the SwarmingBotProvider by examining env variable.

type TaskIdentifier

type TaskIdentifier struct {
	ID string
}

func NewTaskIdentifier

func NewTaskIdentifier(taskBaseIdentifier string) *TaskIdentifier

func (*TaskIdentifier) AddDeviceID

func (id *TaskIdentifier) AddDeviceID(deviceID *DeviceIdentifier) *TaskIdentifier

func (*TaskIdentifier) GetRPCRequest

func (id *TaskIdentifier) GetRPCRequest(rpc string, innerValueCallChain ...string) string

func (*TaskIdentifier) GetRPCResponse

func (id *TaskIdentifier) GetRPCResponse(rpc string, innerValueCallChain ...string) string

type TestBenchMessage

type TestBenchMessage struct {
	Attributes []string `json:"attributes,omitempty"`
	Cluster    string   `json:"cluster,omitempty"`
	// Properties: Key values message.
	Properties []*KeyValuesMessage `json:"properties,omitempty"`
	RunTarget  string              `json:"runTarget,omitempty"`
	// Possible values:
	//   "ANDROIDX_FTL"
	//   "ANDROIDX_PLAYGROUND"
	//   "ANDROID_EMU"
	//   "ANDROID_G3"
	//   "AUTOTEST"
	//   "BATCAVE"
	//   "CTP"
	//   "MOBILE_HARNESS"
	//   "NO_OP"
	//   "PIXEL_CAMERA_FLEXTAPE"
	//   "PIXEL_CAMERA_PRESIL"
	//   "SWARMING"
	//   "TRADEFED"
	//   "UNITY_INTEGRATION"
	//   "UNKNOWN_RUNNER"
	//   "VERSIONED_TF"
	Scheduler string `json:"scheduler,omitempty"`
	// ForceSendFields is a list of field names (e.g. "Attributes") to
	// unconditionally include in API requests. By default, fields with empty or
	// default values are omitted from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
	// details.
	ForceSendFields []string `json:"-"`
	// NullFields is a list of field names (e.g. "Attributes") to include in API
	// requests with the JSON null value. By default, fields with empty values are
	// omitted from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
	NullFields []string `json:"-"`
}

TestBenchMessage: TestBench message. TestBench is where actually the test should be run.

func (*TestBenchMessage) MarshalJSON

func (s *TestBenchMessage) MarshalJSON() ([]byte, error)

type TestConfigMessage

type TestConfigMessage struct {
	// Args: Key values message.
	Args               []*KeyValuesMessage `json:"args,omitempty"`
	Command            string              `json:"command,omitempty"`
	Name               string              `json:"name,omitempty"`
	PrimaryBuildDevice string              `json:"primaryBuildDevice,omitempty"`
	RunCount           int64               `json:"runCount,omitempty"`
	Shards             int64               `json:"shards,omitempty"`
	// ForceSendFields is a list of field names (e.g. "Args") to unconditionally
	// include in API requests. By default, fields with empty or default values are
	// omitted from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
	// details.
	ForceSendFields []string `json:"-"`
	// NullFields is a list of field names (e.g. "Args") to include in API requests
	// with the JSON null value. By default, fields with empty values are omitted
	// from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
	NullFields []string `json:"-"`
}

TestConfigMessage: TestConfig message. TestConfig is the basic config for a TestJob.

func (*TestConfigMessage) MarshalJSON

func (s *TestConfigMessage) MarshalJSON() ([]byte, error)

type TestJobEventMessage

type TestJobEventMessage struct {
	DeviceLostDetected int64    `json:"deviceLostDetected,omitempty"`
	EventTimestamp     string   `json:"eventTimestamp,omitempty"`
	FailedTestCount    int64    `json:"failedTestCount"`
	FailedTestRunCount int64    `json:"failedTestRunCount"`
	ResultLinks        []string `json:"resultLinks,omitempty"` // Deprecated/Unused
	// Possible values:
	//   "CANCELED"
	//   "COMPLETED"
	//   "ERROR"
	//   "FATAL"
	//   "QUEUED"
	//   "RUNNING"
	//   "UNKNOWN"
	State   string `json:"state,omitempty"`
	Summary string `json:"summary,omitempty"`
	// TestJob: TestJob message. TestJob is a test job running in the test runner.
	// This message has information about test job's config, state and result. A
	// TestJob can be executed by creating one or multiple TestTasks based on the
	// test's configuration. Attributes: id: a test job ID. user: an email of a
	// user who created the test job. runner: a test job runner type. test: a
	// TestConfigMessage object. build: a BuildMessage object. testBench: a
	// TestBenchMessage object. testJobState: a state of a test job.
	// creationTimestamp: time when a test job was created. startTimestamp: time
	// when a test job was started. updateTimestamp: time when a test job was last
	// updated. endTimestamp: time when a test job was ended. tasks: a list of
	// TestTaskMessage objects. jobInfo: extra information about a test job.
	// priority: a priority of a test job. Must be in range [0, 1000].
	// runnerOptions: test runner options. context: context for the test job
	// context has gerrit_cl and test_result_id. stateReason: a state reason of a
	// test job when error/cancel happen. extra_builds: a list of extra builds.
	// plugin_data: a list of KeyValuesMessage for plugin data. utilization: a list
	// of ResourceUsage resultLinks: a list of result links
	TestJob         *TestJobMessage `json:"testJob,omitempty"`
	TestJobId       string          `json:"testJobId,omitempty"`
	TotalRunTimeSec int64           `json:"totalRunTimeSec,omitempty"`
	TotalTestCount  int64           `json:"totalTestCount"`
	// Possible values:
	//   "STATE_CHANGED"
	Type string `json:"type,omitempty"`
	// ForceSendFields is a list of field names (e.g. "DeviceLostDetected") to
	// unconditionally include in API requests. By default, fields with empty or
	// default values are omitted from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
	// details.
	ForceSendFields []string `json:"-"`
	// NullFields is a list of field names (e.g. "DeviceLostDetected") to include
	// in API requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
	NullFields []string `json:"-"`
}

TestJobEventMessage: TestJobEvent message. TestJobEvent is a TestJob event. Every time the status of a TestJob changes, the test runner should report a TestJobEvent back.

func (*TestJobEventMessage) MarshalJSON

func (s *TestJobEventMessage) MarshalJSON() ([]byte, error)

type TestJobMessage

type TestJobMessage struct {
	// Build: Build message. This is a map to the build info comes from the build
	// pubsub. It includes a build's information.
	Build *BuildMessage `json:"build,omitempty"`
	// Context: Key values message.
	Context           []*KeyValuesMessage `json:"context,omitempty"`
	CreationTimestamp string              `json:"creationTimestamp,omitempty"`
	EndTimestamp      string              `json:"endTimestamp,omitempty"`
	// ExtraBuilds: Build message. This is a map to the build info comes from the
	// build pubsub. It includes a build's information.
	ExtraBuilds []*BuildMessage `json:"extraBuilds,omitempty"`
	Id          string          `json:"id,omitempty"`
	// JobInfo: Key values message.
	JobInfo []*KeyValuesMessage `json:"jobInfo,omitempty"`
	// PluginData: Key values message.
	PluginData  []*KeyValuesMessage `json:"plugin_data,omitempty"`
	Priority    int64               `json:"priority,omitempty"`
	ResultLinks []string            `json:"resultLinks,omitempty"`
	// Possible values:
	//   "ANDROIDX_FTL"
	//   "ANDROIDX_PLAYGROUND"
	//   "ANDROID_EMU"
	//   "ANDROID_G3"
	//   "AUTOTEST"
	//   "BATCAVE"
	//   "CTP"
	//   "MOBILE_HARNESS"
	//   "NO_OP"
	//   "PIXEL_CAMERA_FLEXTAPE"
	//   "PIXEL_CAMERA_PRESIL"
	//   "SPELUNKY"
	//   "SWARMING"
	//   "TRADEFED"
	//   "UNITY_INTEGRATION"
	//   "UNKNOWN_RUNNER"
	//   "VERSIONED_TF"
	Runner string `json:"runner,omitempty"`
	// RunnerOptions: Key values message.
	RunnerOptions  []*KeyValuesMessage `json:"runnerOptions,omitempty"`
	StartTimestamp string              `json:"startTimestamp,omitempty"`
	StateMessage   string              `json:"stateMessage,omitempty"`
	// Possible values:
	//   "ASSOCIATED_TEST_LABEL_REMOVED"
	//   "CANARY_TEST_FAILED"
	//   "CANCELED_BY_REQUEST_API"
	//   "CANCELED_BY_TEST_RUN_API"
	//   "EXTRA_BUILD_FAILED"
	//   "INFRA_ERROR"
	//   "MISSING_INVOCATION_FROM_RUNNER"
	//   "OBSOLETED"
	//   "OUT_OF_QUOTA"
	//   "QUEUE_TIMEOUT"
	//   "RUNNER_INTERNAL_FAILURE"
	//   "TEST_ERROR"
	//   "TEST_RUN_CONFIG_BLOCKLISTED"
	//   "TEST_RUN_CONFIG_SUSPENDED"
	//   "UNKNOWN"
	StateReason string `json:"stateReason,omitempty"`
	// Tasks: TestTask message. A single TestJob will create one or multiple
	// TestTasks. TestTaskMessage has information about a TestTask. A TestTask can
	// be executed one or multiple times.
	Tasks []*TestTaskMessage `json:"tasks,omitempty"`
	// Test: TestConfig message. TestConfig is the basic config for a TestJob.
	Test *TestConfigMessage `json:"test,omitempty"`
	// TestBench: TestBench message. TestBench is where actually the test should be
	// run.
	TestBench *TestBenchMessage `json:"testBench,omitempty"`
	// Possible values:
	//   "CANCELED"
	//   "COMPLETED"
	//   "ERROR"
	//   "FATAL"
	//   "QUEUED"
	//   "RUNNING"
	//   "UNKNOWN"
	TestJobState    string `json:"testJobState,omitempty"`
	UpdateTimestamp string `json:"updateTimestamp,omitempty"`
	User            string `json:"user,omitempty"`
	// Utilization: ResourceUsage message. It contains information regarding the
	// usage of a specific resource.
	Utilization []*ResourceUsage `json:"utilization,omitempty"`

	// ServerResponse contains the HTTP response code and headers from the server.
	googleapi.ServerResponse `json:"-"`
	// ForceSendFields is a list of field names (e.g. "Build") to unconditionally
	// include in API requests. By default, fields with empty or default values are
	// omitted from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
	// details.
	ForceSendFields []string `json:"-"`
	// NullFields is a list of field names (e.g. "Build") to include in API
	// requests with the JSON null value. By default, fields with empty values are
	// omitted from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
	NullFields []string `json:"-"`
}

TestJobMessage: TestJob message. TestJob is a test job running in the test runner. This message has information about test job's config, state and result. A TestJob can be executed by creating one or multiple TestTasks based on the test's configuration. Attributes: id: a test job ID. user: an email of a user who created the test job. runner: a test job runner type. test: a TestConfigMessage object. build: a BuildMessage object. testBench: a TestBenchMessage object. testJobState: a state of a test job. creationTimestamp: time when a test job was created. startTimestamp: time when a test job was started. updateTimestamp: time when a test job was last updated. endTimestamp: time when a test job was ended. tasks: a list of TestTaskMessage objects. jobInfo: extra information about a test job. priority: a priority of a test job. Must be in range [0, 1000]. runnerOptions: test runner options. context: context for the test job context has gerrit_cl and test_result_id. stateReason: a state reason of a test job when error/cancel happen. extra_builds: a list of extra builds. plugin_data: a list of KeyValuesMessage for plugin data. utilization: a list of ResourceUsage

func DecodeTestJobMsg

func DecodeTestJobMsg(ctx context.Context, encodedMsg string) (*TestJobMessage, error)

func (*TestJobMessage) MarshalJSON

func (s *TestJobMessage) MarshalJSON() ([]byte, error)

type TestRunnerError

type TestRunnerError struct {
	Type skylab_test_runner.TestRunnerErrorType
	Err  error
}

TestRunnerError implements the error interface for Test Runner errors.

func (*TestRunnerError) Error

func (t *TestRunnerError) Error() string

func (*TestRunnerError) Unwrap

func (t *TestRunnerError) Unwrap() error

type TestTaskAttemptMessage

type TestTaskAttemptMessage struct {
	// AttemptInfo: Key values message.
	AttemptInfo        []*KeyValuesMessage `json:"attemptInfo,omitempty"`
	CreationTimestamp  string              `json:"creationTimestamp,omitempty"`
	EndTimestamp       string              `json:"endTimestamp,omitempty"`
	FailedTestCount    int64               `json:"failedTestCount"`
	FailedTestRunCount int64               `json:"failedTestRunCount"`
	Id                 string              `json:"id,omitempty"`
	StartTimestamp     string              `json:"startTimestamp,omitempty"`
	// Possible values:
	//   "CANCELED"
	//   "COMPLETED"
	//   "ERROR"
	//   "FATAL"
	//   "QUEUED"
	//   "RUNNING"
	//   "UNKNOWN"
	TestTaskAttemptState string `json:"testTaskAttemptState,omitempty"`
	TotalTestCount       int64  `json:"totalTestCount"`
	UpdateTimestamp      string `json:"updateTimestamp,omitempty"`
	// ForceSendFields is a list of field names (e.g. "AttemptInfo") to
	// unconditionally include in API requests. By default, fields with empty or
	// default values are omitted from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
	// details.
	ForceSendFields []string `json:"-"`
	// NullFields is a list of field names (e.g. "AttemptInfo") to include in API
	// requests with the JSON null value. By default, fields with empty values are
	// omitted from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
	NullFields []string `json:"-"`
}

TestTaskAttemptMessage: TestTaskAttempt message. A TestTaskAttempt is a single attempt for a TestTask. TestTask can be executed multiple times and each TestTaskAttemptMessage will have the information about each TestTaskAttempt.

func (*TestTaskAttemptMessage) MarshalJSON

func (s *TestTaskAttemptMessage) MarshalJSON() ([]byte, error)

type TestTaskMessage

type TestTaskMessage struct {
	// Attempts: TestTaskAttempt message. A TestTaskAttempt is a single attempt for
	// a TestTask. TestTask can be executed multiple times and each
	// TestTaskAttemptMessage will have the information about each TestTaskAttempt.
	Attempts          []*TestTaskAttemptMessage `json:"attempts,omitempty"`
	CreationTimestamp string                    `json:"creationTimestamp,omitempty"`
	EndTimestamp      string                    `json:"endTimestamp,omitempty"`
	Id                string                    `json:"id,omitempty"`
	ShardIndex        int64                     `json:"shardIndex,omitempty"`
	Shards            int64                     `json:"shards,omitempty"`
	StartTimestamp    string                    `json:"startTimestamp,omitempty"`
	// TaskInfo: Key values message.
	TaskInfo []*KeyValuesMessage `json:"taskInfo,omitempty"`
	// Possible values:
	//   "CANCELED"
	//   "COMPLETED"
	//   "ERROR"
	//   "FATAL"
	//   "QUEUED"
	//   "RUNNING"
	//   "UNKNOWN"
	TestTaskState   string `json:"testTaskState,omitempty"`
	UpdateTimestamp string `json:"updateTimestamp,omitempty"`
	// ForceSendFields is a list of field names (e.g. "Attempts") to
	// unconditionally include in API requests. By default, fields with empty or
	// default values are omitted from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
	// details.
	ForceSendFields []string `json:"-"`
	// NullFields is a list of field names (e.g. "Attempts") to include in API
	// requests with the JSON null value. By default, fields with empty values are
	// omitted from API requests. See
	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
	NullFields []string `json:"-"`
}

TestTaskMessage: TestTask message. A single TestJob will create one or multiple TestTasks. TestTaskMessage has information about a TestTask. A TestTask can be executed one or multiple times.

func (*TestTaskMessage) MarshalJSON

func (s *TestTaskMessage) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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