If the container is not found when removing, it means it's already not
there anymore, so it's safe to ignore. This should reduce a bit some
`TearDown` flakyness..
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
| ... | ... |
@@ -1291,7 +1291,7 @@ func (s *DockerSuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRootfs( |
| 1291 | 1291 |
readOnly: true, |
| 1292 | 1292 |
volumes: defaultVolumes(testVol), // Our bind mount is at /vol2 |
| 1293 | 1293 |
}) |
| 1294 |
- defer deleteContainer(cID) |
|
| 1294 |
+ defer deleteContainer(false, cID) |
|
| 1295 | 1295 |
|
| 1296 | 1296 |
// Attempt to extract to a symlink in the volume which points to a |
| 1297 | 1297 |
// directory outside the volume. This should cause an error because the |
| ... | ... |
@@ -39,7 +39,7 @@ func setupImageWithTag(c *check.C, tag string) (digest.Digest, error) {
|
| 39 | 39 |
c.Assert(err, checker.IsNil, check.Commentf("image tagging failed: %s", out))
|
| 40 | 40 |
|
| 41 | 41 |
// delete the container as we don't need it any more |
| 42 |
- err = deleteContainer(containerName) |
|
| 42 |
+ err = deleteContainer(false, containerName) |
|
| 43 | 43 |
c.Assert(err, checker.IsNil) |
| 44 | 44 |
|
| 45 | 45 |
// push the image |
| ... | ... |
@@ -2117,7 +2117,7 @@ func (s *DockerSuite) TestRunDeallocatePortOnMissingIptablesRule(c *check.C) {
|
| 2117 | 2117 |
if err != nil {
|
| 2118 | 2118 |
c.Fatal(err, out) |
| 2119 | 2119 |
} |
| 2120 |
- if err := deleteContainer(id); err != nil {
|
|
| 2120 |
+ if err := deleteContainer(false, id); err != nil {
|
|
| 2121 | 2121 |
c.Fatal(err) |
| 2122 | 2122 |
} |
| 2123 | 2123 |
|
| ... | ... |
@@ -118,8 +118,16 @@ func newRequestClient(method, endpoint string, data io.Reader, ct, daemon string |
| 118 | 118 |
return req, client, nil |
| 119 | 119 |
} |
| 120 | 120 |
|
| 121 |
-func deleteContainer(container ...string) error {
|
|
| 121 |
+// FIXME(vdemeester) move this away are remove ignoreNoSuchContainer bool |
|
| 122 |
+func deleteContainer(ignoreNoSuchContainer bool, container ...string) error {
|
|
| 122 | 123 |
result := icmd.RunCommand(dockerBinary, append([]string{"rm", "-fv"}, container...)...)
|
| 124 |
+ if ignoreNoSuchContainer && result.Error != nil {
|
|
| 125 |
+ // If the error is "No such container: ..." this means the container doesn't exists anymore, |
|
| 126 |
+ // we can safely ignore that one. |
|
| 127 |
+ if strings.Contains(result.Error.Error(), "No such container") {
|
|
| 128 |
+ return nil |
|
| 129 |
+ } |
|
| 130 |
+ } |
|
| 123 | 131 |
return result.Compare(icmd.Success) |
| 124 | 132 |
} |
| 125 | 133 |
|
| ... | ... |
@@ -138,7 +146,7 @@ func deleteAllContainers(c *check.C) {
|
| 138 | 138 |
c.Assert(err, checker.IsNil, check.Commentf("containers: %v", containers))
|
| 139 | 139 |
|
| 140 | 140 |
if containers != "" {
|
| 141 |
- err = deleteContainer(strings.Split(strings.TrimSpace(containers), "\n")...) |
|
| 141 |
+ err = deleteContainer(true, strings.Split(strings.TrimSpace(containers), "\n")...) |
|
| 142 | 142 |
c.Assert(err, checker.IsNil) |
| 143 | 143 |
} |
| 144 | 144 |
} |
| ... | ... |
@@ -596,7 +604,7 @@ func (f *remoteFileServer) Close() error {
|
| 596 | 596 |
if f.container == "" {
|
| 597 | 597 |
return nil |
| 598 | 598 |
} |
| 599 |
- return deleteContainer(f.container) |
|
| 599 |
+ return deleteContainer(false, f.container) |
|
| 600 | 600 |
} |
| 601 | 601 |
|
| 602 | 602 |
func newRemoteFileServer(ctx *FakeContext) (*remoteFileServer, error) {
|