Add a restarting check to runAttach

Signed-off-by: Shukui Yang <yangshukui@huawei.com>
This commit is contained in:
Shukui Yang 2017-06-08 07:12:39 +08:00
parent e8cc2cf760
commit 90f497302f
2 changed files with 18 additions and 0 deletions

View File

@ -34,6 +34,9 @@ func inspectContainerAndCheckState(ctx context.Context, cli client.APIClient, ar
if c.State.Paused {
return nil, errors.New("You cannot attach to a paused container, unpause it first")
}
if c.State.Restarting {
return nil, errors.New("You cannot attach to a restarting container, wait until it is running")
}
return &c, nil
}

View File

@ -51,6 +51,21 @@ func TestNewAttachCommandErrors(t *testing.T) {
return c, nil
},
},
{
name: "client-restarting",
args: []string{"5cb5bb5e4a3b"},
expectedError: "You cannot attach to a restarting container",
containerInspectFunc: func(containerID string) (types.ContainerJSON, error) {
c := types.ContainerJSON{}
c.ContainerJSONBase = &types.ContainerJSONBase{}
c.ContainerJSONBase.State = &types.ContainerState{
Running: true,
Paused: false,
Restarting: true,
}
return c, nil
},
},
}
for _, tc := range testCases {
buf := new(bytes.Buffer)