Skip to content

Commit 998560e

Browse files
committed
Use ce_attributes.py in infoservices config
1 parent 03f7bf9 commit 998560e

File tree

4 files changed

+25
-73
lines changed

4 files changed

+25
-73
lines changed

osg_configure/configure_modules/infoservices.py

Lines changed: 13 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
for CE collector info services"""
33

44
import re
5-
import configparser as ConfigParser
5+
from configparser import ConfigParser
66
import subprocess
77
import logging
88

99
from osg_configure.modules import exceptions
1010
from osg_configure.modules import utilities
1111
from osg_configure.modules import configfile
1212
from osg_configure.modules.baseconfiguration import BaseConfiguration
13-
from osg_configure.modules.ce_attributes import BATCH_SYSTEMS, BATCH_SYSTEMS_CASE_MAP
13+
from osg_configure.modules import ce_attributes
1414
from osg_configure.modules import subcluster
1515
from osg_configure.modules import reversevomap
1616

@@ -52,13 +52,10 @@ def __init__(self, *args, **kwargs):
5252

5353
self.ce_collectors = []
5454
self.ce_collector_required_rpms_installed = utilities.rpm_installed('htcondor-ce')
55-
self.osg_resource = ""
56-
self.osg_resource_group = ""
57-
self.enabled_batch_systems = []
5855
self.htcondor_gateway_enabled = None
59-
self.resource_catalog = None
6056
self.authorization_method = None
61-
self.subcluster_sections = None
57+
self.ce_attributes_config = None
58+
self.ce_attributes_str = ""
6259

6360
self.log("InfoServicesConfiguration.__init__ completed")
6461

@@ -77,7 +74,7 @@ def _parse_ce_collectors(self, val):
7774
else:
7875
return val.split(',')
7976

80-
def parse_configuration(self, configuration):
77+
def parse_configuration(self, configuration: ConfigParser):
8178
"""
8279
Try to get configuration information from ConfigParser or SafeConfigParser object given
8380
by configuration and write recognized settings to attributes dict
@@ -110,38 +107,12 @@ def parse_configuration(self, configuration):
110107

111108
self.ce_collectors = self._parse_ce_collectors(self.options['ce_collectors'].value)
112109

113-
def csg(section, option):
114-
return utilities.config_safe_get(configuration, section, option, None)
115-
116-
def csgbool(section, option):
117-
return utilities.config_safe_getboolean(configuration, section, option, False)
118-
119-
# We get some values for HTCondor-CE from the Site Information section
120-
self.osg_resource = csg('Site Information', 'resource')
121-
self.osg_resource_group = csg('Site Information', 'resource_group')
122-
# and the enabled batch systems from their respective sections
123-
self.enabled_batch_systems = [bs for bs in BATCH_SYSTEMS if csgbool(bs, 'enabled')]
124-
125-
if csgbool("Bosco", "enabled"):
126-
try:
127-
bosco_batch = BATCH_SYSTEMS_CASE_MAP[csg("Bosco", "batch").lower()]
128-
if bosco_batch not in self.enabled_batch_systems:
129-
self.enabled_batch_systems.append(bosco_batch)
130-
except (KeyError, AttributeError):
131-
# This is a warning; the bosco module raises the error.
132-
self.log("Bosco.batch does not have a recognized value -- should be one of %s" %
133-
list(BATCH_SYSTEMS_CASE_MAP.keys()),
134-
level=logging.WARNING)
135-
136-
self.htcondor_gateway_enabled = csgbool('Gateway', 'htcondor_gateway_enabled')
137-
138-
self.subcluster_sections = ConfigParser.SafeConfigParser()
110+
self.htcondor_gateway_enabled = configuration.get('Gateway', 'htcondor_gateway_enabled', fallback=False)
139111

112+
self.ce_attributes_config = ConfigParser()
140113
for section in configuration.sections():
141-
if subcluster.is_subcluster_like(section):
142-
self.subcluster_sections.add_section(section)
143-
for key, value in configuration.items(section):
144-
self.subcluster_sections.set(section, key, value)
114+
if subcluster.is_subcluster_like(section) or section.lower() == "site information":
115+
self.ce_attributes_config[section] = configuration[section]
145116

146117
if utilities.ce_installed() and not subcluster.check_config(configuration):
147118
self.log("On a CE but no valid 'Subcluster', 'Resource Entry', or 'Pilot' sections defined."
@@ -155,7 +126,7 @@ def csgbool(section, option):
155126
# configure(), but at this point we don't have a way of knowing what
156127
# default_allowed_vos should be.
157128
if self.ce_collector_required_rpms_installed and self.htcondor_gateway_enabled and classad is not None:
158-
subcluster.resource_catalog_from_config(self.subcluster_sections, default_allowed_vos=["*"])
129+
subcluster.resource_catalog_from_config(self.ce_attributes_config, default_allowed_vos=["*"])
159130

160131
self.log('InfoServicesConfiguration.parse_configuration completed')
161132

@@ -179,14 +150,12 @@ def configure(self, attributes):
179150
if classad is None:
180151
self.log("Cannot configure HTCondor CE info services: unable to import HTCondor Python bindings."
181152
"\nEnsure the 'classad' Python module is installed and accessible to Python scripts."
182-
"\nIf using HTCondor from RPMs, install the 'condor-python' RPM."
153+
"\nIf using HTCondor from RPMs, install the 'python3-condor' RPM."
183154
"\nIf not, you may need to add the directory containing the Python bindings to PYTHONPATH."
184155
"\nHTCondor version must be at least 8.2.0.", level=logging.WARNING)
185156
else:
186157
try:
187-
self.resource_catalog = subcluster.resource_catalog_from_config(
188-
self.subcluster_sections,
189-
default_allowed_vos=["*"])
158+
self.ce_attributes_str = ce_attributes.get_ce_attributes_str(self.ce_attributes_config)
190159
except exceptions.SettingError as err:
191160
self.log("Error in info services configuration: %s" % err, level=logging.ERROR)
192161
return False
@@ -238,27 +207,10 @@ def _write_ce_collector_attributes_file(self, attributes_file):
238207
CE-Collector to advertise
239208
240209
"""
241-
schedd_attrs_list = ["$(SCHEDD_ATTRS)"]
242-
attributes_file_lines = []
243-
244-
for name, value in [
245-
('OSG_Resource', self.osg_resource),
246-
('OSG_ResourceGroup', self.osg_resource_group),
247-
('OSG_BatchSystems', ",".join(self.enabled_batch_systems))
248-
]:
249-
attributes_file_lines.append("%s = %s" % (name, utilities.classad_quote(value)))
250-
schedd_attrs_list.append(name)
251-
252-
if self.resource_catalog:
253-
attributes_file_lines.append(self.resource_catalog.compose_text())
254-
schedd_attrs_list.append('OSG_ResourceCatalog')
255-
256210
attributes_file_contents = (
257211
"# Do not edit - file generated by osg-configure\n"
258-
+ "\n".join(attributes_file_lines) + "\n"
259-
+ "SCHEDD_ATTRS = " + " ".join(schedd_attrs_list) + "\n"
212+
+ self.ce_attributes_str + "\n"
260213
)
261-
262214
return utilities.atomic_write(attributes_file, attributes_file_contents)
263215

264216
def _write_ce_collector_file(self, info_services_file):

osg_configure/modules/ce_attributes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,11 @@ def get_attributes(config: ConfigParser) -> Dict[str, str]:
9595
attributes["OSG_ResourceCatalog"] = resource_catalog
9696

9797
return attributes
98+
99+
100+
def get_ce_attributes_str(
101+
config: ConfigParser,
102+
) -> str:
103+
attributes = get_attributes(config)
104+
attributes["SCHEDD_ATTRS"] = "$(SCHEDD_ATTRS), " + ", ".join(attributes.keys())
105+
return "\n".join(f"{key} = {value}" for key, value in attributes.items())

osg_configure/modules/subcluster.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def check_config(config: ConfigParser) -> bool:
203203
"""
204204
has_sc = False
205205
for section in config.sections():
206-
if is_pilot(section) or is_subcluster(section) or is_resource_entry(section):
206+
if is_subcluster_like(section):
207207
has_sc = True
208208
check_section(config, section)
209209
return has_sc
@@ -255,7 +255,7 @@ def safegetbool(option: str, default=None) -> bool:
255255

256256
sections_without_max_wall_time = []
257257
for section in config.sections():
258-
if not (is_subcluster(section) or is_resource_entry(section) or is_pilot(section)):
258+
if not is_subcluster_like(section):
259259
continue
260260

261261
check_section(config, section)
@@ -335,6 +335,6 @@ def safegetbool(option: str, default=None) -> bool:
335335
if sections_without_max_wall_time:
336336
logger.warning("No max_wall_time specified for some sections; defaulting to 1440."
337337
"\nAdd 'max_wall_time=1440' to the following section(s) to clear this warning:"
338-
"\n'%s'" % "', '".join(sections_without_max_wall_time))
338+
" '%s'" % "', '".join(sections_without_max_wall_time))
339339

340340
return rc

scripts/osg-ce-attribs-gen

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if __name__ == "__main__" and __package__ is None:
1818
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
1919

2020
# local imports here
21-
from osg_configure.modules.ce_attributes import BATCH_SYSTEMS, get_attributes
21+
from osg_configure.modules.ce_attributes import BATCH_SYSTEMS, get_ce_attributes_str
2222
from osg_configure.modules.exceptions import Error
2323
from osg_configure.version import __version__
2424

@@ -96,14 +96,6 @@ def get_options(args):
9696
return parser.parse_args(args)
9797

9898

99-
def get_ce_attributes_str(
100-
config: ConfigParser,
101-
) -> str:
102-
attributes = get_attributes(config)
103-
attributes["SCHEDD_ATTRS"] = "$(SCHEDD_ATTRS), " + ", ".join(attributes.keys())
104-
return "\n".join(f"{key} = {value}" for key, value in attributes.items())
105-
106-
10799
def main(argv):
108100
options = get_options(argv[1:])
109101

0 commit comments

Comments
 (0)