From fc0abf2d9f4fcdff6cd93810e68d472b199b4886 Mon Sep 17 00:00:00 2001 From: Paul Banks Date: Wed, 20 Mar 2024 17:08:33 +0000 Subject: [PATCH] Remove CE-only warning from shared tests (#26052) * Remove CE-only warning from shared tests * Add tests for all warnings emitted during raft config parsing * Unmark warnings as CE only that are universal --- physical/raft/config.go | 2 +- physical/raft/config_test.go | 33 +++++++++++++++++++++++++++- physical/raft/raft_util_stubs_oss.go | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/physical/raft/config.go b/physical/raft/config.go index c765d90c40..fbd0d5038d 100644 --- a/physical/raft/config.go +++ b/physical/raft/config.go @@ -238,7 +238,7 @@ func parseRaftBackendConfig(conf map[string]string, logger log.Logger) (*RaftBac } c.AutopilotRedundancyZone = conf["autopilot_redundancy_zone"] - if c.AutopilotRedundancyZone == "" { + if c.AutopilotRedundancyZone != "" { emitEntWarning(logger, "autopilot_redundancy_zone") } diff --git a/physical/raft/config_test.go b/physical/raft/config_test.go index 3173bf9e7f..37bf84c7bf 100644 --- a/physical/raft/config_test.go +++ b/physical/raft/config_test.go @@ -9,9 +9,17 @@ import ( "time" "github.com/hashicorp/go-hclog" + "github.com/hashicorp/vault/helper/constants" "github.com/stretchr/testify/require" ) +func ceOnlyWarnings(warns ...string) []string { + if !constants.IsEnterprise { + return warns + } + return nil +} + func TestRaft_ParseConfig(t *testing.T) { // Note some of these can be parallel tests but since we need to setEnv in // some we can't make them all parallel so it's don inside the loop. We assume @@ -50,6 +58,7 @@ func TestRaft_ParseConfig(t *testing.T) { cfg.RaftLogVerifierEnabled = true cfg.RaftLogVerificationInterval = defaultRaftLogVerificationInterval }, + wantWarns: []string{"raft_log_verification_interval is less than the minimum allowed"}, }, { name: "WAL verifier interval, one", @@ -63,6 +72,7 @@ func TestRaft_ParseConfig(t *testing.T) { // Below min so should get default cfg.RaftLogVerificationInterval = defaultRaftLogVerificationInterval }, + wantWarns: []string{"raft_log_verification_interval is less than the minimum allowed"}, }, { name: "WAL verifier interval, nothing", @@ -74,6 +84,7 @@ func TestRaft_ParseConfig(t *testing.T) { cfg.RaftLogVerifierEnabled = true cfg.RaftLogVerificationInterval = defaultRaftLogVerificationInterval }, + wantWarns: []string{"raft_log_verification_interval is less than the minimum allowed"}, }, { name: "WAL verifier interval, valid", @@ -104,6 +115,18 @@ func TestRaft_ParseConfig(t *testing.T) { wantErr: "does not parse", }, + // AUTOPILOT Redundancy Zone --------------------------------------------- + { + name: "Autopilot redundancy zone, ok", + conf: map[string]string{ + "autopilot_redundancy_zone": "us-east-1a", + }, + wantMutation: func(cfg *RaftBackendConfig) { + cfg.AutopilotRedundancyZone = "us-east-1a" + }, + wantWarns: ceOnlyWarnings("configuration for a Vault Enterprise feature has been ignored: field=autopilot_redundancy_zone"), + }, + // Non-voter config ------------------------------------------------------ { name: "non-voter, no retry-join, valid false", @@ -113,7 +136,6 @@ func TestRaft_ParseConfig(t *testing.T) { wantMutation: func(cfg *RaftBackendConfig) { // Should be default }, - wantWarns: []string{"is configuration for a Vault Enterprise feature and has been ignored"}, }, { name: "non-voter, retry-join, valid false", @@ -142,6 +164,7 @@ func TestRaft_ParseConfig(t *testing.T) { cfg.RetryJoin = "not-empty" cfg.RaftNonVoter = true }, + wantWarns: ceOnlyWarnings("configuration for a Vault Enterprise feature has been ignored: field=retry_join_as_non_voter"), }, { name: "non-voter, no retry-join, invalid empty", @@ -209,6 +232,7 @@ func TestRaft_ParseConfig(t *testing.T) { cfg.RetryJoin = "not-empty" cfg.RaftNonVoter = true // Any non-empty value is true }, + wantWarns: ceOnlyWarnings("configuration for a Vault Enterprise feature has been ignored: field=retry_join_as_non_voter"), }, { name: "non-voter, no retry-join, valid env true", @@ -229,6 +253,7 @@ func TestRaft_ParseConfig(t *testing.T) { cfg.RetryJoin = "not-empty" cfg.RaftNonVoter = true }, + wantWarns: ceOnlyWarnings("configuration for a Vault Enterprise feature has been ignored: field=retry_join_as_non_voter"), }, { name: "non-voter, no retry-join, valid env not-boolean", @@ -249,6 +274,7 @@ func TestRaft_ParseConfig(t *testing.T) { cfg.RetryJoin = "not-empty" cfg.RaftNonVoter = true }, + wantWarns: ceOnlyWarnings("configuration for a Vault Enterprise feature has been ignored: field=retry_join_as_non_voter"), }, { name: "non-voter, no retry-join, valid env empty", @@ -294,6 +320,7 @@ func TestRaft_ParseConfig(t *testing.T) { cfg.RetryJoin = "not-empty" cfg.RaftNonVoter = true // Env should win }, + wantWarns: ceOnlyWarnings("configuration for a Vault Enterprise feature has been ignored: field=retry_join_as_non_voter"), }, // Entry Size Limits ----------------------------------------------------- @@ -307,6 +334,7 @@ func TestRaft_ParseConfig(t *testing.T) { cfg.MaxEntrySize = 123456 cfg.MaxMountAndNamespaceTableEntrySize = 654321 }, + wantWarns: ceOnlyWarnings("configuration for a Vault Enterprise feature has been ignored: field=max_mount_and_namespace_table_entry_size"), }, { name: "entry size, junk entry size", @@ -394,6 +422,9 @@ func TestRaft_ParseConfig(t *testing.T) { for _, warn := range tc.wantWarns { require.Contains(t, allLogs, warn) } + if len(tc.wantWarns) == 0 { + require.NotContains(t, allLogs, "[WARN]", "no warnings expected") + } }) } } diff --git a/physical/raft/raft_util_stubs_oss.go b/physical/raft/raft_util_stubs_oss.go index a1e578695e..488bc0ba30 100644 --- a/physical/raft/raft_util_stubs_oss.go +++ b/physical/raft/raft_util_stubs_oss.go @@ -14,5 +14,5 @@ func (b *RaftBackend) entrySizeLimitForPath(path string) uint64 { } func emitEntWarning(logger hclog.Logger, field string) { - logger.Warn("%s is configuration for a Vault Enterprise feature and has been ignored.", field) + logger.Warn("configuration for a Vault Enterprise feature has been ignored", "field", field) }