Commit 4774341f authored by Luis Araujo's avatar Luis Araujo

Implement profile inheritance

- The 'main-profile' section can now be used as the parent profile that
will be inherited by listed profiles in the 'profiles' section of the
.yaml configuration file. This allows to overwrite values in profiles
from the main profile section.
- Now the '-p' option takes a list of profiles
- Clean some info/error messages
- Version bump to 20150120.0
parent c4f596db
......@@ -84,8 +84,8 @@ class Cli(object):
help="submit test jobs")
parser.add_argument('--print-json', action='store_true',
help="print the json job to stdout")
parser.add_argument('-p', '--profile', type=str,
help="specify the profile to use")
parser.add_argument('-p', '--profile', nargs='+', type=str,
help="specify the profiles to use")
parser.add_argument('--all-profiles', action='store_true',
help="process all the available profiles")
parser.add_argument('-t', '--template-vars', type=str,
......@@ -130,14 +130,15 @@ class Lava(object):
2) All profiles from 'all-profiles'
3) Or run without any profile....
"""
if self.args.profile:
for profile in self.settings.config.get('profiles', []):
if profile['name'] == self.args.profile:
self._run(profile)
break
elif self.args.all_profiles:
# Fetch the main profile and merge later with any sub profile
main_profile = self.settings.config.get('main-profile', {})
if self.args.profile or self.args.all_profiles:
for profile in self.settings.config.get('profiles', []):
self._run(profile)
if self.args.profile and not profile['name'] in self.args.profile:
continue
# Merge main-profile with available profiles and run!
self._run(_merge_profiles(main_profile, profile))
else:
self._run()
......@@ -199,11 +200,10 @@ class Lava(object):
json.dumps(json_obj))
except Fault as e:
self.settings.logger.error(
"Submitting job '{}': {}".format(job_file, e))
"Submitting job {}: {}".format(job_file, e))
continue
self.settings.logger.info(
"Submitted job '{}' with id '{}'"
.format(job_file, job_id))
self.settings.logger.info("Submitted job {} with id {}"
.format(job_file, job_id))
except EnvironmentError as e:
self.settings.logger.error(e)
continue
......@@ -217,15 +217,14 @@ class Lava(object):
rjob_id = self.server.scheduler.resubmit_job(job_id)
except Fault as e:
self.settings.logger.error(
"resubmit_job {}: '{}'".format(job_id, e))
"resubmit_job {}: {}".format(job_id, e))
except EnvironmentError as e:
self.settings.logger.error(e)
exit(1)
if rjob_id:
self.settings.logger.info(
"Resubmitted job id '{}' with new id '{}'"
.format(job_id, rjob_id))
self.settings.logger.info("Resubmitted job id {} with new id {}"
.format(job_id, rjob_id))
def cancel_job(self):
"""Cancel job id"""
......@@ -235,13 +234,13 @@ class Lava(object):
try:
res = self.server.scheduler.cancel_job(job_id)
except Fault as e:
self.settings.logger.error("cancel_job {}: '{}'".format(job_id, e))
self.settings.logger.error("cancel_job {}: {}".format(job_id, e))
except EnvironmentError as e:
self.settings.logger.error(e)
exit(1)
if res:
self.settings.logger.info("Job '{}' canceled".format(job_id))
self.settings.logger.info("Job {} canceled".format(job_id))
def fetch_result(self):
"""Fetch the result for job id list"""
......@@ -354,3 +353,15 @@ def find_config_file(arg_config, default_config, logger):
logger.error("Configuration file '{}' not found".format(arg_config))
exit(1)
return config
def _merge_profiles(original, update):
"""Merge two hashes.
This is used to merge profiles.
"""
for k, v in update.iteritems():
if type(v) == dict and (k in original and type(original[k]) == dict):
_merge_profiles(original[k], update[k])
else:
original[k] = update[k]
return original
# Version variable
__version__='20150117.0'
__version__='20150120.0'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment