summaryrefslogtreecommitdiff
path: root/test/apiv2
diff options
context:
space:
mode:
Diffstat (limited to 'test/apiv2')
-rw-r--r--test/apiv2/01-basic.at2
-rw-r--r--test/apiv2/10-images.at4
-rw-r--r--test/apiv2/12-imagesMore.at4
-rw-r--r--test/apiv2/20-containers.at31
-rw-r--r--test/apiv2/30-volumes.at35
-rw-r--r--test/apiv2/35-networks.at66
-rw-r--r--test/apiv2/44-mounts.at21
-rw-r--r--test/apiv2/45-system.at8
-rw-r--r--test/apiv2/50-secrets.at13
-rw-r--r--test/apiv2/60-auth.at29
-rw-r--r--test/apiv2/rest_api/__init__.py4
-rw-r--r--test/apiv2/rest_api/test_rest_v2_0_0.py49
-rwxr-xr-xtest/apiv2/test-apiv2122
13 files changed, 298 insertions, 90 deletions
diff --git a/test/apiv2/01-basic.at b/test/apiv2/01-basic.at
index 1ddf49c6f..1357e0ca6 100644
--- a/test/apiv2/01-basic.at
+++ b/test/apiv2/01-basic.at
@@ -18,7 +18,7 @@ t HEAD libpod/_ping 200
for i in /version version; do
t GET $i 200 \
.Components[0].Name="Podman Engine" \
- .Components[0].Details.APIVersion=3.0.0 \
+ .Components[0].Details.APIVersion=3.1.0-dev \
.Components[0].Details.MinAPIVersion=3.0.0 \
.Components[0].Details.Os=linux \
.ApiVersion=1.40 \
diff --git a/test/apiv2/10-images.at b/test/apiv2/10-images.at
index a650cf958..f866422e2 100644
--- a/test/apiv2/10-images.at
+++ b/test/apiv2/10-images.at
@@ -41,7 +41,7 @@ t GET images/$iid/json 200 \
.Id=sha256:$iid \
.RepoTags[0]=$IMAGE
-t POST "images/create?fromImage=alpine" '' 200 .error=null .status~".*Download complete.*"
+t POST "images/create?fromImage=alpine" '' 200 .error~null .status~".*Download complete.*"
t POST "images/create?fromImage=alpine&tag=latest" '' 200
@@ -49,7 +49,7 @@ t POST "images/create?fromImage=alpine&tag=latest" '' 200
old_iid=$(podman image inspect --format "{{.ID}}" docker.io/library/alpine:latest)
podman rmi -f docker.io/library/alpine:latest
podman tag $IMAGE docker.io/library/alpine:latest
-t POST "images/create?fromImage=alpine" '' 200 .error=null .status~".*$old_iid.*"
+t POST "images/create?fromImage=alpine" '' 200 .error~null .status~".*$old_iid.*"
podman untag $IMAGE docker.io/library/alpine:latest
t POST "images/create?fromImage=quay.io/libpod/alpine&tag=sha256:fa93b01658e3a5a1686dc3ae55f170d8de487006fb53a28efcd12ab0710a2e5f" '' 200
diff --git a/test/apiv2/12-imagesMore.at b/test/apiv2/12-imagesMore.at
index 4f3ddf925..ce3049106 100644
--- a/test/apiv2/12-imagesMore.at
+++ b/test/apiv2/12-imagesMore.at
@@ -46,6 +46,10 @@ t POST "images/localhost:5000/myrepo/push?tlsVerify=false&tag=mytag" '' 200
# Untag the image
t POST "libpod/images/$iid/untag?repo=localhost:5000/myrepo&tag=mytag" '' 201
+# Try to push non-existing image
+t POST "images/localhost:5000/idonotexist/push?tlsVerify=false" '' 200
+jq -re 'select(.errorDetail)' <<<"$output" &>/dev/null || echo -e "${red}not ok: error message not found in output${nc}" 1>&2
+
t GET libpod/images/$IMAGE/json 200 \
.RepoTags[-1]=$IMAGE
diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at
index a99e9a184..383d92ef3 100644
--- a/test/apiv2/20-containers.at
+++ b/test/apiv2/20-containers.at
@@ -31,6 +31,13 @@ t GET libpod/containers/json?all=true 200 \
.[0].ExitCode=0 \
.[0].IsInfra=false
+# Test compat API for Network Settings
+t GET /containers/json?all=true 200 \
+ length=1 \
+ .[0].Id~[0-9a-f]\\{64\\} \
+ .[0].Image=$IMAGE \
+ .[0].NetworkSettings.Networks.podman.NetworkID=podman
+
# Make sure `limit` works.
t GET libpod/containers/json?limit=1 200 \
length=1 \
@@ -155,6 +162,7 @@ t DELETE images/localhost/newrepo:v1?force=true 200
t DELETE images/localhost/newrepo:v2?force=true 200
t DELETE libpod/containers/$cid 204
t DELETE libpod/containers/myctr 204
+t DELETE libpod/containers/bogus 404
# test apiv2 create container with correct entrypoint and cmd
@@ -206,9 +214,9 @@ t GET 'containers/json?limit=0&all=1' 200 \
t GET containers/json?limit=2 200 length=2
# Filter with two ids should return both container
-t GET "containers/json?filters=%7B%22id%22%3A%5B%22${cid}%22%2C%22${cid_top}%22%5D%7D&all=1" 200 length=2
+t GET containers/json?filters='{"id":["'${cid}'","'${cid_top}'"]}&all=1' 200 length=2
# Filter with two ids and status running should return only 1 container
-t GET "containers/json?filters=%7B%22id%22%3A%5B%22${cid}%22%2C%22${cid_top}%22%5D%2C%22status%22%3A%5B%22running%22%5D%7D&all=1" 200 \
+t GET containers/json?filters='{"id":["'${cid}'","'${cid_top}'"],"status":["running"]}&all=1' 200 \
length=1 \
.[0].Id=${cid_top}
@@ -246,3 +254,22 @@ t GET containers/$cid/json 200 \
.Mounts[0].Destination="/test"
t DELETE containers/$cid?v=true 204
+
+# test port mapping
+podman run -d --rm --name bar -p 8080:9090 $IMAGE top
+
+t GET containers/json 200 \
+ .[0].Ports[0].PrivatePort=9090 \
+ .[0].Ports[0].PublicPort=8080 \
+ .[0].Ports[0].Type="tcp"
+
+podman stop bar
+
+# Test CPU limit (NanoCPUs)
+t POST containers/create '"Image":"'$IMAGE'","HostConfig":{"NanoCpus":500000}' 201 \
+ .Id~[0-9a-f]\\{64\\}
+cid=$(jq -r '.Id' <<<"$output")
+t GET containers/$cid/json 200 \
+ .HostConfig.NanoCpus=500000
+
+t DELETE containers/$cid?v=true 204
diff --git a/test/apiv2/30-volumes.at b/test/apiv2/30-volumes.at
index b38810039..cf4b3d3ea 100644
--- a/test/apiv2/30-volumes.at
+++ b/test/apiv2/30-volumes.at
@@ -45,18 +45,17 @@ t GET libpod/volumes/json 200 \
.[0].Name~.* \
.[0].Mountpoint~.* \
.[0].CreatedAt~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.*
-# -G --data-urlencode 'filters={"name":["foo1"]}'
-t GET libpod/volumes/json?filters=%7B%22name%22%3A%5B%22foo1%22%5D%7D 200 length=1 .[0].Name=foo1
-# -G --data-urlencode 'filters={"name":["foo1","foo2"]}'
-t GET libpod/volumes/json?filters=%7B%22name%22%3A%20%5B%22foo1%22%2C%20%22foo2%22%5D%7D 200 length=2 .[0].Name=foo1 .[1].Name=foo2
-# -G --data-urlencode 'filters={"name":["nonexistent"]}'
-t GET libpod/volumes/json?filters=%7B%22name%22%3A%5B%22nonexistent%22%5D%7D 200 length=0
-# -G --data-urlencode 'filters={"label":["testlabel"]}'
-t GET libpod/volumes/json?filters=%7B%22label%22:%5B%22testlabel%22%5D%7D 200 length=2
-# -G --data-urlencode 'filters={"label":["testlabel=testonly"]}'
-t GET libpod/volumes/json?filters=%7B%22label%22:%5B%22testlabel=testonly%22%5D%7D 200 length=1
-# -G --data-urlencode 'filters={"label":["testlabel1=testonly"]}'
-t GET libpod/volumes/json?filters=%7B%22label%22:%5B%22testlabel1=testonly%22%5D%7D 200 length=1
+t GET libpod/volumes/json?filters='{"name":["foo1"]}' 200 \
+ length=1 \
+ .[0].Name=foo1
+t GET libpod/volumes/json?filters='{"name":%20["foo1",%20"foo2"]}' 200 \
+ length=2 \
+ .[0].Name=foo1 \
+ .[1].Name=foo2
+t GET libpod/volumes/json?filters='{"name":["nonexistent"]}' 200 length=0
+t GET libpod/volumes/json?filters='{"label":["testlabel"]}' 200 length=2
+t GET libpod/volumes/json?filters='{"label":["testlabel=testonly"]}' 200 length=1
+t GET libpod/volumes/json?filters='{"label":["testlabel1=testonly"]}' 200 length=1
## inspect volume
t GET libpod/volumes/foo1/json 200 \
@@ -79,16 +78,12 @@ t DELETE libpod/volumes/foo1 404 \
.response=404
## Prune volumes with label matching 'testlabel1=testonly'
-# -G --data-urlencode 'filters={"label":["testlabel1=testonly"]}'
-t POST libpod/volumes/prune?filters=%7B%22label%22:%5B%22testlabel1=testonly%22%5D%7D "" 200
-# -G --data-urlencode 'filters={"label":["testlabel1=testonly"]}'
-t GET libpod/volumes/json?filters=%7B%22label%22:%5B%22testlabel1=testonly%22%5D%7D 200 length=0
+t POST libpod/volumes/prune?filters='{"label":["testlabel1=testonly"]}' "" 200
+t GET libpod/volumes/json?filters='{"label":["testlabel1=testonly"]}' 200 length=0
## Prune volumes with label matching 'testlabel'
-# -G --data-urlencode 'filters={"label":["testlabel"]}'
-t POST libpod/volumes/prune?filters=%7B%22label%22:%5B%22testlabel%22%5D%7D "" 200
-# -G --data-urlencode 'filters={"label":["testlabel"]}'
-t GET libpod/volumes/json?filters=%7B%22label%22:%5B%22testlabel%22%5D%7D 200 length=0
+t POST libpod/volumes/prune?filters='{"label":["testlabel"]}' "" 200
+t GET libpod/volumes/json?filters='{"label":["testlabel"]}' 200 length=0
## Prune volumes
t POST libpod/volumes/prune "" 200
diff --git a/test/apiv2/35-networks.at b/test/apiv2/35-networks.at
index 7ce109913..d3bbaf32b 100644
--- a/test/apiv2/35-networks.at
+++ b/test/apiv2/35-networks.at
@@ -7,54 +7,52 @@ t GET networks/non-existing-network 404 \
.cause='network not found'
t POST libpod/networks/create?name=network1 '' 200 \
-.Filename~.*/network1\\.conflist
+ .Filename~.*/network1\\.conflist
# --data '{"Subnet":{"IP":"10.10.254.0","Mask":[255,255,255,0]},"Labels":{"abc":"val"}}'
t POST libpod/networks/create?name=network2 '"Subnet":{"IP":"10.10.254.0","Mask":[255,255,255,0]},"Labels":{"abc":"val"}' 200 \
-.Filename~.*/network2\\.conflist
+ .Filename~.*/network2\\.conflist
# test for empty mask
t POST libpod/networks/create '"Subnet":{"IP":"10.10.1.0","Mask":[]}' 500 \
-.cause~'.*cannot be empty'
+ .cause~'.*cannot be empty'
# test for invalid mask
t POST libpod/networks/create '"Subnet":{"IP":"10.10.1.0","Mask":[0,255,255,0]}' 500 \
-.cause~'.*mask is invalid'
+ .cause~'.*mask is invalid'
# network list
t GET libpod/networks/json 200
-# filters={"name":["network1"]}
-t GET libpod/networks/json?filters=%7B%22name%22%3A%5B%22network1%22%5D%7D 200 \
-length=1 \
-.[0].Name=network1
+t GET libpod/networks/json?filters='{"name":["network1"]}' 200 \
+ length=1 \
+ .[0].Name=network1
t GET networks 200
#network list docker endpoint
-#filters={"name":["network1","network2"]}
-t GET networks?filters=%7B%22name%22%3A%5B%22network1%22%2C%22network2%22%5D%7D 200 \
-length=2
-#filters={"name":["network"]}
-t GET networks?filters=%7B%22name%22%3A%5B%22network%22%5D%7D 200 \
-length=2
-# filters={"label":["abc"]}
-t GET networks?filters=%7B%22label%22%3A%5B%22abc%22%5D%7D 200 \
-length=1
-# id filter filters={"id":["a7662f44d65029fd4635c91feea3d720a57cef52e2a9fcc7772b69072cc1ccd1"]}
-t GET networks?filters=%7B%22id%22%3A%5B%22a7662f44d65029fd4635c91feea3d720a57cef52e2a9fcc7772b69072cc1ccd1%22%5D%7D 200 \
-length=1 \
-.[0].Name=network1 \
-.[0].Id=a7662f44d65029fd4635c91feea3d720a57cef52e2a9fcc7772b69072cc1ccd1
-# invalid filter filters={"dangling":["1"]}
-t GET networks?filters=%7B%22dangling%22%3A%5B%221%22%5D%7D 500 \
-.cause='invalid filter "dangling"'
+t GET networks?filters='{"name":["network1","network2"]}' 200 \
+ length=2
+t GET networks?filters='{"name":["network"]}' 200 \
+ length=2
+t GET networks?filters='{"label":["abc"]}' 200 \
+ length=1
+# old docker filter type see #9526
+t GET networks?filters='{"label":{"abc":true}}' 200 \
+ length=1
+t GET networks?filters='{"id":["a7662f44d65029fd4635c91feea3d720a57cef52e2a9fcc7772b69072cc1ccd1"]}' 200 \
+ length=1 \
+ .[0].Name=network1 \
+ .[0].Id=a7662f44d65029fd4635c91feea3d720a57cef52e2a9fcc7772b69072cc1ccd1
+# invalid filter
+t GET networks?filters='{"dangling":["1"]}' 500 \
+ .cause='invalid filter "dangling"'
# (#9293 with no networks the endpoint should return empty array instead of null)
-t GET networks?filters=%7B%22name%22%3A%5B%22doesnotexists%22%5D%7D 200 \
-"[]"
+t GET networks?filters='{"name":["doesnotexists"]}' 200 \
+ "[]"
# network inspect docker
t GET networks/a7662f44d65029fd4635c91feea3d720a57cef52e2a9fcc7772b69072cc1ccd1 200 \
-.Name=network1 \
-.Id=a7662f44d65029fd4635c91feea3d720a57cef52e2a9fcc7772b69072cc1ccd1 \
-.Scope=local
+ .Name=network1 \
+ .Id=a7662f44d65029fd4635c91feea3d720a57cef52e2a9fcc7772b69072cc1ccd1 \
+ .Scope=local
# network create docker
t POST networks/create '"Name":"net3","IPAM":{"Config":[]}' 201
@@ -63,11 +61,11 @@ t DELETE networks/net3 204
# clean the network
t DELETE libpod/networks/network1 200 \
-.[0].Name~network1 \
-.[0].Err=null
+ .[0].Name~network1 \
+ .[0].Err=null
t DELETE libpod/networks/network2 200 \
-.[0].Name~network2 \
-.[0].Err=null
+ .[0].Name~network2 \
+ .[0].Err=null
# vim: filetype=sh
diff --git a/test/apiv2/44-mounts.at b/test/apiv2/44-mounts.at
new file mode 100644
index 000000000..5dc560852
--- /dev/null
+++ b/test/apiv2/44-mounts.at
@@ -0,0 +1,21 @@
+# -*- sh -*-
+
+podman pull $IMAGE &>/dev/null
+
+# Test various HostConfig options
+tmpfs_name="/mytmpfs"
+t POST containers/create?name=hostconfig_test '"Image":"'$IMAGE'","Cmd":["df"],"HostConfig":{"Binds":["/tmp/doesnotexist:/test1"],"TmpFs":{"'$tmpfs_name'":"rw"}}' 201 \
+ .Id~[0-9a-f]\\{64\\}
+cid=$(jq -r '.Id' <<<"$output")
+
+# Prior to #9512, the tmpfs would be called '/mytmpfs=rw', with the '=rw'
+t GET containers/${cid}/json 200 \
+ .HostConfig.Tmpfs[\"${tmpfs_name}\"]~rw,
+
+# Run the container, verify output
+t POST containers/${cid}/start '' 204
+t POST containers/${cid}/wait '' 200
+t GET containers/${cid}/logs?stdout=true 200
+
+like "$(<$WORKDIR/curl.result.out)" ".* ${tmpfs_name}" \
+ "'df' output includes tmpfs name"
diff --git a/test/apiv2/45-system.at b/test/apiv2/45-system.at
index 985d86e56..ad4bdf4f7 100644
--- a/test/apiv2/45-system.at
+++ b/test/apiv2/45-system.at
@@ -49,18 +49,16 @@ t GET libpod/system/df 200 '.Volumes | length=3'
# Prune volumes
-# -G --data-urlencode 'volumes=true&filters={"label":["testlabel1=idontmatch"]}'
-t POST 'libpod/system/prune?volumes=true&filters=%7B%22label%22:%5B%22testlabel1=idontmatch%22%5D%7D' params='' 200
+t POST 'libpod/system/prune?volumes=true&filters={"label":["testlabel1=idontmatch"]}' params='' 200
# nothing should have been pruned
t GET system/df 200 '.Volumes | length=3'
t GET libpod/system/df 200 '.Volumes | length=3'
-# -G --data-urlencode 'volumes=true&filters={"label":["testlabel1=testonly"]}'
# only foo3 should be pruned because of filter
-t POST 'libpod/system/prune?volumes=true&filters=%7B%22label%22:%5B%22testlabel1=testonly%22%5D%7D' params='' 200 .VolumePruneReports[0].Id=foo3
+t POST 'libpod/system/prune?volumes=true&filters={"label":["testlabel1=testonly"]}' params='' 200 .VolumePruneReports[0].Id=foo3
# only foo2 should be pruned because of filter
-t POST 'libpod/system/prune?volumes=true&filters=%7B%22label%22:%5B%22testlabel1%22%5D%7D' params='' 200 .VolumePruneReports[0].Id=foo2
+t POST 'libpod/system/prune?volumes=true&filters={"label":["testlabel1"]}' params='' 200 .VolumePruneReports[0].Id=foo2
# foo1, the last remaining volume should be pruned without any filters applied
t POST 'libpod/system/prune?volumes=true' params='' 200 .VolumePruneReports[0].Id=foo1
diff --git a/test/apiv2/50-secrets.at b/test/apiv2/50-secrets.at
index 1ef43381a..c4ffb5883 100644
--- a/test/apiv2/50-secrets.at
+++ b/test/apiv2/50-secrets.at
@@ -14,18 +14,21 @@ t POST secrets/create '"Name":"mysecret","Data":"c2VjcmV0","Labels":{"fail":"fai
t POST secrets/create '"Name":"mysecret","Data":"c2VjcmV0"' 409
# secret inspect
-t GET secrets/mysecret 200\
- .Spec.Name=mysecret
+t GET secrets/mysecret 200 \
+ .Spec.Name=mysecret \
+ .Version.Index=1
# secret inspect non-existent secret
t GET secrets/bogus 404
# secret list
-t GET secrets 200\
- length=1
+t GET secrets 200 \
+ length=1 \
+ .[0].Spec.Name=mysecret \
+ .[0].Version.Index=1
# secret list unsupported filters
-t GET secrets?filters=%7B%22name%22%3A%5B%22foo1%22%5D%7D 400
+t GET secrets?filters='{"name":["foo1"]}' 400
# secret rm
t DELETE secrets/mysecret 204
diff --git a/test/apiv2/60-auth.at b/test/apiv2/60-auth.at
new file mode 100644
index 000000000..378955cd7
--- /dev/null
+++ b/test/apiv2/60-auth.at
@@ -0,0 +1,29 @@
+# -*- sh -*-
+#
+# registry-related tests
+#
+
+start_registry
+
+# FIXME FIXME FIXME: remove the 'if false' for use with PR 9589
+if false; then
+
+# FIXME FIXME: please forgive the horrible POST params format; I have an
+# upcoming PR which should fix that.
+
+# Test with wrong password. Confirm bad status and appropriate error message
+t POST /v1.40/auth "\"username\":\"${REGISTRY_USERNAME}\",\"password\":\"WrOnGPassWord\",\"serveraddress\":\"localhost:$REGISTRY_PORT/\"" \
+ 400 \
+ .Status~'.* invalid username/password'
+
+# Test with the right password. Confirm status message and reasonable token
+t POST /v1.40/auth "\"username\":\"${REGISTRY_USERNAME}\",\"password\":\"${REGISTRY_PASSWORD}\",\"serveraddress\":\"localhost:$REGISTRY_PORT/\"" \
+ 200 \
+ .Status="Login Succeeded" \
+ .IdentityToken~[a-zA-Z0-9]
+
+# FIXME: now what? Try something-something using that token?
+token=$(jq -r .IdentityToken <<<"$output")
+# ...
+
+fi # FIXME FIXME FIXME: remove when working
diff --git a/test/apiv2/rest_api/__init__.py b/test/apiv2/rest_api/__init__.py
index db0257f03..b7b8a7649 100644
--- a/test/apiv2/rest_api/__init__.py
+++ b/test/apiv2/rest_api/__init__.py
@@ -27,7 +27,7 @@ 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["REGISTRIES_CONFIG_PATH"] = 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(
{
@@ -36,7 +36,7 @@ class Podman(object):
"registries.block": {"registries": "[]"},
}
)
- with open(os.environ["REGISTRIES_CONFIG_PATH"], "w") as w:
+ with open(os.environ["CONTAINERS_REGISTRIES_CONF"], "w") as w:
p.write(w)
os.environ["CNI_CONFIG_PATH"] = os.path.join(self.anchor_directory, "cni", "net.d")
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 05c24f2ea..8a78f5185 100644
--- a/test/apiv2/rest_api/test_rest_v2_0_0.py
+++ b/test/apiv2/rest_api/test_rest_v2_0_0.py
@@ -64,7 +64,9 @@ class TestApi(unittest.TestCase):
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)
@@ -241,7 +243,9 @@ 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(
@@ -450,11 +454,15 @@ 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,))
@@ -484,8 +492,12 @@ 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_create = requests.post(PODMAN_URL + "/v1.40/networks/create", json={"Name": prune_name})
+ 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")
@@ -493,9 +505,10 @@ class TestApi(unittest.TestCase):
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))
+ 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)
@@ -511,7 +524,9 @@ 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
@@ -688,15 +703,21 @@ 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)
@@ -715,7 +736,9 @@ 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/apiv2/test-apiv2 b/test/apiv2/test-apiv2
index 5b1e2ef80..e32d6bc62 100755
--- a/test/apiv2/test-apiv2
+++ b/test/apiv2/test-apiv2
@@ -17,6 +17,8 @@ PODMAN_TEST_IMAGE_FQN="$PODMAN_TEST_IMAGE_REGISTRY/$PODMAN_TEST_IMAGE_USER/$PODM
IMAGE=$PODMAN_TEST_IMAGE_FQN
+REGISTRY_IMAGE="${PODMAN_TEST_IMAGE_REGISTRY}/${PODMAN_TEST_IMAGE_USER}/registry:2.7"
+
# END stuff you can but probably shouldn't customize
###############################################################################
# BEGIN setup
@@ -188,6 +190,13 @@ function t() {
# entrypoint path can include a descriptive comment; strip it off
path=${path%% *}
+ # path may include JSONish params that curl will barf on; url-encode them
+ path="${path//'['/%5B}"
+ path="${path//']'/%5D}"
+ path="${path//'{'/%7B}"
+ path="${path//'}'/%7D}"
+ path="${path//':'/%3A}"
+
# curl -X HEAD but without --head seems to wait for output anyway
if [[ $method == "HEAD" ]]; then
curl_args="--head"
@@ -306,13 +315,115 @@ function start_service() {
die "Cannot start service on non-localhost ($HOST)"
fi
- $PODMAN_BIN --root $WORKDIR system service --time 15 tcp:127.0.0.1:$PORT \
+ $PODMAN_BIN --root $WORKDIR/server_root system service \
+ --time 15 \
+ tcp:127.0.0.1:$PORT \
&> $WORKDIR/server.log &
service_pid=$!
wait_for_port $HOST $PORT
}
+function stop_service() {
+ # Stop the server
+ if [[ -n $service_pid ]]; then
+ kill $service_pid
+ wait $service_pid
+ fi
+}
+
+####################
+# start_registry # Run a local registry
+####################
+REGISTRY_PORT=
+REGISTRY_USERNAME=
+REGISTRY_PASSWORD=
+function start_registry() {
+ # We can be invoked multiple times, e.g. from different subtests, but
+ # let's assume that once started we only kill it at the end of tests.
+ if [[ -n "$REGISTRY_PORT" ]]; then
+ return
+ fi
+
+ REGISTRY_PORT=$(random_port)
+ REGISTRY_USERNAME=u$(random_string 7)
+ REGISTRY_PASSWORD=p$(random_string 7)
+
+ local REGDIR=$WORKDIR/registry
+ local AUTHDIR=$REGDIR/auth
+ mkdir -p $AUTHDIR
+
+ mkdir -p ${REGDIR}/{root,runroot}
+ local PODMAN_REGISTRY_ARGS="--root ${REGDIR}/root --runroot ${REGDIR}/runroot"
+
+ # Give it three tries, to compensate for network flakes
+ podman ${PODMAN_REGISTRY_ARGS} pull $REGISTRY_IMAGE ||
+ podman ${PODMAN_REGISTRY_ARGS} pull $REGISTRY_IMAGE ||
+ podman ${PODMAN_REGISTRY_ARGS} pull $REGISTRY_IMAGE
+
+ # Create a local cert and credentials
+ # FIXME: is there a hidden "--quiet" flag? This is too noisy.
+ openssl req -newkey rsa:4096 -nodes -sha256 \
+ -keyout $AUTHDIR/domain.key -x509 -days 2 \
+ -out $AUTHDIR/domain.crt \
+ -subj "/C=US/ST=Foo/L=Bar/O=Red Hat, Inc./CN=registry host certificate" \
+ -addext subjectAltName=DNS:localhost
+ htpasswd -Bbn ${REGISTRY_USERNAME} ${REGISTRY_PASSWORD} \
+ > $AUTHDIR/htpasswd
+
+ # Run the registry, and wait for it to come up
+ podman ${PODMAN_REGISTRY_ARGS} run -d \
+ -p ${REGISTRY_PORT}:5000 \
+ --name registry \
+ -v $AUTHDIR:/auth:Z \
+ -e "REGISTRY_AUTH=htpasswd" \
+ -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
+ -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
+ -e REGISTRY_HTTP_TLS_CERTIFICATE=/auth/domain.crt \
+ -e REGISTRY_HTTP_TLS_KEY=/auth/domain.key \
+ ${REGISTRY_IMAGE}
+
+ wait_for_port localhost $REGISTRY_PORT
+}
+
+function stop_registry() {
+ local REGDIR=${WORKDIR}/registry
+ if [[ -d $REGDIR ]]; then
+ local OPTS="--root ${REGDIR}/root --runroot ${REGDIR}/runroot"
+ podman $OPTS stop -f -t 0 -a
+
+ # rm/rmi are important when running rootless: without them we
+ # get EPERMS in tmpdir cleanup because files are owned by subuids.
+ podman $OPTS rm -f -a
+ podman $OPTS rmi -f -a
+ fi
+}
+
+#################
+# random_port # Random open port; arg is range (min-max), default 5000-5999
+#################
+function random_port() {
+ local range=${1:-5000-5999}
+
+ local port
+ for port in $(shuf -i ${range}); do
+ if ! { exec 5<> /dev/tcp/127.0.0.1/$port; } &>/dev/null; then
+ echo $port
+ return
+ fi
+ done
+
+ die "Could not find open port in range $range"
+}
+
+###################
+# random_string # Pseudorandom alphanumeric string of given length
+###################
+function random_string() {
+ local length=${1:-10}
+ head /dev/urandom | tr -dc a-zA-Z0-9 | head -c$length
+}
+
###################
# wait_for_port # Returns once port is available on host
###################
@@ -334,8 +445,8 @@ function wait_for_port() {
# podman # Needed by some test scripts to invoke the actual podman binary
############
function podman() {
- echo "\$ $PODMAN_BIN $*" >>$WORKDIR/output.log
- $PODMAN_BIN --root $WORKDIR "$@" >>$WORKDIR/output.log 2>&1
+ echo "\$ $PODMAN_BIN $*" >>$WORKDIR/output.log
+ $PODMAN_BIN --root $WORKDIR/server_root "$@" >>$WORKDIR/output.log 2>&1
}
####################
@@ -405,9 +516,8 @@ if [ -n "$service_pid" ]; then
podman rm -a
podman rmi -af
- # Stop the server
- kill $service_pid
- wait $service_pid
+ stop_registry
+ stop_service
fi
test_count=$(<$testcounter_file)