Sfoglia il codice sorgente

Stable MAC addresses: Add support for MAC address restoring.

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
Andrea Luzzardi 10 anni fa
parent
commit
b669025949
2 ha cambiato i file con 15 aggiunte e 3 eliminazioni
  1. 2 1
      daemon/container.go
  2. 13 2
      integration-cli/docker_cli_run_test.go

+ 2 - 1
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
 	}

+ 13 - 2
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])
 		}