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

Set data_collector to true only if external automate or local automate is enabled. #4683

Merged
merged 2 commits into from
Feb 8, 2021
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
10 changes: 10 additions & 0 deletions api/config/erchef/config_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"strings"

ac "github.com/chef/automate/api/config/shared"
config "github.com/chef/automate/api/config/shared"
w "github.com/chef/automate/api/config/shared/wrappers"
"github.com/chef/automate/lib/stringutils"
)

// NewConfigRequest returns a new instance of ConfigRequest with zero values.
Expand Down Expand Up @@ -144,3 +146,11 @@ func (c *ConfigRequest) PrepareSystemConfig(creds *ac.TLSCredentials) (ac.Prepar

return c.V1.Sys, nil
}

func (c *ConfigRequest) ConfigureProduct(productConfig *config.ProductConfig) {
if len(productConfig.Products) > 0 {
if !c.V1.Sys.GetExternalAutomate().GetEnable().GetValue() && !stringutils.SliceContains(productConfig.Products, "automate") {
c.V1.Sys.DataCollector.Enabled = w.Bool(false)
}
}
}
31 changes: 31 additions & 0 deletions api/config/erchef/config_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,42 @@ package erchef
import (
"testing"

"github.com/chef/automate/api/config/shared"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

w "github.com/chef/automate/api/config/shared/wrappers"
)

func TestValidateConfigRequestValid(t *testing.T) {
c := NewConfigRequest()
err := c.Validate()
assert.Nil(t, err)
}

func TestDataCollector(t *testing.T) {
t.Run("enabled when External Automate is enabled and Internal Automate is disabled", func(t *testing.T) {
c := DefaultConfigRequest()
c.V1.Sys.ExternalAutomate = &shared.External_Automate{
Enable: w.Bool(true),
}
c.ConfigureProduct(&shared.ProductConfig{
Products: []string{"chef-server"},
})
require.True(t, c.V1.Sys.GetDataCollector().GetEnabled().GetValue())
})
t.Run("enabled when External Automate is disabled and Internal Automate is enabled", func(t *testing.T) {
c := DefaultConfigRequest()
c.ConfigureProduct(&shared.ProductConfig{
Products: []string{"automate", "chef-server"},
})
require.True(t, c.V1.Sys.GetDataCollector().GetEnabled().GetValue())
})
t.Run("disabled when External Automate is disabled and Internal Automate is disabled", func(t *testing.T) {
c := DefaultConfigRequest()
c.ConfigureProduct(&shared.ProductConfig{
Products: []string{"chef-server"},
})
require.False(t, c.V1.Sys.GetDataCollector().GetEnabled().GetValue())
})
}
6 changes: 0 additions & 6 deletions integration/tests/chef_server_only.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ source .studio/chef-server-collection

do_create_config() {
do_create_config_default

#shellcheck disable=SC2154
cat <<EOF >> "$test_config_path"
[erchef.v1.sys.data_collector]
enabled = false
EOF
}

do_deploy() {
Expand Down