tests

package
v0.0.0-...-dae0845 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 38 Imported by: 0

README

Local PV Provisioner BDD

Local PV Provisioner BDD tests are developed using ginkgo & gomega libraries.

How to run the tests?

Pre-requisites
  • These tests are meant to be run in a single-node Kubernetes (v1.16+) cluster with one single available blockdevice with no filesystem on it (should not be mounted).

  • Some of the tests require the 'xfsprogs' and 'quota' packages to run. For Ubuntu, you may need to install the quota_v2 kernel module. Install the 'linux-image-extra-virtual' package to install the kernel module.

    $ #For Ubuntu/Debian
    $ sudo apt-get update && sudo apt-get install -y xfsprogs quota linux-image-extra-virtual
    $ ##The kernel module package name may be different depending on the OS image
    $ ##E.g.: linux-modules-extra-`uname -r`
    $ #For CentOS/RHEL
    $ sudo yum install -y xfsprogs quota
    
  • You will require the Ginkgo binary to be able to run the tests. Install the latest Ginkgo binary using the following command:

    $ go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo@v2.14.0
    
  • Get your Kubernetes Cluster ready and make sure you can run kubectl from your development machine. Note down the path to the kubeconfig file used by kubectl to access your cluster. Example: /home/<user>/.kube/config

  • Set the KUBECONFIG environment variable on your development machine to point to the kubeconfig file. Example: export KUBECONFIG=$HOME/.kube/config

    If you do not set this ENV, you will have to pass the file to the Ginkgo CLI (see below)

  • The tests should not be run in parallel as it may lead to unavailability of blockdevices for some of the tests.

  • Install required OpenEBS LocalPV Provisioner components Example: kubectl apply -f https://openebs.github.io/charts/openebs-operator-lite.yaml

Run tests

Run the tests by being in the localpv tests folder.

Note: The tests require privileges to create loop devices and to create directories in the '/var' directory.

$ cd <repo-directory>/tests
$ sudo -E env "PATH=$PATH" ginkgo -v

In case the KUBECONFIG env is not configured, you can run:

$ sudo -E env "PATH=$PATH" ginkgo -v -kubeconfig=/path/to/kubeconfig

If your OpenEBS LocalPV components are in a different Kubernetes namespace than 'openebs', you may use the '-openebs-namespace' flag:

$ sudo -E env "PATH=$PATH" ginkgo -v -openebs-namespace=<your-namespace>

Tip: Raising a pull request to this repo's 'develop' branch (or any one of the release branches) will automatically run the BDD tests in GitHub Actions. You can verify your code changes by moving to the 'Checks' tab in your pull request page, and checking the results of the 'integration-test' check.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildPersistentVolumeClaim

func BuildPersistentVolumeClaim(namespace, pvcName, scName, capacity string, accessModes []corev1.PersistentVolumeAccessMode) (*corev1.PersistentVolumeClaim, error)

BuildPersistentVolumeClaim builds the PVC object

func BuildPod

func BuildPod(namespace, podName, pvcName string, labelselector map[string]string) (*corev1.Pod, error)

BuildPod builds the pod object

Types

type Operations

type Operations struct {
	KubeClient     *kubeclient.Client
	NodeClient     *node.Kubeclient
	EventClient    *event.KubeClient
	PodClient      *pod.KubeClient
	PVCClient      *pvc.Kubeclient
	PVClient       *pv.Kubeclient
	SCClient       *sc.Kubeclient
	NSClient       *ns.Kubeclient
	SVCClient      *svc.Kubeclient
	UnstructClient *unstruct.Kubeclient
	DeployClient   *deploy.Kubeclient
	BDClient       *bd.Kubeclient
	BDCClient      *bdc.Kubeclient
	KubeConfigPath string
	NameSpace      string
	Config         interface{}
}

Operations provides clients amd methods to perform operations

func NewOperations

func NewOperations(opts ...OperationsOptions) *Operations

NewOperations returns a new instance of kubeclient meant for cstor volume replica operations

func (*Operations) BuildAndDeployBusyBoxPod

func (ops *Operations) BuildAndDeployBusyBoxPod(
	appName, pvcName, namespace string,
	labels map[string]string) (*appsv1.Deployment, error)

func (*Operations) CheckPodStatusEventually

func (ops *Operations) CheckPodStatusEventually(namespace, podName string, expectedPodPhase corev1.PodPhase) corev1.PodPhase

CheckPodStatusEventually gives the phase of the pod eventually

func (*Operations) DeletePersistentVolumeClaim

func (ops *Operations) DeletePersistentVolumeClaim(name, namespace string)

DeletePersistentVolumeClaim deletes PVC from cluster based on provided argument

func (*Operations) ExecPod

func (ops *Operations) ExecPod(opts *Options) (string, string, error)
func (ops *Operations) GetBDCStatusAfterAge(bdcName string, namespace string, untilAge time.Duration) bdcExitStatus {
	bdcObj, err := ops.BDCClient.WithNamespace(namespace).Get(context.TODO(), bdcName, metav1.GetOptions{})
	Expect(err).To(
		BeNil(),
		"when geting BDC {%s} initally to calculate Age",
		bdcName,
	)
	initialCreationTimestamp := bdcObj.CreationTimestamp.Time
	untilTimestamp := initialCreationTimestamp.Add(untilAge)

	time.Sleep(time.Until(untilTimestamp))

	bdcObj, err = ops.BDCClient.WithNamespace(namespace).Get(context.TODO(), bdcName, metav1.GetOptions{})
	finalCreationTimestamp := bdcObj.CreationTimestamp.Time
	if isNotFound(err) || finalCreationTimestamp.After(initialCreationTimestamp) {
		return deleted
	} else if bdcObj.Status.Phase == "Pending" {
		return pending
	} else if bdcObj.Status.Phase == "Bound" {
		return bound
	} else {
		return invalid
	}
}

ExecPod executes arbitrary command inside the pod

func (*Operations) ExecuteCMDEventually

func (ops *Operations) ExecuteCMDEventually(
	podObj *corev1.Pod,
	containerName,
	cmd string,
	expectStdout bool,
) string

ExecuteCMDEventually executes the command on pod container and returns stdout

func (*Operations) GetBDCCount

func (ops *Operations) GetBDCCount(lSelector, namespace string) int

GetBDCCount gets BDC resource count based on provided label selector

func (*Operations) GetBDCCountEventually

func (ops *Operations) GetBDCCountEventually(listOptions metav1.ListOptions, expectedBDCCount int, namespace string) int

GetBDCCountEventually gets BDC resource count based on provided list option.

func (*Operations) GetBDNameFromBDCName

func (ops *Operations) GetBDNameFromBDCName(bdcName, namespace string) string

func (*Operations) GetNdmConfigMap

func (ops *Operations) GetNdmConfigMap(
	clientset *kubernetes.Clientset,
	namespace string,
	ndmConfigLabelSelector string,
) (*corev1.ConfigMap, error)

func (*Operations) GetNodeAffinityLabelKeysFromPv

func (ops *Operations) GetNodeAffinityLabelKeysFromPv(pvName string) ([]string, error)

GetNodeAffinityLabelKeysFromPv returns the label keys for NodeSelector MatchExpressions in a PV.

func (*Operations) GetPVNameFromPVCName

func (ops *Operations) GetPVNameFromPVCName(namespace, pvcName string) string

GetPVNameFromPVCName gives the pv name for the given pvc

func (*Operations) GetPodCompletedCount

func (ops *Operations) GetPodCompletedCount(namespace, lselector string) int

GetPodCompletedCount gives number of pods running currently

func (*Operations) GetPodCompletedCountEventually

func (ops *Operations) GetPodCompletedCountEventually(namespace, lselector string, expectedPodCount int) int

GetPodCompletedCountEventually gives the number of pods running eventually

func (*Operations) GetPodCount

func (ops *Operations) GetPodCount(namespace, lselector string) int

GetPodCount gives number of current pods

func (*Operations) GetPodCountEventually

func (ops *Operations) GetPodCountEventually(
	namespace, lselector string,
	predicateList pod.PredicateList, expectedCount int) int

GetPodCountEventually returns the no.of pods exists with specified labelselector

func (*Operations) GetPodList

func (ops *Operations) GetPodList(namespace, lselector string, predicateList pod.PredicateList) *pod.PodList

GetPodList gives list of running pods for given namespace + label

func (*Operations) GetPodRunningCount

func (ops *Operations) GetPodRunningCount(namespace, lselector string) int

GetPodRunningCount gives number of pods running currently

func (*Operations) GetPodRunningCountEventually

func (ops *Operations) GetPodRunningCountEventually(namespace, lselector string, expectedPodCount int) int

GetPodRunningCountEventually gives the number of pods running eventually

func (*Operations) GetReadyNodes

func (ops *Operations) GetReadyNodes() *corev1.NodeList

GetReadyNodes gives cstorvolumereplica healthy count currently based on selecter

func (*Operations) GetSVCClusterIP

func (ops *Operations) GetSVCClusterIP(ns, lselector string) ([]string, error)

