@@ -6,6 +6,7 @@ import optparse
6
6
import configparser
7
7
import logging
8
8
import traceback
9
+ from typing import Dict
9
10
10
11
from osg_configure .version import __version__
11
12
from osg_configure .modules import exceptions
@@ -96,45 +97,43 @@ def get_configuration_modules():
96
97
return objects
97
98
98
99
99
- def write_attributes (attributes , local_site_attributes , job_environment_attributes , attribute_to_option_map ):
100
+ def write_osg_local_job_environment_conf (local_site_attributes : Dict ):
101
+ """Write osg-local-job-environment.conf, which is a file of job attributes (i.e.
102
+ environment variables) all coming from the "Local Settings" section.
103
+ """
104
+ try :
105
+ filename = os .path .join (OUTPUT_DIRECTORY , "osg-local-job-environment.conf" )
106
+ utilities .write_attribute_file (filename , local_site_attributes )
107
+ except IOError as exception :
108
+ error_exit ("Error writing attributes to osg-local-job-environment.conf" , exception )
109
+
110
+
111
+ def write_attributes (all_attributes , job_environment_attributes_list , attribute_to_option_map ):
100
112
"""
101
113
Write out attributes to osg config files in output_directory.
102
- :param job_environment_attributes :
114
+ :param job_environment_attributes_list :
103
115
There are two files: osg-job-environment.conf and
104
116
osg-local-job-environment.conf. Only local_site_attributes goes in
105
117
osg-local-job-environment.conf. An error will result if a key in
106
118
'job_environment_attributes' is missing from 'attributes'.
107
119
(Exception: OSG_SQUID_LOCATION)
108
120
109
- :param attributes : OSG attributes from all .ini files, including the
121
+ :param all_attributes : OSG attributes from all .ini files, including the
110
122
local site attributes from the "Local Settings" section
111
- :type attributes: dict
112
- :param local_site_attributes: OSG attributes from just the
113
- "Local Settings" section
114
- :type job_environment_attributes: list
115
- :param job_environment_attributes: The required job attributes to write
116
- :type local_site_attributes: dict
123
+ :type all_attributes: dict
124
+ :param job_environment_attributes_list: The required job attributes to write
117
125
:param attribute_to_option_map: list of (section, name) tuples of the
118
126
config option that is mapped to each attribute; gives better error
119
127
messages if required attributes are missing from 'attributes'
120
128
:type attribute_to_option_map: dict
121
129
"""
122
-
123
- # write out osg-local-job-environment.conf
124
- try :
125
- filename = os .path .join (OUTPUT_DIRECTORY , "osg-local-job-environment.conf" )
126
- utilities .write_attribute_file (filename , local_site_attributes )
127
- except IOError as exception :
128
- error_exit ("Error writing attributes to osg-local-job-environment.conf" , exception )
129
-
130
-
131
130
# write out osg-job-environment.conf
132
131
try :
133
132
filename = os .path .join (OUTPUT_DIRECTORY , "osg-job-environment.conf" )
134
133
temp = {}
135
- for key in job_environment_attributes :
134
+ for key in job_environment_attributes_list :
136
135
try :
137
- temp [key ] = attributes [key ]
136
+ temp [key ] = all_attributes [key ]
138
137
except KeyError as exception :
139
138
if key == 'OSG_SQUID_LOCATION' :
140
139
continue
@@ -188,22 +187,22 @@ def configure_system(modules, configure_module=None, force=False):
188
187
except configparser .ParsingError as exception :
189
188
error_exit ("Error while parsing configuration: %s" % exception )
190
189
191
- attributes = {}
192
- local_attributes = {}
190
+ all_attributes = {}
191
+ local_site_attributes = {}
193
192
attribute_to_option_map = {}
194
193
for module in modules :
195
194
if module .__class__ .__name__ == 'LocalSettings' :
196
- local_attributes .update (module .get_attributes ())
195
+ local_site_attributes .update (module .get_attributes ())
197
196
198
- attributes .update (module .get_attributes ())
197
+ all_attributes .update (module .get_attributes ())
199
198
200
199
section = module .config_section
201
200
for opt in module .options .values ():
202
201
name , attribute = opt .name , opt .mapping
203
202
if attribute :
204
203
attribute_to_option_map [attribute ] = attribute_to_option_map .get (attribute , []) + [(section , name )]
205
204
206
- if not check_configuration (modules , attributes , force ):
205
+ if not check_configuration (modules , all_attributes , force ):
207
206
if force :
208
207
logging .warning ("Invalid attributes found but forcing configuration." )
209
208
sys .stderr .write ("Invalid attributes found but forcing configuration.\n " )
@@ -222,21 +221,20 @@ def configure_system(modules, configure_module=None, force=False):
222
221
logging .debug ("Skipping %s configuration" % (module .__class__ .__name__ ))
223
222
continue
224
223
try :
225
- module .configure (attributes )
224
+ module .configure (all_attributes )
226
225
except exceptions .ConfigureError as e :
227
226
logging .debug ("Got ConfigureError %s" % e )
228
227
error_exit ("Can't configure module, exiting" )
229
228
230
229
if utilities .ce_installed ():
231
- job_environment_attributes = list (DEFAULT_JOB_ENVIRONMENT_ATTRIBUTES )
230
+ job_environment_attributes_list = list (DEFAULT_JOB_ENVIRONMENT_ATTRIBUTES )
232
231
gateway_module = condor_module = None
233
232
for module in modules :
234
233
if module .__class__ .__name__ == 'GatewayConfiguration' :
235
234
gateway_module = module
236
235
elif module .__class__ .__name__ == 'CondorConfiguration' :
237
236
condor_module = module
238
237
239
-
240
238
if not configfile .jobmanager_enabled (config ):
241
239
logging .warning ("CE install detected, but no batch systems are enabled in "
242
240
"any of the *.ini files. osg-configure will not configure "
@@ -246,12 +244,14 @@ def configure_system(modules, configure_module=None, force=False):
246
244
if ((gateway_module and not gateway_module .htcondor_gateway_enabled ) or
247
245
(condor_module and not condor_module .enabled )):
248
246
try :
249
- job_environment_attributes .remove ('PATH' )
247
+ job_environment_attributes_list .remove ('PATH' )
250
248
logging .info ('Not setting PATH (not HTCondor-CE with Condor).' )
251
249
except ValueError :
252
250
pass
253
251
254
- write_attributes (attributes , local_attributes , job_environment_attributes , attribute_to_option_map )
252
+ write_osg_local_job_environment_conf (local_site_attributes )
253
+
254
+ write_attributes (all_attributes , job_environment_attributes_list , attribute_to_option_map )
255
255
256
256
if gateway_module and gateway_module .htcondor_gateway_enabled :
257
257
# Reconfigure htcondor-ce after writing the attributes files
0 commit comments