Skip to content

Commit

Permalink
Correct compat network prune response
Browse files Browse the repository at this point in the history
Correcting the structure of the compat network prune response.  They
should follow {"NetworksDeleted": [<network_name>",...]}

Fixes: containers#9310

Signed-off-by: baude <[email protected]>
  • Loading branch information
baude committed Feb 10, 2021
1 parent 4d604c1 commit f28b08f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/api/handlers/compat/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ func Prune(w http.ResponseWriter, r *http.Request) {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
return
}
type response struct {
NetworksDeleted []string
}
var prunedNetworks []string //nolint
for _, pr := range pruneReports {
if pr.Error != nil {
Expand All @@ -408,5 +411,5 @@ func Prune(w http.ResponseWriter, r *http.Request) {
}
prunedNetworks = append(prunedNetworks, pr.Name)
}
utils.WriteResponse(w, http.StatusOK, prunedNetworks)
utils.WriteResponse(w, http.StatusOK, response{NetworksDeleted: prunedNetworks})
}
8 changes: 8 additions & 0 deletions test/apiv2/rest_api/test_rest_v2_0_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,16 @@ def test_network_compat(self):
inspect = requests.get(PODMAN_URL + f"/v1.40/networks/{ident}")
self.assertEqual(inspect.status_code, 404, inspect.content)

# network prune
prune_name = "Network_" + "".join(random.choice(string.ascii_letters) for i in range(10))
prune_create = requests.post(PODMAN_URL + "/v1.40/networks/create", json={"Name": prune_name})
self.assertEqual(create.status_code, 201, prune_create.content)

prune = requests.post(PODMAN_URL + "/v1.40/networks/prune")
self.assertEqual(prune.status_code, 200, prune.content)
obj = json.loads(prune.content)
self.assertTrue(prune_name in obj["NetworksDeleted"])


def test_volumes_compat(self):
name = "Volume_" + "".join(random.choice(string.ascii_letters) for i in range(10))
Expand Down

0 comments on commit f28b08f

Please sign in to comment.