diff --git a/internal/manager/api_impl/varrepl_test.go b/internal/manager/api_impl/varrepl_test.go index 02c0dbfa..de779f63 100644 --- a/internal/manager/api_impl/varrepl_test.go +++ b/internal/manager/api_impl/varrepl_test.go @@ -102,8 +102,8 @@ func TestReplaceJobsVariable(t *testing.T) { // Having the Shaman enabled should create an implicit variable "{jobs}". conf := config.GetTestConfig(func(c *config.Conf) { + c.StoragePath = "/path/to/flamenco-storage" c.Shaman.Enabled = true - c.Shaman.StoragePath = "/path/to/shaman/storage" }) task := varreplTestTask() diff --git a/internal/manager/config/config.go b/internal/manager/config/config.go index 9edd2e78..a5499528 100644 --- a/internal/manager/config/config.go +++ b/internal/manager/config/config.go @@ -76,7 +76,8 @@ type Base struct { SSDPDiscovery bool `yaml:"autodiscoverable"` // Storage configuration: - Shaman shaman_config.Config `yaml:"shaman"` + StoragePath string `yaml:"storage_path"` + Shaman shaman_config.Config `yaml:"shaman"` // TLS certificate management. TLSxxx has priority over ACME. // TLSKey string `yaml:"tlskey"` @@ -233,6 +234,7 @@ func (c *Conf) processAfterLoading(override ...func(c *Conf)) { overrideFunc(c) } + c.processStorage() c.addImplicitVariables() c.ensureVariablesUnique() c.constructVariableLookupTable() @@ -242,20 +244,30 @@ func (c *Conf) processAfterLoading(override ...func(c *Conf)) { c.checkTLS() } +func (c *Conf) processStorage() { + // Shaman should use the Flamenco storage location. + if c.Shaman.Enabled { + c.Shaman.StoragePath = c.StoragePath + } +} + func (c *Conf) addImplicitVariables() { c.implicitVariables = make(map[string]Variable) - if !c.Shaman.Enabled { - return + var jobStorage string + if c.Shaman.Enabled { + jobStorage = c.Shaman.CheckoutPath() + } else { + jobStorage = c.StoragePath } - // Shaman adds a variable to allow job submission to create - // checkout-dir-relative paths. - shamanCheckoutPath := c.Shaman.CheckoutPath() - absPath, err := filepath.Abs(shamanCheckoutPath) + absPath, err := filepath.Abs(jobStorage) if err != nil { - log.Error().Err(err).Msg("unable to find absolute path of Shaman checkout path") - absPath = shamanCheckoutPath + log.Warn(). + Str("storagePath", jobStorage). + Bool("shamanEnabled", c.Shaman.Enabled). + Err(err).Msg("unable to find absolute path of storage path") + absPath = jobStorage } c.implicitVariables["jobs"] = Variable{ IsTwoWay: false, diff --git a/internal/manager/config/defaults.go b/internal/manager/config/defaults.go index 3a9ee971..002c1a58 100644 --- a/internal/manager/config/defaults.go +++ b/internal/manager/config/defaults.go @@ -19,10 +19,10 @@ var defaultConfig = Conf{ DatabaseDSN: "flamenco-manager.sqlite", TaskLogsPath: "./task-logs", SSDPDiscovery: true, + StoragePath: "./flamenco-storage", Shaman: shaman_config.Config{ - Enabled: false, - StoragePath: "./shaman-file-storage", + Enabled: false, GarbageCollect: shaman_config.GarbageCollect{ Period: 24 * time.Hour, MaxAge: 31 * 24 * time.Hour, diff --git a/internal/manager/config/settings_test.go b/internal/manager/config/settings_test.go index 1866e36d..08f634c8 100644 --- a/internal/manager/config/settings_test.go +++ b/internal/manager/config/settings_test.go @@ -41,11 +41,11 @@ func TestVariableValidation(t *testing.T) { // TODO: Test two-way variables. Even though they're not currently in the // default configuration, they should work. -func TestShamanImplicitVariables(t *testing.T) { +func TestStorageImplicitVariablesWithShaman(t *testing.T) { c := DefaultConfig(func(c *Conf) { - // Having the Shaman enabled should create an implicit variable "{jobs}". + // Having the Shaman enabled should create an implicit variable "{jobs}" at the Shaman checkout path. + c.StoragePath = "/path/to/shaman/storage" c.Shaman.Enabled = true - c.Shaman.StoragePath = "/path/to/shaman/storage" c.Variables["jobs"] = Variable{ IsTwoWay: true, @@ -57,7 +57,6 @@ func TestShamanImplicitVariables(t *testing.T) { }, }, } - }) assert.NotContains(t, c.Variables, "jobs", "implicit variables should erase existing variables with the same name") @@ -67,3 +66,29 @@ func TestShamanImplicitVariables(t *testing.T) { assert.False(t, c.implicitVariables["jobs"].IsTwoWay) assert.Equal(t, c.Shaman.CheckoutPath(), c.implicitVariables["jobs"].Values[0].Value) } + +func TestStorageImplicitVariablesWithoutShaman(t *testing.T) { + c := DefaultConfig(func(c *Conf) { + // Having the Shaman disabled should create an implicit variable "{jobs}" at the storage path. + c.StoragePath = "/path/to/shaman/storage" + c.Shaman.Enabled = false + + c.Variables["jobs"] = Variable{ + IsTwoWay: true, + Values: []VariableValue{ + { + Audience: VariableAudienceAll, + Platform: VariablePlatformAll, + Value: "this value should not be seen", + }, + }, + } + }) + + assert.NotContains(t, c.Variables, "jobs", "implicit variables should erase existing variables with the same name") + if !assert.Contains(t, c.implicitVariables, "jobs") { + t.FailNow() + } + assert.False(t, c.implicitVariables["jobs"].IsTwoWay) + assert.Equal(t, c.StoragePath, c.implicitVariables["jobs"].Values[0].Value) +} diff --git a/pkg/shaman/config/config.go b/pkg/shaman/config/config.go index 334cb96a..7c47bffa 100644 --- a/pkg/shaman/config/config.go +++ b/pkg/shaman/config/config.go @@ -45,7 +45,7 @@ type Config struct { TestTempDir string `yaml:"-"` Enabled bool `yaml:"enabled"` - StoragePath string `yaml:"storagePath"` + StoragePath string `yaml:"-"` // Needs to be set externally, not saved in config. GarbageCollect GarbageCollect `yaml:"garbageCollect"` }