integration: Log the instance output

This adds logging so that you can dig deeper into crashes or issues.
This commit is contained in:
James Shubin
2018-03-09 22:43:07 -05:00
parent 62d1fc7ed3
commit ddefb4e987
2 changed files with 34 additions and 1 deletions

View File

@@ -41,6 +41,9 @@ func TestInstance0(t *testing.T) {
}
if err := m.SimpleDeployLang(code); err != nil {
t.Errorf("failed with: %+v", err)
if output, err := m.CombinedOutput(); err == nil {
t.Errorf("logs from instance:\n\n%s", output)
}
return
}
d := m.Dir()
@@ -98,6 +101,9 @@ func TestInstance1(t *testing.T) {
if !fail && err != nil {
t.Errorf("failed with: %+v", err)
if output, err := m.CombinedOutput(); err == nil {
t.Errorf("logs from instance:\n\n%s", output)
}
return
}
if fail && err == nil {
@@ -207,9 +213,15 @@ func TestCluster1(t *testing.T) {
if d := c.Dir(); d != "" {
t.Logf("test ran in:\n%s", d)
}
instances := c.Instances()
if !fail && err != nil {
t.Errorf("failed with: %+v", err)
for _, h := range hosts {
if output, err := instances[h].CombinedOutput(); err == nil {
t.Errorf("logs from instance `%s`:\n\n%s", h, output)
}
}
return
}
if fail && err == nil {
@@ -221,7 +233,6 @@ func TestCluster1(t *testing.T) {
return
}
instances := c.Instances()
for _, h := range hosts {
instance := instances[h]
d := instance.Dir()

View File

@@ -46,6 +46,10 @@ const (
// converged status tracking.
ConvergedStatusFile = "csf.txt"
// StdoutStderrFile is the name of the file which is used for the
// command output.
StdoutStderrFile = "stdoutstderr.txt"
// longTimeout is a high bound of time we're willing to wait for events.
// If we exceed this timeout, then it's likely we are blocked somewhere.
longTimeout = 30 // seconds
@@ -206,6 +210,15 @@ func (obj *Instance) Run(seeds []*Instance) error {
fmt.Sprintf("MGMT_TEST_ROOT=%s", obj.testRootDirectory),
}
// output file for storing logs
file, err := os.Create(path.Join(obj.dir, StdoutStderrFile))
if err != nil {
return errwrap.Wrapf(err, "error creating log file")
}
defer file.Close()
obj.cmd.Stdout = file
obj.cmd.Stderr = file
if err := obj.cmd.Start(); err != nil {
return errwrap.Wrapf(err, "error starting mgmt")
}
@@ -368,3 +381,12 @@ func (obj *Instance) DeployLang(code string) error {
func (obj *Instance) Dir() string {
return obj.dir
}
// CombinedOutput returns the logged output from the instance.
func (obj *Instance) CombinedOutput() (string, error) {
contents, err := ioutil.ReadFile(path.Join(obj.dir, StdoutStderrFile))
if err != nil {
return "", err
}
return string(contents), nil
}