Browse code

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>

Sebastiaan van Stijn authored on 2019/10/09 20:22:59
Showing 1 changed files
... ...
@@ -72,6 +72,7 @@ type Daemon struct {
72 72
 	init                       bool
73 73
 	dockerdBinary              string
74 74
 	log                        logT
75
+	pidFile                    string
75 76
 
76 77
 	// swarm related field
77 78
 	swarmListenAddr string
... ...
@@ -246,11 +247,15 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
246 246
 		return errors.Wrapf(err, "[%s] could not find docker binary in $PATH", d.id)
247 247
 	}
248 248
 
249
+	if d.pidFile == "" {
250
+		d.pidFile = filepath.Join(d.Folder, "docker.pid")
251
+	}
252
+
249 253
 	args := append(d.GlobalFlags,
250 254
 		"--containerd", containerdSocket,
251 255
 		"--data-root", d.Root,
252 256
 		"--exec-root", d.execRoot,
253
-		"--pidfile", fmt.Sprintf("%s/docker.pid", d.Folder),
257
+		"--pidfile", d.pidFile,
254 258
 		fmt.Sprintf("--userland-proxy=%t", d.userlandProxy),
255 259
 		"--containerd-namespace", d.id,
256 260
 		"--containerd-plugins-namespace", d.id+"p",
... ...
@@ -395,7 +400,10 @@ func (d *Daemon) Kill() error {
395 395
 		return err
396 396
 	}
397 397
 
398
-	return os.Remove(fmt.Sprintf("%s/docker.pid", d.Folder))
398
+	if d.pidFile != "" {
399
+		_ = os.Remove(d.pidFile)
400
+	}
401
+	return nil
399 402
 }
400 403
 
401 404
 // Pid returns the pid of the daemon
... ...
@@ -512,7 +520,10 @@ out2:
512 512
 
513 513
 	d.cmd.Wait()
514 514
 
515
-	return os.Remove(fmt.Sprintf("%s/docker.pid", d.Folder))
515
+	if d.pidFile != "" {
516
+		_ = os.Remove(d.pidFile)
517
+	}
518
+	return nil
516 519
 }
517 520
 
518 521
 // Restart will restart the daemon by first stopping it and the starting it.