mirror of
https://github.com/containers/podman-compose.git
synced 2025-02-04 20:39:18 +01:00
Add testcase for failing network config
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
This commit is contained in:
parent
6103df78fb
commit
dd34a90068
59
tests/nets_test_ip/docker-compose.yml
Normal file
59
tests/nets_test_ip/docker-compose.yml
Normal file
@ -0,0 +1,59 @@
|
||||
version: "3"
|
||||
networks:
|
||||
shared-network:
|
||||
driver: bridge
|
||||
ipam:
|
||||
config:
|
||||
- subnet: "172.19.1.0/24"
|
||||
internal-network:
|
||||
driver: bridge
|
||||
ipam:
|
||||
config:
|
||||
- subnet: "172.19.2.0/24"
|
||||
|
||||
services:
|
||||
web1:
|
||||
image: busybox
|
||||
hostname: web1
|
||||
command: ["/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8001"]
|
||||
working_dir: /var/www/html
|
||||
networks:
|
||||
shared-network:
|
||||
ipv4_address: "172.19.1.10"
|
||||
internal-network:
|
||||
ipv4_address: "172.19.2.10"
|
||||
volumes:
|
||||
- ./test1.txt:/var/www/html/index.txt:ro,z
|
||||
web2:
|
||||
image: busybox
|
||||
hostname: web2
|
||||
command: ["/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8001"]
|
||||
working_dir: /var/www/html
|
||||
mac_address: "02:01:01:00:02:02"
|
||||
networks:
|
||||
internal-network:
|
||||
ipv4_address: "172.19.2.11"
|
||||
volumes:
|
||||
- ./test2.txt:/var/www/html/index.txt:ro,z
|
||||
|
||||
web3:
|
||||
image: busybox
|
||||
hostname: web2
|
||||
command: ["/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8001"]
|
||||
working_dir: /var/www/html
|
||||
networks:
|
||||
internal-network:
|
||||
volumes:
|
||||
- ./test3.txt:/var/www/html/index.txt:ro,z
|
||||
|
||||
web4:
|
||||
image: busybox
|
||||
hostname: web2
|
||||
command: ["/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8001"]
|
||||
working_dir: /var/www/html
|
||||
networks:
|
||||
internal-network:
|
||||
shared-network:
|
||||
ipv4_address: "172.19.1.13"
|
||||
volumes:
|
||||
- ./test4.txt:/var/www/html/index.txt:ro,z
|
1
tests/nets_test_ip/test1.txt
Normal file
1
tests/nets_test_ip/test1.txt
Normal file
@ -0,0 +1 @@
|
||||
test1
|
1
tests/nets_test_ip/test2.txt
Normal file
1
tests/nets_test_ip/test2.txt
Normal file
@ -0,0 +1 @@
|
||||
test2
|
1
tests/nets_test_ip/test3.txt
Normal file
1
tests/nets_test_ip/test3.txt
Normal file
@ -0,0 +1 @@
|
||||
test3
|
1
tests/nets_test_ip/test4.txt
Normal file
1
tests/nets_test_ip/test4.txt
Normal file
@ -0,0 +1 @@
|
||||
test4
|
112
tests/test_podman_compose_networks.py
Normal file
112
tests/test_podman_compose_networks.py
Normal file
@ -0,0 +1,112 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
"""
|
||||
test_podman_compose_networks.py
|
||||
|
||||
Tests the podman networking parameters
|
||||
"""
|
||||
|
||||
# pylint: disable=redefined-outer-name
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from .test_podman_compose import podman_compose_path
|
||||
from .test_podman_compose import test_path
|
||||
from .test_utils import RunSubprocessMixin
|
||||
|
||||
|
||||
class TestPodmanComposeNetwork(RunSubprocessMixin, unittest.TestCase):
|
||||
@staticmethod
|
||||
def compose_file():
|
||||
"""Returns the path to the compose file used for this test module"""
|
||||
return os.path.join(test_path(), "nets_test_ip", "docker-compose.yml")
|
||||
|
||||
def teardown(self):
|
||||
"""
|
||||
Ensures that the services within the "profile compose file" are removed between
|
||||
each test case.
|
||||
"""
|
||||
# run the test case
|
||||
yield
|
||||
|
||||
down_cmd = [
|
||||
"coverage",
|
||||
"run",
|
||||
podman_compose_path(),
|
||||
"-f",
|
||||
self.compose_file(),
|
||||
"kill",
|
||||
"-a",
|
||||
]
|
||||
self.run_subprocess(down_cmd)
|
||||
|
||||
def test_networks(self):
|
||||
up_cmd = [
|
||||
"coverage",
|
||||
"run",
|
||||
podman_compose_path(),
|
||||
"-f",
|
||||
self.compose_file(),
|
||||
"up",
|
||||
"-d",
|
||||
"--force-recreate",
|
||||
]
|
||||
|
||||
self.run_subprocess_assert_returncode(up_cmd)
|
||||
|
||||
check_cmd = [
|
||||
podman_compose_path(),
|
||||
"-f",
|
||||
self.compose_file(),
|
||||
"ps",
|
||||
"--format",
|
||||
'"{{.Names}}"',
|
||||
]
|
||||
out, _ = self.run_subprocess_assert_returncode(check_cmd)
|
||||
self.assertIn(b"nets_test_ip_web1_1", out)
|
||||
self.assertIn(b"nets_test_ip_web2_1", out)
|
||||
|
||||
expected_wget = {
|
||||
"172.19.1.10": "test1",
|
||||
"172.19.2.10": "test1",
|
||||
"172.19.2.11": "test2",
|
||||
"web3": "test3",
|
||||
"172.19.1.13": "test4",
|
||||
}
|
||||
|
||||
for service in ("web1", "web2"):
|
||||
for ip, expect in expected_wget.items():
|
||||
wget_cmd = [
|
||||
podman_compose_path(),
|
||||
"-f",
|
||||
self.compose_file(),
|
||||
"exec",
|
||||
service,
|
||||
"wget",
|
||||
"-q",
|
||||
"-O-",
|
||||
f"http://{ip}:8001/index.txt",
|
||||
]
|
||||
out, _ = self.run_subprocess_assert_returncode(wget_cmd)
|
||||
self.assertEqual(f"{expect}\r\n", out.decode('utf-8'))
|
||||
|
||||
expected_macip = {
|
||||
"web1": {"eth0": ["172.19.1.10"], "eth1": ["172.19.2.10"]},
|
||||
"web2": {"eth0": ["172.19.2.11"]},
|
||||
}
|
||||
|
||||
for service, interfaces in expected_macip.items():
|
||||
ip_cmd = [
|
||||
podman_compose_path(),
|
||||
"-f",
|
||||
self.compose_file(),
|
||||
"exec",
|
||||
service,
|
||||
"ip",
|
||||
"addr",
|
||||
"show",
|
||||
]
|
||||
out, _ = self.run_subprocess_assert_returncode(ip_cmd)
|
||||
for interface, values in interfaces.items():
|
||||
ip = values[0]
|
||||
self.assertIn(f"inet {ip}/", out.decode('utf-8'))
|
Loading…
Reference in New Issue
Block a user