Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cephfs: add clone progress report in clone status #1036

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cephfs/admin/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 76 additions & 0 deletions cephfs/admin/clone_progress_report_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//go:build 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)
}()

wasInProgress := false
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:
wasInProgress = true
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 clone status: %q", status.State)
}
time.Sleep(5 * time.Millisecond)
}
assert.Equal(t, wasInProgress, true)
}
76 changes: 76 additions & 0 deletions cephfs/admin/clone_progress_report_unsupported_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//go:build !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)
}()

wasInProgress := false
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:
wasInProgress = true
assert.Empty(t, status.ProgressReport.PercentageCloned)
assert.Empty(t, status.ProgressReport.AmountCloned)
assert.Empty(t, status.ProgressReport.FilesCloned)
case CloneComplete:
done = true
case CloneFailed:
t.Fatal("clone failed")
default:
t.Fatalf("invalid clone status: %q", status.State)
}
time.Sleep(5 * time.Millisecond)
}
assert.Equal(t, wasInProgress, true)
}