adding additional tests for block storage

- tests creating pvcs with various AccessModes
 - Mounting and unmounting PVCs with various AccessModes
 - Scaling up PVCs via stateful sets
This commit is contained in:
Divesh Angula committed 2018-01-02 20:35:31 -08:00
1 parent 9678d80ed0
commit a33c58ab71
9 files changed
+659 -28

No files matched your search

Vendored
+1 -1
View File
@@ -152,7 +152,7 @@ def RunIntegrationTest(k, v) {
set -o pipefail
export KUBECONFIG=$HOME/admin.conf
kubectl config view
_output/tests/linux_amd64/integration -test.v -test.timeout 1800s --host_type '''+"${k}"+''' 2>&1 | tee _output/tests/integrationTests.log'''
_output/tests/linux_amd64/integration -test.v -test.timeout 2400s --host_type '''+"${k}"+''' 2>&1 | tee _output/tests/integrationTests.log'''
}
}
finally{
+9 -4
View File
@@ -30,7 +30,7 @@ parameters:
clusterName: ` + namespace
}
func GetBlockPvcDef(claimName string, storageClassName string) string {
func GetBlockPvcDef(claimName string, storageClassName string, accessModes string) string {
return `apiVersion: v1
kind: PersistentVolumeClaim
metadata:
@@ -39,7 +39,7 @@ metadata:
volume.beta.kubernetes.io/storage-class: ` + storageClassName + `
spec:
accessModes:
- ReadWriteOnce
- ` + accessModes + `
resources:
requests:
storage: 1M`
@@ -51,8 +51,13 @@ func concatYaml(first, second string) string {
` + second
}
func GetBlockPoolStorageClassAndPvcDef(namespace string, poolName string, storageClassName string, blockName string) string {
func GetBlockPoolStorageClassAndPvcDef(namespace string, poolName string, storageClassName string, blockName string, accessMode string) string {
return concatYaml(GetBlockPoolDef(poolName, namespace, "1"),
concatYaml(GetBlockStorageClassDef(poolName, storageClassName, namespace), GetBlockPvcDef(blockName, storageClassName)))
concatYaml(GetBlockStorageClassDef(poolName, storageClassName, namespace), GetBlockPvcDef(blockName, storageClassName, accessMode)))
}
func GetBlockPoolStorageClass(namespace string, poolName string, storageClassName string) string {
return concatYaml(GetBlockPoolDef(poolName, namespace, "1"), GetBlockStorageClassDef(poolName, storageClassName, namespace))
}
+120 -1
View File
@@ -631,6 +631,55 @@ func (k8sh *K8sHelper) IsStorageClassPresent(name string) (bool, error) {
}
//CheckPvcCount returns True if expected number pvs for a app are found
func (k8sh *K8sHelper) CheckPvcCountAndStatus(podName string, namespace string, expectedPvcCount int, expectedStatus string) bool {
logger.Infof("wait until %d pvc for app=%s are present", expectedPvcCount, podName)
listOpts := metav1.ListOptions{LabelSelector: "app=" + podName}
pvcCountCheck := false
actualPvcCount := 0
inc := 0
for inc < RetryLoop {
pvcList, err := k8sh.Clientset.CoreV1().PersistentVolumeClaims(namespace).List(listOpts)
if err != nil {
logger.Errorf("Cannot get pvc for app : %v in namespace %v, err: %v", podName, namespace, err)
return false
}
actualPvcCount = len(pvcList.Items)
if actualPvcCount == expectedPvcCount {
pvcCountCheck = true
break
}
inc++
time.Sleep(RetryInterval * time.Second)
}
if !pvcCountCheck {
logger.Errorf("Expecting %d number of PVCs for %s app, found %d ", expectedPvcCount, podName, actualPvcCount)
return false
}
inc = 0
for inc < RetryLoop {
r := true
pl, _ := k8sh.Clientset.CoreV1().PersistentVolumeClaims(namespace).List(listOpts)
for _, pvc := range pl.Items {
if !(pvc.Status.Phase == v1.PersistentVolumeClaimPhase(expectedStatus)) {
r = false
logger.Infof("waiting for pvc %v to be in %s Phase, currently in %v Phase", pvc.Name, expectedStatus, pvc.Status.Phase)
}
}
if r {
return true
}
inc++
time.Sleep(RetryInterval * time.Second)
}
logger.Errorf("Giving up waiting for %d PVCs for %s app to be in %s phase", expectedPvcCount, podName, expectedStatus)
return false
}
//GetPVCStatus returns status of PVC
func (k8sh *K8sHelper) GetPVCStatus(namespace string, name string) (v1.PersistentVolumeClaimPhase, error) {
getOpts := metav1.GetOptions{}
@@ -644,6 +693,19 @@ func (k8sh *K8sHelper) GetPVCStatus(namespace string, name string) (v1.Persisten
}
//GetPVCAccessModes returns AccessModes on PVC
func (k8sh *K8sHelper) GetPVCAccessModes(namespace string, name string) ([]v1.PersistentVolumeAccessMode, error) {
getOpts := metav1.GetOptions{}
pvc, err := k8sh.Clientset.CoreV1().PersistentVolumeClaims(namespace).Get(name, getOpts)
if err != nil {
return []v1.PersistentVolumeAccessMode{}, fmt.Errorf("PVC %s not found,err->%v", name, err)
}
return pvc.Status.AccessModes, nil
}
//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 (k8sh *K8sHelper) IsPodInExpectedState(podNamePattern string, namespace string, state string) bool {
@@ -668,6 +730,28 @@ func (k8sh *K8sHelper) IsPodInExpectedState(podNamePattern string, namespace str
//CheckPodCountAndState returns true if expected number of pods with matching name are found and are in expected state
func (k8sh *K8sHelper) CheckPodCountAndState(podName string, namespace string, minExpected int, expectedPhase string) bool {
listOpts := metav1.ListOptions{LabelSelector: "app=" + podName}
podCountCheck := false
actualPodCount := 0
inc := 0
for inc < RetryLoop {
podList, err := k8sh.Clientset.CoreV1().Pods(namespace).List(listOpts)
if err != nil {
logger.Errorf("Cannot get logs for app : %v in namespace %v, err: %v", podName, namespace, err)
return false
}
actualPodCount = len(podList.Items)
if actualPodCount >= minExpected {
podCountCheck = true
break
}
inc++
time.Sleep(RetryInterval * time.Second)
}
if !podCountCheck {
logger.Errorf("Expecting %d number of pods for %s app, found %d ", minExpected, podName, actualPodCount)
return false
}
podList, err := k8sh.Clientset.CoreV1().Pods(namespace).List(listOpts)
if err != nil {
@@ -680,7 +764,7 @@ func (k8sh *K8sHelper) CheckPodCountAndState(podName string, namespace string, m
return false
}
inc := 0
inc = 0
for inc < RetryLoop {
r := true
pl, _ := k8sh.Clientset.CoreV1().Pods(namespace).List(listOpts)
@@ -771,6 +855,30 @@ func (k8sh *K8sHelper) WaitUntilPVCIsDeleted(namespace string, pvcname string) b
return false
}
func (k8sh *K8sHelper) DeletePvcWithLabel(namespace string, podName string) bool {
delOpts := metav1.DeleteOptions{}
listOpts := metav1.ListOptions{LabelSelector: "app=" + podName}
err := k8sh.Clientset.CoreV1().PersistentVolumeClaims(namespace).DeleteCollection(&delOpts, listOpts)
if err != nil {
logger.Errorf("cannot deleted PVCs for pods with label app=%s", podName)
return false
}
inc := 0
for inc < RetryLoop {
pvcs, err := k8sh.Clientset.CoreV1().PersistentVolumeClaims(namespace).List(listOpts)
if err == nil {
if len(pvcs.Items) == 0 {
return true
}
}
logger.Infof("waiting for PVCs for pods with label=%s to be deleted.", podName)
inc++
time.Sleep(RetryInterval * time.Second)
}
return false
}
//WaitUntilNameSpaceIsDeleted waits for namespace to be deleted for 180s.
//If namespace is deleted True is returned, if not false.
func (k8sh *K8sHelper) WaitUntilNameSpaceIsDeleted(namespace string) bool {
@@ -936,3 +1044,14 @@ func (k8sh *K8sHelper) DeleteRoleAndBindings(name, namespace string) error {
return nil
}
func (k8sh *K8sHelper) ScaleStatefulSet(statefulsetName string, replicationSize int) bool {
args := []string{"scale", "statefulsets", statefulsetName, fmt.Sprintf("--replicas=%d", replicationSize)}
_, err := k8sh.Kubectl(args...)
if err != nil {
logger.Errorf("stateful set %s not scaled", statefulsetName)
return false
}
logger.Errorf("stateful set %s scaled", statefulsetName)
return true
}
+64 -10
View File
@@ -26,6 +26,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"strconv"
)
var (
@@ -50,14 +51,14 @@ func runBlockE2ETest(helper *clients.TestClient, k8sh *utils.K8sHelper, s suite.
initBlockImages, _ := rbc.BlockList()
logger.Infof("step 1: Create block storage")
_, cbErr := installer.BlockResourceOperation(k8sh, installer.GetBlockPoolStorageClassAndPvcDef(namespace, poolName, storageClassName, blockName), "create")
_, cbErr := installer.BlockResourceOperation(k8sh, installer.GetBlockPoolStorageClassAndPvcDef(namespace, poolName, storageClassName, blockName, "ReadWriteOnce"), "create")
require.Nil(s.T(), cbErr)
require.True(s.T(), retryBlockImageCountCheck(helper, len(initBlockImages), 1), "Make sure a new block is created")
logger.Infof("Block Storage created successfully")
require.True(s.T(), k8sh.WaitUntilPVCIsBound(defaultNamespace, blockName), "Make sure PVC is Bound")
logger.Infof("step 2: Mount block storage")
_, mtErr := rbc.BlockMap(getBlockPodDefintion(podName, blockName), blockMountPath)
_, mtErr := rbc.BlockMap(getBlockPodDefintion(podName, blockName, false), blockMountPath)
require.Nil(s.T(), mtErr)
crdName, err := k8sh.GetVolumeAttachmentResourceName(defaultNamespace, blockName)
require.Nil(s.T(), err)
@@ -78,26 +79,26 @@ func runBlockE2ETest(helper *clients.TestClient, k8sh *utils.K8sHelper, s suite.
logger.Infof("step 5: Mount same block storage on a different pod. Should not be allowed")
otherPod := "block-test2"
_, mtErr = rbc.BlockMap(getBlockPodDefintion(otherPod, blockName), blockMountPath)
_, mtErr = rbc.BlockMap(getBlockPodDefintion(otherPod, blockName, false), blockMountPath)
require.Nil(s.T(), mtErr)
require.True(s.T(), k8sh.IsPodInError(otherPod, defaultNamespace, "FailedMount", "Volume is already attached by pod"), "make sure block-test2 pod errors out while mounting the volume")
logger.Infof("Block Storage successfully fenced")
logger.Infof("step 6: Delete fenced pod")
_, unmtErr := rbc.BlockUnmap(getBlockPodDefintion(otherPod, blockName), blockMountPath)
_, unmtErr := rbc.BlockUnmap(getBlockPodDefintion(otherPod, blockName, false), blockMountPath)
require.Nil(s.T(), unmtErr)
require.True(s.T(), k8sh.IsPodTerminated(otherPod, defaultNamespace), "make sure block-test2 pod is terminated")
logger.Infof("Fenced pod deleted successfully")
logger.Infof("step 7: Unmount block storage")
_, unmtErr = rbc.BlockUnmap(getBlockPodDefintion(podName, blockName), blockMountPath)
_, unmtErr = rbc.BlockUnmap(getBlockPodDefintion(podName, blockName, false), blockMountPath)
require.Nil(s.T(), unmtErr)
require.True(s.T(), k8sh.IsVolumeAttachmentResourceAbsent(installer.SystemNamespace(namespace), crdName), fmt.Sprintf("make sure VolumeAttachment %s is deleted", crdName))
require.True(s.T(), k8sh.IsPodTerminated(blockPodName, defaultNamespace), "make sure block-test pod is terminated")
logger.Infof("Block Storage unmounted successfully")
logger.Infof("step 8: Deleting block storage")
_, dbErr := installer.BlockResourceOperation(k8sh, installer.GetBlockPoolStorageClassAndPvcDef(namespace, poolName, storageClassName, blockName), "delete")
_, dbErr := installer.BlockResourceOperation(k8sh, installer.GetBlockPoolStorageClassAndPvcDef(namespace, poolName, storageClassName, blockName, "ReadWriteOnce"), "delete")
require.Nil(s.T(), dbErr)
require.True(s.T(), retryBlockImageCountCheck(helper, len(initBlockImages), 0), "Make sure a block is deleted")
logger.Infof("Block Storage deleted successfully")
@@ -117,7 +118,7 @@ func runBlockE2ETestLite(helper *clients.TestClient, k8sh *utils.K8sHelper, s su
logger.Infof("step : Create Pool,StorageClass and PVC")
volumeDef := installer.GetBlockPoolStorageClassAndPvcDef(clusterNamespace, poolName, "rook-block", "test-block-claim")
volumeDef := installer.GetBlockPoolStorageClassAndPvcDef(clusterNamespace, poolName, "rook-block", "test-block-claim", "ReadWriteOnce")
res1, err := installer.BlockResourceOperation(k8sh, volumeDef, "create")
require.Contains(s.T(), res1, fmt.Sprintf("pool \"%s\" created", poolName), "Make sure test pool is created")
require.Contains(s.T(), res1, "storageclass \"rook-block\" created", "Make sure storageclass is created")
@@ -180,8 +181,8 @@ func foundPool(helper *clients.TestClient, name string) (bool, error) {
func blockTestDataCleanUp(helper *clients.TestClient, k8sh *utils.K8sHelper, namespace, poolname, storageclassname, blockname, podname string) {
logger.Infof("Cleaning up block storage")
helper.GetBlockClient().BlockUnmap(getBlockPodDefintion(podname, blockname), blockMountPath)
installer.BlockResourceOperation(k8sh, installer.GetBlockPoolStorageClassAndPvcDef(namespace, poolname, storageclassname, blockname), "delete")
helper.GetBlockClient().BlockUnmap(getBlockPodDefintion(podname, blockname, false), blockMountPath)
installer.BlockResourceOperation(k8sh, installer.GetBlockPoolStorageClassAndPvcDef(namespace, poolname, storageclassname, blockname, "ReadWriteOnce"), "delete")
cleanupDynamicBlockStorage(helper)
}
@@ -211,7 +212,7 @@ func cleanupDynamicBlockStorage(helper *clients.TestClient) {
}
func getBlockPodDefintion(podname, blockName string) string {
func getBlockPodDefintion(podname, blockName string, readOnly bool) string {
return `apiVersion: v1
kind: Pod
metadata:
@@ -231,5 +232,58 @@ spec:
- name: block-persistent-storage
persistentVolumeClaim:
claimName: ` + blockName + `
readOnly: ` + strconv.FormatBool(readOnly) + `
restartPolicy: Never`
}
func getBlockStatefulSetDefintion(statefulsetName, podname, StorageClassName string) string {
return `---
apiVersion: v1
kind: Service
metadata:
name: ` + statefulsetName + `
labels:
app: ` + statefulsetName + `
spec:
ports:
- port: 80
name: ` + podname + `
clusterIP: None
selector:
app: ` + statefulsetName + `
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: ` + podname + `
spec:
serviceName: "` + statefulsetName + `"
replicas: 1
template:
metadata:
labels:
app: ` + statefulsetName + `
spec:
containers:
- name: ` + statefulsetName + `
image: busybox
command:
- sleep
- "3600"
ports:
- containerPort: 80
name: ` + podname + `
volumeMounts:
- name: rookpvc
mountPath: /tmp/rook
volumeClaimTemplates:
- metadata:
name: rookpvc
annotations:
volume.beta.kubernetes.io/storage-class: ` + StorageClassName + `
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1M`
}
+137 -11
View File
@@ -27,6 +27,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"k8s.io/api/core/v1"
)
// Test K8s Block Image Creation Scenarios. These tests work when platform is set to Kubernetes
@@ -70,9 +71,9 @@ func (s *K8sBlockImageCreateSuite) TestCreatePVCWhenNoStorageClassExists() {
claimName := "test-no-storage-class-claim"
poolName := "test-no-storage-class-pool"
storageClassName := "rook-block"
defer s.tearDownTest(claimName, poolName, storageClassName)
defer s.tearDownTest(claimName, poolName, storageClassName, "ReadWriteOnce")
result, err := installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef(claimName, storageClassName), "create")
result, err := installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef(claimName, storageClassName, "ReadWriteOnce"), "create")
require.Contains(s.T(), result, fmt.Sprintf("persistentvolumeclaim \"%s\" created", claimName), "Make sure pvc is created. "+result)
require.NoError(s.T(), err)
@@ -87,13 +88,13 @@ func (s *K8sBlockImageCreateSuite) TestCreatePVCWhenNoStorageClassExists() {
}
// Test case when persistentvolumeclaim is created for a valid storage class
func (s *K8sBlockImageCreateSuite) TestCreatePVCWhenStorageClassExists() {
// Test case when persistentvolumeclaim with ReadWriteOnce access is created for a valid storage class
func (s *K8sBlockImageCreateSuite) TestCreatePReadWriteOnceVCWhenStorageClassExists() {
logger.Infof("Test creating PVC(block images) when storage class is created")
claimName := "test-with-storage-class-claim"
poolName := "test-with-storage-class-pool"
storageClassName := "rook-block"
defer s.tearDownTest(claimName, poolName, storageClassName)
defer s.tearDownTest(claimName, poolName, storageClassName, "ReadWriteOnce")
//create pool and storageclass
result0, err0 := installer.BlockResourceOperation(s.kh, installer.GetBlockPoolDef(poolName, s.namespace, "1"), "create")
@@ -109,12 +110,15 @@ func (s *K8sBlockImageCreateSuite) TestCreatePVCWhenStorageClassExists() {
require.True(s.T(), present, "Make sure storageclass is present")
//create pvc
result2, err2 := installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef(claimName, storageClassName), "create")
result2, err2 := installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef(claimName, storageClassName, "ReadWriteOnce"), "create")
require.Contains(s.T(), result2, fmt.Sprintf("persistentvolumeclaim \"%s\" created", claimName), "Make sure pvc is created. "+result2)
require.NoError(s.T(), err2)
//check status of PVC
require.True(s.T(), s.kh.WaitUntilPVCIsBound(defaultNamespace, claimName))
accessModes, err := s.kh.GetPVCAccessModes(defaultNamespace, claimName)
require.NoError(s.T(), err)
assert.Equal(s.T(), accessModes[0], v1.PersistentVolumeAccessMode(v1.ReadWriteOnce))
//check block image count
b, _ := s.bc.BlockList()
@@ -128,7 +132,7 @@ func (s *K8sBlockImageCreateSuite) TestCreateSamePVCTwice() {
claimName := "test-twice-claim"
poolName := "test-twice-pool"
storageClassName := "rook-block"
defer s.tearDownTest(claimName, poolName, storageClassName)
defer s.tearDownTest(claimName, poolName, storageClassName, "ReadWriteOnce")
status, _ := s.kh.GetPVCStatus(defaultNamespace, claimName)
logger.Infof("PVC %s status: %s", claimName, status)
s.bc.BlockList()
@@ -147,7 +151,7 @@ func (s *K8sBlockImageCreateSuite) TestCreateSamePVCTwice() {
require.True(s.T(), present, "Make sure storageclass is present")
logger.Infof("create pvc")
result2, err2 := installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef(claimName, storageClassName), "create")
result2, err2 := installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef(claimName, storageClassName, "ReadWriteOnce"), "create")
require.Contains(s.T(), result2, fmt.Sprintf("persistentvolumeclaim \"%s\" created", claimName), "Make sure pvc is created. "+result2)
require.NoError(s.T(), err2)
@@ -159,7 +163,7 @@ func (s *K8sBlockImageCreateSuite) TestCreateSamePVCTwice() {
assert.Equal(s.T(), s.initBlockCount+1, len(b1), "Make sure new block image is created")
logger.Infof("Create same pvc again")
result3, err3 := installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef(claimName, storageClassName), "create")
result3, err3 := installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef(claimName, storageClassName, "ReadWriteOnce"), "create")
require.Contains(s.T(), result3, fmt.Sprintf("persistentvolumeclaims \"%s\" already exists", claimName), "make sure PVC is not created again. "+result3)
require.NoError(s.T(), err3)
@@ -172,8 +176,130 @@ func (s *K8sBlockImageCreateSuite) TestCreateSamePVCTwice() {
}
func (s *K8sBlockImageCreateSuite) tearDownTest(claimName string, poolName string, storageClassName string) {
installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef(claimName, storageClassName), "delete")
// Test case when persistentvolumeclaim with ReadOnlyMany
func (s *K8sBlockImageCreateSuite) TestCreateReadOnlyManyPVCWhenStorageClassExists() {
logger.Infof("Test creating PVC(block images) when storage class is created")
claimName := "test-with-storage-class-claim-rox"
poolName := "test-with-storage-class-pool-rox"
storageClassName := "rook-block"
defer s.tearDownTest(claimName, poolName, storageClassName, "ReadOnlyMany")
//create pool and storageclass
result0, err0 := installer.BlockResourceOperation(s.kh, installer.GetBlockPoolDef(poolName, s.namespace, "1"), "create")
require.Contains(s.T(), result0, fmt.Sprintf("pool \"%s\" created", poolName), "Make sure test pool is created")
require.NoError(s.T(), err0)
result1, err1 := installer.BlockResourceOperation(s.kh, installer.GetBlockStorageClassDef(poolName, storageClassName, s.namespace), "create")
require.Contains(s.T(), result1, fmt.Sprintf("storageclass \"%s\" created", storageClassName), "Make sure storageclass is created")
require.NoError(s.T(), err1)
//make sure storageclass is created
present, err := s.kh.IsStorageClassPresent(storageClassName)
require.Nil(s.T(), err)
require.True(s.T(), present, "Make sure storageclass is present")
//create pvc
result2, err2 := installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef(claimName, storageClassName, "ReadOnlyMany"), "create")
require.Contains(s.T(), result2, fmt.Sprintf("persistentvolumeclaim \"%s\" created", claimName), "Make sure pvc is created. "+result2)
require.NoError(s.T(), err2)
//check status of PVC
require.True(s.T(), s.kh.WaitUntilPVCIsBound(defaultNamespace, claimName))
accessModes, err := s.kh.GetPVCAccessModes(defaultNamespace, claimName)
require.NoError(s.T(), err)
assert.Equal(s.T(), accessModes[0], v1.PersistentVolumeAccessMode(v1.ReadOnlyMany))
//check block image count
b, _ := s.bc.BlockList()
require.Equal(s.T(), s.initBlockCount+1, len(b), "Make sure new block image is created")
}
// Test case when persistentvolumeclaim with ReadWriteMany
func (s *K8sBlockImageCreateSuite) TestCreateReadWriteManyPVCWhenStorageClassExists() {
logger.Infof("Test creating PVC(block images) when storage class is created")
claimName := "test-with-storage-class-claim-rwx"
poolName := "test-with-storage-class-pool-rwx"
storageClassName := "rook-block"
defer s.tearDownTest(claimName, poolName, storageClassName, "ReadWriteMany")
//create pool and storageclass
result0, err0 := installer.BlockResourceOperation(s.kh, installer.GetBlockPoolDef(poolName, s.namespace, "1"), "create")
require.Contains(s.T(), result0, fmt.Sprintf("pool \"%s\" created", poolName), "Make sure test pool is created")
require.NoError(s.T(), err0)
result1, err1 := installer.BlockResourceOperation(s.kh, installer.GetBlockStorageClassDef(poolName, storageClassName, s.namespace), "create")
require.Contains(s.T(), result1, fmt.Sprintf("storageclass \"%s\" created", storageClassName), "Make sure storageclass is created")
require.NoError(s.T(), err1)
//make sure storageclass is created
present, err := s.kh.IsStorageClassPresent(storageClassName)
require.Nil(s.T(), err)
require.True(s.T(), present, "Make sure storageclass is present")
//create pvc
result2, err2 := installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef(claimName, storageClassName, "ReadWriteMany"), "create")
require.Contains(s.T(), result2, fmt.Sprintf("persistentvolumeclaim \"%s\" created", claimName), "Make sure pvc is created. "+result2)
require.NoError(s.T(), err2)
//check status of PVC
require.True(s.T(), s.kh.WaitUntilPVCIsBound(defaultNamespace, claimName))
accessModes, err := s.kh.GetPVCAccessModes(defaultNamespace, claimName)
require.NoError(s.T(), err)
assert.Equal(s.T(), accessModes[0], v1.PersistentVolumeAccessMode(v1.ReadWriteMany))
//check block image count
b, _ := s.bc.BlockList()
require.Equal(s.T(), s.initBlockCount+1, len(b), "Make sure new block image is created")
}
func (s *K8sBlockImageCreateSuite) TestBlockStorageMountUnMountForStatefulSets() {
poolName := "stspool"
storageClassName := "stssc"
statefulSetName := "block-stateful-set"
statefulPodsName := "ststest"
defer s.statefulSetDataCleanup(poolName, storageClassName, statefulSetName, statefulPodsName)
logger.Infof("Test case when block persistent volumes are scaled up and down along with StatefulSet")
logger.Info("Step 1: Create pool and storageClass")
_, cbErr := installer.BlockResourceOperation(s.kh, installer.GetBlockPoolStorageClass(s.namespace, poolName, storageClassName), "create")
assert.Nil(s.T(), cbErr)
logger.Info("Step 2 : Deploy statefulSet with 1X replication")
_, sderr := installer.BlockResourceOperation(s.kh, getBlockStatefulSetDefintion(statefulSetName, statefulPodsName, storageClassName), "create")
assert.Nil(s.T(), sderr)
assert.True(s.T(), s.kh.CheckPodCountAndState(statefulSetName, defaultNamespace, 1, "Running"))
assert.True(s.T(), s.kh.CheckPvcCountAndStatus(statefulSetName, defaultNamespace, 1, "Bound"))
logger.Info("Step 3 : Scale up replication on statefulSet")
s.kh.ScaleStatefulSet(statefulPodsName, 2)
assert.True(s.T(), s.kh.CheckPodCountAndState(statefulSetName, defaultNamespace, 2, "Running"))
assert.True(s.T(), s.kh.CheckPvcCountAndStatus(statefulSetName, defaultNamespace, 2, "Bound"))
logger.Info("Step 4 : Scale down replication on statefulSet")
s.kh.ScaleStatefulSet(statefulPodsName, 1)
assert.True(s.T(), s.kh.CheckPodCountAndState(statefulSetName, defaultNamespace, 1, "Running"))
assert.True(s.T(), s.kh.CheckPvcCountAndStatus(statefulSetName, defaultNamespace, 2, "Bound"))
logger.Info("Step 5 : Delete statefulSet")
_, sddelerr := installer.BlockResourceOperation(s.kh, getBlockStatefulSetDefintion(statefulSetName, statefulPodsName, storageClassName), "delete")
assert.Nil(s.T(), sddelerr)
assert.True(s.T(), s.kh.WaitUntilPodWithLabelDeleted(fmt.Sprintf("app=%s", statefulSetName), defaultNamespace))
assert.True(s.T(), s.kh.CheckPvcCountAndStatus(statefulSetName, defaultNamespace, 2, "Bound"))
}
func (s *K8sBlockImageCreateSuite) statefulSetDataCleanup(poolName, storageClassName, statefulSetName, statefulPodsName string) {
//Delete stateful set
installer.BlockResourceOperation(s.kh, getBlockStatefulSetDefintion(statefulSetName, statefulPodsName, storageClassName), "delete")
//Delete all PVCs
s.kh.DeletePvcWithLabel(defaultNamespace, statefulSetName)
//Delete storageclass and pool
installer.BlockResourceOperation(s.kh, installer.GetBlockPoolStorageClass(s.namespace, poolName, storageClassName), "delete")
}
func (s *K8sBlockImageCreateSuite) tearDownTest(claimName string, poolName string, storageClassName string, accessMode string) {
installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef(claimName, storageClassName, accessMode), "delete")
installer.BlockResourceOperation(s.kh, installer.GetBlockPoolDef(poolName, s.namespace, "1"), "delete")
installer.BlockResourceOperation(s.kh, installer.GetBlockStorageClassDef(poolName, storageClassName, s.namespace), "delete")
@@ -0,0 +1,296 @@
/*
Copyright 2016 The Rook Authors. All rights reserved.
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 integration
import (
"testing"
"fmt"
"github.com/rook/rook/tests/framework/clients"
"github.com/rook/rook/tests/framework/contracts"
"github.com/rook/rook/tests/framework/installer"
"github.com/rook/rook/tests/framework/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
// ************************************************
// ***Scenarios tested by the BlockMountUnMountSuite ***
// Setup
// - via the cluster CRD
// - set up Block PVC - With ReadWriteOnce
// - set up Block PVC - with ReadWriteMany
// - Mount Volume on a pod and write some data
// - UnMount Volume
// Monitors
// - one mons in the cluster
// OSDs
// - Bluestore running on directory
// Block Mount & UnMount scenarios - repeat for each PVC
// 1. ReadWriteOnce
// a. Mount Volume on a new pod - make sure persisted data is present and write new data
// b. Mount volume on two pods with - mount should be successful only on first pod
//2. ReadOnlyMany
// a. Mount Multiple pods with same volume - All pods should be able to read data
// b. ,Mount Multiple pods with same volume - All pods should not be able to write data
//4. Run StatefulSet with PVC
// a. Scale up pods
// b. Scale down Pods
// c. Failover pods
// d . Delete statefulSet
// ************************************************
func TestBlockMountUnMountSuite(t *testing.T) {
s := new(BlockMountUnMountSuite)
defer func(s *BlockMountUnMountSuite) {
HandlePanics(recover(), s.op, s.T)
}(s)
suite.Run(t, s)
}
type BlockMountUnMountSuite struct {
suite.Suite
testClient *clients.TestClient
bc contracts.BlockOperator
kh *utils.K8sHelper
namespace string
pvcNameRWO string
pvcNameRWX string
installer *installer.InstallHelper
op contracts.Setup
}
func (s *BlockMountUnMountSuite) SetupSuite() {
var err error
s.namespace = "block-test-ns"
s.pvcNameRWO = "block-persistent-rwo"
poolNameRWO := "block-pool-rwo"
storageClassNameRWO := "rook-block-rwo"
s.pvcNameRWX = "block-persistent-rwx"
poolNameRWX := "block-pool-rwo"
storageClassNameRWX := "rook-block-rwo"
s.op, s.kh = NewBaseTestOperations(s.T, s.namespace, "bluestore", "", false, false, 1)
s.testClient = GetTestClient(s.kh, s.namespace, s.op, s.T)
s.bc = s.testClient.GetBlockClient()
// Create PVCs
_, cbErr := installer.BlockResourceOperation(s.kh, installer.GetBlockPoolStorageClassAndPvcDef(s.namespace, poolNameRWO, storageClassNameRWO, s.pvcNameRWO, "ReadWriteOnce"), "create")
require.Nil(s.T(), cbErr)
require.True(s.T(), s.kh.WaitUntilPVCIsBound(defaultNamespace, s.pvcNameRWO), "Make sure PVC is Bound")
_, cbErr2 := installer.BlockResourceOperation(s.kh, installer.GetBlockPoolStorageClassAndPvcDef(s.namespace, poolNameRWX, storageClassNameRWX, s.pvcNameRWX, "ReadWriteMany"), "create")
require.Nil(s.T(), cbErr2)
require.True(s.T(), s.kh.WaitUntilPVCIsBound(defaultNamespace, s.pvcNameRWX), "Make sure PVC is Bound")
// Mount PVC on a pod and write some data.
_, mtErr := s.bc.BlockMap(getBlockPodDefintion("setup-block-rwo", s.pvcNameRWO, false), blockMountPath)
require.Nil(s.T(), mtErr)
crdName, err := s.kh.GetVolumeAttachmentResourceName(defaultNamespace, s.pvcNameRWO)
require.Nil(s.T(), err)
require.True(s.T(), s.kh.IsVolumeAttachmentResourcePresent(installer.SystemNamespace(s.namespace), crdName), fmt.Sprintf("make sure VolumeAttachment %s is created", crdName))
_, mtErr1 := s.bc.BlockMap(getBlockPodDefintion("setup-block-rwx", s.pvcNameRWX, false), blockMountPath)
require.Nil(s.T(), mtErr1)
crdName1, err1 := s.kh.GetVolumeAttachmentResourceName(defaultNamespace, s.pvcNameRWX)
require.Nil(s.T(), err1)
require.True(s.T(), s.kh.IsVolumeAttachmentResourcePresent(installer.SystemNamespace(s.namespace), crdName1), fmt.Sprintf("make sure VolumeAttachment %s is created", crdName))
require.True(s.T(), s.kh.IsPodRunning("setup-block-rwo", defaultNamespace), "make sure setup-block-rwo pod is in running state")
require.True(s.T(), s.kh.IsPodRunning("setup-block-rwx", defaultNamespace), "make sure setup-block-rwx pod is in running state")
// Write Data to Pod
_, wtErr1 := s.bc.BlockWrite("setup-block-rwo", blockMountPath, "Persisted message one", "bsFile1", "")
require.Nil(s.T(), wtErr1)
_, wtErr2 := s.bc.BlockWrite("setup-block-rwx", blockMountPath, "Persisted message one", "bsFile1", "")
require.Nil(s.T(), wtErr2)
//Unmound pod
_, unmtErr1 := s.bc.BlockUnmap(getBlockPodDefintion("setup-block-rwo", s.pvcNameRWO, false), blockMountPath)
_, unmtErr2 := s.bc.BlockUnmap(getBlockPodDefintion("setup-block-rwx", s.pvcNameRWO, false), blockMountPath)
require.Nil(s.T(), unmtErr1)
require.Nil(s.T(), unmtErr2)
require.True(s.T(), s.kh.IsPodTerminated("setup-block-rwo", defaultNamespace), "make sure setup-block-rwo pod is terminated")
require.True(s.T(), s.kh.IsPodTerminated("setup-block-rwx", defaultNamespace), "make sure setup-block-rwx pod is terminated")
}
func (s *BlockMountUnMountSuite) TearDownSuite() {
logger.Infof("Cleaning up block storage")
s.testClient.GetBlockClient().BlockUnmap(getBlockPodDefintion("setup-block-rwo", s.pvcNameRWO, false), blockMountPath)
s.testClient.GetBlockClient().BlockUnmap(getBlockPodDefintion("setup-block-rwx", s.pvcNameRWX, false), blockMountPath)
s.testClient.GetBlockClient().BlockUnmap(getBlockPodDefintion("rwo-block-rw-one", s.pvcNameRWO, false), blockMountPath)
s.testClient.GetBlockClient().BlockUnmap(getBlockPodDefintion("rwo-block-rw-two", s.pvcNameRWO, false), blockMountPath)
s.testClient.GetBlockClient().BlockUnmap(getBlockPodDefintion("rwo-block-ro-one", s.pvcNameRWO, true), blockMountPath)
s.testClient.GetBlockClient().BlockUnmap(getBlockPodDefintion("rwo-block-ro-two", s.pvcNameRWO, true), blockMountPath)
s.testClient.GetBlockClient().BlockUnmap(getBlockPodDefintion("rwx-block-rw-one", s.pvcNameRWX, false), blockMountPath)
s.testClient.GetBlockClient().BlockUnmap(getBlockPodDefintion("rwx-block-rw-two", s.pvcNameRWX, false), blockMountPath)
s.testClient.GetBlockClient().BlockUnmap(getBlockPodDefintion("rwx-block-ro-one", s.pvcNameRWX, true), blockMountPath)
s.testClient.GetBlockClient().BlockUnmap(getBlockPodDefintion("rwx-block-ro-two", s.pvcNameRWX, true), blockMountPath)
installer.BlockResourceOperation(s.kh, installer.GetBlockPoolStorageClassAndPvcDef(s.namespace, "block-pool-rwo", "rook-block-rwo", s.pvcNameRWO, "ReadWriteOnce"), "delete")
installer.BlockResourceOperation(s.kh, installer.GetBlockPoolStorageClassAndPvcDef(s.namespace, "block-pool-rwx", "rook-block-rwx", s.pvcNameRWX, "ReadWriteMany"), "delete")
cleanupDynamicBlockStorage(s.testClient)
s.op.TearDown()
}
func (s *BlockMountUnMountSuite) TestBlockStorageMountUnMountForDifferentAccessModes() {
logger.Infof("Test case when existing RWO PVC is mounted and unmounted on pods with various accessModes")
logger.Infof("Step 1.1: Mount existing ReadWriteOnce and ReadWriteMany PVC on a Pod with RW access")
//mount PVC with RWO access on a pod with readonly set to false
_, mtErr1 := s.bc.BlockMap(getBlockPodDefintion("rwo-block-rw-one", s.pvcNameRWO, false), blockMountPath)
require.Nil(s.T(), mtErr1)
//mount PVC with RWX access on a pod with readonly set to false
_, mtErr2 := s.bc.BlockMap(getBlockPodDefintion("rwx-block-rw-one", s.pvcNameRWX, false), blockMountPath)
require.Nil(s.T(), mtErr2)
crdName1, err1 := s.kh.GetVolumeAttachmentResourceName(defaultNamespace, s.pvcNameRWO)
crdName2, err2 := s.kh.GetVolumeAttachmentResourceName(defaultNamespace, s.pvcNameRWX)
assert.Nil(s.T(), err1)
assert.Nil(s.T(), err2)
assert.True(s.T(), s.kh.IsVolumeAttachmentResourcePresent(installer.SystemNamespace(s.namespace), crdName1), fmt.Sprintf("make sure VolumeAttachment %s is created", crdName1))
assert.True(s.T(), s.kh.IsPodRunning("rwo-block-rw-one", defaultNamespace), "make sure block-rw-one pod is in running state")
assert.True(s.T(), s.kh.IsVolumeAttachmentResourcePresent(installer.SystemNamespace(s.namespace), crdName2), fmt.Sprintf("make sure VolumeAttachment %s is created", crdName2))
assert.True(s.T(), s.kh.IsPodRunning("rwx-block-rw-one", defaultNamespace), "make sure rwx-block-rw-one pod is in running state")
logger.Infof("Step 2: Check if previously persisted data is readable from ReadWriteOnce and ReadWriteMany PVC")
//Read data on RWO PVC Mounted on pod with RW Access
read1, rErr1 := s.bc.BlockRead("rwo-block-rw-one", blockMountPath, "bsFile1", "")
assert.Nil(s.T(), rErr1)
assert.Contains(s.T(), read1, "Persisted message one", "make sure previously persisted data is readable")
//Read data on RWX PVC Mounted on pod with RW Access
read2, rErr2 := s.bc.BlockRead("rwx-block-rw-one", blockMountPath, "bsFile1", "")
assert.Nil(s.T(), rErr2)
assert.Contains(s.T(), read2, "Persisted message one", "make sure previously persisted data is readable")
logger.Infof("Step 3: Check if read/write works on ReadWriteOnce and ReadWriteMany PVC")
//Write data on RWO PVC Mounted on pod with RW Access
_, wtErr1 := s.bc.BlockWrite("rwo-block-rw-one", blockMountPath, "Persisted message two", "bsFile2", "")
assert.Nil(s.T(), wtErr1)
//Read data on RWO PVC Mounted on pod with RW Access
read1, rErr1 = s.bc.BlockRead("rwo-block-rw-one", blockMountPath, "bsFile2", "")
assert.Nil(s.T(), rErr1)
assert.Contains(s.T(), read1, "Persisted message two", "make sure new persisted data is readable")
//Write data on RWX PVC Mounted on pod with RW Access
_, wtErr2 := s.bc.BlockWrite("rwx-block-rw-one", blockMountPath, "Persisted message two", "bsFile2", "")
assert.Nil(s.T(), wtErr2)
//Read data on RWX PVC Mounted on pod with RW Access
read2, rErr2 = s.bc.BlockRead("rwx-block-rw-one", blockMountPath, "bsFile2", "")
assert.Nil(s.T(), rErr2)
assert.Contains(s.T(), read2, "Persisted message two", "make sure new persisted data is readable")
//Mount another Pod with RW access on same PVC
logger.Infof("Step 4: Mount existing ReadWriteOnce and ReadWriteMany PVC on a new Pod with RW access")
//Mount RWO PVC on a new pod with ReadOnly set to false
_, mtErr1 = s.bc.BlockMap(getBlockPodDefintion("rwo-block-rw-two", s.pvcNameRWO, false), blockMountPath)
assert.Nil(s.T(), mtErr1)
//Mount RWX PVC on a new pod with ReadOnly set to false
_, mtErr2 = s.bc.BlockMap(getBlockPodDefintion("rwx-block-rw-two", s.pvcNameRWX, false), blockMountPath)
assert.Nil(s.T(), mtErr2)
assert.True(s.T(), s.kh.IsPodInError("rwo-block-rw-two", defaultNamespace, "FailedMount", "Volume is already attached by pod"), "make sure rwo-block-rw-two pod errors out while mounting the volume")
assert.True(s.T(), s.kh.IsPodInError("rwx-block-rw-two", defaultNamespace, "FailedMount", "Volume is already attached by pod"), "make sure rwx-block-rw-two pod errors out while mounting the volume")
_, unmtErr1 := s.bc.BlockUnmap(getBlockPodDefintion("rwo-block-rw-two", s.pvcNameRWO, false), blockMountPath)
assert.Nil(s.T(), unmtErr1)
_, unmtErr2 := s.bc.BlockUnmap(getBlockPodDefintion("rwx-block-rw-two", s.pvcNameRWX, false), blockMountPath)
assert.Nil(s.T(), unmtErr2)
assert.True(s.T(), s.kh.IsPodTerminated("rwo-block-rw-two", defaultNamespace), "make sure rwo-block-rw-two pod is terminated")
assert.True(s.T(), s.kh.IsPodTerminated("rwx-block-rw-two", defaultNamespace), "make sure rwx-block-rw-two pod is terminated")
logger.Infof("Step 5: Mount existing ReadWriteOnce and ReadWriteMany PVC on a new Pod with RO access")
//Mount RWO PVC on a new pod with ReadOnly set to true
_, mtErr1 = s.bc.BlockMap(getBlockPodDefintion("rwo-block-ro-one", s.pvcNameRWO, true), blockMountPath)
assert.Nil(s.T(), mtErr1)
//Mount RWX PVC on a new pod with ReadOnly set to true
_, mtErr2 = s.bc.BlockMap(getBlockPodDefintion("rwx-block-ro-one", s.pvcNameRWX, true), blockMountPath)
assert.Nil(s.T(), mtErr2)
assert.True(s.T(), s.kh.IsPodInError("rwo-block-ro-one", defaultNamespace, "FailedMount", "Volume is already attached by pod"), "make sure rwo-block-ro-one pod errors out while mounting the volume")
assert.True(s.T(), s.kh.IsPodInError("rwx-block-ro-one", defaultNamespace, "FailedMount", "Volume is already attached by pod"), "make sure rwx-block-ro-one pod errors out while mounting the volume")
_, unmtErr1 = s.bc.BlockUnmap(getBlockPodDefintion("rwo-block-ro-one", s.pvcNameRWO, true), blockMountPath)
assert.Nil(s.T(), unmtErr1)
_, unmtErr2 = s.bc.BlockUnmap(getBlockPodDefintion("rwx-block-ro-one", s.pvcNameRWX, true), blockMountPath)
assert.Nil(s.T(), unmtErr2)
assert.True(s.T(), s.kh.IsPodTerminated("rwo-block-ro-one", defaultNamespace), "make sure rwo-block-ro-one pod is terminated")
assert.True(s.T(), s.kh.IsPodTerminated("rwx-block-ro-one", defaultNamespace), "make sure rwx-block-ro-one pod is terminated")
logger.Infof("Step 6: UnMount Pod with RWX and RWO access")
//UnMount RWO PVC
_, unmtErr1 = s.bc.BlockUnmap(getBlockPodDefintion("rwo-block-rw-one", s.pvcNameRWO, false), blockMountPath)
assert.Nil(s.T(), unmtErr1)
//UnMount RWX PVC
_, unmtErr2 = s.bc.BlockUnmap(getBlockPodDefintion("rwx-block-rw-one", s.pvcNameRWX, false), blockMountPath)
assert.Nil(s.T(), unmtErr2)
assert.True(s.T(), s.kh.IsPodTerminated("rwo-block-rw-one", defaultNamespace), "make sure rwo-block-rw-one pod is terminated")
assert.True(s.T(), s.kh.IsPodTerminated("rwx-block-rw-one", defaultNamespace), "make sure rwx-lock-rw-one pod is terminated")
logger.Infof("Step 7: Mount ReadWriteOnce and ReadWriteMany PVC on two different pods with ReadOnlyMany with Readonly Access")
//Mount RWO PVC on 2 pods with ReadOnly set to True
_, mtErr1_1 := s.bc.BlockMap(getBlockPodDefintion("rwo-block-ro-one", s.pvcNameRWO, true), blockMountPath)
_, mtErr2_1 := s.bc.BlockMap(getBlockPodDefintion("rwo-block-ro-two", s.pvcNameRWO, true), blockMountPath)
assert.Nil(s.T(), mtErr1_1)
assert.Nil(s.T(), mtErr2_1)
//Mount RWX PVC on 2 pods with ReadOnly set to True
_, mtErr1_2 := s.bc.BlockMap(getBlockPodDefintion("rwx-block-ro-one", s.pvcNameRWX, true), blockMountPath)
_, mtErr2_2 := s.bc.BlockMap(getBlockPodDefintion("rwx-block-ro-two", s.pvcNameRWX, true), blockMountPath)
assert.Nil(s.T(), mtErr1_2)
assert.Nil(s.T(), mtErr2_2)
assert.True(s.T(), s.kh.IsPodRunning("rwo-block-ro-one", defaultNamespace), "make sure rwo-block-ro-one pod is in running state")
assert.True(s.T(), s.kh.IsPodRunning("rwo-block-ro-two", defaultNamespace), "make sure rwo-block-ro-two pod is in running state")
assert.True(s.T(), s.kh.IsPodRunning("rwx-block-ro-one", defaultNamespace), "make sure rwx-block-ro-one pod is in running state")
assert.True(s.T(), s.kh.IsPodRunning("rwx-block-ro-two", defaultNamespace), "make sure rwx-block-ro-two pod is in running state")
logger.Infof("Step 7.1: Read Data from both ReadyOnlyMany and ReadWriteOnce pods with ReadOnly Access")
//Read data from RWO PVC via both ReadOnly pods
read1_1, rErr1_1 := s.bc.BlockRead("rwo-block-ro-one", blockMountPath, "bsFile1", "")
read2_1, rErr2_1 := s.bc.BlockRead("rwo-block-ro-two", blockMountPath, "bsFile1", "")
assert.Nil(s.T(), rErr1_1)
assert.Nil(s.T(), rErr2_1)
assert.Contains(s.T(), read1_1, "Persisted message one", "make sure previously persisted data is readable from ReadOnlyMany access Pod")
assert.Contains(s.T(), read2_1, "Persisted message one", "make sure previously persisted data is readable from ReadOnlyMany access Pod")
//Read data from RWX PVC via both ReadOnly pods
read1_2, rErr1_2 := s.bc.BlockRead("rwx-block-ro-one", blockMountPath, "bsFile1", "")
read2_2, rErr2_2 := s.bc.BlockRead("rwx-block-ro-two", blockMountPath, "bsFile1", "")
assert.Nil(s.T(), rErr1_2)
assert.Nil(s.T(), rErr2_2)
assert.Contains(s.T(), read1_2, "Persisted message one", "make sure previously persisted data is readable from ReadOnlyMany access Pod")
assert.Contains(s.T(), read2_2, "Persisted message one", "make sure previously persisted data is readable from ReadOnlyMany access Pod")
logger.Infof("Step 7.2: Write Data to Pod with ReadOnlyMany and ReadWriteOnce PVC mounted with ReadOnly access")
//Write data to RWO PVC via pod with ReadOnly Set to true
_, wtErr1 = s.bc.BlockWrite("rwo-block-ro-one", blockMountPath, "Persisted message three", "bsFile3", "")
assert.Contains(s.T(), wtErr1.Error(), "Unable to write data to pod")
//Write data to RWx PVC via pod with ReadOnly Set to true
_, wtErr2 = s.bc.BlockWrite("rwx-block-ro-one", blockMountPath, "Persisted message three", "bsFile3", "")
assert.Contains(s.T(), wtErr2.Error(), "Unable to write data to pod")
logger.Infof("Step 7.3: UnMount Pod with ReadOnlyMany and ReadWriteOnce PVCs")
//UnMount RWO PVC from both ReadOnly Pods
_, unmtErr1_1 := s.bc.BlockUnmap(getBlockPodDefintion("rwo-block-ro-one", s.pvcNameRWO, true), blockMountPath)
_, unmtErr2_1 := s.bc.BlockUnmap(getBlockPodDefintion("rwo-block-ro-two", s.pvcNameRWO, true), blockMountPath)
assert.Nil(s.T(), unmtErr1_1)
assert.Nil(s.T(), unmtErr2_1)
//UnMount RWX PVC from both ReadOnly Pods
_, unmtErr1_2 := s.bc.BlockUnmap(getBlockPodDefintion("rwx-block-ro-one", s.pvcNameRWX, true), blockMountPath)
_, unmtErr2_2 := s.bc.BlockUnmap(getBlockPodDefintion("rwx-block-ro-two", s.pvcNameRWX, true), blockMountPath)
assert.Nil(s.T(), unmtErr1_2)
assert.Nil(s.T(), unmtErr2_2)
assert.True(s.T(), s.kh.IsPodTerminated("rwo-block-ro-one", defaultNamespace), "make sure rwo-block-ro-one pod is terminated")
assert.True(s.T(), s.kh.IsPodTerminated("rwo-block-ro-two", defaultNamespace), "make sure rwo-block-ro-two pod is terminated")
assert.True(s.T(), s.kh.IsPodTerminated("rwx-block-ro-one", defaultNamespace), "make sure rwx-lock-ro-one pod is terminated")
assert.True(s.T(), s.kh.IsPodTerminated("rwx-block-ro-two", defaultNamespace), "make sure rwx-block-ro-two pod is terminated")
}
+15
View File
@@ -1,3 +1,18 @@
/*
Copyright 2016 The Rook Authors. All rights reserved.
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 integration
import (
@@ -1,3 +1,19 @@
/*
Copyright 2016 The Rook Authors. All rights reserved.
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 integration
import (
+1 -1
View File
@@ -46,7 +46,7 @@ func (s *BlockLongHaulSuiteWithFencing) SetupSuite() {
s.bc = s.testClient.GetBlockClient()
if _, err := s.kh.GetPVCStatus(defaultNamespace, "block-pv-one"); err != nil {
logger.Infof("Creating PVC and mounting it to pod with readOnly set to false")
installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef("block-pv-one", "rook-block"), "create")
installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef("block-pv-one", "rook-block", "ReadWriteOnce"), "create")
mountUnmountPVCOnPod(s.kh, "block-rw", "block-pv-one", "false", "create")
require.True(s.T(), s.kh.IsPodRunning("block-rw", defaultNamespace))