mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-22 06:10:22 +00:00
rbd: get description from remote status
This commit gets the description from remote status instead of local status. Local status doesn't have ',' due to which we get array index out of range panic. Fixes: #3388 Signed-off-by: Yati Padia <ypadia@redhat.com> Co-authored-by: shyam Ranganathan <srangana@redhat.com>
This commit is contained in:
parent
e5c5646963
commit
36b061d426
@ -898,14 +898,14 @@ func (rs *ReplicationServer) GetVolumeReplicationInfo(ctx context.Context,
|
|||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
localStatus, err := mirrorStatus.LocalStatus()
|
remoteStatus, err := RemoteStatus(mirrorStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorLog(ctx, err.Error())
|
log.ErrorLog(ctx, err.Error())
|
||||||
|
|
||||||
return nil, fmt.Errorf("failed to get local status: %w", err)
|
return nil, fmt.Errorf("failed to get remote status: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
description := localStatus.Description
|
description := remoteStatus.Description
|
||||||
lastSyncTime, err := getLastSyncTime(description)
|
lastSyncTime, err := getLastSyncTime(description)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get last sync time: %w", err)
|
return nil, fmt.Errorf("failed to get last sync time: %w", err)
|
||||||
@ -918,6 +918,26 @@ func (rs *ReplicationServer) GetVolumeReplicationInfo(ctx context.Context,
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoteStatus returns one SiteMirrorImageStatus item from the SiteStatuses
|
||||||
|
// slice that corresponds to the remote site's status. If the remote status
|
||||||
|
// is not found than the error ErrNotExist will be returned.
|
||||||
|
func RemoteStatus(gmis *librbd.GlobalMirrorImageStatus) (librbd.SiteMirrorImageStatus, error) {
|
||||||
|
var (
|
||||||
|
ss librbd.SiteMirrorImageStatus
|
||||||
|
err error = librbd.ErrNotExist
|
||||||
|
)
|
||||||
|
for i := range gmis.SiteStatuses {
|
||||||
|
if gmis.SiteStatuses[i].MirrorUUID != "" {
|
||||||
|
ss = gmis.SiteStatuses[i]
|
||||||
|
err = nil
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ss, err
|
||||||
|
}
|
||||||
|
|
||||||
// This function gets the local snapshot time from the description
|
// This function gets the local snapshot time from the description
|
||||||
// of localStatus and converts it into required type.
|
// of localStatus and converts it into required type.
|
||||||
func getLastSyncTime(description string) (*timestamppb.Timestamp, error) {
|
func getLastSyncTime(description string) (*timestamppb.Timestamp, error) {
|
||||||
@ -930,6 +950,9 @@ func getLastSyncTime(description string) (*timestamppb.Timestamp, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
splittedString := strings.SplitN(description, ",", 2)
|
splittedString := strings.SplitN(description, ",", 2)
|
||||||
|
if len(splittedString) == 1 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
type localStatus struct {
|
type localStatus struct {
|
||||||
LocalSnapshotTime int64 `json:"local_snapshot_timestamp"`
|
LocalSnapshotTime int64 `json:"local_snapshot_timestamp"`
|
||||||
}
|
}
|
||||||
|
@ -469,6 +469,12 @@ func TestValidateLastSyncTime(t *testing.T) {
|
|||||||
nil,
|
nil,
|
||||||
"failed to unmarshal description",
|
"failed to unmarshal description",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"description with no JSON",
|
||||||
|
`replaying`,
|
||||||
|
nil,
|
||||||
|
"",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
tt := tt
|
tt := tt
|
||||||
|
Loading…
Reference in New Issue
Block a user