util

package
v0.0.0-...-9febfc8 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: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColonSeparator      string = ":"
	UnderscoreSeparator string = "_"
	Lab                 string = "lab"
	ATL                 string = "atl"
	ACS                 string = "acs"
	Browser             string = "browser"
	CrOS                string = "cros"
	// https://cloud.google.com/datastore/docs/concepts/limits
	OperationPageSize int = 500

	// Version Key format of inventory
	TimestampBasedVersionKeyFormat string = "2006-01-02 15:04:05.000 UTC"

	// Prefix before zone enum string vals
	ZonePrefix string = "ZONE"
	// Prefix before all Satlab for Partner associated zones
	SfPPrefix string = "SFP"
)

message for filtering

View Source
const (
	// AssetCollection refers to the prefix of the corresponding resource.
	AssetCollection string = "assets"
	// MachineCollection refers to the prefix of the corresponding resource.
	MachineCollection string = "machines"
	// RackCollection refers to the prefix of the corresponding resource.
	RackCollection string = "racks"
	// VMCollection refers to the prefix of the corresponding resource.
	VMCollection string = "vms"
	// ChromePlatformCollection refers to the prefix of the corresponding resource.
	ChromePlatformCollection string = "chromeplatforms"
	// MachineLSECollection refers to the prefix of the corresponding resource.
	MachineLSECollection string = "machineLSEs"
	// MachineLSEDeploymentCollection refers to the prefix of the corresponding resource.
	MachineLSEDeploymentCollection string = "machineLSEDeployments"
	// HostCollection refers to the prefix of the corresponding resource.
	HostCollection string = "hosts"
	// RackLSECollection refers to the prefix of the corresponding resource.
	RackLSECollection string = "rackLSEs"
	// NicCollection refers to the prefix of the corresponding resource.
	NicCollection string = "nics"
	// KVMCollection refers to the prefix of the corresponding resource.
	KVMCollection string = "kvms"
	// RPMCollection refers to the prefix of the corresponding resource.
	RPMCollection string = "rpms"
	// DracCollection refers to the prefix of the corresponding resource.
	DracCollection string = "dracs"
	// SwitchCollection refers to the prefix of the corresponding resource.
	SwitchCollection string = "switches"
	// VlanCollection refers to the prefix of the corresponding resource.
	VlanCollection string = "vlans"
	// MachineLSEPrototypeCollection refers to the prefix of the corresponding resource.
	MachineLSEPrototypeCollection string = "machineLSEPrototypes"
	// RackLSEPrototypeCollection refers to the prefix of the corresponding resource.
	RackLSEPrototypeCollection string = "rackLSEPrototypes"
	// DHCPCollection refers to the prefix of the dhcp config id in change history
	DHCPCollection string = "dhcps"
	// IPCollection refers to the prefix of the ip id in change history
	IPCollection string = "ips"
	// StateCollection refers to the prefix of the states id in change history
	StateCollection string = "states"
	// CachingServiceCollection refers to the prefix of the CachingService.
	CachingServiceCollection string = "cachingservices"
	// DutStateCollection refers to the prefix of the DutStates id in change history
	DutStateCollection string = "dutstates"
	// SchedulingUnitCollection refers to the prefix of the SchedulingUnit.
	SchedulingUnitCollection string = "schedulingunits"
	// DefaultWifiCollection refers to the prefix of the DefaultWifi.
	DefaultWifiCollection string = "defaultwifis"
	// DeviceLabelsCollection refers to the prefix of the DeviceLabels.
	DeviceLabelsCollection string = "devicelabels"

	// MaxPageSize maximum page size for list operations
	MaxPageSize int32 = 1000

	// NoHostPrefix is the prefix string for generating a fake non-existing hostname
	NoHostPrefix string = "no-host-yet-"
)
View Source
const (
	ChromiumPool              = "chromium"
	ChromePool                = "chrome"
	ChromiumNamePrefix        = "chromium-"
	ChromeNamePrefix          = "chrome-"
	ChromeClankPrefix         = "chrome-clank-"
	ChromePerfNamePrefix      = "chrome-perf-"
	ChromePerfWaterfallPrefix = "chrome-perf-waterfall-"
	ChromePerfPinpointPrefix  = "chrome-perf-pinpoint-"
)

Browser-related consts

View Source
const AcsLabAdminRealm = "@internal:ufs/os-acs"

AcsLabAdminRealm is the admin realm for acs lab.

View Source
const AtlLabAdminRealm = "@internal:ufs/os-atl"

AtlLabAdminRealm is the admin realm for atl lab.

View Source
const AtlLabChromiumAdminRealm = "@internal:ufs/os-atl-chromium"

AtlLabChromiumAdminRealm is the admin realm for chromium DUTs in atl lab.

View Source
const BrowserLabAdminRealm = "@internal:ufs/browser"

BrowserLabAdminRealm is the admin realm for browser lab.

View Source
const ChromeOSLUCIProject = "chromeos"

ChromeOSLUCIProject where ChromeOS LUCI infra lives

View Source
const OldBrowserLabAdminRealm = "chromium:ufs/browser-admin"

OldBrowserLabAdminRealm is the Old realm for browser lab

If a client sends this realm, replace it with BrowserLabAdminRealm

View Source
const SatLabInternalUserRealm = "@internal:ufs/satlab-internal-users"

SatLabInternalUserRealm is realm for satlab internal users.

Variables

