diff options
Diffstat (limited to 'test/apiv2')
-rw-r--r-- | test/apiv2/01-basic.at | 4 | ||||
-rw-r--r-- | test/apiv2/26-containersWait.at | 47 | ||||
-rw-r--r-- | test/apiv2/rest_api/test_rest_v2_0_0.py | 129 |
3 files changed, 169 insertions, 11 deletions
diff --git a/test/apiv2/01-basic.at b/test/apiv2/01-basic.at index f550d5fc3..1ddf49c6f 100644 --- a/test/apiv2/01-basic.at +++ b/test/apiv2/01-basic.at @@ -18,8 +18,8 @@ t HEAD libpod/_ping 200 for i in /version version; do t GET $i 200 \ .Components[0].Name="Podman Engine" \ - .Components[0].Details.APIVersion=2.0.0 \ - .Components[0].Details.MinAPIVersion=2.0.0 \ + .Components[0].Details.APIVersion=3.0.0 \ + .Components[0].Details.MinAPIVersion=3.0.0 \ .Components[0].Details.Os=linux \ .ApiVersion=1.40 \ .MinAPIVersion=1.24 \ diff --git a/test/apiv2/26-containersWait.at b/test/apiv2/26-containersWait.at new file mode 100644 index 000000000..3f530c3f0 --- /dev/null +++ b/test/apiv2/26-containersWait.at @@ -0,0 +1,47 @@ +# -*- sh -*- +# +# test more container-related endpoints +# + +red='\e[31m' +nc='\e[0m' + +podman pull "${IMAGE}" &>/dev/null + +# Ensure clean slate +podman rm -a -f &>/dev/null + +CTR="WaitTestingCtr" + +t POST "containers/nonExistent/wait?condition=next-exit" '' 404 + +podman create --name "${CTR}" --entrypoint '["sleep", "0.5"]' "${IMAGE}" + +t POST "containers/${CTR}/wait?condition=non-existent-cond" '' 400 + +t POST "containers/${CTR}/wait?condition=not-running" '' 200 + +t POST "containers/${CTR}/wait?condition=next-exit" '' 200 & +child_pid=$! +podman start "${CTR}" +wait "${child_pid}" + + +# check if headers are sent in advance before body +WAIT_TEST_ERROR="" +curl -I -X POST "http://$HOST:$PORT/containers/${CTR}/wait?condition=next-exit" &> "/dev/null" & +child_pid=$! +sleep 0.5 +if kill -2 "${child_pid}" 2> "/dev/null"; then + echo -e "${red}NOK: Failed to get response headers immediately.${nc}" 1>&2; + WAIT_TEST_ERROR="1" +fi + +t POST "containers/${CTR}/wait?condition=removed" '' 200 & +child_pid=$! +podman container rm "${CTR}" +wait "${child_pid}" + +if [[ "${WAIT_TEST_ERROR}" ]] ; then + exit 1; +fi 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 77674e81b..9ce0803fb 100644 --- a/test/apiv2/rest_api/test_rest_v2_0_0.py +++ b/test/apiv2/rest_api/test_rest_v2_0_0.py @@ -1,7 +1,6 @@ import json import os import random -import shutil import string import subprocess import sys @@ -163,7 +162,7 @@ class TestApi(unittest.TestCase): r = requests.post(_url(ctnr("/containers/{}/resize?h=43&w=80"))) self.assertIn(r.status_code, (200, 409), r.text) if r.status_code == 200: - self.assertIsNone(r.text) + self.assertEqual(r.text, "", r.text) def test_attach_containers(self): self.skipTest("FIXME: Test timeouts") @@ -357,16 +356,17 @@ class TestApi(unittest.TestCase): def test_search_compat(self): url = PODMAN_URL + "/v1.40/images/search" + # Had issues with this test hanging when repositories not happy def do_search1(): - payload = {'term': 'alpine'} + payload = {"term": "alpine"} r = requests.get(url, params=payload, timeout=5) self.assertEqual(r.status_code, 200, r.text) objs = json.loads(r.text) self.assertIn(type(objs), (list,)) def do_search2(): - payload = {'term': 'alpine', 'limit': 1} + payload = {"term": "alpine", "limit": 1} r = requests.get(url, params=payload, timeout=5) self.assertEqual(r.status_code, 200, r.text) objs = json.loads(r.text) @@ -374,7 +374,7 @@ class TestApi(unittest.TestCase): self.assertEqual(len(objs), 1) def do_search3(): - payload = {'term': 'alpine', 'filters': '{"is-official":["true"]}'} + payload = {"term": "alpine", "filters": '{"is-official":["true"]}'} r = requests.get(url, params=payload, timeout=5) self.assertEqual(r.status_code, 200, r.text) objs = json.loads(r.text) @@ -383,14 +383,14 @@ class TestApi(unittest.TestCase): self.assertEqual(len(objs), 1) def do_search4(): - headers = {'X-Registry-Auth': 'null'} - payload = {'term': 'alpine'} + headers = {"X-Registry-Auth": "null"} + payload = {"term": "alpine"} r = requests.get(url, params=payload, headers=headers, timeout=5) self.assertEqual(r.status_code, 200, r.text) def do_search5(): - headers = {'X-Registry-Auth': 'invalid value'} - payload = {'term': 'alpine'} + headers = {"X-Registry-Auth": "invalid value"} + payload = {"term": "alpine"} r = requests.get(url, params=payload, headers=headers, timeout=5) self.assertEqual(r.status_code, 400, r.text) @@ -619,6 +619,117 @@ class TestApi(unittest.TestCase): # self.assertIn(img["Id"], prune_payload["ImagesDeleted"][1]["Deleted"]) self.assertIsNotNone(prune_payload["ImagesDeleted"][1]["Deleted"]) + def test_status_compat(self): + r = requests.post( + PODMAN_URL + "/v1.40/containers/create?name=topcontainer", + json={"Cmd": ["top"], "Image": "alpine:latest"}, + ) + self.assertEqual(r.status_code, 201, r.text) + payload = json.loads(r.text) + container_id = payload["Id"] + self.assertIsNotNone(container_id) + + r = requests.get( + PODMAN_URL + "/v1.40/containers/json", + params={"all": "true", "filters": f'{{"id":["{container_id}"]}}'}, + ) + self.assertEqual(r.status_code, 200, r.text) + payload = json.loads(r.text) + self.assertEqual(payload[0]["Status"], "Created") + + r = requests.post(PODMAN_URL + f"/v1.40/containers/{container_id}/start") + self.assertEqual(r.status_code, 204, r.text) + + r = requests.get( + PODMAN_URL + "/v1.40/containers/json", + params={"all": "true", "filters": f'{{"id":["{container_id}"]}}'}, + ) + self.assertEqual(r.status_code, 200, r.text) + payload = json.loads(r.text) + self.assertTrue(str(payload[0]["Status"]).startswith("Up")) + + r = requests.post(PODMAN_URL + f"/v1.40/containers/{container_id}/pause") + self.assertEqual(r.status_code, 204, r.text) + + r = requests.get( + PODMAN_URL + "/v1.40/containers/json", + params={"all": "true", "filters": f'{{"id":["{container_id}"]}}'}, + ) + self.assertEqual(r.status_code, 200, r.text) + payload = json.loads(r.text) + self.assertTrue(str(payload[0]["Status"]).startswith("Up")) + self.assertTrue(str(payload[0]["Status"]).endswith("(Paused)")) + + r = requests.post(PODMAN_URL + f"/v1.40/containers/{container_id}/unpause") + self.assertEqual(r.status_code, 204, r.text) + r = requests.post(PODMAN_URL + f"/v1.40/containers/{container_id}/stop") + self.assertEqual(r.status_code, 204, r.text) + + r = requests.get( + PODMAN_URL + "/v1.40/containers/json", + params={"all": "true", "filters": f'{{"id":["{container_id}"]}}'}, + ) + self.assertEqual(r.status_code, 200, r.text) + payload = json.loads(r.text) + self.assertTrue(str(payload[0]["Status"]).startswith("Exited")) + + r = requests.delete(PODMAN_URL + f"/v1.40/containers/{container_id}") + self.assertEqual(r.status_code, 204, r.text) + + def test_pod_start_conflict(self): + """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))) + + 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}], + }, + ) + self.assertEqual(r.status_code, 201, r.text) + r = requests.post( + _url("/containers/create"), + json={ + "pod": pod_name[0], + "image": "docker.io/alpine:latest", + "command": ["top"], + }, + ) + self.assertEqual(r.status_code, 201, r.text) + + r = requests.post( + _url("/pods/create"), + json={ + "name": pod_name[1], + "no_infra": False, + "portmappings": [{"host_ip": "127.0.0.1", "host_port": 8889, "container_port": 89}], + }, + ) + self.assertEqual(r.status_code, 201, r.text) + r = requests.post( + _url("/containers/create"), + json={ + "pod": pod_name[1], + "image": "docker.io/alpine:latest", + "command": ["top"], + }, + ) + self.assertEqual(r.status_code, 201, r.text) + + r = requests.post(_url(f"/pods/{pod_name[0]}/start")) + self.assertEqual(r.status_code, 200, r.text) + + r = requests.post(_url(f"/pods/{pod_name[1]}/start")) + self.assertEqual(r.status_code, 409, r.text) + + start = json.loads(r.text) + self.assertGreater(len(start["Errs"]), 0, r.text) + if __name__ == "__main__": unittest.main() |