1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/integration/network/delete_test.go

92 lines
3.6 KiB
Go
Raw Normal View History

package network // import "github.com/docker/docker/integration/network"
Fix network name masking network ID on delete If a network is created with a name that matches another network's ID, the network with that name was masking the other network's ID. As a result, it was not possible to remove the network with a given ID. This patch changes the order in which networks are matched to be what we use for other cases; 1. Match on full ID 2. Match on full Name 3. Match on Partial ID Before this patch: $ docker network create foo 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b $ docker network create 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE 4a698333f119 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b bridge local d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local $ docker network rm 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local After this patch: $ docker network create foo 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network create 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 6cbc749a529cd2d9d3b10566c84e56c4203dd88b67417437b5fc7a6e955dd48f $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 2d1791a7def4 foo bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local $ docker network rm 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-08-14 16:23:57 -04:00
import (
"context"
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/versions"
dclient "github.com/docker/docker/client"
"github.com/docker/docker/integration/internal/network"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
"gotest.tools/skip"
Fix network name masking network ID on delete If a network is created with a name that matches another network's ID, the network with that name was masking the other network's ID. As a result, it was not possible to remove the network with a given ID. This patch changes the order in which networks are matched to be what we use for other cases; 1. Match on full ID 2. Match on full Name 3. Match on Partial ID Before this patch: $ docker network create foo 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b $ docker network create 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE 4a698333f119 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b bridge local d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local $ docker network rm 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local After this patch: $ docker network create foo 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network create 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 6cbc749a529cd2d9d3b10566c84e56c4203dd88b67417437b5fc7a6e955dd48f $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 2d1791a7def4 foo bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local $ docker network rm 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-08-14 16:23:57 -04:00
)
func containsNetwork(nws []types.NetworkResource, networkID string) bool {
Fix network name masking network ID on delete If a network is created with a name that matches another network's ID, the network with that name was masking the other network's ID. As a result, it was not possible to remove the network with a given ID. This patch changes the order in which networks are matched to be what we use for other cases; 1. Match on full ID 2. Match on full Name 3. Match on Partial ID Before this patch: $ docker network create foo 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b $ docker network create 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE 4a698333f119 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b bridge local d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local $ docker network rm 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local After this patch: $ docker network create foo 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network create 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 6cbc749a529cd2d9d3b10566c84e56c4203dd88b67417437b5fc7a6e955dd48f $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 2d1791a7def4 foo bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local $ docker network rm 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-08-14 16:23:57 -04:00
for _, n := range nws {
if n.ID == networkID {
Fix network name masking network ID on delete If a network is created with a name that matches another network's ID, the network with that name was masking the other network's ID. As a result, it was not possible to remove the network with a given ID. This patch changes the order in which networks are matched to be what we use for other cases; 1. Match on full ID 2. Match on full Name 3. Match on Partial ID Before this patch: $ docker network create foo 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b $ docker network create 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE 4a698333f119 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b bridge local d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local $ docker network rm 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local After this patch: $ docker network create foo 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network create 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 6cbc749a529cd2d9d3b10566c84e56c4203dd88b67417437b5fc7a6e955dd48f $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 2d1791a7def4 foo bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local $ docker network rm 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-08-14 16:23:57 -04:00
return true
}
}
return false
}
// createAmbiguousNetworks creates three networks, of which the second network
// uses a prefix of the first network's ID as name. The third network uses the
// first network's ID as name.
//
// After successful creation, properties of all three networks is returned
func createAmbiguousNetworks(ctx context.Context, t *testing.T, client dclient.APIClient) (string, string, string) {
testNet := network.CreateNoError(ctx, t, client, "testNet")
idPrefixNet := network.CreateNoError(ctx, t, client, testNet[:12])
fullIDNet := network.CreateNoError(ctx, t, client, testNet)
Fix network name masking network ID on delete If a network is created with a name that matches another network's ID, the network with that name was masking the other network's ID. As a result, it was not possible to remove the network with a given ID. This patch changes the order in which networks are matched to be what we use for other cases; 1. Match on full ID 2. Match on full Name 3. Match on Partial ID Before this patch: $ docker network create foo 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b $ docker network create 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE 4a698333f119 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b bridge local d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local $ docker network rm 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local After this patch: $ docker network create foo 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network create 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 6cbc749a529cd2d9d3b10566c84e56c4203dd88b67417437b5fc7a6e955dd48f $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 2d1791a7def4 foo bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local $ docker network rm 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-08-14 16:23:57 -04:00
nws, err := client.NetworkList(ctx, types.NetworkListOptions{})
assert.NilError(t, err)
Fix network name masking network ID on delete If a network is created with a name that matches another network's ID, the network with that name was masking the other network's ID. As a result, it was not possible to remove the network with a given ID. This patch changes the order in which networks are matched to be what we use for other cases; 1. Match on full ID 2. Match on full Name 3. Match on Partial ID Before this patch: $ docker network create foo 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b $ docker network create 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE 4a698333f119 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b bridge local d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local $ docker network rm 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local After this patch: $ docker network create foo 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network create 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 6cbc749a529cd2d9d3b10566c84e56c4203dd88b67417437b5fc7a6e955dd48f $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 2d1791a7def4 foo bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local $ docker network rm 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-08-14 16:23:57 -04:00
assert.Check(t, is.Equal(true, containsNetwork(nws, testNet)), "failed to create network testNet")
assert.Check(t, is.Equal(true, containsNetwork(nws, idPrefixNet)), "failed to create network idPrefixNet")
assert.Check(t, is.Equal(true, containsNetwork(nws, fullIDNet)), "failed to create network fullIDNet")
Fix network name masking network ID on delete If a network is created with a name that matches another network's ID, the network with that name was masking the other network's ID. As a result, it was not possible to remove the network with a given ID. This patch changes the order in which networks are matched to be what we use for other cases; 1. Match on full ID 2. Match on full Name 3. Match on Partial ID Before this patch: $ docker network create foo 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b $ docker network create 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE 4a698333f119 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b bridge local d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local $ docker network rm 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local After this patch: $ docker network create foo 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network create 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 6cbc749a529cd2d9d3b10566c84e56c4203dd88b67417437b5fc7a6e955dd48f $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 2d1791a7def4 foo bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local $ docker network rm 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-08-14 16:23:57 -04:00
return testNet, idPrefixNet, fullIDNet
}
// TestNetworkCreateDelete tests creation and deletion of a network.
func TestNetworkCreateDelete(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
defer setupTest(t)()
client := testEnv.APIClient()
ctx := context.Background()
netName := "testnetwork_" + t.Name()
network.CreateNoError(ctx, t, client, netName,
network.WithCheckDuplicate(),
)
assert.Check(t, IsNetworkAvailable(client, netName))
// delete the network and make sure it is deleted
err := client.NetworkRemove(ctx, netName)
assert.NilError(t, err)
assert.Check(t, IsNetworkNotAvailable(client, netName))
}
Fix network name masking network ID on delete If a network is created with a name that matches another network's ID, the network with that name was masking the other network's ID. As a result, it was not possible to remove the network with a given ID. This patch changes the order in which networks are matched to be what we use for other cases; 1. Match on full ID 2. Match on full Name 3. Match on Partial ID Before this patch: $ docker network create foo 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b $ docker network create 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE 4a698333f119 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b bridge local d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local $ docker network rm 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local After this patch: $ docker network create foo 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network create 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 6cbc749a529cd2d9d3b10566c84e56c4203dd88b67417437b5fc7a6e955dd48f $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 2d1791a7def4 foo bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local $ docker network rm 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-08-14 16:23:57 -04:00
// TestDockerNetworkDeletePreferID tests that if a network with a name
// equal to another network's ID exists, the Network with the given
// ID is removed, and not the network with the given name.
func TestDockerNetworkDeletePreferID(t *testing.T) {
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.34"), "broken in earlier versions")
skip.If(t, testEnv.OSType == "windows",
"FIXME. Windows doesn't run DinD and uses networks shared between control daemon and daemon under test")
Fix network name masking network ID on delete If a network is created with a name that matches another network's ID, the network with that name was masking the other network's ID. As a result, it was not possible to remove the network with a given ID. This patch changes the order in which networks are matched to be what we use for other cases; 1. Match on full ID 2. Match on full Name 3. Match on Partial ID Before this patch: $ docker network create foo 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b $ docker network create 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE 4a698333f119 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b bridge local d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local $ docker network rm 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local After this patch: $ docker network create foo 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network create 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 6cbc749a529cd2d9d3b10566c84e56c4203dd88b67417437b5fc7a6e955dd48f $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 2d1791a7def4 foo bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local $ docker network rm 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-08-14 16:23:57 -04:00
defer setupTest(t)()
client := testEnv.APIClient()
Fix network name masking network ID on delete If a network is created with a name that matches another network's ID, the network with that name was masking the other network's ID. As a result, it was not possible to remove the network with a given ID. This patch changes the order in which networks are matched to be what we use for other cases; 1. Match on full ID 2. Match on full Name 3. Match on Partial ID Before this patch: $ docker network create foo 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b $ docker network create 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE 4a698333f119 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b bridge local d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local $ docker network rm 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local After this patch: $ docker network create foo 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network create 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 6cbc749a529cd2d9d3b10566c84e56c4203dd88b67417437b5fc7a6e955dd48f $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 2d1791a7def4 foo bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local $ docker network rm 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-08-14 16:23:57 -04:00
ctx := context.Background()
testNet, idPrefixNet, fullIDNet := createAmbiguousNetworks(ctx, t, client)
Fix network name masking network ID on delete If a network is created with a name that matches another network's ID, the network with that name was masking the other network's ID. As a result, it was not possible to remove the network with a given ID. This patch changes the order in which networks are matched to be what we use for other cases; 1. Match on full ID 2. Match on full Name 3. Match on Partial ID Before this patch: $ docker network create foo 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b $ docker network create 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE 4a698333f119 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b bridge local d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local $ docker network rm 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local After this patch: $ docker network create foo 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network create 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 6cbc749a529cd2d9d3b10566c84e56c4203dd88b67417437b5fc7a6e955dd48f $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 2d1791a7def4 foo bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local $ docker network rm 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-08-14 16:23:57 -04:00
// Delete the network using a prefix of the first network's ID as name.
// This should the network name with the id-prefix, not the original network.
err := client.NetworkRemove(ctx, testNet[:12])
assert.NilError(t, err)
Fix network name masking network ID on delete If a network is created with a name that matches another network's ID, the network with that name was masking the other network's ID. As a result, it was not possible to remove the network with a given ID. This patch changes the order in which networks are matched to be what we use for other cases; 1. Match on full ID 2. Match on full Name 3. Match on Partial ID Before this patch: $ docker network create foo 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b $ docker network create 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE 4a698333f119 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b bridge local d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local $ docker network rm 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local After this patch: $ docker network create foo 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network create 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 6cbc749a529cd2d9d3b10566c84e56c4203dd88b67417437b5fc7a6e955dd48f $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 2d1791a7def4 foo bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local $ docker network rm 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-08-14 16:23:57 -04:00
// Delete the network using networkID. This should remove the original
// network, not the network with the name equal to the networkID
err = client.NetworkRemove(ctx, testNet)
assert.NilError(t, err)
Fix network name masking network ID on delete If a network is created with a name that matches another network's ID, the network with that name was masking the other network's ID. As a result, it was not possible to remove the network with a given ID. This patch changes the order in which networks are matched to be what we use for other cases; 1. Match on full ID 2. Match on full Name 3. Match on Partial ID Before this patch: $ docker network create foo 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b $ docker network create 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE 4a698333f119 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b bridge local d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local $ docker network rm 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local After this patch: $ docker network create foo 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network create 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 6cbc749a529cd2d9d3b10566c84e56c4203dd88b67417437b5fc7a6e955dd48f $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 2d1791a7def4 foo bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local $ docker network rm 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-08-14 16:23:57 -04:00
// networks "testNet" and "idPrefixNet" should be removed, but "fullIDNet" should still exist
nws, err := client.NetworkList(ctx, types.NetworkListOptions{})
assert.NilError(t, err)
assert.Check(t, is.Equal(false, containsNetwork(nws, testNet)), "Network testNet not removed")
assert.Check(t, is.Equal(false, containsNetwork(nws, idPrefixNet)), "Network idPrefixNet not removed")
assert.Check(t, is.Equal(true, containsNetwork(nws, fullIDNet)), "Network fullIDNet not found")
Fix network name masking network ID on delete If a network is created with a name that matches another network's ID, the network with that name was masking the other network's ID. As a result, it was not possible to remove the network with a given ID. This patch changes the order in which networks are matched to be what we use for other cases; 1. Match on full ID 2. Match on full Name 3. Match on Partial ID Before this patch: $ docker network create foo 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b $ docker network create 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE 4a698333f119 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b bridge local d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local $ docker network rm 336717eac9eaa3da6557042a04efc803f7e8862ce6cf96f6b9565265ba5c618b 4a698333f1197f20224583abce14876d7f25fdfe416a8545927006c315915a2a $ docker network ls NETWORK ID NAME DRIVER SCOPE d1e40d43a2c0 bridge bridge local 336717eac9ea foo bridge local 13cf280a1bbf host host local d9e4c03728a0 none null local After this patch: $ docker network create foo 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network create 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 6cbc749a529cd2d9d3b10566c84e56c4203dd88b67417437b5fc7a6e955dd48f $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 2d1791a7def4 foo bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local $ docker network rm 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 $ docker network ls NETWORK ID NAME DRIVER SCOPE 6cbc749a529c 2d1791a7def4e2a1ef0f6b83c6add333df0bb4ced2f196c584cb64e6bd94b835 bridge local 166c943dbeb5 bridge bridge local 6c45b8aa6d8e host host local b11c96b51ea7 none null local Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-08-14 16:23:57 -04:00
}