Debian Codegraph @

tests/integration/nets_test_ip/test_podman_compose_nets_test_ip.py

raw symbols SCIP
1 # SPDX-License-Identifier: GPL-2.0
2
3 import os
4 import unittest
5
6 from tests.integration.test_utils import RunSubprocessMixin
7 from tests.integration.test_utils import podman_compose_path
8 from tests.integration.test_utils import test_path
9
10
11 def compose_yaml_path() -> str:
12 return os.path.join(os.path.join(test_path(), "nets_test_ip"), "docker-compose.yml")
13
14
15 class TestComposeNetsTestIp(unittest.TestCase, RunSubprocessMixin):
16 # test if services retain custom ipv4_address and mac_address matching the subnet provided
17 # in networks top-level element
18 def test_nets_test_ip(self) -> None:
19 try:
20 self.run_subprocess_assert_returncode(
21 [
22 podman_compose_path(),
23 "-f",
24 compose_yaml_path(),
25 "up",
26 "-d",
27 ],
28 )
29
30 expected_results = [
31 (
32 "web1",
33 b"inet 172.19.1.10/24 ",
34 b"link/ether 02:01:01:00:01:01 ",
35 b"inet 172.19.2.10/24 ",
36 b"link/ether 02:01:01:00:02:01 ",
37 b"",
38 ),
39 ("web2", b"", b"", b"inet 172.19.2.11/24 ", b"", b"link/ether 02:01:01:00:02:02 "),
40 ("web3", b"", b"", b"inet 172.19.2.", b"", b""),
41 ("web4", b"inet 172.19.1.13/24 ", b"", b"inet 172.19.2.", b"", b""),
42 ]
43
44 for (
45 service_name,
46 shared_network_ip,
47 shared_network_mac_address,
48 internal_network_ip,
49 internal_network_mac_address,
50 mac_address,
51 ) in expected_results:
52 output, _ = self.run_subprocess_assert_returncode([
53 podman_compose_path(),
54 "-f",
55 compose_yaml_path(),
56 "exec",
57 service_name,
58 "ip",
59 "a",
60 ])
61 self.assertIn(shared_network_ip, output)
62 self.assertIn(shared_network_mac_address, output)
63 self.assertIn(internal_network_ip, output)
64 self.assertIn(internal_network_mac_address, output)
65 self.assertIn(mac_address, output)
66 finally:
67 self.run_subprocess_assert_returncode([
68 podman_compose_path(),
69 "-f",
70 compose_yaml_path(),
71 "down",
72 "-t",
73 "0",
74 ])