Skip to content

Commit 189c086

Browse files
authored
Merge pull request #1232 from p12tic/1.4-backport-1231
[1.4 backports] Fix relative host path resolution for volume bind mount source
2 parents bd29caa + 32b3d26 commit 189c086

File tree

4 files changed

+82
-8
lines changed

4 files changed

+82
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed relative host path resolution for volume bind mount source

podman_compose.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ async def assert_volume(compose, mount_dict):
395395
os.makedirs(mount_src, exist_ok=True)
396396
except OSError:
397397
pass
398+
mount_dict["source"] = mount_src
398399
return
399400
if mount_dict["type"] != "volume" or not vol or not vol.get("name"):
400401
return

tests/integration/selinux/test_podman_compose_selinux.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@ def test_selinux(self):
3636
"selinux_container1_1",
3737
])
3838
inspect_out = json.loads(out)
39-
create_command_list = inspect_out[0].get("Config", []).get("CreateCommand", {})
40-
self.assertIn('./host_test_text.txt:/test_text.txt:z', create_command_list)
39+
create_command_list = inspect_out[0].get("Config", []).get("CreateCommand", [])
40+
host_path = os.path.join(test_path(), "selinux", "host_test_text.txt")
41+
self.assertIn(f'{host_path}:/test_text.txt:z', create_command_list)
4142

4243
out, _ = self.run_subprocess_assert_returncode([
4344
"podman",
4445
"inspect",
4546
"selinux_container2_1",
4647
])
4748
inspect_out = json.loads(out)
48-
create_command_list = inspect_out[0].get("Config", []).get("CreateCommand", {})
49-
self.assertIn('./host_test_text.txt:/test_text.txt', create_command_list)
49+
create_command_list = inspect_out[0].get("Config", []).get("CreateCommand", [])
50+
host_path = os.path.join(test_path(), "selinux", "host_test_text.txt")
51+
self.assertIn(f'{host_path}:/test_text.txt', create_command_list)
5052
finally:
5153
out, _ = self.run_subprocess_assert_returncode([
5254
podman_compose_path(),

tests/unit/test_container_to_args.py

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,24 @@ async def test_gpu_device_ids_specific(self):
529529
)
530530

531531
@parameterized.expand([
532-
(False, "z", ["--mount", "type=bind,source=./foo,destination=/mnt,z"]),
533-
(False, "Z", ["--mount", "type=bind,source=./foo,destination=/mnt,Z"]),
534-
(True, "z", ["-v", "./foo:/mnt:z"]),
535-
(True, "Z", ["-v", "./foo:/mnt:Z"]),
532+
(
533+
False,
534+
"z",
535+
[
536+
"--mount",
537+
f"type=bind,source={get_test_file_path('test_dirname/foo')},destination=/mnt,z",
538+
],
539+
),
540+
(
541+
False,
542+
"Z",
543+
[
544+
"--mount",
545+
f"type=bind,source={get_test_file_path('test_dirname/foo')},destination=/mnt,Z",
546+
],
547+
),
548+
(True, "z", ["-v", f"{get_test_file_path('test_dirname/foo')}:/mnt:z"]),
549+
(True, "Z", ["-v", f"{get_test_file_path('test_dirname/foo')}:/mnt:Z"]),
536550
])
537551
async def test_selinux_volume(self, prefer_volume, selinux_type, expected_additional_args):
538552
c = create_compose_mock()
@@ -567,6 +581,62 @@ async def test_selinux_volume(self, prefer_volume, selinux_type, expected_additi
567581
],
568582
)
569583

584+
@parameterized.expand([
585+
(
586+
"absolute_path",
587+
get_test_file_path('test_dirname/foo'),
588+
[
589+
"--mount",
590+
f"type=bind,source={get_test_file_path('test_dirname/foo')},destination=/mnt",
591+
],
592+
),
593+
(
594+
"relative_path",
595+
'./foo',
596+
[
597+
"--mount",
598+
f"type=bind,source={get_test_file_path('test_dirname/foo')},destination=/mnt",
599+
],
600+
),
601+
(
602+
"home_dir",
603+
'~/test_dirname/foo',
604+
[
605+
"--mount",
606+
f"type=bind,source={os.path.expanduser('~/test_dirname/foo')},destination=/mnt",
607+
],
608+
),
609+
])
610+
async def test_volumes_bind_mount_source(
611+
self, test_name: str, mount_source: str, expected_additional_args: list
612+
) -> None:
613+
c = create_compose_mock()
614+
cnt = get_minimal_container()
615+
616+
# This is supposed to happen during `_parse_compose_file`
617+
# but that is probably getting skipped during testing
618+
cnt["_service"] = cnt["service_name"]
619+
620+
cnt["volumes"] = [
621+
{
622+
"type": "bind",
623+
"source": f"{mount_source}",
624+
"target": "/mnt",
625+
}
626+
]
627+
628+
args = await container_to_args(c, cnt)
629+
self.assertEqual(
630+
args,
631+
[
632+
"--name=project_name_service_name1",
633+
"-d",
634+
*expected_additional_args,
635+
"--network=bridge:alias=service_name",
636+
"busybox",
637+
],
638+
)
639+
570640
@parameterized.expand([
571641
("not_compat", False, "test_project_name", "test_project_name_network1"),
572642
("compat_no_dash", True, "test_project_name", "test_project_name_network1"),

0 commit comments

Comments
 (0)