utils

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

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

Go to latest
Published: Feb 28, 2020 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RetryLoop params for tests.
	RetryLoop = 60
	// RetryInterval param for test - wait time while in RetryLoop
	RetryInterval = 5
	// TestMountPath is the path inside a test pod where storage is mounted
	TestMountPath = "/tmp/testrook"
)

Variables

This section is empty.

Functions

func IsKubectlErrorNotFound

func IsKubectlErrorNotFound(output string, err error) bool

Types

type CommandArgs

type CommandArgs struct {
	Command             string
	SubCommand          string
	CmdArgs             []string
	OptionalArgs        []string
	PipeToStdIn         string
	EnvironmentVariable []string
}

CommandArgs is a warpper for cmd args

type CommandOut

type CommandOut struct {
	StdOut   string
	StdErr   string
	ExitCode int
	Err      error
}

CommandOut is a wrapper for cmd out returned after executing command args

func ExecuteCommand

func ExecuteCommand(cmdStruct CommandArgs) CommandOut

ExecuteCommand executes a os command with stdin and returns output

type HelmHelper

type HelmHelper struct {
	HelmPath string
	// contains filtered or unexported fields
}

HelmHelper is wrapper for running helm commands

func NewHelmHelper

func NewHelmHelper(helmPath string) *HelmHelper

NewHelmHelper creates a instance of HelmHelper

func (*HelmHelper) DeleteLocalRookHelmChart

func (h *HelmHelper) DeleteLocalRookHelmChart(deployName string) error

DeleteLocalRookHelmChart uninstalls a give helm deploy

func (*HelmHelper) Execute

func (h *HelmHelper) Execute(args ...string) (string, error)

Execute is wrapper for executing helm commands

func (*HelmHelper) GetLocalRookHelmChartVersion

func (h *HelmHelper) GetLocalRookHelmChartVersion(chartName string) (string, error)

GetLocalRookHelmChartVersion returns helm chart version for a given chart

func (*HelmHelper) InstallLocalRookHelmChart

func (h *HelmHelper) InstallLocalRookHelmChart(chartName string, deployName string, chartVersion string, namespace, chartSettings string) error

InstallLocalRookHelmChart installs a give helm chart

type K8sHelper

type K8sHelper struct {
	Clientset        *kubernetes.Clientset
	RookClientset    *rookclient.Clientset
	RunningInCluster bool
	T                func() *testing.T
	// contains filtered or unexported fields
}

K8sHelper is a helper for common kubectl commads

func CreateK8sHelper

func CreateK8sHelper(t func() *testing.T) (*K8sHelper, error)

CreateK8sHelper creates a instance of k8sHelper

func (*K8sHelper) ChangeHostnames

func (k8sh *K8sHelper) ChangeHostnames() error

ChangeHostnames modifies the node hostname label to run tests in an environment where the node name is different from the hostname label

func (*K8sHelper) CheckPodCountAndState

func (k8sh *K8sHelper) CheckPodCountAndState(podName string, namespace string, minExpected int, expectedPhase string) bool

CheckPodCountAndState returns true if expected number of pods with matching name are found and are in expected state

func (*K8sHelper) CheckPvcCountAndStatus

func (k8sh *K8sHelper) CheckPvcCountAndStatus(podName string, namespace string, expectedPvcCount int, expectedStatus string) bool

CheckPvcCount returns True if expected number pvs for a app are found

func (*K8sHelper) CollectPodLogsFromLabel

func (k8sh *K8sHelper) CollectPodLogsFromLabel(podLabel, namespace, testName, platformName string)

CollectPodLogsFromLabel collects logs for pods with the given label

func (*K8sHelper) CountPodsWithLabel

func (k8sh *K8sHelper) CountPodsWithLabel(label string, namespace string) (int, error)

func (*K8sHelper) CreateAnonSystemClusterBinding

func (k8sh *K8sHelper) CreateAnonSystemClusterBinding()

