-
Notifications
You must be signed in to change notification settings - Fork 595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docker v26 compatibility & test fixes #3097
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ package main | |
import ( | ||
"fmt" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/containerd/nerdctl/v2/pkg/testutil" | ||
|
@@ -57,69 +58,85 @@ func TestCreateWithMACAddress(t *testing.T) { | |
networkBridge := "testNetworkBridge" + tID | ||
networkMACvlan := "testNetworkMACvlan" + tID | ||
networkIPvlan := "testNetworkIPvlan" + tID | ||
base.Cmd("network", "create", networkBridge, "--driver", "bridge").AssertOK() | ||
base.Cmd("network", "create", networkMACvlan, "--driver", "macvlan").AssertOK() | ||
base.Cmd("network", "create", networkIPvlan, "--driver", "ipvlan").AssertOK() | ||
t.Cleanup(func() { | ||
|
||
tearDown := func() { | ||
base.Cmd("network", "rm", networkBridge).Run() | ||
base.Cmd("network", "rm", networkMACvlan).Run() | ||
base.Cmd("network", "rm", networkIPvlan).Run() | ||
}) | ||
} | ||
|
||
tearDown() | ||
t.Cleanup(tearDown) | ||
|
||
base.Cmd("network", "create", networkBridge, "--driver", "bridge").AssertOK() | ||
base.Cmd("network", "create", networkMACvlan, "--driver", "macvlan").AssertOK() | ||
base.Cmd("network", "create", networkIPvlan, "--driver", "ipvlan").AssertOK() | ||
|
||
defaultMac := base.Cmd("run", "--rm", "-i", "--network", "host", testutil.CommonImage). | ||
CmdOption(testutil.WithStdin(strings.NewReader("ip addr show eth0 | grep ether | awk '{printf $2}'"))). | ||
Run().Stdout() | ||
|
||
passedMac := "we expect the generated mac on the output" | ||
tests := []struct { | ||
Network string | ||
WantErr bool | ||
Expect string | ||
}{ | ||
{"host", true, "conflicting options"}, | ||
{"none", true, "can't open '/sys/class/net/eth0/address'"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using /sys/class/net is problematic as it does not seem to exist for rootless in any case. Replacing with a call to ip addr to retrieve the mac address instead. |
||
{"container:whatever" + tID, true, "conflicting options"}, | ||
{"bridge", false, ""}, | ||
{networkBridge, false, ""}, | ||
{networkMACvlan, false, ""}, | ||
{"host", false, defaultMac}, // anything but the actual address being passed | ||
{"none", false, ""}, | ||
{"container:whatever" + tID, true, "container"}, // "No such container" vs. "could not find container" | ||
{"bridge", false, passedMac}, | ||
{networkBridge, false, passedMac}, | ||
{networkMACvlan, false, passedMac}, | ||
{networkIPvlan, true, "not support"}, | ||
} | ||
for i, test := range tests { | ||
containerName := fmt.Sprintf("%s_%d", tID, i) | ||
testName := fmt.Sprintf("%s_container:%s_network:%s_expect:%s", tID, containerName, test.Network, test.Expect) | ||
expect := test.Expect | ||
network := test.Network | ||
wantErr := test.WantErr | ||
t.Run(testName, func(tt *testing.T) { | ||
tt.Parallel() | ||
|
||
macAddress, err := nettestutil.GenerateMACAddress() | ||
if err != nil { | ||
tt.Errorf("failed to generate MAC address: %s", err) | ||
} | ||
if test.Expect == "" && !test.WantErr { | ||
test.Expect = macAddress | ||
if expect == passedMac { | ||
expect = macAddress | ||
} | ||
tt.Cleanup(func() { | ||
base.Cmd("rm", "-f", containerName).Run() | ||
}) | ||
cmd := base.Cmd("create", "--network", test.Network, "--mac-address", macAddress, "--name", containerName, testutil.CommonImage, "cat", "/sys/class/net/eth0/address") | ||
if !test.WantErr { | ||
cmd.AssertOK() | ||
// This is currently blocked by https://github.com/containerd/nerdctl/pull/3104 | ||
// res := base.Cmd("create", "-i", "--network", network, "--mac-address", macAddress, testutil.CommonImage).Run() | ||
res := base.Cmd("create", "--network", network, "--name", containerName, | ||
"--mac-address", macAddress, testutil.CommonImage, | ||
"sh", "-c", "--", "ip addr show eth0 | grep ether").Run() | ||
|
||
if !wantErr { | ||
assert.Assert(t, res.ExitCode == 0, "Command should have succeeded", res.Combined()) | ||
// This is currently blocked by: https://github.com/containerd/nerdctl/pull/3104 | ||
// res = base.Cmd("start", "-i", containerName). | ||
// CmdOption(testutil.WithStdin(strings.NewReader("ip addr show eth0 | grep ether | awk '{printf $2}'"))).Run() | ||
base.Cmd("start", containerName).AssertOK() | ||
cmd = base.Cmd("logs", containerName) | ||
cmd.AssertOK() | ||
cmd.AssertOutContains(test.Expect) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing faulty logic resulting in multiple repeat executions. |
||
res = base.Cmd("logs", containerName).Run() | ||
assert.Assert(t, strings.Contains(res.Stdout(), expect), fmt.Sprintf("expected output to contain %q: %q", expect, res.Stdout())) | ||
assert.Assert(t, res.ExitCode == 0, "Command should have succeeded", res.Combined()) | ||
} else { | ||
if (testutil.GetTarget() == testutil.Docker && test.Network == networkIPvlan) || test.Network == "none" { | ||
// 1. unlike nerdctl | ||
// when using network ipvlan in Docker | ||
if testutil.GetTarget() == testutil.Docker && | ||
(network == networkIPvlan || network == "container:whatever"+tID) { | ||
// unlike nerdctl | ||
// when using network ipvlan or container in Docker | ||
// it delays fail on executing start command | ||
// 2. start on network none will success in both | ||
// nerdctl and Docker | ||
cmd.AssertOK() | ||
cmd = base.Cmd("start", containerName) | ||
if test.Network == "none" { | ||
// we check the result on logs command | ||
cmd.AssertOK() | ||
cmd = base.Cmd("logs", containerName) | ||
} | ||
} | ||
cmd.AssertCombinedOutContains(test.Expect) | ||
if test.Network == "none" { | ||
cmd.AssertOK() | ||
} else { | ||
cmd.AssertFail() | ||
assert.Assert(t, res.ExitCode == 0, "Command should have succeeded", res.Combined()) | ||
res = base.Cmd("start", "-i", containerName). | ||
CmdOption(testutil.WithStdin(strings.NewReader("ip addr show eth0 | grep ether | awk '{printf $2}'"))).Run() | ||
} | ||
|
||
assert.Assert(t, strings.Contains(res.Combined(), expect), fmt.Sprintf("expected output to contain %q: %q", expect, res.Combined())) | ||
assert.Assert(t, res.ExitCode != 0, "Command should have failed", res.Combined()) | ||
} | ||
}) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -354,12 +354,17 @@ func TestRunContainerWithStaticIP(t *testing.T) { | |
useNetwork: true, | ||
checkTheIPAddress: false, | ||
}, | ||
{ | ||
ip: "10.4.0.2", | ||
shouldSuccess: true, | ||
useNetwork: false, | ||
checkTheIPAddress: false, | ||
}, | ||
// XXX see https://github.com/containerd/nerdctl/issues/3101 | ||
// docker 24 silently ignored the ip - now, docker 26 is erroring out - furthermore, this ip only makes sense | ||
// in the context of nerdctl bridge network, so, this test needs rewritting either way | ||
/* | ||
{ | ||
ip: "10.4.0.2", | ||
shouldSuccess: true, | ||
useNetwork: false, | ||
checkTheIPAddress: false, | ||
}, | ||
*/ | ||
} | ||
tID := testutil.Identifier(t) | ||
for i, tc := range testCases { | ||
|
@@ -453,43 +458,68 @@ func TestRunContainerWithMACAddress(t *testing.T) { | |
networkBridge := "testNetworkBridge" + tID | ||
networkMACvlan := "testNetworkMACvlan" + tID | ||
networkIPvlan := "testNetworkIPvlan" + tID | ||
base.Cmd("network", "create", networkBridge, "--driver", "bridge").AssertOK() | ||
base.Cmd("network", "create", networkMACvlan, "--driver", "macvlan").AssertOK() | ||
base.Cmd("network", "create", networkIPvlan, "--driver", "ipvlan").AssertOK() | ||
t.Cleanup(func() { | ||
tearDown := func() { | ||
base.Cmd("network", "rm", networkBridge).Run() | ||
base.Cmd("network", "rm", networkMACvlan).Run() | ||
base.Cmd("network", "rm", networkIPvlan).Run() | ||
}) | ||
} | ||
|
||
tearDown() | ||
t.Cleanup(tearDown) | ||
|
||
base.Cmd("network", "create", networkBridge, "--driver", "bridge").AssertOK() | ||
base.Cmd("network", "create", networkMACvlan, "--driver", "macvlan").AssertOK() | ||
base.Cmd("network", "create", networkIPvlan, "--driver", "ipvlan").AssertOK() | ||
|
||
defaultMac := base.Cmd("run", "--rm", "-i", "--network", "host", testutil.CommonImage). | ||
CmdOption(testutil.WithStdin(strings.NewReader("ip addr show eth0 | grep ether | awk '{printf $2}'"))). | ||
Run().Stdout() | ||
|
||
passedMac := "we expect the generated mac on the output" | ||
|
||
tests := []struct { | ||
Network string | ||
WantErr bool | ||
Expect string | ||
}{ | ||
{"host", true, "conflicting options"}, | ||
{"none", true, "can't open '/sys/class/net/eth0/address'"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing this is problematic as it does not seem to be there at all with rootless. |
||
{"container:whatever" + tID, true, "conflicting options"}, | ||
{"bridge", false, ""}, | ||
{networkBridge, false, ""}, | ||
{networkMACvlan, false, ""}, | ||
{"host", false, defaultMac}, // anything but the actual address being passed | ||
{"none", false, ""}, // nothing | ||
{"container:whatever" + tID, true, "container"}, // "No such container" vs. "could not find container" | ||
{"bridge", false, passedMac}, | ||
{networkBridge, false, passedMac}, | ||
{networkMACvlan, false, passedMac}, | ||
{networkIPvlan, true, "not support"}, | ||
} | ||
for _, test := range tests { | ||
macAddress, err := nettestutil.GenerateMACAddress() | ||
if err != nil { | ||
t.Errorf("failed to generate MAC address: %s", err) | ||
} | ||
if test.Expect == "" && !test.WantErr { | ||
test.Expect = macAddress | ||
} | ||
cmd := base.Cmd("run", "--rm", "--network", test.Network, "--mac-address", macAddress, testutil.CommonImage, "cat", "/sys/class/net/eth0/address") | ||
if test.WantErr { | ||
cmd.AssertFail() | ||
cmd.AssertCombinedOutContains(test.Expect) | ||
} else { | ||
cmd.AssertOK() | ||
cmd.AssertOutContains(test.Expect) | ||
} | ||
|
||
for i, test := range tests { | ||
containerName := fmt.Sprintf("%s_%d", tID, i) | ||
testName := fmt.Sprintf("%s_container:%s_network:%s_expect:%s", tID, containerName, test.Network, test.Expect) | ||
expect := test.Expect | ||
network := test.Network | ||
wantErr := test.WantErr | ||
t.Run(testName, func(tt *testing.T) { | ||
tt.Parallel() | ||
|
||
macAddress, err := nettestutil.GenerateMACAddress() | ||
if err != nil { | ||
t.Errorf("failed to generate MAC address: %s", err) | ||
} | ||
if expect == passedMac { | ||
expect = macAddress | ||
} | ||
|
||
res := base.Cmd("run", "--rm", "-i", "--network", network, "--mac-address", macAddress, testutil.CommonImage). | ||
CmdOption(testutil.WithStdin(strings.NewReader("ip addr show eth0 | grep ether | awk '{printf $2}'"))).Run() | ||
|
||
if wantErr { | ||
assert.Assert(t, res.ExitCode != 0, "Command should have failed", res.Combined()) | ||
assert.Assert(t, strings.Contains(res.Combined(), expect), fmt.Sprintf("expected output to contain %q: %q", expect, res.Combined())) | ||
} else { | ||
assert.Assert(t, res.ExitCode == 0, "Command should have succeeded", res.Combined()) | ||
assert.Assert(t, strings.Contains(res.Stdout(), expect), fmt.Sprintf("expected output to contain %q: %q", expect, res.Stdout())) | ||
} | ||
}) | ||
|
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also updating the plugins