Skip to content

Commit a48eec8

Browse files
committed
Merge branch 'pr/common/refactor-attribute-writing' into v4
* pr/common/refactor-attribute-writing: Refactor attribute writing
2 parents c40dbd2 + 05f7f01 commit a48eec8

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

scripts/osg-configure

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import optparse
66
import configparser
77
import logging
88
import traceback
9+
from typing import Dict
910

1011
from osg_configure.version import __version__
1112
from osg_configure.modules import exceptions
@@ -96,45 +97,43 @@ def get_configuration_modules():
9697
return objects
9798

9899

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):
100112
"""
101113
Write out attributes to osg config files in output_directory.
102-
:param job_environment_attributes:
114+
:param job_environment_attributes_list:
103115
There are two files: osg-job-environment.conf and
104116
osg-local-job-environment.conf. Only local_site_attributes goes in
105117
osg-local-job-environment.conf. An error will result if a key in
106118
'job_environment_attributes' is missing from 'attributes'.
107119
(Exception: OSG_SQUID_LOCATION)
108120
109-
:param attributes: OSG attributes from all .ini files, including the
121+
:param all_attributes: OSG attributes from all .ini files, including the
110122
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
117125
:param attribute_to_option_map: list of (section, name) tuples of the
118126
config option that is mapped to each attribute; gives better error
119127
messages if required attributes are missing from 'attributes'
120128
:type attribute_to_option_map: dict
121129
"""
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-
131130
# write out osg-job-environment.conf
132131
try:
133132
filename = os.path.join(OUTPUT_DIRECTORY, "osg-job-environment.conf")
134133
temp = {}
135-
for key in job_environment_attributes:
134+
for key in job_environment_attributes_list:
136135
try:
137-
temp[key] = attributes[key]
136+
temp[key] = all_attributes[key]
138137
except KeyError as exception:
139138
if key == 'OSG_SQUID_LOCATION':
140139
continue
@@ -188,22 +187,22 @@ def configure_system(modules, configure_module=None, force=False):
188187
except configparser.ParsingError as exception:
189188
error_exit("Error while parsing configuration: %s" % exception)
190189

191-
attributes = {}
192-
local_attributes = {}
190+
all_attributes = {}
191+
local_site_attributes = {}
193192
attribute_to_option_map = {}
194193
for module in modules:
195194
if module.__class__.__name__ == 'LocalSettings':
196-
local_attributes.update(module.get_attributes())
195+
local_site_attributes.update(module.get_attributes())
197196

198-
attributes.update(module.get_attributes())
197+
all_attributes.update(module.get_attributes())
199198

200199
section = module.config_section
201200
for opt in module.options.values():
202201
name, attribute = opt.name, opt.mapping
203202
if attribute:
204203
attribute_to_option_map[attribute] = attribute_to_option_map.get(attribute, []) + [(section, name)]
205204

206-
if not check_configuration(modules, attributes, force):
205+
if not check_configuration(modules, all_attributes, force):
207206
if force:
208207
logging.warning("Invalid attributes found but forcing configuration.")
209208
sys.stderr.write("Invalid attributes found but forcing configuration.\n")
@@ -222,21 +221,20 @@ def configure_system(modules, configure_module=None, force=False):
222221
logging.debug("Skipping %s configuration" % (module.__class__.__name__))
223222
continue
224223
try:
225-
module.configure(attributes)
224+
module.configure(all_attributes)
226225
except exceptions.ConfigureError as e:
227226
logging.debug("Got ConfigureError %s" % e)
228227
error_exit("Can't configure module, exiting")
229228

230229
if utilities.ce_installed():
231-
job_environment_attributes = list(DEFAULT_JOB_ENVIRONMENT_ATTRIBUTES)
230+
job_environment_attributes_list = list(DEFAULT_JOB_ENVIRONMENT_ATTRIBUTES)
232231
gateway_module = condor_module = None
233232
for module in modules:
234233
if module.__class__.__name__ == 'GatewayConfiguration':
235234
gateway_module = module
236235
elif module.__class__.__name__ == 'CondorConfiguration':
237236
condor_module = module
238237

239-
240238
if not configfile.jobmanager_enabled(config):
241239
logging.warning("CE install detected, but no batch systems are enabled in "
242240
"any of the *.ini files. osg-configure will not configure "
@@ -246,12 +244,14 @@ def configure_system(modules, configure_module=None, force=False):
246244
if ((gateway_module and not gateway_module.htcondor_gateway_enabled) or
247245
(condor_module and not condor_module.enabled)):
248246
try:
249-
job_environment_attributes.remove('PATH')
247+
job_environment_attributes_list.remove('PATH')
250248
logging.info('Not setting PATH (not HTCondor-CE with Condor).')
251249
except ValueError:
252250
pass
253251

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)
255255

256256
if gateway_module and gateway_module.htcondor_gateway_enabled:
257257
# Reconfigure htcondor-ce after writing the attributes files

0 commit comments

Comments
 (0)