CreateAnonSystemClusterBinding Creates anon-user-access clusterrolebinding for cluster-admin role - used by kubeadm env.

func (*K8sHelper) CreateExternalRGWService

func (k8sh *K8sHelper) CreateExternalRGWService(namespace, storeName string) error

CreateExternalRGWService creates a service for rgw access external to the cluster on a node port

func (*K8sHelper) CreateNamespace

func (k8sh *K8sHelper) CreateNamespace(namespace string) error

func (*K8sHelper) DeletePod

func (k8sh *K8sHelper) DeletePod(namespace, name string) error

DeletePod performs a kubectl delete pod on the given pod

func (*K8sHelper) DeletePods

func (k8sh *K8sHelper) DeletePods(pods ...string) (msg string, err error)

DeletePods performs a kubectl delete pod on the given pods

func (*K8sHelper) DeletePvcWithLabel

func (k8sh *K8sHelper) DeletePvcWithLabel(namespace string, podName string) bool

func (*K8sHelper) DeleteResource

func (k8sh *K8sHelper) DeleteResource(args ...string) error

DeleteResource performs a kubectl delete on the given args

func (*K8sHelper) DeleteResourceAndWait

func (k8sh *K8sHelper) DeleteResourceAndWait(wait bool, args ...string) error

DeleteResource performs a kubectl delete on give args. If wait is false, a flag will be passed to indicate the delete should return immediately

func (*K8sHelper) DeleteRoleAndBindings

func (k8sh *K8sHelper) DeleteRoleAndBindings(name, namespace string) error

func (*K8sHelper) DeleteRoleBinding

func (k8sh *K8sHelper) DeleteRoleBinding(name, namespace string) error

func (*K8sHelper) Exec

func (k8sh *K8sHelper) Exec(namespace, podName, command string, commandArgs []string) (string, error)

func (*K8sHelper) ExecWithRetry

func (k8sh *K8sHelper) ExecWithRetry(retries int, namespace, podName, command string, commandArgs []string) (string, error)

ExecWithRetry will attempt to run a command "retries" times, waiting 3s between each call. Upon success, returns the output.

func (*K8sHelper) GetDockerImage

func (k8sh *K8sHelper) GetDockerImage(image string) error

func (*K8sHelper) GetExternalRGWServiceURL

func (k8sh *K8sHelper) GetExternalRGWServiceURL(storeName string, namespace string) (string, error)

GetRGWServiceURL returns URL of ceph RGW service in the cluster

func (*K8sHelper) GetInternalRGWServiceURL

func (k8sh *K8sHelper) GetInternalRGWServiceURL(storeName string, namespace string) (string, error)

GetRGWServiceURL returns URL of ceph RGW service in the cluster

func (*K8sHelper) GetK8sServerVersion

func (k8sh *K8sHelper) GetK8sServerVersion() string

GetK8sServerVersion returns k8s server version under test

func (*K8sHelper) GetLogsFromNamespace

func (k8sh *K8sHelper) GetLogsFromNamespace(namespace, testName, platformName string)

GetLogsFromNamespace collects logs for all containers in all pods in the namespace

func (*K8sHelper) GetPV

func (k8sh *K8sHelper) GetPV(name string) (*v1.PersistentVolume, error)

GetPV returns PV by name

func (*K8sHelper) GetPVCAccessModes

func (k8sh *K8sHelper) GetPVCAccessModes(namespace string, name string) ([]v1.PersistentVolumeAccessMode, error)

GetPVCAccessModes returns AccessModes on PVC

func (*K8sHelper) GetPVCStatus

func (k8sh *K8sHelper) GetPVCStatus(namespace string, name string) (v1.PersistentVolumeClaimPhase, error)

GetPVCStatus returns status of PVC

func (*K8sHelper) GetPVCVolumeName

func (k8sh *K8sHelper) GetPVCVolumeName(namespace string, name string) (string, error)

