Created
March 6, 2014 03:06
-
-
Save daniel-garcia/9381481 to your computer and use it in GitHub Desktop.
An attempt at reproducing device busy errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"os" | |
"os/exec" | |
"sync" | |
) | |
const testImage = "ubuntu" | |
func dockerPull() { | |
log.Printf("Pulling test image: %s", testImage) | |
cmd := exec.Command("docker", "pull", testImage) | |
output, err := cmd.CombinedOutput() | |
if err != nil { | |
log.Fatal("Could not pull docker image %s:\n\n%s", testImage, string(output)) | |
} | |
} | |
func dockerRunit() { | |
cmd := exec.Command("docker", "run", "-rm", testImage, "/bin/sh", "-c", "touch foo && chown 9999:9999 foo && ls -l1 foo | awk '{ print $3, $4 }'") | |
output, err := cmd.CombinedOutput() | |
if err != nil { | |
log.Printf("docker run... %s:\n\n%s", err, string(output)) | |
} | |
} | |
func versionInfo() { | |
for _, cmdStr := range []string{"docker version", "lxc-version", "uname -srvmpio"} { | |
log.Printf("executing: %s", cmdStr) | |
cmd := exec.Command("sh", "-c", cmdStr) | |
cmd.Stdout = os.Stdout | |
cmd.Stderr = os.Stderr | |
cmd.Run() | |
} | |
} | |
func main() { | |
versionInfo() | |
dockerPull() | |
count := 100 | |
wg := sync.WaitGroup{} | |
wg.Add(count) | |
log.Printf("About to run %d test containers concurrently.", count) | |
for i := 0; i < count; i++ { | |
go func() { | |
dockerRunit() | |
wg.Done() | |
}() | |
} | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment