fix(core): handle permission error when checking system host config and patch in tests
This commit is contained in:
1 parent
3c1589bd0c
commit
0bbc4ce440
2 files changed
+22
-12
No files matched your search
+21
-12
@@ -67,9 +67,12 @@ def lock_exclusive(fp):
|
||||
|
||||
|
||||
def resolve_repo_host_dir(host_name=None):
|
||||
host = host_name or socket.gethostname().split('.')[0]
|
||||
candidate = Path(__file__).resolve().parent / 'hosts' / host
|
||||
return candidate if candidate.is_dir() else None
|
||||
try:
|
||||
host = host_name or socket.gethostname().split('.')[0]
|
||||
candidate = Path(__file__).resolve().parent / 'hosts' / host
|
||||
return candidate if candidate.is_dir() else None
|
||||
except (OSError, PermissionError):
|
||||
return 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:
|
||||
candidates.append(host_dir / 'host.json')
|
||||
for candidate in candidates:
|
||||
if candidate.is_file():
|
||||
with candidate.open(encoding='utf-8') as fp:
|
||||
data = json.load(fp)
|
||||
if isinstance(data, dict):
|
||||
default.update(data)
|
||||
break
|
||||
try:
|
||||
if candidate.is_file():
|
||||
with candidate.open(encoding='utf-8') as fp:
|
||||
data = json.load(fp)
|
||||
if isinstance(data, dict):
|
||||
default.update(data)
|
||||
break
|
||||
except (OSError, PermissionError):
|
||||
continue
|
||||
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(Path(__file__).resolve().parent / 'targets.json')
|
||||
for candidate in candidates:
|
||||
if candidate.is_file():
|
||||
with candidate.open(encoding='utf-8') as fp:
|
||||
return json.load(fp)
|
||||
try:
|
||||
if candidate.is_file():
|
||||
with candidate.open(encoding='utf-8') as fp:
|
||||
return json.load(fp)
|
||||
except (OSError, PermissionError):
|
||||
continue
|
||||
return {'schemaVersion': 1, 'hosts': {}, 'targets': {}}
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ class OrchestratorTests(unittest.TestCase):
|
||||
self.root = Path(self.temp.name)
|
||||
self.patches = [patch.object(app, 'legacy_schedules', return_value=[]),
|
||||
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'})]
|
||||
for p in self.patches:
|
||||
p.start()
|
||||
|
||||
Reference in new issue
Block a user