GetPVCVolumeName returns volume name of PVC

func (*K8sHelper) GetPodDescribeFromNamespace

func (k8sh *K8sHelper) GetPodDescribeFromNamespace(namespace, testName, platformName string)

func (*K8sHelper) GetPodDetails

func (k8sh *K8sHelper) GetPodDetails(podNamePattern string, namespace string) (string, error)

GetPodDetails returns details about a pod

func (*K8sHelper) GetPodEvents

func (k8sh *K8sHelper) GetPodEvents(podNamePattern string, namespace string) (*v1.EventList, error)

GetPodEvents returns events about a pod

func (*K8sHelper) GetPodHostID

func (k8sh *K8sHelper) GetPodHostID(podNamePattern string, namespace string) (string, error)

GetPodHostID returns HostIP address of a pod

func (*K8sHelper) GetPodNamesForApp

func (k8sh *K8sHelper) GetPodNamesForApp(appName, namespace string) ([]string, error)

func (*K8sHelper) GetRGWServiceURL

func (k8sh *K8sHelper) GetRGWServiceURL(storeName string, namespace string) (string, error)

func (*K8sHelper) GetResource

func (k8sh *K8sHelper) GetResource(args ...string) (string, error)

GetResource performs a kubectl get on give args

func (*K8sHelper) GetService

func (k8sh *K8sHelper) GetService(servicename string, namespace string) (*v1.Service, error)

GetService returns output from "kubectl get svc $NAME" command

func (*K8sHelper) GetServiceNodePort

func (k8sh *K8sHelper) GetServiceNodePort(serviceName string, namespace string) (string, error)

GetServiceNodePort returns nodeProt of service

func (*K8sHelper) GetVolumeResourceName

func (k8sh *K8sHelper) GetVolumeResourceName(namespace, pvcName string) (string, error)

GetVolumeResourceName gets the Volume object name from the PVC

func (*K8sHelper) IsCRDPresent

func (k8sh *K8sHelper) IsCRDPresent(crdName string) bool

IsCRDPresent returns true if custom resource definition is present

func (*K8sHelper) IsDefaultStorageClassPresent

func (k8sh *K8sHelper) IsDefaultStorageClassPresent() (bool, error)

func (*K8sHelper) IsPodInError

func (k8sh *K8sHelper) IsPodInError(podNamePattern, namespace, reason, containingMessage string) bool

IsPodInError returns true if a Pod is in error status with the given reason and contains the given message

func (*K8sHelper) IsPodInExpectedState

func (k8sh *K8sHelper) IsPodInExpectedState(podNamePattern string, namespace string, state string) bool

IsPodInExpectedState waits for 90s for a pod to be an expected state If the pod is in expected state within 90s true is returned, if not false

func (*K8sHelper) IsPodRunning

func (k8sh *K8sHelper) IsPodRunning(name string, namespace string) bool

IsPodRunning returns true if a Pod is running status or goes to Running status within 90s else returns false

func (*K8sHelper) IsPodTerminated

func (k8sh *K8sHelper) IsPodTerminated(name string, namespace string) bool

IsPodTerminated wrapper around IsPodTerminatedWithOpts()

func (*K8sHelper) IsPodTerminatedWithOpts

func (k8sh *K8sHelper) IsPodTerminatedWithOpts(name string, namespace string, getOpts metav1.GetOptions) bool

IsPodTerminatedWithOpts returns true if a Pod is terminated status or goes to Terminated status within 90s else returns false\

func (*K8sHelper) IsPodWithLabelPresent

func (k8sh *K8sHelper) IsPodWithLabelPresent(label string, namespace string) bool

IsPodWithLabelPresent return true if there is at least one Pod with the label is present.

func (*K8sHelper) IsRookInstalled

func (k8sh *K8sHelper) IsRookInstalled(namespace string) bool

