mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-09 16:00:22 +00:00
e2e: introduce getClusterID() helper
There are many locations where the cluster-id (`ceph fsid`) is obtained from the Rook Toolbox. Instead of duplicating the code everywhere, use a new helper function getClusterID(). Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
b20e3fa784
commit
e30364cb4d
@ -92,14 +92,12 @@ func createCephfsStorageClass(
|
||||
|
||||
// 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
|
||||
var fsID string
|
||||
fsID, err = getClusterID(f)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get clusterID: %w", err)
|
||||
}
|
||||
if stdErr != "" {
|
||||
return fmt.Errorf("error getting fsid %v", stdErr)
|
||||
}
|
||||
sc.Parameters["clusterID"] = strings.Trim(fsID, "\n")
|
||||
sc.Parameters["clusterID"] = fsID
|
||||
}
|
||||
sc.Namespace = cephCSINamespace
|
||||
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/util"
|
||||
|
||||
@ -45,15 +44,11 @@ func createConfigMap(pluginPath string, c kubernetes.Interface, f *framework.Fra
|
||||
return err
|
||||
}
|
||||
|
||||
fsID, stdErr, err := execCommandInToolBoxPod(f, "ceph fsid", rookNamespace)
|
||||
fsID, err := getClusterID(f)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to exec command in toolbox: %w", err)
|
||||
return fmt.Errorf("failed to get clusterID: %w", err)
|
||||
}
|
||||
if stdErr != "" {
|
||||
return fmt.Errorf("error getting fsid %v", stdErr)
|
||||
}
|
||||
// remove new line present in fsID
|
||||
fsID = strings.Trim(fsID, "\n")
|
||||
|
||||
// get mon list
|
||||
mons, err := getMons(rookNamespace, c)
|
||||
if err != nil {
|
||||
|
@ -136,15 +136,10 @@ func createRBDStorageClass(
|
||||
sc.Parameters["csi.storage.k8s.io/node-stage-secret-namespace"] = cephCSINamespace
|
||||
sc.Parameters["csi.storage.k8s.io/node-stage-secret-name"] = rbdNodePluginSecretName
|
||||
|
||||
fsID, stdErr, err := execCommandInToolBoxPod(f, "ceph fsid", rookNamespace)
|
||||
fsID, err := getClusterID(f)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to get clusterID: %w", err)
|
||||
}
|
||||
if stdErr != "" {
|
||||
return fmt.Errorf("error getting fsid %v", stdErr)
|
||||
}
|
||||
// remove new line present in fsID
|
||||
fsID = strings.Trim(fsID, "\n")
|
||||
|
||||
sc.Parameters["clusterID"] = fsID
|
||||
for k, v := range parameters {
|
||||
|
@ -19,7 +19,6 @@ package e2e
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
snapapi "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
|
||||
@ -158,14 +157,10 @@ func createRBDSnapshotClass(f *framework.Framework) error {
|
||||
sc.Parameters["csi.storage.k8s.io/snapshotter-secret-namespace"] = cephCSINamespace
|
||||
sc.Parameters["csi.storage.k8s.io/snapshotter-secret-name"] = rbdProvisionerSecretName
|
||||
|
||||
fsID, stdErr, err := execCommandInToolBoxPod(f, "ceph fsid", rookNamespace)
|
||||
fsID, err := getClusterID(f)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to get clusterID: %w", err)
|
||||
}
|
||||
if stdErr != "" {
|
||||
return fmt.Errorf("failed to get fsid from ceph cluster %s", stdErr)
|
||||
}
|
||||
fsID = strings.Trim(fsID, "\n")
|
||||
sc.Parameters["clusterID"] = fsID
|
||||
sclient, err := newSnapshotClient()
|
||||
if err != nil {
|
||||
@ -193,14 +188,11 @@ func createCephFSSnapshotClass(f *framework.Framework) error {
|
||||
sc := getSnapshotClass(scPath)
|
||||
sc.Parameters["csi.storage.k8s.io/snapshotter-secret-namespace"] = cephCSINamespace
|
||||
sc.Parameters["csi.storage.k8s.io/snapshotter-secret-name"] = cephFSProvisionerSecretName
|
||||
fsID, stdErr, err := execCommandInToolBoxPod(f, "ceph fsid", rookNamespace)
|
||||
|
||||
fsID, err := getClusterID(f)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to get clusterID: %w", err)
|
||||
}
|
||||
if stdErr != "" {
|
||||
return fmt.Errorf("failed to get fsid from ceph cluster %s", stdErr)
|
||||
}
|
||||
fsID = strings.Trim(fsID, "\n")
|
||||
sc.Parameters["clusterID"] = fsID
|
||||
sclient, err := newSnapshotClient()
|
||||
if err != nil {
|
||||
|
@ -127,15 +127,11 @@ func validateRBDStaticPV(f *framework.Framework, appPath string, isBlock, checkI
|
||||
|
||||
c := f.ClientSet
|
||||
|
||||
fsID, e, err := execCommandInToolBoxPod(f, "ceph fsid", rookNamespace)
|
||||
fsID, err := getClusterID(f)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to get clusterID: %w", err)
|
||||
}
|
||||
if e != "" {
|
||||
return fmt.Errorf("failed to get fsid from ceph cluster %s", e)
|
||||
}
|
||||
// remove new line present in fsID
|
||||
fsID = strings.Trim(fsID, "\n")
|
||||
|
||||
size := staticPVSize
|
||||
// create rbd image
|
||||
cmd := fmt.Sprintf(
|
||||
@ -144,7 +140,7 @@ func validateRBDStaticPV(f *framework.Framework, appPath string, isBlock, checkI
|
||||
staticPVSize,
|
||||
rbdOptions(defaultRBDPool))
|
||||
|
||||
_, e, err = execCommandInToolBoxPod(f, cmd, rookNamespace)
|
||||
_, e, err := execCommandInToolBoxPod(f, cmd, rookNamespace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -346,15 +342,10 @@ func validateCephFsStaticPV(f *framework.Framework, appPath, scPath string) erro
|
||||
LabelSelector: "app=rook-ceph-tools",
|
||||
}
|
||||
|
||||
fsID, e, err := execCommandInPod(f, "ceph fsid", rookNamespace, &listOpt)
|
||||
fsID, err := getClusterID(f)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to get clusterID: %w", err)
|
||||
}
|
||||
if e != "" {
|
||||
return fmt.Errorf("failed to get fsid from ceph cluster %s", e)
|
||||
}
|
||||
// remove new line present in fsID
|
||||
fsID = strings.Trim(fsID, "\n")
|
||||
|
||||
// 4GiB in bytes
|
||||
size := "4294967296"
|
||||
@ -362,7 +353,7 @@ func validateCephFsStaticPV(f *framework.Framework, appPath, scPath string) erro
|
||||
// create subvolumegroup, command will work even if group is already present.
|
||||
cmd := fmt.Sprintf("ceph fs subvolumegroup create %s %s", fileSystemName, groupName)
|
||||
|
||||
_, e, err = execCommandInPod(f, cmd, rookNamespace, &listOpt)
|
||||
_, e, err := execCommandInPod(f, cmd, rookNamespace, &listOpt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
12
e2e/utils.go
12
e2e/utils.go
@ -121,6 +121,18 @@ func getMonsHash(mons string) string {
|
||||
return fmt.Sprintf("%x", md5.Sum([]byte(mons))) //nolint:gosec // hash generation
|
||||
}
|
||||
|
||||
func getClusterID(f *framework.Framework) (string, error) {
|
||||
fsID, stdErr, err := execCommandInToolBoxPod(f, "ceph fsid", rookNamespace)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed getting clusterID through toolbox: %w", err)
|
||||
}
|
||||
if stdErr != "" {
|
||||
return "", fmt.Errorf("error getting fsid: %s", stdErr)
|
||||
}
|
||||
// remove new line present in fsID
|
||||
return strings.Trim(fsID, "\n"), nil
|
||||
}
|
||||
|
||||
func getStorageClass(path string) (scv1.StorageClass, error) {
|
||||
sc := scv1.StorageClass{}
|
||||
err := unmarshal(path, &sc)
|
||||
|
Loading…
Reference in New Issue
Block a user