Signed-off-by: allencloud <allen.sun@daocloud.io>
| ... | ... |
@@ -6,7 +6,6 @@ import ( |
| 6 | 6 |
"io" |
| 7 | 7 |
"net/http" |
| 8 | 8 |
"strconv" |
| 9 |
- "strings" |
|
| 10 | 9 |
"syscall" |
| 11 | 10 |
"time" |
| 12 | 11 |
|
| ... | ... |
@@ -386,10 +385,6 @@ func (s *containerRouter) deleteContainers(ctx context.Context, w http.ResponseW |
| 386 | 386 |
} |
| 387 | 387 |
|
| 388 | 388 |
if err := s.backend.ContainerRm(name, config); err != nil {
|
| 389 |
- // Force a 404 for the empty string |
|
| 390 |
- if strings.Contains(strings.ToLower(err.Error()), "prefix can't be empty") {
|
|
| 391 |
- return fmt.Errorf("no such container: \"\"")
|
|
| 392 |
- } |
|
| 393 | 389 |
return err |
| 394 | 390 |
} |
| 395 | 391 |
|
| ... | ... |
@@ -26,7 +26,8 @@ func (daemon *Daemon) ContainerRm(name string, config *types.ContainerRmConfig) |
| 26 | 26 |
|
| 27 | 27 |
// Container state RemovalInProgress should be used to avoid races. |
| 28 | 28 |
if inProgress := container.SetRemovalInProgress(); inProgress {
|
| 29 |
- return nil |
|
| 29 |
+ err := fmt.Errorf("removal of container %s is already in progress", name)
|
|
| 30 |
+ return errors.NewBadRequestError(err) |
|
| 30 | 31 |
} |
| 31 | 32 |
defer container.ResetRemovalInProgress() |
| 32 | 33 |
|
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package daemon |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "fmt" |
|
| 4 | 5 |
"io/ioutil" |
| 5 | 6 |
"os" |
| 6 | 7 |
"testing" |
| ... | ... |
@@ -34,9 +35,9 @@ func TestContainerDoubleDelete(t *testing.T) {
|
| 34 | 34 |
// Mark the container as having a delete in progress |
| 35 | 35 |
container.SetRemovalInProgress() |
| 36 | 36 |
|
| 37 |
- // Try to remove the container when its start is removalInProgress. |
|
| 38 |
- // It should ignore the container and not return an error. |
|
| 39 |
- if err := daemon.ContainerRm(container.ID, &types.ContainerRmConfig{ForceRemove: true}); err != nil {
|
|
| 40 |
- t.Fatal(err) |
|
| 37 |
+ // Try to remove the container when its state is removalInProgress. |
|
| 38 |
+ // It should return an error indicating it is under removal progress. |
|
| 39 |
+ if err := daemon.ContainerRm(container.ID, &types.ContainerRmConfig{ForceRemove: true}); err == nil {
|
|
| 40 |
+ t.Fatalf("expected err: %v, got nil", fmt.Sprintf("removal of container %s is already in progress", container.ID))
|
|
| 41 | 41 |
} |
| 42 | 42 |
} |
| ... | ... |
@@ -128,6 +128,7 @@ This section lists each version from latest to oldest. Each listing includes a |
| 128 | 128 |
* `GET /networks/` endpoint now correctly returns a list of *all* networks, |
| 129 | 129 |
instead of the default network if a trailing slash is provided, but no `name` |
| 130 | 130 |
or `id`. |
| 131 |
+* `DELETE /containers/(name)` endpoint now returns an error of `removal of container name is already in progress` with status code of 400, when container name is in a state of removal in progress. |
|
| 131 | 132 |
|
| 132 | 133 |
### v1.24 API changes |
| 133 | 134 |
|