|
| 1 | +# SPDX-License-Identifier: GPL-2.0 |
| 2 | + |
| 3 | +import json |
| 4 | +import os |
| 5 | +import unittest |
| 6 | + |
| 7 | +from tests.integration.test_utils import RunSubprocessMixin |
| 8 | +from tests.integration.test_utils import podman_compose_path |
| 9 | +from tests.integration.test_utils import test_path |
| 10 | + |
| 11 | + |
| 12 | +class TestPodmanCompose(unittest.TestCase, RunSubprocessMixin): |
| 13 | + def setUp(self): |
| 14 | + # there must be a source file in the host for volumes type: bind |
| 15 | + head, tail = os.path.split(podman_compose_path()) |
| 16 | + self.path_to_host_test_file = head + "/host_test_text.txt" |
| 17 | + self.run_subprocess(["touch", self.path_to_host_test_file]) |
| 18 | + |
| 19 | + def tearDown(self): |
| 20 | + self.run_subprocess(["rm", self.path_to_host_test_file]) |
| 21 | + |
| 22 | + def test_selinux(self): |
| 23 | + # test if when using volumes type:bind with selinux:z option, container ackquires a |
| 24 | + # respective host:source:z mapping in CreateCommand list |
| 25 | + compose_path = os.path.join(test_path(), "selinux", "docker-compose.yml") |
| 26 | + try: |
| 27 | + self.run_subprocess_assert_returncode([ |
| 28 | + podman_compose_path(), |
| 29 | + "-f", |
| 30 | + compose_path, |
| 31 | + "up", |
| 32 | + "-d", |
| 33 | + "container1", |
| 34 | + ]) |
| 35 | + ( |
| 36 | + self.run_subprocess_assert_returncode([ |
| 37 | + podman_compose_path(), |
| 38 | + "-f", |
| 39 | + compose_path, |
| 40 | + "up", |
| 41 | + "-d", |
| 42 | + "container2", |
| 43 | + ]), |
| 44 | + ) |
| 45 | + |
| 46 | + out, _ = self.run_subprocess_assert_returncode([ |
| 47 | + "podman", |
| 48 | + "inspect", |
| 49 | + "selinux_container1_1", |
| 50 | + ]) |
| 51 | + inspect_out = json.loads(out) |
| 52 | + create_command_map = inspect_out[0].get("Config", {}).get("CreateCommand", {}) |
| 53 | + self.assertIn('./host_test_text.txt:/test_text.txt:z', create_command_map) |
| 54 | + |
| 55 | + out, _ = self.run_subprocess_assert_returncode([ |
| 56 | + "podman", |
| 57 | + "inspect", |
| 58 | + "selinux_container2_1", |
| 59 | + ]) |
| 60 | + inspect_out = json.loads(out) |
| 61 | + create_command_map = inspect_out[0].get("Config", {}).get("CreateCommand", {}) |
| 62 | + self.assertNotIn('./host_test_text.txt:/test_text.txt:z', create_command_map) |
| 63 | + finally: |
| 64 | + out, _ = self.run_subprocess_assert_returncode([ |
| 65 | + podman_compose_path(), |
| 66 | + "-f", |
| 67 | + compose_path, |
| 68 | + "down", |
| 69 | + ]) |
0 commit comments