mirror of https://github.com/status-im/consul.git
Merge pull request #4294 from hashicorp/bugfix/4249-gen-ext-node-id
Catalog Register: Generate UUID for services registered without one
This commit is contained in:
commit
d94747db2d
|
@ -37,6 +37,13 @@ func (c *Catalog) Register(args *structs.RegisterRequest, reply *struct{}) error
|
|||
if _, err := uuid.ParseUUID(string(args.ID)); err != nil {
|
||||
return fmt.Errorf("Bad node ID: %v", err)
|
||||
}
|
||||
} else {
|
||||
id, err := uuid.GenerateUUID()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to generate ID: %v", err)
|
||||
}
|
||||
|
||||
args.ID = types.NodeID(id)
|
||||
}
|
||||
|
||||
// Fetch the ACL token, if any.
|
||||
|
|
|
@ -50,6 +50,37 @@ func TestCatalog_Register(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCatalog_RegisterNoID(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir1, s1 := testServer(t)
|
||||
defer os.RemoveAll(dir1)
|
||||
defer s1.Shutdown()
|
||||
codec := rpcClient(t, s1)
|
||||
defer codec.Close()
|
||||
|
||||
arg := structs.RegisterRequest{
|
||||
Datacenter: "dc1",
|
||||
Node: "foo",
|
||||
Address: "127.0.0.1",
|
||||
Service: &structs.NodeService{
|
||||
Service: "db",
|
||||
Tags: []string{"master"},
|
||||
Port: 8000,
|
||||
},
|
||||
}
|
||||
var out struct{}
|
||||
|
||||
require.NoError(t, msgpackrpc.CallWithCodec(codec, "Catalog.Register", &arg, &out))
|
||||
|
||||
var ns structs.IndexedNodeServices
|
||||
nodeArgs := structs.NodeSpecificRequest{
|
||||
Datacenter: "dc1",
|
||||
Node: "foo",
|
||||
}
|
||||
require.NoError(t, msgpackrpc.CallWithCodec(codec, "Catalog.NodeServices", &nodeArgs, &ns))
|
||||
require.NotEqual(t, types.NodeID(""), ns.NodeServices.Node.ID)
|
||||
}
|
||||
|
||||
func TestCatalog_RegisterService_InvalidAddress(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir1, s1 := testServer(t)
|
||||
|
|
|
@ -134,7 +134,7 @@ func NewClientLogger(config *Config, logger *log.Logger) (*Client, error) {
|
|||
shutdownCh: make(chan struct{}),
|
||||
}
|
||||
|
||||
c.rpcLimiter.Store(rate.NewLimiter(config.RPCRate, config.RPCMaxBurst))
|
||||
c.rpcLimiter.Store(rate.NewLimiter(config.RPCRate, config.RPCMaxBurst))
|
||||
|
||||
if err := c.initEnterprise(); err != nil {
|
||||
c.Shutdown()
|
||||
|
|
Loading…
Reference in New Issue