summaryrefslogtreecommitdiffstats
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--qtip/reporter/testapi.py68
-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
9 files changed, 119 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/qtip/reporter/testapi.py b/qtip/reporter/testapi.py
new file mode 100644
index 00000000..a0be5379
--- /dev/null
+++ b/qtip/reporter/testapi.py
@@ -0,0 +1,68 @@
+##############################################################################
+# Copyright (c) 2017 akhil.batra@research.iiit.ac.in 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 requests
+
+
+payload_template = {'project_name',
+ 'case_name',
+ 'pod_name',
+ 'installer',
+ 'version',
+ 'scenario',
+ 'criteria',
+ 'build_tag',
+ 'start_date',
+ 'stop_date',
+ 'details'}
+
+
+def validate_payload():
+ def _decorator(func):
+ def _execute(testapi_url, payload):
+ if set(payload.keys()) != payload_template:
+ missing_parameters = list(payload_template -
+ set(payload.keys()))
+ print "Missing Parameters -- {}".\
+ format(",".join(missing_parameters))
+ raise MissingParamsError("push_results", missing_parameters)
+ invalid_params = []
+ for key in payload:
+ if (payload[key] == "") or (payload[key] is None):
+ invalid_params.append(key)
+ if len(invalid_params) > 0:
+ print "Invalid or missing values of parameters -- `{}`".\
+ format(",".join(invalid_params))
+ raise InvalidParamsError("push_results", invalid_params)
+ return func(testapi_url, payload)
+ return _execute
+ return _decorator
+
+
+class InvalidParamsError(Exception):
+ def __init__(self, method, params):
+ self.method = method
+ self.params = params
+
+
+class MissingParamsError(Exception):
+ def __init__(self, method, params):
+ self.method = method
+ self.params = params
+
+
+@validate_payload()
+def push_results(testapi_url, payload):
+ """ push results to OPNFV TestAPI """
+
+ response = requests.post(testapi_url + '/results', json=payload)
+ if response.status_code == requests.codes.ok:
+ return response.json()
+ else:
+ response.raise_for_status()
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