IsRookInstalled returns true is rook-ceph-mgr service is running(indicating rook is installed)

func (*K8sHelper) IsServiceUp

func (k8sh *K8sHelper) IsServiceUp(name string, namespace string) bool

IsServiceUp returns true if a service is up or comes up within 150s, else returns false

func (*K8sHelper) IsStorageClassPresent

func (k8sh *K8sHelper) IsStorageClassPresent(name string) error

IsStorageClassPresent returns true if storageClass is present, if not false

func (*K8sHelper) IsVolumeResourceAbsent

func (k8sh *K8sHelper) IsVolumeResourceAbsent(namespace, volumeName string) bool

IsVolumeResourceAbsent returns true if the Volume resource is deleted/absent within 90s else returns false

func (*K8sHelper) IsVolumeResourcePresent

func (k8sh *K8sHelper) IsVolumeResourcePresent(namespace, volumeName string) bool

IsVolumeResourcePresent returns true if Volume resource is present

func (*K8sHelper) Kubectl

func (k8sh *K8sHelper) Kubectl(args ...string) (string, error)

Kubectl is wrapper for executing kubectl commands

func (*K8sHelper) KubectlWithStdin

func (k8sh *K8sHelper) KubectlWithStdin(stdin string, args ...string) (string, error)

KubectlWithStdin is wrapper for executing kubectl commands in stdin

func (*K8sHelper) MakeContext

func (k8sh *K8sHelper) MakeContext() *clusterd.Context

func (*K8sHelper) PrintEventsForNamespace

func (k8sh *K8sHelper) PrintEventsForNamespace(namespace string)

func (*K8sHelper) PrintPVCs

func (k8sh *K8sHelper) PrintPVCs(namespace string, detailed bool)

func (*K8sHelper) PrintPVs

func (k8sh *K8sHelper) PrintPVs(detailed bool)

func (*K8sHelper) PrintPodDescribe

func (k8sh *K8sHelper) PrintPodDescribe(namespace string, args ...string)

func (*K8sHelper) PrintPodStatus

func (k8sh *K8sHelper) PrintPodStatus(namespace string)

PrintPodStatus log out the status phase of a pod

func (*K8sHelper) PrintStorageClasses

func (k8sh *K8sHelper) PrintStorageClasses(detailed bool)

func (*K8sHelper) ReadFromPod

func (k8sh *K8sHelper) ReadFromPod(namespace, podName, filename, expectedMessage string) error

func (*K8sHelper) ReadFromPodRetry

func (k8sh *K8sHelper) ReadFromPodRetry(namespace, podName, filename, expectedMessage string, retries int) error

func (*K8sHelper) ResourceOperation

func (k8sh *K8sHelper) ResourceOperation(action string, manifest string) error

ResourceOperation performs a kubectl action on a pod definition

func (*K8sHelper) ResourceOperationFromTemplate

func (k8sh *K8sHelper) ResourceOperationFromTemplate(action string, podDefinition string, config map[string]string) (string, error)

ResourceOperationFromTemplate performs a kubectl action from a template file after replacing its context

func (*K8sHelper) RestoreHostnames

func (k8sh *K8sHelper) RestoreHostnames() ([]string, error)

RestoreHostnames removes the test suffix from the node hostname labels

func (*K8sHelper) ScaleStatefulSet

func (k8sh *K8sHelper) ScaleStatefulSet(statefulSetName, namespace string, replicationSize int) error

func (*K8sHelper) SetDeploymentVersion

func (k8sh *K8sHelper) SetDeploymentVersion(namespace, deploymentName, containerName, version string) error

SetDeploymentVersion sets the container version on the deployment. It is assumed to be the rook/ceph image.

func (*K8sHelper) VersionAtLeast

func (k8sh *K8sHelper) VersionAtLeast(minVersion string) bool

func (*K8sHelper) VersionMinorMatches

func (k8sh *K8sHelper) VersionMinorMatches(minVersion string) (string, bool)

