conftest.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. import contextlib
  2. import logging
  3. import os
  4. import re
  5. import shlex
  6. import socket
  7. import subprocess
  8. import time
  9. from typing import List
  10. import backoff
  11. import docker
  12. import pytest
  13. import requests
  14. from _pytest._code.code import ReprExceptionInfo
  15. from packaging.version import Version
  16. from docker.models.containers import Container
  17. from requests.packages.urllib3.util.connection import HAS_IPV6
  18. logging.basicConfig(level=logging.INFO)
  19. logging.getLogger('backoff').setLevel(logging.INFO)
  20. logging.getLogger('DNS').setLevel(logging.DEBUG)
  21. logging.getLogger('requests.packages.urllib3.connectionpool').setLevel(logging.WARN)
  22. CA_ROOT_CERTIFICATE = os.path.join(os.path.dirname(__file__), 'certs/ca-root.crt')
  23. PYTEST_RUNNING_IN_CONTAINER = os.environ.get('PYTEST_RUNNING_IN_CONTAINER') == "1"
  24. FORCE_CONTAINER_IPV6 = False # ugly global state to consider containers' IPv6 address instead of IPv4
  25. DOCKER_COMPOSE = os.environ.get('DOCKER_COMPOSE', 'docker compose')
  26. COMPOSE_PROFILES = os.environ.get('COMPOSE_PROFILES', 'singleContainer')
  27. IMAGE_TAG = "test-dockergen" if COMPOSE_PROFILES == "separateContainers" else "test"
  28. docker_client = docker.from_env()
  29. # Name of pytest container to reference if it's being used for running tests
  30. test_container = 'nginx-proxy-pytest'
  31. ###############################################################################
  32. #
  33. # utilities
  34. #
  35. ###############################################################################
  36. @contextlib.contextmanager
  37. def ipv6(force_ipv6=True):
  38. """
  39. Meant to be used as a context manager to force IPv6 sockets:
  40. with ipv6():
  41. nginxproxy.get("http://something.nginx-proxy.example") # force use of IPv6
  42. with ipv6(False):
  43. nginxproxy.get("http://something.nginx-proxy.example") # legacy behavior
  44. """
  45. global FORCE_CONTAINER_IPV6
  46. FORCE_CONTAINER_IPV6 = force_ipv6
  47. yield
  48. FORCE_CONTAINER_IPV6 = False
  49. class requests_for_docker(object):
  50. """
  51. Proxy for calling methods of the requests module.
  52. When a HTTP response failed due to HTTP Error 404 or 502, retry a few times.
  53. Provides method `get_conf` to extract the nginx-proxy configuration content.
  54. """
  55. def __init__(self):
  56. self.session = requests.Session()
  57. if os.path.isfile(CA_ROOT_CERTIFICATE):
  58. self.session.verify = CA_ROOT_CERTIFICATE
  59. @staticmethod
  60. def get_nginx_proxy_containers() -> List[Container]:
  61. """
  62. Return list of containers
  63. """
  64. nginx_proxy_containers = docker_client.containers.list(filters={"ancestor": f"nginxproxy/nginx-proxy:{IMAGE_TAG}"})
  65. if len(nginx_proxy_containers) > 1:
  66. pytest.fail(f"Too many running nginxproxy/nginx-proxy:{IMAGE_TAG} containers", pytrace=False)
  67. elif len(nginx_proxy_containers) == 0:
  68. pytest.fail(f"No running nginxproxy/nginx-proxy:{IMAGE_TAG} container", pytrace=False)
  69. return nginx_proxy_containers
  70. def get_conf(self):
  71. """
  72. Return the nginx config file
  73. """
  74. nginx_proxy_containers = self.get_nginx_proxy_containers()
  75. return get_nginx_conf_from_container(nginx_proxy_containers[0])
  76. def get_ip(self) -> str:
  77. """
  78. Return the nginx container ip address
  79. """
  80. nginx_proxy_containers = self.get_nginx_proxy_containers()
  81. return container_ip(nginx_proxy_containers[0])
  82. def get(self, *args, **kwargs):
  83. with ipv6(kwargs.pop('ipv6', False)):
  84. @backoff.on_predicate(backoff.constant, lambda r: r.status_code in (404, 502), interval=.3, max_tries=30, jitter=None)
  85. def _get(*args, **kwargs):
  86. return self.session.get(*args, **kwargs)
  87. return _get(*args, **kwargs)
  88. def post(self, *args, **kwargs):
  89. with ipv6(kwargs.pop('ipv6', False)):
  90. @backoff.on_predicate(backoff.constant, lambda r: r.status_code in (404, 502), interval=.3, max_tries=30, jitter=None)
  91. def _post(*args, **kwargs):
  92. return self.session.post(*args, **kwargs)
  93. return _post(*args, **kwargs)
  94. def put(self, *args, **kwargs):
  95. with ipv6(kwargs.pop('ipv6', False)):
  96. @backoff.on_predicate(backoff.constant, lambda r: r.status_code in (404, 502), interval=.3, max_tries=30, jitter=None)
  97. def _put(*args, **kwargs):
  98. return self.session.put(*args, **kwargs)
  99. return _put(*args, **kwargs)
  100. def head(self, *args, **kwargs):
  101. with ipv6(kwargs.pop('ipv6', False)):
  102. @backoff.on_predicate(backoff.constant, lambda r: r.status_code in (404, 502), interval=.3, max_tries=30, jitter=None)
  103. def _head(*args, **kwargs):
  104. return self.session.head(*args, **kwargs)
  105. return _head(*args, **kwargs)
  106. def delete(self, *args, **kwargs):
  107. with ipv6(kwargs.pop('ipv6', False)):
  108. @backoff.on_predicate(backoff.constant, lambda r: r.status_code in (404, 502), interval=.3, max_tries=30, jitter=None)
  109. def _delete(*args, **kwargs):
  110. return self.session.delete(*args, **kwargs)
  111. return _delete(*args, **kwargs)
  112. def options(self, *args, **kwargs):
  113. with ipv6(kwargs.pop('ipv6', False)):
  114. @backoff.on_predicate(backoff.constant, lambda r: r.status_code in (404, 502), interval=.3, max_tries=30, jitter=None)
  115. def _options(*args, **kwargs):
  116. return self.session.options(*args, **kwargs)
  117. return _options(*args, **kwargs)
  118. def __getattr__(self, name):
  119. return getattr(requests, name)
  120. def container_ip(container: Container):
  121. """
  122. return the IP address of a container.
  123. If the global FORCE_CONTAINER_IPV6 flag is set, return the IPv6 address
  124. """
  125. global FORCE_CONTAINER_IPV6
  126. if FORCE_CONTAINER_IPV6:
  127. if not HAS_IPV6:
  128. pytest.skip("This system does not support IPv6")
  129. ip = container_ipv6(container)
  130. if ip == '':
  131. pytest.skip(f"Container {container.name} has no IPv6 address")
  132. else:
  133. return ip
  134. else:
  135. net_info = container.attrs["NetworkSettings"]["Networks"]
  136. if "bridge" in net_info:
  137. return net_info["bridge"]["IPAddress"]
  138. # container is running in host network mode
  139. if "host" in net_info:
  140. return "127.0.0.1"
  141. # not default bridge network, fallback on first network defined
  142. network_name = list(net_info.keys())[0]
  143. return net_info[network_name]["IPAddress"]
  144. def container_ipv6(container):
  145. """
  146. return the IPv6 address of a container.
  147. """
  148. net_info = container.attrs["NetworkSettings"]["Networks"]
  149. if "bridge" in net_info:
  150. return net_info["bridge"]["GlobalIPv6Address"]
  151. # container is running in host network mode
  152. if "host" in net_info:
  153. return "::1"
  154. # not default bridge network, fallback on first network defined
  155. network_name = list(net_info.keys())[0]
  156. return net_info[network_name]["GlobalIPv6Address"]
  157. def nginx_proxy_single_container_dns_resolver(domain_name):
  158. """
  159. if "nginx-proxy" if found in host, return the ip address of the docker container
  160. issued from the docker image nginxproxy/nginx-proxy:test.
  161. :return: IP or None
  162. """
  163. log = logging.getLogger('DNS')
  164. log.debug(f"nginx_proxy_single_container_dns_resolver({domain_name!r})")
  165. if 'nginx-proxy' in domain_name:
  166. nginxproxy_containers = docker_client.containers.list(filters={"status": "running", "ancestor": "nginxproxy/nginx-proxy:test"})
  167. if len(nginxproxy_containers) == 0:
  168. log.info(f"no container found from image nginxproxy/nginx-proxy:test while resolving {domain_name!r}")
  169. exited_nginxproxy_containers = docker_client.containers.list(filters={"status": "exited", "ancestor": "nginxproxy/nginx-proxy:test"})
  170. if len(exited_nginxproxy_containers) > 0:
  171. exited_nginxproxy_container_logs = exited_nginxproxy_containers[0].logs()
  172. log.warning(f"nginxproxy/nginx-proxy:test container might have exited unexpectedly. Container logs: " + "\n" + exited_nginxproxy_container_logs.decode())
  173. return
  174. nginxproxy_container = nginxproxy_containers[0]
  175. ip = container_ip(nginxproxy_container)
  176. log.info(f"resolving domain name {domain_name!r} as IP address {ip} of nginx-proxy container {nginxproxy_container.name}")
  177. return ip
  178. def nginx_proxy_separate_containers_dns_resolver(domain_name):
  179. """
  180. if "nginx-proxy" if found in host, return the ip address of the docker container
  181. labeled with "com.github.nginx-proxy.nginx-proxy.nginx".
  182. :return: IP or None
  183. """
  184. log = logging.getLogger('DNS')
  185. log.debug(f"nginx_proxy_separate_containers_dns_resolver({domain_name!r})")
  186. if 'nginx-proxy' in domain_name:
  187. nginx_containers = docker_client.containers.list(filters={"status": "running", "label": "com.github.nginx-proxy.nginx-proxy.nginx"})
  188. if len(nginx_containers) == 0:
  189. log.info(f"no container labeled with com.github.nginx-proxy.nginx-proxy.nginx found while resolving {domain_name!r}")
  190. exited_nginx_containers = docker_client.containers.list(filters={"status": "exited", "label": "com.github.nginx-proxy.nginx-proxy.nginx"})
  191. if len(exited_nginx_containers) > 0:
  192. exited_nginx_container_logs = exited_nginx_containers[0].logs()
  193. log.warning(f"nginx container might have exited unexpectedly. Container logs: " + "\n" + exited_nginx_container_logs.decode())
  194. return
  195. nginx_container = nginx_containers[0]
  196. ip = container_ip(nginx_container)
  197. log.info(f"resolving domain name {domain_name!r} as IP address {ip} of nginx container {nginx_container.name}")
  198. return ip
  199. def docker_container_dns_resolver(domain_name):
  200. """
  201. if domain name is of the form "XXX.container.docker" or "anything.XXX.container.docker", return the ip address of the docker container
  202. named XXX.
  203. :return: IP or None
  204. """
  205. log = logging.getLogger('DNS')
  206. log.debug(f"docker_container_dns_resolver({domain_name!r})")
  207. match = re.search(r'(^|.+\.)(?P<container>[^.]+)\.container\.docker$', domain_name)
  208. if not match:
  209. log.debug(f"{domain_name!r} does not match")
  210. return
  211. container_name = match.group('container')
  212. log.debug(f"looking for container {container_name!r}")
  213. try:
  214. container = docker_client.containers.get(container_name)
  215. except docker.errors.NotFound:
  216. log.warning(f"container named {container_name!r} not found while resolving {domain_name!r}")
  217. return
  218. log.debug(f"container {container.name!r} found ({container.short_id})")
  219. ip = container_ip(container)
  220. log.info(f"resolving domain name {domain_name!r} as IP address {ip} of container {container.name}")
  221. return ip
  222. def monkey_patch_urllib_dns_resolver():
  223. """
  224. Alter the behavior of the urllib DNS resolver so that any domain name
  225. containing substring 'nginx-proxy' will resolve to the IP address
  226. of the container created from image 'nginxproxy/nginx-proxy:test' or
  227. labeled with 'com.github.nginx-proxy.nginx-proxy.nginx'.
  228. """
  229. prv_getaddrinfo = socket.getaddrinfo
  230. dns_cache = {}
  231. def new_getaddrinfo(*args):
  232. logging.getLogger('DNS').debug(f"resolving domain name {repr(args)}")
  233. _args = list(args)
  234. # Fail early when querying IP directly and it is forced ipv6 when not supported,
  235. # Otherwise a pytest container not using the host network fails to pass `test_raw-ip-vhost`.
  236. if FORCE_CONTAINER_IPV6 and not HAS_IPV6:
  237. pytest.skip("This system does not support IPv6")
  238. # custom DNS resolvers
  239. ip = nginx_proxy_single_container_dns_resolver(args[0])
  240. if ip is None:
  241. ip = nginx_proxy_separate_containers_dns_resolver(args[0])
  242. if ip is None:
  243. ip = docker_container_dns_resolver(args[0])
  244. if ip is not None:
  245. _args[0] = ip
  246. # call on original DNS resolver, with eventually the original host changed to the wanted IP address
  247. try:
  248. return dns_cache[tuple(_args)]
  249. except KeyError:
  250. res = prv_getaddrinfo(*_args)
  251. dns_cache[tuple(_args)] = res
  252. return res
  253. socket.getaddrinfo = new_getaddrinfo
  254. return prv_getaddrinfo
  255. def restore_urllib_dns_resolver(getaddrinfo_func):
  256. socket.getaddrinfo = getaddrinfo_func
  257. def remove_all_containers():
  258. for container in docker_client.containers.list(all=True):
  259. if PYTEST_RUNNING_IN_CONTAINER and container.name == test_container:
  260. continue # pytest is running within a Docker container, so we do not want to remove that particular container
  261. logging.info(f"removing container {container.name}")
  262. container.remove(v=True, force=True)
  263. def get_nginx_conf_from_container(container):
  264. """
  265. return the nginx /etc/nginx/conf.d/default.conf file content from a container
  266. """
  267. import tarfile
  268. from io import BytesIO
  269. strm_generator, stat = container.get_archive('/etc/nginx/conf.d/default.conf')
  270. strm_fileobj = BytesIO(b"".join(strm_generator))
  271. with tarfile.open(fileobj=strm_fileobj) as tf:
  272. conffile = tf.extractfile('default.conf')
  273. return conffile.read()
  274. def docker_compose_up(compose_file='docker-compose.yml'):
  275. logging.info(f'{DOCKER_COMPOSE} -f {compose_file} up -d')
  276. try:
  277. subprocess.check_output(shlex.split(f'{DOCKER_COMPOSE} -f {compose_file} up -d'), stderr=subprocess.STDOUT)
  278. except subprocess.CalledProcessError as e:
  279. pytest.fail(f"Error while runninng '{DOCKER_COMPOSE} -f {compose_file} up -d':\n{e.output}", pytrace=False)
  280. def docker_compose_down(compose_file='docker-compose.yml'):
  281. logging.info(f'{DOCKER_COMPOSE} -f {compose_file} down -v')
  282. try:
  283. subprocess.check_output(shlex.split(f'{DOCKER_COMPOSE} -f {compose_file} down -v'), stderr=subprocess.STDOUT)
  284. except subprocess.CalledProcessError as e:
  285. pytest.fail(f"Error while runninng '{DOCKER_COMPOSE} -f {compose_file} down -v':\n{e.output}", pytrace=False)
  286. def wait_for_nginxproxy_to_be_ready():
  287. """
  288. If one (and only one) container started from image nginxproxy/nginx-proxy:test
  289. or nginxproxy/nginx-proxy:test-dockergen is found, wait for its log to contain
  290. substring "Watching docker events"
  291. """
  292. containers = docker_client.containers.list(filters={"ancestor": f"nginxproxy/nginx-proxy:{IMAGE_TAG}"})
  293. if len(containers) != 1:
  294. return
  295. container = containers[0]
  296. for line in container.logs(stream=True):
  297. if b"Watching docker events" in line:
  298. logging.debug("nginx-proxy ready")
  299. break
  300. @pytest.fixture
  301. def docker_compose_file(request):
  302. """Fixture naming the docker compose file to consider.
  303. If a YAML file exists with the same name as the test module (with the `.py` extension replaced
  304. with `.yml` or `.yaml`), use that. Otherwise, use `docker-compose.yml` in the same directory
  305. as the test module.
  306. Tests can override this fixture to specify a custom location.
  307. """
  308. test_module_dir = os.path.dirname(request.module.__file__)
  309. yml_file = os.path.join(test_module_dir, request.module.__name__ + '.yml')
  310. yaml_file = os.path.join(test_module_dir, request.module.__name__ + '.yaml')
  311. default_file = os.path.join(test_module_dir, 'docker-compose.yml')
  312. if os.path.isfile(yml_file):
  313. docker_compose_file = yml_file
  314. elif os.path.isfile(yaml_file):
  315. docker_compose_file = yaml_file
  316. else:
  317. docker_compose_file = default_file
  318. if not os.path.isfile(docker_compose_file):
  319. logging.error("Could not find any docker compose file named either '{0}.yml', '{0}.yaml' or 'docker-compose.yml'".format(request.module.__name__))
  320. logging.debug(f"using docker compose file {docker_compose_file}")
  321. return docker_compose_file
  322. def connect_to_network(network):
  323. """
  324. If we are running from a container, connect our container to the given network
  325. :return: the name of the network we were connected to, or None
  326. """
  327. if PYTEST_RUNNING_IN_CONTAINER:
  328. try:
  329. my_container = docker_client.containers.get(test_container)
  330. except docker.errors.NotFound:
  331. logging.warning(f"container {test_container} not found")
  332. return
  333. # figure out our container networks
  334. my_networks = list(my_container.attrs["NetworkSettings"]["Networks"].keys())
  335. # If the pytest container is using host networking, it cannot connect to container networks (not required with host network)
  336. if 'host' in my_networks:
  337. return None
  338. # Make sure our container is connected to the nginx-proxy's network,
  339. # but avoid connecting to `none` network (not valid) with `test_server-down` tests
  340. if network.name not in my_networks and network.name != 'none':
  341. logging.info(f"Connecting to docker network: {network.name}")
  342. network.connect(my_container)
  343. return network
  344. def disconnect_from_network(network=None):
  345. """
  346. If we are running from a container, disconnect our container from the given network.
  347. :param network: name of a docker network to disconnect from
  348. """
  349. if PYTEST_RUNNING_IN_CONTAINER and network is not None:
  350. try:
  351. my_container = docker_client.containers.get(test_container)
  352. except docker.errors.NotFound:
  353. logging.warning(f"container {test_container} not found")
  354. return
  355. # figure out our container networks
  356. my_networks_names = list(my_container.attrs["NetworkSettings"]["Networks"].keys())
  357. # disconnect our container from the given network
  358. if network.name in my_networks_names:
  359. logging.info(f"Disconnecting from network {network.name}")
  360. network.disconnect(my_container)
  361. def connect_to_all_networks():
  362. """
  363. If we are running from a container, connect our container to all current docker networks.
  364. :return: a list of networks we connected to
  365. """
  366. if not PYTEST_RUNNING_IN_CONTAINER:
  367. return []
  368. else:
  369. # find the list of docker networks
  370. networks = [network for network in docker_client.networks.list(greedy=True) if len(network.containers) > 0 and network.name != 'bridge']
  371. return [connect_to_network(network) for network in networks]
  372. class DockerComposer(contextlib.AbstractContextManager):
  373. def __init__(self):
  374. self._docker_compose_file = None
  375. def __exit__(self, *exc_info):
  376. self._down()
  377. def _down(self):
  378. if self._docker_compose_file is None:
  379. return
  380. for network in self._networks:
  381. disconnect_from_network(network)
  382. docker_compose_down(self._docker_compose_file)
  383. self._docker_compose_file = None
  384. def compose(self, docker_compose_file):
  385. if docker_compose_file == self._docker_compose_file:
  386. return
  387. self._down()
  388. if docker_compose_file is None:
  389. return
  390. remove_all_containers()
  391. docker_compose_up(docker_compose_file)
  392. self._networks = connect_to_all_networks()
  393. wait_for_nginxproxy_to_be_ready()
  394. time.sleep(3) # give time to containers to be ready
  395. self._docker_compose_file = docker_compose_file
  396. ###############################################################################
  397. #
  398. # Py.test fixtures
  399. #
  400. ###############################################################################
  401. @pytest.fixture(scope="module")
  402. def docker_composer():
  403. with DockerComposer() as d:
  404. yield d
  405. @pytest.fixture
  406. def ca_root_certificate():
  407. return CA_ROOT_CERTIFICATE
  408. @pytest.fixture
  409. def monkey_patched_dns():
  410. original_dns_resolver = monkey_patch_urllib_dns_resolver()
  411. yield
  412. restore_urllib_dns_resolver(original_dns_resolver)
  413. @pytest.fixture
  414. def docker_compose(monkey_patched_dns, docker_composer, docker_compose_file):
  415. """Ensures containers described in a docker compose file are started.
  416. A custom docker compose file name can be specified by overriding the `docker_compose_file`
  417. fixture.
  418. Also, in the case where pytest is running from a docker container, this fixture makes sure
  419. our container will be attached to all the docker networks.
  420. """
  421. docker_composer.compose(docker_compose_file)
  422. yield docker_client
  423. @pytest.fixture()
  424. def nginxproxy():
  425. """
  426. Provides the `nginxproxy` object that can be used in the same way the requests module is:
  427. r = nginxproxy.get("http://foo.com")
  428. The difference is that in case an HTTP requests has status code 404 or 502 (which mostly
  429. indicates that nginx has just reloaded), we retry up to 30 times the query.
  430. Also, the nginxproxy methods accept an additional keyword parameter: `ipv6` which forces requests
  431. made against containers to use the containers IPv6 address when set to `True`. If IPv6 is not
  432. supported by the system or docker, that particular test will be skipped.
  433. """
  434. yield requests_for_docker()
  435. @pytest.fixture()
  436. def acme_challenge_path():
  437. """
  438. Provides fake Let's Encrypt ACME challenge path used in certain tests
  439. """
  440. return ".well-known/acme-challenge/test-filename"
  441. ###############################################################################
  442. #
  443. # Py.test hooks
  444. #
  445. ###############################################################################
  446. # pytest hook to display additionnal stuff in test report
  447. def pytest_runtest_logreport(report):
  448. if report.failed:
  449. if isinstance(report.longrepr, ReprExceptionInfo):
  450. nginx_containers = docker_client.containers.list(all=True, filters={"label": "com.github.nginx-proxy.nginx-proxy.nginx"})
  451. for container in nginx_containers:
  452. report.longrepr.addsection('nginx container logs', container.logs())
  453. test_containers = docker_client.containers.list(all=True, filters={"ancestor": f"nginxproxy/nginx-proxy:{IMAGE_TAG}"})
  454. for container in test_containers:
  455. report.longrepr.addsection('nginx-proxy logs', container.logs())
  456. report.longrepr.addsection('nginx-proxy conf', get_nginx_conf_from_container(container))
  457. # Py.test `incremental` marker, see http://stackoverflow.com/a/12579625/107049
  458. def pytest_runtest_makereport(item, call):
  459. if "incremental" in item.keywords:
  460. if call.excinfo is not None:
  461. parent = item.parent
  462. parent._previousfailed = item
  463. def pytest_runtest_setup(item):
  464. previousfailed = getattr(item.parent, "_previousfailed", None)
  465. if previousfailed is not None:
  466. pytest.xfail(f"previous test failed ({previousfailed.name})")
  467. ###############################################################################
  468. #
  469. # Check requirements
  470. #
  471. ###############################################################################
  472. try:
  473. docker_client.images.get(f"nginxproxy/nginx-proxy:{IMAGE_TAG}")
  474. except docker.errors.ImageNotFound:
  475. pytest.exit(f"The docker image 'nginxproxy/nginx-proxy:{IMAGE_TAG}' is missing")
  476. if Version(docker.__version__) < Version("7.0.0"):
  477. pytest.exit("This test suite is meant to work with the python docker module v7.0.0 or later")