From 6d4e457f1f7e21171ba3956d8539c74cf5b74bc3 Mon Sep 17 00:00:00 2001 From: Random-Liu Date: Tue, 29 Nov 2016 12:18:14 -0800 Subject: [PATCH] Collect serial output when test fails in node e2e. --- test/e2e_node/remote/remote.go | 13 +++++++++++++ test/e2e_node/runner/remote/run_remote.go | 16 +++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/test/e2e_node/remote/remote.go b/test/e2e_node/remote/remote.go index 3a1d07bd88f..8b97ceb29b6 100644 --- a/test/e2e_node/remote/remote.go +++ b/test/e2e_node/remote/remote.go @@ -350,6 +350,19 @@ func getTestArtifacts(host, testDir string) error { return nil } +// WriteLog is a temporary function to make it possible to write log +// in the runner. This is used to collect serial console log. +// TODO(random-liu): Use the log-dump script in cluster e2e. +func WriteLog(host, filename, content string) error { + f, err := os.Create(filepath.Join(*resultsDir, host, filename)) + if err != nil { + return err + } + defer f.Close() + _, err = f.WriteString(content) + return err +} + // getSSHCommand handles proper quoting so that multiple commands are executed in the same shell over ssh func getSSHCommand(sep string, args ...string) string { return fmt.Sprintf("'%s'", strings.Join(args, sep)) diff --git a/test/e2e_node/runner/remote/run_remote.go b/test/e2e_node/runner/remote/run_remote.go index 045a4278ee6..35a09485ed4 100644 --- a/test/e2e_node/runner/remote/run_remote.go +++ b/test/e2e_node/runner/remote/run_remote.go @@ -449,7 +449,21 @@ func testImage(imageConfig *internalGCEImage, junitFilePrefix string) *TestResul // Only delete the files if we are keeping the instance and want it cleaned up. // If we are going to delete the instance, don't bother with cleaning up the files deleteFiles := !*deleteInstances && *cleanup - return testHost(host, deleteFiles, junitFilePrefix, *setupNode, ginkgoFlagsStr) + + result := testHost(host, deleteFiles, junitFilePrefix, *setupNode, ginkgoFlagsStr) + // This is a temporary solution to collect serial node serial log. Only port 1 contains useful information. + // TODO(random-liu): Extract out and unify log collection logic with cluste e2e. + serialPortOutput, err := computeService.Instances.GetSerialPortOutput(*project, *zone, host).Port(1).Do() + if err != nil { + glog.Errorf("Failed to collect serial output from node %q: %v", host, err) + } else { + logFilename := "serial-1.log" + err := remote.WriteLog(host, logFilename, serialPortOutput.Contents) + if err != nil { + glog.Errorf("Failed to write serial output from node %q to %q: %v", host, logFilename, err) + } + } + return result } // Provision a gce instance using image