mirror of https://github.com/docker/docs.git
Node: Refuse to connect to unsupported Docker engine versions.
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
f9f83aae1f
commit
496377d998
|
@ -106,6 +106,11 @@ func (n *Node) updateSpecs() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Older versions of Docker don't expose the ID field and are not supported
|
||||
// by Swarm. Catch the error ASAP and refuse to connect.
|
||||
if len(info.ID) == 0 {
|
||||
return fmt.Errorf("Node %s is running an unsupported version of Docker Engine. Please upgrade.", n.Addr)
|
||||
}
|
||||
n.ID = info.ID
|
||||
n.Name = info.Name
|
||||
n.Cpus = info.NCPU
|
||||
|
@ -333,7 +338,7 @@ func (n *Node) Pull(image string) error {
|
|||
// Register an event handler.
|
||||
func (n *Node) Events(h EventHandler) error {
|
||||
if n.eventHandler != nil {
|
||||
return fmt.Errorf("event handler already set")
|
||||
return errors.New("event handler already set")
|
||||
}
|
||||
n.eventHandler = h
|
||||
return nil
|
||||
|
|
|
@ -12,6 +12,8 @@ import (
|
|||
|
||||
var (
|
||||
mockInfo = &dockerclient.Info{
|
||||
ID: "id",
|
||||
Name: "name",
|
||||
NCPU: 10,
|
||||
MemTotal: 20,
|
||||
Driver: "driver-test",
|
||||
|
@ -36,6 +38,17 @@ func TestNodeConnectionFailure(t *testing.T) {
|
|||
client.Mock.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestOutdatedNode(t *testing.T) {
|
||||
node := NewNode("test")
|
||||
client := dockerclient.NewMockClient()
|
||||
client.On("Info").Return(&dockerclient.Info{}, nil)
|
||||
|
||||
assert.Error(t, node.connectClient(client))
|
||||
assert.False(t, node.IsConnected())
|
||||
|
||||
client.Mock.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestNodeSpecs(t *testing.T) {
|
||||
node := NewNode("test")
|
||||
assert.False(t, node.IsConnected())
|
||||
|
|
Loading…
Reference in New Issue