Makes TestDaemonDefaultNetworkPools re-runnable, and stops the
accumulation of bridges from the others.
Signed-off-by: Rob Murray <rob.murray@docker.com>
| ... | ... |
@@ -179,6 +179,7 @@ func TestHostIPv4BridgeLabel(t *testing.T) {
|
| 179 | 179 |
network.WithOption("com.docker.network.host_ipv4", ipv4SNATAddr),
|
| 180 | 180 |
network.WithOption("com.docker.network.bridge.name", bridgeName),
|
| 181 | 181 |
) |
| 182 |
+ defer network.RemoveNoError(ctx, t, c, bridgeName) |
|
| 182 | 183 |
out, err := c.NetworkInspect(ctx, bridgeName, networktypes.InspectOptions{Verbose: true})
|
| 183 | 184 |
assert.NilError(t, err) |
| 184 | 185 |
assert.Assert(t, len(out.IPAM.Config) > 0) |
| ... | ... |
@@ -281,6 +282,7 @@ func TestForbidDuplicateNetworkNames(t *testing.T) {
|
| 281 | 281 |
defer c.Close() |
| 282 | 282 |
|
| 283 | 283 |
network.CreateNoError(ctx, t, c, "testnet") |
| 284 |
+ defer network.RemoveNoError(ctx, t, c, "testnet") |
|
| 284 | 285 |
|
| 285 | 286 |
_, err := c.NetworkCreate(ctx, "testnet", networktypes.CreateOptions{})
|
| 286 | 287 |
assert.Error(t, err, "Error response from daemon: network with name testnet already exists", "2nd NetworkCreate call should have failed") |
| ... | ... |
@@ -14,6 +14,7 @@ import ( |
| 14 | 14 |
"github.com/docker/docker/testutil" |
| 15 | 15 |
"github.com/docker/docker/testutil/daemon" |
| 16 | 16 |
"gotest.tools/v3/assert" |
| 17 |
+ is "gotest.tools/v3/assert/cmp" |
|
| 17 | 18 |
"gotest.tools/v3/icmd" |
| 18 | 19 |
"gotest.tools/v3/poll" |
| 19 | 20 |
"gotest.tools/v3/skip" |
| ... | ... |
@@ -72,6 +73,7 @@ func TestDaemonDefaultNetworkPools(t *testing.T) {
|
| 72 | 72 |
"--default-address-pool", "base=175.30.0.0/16,size=16", |
| 73 | 73 |
"--default-address-pool", "base=175.33.0.0/16,size=24", |
| 74 | 74 |
) |
| 75 |
+ defer delInterface(ctx, t, defaultNetworkBridge) |
|
| 75 | 76 |
|
| 76 | 77 |
c := d.NewClientT(t) |
| 77 | 78 |
defer c.Close() |
| ... | ... |
@@ -86,19 +88,20 @@ func TestDaemonDefaultNetworkPools(t *testing.T) {
|
| 86 | 86 |
network.CreateNoError(ctx, t, c, name, |
| 87 | 87 |
network.WithDriver("bridge"),
|
| 88 | 88 |
) |
| 89 |
+ defer network.RemoveNoError(ctx, t, c, name) |
|
| 89 | 90 |
out, err = c.NetworkInspect(ctx, name, networktypes.InspectOptions{})
|
| 90 | 91 |
assert.NilError(t, err) |
| 91 |
- assert.Equal(t, out.IPAM.Config[0].Subnet, "175.33.0.0/24") |
|
| 92 |
+ assert.Check(t, is.Equal(out.IPAM.Config[0].Subnet, "175.33.0.0/24")) |
|
| 92 | 93 |
|
| 93 | 94 |
// Create a bridge network and verify its subnet is the third default pool |
| 94 | 95 |
name = "saanvi" + t.Name() |
| 95 | 96 |
network.CreateNoError(ctx, t, c, name, |
| 96 | 97 |
network.WithDriver("bridge"),
|
| 97 | 98 |
) |
| 99 |
+ defer network.RemoveNoError(ctx, t, c, name) |
|
| 98 | 100 |
out, err = c.NetworkInspect(ctx, name, networktypes.InspectOptions{})
|
| 99 | 101 |
assert.NilError(t, err) |
| 100 |
- assert.Equal(t, out.IPAM.Config[0].Subnet, "175.33.1.0/24") |
|
| 101 |
- delInterface(ctx, t, defaultNetworkBridge) |
|
| 102 |
+ assert.Check(t, is.Equal(out.IPAM.Config[0].Subnet, "175.33.1.0/24")) |
|
| 102 | 103 |
} |
| 103 | 104 |
|
| 104 | 105 |
func TestDaemonRestartWithExistingNetwork(t *testing.T) {
|
| ... | ... |
@@ -107,7 +110,6 @@ func TestDaemonRestartWithExistingNetwork(t *testing.T) {
|
| 107 | 107 |
skip.If(t, testEnv.IsRootless, "rootless mode has different view of network") |
| 108 | 108 |
ctx := testutil.StartSpan(baseContext, t) |
| 109 | 109 |
|
| 110 |
- defaultNetworkBridge := "docker0" |
|
| 111 | 110 |
d := daemon.New(t) |
| 112 | 111 |
d.Start(t) |
| 113 | 112 |
defer d.Stop(t) |
| ... | ... |
@@ -119,6 +121,7 @@ func TestDaemonRestartWithExistingNetwork(t *testing.T) {
|
| 119 | 119 |
network.CreateNoError(ctx, t, c, name, |
| 120 | 120 |
network.WithDriver("bridge"),
|
| 121 | 121 |
) |
| 122 |
+ defer network.RemoveNoError(ctx, t, c, name) |
|
| 122 | 123 |
|
| 123 | 124 |
// Verify bridge network's subnet |
| 124 | 125 |
out, err := c.NetworkInspect(ctx, name, networktypes.InspectOptions{})
|
| ... | ... |
@@ -129,11 +132,11 @@ func TestDaemonRestartWithExistingNetwork(t *testing.T) {
|
| 129 | 129 |
d.Restart(t, |
| 130 | 130 |
"--default-address-pool", "base=175.30.0.0/16,size=16", |
| 131 | 131 |
"--default-address-pool", "base=175.33.0.0/16,size=24") |
| 132 |
+ defer delInterface(ctx, t, "docker0") |
|
| 132 | 133 |
|
| 133 | 134 |
out1, err := c.NetworkInspect(ctx, name, networktypes.InspectOptions{})
|
| 134 | 135 |
assert.NilError(t, err) |
| 135 | 136 |
assert.Equal(t, out1.IPAM.Config[0].Subnet, networkip) |
| 136 |
- delInterface(ctx, t, defaultNetworkBridge) |
|
| 137 | 137 |
} |
| 138 | 138 |
|
| 139 | 139 |
func TestDaemonRestartWithExistingNetworkWithDefaultPoolRange(t *testing.T) {
|
| ... | ... |
@@ -143,7 +146,6 @@ func TestDaemonRestartWithExistingNetworkWithDefaultPoolRange(t *testing.T) {
|
| 143 | 143 |
|
| 144 | 144 |
ctx := testutil.StartSpan(baseContext, t) |
| 145 | 145 |
|
| 146 |
- defaultNetworkBridge := "docker0" |
|
| 147 | 146 |
d := daemon.New(t) |
| 148 | 147 |
d.Start(t) |
| 149 | 148 |
defer d.Stop(t) |
| ... | ... |
@@ -155,6 +157,7 @@ func TestDaemonRestartWithExistingNetworkWithDefaultPoolRange(t *testing.T) {
|
| 155 | 155 |
network.CreateNoError(ctx, t, c, name, |
| 156 | 156 |
network.WithDriver("bridge"),
|
| 157 | 157 |
) |
| 158 |
+ defer network.RemoveNoError(ctx, t, c, name) |
|
| 158 | 159 |
|
| 159 | 160 |
// Verify bridge network's subnet |
| 160 | 161 |
out, err := c.NetworkInspect(ctx, name, networktypes.InspectOptions{})
|
| ... | ... |
@@ -166,6 +169,7 @@ func TestDaemonRestartWithExistingNetworkWithDefaultPoolRange(t *testing.T) {
|
| 166 | 166 |
network.CreateNoError(ctx, t, c, name, |
| 167 | 167 |
network.WithDriver("bridge"),
|
| 168 | 168 |
) |
| 169 |
+ defer network.RemoveNoError(ctx, t, c, name) |
|
| 169 | 170 |
out, err = c.NetworkInspect(ctx, name, networktypes.InspectOptions{})
|
| 170 | 171 |
assert.NilError(t, err) |
| 171 | 172 |
networkip2 := out.IPAM.Config[0].Subnet |
| ... | ... |
@@ -175,18 +179,19 @@ func TestDaemonRestartWithExistingNetworkWithDefaultPoolRange(t *testing.T) {
|
| 175 | 175 |
"--default-address-pool", "base=175.18.0.0/16,size=16", |
| 176 | 176 |
"--default-address-pool", "base=175.19.0.0/16,size=24", |
| 177 | 177 |
) |
| 178 |
+ defer delInterface(ctx, t, "docker0") |
|
| 178 | 179 |
|
| 179 | 180 |
// Create a bridge network |
| 180 | 181 |
name = "saanvi" + t.Name() |
| 181 | 182 |
network.CreateNoError(ctx, t, c, name, |
| 182 | 183 |
network.WithDriver("bridge"),
|
| 183 | 184 |
) |
| 185 |
+ defer network.RemoveNoError(ctx, t, c, name) |
|
| 184 | 186 |
out1, err := c.NetworkInspect(ctx, name, networktypes.InspectOptions{})
|
| 185 | 187 |
assert.NilError(t, err) |
| 186 | 188 |
|
| 187 | 189 |
assert.Check(t, out1.IPAM.Config[0].Subnet != networkip) |
| 188 | 190 |
assert.Check(t, out1.IPAM.Config[0].Subnet != networkip2) |
| 189 |
- delInterface(ctx, t, defaultNetworkBridge) |
|
| 190 | 191 |
} |
| 191 | 192 |
|
| 192 | 193 |
func TestDaemonWithBipAndDefaultNetworkPool(t *testing.T) {
|
| ... | ... |
@@ -196,7 +201,6 @@ func TestDaemonWithBipAndDefaultNetworkPool(t *testing.T) {
|
| 196 | 196 |
|
| 197 | 197 |
ctx := testutil.StartSpan(baseContext, t) |
| 198 | 198 |
|
| 199 |
- defaultNetworkBridge := "docker0" |
|
| 200 | 199 |
d := daemon.New(t) |
| 201 | 200 |
defer d.Stop(t) |
| 202 | 201 |
d.Start(t, |
| ... | ... |
@@ -204,6 +208,7 @@ func TestDaemonWithBipAndDefaultNetworkPool(t *testing.T) {
|
| 204 | 204 |
"--default-address-pool", "base=175.30.0.0/16,size=16", |
| 205 | 205 |
"--default-address-pool", "base=175.33.0.0/16,size=24", |
| 206 | 206 |
) |
| 207 |
+ defer delInterface(ctx, t, "docker0") |
|
| 207 | 208 |
|
| 208 | 209 |
c := d.NewClientT(t) |
| 209 | 210 |
defer c.Close() |
| ... | ... |
@@ -213,7 +218,6 @@ func TestDaemonWithBipAndDefaultNetworkPool(t *testing.T) {
|
| 213 | 213 |
assert.NilError(t, err) |
| 214 | 214 |
// Make sure BIP IP doesn't get override with new default address pool . |
| 215 | 215 |
assert.Equal(t, out.IPAM.Config[0].Subnet, "172.60.0.0/16") |
| 216 |
- delInterface(ctx, t, defaultNetworkBridge) |
|
| 217 | 216 |
} |
| 218 | 217 |
|
| 219 | 218 |
func TestServiceWithPredefinedNetwork(t *testing.T) {
|