mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
Refactor docker-py compatibility tests
* Add which python client is being used to run tests, see "python client" below. * Remove redundate code from test classes * Update/Add comments to modules and classes ======================================================= test session starts ======================================================== platform linux -- Python 3.10.0, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 python client -- DockerClient rootdir: /home/jhonce/Projects/go/src/github.com/containers/podman plugins: requests-mock-1.8.0 collected 33 items test/python/docker/compat/test_containers.py ...s.............. [ 54%] test/python/docker/compat/test_images.py ............ [ 90%] test/python/docker/compat/test_system.py ... [100%] Note: Follow-up PRs will verify the test results and expand the tests. Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
@ -1,71 +1,32 @@
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
"""
|
||||
Integration tests for exercising docker-py against Podman Service.
|
||||
"""
|
||||
|
||||
from docker import DockerClient
|
||||
|
||||
from test.python.docker import Podman, constant
|
||||
# pylint: disable=no-name-in-module,import-error,wrong-import-order
|
||||
from test.python.docker import constant
|
||||
from test.python.docker.compat import common
|
||||
|
||||
|
||||
class TestSystem(unittest.TestCase):
|
||||
podman = None # initialized podman configuration for tests
|
||||
service = None # podman service instance
|
||||
topContainerId = ""
|
||||
# pylint: disable=missing-function-docstring
|
||||
class TestSystem(common.DockerTestCase):
|
||||
"""TestCase for exercising Podman system services."""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.client = DockerClient(base_url="tcp://127.0.0.1:8080", timeout=15)
|
||||
|
||||
TestSystem.podman.restore_image_from_cache(self.client)
|
||||
TestSystem.topContainerId = common.run_top_container(self.client)
|
||||
|
||||
def tearDown(self):
|
||||
common.remove_all_containers(self.client)
|
||||
common.remove_all_images(self.client)
|
||||
self.client.close()
|
||||
return super().tearDown()
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
TestSystem.podman = Podman()
|
||||
TestSystem.service = TestSystem.podman.open(
|
||||
"system", "service", "tcp:127.0.0.1:8080", "--time=0"
|
||||
)
|
||||
# give the service some time to be ready...
|
||||
time.sleep(2)
|
||||
|
||||
returncode = TestSystem.service.poll()
|
||||
if returncode is not None:
|
||||
raise subprocess.CalledProcessError(returncode, "podman system service")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
TestSystem.service.terminate()
|
||||
stdout, stderr = TestSystem.service.communicate(timeout=0.5)
|
||||
if stdout:
|
||||
sys.stdout.write("\nImages Service Stdout:\n" + stdout.decode("utf-8"))
|
||||
if stderr:
|
||||
sys.stderr.write("\nImAges Service Stderr:\n" + stderr.decode("utf-8"))
|
||||
|
||||
TestSystem.podman.tear_down()
|
||||
return super().tearDownClass()
|
||||
|
||||
def test_Info(self):
|
||||
info = self.client.info()
|
||||
def test_info(self):
|
||||
info = self.docker.info()
|
||||
self.assertIsNotNone(info)
|
||||
self.assertEqual(info["RegistryConfig"]["IndexConfigs"]["localhost:5000"]["Secure"], False)
|
||||
self.assertEqual(info["RegistryConfig"]["IndexConfigs"]["localhost:5000"]["Mirrors"], ["mirror.localhost:5000"])
|
||||
self.assertEqual(
|
||||
info["RegistryConfig"]["IndexConfigs"]["localhost:5000"]["Mirrors"],
|
||||
["mirror.localhost:5000"],
|
||||
)
|
||||
|
||||
def test_info_container_details(self):
|
||||
info = self.client.info()
|
||||
info = self.docker.info()
|
||||
self.assertEqual(info["Containers"], 1)
|
||||
self.client.containers.create(image=constant.ALPINE)
|
||||
info = self.client.info()
|
||||
self.docker.containers.create(image=constant.ALPINE)
|
||||
info = self.docker.info()
|
||||
self.assertEqual(info["Containers"], 2)
|
||||
|
||||
def test_version(self):
|
||||
version = self.client.version()
|
||||
version = self.docker.version()
|
||||
self.assertIsNotNone(version["Platform"]["Name"])
|
||||
|
Reference in New Issue
Block a user