support only 1.6.0+

update test/regression/run.sh
uddate doc
update tests

Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
Victor Vieux 2015-06-11 13:31:47 -07:00
parent 19b0ddcf4d
commit 1afc1be2d1
8 changed files with 133 additions and 9 deletions

5
Godeps/Godeps.json generated
View File

@ -55,6 +55,11 @@
"Comment": "v1.4.1-3245-g443437f",
"Rev": "443437f5ea04da9d62bf3e05d7951f7d30e77d96"
},
{
"ImportPath": "github.com/docker/docker/pkg/version",
"Comment": "v1.4.1-3245-g443437f",
"Rev": "443437f5ea04da9d62bf3e05d7951f7d30e77d96"
},
{
"ImportPath": "github.com/gogo/protobuf/proto",
"Rev": "bc946d07d1016848dfd2507f90f0859c9471681e"

View File

@ -0,0 +1,63 @@
package version
import (
"strconv"
"strings"
)
// Version provides utility methods for comparing versions.
type Version string
func (v Version) compareTo(other Version) int {
var (
currTab = strings.Split(string(v), ".")
otherTab = strings.Split(string(other), ".")
)
max := len(currTab)
if len(otherTab) > max {
max = len(otherTab)
}
for i := 0; i < max; i++ {
var currInt, otherInt int
if len(currTab) > i {
currInt, _ = strconv.Atoi(currTab[i])
}
if len(otherTab) > i {
otherInt, _ = strconv.Atoi(otherTab[i])
}
if currInt > otherInt {
return 1
}
if otherInt > currInt {
return -1
}
}
return 0
}
// LessThan checks if a version is less than another
func (v Version) LessThan(other Version) bool {
return v.compareTo(other) == -1
}
// LessThanOrEqualTo checks if a version is less than or equal to another
func (v Version) LessThanOrEqualTo(other Version) bool {
return v.compareTo(other) <= 0
}
// GreaterThan checks if a version is greater than another
func (v Version) GreaterThan(other Version) bool {
return v.compareTo(other) == 1
}
// GreaterThanOrEqualTo checks if a version is greater than or equal to another
func (v Version) GreaterThanOrEqualTo(other Version) bool {
return v.compareTo(other) >= 0
}
// Equal checks if a version is equal to another
func (v Version) Equal(other Version) bool {
return v.compareTo(other) == 0
}

View File

@ -0,0 +1,27 @@
package version
import (
"testing"
)
func assertVersion(t *testing.T, a, b string, result int) {
if r := Version(a).compareTo(Version(b)); r != result {
t.Fatalf("Unexpected version comparison result. Found %d, expected %d", r, result)
}
}
func TestCompareVersion(t *testing.T) {
assertVersion(t, "1.12", "1.12", 0)
assertVersion(t, "1.0.0", "1", 0)
assertVersion(t, "1", "1.0.0", 0)
assertVersion(t, "1.05.00.0156", "1.0.221.9289", 1)
assertVersion(t, "1", "1.0.1", -1)
assertVersion(t, "1.0.1", "1", 1)
assertVersion(t, "1.0.1", "1.0.2", -1)
assertVersion(t, "1.0.2", "1.0.3", -1)
assertVersion(t, "1.0.3", "1.1", -1)
assertVersion(t, "1.1", "1.1.1", -1)
assertVersion(t, "1.1.1", "1.1.2", -1)
assertVersion(t, "1.1.2", "1.2", -1)
}

View File

@ -12,6 +12,7 @@ import (
"time"
log "github.com/Sirupsen/logrus"
"github.com/docker/docker/pkg/version"
"github.com/samalba/dockerclient"
)
@ -21,6 +22,9 @@ const (
// Timeout for requests sent out to the engine.
requestTimeout = 10 * time.Second
// Minimum docker engine version supported by swarm.
minSupportedVersion = version.Version("1.6.0")
)
// NewEngine is exported
@ -141,11 +145,19 @@ func (e *Engine) updateSpecs() error {
return fmt.Errorf("cannot get resources for this engine, make sure %s is a Docker Engine, not a Swarm manager", e.Addr)
}
// 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("engine %s is running an unsupported version of Docker Engine. Please upgrade", e.Addr)
v, err := e.client.Version()
if err != nil {
return err
}
engineVersion := version.Version(v.Version)
// Older versions of Docker don't expose the ID field, Labels and are not supported
// by Swarm. Catch the error ASAP and refuse to connect.
if engineVersion.LessThan(minSupportedVersion) {
return fmt.Errorf("engine %s is running an unsupported version of Docker Engine. Please upgrade to at least %s", e.Addr, minSupportedVersion)
}
e.ID = info.ID
e.Name = info.Name
e.Cpus = info.NCPU

View File

@ -24,6 +24,10 @@ var (
OperatingSystem: "golang",
Labels: []string{"foo=bar"},
}
mockVersion = &dockerclient.Version{
Version: "1.6.2",
}
)
func TestEngineConnectionFailure(t *testing.T) {
@ -58,6 +62,7 @@ func TestEngineCpusMemory(t *testing.T) {
client := mockclient.NewMockClient()
client.On("Info").Return(mockInfo, nil)
client.On("Version").Return(mockVersion, nil)
client.On("ListContainers", true, false, "").Return([]dockerclient.Container{}, nil)
client.On("ListImages").Return([]*dockerclient.Image{}, nil)
client.On("StartMonitorEvents", mock.Anything, mock.Anything, mock.Anything).Return()
@ -78,6 +83,7 @@ func TestEngineSpecs(t *testing.T) {
client := mockclient.NewMockClient()
client.On("Info").Return(mockInfo, nil)
client.On("Version").Return(mockVersion, nil)
client.On("ListContainers", true, false, "").Return([]dockerclient.Container{}, nil)
client.On("ListImages").Return([]*dockerclient.Image{}, nil)
client.On("StartMonitorEvents", mock.Anything, mock.Anything, mock.Anything).Return()
@ -103,6 +109,7 @@ func TestEngineState(t *testing.T) {
client := mockclient.NewMockClient()
client.On("Info").Return(mockInfo, nil)
client.On("Version").Return(mockVersion, nil)
client.On("StartMonitorEvents", mock.Anything, mock.Anything, mock.Anything).Return()
// The client will return one container at first, then a second one will appear.
@ -149,6 +156,7 @@ func TestCreateContainer(t *testing.T) {
)
client.On("Info").Return(mockInfo, nil)
client.On("Version").Return(mockVersion, nil)
client.On("StartMonitorEvents", mock.Anything, mock.Anything, mock.Anything).Return()
client.On("ListContainers", true, false, "").Return([]dockerclient.Container{}, nil).Once()
client.On("ListImages").Return([]*dockerclient.Image{}, nil).Once()
@ -231,6 +239,7 @@ func TestUsedCpus(t *testing.T) {
cpuShares := int64(math.Ceil(float64(cn*1024) / float64(mockInfo.NCPU)))
client.On("Info").Return(mockInfo, nil)
client.On("Version").Return(mockVersion, nil)
client.On("StartMonitorEvents", mock.Anything, mock.Anything, mock.Anything).Return()
client.On("ListImages").Return([]*dockerclient.Image{}, nil).Once()
client.On("ListContainers", true, false, "").Return([]dockerclient.Container{{Id: "test"}}, nil).Once()

View File

@ -3,13 +3,14 @@ package swarm
import (
"bytes"
"fmt"
"io"
"testing"
"github.com/docker/swarm/cluster"
"github.com/samalba/dockerclient"
"github.com/samalba/dockerclient/mockclient"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"io"
"testing"
)
type nopCloser struct {
@ -33,6 +34,10 @@ var (
OperatingSystem: "golang",
Labels: []string{"foo=bar"},
}
mockVersion = &dockerclient.Version{
Version: "1.6.2",
}
)
func createEngine(t *testing.T, ID string, containers ...*cluster.Container) *cluster.Engine {
@ -119,6 +124,7 @@ func TestImportImage(t *testing.T) {
// create mock client
client := mockclient.NewMockClient()
client.On("Info").Return(mockInfo, nil)
client.On("Version").Return(mockVersion, nil)
client.On("StartMonitorEvents", mock.Anything, mock.Anything, mock.Anything).Return()
client.On("ListContainers", true, false, "").Return([]dockerclient.Container{}, nil).Once()
client.On("ListImages").Return([]*dockerclient.Image{}, nil)
@ -166,6 +172,7 @@ func TestLoadImage(t *testing.T) {
// create mock client
client := mockclient.NewMockClient()
client.On("Info").Return(mockInfo, nil)
client.On("Version").Return(mockVersion, nil)
client.On("StartMonitorEvents", mock.Anything, mock.Anything, mock.Anything).Return()
client.On("ListContainers", true, false, "").Return([]dockerclient.Container{}, nil).Once()
client.On("ListImages").Return([]*dockerclient.Image{}, nil)

View File

@ -10,7 +10,8 @@ This section tells you how to create a Docker Swarm on your network to use only
You install Docker Swarm on a single system which is known as your Docker Swarm manager. You create the cluster, or swarm, on one or more additional nodes on your network. Each node in your swarm must:
* be accessible by the swarm manager across your network
* a TCP port open to listen for the swarm manager
* have Docker Engine 1.6.0+ installed
* open a TCP port to listen for the manager
You can run Docker Swarm on Linux 64-bit architectures. You can also install and run it on 64-bit Windows and Max OSX but these architectures are *not* regularly tested for compatibility in the BETA phase.

View File

@ -4,7 +4,7 @@ set -e
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
RELEASE_IMAGE="dockerswarm/dind"
RELEASE_VERSIONS="1.6.0 1.5.0 1.4.0"
RELEASE_VERSIONS="1.6.2 1.6.1 1.6.0"
# Master.
echo "+++ Testing against docker master"
@ -15,6 +15,6 @@ for version in $RELEASE_VERSIONS; do
export DOCKER_IMAGE="$RELEASE_IMAGE"
export DOCKER_VERSION="$version"
echo "+++ Testing with $version"
echo "+++ Testing against docker $version"
bash "../integration/run.sh"
done