mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 18:43:34 +00:00
csiaddons: read volumeId from source
read the volumeID from replication source if the ID is missing read it from req VolumeId as a fallback. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
committed by
mergify[bot]
parent
a160bf1359
commit
c03152bcaf
@ -116,6 +116,43 @@ func NewMiddlewareServerOption() grpc.ServerOption {
|
||||
return grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(middleWare...))
|
||||
}
|
||||
|
||||
// GetIDFromReplication returns the volumeID for Replication.
|
||||
func GetIDFromReplication(req interface{}) string {
|
||||
getID := func(r interface {
|
||||
GetVolumeId() string
|
||||
GetReplicationSource() *replication.ReplicationSource
|
||||
},
|
||||
) string {
|
||||
reqID := ""
|
||||
src := r.GetReplicationSource()
|
||||
if src != nil && src.GetVolume() != nil {
|
||||
reqID = src.GetVolume().GetVolumeId()
|
||||
}
|
||||
if reqID == "" {
|
||||
reqID = r.GetVolumeId() //nolint:nolintlint,staticcheck // req.VolumeId is deprecated
|
||||
}
|
||||
|
||||
return reqID
|
||||
}
|
||||
|
||||
switch r := req.(type) {
|
||||
case *replication.EnableVolumeReplicationRequest:
|
||||
return getID(r)
|
||||
case *replication.DisableVolumeReplicationRequest:
|
||||
return getID(r)
|
||||
case *replication.PromoteVolumeRequest:
|
||||
return getID(r)
|
||||
case *replication.DemoteVolumeRequest:
|
||||
return getID(r)
|
||||
case *replication.ResyncVolumeRequest:
|
||||
return getID(r)
|
||||
case *replication.GetVolumeReplicationInfoRequest:
|
||||
return getID(r)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func getReqID(req interface{}) string {
|
||||
// if req is nil empty string will be returned
|
||||
reqID := ""
|
||||
@ -156,17 +193,17 @@ func getReqID(req interface{}) string {
|
||||
|
||||
// Replication
|
||||
case *replication.EnableVolumeReplicationRequest:
|
||||
reqID = r.GetVolumeId()
|
||||
reqID = GetIDFromReplication(r)
|
||||
case *replication.DisableVolumeReplicationRequest:
|
||||
reqID = r.GetVolumeId()
|
||||
reqID = GetIDFromReplication(r)
|
||||
case *replication.PromoteVolumeRequest:
|
||||
reqID = r.GetVolumeId()
|
||||
reqID = GetIDFromReplication(r)
|
||||
case *replication.DemoteVolumeRequest:
|
||||
reqID = r.GetVolumeId()
|
||||
reqID = GetIDFromReplication(r)
|
||||
case *replication.ResyncVolumeRequest:
|
||||
reqID = r.GetVolumeId()
|
||||
reqID = GetIDFromReplication(r)
|
||||
case *replication.GetVolumeReplicationInfoRequest:
|
||||
reqID = r.GetVolumeId()
|
||||
reqID = GetIDFromReplication(r)
|
||||
}
|
||||
|
||||
return reqID
|
||||
|
@ -94,6 +94,62 @@ func TestGetReqID(t *testing.T) {
|
||||
&replication.GetVolumeReplicationInfoRequest{
|
||||
VolumeId: fakeID,
|
||||
},
|
||||
|
||||
// volumeId is set in ReplicationSource
|
||||
&replication.EnableVolumeReplicationRequest{
|
||||
ReplicationSource: &replication.ReplicationSource{
|
||||
Type: &replication.ReplicationSource_Volume{
|
||||
Volume: &replication.ReplicationSource_VolumeSource{
|
||||
VolumeId: fakeID,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&replication.DisableVolumeReplicationRequest{
|
||||
ReplicationSource: &replication.ReplicationSource{
|
||||
Type: &replication.ReplicationSource_Volume{
|
||||
Volume: &replication.ReplicationSource_VolumeSource{
|
||||
VolumeId: fakeID,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&replication.PromoteVolumeRequest{
|
||||
ReplicationSource: &replication.ReplicationSource{
|
||||
Type: &replication.ReplicationSource_Volume{
|
||||
Volume: &replication.ReplicationSource_VolumeSource{
|
||||
VolumeId: fakeID,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&replication.DemoteVolumeRequest{
|
||||
ReplicationSource: &replication.ReplicationSource{
|
||||
Type: &replication.ReplicationSource_Volume{
|
||||
Volume: &replication.ReplicationSource_VolumeSource{
|
||||
VolumeId: fakeID,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&replication.ResyncVolumeRequest{
|
||||
ReplicationSource: &replication.ReplicationSource{
|
||||
Type: &replication.ReplicationSource_Volume{
|
||||
Volume: &replication.ReplicationSource_VolumeSource{
|
||||
VolumeId: fakeID,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&replication.GetVolumeReplicationInfoRequest{
|
||||
ReplicationSource: &replication.ReplicationSource{
|
||||
Type: &replication.ReplicationSource_Volume{
|
||||
Volume: &replication.ReplicationSource_VolumeSource{
|
||||
VolumeId: fakeID,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, r := range req {
|
||||
if got := getReqID(r); got != fakeID {
|
||||
|
Reference in New Issue
Block a user