e2e: pass SC parameters to createCephfsStorageClass()

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-09-21 16:56:15 +02:00 committed by mergify[bot]
parent 6f2f972f5b
commit 85df59531b
3 changed files with 30 additions and 17 deletions

View File

@ -220,7 +220,7 @@ var _ = Describe("cephfs", func() {
}) })
By("create a storageclass with pool and a PVC then bind it to an app", func() { By("create a storageclass with pool and a PVC then bind it to an app", func() {
err := createCephfsStorageClass(f.ClientSet, f, true, "") err := createCephfsStorageClass(f.ClientSet, f, true, nil)
if err != nil { if err != nil {
e2elog.Failf("failed to create CephFS storageclass with error %v", err) e2elog.Failf("failed to create CephFS storageclass with error %v", err)
} }
@ -235,7 +235,7 @@ var _ = Describe("cephfs", func() {
}) })
By("create a PVC and bind it to an app", func() { By("create a PVC and bind it to an app", func() {
err := createCephfsStorageClass(f.ClientSet, f, false, "") err := createCephfsStorageClass(f.ClientSet, f, false, nil)
if err != nil { if err != nil {
e2elog.Failf("failed to create CephFS storageclass with error %v", err) e2elog.Failf("failed to create CephFS storageclass with error %v", err)
} }
@ -332,7 +332,10 @@ var _ = Describe("cephfs", func() {
if err != nil { if err != nil {
e2elog.Failf("failed to create configmap with error %v", err) e2elog.Failf("failed to create configmap with error %v", err)
} }
err = createCephfsStorageClass(f.ClientSet, f, false, "clusterID-1") params := map[string]string{
"clusterID": "clusterID-1",
}
err = createCephfsStorageClass(f.ClientSet, f, false, params)
if err != nil { if err != nil {
e2elog.Failf("failed to create storageclass with error %v", err) e2elog.Failf("failed to create storageclass with error %v", err)
} }
@ -352,7 +355,8 @@ var _ = Describe("cephfs", func() {
// create resources and verify subvolume group creation // create resources and verify subvolume group creation
// for the second cluster. // for the second cluster.
err = createCephfsStorageClass(f.ClientSet, f, false, "clusterID-2") params["clusterID"] = "clusterID-2"
err = createCephfsStorageClass(f.ClientSet, f, false, params)
if err != nil { if err != nil {
e2elog.Failf("failed to create storageclass with error %v", err) e2elog.Failf("failed to create storageclass with error %v", err)
} }
@ -376,7 +380,7 @@ var _ = Describe("cephfs", func() {
if err != nil { if err != nil {
e2elog.Failf("failed to create configmap with error %v", err) e2elog.Failf("failed to create configmap with error %v", err)
} }
err = createCephfsStorageClass(f.ClientSet, f, false, "") err = createCephfsStorageClass(f.ClientSet, f, false, nil)
if err != nil { if err != nil {
e2elog.Failf("failed to create storageclass with error %v", err) e2elog.Failf("failed to create storageclass with error %v", err)
} }

View File

@ -34,7 +34,7 @@ func validateSubvolumegroup(f *framework.Framework, subvolgrp string) error {
return nil return nil
} }
func createCephfsStorageClass(c kubernetes.Interface, f *framework.Framework, enablePool bool, clusterID string) error { func createCephfsStorageClass(c kubernetes.Interface, f *framework.Framework, enablePool bool, params map[string]string) error {
scPath := fmt.Sprintf("%s/%s", cephfsExamplePath, "storageclass.yaml") scPath := fmt.Sprintf("%s/%s", cephfsExamplePath, "storageclass.yaml")
sc, err := getStorageClass(scPath) sc, err := getStorageClass(scPath)
if err != nil { if err != nil {
@ -53,20 +53,29 @@ func createCephfsStorageClass(c kubernetes.Interface, f *framework.Framework, en
if enablePool { if enablePool {
sc.Parameters["pool"] = "myfs-data0" sc.Parameters["pool"] = "myfs-data0"
} }
fsID, stdErr, err := execCommandInToolBoxPod(f, "ceph fsid", rookNamespace)
if err != nil { // overload any parameters that were passed
return err if params == nil {
// create an empty params, so that params["clusterID"] below
// does not panic
params = map[string]string{}
}
for param, value := range params {
sc.Parameters[param] = value
}
// fetch and set fsID from the cluster if not set in params
if _, found := params["clusterID"]; !found {
fsID, stdErr, failErr := execCommandInToolBoxPod(f, "ceph fsid", rookNamespace)
if failErr != nil {
return failErr
} }
if stdErr != "" { if stdErr != "" {
return fmt.Errorf("error getting fsid %v", stdErr) return fmt.Errorf("error getting fsid %v", stdErr)
} }
// remove new line present in fsID sc.Parameters["clusterID"] = strings.Trim(fsID, "\n")
fsID = strings.Trim(fsID, "\n")
if clusterID != "" {
fsID = clusterID
} }
sc.Namespace = cephCSINamespace sc.Namespace = cephCSINamespace
sc.Parameters["clusterID"] = fsID
_, err = c.StorageV1().StorageClasses().Create(context.TODO(), &sc, metav1.CreateOptions{}) _, err = c.StorageV1().StorageClasses().Create(context.TODO(), &sc, metav1.CreateOptions{})
return err return err
} }

View File

@ -55,7 +55,7 @@ var _ = Describe("CephFS Upgrade Testing", func() {
if err != nil { if err != nil {
e2elog.Failf("failed to create secret with error %v", err) e2elog.Failf("failed to create secret with error %v", err)
} }
err = createCephfsStorageClass(f.ClientSet, f, true, "") err = createCephfsStorageClass(f.ClientSet, f, true, nil)
if err != nil { if err != nil {
e2elog.Failf("failed to create storageclass with error %v", err) e2elog.Failf("failed to create storageclass with error %v", err)
} }