func (*K8sHelper) WaitForCustomResourceDeletion

func (k8sh *K8sHelper) WaitForCustomResourceDeletion(namespace string, checkerFunc func() error) error

WaitForCustomResourceDeletion waits for the CRD deletion

func (*K8sHelper) WaitForDeploymentCount

func (k8sh *K8sHelper) WaitForDeploymentCount(label, namespace string, count int) error

WaitForDeploymentCount waits until the desired number of deployments with the label exist. The deployments are not guaranteed to be running, only existing.

func (*K8sHelper) WaitForDeploymentCountWithRetries

func (k8sh *K8sHelper) WaitForDeploymentCountWithRetries(label, namespace string, count, retries int) error

WaitForDeploymentCountWithRetries waits until the desired number of deployments with the label exist, retrying the specified number of times. The deployments are not guaranteed to be running, only existing.

func (*K8sHelper) WaitForLabeledDeploymentsToBeReady

func (k8sh *K8sHelper) WaitForLabeledDeploymentsToBeReady(label, namespace string) error

WaitForLabeledDeploymentsToBeReady waits for all deployments matching the given label selector to be fully ready with a default timeout.

func (*K8sHelper) WaitForLabeledDeploymentsToBeReadyWithRetries

func (k8sh *K8sHelper) WaitForLabeledDeploymentsToBeReadyWithRetries(label, namespace string, retries int) error

WaitForLabeledDeploymentsToBeReadyWithRetries waits for all deployments matching the given label selector to be fully ready. Retry the number of times given.

func (*K8sHelper) WaitForLabeledPodsToRun

func (k8sh *K8sHelper) WaitForLabeledPodsToRun(label, namespace string) error

WaitForLabeledPodsToRun calls WaitForLabeledPodsToRunWithRetries with the default number of retries

func (*K8sHelper) WaitForLabeledPodsToRunWithRetries

func (k8sh *K8sHelper) WaitForLabeledPodsToRunWithRetries(label string, namespace string, retries int) error

WaitForLabeledPodsToRunWithRetries returns true if a Pod is running status or goes to Running status within 90s else returns false

func (*K8sHelper) WaitForPodCount

func (k8sh *K8sHelper) WaitForPodCount(label, namespace string, count int) error

WaitForPodCount waits until the desired number of pods with the label are started

func (*K8sHelper) WaitUntilNameSpaceIsDeleted

func (k8sh *K8sHelper) WaitUntilNameSpaceIsDeleted(namespace string) bool

WaitUntilNameSpaceIsDeleted waits for namespace to be deleted for 180s. If namespace is deleted True is returned, if not false.

func (*K8sHelper) WaitUntilPVCIsBound

func (k8sh *K8sHelper) WaitUntilPVCIsBound(namespace string, pvcname string) bool

WaitUntilPVCIsBound waits for a PVC to be in bound state for 90 seconds if PVC goes to Bound state within 90s True is returned, if not false

func (*K8sHelper) WaitUntilPVCIsDeleted

func (k8sh *K8sHelper) WaitUntilPVCIsDeleted(namespace string, pvcname string) bool

func (*K8sHelper) WaitUntilPVCIsExpanded

func (k8sh *K8sHelper) WaitUntilPVCIsExpanded(namespace, pvcname, size string) bool

WaitUntilPVCIsExpanded waits for a PVC to be resized for specified value

func (*K8sHelper) WaitUntilPodInNamespaceIsDeleted

func (k8sh *K8sHelper) WaitUntilPodInNamespaceIsDeleted(podNamePattern string, namespace string) bool

WaitUntilPodInNamespaceIsDeleted waits for 90s for a pod in a namespace to be terminated If the pod disappears within 90s true is returned, if not false

func (*K8sHelper) WaitUntilPodIsDeleted

func (k8sh *K8sHelper) WaitUntilPodIsDeleted(name, namespace string) bool

