1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

testutil/daemon: wrap errors

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2019-10-09 13:20:47 +02:00
parent 2b3957d0b1
commit 22662cac57
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 10 additions and 10 deletions

View file

@ -575,7 +575,7 @@ func (s *DockerDaemonSuite) TestDaemonExitOnFailure(c *testing.T) {
//attempt to start daemon with incorrect flags (we know -b and --bip conflict) //attempt to start daemon with incorrect flags (we know -b and --bip conflict)
if err := s.d.StartWithError("--bridge", "nosuchbridge", "--bip", "1.1.1.1"); err != nil { if err := s.d.StartWithError("--bridge", "nosuchbridge", "--bip", "1.1.1.1"); err != nil {
//verify we got the right error //verify we got the right error
if !strings.Contains(err.Error(), "Daemon exited") { if !strings.Contains(err.Error(), "daemon exited") {
c.Fatalf("Expected daemon not to start, got %v", err) c.Fatalf("Expected daemon not to start, got %v", err)
} }
// look in the log and make sure we got the message that daemon is shutting down // look in the log and make sure we got the message that daemon is shutting down

View file

@ -90,7 +90,7 @@ func NewDaemon(workingDir string, ops ...Option) (*Daemon, error) {
storageDriver := os.Getenv("DOCKER_GRAPHDRIVER") storageDriver := os.Getenv("DOCKER_GRAPHDRIVER")
if err := os.MkdirAll(SockRoot, 0700); err != nil { if err := os.MkdirAll(SockRoot, 0700); err != nil {
return nil, fmt.Errorf("could not create daemon socket root: %v", err) return nil, errors.Wrapf(err, "failed to create daemon socket root %q", SockRoot)
} }
id := fmt.Sprintf("d%s", stringid.TruncateID(stringid.GenerateRandomID())) id := fmt.Sprintf("d%s", stringid.TruncateID(stringid.GenerateRandomID()))
@ -101,7 +101,7 @@ func NewDaemon(workingDir string, ops ...Option) (*Daemon, error) {
} }
daemonRoot := filepath.Join(daemonFolder, "root") daemonRoot := filepath.Join(daemonFolder, "root")
if err := os.MkdirAll(daemonRoot, 0755); err != nil { if err := os.MkdirAll(daemonRoot, 0755); err != nil {
return nil, fmt.Errorf("could not create daemon root: %v", err) return nil, errors.Wrapf(err, "failed to create daemon root %q", daemonRoot)
} }
userlandProxy := true userlandProxy := true
@ -298,7 +298,7 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
d.logFile = out d.logFile = out
if err := d.cmd.Start(); err != nil { if err := d.cmd.Start(); err != nil {
return errors.Errorf("[%s] could not start daemon container: %v", d.id, err) return errors.Wrapf(err, "[%s] could not start daemon container", d.id)
} }
wait := make(chan error, 1) wait := make(chan error, 1)
@ -338,9 +338,9 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
select { select {
case <-ctx.Done(): case <-ctx.Done():
return errors.Errorf("[%s] Daemon exited and never started: %s", d.id, ctx.Err()) return errors.Wrapf(ctx.Err(), "[%s] daemon exited and never started", d.id)
case err := <-d.Wait: case err := <-d.Wait:
return errors.Errorf("[%s] Daemon exited during startup: %v", d.id, err) return errors.Wrapf(err, "[%s] daemon exited during startup", d.id)
default: default:
rctx, rcancel := context.WithTimeout(context.TODO(), 2*time.Second) rctx, rcancel := context.WithTimeout(context.TODO(), 2*time.Second)
defer rcancel() defer rcancel()
@ -365,7 +365,7 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
d.log.Logf("[%s] daemon started\n", d.id) d.log.Logf("[%s] daemon started\n", d.id)
d.Root, err = d.queryRootDir() d.Root, err = d.queryRootDir()
if err != nil { if err != nil {
return errors.Errorf("[%s] error querying daemon for root directory: %v", d.id, err) return errors.Wrapf(err, "[%s] error querying daemon for root directory", d.id)
} }
return nil return nil
} }
@ -472,7 +472,7 @@ func (d *Daemon) StopWithError() (err error) {
if strings.Contains(err.Error(), "os: process already finished") { if strings.Contains(err.Error(), "os: process already finished") {
return errDaemonNotStarted return errDaemonNotStarted
} }
return errors.Errorf("[%s] could not send signal: %v", d.id, err) return errors.Wrapf(err, "[%s] could not send signal", d.id)
} }
out1: out1:
@ -500,7 +500,7 @@ out2:
} }
d.log.Logf("[%d] attempt #%d/5: daemon is still running with pid %d", i, d.cmd.Process.Pid) d.log.Logf("[%d] attempt #%d/5: daemon is still running with pid %d", i, d.cmd.Process.Pid)
if err := d.cmd.Process.Signal(os.Interrupt); err != nil { if err := d.cmd.Process.Signal(os.Interrupt); err != nil {
return errors.Errorf("[%s] attempt #%d/5 could not send signal: %v", d.id, i, err) return errors.Wrapf(err, "[%s] attempt #%d/5 could not send signal", d.id, i)
} }
} }
} }
@ -577,7 +577,7 @@ func (d *Daemon) ReloadConfig() error {
<-started <-started
if err := signalDaemonReload(d.cmd.Process.Pid); err != nil { if err := signalDaemonReload(d.cmd.Process.Pid); err != nil {
return errors.Errorf("[%s] error signaling daemon reload: %v", d.id, err) return errors.Wrapf(err, "[%s] error signaling daemon reload", d.id)
} }
select { select {
case err := <-errCh: case err := <-errCh: