Improve rktRemove error message

This commit is contained in:
Michael Schurter
2017-11-16 15:45:14 -08:00
parent ce3fbb62b7
commit 9929ac2382
2 changed files with 31 additions and 3 deletions

View File

@@ -229,10 +229,18 @@ func rktManifestMakePortMap(manifest *appcschema.PodManifest, configPortMap map[
// rktRemove pod after it has exited.
func rktRemove(uuid string) error {
errBuf := &bytes.Buffer{}
cmd := exec.Command(rktCmd, "rm", uuid)
cmd.Stdout = ioutil.Discard
cmd.Stderr = ioutil.Discard
return cmd.Run()
cmd.Stderr = errBuf
if err := cmd.Run(); err != nil {
if msg := errBuf.String(); len(msg) > 0 {
return fmt.Errorf("error removing pod %q: %s", uuid, msg)
}
return err
}
return nil
}
// NewRktDriver is used to create a new rkt driver
@@ -791,7 +799,7 @@ func (h *rktHandle) run() {
// Remove the pod
if err := rktRemove(h.uuid); err != nil {
h.logger.Printf("[ERR] driver.rkt: error removing pod %q - must gc manually", h.uuid)
h.logger.Printf("[ERR] driver.rkt: error removing pod %q - must gc manually: %v", h.uuid, err)
} else {
h.logger.Printf("[DEBUG] driver.rkt: removed pod %q", h.uuid)
}

View File

@@ -589,3 +589,23 @@ func TestRktDriver_HandlerExec(t *testing.T) {
t.Fatalf("error killing handle: %v", err)
}
}
func TestRktDriver_Remove_Error(t *testing.T) {
if !testutil.IsTravis() {
t.Parallel()
}
if os.Getenv("NOMAD_TEST_RKT") == "" {
t.Skip("skipping rkt tests")
}
ctestutils.RktCompatible(t)
// Removing a non-existent pod should return an error
if err := rktRemove("00000000-0000-0000-0000-000000000000"); err == nil {
t.Fatalf("expected an error")
}
if err := rktRemove("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"); err == nil {
t.Fatalf("expected an error")
}
}