Browse code

Stable MAC addresses: Add support for MAC address restoring.

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>

Andrea Luzzardi authored on 2014/10/04 05:29:09
Showing 2 changed files
... ...
@@ -544,9 +544,10 @@ func (container *Container) RestoreNetwork() error {
544 544
 
545 545
 	eng := container.daemon.eng
546 546
 
547
-	// Re-allocate the interface with the same IP address.
547
+	// Re-allocate the interface with the same IP and MAC address.
548 548
 	job := eng.Job("allocate_interface", container.ID)
549 549
 	job.Setenv("RequestedIP", container.NetworkSettings.IPAddress)
550
+	job.Setenv("RequestedMac", container.NetworkSettings.MacAddress)
550 551
 	if err := job.Run(); err != nil {
551 552
 		return err
552 553
 	}
... ...
@@ -1870,7 +1870,7 @@ func TestRunMutableNetworkFiles(t *testing.T) {
1870 1870
 
1871 1871
 func TestRunStableIPAndPort(t *testing.T) {
1872 1872
 	const nContainers = 2
1873
-	var ids, ips, ports [nContainers]string
1873
+	var ids, ips, macs, ports [nContainers]string
1874 1874
 
1875 1875
 	// Setup: Create a couple of containers and collect their IPs and public ports.
1876 1876
 	for i := 0; i < nContainers; i++ {
... ...
@@ -1880,12 +1880,16 @@ func TestRunStableIPAndPort(t *testing.T) {
1880 1880
 			t.Fatal(err)
1881 1881
 		}
1882 1882
 		ids[i] = strings.TrimSpace(out)
1883
+
1883 1884
 		ips[i], err = inspectField(ids[i], "NetworkSettings.IPAddress")
1884 1885
 		errorOut(err, t, out)
1885 1886
 		if ips[i] == "" {
1886 1887
 			t.Fatal("IP allocation failed")
1887 1888
 		}
1888 1889
 
1890
+		macs[i], err = inspectField(ids[i], "NetworkSettings.MacAddress")
1891
+		errorOut(err, t, out)
1892
+
1889 1893
 		portCmd := exec.Command(dockerBinary, "port", ids[i], "1234")
1890 1894
 		ports[i], _, err = runCommandWithOutput(portCmd)
1891 1895
 		errorOut(err, t, out)
... ...
@@ -1927,7 +1931,7 @@ func TestRunStableIPAndPort(t *testing.T) {
1927 1927
 		}
1928 1928
 	}
1929 1929
 
1930
-	// Start the containers back, and ensure they are getting the same IPs and ports.
1930
+	// Start the containers back, and ensure they are getting the same IPs, MACs and ports.
1931 1931
 	for i, id := range ids {
1932 1932
 		runCmd := exec.Command(dockerBinary, "start", id)
1933 1933
 		out, _, err := runCommandWithOutput(runCmd)
... ...
@@ -1935,6 +1939,10 @@ func TestRunStableIPAndPort(t *testing.T) {
1935 1935
 
1936 1936
 		ip, err := inspectField(id, "NetworkSettings.IPAddress")
1937 1937
 		errorOut(err, t, out)
1938
+
1939
+		mac, err := inspectField(id, "NetworkSettings.MacAddress")
1940
+		errorOut(err, t, out)
1941
+
1938 1942
 		portCmd := exec.Command(dockerBinary, "port", ids[i], "1234")
1939 1943
 		port, _, err := runCommandWithOutput(portCmd)
1940 1944
 		errorOut(err, t, out)
... ...
@@ -1942,6 +1950,9 @@ func TestRunStableIPAndPort(t *testing.T) {
1942 1942
 		if ips[i] != ip {
1943 1943
 			t.Fatalf("Container started with a different IP: %s != %s", ip, ips[i])
1944 1944
 		}
1945
+		if macs[i] != mac {
1946
+			t.Fatalf("Container started with a different MAC: %s != %s", mac, macs[i])
1947
+		}
1945 1948
 		if ports[i] != port {
1946 1949
 			t.Fatalf("Container started with a different port: %s != %s", port, ports[i])
1947 1950
 		}