Docker-DCO-1.1-Signed-off-by: Jessica Frazelle <jess@docker.com> (github: jfrazelle)
| ... | ... |
@@ -623,3 +623,59 @@ func TestRunExecDir(t *testing.T) {
|
| 623 | 623 |
|
| 624 | 624 |
logDone("run - check execdriver dir behavior")
|
| 625 | 625 |
} |
| 626 |
+ |
|
| 627 |
+func TestRunMutableNetworkFiles(t *testing.T) {
|
|
| 628 |
+ defer deleteAllContainers() |
|
| 629 |
+ |
|
| 630 |
+ for _, fn := range []string{"resolv.conf", "hosts"} {
|
|
| 631 |
+ deleteAllContainers() |
|
| 632 |
+ |
|
| 633 |
+ content, err := runCommandAndReadContainerFile(fn, exec.Command(dockerBinary, "run", "-d", "--name", "c1", "busybox", "sh", "-c", fmt.Sprintf("echo success >/etc/%s && top", fn)))
|
|
| 634 |
+ if err != nil {
|
|
| 635 |
+ t.Fatal(err) |
|
| 636 |
+ } |
|
| 637 |
+ |
|
| 638 |
+ if strings.TrimSpace(string(content)) != "success" {
|
|
| 639 |
+ t.Fatal("Content was not what was modified in the container", string(content))
|
|
| 640 |
+ } |
|
| 641 |
+ |
|
| 642 |
+ out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "c2", "busybox", "top")) |
|
| 643 |
+ if err != nil {
|
|
| 644 |
+ t.Fatal(err) |
|
| 645 |
+ } |
|
| 646 |
+ |
|
| 647 |
+ contID := strings.TrimSpace(out) |
|
| 648 |
+ |
|
| 649 |
+ netFilePath := containerStorageFile(contID, fn) |
|
| 650 |
+ |
|
| 651 |
+ f, err := os.OpenFile(netFilePath, os.O_WRONLY|os.O_SYNC|os.O_APPEND, 0644) |
|
| 652 |
+ if err != nil {
|
|
| 653 |
+ t.Fatal(err) |
|
| 654 |
+ } |
|
| 655 |
+ |
|
| 656 |
+ if _, err := f.Seek(0, 0); err != nil {
|
|
| 657 |
+ f.Close() |
|
| 658 |
+ t.Fatal(err) |
|
| 659 |
+ } |
|
| 660 |
+ |
|
| 661 |
+ if err := f.Truncate(0); err != nil {
|
|
| 662 |
+ f.Close() |
|
| 663 |
+ t.Fatal(err) |
|
| 664 |
+ } |
|
| 665 |
+ |
|
| 666 |
+ if _, err := f.Write([]byte("success2\n")); err != nil {
|
|
| 667 |
+ f.Close() |
|
| 668 |
+ t.Fatal(err) |
|
| 669 |
+ } |
|
| 670 |
+ f.Close() |
|
| 671 |
+ |
|
| 672 |
+ res, err := exec.Command(dockerBinary, "exec", contID, "cat", "/etc/"+fn).CombinedOutput() |
|
| 673 |
+ if err != nil {
|
|
| 674 |
+ t.Fatalf("Output: %s, error: %s", res, err)
|
|
| 675 |
+ } |
|
| 676 |
+ if string(res) != "success2\n" {
|
|
| 677 |
+ t.Fatalf("Expected content of %s: %q, got: %q", fn, "success2\n", res)
|
|
| 678 |
+ } |
|
| 679 |
+ } |
|
| 680 |
+ logDone("run - mutable network files")
|
|
| 681 |
+} |
| ... | ... |
@@ -2166,62 +2166,6 @@ func TestRunBindMounts(t *testing.T) {
|
| 2166 | 2166 |
logDone("run - bind mounts")
|
| 2167 | 2167 |
} |
| 2168 | 2168 |
|
| 2169 |
-func TestRunMutableNetworkFiles(t *testing.T) {
|
|
| 2170 |
- defer deleteAllContainers() |
|
| 2171 |
- |
|
| 2172 |
- for _, fn := range []string{"resolv.conf", "hosts"} {
|
|
| 2173 |
- deleteAllContainers() |
|
| 2174 |
- |
|
| 2175 |
- content, err := runCommandAndReadContainerFile(fn, exec.Command(dockerBinary, "run", "-d", "--name", "c1", "busybox", "sh", "-c", fmt.Sprintf("echo success >/etc/%s && top", fn)))
|
|
| 2176 |
- if err != nil {
|
|
| 2177 |
- t.Fatal(err) |
|
| 2178 |
- } |
|
| 2179 |
- |
|
| 2180 |
- if strings.TrimSpace(string(content)) != "success" {
|
|
| 2181 |
- t.Fatal("Content was not what was modified in the container", string(content))
|
|
| 2182 |
- } |
|
| 2183 |
- |
|
| 2184 |
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "c2", "busybox", "top")) |
|
| 2185 |
- if err != nil {
|
|
| 2186 |
- t.Fatal(err) |
|
| 2187 |
- } |
|
| 2188 |
- |
|
| 2189 |
- contID := strings.TrimSpace(out) |
|
| 2190 |
- |
|
| 2191 |
- netFilePath := containerStorageFile(contID, fn) |
|
| 2192 |
- |
|
| 2193 |
- f, err := os.OpenFile(netFilePath, os.O_WRONLY|os.O_SYNC|os.O_APPEND, 0644) |
|
| 2194 |
- if err != nil {
|
|
| 2195 |
- t.Fatal(err) |
|
| 2196 |
- } |
|
| 2197 |
- |
|
| 2198 |
- if _, err := f.Seek(0, 0); err != nil {
|
|
| 2199 |
- f.Close() |
|
| 2200 |
- t.Fatal(err) |
|
| 2201 |
- } |
|
| 2202 |
- |
|
| 2203 |
- if err := f.Truncate(0); err != nil {
|
|
| 2204 |
- f.Close() |
|
| 2205 |
- t.Fatal(err) |
|
| 2206 |
- } |
|
| 2207 |
- |
|
| 2208 |
- if _, err := f.Write([]byte("success2\n")); err != nil {
|
|
| 2209 |
- f.Close() |
|
| 2210 |
- t.Fatal(err) |
|
| 2211 |
- } |
|
| 2212 |
- f.Close() |
|
| 2213 |
- |
|
| 2214 |
- res, err := exec.Command(dockerBinary, "exec", contID, "cat", "/etc/"+fn).CombinedOutput() |
|
| 2215 |
- if err != nil {
|
|
| 2216 |
- t.Fatalf("Output: %s, error: %s", res, err)
|
|
| 2217 |
- } |
|
| 2218 |
- if string(res) != "success2\n" {
|
|
| 2219 |
- t.Fatalf("Expected content of %s: %q, got: %q", fn, "success2\n", res)
|
|
| 2220 |
- } |
|
| 2221 |
- } |
|
| 2222 |
- logDone("run - mutable network files")
|
|
| 2223 |
-} |
|
| 2224 |
- |
|
| 2225 | 2169 |
// Ensure that CIDFile gets deleted if it's empty |
| 2226 | 2170 |
// Perform this test by making `docker run` fail |
| 2227 | 2171 |
func TestRunCidFileCleanupIfEmpty(t *testing.T) {
|