Skip to content

Commit

Permalink
Merge pull request #9235 from Luap99/fix-9234
Browse files Browse the repository at this point in the history
Fix podman network disconnect wrong NetworkStatus number
  • Loading branch information
openshift-merge-robot authored Feb 4, 2021
2 parents e6e3520 + 5c6ab30 commit b1bd126
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libpod/networking_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ func (c *Container) NetworkDisconnect(nameOrID, netName string, force bool) erro
// update network status if container is not running
networkStatus := c.state.NetworkStatus
// clip out the index of the network
tmpNetworkStatus := make([]*cnitypes.Result, len(networkStatus)-1)
tmpNetworkStatus := make([]*cnitypes.Result, 0, len(networkStatus)-1)
for k, v := range networkStatus {
if index != k {
tmpNetworkStatus = append(tmpNetworkStatus, v)
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/network_connect_disconnect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ var _ = Describe("Podman network connect and disconnect", func() {
dis.WaitWithDefaultTimeout()
Expect(dis.ExitCode()).To(BeZero())

inspect := podmanTest.Podman([]string{"container", "inspect", "test", "--format", "{{len .NetworkSettings.Networks}}"})
inspect.WaitWithDefaultTimeout()
Expect(inspect.ExitCode()).To(BeZero())
Expect(inspect.OutputToString()).To(Equal("0"))

exec = podmanTest.Podman([]string{"exec", "-it", "test", "ip", "addr", "show", "eth0"})
exec.WaitWithDefaultTimeout()
Expect(exec.ExitCode()).ToNot(BeZero())
Expand Down Expand Up @@ -146,6 +151,11 @@ var _ = Describe("Podman network connect and disconnect", func() {
connect.WaitWithDefaultTimeout()
Expect(connect.ExitCode()).To(BeZero())

inspect := podmanTest.Podman([]string{"container", "inspect", "test", "--format", "{{len .NetworkSettings.Networks}}"})
inspect.WaitWithDefaultTimeout()
Expect(inspect.ExitCode()).To(BeZero())
Expect(inspect.OutputToString()).To(Equal("2"))

exec = podmanTest.Podman([]string{"exec", "-it", "test", "ip", "addr", "show", "eth1"})
exec.WaitWithDefaultTimeout()
Expect(exec.ExitCode()).To(BeZero())
Expand All @@ -167,6 +177,11 @@ var _ = Describe("Podman network connect and disconnect", func() {
dis.WaitWithDefaultTimeout()
Expect(dis.ExitCode()).To(BeZero())

inspect := podmanTest.Podman([]string{"container", "inspect", "test", "--format", "{{len .NetworkSettings.Networks}}"})
inspect.WaitWithDefaultTimeout()
Expect(inspect.ExitCode()).To(BeZero())
Expect(inspect.OutputToString()).To(Equal("2"))

start := podmanTest.Podman([]string{"start", "test"})
start.WaitWithDefaultTimeout()
Expect(start.ExitCode()).To(BeZero())
Expand Down Expand Up @@ -202,6 +217,11 @@ var _ = Describe("Podman network connect and disconnect", func() {
dis.WaitWithDefaultTimeout()
Expect(dis.ExitCode()).To(BeZero())

inspect := podmanTest.Podman([]string{"container", "inspect", "test", "--format", "{{len .NetworkSettings.Networks}}"})
inspect.WaitWithDefaultTimeout()
Expect(inspect.ExitCode()).To(BeZero())
Expect(inspect.OutputToString()).To(Equal("1"))

start := podmanTest.Podman([]string{"start", "test"})
start.WaitWithDefaultTimeout()
Expect(start.ExitCode()).To(BeZero())
Expand Down

0 comments on commit b1bd126

Please sign in to comment.