Files
Sebastian UnterschützandClaude Opus 5.5 330a3ec12c feat!: remove the rsync backend
The native libcephfs backend is the only transfer path. The rsync
transport, the mounted-filesystem access and its helpers (mount check,
path resolution below a mount, mount claim, quota and hardlink repair
through the mount) are removed, together with the rsync lab test and
the client image that only added rsync.

The claim and release tests now exercise the native claim through a
local test file system with real flock locks.

BREAKING CHANGE: "backend": "rsync" and the endpoint field "mount" are
rejected. "backend" is optional and only accepts "native"; jobs created
with "native" resume without it. Journals of rsync jobs cannot be
resumed. Builds without the build tag ceph only support doctor and
status.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 22:03:22 +01:00

145 lines
4.1 KiB
Go

package migration
import (
"context"
"encoding/json"
"errors"
"io"
"path/filepath"
"slices"
"testing"
)
// snapshotCeph fakes "ceph fs subvolume snapshot ls|rm" for two clusters,
// told apart by the --conf argument.
type snapshotCeph struct {
snaps map[string][]string
failRm string
removed []string
}
func (f *snapshotCeph) Exec(_ context.Context, out io.Writer, _ string, args ...string) error {
conf := args[1]
i := slices.Index(args, "snapshot")
switch args[i+1] {
case "ls":
var list []map[string]string
for _, n := range f.snaps[conf] {
list = append(list, map[string]string{"name": n})
}
return json.NewEncoder(out).Encode(list)
case "rm":
name := args[i+4]
if name == f.failRm {
return errors.New("injected failure")
}
f.snaps[conf] = slices.DeleteFunc(f.snaps[conf], func(n string) bool { return n == name })
f.removed = append(f.removed, conf+":"+name)
return nil
}
return errors.New("unexpected command")
}
func TestRemoveOwnedSnapshots(t *testing.T) {
all := []string{"app-1", "cephmig-a", "cephmig-b", "cephmig-c"}
newState := func() *State {
s := testState()
for _, n := range all {
s.Snapshots = append(s.Snapshots, Snapshot{Name: n, Owned: n != "app-1", Done: true,
CreatedAt: "2026-01-01 00:00:00", TargetCreatedAt: "2026-01-01 00:00:01"})
}
s.LiveSnapshot = "cephmig-c"
return s
}
statePath := filepath.Join(t.TempDir(), "state.json")
f := &snapshotCeph{snaps: map[string][]string{"src.conf": slices.Clone(all), "dst.conf": slices.Clone(all)}}
src := ceph{endpoint: Endpoint{Config: "src.conf", Filesystem: "fs", Subvolume: "v"}, exec: f}
dst := ceph{endpoint: Endpoint{Config: "dst.conf", Filesystem: "fs", Subvolume: "v"}, exec: f}
// An interrupted run leaves the journal marked, and the retry finishes.
s := newState()
f.failRm = "cephmig-b"
if err := removeOwnedSnapshots(context.Background(), src, dst, statePath, s, s.LiveSnapshot); err == nil {
t.Fatal("injected failure not reported")
}
loaded, err := LoadState(statePath)
if err != nil {
t.Fatal(err)
}
if !loaded.Snapshots[1].Removed || !loaded.Snapshots[2].Removed || loaded.Snapshots[3].Removed || loaded.Snapshots[0].Removed {
t.Fatalf("journal marks: %+v", loaded.Snapshots)
}
f.failRm = ""
if err := removeOwnedSnapshots(context.Background(), src, dst, statePath, loaded, loaded.LiveSnapshot); err != nil {
t.Fatal(err)
}
for conf, names := range f.snaps {
if !slices.Equal(names, []string{"app-1", "cephmig-c"}) {
t.Fatalf("%s keeps %v", conf, names)
}
}
// Cleanup removes the base too, but never application snapshots.
loaded.LiveSnapshot = ""
if err := removeOwnedSnapshots(context.Background(), src, dst, statePath, loaded, ""); err != nil {
t.Fatal(err)
}
for conf, names := range f.snaps {
if !slices.Equal(names, []string{"app-1"}) {
t.Fatalf("%s keeps %v", conf, names)
}
}
if _, err := LoadState(statePath); err != nil {
t.Fatal(err)
}
}
func TestStateRejectsInvalidRemoval(t *testing.T) {
done := Snapshot{Name: "a", Owned: true, Done: true, Removed: true, CreatedAt: "x", TargetCreatedAt: "y"}
for name, modify := range map[string]func(*State){
"application snapshot": func(s *State) { d := done; d.Owned = false; s.Snapshots = []Snapshot{d} },
"incomplete": func(s *State) { s.Snapshots = []Snapshot{{Name: "a", Owned: true, Removed: true}} },
"removed live base": func(s *State) { s.Snapshots = []Snapshot{done}; s.LiveSnapshot = "a" },
} {
t.Run(name, func(t *testing.T) {
p := filepath.Join(t.TempDir(), "state.json")
s := testState()
modify(s)
if err := SaveState(p, s); err != nil {
t.Fatal(err)
}
if _, err := LoadState(p); err == nil {
t.Fatal("accepted invalid removal")
}
})
}
}
func TestCleanedUp(t *testing.T) {
s := testState()
s.Phase = "ready-for-cutover"
s.Snapshots = []Snapshot{{Name: "app", Done: true}, {Name: "cephmig-x", Owned: true, Done: true, Final: true}}
s.LiveSnapshot = "cephmig-x"
if cleanedUp(s) {
t.Fatal("ready job reported as cleaned up")
}
s.LiveSnapshot = ""
s.Snapshots[1].Removed = true
if !cleanedUp(s) {
t.Fatal("cleaned job not recognized")
}
}