View Source
var (
	ZoneFilterName                 string = "zone"
	ZonesFilterName                string = "zones"
	RackFilterName                 string = "rack"
	MachineFilterName              string = "machine"
	HostFilterName                 string = "host"
	NicFilterName                  string = "nic"
	DracFilterName                 string = "drac"
	KVMFilterName                  string = "kvm"
	KVMPortFilterName              string = "kvmport"
	MacAddressFilterName           string = "mac"
	RPMFilterName                  string = "rpm"
	RPMPortFilterName              string = "rpmport"
	RPMTypeFilterName              string = "rpmtype"
	SwitchFilterName               string = "switch"
	SwitchPortFilterName           string = "switchport"
	ServoFilterName                string = "servo"
	ServoTypeFilterName            string = "servotype"
	TagFilterName                  string = "tag"
	ChromePlatformFilterName       string = "platform"
	MachinePrototypeFilterName     string = "machineprototype"
	RackPrototypeFilterName        string = "rackprototype"
	VlanFilterName                 string = "vlan"
	StateFilterName                string = "state"
	IPV4FilterName                 string = "ipv4"
	IPV4StringFilterName           string = "ipv4str"
	OccupiedFilterName             string = "occupied"
	ManufacturerFilterName         string = "man"
	FreeVMFilterName               string = "free"
	ResourceTypeFilterName         string = "resourcetype"
	OSVersionFilterName            string = "osversion"
	OSFilterName                   string = "os"
	VirtualDatacenterFilterName    string = "vdc"
	ModelFilterName                string = "model"
	BuildTargetFilterName          string = "target"
	BoardFilterName                string = "board"
	DeviceTypeFilterName           string = "devicetype"
	PhaseFilterName                string = "phase"
	AssetTypeFilterName            string = "assettype"
	SubnetsFilterName              string = "subnets"
	PoolsFilterName                string = "pools"
	DeploymentIdentifierFilterName string = "deploymentidentifier"
	DeploymentEnvFilterName        string = "deploymentenv"
	MachineLSEsFilterName          string = "duts"
	TypeFilterName                 string = "type"
	SerialNumberFilterName         string = "serialnumber"
	BbnumFilterName                string = "bbnum"
	AssetTagFilterName             string = "assettag"
	CpuCoresFilterName             string = "cpucores"
	MemoryFilterName               string = "memory"
	StorageFilterName              string = "storage"
	LogicalZoneFilterName          string = "logicalzone"
	GPNFilterName                  string = "gpn"
	AssetType                      string = "assettype"
	CommittishFilterName           string = "commitsh"
	HiveFilterName                 string = "hive"
)

Filter names for indexed properties in datastore for different entities

View Source
var (
	// OSNamespace os namespace to be set in client context metadata. OS data is stored in os namespace in the datastore.
	OSNamespace = "os"
	// BrowserNamespace browser namespace to be set in client context metadata. Browser data is stored in default namespace in the datastore.
	BrowserNamespace = "browser"
	// OSPartnerNamespace partner namespace to be set in client context metadata. Partner data is stored in partner namespace in the datastore.
	// This is expected to hold and be accessible to non-Google entities (subject to RPC and zone ACLs) working on ChromeOS.
	OSPartnerNamespace = "os-partner"
	// Namespace key in the incoming context metadata
	Namespace = "namespace"
)

Namespace namespace to be set by clients in context metadata This will be used to set the actual datastore namespace in the context

View Source
var (
	// ConfigurationsGet allows to get configuration resources.
	ConfigurationsGet = realms.RegisterPermission("ufs.configurations.get")
	// ConfigurationsList allows to list configuration resources.
	ConfigurationsList = realms.RegisterPermission("ufs.configurations.list")
	// ConfigurationsCreate allows to create configuration resources.
	ConfigurationsCreate = realms.RegisterPermission("ufs.configurations.create")
	// ConfigurationUpdate allows to update configuration resources.
	ConfigurationsUpdate = realms.RegisterPermission("ufs.configurations.update")
	// ConfigurationsDelete allows to delete configuration resources.
	ConfigurationsDelete = realms.RegisterPermission("ufs.configurations.delete")

	// RegistrationsGet allows to get registration resources.
	RegistrationsGet = realms.RegisterPermission("ufs.registrations.get")
	// RegistrationsList allows to list registration resources.
	RegistrationsList = realms.RegisterPermission("ufs.registrations.list")
	// RegistrationsCreate allows to create registration resources.
	RegistrationsCreate = realms.RegisterPermission("ufs.registrations.create")
	// RegistrationsUpdate allows to update registration resources.
	RegistrationsUpdate = realms.RegisterPermission("ufs.registrations.update")
	// RegistrationsDelete allows to delete registration resources.
	RegistrationsDelete = realms.RegisterPermission("ufs.registrations.delete")

	// InventoriesGet allows to get inventory resources.
	InventoriesGet = realms.RegisterPermission("ufs.inventories.get")
	// InventoriesList allows to list inventory resources.
	InventoriesList = realms.RegisterPermission("ufs.inventories.list")
	// InventoriesCreate allows to create inventory resources.
	InventoriesCreate = realms.RegisterPermission("ufs.inventories.create")
	// InventoriesUpdate allows to update inventory resources.
	InventoriesUpdate = realms.RegisterPermission("ufs.inventories.update")
	// InventoriesDelete allows to delete inventory resources.
	InventoriesDelete = realms.RegisterPermission("ufs.inventories.delete")

	// NetworksGet allows to get network resources.
	NetworksGet = realms.RegisterPermission("ufs.networks.get")
	// NetworksList allows to list network resources.
	NetworksList = realms.RegisterPermission("ufs.networks.list")
	// NetworksCreate allows to create network resources.
	NetworksCreate = realms.RegisterPermission("ufs.networks.create")
	// NetworksUpdate allows to update network resources.
	NetworksUpdate = realms.RegisterPermission("ufs.networks.update")
	// NetworksDelete allows to delete network resources.
	NetworksDelete = realms.RegisterPermission("ufs.networks.delete")

	// ResourcesImport allows to import resource resources.
	ResourcesImport = realms.RegisterPermission("ufs.resources.import")
)

