| 1 |
|
| 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) -> None: |
| 15 |
|
| 16 |
|
| 17 |
compose_path = os.path.join(test_path(), "selinux", "docker-compose.yml") |
| 18 |
try: |
| 19 |
|
| 20 |
|
| 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 |
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) |
| 42 |
|
| 43 |
out, _ = self.run_subprocess_assert_returncode([ |
| 44 |
"podman", |
| 45 |
"inspect", |
| 46 |
"selinux_container2_1", |
| 47 |
]) |
| 48 |
inspect_out = json.loads(out) |
| 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) |
| 52 |
finally: |
| 53 |
out, _ = self.run_subprocess_assert_returncode([ |
| 54 |
podman_compose_path(), |
| 55 |
"-f", |
| 56 |
compose_path, |
| 57 |
"down", |
| 58 |
"-t", |
| 59 |
"0", |
| 60 |
]) |