e2e: adjust migration tests to use clusterID in the volume context

Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
Humble Chirammal 2021-10-08 14:01:33 +05:30 committed by mergify[bot]
parent c584fa20da
commit 819f4f9048
3 changed files with 62 additions and 23 deletions

View File

@ -8,6 +8,7 @@ import (
"strings" "strings"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
) )
@ -48,7 +49,7 @@ func validateRBDStaticMigrationPVDeletion(f *framework.Framework, appPath, scNam
} }
opt["migration"] = "true" opt["migration"] = "true"
opt["monitors"] = mon opt["clusterID"] = getMonsHash(mon)
opt["imageFeatures"] = staticPVImageFeature opt["imageFeatures"] = staticPVImageFeature
opt["pool"] = defaultRBDPool opt["pool"] = defaultRBDPool
opt["staticVolume"] = strconv.FormatBool(true) opt["staticVolume"] = strconv.FormatBool(true)
@ -114,3 +115,32 @@ func composeIntreeMigVolID(mons, rbdImageName string) string {
return strings.Join(vhSlice, "_") return strings.Join(vhSlice, "_")
} }
// generateClusterIDConfigMapForMigration retrieve monitors and generate a hash value which
// is used as a clusterID in the custom configmap, this function also recreate RBD CSI pods
// once the custom config map has been recreated.
func generateClusterIDConfigMapForMigration(f *framework.Framework, c kubernetes.Interface) error {
// create monitors hash by fetching monitors from the cluster.
mons, err := getMons(rookNamespace, c)
if err != nil {
return fmt.Errorf("failed to get monitors %w", err)
}
mon := strings.Join(mons, ",")
inClusterID := getMonsHash(mon)
clusterInfo := map[string]map[string]string{}
clusterInfo[inClusterID] = map[string]string{}
// create custom configmap
err = createCustomConfigMap(f.ClientSet, rbdDirPath, clusterInfo)
if err != nil {
return fmt.Errorf("failed to create configmap with error %w", err)
}
// restart csi pods for the configmap to take effect.
err = recreateCSIRBDPods(f)
if err != nil {
return fmt.Errorf("failed to recreate rbd csi pods with error %w", err)
}
return nil
}

View File

@ -367,32 +367,17 @@ var _ = Describe("RBD", func() {
} }
}) })
} }
// todo: may be remove the below deletion test later once the migration nodestage tests are adjusted
// also to have deletion validation through the same.
By("validate RBD migration+static Block PVC Deletion", func() { By("validate RBD migration+static Block PVC Deletion", func() {
// create monitors hash by fetching monitors from the cluster. err := generateClusterIDConfigMapForMigration(f, c)
mons, err := getMons(rookNamespace, c)
if err != nil { if err != nil {
e2elog.Failf("failed to get monitors %v", err) e2elog.Failf("failed to generate clusterID configmap with error %v", err)
}
mon := strings.Join(mons, ",")
inClusterID := getMonsHash(mon)
clusterInfo := map[string]map[string]string{}
clusterInfo[inClusterID] = map[string]string{}
// create custom configmap
err = createCustomConfigMap(f.ClientSet, rbdDirPath, clusterInfo)
if err != nil {
e2elog.Failf("failed to create configmap with error %v", err)
} }
err = createRBDStorageClass(f.ClientSet, f, "migrationsc", nil, nil, deletePolicy) err = createRBDStorageClass(f.ClientSet, f, "migrationsc", nil, nil, deletePolicy)
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)
} }
// restart csi pods for the configmap to take effect.
err = recreateCSIRBDPods(f)
if err != nil {
e2elog.Failf("failed to recreate rbd csi pods with error %v", err)
}
err = validateRBDStaticMigrationPVDeletion(f, rawAppPath, "migrationsc", true) err = validateRBDStaticMigrationPVDeletion(f, rawAppPath, "migrationsc", true)
if err != nil { if err != nil {
e2elog.Failf("failed to validate rbd migrated static block pv with error %v", err) e2elog.Failf("failed to validate rbd migrated static block pv with error %v", err)
@ -1617,21 +1602,45 @@ var _ = Describe("RBD", func() {
}) })
By("validate RBD migration+static FileSystem PVC", func() { By("validate RBD migration+static FileSystem PVC", func() {
err := validateRBDStaticMigrationPV(f, appPath, false) err := generateClusterIDConfigMapForMigration(f, c)
if err != nil {
e2elog.Failf("failed to generate clusterID configmap with error %v", err)
}
err = validateRBDStaticMigrationPV(f, appPath, false)
if err != nil { if err != nil {
e2elog.Failf("failed to validate rbd migrated static pv with error %v", err) e2elog.Failf("failed to validate rbd migrated static pv with error %v", err)
} }
// validate created backend rbd images // validate created backend rbd images
validateRBDImageCount(f, 0, defaultRBDPool) validateRBDImageCount(f, 0, defaultRBDPool)
err = deleteConfigMap(rbdDirPath)
if err != nil {
e2elog.Failf("failed to delete configmap with error %v", err)
}
err = createConfigMap(rbdDirPath, f.ClientSet, f)
if err != nil {
e2elog.Failf("failed to create configmap with error %v", err)
}
}) })
By("validate RBD migration+static Block PVC", func() { By("validate RBD migration+static Block PVC", func() {
err := validateRBDStaticMigrationPV(f, rawAppPath, true) err := generateClusterIDConfigMapForMigration(f, c)
if err != nil {
e2elog.Failf("failed to generate clusterID configmap with error %v", err)
}
err = validateRBDStaticMigrationPV(f, rawAppPath, true)
if err != nil { if err != nil {
e2elog.Failf("failed to validate rbd migrated static block pv with error %v", err) e2elog.Failf("failed to validate rbd migrated static block pv with error %v", err)
} }
// validate created backend rbd images // validate created backend rbd images
validateRBDImageCount(f, 0, defaultRBDPool) validateRBDImageCount(f, 0, defaultRBDPool)
err = deleteConfigMap(rbdDirPath)
if err != nil {
e2elog.Failf("failed to delete configmap with error %v", err)
}
err = createConfigMap(rbdDirPath, f.ClientSet, f)
if err != nil {
e2elog.Failf("failed to create configmap with error %v", err)
}
}) })
By("validate failure of RBD static PVC without imageFeatures parameter", func() { By("validate failure of RBD static PVC without imageFeatures parameter", func() {

View File

@ -256,7 +256,7 @@ func validateRBDStaticMigrationPV(f *framework.Framework, appPath string, isBloc
} }
opt["migration"] = "true" opt["migration"] = "true"
opt["monitors"] = mon opt["clusterID"] = getMonsHash(mon)
opt["imageFeatures"] = staticPVImageFeature opt["imageFeatures"] = staticPVImageFeature
opt["pool"] = defaultRBDPool opt["pool"] = defaultRBDPool
opt["staticVolume"] = strconv.FormatBool(true) opt["staticVolume"] = strconv.FormatBool(true)