From 71f3467dc8f22eb6000adf2a1cd21cd6eb4eaaf0 Mon Sep 17 00:00:00 2001 From: Sebastian Goscik Date: Mon, 26 Sep 2016 17:13:22 +0100 Subject: [PATCH] Configuration: Removed merge_using_priority_specificity This had moved to now be done by plugin cache so it has been removed from wlauto.core.configuration.configuration and any referenced to it have been changed to use plugin cache instead. --- wlauto/core/configuration/configuration.py | 93 +--------------------- 1 file changed, 4 insertions(+), 89 deletions(-) diff --git a/wlauto/core/configuration/configuration.py b/wlauto/core/configuration/configuration.py index 8d6e89ad..5f99a4cb 100644 --- a/wlauto/core/configuration/configuration.py +++ b/wlauto/core/configuration/configuration.py @@ -489,89 +489,6 @@ class CpuFreqParameters(object): ##################### -# pylint: disable=too-many-nested-blocks, too-many-branches -def merge_using_priority_specificity(generic_name, specific_name, plugin_cache): - """ - WA configuration can come from various sources of increasing priority, as well - as being specified in a generic and specific manner (e.g. ``device_config`` - and ``nexus10`` respectivly). WA has two rules for the priority of configuration: - - - Configuration from higher priority sources overrides configuration from - lower priority sources. - - More specific configuration overrides less specific configuration. - - There is a situation where these two rules come into conflict. When a generic - configuration is given in config source of high priority and a specific - configuration is given in a config source of lower priority. In this situation - it is not possible to know the end users intention and WA will error. - - :param generic_name: The name of the generic configuration e.g ``device_config`` - :param specific_name: The name of the specific configuration used, e.g ``nexus10`` - :param cfg_point: A dict of ``ConfigurationPoint``s to be used when merging configuration. - keys=config point name, values=config point - - :rtype: A fully merged and validated configuration in the form of a obj_dict. - """ - generic_config = plugin_cache.get_plugin_config(generic_name) - specific_config = plugin_cache.get_plugin_config(specific_name) - cfg_points = plugin_cache.get_plugin_parameters(specific_name) - sources = plugin_cache.sources - final_config = obj_dict(not_in_dict=['name']) - seen_specific_config = defaultdict(list) - - # set_value uses the 'name' attribute of the passed object in it error - # messages, to ensure these messages make sense the name will have to be - # changed several times during this function. - final_config.name = specific_name - - # Load default config - for cfg_point in cfg_points.itervalues(): - cfg_point.set_value(final_config, check_mandatory=False) - - # pylint: disable=too-many-nested-blocks - for source in sources: - try: - if source in generic_config: - for name, cfg_point in cfg_points.iteritems(): - final_config.name = generic_name - if name in generic_config[source]: - if name in seen_specific_config: - msg = ('"{generic_name}" configuration "{config_name}" has already been ' - 'specified more specifically for {specific_name} in:\n\t\t{sources}') - msg = msg.format(generic_name=generic_name, - config_name=name, - specific_name=specific_name, - sources="\n\t\t".join(seen_specific_config[name])) - raise ConfigError(msg) - value = generic_config[source].pop(name) - cfg_point.set_value(final_config, value, check_mandatory=False) - if generic_config[source]: - msg = 'Invalid entry(ies) for "{}" in "{}": "{}"' - msg = msg.format(specific_name, generic_name, '", "'.join(generic_config[source])) - raise ConfigError(msg) - - if source in specific_config: - final_config.name = specific_name - for name, cfg_point in cfg_points.iteritems(): - if name in specific_config[source]: - seen_specific_config[name].append(source) - value = specific_config[source].pop(name) - cfg_point.set_value(final_config, value, check_mandatory=False) - if specific_config[source]: - msg = 'Invalid entry(ies) for "{}": "{}"' - raise ConfigError(msg.format(specific_name, '", "'.join(specific_config[source]))) - - except ConfigError as e: - raise ConfigError('Error in "{}":\n\t{}'.format(source, str(e))) - - # Validate final configuration - final_config.name = specific_name - for cfg_point in cfg_points.itervalues(): - cfg_point.validate(final_config) - - return final_config - - class Configuration(object): config_points = [] @@ -845,9 +762,8 @@ class RunConfiguration(Configuration): selected device. """ # pylint: disable=no-member - self.device_config = merge_using_priority_specificity("device_config", - self.device, - plugin_cache) + self.device_config = plugin_cache.get_plugin_config(self.device_config, + generic_name="device_config") def to_pod(self): pod = super(RunConfiguration, self).to_pod() @@ -950,9 +866,8 @@ class JobSpec(Configuration): # Only call after the rest of the JobSpec is merged def merge_workload_parameters(self, plugin_cache): # merge global generic and specific config - workload_params = merge_using_priority_specificity("workload_parameters", - self.workload_name, - plugin_cache) + workload_params = plugin_cache.get_plugin_config(self.workload_name, + generic_name="workload_parameters") # Merge entry "workload_parameters" # TODO: Wrap in - "error in [agenda path]"