From 862f2afe226492ee17e9e93ff98a604aa744e702 Mon Sep 17 00:00:00 2001 From: Pietro Pasotti Date: Wed, 18 Oct 2023 10:25:20 +0200 Subject: [PATCH] fixed itest --- src/traefik.py | 15 ++++++++++++++- tests/integration/test_tls.py | 2 +- tox.ini | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/traefik.py b/src/traefik.py index 7c1c4567..1b787336 100644 --- a/src/traefik.py +++ b/src/traefik.py @@ -124,6 +124,7 @@ def configure(self): # Ensure the required basic configurations and folders exist tcp_entrypoints = self._tcp_entrypoints self._update_static_configuration(tcp_entrypoints) + self._setup_dynamic_config_folder() if self._tls_enabled: self._update_tls_configuration() @@ -532,7 +533,14 @@ def delete_dynamic_config(self, file_name: str): logger.debug("deleted dynamic configuration file: %s", file_name) def add_dynamic_config(self, file_name: str, config: str): - """Push a yaml to the dynamic config dir.""" + """Push a yaml to the dynamic config dir. + + The dynamic config dir is assumed to exist already. + """ + # make_dirs is technically not necessary at runtime, since traefik.configure() should + # guarantee that the dynamic config dir exists. However, it simplifies testing as it means + # we don't have to worry about setting up manually the traefik container every time we + # simulate an event. self._container.push(Path(DYNAMIC_CONFIG_DIR) / file_name, config, make_dirs=True) logger.debug("Updated dynamic configuration file: %s", file_name) @@ -585,3 +593,8 @@ def generate_per_unit_tcp_config(prefix: str, host: str, port: int) -> dict: } } return config + + def _setup_dynamic_config_folder(self): + # ensure the dynamic config dir exists else traefik will error on startup and fail to + # set up the watcher + self._container.make_dir(DYNAMIC_CONFIG_DIR, make_parents=True) diff --git a/tests/integration/test_tls.py b/tests/integration/test_tls.py index a73a37bc..cec2928a 100644 --- a/tests/integration/test_tls.py +++ b/tests/integration/test_tls.py @@ -92,7 +92,7 @@ async def test_build_and_deploy(ops_test: OpsTest, traefik_charm): async def test_ingressed_endpoints_reachable_after_metallb_enabled(ops_test: OpsTest): ip = await get_address(ops_test, trfk.name) for ep in get_endpoints(ops_test, scheme="http", netloc=ip): - logger.debug("Attempting to reach %s", ep) # Traceback doesn't spell out the endpoint + logger.info("Attempting to reach %s", ep) # Traceback doesn't spell out the endpoint urlopen(ep) diff --git a/tox.ini b/tox.ini index d167fce4..e6c68a17 100644 --- a/tox.ini +++ b/tox.ini @@ -67,8 +67,8 @@ deps = tenacity -r{toxinidir}/requirements.txt commands = - pytest -v --tb native --log-cli-level=INFO -s {[vars]tst_path}/integration {posargs} -; pytest -v --tb native --log-cli-level=INFO -s {posargs} +; pytest -v --tb native --log-cli-level=INFO -s {[vars]tst_path}/integration {posargs} + pytest -v --tb native --log-cli-level=INFO -s {posargs} [testenv:static-{charm,lib}] description = Static code checking