Merge branch 'fix/label-scoped-attach'
This commit is contained in:
commit
53104905b9
2 changed files with 52 additions and 0 deletions
|
|
@ -26,6 +26,9 @@ class Docker(ProcessorInterface):
|
|||
|
||||
self.parsed_object = {}
|
||||
for container in self.client.containers.list():
|
||||
if not any(self.label in key for key in container.labels):
|
||||
continue
|
||||
|
||||
# Issue 32 - Docker container cannot connect to containers in different network.
|
||||
if ha_proxy_network_name not in container.attrs["NetworkSettings"]["Networks"].keys():
|
||||
ha_proxy_network.connect(container.name)
|
||||
|
|
|
|||
|
|
@ -105,4 +105,53 @@ def test_processor_docker():
|
|||
container2.stop()
|
||||
|
||||
|
||||
def test_processor_docker_ignores_unlabeled():
|
||||
try:
|
||||
client = docker.from_env()
|
||||
except docker.errors.DockerException:
|
||||
pytest.skip("There is no docker environment")
|
||||
|
||||
if len(client.containers.list()) > 0:
|
||||
pytest.skip("I cannot run this test with other containers running.")
|
||||
|
||||
network = client.networks.create("test_processor_docker_network", driver="bridge")
|
||||
# The most recent container is inspected first, so the labeled one defines the network to use.
|
||||
unlabeled = client.containers.run("byjg/static-httpserver",
|
||||
name="test_processor_docker_unlabeled",
|
||||
detach=True,
|
||||
auto_remove=True,
|
||||
remove=True)
|
||||
time.sleep(1)
|
||||
container = client.containers.run("byjg/static-httpserver",
|
||||
name="test_processor_docker_labeled",
|
||||
detach=True,
|
||||
auto_remove=True,
|
||||
remove=True,
|
||||
network=network.name,
|
||||
labels={
|
||||
"easyhaproxy.labeled.port": "80",
|
||||
"easyhaproxy.labeled.localport": "8080",
|
||||
"easyhaproxy.labeled.host": "labeled.local",
|
||||
})
|
||||
try:
|
||||
time.sleep(1)
|
||||
|
||||
static = ProcessorInterface.factory(ProcessorInterface.DOCKER)
|
||||
|
||||
# The labeled container is served through the network it already belongs to.
|
||||
labeled_ip = client.containers.get(container.name).attrs["NetworkSettings"]["Networks"][network.name][
|
||||
"IPAddress"]
|
||||
assert _get_ip_host(static.get_parsed_object(), "easyhaproxy.labeled") == labeled_ip
|
||||
|
||||
# The container without any label is neither inspected nor connected to the network.
|
||||
unlabeled_networks = client.containers.get(unlabeled.name).attrs["NetworkSettings"]["Networks"]
|
||||
assert list(unlabeled_networks.keys()) == ["bridge"]
|
||||
assert unlabeled_networks["bridge"]["IPAddress"] not in static.get_parsed_object()
|
||||
finally:
|
||||
container.stop()
|
||||
unlabeled.stop()
|
||||
time.sleep(1)
|
||||
network.remove()
|
||||
|
||||
|
||||
# test_processor_docker()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue