mirror of https://github.com/docker/docs.git
Merge pull request #3082 from patrikerdes/3015_active_timeout_error_message
Fix #3015
This commit is contained in:
commit
0c9adcb01e
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/machine/libmachine"
|
"github.com/docker/machine/libmachine"
|
||||||
"github.com/docker/machine/libmachine/persist"
|
"github.com/docker/machine/libmachine/persist"
|
||||||
|
"github.com/docker/machine/libmachine/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -15,7 +16,8 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errNoActiveHost = errors.New("No active host found")
|
errNoActiveHost = errors.New("No active host found")
|
||||||
|
errActiveTimeout = errors.New("Error getting active host: timeout")
|
||||||
)
|
)
|
||||||
|
|
||||||
func cmdActive(c CommandLine, api libmachine.API) error {
|
func cmdActive(c CommandLine, api libmachine.API) error {
|
||||||
|
@ -42,10 +44,17 @@ func cmdActive(c CommandLine, api libmachine.API) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func activeHost(items []HostListItem) (HostListItem, error) {
|
func activeHost(items []HostListItem) (HostListItem, error) {
|
||||||
|
timeout := false
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
if item.ActiveHost || item.ActiveSwarm {
|
if item.ActiveHost || item.ActiveSwarm {
|
||||||
return item, nil
|
return item, nil
|
||||||
}
|
}
|
||||||
|
if item.State == state.Timeout {
|
||||||
|
timeout = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if timeout {
|
||||||
|
return HostListItem{}, errActiveTimeout
|
||||||
}
|
}
|
||||||
return HostListItem{}, errNoActiveHost
|
return HostListItem{}, errNoActiveHost
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package commands
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/machine/libmachine/state"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,16 +13,19 @@ func TestCmdActiveNone(t *testing.T) {
|
||||||
Name: "host1",
|
Name: "host1",
|
||||||
ActiveHost: false,
|
ActiveHost: false,
|
||||||
ActiveSwarm: false,
|
ActiveSwarm: false,
|
||||||
|
State: state.Running,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "host2",
|
Name: "host2",
|
||||||
ActiveHost: false,
|
ActiveHost: false,
|
||||||
ActiveSwarm: false,
|
ActiveSwarm: false,
|
||||||
|
State: state.Running,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "host3",
|
Name: "host3",
|
||||||
ActiveHost: false,
|
ActiveHost: false,
|
||||||
ActiveSwarm: false,
|
ActiveSwarm: false,
|
||||||
|
State: state.Running,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err := activeHost(hostListItems)
|
_, err := activeHost(hostListItems)
|
||||||
|
@ -34,16 +38,19 @@ func TestCmdActiveHost(t *testing.T) {
|
||||||
Name: "host1",
|
Name: "host1",
|
||||||
ActiveHost: false,
|
ActiveHost: false,
|
||||||
ActiveSwarm: false,
|
ActiveSwarm: false,
|
||||||
|
State: state.Timeout,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "host2",
|
Name: "host2",
|
||||||
ActiveHost: true,
|
ActiveHost: true,
|
||||||
ActiveSwarm: false,
|
ActiveSwarm: false,
|
||||||
|
State: state.Running,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "host3",
|
Name: "host3",
|
||||||
ActiveHost: false,
|
ActiveHost: false,
|
||||||
ActiveSwarm: false,
|
ActiveSwarm: false,
|
||||||
|
State: state.Running,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
active, err := activeHost(hostListItems)
|
active, err := activeHost(hostListItems)
|
||||||
|
@ -57,19 +64,47 @@ func TestCmdActiveSwarm(t *testing.T) {
|
||||||
Name: "host1",
|
Name: "host1",
|
||||||
ActiveHost: false,
|
ActiveHost: false,
|
||||||
ActiveSwarm: false,
|
ActiveSwarm: false,
|
||||||
|
State: state.Running,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "host2",
|
Name: "host2",
|
||||||
ActiveHost: false,
|
ActiveHost: false,
|
||||||
ActiveSwarm: false,
|
ActiveSwarm: false,
|
||||||
|
State: state.Running,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "host3",
|
Name: "host3",
|
||||||
ActiveHost: false,
|
ActiveHost: false,
|
||||||
ActiveSwarm: true,
|
ActiveSwarm: true,
|
||||||
|
State: state.Running,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
active, err := activeHost(hostListItems)
|
active, err := activeHost(hostListItems)
|
||||||
assert.Equal(t, err, nil)
|
assert.Equal(t, err, nil)
|
||||||
assert.Equal(t, active.Name, "host3")
|
assert.Equal(t, active.Name, "host3")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCmdActiveTimeout(t *testing.T) {
|
||||||
|
hostListItems := []HostListItem{
|
||||||
|
{
|
||||||
|
Name: "host1",
|
||||||
|
ActiveHost: false,
|
||||||
|
ActiveSwarm: false,
|
||||||
|
State: state.Running,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "host2",
|
||||||
|
ActiveHost: false,
|
||||||
|
ActiveSwarm: false,
|
||||||
|
State: state.Running,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "host3",
|
||||||
|
ActiveHost: false,
|
||||||
|
ActiveSwarm: false,
|
||||||
|
State: state.Timeout,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_, err := activeHost(hostListItems)
|
||||||
|
assert.Equal(t, err, errActiveTimeout)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue