2017-12-29 00:33:36 -08:00
/*
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 (
2020-02-11 17:11:41 -07:00
"strconv"
2017-12-29 00:33:36 -08:00
"testing"
"fmt"
2018-01-09 18:18:20 -08:00
2017-12-29 00:33:36 -08:00
"github.com/rook/rook/tests/framework/clients"
"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"
2019-10-14 16:33:13 -06:00
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2020-02-11 17:11:41 -07:00
"k8s.io/apimachinery/pkg/util/version"
2017-12-29 00:33:36 -08:00
)
2018-01-10 12:12:55 -08:00
// ******************************************************
2020-02-11 17:11:41 -07:00
// *** Scenarios tested by the TestCephFlexSuite ***
// Flex driver block scenarios - repeat for each PVC
2017-12-29 00:33:36 -08:00
// 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
2018-01-10 12:12:55 -08:00
// 2. ReadOnlyMany
2017-12-29 00:33:36 -08:00
// a. Mount Multiple pods with same volume - All pods should be able to read data
2018-01-10 12:12:55 -08:00
// b. Mount Multiple pods with same volume - All pods should not be able to write data
// 3. Run StatefulSet with PVC
2017-12-29 00:33:36 -08:00
// a. Scale up pods
2018-01-10 12:12:55 -08:00
// b. Scale down pods
2017-12-29 00:33:36 -08:00
// c. Failover pods
2018-01-10 12:12:55 -08:00
// d. Delete StatefulSet
2020-02-11 17:11:41 -07:00
//
// Flex driver file system scenarios
// 1. Create a filesystem
// a. Mount a directory with the static mount
2018-01-10 12:12:55 -08:00
// ******************************************************
2017-12-29 00:33:36 -08:00
2020-02-11 17:11:41 -07:00
func TestCephFlexSuite ( t * testing . T ) {
2019-07-16 22:16:15 -06:00
if installer . SkipTestSuite ( installer . CephTestSuite ) {
t . Skip ()
}
2020-02-11 17:11:41 -07:00
s := new ( CephFlexDriverSuite )
defer func ( s * CephFlexDriverSuite ) {
2017-12-29 00:33:36 -08:00
HandlePanics ( recover (), s . op , s . T )
}( s )
suite . Run ( t , s )
}
2020-02-11 17:11:41 -07:00
type CephFlexDriverSuite struct {
2017-12-29 00:33:36 -08:00
suite . Suite
testClient * clients . TestClient
2018-03-16 08:31:34 -07:00
bc * clients . BlockOperation
2017-12-29 00:33:36 -08:00
kh * utils . K8sHelper
namespace string
pvcNameRWO string
pvcNameRWX string
2018-08-21 15:24:52 -06:00
installer * installer . CephInstaller
op * TestCluster
2017-12-29 00:33:36 -08:00
}
2020-02-11 17:11:41 -07:00
func ( s * CephFlexDriverSuite ) SetupSuite () {
2017-12-29 00:33:36 -08:00
2020-02-11 17:11:41 -07:00
s . namespace = "flex-ns"
2017-12-29 00:33:36 -08:00
s . pvcNameRWO = "block-persistent-rwo"
s . pvcNameRWX = "block-persistent-rwx"
2018-06-19 13:08:33 -07:00
useHelm := false
2018-11-28 08:29:37 -07:00
mons := 1
rbdMirrorWorkers := 1
2020-02-11 17:11:41 -07:00
s . op , s . kh = StartTestCluster ( s . T , flexDriverMinimalTestVersion , s . namespace , "bluestore" , useHelm , false , "" , mons , rbdMirrorWorkers , installer . VersionMaster , installer . NautilusVersion )
2018-08-21 15:24:52 -06:00
s . testClient = clients . CreateTestClient ( s . kh , s . op . installer . Manifests )
2018-03-16 08:31:34 -07:00
s . bc = s . testClient . BlockClient
2018-05-15 15:05:37 -07:00
}
2020-02-11 17:11:41 -07:00
func ( s * CephFlexDriverSuite ) AfterTest ( suiteName , testName string ) {
2019-08-11 07:39:18 -06:00
s . op . installer . CollectOperatorLog ( suiteName , testName , installer . SystemNamespace ( s . namespace ))
}
2020-02-11 17:11:41 -07:00
func ( s * CephFlexDriverSuite ) TestFileSystem () {
useCSI := false
runFileE2ETest ( s . testClient , s . kh , s . Suite , s . namespace , "smoke-test-fs" , useCSI )
}
func ( s * CephFlexDriverSuite ) TestBlockStorageMountUnMountForStatefulSets () {
2019-10-14 16:33:13 -06:00
poolName := "stspool"
storageClassName := "stssc"
reclaimPolicy := "Delete"
statefulSetName := "block-stateful-set"
statefulPodsName := "ststest"
defer s . statefulSetDataCleanup ( defaultNamespace , poolName , storageClassName , reclaimPolicy , 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" )
2020-02-11 17:11:41 -07:00
err := s . testClient . PoolClient . Create ( poolName , s . namespace , 1 )
assert . Nil ( s . T (), err )
err = s . testClient . BlockClient . CreateStorageClass ( false , poolName , storageClassName , reclaimPolicy , s . namespace )
2019-10-14 16:33:13 -06:00
assert . Nil ( s . T (), err )
logger . Info ( "Step 2 : Deploy statefulSet with 1X replication" )
service , statefulset := getBlockStatefulSetAndServiceDefinition ( defaultNamespace , statefulSetName , statefulPodsName , storageClassName )
_ , err = s . kh . Clientset . CoreV1 (). Services ( defaultNamespace ). Create ( service )
assert . Nil ( s . T (), err )
_ , err = s . kh . Clientset . AppsV1 (). StatefulSets ( defaultNamespace ). Create ( statefulset )
assert . Nil ( s . T (), err )
require . True ( s . T (), s . kh . CheckPodCountAndState ( statefulSetName , defaultNamespace , 1 , "Running" ))
require . True ( s . T (), s . kh . CheckPvcCountAndStatus ( statefulSetName , defaultNamespace , 1 , "Bound" ))
logger . Info ( "Step 3 : Scale up replication on statefulSet" )
scaleerr := s . kh . ScaleStatefulSet ( statefulPodsName , defaultNamespace , 2 )
assert . NoError ( s . T (), scaleerr , "make sure scale up is successful" )
require . True ( s . T (), s . kh . CheckPodCountAndState ( statefulSetName , defaultNamespace , 2 , "Running" ))
require . True ( s . T (), s . kh . CheckPvcCountAndStatus ( statefulSetName , defaultNamespace , 2 , "Bound" ))
logger . Info ( "Step 4 : Scale down replication on statefulSet" )
scaleerr = s . kh . ScaleStatefulSet ( statefulPodsName , defaultNamespace , 1 )
assert . NoError ( s . T (), scaleerr , "make sure scale down is successful" )
require . True ( s . T (), s . kh . CheckPodCountAndState ( statefulSetName , defaultNamespace , 1 , "Running" ))
require . True ( s . T (), s . kh . CheckPvcCountAndStatus ( statefulSetName , defaultNamespace , 2 , "Bound" ))
logger . Info ( "Step 5 : Delete statefulSet" )
delOpts := metav1 . DeleteOptions {}
listOpts := metav1 . ListOptions { LabelSelector : "app=" + statefulSetName }
err = s . kh . Clientset . CoreV1 (). Services ( defaultNamespace ). Delete ( statefulSetName , & delOpts )
assert . Nil ( s . T (), err )
err = s . kh . Clientset . AppsV1 (). StatefulSets ( defaultNamespace ). Delete ( statefulPodsName , & delOpts )
assert . Nil ( s . T (), err )
err = s . kh . Clientset . CoreV1 (). Pods ( defaultNamespace ). DeleteCollection ( & delOpts , listOpts )
assert . Nil ( s . T (), err )
require . True ( s . T (), s . kh . WaitUntilPodWithLabelDeleted ( fmt . Sprintf ( "app=%s" , statefulSetName ), defaultNamespace ))
require . True ( s . T (), s . kh . CheckPvcCountAndStatus ( statefulSetName , defaultNamespace , 2 , "Bound" ))
}
2020-02-11 17:11:41 -07:00
func ( s * CephFlexDriverSuite ) statefulSetDataCleanup ( namespace , poolName , storageClassName , reclaimPolicy , statefulSetName , statefulPodsName string ) {
2019-10-14 16:33:13 -06:00
delOpts := metav1 . DeleteOptions {}
listOpts := metav1 . ListOptions { LabelSelector : "app=" + statefulSetName }
// Delete stateful set
s . kh . Clientset . CoreV1 (). Services ( namespace ). Delete ( statefulSetName , & delOpts )
s . kh . Clientset . AppsV1 (). StatefulSets ( defaultNamespace ). Delete ( statefulPodsName , & delOpts )
s . kh . Clientset . CoreV1 (). Pods ( defaultNamespace ). DeleteCollection ( & delOpts , listOpts )
// Delete all PVCs
s . kh . DeletePvcWithLabel ( defaultNamespace , statefulSetName )
// Delete storageclass and pool
2019-10-30 00:00:05 -06:00
s . testClient . PoolClient . DeletePool ( s . testClient . BlockClient , s . namespace , poolName )
2020-02-11 17:11:41 -07:00
s . testClient . BlockClient . DeleteStorageClass ( storageClassName )
2019-10-14 16:33:13 -06:00
}
2020-02-11 17:11:41 -07:00
func ( s * CephFlexDriverSuite ) setupPVCs () {
2018-05-15 15:05:37 -07:00
logger . Infof ( "creating the test PVCs" )
poolNameRWO := "block-pool-rwo"
2018-05-18 14:32:43 -07:00
storageClassNameRWO := "rook-ceph-block-rwo"
2020-02-11 17:11:41 -07:00
systemNamespace := installer . SystemNamespace ( s . namespace )
2017-12-29 00:33:36 -08:00
// Create PVCs
2020-02-11 17:11:41 -07:00
useCSI := false
err := s . testClient . BlockClient . CreateStorageClassAndPVC ( useCSI , defaultNamespace , s . namespace , systemNamespace , poolNameRWO , storageClassNameRWO , "Delete" , s . pvcNameRWO , "ReadWriteOnce" )
require . Nil ( s . T (), err )
2017-12-29 00:33:36 -08:00
require . True ( s . T (), s . kh . WaitUntilPVCIsBound ( defaultNamespace , s . pvcNameRWO ), "Make sure PVC is Bound" )
2020-02-11 17:11:41 -07:00
err = s . testClient . BlockClient . CreatePVC ( defaultNamespace , s . pvcNameRWX , storageClassNameRWO , "ReadWriteMany" , "1M" )
require . Nil ( s . T (), err )
2017-12-29 00:33:36 -08:00
require . True ( s . T (), s . kh . WaitUntilPVCIsBound ( defaultNamespace , s . pvcNameRWX ), "Make sure PVC is Bound" )
// Mount PVC on a pod and write some data.
2020-02-11 17:11:41 -07:00
err = s . bc . CreateClientPod ( getFlexBlockPodDefinition ( "setup-block-rwo" , s . pvcNameRWO , false ))
require . Nil ( s . T (), err )
2018-05-18 14:32:43 -07:00
crdName , err := s . kh . GetVolumeResourceName ( defaultNamespace , s . pvcNameRWO )
2017-12-29 00:33:36 -08:00
require . Nil ( s . T (), err )
2020-02-11 17:11:41 -07:00
s . kh . IsVolumeResourcePresent ( systemNamespace , crdName )
2017-12-29 00:33:36 -08:00
2020-02-11 17:11:41 -07:00
err = s . bc . CreateClientPod ( getFlexBlockPodDefinition ( "setup-block-rwx" , s . pvcNameRWX , false ))
require . Nil ( s . T (), err )
crdName , err = s . kh . GetVolumeResourceName ( defaultNamespace , s . pvcNameRWX )
require . Nil ( s . T (), err )
s . kh . IsVolumeResourcePresent ( systemNamespace , crdName )
2017-12-29 00:33:36 -08:00
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
2018-08-23 06:56:59 -06:00
message := "Persisted message one"
filename := "bsFile1"
err = s . kh . WriteToPod ( "" , "setup-block-rwo" , filename , message )
require . Nil ( s . T (), err )
err = s . kh . WriteToPod ( "" , "setup-block-rwx" , filename , message )
require . Nil ( s . T (), err )
2017-12-29 00:33:36 -08:00
2018-01-09 18:18:20 -08:00
// Unmount pod
2018-08-23 06:56:59 -06:00
_ , err = s . kh . DeletePods ( "setup-block-rwo" , "setup-block-rwx" )
require . Nil ( s . T (), err )
2017-12-29 00:33:36 -08:00
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" )
}
2020-02-11 17:11:41 -07:00
func ( s * CephFlexDriverSuite ) TearDownSuite () {
2017-12-29 00:33:36 -08:00
logger . Infof ( "Cleaning up block storage" )
2018-08-21 15:24:52 -06:00
s . kh . DeletePods (
"setup-block-rwo" , "setup-block-rwx" , "rwo-block-rw-one" , "rwo-block-rw-two" , "rwo-block-ro-one" ,
"rwo-block-ro-two" , "rwx-block-rw-one" , "rwx-block-rw-two" , "rwx-block-ro-one" , "rwx-block-ro-two" )
2017-12-29 00:33:36 -08:00
2020-02-11 17:11:41 -07:00
s . testClient . BlockClient . DeletePVC ( s . namespace , s . pvcNameRWO )
s . testClient . BlockClient . DeletePVC ( s . namespace , s . pvcNameRWX )
s . testClient . BlockClient . DeleteStorageClass ( "rook-ceph-block-rwo" )
s . testClient . BlockClient . DeleteStorageClass ( "rook-ceph-block-rwx" )
2019-10-30 00:00:05 -06:00
s . testClient . PoolClient . DeletePool ( s . testClient . BlockClient , s . namespace , "block-pool-rwo" )
s . testClient . PoolClient . DeletePool ( s . testClient . BlockClient , s . namespace , "block-pool-rwx" )
2018-08-21 15:24:52 -06:00
s . op . Teardown ()
2017-12-29 00:33:36 -08:00
}
2020-02-11 17:11:41 -07:00
func ( s * CephFlexDriverSuite ) TestBlockStorageMountUnMountForDifferentAccessModes () {
2018-05-15 15:05:37 -07:00
s . setupPVCs ()
2017-12-29 00:33:36 -08:00
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" )
2018-10-14 12:10:08 +02:00
// mount PVC with RWO access on a pod with readonly set to false
2020-02-11 17:11:41 -07:00
err := s . bc . CreateClientPod ( getFlexBlockPodDefinition ( "rwo-block-rw-one" , s . pvcNameRWO , false ))
2018-08-21 15:24:52 -06:00
require . Nil ( s . T (), err )
2018-10-14 12:10:08 +02:00
// mount PVC with RWX access on a pod with readonly set to false
2020-02-11 17:11:41 -07:00
err = s . bc . CreateClientPod ( getFlexBlockPodDefinition ( "rwx-block-rw-one" , s . pvcNameRWX , false ))
2018-08-21 15:24:52 -06:00
require . Nil ( s . T (), err )
2020-02-11 17:11:41 -07:00
crdName , err := s . kh . GetVolumeResourceName ( defaultNamespace , s . pvcNameRWO )
assert . Nil ( s . T (), err )
assert . True ( s . T (), s . kh . IsVolumeResourcePresent ( installer . SystemNamespace ( s . namespace ), crdName ), fmt . Sprintf ( "make sure Volume %s is created" , crdName ))
2017-12-29 00:33:36 -08:00
assert . True ( s . T (), s . kh . IsPodRunning ( "rwo-block-rw-one" , defaultNamespace ), "make sure block-rw-one pod is in running state" )
2020-02-11 17:11:41 -07:00
crdName , err = s . kh . GetVolumeResourceName ( defaultNamespace , s . pvcNameRWX )
assert . Nil ( s . T (), err )
assert . True ( s . T (), s . kh . IsVolumeResourcePresent ( installer . SystemNamespace ( s . namespace ), crdName ), fmt . Sprintf ( "make sure Volume %s is created" , crdName ))
2017-12-29 00:33:36 -08:00
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" )
2018-10-14 12:10:08 +02:00
// Read data on RWO PVC Mounted on pod with RW Access
2018-08-23 06:56:59 -06:00
filename1 := "bsFile1"
message1 := "Persisted message one"
err = s . kh . ReadFromPod ( "" , "rwo-block-rw-one" , filename1 , message1 )
2018-08-21 15:24:52 -06:00
assert . Nil ( s . T (), err )
2018-08-23 06:56:59 -06:00
2018-10-14 12:10:08 +02:00
// Read data on RWX PVC Mounted on pod with RW Access
2018-08-23 06:56:59 -06:00
err = s . kh . ReadFromPod ( "" , "rwx-block-rw-one" , filename1 , message1 )
2018-08-21 15:24:52 -06:00
assert . Nil ( s . T (), err )
2017-12-29 00:33:36 -08:00
logger . Infof ( "Step 3: Check if read/write works on ReadWriteOnce and ReadWriteMany PVC" )
2018-10-14 12:10:08 +02:00
// Write data on RWO PVC Mounted on pod with RW Access
2018-08-23 06:56:59 -06:00
filename2 := "bsFile2"
message2 := "Persisted message two"
assert . Nil ( s . T (), s . kh . WriteToPod ( "" , "rwo-block-rw-one" , filename2 , message2 ))
2018-10-14 12:10:08 +02:00
// Read data on RWO PVC Mounted on pod with RW Access
2018-08-23 06:56:59 -06:00
assert . Nil ( s . T (), s . kh . ReadFromPod ( "" , "rwo-block-rw-one" , filename2 , message2 ))
2018-10-14 12:10:08 +02:00
// Write data on RWX PVC Mounted on pod with RW Access
2018-08-23 06:56:59 -06:00
assert . Nil ( s . T (), s . kh . WriteToPod ( "" , "rwx-block-rw-one" , filename2 , message2 ))
2018-10-14 12:10:08 +02:00
// Read data on RWX PVC Mounted on pod with RW Access
2018-08-23 06:56:59 -06:00
assert . Nil ( s . T (), s . kh . ReadFromPod ( "" , "rwx-block-rw-one" , filename2 , message2 ))
2017-12-29 00:33:36 -08:00
2018-10-14 12:10:08 +02:00
// Mount another Pod with RW access on same PVC
2017-12-29 00:33:36 -08:00
logger . Infof ( "Step 4: Mount existing ReadWriteOnce and ReadWriteMany PVC on a new Pod with RW access" )
2018-10-14 12:10:08 +02:00
// Mount RWO PVC on a new pod with ReadOnly set to false
2020-02-11 17:11:41 -07:00
err = s . bc . CreateClientPod ( getFlexBlockPodDefinition ( "rwo-block-rw-two" , s . pvcNameRWO , false ))
2018-08-21 15:24:52 -06:00
assert . Nil ( s . T (), err )
2018-10-14 12:10:08 +02:00
// Mount RWX PVC on a new pod with ReadOnly set to false
2020-02-11 17:11:41 -07:00
err = s . bc . CreateClientPod ( getFlexBlockPodDefinition ( "rwx-block-rw-two" , s . pvcNameRWX , false ))
2018-08-21 15:24:52 -06:00
assert . Nil ( s . T (), err )
2017-12-29 00:33:36 -08:00
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" )
2018-08-21 15:24:52 -06:00
_ , err = s . kh . DeletePods ( "rwo-block-rw-two" , "rwx-block-rw-two" )
assert . Nil ( s . T (), err )
2017-12-29 00:33:36 -08:00
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" )
2018-10-14 12:10:08 +02:00
// Mount RWO PVC on a new pod with ReadOnly set to true
2020-02-11 17:11:41 -07:00
err = s . bc . CreateClientPod ( getFlexBlockPodDefinition ( "rwo-block-ro-one" , s . pvcNameRWO , true ))
2018-08-21 15:24:52 -06:00
assert . Nil ( s . T (), err )
2018-10-14 12:10:08 +02:00
// Mount RWX PVC on a new pod with ReadOnly set to true
2020-02-11 17:11:41 -07:00
err = s . bc . CreateClientPod ( getFlexBlockPodDefinition ( "rwx-block-ro-one" , s . pvcNameRWX , true ))
2018-08-21 15:24:52 -06:00
assert . Nil ( s . T (), err )
2017-12-29 00:33:36 -08:00
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" )
2018-08-21 15:24:52 -06:00
_ , err = s . kh . DeletePods ( "rwo-block-ro-one" , "rwx-block-ro-one" )
assert . Nil ( s . T (), err )
2017-12-29 00:33:36 -08:00
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" )
2018-08-21 15:24:52 -06:00
_ , err = s . kh . DeletePods ( "rwo-block-rw-one" , "rwx-block-rw-one" )
assert . Nil ( s . T (), err )
2017-12-29 00:33:36 -08:00
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" )
2020-02-11 17:11:41 -07:00
2018-10-14 12:10:08 +02:00
// Mount RWO PVC on 2 pods with ReadOnly set to True
2020-02-11 17:11:41 -07:00
err = s . bc . CreateClientPod ( getFlexBlockPodDefinition ( "rwo-block-ro-one" , s . pvcNameRWO , true ))
assert . Nil ( s . T (), err )
err = s . bc . CreateClientPod ( getFlexBlockPodDefinition ( "rwo-block-ro-two" , s . pvcNameRWO , true ))
assert . Nil ( s . T (), err )
2018-10-14 12:10:08 +02:00
// Mount RWX PVC on 2 pods with ReadOnly set to True
2020-02-11 17:11:41 -07:00
err = s . bc . CreateClientPod ( getFlexBlockPodDefinition ( "rwx-block-ro-one" , s . pvcNameRWX , true ))
assert . Nil ( s . T (), err )
err = s . bc . CreateClientPod ( getFlexBlockPodDefinition ( "rwx-block-ro-two" , s . pvcNameRWX , true ))
assert . Nil ( s . T (), err )
2017-12-29 00:33:36 -08:00
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" )
2018-01-04 00:30:06 -08:00
logger . Infof ( "Step 8: Read Data from both ReadyOnlyMany and ReadWriteOnce pods with ReadOnly Access" )
2018-10-14 12:10:08 +02:00
// Read data from RWO PVC via both ReadOnly pods
2018-08-23 06:56:59 -06:00
assert . Nil ( s . T (), s . kh . ReadFromPod ( "" , "rwo-block-ro-one" , filename1 , message1 ))
assert . Nil ( s . T (), s . kh . ReadFromPod ( "" , "rwo-block-ro-two" , filename1 , message1 ))
2018-10-14 12:10:08 +02:00
// Read data from RWX PVC via both ReadOnly pods
2018-08-23 06:56:59 -06:00
assert . Nil ( s . T (), s . kh . ReadFromPod ( "" , "rwx-block-ro-one" , filename1 , message1 ))
assert . Nil ( s . T (), s . kh . ReadFromPod ( "" , "rwx-block-ro-two" , filename1 , message1 ))
2017-12-29 00:33:36 -08:00
2018-01-04 00:30:06 -08:00
logger . Infof ( "Step 9: Write Data to Pod with ReadOnlyMany and ReadWriteOnce PVC mounted with ReadOnly access" )
2018-10-14 12:10:08 +02:00
// Write data to RWO PVC via pod with ReadOnly Set to true
2018-08-23 06:56:59 -06:00
message3 := "Persisted message three"
filename3 := "bsFile3"
err = s . kh . WriteToPod ( "" , "rwo-block-ro-one" , filename3 , message3 )
assert . Contains ( s . T (), err . Error (), "failed to write file" )
2018-10-14 12:10:08 +02:00
// Write data to RWx PVC via pod with ReadOnly Set to true
2018-08-23 06:56:59 -06:00
err = s . kh . WriteToPod ( "" , "rwx-block-ro-one" , filename3 , message3 )
assert . Contains ( s . T (), err . Error (), "failed to write file" )
2017-12-29 00:33:36 -08:00
2018-01-04 00:30:06 -08:00
logger . Infof ( "Step 10: UnMount Pod with ReadOnlyMany and ReadWriteOnce PVCs" )
2018-10-14 12:10:08 +02:00
// UnMount RWO PVC from both ReadOnly Pods
2018-08-21 15:24:52 -06:00
_ , err = s . kh . DeletePods ( "rwo-block-ro-one" , "rwo-block-ro-two" , "rwx-block-ro-one" , "rwx-block-ro-two" )
assert . Nil ( s . T (), err )
2017-12-29 00:33:36 -08:00
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" )
2020-02-11 17:11:41 -07:00
// Test volume expansion
v := version . MustParseSemantic ( s . kh . GetK8sServerVersion ())
if v . AtLeast ( version . MustParseSemantic ( "1.15.0" )) {
logger . Infof ( "additional step: Expand block storage" )
// Expanding the image by applying new PVC specs
err := s . testClient . BlockClient . CreatePVC ( defaultNamespace , s . pvcNameRWO , "rook-ceph-block-rwo" , "ReadWriteOnce" , "2M" )
require . Nil ( s . T (), err )
// Once the pod using the volume is terminated, the filesystem is expanded and the size of the PVC is increased.
expandedPodName := "setup-block-rwo"
err = s . kh . DeletePod ( defaultNamespace , expandedPodName )
require . Nil ( s . T (), err )
err = s . bc . CreateClientPod ( getFlexBlockPodDefinition ( expandedPodName , s . pvcNameRWO , false ))
require . Nil ( s . T (), err )
require . True ( s . T (), s . kh . IsPodRunning ( expandedPodName , defaultNamespace ), "Make sure new pod is running" )
require . True ( s . T (), s . kh . WaitUntilPVCIsExpanded ( defaultNamespace , s . pvcNameRWO , "2M" ), "Make sure PVC is expanded" )
logger . Infof ( "Block Storage successfully expanded" )
}
}
func getFlexBlockPodDefinition ( podName , blockName string , readOnly bool ) string {
return `apiVersion: v1
kind: Pod
metadata:
name: ` + podName + `
spec:
containers:
- image: busybox
name: block-test1
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
volumeMounts:
- name: block-persistent-storage
mountPath: ` + utils . TestMountPath + `
volumes:
- name: block-persistent-storage
persistentVolumeClaim:
claimName: ` + blockName + `
readOnly: ` + strconv . FormatBool ( readOnly ) + `
restartPolicy: Never`
2017-12-29 00:33:36 -08:00
}