mirror of
https://github.com/containers/podman-compose.git
synced 2025-06-13 00:16:55 +02:00
Add integration test for network scoped aliases
Signed-off-by: Songmin Li <lisongmin@protonmail.com>
This commit is contained in:
parent
978a1381bc
commit
55642247e3
@ -983,9 +983,9 @@ def get_net_args_from_networks(compose, cnt):
|
|||||||
|
|
||||||
ipv4 = net_config_.get("ipv4_address")
|
ipv4 = net_config_.get("ipv4_address")
|
||||||
ipv6 = net_config_.get("ipv6_address")
|
ipv6 = net_config_.get("ipv6_address")
|
||||||
|
# custom extension; not supported by docker-compose v3
|
||||||
mac = net_config_.get("x-podman.mac_address")
|
mac = net_config_.get("x-podman.mac_address")
|
||||||
aliases_on_net = net_config_.get("aliases")
|
aliases_on_net = norm_as_list(net_config_.get("aliases", []))
|
||||||
|
|
||||||
# if a mac_address was specified on the container level, apply it to the first network
|
# if a mac_address was specified on the container level, apply it to the first network
|
||||||
# This works for Python > 3.6, because dict insert ordering is preserved, so we are
|
# This works for Python > 3.6, because dict insert ordering is preserved, so we are
|
||||||
|
33
tests/integration/network_scoped_aliases/docker-compose.yaml
Normal file
33
tests/integration/network_scoped_aliases/docker-compose.yaml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
---
|
||||||
|
networks:
|
||||||
|
net0:
|
||||||
|
ipam:
|
||||||
|
config:
|
||||||
|
- subnet: "172.19.3.0/24"
|
||||||
|
net1:
|
||||||
|
ipam:
|
||||||
|
config:
|
||||||
|
- subnet: "172.19.4.0/24"
|
||||||
|
services:
|
||||||
|
web1:
|
||||||
|
image: busybox
|
||||||
|
command: ["/bin/busybox", "httpd", "-f", "-h", "/tmp", "-p", "8001"]
|
||||||
|
networks:
|
||||||
|
net0:
|
||||||
|
ipv4_address: "172.19.3.11"
|
||||||
|
aliases:
|
||||||
|
- secure-web
|
||||||
|
net1:
|
||||||
|
ipv4_address: "172.19.4.11"
|
||||||
|
aliases:
|
||||||
|
- insecure-web
|
||||||
|
utils-net0:
|
||||||
|
image: busybox
|
||||||
|
command: ["/bin/busybox", "httpd", "-f", "-h", "/tmp", "-p", "8001"]
|
||||||
|
networks:
|
||||||
|
- net0
|
||||||
|
utils-net1:
|
||||||
|
image: busybox
|
||||||
|
command: ["/bin/busybox", "httpd", "-f", "-h", "/tmp", "-p", "8001"]
|
||||||
|
networks:
|
||||||
|
- net1
|
@ -0,0 +1,84 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-2.0
|
||||||
|
|
||||||
|
# pylint: disable=redefined-outer-name
|
||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from tests.integration.test_podman_compose import podman_compose_path
|
||||||
|
from tests.integration.test_podman_compose import test_path
|
||||||
|
from tests.integration.test_utils import RunSubprocessMixin
|
||||||
|
|
||||||
|
|
||||||
|
class TestPodmanComposeNetworkScopedAliases(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(), "network_scoped_aliases", "docker-compose.yaml")
|
||||||
|
|
||||||
|
def test_network_scoped_aliases(self):
|
||||||
|
try:
|
||||||
|
self.up()
|
||||||
|
self.verify()
|
||||||
|
finally:
|
||||||
|
self.down()
|
||||||
|
|
||||||
|
def up(self):
|
||||||
|
up_cmd = [
|
||||||
|
"coverage",
|
||||||
|
"run",
|
||||||
|
podman_compose_path(),
|
||||||
|
"-f",
|
||||||
|
self.compose_file(),
|
||||||
|
"up",
|
||||||
|
"-d",
|
||||||
|
"--force-recreate",
|
||||||
|
]
|
||||||
|
|
||||||
|
self.run_subprocess_assert_returncode(up_cmd)
|
||||||
|
|
||||||
|
def down(self):
|
||||||
|
down_cmd = [
|
||||||
|
"coverage",
|
||||||
|
"run",
|
||||||
|
podman_compose_path(),
|
||||||
|
"-f",
|
||||||
|
self.compose_file(),
|
||||||
|
"kill",
|
||||||
|
"-a",
|
||||||
|
]
|
||||||
|
self.run_subprocess(down_cmd)
|
||||||
|
|
||||||
|
def verify(self):
|
||||||
|
expected_results = [
|
||||||
|
("utils-net0", "web1", ["172.19.3.11"]),
|
||||||
|
("utils-net0", "secure-web", ["172.19.3.11"]),
|
||||||
|
("utils-net0", "insecure-web", []),
|
||||||
|
("utils-net1", "web1", ["172.19.4.11"]),
|
||||||
|
("utils-net1", "secure-web", []),
|
||||||
|
("utils-net1", "insecure-web", ["172.19.4.11"]),
|
||||||
|
]
|
||||||
|
|
||||||
|
for utils, service, expected_result in expected_results:
|
||||||
|
cmd = [
|
||||||
|
podman_compose_path(),
|
||||||
|
"-f",
|
||||||
|
self.compose_file(),
|
||||||
|
"exec",
|
||||||
|
utils,
|
||||||
|
"nslookup",
|
||||||
|
service,
|
||||||
|
]
|
||||||
|
out, _, _ = self.run_subprocess(cmd)
|
||||||
|
addresses = self.parse_dnslookup(out.decode())
|
||||||
|
self.assertEqual(addresses, expected_result)
|
||||||
|
|
||||||
|
def parse_dnslookup(self, output):
|
||||||
|
lines = output.splitlines()
|
||||||
|
addresses = []
|
||||||
|
for line in lines:
|
||||||
|
if line.startswith("Address"):
|
||||||
|
addr = line.split(":", 1)[1].strip()
|
||||||
|
if ":" not in addr:
|
||||||
|
addresses.append(addr)
|
||||||
|
|
||||||
|
return list(sorted(set(addresses)))
|
Loading…
x
Reference in New Issue
Block a user