bat

package
v0.0.0-...-3c0cf66 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

README

BAT

The BAT package provides a set of utility functions that can be used to test and manipulate a ciao cluster. These functions are just wrappers around the ciao-cli command. They invoke ciao-cli commands and parse and return the output from these commands in easily consumable go values. Invoking the ciao-cli commands directly, rather than calling the REST APIs exposed by ciao's various services, allows us to test a little bit more of ciao.

Example

Here's a quick example. The following code retrieves the instances defined on the default tenant and prints out their UUIDs and statuses.

	instances, err := bat.GetAllInstances(context.Background(), "")
	if err != nil {
		return err
	}
	for uuid, instance := range instances {
		fmt.Printf("%s : %s\n", uuid, instance.Status)
	}

The bat.GetAllInstances command calls ciao-cli instance list.

Documentation

Overview

Package bat contains a number of helper functions that can be used to perform various operations on a ciao cluster such as creating an instance or retrieving a list of all the defined workloads, etc. All of these helper functions are implemented by calling ciao-cli rather than by using ciao's REST APIs. This package is mainly intended for use by BAT tests. Manipulating the cluster via ciao-cli, rather than through the REST APIs, allows us to test a little bit more of ciao.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteAllInstances

func DeleteAllInstances(ctx context.Context, tenant string) error

DeleteAllInstances deletes all the instances created for the specified tenant by calling ciao-cli instance delete -all. It returns an error if the ciao-cli command fails. An error will be returned if the following environment variables are not set; CIAO_IDENTITY, CIAO_CONTROLLER, CIAO_USERNAME, CIAO_PASSWORD.

func DeleteInstance

func DeleteInstance(ctx context.Context, tenant string, instance string) error

DeleteInstance deletes a specific instance from the cluster. It deletes the instance using ciao-cli instance delete. An error will be returned if the following environment variables are not set; CIAO_IDENTITY, CIAO_CONTROLLER, CIAO_USERNAME, CIAO_PASSWORD.

func DeleteInstances

func DeleteInstances(ctx context.Context, tenant string, instances []string) ([]error, error)

DeleteInstances deletes a set of instances provided by the instances slice. If the function encounters an error deleting an instance it records the error and proceeds to the delete the next instance. The function returns two values, an error and a slice of errors. A single error value is set if any of the instance deletion attempts failed. A slice of errors is also returned so that the caller can determine which of the deletion attempts failed. The indices in the error slice match the indicies in the instances slice, i.e., a non nil value in the first element of the error slice indicates that there was an error deleting the first instance in the instances slice. An error will be returned if the following environment variables are not set; CIAO_IDENTITY, CIAO_CONTROLLER, CIAO_USERNAME, CIAO_PASSWORD.

func GetAllInstances

func GetAllInstances(ctx context.Context, tenant string) (map[string]*Instance, error)

GetAllInstances returns information about all instances in the specified tenant in a map. The key of the map is the instance uuid. The information is retrieved by calling ciao-cli instance list. An error will be returned if the following environment variables are not set; CIAO_IDENTITY, CIAO_CONTROLLER, CIAO_USERNAME, CIAO_PASSWORD.

func GetCNCIs

func GetCNCIs(ctx context.Context) (map[string]*CNCI, error)

GetCNCIs returns a map of the CNCIs present in the cluster. The key of the map is the CNCI ID. The CNCI information is retrieved using ciao-cli list -cnci command. An error will be returned if the following environment are not set; CIAO_IDENTITY, CIAO_CONTROLLER, CIAO_ADMIN_USERNAME, CIAO_ADMIN_PASSWORD.

func LaunchInstances

func LaunchInstances(ctx context.Context, tenant string, workload string, num int) ([]string, error)

LaunchInstances launches num instances of the specified workload. On success the function returns a slice of UUIDs of the new instances. The instances are launched using ciao-cli instance add. An error will be returned if the following environment variables are not set; CIAO_IDENTITY, CIAO_CONTROLLER, CIAO_USERNAME, CIAO_PASSWORD.

func RetrieveInstanceStatus

func RetrieveInstanceStatus(ctx context.Context, tenant string, instance string) (string, error)

RetrieveInstanceStatus retrieve the status of a specific instance. This information is retrieved using ciao-cli instance show. An error will be returned if the following environment variables are not set; CIAO_IDENTITY, CIAO_CONTROLLER, CIAO_USERNAME, CIAO_PASSWORD.

func RetrieveInstancesStatuses

func RetrieveInstancesStatuses(ctx context.Context, tenant string) (map[string]string, error)

RetrieveInstancesStatuses retrieves the statuses of a slice of specific instances. This information is retrieved using ciao-cli instance list. An error will be returned if the following environment variables are not set; CIAO_IDENTITY, CIAO_CONTROLLER, CIAO_USERNAME, CIAO_PASSWORD.

func RunCIAOCLI

func RunCIAOCLI(ctx context.Context, tenant string, args []string) ([]byte, error)

RunCIAOCLI execs the ciao-cli command with a set of arguments. The ciao-cli process will be killed if the context is Done. An error will be returned if the following environment are not set; CIAO_IDENTITY, CIAO_CONTROLLER, CIAO_USERNAME, CIAO_PASSWORD. On success the data written to ciao-cli on stdout will be returned.

func RunCIAOCLIAsAdmin

func RunCIAOCLIAsAdmin(ctx context.Context, tenant string, args []string) ([]byte, error)

