diff options
author | Andrei Vagin <avagin@google.com> | 2019-05-03 11:20:12 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-05-03 11:21:22 -0700 |
commit | 3f3e3a63033f87dd42076423661b62c04d10c15f (patch) | |
tree | 07273107138b0fcde054748337d0b9fa0b08ccd0 /runsc/test/testutil/docker.go | |
parent | 458fe955a74bca6c33cb321901d771cf146f5cc6 (diff) |
gvisor/kokoro: save runsc logs
PiperOrigin-RevId: 246542315
Change-Id: Ia9ba2bc104e0af3277d3b6102122c13d320ea802
Diffstat (limited to 'runsc/test/testutil/docker.go')
-rw-r--r-- | runsc/test/testutil/docker.go | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/runsc/test/testutil/docker.go b/runsc/test/testutil/docker.go index 29ef505b4..ecd66dc77 100644 --- a/runsc/test/testutil/docker.go +++ b/runsc/test/testutil/docker.go @@ -120,7 +120,7 @@ func getLocalPath(file string) string { // do executes docker command. func do(args ...string) (string, error) { - fmt.Printf("Running: docker %s\n", args) + log.Printf("Running: docker %s\n", args) cmd := exec.Command("docker", args...) out, err := cmd.CombinedOutput() if err != nil { @@ -131,7 +131,7 @@ func do(args ...string) (string, error) { // doWithPty executes docker command with stdio attached to a pty. func doWithPty(args ...string) (*exec.Cmd, *os.File, error) { - fmt.Printf("Running with pty: docker %s\n", args) + log.Printf("Running with pty: docker %s\n", args) cmd := exec.Command("docker", args...) ptmx, err := pty.Start(cmd) if err != nil { @@ -160,11 +160,23 @@ func MakeDocker(namePrefix string) Docker { return Docker{Name: RandomName(namePrefix), Runtime: getRuntime()} } +// logDockerID logs a container id, which is needed to find container runsc logs. +func (d *Docker) logDockerID() { + id, err := d.ID() + if err != nil { + log.Printf("%v\n", err) + } + log.Printf("Name: %s ID: %v\n", d.Name, id) +} + // Create calls 'docker create' with the arguments provided. func (d *Docker) Create(args ...string) error { a := []string{"create", "--runtime", d.Runtime, "--name", d.Name} a = append(a, args...) _, err := do(a...) + if err == nil { + d.logDockerID() + } return err } @@ -190,6 +202,9 @@ func (d *Docker) Run(args ...string) error { a := []string{"run", "--runtime", d.Runtime, "--name", d.Name, "-d"} a = append(a, args...) _, err := do(a...) + if err == nil { + d.logDockerID() + } return err } @@ -206,6 +221,9 @@ func (d *Docker) RunFg(args ...string) (string, error) { a := []string{"run", "--runtime", d.Runtime, "--name", d.Name} a = append(a, args...) out, err := do(a...) + if err == nil { + d.logDockerID() + } return string(out), err } @@ -255,6 +273,7 @@ func (d *Docker) Remove() error { // CleanUp kills and deletes the container (best effort). func (d *Docker) CleanUp() { + d.logDockerID() if _, err := do("kill", d.Name); err != nil { log.Printf("error killing container %q: %v", d.Name, err) } |