mirror of
https://github.com/containers/podman.git
synced 2025-06-25 20:26:51 +08:00
Fix for podman network rm (-f) workflow
Signed-off-by: Jakub Guzik <jakubmguzik@gmail.com>
This commit is contained in:
@ -96,7 +96,15 @@ func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, o
|
|||||||
}
|
}
|
||||||
// We need to iterate containers looking to see if they belong to the given network
|
// We need to iterate containers looking to see if they belong to the given network
|
||||||
for _, c := range containers {
|
for _, c := range containers {
|
||||||
if util.StringInSlice(name, c.Config().Networks) {
|
networks, _, err := c.Networks()
|
||||||
|
// if container vanished or network does not exist, go to next container
|
||||||
|
if errors.Is(err, define.ErrNoSuchNetwork) || errors.Is(err, define.ErrNoSuchCtr) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return reports, err
|
||||||
|
}
|
||||||
|
if util.StringInSlice(name, networks) {
|
||||||
// if user passes force, we nuke containers and pods
|
// if user passes force, we nuke containers and pods
|
||||||
if !options.Force {
|
if !options.Force {
|
||||||
// Without the force option, we return an error
|
// Without the force option, we return an error
|
||||||
|
@ -352,6 +352,29 @@ var _ = Describe("Podman network", func() {
|
|||||||
Expect(rmAll.ExitCode()).To(BeZero())
|
Expect(rmAll.ExitCode()).To(BeZero())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman network remove after disconnect when container initially created with the network", func() {
|
||||||
|
SkipIfRootless("disconnect works only in non rootless container")
|
||||||
|
|
||||||
|
container := "test"
|
||||||
|
network := "foo"
|
||||||
|
|
||||||
|
session := podmanTest.Podman([]string{"network", "create", network})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"run", "--name", container, "--network", network, "-d", ALPINE, "top"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"network", "disconnect", network, container})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"network", "rm", network})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
})
|
||||||
|
|
||||||
It("podman network remove bogus", func() {
|
It("podman network remove bogus", func() {
|
||||||
session := podmanTest.Podman([]string{"network", "rm", "bogus"})
|
session := podmanTest.Podman([]string{"network", "rm", "bogus"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
|
Reference in New Issue
Block a user