mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 23:08:06 +02:00
Implemented schema/main.yml und config/main.yml file
This commit is contained in:
@@ -5,11 +5,11 @@ import yaml
|
||||
class TestConfigurationDatabaseDependency(unittest.TestCase):
|
||||
# Define project root and glob pattern for configuration files
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
||||
CONFIG_PATTERN = 'roles/*/vars/configuration.yml'
|
||||
CONFIG_PATTERN = 'roles/*/config/main.yml'
|
||||
|
||||
def test_central_database_implies_database_service_enabled(self):
|
||||
"""
|
||||
For each roles/*/vars/configuration.yml:
|
||||
For each roles/*/config/main.yml:
|
||||
If features.central_database is true,
|
||||
then docker.services.database.enabled must be true.
|
||||
"""
|
||||
|
@@ -33,14 +33,14 @@ def find_none_values(data, prefix=None):
|
||||
|
||||
class TestConfigurationNoNone(unittest.TestCase):
|
||||
def test_configuration_files_have_no_none_values(self):
|
||||
# Find all configuration.yml files under roles/*/vars
|
||||
# Find all config/main.yml files under roles/*/vars
|
||||
pattern = os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
os.pardir, os.pardir,
|
||||
'roles', '*', 'vars', 'configuration.yml'
|
||||
'roles', '*', "config" , "main.yml"
|
||||
)
|
||||
files = glob.glob(pattern)
|
||||
self.assertTrue(files, f"No configuration.yml files found with pattern: {pattern}")
|
||||
self.assertTrue(files, f"No config/main.yml files found with pattern: {pattern}")
|
||||
|
||||
all_errors = []
|
||||
for filepath in files:
|
||||
|
@@ -37,7 +37,7 @@ class TestCspConfigurationConsistency(unittest.TestCase):
|
||||
|
||||
def test_csp_configuration_structure(self):
|
||||
"""
|
||||
Iterate all roles; for each vars/configuration.yml that defines 'csp',
|
||||
Iterate all roles; for each config/main.yml that defines 'csp',
|
||||
assert that:
|
||||
- csp is a dict
|
||||
- its whitelist/flags/hashes keys only use supported directives
|
||||
@@ -52,7 +52,7 @@ class TestCspConfigurationConsistency(unittest.TestCase):
|
||||
if not role_path.is_dir():
|
||||
continue
|
||||
|
||||
cfg_file = role_path / "vars" / "configuration.yml"
|
||||
cfg_file = role_path / "config" / "main.yml"
|
||||
if not cfg_file.exists():
|
||||
continue
|
||||
|
||||
|
@@ -5,7 +5,7 @@ import yaml
|
||||
class TestDeprecatedVersionKey(unittest.TestCase):
|
||||
def test_version_key_deprecation(self):
|
||||
"""
|
||||
Checks all roles/web-app-*/vars/configuration.yml for deprecated use of 'version'.
|
||||
Checks all roles/web-app-*/config/main.yml for deprecated use of 'version'.
|
||||
Warns if 'version' is set but 'images' is missing.
|
||||
Prints warnings but does NOT fail the test.
|
||||
"""
|
||||
@@ -17,7 +17,7 @@ class TestDeprecatedVersionKey(unittest.TestCase):
|
||||
if not (role_path.is_dir() and role_path.name.startswith("web-app-")):
|
||||
continue
|
||||
|
||||
cfg_file = role_path / "vars" / "configuration.yml"
|
||||
cfg_file = role_path / "config" / "main.yml"
|
||||
if not cfg_file.exists():
|
||||
continue
|
||||
|
||||
@@ -32,12 +32,12 @@ class TestDeprecatedVersionKey(unittest.TestCase):
|
||||
|
||||
if uses_version:
|
||||
warnings.append(
|
||||
f"[DEPRECATION WARNING] {role_path.name}/vars/configuration.yml: "
|
||||
f"[DEPRECATION WARNING] {role_path.name}/config/main.yml: "
|
||||
f"'version' is deprecated. Replace it by docker.versions[version]."
|
||||
)
|
||||
if uses_images:
|
||||
warnings.append(
|
||||
f"[DEPRECATION WARNING] {role_path.name}/vars/configuration.yml: "
|
||||
f"[DEPRECATION WARNING] {role_path.name}/config/main.yml: "
|
||||
f"'images' is deprecated. Replace it by docker.images[image]."
|
||||
)
|
||||
|
||||
|
@@ -7,7 +7,7 @@ class TestDockerRoleImagesConfiguration(unittest.TestCase):
|
||||
def test_images_keys_and_templates(self):
|
||||
"""
|
||||
For each web-app-* role, check that:
|
||||
- roles/web-app-*/vars/configuration.yml contains 'images' as a dict with keys/values
|
||||
- roles/web-app-*/config/main.yml contains 'images' 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
|
||||
@@ -21,7 +21,7 @@ class TestDockerRoleImagesConfiguration(unittest.TestCase):
|
||||
if not (role_path.is_dir() and role_path.name.startswith("web-app-")):
|
||||
continue
|
||||
|
||||
cfg_file = role_path / "vars" / "configuration.yml"
|
||||
cfg_file = role_path / "config" / "main.yml"
|
||||
if not cfg_file.exists():
|
||||
continue # No configuration to check
|
||||
|
||||
@@ -35,11 +35,11 @@ class TestDockerRoleImagesConfiguration(unittest.TestCase):
|
||||
|
||||
images = config.get("docker",{}).get("images")
|
||||
if not images:
|
||||
warnings.append(f"[WARNING] {role_path.name}: No 'docker.images' key in configuration.yml")
|
||||
warnings.append(f"[WARNING] {role_path.name}: No 'docker.images' key in config/main.yml")
|
||||
continue
|
||||
|
||||
if not isinstance(images, dict):
|
||||
errors.append(f"{role_path.name}: 'images' must be a dict in configuration.yml")
|
||||
errors.append(f"{role_path.name}: 'images' must be a dict in config/main.yml")
|
||||
continue
|
||||
|
||||
# OPTIONAL: Check if the image is available locally via docker images
|
||||
|
@@ -10,7 +10,7 @@ class TestOauth2AclMutualExclusion(unittest.TestCase):
|
||||
failures = []
|
||||
|
||||
for role_path in ROLES_DIR.iterdir():
|
||||
vars_file = role_path / "vars" / "configuration.yml"
|
||||
vars_file = role_path / "config" / "main.yml"
|
||||
if not vars_file.exists():
|
||||
continue
|
||||
|
||||
|
@@ -24,10 +24,10 @@ class TestOAuth2ProxyPorts(unittest.TestCase):
|
||||
if not role_path.is_dir():
|
||||
continue
|
||||
with self.subTest(role=role_path.name):
|
||||
# Check for configuration.yml
|
||||
config_file = role_path / 'vars' / 'configuration.yml'
|
||||
# Check for config/main.yml
|
||||
config_file = role_path / "config" / "main.yml"
|
||||
if not config_file.exists():
|
||||
self.skipTest(f"No configuration.yml for role {role_path.name}")
|
||||
self.skipTest(f"No config/main.yml for role {role_path.name}")
|
||||
|
||||
config = yaml.safe_load(config_file.read_text()) or {}
|
||||
if not config.get('features', {}).get('oauth2', False):
|
||||
|
@@ -50,19 +50,20 @@ class TestCreateCredentials(unittest.TestCase):
|
||||
# Setup temporary files for role-path vars and inventory
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
role_path = os.path.join(tmpdir, 'role')
|
||||
os.makedirs(os.path.join(role_path, 'config'))
|
||||
os.makedirs(os.path.join(role_path, 'schema'))
|
||||
os.makedirs(os.path.join(role_path, 'vars'))
|
||||
os.makedirs(os.path.join(role_path, 'meta'))
|
||||
# Create vars/main.yml with application_id
|
||||
main_vars = {'application_id': 'app_test'}
|
||||
with open(os.path.join(role_path, 'vars', 'main.yml'), 'w') as f:
|
||||
yaml.dump(main_vars, f)
|
||||
# Create vars/configuration.yml with features disabled
|
||||
# Create config/main.yml with features disabled
|
||||
config = {'features': {'central_database': False}}
|
||||
with open(os.path.join(role_path, 'vars', 'configuration.yml'), 'w') as f:
|
||||
with open(os.path.join(role_path, "config" , "main.yml"), 'w') as f:
|
||||
yaml.dump(config, f)
|
||||
# Create schema.yml defining plain credential
|
||||
schema = {'credentials': {'api_key': {'description': 'API key', 'algorithm': 'plain', 'validation': {}}}}
|
||||
with open(os.path.join(role_path, 'meta', 'schema.yml'), 'w') as f:
|
||||
with open(os.path.join(role_path, 'schema', 'main.yml'), 'w') as f:
|
||||
yaml.dump(schema, f)
|
||||
# Prepare inventory file
|
||||
inventory_file = os.path.join(tmpdir, 'inventory.yml')
|
||||
|
@@ -16,11 +16,12 @@ class TestGenerateDefaultApplicationsUsers(unittest.TestCase):
|
||||
# Sample role with users meta
|
||||
self.role = self.roles_dir / "web-app-app-with-users"
|
||||
(self.role / "vars").mkdir(parents=True)
|
||||
(self.role / "config").mkdir(parents=True)
|
||||
(self.role / "meta").mkdir(parents=True)
|
||||
|
||||
# Write application_id and configuration
|
||||
(self.role / "vars" / "main.yml").write_text("application_id: app_with_users\n")
|
||||
(self.role / "vars" / "configuration.yml").write_text("setting: value\n")
|
||||
(self.role / "config" / "main.yml").write_text("setting: value\n")
|
||||
|
||||
# Write users meta
|
||||
users_meta = {
|
||||
|
@@ -17,10 +17,11 @@ class TestGenerateDefaultApplications(unittest.TestCase):
|
||||
# Sample role
|
||||
self.sample_role = self.roles_dir / "web-app-testapp"
|
||||
(self.sample_role / "vars").mkdir(parents=True)
|
||||
(self.sample_role / "config").mkdir(parents=True)
|
||||
|
||||
# Write application_id and configuration
|
||||
(self.sample_role / "vars" / "main.yml").write_text("application_id: testapp\n")
|
||||
(self.sample_role / "vars" / "configuration.yml").write_text("foo: bar\nbaz: 123\n")
|
||||
(self.sample_role / "config" / "main.yml").write_text("foo: bar\nbaz: 123\n")
|
||||
|
||||
# Output file path
|
||||
self.output_file = self.temp_dir / "group_vars" / "all" / "04_applications.yml"
|
||||
|
@@ -48,8 +48,8 @@ class TestInventoryManager(unittest.TestCase):
|
||||
|
||||
def fake_load_yaml(self, path):
|
||||
path = Path(path)
|
||||
# Return schema for meta/schema.yml
|
||||
if path.match("*/meta/schema.yml"):
|
||||
# Return schema for schema/main.yml
|
||||
if path.match("*/schema/main.yml"):
|
||||
return {
|
||||
"credentials": {
|
||||
"plain_cred": {"description": "desc", "algorithm": "plain", "validation": {}},
|
||||
@@ -59,8 +59,8 @@ class TestInventoryManager(unittest.TestCase):
|
||||
# Return application_id for vars/main.yml
|
||||
if path.match("*/vars/main.yml"):
|
||||
return {"application_id": "testapp"}
|
||||
# Return feature flags for vars/configuration.yml
|
||||
if path.match("*/vars/configuration.yml"):
|
||||
# Return feature flags for config/main.yml
|
||||
if path.match("*/config/main.yml"):
|
||||
return {"features": {"central_database": True}}
|
||||
# Return empty inventory for inventory.yml
|
||||
if path.name == "inventory.yml":
|
||||
|
@@ -59,10 +59,10 @@ class TestLoadConfigurationFilter(unittest.TestCase):
|
||||
@patch('load_configuration.open', new_callable=mock_open)
|
||||
@patch('load_configuration.yaml.safe_load')
|
||||
def test_primary_and_cache(self, mock_yaml, mock_file, mock_exists, *_):
|
||||
mock_exists.side_effect = lambda p: p.endswith('vars/main.yml') or p.endswith('vars/configuration.yml')
|
||||
mock_exists.side_effect = lambda p: p.endswith('vars/main.yml') or p.endswith('config/main.yml')
|
||||
mock_yaml.side_effect = [
|
||||
{'application_id': self.app}, # main.yml
|
||||
self.nested_cfg # configuration.yml
|
||||
self.nested_cfg # config/main.yml
|
||||
]
|
||||
# first load
|
||||
self.assertTrue(self.f(self.app, 'features.matomo'))
|
||||
@@ -88,7 +88,7 @@ class TestLoadConfigurationFilter(unittest.TestCase):
|
||||
@patch('load_configuration.open', new_callable=mock_open)
|
||||
@patch('load_configuration.yaml.safe_load')
|
||||
def test_fallback_nested(self, mock_yaml, mock_file, mock_exists, *_):
|
||||
mock_exists.side_effect = lambda p: p.endswith('vars/configuration.yml')
|
||||
mock_exists.side_effect = lambda p: p.endswith('config/main.yml')
|
||||
mock_yaml.return_value = self.nested_cfg
|
||||
# nested fallback must work
|
||||
self.assertTrue(self.f(self.app, 'features.matomo'))
|
||||
@@ -102,7 +102,7 @@ class TestLoadConfigurationFilter(unittest.TestCase):
|
||||
@patch('load_configuration.yaml.safe_load')
|
||||
def test_fallback_with_indexed_key(self, mock_yaml, mock_file, mock_exists, *_):
|
||||
# Testing with an indexed key like domains.canonical[0]
|
||||
mock_exists.side_effect = lambda p: p.endswith('vars/configuration.yml')
|
||||
mock_exists.side_effect = lambda p: p.endswith('config/main.yml')
|
||||
mock_yaml.return_value = {
|
||||
'file-server': {
|
||||
'domains': {
|
||||
|
Reference in New Issue
Block a user