Skip to content

Commit e537db0

Browse files
committed
Friendlier _verify_gratia_dirs_for_htcondor_ce_probe
1 parent 26c8291 commit e537db0

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

osg_configure/configure_modules/gratia.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -428,57 +428,57 @@ def _configure_htcondor_ce_probe(self):
428428

429429
def _verify_gratia_dirs_for_htcondor_ce_probe(self) -> bool:
430430
"""
431-
Verify that the condor per_job_history directory and the DataFolder
432-
directory are the same and warn if admin if the two don't match
431+
Verify that the HTCondor-CE PER_JOB_HISTORY_DIR and the DataFolder
432+
directory are the same and warn the admin if the two don't match
433433
"""
434434

435435
if not os.path.exists(CONDOR_CE_CONFIG_VAL):
436436
raise exceptions.ConfigureError(f"{CONDOR_CE_CONFIG_VAL} missing")
437437

438+
history_dir = self._get_condor_ce_history_dir()
439+
438440
config_location = GRATIA_CONFIG_FILES['htcondor-ce']
439-
contents = open(config_location, "r", encoding="latin-1").read()
441+
contents = utilities.read_file(config_location, default="")
440442
re_obj = re.compile(r'(?m)^\s*DataFolder\s*=(.*)\s*$')
441443
match = re_obj.search(contents)
442-
if not match:
443-
return True
444+
data_folder = match.group(1).strip('" \t') if match else None
444445

445-
data_folder = match.group(1)
446-
data_folder = data_folder.strip('" \t')
447-
# Per Gratia-126 DataFolder must end in / otherwise gratia won't find certinfo files
448-
if not data_folder.endswith('/'):
449-
self.logger.error("DataFolder setting in %s must end in a /", config_location)
450-
return False
446+
advice_on_error = (
447+
f"Make sure DataFolder in {config_location} ({data_folder or 'missing'})"
448+
f" and PER_JOB_HISTORY_DIR in the HTCondor-CE config ({history_dir or 'missing'})"
449+
f" exist and are the same, accessible directory."
450+
)
451451

452-
history_dir = self._get_condor_ce_history_dir()
453-
if not history_dir:
454-
self.logger.error(textwrap.fill(
455-
"""Could not verify DataFolder correctness: unable to get PER_JOB_HISTORY_DIR
456-
for the schedd. This may be caused by PER_JOB_HISTORY_DIR not being defined."""
457-
))
458-
return False
452+
try:
453+
ok = True
454+
if not history_dir:
455+
self.logger.error("PER_JOB_HISTORY_DIR is not defined")
456+
ok = False
457+
elif not os.path.isdir(history_dir):
458+
self.logger.error("PER_JOB_HISTORY_DIR does not point to a valid directory")
459+
ok = False
460+
461+
if not data_folder:
462+
self.logger.error(f"DataFolder is not defined")
463+
ok = False
464+
elif not os.path.isdir(data_folder):
465+
self.logger.error(f"DataFolder does not point to a valid directory")
466+
ok = False
467+
468+
if not ok: # can't do any more checking
469+
self.logger.error(advice_on_error)
470+
return False
459471

460-
# os.path.samefile will die if the paths don't exist so check that explicitly (SOFTWARE-1735)
461-
if not os.path.exists(data_folder):
462-
self.logger.error("DataFolder setting in %s (%s) points to a nonexistent location",
463-
config_location, data_folder)
464-
return False
465-
elif not os.path.exists(history_dir):
466-
self.logger.error("condor-ce schedd's PER_JOB_HISTORY_DIR (%s) points to a nonexistent location", history_dir)
467-
return False
468-
else:
469-
try:
470-
if os.path.samefile(data_folder, history_dir):
471-
return True
472-
else:
473-
self.logger.error("DataFolder setting in %s (%s) and condor-ce PER_JOB_HISTORY_DIR (%s) "
474-
"do not match, these settings must match!",
475-
config_location, data_folder, history_dir)
476-
return False
477-
except OSError as e:
478-
self.logger.error(
479-
"Error comparing DataFolder setting in %s (%s) and condor-ce PER_JOB_HISTORY_DIR %s:\n%s",
480-
config_location, data_folder, history_dir, e)
472+
if os.path.samefile(data_folder, history_dir):
473+
return True
474+
else:
475+
self.logger.error("DataFolder and PER_JOB_HISTORY_DIR do not point to the same directory")
476+
self.logger.error(advice_on_error)
481477
return False
478+
except OSError as e:
479+
self.logger.error("Unexpected error checking DataFolder and PER_JOB_HISTORY_DIR: %s", e)
480+
self.logger.error(advice_on_error)
481+
return False
482482

483483
def _get_condor_ce_history_dir(self):
484484
cmd = [CONDOR_CE_CONFIG_VAL, '-subsystem', 'SCHEDD', 'PER_JOB_HISTORY_DIR']

0 commit comments

Comments
 (0)