From 4676b1d4dbd7b6915801292d2d1e103d1bb33a65 Mon Sep 17 00:00:00 2001 From: Yaroslav Lobankov Date: Fri, 18 Sep 2015 15:41:41 +0300 Subject: [PATCH] Adding possibility to generate tempest.conf, not running tempest Rally has not had a command so far that would allow us to generate Tempest config file without starting Tempest tests. This patch adds the separate "genconfig" command that allows us to do it. Now to generate Tempest config file without starting the tests we can execute the following command: $ rally verify genconfig Change-Id: I941769bf47ff2a6fc5ecdaea531cc3fa75a5b342 --- etc/rally.bash_completion | 1 + rally/api.py | 41 ++++++++++++++++++++++---- rally/cli/commands/verify.py | 19 ++++++++++++ rally/verification/tempest/tempest.py | 11 ++++--- tests/unit/cli/commands/test_verify.py | 34 +++++++++++++++++++++ tests/unit/test_api.py | 7 +++++ 6 files changed, 104 insertions(+), 9 deletions(-) diff --git a/etc/rally.bash_completion b/etc/rally.bash_completion index 198c4b1a1d..d5ec501e02 100644 --- a/etc/rally.bash_completion +++ b/etc/rally.bash_completion @@ -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" diff --git a/rally/api.py b/rally/api.py index 007347a49e..3b31bf2cd1 100644 --- a/rally/api.py +++ b/rally/api.py @@ -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) diff --git a/rally/cli/commands/verify.py b/rally/cli/commands/verify.py index 7ce86e201a..b13fd1793e 100644 --- a/rally/cli/commands/verify.py +++ b/rally/cli/commands/verify.py @@ -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) diff --git a/rally/verification/tempest/tempest.py b/rally/verification/tempest/tempest.py index 66d40c5a47..8f872d5cc3 100644 --- a/rally/verification/tempest/tempest.py +++ b/rally/verification/tempest/tempest.py @@ -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.")) diff --git a/tests/unit/cli/commands/test_verify.py b/tests/unit/cli/commands/test_verify.py index 6e9f92989c..088fab2bbe 100644 --- a/tests/unit/cli/commands/test_verify.py +++ b/tests/unit/cli/commands/test_verify.py @@ -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) diff --git a/tests/unit/test_api.py b/tests/unit/test_api.py index 58944d78e3..2c06c250fb 100644 --- a/tests/unit/test_api.py +++ b/tests/unit/test_api.py @@ -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)