From 01a1b5fc6e242775d126a0f357ea91c38c783404 Mon Sep 17 00:00:00 2001 From: Andrey Kurilin Date: Wed, 28 Dec 2016 16:44:51 +0200 Subject: [PATCH] [verification] Fix small bugs in verification component Co-Authored-By: Yaroslav Lobankov Change-Id: I654cedd465b4efacb3e28124ec5752a46060cc66 --- rally/common/utils.py | 2 +- rally/plugins/common/verification/testr.py | 10 ++++++---- .../openstack/verification/tempest/manager.py | 12 +++++++----- rally/verification/context.py | 4 ++-- rally/verification/manager.py | 7 +++---- tests/unit/plugins/common/verification/test_testr.py | 3 ++- .../openstack/verification/tempest/test_manager.py | 3 ++- tests/unit/verification/test_manager.py | 2 +- 8 files changed, 24 insertions(+), 19 deletions(-) diff --git a/rally/common/utils.py b/rally/common/utils.py index 1974566574..b67a0c8552 100644 --- a/rally/common/utils.py +++ b/rally/common/utils.py @@ -716,7 +716,7 @@ class Stopwatch(object): def generate_random_path(root_dir=None): - """Generates a vacant name foo file or dir at specified place. + """Generates a vacant name for a file or dir at the specified place. :param root_dir: Name of a directory to generate path in. If None (default behaviour), temporary directory (i.e /tmp in linux) will be used. diff --git a/rally/plugins/common/verification/testr.py b/rally/plugins/common/verification/testr.py index 3398df4ca7..ee0d752128 100644 --- a/rally/plugins/common/verification/testr.py +++ b/rally/plugins/common/verification/testr.py @@ -18,9 +18,11 @@ import re import shutil import subprocess +from rally.common.i18n import _LE from rally.common.io import subunit_v2 from rally.common import logging from rally.common import utils as common_utils +from rally import exceptions from rally.verification import context from rally.verification import manager from rally.verification import utils @@ -97,8 +99,8 @@ class TestrLauncher(manager.VerifierManager): except (subprocess.CalledProcessError, OSError): if os.path.exists(test_repository_dir): shutil.rmtree(test_repository_dir) - LOG.error("Failed to initialize a new repository for 'testr'.") - raise + raise exceptions.RallyException( + _LE("Failed to initialize testr.")) def install(self): super(TestrLauncher, self).install() @@ -133,7 +135,7 @@ class TestrLauncher(manager.VerifierManager): def _process_run_args(self, run_args): """Process run_args before verification execution. - This method is called by TestrContext before transforming run_args to - cli arguments of testr. + This method is called by TestrContext before transforming run_args into + cli arguments for testr. """ return run_args diff --git a/rally/plugins/openstack/verification/tempest/manager.py b/rally/plugins/openstack/verification/tempest/manager.py index d5840a01a1..d6edfc5084 100644 --- a/rally/plugins/openstack/verification/tempest/manager.py +++ b/rally/plugins/openstack/verification/tempest/manager.py @@ -57,6 +57,9 @@ class TempestManager(testr.TestrLauncher): return config.read_configfile(self.configfile) def configure(self, extra_options=None): + if not os.path.isdir(os.path.dirname(self.configfile)): + os.makedirs(os.path.dirname(self.configfile)) + cm = config.TempestConfigfileManager(self.verifier.deployment) raw_configfile = cm.create(self.configfile, extra_options) return raw_configfile @@ -68,13 +71,12 @@ class TempestManager(testr.TestrLauncher): with open(self.configfile, "w") as f: f.write(new_content) - def install_extension(self, source, version=None, extra=None): + def install_extension(self, source, version=None, extra_settings=None): """Install a Tempest plugin.""" - if extra: + if extra_settings: raise NotImplementedError( - _LE("'%s' verifiers don't support extra options for " - "extension installations.") - % self.get_name()) + _LE("'%s' verifiers don't support extra installation settings " + "for extensions.") % self.get_name()) version = version or "master" egg = re.sub("\.git$", "", os.path.basename(source.strip("/"))) full_source = "git+{0}@{1}#egg={2}".format(source, version, egg) diff --git a/rally/verification/context.py b/rally/verification/context.py index cde2d5c595..7ed5434b7c 100644 --- a/rally/verification/context.py +++ b/rally/verification/context.py @@ -44,5 +44,5 @@ class ContextManager(context.ContextManager): VerifierContext.get(name).validate(config, non_hidden=non_hidden) def _get_sorted_context_lst(self): - return sorted([VerifierContext.get(name)(cfg) - for name, cfg in self.context_obj["config"].items()]) + return sorted([VerifierContext.get(name)(self.context_obj) + for name in self.context_obj["config"].keys()]) diff --git a/rally/verification/manager.py b/rally/verification/manager.py index 3913562e13..8f3b0304fc 100644 --- a/rally/verification/manager.py +++ b/rally/verification/manager.py @@ -49,7 +49,7 @@ def configure(name, namespace="default", default_repo=None, plugin._configure(name, namespace) plugin._meta_set("default_repo", default_repo) plugin._meta_set("default_version", default_version) - plugin._meta_set("config", context or {}) + plugin._meta_set("context", context or {}) return plugin return decorator @@ -126,8 +126,7 @@ class VerifierManager(plugin.Plugin): @classmethod def validate(cls, deployment, run_args): - ctx_config = cls._meta_get("context") - context.ContextManager.validate({"config": ctx_config}) + context.ContextManager.validate(cls._meta_get("context")) cls.validate_args(run_args) def _clone(self): @@ -173,7 +172,7 @@ class VerifierManager(plugin.Plugin): LOG.info("Deleting old virtual environment.") shutil.rmtree(self.venv_dir) - LOG.info("Creating virtual environment.") + LOG.info("Creating virtual environment. It may take a few minutes.") LOG.debug("Initializing virtual environment in %s directory.", self.venv_dir) diff --git a/tests/unit/plugins/common/verification/test_testr.py b/tests/unit/plugins/common/verification/test_testr.py index db09ba260c..7856222e29 100644 --- a/tests/unit/plugins/common/verification/test_testr.py +++ b/tests/unit/plugins/common/verification/test_testr.py @@ -16,6 +16,7 @@ import subprocess import mock +from rally import exceptions from rally.plugins.common.verification import testr from tests.unit import test @@ -222,7 +223,7 @@ class TestrLauncherTestCase(test.TestCase): test_repository_dir = os.path.join(launcher.base_dir, ".testrepository") - self.assertRaises(OSError, launcher._init_testr) + self.assertRaises(exceptions.RallyException, launcher._init_testr) mock_check_output.assert_called_once_with( ["testr", "init"], cwd=launcher.repo_dir, env=launcher.environ) diff --git a/tests/unit/plugins/openstack/verification/tempest/test_manager.py b/tests/unit/plugins/openstack/verification/tempest/test_manager.py index 42eae5d8c5..3cd50579c6 100644 --- a/tests/unit/plugins/openstack/verification/tempest/test_manager.py +++ b/tests/unit/plugins/openstack/verification/tempest/test_manager.py @@ -88,7 +88,8 @@ class TempestManagerTestCase(test.TestCase): system_wide=True)) e = self.assertRaises(NotImplementedError, tempest.install_extension, None, None, {"key": "value"}) - self.assertIn("verifiers don't support extra options", "%s" % e) + self.assertIn("verifiers don't support extra installation settings", + "%s" % e) # case #1 system-wide installation source = "https://github.com/example/example" diff --git a/tests/unit/verification/test_manager.py b/tests/unit/verification/test_manager.py index c36c7d62f6..a21ef3c256 100644 --- a/tests/unit/verification/test_manager.py +++ b/tests/unit/verification/test_manager.py @@ -70,7 +70,7 @@ class VerifierManagerTestCase(test.TestCase): mock__meta_get.assert_called_once_with("context") mock_validate_args.assert_called_once_with(args) mock_context_manager_validate.assert_called_once_with( - {"config": mock__meta_get.return_value}) + mock__meta_get.return_value) def test__clone(self): verifier = mock.Mock(source=None)