Restore error type in FindNetwork

The error type libnetwork.ErrNoSuchNetwork is used in the controller
to retry the network creation as a managed network though the manager.
The change of the type was breaking the logic causing the network to
not being created anymore so that no new container on that network
was able to be launched
Added unit test

Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
This commit is contained in:
Flavio Crisciani
2017-11-28 17:06:26 -08:00
parent c307e0ce49
commit 51cea0a53c
5 changed files with 34 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ import (
"runtime"
"testing"
"github.com/docker/docker/api/errdefs"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/container"
_ "github.com/docker/docker/pkg/discovery/memory"
@@ -17,6 +18,8 @@ import (
"github.com/docker/docker/volume/local"
"github.com/docker/docker/volume/store"
"github.com/docker/go-connections/nat"
"github.com/docker/libnetwork"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
@@ -311,3 +314,12 @@ func TestValidateContainerIsolation(t *testing.T) {
_, err := d.verifyContainerSettings(runtime.GOOS, &containertypes.HostConfig{Isolation: containertypes.Isolation("invalid")}, nil, false)
assert.EqualError(t, err, "invalid isolation 'invalid' on "+runtime.GOOS)
}
func TestFindNetworkErrorType(t *testing.T) {
d := Daemon{}
_, err := d.FindNetwork("fakeNet")
_, ok := errors.Cause(err).(libnetwork.ErrNoSuchNetwork)
if !errdefs.IsNotFound(err) || !ok {
assert.Fail(t, "The FindNetwork method MUST always return an error that implements the NotFound interface and is ErrNoSuchNetwork")
}
}