Skip to content

Commit

Permalink
feat(BDD): add positive test cases for verifying waitforfirstconsumer…
Browse files Browse the repository at this point in the history
… With CStor Volume Provisioning (#1643)

Signed-off-by: mittachaitu <[email protected]>
  • Loading branch information
sai chaithanya authored Apr 3, 2020
1 parent ca49df8 commit 30ae345
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pkg/kubernetes/pod/v1alpha1/buildlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// Podlist
type ListBuilder struct {
list *PodList
filters predicateList
filters PredicateList
}

// NewListBuilder returns a instance of ListBuilder
Expand Down
12 changes: 6 additions & 6 deletions pkg/kubernetes/pod/v1alpha1/buildlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,33 +126,33 @@ func TestFilterList(t *testing.T) {
tests := map[string]struct {
availablePods map[string]string
filteredPods []string
filters predicateList
filters PredicateList
}{
"Pods Set 1": {
availablePods: map[string]string{"Pod 1": "Running", "Pod 2": "CrashLoopBackOff"},
filteredPods: []string{"Pod 1"},
filters: predicateList{IsRunning()},
filters: PredicateList{IsRunning()},
},
"Pods Set 2": {
availablePods: map[string]string{"Pod 1": "Running", "Pod 2": "Running"},
filteredPods: []string{"Pod 1", "Pod 2"},
filters: predicateList{IsRunning()},
filters: PredicateList{IsRunning()},
},

"Pods Set 3": {
availablePods: map[string]string{"Pod 1": "CrashLoopBackOff", "Pod 2": "CrashLoopBackOff", "Pod 3": "CrashLoopBackOff"},
filteredPods: []string{},
filters: predicateList{IsRunning()},
filters: PredicateList{IsRunning()},
},
"Pod Set 4": {
availablePods: map[string]string{"Pod 1": "Running", "Pod 2": "Running"},
filteredPods: []string{},
filters: predicateList{IsNil()},
filters: PredicateList{IsNil()},
},
"Pod Set 5": {
availablePods: map[string]string{"Pod 1": "Running", "Pod 2": "Running"},
filteredPods: []string{"Pod 1", "Pod 2"},
filters: predicateList{},
filters: PredicateList{},
},
"Pod Set 6": {
availablePods: map[string]string{"Pod 1": "Running", "Pod 2": "Running"},
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubernetes/pod/v1alpha1/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type PodList struct {
}

// PredicateList holds a list of predicate
type predicateList []Predicate
type PredicateList []Predicate

// Predicate defines an abstraction
// to determine conditional checks
Expand Down Expand Up @@ -64,7 +64,7 @@ func (pl *PodList) Len() int {
// all returns true if all the predicates
// succeed against the provided pod
// instance
func (l predicateList) all(p *Pod) bool {
func (l PredicateList) all(p *Pod) bool {
for _, pred := range l {
if !pred(p) {
return false
Expand Down
4 changes: 0 additions & 4 deletions pkg/kubernetes/storageclass/v1alpha1/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ func (b *Builder) Build() (*storagev1.StorageClass, error) {
// references the PeristentVolumeClaim. The volume provisioning and
// binding will occur during Pod scheduing.
func (b *Builder) WithVolumeBindingMode(bindingMode storagev1.VolumeBindingMode) *Builder {
if bindingMode == "" {
b.errs = append(b.errs, errors.New("failed to build storageclass: missing volume binding mode"))
return b
}
b.sc.object.VolumeBindingMode = &bindingMode
return b
}
6 changes: 0 additions & 6 deletions pkg/kubernetes/storageclass/v1alpha1/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ func TestBuilderWithVolumeBind(t *testing.T) {
builder: &Builder{sc: &StorageClass{object: &storagev1.StorageClass{}}},
expectErr: false,
},

"Test SC with nil binding mode": {
bindmode: "",
builder: &Builder{sc: &StorageClass{object: &storagev1.StorageClass{}}},
expectErr: true,
},
}
for name, mock := range tests {
name, mock := name, mock
Expand Down
5 changes: 3 additions & 2 deletions tests/cstor/volume/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
cvr "github.com/openebs/maya/pkg/cstor/volumereplica/v1alpha1"
pv "github.com/openebs/maya/pkg/kubernetes/persistentvolume/v1alpha1"
pvc "github.com/openebs/maya/pkg/kubernetes/persistentvolumeclaim/v1alpha1"
pod "github.com/openebs/maya/pkg/kubernetes/pod/v1alpha1"
sc "github.com/openebs/maya/pkg/kubernetes/storageclass/v1alpha1"
spc "github.com/openebs/maya/pkg/storagepoolclaim/v1alpha1"
"github.com/openebs/maya/tests/cstor"
Expand Down Expand Up @@ -212,7 +213,7 @@ var _ = Describe("[Cstor Volume Provisioning Positive] TEST VOLUME PROVISIONING"
Expect(err).To(BeNil(), "While fetching maya-apiserver address")
Expect(len(maddr)).To(Equal(1), "maya-apiserver address")

podList := ops.GetPodList(openebsNamespace, mayaAPIPodLabel)
podList := ops.GetPodList(openebsNamespace, mayaAPIPodLabel, pod.PredicateList{pod.IsRunning()})
Expect(err).To(BeNil(), "maya-apiserver pod fetch error")
mPodList := podList.ToAPIList()
Expect(len(mPodList.Items)).To(Equal(1), "maya-apiserver pod count")
Expand Down Expand Up @@ -284,7 +285,7 @@ var _ = Describe("[Cstor Volume Provisioning Positive] TEST VOLUME PROVISIONING"
Expect(err).To(BeNil(), "While fetching maya-apiserver address")
Expect(len(maddr)).To(Equal(1), "maya-apiserver address")

podList := ops.GetPodList(openebsNamespace, mayaAPIPodLabel)
podList := ops.GetPodList(openebsNamespace, mayaAPIPodLabel, pod.PredicateList{pod.IsRunning()})
Expect(err).To(BeNil(), "maya-apiserver pod fetch error")
mPodList := podList.ToAPIList()
Expect(len(mPodList.Items)).To(Equal(1), "maya-apiserver pod count")
Expand Down
2 changes: 2 additions & 0 deletions tests/cstor/volume/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

apis "github.com/openebs/maya/pkg/apis/openebs.io/v1alpha1"
ns "github.com/openebs/maya/pkg/kubernetes/namespace/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -49,6 +50,7 @@ var (
spcObj *apis.StoragePoolClaim
pvcObj *corev1.PersistentVolumeClaim
spcList *apis.StoragePoolClaimList
appDeployment *appsv1.Deployment
targetLabel = "openebs.io/target=cstor-target"
pvLabel = "openebs.io/persistent-volume="
pvcLabel = "openebs.io/persistent-volume-claim="
Expand Down
139 changes: 139 additions & 0 deletions tests/cstor/volume/waitforfirstconsumer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
Copyright 2020 The OpenEBS Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package volume

import (
"fmt"
"strconv"
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
apis "github.com/openebs/maya/pkg/apis/openebs.io/v1alpha1"
cv "github.com/openebs/maya/pkg/cstor/volume/v1alpha1"
cvr "github.com/openebs/maya/pkg/cstor/volumereplica/v1alpha1"
pod "github.com/openebs/maya/pkg/kubernetes/pod/v1alpha1"
"github.com/openebs/maya/tests"
"github.com/openebs/maya/tests/cstor"
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

// auth plugins

_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
)

// This Test Can Be Run By Using Following Command
// ginkgo -v -focus="\[WAITFORFIRSTCONSUMER\] " -- -kubeconfig=<path_to_kube_config> -cstor-maxpools=<no.of_pools> -cstor-replicas=<no.of_storagereplicas>

var _ = Describe("[WAITFORFIRSTCONSUMER] CStor Volume Provisioning", func() {
When("SPC is created", func() {
It("cStor Pools Should be Provisioned ", func() {

By("Build And Create StoragePoolClaim object")
// Populate configurations and create
spcConfig := &tests.SPCConfig{
Name: spcName,
DiskType: "sparse",
PoolCount: cstor.PoolCount,
IsThickProvisioning: true,
PoolType: "striped",
}
ops.Config = spcConfig
spcObj = ops.BuildAndCreateSPC()
By("Creating SPC, Desired Number of CSP Should Be Created", func() {
ops.VerifyDesiredCSPCount(spcObj, cstor.PoolCount)
})
})
})

When("Apply Volume Related Artifacts", func() {
It("Volume Should be Created and Provisioned", func() {
By("Build And Create StorageClass")

casConfig := strings.Replace(
openebsCASConfigValue, "$spcName", spcObj.Name, 1)
casConfig = strings.Replace(
casConfig, "$count", strconv.Itoa(cstor.ReplicaCount), 1)
annotations[string(apis.CASTypeKey)] = string(apis.CstorVolume)
annotations[string(apis.CASConfigKey)] = casConfig
scConfig := &tests.SCConfig{
Name: scName,
Annotations: annotations,
Provisioner: openebsProvisioner,
VolumeBindingMode: storagev1.VolumeBindingWaitForFirstConsumer,
}
ops.Config = scConfig
scObj = ops.CreateStorageClass()

pvcConfig := &tests.PVCConfig{
Name: pvcName,
Namespace: nsObj.Name,
SCName: scObj.Name,
Capacity: "5G",
AccessModes: accessModes,
}
ops.Config = pvcConfig
pvcObj = ops.BuildAndCreatePVC()
})
})

When("Deploying BusyBox Application", func() {
It("CStor Volume Related Resources Should Be Created and Become Healthy", func() {
var err error
// Deploying Application
By("Building a busybox app pod deployment using above volume")
appDeployment, err = ops.BuildAndDeployBusyBoxPod(
"busybox-cstor",
pvcObj.Name, pvcObj.Namespace,
map[string]string{"app": "busybox"})
Expect(err).ShouldNot(HaveOccurred(), "while building app deployement {%v}", err)

By("Verifying pvc status as bound")

// Verify health of CStor Volume Related CR's
ops.VerifyVolumeStatus(pvcObj,
cstor.ReplicaCount,
cvr.PredicateList{cvr.IsHealthy()},
cv.PredicateList{cv.IsHealthy()},
)
pvcObj, err = ops.PVCClient.
WithNamespace(pvcObj.Namespace).
Get(pvcObj.Name, metav1.GetOptions{})
Expect(err).To(BeNil())
})
})

When("Deleting Application, PVC and SPC", func() {
It("Should Delete Volume and Pools Related to test", func() {
err := ops.DeployClient.WithNamespace(nsObj.Name).
Delete(appDeployment.Name, &metav1.DeleteOptions{})
Expect(err).ShouldNot(HaveOccurred(), "while deleting application pod")
cnt := ops.GetPodCountEventually(nsObj.Name, "app=busybox", pod.PredicateList{}, 0)
Expect(cnt).Should(BeNumerically("==", 0), fmt.Sprintf("While waiting for application pod to scale down"))

ops.DeletePersistentVolumeClaim(pvcObj.Name, pvcObj.Namespace)
ops.VerifyVolumeResources(pvcObj.Spec.VolumeName, openebsNamespace, cvr.PredicateList{}, cv.PredicateList{})
err = ops.SCClient.Delete(scObj.Name, &metav1.DeleteOptions{})
Expect(err).To(BeNil())

err = ops.SPCClient.Delete(
spcObj.Name, &metav1.DeleteOptions{})
Expect(err).To(BeNil(), "while deleting spc {%s}", spcObj.Name)
})
})
})
Loading

0 comments on commit 30ae345

Please sign in to comment.