Implemented schema/main.yml und config/main.yml file

This commit is contained in:
2025-07-09 02:03:32 +02:00
parent 7362accab0
commit 22b4342300
114 changed files with 48 additions and 45 deletions

View File

@@ -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')

View File

@@ -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 = {

View File

@@ -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"

View File

@@ -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":

View File

@@ -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': {