| 1 |
|
| 2 |
|
| 3 |
import json |
| 4 |
import os |
| 5 |
import unittest |
| 6 |
|
| 7 |
from tests.integration.test_utils import RunSubprocessMixin |
| 8 |
from tests.integration.test_utils import podman_compose_path |
| 9 |
from tests.integration.test_utils import test_path |
| 10 |
|
| 11 |
|
| 12 |
def compose_yaml_path() -> str: |
| 13 |
return os.path.join(os.path.join(test_path(), "ipam_default"), "docker-compose.yaml") |
| 14 |
|
| 15 |
|
| 16 |
class TestComposeIpamDefault(unittest.TestCase, RunSubprocessMixin): |
| 17 |
def test_ipam_default(self) -> None: |
| 18 |
try: |
| 19 |
self.run_subprocess_assert_returncode( |
| 20 |
[podman_compose_path(), "-f", compose_yaml_path(), "up", "-d"], |
| 21 |
) |
| 22 |
|
| 23 |
output, _ = self.run_subprocess_assert_returncode([ |
| 24 |
podman_compose_path(), |
| 25 |
"-f", |
| 26 |
compose_yaml_path(), |
| 27 |
"logs", |
| 28 |
]) |
| 29 |
|
| 30 |
|
| 31 |
self.assertIn("ipamtest", str(output)) |
| 32 |
|
| 33 |
output, _ = self.run_subprocess_assert_returncode( |
| 34 |
[ |
| 35 |
"podman", |
| 36 |
"inspect", |
| 37 |
"ipam_default_testipam_1", |
| 38 |
], |
| 39 |
) |
| 40 |
network_info = json.loads(output.decode('utf-8'))[0] |
| 41 |
network_name = next(iter(network_info["NetworkSettings"]["Networks"].keys())) |
| 42 |
|
| 43 |
output, _ = self.run_subprocess_assert_returncode([ |
| 44 |
"podman", |
| 45 |
"network", |
| 46 |
"inspect", |
| 47 |
f"{network_name}", |
| 48 |
]) |
| 49 |
network_info = json.loads(output.decode('utf-8'))[0] |
| 50 |
|
| 51 |
self.assertEqual(network_info['driver'], "bridge") |
| 52 |
self.assertEqual(network_info['ipam_options'], {'driver': 'host-local'}) |
| 53 |
finally: |
| 54 |
self.run_subprocess_assert_returncode([ |
| 55 |
podman_compose_path(), |
| 56 |
"-f", |
| 57 |
compose_yaml_path(), |
| 58 |
"down", |
| 59 |
]) |