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>
139 lines
3.1 KiB
Go
139 lines
3.1 KiB
Go
package migration
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
func testState() *State {
|
|
return &State{Version: stateVersion, ID: "1234567890abcdef1234567890abcdef", Config: testConfig(), Phase: "syncing"}
|
|
}
|
|
|
|
func TestStateAtomicAndPrivate(t *testing.T) {
|
|
p := filepath.Join(t.TempDir(), "state.json")
|
|
s := testState()
|
|
s.Notes = []string{SnapshotIdentityNote}
|
|
if err := SaveState(p, s); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
st, err := os.Stat(p)
|
|
if err != nil || st.Mode().Perm() != 0600 {
|
|
t.Fatalf("state permissions: %v, %v", st, err)
|
|
}
|
|
|
|
var wg sync.WaitGroup
|
|
wg.Add(1)
|
|
go func() {
|
|
defer wg.Done()
|
|
for i := 0; i < 40; i++ {
|
|
if err := SaveState(p, s); err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
}
|
|
}()
|
|
|
|
for i := 0; i < 100; i++ {
|
|
got, err := LoadState(p)
|
|
if err != nil {
|
|
t.Fatalf("reader observed partial state: %v", err)
|
|
}
|
|
|
|
if got.ID != s.ID {
|
|
t.Fatal("state identity changed")
|
|
}
|
|
|
|
if len(got.Notes) != 1 || got.Notes[0] != SnapshotIdentityNote {
|
|
t.Fatal("snapshot identity note was lost")
|
|
}
|
|
}
|
|
|
|
wg.Wait()
|
|
}
|
|
|
|
func TestStateRejectsCorruption(t *testing.T) {
|
|
for name, modify := range map[string]func(*State){
|
|
"version": func(s *State) { s.Version++ },
|
|
"short-id": func(s *State) { s.ID = "bad" },
|
|
"phase": func(s *State) { s.Phase = "finished" },
|
|
"ready-without-final": func(s *State) { s.Phase = "ready-for-cutover" },
|
|
"duplicate": func(s *State) { s.Snapshots = []Snapshot{{Name: "a"}, {Name: "a"}} },
|
|
"invalid-done": func(s *State) { s.Snapshots = []Snapshot{{Name: "a", Done: true}} },
|
|
"missing-live-base": func(s *State) { s.LiveSnapshot = "missing" },
|
|
"pending-live-base": func(s *State) {
|
|
s.Snapshots = []Snapshot{{Name: "pending"}}
|
|
s.LiveSnapshot = "pending"
|
|
},
|
|
} {
|
|
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 corrupt state")
|
|
}
|
|
})
|
|
}
|
|
|
|
p := filepath.Join(t.TempDir(), "state.json")
|
|
b, _ := json.Marshal(testState())
|
|
if err := os.WriteFile(p, append(b, []byte(" {}")...), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if _, err := LoadState(p); err == nil {
|
|
t.Fatal("accepted trailing data")
|
|
}
|
|
}
|
|
|
|
func TestLockExclusionAndRelease(t *testing.T) {
|
|
p := filepath.Join(t.TempDir(), "lock")
|
|
first, err := lockFile(p)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if second, err := lockFile(p); err == nil {
|
|
second.Close()
|
|
t.Fatal("second process acquired lock")
|
|
}
|
|
|
|
first.Close()
|
|
third, err := lockFile(p)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
third.Close()
|
|
}
|
|
|
|
func TestStateAndLockRejectSymlinks(t *testing.T) {
|
|
root := t.TempDir()
|
|
real := filepath.Join(root, "real")
|
|
if err := SaveState(real, testState()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
link := filepath.Join(root, "link")
|
|
if err := os.Symlink(real, link); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if _, err := LoadState(link); err == nil {
|
|
t.Fatal("followed state symlink")
|
|
}
|
|
|
|
if f, err := lockFile(link); err == nil {
|
|
f.Close()
|
|
t.Fatal("followed lock symlink")
|
|
}
|
|
}
|