Break some routines out of the mutable files test for future use
Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
This commit is contained in:
parent
1eb5e5d25f
commit
20575d20ba
|
@ -1897,37 +1897,25 @@ func TestRunMutableNetworkFiles(t *testing.T) {
|
||||||
for _, fn := range []string{"resolv.conf", "hosts"} {
|
for _, fn := range []string{"resolv.conf", "hosts"} {
|
||||||
deleteAllContainers()
|
deleteAllContainers()
|
||||||
|
|
||||||
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "c1", "busybox", "sh", "-c", fmt.Sprintf("echo success >/etc/%s; while true; do sleep 1; done", fn)))
|
content, err := runCommandAndReadContainerFile(fn, exec.Command(dockerBinary, "run", "-d", "--name", "c1", "busybox", "sh", "-c", fmt.Sprintf("echo success >/etc/%s; while true; do sleep 1; done", fn)))
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err, out)
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
|
|
||||||
contID := strings.TrimSpace(out)
|
|
||||||
|
|
||||||
f, err := os.Open(filepath.Join("/var/lib/docker/containers", contID, fn))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := ioutil.ReadAll(f)
|
|
||||||
f.Close()
|
|
||||||
|
|
||||||
if strings.TrimSpace(string(content)) != "success" {
|
if strings.TrimSpace(string(content)) != "success" {
|
||||||
t.Fatal("Content was not what was modified in the container", string(content))
|
t.Fatal("Content was not what was modified in the container", string(content))
|
||||||
}
|
}
|
||||||
|
|
||||||
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "c2", "busybox", "sh", "-c", fmt.Sprintf("while true; do cat /etc/%s; sleep 1; done", fn)))
|
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "c2", "busybox", "sh", "-c", fmt.Sprintf("while true; do cat /etc/%s; sleep 1; done", fn)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
contID = strings.TrimSpace(out)
|
contID := strings.TrimSpace(out)
|
||||||
|
|
||||||
resolvConfPath := filepath.Join("/var/lib/docker/containers", contID, fn)
|
resolvConfPath := containerStorageFile(contID, fn)
|
||||||
|
|
||||||
f, err = os.OpenFile(resolvConfPath, os.O_WRONLY|os.O_SYNC|os.O_APPEND, 0644)
|
f, err := os.OpenFile(resolvConfPath, os.O_WRONLY|os.O_SYNC|os.O_APPEND, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,11 @@ var (
|
||||||
// the private registry to use for tests
|
// the private registry to use for tests
|
||||||
privateRegistryURL = "127.0.0.1:5000"
|
privateRegistryURL = "127.0.0.1:5000"
|
||||||
|
|
||||||
dockerBasePath = "/var/lib/docker"
|
dockerBasePath = "/var/lib/docker"
|
||||||
execDriverPath = dockerBasePath + "/execdriver/native"
|
execDriverPath = dockerBasePath + "/execdriver/native"
|
||||||
volumesConfigPath = dockerBasePath + "/volumes"
|
volumesConfigPath = dockerBasePath + "/volumes"
|
||||||
volumesStoragePath = dockerBasePath + "/vfs/dir"
|
volumesStoragePath = dockerBasePath + "/vfs/dir"
|
||||||
|
containerStoragePath = dockerBasePath + "/containers"
|
||||||
|
|
||||||
workingDirectory string
|
workingDirectory string
|
||||||
)
|
)
|
||||||
|
|
|
@ -731,3 +731,35 @@ func readFile(src string, t *testing.T) (content string) {
|
||||||
}
|
}
|
||||||
return string(data)
|
return string(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func containerStorageFile(containerId, basename string) string {
|
||||||
|
return filepath.Join("/var/lib/docker/containers", containerId, basename)
|
||||||
|
}
|
||||||
|
|
||||||
|
func runCommandAndReadContainerFile(filename string, cmd *exec.Cmd) ([]byte, error) {
|
||||||
|
out, _, err := runCommandWithOutput(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
|
contID := strings.TrimSpace(out)
|
||||||
|
|
||||||
|
return readContainerFile(contID, filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
func readContainerFile(containerId, filename string) ([]byte, error) {
|
||||||
|
f, err := os.Open(containerStorageFile(containerId, filename))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
content, err := ioutil.ReadAll(f)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return content, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue