diff options
Diffstat (limited to 'qtip')
-rw-r--r-- | qtip/cli/commands/cmd_report.py | 47 | ||||
-rw-r--r-- | qtip/reporter/console.py | 32 |
2 files changed, 48 insertions, 31 deletions
diff --git a/qtip/cli/commands/cmd_report.py b/qtip/cli/commands/cmd_report.py index 4176fd90..1a58aa60 100644 --- a/qtip/cli/commands/cmd_report.py +++ b/qtip/cli/commands/cmd_report.py @@ -7,11 +7,42 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from asq.initiators import query import click +from prettytable import PrettyTable from qtip.reporter.console import ConsoleReporter +def extract_section(sections, section_name, node): + """ Extract information related to QPI """ + qpi = query(sections).where(lambda child: child['name'] == node) \ + .select_many(lambda child: child['sections']) \ + .where(lambda child: child['name'] == section_name) \ + .first() + return qpi + + +def display_report(report, section_name, node): + table_workload = PrettyTable(['Workload', 'Description', + 'Result', 'Score']) + table_workload.align = 'l' + + section_report = extract_section(report['nodes'], section_name, node) + + for metric in section_report['metrics']: + for wl in metric['workloads']: + table_workload.add_row([wl['name'], + wl['description'], + wl['result'], + wl['score']]) + return { + "ss": section_report['score'], + "desc": section_report['description'], + "table": table_workload + } + + @click.group() def cli(): """ View QTIP results""" @@ -19,9 +50,13 @@ def cli(): @cli.command('show') -@click.argument('metric') -@click.option('-p', '--path', help='Path to result directory') -def show(metric, path): - reporter = ConsoleReporter({}) - report = reporter.render(metric, path) - click.echo(report) +@click.option('-n', '--node', help="Compute node in OPNFV cluster") +@click.argument('section-name') +def show(node, section_name): + qpi = ConsoleReporter.load_result() + result = display_report(qpi, section_name, node) + + click.echo("Node Score: {}".format(qpi['score'])) + click.echo("Section Score: {}".format(result['ss'])) + click.echo("Description: {}".format(result['desc'])) + click.echo(result['table']) diff --git a/qtip/reporter/console.py b/qtip/reporter/console.py index da04930f..9aaa5f78 100644 --- a/qtip/reporter/console.py +++ b/qtip/reporter/console.py @@ -7,14 +7,12 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import glob import json +import os from os import path -from jinja2 import Environment -from jinja2 import FileSystemLoader from qtip.base import BaseActor -from qtip.reporter import filters + ROOT_DIR = path.join(path.dirname(__file__), path.pardir, path.pardir) @@ -22,25 +20,9 @@ ROOT_DIR = path.join(path.dirname(__file__), path.pardir, path.pardir) class ConsoleReporter(BaseActor): """ report benchmark result to console """ - def __init__(self, config, parent=None): - super(ConsoleReporter, self).__init__(config, parent=parent) - - # TODO (taseer) load template from config - tpl_path = path.join(path.dirname(__file__), 'templates') - tpl_loader = FileSystemLoader(tpl_path) - self._env = Environment(loader=tpl_loader) - self._env.filters['justify'] = filters.justify - - def load_result(self, result_path): - result_dirs = glob.glob('{}/qtip-*'.format(result_path)) - # select the last (latest) directory for rendering report, result_dirs[-1] - with open(path.join(result_path, result_dirs[-1], 'result.json')) as sample: - result = json.load(sample) + @staticmethod + def load_result(): + result_path = path.join(os.getcwd(), 'results', 'current', 'qpi.json') + with open(result_path) as qpi: + result = json.load(qpi) return result - - def render(self, metric, result_path): - template = self._env.get_template('base.j2') - var_dict = self.load_result(result_path) - var_dict['metric_name'] = metric - out = template.render(var_dict) - return out |