From 0bb532c41e89568966ca2bfae259737e8830249b Mon Sep 17 00:00:00 2001 From: Moshe Date: Mon, 26 Feb 2018 13:39:57 +0200 Subject: Initial VNFTEST fw Issue-ID: VNFSDK-195 Change-Id: I5abf0dd033e76e5225bb8271c0afaea325d741d9 Signed-off-by: Moshe docker build Issue-ID: VNFSDK-195 Change-Id: I25eb933504c0201e6c26477b540626fd515d2887 Signed-off-by: Moshe fix requirements Issue-ID: VNFSDK-195 Change-Id: I5907fa102bfbf9cb81d42e491c133b4fdbb0d6fd Signed-off-by: Moshe rm netifaces Issue-ID: VNFSDK-195 Change-Id: I349d0c738442edfef256c90b06cbaeb446c1db13 Signed-off-by: Moshe fix tox config IssueID: VNFTEST-195 Change-Id: I5c0b0e0ab96cad1bdc56ab63860d794bfd15b5eb Signed-off-by: Moshe Add unit test IssueID: VNFTEST-195 Change-Id: I08c9ba53721306aff4b74720181f8c853c4ccabe Signed-off-by: Moshe fix setup.py Issue-ID: VNFSDK-195 Change-Id: I72bd93e4977edf5ef0b46c72fe47165b805aab7b Signed-off-by: Moshe fix test execution Issue-ID: VNFSDK-195 Change-Id: I488a6226d2562229f0e7fa6c1d20f0c43882bc3b Signed-off-by: Moshe --- vnftest/cmd/commands/__init__.py | 17 +++++++ vnftest/cmd/commands/env.py | 95 ++++++++++++++++++++++++++++++++++++++++ vnftest/cmd/commands/plugin.py | 44 +++++++++++++++++++ vnftest/cmd/commands/report.py | 34 ++++++++++++++ vnftest/cmd/commands/runner.py | 41 +++++++++++++++++ vnftest/cmd/commands/step.py | 40 +++++++++++++++++ vnftest/cmd/commands/task.py | 70 +++++++++++++++++++++++++++++ vnftest/cmd/commands/testcase.py | 49 +++++++++++++++++++++ 8 files changed, 390 insertions(+) create mode 100644 vnftest/cmd/commands/__init__.py create mode 100644 vnftest/cmd/commands/env.py create mode 100644 vnftest/cmd/commands/plugin.py create mode 100644 vnftest/cmd/commands/report.py create mode 100644 vnftest/cmd/commands/runner.py create mode 100644 vnftest/cmd/commands/step.py create mode 100644 vnftest/cmd/commands/task.py create mode 100644 vnftest/cmd/commands/testcase.py (limited to 'vnftest/cmd/commands') 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) -- cgit 1.2.3-korg