Skip to content

Commit

Permalink
Merge 4f8100e into 522d4bc
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovic committed Dec 5, 2018
2 parents 522d4bc + 4f8100e commit 374f1ea
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
21 changes: 21 additions & 0 deletions server/reload.go
Expand Up @@ -637,6 +637,22 @@ func (s *Server) diffOptions(newOpts *Options) ([]option, error) {
diffOpts = append(diffOpts, &clientAdvertiseOption{newValue: cliAdv})
case "accounts":
diffOpts = append(diffOpts, &accountsOption{})
case "gateway":
// Not supported for now, but report warning if configuration of gateway
// is actually changed so that user knows that it won't take effect.

// Any deep-equal is likely to fail for when there is a TLSConfig. so
// remove for the test.
tmpOld := oldValue.(GatewayOpts)
tmpNew := newValue.(GatewayOpts)
tmpOld.TLSConfig = nil
tmpNew.TLSConfig = nil
// If there is really a change prevents reload.
if !reflect.DeepEqual(tmpOld, tmpNew) {
// See TODO(ik) note below about printing old/new values.
return nil, fmt.Errorf("Config reload not supported for %s: old=%v, new=%v",
field.Name, oldValue, newValue)
}
case "nolog", "nosigs":
// Ignore NoLog and NoSigs options since they are not parsed and only used in
// testing.
Expand All @@ -649,6 +665,11 @@ func (s *Server) diffOptions(newOpts *Options) ([]option, error) {
}
fallthrough
default:
// TODO(ik): Implement String() on those options to have a nice print.
// %v is difficult to figure what's what, %+v print private fields and
// would print passwords. Tried json.Marshal but it is too verbose for
// the URL array.

// Bail out if attempting to reload any unsupported options.
return nil, fmt.Errorf("Config reload not supported for %s: old=%v, new=%v",
field.Name, oldValue, newValue)
Expand Down
19 changes: 15 additions & 4 deletions server/reload_test.go
Expand Up @@ -3186,8 +3186,6 @@ func TestConfigReloadAccountServicesImportExport(t *testing.T) {
// As of now, config reload does not support changes for gateways.
// However, ensure that if a gateway is defined, one can still
// do reload as long as we don't change the gateway spec.
// There was an issue with the initialization of default TLS timeout
// that caused the reload to fail.
func TestConfigReloadNotPreventedByGateways(t *testing.T) {
confTemplate := `
listen: "127.0.0.1:-1"
Expand All @@ -3198,14 +3196,27 @@ func TestConfigReloadNotPreventedByGateways(t *testing.T) {
tls {
cert_file: "configs/certs/server.pem"
key_file: "configs/certs/key.pem"
timeout: %s
}
gateways [
{
name: "B"
url: "nats://localhost:8888"
}
]
}
`
conf := createConfFile(t, []byte(fmt.Sprintf(confTemplate, "")))
conf := createConfFile(t, []byte(fmt.Sprintf(confTemplate, "", "5")))
defer os.Remove(conf)
s, _ := RunServerWithConfig(conf)
defer s.Shutdown()

// Cause reload with adding a param that is supported
reloadUpdateConfig(t, s, conf, fmt.Sprintf(confTemplate, "max_payload: 100000"))
reloadUpdateConfig(t, s, conf, fmt.Sprintf(confTemplate, "max_payload: 100000", "5"))

// Now update gateway, should fail to reload.
changeCurrentConfigContentWithNewContent(t, conf, []byte(fmt.Sprintf(confTemplate, "max_payload: 100000", "3")))
if err := s.Reload(); err == nil || !strings.Contains(err.Error(), "not supported for Gateway") {
t.Fatalf("Expected Reload to return a not supported error, got %v", err)
}
}

0 comments on commit 374f1ea

Please sign in to comment.