Skip to content

Commit 52e2912

Browse files
authored
Merge pull request #1157 from mokibit/automate-selinux-test
test/integration: Automate manual `selinux` test
2 parents 04fcc26 + 8ef537e commit 52e2912

File tree

3 files changed

+70
-7
lines changed

3 files changed

+70
-7
lines changed
+11-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
version: "3"
22
services:
3-
web1:
3+
container1:
44
image: busybox
5-
command: httpd -f -p 80 -h /var/www/html
5+
command: ["busybox", "sleep", "infinity"]
66
volumes:
77
- type: bind
8-
source: ./docker-compose.yml
9-
target: /var/www/html/index.html
8+
source: ./host_test_text.txt
9+
target: /test_text.txt
1010
bind:
1111
selinux: z
12-
ports:
13-
- "8080:80"
14-
12+
container2:
13+
image: busybox
14+
command: ["busybox", "sleep", "infinity"]
15+
volumes:
16+
- type: bind
17+
source: ./host_test_text.txt
18+
target: /test_text.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# There must be a source file in the host for volumes type: bind
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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

Comments
 (0)