This is a regression test for #36145 It ensures that a container can be started when the daemon was improperly shutdown when the daemon is brought back up. The regression is due to improper error handling preventing a container from being restored and as such have the resources cleaned up. To test
(t *testing.T)
| 33 | // the container process, then start dockerd back up and attempt to start the |
| 34 | // container again. |
| 35 | func TestContainerStartOnDaemonRestart(t *testing.T) { |
| 36 | skip.If(t, testEnv.IsRemoteDaemon, "cannot start daemon on remote test run") |
| 37 | skip.If(t, testEnv.DaemonInfo.OSType == "windows") |
| 38 | skip.If(t, testEnv.IsRootless) |
| 39 | t.Parallel() |
| 40 | |
| 41 | ctx := testutil.StartSpan(baseContext, t) |
| 42 | |
| 43 | d := daemon.New(t) |
| 44 | d.StartWithBusybox(ctx, t, "--iptables=false", "--ip6tables=false") |
| 45 | defer d.Stop(t) |
| 46 | |
| 47 | c := d.NewClientT(t) |
| 48 | |
| 49 | cID := container.Create(ctx, t, c) |
| 50 | defer c.ContainerRemove(ctx, cID, client.ContainerRemoveOptions{Force: true}) |
| 51 | |
| 52 | _, err := c.ContainerStart(ctx, cID, client.ContainerStartOptions{}) |
| 53 | assert.Check(t, err, "error starting test container") |
| 54 | |
| 55 | inspect, err := c.ContainerInspect(ctx, cID, client.ContainerInspectOptions{}) |
| 56 | assert.Check(t, err, "error getting inspect data") |
| 57 | |
| 58 | ppid := getContainerdShimPid(t, inspect.Container) |
| 59 | |
| 60 | err = d.Kill() |
| 61 | assert.Check(t, err, "failed to kill test daemon") |
| 62 | |
| 63 | err = unix.Kill(inspect.Container.State.Pid, unix.SIGKILL) |
| 64 | assert.Check(t, err, "failed to kill container process") |
| 65 | |
| 66 | err = unix.Kill(ppid, unix.SIGKILL) |
| 67 | assert.Check(t, err, "failed to kill containerd-shim") |
| 68 | |
| 69 | d.Start(t, "--iptables=false", "--ip6tables=false") |
| 70 | |
| 71 | _, err = c.ContainerStart(ctx, cID, client.ContainerStartOptions{}) |
| 72 | assert.Check(t, err, "failed to start test container") |
| 73 | } |
| 74 | |
| 75 | func getContainerdShimPid(t *testing.T, c containertypes.InspectResponse) int { |
| 76 | statB, err := os.ReadFile(fmt.Sprintf("/proc/%d/stat", c.State.Pid)) |
nothing calls this directly
no test coverage detected
searching dependent graphs…