diff options
-rw-r--r-- | qtip/base/constant.py | 29 | ||||
-rw-r--r-- | qtip/cli/commands/cmd_metric.py | 3 | ||||
-rw-r--r-- | qtip/cli/commands/cmd_plan.py | 45 | ||||
-rw-r--r-- | qtip/loader/base.py | 15 | ||||
-rw-r--r-- | qtip/loader/plan.py | 5 | ||||
-rw-r--r-- | qtip/loader/qpi.py | 14 | ||||
-rw-r--r-- | qtip/runner/__init__.py | 10 | ||||
-rw-r--r-- | tests/unit/cli/test_metric.py | 9 | ||||
-rw-r--r-- | tests/unit/cli/test_plan.py | 31 | ||||
-rw-r--r-- | tests/unit/loader/metric_test.py | 18 | ||||
-rw-r--r-- | tests/unit/loader/plan_test.py | 18 | ||||
-rw-r--r-- | tests/unit/loader/qpi_test.py | 22 |
12 files changed, 140 insertions, 79 deletions
diff --git a/qtip/base/constant.py b/qtip/base/constant.py index 76481b47..58cc0cc1 100644 --- a/qtip/base/constant.py +++ b/qtip/base/constant.py @@ -25,26 +25,49 @@ class PkgName(object): SPEC = 'spec' -class PropName(object): +class BaseProp(object): """property names""" # list NAME = 'name' CONTENT = 'content' ABSPATH = 'abspath' + # content - name = 'name' DESCRIPTION = 'description' + + +class SpecProp(BaseProp): # spec SECTIONS = 'sections' WEIGHT = 'weight' FORMULA = 'formula' METRICS = 'metrics' WORKLOADS = 'workloads' + + +class PlanProp(BaseProp): # plan - CONFIG = 'config' + INFO = 'info' + FACILITY = 'facility' ENGINEER = 'engineer' + + CONFIG = 'config' + DRIVER = 'driver' COLLECTOR = 'collector' REPORTER = 'reporter' + QPIS = 'QPIs' + + +class CollectorProp(BaseProp): + LOGS = 'logs' + FILENAME = 'filename' + PATTERNS = 'patterns' + MATCH = 'match' + CAPTURE = 'capture' + + +class ReporterBaseProp(BaseProp): + TRANSFORMER = 'transformer' diff --git a/qtip/cli/commands/cmd_metric.py b/qtip/cli/commands/cmd_metric.py index 7f5c18d3..d2fbd58f 100644 --- a/qtip/cli/commands/cmd_metric.py +++ b/qtip/cli/commands/cmd_metric.py @@ -28,6 +28,7 @@ def cmd_list(ctx): @cli.command('run', help='Run tests to collect Performance Metrics') +@click.argument('name') @pass_context -def cmd_run(ctx): +def cmd_run(ctx, name): pass diff --git a/qtip/cli/commands/cmd_plan.py b/qtip/cli/commands/cmd_plan.py index 6f622e5a..0c0a3c12 100644 --- a/qtip/cli/commands/cmd_plan.py +++ b/qtip/cli/commands/cmd_plan.py @@ -1,4 +1,4 @@ -############################################################################# +############################################################################## # Copyright (c) 2016 ZTE Corp and others. # # All rights reserved. This program and the accompanying materials @@ -7,38 +7,39 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## + import click -from prettytable import PrettyTable -from qtip.loader.plan import Plan +from qtip.cli.entry import Context + + +pass_context = click.make_pass_decorator(Context, ensure=False) @click.group() -def cli(): +@pass_context +def cli(ctx): + ''' Bechmarking Plan ''' pass -@cli.group() -def plan_cmd(): +@cli.command('init', help='Initialize Environment') +@click.option('--inst_type', prompt='Installer Type') +@click.option('--inst_ip', prompt='Installer IP') +@click.option('--ext_net', prompt='Openstack External Network') +@pass_context +def init(ctx, inst_type, inst_ip, ext_net): pass -@plan_cmd.command('list', help='List the different TestPlans.') -def list_all(): - plans = Plan.list_all() - table = PrettyTable(["Testplans"]) - table.align = 'l' - for plan in plans: - table.add_row([plan['name']]) - click.echo(table) +@cli.command('list', help='List the Plans') +@pass_context +def list(ctx): + pass -@plan_cmd.command('show', help='Show details of specified TestPlan.') +@cli.command('run', help='Execute a Plan') @click.argument('name') -def show(name): - plan = Plan(name) - results = plan.content() - table = PrettyTable(["Name", "Description"]) - table.align = 'l' - table.add_row([results['name'], results['description']]) - click.echo(table) +@pass_context +def run(ctx, name): + pass diff --git a/qtip/loader/base.py b/qtip/loader/base.py index d3a7e1d3..a0e5d031 100644 --- a/qtip/loader/base.py +++ b/qtip/loader/base.py @@ -7,13 +7,14 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from collections import defaultdict from itertools import chain from os import listdir from os import path import yaml from qtip.base.error import InvalidFormat, NotFound -from qtip.base.constant import PropName +from qtip.base.constant import BaseProp ROOT_DIR = path.join(path.dirname(__file__), path.pardir, path.pardir, @@ -28,15 +29,15 @@ class BaseLoader(object): def __init__(self, name, paths=None): self._file = name self._abspath = self._find(name, paths=paths) + content = defaultdict(lambda: None) try: - content = yaml.safe_load(file(self._abspath)) + content.update(yaml.safe_load(file(self._abspath))) except yaml.YAMLError: # TODO(yujunz) log yaml error raise InvalidFormat(self._abspath) - self.name = content[PropName.NAME] if PropName.NAME in content \ - else path.splitext(name)[0] + self.name = content[BaseProp.NAME] or path.splitext(name)[0] self.content = content def _find(self, name, paths=None): @@ -57,6 +58,6 @@ class BaseLoader(object): for name in names: item = cls(name, paths=paths) yield { - PropName.NAME: name, - PropName.ABSPATH: item._abspath, - PropName.CONTENT: item.content} + BaseProp.NAME: name, + BaseProp.ABSPATH: item._abspath, + BaseProp.CONTENT: item.content} diff --git a/qtip/loader/plan.py b/qtip/loader/plan.py index cf517ea2..c1ee00be 100644 --- a/qtip/loader/plan.py +++ b/qtip/loader/plan.py @@ -8,7 +8,7 @@ ############################################################################## -from qtip.base.constant import PropName +from qtip.base.constant import PlanProp from qtip.loader.base import BaseLoader from qtip.loader.qpi import QPISpec @@ -24,4 +24,5 @@ class Plan(BaseLoader): super(Plan, self).__init__(name, paths) self.qpis = [QPISpec(qpi, paths=paths) - for qpi in self.content[PropName.QPIS]] + for qpi in self.content[PlanProp.QPIS]] + self.info = self.content[PlanProp.INFO] diff --git a/qtip/loader/qpi.py b/qtip/loader/qpi.py index fe2323dd..ef6e065e 100644 --- a/qtip/loader/qpi.py +++ b/qtip/loader/qpi.py @@ -10,7 +10,7 @@ from base import BaseLoader from metric import MetricSpec -from qtip.base.constant import PropName +from qtip.base.constant import SpecProp from qtip.util.formula import Formula @@ -24,15 +24,15 @@ class QPISpec(BaseLoader): def __init__(self, name, paths=None): super(QPISpec, self).__init__(name, paths=paths) content = self.content - self.formula = Formula(content[PropName.FORMULA]) + self.formula = Formula(content[SpecProp.FORMULA]) self.sections = [Section(record, paths=paths) - for record in content[PropName.SECTIONS]] + for record in content[SpecProp.SECTIONS]] class Section(object): def __init__(self, content, paths=None): - self.name = content[PropName.NAME] - self.weight = content[PropName.WEIGHT] - self.formula = Formula(content[PropName.FORMULA]) + self.name = content[SpecProp.NAME] + self.weight = content[SpecProp.WEIGHT] + self.formula = Formula(content[SpecProp.FORMULA]) self.metrics = [MetricSpec(record, paths=paths) - for record in content[PropName.METRICS]] + for record in content[SpecProp.METRICS]] diff --git a/qtip/runner/__init__.py b/qtip/runner/__init__.py index eab81156..1db8498e 100644 --- a/qtip/runner/__init__.py +++ b/qtip/runner/__init__.py @@ -7,7 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -from qtip.base.constant import PkgName, PropName +from qtip.base.constant import PkgName, BaseProp from qtip.base.error import NotFound from qtip.collector.stdout import StdoutCollector from qtip.driver.random import RandomDriver @@ -17,11 +17,11 @@ from qtip.reporter.console import ConsoleReporter class Runner(object): def __init__(self, spec, config=None): if config is None: - config = spec[PropName.CONFIG] + config = spec[BaseProp.CONFIG] - driver_name = config[PropName.DRIVER] - collector_name = config[PropName.COLLECTOR] - reporter_name = config[PropName.REPORTER] + driver_name = config[BaseProp.DRIVER] + collector_name = config[BaseProp.COLLECTOR] + reporter_name = config[BaseProp.REPORTER] # TODO(yujunz) dynamically load modules by name diff --git a/tests/unit/cli/test_metric.py b/tests/unit/cli/test_metric.py index ed10689c..239da96e 100644 --- a/tests/unit/cli/test_metric.py +++ b/tests/unit/cli/test_metric.py @@ -10,7 +10,7 @@ import pytest from click.testing import CliRunner -from qtip.cli.commands.cmd_metric import cli +from qtip.cli.entry import cli @pytest.fixture() @@ -19,10 +19,13 @@ def runner(): def test_list(runner): - result = runner.invoke(cli, ['list']) + result = runner.invoke(cli, ['metric', 'list']) assert result.output == '' def test_run(runner): - result = runner.invoke(cli, ['run']) + result = runner.invoke(cli, ['metric', 'run', 'fake-metric']) assert result.output == '' + + result = runner.invoke(cli, ['metric', 'run']) + assert 'Missing argument "name".' in result.output diff --git a/tests/unit/cli/test_plan.py b/tests/unit/cli/test_plan.py new file mode 100644 index 00000000..3ce3766e --- /dev/null +++ b/tests/unit/cli/test_plan.py @@ -0,0 +1,31 @@ +############################################################### +# Copyright (c) 2016 ZTE Corp and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import pytest +from click.testing import CliRunner + +from qtip.cli.entry import cli + + +@pytest.fixture() +def runner(): + return CliRunner() + + +def test_list(runner): + result = runner.invoke(cli, ['plan', 'list']) + assert result.output == '' + + +def test_run(runner): + result = runner.invoke(cli, ['plan', 'run', 'fake-plan']) + assert result.output == '' + + result = runner.invoke(cli, ['plan', 'run']) + assert 'Missing argument "name".' in result.output diff --git a/tests/unit/loader/metric_test.py b/tests/unit/loader/metric_test.py index d2be0388..91d0dd2c 100644 --- a/tests/unit/loader/metric_test.py +++ b/tests/unit/loader/metric_test.py @@ -9,7 +9,7 @@ import pytest -from qtip.base.constant import PropName +from qtip.base.constant import BaseProp from qtip.loader.metric import MetricSpec @@ -31,15 +31,15 @@ def list_all_test(): metric_list = MetricSpec.list_all() assert len(list(metric_list)) is 6 for desc in metric_list: - assert PropName.NAME in desc - assert PropName.DESCRIPTION in desc - assert PropName.ABSPATH in desc - assert PropName.ABSPATH is not None + assert BaseProp.NAME in desc + assert BaseProp.DESCRIPTION in desc + assert BaseProp.ABSPATH in desc + assert BaseProp.ABSPATH is not None def content_test(metric): content = metric.content - assert PropName.NAME in content - assert PropName.DESCRIPTION in content - assert PropName.WORKLOADS in content - assert isinstance(content[PropName.WORKLOADS], list) + assert BaseProp.NAME in content + assert BaseProp.DESCRIPTION in content + assert BaseProp.WORKLOADS in content + assert isinstance(content[BaseProp.WORKLOADS], list) diff --git a/tests/unit/loader/plan_test.py b/tests/unit/loader/plan_test.py index 6aab5e8a..b57bcfb5 100644 --- a/tests/unit/loader/plan_test.py +++ b/tests/unit/loader/plan_test.py @@ -9,7 +9,7 @@ import pytest -from qtip.base.constant import PropName +from qtip.base.constant import PlanProp from qtip.loader.plan import Plan, QPISpec @@ -29,15 +29,15 @@ def test_list_all(benchmarks_root): plan_list = Plan.list_all(paths=[benchmarks_root]) assert len(list(plan_list)) is 1 for desc in plan_list: - assert PropName.NAME in desc - assert PropName.CONTENT in desc - assert PropName.ABSPATH in desc - assert PropName.ABSPATH is not None + assert PlanProp.NAME in desc + assert PlanProp.CONTENT in desc + assert PlanProp.ABSPATH in desc + assert PlanProp.ABSPATH is not None def test_content(plan): content = plan.content - assert PropName.NAME in content - assert PropName.DESCRIPTION in content - assert PropName.CONFIG in content - assert PropName.QPIS in content + assert PlanProp.NAME in content + assert PlanProp.DESCRIPTION in content + assert PlanProp.CONFIG in content + assert PlanProp.QPIS in content diff --git a/tests/unit/loader/qpi_test.py b/tests/unit/loader/qpi_test.py index 4b3fd4d0..3328b43a 100644 --- a/tests/unit/loader/qpi_test.py +++ b/tests/unit/loader/qpi_test.py @@ -9,7 +9,7 @@ import pytest -from qtip.base.constant import FormulaName, PropName +from qtip.base.constant import FormulaName, SpecProp from qtip.loader.qpi import QPISpec QPI_SPEC = 'compute.yaml' @@ -33,20 +33,20 @@ def test_list_all(benchmarks_root): qpi_spec_list = QPISpec.list_all(paths=[benchmarks_root]) assert len(list(qpi_spec_list)) is 2 for item in qpi_spec_list: - assert PropName.NAME in item - assert PropName.CONTENT in item - assert PropName.ABSPATH in item - assert PropName.ABSPATH is not None + assert SpecProp.NAME in item + assert SpecProp.CONTENT in item + assert SpecProp.ABSPATH in item + assert SpecProp.ABSPATH is not None def test_content(qpi_spec): content = qpi_spec.content - assert PropName.DESCRIPTION in content - assert PropName.FORMULA in content - assert PropName.SECTIONS in content + assert SpecProp.DESCRIPTION in content + assert SpecProp.FORMULA in content + assert SpecProp.SECTIONS in content - assert content[PropName.FORMULA] in FormulaName.__dict__.values() - sections = content[PropName.SECTIONS] + assert content[SpecProp.FORMULA] in FormulaName.__dict__.values() + sections = content[SpecProp.SECTIONS] assert isinstance(sections, list) for section in sections: - assert PropName.NAME in section + assert SpecProp.NAME in section |