summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2020-12-04 13:44:33 -0700
committerJhon Honce <jhonce@redhat.com>2020-12-04 13:44:33 -0700
commit53c8bc5a5e48f02fb0c1f1a87ec5214fb47f0b93 (patch)
tree02832295349dfbff4ea821320ccd8f59cbfba72c
parentf01630acf35a11aecdbfb9b77b249dcec85e67b5 (diff)
downloadpodman-53c8bc5a5e48f02fb0c1f1a87ec5214fb47f0b93.tar.gz
podman-53c8bc5a5e48f02fb0c1f1a87ec5214fb47f0b93.tar.bz2
podman-53c8bc5a5e48f02fb0c1f1a87ec5214fb47f0b93.zip
Jira RUN-1106 Network handlers updates
* Add network API tests * Update network create endpoint to return ID not Name Audit: - GET /networks ListNetworks - GET /networks/{id} InspectNetwork - DELETE /networks/{id} RemoveNetwork - POST /networks/create CreateNetwork - POST /networks/prune 405 not implemented Signed-off-by: Jhon Honce <jhonce@redhat.com>
-rw-r--r--pkg/api/handlers/compat/networks.go9
-rw-r--r--test/apiv2/rest_api/test_rest_v2_0_0.py43
2 files changed, 48 insertions, 4 deletions
diff --git a/pkg/api/handlers/compat/networks.go b/pkg/api/handlers/compat/networks.go
index b4f3aa2f1..fe13971b0 100644
--- a/pkg/api/handlers/compat/networks.go
+++ b/pkg/api/handlers/compat/networks.go
@@ -271,11 +271,16 @@ func CreateNetwork(w http.ResponseWriter, r *http.Request) {
return
}
+ net, err := getNetworkResourceByNameOrID(name, runtime, nil)
+ if err != nil {
+ utils.InternalServerError(w, err)
+ return
+ }
body := struct {
Id string
Warning []string
}{
- Id: name,
+ Id: net.ID,
}
utils.WriteResponse(w, http.StatusCreated, body)
}
@@ -320,7 +325,7 @@ func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
return
}
- utils.WriteResponse(w, http.StatusNoContent, "")
+ utils.WriteResponse(w, http.StatusNoContent, nil)
}
// Connect adds a container to a network
diff --git a/test/apiv2/rest_api/test_rest_v2_0_0.py b/test/apiv2/rest_api/test_rest_v2_0_0.py
index dc92a2966..d4608a5f7 100644
--- a/test/apiv2/rest_api/test_rest_v2_0_0.py
+++ b/test/apiv2/rest_api/test_rest_v2_0_0.py
@@ -1,11 +1,13 @@
import json
+import random
+import string
import subprocess
-import sys
-import time
import unittest
from multiprocessing import Process
import requests
+import sys
+import time
from dateutil.parser import parse
from test.apiv2.rest_api import Podman
@@ -384,6 +386,43 @@ class TestApi(unittest.TestCase):
for k in required_keys:
self.assertIn(k, o)
+ def test_network_compat(self):
+ name = "Network_" + "".join(random.choice(string.ascii_letters) for i in range(10))
+
+ # Cannot test for 0 existing networks because default "podman" network always exists
+
+ create = requests.post(PODMAN_URL + "/v1.40/networks/create", json={"Name": name})
+ self.assertEqual(create.status_code, 201, create.content)
+ obj = json.loads(create.content)
+ self.assertIn(type(obj), (dict,))
+ self.assertIn("Id", obj)
+ ident = obj["Id"]
+ self.assertNotEqual(name, ident)
+
+ ls = requests.get(PODMAN_URL + "/v1.40/networks")
+ self.assertEqual(ls.status_code, 200, ls.content)
+ objs = json.loads(ls.content)
+ self.assertIn(type(objs), (list,))
+
+ found = False
+ for network in objs:
+ if network["Name"] == name:
+ found = True
+ self.assertTrue(found, f"Network {name} not found")
+
+ inspect = requests.get(PODMAN_URL + f"/v1.40/networks/{ident}")
+ self.assertEqual(inspect.status_code, 200, inspect.content)
+ obj = json.loads(create.content)
+ self.assertIn(type(obj), (dict,))
+
+ inspect = requests.delete(PODMAN_URL + f"/v1.40/networks/{ident}")
+ self.assertEqual(inspect.status_code, 204, inspect.content)
+ inspect = requests.get(PODMAN_URL + f"/v1.40/networks/{ident}")
+ self.assertEqual(inspect.status_code, 404, inspect.content)
+
+ prune = requests.post(PODMAN_URL + "/v1.40/networks/prune")
+ self.assertEqual(prune.status_code, 405, prune.content)
+
if __name__ == "__main__":
unittest.main()