aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qtip/base/error.py2
-rw-r--r--qtip/cli/commands/cmd_metric.py17
-rw-r--r--qtip/cli/commands/cmd_plan.py17
-rw-r--r--qtip/cli/commands/cmd_qpi.py17
-rw-r--r--requirements.txt1
-rw-r--r--tests/unit/cli/cmd_metric_test.py3
-rw-r--r--tests/unit/cli/cmd_plan_test.py3
-rw-r--r--tests/unit/cli/cmd_qpi_test.py3
8 files changed, 51 insertions, 12 deletions
diff --git a/qtip/base/error.py b/qtip/base/error.py
index f23d8cd9..d4b516ac 100644
--- a/qtip/base/error.py
+++ b/qtip/base/error.py
@@ -16,12 +16,14 @@ class InvalidContentError(BaseError):
def __init__(self, filename, excinfo=None):
self.filename = filename
self.excinfo = excinfo
+ self.message = "Invalid content in {0}".format(filename)
class NotFoundError(BaseError):
def __init__(self, needle, heystack='qtip'):
self.needle = needle
self.heystack = heystack
+ self.message = "{0} not found in {1}".format(needle[0:-5], heystack)
class ToBeDoneError(BaseError):
diff --git a/qtip/cli/commands/cmd_metric.py b/qtip/cli/commands/cmd_metric.py
index a2208444..1741fb48 100644
--- a/qtip/cli/commands/cmd_metric.py
+++ b/qtip/cli/commands/cmd_metric.py
@@ -8,8 +8,11 @@
##############################################################################
import click
+from colorama import Fore
import os
+from qtip.base.error import InvalidContentError
+from qtip.base.error import NotFoundError
from qtip.cli import utils
from qtip.cli.entry import Context
from qtip.loader.metric import MetricSpec
@@ -36,10 +39,16 @@ def cmd_list(ctx):
@click.argument('name')
@pass_context
def show(ctx, name):
- metric = MetricSpec('{}.yaml'.format(name))
- cnt = metric.content
- output = utils.render('metric', cnt)
- click.echo(output)
+ try:
+ metric = MetricSpec('{}.yaml'.format(name))
+ except NotFoundError as nf:
+ click.echo(Fore.RED + "ERROR: metric spec: " + nf.message)
+ except InvalidContentError as ice:
+ click.echo(Fore.RED + "ERROR: metric spec " + ice.message)
+ else:
+ cnt = metric.content
+ output = utils.render('metric', cnt)
+ click.echo(output)
@cli.command('run', help='Run performance test')
diff --git a/qtip/cli/commands/cmd_plan.py b/qtip/cli/commands/cmd_plan.py
index beb61b0e..b7c540b7 100644
--- a/qtip/cli/commands/cmd_plan.py
+++ b/qtip/cli/commands/cmd_plan.py
@@ -9,8 +9,11 @@
import click
+from colorama import Fore
import os
+from qtip.base.error import InvalidContentError
+from qtip.base.error import NotFoundError
from qtip.cli import utils
from qtip.cli.entry import Context
from qtip.loader.plan import Plan
@@ -44,10 +47,16 @@ def list(ctx):
@click.argument('name')
@pass_context
def show(ctx, name):
- plan = Plan('{}.yaml'.format(name))
- cnt = plan.content
- output = utils.render('plan', cnt)
- click.echo(output)
+ try:
+ plan = Plan('{}.yaml'.format(name))
+ except NotFoundError as nf:
+ click.echo(Fore.RED + "ERROR: plan spec: " + nf.message)
+ except InvalidContentError as ice:
+ click.echo(Fore.RED + "ERROR: plan spec: " + ice.message)
+ else:
+ 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 1e3671c5..a47442b7 100644
--- a/qtip/cli/commands/cmd_qpi.py
+++ b/qtip/cli/commands/cmd_qpi.py
@@ -9,8 +9,11 @@
import click
+from colorama import Fore
import os
+from qtip.base.error import InvalidContentError
+from qtip.base.error import NotFoundError
from qtip.cli import utils
from qtip.cli.entry import Context
from qtip.loader.qpi import QPISpec
@@ -37,10 +40,16 @@ def cmd_list(ctx):
@click.argument('name')
@pass_context
def show(ctx, name):
- qpi = QPISpec('{}.yaml'.format(name))
- cnt = qpi.content
- output = utils.render('qpi', cnt)
- click.echo(output)
+ try:
+ qpi = QPISpec('{}.yaml'.format(name))
+ except NotFoundError as nf:
+ click.echo(Fore.RED + "ERROR: qpi spec: " + nf.message)
+ except InvalidContentError as ice:
+ click.echo(Fore.RED + "ERROR: qpi spec: " + ice.message)
+ else:
+ 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/requirements.txt b/requirements.txt
index b0926b56..0f408520 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,4 @@
+colorama
ansible
click
connexion
diff --git a/tests/unit/cli/cmd_metric_test.py b/tests/unit/cli/cmd_metric_test.py
index cd496ad9..c92e944b 100644
--- a/tests/unit/cli/cmd_metric_test.py
+++ b/tests/unit/cli/cmd_metric_test.py
@@ -41,3 +41,6 @@ def test_show(runner):
result = runner.invoke(cli, ['metric', 'show'])
assert 'Missing argument "name".' in result.output
+
+ result = runner.invoke(cli, ['metric', 'show', 'xyz'])
+ assert "ERROR: metric spec: xyz not found" in result.output
diff --git a/tests/unit/cli/cmd_plan_test.py b/tests/unit/cli/cmd_plan_test.py
index 30025ae0..53a04800 100644
--- a/tests/unit/cli/cmd_plan_test.py
+++ b/tests/unit/cli/cmd_plan_test.py
@@ -38,3 +38,6 @@ def test_show(runner):
result = runner.invoke(cli, ['plan', 'show'])
assert 'Missing argument "name".' in result.output
+
+ result = runner.invoke(cli, ['plan', 'show', 'xyz'])
+ assert "ERROR: plan spec: xyz not found" in result.output
diff --git a/tests/unit/cli/cmd_qpi_test.py b/tests/unit/cli/cmd_qpi_test.py
index 3d2c2613..e7823c9b 100644
--- a/tests/unit/cli/cmd_qpi_test.py
+++ b/tests/unit/cli/cmd_qpi_test.py
@@ -38,3 +38,6 @@ def test_show(runner):
result = runner.invoke(cli, ['qpi', 'show'])
assert 'Missing argument "name".' in result.output
+
+ result = runner.invoke(cli, ['qpi', 'show', 'xyz'])
+ assert "ERROR: qpi spec: xyz not found" in result.output