Merge pull request #37648 from Random-Liu/collect-serial-output-node-e2e

Automatic merge from submit-queue

Node E2E: Collect serial output

This is a temporary solution to collect serial output from test GCE node in node e2e.

We should come up with a better idea later. Ideally, node e2e should share the same log collection logic with cluster e2e. https://github.com/kubernetes/kubernetes/blob/master/cluster/log-dump.sh

Mark v1.5 because this helps debug https://github.com/kubernetes/kubernetes/issues/37333.

@mtaufen @dchen1107 
/cc @kubernetes/sig-node
This commit is contained in:
Kubernetes Submit Queue 2016-12-01 15:06:59 -08:00 committed by GitHub
commit 3a4b4749e3
2 changed files with 28 additions and 1 deletions

View File

@ -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))

View File

@ -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