From ee25ff3292bf84e546302d22330bb48cf22e9850 Mon Sep 17 00:00:00 2001 From: Prajakta Purohit Date: Thu, 4 Feb 2021 06:00:27 -0800 Subject: [PATCH 1/2] Set data_collector to true only if external automate or local automate is enabled. Co-authored-by: Jay Mundrawala Signed-off-by: Prajakta Purohit --- api/config/erchef/config_request.go | 10 ++++++++ api/config/erchef/config_request_test.go | 31 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/api/config/erchef/config_request.go b/api/config/erchef/config_request.go index b9022ae3980..36ce628613b 100644 --- a/api/config/erchef/config_request.go +++ b/api/config/erchef/config_request.go @@ -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. @@ -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) + } + } +} diff --git a/api/config/erchef/config_request_test.go b/api/config/erchef/config_request_test.go index 7bb0ed5fd61..bd73fb90fb3 100644 --- a/api/config/erchef/config_request_test.go +++ b/api/config/erchef/config_request_test.go @@ -3,7 +3,11 @@ 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) { @@ -11,3 +15,30 @@ func TestValidateConfigRequestValid(t *testing.T) { 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()) + }) +} From 2d38d16289986fdf1e5a0feae4982fc77aee66b7 Mon Sep 17 00:00:00 2001 From: Jay Mundrawala Date: Fri, 5 Feb 2021 14:25:11 -0600 Subject: [PATCH 2/2] Remove explicit datacollector config from test Signed-off-by: Jay Mundrawala --- integration/tests/chef_server_only.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/integration/tests/chef_server_only.sh b/integration/tests/chef_server_only.sh index 777d9fd36b6..9e4fbcb809f 100644 --- a/integration/tests/chef_server_only.sh +++ b/integration/tests/chef_server_only.sh @@ -16,12 +16,6 @@ source .studio/chef-server-collection do_create_config() { do_create_config_default - - #shellcheck disable=SC2154 - cat <> "$test_config_path" -[erchef.v1.sys.data_collector] -enabled = false -EOF } do_deploy() {