Create new json exporter

Now the json format which was exported by `rally task results` is too old,
We expect to use `rally task report --json` instead of it.

New json exporter command:
    rally task report --json --uuid <task_uuid> --out <dest_file>
    rally task export --uuid <task_uuid> --type json --to <dest_file>

Change-Id: Idbb20513ec1013d0f2b7a7458dc8bffef4771e84
This commit is contained in:
chenhb
2017-07-01 13:50:51 +08:00
parent b0532ef454
commit 18f8b77cce
3 changed files with 40 additions and 3 deletions

View File

@@ -39,7 +39,7 @@ _rally()
OPTS["task_export"]="--uuid --type --to"
OPTS["task_import"]="--file --deployment --tag"
OPTS["task_list"]="--deployment --all-deployments --status --tag --uuids-only"
OPTS["task_report"]="--out --open --html --html-static --uuid"
OPTS["task_report"]="--out --open --html --html-static --json --uuid"
OPTS["task_results"]="--uuid"
OPTS["task_sla-check"]="--uuid --json"
OPTS["task_sla_check"]="--uuid --json"
@@ -96,4 +96,4 @@ _rally()
return 0
}
complete -o filenames -F _rally rally
complete -o filenames -F _rally rally

View File

@@ -134,6 +134,8 @@ function run () {
gzip -9 rally-plot/detailed_with_iterations.txt
rally task report --html-static --out rally-plot/results.html
gzip -9 rally-plot/results.html
rally task report --json --out rally-plot/new_results.json
gzip -9 rally-plot/new_results.json
rally task export --type junit-xml --to rally-plot/junit.xml
gzip -9 rally-plot/junit.xml

View File

@@ -91,7 +91,7 @@ class TaskTestCase(unittest.TestCase):
def _get_task_uuid(self, output):
return re.search(
r"\trally task results (?P<uuid>[0-9a-f\-]{36})",
r"\trally task report (?P<uuid>[0-9a-f\-]{36})",
output).group("uuid")
def test_status(self):
@@ -363,6 +363,41 @@ class TaskTestCase(unittest.TestCase):
self.assertTrue(os.path.exists(html_report))
self._assert_html_report_libs_are_embedded(html_report)
def _assert_json_report(self, file_path):
results = json.loads(open(file_path).read())
self.assertIn("info", results)
self.assertIn("tasks", results)
# TODO(chenhb): We will switch to check this
# json via json schema in next patch
for task in results["tasks"]:
self.assertIn("subtasks", task)
for subtask in task["subtasks"]:
self.assertIn("workloads", subtask)
def test_report_one_uuid_with_json(self):
rally = utils.Rally()
cfg = self._get_sample_task_config()
config = utils.TaskConfig(cfg)
rally("task start --task %s" % config.filename)
json_report = rally.gen_report_path(extension="json")
rally("task report --out %s --json" % json_report)
self.assertTrue(os.path.exists(json_report))
self._assert_json_report(json_report)
def test_report_bunch_uuids_with_json(self):
rally = utils.Rally()
cfg = self._get_sample_task_config()
config = utils.TaskConfig(cfg)
task_uuids = []
for i in range(3):
res = rally("task start --task %s" % config.filename)
task_uuids.append(self._get_task_uuid(res))
json_report = rally.gen_report_path(extension="json")
rally("task report --json --uuid %s --out %s"
% (" ".join(task_uuids), json_report))
self.assertTrue(os.path.exists(json_report))
self._assert_json_report(json_report)
def test_trends(self):
cfg1 = {
"Dummy.dummy": [