rbd: consider empty mirroring mode

consider the empty mirroring mode when
validating the snapshot interval and
the scheduling time.
Even if the mirroring Mode is not set
validate the snapshot scheduling details
as cephcsi sets the mirroring mode to default
snapshot.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
(cherry picked from commit 3c85219962)
This commit is contained in:
Madhu Rajanna 2021-08-09 10:18:32 +05:30 committed by mergify[bot]
parent 75ff33785b
commit 72a2b97be2
2 changed files with 22 additions and 1 deletions

View File

@ -130,7 +130,7 @@ func getMirroringMode(ctx context.Context, parameters map[string]string) (librbd
// getSchedulingDetails gets the mirroring mode and scheduling details from the // getSchedulingDetails gets the mirroring mode and scheduling details from the
// input GRPC request parameters and validates the scheduling is only supported // input GRPC request parameters and validates the scheduling is only supported
// for mirroring mode. // for snapshot mirroring mode.
func getSchedulingDetails(parameters map[string]string) (admin.Interval, admin.StartTime, error) { func getSchedulingDetails(parameters map[string]string) (admin.Interval, admin.StartTime, error) {
admInt := admin.NoInterval admInt := admin.NoInterval
adminStartTime := admin.NoStartTime adminStartTime := admin.NoStartTime
@ -140,6 +140,10 @@ func getSchedulingDetails(parameters map[string]string) (admin.Interval, admin.S
switch imageMirroringMode(val) { switch imageMirroringMode(val) {
case imageMirrorModeSnapshot: case imageMirrorModeSnapshot:
// If mirroring mode is not set in parameters, we are defaulting mirroring
// mode to snapshot. Discard empty mirroring mode from validation as it is
// an optional parameter.
case "":
default: default:
return admInt, adminStartTime, status.Error(codes.InvalidArgument, "scheduling is only supported for snapshot mode") return admInt, adminStartTime, status.Error(codes.InvalidArgument, "scheduling is only supported for snapshot mode")
} }

View File

@ -138,6 +138,23 @@ func TestGetSchedulingDetails(t *testing.T) {
admin.NoStartTime, admin.NoStartTime,
false, false,
}, },
{
"when no parameters and scheduling details are specified",
map[string]string{},
admin.NoInterval,
admin.NoStartTime,
false,
},
{
"when no mirroring mode is specified",
map[string]string{
schedulingIntervalKey: "1h",
schedulingStartTimeKey: "14:00:00-05:00",
},
admin.Interval("1h"),
admin.StartTime("14:00:00-05:00"),
false,
},
} }
for _, tt := range tests { for _, tt := range tests {
tt := tt tt := tt