From a347ea7d61ddbc21f4f57063d9fcb9f3065b2ceb Mon Sep 17 00:00:00 2001
From: Sebastian Goscik <sebastian.goscik@live.co.uk>
Date: Tue, 20 Sep 2016 16:59:31 +0100
Subject: [PATCH] Misc fixes & improvements

---
 wlauto/__init__.py                         |  3 ++-
 wlauto/core/configuration/configuration.py | 12 +++++++-----
 wlauto/core/configuration/parsers.py       | 10 +++++-----
 wlauto/core/plugin.py                      |  1 -
 wlauto/tests/test_parsers.py               |  2 +-
 5 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/wlauto/__init__.py b/wlauto/__init__.py
index b73f57f4..a7e630a0 100644
--- a/wlauto/__init__.py
+++ b/wlauto/__init__.py
@@ -17,7 +17,8 @@ from wlauto.core.configuration import settings  # NOQA
 from wlauto.core.device_manager import DeviceManager, RuntimeParameter, CoreParameter  # NOQA
 from wlauto.core.command import Command  # NOQA
 from wlauto.core.workload import Workload  # NOQA
-from wlauto.core.plugin import Parameter, Artifact, Alias  # NOQA
+from wlauto.core.plugin import Artifact, Alias  # NOQA
+from wlauto.core.configuration.configuration import ConfigurationPoint as Parameter
 import wlauto.core.pluginloader as PluginLoader  # NOQA
 from wlauto.core.instrumentation import Instrument  # NOQA
 from wlauto.core.result import ResultProcessor, IterationResult  # NOQA
diff --git a/wlauto/core/configuration/configuration.py b/wlauto/core/configuration/configuration.py
index e645d4e5..9c5698aa 100644
--- a/wlauto/core/configuration/configuration.py
+++ b/wlauto/core/configuration/configuration.py
@@ -832,7 +832,7 @@ class JobSpec(Configuration):
 
     def __init__(self):
         super(JobSpec, self).__init__()
-        self._to_merge = defaultdict(dict)
+        self.to_merge = defaultdict(OrderedDict)
         self._sources = []
         self.id = None
         self.workload_parameters = None
@@ -847,7 +847,7 @@ class JobSpec(Configuration):
                 continue
             elif k in ["workload_parameters", "runtime_parameters", "boot_parameters"]:
                 if v:
-                    self._to_merge[k][source] = copy(v)
+                    self.to_merge[k][source] = copy(v)
             else:
                 try:
                     self.set(k, v, check_mandatory=check_mandatory)
@@ -867,8 +867,8 @@ class JobSpec(Configuration):
         # TODO: Wrap in - "error in [agenda path]"
         cfg_points = plugin_cache.get_plugin_parameters(self.workload_name)
         for source in self._sources:
-            if source in self._to_merge["workload_params"]:
-                config = self._to_merge["workload_params"][source]
+            if source in self.to_merge["workload_params"]:
+                config = self.to_merge["workload_params"][source]
                 for name, cfg_point in cfg_points.iteritems():
                     if name in config:
                         value = config.pop(name)
@@ -916,7 +916,7 @@ class JobSpec(Configuration):
             msg = 'No value specified for mandatory parameter "{}}".'
             raise ConfigError(msg.format(e.args[0]))
 
-        instance = super(JobSpec, cls).from_pod(pod, plugin_loader)
+        instance = super(JobSpec, cls).from_pod(pod, plugin_cache)
 
         # TODO: validate parameters and construct the rest of the instance
 
@@ -958,6 +958,8 @@ class JobGenerator(object):
     def set_global_value(self, name, value):
         JobSpec.configuration[name].set_value(self.job_spec_template, value,
                                               check_mandatory=False)
+        if name == "instrumentation":
+            self.update_enabled_instruments(value)
 
     def add_section(self, section, workloads):
         new_node = self.root_node.add_section(section)
diff --git a/wlauto/core/configuration/parsers.py b/wlauto/core/configuration/parsers.py
index 5cde7fcf..7d53424f 100644
--- a/wlauto/core/configuration/parsers.py
+++ b/wlauto/core/configuration/parsers.py
@@ -261,13 +261,15 @@ class AgendaParser(object):
             # TODO: Error handling for workload errors vs section errors ect
             for workload in global_workloads:
                 self.jobs_config.add_workload(_process_workload_entry(workload,
-                                                                      seen_workload_ids))
+                                                                      seen_workload_ids,
+                                                                      self.jobs_config))
 
             for section in sections:
                 workloads = []
                 for workload in section.pop("workloads", []):
                     workloads.append(_process_workload_entry(workload,
-                                                             seen_workload_ids))
+                                                             seen_workload_ids,
+                                                             self.jobs_config))
 
                 _resolve_params_alias(section, seen_section_ids)
                 section = _construct_valid_entry(section, seen_section_ids, "s", self.jobs_config)
@@ -279,7 +281,6 @@ class AgendaParser(object):
 
 
 class EnvironmentVarsParser(object):
-    #TODO: podable
     def __init__(self, wa_config, environ):
         user_directory = environ.pop('WA_USER_DIRECTORY', '')
         if user_directory:
@@ -296,8 +297,7 @@ class EnvironmentVarsParser(object):
 # certain arguments to the correct configuration points and keep a record of
 # how WA was invoked
 class CommandLineArgsParser(object):
-    #TODO: podable
-    def __init__(self, cmd_args, wa_config, run_config, jobs_config):
+    def __init__(self, cmd_args, wa_config, jobs_config):
         wa_config.set("verbosity", cmd_args.verbosity)
         # TODO: Is this correct? Does there need to be a third output dir param
         disabled_instruments = toggle_set(["~{}".format(i) for i in cmd_args.instruments_to_disable])
diff --git a/wlauto/core/plugin.py b/wlauto/core/plugin.py
index 9e7cb13b..87cea5f5 100644
--- a/wlauto/core/plugin.py
+++ b/wlauto/core/plugin.py
@@ -714,7 +714,6 @@ class PluginLoader(object):
         base_default_config = self.get_plugin_class(real_name).get_default_config()
         return merge_dicts_simple(base_default_config, alias_config)
 
-
     def list_plugins(self, kind=None):
         """
         List discovered plugin classes. Optionally, only list plugins of a
diff --git a/wlauto/tests/test_parsers.py b/wlauto/tests/test_parsers.py
index 2dd6d171..6f9e75eb 100644
--- a/wlauto/tests/test_parsers.py
+++ b/wlauto/tests/test_parsers.py
@@ -414,7 +414,7 @@ class TestCommandLineArgsParser(TestCase):
         only_run_ids=["wk1", "s1_wk4"],
         some_other_setting="value123"
     )
-    CommandLineArgsParser(cmd_args, wa_config, run_config, jobs_config)
+    CommandLineArgsParser(cmd_args, wa_config, jobs_config)
     wa_config.set.assert_has_calls([call("verbosity", 1)], any_order=True)
     jobs_config.disable_instruments.assert_has_calls([
         call(toggle_set(["~abc", "~def", "~ghi"]))