summaryrefslogtreecommitdiffstats
path: root/vnftest/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'vnftest/cmd')
-rwxr-xr-xvnftest/cmd/NSBperf.py228
-rw-r--r--vnftest/cmd/__init__.py0
-rw-r--r--vnftest/cmd/cli.py184
-rw-r--r--vnftest/cmd/commands/__init__.py17
-rw-r--r--vnftest/cmd/commands/env.py95
-rw-r--r--vnftest/cmd/commands/plugin.py44
-rw-r--r--vnftest/cmd/commands/report.py34
-rw-r--r--vnftest/cmd/commands/runner.py41
-rw-r--r--vnftest/cmd/commands/step.py40
-rw-r--r--vnftest/cmd/commands/task.py70
-rw-r--r--vnftest/cmd/commands/testcase.py49
11 files changed, 802 insertions, 0 deletions
diff --git a/vnftest/cmd/NSBperf.py b/vnftest/cmd/NSBperf.py
new file mode 100755
index 0000000..40a157b
--- /dev/null
+++ b/vnftest/cmd/NSBperf.py
@@ -0,0 +1,228 @@
+#!/usr/bin/env python
+##############################################################################
+# Copyright 2018 EuropeanSoftwareMarketingLtd.
+# ===================================================================
+# Licensed under the ApacheLicense, Version2.0 (the"License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# software distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and limitations under
+# the License
+##############################################################################
+# vnftest comment: this is a modified copy of
+# yardstick/cmd/NSBperf.py
+
+"""NSBPERF main script.
+"""
+
+from __future__ import absolute_import
+from __future__ import print_function
+import os
+import argparse
+import json
+import subprocess
+import signal
+from oslo_serialization import jsonutils
+
+from six.moves import input
+
+CLI_PATH = os.path.dirname(os.path.realpath(__file__))
+REPO_PATH = os.path.abspath(os.path.join(CLI_PATH, os.pardir))
+
+
+def sigint_handler(*args, **kwargs):
+ """ Capture ctrl+c and exit cli """
+ subprocess.call(["pkill", "-9", "vnftest"])
+ raise SystemExit(1)
+
+
+class VnftestNSCli(object):
+ """ This class handles vnftest network serivce testing """
+
+ def __init__(self):
+ super(VnftestNSCli, self).__init__()
+
+ @classmethod
+ def validate_input(cls, choice, choice_len):
+ """ Validate user inputs """
+ if not str(choice):
+ return 1
+
+ choice = int(choice)
+ if not 1 <= choice <= choice_len:
+ print("\nInvalid wrong choice...")
+ input("Press Enter to continue...")
+ return 1
+ subprocess.call(['clear'])
+ return 0
+
+ @classmethod
+ def parse_arguments(cls):
+ """
+ Parse command line arguments.
+ """
+ parser = \
+ argparse.ArgumentParser(
+ prog=__file__,
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+ parser.add_argument('--version', action='version',
+ version='%(prog)s 0.1')
+ parser.add_argument('--list', '--list-tests', action='store_true',
+ help='list all tests and exit')
+ parser.add_argument('--list-vnfs', action='store_true',
+ help='list all system vnfs and exit')
+
+ group = parser.add_argument_group('test selection options')
+ group.add_argument('--vnf', help='vnf to use')
+ group.add_argument('--test', help='test in use')
+
+ args = vars(parser.parse_args())
+
+ return args
+
+ @classmethod
+ def generate_kpi_results(cls, tkey, tgen):
+ """ Generate report for vnf & traffic generator kpis """
+ if tgen:
+ print("\n%s stats" % tkey)
+ print("----------------------------")
+ for key, value in tgen.items():
+ if key != "collect_stats":
+ print(json.dumps({key: value}, indent=2))
+
+ @classmethod
+ def generate_nfvi_results(cls, nfvi):
+ """ Generate report for vnf & traffic generator kpis """
+ if nfvi:
+ nfvi_kpi = {k: v for k, v in nfvi.items() if k == 'collect_stats'}
+ if nfvi_kpi:
+ print("\nNFVi stats")
+ print("----------------------------")
+ for key, value in nfvi_kpi.items():
+ print(json.dumps({key: value}, indent=2))
+
+ def generate_final_report(self, test_case):
+ """ Function will check if partial test results are available
+ and generates final report in rst format.
+ """
+
+ tc_name = os.path.splitext(test_case)[0]
+ report_caption = '{}\n{} ({})\n{}\n\n'.format(
+ '================================================================',
+ 'Performance report for', tc_name.upper(),
+ '================================================================')
+ print(report_caption)
+ if os.path.isfile("/tmp/vnftest.out"):
+ lines = []
+ with open("/tmp/vnftest.out") as infile:
+ lines = jsonutils.load(infile)
+
+ if lines:
+ lines = \
+ lines['result']["testcases"][tc_name]["tc_data"]
+ tc_res = lines.pop(len(lines) - 1)
+ for key, value in tc_res["data"].items():
+ self.generate_kpi_results(key, value)
+ self.generate_nfvi_results(value)
+
+ @classmethod
+ def handle_list_options(cls, args, test_path):
+ """ Process --list cli arguments if needed
+
+ :param args: A dictionary with all CLI arguments
+ """
+ if args['list_vnfs']:
+ vnfs = os.listdir(test_path)
+ print("VNF :")
+ print("================")
+ for index, vnf in enumerate(vnfs, 1):
+ print((' %-2s %s' % ('%s:' % str(index), vnf)))
+ raise SystemExit(0)
+
+ if args['list']:
+ vnfs = os.listdir(test_path)
+
+ print("Available Tests:")
+ print("*****************")
+ for vnf in vnfs:
+ testcases = os.listdir(test_path + vnf)
+ print(("VNF :(%s)" % vnf))
+ print("================")
+ test_cases = [tc for tc in testcases if "tc_" in tc and "template" not in tc]
+
+ print("\tBareMetal Testcase:")
+ print("\t===================")
+ for testcase in [tc for tc in test_cases if "baremetal" in tc]:
+ print("\t%s" % testcase)
+
+ print(os.linesep)
+ print("\tStandalone Virtualization Testcase:")
+ print("\t===================================")
+ for testcase in [tc for tc in test_cases if "ovs" in tc or "sriov" in tc]:
+ print("\t%s" % testcase)
+
+ print(os.linesep)
+ print("\tOpenstack Testcase:")
+ print("\t===================")
+ for testcase in [tc for tc in test_cases if "heat" in tc]:
+ print("\t%s" % testcase)
+ print(os.linesep)
+ raise SystemExit(0)
+
+ @classmethod
+ def terminate_if_less_options(cls, args):
+ """ terminate cli if cmdline options is invalid """
+ if not (args["vnf"] and args["test"]):
+ print("CLI needs option, make sure to pass vnf, test")
+ print("eg: NSBperf.py --vnf <vnf untertest> --test <test yaml>")
+ raise SystemExit(1)
+
+ def run_test(self, args, test_path):
+ """ run requested test """
+ try:
+ vnf = args.get("vnf", "")
+ test = args.get("test", "")
+
+ vnf_dir = test_path + os.sep + vnf
+ if not os.path.exists(vnf_dir):
+ raise ValueError("'%s', vnf not supported." % vnf)
+
+ testcases = [tc for tc in os.listdir(vnf_dir) if "tc" in tc]
+ subtest = set([test]).issubset(testcases)
+ if not subtest:
+ raise ValueError("'%s', testcase not supported." % test)
+
+ os.chdir(vnf_dir)
+ # fixme: Use REST APIs to initiate testcases
+ subprocess.check_output(["vnftest", "--debug",
+ "task", "start", test])
+ self.generate_final_report(test)
+ except (IOError, ValueError):
+ print("Value/I/O error...")
+ except BaseException:
+ print("Test failed. Please verify test inputs & re-run the test..")
+ print("eg: NSBperf.py --vnf <vnf untertest> --test <test yaml>")
+
+ def main(self):
+ """Main function.
+ """
+ test_path = os.path.join(REPO_PATH, "../samples/vnf_samples/nsut/")
+ os.chdir(os.path.join(REPO_PATH, "../"))
+ args = self.parse_arguments()
+
+ # if required, handle list-* operations
+ self.handle_list_options(args, test_path)
+
+ # check for input params
+ self.terminate_if_less_options(args)
+
+ # run test
+ self.run_test(args, test_path)
+
+if __name__ == "__main__":
+ signal.signal(signal.SIGINT, sigint_handler)
+ NS_CLI = VnftestNSCli()
+ NS_CLI.main()
diff --git a/vnftest/cmd/__init__.py b/vnftest/cmd/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/vnftest/cmd/__init__.py
diff --git a/vnftest/cmd/cli.py b/vnftest/cmd/cli.py
new file mode 100644
index 0000000..9bffe56
--- /dev/null
+++ b/vnftest/cmd/cli.py
@@ -0,0 +1,184 @@
+#!/usr/bin/env python
+##############################################################################
+# Copyright 2018 EuropeanSoftwareMarketingLtd.
+# ===================================================================
+# Licensed under the ApacheLicense, Version2.0 (the"License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# software distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and limitations under
+# the License
+##############################################################################
+# vnftest comment: this is a modified copy of
+# yardstick/cmd/cli.py
+"""
+Command-line interface to vnftest
+"""
+
+from __future__ import absolute_import
+import logging
+import os
+import sys
+
+from pkg_resources import get_distribution
+from argparse import RawDescriptionHelpFormatter
+from oslo_config import cfg
+
+from vnftest import _init_logging, _LOG_STREAM_HDLR
+from vnftest.cmd.commands import task
+from vnftest.cmd.commands import runner
+from vnftest.cmd.commands import step
+from vnftest.cmd.commands import testcase
+from vnftest.cmd.commands import plugin
+from vnftest.cmd.commands import env
+from vnftest.cmd.commands import report
+
+CONF = cfg.CONF
+cli_opts = [
+ cfg.BoolOpt('debug',
+ short='d',
+ default=False,
+ help='increase output verbosity to debug')
+]
+CONF.register_cli_opts(cli_opts)
+
+CONFIG_SEARCH_PATHS = [sys.prefix + "/etc/vnftest",
+ "~/.vnftest",
+ "/etc/vnftest"]
+
+
+def find_config_files(path_list):
+ for path in path_list:
+ abspath = os.path.abspath(os.path.expanduser(path))
+ confname = abspath + "/vnftest.conf"
+ if os.path.isfile(confname):
+ return [confname]
+
+ return None
+
+
+class VnftestCLI(): # pragma: no cover
+ """Command-line interface to vnftest"""
+
+ # Command categories
+ categories = {
+ 'task': task.TaskCommands,
+ 'runner': runner.RunnerCommands,
+ 'step': step.StepCommands,
+ 'testcase': testcase.TestcaseCommands,
+ 'plugin': plugin.PluginCommands,
+ 'env': env.EnvCommand,
+ 'report': report.ReportCommands
+ }
+
+ def __init__(self):
+ self.opts = []
+ self._version = 'vnftest version %s ' % \
+ get_distribution('vnftest').version
+
+ def _find_actions(self, subparsers, actions_module):
+ """find action methods"""
+ # Find action methods inside actions_module and
+ # add them to the command parser.
+ # The 'actions_module' argument may be a class
+ # or module. Action methods start with 'do_'
+ for attr in (a for a in dir(actions_module) if a.startswith('do_')):
+ command = attr[3:].replace('_', '-')
+ callback = getattr(actions_module, attr)
+ desc = callback.__doc__ or ''
+ arguments = getattr(callback, 'arguments', [])
+ subparser = subparsers.add_parser(
+ command,
+ description=desc
+ )
+ for (args, kwargs) in arguments:
+ subparser.add_argument(*args, **kwargs)
+ subparser.set_defaults(func=callback)
+
+ def _add_command_parsers(self, categories, subparsers):
+ """add commands to command-line parser"""
+ for category in categories:
+ command_object = categories[category]()
+ desc = command_object.__doc__ or ''
+ subparser = subparsers.add_parser(
+ category, description=desc,
+ formatter_class=RawDescriptionHelpFormatter
+ )
+ subparser.set_defaults(command_object=command_object)
+ cmd_subparsers = subparser.add_subparsers(title='subcommands')
+ self._find_actions(cmd_subparsers, command_object)
+
+ def _register_cli_opt(self):
+
+ # register subcommands to parse additional command line arguments
+ def parser(subparsers):
+ self._add_command_parsers(VnftestCLI.categories, subparsers)
+
+ category_opt = cfg.SubCommandOpt("category",
+ title="Command categories",
+ help="Available categories",
+ handler=parser)
+ self._register_opt(category_opt)
+
+ def _register_opt(self, opt):
+
+ CONF.register_cli_opt(opt)
+ self.opts.append(opt)
+
+ def _load_cli_config(self, argv):
+
+ # load CLI args and config files
+ CONF(argv, project="vnftest", version=self._version,
+ default_config_files=find_config_files(CONFIG_SEARCH_PATHS))
+
+ def _handle_global_opts(self):
+
+ _init_logging()
+ if CONF.debug:
+ _LOG_STREAM_HDLR.setLevel(logging.DEBUG)
+
+ def _dispatch_func_notask(self):
+
+ # dispatch to category parser
+ func = CONF.category.func
+ func(CONF.category)
+
+ def _dispatch_func_task(self, task_id):
+
+ # dispatch to category parser
+ func = CONF.category.func
+ func(CONF.category, task_id=task_id)
+
+ def _clear_config_opts(self):
+
+ CONF.clear()
+ CONF.unregister_opts(self.opts)
+
+ def main(self, argv): # pragma: no cover
+ """run the command line interface"""
+ try:
+ self._register_cli_opt()
+
+ self._load_cli_config(argv)
+
+ self._handle_global_opts()
+
+ self._dispatch_func_notask()
+ finally:
+ self._clear_config_opts()
+
+ def api(self, argv, task_id): # pragma: no cover
+ """run the api interface"""
+ try:
+ self._register_cli_opt()
+
+ self._load_cli_config(argv)
+
+ self._handle_global_opts()
+
+ self._dispatch_func_task(task_id)
+ finally:
+ self._clear_config_opts()
diff --git a/vnftest/cmd/commands/__init__.py b/vnftest/cmd/commands/__init__.py
new file mode 100644
index 0000000..8c46b47
--- /dev/null
+++ b/vnftest/cmd/commands/__init__.py
@@ -0,0 +1,17 @@
+from __future__ import absolute_import
+from vnftest.onap.core import Param
+
+
+def change_osloobj_to_paras(args):
+ param = Param({})
+ for k in vars(param):
+ if hasattr(args, k):
+ setattr(param, k, getattr(args, k))
+ return param
+
+
+class Commands(object):
+
+ def _change_to_dict(self, args):
+ p = Param({})
+ return {k: getattr(args, k) for k in vars(p) if hasattr(args, k)}
diff --git a/vnftest/cmd/commands/env.py b/vnftest/cmd/commands/env.py
new file mode 100644
index 0000000..55f0ebb
--- /dev/null
+++ b/vnftest/cmd/commands/env.py
@@ -0,0 +1,95 @@
+##############################################################################
+# Copyright 2018 EuropeanSoftwareMarketingLtd.
+# ===================================================================
+# Licensed under the ApacheLicense, Version2.0 (the"License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# software distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and limitations under
+# the License
+##############################################################################
+# vnftest comment: this is a modified copy of
+# yardstick/cmd/commands/env.py
+from __future__ import absolute_import
+from __future__ import print_function
+
+import os
+import sys
+import time
+
+from six.moves import range
+
+from vnftest.common import constants as consts
+from vnftest.common.httpClient import HttpClient
+
+
+class EnvCommand(object):
+ """
+
+ Set of commands to prepare environment
+ """
+
+ def do_influxdb(self, args):
+ data = {'action': 'create_influxdb'}
+ task_id = self._start_async_task(data)
+
+ start = '* creating influxDB'
+ self._check_status(task_id, start)
+
+ def do_grafana(self, args):
+ data = {'action': 'create_grafana'}
+ task_id = self._start_async_task(data)
+
+ start = '* creating grafana'
+ self._check_status(task_id, start)
+
+ def do_prepare(self, args):
+ data = {'action': 'prepare_env'}
+ task_id = self._start_async_task(data)
+
+ start = '* preparing vnftest environment'
+ self._check_status(task_id, start)
+
+ def _start_async_task(self, data):
+ url = consts.ENV_ACTION_API
+ return HttpClient().post(url, data)['result']['task_id']
+
+ def _check_status(self, task_id, start):
+ self._print_status(start, '[]\r')
+ url = '{}?task_id={}'.format(consts.ASYNC_TASK_API, task_id)
+
+ CHECK_STATUS_RETRY = 20
+ CHECK_STATUS_DELAY = 5
+
+ for retry in range(CHECK_STATUS_RETRY):
+ response = HttpClient().get(url)
+ status = response['status']
+
+ if status:
+ break
+
+ # wait until the async task finished
+ time.sleep(CHECK_STATUS_DELAY * (retry + 1))
+
+ switcher = {
+ 0: 'Timeout',
+ 1: 'Finished',
+ 2: 'Error'
+ }
+ self._print_status(start, '[{}]'.format(switcher[status]))
+ if status == 2:
+ print(response['result'])
+ sys.stdout.flush()
+ return status
+
+ def _print_status(self, s, e):
+ try:
+ columns = int(os.popen('stty size', 'r').read().split()[1])
+ word = '{}{}{}'.format(s, ' ' * (columns - len(s) - len(e)), e)
+ sys.stdout.write(word)
+ sys.stdout.flush()
+ except IndexError:
+ pass
diff --git a/vnftest/cmd/commands/plugin.py b/vnftest/cmd/commands/plugin.py
new file mode 100644
index 0000000..e05130a
--- /dev/null
+++ b/vnftest/cmd/commands/plugin.py
@@ -0,0 +1,44 @@
+##############################################################################
+# Copyright 2018 EuropeanSoftwareMarketingLtd.
+# ===================================================================
+# Licensed under the ApacheLicense, Version2.0 (the"License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# software distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and limitations under
+# the License
+##############################################################################
+# vnftest comment: this is a modified copy of
+# yardstick/cmd/commands/plugin.py
+""" Handler for vnftest command 'plugin' """
+
+from __future__ import print_function
+
+from __future__ import absolute_import
+from vnftest.onap.core.plugin import Plugin
+from vnftest.common.utils import cliargs
+from vnftest.cmd.commands import change_osloobj_to_paras
+
+
+class PluginCommands(object): # pragma: no cover
+ """Plugin commands.
+
+ Set of commands to manage plugins.
+ """
+
+ @cliargs("input_file", type=str, help="path to plugin configuration file",
+ nargs=1)
+ def do_install(self, args):
+ """Install a plugin."""
+ param = change_osloobj_to_paras(args)
+ Plugin().install(param)
+
+ @cliargs("input_file", type=str, help="path to plugin configuration file",
+ nargs=1)
+ def do_remove(self, args):
+ """Remove a plugin."""
+ param = change_osloobj_to_paras(args)
+ Plugin().remove(param)
diff --git a/vnftest/cmd/commands/report.py b/vnftest/cmd/commands/report.py
new file mode 100644
index 0000000..05b9249
--- /dev/null
+++ b/vnftest/cmd/commands/report.py
@@ -0,0 +1,34 @@
+##############################################################################
+# Copyright (c) 2017 Rajesh Kudaka.
+#
+# Author: Rajesh Kudaka (4k.rajesh@gmail.com)
+# 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
+##############################################################################
+# vnftest comment: this is a modified copy of
+# yardstick/cmd/commands/report.py
+""" Handler for vnftest command 'report' """
+
+from __future__ import print_function
+
+from __future__ import absolute_import
+
+from vnftest.onap.core.report import Report
+from vnftest.cmd.commands import change_osloobj_to_paras
+from vnftest.common.utils import cliargs
+
+
+class ReportCommands(object): # pragma: no cover
+ """Report commands.
+
+ Set of commands to manage benchmark tasks.
+ """
+
+ @cliargs("task_id", type=str, help=" task id", nargs=1)
+ @cliargs("yaml_name", type=str, help=" Yaml file Name", nargs=1)
+ def do_generate(self, args):
+ """Start a benchmark step."""
+ param = change_osloobj_to_paras(args)
+ Report().generate(param)
diff --git a/vnftest/cmd/commands/runner.py b/vnftest/cmd/commands/runner.py
new file mode 100644
index 0000000..557f58f
--- /dev/null
+++ b/vnftest/cmd/commands/runner.py
@@ -0,0 +1,41 @@
+##############################################################################
+# Copyright 2018 EuropeanSoftwareMarketingLtd.
+# ===================================================================
+# Licensed under the ApacheLicense, Version2.0 (the"License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# software distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and limitations under
+# the License
+##############################################################################
+# vnftest comment: this is a modified copy of
+# yardstick/cmd/commands/runner.py
+""" Handler for vnftest command 'runner' """
+
+from __future__ import print_function
+
+from __future__ import absolute_import
+from vnftest.onap.core.runner import Runners
+from vnftest.common.utils import cliargs
+from vnftest.cmd.commands import change_osloobj_to_paras
+
+
+class RunnerCommands(object): # pragma: no cover
+ """Runner commands.
+
+ Set of commands to discover and display runner types.
+ """
+
+ def do_list(self, args):
+ """List existing runner types"""
+ param = change_osloobj_to_paras(args)
+ Runners().list_all(param)
+
+ @cliargs("type", type=str, help="runner type", nargs=1)
+ def do_show(self, args):
+ """Show details of a specific runner type"""
+ param = change_osloobj_to_paras(args)
+ Runners().show(param)
diff --git a/vnftest/cmd/commands/step.py b/vnftest/cmd/commands/step.py
new file mode 100644
index 0000000..10ae913
--- /dev/null
+++ b/vnftest/cmd/commands/step.py
@@ -0,0 +1,40 @@
+##############################################################################
+# Copyright 2018 EuropeanSoftwareMarketingLtd.
+# ===================================================================
+# Licensed under the ApacheLicense, Version2.0 (the"License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# software distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and limitations under
+# the License
+##############################################################################
+# vnftest comment: this is a modified copy of
+# yardstick/cmd/commands/step.py
+""" Handler for vnftest command 'step' """
+
+from __future__ import print_function
+from __future__ import absolute_import
+from vnftest.onap.core.step import Steps
+from vnftest.common.utils import cliargs
+from vnftest.cmd.commands import change_osloobj_to_paras
+
+
+class StepCommands(object): # pragma: no cover
+ """Step commands.
+
+ Set of commands to discover and display step types.
+ """
+
+ def do_list(self, args):
+ """List existing step types"""
+ param = change_osloobj_to_paras(args)
+ Steps().list_all(param)
+
+ @cliargs("type", type=str, help="runner type", nargs=1)
+ def do_show(self, args):
+ """Show details of a specific step type"""
+ param = change_osloobj_to_paras(args)
+ Steps().show(param)
diff --git a/vnftest/cmd/commands/task.py b/vnftest/cmd/commands/task.py
new file mode 100644
index 0000000..cc77bb8
--- /dev/null
+++ b/vnftest/cmd/commands/task.py
@@ -0,0 +1,70 @@
+#############################################################################
+# Copyright (c) 2015 Ericsson AB 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
+##############################################################################
+# vnftest comment: this is a modified copy of
+# yardstick/cmd/commands/task.py
+""" Handler for vnftest command 'task' """
+from __future__ import print_function
+from __future__ import absolute_import
+
+import logging
+
+from vnftest.onap.core.task import Task
+from vnftest.common.utils import cliargs
+from vnftest.common.utils import write_json_to_file
+from vnftest.cmd.commands import change_osloobj_to_paras
+
+output_file_default = "/tmp/vnftest.out"
+
+
+LOG = logging.getLogger(__name__)
+
+
+class TaskCommands(object): # pragma: no cover
+ """Task commands.
+
+ Set of commands to manage benchmark tasks.
+ """
+
+ @cliargs("inputfile", type=str, help="path to task or suite file", nargs=1)
+ @cliargs("--task-args", dest="task_args",
+ help="Input task args (dict in json). These args are used"
+ "to render input task that is jinja2 template.")
+ @cliargs("--task-args-file", dest="task_args_file",
+ help="Path to the file with input task args (dict in "
+ "json/yaml). These args are used to render input"
+ "task that is jinja2 template.")
+ @cliargs("--keep-deploy", help="keep context deployed in cloud",
+ action="store_true")
+ @cliargs("--parse-only", help="parse the config file and exit",
+ action="store_true")
+ @cliargs("--output-file", help="file where output is stored, default %s" %
+ output_file_default, default=output_file_default)
+ @cliargs("--suite", help="process test suite file instead of a task file",
+ action="store_true")
+ def do_start(self, args, **kwargs):
+ param = change_osloobj_to_paras(args)
+ self.output_file = param.output_file
+
+ result = {}
+ LOG.info('Task START')
+ try:
+ result = Task().start(param, **kwargs)
+ except Exception as e:
+ self._write_error_data(e)
+ LOG.exception("")
+
+ if result.get('result', {}).get('criteria') == 'PASS':
+ LOG.info('Task SUCCESS')
+ else:
+ LOG.info('Task FAILED')
+ raise RuntimeError('Task Failed')
+
+ def _write_error_data(self, error):
+ data = {'status': 2, 'result': str(error)}
+ write_json_to_file(self.output_file, data)
diff --git a/vnftest/cmd/commands/testcase.py b/vnftest/cmd/commands/testcase.py
new file mode 100644
index 0000000..518df2d
--- /dev/null
+++ b/vnftest/cmd/commands/testcase.py
@@ -0,0 +1,49 @@
+##############################################################################
+# Copyright 2018 EuropeanSoftwareMarketingLtd.
+# ===================================================================
+# Licensed under the ApacheLicense, Version2.0 (the"License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# software distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and limitations under
+# the License
+##############################################################################
+# vnftest comment: this is a modified copy of
+# yardstick/cmd/commands/testcase.py
+""" Handler for vnftest command 'testcase' """
+from __future__ import absolute_import
+
+import prettytable
+
+from vnftest.onap.core.testcase import Testcase
+from vnftest.common.utils import cliargs
+from vnftest.cmd.commands import change_osloobj_to_paras
+from vnftest.cmd.commands import Commands
+
+
+class TestcaseCommands(Commands):
+ """Testcase commands.
+
+ Set of commands to discover and display test cases.
+ """
+
+ def do_list(self, *args):
+ testcase_list = ""
+ self._format_print(testcase_list)
+
+ @cliargs("casename", type=str, help="test case name", nargs=1)
+ def do_show(self, args):
+ """Show details of a specific test case"""
+ param = change_osloobj_to_paras(args)
+ Testcase().show(param)
+
+ def _format_print(self, testcase_list):
+ """format output"""
+ case_table = prettytable.PrettyTable(['Testcase Name', 'Description'])
+ case_table.align = 'l'
+ for testcase_record in testcase_list:
+ case_table.add_row([testcase_record['Name'], testcase_record['Description']])
+ print(case_table)