summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/api/server/register_networks.go45
-rw-r--r--test/apiv2/rest_api/__init__.py26
-rw-r--r--test/apiv2/rest_api/test_rest_v2_0_0.py59
-rw-r--r--test/system/260-sdnotify.bats13
4 files changed, 70 insertions, 73 deletions
diff --git a/pkg/api/server/register_networks.go b/pkg/api/server/register_networks.go
index 68a8d4ae4..c54de952f 100644
--- a/pkg/api/server/register_networks.go
+++ b/pkg/api/server/register_networks.go
@@ -220,28 +220,6 @@ func (s *APIServer) registerNetworkHandlers(r *mux.Router) error {
*/
r.HandleFunc(VersionedPath("/libpod/networks/{name}"), s.APIHandler(libpod.RemoveNetwork)).Methods(http.MethodDelete)
- // swagger:operation GET /libpod/networks/{name}/json libpod libpodInspectNetwork
- // ---
- // tags:
- // - networks
- // summary: Inspect a network
- // description: Display low level configuration for a CNI network
- // parameters:
- // - in: path
- // name: name
- // type: string
- // required: true
- // description: the name of the network
- // produces:
- // - application/json
- // responses:
- // 200:
- // $ref: "#/responses/NetworkInspectReport"
- // 404:
- // $ref: "#/responses/NoSuchNetwork"
- // 500:
- // $ref: "#/responses/InternalError"
- r.HandleFunc(VersionedPath("/libpod/networks/{name}/json"), s.APIHandler(libpod.InspectNetwork)).Methods(http.MethodGet)
// swagger:operation GET /libpod/networks/{name}/exists libpod libpodExistsNetwork
// ---
// tags:
@@ -289,6 +267,29 @@ func (s *APIServer) registerNetworkHandlers(r *mux.Router) error {
// 500:
// $ref: "#/responses/InternalError"
r.HandleFunc(VersionedPath("/libpod/networks/json"), s.APIHandler(libpod.ListNetworks)).Methods(http.MethodGet)
+ // swagger:operation GET /libpod/networks/{name}/json libpod libpodInspectNetwork
+ // ---
+ // tags:
+ // - networks
+ // summary: Inspect a network
+ // description: Display low level configuration for a CNI network
+ // parameters:
+ // - in: path
+ // name: name
+ // type: string
+ // required: true
+ // description: the name of the network
+ // produces:
+ // - application/json
+ // responses:
+ // 200:
+ // $ref: "#/responses/NetworkInspectReport"
+ // 404:
+ // $ref: "#/responses/NoSuchNetwork"
+ // 500:
+ // $ref: "#/responses/InternalError"
+ r.HandleFunc(VersionedPath("/libpod/networks/{name}/json"), s.APIHandler(libpod.InspectNetwork)).Methods(http.MethodGet)
+ r.HandleFunc(VersionedPath("/libpod/networks/{name}"), s.APIHandler(libpod.InspectNetwork)).Methods(http.MethodGet)
// swagger:operation POST /libpod/networks/create libpod libpodCreateNetwork
// ---
// tags:
diff --git a/test/apiv2/rest_api/__init__.py b/test/apiv2/rest_api/__init__.py
index b7b8a7649..0ad6b51b3 100644
--- a/test/apiv2/rest_api/__init__.py
+++ b/test/apiv2/rest_api/__init__.py
@@ -3,6 +3,7 @@ import json
import os
import shutil
import subprocess
+import sys
import tempfile
@@ -27,7 +28,9 @@ class Podman(object):
self.cmd.append("--root=" + os.path.join(self.anchor_directory, "crio"))
self.cmd.append("--runroot=" + os.path.join(self.anchor_directory, "crio-run"))
- os.environ["CONTAINERS_REGISTRIES_CONF"] = os.path.join(self.anchor_directory, "registry.conf")
+ os.environ["CONTAINERS_REGISTRIES_CONF"] = os.path.join(
+ self.anchor_directory, "registry.conf"
+ )
p = configparser.ConfigParser()
p.read_dict(
{
@@ -114,13 +117,20 @@ class Podman(object):
check = kwargs.get("check", False)
shell = kwargs.get("shell", False)
- return subprocess.run(
- cmd,
- shell=shell,
- check=check,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- )
+ try:
+ return subprocess.run(
+ cmd,
+ shell=shell,
+ check=check,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ )
+ except subprocess.CalledProcessError as e:
+ if e.stdout:
+ sys.stdout.write("\nRun Stdout:\n" + e.stdout.decode("utf-8"))
+ if e.stderr:
+ sys.stderr.write("\nRun Stderr:\n" + e.stderr.decode("utf-8"))
+ raise
def tear_down(self):
shutil.rmtree(self.anchor_directory, ignore_errors=True)
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 8a78f5185..c0b61ea85 100644
--- a/test/apiv2/rest_api/test_rest_v2_0_0.py
+++ b/test/apiv2/rest_api/test_rest_v2_0_0.py
@@ -50,23 +50,20 @@ class TestApi(unittest.TestCase):
def setUp(self):
super().setUp()
- try:
- TestApi.podman.run("run", "alpine", "/bin/ls", check=True)
- except subprocess.CalledProcessError as e:
- if e.stdout:
- sys.stdout.write("\nRun Stdout:\n" + e.stdout.decode("utf-8"))
- if e.stderr:
- sys.stderr.write("\nRun Stderr:\n" + e.stderr.decode("utf-8"))
- raise
+ TestApi.podman.run("run", "alpine", "/bin/ls", check=True)
+
+ def tearDown(self) -> None:
+ super().tearDown()
+
+ TestApi.podman.run("pod", "rm", "--all", "--force", check=True)
+ TestApi.podman.run("rm", "--all", "--force", check=True)
@classmethod
def setUpClass(cls):
super().setUpClass()
TestApi.podman = Podman()
- TestApi.service = TestApi.podman.open(
- "system", "service", "tcp:localhost:8080", "--time=0"
- )
+ TestApi.service = TestApi.podman.open("system", "service", "tcp:localhost:8080", "--time=0")
# give the service some time to be ready...
time.sleep(2)
@@ -243,9 +240,7 @@ class TestApi(unittest.TestCase):
def test_post_create_compat(self):
"""Create network and connect container during create"""
- net = requests.post(
- PODMAN_URL + "/v1.40/networks/create", json={"Name": "TestNetwork"}
- )
+ net = requests.post(PODMAN_URL + "/v1.40/networks/create", json={"Name": "TestNetwork"})
self.assertEqual(net.status_code, 201, net.text)
create = requests.post(
@@ -454,15 +449,11 @@ class TestApi(unittest.TestCase):
self.assertIn(k, o)
def test_network_compat(self):
- name = "Network_" + "".join(
- random.choice(string.ascii_letters) for i in range(10)
- )
+ 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}
- )
+ 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,))
@@ -492,9 +483,7 @@ class TestApi(unittest.TestCase):
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_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}
)
@@ -506,9 +495,7 @@ class TestApi(unittest.TestCase):
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)
- )
+ name = "Volume_" + "".join(random.choice(string.ascii_letters) for i in range(10))
ls = requests.get(PODMAN_URL + "/v1.40/volumes")
self.assertEqual(ls.status_code, 200, ls.content)
@@ -524,9 +511,7 @@ class TestApi(unittest.TestCase):
for k in required_keys:
self.assertIn(k, obj)
- create = requests.post(
- PODMAN_URL + "/v1.40/volumes/create", json={"Name": name}
- )
+ create = requests.post(PODMAN_URL + "/v1.40/volumes/create", json={"Name": name})
self.assertEqual(create.status_code, 201, create.content)
# See https://docs.docker.com/engine/api/v1.40/#operation/VolumeCreate
@@ -703,21 +688,15 @@ class TestApi(unittest.TestCase):
"""Verify issue #8865"""
pod_name = list()
- pod_name.append(
- "Pod_" + "".join(random.choice(string.ascii_letters) for i in range(10))
- )
- pod_name.append(
- "Pod_" + "".join(random.choice(string.ascii_letters) for i in range(10))
- )
+ pod_name.append("Pod_" + "".join(random.choice(string.ascii_letters) for i in range(10)))
+ pod_name.append("Pod_" + "".join(random.choice(string.ascii_letters) for i in range(10)))
r = requests.post(
_url("/pods/create"),
json={
"name": pod_name[0],
"no_infra": False,
- "portmappings": [
- {"host_ip": "127.0.0.1", "host_port": 8889, "container_port": 89}
- ],
+ "portmappings": [{"host_ip": "127.0.0.1", "host_port": 8889, "container_port": 89}],
},
)
self.assertEqual(r.status_code, 201, r.text)
@@ -736,9 +715,7 @@ class TestApi(unittest.TestCase):
json={
"name": pod_name[1],
"no_infra": False,
- "portmappings": [
- {"host_ip": "127.0.0.1", "host_port": 8889, "container_port": 89}
- ],
+ "portmappings": [{"host_ip": "127.0.0.1", "host_port": 8889, "container_port": 89}],
},
)
self.assertEqual(r.status_code, 201, r.text)
diff --git a/test/system/260-sdnotify.bats b/test/system/260-sdnotify.bats
index a5fa0f4e6..8bf49eb1d 100644
--- a/test/system/260-sdnotify.bats
+++ b/test/system/260-sdnotify.bats
@@ -42,14 +42,22 @@ function _start_socat() {
_SOCAT_LOG="$PODMAN_TMPDIR/socat.log"
rm -f $_SOCAT_LOG
- socat unix-recvfrom:"$NOTIFY_SOCKET",fork \
- system:"(cat;echo) >> $_SOCAT_LOG" &
+ # Execute in subshell so we can close fd3 (which BATS uses).
+ # This is a superstitious ritual to try to avoid leaving processes behind,
+ # and thus prevent CI hangs.
+ (exec socat unix-recvfrom:"$NOTIFY_SOCKET",fork \
+ system:"(cat;echo) >> $_SOCAT_LOG" 3>&-) &
_SOCAT_PID=$!
}
# Stop the socat background process and clean up logs
function _stop_socat() {
if [[ -n "$_SOCAT_PID" ]]; then
+ # Kill all child processes, then the process itself.
+ # This is a superstitious incantation to avoid leaving processes behind.
+ # The '|| true' is because only f35 leaves behind socat processes;
+ # f33 (and perhaps others?) behave nicely. ARGH!
+ pkill -P $_SOCAT_PID || true
kill $_SOCAT_PID
fi
_SOCAT_PID=
@@ -57,6 +65,7 @@ function _stop_socat() {
if [[ -n "$_SOCAT_LOG" ]]; then
rm -f $_SOCAT_LOG
fi
+ _SOCAT_LOG=
}
# Check that MAINPID=xxxxx points to a running conmon process