RunCIAOCLIAsAdmin execs the ciao-cli command as the admin user with a set of provided arguments. The ciao-cli process will be killed if the context is Done. An error will be returned if the following environment are not set; CIAO_IDENTITY, CIAO_CONTROLLER, CIAO_ADMIN_USERNAME, CIAO_ADMIN_PASSWORD. On success the data written to ciao-cli on stdout will be returned.

func RunCIAOCLIAsAdminJS

func RunCIAOCLIAsAdminJS(ctx context.Context, tenant string, args []string,
	jsdata interface{}) error

RunCIAOCLIAsAdminJS is similar to RunCIAOCLIAsAdmin with the exception that the output of the ciao-cli command is expected to be in json format. The json is decoded into the jsdata parameter which should be a pointer to a type that corresponds to the json output.

func RunCIAOCLIJS

func RunCIAOCLIJS(ctx context.Context, tenant string, args []string, jsdata interface{}) error

RunCIAOCLIJS is similar to RunCIAOCLI with the exception that the output of the ciao-cli command is expected to be in json format. The json is decoded into the jsdata parameter which should be a pointer to a type that corresponds to the json output.

func StartRandomInstances

func StartRandomInstances(ctx context.Context, tenant string, num int) ([]string, error)

StartRandomInstances starts a specified number of instances using a random workload. The UUIDs of the started instances are returned to the user. An error will be returned if the following environment variables are not set; CIAO_IDENTITY, CIAO_CONTROLLER, CIAO_USERNAME, CIAO_PASSWORD.

func WaitForInstancesLaunch

func WaitForInstancesLaunch(ctx context.Context, tenant string, instances []string,
	mustBeActive bool) ([]string, error)

WaitForInstancesLaunch waits for a slice of newly created instances to be scheduled. An instance is scheduled when its status changes from pending to exited or active. If mustBeActive is set to true, the function will fail if it sees an instance that has been scheduled but whose status is exited. The function returns a slice of instance UUIDs and an error. In the case of success, the returned slice of UUIDs will equal the instances array. In the case of error, these two slices may be different. This can happen if one or more of the instances has failed to launch. If errors are detected with multiple instances, e.g., mustBeActive is true and two instances have a status of 'exited' the error returned will refers to the first instance only. An error will be returned if the following environment variables are not set; CIAO_IDENTITY, CIAO_CONTROLLER, CIAO_USERNAME, CIAO_PASSWORD.

Types

type CNCI

type CNCI struct {
	TenantID  string   `json:"tenant_id"`
	IPv4      string   `json:"ip"`
	Geography string   `json:"geo"`
	Subnets   []string `json:"subnets"`
}

CNCI contains information about a CNCI

type ClusterStatus

type ClusterStatus struct {
	TotalNodes            int `json:"nodes"`
	TotalNodesReady       int `json:"ready"`
	TotalNodesFull        int `json:"full"`
	TotalNodesOffline     int `json:"offline"`
	TotalNodesMaintenance int `json:"maintenance"`
}

ClusterStatus contains information about the status of a ciao cluster

func GetClusterStatus

func GetClusterStatus(ctx context.Context) (*ClusterStatus, error)

GetClusterStatus returns the status of the ciao cluster. The information is retrieved by calling ciao-cli node status. An error will be returned if the following environment are not set; CIAO_IDENTITY, CIAO_CONTROLLER, CIAO_ADMIN_USERNAME, CIAO_ADMIN_PASSWORD.

type Instance

type Instance struct {
	HostID     string `json:"host_id"`
	TenantID   string `json:"tenant_id"`
	FlavorID   string `json:"flavor_id"`
	ImageID    string `json:"image_id"`
	Status     string `json:"status"`
	PrivateIP  string `json:"private_ip"`
	MacAddress string `json:"mac_address"`
	SSHIP      string `json:"ssh_ip"`
	SSHPort    int    `json:"ssh_port"`
}

Instance contains detailed information about an instance

func GetInstance

func GetInstance(ctx context.Context, tenant string, uuid string) (*Instance, error)

GetInstance returns an Instance structure that contains information about a specific instance. The informaion is retrieved by calling ciao-cli show --instance. An error will be returned if the following environment variables are not set; CIAO_IDENTITY, CIAO_CONTROLLER, CIAO_USERNAME, CIAO_PASSWORD.

type Tenant

type Tenant struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Tenant contains basic information about a tenant

func GetAllTenants

func GetAllTenants(ctx context.Context) ([]*Tenant, error)

GetAllTenants retrieves a list of all tenants in the cluster by calling ciao-cli tenant list -all. An error will be returned if the following environment variables are not set; CIAO_IDENTITY, CIAO_CONTROLLER, CIAO_ADMIN_USERNAME, CIAO_ADMIN_PASSWORD.

type Workload

type Workload struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	ImageUUID string `json:"image_uuid"`
	CPUs      int    `json:"cpus"`
	Mem       int    `json:"mem"`
}

Workload contains detailed information about a workload

func GetAllWorkloads

func GetAllWorkloads(ctx context.Context, tenant string) ([]Workload, error)

GetAllWorkloads retrieves a list of all workloads in the cluster by calling ciao-cli workload list. An error will be returned if the following environment variables are not set; CIAO_IDENTITY, CIAO_CONTROLLER, CIAO_USERNAME, CIAO_PASSWORD.

Jump to

Keyboard shortcuts

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