mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #31522 from vdemeester/fix-clean-in-env
Ignore no such container in testEnv.Clean
This commit is contained in:
commit
cddb8981ca
5 changed files with 16 additions and 16 deletions
|
@ -1261,7 +1261,7 @@ func (s *DockerSuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRootfs(
|
|||
readOnly: true,
|
||||
volumes: defaultVolumes(testVol), // Our bind mount is at /vol2
|
||||
})
|
||||
defer deleteContainer(false, cID)
|
||||
defer deleteContainer(cID)
|
||||
|
||||
// Attempt to extract to a symlink in the volume which points to a
|
||||
// directory outside the volume. This should cause an error because the
|
||||
|
|
|
@ -42,7 +42,7 @@ func setupImageWithTag(c *check.C, tag string) (digest.Digest, error) {
|
|||
c.Assert(err, checker.IsNil, check.Commentf("image tagging failed: %s", out))
|
||||
|
||||
// delete the container as we don't need it any more
|
||||
err = deleteContainer(false, containerName)
|
||||
err = deleteContainer(containerName)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
// push the image
|
||||
|
|
|
@ -2029,7 +2029,7 @@ func (s *DockerSuite) TestRunDeallocatePortOnMissingIptablesRule(c *check.C) {
|
|||
icmd.RunCommand("iptables", "-D", "DOCKER", "-d", fmt.Sprintf("%s/32", ip),
|
||||
"!", "-i", "docker0", "-o", "docker0", "-p", "tcp", "-m", "tcp", "--dport", "23", "-j", "ACCEPT").Assert(c, icmd.Success)
|
||||
|
||||
if err := deleteContainer(false, id); err != nil {
|
||||
if err := deleteContainer(id); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -36,16 +36,8 @@ func daemonHost() string {
|
|||
}
|
||||
|
||||
// FIXME(vdemeester) move this away are remove ignoreNoSuchContainer bool
|
||||
func deleteContainer(ignoreNoSuchContainer bool, container ...string) error {
|
||||
result := icmd.RunCommand(dockerBinary, append([]string{"rm", "-fv"}, container...)...)
|
||||
if ignoreNoSuchContainer && result.Error != nil {
|
||||
// If the error is "No such container: ..." this means the container doesn't exists anymore,
|
||||
// we can safely ignore that one.
|
||||
if strings.Contains(result.Stderr(), "No such container") {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return result.Compare(icmd.Success)
|
||||
func deleteContainer(container ...string) error {
|
||||
return icmd.RunCommand(dockerBinary, append([]string{"rm", "-fv"}, container...)...).Compare(icmd.Success)
|
||||
}
|
||||
|
||||
func getAllContainers(c *check.C) string {
|
||||
|
@ -58,7 +50,7 @@ func getAllContainers(c *check.C) string {
|
|||
func deleteAllContainers(c *check.C) {
|
||||
containers := getAllContainers(c)
|
||||
if containers != "" {
|
||||
err := deleteContainer(true, strings.Split(strings.TrimSpace(containers), "\n")...)
|
||||
err := deleteContainer(strings.Split(strings.TrimSpace(containers), "\n")...)
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
}
|
||||
|
@ -346,7 +338,7 @@ func (f *remoteFileServer) Close() error {
|
|||
if f.container == "" {
|
||||
return nil
|
||||
}
|
||||
return deleteContainer(false, f.container)
|
||||
return deleteContainer(f.container)
|
||||
}
|
||||
|
||||
func newRemoteFileServer(c *check.C, ctx *FakeContext) *remoteFileServer {
|
||||
|
|
|
@ -53,7 +53,15 @@ func getPausedContainers(t testingT, dockerBinary string) []string {
|
|||
func deleteAllContainers(t testingT, dockerBinary string) {
|
||||
containers := getAllContainers(t, dockerBinary)
|
||||
if len(containers) > 0 {
|
||||
icmd.RunCommand(dockerBinary, append([]string{"rm", "-fv"}, containers...)...).Assert(t, icmd.Success)
|
||||
result := icmd.RunCommand(dockerBinary, append([]string{"rm", "-fv"}, containers...)...)
|
||||
if result.Error != nil {
|
||||
// If the error is "No such container: ..." this means the container doesn't exists anymore,
|
||||
// we can safely ignore that one.
|
||||
if strings.Contains(result.Stderr(), "No such container") {
|
||||
return
|
||||
}
|
||||
t.Fatalf("error removing containers %v : %v (%s)", containers, result.Error, result.Combined())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue