[verification] Fix small bugs in verification component

Co-Authored-By: Yaroslav Lobankov <ylobankov@mirantis.com>

Change-Id: I654cedd465b4efacb3e28124ec5752a46060cc66
This commit is contained in:
Andrey Kurilin 2016-12-28 16:44:51 +02:00 committed by Yaroslav Lobankov
parent bb336b0a11
commit 01a1b5fc6e
8 changed files with 24 additions and 19 deletions

View File

@ -716,7 +716,7 @@ class Stopwatch(object):
def generate_random_path(root_dir=None): 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 :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. behaviour), temporary directory (i.e /tmp in linux) will be used.

View File

@ -18,9 +18,11 @@ import re
import shutil import shutil
import subprocess import subprocess
from rally.common.i18n import _LE
from rally.common.io import subunit_v2 from rally.common.io import subunit_v2
from rally.common import logging from rally.common import logging
from rally.common import utils as common_utils from rally.common import utils as common_utils
from rally import exceptions
from rally.verification import context from rally.verification import context
from rally.verification import manager from rally.verification import manager
from rally.verification import utils from rally.verification import utils
@ -97,8 +99,8 @@ class TestrLauncher(manager.VerifierManager):
except (subprocess.CalledProcessError, OSError): except (subprocess.CalledProcessError, OSError):
if os.path.exists(test_repository_dir): if os.path.exists(test_repository_dir):
shutil.rmtree(test_repository_dir) shutil.rmtree(test_repository_dir)
LOG.error("Failed to initialize a new repository for 'testr'.") raise exceptions.RallyException(
raise _LE("Failed to initialize testr."))
def install(self): def install(self):
super(TestrLauncher, self).install() super(TestrLauncher, self).install()
@ -133,7 +135,7 @@ class TestrLauncher(manager.VerifierManager):
def _process_run_args(self, run_args): def _process_run_args(self, run_args):
"""Process run_args before verification execution. """Process run_args before verification execution.
This method is called by TestrContext before transforming run_args to This method is called by TestrContext before transforming run_args into
cli arguments of testr. cli arguments for testr.
""" """
return run_args return run_args

View File

@ -57,6 +57,9 @@ class TempestManager(testr.TestrLauncher):
return config.read_configfile(self.configfile) return config.read_configfile(self.configfile)
def configure(self, extra_options=None): 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) cm = config.TempestConfigfileManager(self.verifier.deployment)
raw_configfile = cm.create(self.configfile, extra_options) raw_configfile = cm.create(self.configfile, extra_options)
return raw_configfile return raw_configfile
@ -68,13 +71,12 @@ class TempestManager(testr.TestrLauncher):
with open(self.configfile, "w") as f: with open(self.configfile, "w") as f:
f.write(new_content) 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.""" """Install a Tempest plugin."""
if extra: if extra_settings:
raise NotImplementedError( raise NotImplementedError(
_LE("'%s' verifiers don't support extra options for " _LE("'%s' verifiers don't support extra installation settings "
"extension installations.") "for extensions.") % self.get_name())
% self.get_name())
version = version or "master" version = version or "master"
egg = re.sub("\.git$", "", os.path.basename(source.strip("/"))) egg = re.sub("\.git$", "", os.path.basename(source.strip("/")))
full_source = "git+{0}@{1}#egg={2}".format(source, version, egg) full_source = "git+{0}@{1}#egg={2}".format(source, version, egg)

View File

@ -44,5 +44,5 @@ class ContextManager(context.ContextManager):
VerifierContext.get(name).validate(config, non_hidden=non_hidden) VerifierContext.get(name).validate(config, non_hidden=non_hidden)
def _get_sorted_context_lst(self): def _get_sorted_context_lst(self):
return sorted([VerifierContext.get(name)(cfg) return sorted([VerifierContext.get(name)(self.context_obj)
for name, cfg in self.context_obj["config"].items()]) for name in self.context_obj["config"].keys()])

View File

@ -49,7 +49,7 @@ def configure(name, namespace="default", default_repo=None,
plugin._configure(name, namespace) plugin._configure(name, namespace)
plugin._meta_set("default_repo", default_repo) plugin._meta_set("default_repo", default_repo)
plugin._meta_set("default_version", default_version) plugin._meta_set("default_version", default_version)
plugin._meta_set("config", context or {}) plugin._meta_set("context", context or {})
return plugin return plugin
return decorator return decorator
@ -126,8 +126,7 @@ class VerifierManager(plugin.Plugin):
@classmethod @classmethod
def validate(cls, deployment, run_args): def validate(cls, deployment, run_args):
ctx_config = cls._meta_get("context") context.ContextManager.validate(cls._meta_get("context"))
context.ContextManager.validate({"config": ctx_config})
cls.validate_args(run_args) cls.validate_args(run_args)
def _clone(self): def _clone(self):
@ -173,7 +172,7 @@ class VerifierManager(plugin.Plugin):
LOG.info("Deleting old virtual environment.") LOG.info("Deleting old virtual environment.")
shutil.rmtree(self.venv_dir) 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.", LOG.debug("Initializing virtual environment in %s directory.",
self.venv_dir) self.venv_dir)

View File

@ -16,6 +16,7 @@ import subprocess
import mock import mock
from rally import exceptions
from rally.plugins.common.verification import testr from rally.plugins.common.verification import testr
from tests.unit import test from tests.unit import test
@ -222,7 +223,7 @@ class TestrLauncherTestCase(test.TestCase):
test_repository_dir = os.path.join(launcher.base_dir, test_repository_dir = os.path.join(launcher.base_dir,
".testrepository") ".testrepository")
self.assertRaises(OSError, launcher._init_testr) self.assertRaises(exceptions.RallyException, launcher._init_testr)
mock_check_output.assert_called_once_with( mock_check_output.assert_called_once_with(
["testr", "init"], cwd=launcher.repo_dir, env=launcher.environ) ["testr", "init"], cwd=launcher.repo_dir, env=launcher.environ)

View File

@ -88,7 +88,8 @@ class TempestManagerTestCase(test.TestCase):
system_wide=True)) system_wide=True))
e = self.assertRaises(NotImplementedError, tempest.install_extension, e = self.assertRaises(NotImplementedError, tempest.install_extension,
None, None, {"key": "value"}) 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 # case #1 system-wide installation
source = "https://github.com/example/example" source = "https://github.com/example/example"

View File

@ -70,7 +70,7 @@ class VerifierManagerTestCase(test.TestCase):
mock__meta_get.assert_called_once_with("context") mock__meta_get.assert_called_once_with("context")
mock_validate_args.assert_called_once_with(args) mock_validate_args.assert_called_once_with(args)
mock_context_manager_validate.assert_called_once_with( mock_context_manager_validate.assert_called_once_with(
{"config": mock__meta_get.return_value}) mock__meta_get.return_value)
def test__clone(self): def test__clone(self):
verifier = mock.Mock(source=None) verifier = mock.Mock(source=None)