Skip to content

Commit

Permalink
[core] disable empty aggregator roles
Browse files Browse the repository at this point in the history
...to avoid failed environment deployments due to missing status update
  • Loading branch information
knopers8 committed Oct 4, 2024
1 parent 5f2ef41 commit 41dfe21
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/workflow/aggregatorrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ func (r *aggregatorRole) ProcessTemplates(workflowRepo repos.IRepo, loadSubworkf
}
r.Roles = enabledRoles

// If there are no roles in the aggregator role, it has no use and should be disabled
if len(r.Roles) == 0 {
r.Enabled = "false"
}

return
}

Expand Down
72 changes: 72 additions & 0 deletions core/workflow/aggregatorrole_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package workflow

import (
"github.com/AliceO2Group/Control/core/repos"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("aggregator role", func() {
var _ = Describe("processing templates", func() {
var root Role
var repo repos.Repo
var configStack map[string]string

BeforeEach(func() {
_, repo, _ = repos.NewRepo("/home/user/git/ControlWorkflows", "", "/var/lib/o2/aliecs/repos")
configStack = make(map[string]string)
})

When("an aggregator role is empty", func() {
BeforeEach(func() {
root = &aggregatorRole{
roleBase{Name: "root", Enabled: "true"},
aggregator{Roles: []Role{}},
}
})
It("should disable itself", func() {
Expect(root.IsEnabled()).To(BeTrue())
err := root.ProcessTemplates(&repo, nil, configStack)
Expect(err).NotTo(HaveOccurred())
Expect(root.IsEnabled()).To(BeFalse())
})
})

When("an aggregator role has only disabled sub-roles", func() {
BeforeEach(func() {
root = &aggregatorRole{
roleBase{Name: "root", Enabled: "true"},
aggregator{
Roles: []Role{&taskRole{roleBase: roleBase{Name: "task1", Enabled: "false"}}},
},
}
})
It("remove the disabled roles and disable itself", func() {
Expect(root.IsEnabled()).To(BeTrue())
err := root.ProcessTemplates(&repo, nil, configStack)
Expect(err).NotTo(HaveOccurred())
Expect(root.IsEnabled()).To(BeFalse())
Expect(root.GetRoles()).Should(BeEmpty())
})
})

When("an aggregator role has an enabled role", func() {
BeforeEach(func() {
root = &aggregatorRole{
roleBase{Name: "root", Enabled: "true"},
aggregator{
Roles: []Role{&taskRole{roleBase: roleBase{Name: "task1", Enabled: "true"}}},
},
}
})
It("should be enabled", func() {
Expect(root.IsEnabled()).To(BeTrue())
err := root.ProcessTemplates(&repo, nil, configStack)
Expect(err).NotTo(HaveOccurred())
Expect(root.IsEnabled()).To(BeTrue())
Expect(root.GetRoles()).ShouldNot(BeEmpty())
})
})
})

})
5 changes: 5 additions & 0 deletions core/workflow/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ package workflow
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/spf13/viper"
"testing"
)

var _ = BeforeSuite(func() {
viper.Set("config_endpoint", "mock://")
})

func TestCoreWorkflow(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Core Workflow Test Suite")
Expand Down

0 comments on commit 41dfe21

Please sign in to comment.