[verify] Extend rerun cmd with tag and concurrency args

CLI method rerun should look as similar as `rally verify start`

Change-Id: Iad93e344c8f9d9d27a972ba5b7314788beb91580
This commit is contained in:
Andrey Kurilin 2017-03-15 15:34:39 +02:00
parent 5a465f9057
commit f488f8652c
5 changed files with 33 additions and 14 deletions

View File

@ -55,7 +55,7 @@ _rally()
OPTS["verify_list-verifier-tests"]="--id --pattern" OPTS["verify_list-verifier-tests"]="--id --pattern"
OPTS["verify_list-verifiers"]="--status" OPTS["verify_list-verifiers"]="--status"
OPTS["verify_report"]="--uuid --type --to --open" OPTS["verify_report"]="--uuid --type --to --open"
OPTS["verify_rerun"]="--uuid --deployment-id --failed --detailed --no-use" OPTS["verify_rerun"]="--uuid --deployment-id --failed --tag --concurrency --detailed --no-use"
OPTS["verify_show"]="--uuid --sort-by --detailed" OPTS["verify_show"]="--uuid --sort-by --detailed"
OPTS["verify_show-verifier"]="--id" OPTS["verify_show-verifier"]="--id"
OPTS["verify_start"]="--id --deployment-id --tag --pattern --concurrency --load-list --skip-list --xfail-list --detailed --no-use" OPTS["verify_start"]="--id --deployment-id --tag --pattern --concurrency --load-list --skip-list --xfail-list --detailed --no-use"

View File

@ -879,15 +879,22 @@ class _Verification(object):
return verification, results return verification, results
@classmethod @classmethod
def rerun(cls, verification_uuid, deployment_id=None, failed=False): def rerun(cls, verification_uuid, deployment_id=None, failed=False,
tags=None, concurrency=0):
"""Rerun tests from a verification. """Rerun tests from a verification.
:param verification_uuid: Verification UUID :param verification_uuid: Verification UUID
:param deployment_id: Deployment name or UUID :param deployment_id: Deployment name or UUID
:param failed: Rerun only failed tests :param failed: Rerun only failed tests
:param tags: List of tags to assign them to verification
:param concurrency: The number of processes to use to run verifier
tests
""" """
# TODO(ylobankov): Improve this method in the future: put some # TODO(ylobankov): Improve this method in the future: put some
# information about re-run in run_args. # information about re-run in run_args.
run_args = {}
if concurrency:
run_args["concurrency"] = concurrency
verification = cls.get(verification_uuid) verification = cls.get(verification_uuid)
tests = verification.tests tests = verification.tests
@ -906,8 +913,9 @@ class _Verification(object):
LOG.info("Re-running %stests from verification (UUID=%s) for " LOG.info("Re-running %stests from verification (UUID=%s) for "
"deployment '%s' (UUID=%s).", "failed " if failed else "", "deployment '%s' (UUID=%s).", "failed " if failed else "",
verification.uuid, deployment["name"], deployment["uuid"]) verification.uuid, deployment["name"], deployment["uuid"])
return cls.start(verification.verifier_uuid, deployment["uuid"], return cls.start(
load_list=tests) verification.verifier_uuid, deployment["uuid"], load_list=tests,
tags=tags, **run_args)
@staticmethod @staticmethod
def get(verification_uuid): def get(verification_uuid):

View File