WaitUntilPodIsDeleted waits for 90s for a pod to be terminated If the pod disappears within 90s true is returned, if not false

func (*K8sHelper) WaitUntilPodWithLabelDeleted

func (k8sh *K8sHelper) WaitUntilPodWithLabelDeleted(label string, namespace string) bool

WaitUntilPodWithLabelDeleted returns true if a Pod is deleted within 90s else returns false

func (*K8sHelper) WriteToPod

func (k8sh *K8sHelper) WriteToPod(namespace, podName, filename, message string) error

WriteToPod write file in Pod

func (*K8sHelper) WriteToPodRetry

func (k8sh *K8sHelper) WriteToPodRetry(namespace, podName, filename, message string, retries int) error

WriteToPodRetry WriteToPod in a retry loop

type MySQLHelper

type MySQLHelper struct {
	DB *sql.DB
}

MySQLHelper contains pointer to MySqlDB and wrappers for basic object on mySql database

func CreateNewMySQLHelper

func CreateNewMySQLHelper(username string, password string, url string, dbname string) *MySQLHelper

CreateNewMySQLHelper creates a s3 client for specified endpoint and creds

func (*MySQLHelper) CloseConnection

func (h *MySQLHelper) CloseConnection()

CloseConnection function closes mysql connection

func (*MySQLHelper) CreateTable

func (h *MySQLHelper) CreateTable() sql.Result

CreateTable func create sample Table

func (*MySQLHelper) DeleteRandomRow

func (h *MySQLHelper) DeleteRandomRow() sql.Result

DeleteRandomRow deletes a random row

func (*MySQLHelper) InsertRandomData

func (h *MySQLHelper) InsertRandomData(dataSize int) sql.Result

InsertRandomData Inserts random Data into the table

func (*MySQLHelper) PingSuccess

func (h *MySQLHelper) PingSuccess() bool

PingSuccess function is used check connection to a database

func (*MySQLHelper) SelectRandomData

func (h *MySQLHelper) SelectRandomData(limit int) *sql.Rows

TableRowCount gets row count of table

func (*MySQLHelper) TableExists

func (h *MySQLHelper) TableExists() bool

TableExists checks if a table exists

func (*MySQLHelper) TableRowCount

func (h *MySQLHelper) TableRowCount() (count int)

TableRowCount gets row count of table

type S3Helper

type S3Helper struct {
	// contains filtered or unexported fields
}

S3Helper contains pointer to s3 client and wrappers for basic object store operations

func CreateNewS3Helper

func CreateNewS3Helper(endpoint string, keyID string, keySecret string) *S3Helper

CreateNewS3Helper creates a s3 client for specified endpoint and creds

func (*S3Helper) CreateBucket

func (h *S3Helper) CreateBucket(name string) (bool, error)

CreateBucket function creates bucket using s3 client

func (*S3Helper) DeleteBucket

func (h *S3Helper) DeleteBucket(name string) (bool, error)

DeleteBucket function deletes given bucket using s3 client

func (*S3Helper) DeleteObjectInBucket

func (h *S3Helper) DeleteObjectInBucket(bucketname string, key string) (bool, error)

DeleteObjectInBucket function deletes given bucket using s3 client

func (*S3Helper) GetObjectInBucket

func (h *S3Helper) GetObjectInBucket(bucketname string, key string) (string, error)

GetObjectInBucket function retrieves an object from a bucket using s3 client

func (*S3Helper) IsBucketPresent

func (h *S3Helper) IsBucketPresent(bucketname string) (bool, error)

IsBucketPresent function returns true if a bucket is present and false if it's not present

func (*S3Helper) PutObjectInBucket

func (h *S3Helper) PutObjectInBucket(bucketname string, body string, key string,
	contentType string) (bool, error)

PutObjectInBucket function puts an object in a bucket using s3 client

Jump to

Keyboard shortcuts

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