Skip to content

Commit

Permalink
Fix network remove for the podman remote client
Browse files Browse the repository at this point in the history
The podman remote client ignored the force option due a typo.
If an error occured the remote client would panic with an
index out of range error.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Paul Holzinger committed Sep 28, 2020
1 parent 393120c commit 343a10e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/bindings/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func Remove(ctx context.Context, nameOrID string, force *bool) ([]*entities.Netw
}
params := url.Values{}
if force != nil {
params.Set("size", strconv.FormatBool(*force))
params.Set("force", strconv.FormatBool(*force))
}
response, err := conn.DoRequest(nil, http.MethodDelete, "/networks/%s", params, nil, nameOrID)
if err != nil {
Expand Down
11 changes: 8 additions & 3 deletions pkg/domain/infra/tunnel/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ func (ic *ContainerEngine) NetworkInspect(ctx context.Context, namesOrIds []stri
func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, options entities.NetworkRmOptions) ([]*entities.NetworkRmReport, error) {
reports := make([]*entities.NetworkRmReport, 0, len(namesOrIds))
for _, name := range namesOrIds {
report, err := network.Remove(ic.ClientCxt, name, &options.Force)
response, err := network.Remove(ic.ClientCxt, name, &options.Force)
if err != nil {
report[0].Err = err
report := &entities.NetworkRmReport{
Name: name,
Err: err,
}
reports = append(reports, report)
} else {
reports = append(reports, response...)
}
reports = append(reports, report...)
}
return reports, nil
}
Expand Down
19 changes: 19 additions & 0 deletions test/e2e/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,23 @@ var _ = Describe("Podman network", func() {
Expect(session.ExitCode()).To(BeZero())
Expect(session.OutputToString()).To(Not(ContainSubstring(netName)))
})

It("podman network remove with two networks", func() {
netName1 := "net1"
session := podmanTest.Podman([]string{"network", "create", netName1})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(BeZero())

netName2 := "net2"
session = podmanTest.Podman([]string{"network", "create", netName2})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(BeZero())

session = podmanTest.Podman([]string{"network", "rm", netName1, netName2})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(BeZero())
lines := session.OutputToStringArray()
Expect(lines[0]).To(Equal(netName1))
Expect(lines[1]).To(Equal(netName2))
})
})

0 comments on commit 343a10e

Please sign in to comment.