feat(storage): rename snapraid_content to snapraid_conf; clarify conf vs content file; add auto-detect and conf viewer
This commit is contained in:
@@ -170,13 +170,13 @@ func (jm *JobManager) runJob(job db.StorageJob) {
|
||||
return
|
||||
}
|
||||
sc := SnapraidConfig{
|
||||
Content: envcfg.SnapraidContent,
|
||||
Conf: envcfg.SnapraidConf,
|
||||
DataDirs: ParseSnapraidDataDirs(envcfg.SnapraidDataDirs),
|
||||
ParityDir: envcfg.SnapraidParityDir,
|
||||
ScrubPlan: envcfg.SnapraidScrubPlan,
|
||||
}
|
||||
if err := ValidateSnapraidContent(sc.Content); err != nil {
|
||||
jm.failJob(job.ID, -1, fmt.Sprintf("content validation: %v", err))
|
||||
if err := ValidateSnapraidConf(sc.Conf); err != nil {
|
||||
jm.failJob(job.ID, -1, fmt.Sprintf("conf validation: %v", err))
|
||||
return
|
||||
}
|
||||
if job.Kind == "snapraid_scrub" {
|
||||
|
||||
@@ -8,17 +8,17 @@ import (
|
||||
)
|
||||
|
||||
type SnapraidConfig struct {
|
||||
Content string
|
||||
DataDirs []string
|
||||
Conf string
|
||||
DataDirs []string
|
||||
ParityDir string
|
||||
ScrubPlan int
|
||||
}
|
||||
|
||||
func BuildSnapraidArgs(kind string, cfg SnapraidConfig) ([]string, error) {
|
||||
if cfg.Content == "" {
|
||||
return nil, fmt.Errorf("snapraid content file is required")
|
||||
if cfg.Conf == "" {
|
||||
return nil, fmt.Errorf("snapraid conf file is required")
|
||||
}
|
||||
args := []string{"snapraid", "-c", cfg.Content}
|
||||
args := []string{"snapraid", "-c", cfg.Conf}
|
||||
switch kind {
|
||||
case "snapraid_diff":
|
||||
args = append(args, "diff")
|
||||
@@ -34,16 +34,16 @@ func BuildSnapraidArgs(kind string, cfg SnapraidConfig) ([]string, error) {
|
||||
return args, nil
|
||||
}
|
||||
|
||||
func ValidateSnapraidContent(content string) error {
|
||||
if content == "" {
|
||||
return fmt.Errorf("snapraid content file is required")
|
||||
func ValidateSnapraidConf(conf string) error {
|
||||
if conf == "" {
|
||||
return fmt.Errorf("snapraid conf file is required")
|
||||
}
|
||||
info, err := os.Stat(content)
|
||||
info, err := os.Stat(conf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("snapraid content %s: %w", content, err)
|
||||
return fmt.Errorf("snapraid conf %s: %w", conf, err)
|
||||
}
|
||||
if info.IsDir() {
|
||||
return fmt.Errorf("snapraid content %s: is a directory, not a file", content)
|
||||
return fmt.Errorf("snapraid conf %s: is a directory, not a file", conf)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -10,23 +10,23 @@ func TestBuildSnapraidArgs(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
"snapraid_diff",
|
||||
SnapraidConfig{Content: "/pool/snapraid.content"},
|
||||
[]string{"snapraid", "-c", "/pool/snapraid.content", "diff"},
|
||||
SnapraidConfig{Conf: "/etc/snapraid.conf"},
|
||||
[]string{"snapraid", "-c", "/etc/snapraid.conf", "diff"},
|
||||
},
|
||||
{
|
||||
"snapraid_sync",
|
||||
SnapraidConfig{Content: "/pool/snapraid.content"},
|
||||
[]string{"snapraid", "-c", "/pool/snapraid.content", "sync"},
|
||||
SnapraidConfig{Conf: "/etc/snapraid.conf"},
|
||||
[]string{"snapraid", "-c", "/etc/snapraid.conf", "sync"},
|
||||
},
|
||||
{
|
||||
"snapraid_check",
|
||||
SnapraidConfig{Content: "/pool/snapraid.content"},
|
||||
[]string{"snapraid", "-c", "/pool/snapraid.content", "check"},
|
||||
SnapraidConfig{Conf: "/etc/snapraid.conf"},
|
||||
[]string{"snapraid", "-c", "/etc/snapraid.conf", "check"},
|
||||
},
|
||||
{
|
||||
"snapraid_scrub",
|
||||
SnapraidConfig{Content: "/pool/snapraid.content", ScrubPlan: 8},
|
||||
[]string{"snapraid", "-c", "/pool/snapraid.content", "scrub", "-p", "8"},
|
||||
SnapraidConfig{Conf: "/etc/snapraid.conf", ScrubPlan: 8},
|
||||
[]string{"snapraid", "-c", "/etc/snapraid.conf", "scrub", "-p", "8"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -48,10 +48,10 @@ func TestBuildSnapraidArgs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildSnapraidArgsNoContent(t *testing.T) {
|
||||
_, err := BuildSnapraidArgs("snapraid_sync", SnapraidConfig{Content: ""})
|
||||
func TestBuildSnapraidArgsNoConf(t *testing.T) {
|
||||
_, err := BuildSnapraidArgs("snapraid_sync", SnapraidConfig{Conf: ""})
|
||||
if err == nil {
|
||||
t.Error("expected error for empty content")
|
||||
t.Error("expected error for empty conf")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user