Skip to content

Commit cb294d7

Browse files
mokibitp12tic
authored andcommitted
tests/integration: Automate manual 'nethost' test
Signed-off-by: Monika Kairaityte <monika@kibit.lt>
1 parent 351858d commit cb294d7

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

tests/integration/nethost/docker-compose.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ version: '3'
22
services:
33
web:
44
image: busybox
5-
command: httpd -f -p 8123 -h /etc/
5+
command: httpd -f -p 8123 -h /tmp/
66
network_mode: host
7-
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
import os
4+
import unittest
5+
6+
import requests
7+
8+
from tests.integration.test_podman_compose import podman_compose_path
9+
from tests.integration.test_podman_compose import test_path
10+
from tests.integration.test_utils import RunSubprocessMixin
11+
12+
13+
def compose_yaml_path():
14+
return os.path.join(os.path.join(test_path(), "nethost"), "docker-compose.yaml")
15+
16+
17+
class TestComposeNethost(unittest.TestCase, RunSubprocessMixin):
18+
# check if container listens for http requests and sends response back
19+
# as network_mode: host allows to connect to container easily
20+
def test_nethost(self):
21+
try:
22+
self.run_subprocess_assert_returncode(
23+
[podman_compose_path(), "-f", compose_yaml_path(), "up", "-d"],
24+
)
25+
26+
container_id, _ = self.run_subprocess_assert_returncode(
27+
[
28+
podman_compose_path(),
29+
"-f",
30+
compose_yaml_path(),
31+
"ps",
32+
"--format",
33+
'{{.ID}}',
34+
],
35+
)
36+
container_id = container_id.decode('utf-8').split('\n')[0]
37+
output, _ = self.run_subprocess_assert_returncode(
38+
[
39+
"podman",
40+
"exec",
41+
"-it",
42+
container_id,
43+
"sh",
44+
"-c",
45+
"echo test_123 >> /tmp/test.txt",
46+
],
47+
)
48+
response = requests.get('http://localhost:8123/test.txt')
49+
self.assertEqual(response.ok, True)
50+
self.assertEqual(response.text, "test_123\n")
51+
finally:
52+
self.run_subprocess_assert_returncode([
53+
podman_compose_path(),
54+
"-f",
55+
compose_yaml_path(),
56+
"down",
57+
"-t",
58+
"0",
59+
])

0 commit comments

Comments
 (0)