mirror of
https://github.com/containers/podman.git
synced 2025-09-19 00:56:15 +08:00
remove unmapped ports from inspect port bindings
Signed-off-by: Jakob Ahrer <jakob@ahrer.dev>
This commit is contained in:

committed by
SoMuchForSubtlety

parent
0037bffbb1
commit
97f63da67d
@ -1,7 +1,9 @@
|
||||
import io
|
||||
import multiprocessing
|
||||
import queue
|
||||
import random
|
||||
import subprocess
|
||||
import tarfile
|
||||
import threading
|
||||
import unittest
|
||||
|
||||
@ -359,6 +361,43 @@ class ContainerTestCase(APITestCase):
|
||||
self.assertEqual(2000, out["HostConfig"]["MemorySwap"])
|
||||
self.assertEqual(1000, out["HostConfig"]["Memory"])
|
||||
|
||||
def test_host_config_port_bindings(self):
|
||||
# create a container with two ports exposed, but only one of the ports bound
|
||||
r = requests.post(
|
||||
self.podman_url + "/v1.40/containers/create",
|
||||
json={
|
||||
"Name": "memory",
|
||||
"Cmd": ["top"],
|
||||
"Image": "alpine:latest",
|
||||
"HostConfig": {
|
||||
"PortBindings": {
|
||||
"8080": [{"HostPort": "87634"}]
|
||||
}
|
||||
},
|
||||
"ExposedPorts": {
|
||||
"8080": {},
|
||||
"8081": {}
|
||||
}
|
||||
},
|
||||
)
|
||||
self.assertEqual(r.status_code, 201, r.text)
|
||||
payload = r.json()
|
||||
container_id = payload["Id"]
|
||||
self.assertIsNotNone(container_id)
|
||||
|
||||
r = requests.get(self.podman_url +
|
||||
f"/v1.40/containers/{container_id}/json")
|
||||
self.assertEqual(r.status_code, 200, r.text)
|
||||
inspect_response = r.json()
|
||||
# both ports are in the config
|
||||
self.assertEqual(2, len(inspect_response["Config"]["ExposedPorts"]))
|
||||
self.assertTrue("8080/tcp" in inspect_response["Config"]["ExposedPorts"])
|
||||
self.assertTrue("8081/tcp" in inspect_response["Config"]["ExposedPorts"])
|
||||
# only 8080 one port is bound
|
||||
self.assertEqual(1, len(inspect_response["HostConfig"]["PortBindings"]))
|
||||
self.assertTrue("8080/tcp" in inspect_response["HostConfig"]["PortBindings"])
|
||||
self.assertFalse("8081/tcp" in inspect_response["HostConfig"]["PortBindings"])
|
||||
|
||||
def execute_process(cmd):
|
||||
return subprocess.run(
|
||||
cmd,
|
||||
|
Reference in New Issue
Block a user