From 2b62f2f172f5bd2c7fb727f4ab0dff3c0ad8d185 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Mon, 4 May 2015 17:36:17 -0700 Subject: [PATCH] agent: use an additional parameter for passing tokens --- command/agent/agent.go | 30 +++++++------- command/agent/agent_endpoint.go | 6 +-- command/agent/agent_endpoint_test.go | 18 ++++----- command/agent/agent_test.go | 60 +++++++++++++--------------- command/agent/local.go | 42 +++---------------- command/agent/local_test.go | 42 +++++++++---------- command/agent/user_event_test.go | 4 +- command/maint_test.go | 6 +-- 8 files changed, 84 insertions(+), 124 deletions(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index ea646d5888..e59b1edd46 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -155,7 +155,7 @@ func Create(config *Config, logOutput io.Writer) (*Agent, error) { Port: agent.config.Ports.Server, Tags: []string{}, } - agent.state.AddService(&consulService) + agent.state.AddService(&consulService, "") } else { err = agent.setupClient() agent.state.SetIface(agent.client) @@ -599,7 +599,7 @@ func (a *Agent) purgeCheck(checkID string) error { // AddService is used to add a service entry. // This entry is persistent and the agent will make a best effort to // ensure it is registered -func (a *Agent) AddService(service *structs.NodeService, chkTypes CheckTypes, persist bool) error { +func (a *Agent) AddService(service *structs.NodeService, chkTypes CheckTypes, persist bool, token string) error { if service.Service == "" { return fmt.Errorf("Service name missing") } @@ -629,7 +629,7 @@ func (a *Agent) AddService(service *structs.NodeService, chkTypes CheckTypes, pe } // Add the service - a.state.AddService(service) + a.state.AddService(service, token) // Persist the service to a file if persist { @@ -653,7 +653,7 @@ func (a *Agent) AddService(service *structs.NodeService, chkTypes CheckTypes, pe ServiceID: service.ID, ServiceName: service.Service, } - if err := a.AddCheck(check, chkType, persist); err != nil { + if err := a.AddCheck(check, chkType, persist, token); err != nil { return err } } @@ -704,7 +704,7 @@ func (a *Agent) RemoveService(serviceID string, persist bool) error { // This entry is persistent and the agent will make a best effort to // ensure it is registered. The Check may include a CheckType which // is used to automatically update the check status -func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *CheckType, persist bool) error { +func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *CheckType, persist bool, token string) error { if check.CheckID == "" { return fmt.Errorf("CheckID missing") } @@ -783,7 +783,7 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *CheckType, persist } // Add to the local state for anti-entropy - a.state.AddCheck(check) + a.state.AddCheck(check, token) // Persist the check if persist { @@ -928,8 +928,7 @@ func (a *Agent) loadServices(conf *Config) error { for _, service := range conf.Services { ns := service.NodeService() chkTypes := service.CheckTypes() - a.state.SetServiceToken(service.ID, service.Token) - if err := a.AddService(ns, chkTypes, false); err != nil { + if err := a.AddService(ns, chkTypes, false, service.Token); err != nil { return fmt.Errorf("Failed to register service '%s': %v", service.ID, err) } } @@ -958,6 +957,7 @@ func (a *Agent) loadServices(conf *Config) error { } var wrapped *persistedService + var token string var svc *structs.NodeService if err := json.Unmarshal(content, &wrapped); err != nil { // Backwards-compatibility for pre-0.5.1 persisted services @@ -966,7 +966,7 @@ func (a *Agent) loadServices(conf *Config) error { } } else { svc = wrapped.Service - a.state.SetServiceToken(svc.ID, wrapped.Token) + token = wrapped.Token } if _, ok := a.state.services[svc.ID]; ok { @@ -978,7 +978,7 @@ func (a *Agent) loadServices(conf *Config) error { } else { a.logger.Printf("[DEBUG] agent: restored service definition %q from %q", svc.ID, filePath) - return a.AddService(svc, nil, false) + return a.AddService(svc, nil, false, token) } }) @@ -1007,8 +1007,7 @@ func (a *Agent) loadChecks(conf *Config) error { for _, check := range conf.Checks { health := check.HealthCheck(conf.NodeName) chkType := &check.CheckType - a.state.SetCheckToken(check.ID, check.Token) - if err := a.AddCheck(health, chkType, false); err != nil { + if err := a.AddCheck(health, chkType, false, check.Token); err != nil { return fmt.Errorf("Failed to register check '%s': %v %v", check.Name, err, check) } } @@ -1040,7 +1039,6 @@ func (a *Agent) loadChecks(conf *Config) error { if err := json.Unmarshal(content, &p); err != nil { return err } - a.state.SetCheckToken(p.Check.CheckID, p.Token) if _, ok := a.state.checks[p.Check.CheckID]; ok { // Purge previously persisted check. This allows config to be @@ -1053,7 +1051,7 @@ func (a *Agent) loadChecks(conf *Config) error { // services into the active pool p.Check.Status = structs.HealthCritical - if err := a.AddCheck(p.Check, p.ChkType, false); err != nil { + if err := a.AddCheck(p.Check, p.ChkType, false, p.Token); err != nil { // Purge the check if it is unable to be restored. a.logger.Printf("[WARN] agent: Failed to restore check %q: %s", p.Check.CheckID, err) @@ -1130,7 +1128,7 @@ func (a *Agent) EnableServiceMaintenance(serviceID, reason string) error { ServiceName: service.Service, Status: structs.HealthCritical, } - a.AddCheck(check, nil, true) + a.AddCheck(check, nil, true, "") a.logger.Printf("[INFO] agent: Service %q entered maintenance mode", serviceID) return nil @@ -1176,7 +1174,7 @@ func (a *Agent) EnableNodeMaintenance(reason string) { Notes: reason, Status: structs.HealthCritical, } - a.AddCheck(check, nil, true) + a.AddCheck(check, nil, true, "") a.logger.Printf("[INFO] agent: Node entered maintenance mode") } diff --git a/command/agent/agent_endpoint.go b/command/agent/agent_endpoint.go index 201b684c69..18a8556205 100644 --- a/command/agent/agent_endpoint.go +++ b/command/agent/agent_endpoint.go @@ -100,10 +100,9 @@ func (s *HTTPServer) AgentRegisterCheck(resp http.ResponseWriter, req *http.Requ // Get the provided token, if any var token string s.parseToken(req, &token) - s.agent.state.SetCheckToken(health.CheckID, token) // Add the check - if err := s.agent.AddCheck(health, chkType, true); err != nil { + if err := s.agent.AddCheck(health, chkType, true, token); err != nil { return nil, err } s.syncChanges() @@ -207,10 +206,9 @@ func (s *HTTPServer) AgentRegisterService(resp http.ResponseWriter, req *http.Re // Get the provided token, if any var token string s.parseToken(req, &token) - s.agent.state.SetServiceToken(ns.ID, token) // Add the check - if err := s.agent.AddService(ns, chkTypes, true); err != nil { + if err := s.agent.AddService(ns, chkTypes, true, token); err != nil { return nil, err } s.syncChanges() diff --git a/command/agent/agent_endpoint_test.go b/command/agent/agent_endpoint_test.go index 5c95c1a3e7..78469f774a 100644 --- a/command/agent/agent_endpoint_test.go +++ b/command/agent/agent_endpoint_test.go @@ -25,7 +25,7 @@ func TestHTTPAgentServices(t *testing.T) { Tags: []string{"master"}, Port: 5000, } - srv.agent.state.AddService(srv1) + srv.agent.state.AddService(srv1, "") obj, err := srv.AgentServices(nil, nil) if err != nil { @@ -52,7 +52,7 @@ func TestHTTPAgentChecks(t *testing.T) { Name: "mysql", Status: structs.HealthPassing, } - srv.agent.state.AddCheck(chk1) + srv.agent.state.AddCheck(chk1, "") obj, err := srv.AgentChecks(nil, nil) if err != nil { @@ -294,7 +294,7 @@ func TestHTTPAgentDeregisterCheck(t *testing.T) { defer srv.agent.Shutdown() chk := &structs.HealthCheck{Name: "test", CheckID: "test"} - if err := srv.agent.AddCheck(chk, nil, false); err != nil { + if err := srv.agent.AddCheck(chk, nil, false, ""); err != nil { t.Fatalf("err: %v", err) } @@ -326,7 +326,7 @@ func TestHTTPAgentPassCheck(t *testing.T) { chk := &structs.HealthCheck{Name: "test", CheckID: "test"} chkType := &CheckType{TTL: 15 * time.Second} - if err := srv.agent.AddCheck(chk, chkType, false); err != nil { + if err := srv.agent.AddCheck(chk, chkType, false, ""); err != nil { t.Fatalf("err: %v", err) } @@ -359,7 +359,7 @@ func TestHTTPAgentWarnCheck(t *testing.T) { chk := &structs.HealthCheck{Name: "test", CheckID: "test"} chkType := &CheckType{TTL: 15 * time.Second} - if err := srv.agent.AddCheck(chk, chkType, false); err != nil { + if err := srv.agent.AddCheck(chk, chkType, false, ""); err != nil { t.Fatalf("err: %v", err) } @@ -392,7 +392,7 @@ func TestHTTPAgentFailCheck(t *testing.T) { chk := &structs.HealthCheck{Name: "test", CheckID: "test"} chkType := &CheckType{TTL: 15 * time.Second} - if err := srv.agent.AddCheck(chk, chkType, false); err != nil { + if err := srv.agent.AddCheck(chk, chkType, false, ""); err != nil { t.Fatalf("err: %v", err) } @@ -485,7 +485,7 @@ func TestHTTPAgentDeregisterService(t *testing.T) { ID: "test", Service: "test", } - if err := srv.agent.AddService(service, nil, false); err != nil { + if err := srv.agent.AddService(service, nil, false, ""); err != nil { t.Fatalf("err: %v", err) } @@ -571,7 +571,7 @@ func TestHTTPAgent_EnableServiceMaintenance(t *testing.T) { ID: "test", Service: "test", } - if err := srv.agent.AddService(service, nil, false); err != nil { + if err := srv.agent.AddService(service, nil, false, ""); err != nil { t.Fatalf("err: %v", err) } @@ -609,7 +609,7 @@ func TestHTTPAgent_DisableServiceMaintenance(t *testing.T) { ID: "test", Service: "test", } - if err := srv.agent.AddService(service, nil, false); err != nil { + if err := srv.agent.AddService(service, nil, false, ""); err != nil { t.Fatalf("err: %v", err) } diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index 8caea85cab..1a2aed3a1b 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -153,7 +153,7 @@ func TestAgent_AddService(t *testing.T) { Notes: "redis heath check 2", }, } - err := agent.AddService(srv, chkTypes, false) + err := agent.AddService(srv, chkTypes, false, "") if err != nil { t.Fatalf("err: %v", err) } @@ -197,7 +197,7 @@ func TestAgent_AddService(t *testing.T) { Notes: "memcache heath check 2", }, } - if err := agent.AddService(srv, chkTypes, false); err != nil { + if err := agent.AddService(srv, chkTypes, false, ""); err != nil { t.Fatalf("err: %v", err) } @@ -261,7 +261,7 @@ func TestAgent_RemoveService(t *testing.T) { } chkTypes := CheckTypes{&CheckType{TTL: time.Minute}} - if err := agent.AddService(srv, chkTypes, false); err != nil { + if err := agent.AddService(srv, chkTypes, false, ""); err != nil { t.Fatalf("err: %v", err) } @@ -284,7 +284,7 @@ func TestAgent_RemoveService(t *testing.T) { &CheckType{TTL: time.Minute}, &CheckType{TTL: 30 * time.Second}, } - if err := agent.AddService(srv, chkTypes, false); err != nil { + if err := agent.AddService(srv, chkTypes, false, ""); err != nil { t.Fatalf("err: %v", err) } @@ -331,7 +331,7 @@ func TestAgent_AddCheck(t *testing.T) { Script: "exit 0", Interval: 15 * time.Second, } - err := agent.AddCheck(health, chk, false) + err := agent.AddCheck(health, chk, false, "") if err != nil { t.Fatalf("err: %v", err) } @@ -362,7 +362,7 @@ func TestAgent_AddCheck_MinInterval(t *testing.T) { Script: "exit 0", Interval: time.Microsecond, } - err := agent.AddCheck(health, chk, false) + err := agent.AddCheck(health, chk, false, "") if err != nil { t.Fatalf("err: %v", err) } @@ -395,7 +395,7 @@ func TestAgent_AddCheck_MissingService(t *testing.T) { Script: "exit 0", Interval: time.Microsecond, } - err := agent.AddCheck(health, chk, false) + err := agent.AddCheck(health, chk, false, "") if err == nil || err.Error() != `ServiceID "baz" does not exist` { t.Fatalf("expected service id error, got: %v", err) } @@ -426,7 +426,7 @@ func TestAgent_RemoveCheck(t *testing.T) { Script: "exit 0", Interval: 15 * time.Second, } - err := agent.AddCheck(health, chk, false) + err := agent.AddCheck(health, chk, false, "") if err != nil { t.Fatalf("err: %v", err) } @@ -461,7 +461,7 @@ func TestAgent_UpdateCheck(t *testing.T) { chk := &CheckType{ TTL: 15 * time.Second, } - err := agent.AddCheck(health, chk, false) + err := agent.AddCheck(health, chk, false, "") if err != nil { t.Fatalf("err: %v", err) } @@ -521,11 +521,8 @@ func TestAgent_PersistService(t *testing.T) { file := filepath.Join(agent.config.DataDir, servicesDir, stringHash(svc.ID)) - // Configure a service token - agent.state.SetServiceToken(svc.ID, "hello") - // Check is not persisted unless requested - if err := agent.AddService(svc, nil, false); err != nil { + if err := agent.AddService(svc, nil, false, ""); err != nil { t.Fatalf("err: %v", err) } if _, err := os.Stat(file); err == nil { @@ -533,7 +530,7 @@ func TestAgent_PersistService(t *testing.T) { } // Persists to file if requested - if err := agent.AddService(svc, nil, true); err != nil { + if err := agent.AddService(svc, nil, true, "mytoken"); err != nil { t.Fatalf("err: %v", err) } @@ -542,7 +539,7 @@ func TestAgent_PersistService(t *testing.T) { } expected, err := json.Marshal(persistedService{ - Token: "hello", + Token: "mytoken", Service: svc, }) if err != nil { @@ -567,7 +564,7 @@ func TestAgent_PersistService(t *testing.T) { if _, ok := agent2.state.services[svc.ID]; !ok { t.Fatalf("bad: %#v", agent2.state.services) } - if agent2.state.serviceTokens[svc.ID] != "hello" { + if agent2.state.serviceTokens[svc.ID] != "mytoken" { t.Fatalf("bad: %#v", agent2.state.services[svc.ID]) } } @@ -632,7 +629,7 @@ func TestAgent_PurgeService(t *testing.T) { } file := filepath.Join(agent.config.DataDir, servicesDir, stringHash(svc.ID)) - if err := agent.AddService(svc, nil, true); err != nil { + if err := agent.AddService(svc, nil, true, ""); err != nil { t.Fatalf("err: %v", err) } @@ -668,7 +665,7 @@ func TestAgent_PurgeServiceOnDuplicate(t *testing.T) { } // First persist the service - if err := agent.AddService(svc1, nil, true); err != nil { + if err := agent.AddService(svc1, nil, true, ""); err != nil { t.Fatalf("err: %v", err) } agent.Shutdown() @@ -722,11 +719,8 @@ func TestAgent_PersistCheck(t *testing.T) { file := filepath.Join(agent.config.DataDir, checksDir, stringHash(check.CheckID)) - // Configure a service registration token - agent.state.SetCheckToken(check.CheckID, "hello") - // Not persisted if not requested - if err := agent.AddCheck(check, chkType, false); err != nil { + if err := agent.AddCheck(check, chkType, false, ""); err != nil { t.Fatalf("err: %v", err) } if _, err := os.Stat(file); err == nil { @@ -734,7 +728,7 @@ func TestAgent_PersistCheck(t *testing.T) { } // Should persist if requested - if err := agent.AddCheck(check, chkType, true); err != nil { + if err := agent.AddCheck(check, chkType, true, "mytoken"); err != nil { t.Fatalf("err: %v", err) } @@ -745,7 +739,7 @@ func TestAgent_PersistCheck(t *testing.T) { expected, err := json.Marshal(persistedCheck{ Check: check, ChkType: chkType, - Token: "hello", + Token: "mytoken", }) if err != nil { t.Fatalf("err: %s", err) @@ -778,7 +772,7 @@ func TestAgent_PersistCheck(t *testing.T) { if _, ok := agent2.checkMonitors[check.CheckID]; !ok { t.Fatalf("bad: %#v", agent2.checkMonitors) } - if agent2.state.checkTokens[check.CheckID] != "hello" { + if agent2.state.checkTokens[check.CheckID] != "mytoken" { t.Fatalf("bad: %s", agent2.state.checkTokens[check.CheckID]) } } @@ -797,7 +791,7 @@ func TestAgent_PurgeCheck(t *testing.T) { } file := filepath.Join(agent.config.DataDir, checksDir, stringHash(check.CheckID)) - if err := agent.AddCheck(check, nil, true); err != nil { + if err := agent.AddCheck(check, nil, true, ""); err != nil { t.Fatalf("err: %v", err) } @@ -833,7 +827,7 @@ func TestAgent_PurgeCheckOnDuplicate(t *testing.T) { } // First persist the check - if err := agent.AddCheck(check1, nil, true); err != nil { + if err := agent.AddCheck(check1, nil, true, ""); err != nil { t.Fatalf("err: %v", err) } agent.Shutdown() @@ -906,7 +900,7 @@ func TestAgent_unloadChecks(t *testing.T) { Tags: []string{"foo"}, Port: 8000, } - if err := agent.AddService(svc, nil, false); err != nil { + if err := agent.AddService(svc, nil, false, ""); err != nil { t.Fatalf("err: %v", err) } @@ -919,7 +913,7 @@ func TestAgent_unloadChecks(t *testing.T) { ServiceID: "redis", ServiceName: "redis", } - if err := agent.AddCheck(check1, nil, false); err != nil { + if err := agent.AddCheck(check1, nil, false, ""); err != nil { t.Fatalf("err: %s", err) } found := false @@ -981,7 +975,7 @@ func TestAgent_unloadServices(t *testing.T) { } // Register the service - if err := agent.AddService(svc, nil, false); err != nil { + if err := agent.AddService(svc, nil, false, ""); err != nil { t.Fatalf("err: %v", err) } found := false @@ -1029,7 +1023,7 @@ func TestAgent_ServiceMaintenanceMode(t *testing.T) { } // Register the service - if err := agent.AddService(svc, nil, false); err != nil { + if err := agent.AddService(svc, nil, false, ""); err != nil { t.Fatalf("err: %v", err) } @@ -1129,7 +1123,7 @@ func TestAgent_checkStateSnapshot(t *testing.T) { Tags: []string{"foo"}, Port: 8000, } - if err := agent.AddService(svc, nil, false); err != nil { + if err := agent.AddService(svc, nil, false, ""); err != nil { t.Fatalf("err: %v", err) } @@ -1142,7 +1136,7 @@ func TestAgent_checkStateSnapshot(t *testing.T) { ServiceID: "redis", ServiceName: "redis", } - if err := agent.AddCheck(check1, nil, true); err != nil { + if err := agent.AddCheck(check1, nil, true, ""); err != nil { t.Fatalf("err: %s", err) } diff --git a/command/agent/local.go b/command/agent/local.go index 83fefbf885..f864457706 100644 --- a/command/agent/local.go +++ b/command/agent/local.go @@ -123,23 +123,6 @@ func (l *localState) isPaused() bool { return atomic.LoadInt32(&l.paused) == 1 } -// SetServiceToken configures the provided token for the service ID. -// The token will be used to perform service registration operations. -func (l *localState) SetServiceToken(id, token string) { - if token != "" { - l.Lock() - defer l.Unlock() - l.serviceTokens[id] = token - } -} - -// RemoveServiceToken is used to remove a configured service token. -func (l *localState) RemoveServiceToken(id string) { - l.Lock() - defer l.Unlock() - delete(l.serviceTokens, id) -} - // ServiceToken returns the configured ACL token for the given // service ID. If none is present, the agent's token is returned. func (l *localState) ServiceToken(id string) string { @@ -160,7 +143,7 @@ func (l *localState) serviceToken(id string) string { // AddService is used to add a service entry to the local state. // This entry is persistent and the agent will make a best effort to // ensure it is registered -func (l *localState) AddService(service *structs.NodeService) { +func (l *localState) AddService(service *structs.NodeService, token string) { // Assign the ID if none given if service.ID == "" && service.Service != "" { service.ID = service.Service @@ -171,6 +154,7 @@ func (l *localState) AddService(service *structs.NodeService) { l.services[service.ID] = service l.serviceStatus[service.ID] = syncStatus{} + l.serviceTokens[service.ID] = token l.changeMade() } @@ -181,6 +165,7 @@ func (l *localState) RemoveService(serviceID string) { defer l.Unlock() delete(l.services, serviceID) + delete(l.serviceTokens, serviceID) l.serviceStatus[serviceID] = syncStatus{remoteDelete: true} l.changeMade() } @@ -198,23 +183,6 @@ func (l *localState) Services() map[string]*structs.NodeService { return services } -// SetCheckToken is used to configure an ACL token for a specific -// health check. The token is used during check registration operations. -func (l *localState) SetCheckToken(id, token string) { - if token != "" { - l.Lock() - defer l.Unlock() - l.checkTokens[id] = token - } -} - -// RemoveCheckToken is used to remove a configured check token. -func (l *localState) RemoveCheckToken(id string) { - l.Lock() - defer l.Unlock() - delete(l.checkTokens, id) -} - // CheckToken is used to return the configured health check token, or // if none is configured, the default agent ACL token. func (l *localState) CheckToken(id string) string { @@ -235,7 +203,7 @@ func (l *localState) checkToken(id string) string { // AddCheck is used to add a health check to the local state. // This entry is persistent and the agent will make a best effort to // ensure it is registered -func (l *localState) AddCheck(check *structs.HealthCheck) { +func (l *localState) AddCheck(check *structs.HealthCheck, token string) { // Set the node name check.Node = l.config.NodeName @@ -244,6 +212,7 @@ func (l *localState) AddCheck(check *structs.HealthCheck) { l.checks[check.CheckID] = check l.checkStatus[check.CheckID] = syncStatus{} + l.checkTokens[check.CheckID] = token l.changeMade() } @@ -254,6 +223,7 @@ func (l *localState) RemoveCheck(checkID string) { defer l.Unlock() delete(l.checks, checkID) + delete(l.checkTokens, checkID) l.checkStatus[checkID] = syncStatus{remoteDelete: true} l.changeMade() } diff --git a/command/agent/local_test.go b/command/agent/local_test.go index 84c7c2d26a..113bbe36e9 100644 --- a/command/agent/local_test.go +++ b/command/agent/local_test.go @@ -34,7 +34,7 @@ func TestAgentAntiEntropy_Services(t *testing.T) { Tags: []string{"master"}, Port: 5000, } - agent.state.AddService(srv1) + agent.state.AddService(srv1, "") args.Service = srv1 if err := agent.RPC("Catalog.Register", args, &out); err != nil { t.Fatalf("err: %v", err) @@ -47,7 +47,7 @@ func TestAgentAntiEntropy_Services(t *testing.T) { Tags: []string{}, Port: 8000, } - agent.state.AddService(srv2) + agent.state.AddService(srv2, "") srv2_mod := new(structs.NodeService) *srv2_mod = *srv2 @@ -64,7 +64,7 @@ func TestAgentAntiEntropy_Services(t *testing.T) { Tags: []string{}, Port: 80, } - agent.state.AddService(srv3) + agent.state.AddService(srv3, "") // Exists remote (delete) srv4 := &structs.NodeService{ @@ -86,7 +86,7 @@ func TestAgentAntiEntropy_Services(t *testing.T) { Address: "127.0.0.10", Port: 8000, } - agent.state.AddService(srv5) + agent.state.AddService(srv5, "") // Exists local, in sync, remote missing (create) srv6 := &structs.NodeService{ @@ -95,7 +95,7 @@ func TestAgentAntiEntropy_Services(t *testing.T) { Tags: []string{}, Port: 11211, } - agent.state.AddService(srv6) + agent.state.AddService(srv6, "") agent.state.serviceStatus["cache"] = syncStatus{inSync: true} srv5_mod := new(structs.NodeService) @@ -185,7 +185,7 @@ func TestAgentAntiEntropy_Services_WithChecks(t *testing.T) { Tags: []string{"master"}, Port: 5000, } - agent.state.AddService(srv) + agent.state.AddService(srv, "") chk := &structs.HealthCheck{ Node: agent.config.NodeName, @@ -194,7 +194,7 @@ func TestAgentAntiEntropy_Services_WithChecks(t *testing.T) { ServiceID: "mysql", Status: structs.HealthPassing, } - agent.state.AddCheck(chk) + agent.state.AddCheck(chk, "") // Sync the service once if err := agent.state.syncService("mysql"); err != nil { @@ -236,7 +236,7 @@ func TestAgentAntiEntropy_Services_WithChecks(t *testing.T) { Tags: []string{"master"}, Port: 5000, } - agent.state.AddService(srv) + agent.state.AddService(srv, "") chk1 := &structs.HealthCheck{ Node: agent.config.NodeName, @@ -245,7 +245,7 @@ func TestAgentAntiEntropy_Services_WithChecks(t *testing.T) { ServiceID: "redis", Status: structs.HealthPassing, } - agent.state.AddCheck(chk1) + agent.state.AddCheck(chk1, "") chk2 := &structs.HealthCheck{ Node: agent.config.NodeName, @@ -254,7 +254,7 @@ func TestAgentAntiEntropy_Services_WithChecks(t *testing.T) { ServiceID: "redis", Status: structs.HealthPassing, } - agent.state.AddCheck(chk2) + agent.state.AddCheck(chk2, "") // Sync the service once if err := agent.state.syncService("redis"); err != nil { @@ -326,7 +326,7 @@ func TestAgentAntiEntropy_Services_ACLDeny(t *testing.T) { Tags: []string{"master"}, Port: 5000, } - agent.state.AddService(srv1) + agent.state.AddService(srv1, "") // Create service (Disallowed) srv2 := &structs.NodeService{ @@ -335,7 +335,7 @@ func TestAgentAntiEntropy_Services_ACLDeny(t *testing.T) { Tags: []string{"foo"}, Port: 5001, } - agent.state.AddService(srv2) + agent.state.AddService(srv2, "") // Trigger anti-entropy run and wait agent.StartSync() @@ -409,7 +409,7 @@ func TestAgentAntiEntropy_Checks(t *testing.T) { Name: "mysql", Status: structs.HealthPassing, } - agent.state.AddCheck(chk1) + agent.state.AddCheck(chk1, "") args.Check = chk1 if err := agent.RPC("Catalog.Register", args, &out); err != nil { t.Fatalf("err: %v", err) @@ -422,7 +422,7 @@ func TestAgentAntiEntropy_Checks(t *testing.T) { Name: "redis", Status: structs.HealthPassing, } - agent.state.AddCheck(chk2) + agent.state.AddCheck(chk2, "") chk2_mod := new(structs.HealthCheck) *chk2_mod = *chk2 @@ -439,7 +439,7 @@ func TestAgentAntiEntropy_Checks(t *testing.T) { Name: "web", Status: structs.HealthPassing, } - agent.state.AddCheck(chk3) + agent.state.AddCheck(chk3, "") // Exists remote (delete) chk4 := &structs.HealthCheck{ @@ -460,7 +460,7 @@ func TestAgentAntiEntropy_Checks(t *testing.T) { Name: "cache", Status: structs.HealthPassing, } - agent.state.AddCheck(chk5) + agent.state.AddCheck(chk5, "") agent.state.checkStatus["cache"] = syncStatus{inSync: true} // Trigger anti-entropy run and wait @@ -539,7 +539,7 @@ func TestAgentAntiEntropy_Check_DeferSync(t *testing.T) { Status: structs.HealthPassing, Output: "", } - agent.state.AddCheck(check) + agent.state.AddCheck(check, "") // Trigger anti-entropy run and wait agent.StartSync() @@ -627,13 +627,13 @@ func TestAgent_serviceTokens(t *testing.T) { } // Returns configured token - l.SetServiceToken("redis", "abc123") + l.serviceTokens["redis"] = "abc123" if token := l.ServiceToken("redis"); token != "abc123" { t.Fatalf("bad: %s", token) } // Removes token - l.RemoveServiceToken("redis") + l.RemoveService("redis") if token := l.ServiceToken("redis"); token != "default" { t.Fatalf("bad: %s", token) } @@ -651,13 +651,13 @@ func TestAgent_checkTokens(t *testing.T) { } // Returns configured token - l.SetCheckToken("mem", "abc123") + l.checkTokens["mem"] = "abc123" if token := l.CheckToken("mem"); token != "abc123" { t.Fatalf("bad: %s", token) } // Removes token - l.RemoveCheckToken("mem") + l.RemoveCheck("mem") if token := l.CheckToken("mem"); token != "default" { t.Fatalf("bad: %s", token) } diff --git a/command/agent/user_event_test.go b/command/agent/user_event_test.go index e3aa8f3810..336bf04943 100644 --- a/command/agent/user_event_test.go +++ b/command/agent/user_event_test.go @@ -57,7 +57,7 @@ func TestShouldProcessUserEvent(t *testing.T) { Tags: []string{"test", "foo", "bar", "master"}, Port: 5000, } - agent.state.AddService(srv1) + agent.state.AddService(srv1, "") p := &UserEvent{} if !agent.shouldProcessUserEvent(p) { @@ -159,7 +159,7 @@ func TestFireReceiveEvent(t *testing.T) { Tags: []string{"test", "foo", "bar", "master"}, Port: 5000, } - agent.state.AddService(srv1) + agent.state.AddService(srv1, "") p1 := &UserEvent{Name: "deploy", ServiceFilter: "web"} err := agent.UserEvent("", p1) diff --git a/command/maint_test.go b/command/maint_test.go index 92bf02b767..2793051306 100644 --- a/command/maint_test.go +++ b/command/maint_test.go @@ -42,7 +42,7 @@ func TestMaintCommandRun_NoArgs(t *testing.T) { ID: "test", Service: "test", } - if err := a1.agent.AddService(service, nil, false); err != nil { + if err := a1.agent.AddService(service, nil, false, ""); err != nil { t.Fatalf("err: %v", err) } if err := a1.agent.EnableServiceMaintenance("test", "broken 1"); err != nil { @@ -132,7 +132,7 @@ func TestMaintCommandRun_EnableServiceMaintenance(t *testing.T) { ID: "test", Service: "test", } - if err := a1.agent.AddService(service, nil, false); err != nil { + if err := a1.agent.AddService(service, nil, false, ""); err != nil { t.Fatalf("err: %v", err) } @@ -164,7 +164,7 @@ func TestMaintCommandRun_DisableServiceMaintenance(t *testing.T) { ID: "test", Service: "test", } - if err := a1.agent.AddService(service, nil, false); err != nil { + if err := a1.agent.AddService(service, nil, false, ""); err != nil { t.Fatalf("err: %v", err) }