Documentation
¶
Overview ¶
Package utils contains commonly needed utility functions for test suites inside the VM and in test workflow setup.
Index ¶
- Constants
- Variables
- func AccessSecret(ctx context.Context, client *secretmanager.Client, secretName string) (string, error)
- func CheckLinuxCmdExists(cmd string) bool
- func CheckPowershellReturnCode(command string, want int) error
- func CheckPowershellSuccess(command string) error
- func Context(t *testing.T) context.Context
- func CopyFile(src, dst string) error
- func CreateClient(user, host string, pembytes []byte) (*ssh.Client, error)
- func DownloadGCSObject(ctx context.Context, client *storage.Client, gcsPath string) ([]byte, error)
- func DownloadGCSObjectToFile(ctx context.Context, client *storage.Client, gcsPath, file string) error
- func DownloadPrivateKey(ctx context.Context, user string) ([]byte, error)
- func Exists(path string, fileType FileType) bool
- func ExtractBaseImageName(image string) (string, error)
- func FailOnPowershellFail(command string, errorMsg string, t *testing.T)
- func FilterLoopbackTunnelingInterfaces(ifaces []net.Interface) []net.Interface
- func GetDaisyClient(ctx context.Context) (daisyCompute.Client, error)
- func GetHostKeysFileFromDisk() ([]byte, error)
- func GetHostKeysFromDisk() (map[string]string, error)
- func GetInstanceMetadata(t *testing.T, name string) *compute.Metadata
- func GetInstanceName(ctx context.Context) (string, error)
- func GetInterface(ctx context.Context, index int) (net.Interface, error)
- func GetInterfaceByMAC(mac string) (net.Interface, error)
- func GetMetadata(ctx context.Context, elem ...string) (string, error)
- func GetMetadataWithHeaders(ctx context.Context, elem ...string) (string, http.Header, error)
- func GetMountDiskPartition(diskExpectedSizeGB int) (string, error)
- func GetMountDiskPartitionSymlink(mountDiskName string) (string, error)
- func GetProjectZone(ctx context.Context) (string, string, error)
- func GetRealVMName(ctx context.Context, name string) (string, error)
- func HasFeature(img *compute.Image, feature string) bool
- func IfOldAgentInstalled() bool
- func InstallPackage(packages ...string) error
- func Is32BitWindows(image string) bool
- func IsCOS(image string) bool
- func IsCoreDisabled() bool
- func IsWindows() bool
- func IsWindowsClient(image string) bool
- func LinuxOnly(t *testing.T)
- func ParseHostKey(bytes []byte) (map[string]string, error)
- func ParseInterfaceIPv4(iface net.Interface) (net.IP, error)
- func ParseStderr(err error) string
- func ProcessExistsLinux(t *testing.T, shouldExist bool, processName string)
- func ProcessExistsWindows(t *testing.T, shouldExist bool, processName string)
- func PutMetadata(ctx context.Context, path string, data string) error
- func RestartAgent(ctx context.Context) error
- func SetInstanceMetadata(t *testing.T, name string, metadata *compute.Metadata)
- func Skip32BitWindows(t *testing.T, skipMsg string)
- func SkipWindowsClientImages(t *testing.T)
- func UpsertMetadata(ctx context.Context, key, value string) error
- func ValidWindowsPassword(userPwLgth int) string
- func WindowsContainersOnly(t *testing.T)
- func WindowsOnly(t *testing.T)
- type BlockDevice
- type BlockDeviceList
- type FileType
- type ProcessStatus
Constants ¶
const ( // GuestAttributeTestNamespace is the namespace for the guest attribute in the daisy "wait for instance" step for CIT. GuestAttributeTestNamespace = "citTest" // GuestAttributeTestKey is the key for the guest attribute in the daisy "wait for instance" step for CIT in the common case. GuestAttributeTestKey = "test-complete" // FirstBootGAKey is the key for guest attribute in the daisy "wait for instance" step in the case where it is the first boot, and we still want to wait for results from a subsequent reboot. FirstBootGAKey = "first-boot-key" )
Variables ¶
var ( // ErrMDSEntryNotFound is an error used to report 404 status code. ErrMDSEntryNotFound = errors.New("No metadata entry found: 404 error") )
var ( // ErrPackageManagersNotFound is the error message returned when an object is not found. ErrPackageManagersNotFound = fmt.Errorf("no supported package managers found") )
Functions ¶
func AccessSecret ¶
func AccessSecret(ctx context.Context, client *secretmanager.Client, secretName string) (string, error)
AccessSecret accesses the given secret.
func CheckLinuxCmdExists ¶
CheckLinuxCmdExists checks that a command exists on the linux image, and is executable.
func CheckPowershellReturnCode ¶
CheckPowershellReturnCode returns an error if the exit code doesn't match the expected value.
func CheckPowershellSuccess ¶
CheckPowershellSuccess returns an error if the powershell command fails.
func Context ¶
Context returns a context to be used by test implementations, it handles the context cancellation based on the test's timeout(deadline), if no timeout is defined (or the deadline can't be assessed) then a plain background context is returned.
func CreateClient ¶
CreateClient create a ssh client to connect host.
func DownloadGCSObject ¶
DownloadGCSObject downloads a GCS object.
func DownloadGCSObjectToFile ¶
func DownloadGCSObjectToFile(ctx context.Context, client *storage.Client, gcsPath, file string) error
DownloadGCSObjectToFile downloads a GCS object, writing it to the specified file.
func DownloadPrivateKey ¶
DownloadPrivateKey download private key from daisy source.
func ExtractBaseImageName ¶
ExtractBaseImageName extract the base image name from full image resource.
func FailOnPowershellFail ¶
FailOnPowershellFail fails the test if the powershell command fails.
func FilterLoopbackTunnelingInterfaces ¶
FilterLoopbackTunnelingInterfaces filters the list of interfaces to contain only the actual NICs, removing the loopback and tunneling interfaces listed in skipInterfaces.
func GetDaisyClient ¶
func GetDaisyClient(ctx context.Context) (daisyCompute.Client, error)
GetDaisyClient returns a daisy compute client with the correct compute endpoint.
func GetHostKeysFileFromDisk ¶
GetHostKeysFileFromDisk read ssh host public key as bytes
func GetHostKeysFromDisk ¶
GetHostKeysFromDisk read ssh host public key and parse
func GetInstanceMetadata ¶
GetInstanceMetadata gets the metadata for the instance.
func GetInstanceName ¶
GetInstanceName gets the instance name.
func GetInterface ¶
GetInterface returns the interface corresponding to the metadata interface array at the specified index.
func GetInterfaceByMAC ¶
GetInterfaceByMAC returns the interface with the specified MAC address.
func GetMetadata ¶
GetMetadata does a HTTP Get request to the metadata server, the metadata entry of interest is provided by elem as the elements of the entry path, the following example does a Get request to the entry "instance/guest-attributes":
resp, err := GetAttribute(context.Background(), "instance", "guest-attributes") ...
func GetMetadataWithHeaders ¶
GetMetadataWithHeaders is similar to GetMetadata it only differs on the return where GetMetadata returns only the response's body as a string and an error GetMetadataWithHeaders returns the response's body as a string, the headers and an error.
func GetMountDiskPartition ¶
GetMountDiskPartition runs lsblk to get the partition of the mount disk on linux, assuming the size of the mount disk is diskExpectedSizeGb.
func GetMountDiskPartitionSymlink ¶
GetMountDiskPartitionSymlink uses symlinks to get the partition of the mount disk on linux, assuming the name of the disk resource is mountDiskName.
func GetProjectZone ¶
GetProjectZone gets the project and zone of the instance.
func GetRealVMName ¶
GetRealVMName returns the real name of a VM running in the same test.
func HasFeature ¶
HasFeature reports whether a compute.Image has a GuestOsFeature tag.
func IfOldAgentInstalled ¶
func IfOldAgentInstalled() bool
IfOldAgentInstalled returns true if the old agent is installed.
func InstallPackage ¶
InstallPackage installs the given packages on the instance.
It supports apt, yum, dnf, and zypper package managers. Returns ErrNotFound if none of the package managers are found.
func Is32BitWindows ¶
Is32BitWindows returns true if the image contains -x86.
func IsCoreDisabled ¶
func IsCoreDisabled() bool
IsCoreDisabled returns true if the core plugin is disabled by the config file.
func IsWindows ¶
func IsWindows() bool
IsWindows returns true if the detected runtime environment is Windows.
func IsWindowsClient ¶
IsWindowsClient returns true if the image is a client (non-server) Windows image.
func ParseHostKey ¶
ParseHostKey parse hostkey data from bytes.
func ParseInterfaceIPv4 ¶
ParseInterfaceIPv4 parses the interface's IPv4 address.
func ParseStderr ¶
ParseStderr returns the stderr output from an exec.ExitError, or the error string if the error is not an exec.ExitError.
func ProcessExistsLinux ¶
ProcessExistsLinux checks if the process exists on Linux.
func ProcessExistsWindows ¶
ProcessExistsWindows checks if the process exists on Windows.
func PutMetadata ¶
PutMetadata does a HTTP Put request to the metadata server, the metadata entry of interest is provided by path as the section of the path after the metadata server, with the data string as the post data. The following example sets the key "instance/guest-attributes/example" to "data":
err := PutMetadata(context.Background(), path.Join("instance", "guest-attributes", "example"), "data") ...
func RestartAgent ¶
RestartAgent restarts the guest agent on the instance.
func SetInstanceMetadata ¶
SetInstanceMetadata sets the instance metadata.
func Skip32BitWindows ¶
Skip32BitWindows skips tests on 32-bit client images.
func SkipWindowsClientImages ¶
SkipWindowsClientImages skips tests on Windows Client Images.
func UpsertMetadata ¶
UpsertMetadata inserts or updates a metadata entry on a currently running instance.
func ValidWindowsPassword ¶
ValidWindowsPassword returns a random password of the given length which meets Windows complexity requirements.
func WindowsContainersOnly ¶
WindowsContainersOnly skips tests not on Windows "for Containers" images.
Types ¶
type BlockDevice ¶
type BlockDevice struct { Name string `json:"name,omitempty"` // on some OSes, size is a string, and on some OSes, size is a number. // This allows both to be parsed Size json.Number `json:"size,omitempty"` Type string `json:"type,omitempty"` // Other fields are not currently used. X map[string]any `json:"-"` }
BlockDevice defines information about a single partition or disk in the output of lsblk.
type BlockDeviceList ¶
type BlockDeviceList struct {
BlockDevices []BlockDevice `json:"blockdevices,omitempty"`
}
BlockDeviceList gives full information about blockdevices, from the output of lsblk.
type ProcessStatus ¶
ProcessStatus holds stdout, stderr and the exit code from an external command call.
func RunPowershellCmd ¶
func RunPowershellCmd(command string) (ProcessStatus, error)
RunPowershellCmd runs a powershell command and returns stdout and stderr if successful.
Directories
¶
Path | Synopsis |
---|---|
Package exceptions provides utilities for checking if an image matches a list of exceptions.
|
Package exceptions provides utilities for checking if an image matches a list of exceptions. |