aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaseer <taseer94@gmail.com>2017-03-13 21:13:45 +0500
committerTaseer <taseer94@gmail.com>2017-03-14 14:23:31 +0500
commitbb5af4b9be1325b61c7f80e71c7d50892ae22956 (patch)
tree236caabf92576f3a4d9708bc03768340782f09e7
parenta5145885c7a43622f803534ed97890ef9acb852d (diff)
Implement 'show' command.
- Render the description via templates JIRA: QTIP-205 Change-Id: I10523f85f80350e901a4a701bb65ca4833f8ff7c Signed-off-by: Taseer Ahmed <taseer94@gmail.com>
-rw-r--r--qtip/cli/commands/cmd_metric.py5
-rw-r--r--qtip/cli/commands/cmd_plan.py5
-rw-r--r--qtip/cli/commands/cmd_qpi.py5
-rw-r--r--qtip/cli/templates/metric.j26
-rw-r--r--qtip/cli/templates/plan.j22
-rw-r--r--qtip/cli/templates/qpi.j212
-rw-r--r--qtip/cli/utils.py13
-rw-r--r--tests/unit/cli/cmd_metric_test.py6
-rw-r--r--tests/unit/cli/cmd_plan_test.py5
-rw-r--r--tests/unit/cli/cmd_qpi_test.py5
10 files changed, 55 insertions, 9 deletions
diff --git a/qtip/cli/commands/cmd_metric.py b/qtip/cli/commands/cmd_metric.py
index e8d86972..31b7b702 100644
--- a/qtip/cli/commands/cmd_metric.py
+++ b/qtip/cli/commands/cmd_metric.py
@@ -35,7 +35,10 @@ def cmd_list(ctx):
@click.argument('name')
@pass_context
def show(ctx, name):
- pass
+ metric = MetricSpec('{}.yaml'.format(name))
+ cnt = metric.content
+ output = utils.render('metric', cnt)
+ click.echo(output)
@cli.command('run', help='Run tests to run Performance Metrics')
diff --git a/qtip/cli/commands/cmd_plan.py b/qtip/cli/commands/cmd_plan.py
index 2f07965d..90773491 100644
--- a/qtip/cli/commands/cmd_plan.py
+++ b/qtip/cli/commands/cmd_plan.py
@@ -43,7 +43,10 @@ def list(ctx):
@click.argument('name')
@pass_context
def show(ctx, name):
- pass
+ plan = Plan('{}.yaml'.format(name))
+ cnt = plan.content
+ output = utils.render('plan', cnt)
+ click.echo(output)
@cli.command('run', help='Execute a Plan')
diff --git a/qtip/cli/commands/cmd_qpi.py b/qtip/cli/commands/cmd_qpi.py
index a12fa983..1f23211e 100644
--- a/qtip/cli/commands/cmd_qpi.py
+++ b/qtip/cli/commands/cmd_qpi.py
@@ -36,7 +36,10 @@ def cmd_list(ctx):
@click.argument('name')
@pass_context
def show(ctx, name):
- pass
+ qpi = QPISpec('{}.yaml'.format(name))
+ cnt = qpi.content
+ output = utils.render('qpi', cnt)
+ click.echo(output)
@cli.command('run', help='Run performance tests for the specified QPI')
diff --git a/qtip/cli/templates/metric.j2 b/qtip/cli/templates/metric.j2
new file mode 100644
index 00000000..126587f9
--- /dev/null
+++ b/qtip/cli/templates/metric.j2
@@ -0,0 +1,6 @@
+Name: {{ name }}
+Description: {{ description }}
+Workloads:
+{% for wl in workloads %}
+ {{ wl }}
+{% endfor %}
diff --git a/qtip/cli/templates/plan.j2 b/qtip/cli/templates/plan.j2
new file mode 100644
index 00000000..c9adccc8
--- /dev/null
+++ b/qtip/cli/templates/plan.j2
@@ -0,0 +1,2 @@
+Name: {{ name }}
+Description: {{ description }}
diff --git a/qtip/cli/templates/qpi.j2 b/qtip/cli/templates/qpi.j2
new file mode 100644
index 00000000..cc85f10d
--- /dev/null
+++ b/qtip/cli/templates/qpi.j2
@@ -0,0 +1,12 @@
+Name: {{ title }}
+Description: {{ description }}
+{% for section in sections %}
+ Name: {{ section.name }}
+ Weight: {{ section.weight }}
+ Formula: {{ section.formula }}
+ Metrics:
+ {% for metric in section.metrics %}
+ {{ metric }}
+ {% endfor %}
+{% endfor %}
+
diff --git a/qtip/cli/utils.py b/qtip/cli/utils.py
index 844d4f34..a7473236 100644
--- a/qtip/cli/utils.py
+++ b/qtip/cli/utils.py
@@ -7,6 +7,9 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+from jinja2 import Environment
+from jinja2 import FileSystemLoader
+from os import path
from prettytable import PrettyTable
@@ -16,3 +19,13 @@ def table(name, components):
table.align[name] = 'l'
[table.add_row([component['name'][0:-5]]) for component in components]
return table
+
+
+def render(name, var_dict):
+ """ Get the templates to render for specific component """
+ tmpl_path = path.join(path.dirname(__file__), 'templates')
+ tmpl_loader = FileSystemLoader(tmpl_path)
+ env = Environment(loader=tmpl_loader)
+ template = env.get_template('{}.j2'.format(name))
+ result = template.render(var_dict)
+ return result
diff --git a/tests/unit/cli/cmd_metric_test.py b/tests/unit/cli/cmd_metric_test.py
index e121fb1e..cd496ad9 100644
--- a/tests/unit/cli/cmd_metric_test.py
+++ b/tests/unit/cli/cmd_metric_test.py
@@ -34,8 +34,10 @@ def test_run(runner):
def test_show(runner):
- result = runner.invoke(cli, ['metric', 'show', 'fake-metric'])
- assert result.output == ''
+ result = runner.invoke(cli, ['metric', 'show', 'dhrystone'])
+ assert 'Name: dhrystone' in result.output
+ assert 'Description: A synthetic computing benchmark program intended to be representative of' \
+ 'system (integer) programming.'
result = runner.invoke(cli, ['metric', 'show'])
assert 'Missing argument "name".' in result.output
diff --git a/tests/unit/cli/cmd_plan_test.py b/tests/unit/cli/cmd_plan_test.py
index 7c3335fc..30025ae0 100644
--- a/tests/unit/cli/cmd_plan_test.py
+++ b/tests/unit/cli/cmd_plan_test.py
@@ -32,8 +32,9 @@ def test_run(runner):
def test_show(runner):
- result = runner.invoke(cli, ['plan', 'show', 'fake-plan'])
- assert result.output == ''
+ result = runner.invoke(cli, ['plan', 'show', 'compute'])
+ assert 'Name: compute QPI' in result.output
+ assert 'Description: compute QPI profile'
result = runner.invoke(cli, ['plan', 'show'])
assert 'Missing argument "name".' in result.output
diff --git a/tests/unit/cli/cmd_qpi_test.py b/tests/unit/cli/cmd_qpi_test.py
index 7067d62c..3d2c2613 100644
--- a/tests/unit/cli/cmd_qpi_test.py
+++ b/tests/unit/cli/cmd_qpi_test.py
@@ -32,8 +32,9 @@ def test_run(runner):
def test_show(runner):
- result = runner.invoke(cli, ['qpi', 'show', 'fake-qpi'])
- assert result.output == ''
+ result = runner.invoke(cli, ['qpi', 'show', 'compute'])
+ assert 'Name: compute' in result.output
+ assert 'Description: sample performance index of computing' in result.output
result = runner.invoke(cli, ['qpi', 'show'])
assert 'Missing argument "name".' in result.output