mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-02-24 09:48:14 +00:00
chore: Extract hostname access to a var
DRY and clearer that we're referring to the pytest container.
This commit is contained in:
parent
93c04dce8d
commit
e748d53a1f
@ -28,6 +28,7 @@ FORCE_CONTAINER_IPV6 = False # ugly global state to consider containers' IPv6 a
|
|||||||
|
|
||||||
|
|
||||||
docker_client = docker.from_env()
|
docker_client = docker.from_env()
|
||||||
|
test_container = socket.gethostname()
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -259,7 +260,7 @@ def restore_urllib_dns_resolver(getaddrinfo_func):
|
|||||||
|
|
||||||
def remove_all_containers():
|
def remove_all_containers():
|
||||||
for container in docker_client.containers.list(all=True):
|
for container in docker_client.containers.list(all=True):
|
||||||
if PYTEST_RUNNING_IN_CONTAINER and container.id.startswith(socket.gethostname()):
|
if PYTEST_RUNNING_IN_CONTAINER and container.id.startswith(test_container):
|
||||||
continue # pytest is running within a Docker container, so we do not want to remove that particular container
|
continue # pytest is running within a Docker container, so we do not want to remove that particular container
|
||||||
logging.info(f"removing container {container.name}")
|
logging.info(f"removing container {container.name}")
|
||||||
container.remove(v=True, force=True)
|
container.remove(v=True, force=True)
|
||||||
@ -351,9 +352,9 @@ def connect_to_network(network):
|
|||||||
"""
|
"""
|
||||||
if PYTEST_RUNNING_IN_CONTAINER:
|
if PYTEST_RUNNING_IN_CONTAINER:
|
||||||
try:
|
try:
|
||||||
my_container = docker_client.containers.get(socket.gethostname())
|
my_container = docker_client.containers.get(test_container)
|
||||||
except docker.errors.NotFound:
|
except docker.errors.NotFound:
|
||||||
logging.warn(f"container {socket.gethostname()!r} not found")
|
logging.warn(f"container {test_container} not found")
|
||||||
return
|
return
|
||||||
|
|
||||||
# figure out our container networks
|
# figure out our container networks
|
||||||
@ -374,9 +375,9 @@ def disconnect_from_network(network=None):
|
|||||||
"""
|
"""
|
||||||
if PYTEST_RUNNING_IN_CONTAINER and network is not None:
|
if PYTEST_RUNNING_IN_CONTAINER and network is not None:
|
||||||
try:
|
try:
|
||||||
my_container = docker_client.containers.get(socket.gethostname())
|
my_container = docker_client.containers.get(test_container)
|
||||||
except docker.errors.NotFound:
|
except docker.errors.NotFound:
|
||||||
logging.warn(f"container {socket.gethostname()!r} not found")
|
logging.warn(f"container {test_container} not found")
|
||||||
return
|
return
|
||||||
|
|
||||||
# figure out our container networks
|
# figure out our container networks
|
||||||
|
Loading…
x
Reference in New Issue
Block a user