Skip to content

Commit

Permalink
Fix user overriding environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
elwasif committed Sep 22, 2017
1 parent a299438 commit 31fc691
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions framework/src/configurationManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,6 @@ def initialize(self, data_mgr, resource_mgr, task_mgr, ftb):
#pytau.stop(self.timers['initialize'])
#stop(self.timers['initialize'])
raise
# Grab environment variables
for (k, v) in os.environ.iteritems():
if k not in self.platform_conf.keys() \
and not any([x in v for x in '{}()$']):
print k," ", v
self.platform_conf[k] = v

# get mandatory values
for kw in self.platform_keywords:
try:
Expand Down Expand Up @@ -210,6 +203,13 @@ def initialize(self, data_mgr, resource_mgr, task_mgr, ftb):
pass
self.platform_conf['USER'] = user

# Grab environment variables
plat_keys = self.platform_conf.keys()
for (k, v) in os.environ.iteritems():
if k not in plat_keys \
and not any([x in v for x in '{}()$']):
self.platform_conf[k] = v

try:
mpirun_version = self.platform_conf['MPIRUN_VERSION']
except KeyError:
Expand Down Expand Up @@ -320,16 +320,18 @@ def initialize(self, data_mgr, resource_mgr, task_mgr, ftb):
conf.merge(csconf)
# Import environment variables into config file
# giving precedence to config file definitions in case of duplicates
conf_keys = conf.keys()
for (k,v) in os.environ.iteritems():
if not any([x in v for x in '{}()$']):
if k not in conf_keys and not any([x in v for x in '{}()$']):
conf[k] = v

# Allow simulation file to override platform values
# and then put all platform values into simulation map
for key in self.platform_conf.keys():
if key in conf.keys() and key not in os.environ.keys():
if key in conf_keys and key not in os.environ.keys():
self.platform_conf[key] = conf[key]
conf.merge(self.platform_conf)
if key not in conf_keys:
conf[key] = self.platform_conf[key]

except IOError, (ex):
self.fwk.exception('Error opening config file %s: ', conf_file)
Expand Down Expand Up @@ -850,9 +852,10 @@ def create_simulation(self, sim_name, config_file, override, sub_workflow=False)
parent_sim = self.sim_map[parent_sim_name]
# Incorporate environment variables into config file
# Use config file entries when duplicates are detected
conf_keys = conf.keys()
for (k,v) in os.environ.iteritems():
# Do not include functions from environment
if k not in conf.keys() and \
if k not in conf_keys and \
not any([x in v for x in '{}()$']):
conf[k] = v

Expand Down

0 comments on commit 31fc691

Please sign in to comment.