mirror of https://github.com/containers/podman.git
Merge pull request #9556 from jwhonce/wip/docker
Refactor python tests to run against python3.9
This commit is contained in:
commit
8af66806c8
|
@ -64,7 +64,9 @@ class TestApi(unittest.TestCase):
|
||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
|
|
||||||
TestApi.podman = Podman()
|
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...
|
# give the service some time to be ready...
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
|
@ -241,7 +243,9 @@ class TestApi(unittest.TestCase):
|
||||||
|
|
||||||
def test_post_create_compat(self):
|
def test_post_create_compat(self):
|
||||||
"""Create network and connect container during create"""
|
"""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)
|
self.assertEqual(net.status_code, 201, net.text)
|
||||||
|
|
||||||
create = requests.post(
|
create = requests.post(
|
||||||
|
@ -450,11 +454,15 @@ class TestApi(unittest.TestCase):
|
||||||
self.assertIn(k, o)
|
self.assertIn(k, o)
|
||||||
|
|
||||||
def test_network_compat(self):
|
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
|
# 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)
|
self.assertEqual(create.status_code, 201, create.content)
|
||||||
obj = json.loads(create.content)
|
obj = json.loads(create.content)
|
||||||
self.assertIn(type(obj), (dict,))
|
self.assertIn(type(obj), (dict,))
|
||||||
|
@ -484,8 +492,12 @@ class TestApi(unittest.TestCase):
|
||||||
self.assertEqual(inspect.status_code, 404, inspect.content)
|
self.assertEqual(inspect.status_code, 404, inspect.content)
|
||||||
|
|
||||||
# network prune
|
# network prune
|
||||||
prune_name = "Network_" + "".join(random.choice(string.ascii_letters) for i in range(10))
|
prune_name = "Network_" + "".join(
|
||||||
prune_create = requests.post(PODMAN_URL + "/v1.40/networks/create", json={"Name": prune_name})
|
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)
|
self.assertEqual(create.status_code, 201, prune_create.content)
|
||||||
|
|
||||||
prune = requests.post(PODMAN_URL + "/v1.40/networks/prune")
|
prune = requests.post(PODMAN_URL + "/v1.40/networks/prune")
|
||||||
|
@ -493,9 +505,10 @@ class TestApi(unittest.TestCase):
|
||||||
obj = json.loads(prune.content)
|
obj = json.loads(prune.content)
|
||||||
self.assertTrue(prune_name in obj["NetworksDeleted"])
|
self.assertTrue(prune_name in obj["NetworksDeleted"])
|
||||||
|
|
||||||
|
|
||||||
def test_volumes_compat(self):
|
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")
|
ls = requests.get(PODMAN_URL + "/v1.40/volumes")
|
||||||
self.assertEqual(ls.status_code, 200, ls.content)
|
self.assertEqual(ls.status_code, 200, ls.content)
|
||||||
|
@ -511,7 +524,9 @@ class TestApi(unittest.TestCase):
|
||||||
for k in required_keys:
|
for k in required_keys:
|
||||||
self.assertIn(k, obj)
|
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)
|
self.assertEqual(create.status_code, 201, create.content)
|
||||||
|
|
||||||
# See https://docs.docker.com/engine/api/v1.40/#operation/VolumeCreate
|
# See https://docs.docker.com/engine/api/v1.40/#operation/VolumeCreate
|
||||||
|
@ -688,15 +703,21 @@ class TestApi(unittest.TestCase):
|
||||||
"""Verify issue #8865"""
|
"""Verify issue #8865"""
|
||||||
|
|
||||||
pod_name = list()
|
pod_name = list()
|
||||||
pod_name.append("Pod_" + "".join(random.choice(string.ascii_letters) for i in range(10)))
|
pod_name.append(
|
||||||
pod_name.append("Pod_" + "".join(random.choice(string.ascii_letters) for i in range(10)))
|
"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(
|
r = requests.post(
|
||||||
_url("/pods/create"),
|
_url("/pods/create"),
|
||||||
json={
|
json={
|
||||||
"name": pod_name[0],
|
"name": pod_name[0],
|
||||||
"no_infra": False,
|
"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)
|
self.assertEqual(r.status_code, 201, r.text)
|
||||||
|
@ -715,7 +736,9 @@ class TestApi(unittest.TestCase):
|
||||||
json={
|
json={
|
||||||
"name": pod_name[1],
|
"name": pod_name[1],
|
||||||
"no_infra": False,
|
"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)
|
self.assertEqual(r.status_code, 201, r.text)
|
||||||
|
|
|
@ -8,7 +8,7 @@ import tempfile
|
||||||
|
|
||||||
from docker import DockerClient
|
from docker import DockerClient
|
||||||
|
|
||||||
from test.python.docker import constant
|
from .compat import constant
|
||||||
|
|
||||||
|
|
||||||
class Podman(object):
|
class Podman(object):
|
||||||
|
@ -39,7 +39,9 @@ class Podman(object):
|
||||||
self.cmd.append("--root=" + os.path.join(self.anchor_directory, "crio"))
|
self.cmd.append("--root=" + os.path.join(self.anchor_directory, "crio"))
|
||||||
self.cmd.append("--runroot=" + os.path.join(self.anchor_directory, "crio-run"))
|
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["REGISTRIES_CONFIG_PATH"] = os.path.join(
|
||||||
|
self.anchor_directory, "registry.conf"
|
||||||
|
)
|
||||||
p = configparser.ConfigParser()
|
p = configparser.ConfigParser()
|
||||||
p.read_dict(
|
p.read_dict(
|
||||||
{
|
{
|
||||||
|
@ -51,10 +53,14 @@ class Podman(object):
|
||||||
with open(os.environ["REGISTRIES_CONFIG_PATH"], "w") as w:
|
with open(os.environ["REGISTRIES_CONFIG_PATH"], "w") as w:
|
||||||
p.write(w)
|
p.write(w)
|
||||||
|
|
||||||
os.environ["CNI_CONFIG_PATH"] = os.path.join(self.anchor_directory, "cni", "net.d")
|
os.environ["CNI_CONFIG_PATH"] = os.path.join(
|
||||||
|
self.anchor_directory, "cni", "net.d"
|
||||||
|
)
|
||||||
os.makedirs(os.environ["CNI_CONFIG_PATH"], exist_ok=True)
|
os.makedirs(os.environ["CNI_CONFIG_PATH"], exist_ok=True)
|
||||||
self.cmd.append("--cni-config-dir=" + os.environ["CNI_CONFIG_PATH"])
|
self.cmd.append("--cni-config-dir=" + os.environ["CNI_CONFIG_PATH"])
|
||||||
cni_cfg = os.path.join(os.environ["CNI_CONFIG_PATH"], "87-podman-bridge.conflist")
|
cni_cfg = os.path.join(
|
||||||
|
os.environ["CNI_CONFIG_PATH"], "87-podman-bridge.conflist"
|
||||||
|
)
|
||||||
# json decoded and encoded to ensure legal json
|
# json decoded and encoded to ensure legal json
|
||||||
buf = json.loads(
|
buf = json.loads(
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -13,26 +13,26 @@ To run the tests locally in your sandbox (Fedora 32,33):
|
||||||
|
|
||||||
### Run the entire test suite
|
### Run the entire test suite
|
||||||
|
|
||||||
|
All commands are run from the root of the repository.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# python3 -m unittest discover test/python/docker
|
# python3 -m unittest discover -s test/python/docker
|
||||||
```
|
```
|
||||||
|
|
||||||
Passing the -v option to your test script will instruct unittest.main() to enable a higher level of verbosity, and produce detailed output:
|
Passing the -v option to your test script will instruct unittest.main() to enable a higher level of verbosity, and produce detailed output:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# python3 -m unittest -v discover test/python/docker
|
# python3 -m unittest -v discover -s test/python/docker
|
||||||
```
|
```
|
||||||
|
|
||||||
### Run a specific test class
|
### Run a specific test class
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# cd test/python/docker
|
# python3 -m unittest -v test.python.docker.compat.test_images.TestImages
|
||||||
# python3 -m unittest -v tests.test_images
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Run a specific test within the test class
|
### Run a specific test within the test class
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# cd test/python/docker
|
# python3 -m unittest test.python.docker.compat.test_images.TestImages.test_tag_valid_image
|
||||||
# python3 -m unittest tests.test_images.TestImages.test_import_image
|
|
||||||
```
|
```
|
|
@ -1,10 +1,12 @@
|
||||||
from docker import DockerClient
|
from docker import DockerClient
|
||||||
|
|
||||||
from test.python.docker import constant
|
from test.python.docker.compat import constant
|
||||||
|
|
||||||
|
|
||||||
def run_top_container(client: DockerClient):
|
def run_top_container(client: DockerClient):
|
||||||
c = client.containers.create(constant.ALPINE, command="top", detach=True, tty=True, name="top")
|
c = client.containers.create(
|
||||||
|
constant.ALPINE, command="top", detach=True, tty=True, name="top"
|
||||||
|
)
|
||||||
c.start()
|
c.start()
|
||||||
return c.id
|
return c.id
|
||||||
|
|
|
@ -5,7 +5,8 @@ import unittest
|
||||||
|
|
||||||
from docker import DockerClient, errors
|
from docker import DockerClient, errors
|
||||||
|
|
||||||
from test.python.docker import Podman, common, constant
|
from test.python.docker import Podman
|
||||||
|
from test.python.docker.compat import common, constant
|
||||||
|
|
||||||
|
|
||||||
class TestContainers(unittest.TestCase):
|
class TestContainers(unittest.TestCase):
|
||||||
|
@ -87,9 +88,11 @@ class TestContainers(unittest.TestCase):
|
||||||
self.assertEqual(len(containers), 2)
|
self.assertEqual(len(containers), 2)
|
||||||
|
|
||||||
def test_start_container_with_random_port_bind(self):
|
def test_start_container_with_random_port_bind(self):
|
||||||
container = self.client.containers.create(image=constant.ALPINE,
|
container = self.client.containers.create(
|
||||||
|
image=constant.ALPINE,
|
||||||
name="containerWithRandomBind",
|
name="containerWithRandomBind",
|
||||||
ports={'1234/tcp': None})
|
ports={"1234/tcp": None},
|
||||||
|
)
|
||||||
containers = self.client.containers.list(all=True)
|
containers = self.client.containers.list(all=True)
|
||||||
self.assertTrue(container in containers)
|
self.assertTrue(container in containers)
|
||||||
|
|
|
@ -7,7 +7,8 @@ import unittest
|
||||||
|
|
||||||
from docker import DockerClient, errors
|
from docker import DockerClient, errors
|
||||||
|
|
||||||
from test.python.docker import Podman, common, constant
|
from test.python.docker import Podman
|
||||||
|
from test.python.docker.compat import common, constant
|
||||||
|
|
||||||
|
|
||||||
class TestImages(unittest.TestCase):
|
class TestImages(unittest.TestCase):
|
||||||
|
@ -78,7 +79,9 @@ class TestImages(unittest.TestCase):
|
||||||
self.assertEqual(len(self.client.images.list()), 2)
|
self.assertEqual(len(self.client.images.list()), 2)
|
||||||
|
|
||||||
# List images with filter
|
# List images with filter
|
||||||
self.assertEqual(len(self.client.images.list(filters={"reference": "alpine"})), 1)
|
self.assertEqual(
|
||||||
|
len(self.client.images.list(filters={"reference": "alpine"})), 1
|
||||||
|
)
|
||||||
|
|
||||||
def test_search_image(self):
|
def test_search_image(self):
|
||||||
"""Search for image"""
|
"""Search for image"""
|
||||||
|
@ -91,7 +94,7 @@ class TestImages(unittest.TestCase):
|
||||||
r = self.client.images.search("bogus/bogus")
|
r = self.client.images.search("bogus/bogus")
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
self.assertTrue(len(r)==0)
|
self.assertTrue(len(r) == 0)
|
||||||
|
|
||||||
def test_remove_image(self):
|
def test_remove_image(self):
|
||||||
"""Remove image"""
|
"""Remove image"""
|
|
@ -5,7 +5,8 @@ import unittest
|
||||||
|
|
||||||
from docker import DockerClient
|
from docker import DockerClient
|
||||||
|
|
||||||
from test.python.docker import Podman, common, constant
|
from test.python.docker import Podman, constant
|
||||||
|
from test.python.docker.compat import common
|
||||||
|
|
||||||
|
|
||||||
class TestSystem(unittest.TestCase):
|
class TestSystem(unittest.TestCase):
|
|
@ -0,0 +1,6 @@
|
||||||
|
docker~=4.4.3
|
||||||
|
|
||||||
|
requests~=2.20.0
|
||||||
|
setuptools~=50.3.2
|
||||||
|
python-dateutil~=2.8.1
|
||||||
|
PyYAML~=5.4.1
|
Loading…
Reference in New Issue