Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCTRL-930 disable empty aggregator roles + mocked configuration source #620

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions apricot/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,26 @@ func newService(configUri string) (configuration.Service, error) {
svc, err = cacheproxy.NewService(svc)
}
return svc, err
case "mock":
svc, err = local.NewService(configUri)
if err != nil {
return svc, err
}
return svc, err
default:
return nil, fmt.Errorf("invalid configuration URI scheme %s", parsedUri.Scheme)
}
}

func Instance() configuration.Service {
once.Do(func() {
var(
err error
var (
err error
configUri string
)
if viper.IsSet("config_endpoint") { //coconut
configUri = viper.GetString("config_endpoint")
} else if viper.IsSet("configServiceUri"){ //core
} else if viper.IsSet("configServiceUri") { //core
configUri = viper.GetString("configServiceUri")
} else { //apricot
configUri = viper.GetString("backendUri")
Expand All @@ -118,4 +124,3 @@ func Instance() configuration.Service {
})
return instance
}

68 changes: 68 additions & 0 deletions configuration/cfgbackend/mocksource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* === This file is part of ALICE O² ===
*
* Copyright 2018 CERN and copyright holders of ALICE O².
* Author: Teo Mrnjavac <teo.mrnjavac@cern.ch>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In applying this license CERN does not waive the privileges and
* immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
*/

package cfgbackend

// MockSource is a minimal mock implementation of the Source interface
type MockSource struct{}

func NewMockSource() (*MockSource, error) {
return &MockSource{}, nil
}

func (m *MockSource) Get(key string) (string, error) {
return "", nil
}

func (m *MockSource) GetKeysByPrefix(prefix string) ([]string, error) {
return []string{}, nil
}

func (m *MockSource) GetRecursive(key string) (Item, error) {
return make(Map), nil
}

func (m *MockSource) GetRecursiveYaml(key string) ([]byte, error) {
return []byte{}, nil
}

func (m *MockSource) Exists(key string) (bool, error) {
return false, nil
}

func (m *MockSource) IsDir(key string) bool {
return false
}

func (m *MockSource) Put(key, value string) error {
return nil
}

func (m *MockSource) PutRecursive(key string, item Item) error {
return nil
}

func (m *MockSource) PutRecursiveYaml(key string, data []byte) error {
return nil
}
3 changes: 3 additions & 0 deletions configuration/cfgbackend/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func NewSource(uri string) (configuration Source, err error) {
(strings.HasSuffix(uri, ".yaml") || strings.HasSuffix(uri, ".json")) {
configuration, err = newYamlSource(uri)
return
} else if strings.HasPrefix(uri, "mock://") {
configuration, err = NewMockSource()
return
}

err = errors.New("bad URI for configuration source")
Expand Down
34 changes: 1 addition & 33 deletions core/environment/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,19 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/spf13/viper"
"io"
"os"
"testing"
)

const envTestConfig = "environment_test.yaml"

var tmpDir *string

var _ = BeforeSuite(func() {
var err error
tmpDir = new(string)
*tmpDir, err = os.MkdirTemp("", "o2control-core-environment")
Expect(err).NotTo(HaveOccurred())

// copy config files
configFiles := []string{envTestConfig}
for _, configFile := range configFiles {
from, err := os.Open("./" + configFile)
Expect(err).NotTo(HaveOccurred())
defer from.Close()

to, err := os.OpenFile(*tmpDir+"/"+configFile, os.O_RDWR|os.O_CREATE, 0666)
Expect(err).NotTo(HaveOccurred())
defer to.Close()

_, err = io.Copy(to, from)
Expect(err).NotTo(HaveOccurred())
}

viper.Set("coreWorkingDir", tmpDir) // used by NewRunNumber with YAML backend

integration.Reset()
integration.RegisterPlugin("testplugin", "testPluginEndpoint", testplugin.NewPlugin)
viper.Reset()
viper.Set("integrationPlugins", []string{"testplugin"})
viper.Set("testPluginEndpoint", "http://example.com")
viper.Set("config_endpoint", "file://"+*tmpDir+"/"+envTestConfig)
viper.Set("config_endpoint", "mock://")
})

func TestCoreEnvironment(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Core Environment Test Suite")
}

var _ = AfterSuite(func() {
os.RemoveAll(*tmpDir)
})
13 changes: 0 additions & 13 deletions core/environment/environment_test.yaml

This file was deleted.

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
Loading