Created
January 8, 2020 04:36
-
-
Save AstraLuma/fcbf7f96d08685a2252a672b8574f54a to your computer and use it in GitHub Desktop.
Podman Varlink Networking Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contextlib | |
import json | |
import os.path | |
import subprocess | |
import tempfile | |
import time | |
from varlink import Client | |
IMG = "quay.io/libpod/alpine_nginx:latest" | |
@contextlib.contextmanager | |
def client(): | |
socket = tempfile.mktemp() | |
proc = subprocess.Popen( | |
['podman', 'varlink', '--timeout', '0', f'unix:{socket}'], | |
stdin=subprocess.DEVNULL, | |
stdout=subprocess.DEVNULL, | |
) | |
# Wait for it to start | |
while not os.path.exists(socket): | |
time.sleep(0.1) | |
try: | |
with Client(f'unix:{socket}') as client, client.open("io.podman") as connection: | |
yield connection | |
finally: | |
# Since the process doesn't have to timeout, we have to signal it to stop | |
proc.terminate() | |
with client() as podman: | |
img_id = podman.PullImage(IMG)['reply']['id'] | |
results = podman.InspectImage(img_id) | |
deets = json.loads(results['image']) | |
container_args = { | |
'command': deets['Config']['Cmd'], | |
'env': deets['Config']['Env'], | |
'args': [img_id, *deets['Config']['Cmd']], | |
} | |
# (Y) Test 1: Publish pod | |
pod1 = podman.CreatePod({ | |
'name': "test1", 'publish': ["8081:80"], | |
'infra': True, 'share': ['cgroup', 'ipc', 'net', 'uts'], | |
})['pod'] | |
con1 = podman.CreateContainer({'pod': pod1, **container_args})['container'] | |
podman.StartPod(pod1) | |
# (Y) Test 2: Publish container | |
pod2 = podman.CreatePod({'name': "test2"})['pod'] | |
con2 = podman.CreateContainer({ | |
'pod': pod2, 'publish': ["8082:80"], **container_args | |
})['container'] | |
podman.StartPod(pod2) | |
# (N) Test 3: Publish pod and container (parallel) | |
# pod3 = podman.CreatePod({ | |
# 'name': "test3", 'publish': ["8083:80"], | |
# 'infra': True, 'share': ['cgroup', 'ipc', 'net', 'uts'], | |
# })['pod'] | |
# con3 = podman.CreateContainer({ | |
# 'pod': pod3, 'publish': ["8083:80"], **container_args | |
# })['container'] | |
# # VarlinkError: {'parameters': {'reason': 'cannot set port bindings on an existing container network namespace'}, 'error': 'io.podman.ErrorOccurred'} | |
# podman.StartPod(pod3) | |
# (N) Test 4: Publish pod and container (routed) | |
# pod4 = podman.CreatePod({ | |
# 'name': "test4", 'publish': ["8084:80"], | |
# 'infra': True, 'share': ['cgroup', 'ipc', 'net', 'uts'], | |
# })['pod'] | |
# con4 = podman.CreateContainer({ | |
# 'pod': pod4, 'publish': ["80:80"], **container_args | |
# })['container'] | |
# # VarlinkError: {'parameters': {'reason': 'cannot set port bindings on an existing container network namespace'}, 'error': 'io.podman.ErrorOccurred'} | |
# podman.StartPod(pod4) | |
# (N) Test 5: Publish container (with infra container) | |
# pod5 = podman.CreatePod({ | |
# 'name': "test5", | |
# 'infra': True, 'share': ['cgroup', 'ipc', 'net', 'uts'], | |
# })['pod'] | |
# con5 = podman.CreateContainer({ | |
# 'pod': pod5, 'publish': ["8085:80"], **container_args | |
# })['container'] | |
# # VarlinkError: {'parameters': {'reason': 'cannot set port bindings on an existing container network namespace'}, 'error': 'io.podman.ErrorOccurred'} | |
# podman.StartPod(pod2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment