From ead8776edcb3f881b6bc6e6d86d56503b277a7a8 Mon Sep 17 00:00:00 2001 From: Nikhil-Ladha Date: Thu, 17 Oct 2024 16:56:17 +0530 Subject: [PATCH] cephfs: add clone progress report in clone status add clone progress report in clone status output Signed-off-by: Nikhil-Ladha --- cephfs/admin/clone.go | 12 ++++- cephfs/admin/clone_progress_test.go | 73 +++++++++++++++++++++++++++++ cephfs/admin/clone_test.go | 8 ++++ 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 cephfs/admin/clone_progress_test.go diff --git a/cephfs/admin/clone.go b/cephfs/admin/clone.go index d8281359c7..9a00402fed 100644 --- a/cephfs/admin/clone.go +++ b/cephfs/admin/clone.go @@ -81,10 +81,18 @@ type CloneSource struct { Snapshot string `json:"snapshot"` } +// CloneProgressReport contains the progress report of a subvolume clone. +type CloneProgressReport struct { + PercentageCloned string `json:"percentage cloned"` + AmountCloned string `json:"amount cloned"` + FilesCloned string `json:"files cloned"` +} + // CloneStatus reports on the status of a subvolume clone. type CloneStatus struct { - State CloneState `json:"state"` - Source CloneSource `json:"source"` + State CloneState `json:"state"` + Source CloneSource `json:"source"` + ProgressReport CloneProgressReport `json:"progress_report"` // failure can be obtained through .GetFailure() failure *CloneFailure diff --git a/cephfs/admin/clone_progress_test.go b/cephfs/admin/clone_progress_test.go new file mode 100644 index 0000000000..9be78a1d16 --- /dev/null +++ b/cephfs/admin/clone_progress_test.go @@ -0,0 +1,73 @@ +//go:build ceph_main + +package admin + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func TestCloneProgress(t *testing.T) { + fsa := getFSAdmin(t) + volume := "cephfs" + group := "Park" + subname := "Jurrasic" + snapname := "dinodna1" + clonename := "babydino" + + err := fsa.CreateSubVolumeGroup(volume, group, nil) + assert.NoError(t, err) + defer func() { + err := fsa.RemoveSubVolumeGroup(volume, group) + assert.NoError(t, err) + }() + + svopts := &SubVolumeOptions{ + Mode: 0750, + Size: 20 * gibiByte, + } + err = fsa.CreateSubVolume(volume, group, subname, svopts) + assert.NoError(t, err) + defer func() { + err := fsa.RemoveSubVolume(volume, group, subname) + assert.NoError(t, err) + }() + + err = fsa.CreateSubVolumeSnapshot(volume, group, subname, snapname) + assert.NoError(t, err) + defer func() { + err := fsa.RemoveSubVolumeSnapshot(volume, group, subname, snapname) + assert.NoError(t, err) + }() + + err = fsa.CloneSubVolumeSnapshot( + volume, group, subname, snapname, clonename, + &CloneOptions{TargetGroup: group}) + assert.NoError(t, err) + defer func() { + err := fsa.RemoveSubVolume(volume, group, clonename) + assert.NoError(t, err) + }() + + for done := false; !done; { + status, err := fsa.CloneStatus(volume, group, clonename) + assert.NoError(t, err) + assert.NotNil(t, status) + switch status.State { + case ClonePending: + case CloneInProgress: + assert.NotNil(t, status.ProgressReport.PercentageCloned) + assert.NotNil(t, status.ProgressReport.AmountCloned) + assert.NotNil(t, status.ProgressReport.FilesCloned) + case CloneComplete: + done = true + case CloneFailed: + t.Fatal("clone failed") + default: + t.Fatalf("invalid status.State: %q", status.State) + } + time.Sleep(5 * time.Millisecond) + } +} diff --git a/cephfs/admin/clone_test.go b/cephfs/admin/clone_test.go index 0d947449b6..e5adda4d1f 100644 --- a/cephfs/admin/clone_test.go +++ b/cephfs/admin/clone_test.go @@ -27,6 +27,11 @@ var sampleCloneStatusInProg = []byte(`{ "volume": "cephfs", "subvolume": "subvol1", "snapshot": "snap1" + }, + "progress_report": { + "percentage cloned": "25%", + "amount cloned": "55/202", + "files cloned": "1/3" } } }`) @@ -66,6 +71,9 @@ func TestParseCloneStatus(t *testing.T) { assert.EqualValues(t, "subvol1", status.Source.SubVolume) assert.EqualValues(t, "snap1", status.Source.Snapshot) assert.EqualValues(t, "", status.Source.Group) + assert.EqualValues(t, "25%", status.ProgressReport.PercentageCloned) + assert.EqualValues(t, "55/202", status.ProgressReport.AmountCloned) + assert.EqualValues(t, "1/3", status.ProgressReport.FilesCloned) } }) }