From b669025949f1dba1ad3af9bab6711736863d6e24 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Fri, 3 Oct 2014 13:29:09 -0700 Subject: [PATCH] Stable MAC addresses: Add support for MAC address restoring. Signed-off-by: Andrea Luzzardi --- daemon/container.go | 3 ++- integration-cli/docker_cli_run_test.go | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/daemon/container.go b/daemon/container.go index 1d38de3115..221edaad2c 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -544,9 +544,10 @@ func (container *Container) RestoreNetwork() error { eng := container.daemon.eng - // Re-allocate the interface with the same IP address. + // Re-allocate the interface with the same IP and MAC address. job := eng.Job("allocate_interface", container.ID) job.Setenv("RequestedIP", container.NetworkSettings.IPAddress) + job.Setenv("RequestedMac", container.NetworkSettings.MacAddress) if err := job.Run(); err != nil { return err } diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 813c02fcbf..280a8761da 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -1870,7 +1870,7 @@ func TestRunMutableNetworkFiles(t *testing.T) { func TestRunStableIPAndPort(t *testing.T) { const nContainers = 2 - var ids, ips, ports [nContainers]string + var ids, ips, macs, ports [nContainers]string // Setup: Create a couple of containers and collect their IPs and public ports. for i := 0; i < nContainers; i++ { @@ -1880,12 +1880,16 @@ func TestRunStableIPAndPort(t *testing.T) { t.Fatal(err) } ids[i] = strings.TrimSpace(out) + ips[i], err = inspectField(ids[i], "NetworkSettings.IPAddress") errorOut(err, t, out) if ips[i] == "" { t.Fatal("IP allocation failed") } + macs[i], err = inspectField(ids[i], "NetworkSettings.MacAddress") + errorOut(err, t, out) + portCmd := exec.Command(dockerBinary, "port", ids[i], "1234") ports[i], _, err = runCommandWithOutput(portCmd) errorOut(err, t, out) @@ -1927,7 +1931,7 @@ func TestRunStableIPAndPort(t *testing.T) { } } - // Start the containers back, and ensure they are getting the same IPs and ports. + // Start the containers back, and ensure they are getting the same IPs, MACs and ports. for i, id := range ids { runCmd := exec.Command(dockerBinary, "start", id) out, _, err := runCommandWithOutput(runCmd) @@ -1935,6 +1939,10 @@ func TestRunStableIPAndPort(t *testing.T) { ip, err := inspectField(id, "NetworkSettings.IPAddress") errorOut(err, t, out) + + mac, err := inspectField(id, "NetworkSettings.MacAddress") + errorOut(err, t, out) + portCmd := exec.Command(dockerBinary, "port", ids[i], "1234") port, _, err := runCommandWithOutput(portCmd) errorOut(err, t, out) @@ -1942,6 +1950,9 @@ func TestRunStableIPAndPort(t *testing.T) { if ips[i] != ip { t.Fatalf("Container started with a different IP: %s != %s", ip, ips[i]) } + if macs[i] != mac { + t.Fatalf("Container started with a different MAC: %s != %s", mac, macs[i]) + } if ports[i] != port { t.Fatalf("Container started with a different port: %s != %s", port, ports[i]) }