Stable MAC addresses: Add support for MAC address restoring.

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2014-10-03 13:29:09 -07:00
parent f1087c5fcf
commit b669025949
2 changed files with 15 additions and 3 deletions

View file

@ -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
}

View file

@ -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])
}