diff options
Diffstat (limited to 'qtip')
-rw-r--r-- | qtip/api/__main__.py | 9 | ||||
-rw-r--r-- | qtip/api/controllers/common.py | 15 | ||||
-rw-r--r-- | qtip/api/controllers/metric.py | 13 | ||||
-rw-r--r-- | qtip/api/controllers/plan.py | 25 | ||||
-rw-r--r-- | qtip/api/controllers/qpi.py | 21 | ||||
-rw-r--r-- | qtip/api/swagger/swagger.yaml | 64 | ||||
-rw-r--r-- | qtip/cli/commands/cmd_metric.py | 10 | ||||
-rw-r--r-- | qtip/cli/commands/cmd_plan.py | 8 | ||||
-rw-r--r-- | qtip/cli/commands/cmd_qpi.py | 8 | ||||
-rw-r--r-- | qtip/cli/commands/cmd_report.py | 5 | ||||
-rw-r--r-- | qtip/collector/parser/regex.yaml | 4 | ||||
-rw-r--r-- | qtip/reporter/console.py | 12 | ||||
-rw-r--r-- | qtip/runner/runner.py | 2 |
13 files changed, 88 insertions, 108 deletions
diff --git a/qtip/api/__main__.py b/qtip/api/__main__.py index 05d92315..381622af 100644 --- a/qtip/api/__main__.py +++ b/qtip/api/__main__.py @@ -14,9 +14,14 @@ import os swagger_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'swagger/')) -def main(): +def get_app(): app = connexion.App(__name__, specification_dir=swagger_dir) - app.add_api('swagger.yaml', base_path='/v1.0') + app.add_api('swagger.yaml', base_path='/v1.0', strict_validation=True) + return app + + +def main(): + app = get_app() app.run(host="0.0.0.0", port=5000) diff --git a/qtip/api/controllers/common.py b/qtip/api/controllers/common.py index eeae0fee..6ddab7a9 100644 --- a/qtip/api/controllers/common.py +++ b/qtip/api/controllers/common.py @@ -14,15 +14,22 @@ import connexion from qtip.base import error -def get_one_exceptions(resource): +def check_endpoint_for_error(resource, operation=None): def _decorator(func): - def _execute(name): + def _execute(name=None): try: return func(name), httplib.OK except error.NotFoundError: return connexion.problem( httplib.NOT_FOUND, - '{} Not Found'.format(resource), - 'Requested {} `{}` not found.'.format(resource, name)) + '{} not found'.format(resource), + 'Requested {} `{}` not found.' + .format(resource.lower(), name)) + except error.ToBeDoneError: + return connexion.problem( + httplib.NOT_IMPLEMENTED, + '{} handler not implemented'.format(operation), + 'Requested operation `{}` on {} not implemented.' + .format(operation.lower(), resource.lower())) return _execute return _decorator diff --git a/qtip/api/controllers/metric.py b/qtip/api/controllers/metric.py index dd4c8ac6..96cd985c 100644 --- a/qtip/api/controllers/metric.py +++ b/qtip/api/controllers/metric.py @@ -14,13 +14,12 @@ from qtip.loader import metric def list_metrics(): - metric_list = list(metric.MetricSpec.list_all()) - return metric_list, httplib.OK + metrics = list(metric.MetricSpec.list_all()) + metrics_by_name = [m['name'] for m in metrics] + return {'metrics': metrics_by_name}, httplib.OK -@common.get_one_exceptions(resource='metric') +@common.check_endpoint_for_error(resource='Metric') def get_metric(name): - metric_spec = metric.MetricSpec(name) - return {'name': metric_spec.name, - 'abspath': metric_spec.abspath, - 'content': metric_spec.content} + metric_spec = metric.MetricSpec(name) + return metric_spec.content diff --git a/qtip/api/controllers/plan.py b/qtip/api/controllers/plan.py index 93836a32..00593878 100644 --- a/qtip/api/controllers/plan.py +++ b/qtip/api/controllers/plan.py @@ -9,30 +9,23 @@ import httplib -import connexion - +from qtip.api.controllers import common from qtip.base import error from qtip.loader import plan def list_plans(): - plan_list = list(plan.Plan.list_all()) - return plan_list, httplib.OK + plans = list(plan.Plan.list_all()) + plans_by_name = [p['name'] for p in plans] + return {'plans': plans_by_name}, httplib.OK +@common.check_endpoint_for_error(resource='Plan') def get_plan(name): - try: - plan_spec = plan.Plan(name) - return {'name': plan_spec.name, - 'abspath': plan_spec.abspath, - 'content': plan_spec.content}, httplib.OK - except error.NotFoundError: - return connexion.problem(httplib.NOT_FOUND, - 'Plan Not Found', - 'requested plan `' + name + '` not found.') + plan_spec = plan.Plan(name) + return plan_spec.content +@common.check_endpoint_for_error(resource='Plan', operation='Run') def run_plan(name, action="run"): - return connexion.problem(httplib.NOT_IMPLEMENTED, - 'Run a plan', - 'Plan runner not implemented') + raise error.ToBeDoneError('run_plan', 'plan') diff --git a/qtip/api/controllers/qpi.py b/qtip/api/controllers/qpi.py index 3c4dd718..af08a824 100644 --- a/qtip/api/controllers/qpi.py +++ b/qtip/api/controllers/qpi.py @@ -9,24 +9,17 @@ import httplib -import connexion - -from qtip.base import error +from qtip.api.controllers import common from qtip.loader import qpi def list_qpis(): - qpi_spec_list = list(qpi.QPISpec.list_all()) - return qpi_spec_list, httplib.OK + qpi_specs = list(qpi.QPISpec.list_all()) + qpis_by_name = [q['name'] for q in qpi_specs] + return {'qpis': qpis_by_name}, httplib.OK +@common.check_endpoint_for_error(resource='QPI') def get_qpi(name): - try: - qpi_spec = qpi.QPISpec(name) - return {'name': qpi_spec.name, - 'abspath': qpi_spec.abspath, - 'content': qpi_spec.content}, httplib.OK - except error.NotFoundError: - return connexion.problem(httplib.NOT_FOUND, - 'QPI Not Found', - 'Requested QPI Spec `' + name + '` not found.') + qpi_spec = qpi.QPISpec(name) + return qpi_spec.content diff --git a/qtip/api/swagger/swagger.yaml b/qtip/api/swagger/swagger.yaml index c2de2d68..51c3ebb8 100644 --- a/qtip/api/swagger/swagger.yaml +++ b/qtip/api/swagger/swagger.yaml @@ -212,7 +212,7 @@ paths: schema: $ref: '#/definitions/Error' definitions: - PlanContent: + Plan: type: object required: - name @@ -232,23 +232,13 @@ definitions: Plans: type: object required: - - name - - abspath + - plans properties: - name: - type: string - abspath: - type: string - Plan: - allOf: - - $ref: '#/definitions/Plans' - - type: object - - required: - - content - properties: - content: - $ref: '#/definitions/PlanContent' - MetricContent: + plans: + type: array + items: + type: string + Metric: type: object required: - name @@ -268,22 +258,13 @@ definitions: Metrics: type: object required: - - name - - abspath + - metrics properties: - name: - type: string - abspath: - type: string - Metric: - allOf: - - $ref: '#/definitions/Metrics' - - required: - - content - properties: - content: - $ref: '#/definitions/MetricContent' - QPIContent: + metrics: + type: array + items: + type: string + QPI: type: object required: - name @@ -301,21 +282,12 @@ definitions: QPIs: type: object required: - - name - - abspath + - qpis properties: - name: - type: string - abspath: - type: string - QPI: - allOf: - - $ref: '#/definitions/QPIs' - - required: - - content - properties: - content: - $ref: '#/definitions/QPIContent' + qpis: + type: array + items: + type: string Error: type: object properties: 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/collector/parser/regex.yaml b/qtip/collector/parser/regex.yaml index 397f8973..94271136 100644 --- a/qtip/collector/parser/regex.yaml +++ b/qtip/collector/parser/regex.yaml @@ -25,8 +25,8 @@ dpi: - filename: dpi_dump.txt grep: - |- - ^\s+nDPI throughput:.+?(?P<pps>\d+.\d+)\sM\spps.+ - ?(?P<bps>\d+.\d+)\sGb\/sec + ^\s+nDPI throughput:.+?(?P<pps>\d+.\d+)\s.+\spps.+ + ?(?P<bps>\d+.\d+)\s.+\/sec ramspeed: - filename: Intmem grep: 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)) |