summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-01-08 06:56:15 -0500
committerGitHub <noreply@github.com>2021-01-08 06:56:15 -0500
commita0b432d29d18c7385c2c976249bdc4eec95d335a (patch)
tree9e40297a48967cb64d2f3325f9ee15b3ea31aa7f /test
parent78cda71372485f163909525f8d07194920968486 (diff)
parentb059e1044f5a1bac6a531e6241e24f82c8c6a9c0 (diff)
downloadpodman-a0b432d29d18c7385c2c976249bdc4eec95d335a.tar.gz
podman-a0b432d29d18c7385c2c976249bdc4eec95d335a.tar.bz2
podman-a0b432d29d18c7385c2c976249bdc4eec95d335a.zip
Merge pull request #8912 from jwhonce/issues/8891
Restore compatible API for prune endpoints
Diffstat (limited to 'test')
-rw-r--r--test/apiv2/rest_api/test_rest_v2_0_0.py62
1 files changed, 59 insertions, 3 deletions
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 2f9e62149..cc66dd5af 100644
--- a/test/apiv2/rest_api/test_rest_v2_0_0.py
+++ b/test/apiv2/rest_api/test_rest_v2_0_0.py
@@ -1,13 +1,15 @@
import json
+import os
import random
+import shutil
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
@@ -449,7 +451,7 @@ class TestApi(unittest.TestCase):
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)
+ self.assertEqual(prune.status_code, 404, prune.content)
def test_volumes_compat(self):
name = "Volume_" + "".join(random.choice(string.ascii_letters) for i in range(10))
@@ -499,8 +501,18 @@ class TestApi(unittest.TestCase):
rm = requests.delete(PODMAN_URL + f"/v1.40/volumes/{name}")
self.assertEqual(rm.status_code, 204, rm.content)
+ # recreate volume with data and then prune it
+ r = requests.post(PODMAN_URL + "/v1.40/volumes/create", json={"Name": name})
+ self.assertEqual(create.status_code, 201, create.content)
+ create = json.loads(r.content)
+ with open(os.path.join(create["Mountpoint"], "test_prune"), "w") as file:
+ file.writelines(["This is a test\n", "This is a good test\n"])
+
prune = requests.post(PODMAN_URL + "/v1.40/volumes/prune")
self.assertEqual(prune.status_code, 200, prune.content)
+ payload = json.loads(prune.content)
+ self.assertIn(name, payload["VolumesDeleted"])
+ self.assertGreater(payload["SpaceReclaimed"], 0)
def test_auth_compat(self):
r = requests.post(
@@ -530,6 +542,50 @@ class TestApi(unittest.TestCase):
self.assertIn("Volumes", obj)
self.assertIn("BuildCache", obj)
+ def test_prune_compat(self):
+ name = "Ctnr_" + "".join(random.choice(string.ascii_letters) for i in range(10))
+
+ r = requests.post(
+ PODMAN_URL + f"/v1.40/containers/create?name={name}",
+ json={
+ "Cmd": ["cp", "/etc/motd", "/motd.size_test"],
+ "Image": "alpine:latest",
+ "NetworkDisabled": True,
+ },
+ )
+ self.assertEqual(r.status_code, 201, r.text)
+ create = json.loads(r.text)
+
+ r = requests.post(PODMAN_URL + f"/v1.40/containers/{create['Id']}/start")
+ self.assertEqual(r.status_code, 204, r.text)
+
+ r = requests.post(PODMAN_URL + f"/v1.40/containers/{create['Id']}/wait")
+ self.assertEqual(r.status_code, 200, r.text)
+ wait = json.loads(r.text)
+ self.assertEqual(wait["StatusCode"], 0, wait["Error"]["Message"])
+
+ prune = requests.post(PODMAN_URL + "/v1.40/containers/prune")
+ self.assertEqual(prune.status_code, 200, prune.status_code)
+ prune_payload = json.loads(prune.text)
+ self.assertGreater(prune_payload["SpaceReclaimed"], 0)
+ self.assertIn(create["Id"], prune_payload["ContainersDeleted"])
+
+ # Delete any orphaned containers
+ r = requests.get(PODMAN_URL + "/v1.40/containers/json?all=true")
+ self.assertEqual(r.status_code, 200, r.text)
+ for ctnr in json.loads(r.text):
+ requests.delete(PODMAN_URL + f"/v1.40/containers/{ctnr['Id']}?force=true")
+
+ prune = requests.post(PODMAN_URL + "/v1.40/images/prune")
+ self.assertEqual(prune.status_code, 200, prune.text)
+ prune_payload = json.loads(prune.text)
+ self.assertGreater(prune_payload["SpaceReclaimed"], 0)
+
+ # FIXME need method to determine which image is going to be "pruned" to fix test
+ # TODO should handler be recursive when deleting images?
+ # self.assertIn(img["Id"], prune_payload["ImagesDeleted"][1]["Deleted"])
+ self.assertIsNotNone(prune_payload["ImagesDeleted"][1]["Deleted"])
+
if __name__ == "__main__":
unittest.main()