Skip to content

Commit

Permalink
Add testcase for defaultfstype provisioner conditions:
Browse files Browse the repository at this point in the history
There are 4 combinations added here:

    StorageClass set + default set
    StorageClass unset + default set
    StorageClass set + default unset
    StorageClass unset + default unset

Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
  • Loading branch information
humblec committed Jun 14, 2020
1 parent fa371e7 commit bbeab57
Showing 1 changed file with 134 additions and 1 deletion.
135 changes: 134 additions & 1 deletion pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ type provisioningTestcase struct {
expectCreateVolDo interface{}
withExtraMetadata bool
skipCreateVolume bool
skipDefaultFSType bool
}

type pvSpec struct {
Expand Down Expand Up @@ -865,6 +866,135 @@ func getDefaultSecretObjects() []runtime.Object {
}
}

func TestFSTypeProvision(t *testing.T) {
var requestedBytes int64 = 100
deletePolicy := v1.PersistentVolumeReclaimDelete
testcases := map[string]provisioningTestcase{
"fstype not set/'nil' in SC to provision": {
volOpts: controller.ProvisionOptions{
StorageClass: &storagev1.StorageClass{
ReclaimPolicy: &deletePolicy,
Parameters: map[string]string{
// We deliberately skip fsType in sc param
// "fstype": "",
},
},
PVName: "test-name",
PVC: createFakePVC(requestedBytes),
},
expectedPVSpec: &pvSpec{
Name: "test-testi",
ReclaimPolicy: v1.PersistentVolumeReclaimDelete,
Capacity: v1.ResourceList{
v1.ResourceName(v1.ResourceStorage): bytesToGiQuantity(requestedBytes),
},
CSIPVS: &v1.CSIPersistentVolumeSource{
Driver: "test-driver",
VolumeHandle: "test-volume-id",
FSType: "ext4",
VolumeAttributes: map[string]string{
"storage.kubernetes.io/csiProvisionerIdentity": "test-provisioner",
},
},
},
expectState: controller.ProvisioningFinished,
},
"Other fstype(ex:'xfs') set in SC": {
volOpts: controller.ProvisionOptions{
StorageClass: &storagev1.StorageClass{
ReclaimPolicy: &deletePolicy,
Parameters: map[string]string{
"fstype": "xfs",
},
},
PVName: "test-name",
PVC: createFakePVC(requestedBytes),
},
expectedPVSpec: &pvSpec{
Name: "test-testi",
ReclaimPolicy: v1.PersistentVolumeReclaimDelete,
Capacity: v1.ResourceList{
v1.ResourceName(v1.ResourceStorage): bytesToGiQuantity(requestedBytes),
},
CSIPVS: &v1.CSIPersistentVolumeSource{
Driver: "test-driver",
VolumeHandle: "test-volume-id",
FSType: "xfs",
VolumeAttributes: map[string]string{
"storage.kubernetes.io/csiProvisionerIdentity": "test-provisioner",
},
},
},
expectState: controller.ProvisioningFinished,
},

"fstype not set/Nil in SC and defaultFSType arg unset for provisioner": {
volOpts: controller.ProvisionOptions{
StorageClass: &storagev1.StorageClass{
ReclaimPolicy: &deletePolicy,
Parameters: map[string]string{
// We deliberately skip fsType in sc param
// "fstype": "xfs",
},
},
PVName: "test-name",
PVC: createFakePVC(requestedBytes),
},
skipDefaultFSType: true,
expectedPVSpec: &pvSpec{
Name: "test-testi",
ReclaimPolicy: v1.PersistentVolumeReclaimDelete,
Capacity: v1.ResourceList{
v1.ResourceName(v1.ResourceStorage): bytesToGiQuantity(requestedBytes),
},
CSIPVS: &v1.CSIPersistentVolumeSource{
Driver: "test-driver",
VolumeHandle: "test-volume-id",
FSType: "",
VolumeAttributes: map[string]string{
"storage.kubernetes.io/csiProvisionerIdentity": "test-provisioner",
},
},
},
expectState: controller.ProvisioningFinished,
},

"fstype set in SC and defaultFSType arg unset for provisioner": {
volOpts: controller.ProvisionOptions{
StorageClass: &storagev1.StorageClass{
ReclaimPolicy: &deletePolicy,
Parameters: map[string]string{
"fstype": "xfs",
},
},
PVName: "test-name",
PVC: createFakePVC(requestedBytes),
},
skipDefaultFSType: true,
expectedPVSpec: &pvSpec{
Name: "test-testi",
ReclaimPolicy: v1.PersistentVolumeReclaimDelete,
Capacity: v1.ResourceList{
v1.ResourceName(v1.ResourceStorage): bytesToGiQuantity(requestedBytes),
},
CSIPVS: &v1.CSIPersistentVolumeSource{
Driver: "test-driver",
VolumeHandle: "test-volume-id",
FSType: "xfs",
VolumeAttributes: map[string]string{
"storage.kubernetes.io/csiProvisionerIdentity": "test-provisioner",
},
},
},
expectState: controller.ProvisioningFinished,
},
}

for k, tc := range testcases {
runProvisionTest(t, k, tc, requestedBytes, driverName, "" /* no migration */)
}
}

func TestProvision(t *testing.T) {
var requestedBytes int64 = 100
deletePolicy := v1.PersistentVolumeReclaimDelete
Expand Down Expand Up @@ -1696,7 +1826,6 @@ func newSnapshot(name, className, boundToContent, snapshotUID, claimName string,

func runProvisionTest(t *testing.T, k string, tc provisioningTestcase, requestedBytes int64, provisionDriverName, supportsMigrationFromInTreePluginName string) {
t.Logf("Running test: %v", k)

tmpdir := tempDir(t)
defer os.RemoveAll(tmpdir)
mockController, driver, _, controllerServer, csiConn, err := createMockServer(t, tmpdir)
Expand All @@ -1709,6 +1838,10 @@ func runProvisionTest(t *testing.T, k string, tc provisioningTestcase, requested
clientSet := fakeclientset.NewSimpleClientset(tc.clientSetObjects...)

pluginCaps, controllerCaps := provisionCapabilities()

if tc.skipDefaultFSType {
defaultfsType = ""
}
csiProvisioner := NewCSIProvisioner(clientSet, 5*time.Second, "test-provisioner", "test", 5, csiConn.conn,
nil, provisionDriverName, pluginCaps, controllerCaps, supportsMigrationFromInTreePluginName, false, csitrans.New(), nil, nil, nil, nil, nil, tc.withExtraMetadata, defaultfsType)
out := &csi.CreateVolumeResponse{
Expand Down

0 comments on commit bbeab57

Please sign in to comment.