gvisor/kokoro: save runsc logs

PiperOrigin-RevId: 246542315
Change-Id: Ia9ba2bc104e0af3277d3b6102122c13d320ea802
This commit is contained in:
Andrei Vagin
2019-05-03 11:21:22 -07:00
committed by Shentubot
parent 458fe955a7
commit 3f3e3a6303
4 changed files with 27 additions and 2 deletions
+2
View File
@@ -7,5 +7,7 @@ action {
define_artifacts {
regex: "**/sponge_log.xml"
regex: "**/sponge_log.log"
regex: "**/outputs.zip"
regex: "**/runsc-logs.tar.gz"
}
}
+1
View File
@@ -8,5 +8,6 @@ action {
regex: "**/sponge_log.xml"
regex: "**/sponge_log.log"
regex: "**/outputs.zip"
regex: "**/runsc-logs.tar.gz"
}
}
+3
View File
@@ -183,6 +183,9 @@ upload_test_artifacts() {
find -L "bazel-testlogs" -name "test.xml" -o -name "test.log" -o -name "outputs.zip" |
tar --create --files-from - --transform 's/test\./sponge_log./' |
tar --extract --directory ${KOKORO_ARTIFACTS_DIR}
if [[ -d "/tmp/${RUNTIME}/logs" ]]; then
tar --create --gzip "--file=${KOKORO_ARTIFACTS_DIR}/runsc-logs.tar.gz" -C /tmp/ ${RUNTIME}/logs
fi
}
# Finish runs at exit, even in the event of an error, and uploads all test
+21 -2
View File
@@ -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)
}