mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Merge pull request #51355 from corhere/api-macaddr-marshaltext
api/t/network: represent MAC addrs as byte slices
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/docker/go-units"
|
||||
"github.com/moby/moby/api/pkg/stdcopy"
|
||||
containertypes "github.com/moby/moby/api/types/container"
|
||||
networktypes "github.com/moby/moby/api/types/network"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/moby/moby/v2/integration/internal/container"
|
||||
net "github.com/moby/moby/v2/integration/internal/network"
|
||||
@@ -295,7 +296,7 @@ func TestMacAddressIsAppliedToMainNetworkWithShortID(t *testing.T) {
|
||||
|
||||
c := container.Inspect(ctx, t, apiClient, cid)
|
||||
assert.Assert(t, c.NetworkSettings.Networks["testnet"] != nil)
|
||||
assert.Equal(t, c.NetworkSettings.Networks["testnet"].MacAddress, "02:42:08:26:a9:55")
|
||||
assert.DeepEqual(t, c.NetworkSettings.Networks["testnet"].MacAddress, networktypes.HardwareAddr{0x02, 0x42, 0x08, 0x26, 0xa9, 0x55})
|
||||
}
|
||||
|
||||
func TestStaticIPOutsideSubpool(t *testing.T) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package container
|
||||
|
||||
import (
|
||||
"maps"
|
||||
"net"
|
||||
"net/netip"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -151,6 +152,10 @@ func WithTmpfs(targetAndOpts string) func(config *TestContainerConfig) {
|
||||
}
|
||||
|
||||
func WithMacAddress(networkName, mac string) func(config *TestContainerConfig) {
|
||||
maddr, err := net.ParseMAC(mac)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return func(c *TestContainerConfig) {
|
||||
if c.NetworkingConfig.EndpointsConfig == nil {
|
||||
c.NetworkingConfig.EndpointsConfig = map[string]*network.EndpointSettings{}
|
||||
@@ -158,7 +163,7 @@ func WithMacAddress(networkName, mac string) func(config *TestContainerConfig) {
|
||||
if v, ok := c.NetworkingConfig.EndpointsConfig[networkName]; !ok || v == nil {
|
||||
c.NetworkingConfig.EndpointsConfig[networkName] = &network.EndpointSettings{}
|
||||
}
|
||||
c.NetworkingConfig.EndpointsConfig[networkName].MacAddress = mac
|
||||
c.NetworkingConfig.EndpointsConfig[networkName].MacAddress = network.HardwareAddr(maddr)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1816,7 +1816,7 @@ func TestAdvertiseAddresses(t *testing.T) {
|
||||
// The original defer will stop ctr2Id.
|
||||
|
||||
ctr2NewMAC := container.Inspect(ctx, t, c, ctr2Id).NetworkSettings.Networks[netName].MacAddress
|
||||
assert.Check(t, ctr2OrigMAC != ctr2NewMAC, "expected restarted ctr2 to have a different MAC address")
|
||||
assert.Check(t, !slices.Equal(ctr2OrigMAC, ctr2NewMAC), "expected restarted ctr2 to have a different MAC address")
|
||||
|
||||
ctr1Neighs = container.ExecT(ctx, t, c, ctr1Id, []string{"ip", "neigh", "show"})
|
||||
assert.Assert(t, is.Equal(ctr1Neighs.ExitCode, 0))
|
||||
@@ -1843,9 +1843,6 @@ func TestAdvertiseAddresses(t *testing.T) {
|
||||
|
||||
// Check ARP/NA messages received for ctr2's new address (all unsolicited).
|
||||
|
||||
ctr2NewHwAddr, err := net.ParseMAC(ctr2NewMAC)
|
||||
assert.NilError(t, err)
|
||||
|
||||
checkPkts := func(pktDesc string, pkts []network.TimestampedPkt, matchIP netip.Addr, unpack func(pkt network.TimestampedPkt) (sh net.HardwareAddr, sp netip.Addr, err error)) {
|
||||
t.Helper()
|
||||
var count int
|
||||
@@ -1860,7 +1857,7 @@ func TestAdvertiseAddresses(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
t.Logf("%s %d: %s '%s' is at '%s'", pktDesc, i+1, p.ReceivedAt.Format("15:04:05.000"), pa, ha)
|
||||
if pa != matchIP || slices.Compare(ha, ctr2NewHwAddr) != 0 {
|
||||
if pa != matchIP || slices.Compare(ha, net.HardwareAddr(ctr2NewMAC)) != 0 {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
containertypes "github.com/moby/moby/api/types/container"
|
||||
@@ -82,7 +83,7 @@ func TestMACAddrOnRestart(t *testing.T) {
|
||||
ctr2Inspect := container.Inspect(ctx, t, c, ctr2Name)
|
||||
ctr2MAC := ctr2Inspect.NetworkSettings.Networks[netName].MacAddress
|
||||
|
||||
assert.Check(t, ctr1MAC != ctr2MAC,
|
||||
assert.Check(t, !slices.Equal(ctr1MAC, ctr2MAC),
|
||||
"expected containers to have different MAC addresses; got %q for both", ctr1MAC)
|
||||
}
|
||||
|
||||
@@ -120,7 +121,7 @@ func TestCfgdMACAddrOnRestart(t *testing.T) {
|
||||
|
||||
inspect := container.Inspect(ctx, t, c, ctr1Name)
|
||||
gotMAC := inspect.NetworkSettings.Networks[netName].MacAddress
|
||||
assert.Check(t, is.Equal(wantMAC, gotMAC))
|
||||
assert.Check(t, is.Equal(wantMAC, gotMAC.String()))
|
||||
|
||||
startAndCheck := func() {
|
||||
t.Helper()
|
||||
@@ -128,7 +129,7 @@ func TestCfgdMACAddrOnRestart(t *testing.T) {
|
||||
assert.Assert(t, is.Nil(err))
|
||||
inspect = container.Inspect(ctx, t, c, ctr1Name)
|
||||
gotMAC = inspect.NetworkSettings.Networks[netName].MacAddress
|
||||
assert.Check(t, is.Equal(wantMAC, gotMAC))
|
||||
assert.Check(t, is.Equal(wantMAC, gotMAC.String()))
|
||||
}
|
||||
|
||||
// Restart the container, check that the MAC address is restored.
|
||||
@@ -301,7 +302,7 @@ func TestWatchtowerCreate(t *testing.T) {
|
||||
inspect := container.Inspect(ctx, t, c, ctrName)
|
||||
netSettings := inspect.NetworkSettings.Networks[netName]
|
||||
assert.Check(t, is.Equal(netSettings.IPAddress, netip.MustParseAddr(ctrIP)))
|
||||
assert.Check(t, is.Equal(netSettings.MacAddress, ctrMAC))
|
||||
assert.Check(t, is.Equal(netSettings.MacAddress.String(), ctrMAC))
|
||||
}
|
||||
|
||||
type legacyCreateRequest struct {
|
||||
|
||||
Reference in New Issue
Block a user