Optimized warnings

This commit is contained in:
Kevin Veen-Birkenbach 2025-07-14 11:19:29 +02:00
parent 81ef808191
commit 9dc55c5893
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E
2 changed files with 12 additions and 15 deletions

View File

@ -33,12 +33,12 @@ class TestDeprecatedVersionKey(unittest.TestCase):
if uses_version: if uses_version:
warnings.append( warnings.append(
f"[DEPRECATION WARNING] {role_path.name}/config/main.yml: " f"[DEPRECATION WARNING] {role_path.name}/config/main.yml: "
f"'version' is deprecated. Replace it by docker.versions[version]." f"'version' is deprecated. Replace it by docker.services[service].version."
) )
if uses_images: if uses_images:
warnings.append( warnings.append(
f"[DEPRECATION WARNING] {role_path.name}/config/main.yml: " f"[DEPRECATION WARNING] {role_path.name}/config/main.yml: "
f"'images' is deprecated. Replace it by docker.images[image]." f"'images' is deprecated. Replace it by docker.services[service].image."
) )
if warnings: if warnings:

View File

@ -3,14 +3,11 @@ import yaml
from pathlib import Path from pathlib import Path
import re import re
class TestDockerRoleImagesConfiguration(unittest.TestCase): class TestDockerRoleServicesConfiguration(unittest.TestCase):
def test_images_keys_and_templates(self): def test_services_keys_and_templates(self):
""" """
For each web-app-* role, check that: For each web-app-* role, check that:
- roles/web-app-*/config/main.yml contains 'images' as a dict with keys/values - roles/web-app-*/config/main.yml contains 'services' as a dict with keys/values
- Each image key is referenced as:
image: "{{ applications[application_id].images.<key> }}"
in either roles/web-app-*/templates/docker-compose.yml.j2 or env.j2
""" """
repo_root = Path(__file__).resolve().parent.parent.parent repo_root = Path(__file__).resolve().parent.parent.parent
roles_dir = repo_root / "roles" roles_dir = repo_root / "roles"
@ -33,13 +30,13 @@ class TestDockerRoleImagesConfiguration(unittest.TestCase):
errors.append(f"{role_path.name}: YAML parse error: {e}") errors.append(f"{role_path.name}: YAML parse error: {e}")
continue continue
images = config.get("docker",{}).get("images") services = config.get("docker",{}).get("services",{})
if not images: if not services:
warnings.append(f"[WARNING] {role_path.name}: No 'docker.images' key in config/main.yml") warnings.append(f"[WARNING] {role_path.name}: No 'docker.services' key in config/main.yml")
continue continue
if not isinstance(images, dict): if not isinstance(services, dict):
errors.append(f"{role_path.name}: 'images' must be a dict in config/main.yml") errors.append(f"{role_path.name}: 'services' must be a dict in config/main.yml")
continue continue
# OPTIONAL: Check if the image is available locally via docker images # OPTIONAL: Check if the image is available locally via docker images
@ -55,9 +52,9 @@ class TestDockerRoleImagesConfiguration(unittest.TestCase):
# except Exception as e: # except Exception as e:
# errors.append(f"{role_path.name}: Error running 'docker images' (optional): {e}") # errors.append(f"{role_path.name}: Error running 'docker images' (optional): {e}")
if warnings: if warnings:
print("\nWarnings in docker role images configuration:\n" + "\n".join(warnings)) print("\nWarnings in docker role services configuration:\n" + "\n".join(warnings))
if errors: if errors:
self.fail("Errors in docker role images configuration:\n" + "\n".join(errors)) self.fail("Errors in docker role services configuration:\n" + "\n".join(errors))
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()