Skip to content

Commit

Permalink
Set data_collector to true only if external automate or local automat…
Browse files Browse the repository at this point in the history
…e is enabled. (#4683)

Currently chef-server will not come up if automate is disabled in the dev vm.

This happens because data-collector is set to true(enable) by default. This change makes it such that data-collector will be enabled only if external or internal automate are enabled.

Co-authored-by: Jay Mundrawala <[email protected]>
Signed-off-by: Prajakta Purohit <[email protected]>
  • Loading branch information
PrajaktaPurohit and Jay Mundrawala authored Feb 8, 2021
1 parent dc80d3b commit bc59cdf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
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

0 comments on commit bc59cdf

Please sign in to comment.