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:
parent
f61522f396
commit
e70dad2177
@ -102,8 +102,8 @@ func TestReplaceJobsVariable(t *testing.T) {
|
|||||||
|
|
||||||
// Having the Shaman enabled should create an implicit variable "{jobs}".
|
// Having the Shaman enabled should create an implicit variable "{jobs}".
|
||||||
conf := config.GetTestConfig(func(c *config.Conf) {
|
conf := config.GetTestConfig(func(c *config.Conf) {
|
||||||
|
c.StoragePath = "/path/to/flamenco-storage"
|
||||||
c.Shaman.Enabled = true
|
c.Shaman.Enabled = true
|
||||||
c.Shaman.StoragePath = "/path/to/shaman/storage"
|
|
||||||
})
|
})
|
||||||
|
|
||||||
task := varreplTestTask()
|
task := varreplTestTask()
|
||||||
|
@ -76,6 +76,7 @@ type Base struct {
|
|||||||
SSDPDiscovery bool `yaml:"autodiscoverable"`
|
SSDPDiscovery bool `yaml:"autodiscoverable"`
|
||||||
|
|
||||||
// Storage configuration:
|
// Storage configuration:
|
||||||
|
StoragePath string `yaml:"storage_path"`
|
||||||
Shaman shaman_config.Config `yaml:"shaman"`
|
Shaman shaman_config.Config `yaml:"shaman"`
|
||||||
|
|
||||||
// TLS certificate management. TLSxxx has priority over ACME.
|
// TLS certificate management. TLSxxx has priority over ACME.
|
||||||
@ -233,6 +234,7 @@ func (c *Conf) processAfterLoading(override ...func(c *Conf)) {
|
|||||||
overrideFunc(c)
|
overrideFunc(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.processStorage()
|
||||||
c.addImplicitVariables()
|
c.addImplicitVariables()
|
||||||
c.ensureVariablesUnique()
|
c.ensureVariablesUnique()
|
||||||
c.constructVariableLookupTable()
|
c.constructVariableLookupTable()
|
||||||
@ -242,20 +244,30 @@ func (c *Conf) processAfterLoading(override ...func(c *Conf)) {
|
|||||||
c.checkTLS()
|
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() {
|
func (c *Conf) addImplicitVariables() {
|
||||||
c.implicitVariables = make(map[string]Variable)
|
c.implicitVariables = make(map[string]Variable)
|
||||||
|
|
||||||
if !c.Shaman.Enabled {
|
var jobStorage string
|
||||||
return
|
if c.Shaman.Enabled {
|
||||||
|
jobStorage = c.Shaman.CheckoutPath()
|
||||||
|
} else {
|
||||||
|
jobStorage = c.StoragePath
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shaman adds a variable to allow job submission to create
|
absPath, err := filepath.Abs(jobStorage)
|
||||||
// checkout-dir-relative paths.
|
|
||||||
shamanCheckoutPath := c.Shaman.CheckoutPath()
|
|
||||||
absPath, err := filepath.Abs(shamanCheckoutPath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("unable to find absolute path of Shaman checkout path")
|
log.Warn().
|
||||||
absPath = shamanCheckoutPath
|
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{
|
c.implicitVariables["jobs"] = Variable{
|
||||||
IsTwoWay: false,
|
IsTwoWay: false,
|
||||||
|
@ -19,10 +19,10 @@ var defaultConfig = Conf{
|
|||||||
DatabaseDSN: "flamenco-manager.sqlite",
|
DatabaseDSN: "flamenco-manager.sqlite",
|
||||||
TaskLogsPath: "./task-logs",
|
TaskLogsPath: "./task-logs",
|
||||||
SSDPDiscovery: true,
|
SSDPDiscovery: true,
|
||||||
|
StoragePath: "./flamenco-storage",
|
||||||
|
|
||||||
Shaman: shaman_config.Config{
|
Shaman: shaman_config.Config{
|
||||||
Enabled: false,
|
Enabled: false,
|
||||||
StoragePath: "./shaman-file-storage",
|
|
||||||
GarbageCollect: shaman_config.GarbageCollect{
|
GarbageCollect: shaman_config.GarbageCollect{
|
||||||
Period: 24 * time.Hour,
|
Period: 24 * time.Hour,
|
||||||
MaxAge: 31 * 24 * time.Hour,
|
MaxAge: 31 * 24 * time.Hour,
|
||||||
|
@ -41,11 +41,11 @@ func TestVariableValidation(t *testing.T) {
|
|||||||
// TODO: Test two-way variables. Even though they're not currently in the
|
// TODO: Test two-way variables. Even though they're not currently in the
|
||||||
// default configuration, they should work.
|
// default configuration, they should work.
|
||||||
|
|
||||||
func TestShamanImplicitVariables(t *testing.T) {
|
func TestStorageImplicitVariablesWithShaman(t *testing.T) {
|
||||||
c := DefaultConfig(func(c *Conf) {
|
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.Enabled = true
|
||||||
c.Shaman.StoragePath = "/path/to/shaman/storage"
|
|
||||||
|
|
||||||
c.Variables["jobs"] = Variable{
|
c.Variables["jobs"] = Variable{
|
||||||
IsTwoWay: true,
|
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")
|
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.False(t, c.implicitVariables["jobs"].IsTwoWay)
|
||||||
assert.Equal(t, c.Shaman.CheckoutPath(), c.implicitVariables["jobs"].Values[0].Value)
|
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)
|
||||||
|
}
|
||||||
|
@ -45,7 +45,7 @@ type Config struct {
|
|||||||
TestTempDir string `yaml:"-"`
|
TestTempDir string `yaml:"-"`
|
||||||
|
|
||||||
Enabled bool `yaml:"enabled"`
|
Enabled bool `yaml:"enabled"`
|
||||||
StoragePath string `yaml:"storagePath"`
|
StoragePath string `yaml:"-"` // Needs to be set externally, not saved in config.
|
||||||
GarbageCollect GarbageCollect `yaml:"garbageCollect"`
|
GarbageCollect GarbageCollect `yaml:"garbageCollect"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user