sanity

package
v0.3.0-4 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

README

CSI Driver Sanity Tester

This library provides a simple way to ensure that a CSI driver conforms to the CSI specification. There are two ways to leverage this testing framework. For CSI drivers written in Golang, the framework provides a simple API function to call to test the driver. Another way to run the test suite is to use the command line program csi-sanity.

For Golang CSI Drivers

This framework leverages the Ginkgo BDD testing framework to deliver a descriptive test suite for your driver. To test your driver, simply call the API in one of your Golang TestXXX functions. For example:

func TestMyDriver(t *testing.T) {
	// Setup the full driver and its environment
	... setup driver ...
	config := &sanity.Config{
		TargetPath:     ...
		StagingPath:    ...
		Address:        endpoint,
	}


	// Now call the test suite
	sanity.Test(t, config)
}

Only one such test function is supported because under the hood a Ginkgo test suite gets constructed and executed by the call.

Alternatively, the tests can also be embedded inside a Ginkgo test suite. In that case it is possible to define multiple tests with different configurations:

var _ = Describe("MyCSIDriver", func () {
	Context("Config A", func () {
		var config &sanity.Config

		BeforeEach() {
			... setup driver and config...
		}

		AfterEach() {
			...tear down driver...
		}

		Describe("CSI sanity", func() {
			sanity.GinkgoTest(config)
		})
	})

	Context("Config B", func () {
		...
	})
})

Command line program

Please see csi-sanity

Documentation

Index

Constants

View Source
const (
	// DefTestVolumeSize defines the base size of dynamically
	// provisioned volumes. 10GB by default, can be overridden by
	// setting Config.TestVolumeSize.
	DefTestVolumeSize int64 = 10 * 1024 * 1024 * 1024

	MaxNameLength int = 128
)

Variables

This section is empty.

Functions

func DescribeSanity

func DescribeSanity(text string, body func(*SanityContext)) bool

DescribeSanity must be used instead of the usual Ginkgo Describe to register a test block. The difference is that the body function will be called multiple times with the right context (when setting up a Ginkgo suite or a testing.T test, with the right configuration).

func GinkgoTest

func GinkgoTest(reqConfig *Config)

func MakeCreateSnapshotReq

func MakeCreateSnapshotReq(sc *SanityContext, name, sourceVolumeId string, parameters map[string]string) *csi.CreateSnapshotRequest

func MakeCreateVolumeReq

func MakeCreateVolumeReq(sc *SanityContext, name string) *csi.CreateVolumeRequest

func MakeDeleteSnapshotReq

func MakeDeleteSnapshotReq(sc *SanityContext, id string) *csi.DeleteSnapshotRequest

func MakeDeleteVolumeReq

func MakeDeleteVolumeReq(sc *SanityContext, id string) *csi.DeleteVolumeRequest

func Test

func Test(t *testing.T, reqConfig *Config)

Test will test the CSI driver at the specified address by setting up a Ginkgo suite and running it.

func TestVolumeSize

func TestVolumeSize(sc *SanityContext) int64

Types

type CSISecrets

type CSISecrets struct {
	CreateVolumeSecret              map[string]string `yaml:"CreateVolumeSecret"`
	DeleteVolumeSecret              map[string]string `yaml:"DeleteVolumeSecret"`
	ControllerPublishVolumeSecret   map[string]string `yaml:"ControllerPublishVolumeSecret"`
	ControllerUnpublishVolumeSecret map[string]string `yaml:"ControllerUnpublishVolumeSecret"`
	NodeStageVolumeSecret           map[string]string `yaml:"NodeStageVolumeSecret"`
	NodePublishVolumeSecret         map[string]string `yaml:"NodePublishVolumeSecret"`
	CreateSnapshotSecret            map[string]string `yaml:"CreateSnapshotSecret"`
	DeleteSnapshotSecret            map[string]string `yaml:"DeleteSnapshotSecret"`
}

CSISecrets consists of secrets used in CSI credentials.

type Cleanup

type Cleanup struct {
	Context                    *SanityContext
	ControllerClient           csi.ControllerClient
	NodeClient                 csi.NodeClient
	ControllerPublishSupported bool
	NodeStageSupported         bool
	// contains filtered or unexported fields
}

Cleanup keeps track of resources, in particular volumes, which need to be freed when testing is done.

func (*Cleanup) DeleteVolumes

func (cl *Cleanup) DeleteVolumes()

DeleteVolumes stops using the registered volumes and tries to delete all of them.

func (*Cleanup) MaybeRegisterVolume

func (cl *Cleanup) MaybeRegisterVolume(name string, vol *csi.CreateVolumeResponse, err error)

MaybeRegisterVolume adds or updates an entry for the volume with the given name if CreateVolume was successful.

func (*Cleanup) RegisterVolume

func (cl *Cleanup) RegisterVolume(name string, info VolumeInfo)

RegisterVolume adds or updates an entry for the volume with the given name.

func (*Cleanup) UnregisterVolume

func (cl *Cleanup) UnregisterVolume(name string)

UnregisterVolume removes the entry for the volume with the given name, thus preventing all cleanup operations for it.

type Config

type Config struct {
	TargetPath     string
	StagingPath    string
	Address        string
	SecretsFile    string
	TestVolumeSize int64
}

Config provides the configuration for the sanity tests. It needs to be initialized by the user of the sanity package.

type SanityContext

type SanityContext struct {
	Config  *Config
	Conn    *grpc.ClientConn
	Secrets *CSISecrets
	// contains filtered or unexported fields
}

SanityContext holds the variables that each test can depend on. It gets initialized before each test block runs.

type VolumeInfo

type VolumeInfo struct {
	// Node on which the volume was published, empty if none
	// or publishing is not supported.
	NodeID string

	// Volume ID assigned by CreateVolume.
	VolumeID string
}

VolumeInfo keeps track of the information needed to delete a volume.

Jump to

Keyboard shortcuts

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