fix(core): handle permission error when checking system host config and patch in tests

This commit is contained in:
Lars committed 2026-10-29 15:31:39 +01:00
1 parent 3c1589bd0c
commit 0bbc4ce440
2 files changed
+10

No files matched your search

+9
View File
@@ -67,9 +67,12 @@ def lock_exclusive(fp):
def resolve_repo_host_dir(host_name=None): def resolve_repo_host_dir(host_name=None):
try:
host = host_name or socket.gethostname().split('.')[0] host = host_name or socket.gethostname().split('.')[0]
candidate = Path(__file__).resolve().parent / 'hosts' / host candidate = Path(__file__).resolve().parent / 'hosts' / host
return candidate if candidate.is_dir() else None return candidate if candidate.is_dir() else None
except (OSError, PermissionError):
return None
def load_host_config(path=DEFAULT_HOST_CONFIG, host_name=None): def load_host_config(path=DEFAULT_HOST_CONFIG, host_name=None):
@@ -95,12 +98,15 @@ def load_host_config(path=DEFAULT_HOST_CONFIG, host_name=None):
if host_dir: if host_dir:
candidates.append(host_dir / 'host.json') candidates.append(host_dir / 'host.json')
for candidate in candidates: for candidate in candidates:
try:
if candidate.is_file(): if candidate.is_file():
with candidate.open(encoding='utf-8') as fp: with candidate.open(encoding='utf-8') as fp:
data = json.load(fp) data = json.load(fp)
if isinstance(data, dict): if isinstance(data, dict):
default.update(data) default.update(data)
break break
except (OSError, PermissionError):
continue
return default return default
@@ -117,9 +123,12 @@ def load_targets_config(path=DEFAULT_TARGETS_CONFIG, host_name=None):
candidates.append(host_dir / 'targets.json') candidates.append(host_dir / 'targets.json')
candidates.append(Path(__file__).resolve().parent / 'targets.json') candidates.append(Path(__file__).resolve().parent / 'targets.json')
for candidate in candidates: for candidate in candidates:
try:
if candidate.is_file(): if candidate.is_file():
with candidate.open(encoding='utf-8') as fp: with candidate.open(encoding='utf-8') as fp:
return json.load(fp) return json.load(fp)
except (OSError, PermissionError):
continue
return {'schemaVersion': 1, 'hosts': {}, 'targets': {}} return {'schemaVersion': 1, 'hosts': {}, 'targets': {}}
+1
View File
@@ -20,6 +20,7 @@ class OrchestratorTests(unittest.TestCase):
self.root = Path(self.temp.name) self.root = Path(self.temp.name)
self.patches = [patch.object(app, 'legacy_schedules', return_value=[]), self.patches = [patch.object(app, 'legacy_schedules', return_value=[]),
patch.object(app, 'nas_mount_ready', return_value=True), patch.object(app, 'nas_mount_ready', return_value=True),
patch.object(app, 'load_host_config', return_value={'hostname':'test-host', 'nas_mount':'/backup', 'nas_source':'192.168.2.63:/volume1/Backup_Paperless'}),
patch.dict(os.environ, {'BACKUP_ORCHESTRATOR_CUTOVER_APPROVED':'YES'})] patch.dict(os.environ, {'BACKUP_ORCHESTRATOR_CUTOVER_APPROVED':'YES'})]
for p in self.patches: for p in self.patches:
p.start() p.start()