testutil/daemon: store pidfile-path, and ignore errors when removing

This patch stores the location of the pidfile, so that we can use the
same path that was set to create it. If no pidfile was created, we'll
not try to remove it.

We're now also ignoring errors when removing the pidfile, as they should
not fail the test (especialy if no pidfile was created in the first place,
as that could potentially hide the actual failure).

This may help with "failures" such as the one below:

```
FAIL: check_test.go:347: DockerSwarmSuite.TearDownTest

check_test.go:352:
    d.Stop(c)
/go/src/github.com/docker/docker/internal/test/daemon/daemon.go:414:
    t.Fatalf("Error while stopping the daemon %s : %v", d.id, err)
... Error: Error while stopping the daemon d1512c423813a : remove /go/src/github.com/docker/docker/bundles/test-integration/DockerSwarmSuite.TestServiceLogs/d1512c423813a/docker.pid: no such file or directory
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2019-10-09 13:22:59 +02:00
parent 22662cac57
commit b843b1ffe3
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -72,6 +72,7 @@ type Daemon struct {
init bool
dockerdBinary string
log logT
pidFile string
// swarm related field
swarmListenAddr string
@ -246,11 +247,15 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
return errors.Wrapf(err, "[%s] could not find docker binary in $PATH", d.id)
}
if d.pidFile == "" {
d.pidFile = filepath.Join(d.Folder, "docker.pid")
}
args := append(d.GlobalFlags,
"--containerd", containerdSocket,
"--data-root", d.Root,
"--exec-root", d.execRoot,
"--pidfile", fmt.Sprintf("%s/docker.pid", d.Folder),
"--pidfile", d.pidFile,
fmt.Sprintf("--userland-proxy=%t", d.userlandProxy),
"--containerd-namespace", d.id,
"--containerd-plugins-namespace", d.id+"p",
@ -395,7 +400,10 @@ func (d *Daemon) Kill() error {
return err
}
return os.Remove(fmt.Sprintf("%s/docker.pid", d.Folder))
if d.pidFile != "" {
_ = os.Remove(d.pidFile)
}
return nil
}
// Pid returns the pid of the daemon
@ -512,7 +520,10 @@ out2:
d.cmd.Wait()
return os.Remove(fmt.Sprintf("%s/docker.pid", d.Folder))
if d.pidFile != "" {
_ = os.Remove(d.pidFile)
}
return nil
}
// Restart will restart the daemon by first stopping it and the starting it.