mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-30 10:10:21 +00:00
rbd: move GetMappedID() to util package
This commit moves getMappedID() from rbd to util
package since it is not rbd specific and exports
it from there.
Signed-off-by: Rakshith R <rar@redhat.com>
(cherry picked from commit 496bcba85c
)
This commit is contained in:
parent
d42814dfb9
commit
dcd2a8c900
@ -1101,7 +1101,7 @@ func generateVolumeFromMapping(
|
||||
// extract clusterID mapping
|
||||
for _, cm := range *mapping {
|
||||
for key, val := range cm.ClusterIDMapping {
|
||||
mappedClusterID := getMappedID(key, val, vi.ClusterID)
|
||||
mappedClusterID := util.GetMappedID(key, val, vi.ClusterID)
|
||||
if mappedClusterID == "" {
|
||||
continue
|
||||
}
|
||||
@ -1115,7 +1115,7 @@ func generateVolumeFromMapping(
|
||||
poolID := fmt.Sprintf("%d", (vi.LocationID))
|
||||
for _, pools := range cm.RBDpoolIDMappingInfo {
|
||||
for key, val := range pools {
|
||||
mappedPoolID := getMappedID(key, val, poolID)
|
||||
mappedPoolID := util.GetMappedID(key, val, poolID)
|
||||
if mappedPoolID == "" {
|
||||
continue
|
||||
}
|
||||
@ -1142,20 +1142,6 @@ func generateVolumeFromMapping(
|
||||
return vol, util.ErrPoolNotFound
|
||||
}
|
||||
|
||||
// getMappedID check the input id is matching key or value.
|
||||
// If key==id the value will be returned.
|
||||
// If value==id the key will be returned.
|
||||
func getMappedID(key, value, id string) string {
|
||||
if key == id {
|
||||
return value
|
||||
}
|
||||
if value == id {
|
||||
return key
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func genVolFromVolumeOptions(
|
||||
ctx context.Context,
|
||||
volOptions, credentials map[string]string,
|
||||
|
@ -137,55 +137,3 @@ func TestValidateImageFeatures(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMappedID(t *testing.T) {
|
||||
t.Parallel()
|
||||
type args struct {
|
||||
key string
|
||||
value string
|
||||
id string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "test for matching key",
|
||||
args: args{
|
||||
key: "cluster1",
|
||||
value: "cluster2",
|
||||
id: "cluster1",
|
||||
},
|
||||
expected: "cluster2",
|
||||
},
|
||||
{
|
||||
name: "test for matching value",
|
||||
args: args{
|
||||
key: "cluster1",
|
||||
value: "cluster2",
|
||||
id: "cluster2",
|
||||
},
|
||||
expected: "cluster1",
|
||||
},
|
||||
{
|
||||
name: "test for invalid match",
|
||||
args: args{
|
||||
key: "cluster1",
|
||||
value: "cluster2",
|
||||
id: "cluster3",
|
||||
},
|
||||
expected: "",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
val := getMappedID(tt.args.key, tt.args.value, tt.args.id)
|
||||
if val != tt.expected {
|
||||
t.Errorf("getMappedID() got = %v, expected %v", val, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -120,3 +120,17 @@ func getClusterMappingInfo(clusterID, filename string) (*[]ClusterMappingInfo, e
|
||||
func GetClusterMappingInfo(clusterID string) (*[]ClusterMappingInfo, error) {
|
||||
return getClusterMappingInfo(clusterID, clusterMappingConfigFile)
|
||||
}
|
||||
|
||||
// GetMappedID check the input id is matching key or value.
|
||||
// If key==id the value will be returned.
|
||||
// If value==id the key will be returned.
|
||||
func GetMappedID(key, value, id string) string {
|
||||
if key == id {
|
||||
return value
|
||||
}
|
||||
if value == id {
|
||||
return key
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
@ -246,3 +246,55 @@ func validateMapping(t *testing.T, clusterID, rbdPoolID, cephFSPoolID string, ma
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestGetMappedID(t *testing.T) {
|
||||
t.Parallel()
|
||||
type args struct {
|
||||
key string
|
||||
value string
|
||||
id string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "test for matching key",
|
||||
args: args{
|
||||
key: "cluster1",
|
||||
value: "cluster2",
|
||||
id: "cluster1",
|
||||
},
|
||||
expected: "cluster2",
|
||||
},
|
||||
{
|
||||
name: "test for matching value",
|
||||
args: args{
|
||||
key: "cluster1",
|
||||
value: "cluster2",
|
||||
id: "cluster2",
|
||||
},
|
||||
expected: "cluster1",
|
||||
},
|
||||
{
|
||||
name: "test for invalid match",
|
||||
args: args{
|
||||
key: "cluster1",
|
||||
value: "cluster2",
|
||||
id: "cluster3",
|
||||
},
|
||||
expected: "",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
val := GetMappedID(tt.args.key, tt.args.value, tt.args.id)
|
||||
if val != tt.expected {
|
||||
t.Errorf("getMappedID() got = %v, expected %v", val, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user