From c2bb13c460566a18e61a3c840bf12f7f717940c2 Mon Sep 17 00:00:00 2001 From: Taseer Date: Thu, 23 Mar 2017 14:26:49 +0500 Subject: Integrate cli, runner and reporter. - Execute runner via a shell command - Change format of qtip result directory to qtip-timestamp - Add path option in reporter to match with runner JIRA: QTIP-229 Change-Id: I7d8562fd7100b1f40cdc8d53b0daa6a06a55b495 Signed-off-by: Taseer Ahmed --- qtip/cli/commands/cmd_metric.py | 10 +++++++--- qtip/cli/commands/cmd_plan.py | 8 ++++++-- qtip/cli/commands/cmd_qpi.py | 8 ++++++-- qtip/cli/commands/cmd_report.py | 5 +++-- qtip/reporter/console.py | 12 +++++------- qtip/runner/runner.py | 2 +- 6 files changed, 28 insertions(+), 17 deletions(-) (limited to 'qtip') diff --git a/qtip/cli/commands/cmd_metric.py b/qtip/cli/commands/cmd_metric.py index 31b7b702..a2208444 100644 --- a/qtip/cli/commands/cmd_metric.py +++ b/qtip/cli/commands/cmd_metric.py @@ -8,6 +8,7 @@ ############################################################################## import click +import os from qtip.cli import utils from qtip.cli.entry import Context @@ -41,8 +42,11 @@ def show(ctx, name): click.echo(output) -@cli.command('run', help='Run tests to run Performance Metrics') +@cli.command('run', help='Run performance test') @click.argument('name') +@click.option('-p', '--path', help='Path to store results') @pass_context -def cmd_run(ctx, name): - pass +def run(ctx, name, path): + runner_path = os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir, + 'runner/runner.py') + os.system('python {0} -b {1} -d {2}'.format(runner_path, name, path)) diff --git a/qtip/cli/commands/cmd_plan.py b/qtip/cli/commands/cmd_plan.py index 90773491..beb61b0e 100644 --- a/qtip/cli/commands/cmd_plan.py +++ b/qtip/cli/commands/cmd_plan.py @@ -9,6 +9,7 @@ import click +import os from qtip.cli import utils from qtip.cli.entry import Context @@ -51,6 +52,9 @@ def show(ctx, name): @cli.command('run', help='Execute a Plan') @click.argument('name') +@click.option('-p', '--path', help='Path to store results') @pass_context -def run(ctx, name): - pass +def run(ctx, name, path): + runner_path = os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir, + 'runner/runner.py') + os.system('python {0} -b all -d {1}'.format(runner_path, path)) diff --git a/qtip/cli/commands/cmd_qpi.py b/qtip/cli/commands/cmd_qpi.py index 1f23211e..1e3671c5 100644 --- a/qtip/cli/commands/cmd_qpi.py +++ b/qtip/cli/commands/cmd_qpi.py @@ -9,6 +9,7 @@ import click +import os from qtip.cli import utils from qtip.cli.entry import Context @@ -44,6 +45,9 @@ def show(ctx, name): @cli.command('run', help='Run performance tests for the specified QPI') @click.argument('name') +@click.option('-p', '--path', help='Path to store results') @pass_context -def run(ctx, name): - pass +def run(ctx, name, path): + runner_path = path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir, + 'runner/runner.py') + os.system('python {0} -b all -d {1}'.format(runner_path, path)) diff --git a/qtip/cli/commands/cmd_report.py b/qtip/cli/commands/cmd_report.py index cb9c70b6..c9f31f4a 100644 --- a/qtip/cli/commands/cmd_report.py +++ b/qtip/cli/commands/cmd_report.py @@ -24,8 +24,9 @@ def cli(ctx): @cli.command('show') @click.argument('metric') +@click.option('-p', '--path', help='Path to result directory') @pass_context -def show(ctx, metric): +def show(ctx, metric, path): reporter = ConsoleReporter({}) - report = reporter.render(metric) + report = reporter.render(metric, path) click.echo(report) diff --git a/qtip/reporter/console.py b/qtip/reporter/console.py index 64d677ba..cb51d9c9 100644 --- a/qtip/reporter/console.py +++ b/qtip/reporter/console.py @@ -28,19 +28,17 @@ class ConsoleReporter(BaseActor): tpl_path = path.join(path.dirname(__file__), 'templates') tpl_loader = FileSystemLoader(tpl_path) self._env = Environment(loader=tpl_loader) - self.result_path = path.join(ROOT_DIR, 'collector') - def load_result(self): - # TODO (taseer) change result directory format more suitable to filter out - result_dirs = glob.glob('{}/20*'.format(self.result_path)) + 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(self.result_path, result_dirs[-1], 'result.json')) as sample: + with open(path.join(result_path, result_dirs[-1], 'result.json')) as sample: result = json.load(sample) return result - def render(self, metric): + def render(self, metric, result_path): template = self._env.get_template('base.j2') - var_dict = self.load_result() + var_dict = self.load_result(result_path) var_dict['metric_name'] = metric out = template.render(var_dict) return out diff --git a/qtip/runner/runner.py b/qtip/runner/runner.py index 8bdbfb78..9b09f0f8 100644 --- a/qtip/runner/runner.py +++ b/qtip/runner/runner.py @@ -93,7 +93,7 @@ def main(args=sys.argv[1:]): logger.info("start_time: {0}".format(start_time)) if not args.dest.endswith('/'): args.dest += '/' - result_dir = args.dest + start_time + result_dir = args.dest + 'qtip-' + start_time ansible_result = run_benchmark(result_dir, args.benchmark) stop_time = time.strftime("%Y-%m-%d-%H-%M") logger.info("stop_time: {0}".format(stop_time)) -- cgit 1.2.3-korg