forked from openebs-archive/maya
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cstor, csi, BDD): add integration test for cstor volume provisio…
…ning via CSI (openebs-archive#1215) Add BDD test for provisioning cstor Volume via CSI. Test provision a cstor volume and delete using CSI driver. Signed-off-by: Payes <[email protected]>
- Loading branch information
1 parent
f73db03
commit f4dd6ae
Showing
3 changed files
with
254 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/* | ||
Copyright 2019 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 ( | ||
"strconv" | ||
"strings" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
apis "github.com/openebs/maya/pkg/apis/openebs.io/v1alpha1" | ||
pvc "github.com/openebs/maya/pkg/kubernetes/persistentvolumeclaim/v1alpha1" | ||
sc "github.com/openebs/maya/pkg/kubernetes/storageclass/v1alpha1" | ||
spc "github.com/openebs/maya/pkg/storagepoolclaim/v1alpha1" | ||
"github.com/openebs/maya/tests/cstor" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
var _ = Describe("[cstor] [sparse] TEST VOLUME PROVISIONING", func() { | ||
var ( | ||
err error | ||
pvcName = "cstor-volume-claim" | ||
) | ||
|
||
BeforeEach(func() { | ||
When(" creating a cstor based volume", func() { | ||
By("building a storagepoolclaim") | ||
spcObj = spc.NewBuilder(). | ||
WithGenerateName(spcName). | ||
WithDiskType(string(apis.TypeSparseCPV)). | ||
WithMaxPool(cstor.PoolCount). | ||
WithOverProvisioning(false). | ||
WithPoolType(string(apis.PoolTypeStripedCPV)). | ||
Build().Object | ||
|
||
By("creating above storagepoolclaim") | ||
spcObj, err = ops.SPCClient.Create(spcObj) | ||
Expect(err).To(BeNil(), | ||
"while creating spc with prefix {%s}", spcName) | ||
|
||
By("verifying healthy cstorpool count") | ||
cspCount := ops.GetHealthyCSPCount(spcObj.Name, cstor.PoolCount) | ||
Expect(cspCount).To(Equal(cstor.PoolCount), | ||
"while checking healthy cstor pool count") | ||
|
||
By("building a CAS Config with generated SPC name") | ||
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 | ||
|
||
By("building a storageclass") | ||
scObj, err = sc.NewBuilder(). | ||
WithGenerateName(scName). | ||
WithAnnotations(annotations). | ||
WithProvisioner(openebsProvisioner).Build() | ||
Expect(err).ShouldNot(HaveOccurred(), | ||
"while building storageclass obj with prefix {%s}", scName) | ||
|
||
By("creating above storageclass") | ||
scObj, err = ops.SCClient.Create(scObj) | ||
Expect(err).To(BeNil(), "while creating storageclass with prefix {%s}", scName) | ||
|
||
}) | ||
}) | ||
|
||
AfterEach(func() { | ||
By("deleting resources created for testing cstor volume provisioning", | ||
func() { | ||
By("deleting storagepoolclaim") | ||
_, err = ops.SPCClient.Delete( | ||
spcObj.Name, &metav1.DeleteOptions{}) | ||
Expect(err).To(BeNil(), "while deleting spc {%s}", spcObj.Name) | ||
By("deleting storageclass") | ||
err = ops.SCClient.Delete(scObj.Name, &metav1.DeleteOptions{}) | ||
Expect(err).To(BeNil(), | ||
"while deleting storageclass {%s}", scObj.Name) | ||
}) | ||
}) | ||
|
||
When("cstor pvc with replicacount 1 is created", func() { | ||
It("should create cstor volume target pod", func() { | ||
|
||
By("building a pvc") | ||
pvcObj, err = pvc.NewBuilder(). | ||
WithName(pvcName). | ||
WithNamespace(nsObj.Name). | ||
WithStorageClass(scObj.Name). | ||
WithAccessModes(accessModes). | ||
WithCapacity(capacity).Build() | ||
Expect(err).ShouldNot( | ||
HaveOccurred(), | ||
"while building pvc {%s} in namespace {%s}", | ||
pvcName, | ||
nsObj.Name, | ||
) | ||
|
||
By("creating above pvc") | ||
_, err = ops.PVCClient.WithNamespace(nsObj.Name).Create(pvcObj) | ||
Expect(err).To( | ||
BeNil(), | ||
"while creating pvc {%s} in namespace {%s}", | ||
pvcName, | ||
nsObj.Name, | ||
) | ||
|
||
By("verifying target pod count as 1") | ||
targetVolumeLabel := pvcLabel + pvcObj.Name | ||
controllerPodCount := ops.GetPodRunningCountEventually( | ||
openebsNamespace, targetVolumeLabel, 1) | ||
Expect(controllerPodCount).To(Equal(1), | ||
"while checking controller pod count") | ||
|
||
By("verifying pvc status as bound") | ||
status := ops.IsPVCBound(pvcName) | ||
Expect(status).To(Equal(true), | ||
"while checking status equal to bound") | ||
|
||
By("deleting above pvc") | ||
err := ops.PVCClient.Delete(pvcName, &metav1.DeleteOptions{}) | ||
Expect(err).To( | ||
BeNil(), | ||
"while deleting pvc {%s} in namespace {%s}", | ||
pvcName, | ||
nsObj.Name, | ||
) | ||
|
||
By("verifying target pod count as 0") | ||
controllerPodCount = ops.GetPodRunningCountEventually( | ||
openebsNamespace, targetLabel, 0) | ||
Expect(controllerPodCount).To(Equal(0), | ||
"while checking controller pod count") | ||
|
||
By("verifying deleted pvc") | ||
pvc := ops.IsPVCDeleted(pvcName) | ||
Expect(pvc).To(Equal(true), "while trying to get deleted pvc") | ||
|
||
By("verifying if cstorvolume is deleted") | ||
CstorVolumeLabel := "openebs.io/persistent-volume=" + pvcObj.Spec.VolumeName | ||
cvCount := ops.GetCstorVolumeCountEventually( | ||
openebsNamespace, CstorVolumeLabel, 0) | ||
Expect(cvCount).To(Equal(true), "while checking cstorvolume count") | ||
}) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
Copyright 2019 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 ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/openebs/maya/tests" | ||
"github.com/openebs/maya/tests/cstor" | ||
|
||
apis "github.com/openebs/maya/pkg/apis/openebs.io/v1alpha1" | ||
ns "github.com/openebs/maya/pkg/kubernetes/namespace/v1alpha1" | ||
corev1 "k8s.io/api/core/v1" | ||
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" | ||
) | ||
|
||
var ( | ||
openebsNamespace = "openebs" | ||
nsName = "cstor-provision" | ||
scName = "cstor-volume" | ||
openebsCASConfigValue = ` | ||
- name: ReplicaCount | ||
value: $count | ||
- name: StoragePoolClaim | ||
value: $spcName | ||
` | ||
openebsProvisioner = "openebs-csi.openebs.io" | ||
spcName = "sparse-pool-auto" | ||
nsObj *corev1.Namespace | ||
scObj *storagev1.StorageClass | ||
spcObj *apis.StoragePoolClaim | ||
pvcObj *corev1.PersistentVolumeClaim | ||
targetLabel = "openebs.io/target=cstor-target" | ||
pvcLabel = "openebs.io/persistent-volume-claim=" | ||
accessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce} | ||
capacity = "5G" | ||
annotations = map[string]string{} | ||
) | ||
|
||
func TestSource(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Test cstor volume provisioning") | ||
} | ||
|
||
func init() { | ||
cstor.ParseFlags() | ||
} | ||
|
||
var ops *tests.Operations | ||
|
||
var _ = BeforeSuite(func() { | ||
|
||
ops = tests.NewOperations(tests.WithKubeConfigPath(cstor.KubeConfigPath)).VerifyOpenebs(1) | ||
var err error | ||
By("building a namespace") | ||
nsObj, err = ns.NewBuilder(). | ||
WithGenerateName(nsName). | ||
APIObject() | ||
Expect(err).ShouldNot(HaveOccurred(), "while building namespace {%s}", nsObj.Name) | ||
|
||
By("creating above namespace") | ||
nsObj, err = ops.NSClient.Create(nsObj) | ||
Expect(err).To(BeNil(), "while creating namespace {%s}", nsObj.Name) | ||
}) | ||
|
||
var _ = AfterSuite(func() { | ||
|
||
By("deleting namespace") | ||
err := ops.NSClient.Delete(nsObj.Name, &metav1.DeleteOptions{}) | ||
Expect(err).To(BeNil(), "while deleting namespace {%s}", nsObj.Name) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters