| 1 |
|
| 2 |
|
| 3 |
import json |
| 4 |
import os |
| 5 |
import unittest |
| 6 |
|
| 7 |
from packaging import version |
| 8 |
|
| 9 |
from tests.integration.test_utils import RunSubprocessMixin |
| 10 |
from tests.integration.test_utils import get_podman_version |
| 11 |
from tests.integration.test_utils import podman_compose_path |
| 12 |
from tests.integration.test_utils import test_path |
| 13 |
|
| 14 |
|
| 15 |
def compose_yaml_path(compose_name: str) -> str: |
| 16 |
""" "Returns the path to the compose file used for this test module""" |
| 17 |
base_path = os.path.join(test_path(), "merge/volumes_merge/") |
| 18 |
return os.path.join(base_path, compose_name) |
| 19 |
|
| 20 |
|
| 21 |
class TestComposeVolumesMerge(unittest.TestCase, RunSubprocessMixin): |
| 22 |
@unittest.skipIf(get_podman_version() >= version.parse("5.7.0"), "Breaks as of podman-5.7.1.") |
| 23 |
def test_volumes_merge(self) -> None: |
| 24 |
|
| 25 |
try: |
| 26 |
self.run_subprocess_assert_returncode([ |
| 27 |
podman_compose_path(), |
| 28 |
"-f", |
| 29 |
compose_yaml_path("docker-compose.yaml"), |
| 30 |
"-f", |
| 31 |
compose_yaml_path("docker-compose.override.yaml"), |
| 32 |
"up", |
| 33 |
"-d", |
| 34 |
]) |
| 35 |
|
| 36 |
out, _ = self.run_subprocess_assert_returncode([ |
| 37 |
"podman", |
| 38 |
"exec", |
| 39 |
"-ti", |
| 40 |
"volumes_merge_web_1", |
| 41 |
"cat", |
| 42 |
"/var/www/html/index.html", |
| 43 |
"/var/www/html/index2.html", |
| 44 |
"/var/www/html/index3.html", |
| 45 |
]) |
| 46 |
self.assertEqual( |
| 47 |
out, |
| 48 |
b"The file from docker-compose.override.yaml\r\n" |
| 49 |
b"The file from docker-compose.override.yaml\r\n" |
| 50 |
b"The file from docker-compose.override.yaml\r\n", |
| 51 |
) |
| 52 |
|
| 53 |
out, _ = self.run_subprocess_assert_returncode([ |
| 54 |
"podman", |
| 55 |
"inspect", |
| 56 |
"volumes_merge_web_1", |
| 57 |
]) |
| 58 |
volumes_info = json.loads(out.decode('utf-8'))[0] |
| 59 |
binds_info = volumes_info["HostConfig"]["Binds"] |
| 60 |
binds_info.sort() |
| 61 |
|
| 62 |
file_path = os.path.join(test_path(), "merge/volumes_merge/override.txt") |
| 63 |
expected = [ |
| 64 |
f'{file_path}:/var/www/html/index.html:ro,rprivate,rbind', |
| 65 |
f'{file_path}:/var/www/html/index2.html:rw,rprivate,rbind', |
| 66 |
f'{file_path}:/var/www/html/index3.html:rw,rprivate,rbind', |
| 67 |
] |
| 68 |
self.assertEqual(binds_info, expected) |
| 69 |
finally: |
| 70 |
out, _ = self.run_subprocess_assert_returncode([ |
| 71 |
podman_compose_path(), |
| 72 |
"-f", |
| 73 |
compose_yaml_path("docker-compose.yaml"), |
| 74 |
"-f", |
| 75 |
compose_yaml_path("docker-compose.override.yaml"), |
| 76 |
"down", |
| 77 |
"-t", |
| 78 |
"0", |
| 79 |
]) |