From c5b2895b0b5166da84073c0841f89f158eb38e8b Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Fri, 17 Jul 2020 11:02:00 -0400 Subject: [PATCH 1/6] Fix pro tags --- api/namespace_test.go | 2 +- api/sentinel_test.go | 2 +- command/namespace_apply_test.go | 2 +- command/namespace_delete_test.go | 2 +- command/namespace_list_test.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/api/namespace_test.go b/api/namespace_test.go index d58d1adb8..a5fac0310 100644 --- a/api/namespace_test.go +++ b/api/namespace_test.go @@ -1,4 +1,4 @@ -// +build pro ent +// +build ent package api diff --git a/api/sentinel_test.go b/api/sentinel_test.go index 32fc2a6f9..0eebd62f9 100644 --- a/api/sentinel_test.go +++ b/api/sentinel_test.go @@ -1,4 +1,4 @@ -// +build pro ent +// +build ent package api diff --git a/command/namespace_apply_test.go b/command/namespace_apply_test.go index a8d683065..5aebff376 100644 --- a/command/namespace_apply_test.go +++ b/command/namespace_apply_test.go @@ -1,4 +1,4 @@ -// +build pro ent +// +build ent package command diff --git a/command/namespace_delete_test.go b/command/namespace_delete_test.go index 6205904dd..f8fe99ef3 100644 --- a/command/namespace_delete_test.go +++ b/command/namespace_delete_test.go @@ -1,4 +1,4 @@ -// +build pro ent +// +build ent package command diff --git a/command/namespace_list_test.go b/command/namespace_list_test.go index f2a11701f..2c74ff0f1 100644 --- a/command/namespace_list_test.go +++ b/command/namespace_list_test.go @@ -1,4 +1,4 @@ -// +build pro ent +// +build ent package command From c7828c1f7cdef0af9977635bf96b40d86c7d8217 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Fri, 17 Jul 2020 11:04:57 -0400 Subject: [PATCH 2/6] Set AgentShutdown --- command/agent/agent.go | 1 + nomad/config.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/command/agent/agent.go b/command/agent/agent.go index 1e381b4fb..4c1a700c9 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -430,6 +430,7 @@ func (a *Agent) finalizeServerConfig(c *nomad.Config) { // Setup the plugin loaders c.PluginLoader = a.pluginLoader c.PluginSingletonLoader = a.pluginSingletonLoader + c.AgentShutdown = func() error { return a.Shutdown() } } // clientConfig is used to generate a new client configuration struct for diff --git a/nomad/config.go b/nomad/config.go index ea3d71ba2..2e25e0471 100644 --- a/nomad/config.go +++ b/nomad/config.go @@ -351,6 +351,10 @@ type Config struct { // LicenseConfig is a tunable knob for enterprise license testing. LicenseConfig *LicenseConfig + + // AgentShutdown is used to call agent.Shutdown from the context of a Server + // It is used primarily for licensing + AgentShutdown func() error } // CheckVersion is used to check if the ProtocolVersion is valid From 32910ae0ba5b4e1679c8429c17479069c01e2fb2 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Fri, 17 Jul 2020 11:05:57 -0400 Subject: [PATCH 3/6] Refactor setupLoggers --- command/agent/command.go | 42 +++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/command/agent/command.go b/command/agent/command.go index 771fc326b..b394ca99f 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -385,35 +385,35 @@ func (c *Command) isValidConfig(config, cmdConfig *Config) bool { } // setupLoggers is used to setup the logGate, and our logOutput -func (c *Command) setupLoggers(config *Config) (*gatedwriter.Writer, io.Writer) { +func SetupLoggers(ui cli.Ui, config *Config) (*logutils.LevelFilter, *gatedwriter.Writer, io.Writer) { // Setup logging. First create the gated log writer, which will // store logs until we're ready to show them. Then create the level // filter, filtering logs of the specified level. logGate := &gatedwriter.Writer{ - Writer: &cli.UiWriter{Ui: c.Ui}, + Writer: &cli.UiWriter{Ui: ui}, } - c.logFilter = LevelFilter() - c.logFilter.MinLevel = logutils.LogLevel(strings.ToUpper(config.LogLevel)) - c.logFilter.Writer = logGate - if !ValidateLevelFilter(c.logFilter.MinLevel, c.logFilter) { - c.Ui.Error(fmt.Sprintf( + logFilter := LevelFilter() + logFilter.MinLevel = logutils.LogLevel(strings.ToUpper(config.LogLevel)) + logFilter.Writer = logGate + if !ValidateLevelFilter(logFilter.MinLevel, logFilter) { + ui.Error(fmt.Sprintf( "Invalid log level: %s. Valid log levels are: %v", - c.logFilter.MinLevel, c.logFilter.Levels)) - return nil, nil + logFilter.MinLevel, logFilter.Levels)) + return nil, nil, nil } // Create a log writer, and wrap a logOutput around it - writers := []io.Writer{c.logFilter} + writers := []io.Writer{logFilter} // Check if syslog is enabled if config.EnableSyslog { l, err := gsyslog.NewLogger(gsyslog.LOG_NOTICE, config.SyslogFacility, "nomad") if err != nil { - c.Ui.Error(fmt.Sprintf("Syslog setup failed: %v", err)) - return nil, nil + ui.Error(fmt.Sprintf("Syslog setup failed: %v", err)) + return nil, nil, nil } - writers = append(writers, &SyslogWrapper{l, c.logFilter}) + writers = append(writers, &SyslogWrapper{l, logFilter}) } // Check if file logging is enabled @@ -430,8 +430,8 @@ func (c *Command) setupLoggers(config *Config) (*gatedwriter.Writer, io.Writer) if config.LogRotateDuration != "" { duration, err := time.ParseDuration(config.LogRotateDuration) if err != nil { - c.Ui.Error(fmt.Sprintf("Failed to parse log rotation duration: %v", err)) - return nil, nil + ui.Error(fmt.Sprintf("Failed to parse log rotation duration: %v", err)) + return nil, nil, nil } logRotateDuration = duration } else { @@ -440,7 +440,7 @@ func (c *Command) setupLoggers(config *Config) (*gatedwriter.Writer, io.Writer) } logFile := &logFile{ - logFilter: c.logFilter, + logFilter: logFilter, fileName: fileName, logPath: dir, duration: logRotateDuration, @@ -451,9 +451,9 @@ func (c *Command) setupLoggers(config *Config) (*gatedwriter.Writer, io.Writer) writers = append(writers, logFile) } - c.logOutput = io.MultiWriter(writers...) - log.SetOutput(c.logOutput) - return logGate, c.logOutput + logOutput := io.MultiWriter(writers...) + log.SetOutput(logOutput) + return logFilter, logGate, logOutput } // setupAgent is used to start the agent and various interfaces @@ -607,7 +607,9 @@ func (c *Command) Run(args []string) int { } // Setup the log outputs - logGate, logOutput := c.setupLoggers(config) + logFilter, logGate, logOutput := SetupLoggers(c.Ui, config) + c.logFilter = logFilter + c.logOutput = logOutput if logGate == nil { return 1 } From 040cc8f5af12f117e39f604579941b4994cde4d2 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Mon, 20 Jul 2020 09:22:26 -0400 Subject: [PATCH 4/6] enterprise specific state store objects --- nomad/state/state_store.go | 6 ++++++ nomad/state/state_store_oss.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index eb57f3814..273ef3de4 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -80,6 +80,12 @@ func NewStateStore(config *StateStoreConfig) (*StateStore, error) { config: config, abandonCh: make(chan struct{}), } + + // Initialize the state store with required enterprise objects + if err := s.enterpriseInit(); err != nil { + return nil, fmt.Errorf("enterprise state store initialization failed: %v", err) + } + return s, nil } diff --git a/nomad/state/state_store_oss.go b/nomad/state/state_store_oss.go index cf6841e0d..3ef4e600b 100644 --- a/nomad/state/state_store_oss.go +++ b/nomad/state/state_store_oss.go @@ -7,6 +7,12 @@ import ( "github.com/hashicorp/nomad/nomad/structs" ) +// enterpriseInit is used to initialize the state store with enterprise +// objects. +func (s *StateStore) enterpriseInit() error { + return nil +} + // namespaceExists returns whether a namespace exists func (s *StateStore) namespaceExists(txn *memdb.Txn, namespace string) (bool, error) { return namespace == structs.DefaultNamespace, nil From 68bd10c22df233d3e95e2326fc0d76636e4a4382 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Mon, 20 Jul 2020 09:25:09 -0400 Subject: [PATCH 5/6] minor tweaks from Ent --- command/license_get_test.go | 1 - nomad/client_agent_endpoint_test.go | 3 --- nomad/operator_endpoint.go | 1 + 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/command/license_get_test.go b/command/license_get_test.go index 1fb8e08b3..c35132594 100644 --- a/command/license_get_test.go +++ b/command/license_get_test.go @@ -21,7 +21,6 @@ func TestCommand_LicenseGet_OSSErr(t *testing.T) { code := cmd.Run([]string{"-address=" + url}) if srv.Enterprise { require.Equal(t, 0, code) - require.Contains(t, ui.OutputWriter.String(), "License Status = valid") } else { require.Equal(t, 1, code) require.Contains(t, ui.ErrorWriter.String(), "Nomad Enterprise only endpoint") diff --git a/nomad/client_agent_endpoint_test.go b/nomad/client_agent_endpoint_test.go index 499a05949..0c48f76e8 100644 --- a/nomad/client_agent_endpoint_test.go +++ b/nomad/client_agent_endpoint_test.go @@ -573,7 +573,6 @@ func TestAgentProfile_RemoteClient(t *testing.T) { // Test that we prevent a forwarding loop if the requested // serverID does not exist in the requested region func TestAgentProfile_RemoteRegionMisMatch(t *testing.T) { - t.Parallel() require := require.New(t) // start server and client @@ -611,7 +610,6 @@ func TestAgentProfile_RemoteRegionMisMatch(t *testing.T) { // Test that Agent.Profile can forward to a different region func TestAgentProfile_RemoteRegion(t *testing.T) { - t.Parallel() require := require.New(t) // start server and client @@ -649,7 +647,6 @@ func TestAgentProfile_RemoteRegion(t *testing.T) { } func TestAgentProfile_Server(t *testing.T) { - t.Parallel() // start servers s1, cleanup := TestServer(t, func(c *Config) { diff --git a/nomad/operator_endpoint.go b/nomad/operator_endpoint.go index fe42bbc91..aab11c539 100644 --- a/nomad/operator_endpoint.go +++ b/nomad/operator_endpoint.go @@ -319,6 +319,7 @@ func (op *Operator) SchedulerSetConfiguration(args *structs.SchedulerSetConfigRe if !ServersMeetMinimumVersion(op.srv.Members(), minSchedulerConfigVersion, false) { return fmt.Errorf("All servers should be running version %v to update scheduler config", minSchedulerConfigVersion) } + // Apply the update resp, index, err := op.srv.raftApply(structs.SchedulerConfigRequestType, args) if err != nil { From c9e51fb255b120a9b9fae72add93c8967a8a91db Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Mon, 20 Jul 2020 09:55:55 -0400 Subject: [PATCH 6/6] Remove unused state.TestInitState --- nomad/fsm_test.go | 1 - nomad/server_setup_oss.go | 1 - nomad/state/testing.go | 1 - nomad/state/testing_oss.go | 9 --------- 4 files changed, 12 deletions(-) delete mode 100644 nomad/state/testing_oss.go diff --git a/nomad/fsm_test.go b/nomad/fsm_test.go index 6179d0720..e371b5d2a 100644 --- a/nomad/fsm_test.go +++ b/nomad/fsm_test.go @@ -63,7 +63,6 @@ func testFSM(t *testing.T) *nomadFSM { if fsm == nil { t.Fatalf("missing fsm") } - state.TestInitState(t, fsm.state) return fsm } diff --git a/nomad/server_setup_oss.go b/nomad/server_setup_oss.go index 4825a961e..267638d01 100644 --- a/nomad/server_setup_oss.go +++ b/nomad/server_setup_oss.go @@ -23,5 +23,4 @@ func (s *Server) setupEnterprise(config *Config) error { return nil } - func (s *Server) startEnterpriseBackground() {} diff --git a/nomad/state/testing.go b/nomad/state/testing.go index 78e31766b..353c8de1d 100644 --- a/nomad/state/testing.go +++ b/nomad/state/testing.go @@ -21,7 +21,6 @@ func TestStateStore(t testing.T) *StateStore { if state == nil { t.Fatalf("missing state") } - TestInitState(t, state) return state } diff --git a/nomad/state/testing_oss.go b/nomad/state/testing_oss.go deleted file mode 100644 index 178e78a39..000000000 --- a/nomad/state/testing_oss.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build !ent - -package state - -import ( - testing "github.com/mitchellh/go-testing-interface" -) - -func TestInitState(t testing.T, state *StateStore) {}