From 9badd05327bc3a1a96c828de3c32dc8101be77cc Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 19 Nov 2017 12:29:00 +0100 Subject: vm/gce: provide VM console output on boot failures "can't ssh into the instance" is not a very useful error. --- pkg/gce/gce.go | 10 ++++++++++ vm/gce/gce.go | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/pkg/gce/gce.go b/pkg/gce/gce.go index e8ad084e6..c08ae5519 100644 --- a/pkg/gce/gce.go +++ b/pkg/gce/gce.go @@ -228,6 +228,16 @@ func (ctx *Context) DeleteImage(imageName string) error { return nil } +func (ctx *Context) GetSerialPortOutput(instance string) (string, error) { + <-ctx.apiRateGate + output, err := ctx.computeService.Instances.GetSerialPortOutput( + ctx.ProjectID, ctx.ZoneID, instance).Port(1).Do() + if err != nil { + return "", fmt.Errorf("failed to get serial port output: %v", err) + } + return output.Contents, nil +} + type resourcePoolExhaustedError string func (err resourcePoolExhaustedError) Error() string { diff --git a/vm/gce/gce.go b/vm/gce/gce.go index 165ffe4ce..7d973fe2e 100644 --- a/vm/gce/gce.go +++ b/vm/gce/gce.go @@ -15,6 +15,7 @@ import ( "archive/tar" "bytes" "compress/gzip" + "errors" "fmt" "io" "io/ioutil" @@ -164,6 +165,9 @@ func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) { } Logf(0, "wait instance to boot: %v (%v)", name, ip) if err := pool.waitInstanceBoot(ip, sshKey, sshUser); err != nil { + if output, err := pool.GCE.GetSerialPortOutput(name); err == nil { + err = errors.New(err.Error() + "\n\n" + output) + } return nil, err } ok = true -- cgit mrf-deployment