|
| 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 test_selinux(self): |
| 14 | + # test if when using volumes type:bind with selinux:z option, container ackquires a |
| 15 | + # respective host:source:z mapping in CreateCommand list |
| 16 | + # change working directory to where docker-compose.yml file is so that containers can |
| 17 | + # directly access host source file for mounting from that working directory |
| 18 | + os.chdir(os.path.join(test_path(), 'selinux')) |
| 19 | + try: |
| 20 | + self.run_subprocess_assert_returncode([ |
| 21 | + podman_compose_path(), |
| 22 | + "up", |
| 23 | + "-d", |
| 24 | + "container1", |
| 25 | + "container2", |
| 26 | + ]) |
| 27 | + |
| 28 | + out, _ = self.run_subprocess_assert_returncode([ |
| 29 | + "podman", |
| 30 | + "inspect", |
| 31 | + "selinux_container1_1", |
| 32 | + ]) |
| 33 | + inspect_out = json.loads(out) |
| 34 | + create_command_list = inspect_out[0].get("Config", {}).get("CreateCommand", {}) |
| 35 | + self.assertIn('./host_test_text.txt:/test_text.txt:z', create_command_list) |
| 36 | + |
| 37 | + out, _ = self.run_subprocess_assert_returncode([ |
| 38 | + "podman", |
| 39 | + "inspect", |
| 40 | + "selinux_container2_1", |
| 41 | + ]) |
| 42 | + inspect_out = json.loads(out) |
| 43 | + create_command_list = inspect_out[0].get("Config", {}).get("CreateCommand", {}) |
| 44 | + self.assertIn('./host_test_text.txt:/test_text.txt', create_command_list) |
| 45 | + finally: |
| 46 | + out, _ = self.run_subprocess_assert_returncode([ |
| 47 | + podman_compose_path(), |
| 48 | + "down", |
| 49 | + "-t", |
| 50 | + "0", |
| 51 | + ]) |
0 commit comments