Manager: unify Flamenco and Shaman storage paths

Flamenco Manager now has a "storage path" config option, which will be
used by Shaman if enabled. Now the `{jobs}` implicit variable will always
exist, its value depending on whether Shaman is enabled or not.
This commit is contained in:
Sybren A. Stüvel 2022-04-01 13:43:51 +02:00
parent f61522f396
commit e70dad2177
5 changed files with 54 additions and 17 deletions

View File

@ -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()

View File

@ -76,6 +76,7 @@ type Base struct {
SSDPDiscovery bool `yaml:"autodiscoverable"`
// Storage configuration:
StoragePath string `yaml:"storage_path"`
Shaman shaman_config.Config `yaml:"shaman"`
// TLS certificate management. TLSxxx has priority over ACME.
@ -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,

View File

@ -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",
GarbageCollect: shaman_config.GarbageCollect{
Period: 24 * time.Hour,
MaxAge: 31 * 24 * time.Hour,

View File

@ -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)
}

View File

@ -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"`
}