Skip to content

Commit

Permalink
Merge pull request #5898 from clebergnu/nrunner_recipe_config_merge
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Richter <jarichte@redhat.com>
  • Loading branch information
richtja committed Apr 17, 2024
2 parents 7021bb9 + 94584fc commit a6b2555
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
40 changes: 20 additions & 20 deletions avocado/core/nrunner/runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(self, kind, uri, *args, config=None, **kwargs):
#: attr:`avocado.core.nrunner.runner.BaseRunner.CONFIGURATION_USED`
self._config = {}
if config is None:
config = self.filter_runnable_config(kind, {})
config = self.add_configuration_used(kind, {})
self.config = config or {}
self.args = args
self.tags = kwargs.pop("tags", None)
Expand Down Expand Up @@ -176,10 +176,10 @@ def config(self, config):
configuration_used = Runnable.get_configuration_used_by_kind(self.kind)
if not set(configuration_used).issubset(set(config.keys())):
LOG.warning(
"The runnable config should have only values "
"essential for its runner. In the next version of "
"avocado, this will raise a Value Error. Please "
"use avocado.core.nrunner.runnable.Runnable.filter_runnable_config "
"The runnable config should have values essential for its runner. "
"In this case, it's missing some of the used configuration. In a "
"future avocado version this will raise a ValueError. Please "
"use avocado.core.nrunner.runnable.Runnable.add_configuration_used "
"or avocado.core.nrunner.runnable.Runnable.from_avocado_config"
)
self._config = config
Expand Down Expand Up @@ -221,7 +221,7 @@ def from_avocado_config(cls, kind, uri, *args, config=None, **kwargs):
"""Creates runnable with only essential config for runner of specific kind."""
if not config:
config = {}
config = cls.filter_runnable_config(kind, config)
config = cls.add_configuration_used(kind, config)
return cls(kind, uri, *args, config=config, **kwargs)

@classmethod
Expand All @@ -245,30 +245,30 @@ def get_configuration_used_by_kind(cls, kind):
return configuration_used

@classmethod
def filter_runnable_config(cls, kind, config):
def add_configuration_used(cls, kind, config):
"""
Returns only essential values for specific runner.
Adds essential configuration values for specific runner.
It will use configuration from argument completed by values from
config file and avocado default configuration.
It will add missing configuration in the given config,
complementing it with values from config file and avocado default
configuration.
:param kind: Kind of runner which should use the configuration.
:type kind: str
:param config: Configuration values for runner. If some values will be
missing the default ones and from config file will be
used.
:param config: Configuration values for runner. If any used configuration
values are missing, the default ones and from config file
will be used.
:type config: dict
:returns: Config dict, which has only values essential for runner
based on STANDALONE_EXECUTABLE_CONFIG_USED
:returns: Config dict, which has existing entries plus values
essential for runner based on
STANDALONE_EXECUTABLE_CONFIG_USED
:rtype: dict
"""
whole_config = settings.as_dict()
filtered_config = {}
for config_item in cls.get_configuration_used_by_kind(kind):
filtered_config[config_item] = config.get(
config_item, whole_config.get(config_item)
)
return filtered_config
if config_item not in config:
config[config_item] = whole_config.get(config_item)
return config

def get_command_args(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion avocado/plugins/runner_nrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _update_avocado_configuration_used_on_runnables(runnables, config):
:type config: dict
"""
for runnable in runnables:
runnable.config = Runnable.filter_runnable_config(runnable.kind, config)
runnable.config = Runnable.add_configuration_used(runnable.kind, config)

def _determine_status_server(self, test_suite, config_key):
if test_suite.config.get("run.status_server_auto"):
Expand Down
2 changes: 1 addition & 1 deletion selftests/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"job-api-7": 1,
"nrunner-interface": 70,
"nrunner-requirement": 16,
"unit": 668,
"unit": 669,
"jobs": 11,
"functional-parallel": 301,
"functional-serial": 4,
Expand Down
17 changes: 17 additions & 0 deletions selftests/unit/nrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ def test_recipe_exec(self):
self.assertEqual(runnable.args, ("/etc/profile",))
self.assertEqual(runnable.kwargs, {"TERM": "vt3270"})

def test_recipe_config(self):
open_mocked = unittest.mock.mock_open(
read_data=(
'{"kind": "exec-test", "uri": "/bin/sh", '
'"args": ["/etc/profile"], '
'"config": {"runner.identifier_format": "{uri}-{args[0]}"}}'
)
)
with unittest.mock.patch("builtins.open", open_mocked):
runnable = Runnable.from_recipe("fake_path")
configuration_used = ["run.keep_tmp", "runner.exectest.exitcodes.skip"]
for conf in configuration_used:
self.assertIn(conf, runnable.config)
self.assertEqual(
runnable.config.get("runner.identifier_format"), "{uri}-{args[0]}"
)

def test_identifier_args(self):
config = {"runner.identifier_format": "{uri}-{args[0]}"}
runnable = Runnable("exec-test", "uri", "arg1", "arg2", config=config)
Expand Down

0 comments on commit a6b2555

Please sign in to comment.