GetSVCClusterIP returns list of IP address of the services, having given label and namespace

func (*Operations) IsBDCDeletedEventually

func (ops *Operations) IsBDCDeletedEventually(bdcName, namespace string) bool

IsBDCDeletedEventually tries to get the deleted BDC and returns true if BDC is not found else returns false

func (*Operations) IsBdCleanedUpEventually

func (ops *Operations) IsBdCleanedUpEventually(namespace, bdName, bdcName string) bool

IsBdCleanedUpEventually tries to get the deleted BDC and returns true if BDC is not found else returns false

func (*Operations) IsFinalizerExistsOnBDC

func (ops *Operations) IsFinalizerExistsOnBDC(bdcName, finalizer string) bool

IsFinalizerExistsOnBDC returns true if the object with provided name contains the finalizer.

func (*Operations) IsNdmPrerequisiteMet

func (ops *Operations) IsNdmPrerequisiteMet(
	namespace string,
	ndmLabelSelector string,
	ndmOperatorLabelSelector string,
) bool

This function returns true if: 1. The Pod count for the NDM Daemonset Pod, the NDM Operator are greater than 1 2. Only a single blockdevice without a filesystem in Unclaimed and Active state is available

func (*Operations) IsPVCBound

func (ops *Operations) IsPVCBound(namespace, pvcName string) bool

IsPVCBound checks if the pvc is bound or not

func (*Operations) IsPVCBoundEventually

func (ops *Operations) IsPVCBoundEventually(namespace string, pvcName string) bool

IsPVCBoundEventually checks if the pvc is bound or not eventually

func (*Operations) IsPVCDeleted

func (ops *Operations) IsPVCDeleted(pvcName, namespace string) bool

IsPVCDeleted tries to get the deleted pvc and returns true if pvc is not found else returns false

func (*Operations) IsPVCDeletedEventually

func (ops *Operations) IsPVCDeletedEventually(pvcName, namespace string) bool

IsPVCDeletedEventually tries to get the deleted pvc and returns true if pvc is not found else returns false

func (*Operations) IsPVDeleted

func (ops *Operations) IsPVDeleted(pvName string) bool

IsPVDeleted tries to get the deleted pvc and returns true if PV is not found else returns false

func (*Operations) IsPVDeletedEventually

func (ops *Operations) IsPVDeletedEventually(pvName string) bool

IsPVDeletedEventually tries to get the deleted pvc and returns true if PV is not found else returns false

func (*Operations) IsPodDeletedEventually

func (ops *Operations) IsPodDeletedEventually(namespace, podName string) bool

IsPodDeletedEventually checks if the pod is deleted or not eventually

func (*Operations) IsPodRunningEventually

func (ops *Operations) IsPodRunningEventually(namespace, podName string) bool

IsPodRunningEventually return true if the pod comes to running state

func (*Operations) PathFilterExclude

func (ops *Operations) PathFilterExclude(
	option PathFilterOption,
	namespace string,
	ndmConfigLabelSelector string,
	ndmLabelSelector string,
	diskPath string,
) error

func (*Operations) PodDeleteCollection

func (ops *Operations) PodDeleteCollection(ns string, lopts metav1.ListOptions) error

PodDeleteCollection deletes all the pods in a namespace matched the given labelselector

func (*Operations) VerifyCapacity

func (ops *Operations) VerifyCapacity(namespace, pvcName, capacity string) bool

VerifyCapacity checks if the pvc capacity has been updated

type OperationsOptions

type OperationsOptions func(*Operations)

OperationsOptions abstracts creating an instance of operations

func WithKubeConfigPath

func WithKubeConfigPath(path string) OperationsOptions

WithKubeConfigPath sets the kubeConfig path against operations instance

type Options

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

Options holds the args used for exec'ing into the pod

func NewOptions

func NewOptions() *Options

NewOptions returns the new instance of Options

func (*Options) WithCommand

func (o *Options) WithCommand(cmd ...string) *Options

WithCommand fills the cmd field in Options struct

func (*Options) WithContainer

func (o *Options) WithContainer(container string) *Options

WithContainer fills the container field in Options struct

func (*Options) WithNamespace

func (o *Options) WithNamespace(ns string) *Options

WithNamespace fills the namespace field in Options struct

func (*Options) WithPodName

func (o *Options) WithPodName(name string) *Options

WithPodName fills the podName field in Options struct

type PathFilterOption

type PathFilterOption string

NDM Path-Filter options

const (
	APPEND PathFilterOption = "Append"
	REMOVE PathFilterOption = "Remove"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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