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>
98 lines
2.9 KiB
Go
98 lines
2.9 KiB
Go
package migration
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func testConfig() Config {
|
|
return Config{Source: Endpoint{Config: "/clusters/a/ceph.conf", Keyring: "/clusters/a/keyring", Filesystem: "cephfs", Group: "group", Subvolume: "source"},
|
|
Target: Endpoint{Config: "/clusters/b/ceph.conf", Keyring: "/clusters/b/keyring", Filesystem: "cephfs", Group: "group", Subvolume: "target"}}
|
|
}
|
|
|
|
func TestConfigRejectsUnsafePathsAndNames(t *testing.T) {
|
|
for name, modify := range map[string]func(*Config){
|
|
"relative": func(c *Config) { c.Source.Config = "relative" },
|
|
"unclean": func(c *Config) { c.Target.Keyring = "/clusters/b/../b/keyring" },
|
|
"rsync-backend": func(c *Config) { c.Backend = "rsync" },
|
|
"flag-name": func(c *Config) { c.Target.Subvolume = "--force" },
|
|
"traversal": func(c *Config) { c.Source.Group = "../outside" },
|
|
"negative-rate": func(c *Config) { c.BandwidthKiB = -1 },
|
|
"overflow-rate": func(c *Config) { c.BandwidthKiB = 1 << 62 },
|
|
"bad-backend": func(c *Config) { c.Backend = "raw" },
|
|
"bad-workers": func(c *Config) { c.Workers = 65 },
|
|
"invalid-user": func(c *Config) { c.Source.User = "osd.0" },
|
|
} {
|
|
t.Run(name, func(t *testing.T) {
|
|
c := testConfig()
|
|
modify(&c)
|
|
if c.Validate() == nil {
|
|
t.Fatal("accepted invalid config")
|
|
}
|
|
})
|
|
}
|
|
|
|
if err := testConfig().Validate(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestNativeConfigAndResumeSettings(t *testing.T) {
|
|
c := testConfig()
|
|
c.Backend = "native"
|
|
if err := c.Validate(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
implicit := c
|
|
implicit.Backend = ""
|
|
if !sameMigrationIdentity(c, implicit) {
|
|
t.Fatal(`backend "" and "native" differ in resume identity`)
|
|
}
|
|
|
|
changed := c
|
|
changed.Workers, changed.BandwidthKiB = 32, 100000
|
|
if !sameMigrationIdentity(c, changed) {
|
|
t.Fatal("runtime settings invalidated resume identity")
|
|
}
|
|
|
|
changed.Target.Subvolume = "another"
|
|
if sameMigrationIdentity(c, changed) {
|
|
t.Fatal("accepted a different target")
|
|
}
|
|
}
|
|
|
|
func TestStrictJSONConfig(t *testing.T) {
|
|
b, _ := json.Marshal(testConfig())
|
|
for name, data := range map[string]string{"unknown": strings.TrimSuffix(string(b), "}") + ", \"typo\": true}", "trailing": string(b) + " {}", "truncated": string(b[:len(b)-2])} {
|
|
t.Run(name, func(t *testing.T) {
|
|
p := filepath.Join(t.TempDir(), "config.json")
|
|
if err := os.WriteFile(p, []byte(data), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if _, err := ReadConfig(p); err == nil {
|
|
t.Fatal("accepted invalid JSON config")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPrivateDirectoriesNeverFollowsSymlink(t *testing.T) {
|
|
root, outside := t.TempDir(), t.TempDir()
|
|
if err := os.Symlink(outside, filepath.Join(root, "link")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := privateDirectories(filepath.Join(root, "link", "new")); err == nil {
|
|
t.Fatal("followed symlink")
|
|
}
|
|
|
|
if _, err := os.Stat(filepath.Join(outside, "new")); !os.IsNotExist(err) {
|
|
t.Fatal("created directory through symlink")
|
|
}
|
|
}
|