提交 09b951b5 编写于 作者: C Cleber Rosa

Parameters: remove knowledge about a specific (job) logger

The forward reference from the parameter module towards the job log
is not ideal.  The parameter module should be used by test (and
related code) and should not know about the test and job internals.

But, there's the clear requirement and convenience of logging the
access to the parameters.  This makes the user of the parameter
instance define which logger should be used, and not the other
way around.

Logger names are used here, because, the communication between
runner and test (get_state()) currently includes test parameters,
and serializing a logger instance is not possible.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 c3d8c80a
......@@ -15,13 +15,12 @@
Module related to test parameters
"""
import logging
import re
from six import iterkeys, iteritems
from six.moves import xrange as range
from . import output
class NoMatchError(KeyError):
pass
......@@ -40,18 +39,16 @@ class AvocadoParams(object):
You can also iterate through all keys, but this can generate quite a lot
of duplicate entries inherited from ancestor nodes. It shouldn't produce
false values, though.
In this version each new "get()" call is logged into avocado.LOG_JOB.
This is subject of change (separate file, perhaps)
"""
# TODO: Use "test" to log params.get()
def __init__(self, leaves, test_id, mux_path):
def __init__(self, leaves, test_id, mux_path, logger_name=None):
"""
:param leaves: List of TreeNode leaves defining current variant
:param test_id: test id
:param mux_path: list of entry points
:param logger_name: the name of a logger to use to record attempts
to get parameters
:type logger_name: str
"""
self._rel_paths = []
leaves = list(leaves)
......@@ -64,6 +61,7 @@ class AvocadoParams(object):
self._abs_path = AvocadoParam(path_leaves, '*: *')
self.id = test_id
self._cache = {} # TODO: Implement something more efficient
self._logger_name = logger_name
def __eq__(self, other):
if set(iterkeys(self.__dict__)) != set(iterkeys(other.__dict__)):
......@@ -76,15 +74,6 @@ class AvocadoParams(object):
def __ne__(self, other):
return not (self == other)
def __getstate__(self):
""" log can't be pickled """
copy = self.__dict__.copy()
return copy
def __setstate__(self, orig):
""" refresh log """
self.__dict__.update(orig)
def __repr__(self):
return "<AvocadoParams %s>" % self._str()
......@@ -98,11 +87,6 @@ class AvocadoParams(object):
else:
return self._abs_path.str_leaves_variant
def log(self, key, path, default, value):
""" Predefined format for displaying params query """
output.LOG_JOB.debug("PARAMS (key=%s, path=%s, default=%s) => %r", key,
path, default, value)
def _get_matching_leaves(self, path, leaves):
"""
Pops and returns list of matching nodes
......@@ -160,7 +144,10 @@ class AvocadoParams(object):
# KeyError - first query
# TypeError - unable to hash
value = self._get(key, path, default)
self.log(key, path, default, value)
if self._logger_name is not None:
logger = logging.getLogger(self._logger_name)
logger.debug("PARAMS (key=%s, path=%s, default=%s) => %r",
key, path, default, value)
try:
self._cache[(key, path, default)] = value
except TypeError:
......
......@@ -367,7 +367,7 @@ class Test(unittest.TestCase, TestData):
elif isinstance(params, tuple):
params, mux_path = params[0], params[1]
self.__params = parameters.AvocadoParams(params, self.name,
mux_path)
mux_path, self.__log.name)
default_timeout = getattr(self, "timeout", None)
self.timeout = self.params.get("timeout", default=default_timeout)
......
......@@ -19,6 +19,7 @@ from six import iteritems
from avocado.core import loader
from avocado.core import parameters
from avocado.core import output
from avocado.core.plugin_interfaces import CLI
from avocado_varianter_yaml_to_mux import create_from_yaml
from avocado_varianter_yaml_to_mux import mux
......@@ -101,7 +102,7 @@ class YamlTestsuiteLoader(loader.TestLoader):
mux_tree = mux.MuxTree(root)
for variant in mux_tree:
params = parameters.AvocadoParams(variant, "YamlTestsuiteLoader",
["/run/*"])
["/run/*"], output.LOG_UI.name)
reference = params.get("test_reference")
test_loader = self._get_loader(params)
if not test_loader:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册