Skip to content

Commit

Permalink
Add BDD spec (#198)
Browse files Browse the repository at this point in the history
* tests(quota): add namespace to the PVC delete calls

Signed-off-by: Niladri Halder <[email protected]>

* tests(bdd): add bdd specs for existing tests

Signed-off-by: Niladri Halder <[email protected]>

* tests(bdd): use Then directive to only check code behaviour

Signed-off-by: Niladri Halder <[email protected]>

---------

Signed-off-by: Niladri Halder <[email protected]>
  • Loading branch information
niladrih authored Jul 30, 2024
1 parent 52d6cb5 commit eb0e8bd
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 4 deletions.
56 changes: 56 additions & 0 deletions tests/bdd/ext4_quota.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Feature: Hostpath EXT4 Quota Local PV

Scenario: HostPath EXT4 Quota Local PV with Unsupported Filesystem
Given a sparse file "disk.img"
And a loop device is created on top of disk.img

When a StorageClass is created with the following attributes:
| name | sc-hp-ext4 |
| BasePath | /path/to/hostpath |
| EXT4QuotaEnabled | "true" |
| softLimit | "20%" |
| hardLimit | "50%" |
| provisionerName | openebs.io/local |
| volumeBindingMode | WaitForFirstConsumer |
| reclaimPolicy | Delete |
And a minix filesystem is written into the loop device
And the minix filesystem is mounted with project quota enabled
And a PVC "pvc-hp-ext4" is created with the StorageClass "sc-hp-ext4"
And a Pod is created with PVC "pvc-hp-ext4"
Then the Pod should be in pending state
And the PVC should be in pending state

When the Pod "busybox-hostpath" is deleted
Then the Pod should be deleted successfully

When the PVC "pvc-hp-ext4" is deleted
Then the PVC should be deleted successfully

Scenario: HostPath EXT4 Quota Local PV with EXT4 Filesystem
Given a sparse file "disk.img"
And a loop device is created on top of disk.img

When a StorageClass with valid EXT4 quota parameters is created
Then it should create a StorageClass with the following attributes:
| name | sc-hp-ext4 |
| BasePath | /path/to/hostpath |
| EXT4QuotaEnabled | "true" |
| provisionerName | openebs.io/local |
| volumeBindingMode | WaitForFirstConsumer |
| reclaimPolicy | Delete |

When the loop device is formatted with EXT4 filesystem
And the ext4 filesysten is mounted with project quota enabled
And a PVC "pvc-hp-ext4" is created with the StorageClass "sc-hp-ext4"
And a Pod is created with PVC "pvc-hp-ext4"
Then the Pod should be up and running

When data is written more than the quota limit into the hostpath volume
Then the container process should not be able to write more than the enforced limit

When the Pod consuming PVC "pvc-hp-ext4" is deleted
Then the Pod should be deleted successfully

When the PVC "pvc-hp-ext4" is deleted
Then the PVC should be deleted successfully
And the Provisioner should delete the PV
30 changes: 30 additions & 0 deletions tests/bdd/hostpath.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Feature: TEST HOSTPATH LOCAL PV

Scenario: Creating and Deleting StorageClass, PVC, and Deployment with Busybox
Given a hostpath provisioner is running
When a StorageClass is created with the following attributes:
| name | sc-hp |
| BasePath | /path/to/hostpath |
| provisionerName | openebs.io/local |
| volumeBindingMode | WaitForFirstConsumer |
| reclaimPolicy | Delete |
And a PVC is created with the following attributes:
| name | pvc-hp |
| storageClass | sc-hp |
| accessModes | ReadWriteOnce |
| capacity | 2Gi |
And a deployment with a busybox image is created with the following attributes:
| name | busybox-hostpath |
| image | busybox |
| command | ["sleep", "3600"] |
| volumeMounts | name: demo-vol1, mountPath: /mnt/store1 |
| volumes | name: demo-vol1, pvcName: pvc-hp |
Then the Pod should be in Running state
And a bound PV should be created

When the deployment is deleted
Then the deployment should not have any deployment or pod remaining

When the PVC is deleted
Then the PVC should be deleted successfully
Then the PV should be deleted
21 changes: 21 additions & 0 deletions tests/bdd/nodeAffinityLabels_cas_config.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Volume Provisioning/De-provisioning with NodeAffinityLabels CAS-config on StorageClass

Scenario: Volume provisioning/de-provisioning with custom NodeAffinityLabels CAS-config on StorageClass
When a StorageClass is created with the following attributes:
| name | sc-nod-aff-lab |
| BasePath | /path/to/hostpath |
| NodeAffinityLabels | "kubernetes.io/hostname", "kubernetes.io/os", "kubernetes.io/arch" |
| provisionerName | openebs.io/local |
| volumeBindingMode | WaitForFirstConsumer |
| reclaimPolicy | Delete |
And a PVC "pvc-nod-aff-lab" is created with StorageClass "sc-nod-aff-lab"
And a deployment with a busybox image is created with PVC "pvc-nod-aff-lab"
Then a Pod should be up and running
And a bound PV should be created
And the SC NodeAffinityLabels CAS-config should be set correctly on the PV

When the application Deployment is deleted
Then The Pod should be deleted

When the PVC is deleted
Then the PV should be deleted
50 changes: 50 additions & 0 deletions tests/bdd/pvc_cas_config.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Feature: Volume Provisioning/De-provisioning with Additive and Conflicting CAS-configs on PVC and SC

Scenario: Additive CAS-configs on PVC and SC
When a StorageClass with is created with the following attributes:
| name | sc-additive-cas-config |
| BasePath | /path/to/hostpath |
| provisionerName | openebs.io/local |
| volumeBindingMode | WaitForFirstConsumer |
| reclaimPolicy | Delete |
And a PVC "pvc-additive-cas-config" is created with the following attributes:
| name | pvc-additive-cas-config |
| storageClass | sc-hp |
| NodeAffinityLabels | "kubernetes.io/os", "kubernetes.io/arch" |
| accessModes | ReadWriteOnce |
| capacity | 2Gi |
And a Deployment is created with PVC "pvc-additive-cas-config"
Then the Pod should be up and running
And a bound PV should be created
And the PVC NodeAffinityLabels CAS-configs should be set correctly on the PV

When the application Deployment is deleted
Then The Pod should be deleted

When the PVC is deleted
Then the PV should be deleted

Scenario: Conflicting CAS-configs on PVC and SC
When a StorageClass is created with the following attributes:
| name | sc-conflicting-cas-config |
| BasePath | /path/to/hostpath |
| NodeAffinityLabels | "kubernetes.io/hostname" |
| provisionerName | openebs.io/local |
| volumeBindingMode | WaitForFirstConsumer |
| reclaimPolicy | Delete |
And a PVC "pvc-conflicting-cas-config" is created with the following attributes:
| name | pvc-conflicting-cas-config |
| storageClass | sc-hp |
| NodeAffinityLabels | "kubernetes.io/os", "kubernetes.io/arch" |
| accessModes | ReadWriteOnce |
| capacity | 2Gi |
And a Deployment is created with PVC "pvc-conflicting-cas-config"
Then a Pod should be up and running
And a bound PV should be created
And the SC NodeAffinityLabels CAS-config should be set correctly on the PV

When the application Deployment deleted
Then The Pod should be deleted

When the PVC is deleted
Then the PV should be deleted
54 changes: 54 additions & 0 deletions tests/bdd/xfs_quota.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Feature: Hostpath XFS Quota Local PV

Scenario: HostPath XFS Quota Local PV with Unsupported Filesystem
Given a sparse file "disk.img"
And a loop device is created on top of disk.img

When a StorageClass is created with the following attributes:
| name | sc-hp-xfs |
| BasePath | /path/to/hostpath |
| XFSQuotaEnabled | "true" |
| softLimit | "20%" |
| hardLimit | "50%" |
| provisionerName | openebs.io/local |
| volumeBindingMode | WaitForFirstConsumer |
| reclaimPolicy | Delete |
And a minix filesystem is written into the loop device
And the minix filesystem is mounted with project quota enabled
And a PVC "pvc-hp-xfs" is created with the StorageClass "sc-hp-xfs"
And a Pod is created with PVC "pvc-hp-xfs"
Then the Pod should be in pending state
And the PVC should be in pending state

When the Pod "busybox-hostpath" is deleted
Then the Pod should be deleted successfully

When the PVC "pvc-hp-xfs" is deleted
Then the PVC should be deleted successfully

Scenario: HostPath XFS Quota Local PV with XFS Filesystem
Given a sparse file "disk.img"
And a loop device is created on top of disk.img

When a StorageClass is created with the following attributes:
| name | sc-hp-xfs |
| BasePath | /path/to/hostpath |
| XFSQuotaEnabled | "true" |
| provisionerName | openebs.io/local |
| volumeBindingMode | WaitForFirstConsumer |
| reclaimPolicy | Delete |
And the loop device is formatted with XFS filesystem
And the xfs filesysten is mounted with project quota enabled
And a PVC "pvc-hp-xfs" is created with the StorageClass "sc-hp-xfs"
And a Pod is created with PVC "pvc-hp-xfs"
Then the Pod should be up and running

When data is written more than the quota limit into the hostpath volume
Then the container process should not be able to write more than the enforced limit

When the Pod consuming PVC "pvc-hp-xfs" is deleted
Then the Pod should be deleted successfully

When the PVC "pvc-hp-xfs" is deleted
Then the PVC should be deleted successfully
And the Provisioner should delete the PV
8 changes: 4 additions & 4 deletions tests/hostpath_quota_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ var _ = Describe("TEST HOSTPATH XFS QUOTA LOCAL PV WITH UNSUPPORTED FILESYSTEM",
)

By("deleting above PVC")
err = ops.PVCClient.Delete(context.TODO(), pvcName, &metav1.DeleteOptions{})
err = ops.PVCClient.WithNamespace(namespaceObj.Name).Delete(context.TODO(), pvcName, &metav1.DeleteOptions{})
Expect(err).To(
BeNil(),
"while deleting pvc {%s} in namespace {%s}",
Expand Down Expand Up @@ -357,7 +357,7 @@ var _ = Describe("TEST HOSTPATH XFS QUOTA LOCAL PV WITH XFS FILESYSTEM", func()
)

By("deleting above PVC")
err = ops.PVCClient.Delete(context.TODO(), pvcName, &metav1.DeleteOptions{})
err = ops.PVCClient.WithNamespace(namespaceObj.Name).Delete(context.TODO(), pvcName, &metav1.DeleteOptions{})
Expect(err).To(
BeNil(),
"while deleting pvc {%s} in namespace {%s}",
Expand Down Expand Up @@ -543,7 +543,7 @@ var _ = Describe("TEST HOSTPATH EXT4 QUOTA LOCAL PV WITH UNSUPPORTED FILESYSTEM"
)

By("deleting above PVC")
err = ops.PVCClient.Delete(context.TODO(), pvcName, &metav1.DeleteOptions{})
err = ops.PVCClient.WithNamespace(namespaceObj.Name).Delete(context.TODO(), pvcName, &metav1.DeleteOptions{})
Expect(err).To(
BeNil(),
"while deleting pvc {%s} in namespace {%s}",
Expand Down Expand Up @@ -736,7 +736,7 @@ var _ = Describe("TEST HOSTPATH EXT4 QUOTA LOCAL PV WITH EXT4 FILESYSTEM", func(
)

By("deleting above PVC")
err = ops.PVCClient.Delete(context.TODO(), pvcName, &metav1.DeleteOptions{})
err = ops.PVCClient.WithNamespace(namespaceObj.Name).Delete(context.TODO(), pvcName, &metav1.DeleteOptions{})
Expect(err).To(
BeNil(),
"while deleting pvc {%s} in namespace {%s}",
Expand Down

0 comments on commit eb0e8bd

Please sign in to comment.