22 for CE collector info services"""
33
44import re
5- import configparser as ConfigParser
5+ from configparser import ConfigParser
66import subprocess
77import logging
88
99from osg_configure .modules import exceptions
1010from osg_configure .modules import utilities
1111from osg_configure .modules import configfile
1212from osg_configure .modules .baseconfiguration import BaseConfiguration
13+ from osg_configure .modules import ce_attributes
1314from osg_configure .modules import subcluster
1415from osg_configure .modules import reversevomap
1516
2223BAN_VOMS_MAPFILE = reversevomap .BAN_MAPFILE
2324BAN_MAPFILE = '/etc/grid-security/ban-mapfile'
2425
25- # BATCH_SYSTEMS here is both the config sections for the batch systems
26- # and the values in the OSG_BatchSystems attribute since they are
27- # coincidentally the same. If they ever change, make a mapping.
28- BATCH_SYSTEMS = ['Condor' , 'LSF' , 'PBS' , 'SGE' , 'SLURM' ]
2926
3027try :
3128 import classad
@@ -55,13 +52,10 @@ def __init__(self, *args, **kwargs):
5552
5653 self .ce_collectors = []
5754 self .ce_collector_required_rpms_installed = utilities .rpm_installed ('htcondor-ce' )
58- self .osg_resource = ""
59- self .osg_resource_group = ""
60- self .enabled_batch_systems = []
6155 self .htcondor_gateway_enabled = None
62- self .resource_catalog = None
6356 self .authorization_method = None
64- self .subcluster_sections = None
57+ self .configuration = None
58+ self .ce_attributes_str = ""
6559
6660 self .log ("InfoServicesConfiguration.__init__ completed" )
6761
@@ -80,7 +74,7 @@ def _parse_ce_collectors(self, val):
8074 else :
8175 return val .split (',' )
8276
83- def parse_configuration (self , configuration ):
77+ def parse_configuration (self , configuration : ConfigParser ):
8478 """
8579 Try to get configuration information from ConfigParser or SafeConfigParser object given
8680 by configuration and write recognized settings to attributes dict
@@ -113,27 +107,9 @@ def parse_configuration(self, configuration):
113107
114108 self .ce_collectors = self ._parse_ce_collectors (self .options ['ce_collectors' ].value )
115109
116- def csg (section , option ):
117- return utilities .config_safe_get (configuration , section , option , None )
110+ self .htcondor_gateway_enabled = configuration .get ('Gateway' , 'htcondor_gateway_enabled' , fallback = False )
118111
119- def csgbool (section , option ):
120- return utilities .config_safe_getboolean (configuration , section , option , False )
121-
122- # We get some values for HTCondor-CE from the Site Information section
123- self .osg_resource = csg ('Site Information' , 'resource' )
124- self .osg_resource_group = csg ('Site Information' , 'resource_group' )
125- # and the enabled batch systems from their respective sections
126- self .enabled_batch_systems = [bs for bs in BATCH_SYSTEMS if csgbool (bs , 'enabled' )]
127-
128- self .htcondor_gateway_enabled = csgbool ('Gateway' , 'htcondor_gateway_enabled' )
129-
130- self .subcluster_sections = ConfigParser .SafeConfigParser ()
131-
132- for section in configuration .sections ():
133- if subcluster .is_subcluster_like (section ):
134- self .subcluster_sections .add_section (section )
135- for key , value in configuration .items (section ):
136- self .subcluster_sections .set (section , key , value )
112+ self .configuration = configuration # save for later: the ce_attributes module reads the whole config.
137113
138114 if utilities .ce_installed () and not subcluster .check_config (configuration ):
139115 self .log ("On a CE but no valid 'Subcluster', 'Resource Entry', or 'Pilot' sections defined."
@@ -147,7 +123,7 @@ def csgbool(section, option):
147123 # configure(), but at this point we don't have a way of knowing what
148124 # default_allowed_vos should be.
149125 if self .ce_collector_required_rpms_installed and self .htcondor_gateway_enabled and classad is not None :
150- subcluster .resource_catalog_from_config (self . subcluster_sections , default_allowed_vos = ["*" ])
126+ subcluster .resource_catalog_from_config (configuration , default_allowed_vos = ["*" ])
151127
152128 self .log ('InfoServicesConfiguration.parse_configuration completed' )
153129
@@ -171,14 +147,12 @@ def configure(self, attributes):
171147 if classad is None :
172148 self .log ("Cannot configure HTCondor CE info services: unable to import HTCondor Python bindings."
173149 "\n Ensure the 'classad' Python module is installed and accessible to Python scripts."
174- "\n If using HTCondor from RPMs, install the 'condor-python ' RPM."
150+ "\n If using HTCondor from RPMs, install the 'python3-condor ' RPM."
175151 "\n If not, you may need to add the directory containing the Python bindings to PYTHONPATH."
176152 "\n HTCondor version must be at least 8.2.0." , level = logging .WARNING )
177153 else :
178154 try :
179- self .resource_catalog = subcluster .resource_catalog_from_config (
180- self .subcluster_sections ,
181- default_allowed_vos = ["*" ])
155+ self .ce_attributes_str = ce_attributes .get_ce_attributes_str (self .configuration )
182156 except exceptions .SettingError as err :
183157 self .log ("Error in info services configuration: %s" % err , level = logging .ERROR )
184158 return False
@@ -230,27 +204,10 @@ def _write_ce_collector_attributes_file(self, attributes_file):
230204 CE-Collector to advertise
231205
232206 """
233- schedd_attrs_list = ["$(SCHEDD_ATTRS)" ]
234- attributes_file_lines = []
235-
236- for name , value in [
237- ('OSG_Resource' , self .osg_resource ),
238- ('OSG_ResourceGroup' , self .osg_resource_group ),
239- ('OSG_BatchSystems' , "," .join (self .enabled_batch_systems ))
240- ]:
241- attributes_file_lines .append ("%s = %s" % (name , utilities .classad_quote (value )))
242- schedd_attrs_list .append (name )
243-
244- if self .resource_catalog :
245- attributes_file_lines .append (self .resource_catalog .compose_text ())
246- schedd_attrs_list .append ('OSG_ResourceCatalog' )
247-
248207 attributes_file_contents = (
249208 "# Do not edit - file generated by osg-configure\n "
250- + "\n " .join (attributes_file_lines ) + "\n "
251- + "SCHEDD_ATTRS = " + " " .join (schedd_attrs_list ) + "\n "
209+ + self .ce_attributes_str + "\n "
252210 )
253-
254211 return utilities .atomic_write (attributes_file , attributes_file_contents )
255212
256213 def _write_ce_collector_file (self , info_services_file ):
0 commit comments