vm/gce: provide VM console output on boot failures

"can't ssh into the instance" is not a very useful error.
This commit is contained in:
Dmitry Vyukov 2017-11-19 12:29:00 +01:00
parent 2994ea0981
commit 9badd05327
2 changed files with 14 additions and 0 deletions

View File

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

View File

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