mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-30 07:18:09 +02:00
Optimized images and version configuration for dockerfiles
This commit is contained in:
49
tests/integration/test_deprecated_version_key.py
Normal file
49
tests/integration/test_deprecated_version_key.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
import yaml
|
||||
|
||||
class TestDeprecatedVersionKey(unittest.TestCase):
|
||||
def test_version_key_deprecation(self):
|
||||
"""
|
||||
Checks all roles/docker-*/vars/configuration.yml for deprecated use of 'version'.
|
||||
Warns if 'version' is set but 'images' is missing.
|
||||
Prints warnings but does NOT fail the test.
|
||||
"""
|
||||
repo_root = Path(__file__).resolve().parent.parent.parent
|
||||
roles_dir = repo_root / "roles"
|
||||
warnings = []
|
||||
|
||||
for role_path in roles_dir.iterdir():
|
||||
if not (role_path.is_dir() and role_path.name.startswith("docker-")):
|
||||
continue
|
||||
|
||||
cfg_file = role_path / "vars" / "configuration.yml"
|
||||
if not cfg_file.exists():
|
||||
continue
|
||||
|
||||
try:
|
||||
config = yaml.safe_load(cfg_file.read_text("utf-8")) or {}
|
||||
except yaml.YAMLError as e:
|
||||
print(f"YAML parse error in {cfg_file}: {e}")
|
||||
continue
|
||||
|
||||
uses_version = 'version' in config
|
||||
uses_images = 'images' in config
|
||||
|
||||
if uses_version and not uses_images:
|
||||
warnings.append(
|
||||
f"[DEPRECATION WARNING] {role_path.name}/vars/configuration.yml: "
|
||||
f"'version:' is set, but 'images:' is missing. "
|
||||
f"'version' is deprecated and must only be set if 'images' is present."
|
||||
)
|
||||
|
||||
if warnings:
|
||||
print("\n".join(warnings))
|
||||
else:
|
||||
print("No deprecated 'version:' keys found in docker roles without 'images:'.")
|
||||
|
||||
# Never fail, just warn
|
||||
self.assertTrue(True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Reference in New Issue
Block a user