1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2024-10-06 19:01:15 +01:00

AgendaParser: Various fixes

- Fixed merge_result_processors_instruments not merging result_processors
 - Made AgendaParser have the same load/load_from_path interface as ConfigParser
 - Removed source from error messages because its already predended when caught
 - AgendaParser no longer needs to be passed a ConfigParser, it makes its own instance
 - Changed quote style from "Error in {}" message to match other errors
This commit is contained in:
Sebastian Goscik 2016-08-16 10:49:37 +01:00
parent 55c4ed8c56
commit 3be1d1202c

View File

@ -79,7 +79,7 @@ def merge_result_processors_instruments(raw):
msg = '"instrumentation" and "result_processors" have conflicting entries: {}' msg = '"instrumentation" and "result_processors" have conflicting entries: {}'
entires = ', '.join('"{}"'.format(c.strip("~")) for c in conflicts) entires = ', '.join('"{}"'.format(c.strip("~")) for c in conflicts)
raise ConfigError(msg.format(entires)) raise ConfigError(msg.format(entires))
raw['instrumentation'] = instruments.merge_with(instruments) raw['instrumentation'] = instruments.merge_with(result_processors)
def _construct_valid_entry(raw, seen_ids, counter_name): def _construct_valid_entry(raw, seen_ids, counter_name):
@ -175,32 +175,39 @@ class ConfigParser(object):
class AgendaParser(object): class AgendaParser(object):
def __init__(self, config_parser, wa_config, run_config, jobs_config, plugin_cache): def __init__(self, wa_config, run_config, jobs_config, plugin_cache):
self.config_parser = config_parser
self.wa_config = wa_config self.wa_config = wa_config
self.run_config = run_config self.run_config = run_config
self.jobs_config = jobs_config self.jobs_config = jobs_config
self.plugin_cache = plugin_cache self.plugin_cache = plugin_cache
def load(self, filepath): # pylint: disable=too-many-branches, too-many-locals def load_from_path(self, filepath):
raw = _load_file(filepath, 'Agenda') raw = _load_file(filepath, 'Agenda')
self.load(raw, filepath)
def load(self, raw, source): # pylint: disable=too-many-branches, too-many-locals
try: try:
if not isinstance(raw, dict):
raise ConfigError('Invalid agenda, top level entry must be a dict')
# PHASE 1: Populate and validate configuration. # PHASE 1: Populate and validate configuration.
for name in ['config', 'global']: for name in ['config', 'global']:
entry = raw.pop(name, {}) entry = raw.pop(name, {})
if not isinstance(entry, dict): if not isinstance(entry, dict):
raise ConfigError('Invalid entry "{}" in {} - must be a dict'.format(name, filepath)) raise ConfigError('Invalid entry "{}" - must be a dict'.format(name))
if 'run_name' in entry: if 'run_name' in entry:
self.run_config.set('run_name', entry.pop('run_name')) self.run_config.set('run_name', entry.pop('run_name'))
self.config_parser.load(entry, filepath) config_parser = ConfigParser(self.wa_config, self.run_config,
self.jobs_config, self.plugin_cache)
config_parser.load(entry, source)
# PHASE 2: Getting "section" and "workload" entries. # PHASE 2: Getting "section" and "workload" entries.
sections = raw.pop("sections", []) sections = raw.pop("sections", [])
if not isinstance(sections, list): if not isinstance(sections, list):
raise ConfigError('Invalid entry "sections" in {} - must be a list'.format(filepath)) raise ConfigError('Invalid entry "sections" - must be a list')
global_workloads = raw.pop("workloads", []) global_workloads = raw.pop("workloads", [])
if not isinstance(global_workloads, list): if not isinstance(global_workloads, list):
raise ConfigError('Invalid entry "workloads" in {} - must be a list'.format(filepath)) raise ConfigError('Invalid entry "workloads" - must be a list')
if raw: if raw:
msg = 'Invalid top level agenda entry(ies): "{}"' msg = 'Invalid top level agenda entry(ies): "{}"'
raise ConfigError(msg.format('", "'.join(raw.keys()))) raise ConfigError(msg.format('", "'.join(raw.keys())))
@ -252,7 +259,7 @@ class AgendaParser(object):
self.jobs_config.add_section(section, workloads) self.jobs_config.add_section(section, workloads)
except (ConfigError, SerializerSyntaxError) as e: except (ConfigError, SerializerSyntaxError) as e:
raise ConfigError("Error in '{}':\n\t{}".format(filepath, str(e))) raise ConfigError('Error in "{}":\n\t{}'.format(source, str(e)))
def _process_entry(self, entry, seen_workload_ids): def _process_entry(self, entry, seen_workload_ids):
workload = get_workload_entry(entry) workload = get_workload_entry(entry)