Merge "Adding possibility to generate tempest.conf, not running tempest"

This commit is contained in:
Jenkins 2015-09-21 07:28:31 +00:00 committed by Gerrit Code Review
commit 52f62e31dc
6 changed files with 104 additions and 9 deletions

View File

@ -52,6 +52,7 @@ _rally()
OPTS["task_validate"]="--deployment --task --task-args --task-args-file"
OPTS["verify_compare"]="--uuid-1 --uuid-2 --csv --html --json --output-file --threshold"
OPTS["verify_detailed"]="--uuid --sort-by"
OPTS["verify_genconfig"]="--deployment --tempest-config --override"
OPTS["verify_list"]=""
OPTS["verify_results"]="--uuid --html --json --output-file"
OPTS["verify_show"]="--uuid --sort-by --detailed"

View File

@ -267,6 +267,27 @@ class Verification(object):
deployment_uuid = objects.Deployment.get(deployment)["uuid"]
verification = objects.Verification(deployment_uuid=deployment_uuid)
verifier = cls._create_verifier(deployment_uuid, verification,
tempest_config, system_wide_install)
LOG.info("Starting verification of deployment: %s" % deployment_uuid)
verification.set_running()
verifier.verify(set_name=set_name, regex=regex)
return verification
@staticmethod
def _create_verifier(deployment_uuid, verification=None,
tempest_config=None, system_wide_install=False):
"""Create a Tempest object.
:param deployment_uuid: UUID or name of a deployment
:param verification: Verification object
:param tempest_config: User specified Tempest config file
:param system_wide_install: Use virtualenv else run tests in local
environment
:return: Tempest object
"""
verifier = tempest.Tempest(deployment_uuid, verification=verification,
tempest_config=tempest_config,
system_wide_install=system_wide_install)
@ -274,12 +295,8 @@ class Verification(object):
print("Tempest is not installed for specified deployment.")
print("Installing Tempest for deployment %s" % deployment_uuid)
verifier.install()
LOG.info("Starting verification of deployment: %s" % deployment_uuid)
verification.set_running()
verifier.verify(set_name=set_name, regex=regex)
return verification
return verifier
@classmethod
def install_tempest(cls, deployment, source=None):
@ -326,3 +343,17 @@ class Verification(object):
verifier.install()
if not tempest_config:
shutil.move(tmp_conf_path, verifier.config_file)
@classmethod
def configure_tempest(cls, deployment, tempest_config=None,
override=False):
"""Generate configuration file of Tempest.
:param deployment: UUID or name of a deployment
:param tempest_config: User specified Tempest config file location
:param override: Whether or not override existing Tempest config file
"""
deployment_uuid = objects.Deployment.get(deployment)["uuid"]
verifier = cls._create_verifier(deployment_uuid,
tempest_config=tempest_config)
verifier.generate_config_file(override)

View File

@ -281,3 +281,22 @@ class VerifyCommands(object):
print("Verification UUID: %s" % verification)
db.verification_get(verification)
fileutils.update_globals_file("RALLY_VERIFICATION", verification)
@cliutils.args("--deployment", dest="deployment", type=str,
required=False, help="UUID or name of a deployment")
@cliutils.args("--tempest-config", dest="tempest_config", type=str,
required=False,
help="User specified Tempest config file location")
@cliutils.args("--override", dest="override",
help="Override existing Tempest config file",
required=False, action="store_true")
@envutils.with_default_deployment(cli_arg_name="deployment")
def genconfig(self, deployment=None, tempest_config=None, override=False):
"""Generate configuration file of Tempest.
:param deployment: UUID or name of a deployment
:param tempest_config: User specified Tempest config file location
:param override: Whether or not override existing Tempest config file
"""
api.Verification.configure_tempest(deployment, tempest_config,
override)

View File

@ -218,11 +218,12 @@ class Tempest(object):
def is_configured(self):
return os.path.isfile(self.config_file)
def generate_config_file(self):
"""Generate configuration file of tempest for current deployment."""
def generate_config_file(self, override=False):
"""Generate configuration file of tempest for current deployment.
LOG.debug("Tempest config file: %s " % self.config_file)
if not self.is_configured():
:param override: Whether or not override existing Tempest config file
"""
if not self.is_configured() or override:
msg = _("Creation of configuration file for tempest.")
LOG.info(_("Starting: ") + msg)
@ -231,6 +232,8 @@ class Tempest(object):
else:
LOG.info("Tempest is already configured.")
LOG.info("Tempest config file: %s " % self.config_file)
def _initialize_testr(self):
if not os.path.isdir(self.path(".testrepository")):
print(_("Test Repository initialization."))

View File

@ -318,3 +318,37 @@ class VerifyCommandsTestCase(test.TestCase):
uuid=verification_id)
self.assertRaises(exceptions.NotFoundException, self.verify.use,
verification_id)
@mock.patch("rally.api.Verification.configure_tempest")
def test_genconfig(self, mock_verification_configure_tempest):
deployment_id = "14377d10-ca77-4104-aba8-36edebcfc120"
self.verify.genconfig(deployment_id)
mock_verification_configure_tempest.assert_called_once_with(
deployment_id, None, False)
@mock.patch("rally.api.Verification.configure_tempest")
def test_genconfig_with_config_specified(
self, mock_verification_configure_tempest):
deployment_id = "68b501af-a553-431c-83ac-30f93a112231"
tempest_conf = "/tmp/tempest.conf"
self.verify.genconfig(deployment_id, tempest_config=tempest_conf)
mock_verification_configure_tempest.assert_called_once_with(
deployment_id, tempest_conf, False)
@mock.patch("rally.api.Verification.configure_tempest")
def test_genconfig_override_config(
self, mock_verification_configure_tempest):
deployment_id = "cd5b64ad-c12f-4781-a89e-95535b145a11"
self.verify.genconfig(deployment_id, override=True)
mock_verification_configure_tempest.assert_called_once_with(
deployment_id, None, True)
@mock.patch("rally.api.Verification.configure_tempest")
def test_genconfig_with_config_specified_and_override_config(
self, mock_verification_configure_tempest):
deployment_id = "89982aba-efef-48cb-8d94-ca893b4e78a6"
tempest_conf = "/tmp/tempest.conf"
self.verify.genconfig(deployment_id,
tempest_config=tempest_conf, override=True)
mock_verification_configure_tempest.assert_called_once_with(
deployment_id, tempest_conf, True)

View File

@ -340,3 +340,10 @@ class VerificationAPITestCase(BaseDeploymentTestCase):
mock_copy2.assert_called_once_with(fake_conf, tmp_file)
self.tempest.install.assert_called_once_with()
mock_move.assert_called_once_with(tmp_file, fake_conf)
@mock.patch("rally.common.objects.Deployment.get")
@mock.patch("rally.verification.tempest.tempest.Tempest")
def test_configure_tempest(self, mock_tempest, mock_deployment_get):
mock_tempest.return_value = self.tempest
api.Verification.configure_tempest(self.deployment_uuid)
self.tempest.generate_config_file.assert_called_once_with(False)