@ -414,8 +414,9 @@ class VerifyCommands(object):
"in case of Tempest you can specify 'set=smoke').") "in case of Tempest you can specify 'set=smoke').")
@cliutils.args("--concurrency", dest="concur", type=int, metavar="<N>", @cliutils.args("--concurrency", dest="concur", type=int, metavar="<N>",
required=False, required=False,
help="How many processes to use to run verifier tests. " help="How many processes to be used for running verifier "
"The default value (0) auto-detects your CPU count.") "tests. The default value (0) auto-detects your CPU "
"count.")
@cliutils.args("--load-list", dest="load_list", type=str, metavar="<path>", @cliutils.args("--load-list", dest="load_list", type=str, metavar="<path>",
required=False, required=False,
help="Path to a file with a list of tests to run.") help="Path to a file with a list of tests to run.")
@ -515,6 +516,13 @@ class VerifyCommands(object):
help="Deployment name or UUID. " + LIST_DEPLOYMENTS_HINT) help="Deployment name or UUID. " + LIST_DEPLOYMENTS_HINT)
@cliutils.args("--failed", dest="failed", required=False, @cliutils.args("--failed", dest="failed", required=False,
help="Rerun only failed tests.", action="store_true") help="Rerun only failed tests.", action="store_true")
@cliutils.args("--tag", nargs="+", dest="tags", type=str, required=False,
help="Mark verification with a tag or a few tags.")
@cliutils.args("--concurrency", dest="concur", type=int, metavar="<N>",
required=False,
help="How many processes to be used for running verifier "
"tests. The default value (0) auto-detects your CPU "
"count.")
@cliutils.args("--detailed", dest="detailed", action="store_true", @cliutils.args("--detailed", dest="detailed", action="store_true",
required=False, required=False,
help="Show verification details such as errors of failed " help="Show verification details such as errors of failed "
@ -525,11 +533,14 @@ class VerifyCommands(object):
@envutils.with_default_verification_uuid @envutils.with_default_verification_uuid
@envutils.with_default_deployment(cli_arg_name="deployment-id") @envutils.with_default_deployment(cli_arg_name="deployment-id")
@plugins.ensure_plugins_are_loaded @plugins.ensure_plugins_are_loaded
def rerun(self, api, verification_uuid=None, deployment=None, def rerun(self, api, verification_uuid=None, deployment=None, tags=None,
failed=False, detailed=False, do_use=True): concur=None, failed=False, detailed=False, do_use=True):
"""Rerun tests from a verification for a specific deployment.""" """Rerun tests from a verification for a specific deployment."""
verification, results = api.verification.rerun(verification_uuid, verification, results = api.verification.rerun(verification_uuid,
deployment, failed) deployment=deployment,
failed=failed,
tags=tags,
concur=concur)
if detailed: if detailed:
self._print_details_after_run(results) self._print_details_after_run(results)

View File

@ -359,9 +359,9 @@ class VerifyCommandsTestCase(test.TestCase):
"failures": 0}) "failures": 0})
self.fake_api.verification.rerun.return_value = (verification, results) self.fake_api.verification.rerun.return_value = (verification, results)
self.verify.rerun(self.fake_api, "v_uuid", "d_id", failed=True) self.verify.rerun(self.fake_api, "v_uuid", "d_id", failed=True,)
self.fake_api.verification.rerun.assert_called_once_with("v_uuid", self.fake_api.verification.rerun.assert_called_once_with(
"d_id", True) "v_uuid", deployment="d_id", failed=True, tags=None, concur=None)
def test_show(self): def test_show(self):
deployment_name = "Some Deploy" deployment_name = "Some Deploy"

View File

@ -1394,7 +1394,7 @@ class VerificationAPITestCase(test.TestCase):
api._Verification.rerun("uuid") api._Verification.rerun("uuid")
mock___verification_start.assert_called_once_with( mock___verification_start.assert_called_once_with(
"v_uuid", "d_uuid", load_list=tests.keys()) "v_uuid", "d_uuid", load_list=tests.keys(), tags=None)
@mock.patch("rally.api._Verification.start") @mock.patch("rally.api._Verification.start")
@mock.patch("rally.api._Deployment.get") @mock.patch("rally.api._Deployment.get")
@ -1414,7 +1414,7 @@ class VerificationAPITestCase(test.TestCase):
api._Verification.rerun("uuid", failed=True) api._Verification.rerun("uuid", failed=True)
expected_tests = [t for t, r in tests.items() if r["status"] == "fail"] expected_tests = [t for t, r in tests.items() if r["status"] == "fail"]
mock___verification_start.assert_called_once_with( mock___verification_start.assert_called_once_with(
"v_uuid", "d_uuid", load_list=expected_tests) "v_uuid", "d_uuid", load_list=expected_tests, tags=None)
@mock.patch("rally.api._Verification.get") @mock.patch("rally.api._Verification.get")
def test_rerun_failed_tests_raise_exc( def test_rerun_failed_tests_raise_exc(