|
| 1 | +# SPDX-License-Identifier: GPL-2.0 |
| 2 | + |
| 3 | +import json |
| 4 | +import os |
| 5 | +import subprocess |
| 6 | +import unittest |
| 7 | + |
| 8 | +from tests.integration.test_utils import RunSubprocessMixin |
| 9 | +from tests.integration.test_utils import podman_compose_path |
| 10 | +from tests.integration.test_utils import test_path |
| 11 | + |
| 12 | + |
| 13 | +class TestPodmanCompose(unittest.TestCase, RunSubprocessMixin): |
| 14 | + def test_selinux(self): |
| 15 | + # test if when using volumes type:bind with selinux:z option, container ackquires a |
| 16 | + # respective host:source:z mapping in CreateCommand list |
| 17 | + compose_path = os.path.join(test_path(), "selinux", "docker-compose.yml") |
| 18 | + try: |
| 19 | + # change working directory to where docker-compose.yml file is so that containers can |
| 20 | + # directly access host source file for mounting from that working directory |
| 21 | + subprocess.run( |
| 22 | + [ |
| 23 | + podman_compose_path(), |
| 24 | + "-f", |
| 25 | + compose_path, |
| 26 | + "up", |
| 27 | + "-d", |
| 28 | + "container1", |
| 29 | + "container2", |
| 30 | + ], |
| 31 | + cwd=os.path.join(test_path(), 'selinux'), |
| 32 | + ) |
| 33 | + out, _ = self.run_subprocess_assert_returncode([ |
| 34 | + "podman", |
| 35 | + "inspect", |
| 36 | + "selinux_container1_1", |
| 37 | + ]) |
| 38 | + 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) |
| 41 | + |
| 42 | + out, _ = self.run_subprocess_assert_returncode([ |
| 43 | + "podman", |
| 44 | + "inspect", |
| 45 | + "selinux_container2_1", |
| 46 | + ]) |
| 47 | + 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) |
| 50 | + finally: |
| 51 | + out, _ = self.run_subprocess_assert_returncode([ |
| 52 | + podman_compose_path(), |
| 53 | + "-f", |
| 54 | + compose_path, |
| 55 | + "down", |
| 56 | + "-t", |
| 57 | + "0", |
| 58 | + ]) |
0 commit comments