diff options
author | David Sommerseth <davids@redhat.com> | 2012-12-19 17:07:38 +0100 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2012-12-19 17:07:38 +0100 |
commit | 77fcdf51e62efa910eb25eb055fa8909f6ea71cf (patch) | |
tree | a61801f276a4efb20d1622d37e8ea508eb730f23 | |
parent | 96d0f3853fbac2b05dfb9fa97372f3a354083dd2 (diff) | |
download | rteval-77fcdf51e62efa910eb25eb055fa8909f6ea71cf.tar.gz |
Instead of passing the config class a few places, save it in __init__()
This cleans up the API a little bit, and lets the configuration access
become a bit easier in the load and measurement classes.
Signed-off-by: David Sommerseth <davids@redhat.com>
-rwxr-xr-x | rteval-cmd | 2 | ||||
-rw-r--r-- | rteval/modules/__init__.py | 7 | ||||
-rw-r--r-- | rteval/modules/loads/__init__.py | 11 | ||||
-rw-r--r-- | rteval/modules/measurement/__init__.py | 13 |
4 files changed, 17 insertions, 16 deletions
@@ -231,7 +231,7 @@ if __name__ == '__main__': # parse command line options parser = optparse.OptionParser() - loadmods.SetupModuleOptions(parser, config) + loadmods.SetupModuleOptions(parser) measuremods.SetupModuleOptions(parser) cmd_args = parse_options(config, parser, sys.argv[1:]) diff --git a/rteval/modules/__init__.py b/rteval/modules/__init__.py index d4a06d5..c4e83cc 100644 --- a/rteval/modules/__init__.py +++ b/rteval/modules/__init__.py @@ -328,12 +328,13 @@ class RtEvalModules(object): This class takes care of managing imported modules and have methods for starting and stopping the workload these modules contains.""" - def __init__(self, modules_root, logger): + def __init__(self, config, modules_root, logger): """Initialises the RtEvalModules() internal variables. The modules_root argument should point at the root directory where the modules will be loaded from. The logger argument should point to a Log() object which will be used for logging and will also be given to the instantiated objects during module import.""" + self._cfg = config self._logger = logger self.__modules = ModuleContainer(modules_root, logger) @@ -365,9 +366,9 @@ and will also be given to the instantiated objects during module import.""" "Returns a list of module names" return self.__modules.GetModulesList() - def SetupModuleOptions(self, parser, config): + def SetupModuleOptions(self, parser): "Sets up optparse based option groups for the loaded modules" - return self.__modules.SetupModuleOptions(parser, config) + return self.__modules.SetupModuleOptions(parser, self._cfg) def GetNamedModuleObject(self, modname): "Returns a list of module names" diff --git a/rteval/modules/loads/__init__.py b/rteval/modules/loads/__init__.py index 3c897b8..ca84f47 100644 --- a/rteval/modules/loads/__init__.py +++ b/rteval/modules/loads/__init__.py @@ -93,9 +93,8 @@ class LoadModules(RtEvalModules): self._report_tag = "loads" self.__loadavg_accum = 0.0 self.__loadavg_samples = 0 - self.__cfg = config - RtEvalModules.__init__(self, "modules.loads", logger) - self.__LoadModules(self.__cfg.GetSection(self._module_config)) + RtEvalModules.__init__(self, config, "modules.loads", logger) + self.__LoadModules(self._cfg.GetSection(self._module_config)) def __LoadModules(self, modcfg): @@ -112,13 +111,13 @@ class LoadModules(RtEvalModules): if not isinstance(modparams, dict): raise TypeError("modparams attribute is not of a dictionary type") - modcfg = self.__cfg.GetSection(self._module_config) + modcfg = self._cfg.GetSection(self._module_config) for m in modcfg: # hope to eventually have different kinds but module is only on # for now (jcw) if m[1].lower() == 'module': - self.__cfg.AppendConfig(m[0], modparams) - modobj = self._InstantiateModule(m[0], self.__cfg.GetSection(m[0])) + self._cfg.AppendConfig(m[0], modparams) + modobj = self._InstantiateModule(m[0], self._cfg.GetSection(m[0])) self._RegisterModuleObject(m[0], modobj) diff --git a/rteval/modules/measurement/__init__.py b/rteval/modules/measurement/__init__.py index 90345ad..2a46bcc 100644 --- a/rteval/modules/measurement/__init__.py +++ b/rteval/modules/measurement/__init__.py @@ -29,7 +29,7 @@ from rteval.modules import RtEvalModules, ModuleContainer class MeasurementProfile(RtEvalModules): """Keeps and controls all the measurement modules with the same measurement profile""" - def __init__(self, with_load, run_parallel, modules_root, logger): + def __init__(self, config, with_load, run_parallel, modules_root, logger): self.__with_load = with_load self.__run_parallel = run_parallel @@ -39,7 +39,7 @@ class MeasurementProfile(RtEvalModules): self._module_type = "measurement" self._module_config = "measurement" self._report_tag = "Profile" - RtEvalModules.__init__(self, modules_root, logger) + RtEvalModules.__init__(self, config, modules_root, logger) def GetProfile(self): @@ -52,10 +52,10 @@ class MeasurementProfile(RtEvalModules): return self._ImportModule(module) - def Setup(self, modname, modcfg): + def Setup(self, modname): "Instantiates and prepares a measurement module" - modobj = self._InstantiateModule(modname, modcfg) + modobj = self._InstantiateModule(modname, self._cfg.GetSection(modname)) self._RegisterModuleObject(modname, modobj) @@ -165,7 +165,8 @@ measurement profiles, based on their characteristics""" mp = self.GetProfile(modinfo["loads"], modinfo["parallel"]) if mp is None: # If not found, create a new measurement profile - mp = MeasurementProfile(modinfo["loads"], modinfo["parallel"], + mp = MeasurementProfile(self.__cfg, + modinfo["loads"], modinfo["parallel"], self.__modules_root, self.__logger) self.__measureprofiles.append(mp) @@ -175,7 +176,7 @@ measurement profiles, based on their characteristics""" # Setup this imported module inside the appropriate measurement profile self.__cfg.AppendConfig(modname, modparams) - mp.Setup(modname, self.__cfg.GetSection(modname)) + mp.Setup(modname) del self.__container |