resources

package
v0.0.0-...-3924ef3 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RemoveBucketNamePrefix

func RemoveBucketNamePrefix(bucket string) string

RemoveBucketNamePrefix removes the prefix from the bucket name and returns the test run ID.

Types

type EC2MetadataAPI

type EC2MetadataAPI interface {
	GetInstanceIdentityDocument() (ec2metadata.EC2InstanceIdentityDocument, error)
}

EC2MetadataAPI provides an interface to enable mocking the ec2metadata.EC2Metadata service client's APIs.

type Instance

type Instance struct {
	InstanceId   string   `json:"instance-id"`
	InstanceType string   `json:"instance-type"`
	VCpus        string   `json:"vCPUs"`
	Memory       string   `json:"memory"`
	Os           string   `json:"OS"`
	Architecture string   `json:"Architecture"`
	IsTimeout    bool     `json:"isTimeout"`
	Results      []Result `json:"results"`
}

Instance contains the data of an instance.

type Metric

type Metric struct {
	MetricUsed string  `json:"metric"`
	Value      float64 `json:"value"`
	Threshold  float64 `json:"threshold"`
	Unit       string  `json:"unit"`
}

Metric represents the metric data.

type Resources

type Resources struct {
	EC2                 ec2iface.EC2API
	AutoScaling         autoscalingiface.AutoScalingAPI
	S3                  s3iface.S3API
	S3ManagerUploader   s3manageriface.UploaderAPI
	S3ManagerDownloader s3manageriface.DownloaderAPI
	CloudFormation      cloudformationiface.CloudFormationAPI
	CloudWatch          cloudwatchiface.CloudWatchAPI
	EC2Metadata         EC2MetadataAPI
}

Resources is used to store clients for AWS services.

func New

func New(sess *session.Session) *Resources

New creates an instance of Resources provided an AWS session.

func (Resources) CreateBucket

func (itf Resources) CreateBucket(runId string, outputStream *os.File) error

CreateBucket creates a bucket and blocks all public access.

func (Resources) CreateCfnStack

func (itf Resources) CreateCfnStack(cfnTemplate string, vpcId string, subnetId string, outputStream *os.File) error

CreateCfnStack creates the CloudFormation stack for the instance-qualifier run.

func (Resources) CreateInstance

func (itf Resources) CreateInstance(instanceType string, vCpus string, memory string, osVersion string, architecture string) (instance Instance, err error)

CreateInstance populates the Instance struct with metadata.

func (Resources) DeleteBucket

func (itf Resources) DeleteBucket() error

DeleteBucket empties and deletes the instance-qualifier bucket.

func (Resources) DeleteCfnStack

func (itf Resources) DeleteCfnStack() error

DeleteCfnStack starts the async deletion of instance-qualifier CloudFormation stack.

func (Resources) DownloadFromBucket

func (itf Resources) DownloadFromBucket(bucket string, localPath string, remotePath string) error

DownloadFromBucket downloads a file from the bucket to the specified local location.

func (Resources) DownloadFromS3

func (itf Resources) DownloadFromS3(bucketName string, remotePath string) ([]byte, error)

DownloadFromS3 is similar to DownloadFromBucket, but returns bytes directly instead of saving to a local file

func (Resources) FindBestAvailabilityZone

func (itf Resources) FindBestAvailabilityZone(instanceTypes string, subnetId string) (bestAvailabilityZone string, supportedInstanceTypes []string, err error)

FindBestAvailabilityZone finds the Availability Zone that can support the most instance types provided by the user. It returns the name of the best Availability Zone, and user-specified instance types that are available in that Availability Zone.

func (Resources) GetAmiId

func (itf Resources) GetAmiId(amiId string, inputStream *os.File, outputStream *os.File) (string, error)

GetAmiId returns the AMI ID. If the user provides a valid AMI ID, return it; otherwise, return the ID of the latest AMI of Amazon Linux 2 in the current region.

func (Resources) GetCloudWatchData

func (itf Resources) GetCloudWatchData(instances []Instance, testFixture config.TestFixture) (resp *cloudwatch.GetMetricDataOutput, err error)

GetCloudWatchData retrieves instance metric data from CloudWatch

func (Resources) GetInstancesInCfnStack

func (itf Resources) GetInstancesInCfnStack() (instances []Instance, err error)

GetInstancesInCfnStack populates InstanceId and InstanceType fields of the Instance struct for all instances in the CloudFormation stack, and returns them.

func (Resources) GetRegion

func (itf Resources) GetRegion() (region string, err error)

GetRegion returns the AWS region.

func (Resources) GetSupportedInstances

func (itf Resources) GetSupportedInstances(instanceTypes []string, amiId string, subnetId string) (instances []Instance, err error)

GetSupportedInstances returns instances that are supported to be launched. It checks 2 things: 1. Whether the instance type is available in the Availability Zone. 2. Whether the instance type supports the AMI architecture. The metadata of returned instances is also populated.

func (Resources) GetVpcAndSubnetIds

func (itf Resources) GetVpcAndSubnetIds(vpcId string, subnetId string, inputStream *os.File, outputStream *os.File) (string, string, error)

GetVpcAndSubnetIds returns VPC and subnet IDs.

If the user doesn't specify VPC nor subnet, the function returns "NONE" for both VPC and subnet IDs, meaning that a new VPC infrastructure needs to be created.

If the user only specifies VPC, the function asks the user to choose any one of subnets in that VPC. If the VPC ID is invalid, the user will be asked whether to create a new VPC. If there is no subnet in the VPC, an error will be returned.

If the user only specifies subnet, the function finds the corresponding VPC and returns the IDs of them. If the subnet ID is invalid, the user will be asked whether to create a new VPC.

If the user specifies both VPC and subnet, the function validates them. If valid, returns them; otherwise, returns error.

func (Resources) IsInstanceRunning

func (itf Resources) IsInstanceRunning(instanceId string) (bool, error)

IsInstanceRunning returns true if an instance is in running state; false otherwise.

func (Resources) UploadToBucket

func (itf Resources) UploadToBucket(bucket string, localPath string, remotePath string) error

UploadToBucket uploads a local file to the specified location of the bucket.

func (Resources) UploadToS3

func (itf Resources) UploadToS3(bucketName string, data io.Reader, remotePath string) error

UploadToS3 is similar to UploadToBucket, but provide data directly instead of a local file

func (Resources) WaitUntilCfnStackDeleteComplete

func (itf Resources) WaitUntilCfnStackDeleteComplete() error

WaitUntilCfnStackDeleteComplete waits until the stack deletion is complete.

type Result

type Result struct {
	Label         string   `json:"label"`
	Status        string   `json:"status"`
	ExecutionTime string   `json:"execution-time"`
	Metrics       []Metric `json:"Metrics"`
}

Result represents the result of one test file.

Jump to

Keyboard shortcuts

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