UFS registered permissions in process registry

View Source
var (
	ChromePerfPools = []string{"chrome.tests.pinpoint", "chrome.tests.perf"}
)

ClientToDatastoreNamespace refers a map between client namespace(set in context metadata) to actual datastore namespace

View Source
var PoolNameRegex = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_-]*$`)

PoolNameRegex ensures that a pool name is valid.

View Source
var ServoV3HostnameRegex = regexp.MustCompile(`.*-servo`)

ServoV3HostnameRegex is used to identify servo V3 hosts.

View Source
var SkipRealmsCheck = false

SkipRealmsCheck flag to skip realms check

View Source
var StateToDescription = map[string]string{
	"registered":           "Needs deploy",
	"deployed_pre_serving": "Deployed but not placed in prod",
	"deployed_testing":     "Deployed to the prod, but for testing",
	"serving":              "Deployed to the prod, serving",
	"needs_reset":          "Deployed to the prod, but required cleanup and verify",
	"needs_repair":         "Deployed to the prod, needs repair",
	"repair_failed":        "Deployed to the prod, failed to be repaired in previous step and requires new repair attempt",
	"disabled":             "Deployed to the prod, but disabled",
	"reserved":             "Deployed to the prod, but reserved (e.g. locked)",
	"decommissioned":       "Decommissioned from the prod, but still lives in UFS record",
	"deploying":            "Deploying the resource with required configs just before it is READY",
	"ready":                "Resource is ready for use or free to use",
	"build":                "Resource is in the process of being built out or assembled",
	"missing":              "Resource is not detected and has gone missing",
}

StateToDescription refers a map between a State to its description.

View Source
var StrToAntennaConnection = map[string]string{
	"unknown":    "CONN_UNKNOWN",
	"conductive": "CONN_CONDUCTIVE",
	"ota":        "CONN_OTA",
}

StrToAntennaConnection refers a map between a string to a AntennaConnection map.

View Source
var StrToCableType = map[string]string{
	"invalid":     "CABLE_INVALID",
	"audiojack":   "CABLE_AUDIOJACK",
	"usbaudio":    "CABLE_USBAUDIO",
	"usbprinting": "CABLE_USBPRINTING",
	"hdmiaudio":   "CABLE_HDMIAUDIO",
}

StrToCableType refers a map between a string to a CableType map.

View Source
var StrToCameraType = map[string]string{
	"invalid": "CAMERA_INVALID",
	"huddly":  "CAMERA_HUDDLY",
	"ptzpro2": "CAMERA_PTZPRO2",
}

StrToCameraType refers a map between a string to a CameraType map.

View Source
var StrToChameleonType = map[string]string{
	"invalid": "CHAMELEON_TYPE_INVALID",
	"dp":      "CHAMELEON_TYPE_DP",
	"hdmi":    "CHAMELEON_TYPE_HDMI",
}

StrToChameleonType refers a map between a string to a ChameleonType map.

StrToDevicePhase refers to a map between a string and the ManufacturingConfig Phase type.

View Source
var StrToFacing = map[string]string{
	"unknown":  "FACING_UNKNOWN",
	"back":     "FACING_BACK",
	"front":    "FACING_FRONT",
	"nocamera": "FACING_NOCAMERA",
}

StrToFacing refers a map between a string to a Facing map.

View Source
var StrToLicenseType = map[string]string{
	"invalid":      "LICENSE_TYPE_UNSPECIFIED",
	"windows10pro": "LICENSE_TYPE_WINDOWS_10_PRO",
	"msofficestd":  "LICENSE_TYPE_MS_OFFICE_STANDARD",
}

StrToLicenseType refers a map between a string to a LicenseType map.

View Source
var StrToLight = map[string]string{
	"unknown": "LIGHT_UNKNOWN",
	"led":     "LIGHT_LED",
	"noled":   "LIGHT_NOLED",
}

StrToLight refers a map between a string to a Light map.

View Source
var StrToLogicalZone = map[string]string{
	"unspecified":     "LOGICAL_ZONE_UNSPECIFIED",
	"drillzone_sfo36": "LOGICAL_ZONE_DRILLZONE_SFO36",
}

StrToLogicalZone refers a map between a string to a LogicalZone map.

View Source
var StrToRPMType = map[string]string{
	"unknown": "TYPE_UNKNOWN",
	"sentry":  "TYPE_SENTRY",
	"ip9850":  "TYPE_IP9850",
	"cpi":     "TYPE_CPI",
}

StrToRPMType refers a map between a string to a OSRPM_Type map.

View Source
var StrToResourceType = genStrToResourceType()

StrToResourceType refers a map between a string to a ResourceType map.

View Source
var StrToRouter = map[string]string{
	"unspecified": "ROUTER_UNSPECIFIED",
	"80211ax":     "ROUTER_802_11AX",
}

StrToRouter refers a map between a string to a Router map.

View Source
var StrToSIMType = map[string]int32{
	"SIM_UNKNOWN":  0,
	"SIM_PHYSICAL": 1,
	"SIM_DIGITAL":  2,
}

StrToSIMType refers a map between sim type and and enum value.

View Source
var StrToSchedulingUnitExposeType = map[string]string{
	"default":               "DEFAULT",
	"default_plus_primary":  "DEFAULT_PLUS_PRIMARY",
	"strictly_primary_only": "STRICTLY_PRIMARY_ONLY",
}

StrToSchedulingUnitExposeType refers a map between a string to a UFS defined map.

View Source
var StrToSchedulingUnitType = map[string]string{
	"invalid":    "SCHEDULING_UNIT_TYPE_INVALID",
	"all":        "SCHEDULING_UNIT_TYPE_ALL",
	"individual": "SCHEDULING_UNIT_TYPE_INDIVIDUAL",
}

StrToSchedulingUnitType refers a map between a string to a UFS defined map.

View Source
var StrToUFSAttachedDeviceType = map[string]string{
	"unspecified":    "ATTACHED_DEVICE_TYPE_UNSPECIFIED",
	"apple_phone":    "ATTACHED_DEVICE_TYPE_APPLE_PHONE",
	"android_phone":  "ATTACHED_DEVICE_TYPE_ANDROID_PHONE",
	"apple_tablet":   "ATTACHED_DEVICE_TYPE_APPLE_TABLET",
	"android_tablet": "ATTACHED_DEVICE_TYPE_ANDROID_TABLET",
	"devboard":       "ATTACHED_DEVICE_TYPE_DEVBOARD",
	"jetstream":      "ATTACHED_DEVICE_TYPE_JETSTREAM",
}

StrToUFSAttachedDeviceType refers a map between a string to a UFS defined map.

View Source
var StrToUFSDevboardType = map[string]string{
	"andreiboard": "unifiedfleet.api.v1.models.Andreiboard",
	"icetower":    "unifiedfleet.api.v1.models.Icetower",
	"dragonclaw":  "unifiedfleet.api.v1.models.Dragonclaw",
}

StrToUFSDevboardType refers a map between a string to a UFS defined map.

View Source
var StrToUFSDeviceType = map[string]string{
	"chromebook":  "DEVICE_CHROMEBOOK",
	"labstation":  "DEVICE_LABSTATION",
	"servo":       "DEVICE_SERVO",
	"unspecified": "CHROME_OS_DEVICE_TYPE_UNSPECIFIED",
}

StrToUFSDeviceType refers a map between a string to a UFS defined map.

View Source
var StrToUFSState = map[string]string{
	"registered":           "STATE_REGISTERED",
	"deployed_pre_serving": "STATE_DEPLOYED_PRE_SERVING",
	"deployed_testing":     "STATE_DEPLOYED_TESTING",
	"serving":              "STATE_SERVING",
	"needs_reset":          "STATE_NEEDS_RESET",
	"needs_repair":         "STATE_NEEDS_REPAIR",
	"repair_failed":        "STATE_REPAIR_FAILED",
	"disabled":             "STATE_DISABLED",
	"reserved":             "STATE_RESERVED",
	"decommissioned":       "STATE_DECOMMISSIONED",
	"deploying":            "STATE_DEPLOYING",
	"ready":                "STATE_READY",
	"build":                "STATE_BUILD",
	"missing":              "STATE_MISSING",
}

StrToUFSState refers a map between a string to a UFS defined state map.

View Source
var StrToUFSZone = genStrToUFSZone()

StrToUFSZone refers a map between a string to a UFS defined map.

Functions

func AddPrefix

func AddPrefix(collection, entity string) string

AddPrefix adds the prefix for a given resource name

func AppendUniqueStrings

func AppendUniqueStrings(des []string, src ...string) []string

AppendUniqueStrings returns a slice with unique elements such that all the des elements are appended to src.

func BQTransientErrorRetries

func BQTransientErrorRetries() retry.Factory

BQTransientErrorRetries returns a retry.Factory to use on transient errors

func CheckPermission

func CheckPermission(ctx context.Context, perm realms.Permission, realm string) error

CheckPermission checks if the user has permission in the realm

return error if user doesnt have permission or unable to check permission in realm else returns nil

func ContainsAnyStrings

func ContainsAnyStrings(list []string, inputs ...string) bool

ContainsAnyStrings returns true if at least one of the inputs is in list.

func CurrentUser

func CurrentUser(ctx context.Context) string

CurrentUser returns the current user

func ExecuteRequest

func ExecuteRequest(ctx context.Context, hc *http.Client, req *http.Request, value proto.Message) error

func FormatDHCPHostname

func FormatDHCPHostname(old string) string

FormatDHCPHostname formats a name which will be a dhcp host

func FormatDHCPHostnames

func FormatDHCPHostnames(names []string) []string

FormatDHCPHostnames formats a given array of resource names which could be used as dhcp hostnames

func FormatDeploymentRecord

func FormatDeploymentRecord(hostname, serialNumber string) *ufspb.MachineLSEDeployment

FormatDeploymentRecord initialize a MachineLSE deployment record object by hostname and given serial number.

func FormatIP

func FormatIP(vlanName, ipAddress string, reserve, occupied bool) *ufspb.IP

FormatIP initialize an IP object

func FormatInputNames

func FormatInputNames(names []string) []string

FormatInputNames formats a given array of resource names

func FormatResourceName

func FormatResourceName(old string) string

FormatResourceName formats the resource name

func GetATLLabName

func GetATLLabName(raw string) string

GetATLLabName returns a resource name with atl prefix and a given user-specified raw name.

func GetBrowserLabName

func GetBrowserLabName(raw string) string

GetBrowserLabName return a resource name with browser prefix and a given user-specified raw name.

func GetCrOSLabName

func GetCrOSLabName(raw string) string

GetCrOSLabName returns a resource name with ChromeOS prefix and a given user-specified raw name.

func GetDatastoreNamespace

func GetDatastoreNamespace(ctx context.Context) string

GetDatastoreNamespace returns the namespace used in context

func GetDeployBBBuilderName

func GetDeployBBBuilderName(hostname string) string

GetDeployBBBuilderName returns builder name for deployment based on configs.

The deploy builder is decided in https://source.corp.google.com/h/chrome-internal/chromeos/codesearch/+/main:infra/config/lab_platform/labpack/main.star;l=96;bpv=1 The name is different for different swarming pool, swarming pool is decided by bot prefix, and bot prefix is decided by hostname prefix.

func GetDevboardType

func GetDevboardType(b *ufspb.Devboard) string

GetDevboardType returns the board type string for a devboard.

func GetHiveForDut

func GetHiveForDut(hostname string, hive string) string

GetHiveForDut returns the hive value for a DUT.

if the hive is not store in UFS, hive value is derived from the DUT hostname. TODO(b:296635614) use UFS stored data instead of hostname to determine hive.

func GetHostnameWithNoHostPrefix

func GetHostnameWithNoHostPrefix(suffix string) string

GetHostnameWithNoHostPrefix generates a hostname with NoHostPrefix.

func GetIPName

func GetIPName(vlanName, ipv4Str string) string

GetIPName returns a formatted IP name

func GetIncomingCtxNamespace

func GetIncomingCtxNamespace(ctx context.Context) string

GetIncomingCtxNamespace parses namespace in incoming context passed to UFS

The user must explicitly specify a recognized namespace string for the corresponding namespace to be returned. An empty or unrecognized string will cause namespace=BrowserNamespace.

func GetNamespaceFromCtx

func GetNamespaceFromCtx(ctx context.Context) string

GetNamespaceFromCtx parses namespace from ctx, either a normal context or an incoming context.

func GetNewNicNameForRenameMachine

func GetNewNicNameForRenameMachine(oldNicName, oldMachineName, newMachineName string) string

GetNewNicNameForRenameMachine returns new nic name for new machine name

func GetNicNameForHost

func GetNicNameForHost(hostname string) string

GetNicNameForHost returns a nic name for a ChromeOS DUT

func GetPageSize

func GetPageSize(pageSize int32) int32

GetPageSize gets the correct page size for List pagination

func GetPrefix

func GetPrefix(resourceName string) string

GetPrefix returns the prefix for a resource name

func GetRackHostname

func GetRackHostname(rackName string) string

GetRackHostname returns a rack host name.

func GetResourcePrefix

func GetResourcePrefix(message proto.Message) (string, error)

GetResourcePrefix gets the resource prefix given to the proto message.

Returns the resource prefix for a given proto message. See also: https://blog.golang.org/protobuf-apiv2

func GetSatlabForPartnersRealm

func GetSatlabForPartnersRealm(zone string) string

GetSatlabForPartnersRealm determines the realm for zones that are formatted in a manner consistent with SfP naming conventions

func GetStateDescription

func GetStateDescription(state string) string

GetStateDescription returns the description for the state

func GetSuffixAfterSeparator

func GetSuffixAfterSeparator(name, seprator string) string

GetSuffixAfterSeparator extracts the string appearing after the separator

returns the suffix after the first found separator

func GetValidRealmName

func GetValidRealmName(realm string) string

GetValidRealmName replaces the older Browser realm with newer realm

func IPv4IntToStr

func IPv4IntToStr(ipAddress uint32) string

IPv4IntToStr returns a string ip address

func IPv4StrToInt

func IPv4StrToInt(ipAddress string) (uint32, error)

IPv4StrToInt returns an uint32 address from the given ip address string.

func IPv4ToUint32

func IPv4ToUint32(ip net.IP) (uint32, error)

IPv4ToUint32 converts an IP to a uint32

func Int32ToStr

func Int32ToStr(v int32) string

Int32ToStr converts the int32 to string

func Int64ToStr

func Int64ToStr(v int64) string

Int64ToStr converts the int64 to string

func IsAntennaConnection

func IsAntennaConnection(antennaConnection string) bool

IsAntennaConnection checks if a string refers to a valid AntennaConnection.

func IsAssetType

func IsAssetType(assetType string) bool

IsAssetType checks if a strings is a valid asset type

func IsAttachedDeviceType

func IsAttachedDeviceType(deviceType string) bool

IsAttachedDeviceType checks if a string refers to a valid AttachedDeviceType.

func IsBrowserLegacyAsset

func IsBrowserLegacyAsset(name string) bool

IsBrowserLegacyAsset returns if an asset is a legacy asset migrated from browser lab which doesn't have an assetTag

func IsCableType

func IsCableType(cableType string) bool

IsCableType checks if a string refers to a valid CableType.

func IsCameraType

func IsCameraType(cameraType string) bool

IsCameraType checks if a string refers to a valid CameraType.

func IsChameleonType

func IsChameleonType(chameleonType string) bool

IsChameleonType checks if a string refers to a valid ChameleonType.

func IsChromeLegacyHost

func IsChromeLegacyHost(name string) bool

IsChromeLegacyHost returns if a host is a legacy browser host used internally

func IsChromePerfHost

func IsChromePerfHost(name string) bool

IsChromePerfHost returns if a host is a legacy browser perf host used internally

func IsChromiumLegacyHost

func IsChromiumLegacyHost(name string) bool

IsChromiumLegacyHost returns if a host is a legacy browser host used externally

func IsClankHost

func IsClankHost(name string) bool

IsClankHost returns if a host is a DUT used for clank

func IsClientNamespace

func IsClientNamespace(namespace string) bool

IsClientNamespace checks if a string refers to a valid client namespace.

func IsDevboardType

func IsDevboardType(deviceType string) bool

IsDevboardType checks if a string refers to a valid Devboard type.

func IsFacing

func IsFacing(facing string) bool

IsFacing checks if a string refers to a valid Facing.

func IsInBrowserZone

func IsInBrowserZone(name string) bool

IsInBrowserZone check if a given name(resource or zone name) indicates it's in browser zone.

func IsInChromePerfPool

func IsInChromePerfPool(pools []string) bool

IsInChromePerfPool checks if any chrome perf pool exist in the given pool labels

func IsInChromePool

func IsInChromePool(pools []string) bool

IsInChromePool checks if any chrome pool exist in the given pool labels.

func IsInChromiumPool

func IsInChromiumPool(pools []string) bool

IsInChromiumPool checks if any chromium pool exist in the given pool labels.

func IsInOSZone

func IsInOSZone(name string) bool

IsInOSZone check if a given name(resource or zone name) indicates it's in OS zone.

func IsInternalError

func IsInternalError(err error) bool

IsInternalError checks if an error has code INTERNAL

func IsLicenseType

func IsLicenseType(licenseType string) bool

IsLicenseType checks if a string refers to a valid LicenseType.

func IsLight

func IsLight(light string) bool

IsLight checks if a string refers to a valid Light.

func IsLogicalZone

func IsLogicalZone(logicalZone string) bool

IsLogicalZone checks if a string is a valid logical zone

func IsMacFormatValid

func IsMacFormatValid(userMac string) error

IsMacFormatValid check if the given mac address is in valid format

TODO(gregorynisbet): only shivas uses this function, move it.

func IsModemType

func IsModemType(modemType string) bool

IsModemType checks if a string refers to a valid ModemType.

func IsNetworkType

func IsNetworkType(networkType string) bool

IsNetworkType checks if a string refers to a valid NetworkProvider.

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError checks if an error has code NOT_FOUND

func IsRPMType

func IsRPMType(rpmType string) bool

IsRPMType checks if a string refers to a valid OSRPM_Type.

func IsResourceType

func IsResourceType(resourceType string) bool

IsResourceType checks if a string is a valid resource type

func IsRouter

func IsRouter(router string) bool

IsRouter checks if a string refers to a valid Router.

func IsSFPZone

func IsSFPZone(zone string) bool

IsSFPZone checks if a given zone name indicates it's a SfP zone. This check looks for a string of format "ZONE_SFP_*"

func IsSIMType

func IsSIMType(simType string) bool

IsSIMType checks if a string refers to a valid simType.

func IsSchedulingUnitExposeType

func IsSchedulingUnitExposeType(schedulingUnitExposeType string) bool

IsSchedulingUnitExposeType checks if a string refers to a valid SchedulingUnit_ExposeType.

func IsSchedulingUnitType

func IsSchedulingUnitType(schedulingUnitType string) bool

IsSchedulingUnitType checks if a string refers to a valid SchedulingUnitType.

func IsUFSState

func IsUFSState(state string) bool

IsUFSState checks if a string refers to a valid UFS state.

func IsUFSZone

func IsUFSZone(zone string) bool

IsUFSZone checks if a string refers to a valid UFS zone.

func LabToZone

func LabToZone(lab string) ufspb.Zone

LabToZone converts deprecated Lab type to Zone

func Min

func Min(a, b int) int

Min returns the smaller integer of the two inputs.

func ParseATLTopology

func ParseATLTopology(data *sheets.Spreadsheet) (map[string]*ufspb.Vlan, []*ufspb.Vlan)

ParseATLTopology parse the topology of ATL lab based on a Google sheet

func ParseMac

func ParseMac(userMac string) (string, error)

ParseMac returns a valid mac address after parsing user input.

func ParseVlan

func ParseVlan(vlanName, cidr, freeStartIPStr, freeEndIPStr string) ([]*ufspb.IP, int, string, string, int, error)

ParseVlan parses vlan to a list of IPs

vlanName here is a full vlan name, e.g. browser:123 The first 10 and last 1 ip of this cidr block will be reserved and not returned to users for further operations

func ProtoEqual

func ProtoEqual(i, j proto.Message) bool

ProtoEqual compares the given protos i, j and returns true if Type(i) == Type(j) and one of the following holds 1. i == j == nil 2. For each exported field(proto message field) x in Type(i), i.Equal(j) or i.x == j.y. returns false otherwise.

func PublishHaRTAssetInfoRequest

func PublishHaRTAssetInfoRequest(ctx context.Context, assets []string) (err error)

PublishHaRTAssetInfoRequest sends a request for asset info update for given assets

func RemoveGivenPrefix

func RemoveGivenPrefix(msg, prefix string) string

RemoveGivenPrefix removes the prefix from the string

func RemovePrefix

func RemovePrefix(name string) string

RemovePrefix extracts string appearing after a "/"

func RemoveStatePrefix

func RemoveStatePrefix(state string) string

RemoveStatePrefix removes the "state_" prefix from the string

func RemoveStringEntry

func RemoveStringEntry(slice []string, entry string) []string

RemoveStringEntry removes string entry from the string slice

func RemoveZonePrefix

func RemoveZonePrefix(zone string) string

RemoveZonePrefix removes the "zone_" prefix from the string

func SchedulingUnitDutState

func SchedulingUnitDutState(states []string) string

SchedulingUnitDutState calculates a weighted state based on all DUTs to represent the scheduling unit Copied from infra/go/src/infra/cmd/shivas/utils/schedulingunit/su_utility.go

func SetupDatastoreNamespace

func SetupDatastoreNamespace(ctx context.Context, namespace string) (context.Context, error)

SetupDatastoreNamespace sets the datastore namespace in the context to access the correct namespace in the datastore

func StringifyIP

func StringifyIP(ip net.IP) string

StringifyIP stringifies an IP. The standard library makes the interesting choice of mapping an empty IP address object to "<nil>" rather than "".

Here we just return an empty string given an empty IP.

func ToAntennaConnection

func ToAntennaConnection(antennaConnection string) chromeosLab.Wifi_AntennaConnection

ToAntennaConnection converts antennaConnection string to a Wifi_AntennaConnection enum.

func ToAssetType

func ToAssetType(assetType string) ufspb.AssetType

ToAssetType returns an AssetType object corresponding to string

func ToCableType

func ToCableType(cableType string) chromeosLab.CableType

ToCableType converts cableType string to a Cable type enum.

func ToCameraType

func ToCameraType(cameraType string) chromeosLab.CameraType

ToCameraType converts cameraType string to a Camera type enum.

func ToChameleonType

func ToChameleonType(chameleonType string) chromeosLab.ChameleonType

ToChameleonType converts chameleonType string to a Chameleon type enum.

func ToFacing

func ToFacing(facing string) chromeosLab.Camerabox_Facing

ToFacing converts facing string to a Camerabox_Facing enum.

func ToLicenseType

func ToLicenseType(licenseType string) chromeosLab.LicenseType

ToLicenseType converts licenseType string to a License type enum.

func ToLight

func ToLight(light string) chromeosLab.Camerabox_Light

ToLight converts light string to a Camerabox_Light enum.

func ToLogicalZone

func ToLogicalZone(logicalZone string) ufspb.LogicalZone

ToLogicalZone returns an LogicalZone object corresponding to string

func ToModemType

func ToModemType(modemType string) chromeosLab.ModemType

ToModemType converts modemType string to a Modem type enum.

func ToNetworkType

func ToNetworkType(networkType string) chromeosLab.NetworkProvider

ToNetworkType converts Type string to a NetworkProvider type enum.

func ToRPMType

func ToRPMType(rpmType string) chromeosLab.OSRPM_Type

ToRPMType converts rpmType string to a OSRPM_Type enum.

func ToResourceType

func ToResourceType(resourceType string) ufspb.ResourceType

ToResourceType returns an ResourceType object corresponding to string

func ToRouter

func ToRouter(router string) chromeosLab.Wifi_Router

ToRouter converts router string to a Wifi_Router enum.

func ToSIMType

func ToSIMType(simType string) chromeosLab.SIMType

ToSIMType converts simType string to a Sim type enum.

func ToSchedulingUnitExposeType

func ToSchedulingUnitExposeType(schedulingUnitExposeType string) ufspb.SchedulingUnit_ExposeType

ToSchedulingUnitExposeType converts SchedulingUnitExposeType string to a UFS SchedulingUnit_ExposeType enum.

func ToSchedulingUnitType

func ToSchedulingUnitType(schedulingUnitType string) ufspb.SchedulingUnitType

ToSchedulingUnitType converts SchedulingUnitType string to a UFS SchedulingUnitType enum.

func ToUFSAttachedDeviceType

func ToUFSAttachedDeviceType(deviceType string) ufspb.AttachedDeviceType

ToUFSAttachedDeviceType converts type string to a UFS attached device type enum.

func ToUFSDeploymentEnv

func ToUFSDeploymentEnv(env string) ufspb.DeploymentEnv

ToUFSDeploymentEnv converts string to a UFS DeploymentEnv enum.

func ToUFSDept

func ToUFSDept(zone string) string

ToUFSDept returns the dept name based on zone string.

func ToUFSDevicePhase

func ToUFSDevicePhase(devicePhase string) ufsmfg.ManufacturingConfig_Phase

ToUFSDevicePhase converts type string to a UFS attached device type enum.

func ToUFSDeviceType

func ToUFSDeviceType(devicetype string) ufspb.ChromeOSDeviceType

ToUFSDeviceType converts devicetype string to a UFS devicetype enum.

func ToUFSRealm

func ToUFSRealm(zone string) string

ToUFSRealm returns the realm name based on zone string.

func ToUFSState

func ToUFSState(state string) ufspb.State

ToUFSState converts state string to a UFS state enum.

func ToUFSZone

func ToUFSZone(zone string) ufspb.Zone

ToUFSZone converts zone string to a UFS zone enum.

func Uint32Iter

func Uint32Iter(start uint32, end uint32, f func(uint32) error) error

Uint32Iter runs a command over a range of Uint32's. Useful for iterating over IP addresses.

func ValidAntennaConnectionStr

func ValidAntennaConnectionStr() []string

ValidAntennaConnectionStr returns a valid str list for AntennaConnection strings.

func ValidAssetTypeStr

func ValidAssetTypeStr() []string

ValidAssetTypeStr returns a valid str list for AssetTypes

func ValidAttachedDeviceTypeStr

func ValidAttachedDeviceTypeStr() []string

ValidAttachedDeviceTypeStr returns a valid str list for attached device type strings.

func ValidCableTypeStr

func ValidCableTypeStr() []string

ValidCableTypeStr returns a valid str list for CableType strings.

func ValidCameraTypeStr

func ValidCameraTypeStr() []string

ValidCameraTypeStr returns a valid str list for CameraType strings.

func ValidChameleonTypeStr

func ValidChameleonTypeStr() []string

ValidChameleonTypeStr returns a valid str list for Chameleontype strings.

func ValidClientNamespaceStr

func ValidClientNamespaceStr() []string

ValidClientNamespaceStr returns a valid str list for client namespace(set in incoming context metadata) strings.

func ValidDeploymentEnvStr

func ValidDeploymentEnvStr() []string

ValidDeploymentEnvStr returns a valid str list for DeploymentEnv

func ValidDevboardTypeStr

func ValidDevboardTypeStr() []string

ValidDevboardTypeStr returns a valid str list for attached device type strings.

func ValidDeviceTypeStr

func ValidDeviceTypeStr() []string

ValidDeviceTypeStr returns a valid str list for devicetype strings.

func ValidFacingStr

func ValidFacingStr() []string

ValidFacingStr returns a valid str list for Facing strings.

func ValidLicenseTypeStr

func ValidLicenseTypeStr() []string

ValidLicenseTypeStr returns a valid str list for LicenseType strings.

func ValidLightStr

func ValidLightStr() []string

ValidLightStr returns a valid str list for Light strings.

func ValidLogicalZoneStr

func ValidLogicalZoneStr() []string

ValidLogicalZoneStr returns a valid str list for LogicalZone

func ValidModemTypeStr

func ValidModemTypeStr() []string

ValidModemTypeStr returns a valid str list for ModemType strings.

func ValidRPMTypeStr

func ValidRPMTypeStr() []string

ValidRPMTypeStr returns a valid str list for OSRPM_Type strings.

func ValidResourceTypeStr

func ValidResourceTypeStr() []string

ValidResourceTypeStr returns a valid str list for ResourceType

func ValidRouterStr

func ValidRouterStr() []string

ValidRouterStr returns a valid str list for Router strings.

func ValidSchedulingUnitExposeTypeStr

func ValidSchedulingUnitExposeTypeStr() []string

ValidSchedulingUnitExposeTypeStr returns a valid str list for SchedulingUnit_ExposeType strings.

func ValidSchedulingUnitTypeStr

func ValidSchedulingUnitTypeStr() []string

ValidSchedulingUnitTypeStr returns a valid str list for SchedulingUnitType strings.

func ValidSimTypeStr

func ValidSimTypeStr() []string

ValidSimTypeStr returns a valid str list for SimType strings.

func ValidStateStr

func ValidStateStr() []string

ValidStateStr returns a valid str list for state strings.

func ValidZoneStr

func ValidZoneStr() []string

ValidZoneStr returns a valid str list for zone strings.

func ValidateTags

func ValidateTags(tags []string) bool

ValidateTags checks if the tags contain only valid characters

Types

type DHCPConf

type DHCPConf struct {
	ValidVlans       []*ufspb.Vlan
	ValidIPs         []*ufspb.IP
	ValidDHCPs       []*ufspb.DHCPConfig
	DHCPsWithoutVlan []*ufspb.DHCPConfig
	MismatchedVlans  []*ufspb.Vlan
	DuplicatedVlans  []*ufspb.Vlan
	DuplicatedIPs    []*ufspb.IP
}

DHCPConf defines the format of response after parsing a ChromeOS dhcp conf file

func ParseOSDhcpdConf

func ParseOSDhcpdConf(conf string, topology map[string]*ufspb.Vlan) (*DHCPConf, error)

ParseOSDhcpdConf parses dhcpd.conf

type HTTPError

type HTTPError struct {
	Method     string
	URL        *url.URL
	StatusCode int
	Body       string
}

HTTPError wraps the http response errors.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type Key

type Key string

Key is a type for use in adding values to context. It is not recommended to use plain string as key.

type PSRequest

type PSRequest struct {
	Msg struct {
		Data      string `json:"data"`
		MessageID string `json:"messageId"`
	} `json:"message"`
	Sub string `json:"subscription"`
}

PSRequest helps to unmarshall json data sent from pubsub

The format of the data sent by PubSub is described in https://cloud.google.com/pubsub/docs/push?hl=en#receiving_push_messages

func NewPSRequest

func NewPSRequest(r *http.Request) (*PSRequest, error)

NewPSRequest returns a PSRequest object constructed from http request

func (*PSRequest) DecodeMessage

func (p *PSRequest) DecodeMessage() ([]byte, error)

DecodeMessage decodes []byte pertaining to the request

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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