Add ability to report tasks by deployment
Add ability to rally task export/report cmd to export/report all tasks with specified deployment by new arg --deployment. Change-Id: I8d7b41e0d2bb3f922f6bd0411aba405e942691fc
This commit is contained in:
parent
4ddf0bdb71
commit
910478f808
|
@ -17,6 +17,16 @@ Changelog
|
|||
.. Release notes for existing releases are MUTABLE! If there is something that
|
||||
was missed or can be improved, feel free to change it!
|
||||
|
||||
Unreleased
|
||||
----------
|
||||
|
||||
Changed
|
||||
~~~~~~~
|
||||
|
||||
* Add the --deployment option to commands ``rally task report`` and
|
||||
``rally task export`` that allows to report/export all tasks from defined
|
||||
deployment.
|
||||
|
||||
[1.2.1] - 2018-09-27
|
||||
--------------------
|
||||
|
||||
|
|
|
@ -46,10 +46,10 @@ _rally()
|
|||
OPTS["task_abort"]="--uuid --soft"
|
||||
OPTS["task_delete"]="--force --uuid"
|
||||
OPTS["task_detailed"]="--uuid --iterations-data --filter-by"
|
||||
OPTS["task_export"]="--uuid --type --to"
|
||||
OPTS["task_export"]="--uuid --type --to --deployment"
|
||||
OPTS["task_import"]="--file --deployment --tag"
|
||||
OPTS["task_list"]="--deployment --all-deployments --status --tag --uuids-only"
|
||||
OPTS["task_report"]="--out --open --html --html-static --json --uuid"
|
||||
OPTS["task_report"]="--out --open --html --html-static --json --uuid --deployment"
|
||||
OPTS["task_results"]="--uuid"
|
||||
OPTS["task_sla-check"]="--uuid --json"
|
||||
OPTS["task_sla_check"]="--uuid --json"
|
||||
|
|
|
@ -878,15 +878,19 @@ class TaskCommands(object):
|
|||
"--type junit-xml"))
|
||||
@cliutils.args("--uuid", dest="tasks", nargs="+", type=str,
|
||||
help="UUIDs of tasks or json reports of tasks")
|
||||
@cliutils.args("--deployment", dest="deployment", type=str,
|
||||
help="Report all tasks with defined deployment",
|
||||
required=False)
|
||||
@envutils.default_from_global("tasks", envutils.ENV_TASK, "uuid")
|
||||
@cliutils.suppress_warnings
|
||||
def report(self, api, tasks=None, out=None,
|
||||
open_it=False, out_format="html"):
|
||||
open_it=False, out_format="html", deployment=None):
|
||||
"""Generate a report for the specified task(s)."""
|
||||
self.export(api, tasks=tasks,
|
||||
output_type=out_format,
|
||||
output_dest=out,
|
||||
open_it=open_it)
|
||||
open_it=open_it,
|
||||
deployment=deployment)
|
||||
|
||||
@cliutils.args("--force", action="store_true", help="force delete")
|
||||
@cliutils.args("--uuid", type=str, dest="task_id", nargs="*",
|
||||
|
@ -979,12 +983,20 @@ class TaskCommands(object):
|
|||
"types) to save the report to or a connection string."
|
||||
" It depends on the report type."
|
||||
)
|
||||
@cliutils.args("--deployment", dest="deployment", type=str,
|
||||
help="Report all tasks with defined deployment",
|
||||
required=False)
|
||||
@envutils.default_from_global("tasks", envutils.ENV_TASK, "uuid")
|
||||
@plugins.ensure_plugins_are_loaded
|
||||
def export(self, api, tasks=None, output_type=None, output_dest=None,
|
||||
open_it=False):
|
||||
open_it=False, deployment=None):
|
||||
"""Export task results to the custom task's exporting system."""
|
||||
tasks = isinstance(tasks, list) and tasks or [tasks]
|
||||
|
||||
if deployment is not None:
|
||||
tasks = api.task.list(deployment=deployment, uuids_only=True)
|
||||
tasks = [task["uuid"] for task in tasks]
|
||||
else:
|
||||
tasks = isinstance(tasks, list) and tasks or [tasks]
|
||||
|
||||
exported_tasks = []
|
||||
for task_file_or_uuid in tasks:
|
||||
|
|
|
@ -287,7 +287,7 @@ def task_update_status(session, uuid, status, allowed_statuses):
|
|||
|
||||
|
||||
@with_session
|
||||
def task_list(session, status=None, env=None, tags=None):
|
||||
def task_list(session, status=None, env=None, tags=None, uuids_only=False):
|
||||
tasks = []
|
||||
query = session.query(models.Task)
|
||||
|
||||
|
@ -305,9 +305,13 @@ def task_list(session, status=None, env=None, tags=None):
|
|||
return []
|
||||
query = query.filter(models.Task.uuid.in_(uuids))
|
||||
|
||||
if uuids_only:
|
||||
query = query.options(sa.orm.load_only("uuid"))
|
||||
|
||||
for task in query.all():
|
||||
task = task.as_dict()
|
||||
task["tags"] = sorted(tags_get(task["uuid"], consts.TagType.TASK))
|
||||
if not uuids_only:
|
||||
task["tags"] = sorted(tags_get(task["uuid"], consts.TagType.TASK))
|
||||
tasks.append(task)
|
||||
|
||||
return tasks
|
||||
|
|
|
@ -324,11 +324,12 @@ class Task(object):
|
|||
|
||||
def to_dict(self):
|
||||
db_task = self.task
|
||||
env_name = db.env_get(self.task["env_uuid"])["name"]
|
||||
db_task["env_name"] = env_name
|
||||
db_task["deployment_name"] = env_name
|
||||
db_task["deployment_uuid"] = db_task["env_uuid"]
|
||||
self._serialize_dt(db_task)
|
||||
if self.task.get("env_uuid"):
|
||||
env_name = db.env_get(self.task["env_uuid"])["name"]
|
||||
db_task["env_name"] = env_name
|
||||
db_task["deployment_name"] = env_name
|
||||
db_task["deployment_uuid"] = db_task["env_uuid"]
|
||||
self._serialize_dt(db_task)
|
||||
for subtask in db_task.get("subtasks", []):
|
||||
self._serialize_dt(subtask)
|
||||
for workload in subtask["workloads"]:
|
||||
|
@ -344,9 +345,9 @@ class Task(object):
|
|||
return db.task_get_status(uuid)
|
||||
|
||||
@staticmethod
|
||||
def list(status=None, deployment=None, tags=None):
|
||||
def list(status=None, deployment=None, tags=None, uuids_only=False):
|
||||
return [Task(db_task) for db_task in db.task_list(
|
||||
status, env=deployment, tags=tags)]
|
||||
status, env=deployment, tags=tags, uuids_only=False)]
|
||||
|
||||
@staticmethod
|
||||
def delete_by_uuid(uuid, status=None):
|
||||
|
|
|
@ -732,7 +732,7 @@ class TaskCommandsTestCase(test.TestCase):
|
|||
out="out", open_it=False, out_format="junit-xml")
|
||||
self.task.export.assert_called_once_with(
|
||||
self.fake_api, tasks="uuid", output_type="junit-xml",
|
||||
output_dest="out", open_it=False
|
||||
output_dest="out", open_it=False, deployment=None
|
||||
)
|
||||
|
||||
@mock.patch("rally.cli.commands.task.cliutils.print_list")
|
||||
|
|
Loading…
Reference in New Issue