From 698cd3f4246c4e472c306fcad57d8d7b6431333f Mon Sep 17 00:00:00 2001 From: Moshe Date: Sun, 4 Mar 2018 15:42:23 +0200 Subject: Integrate dovetail with ONAP Change-Id: I6a1fa5f27df2f5127eb00156b3135dc79caf5e77 Issue-ID: DOVETAIL-629 Signed-off-by: Moshe --- docs/testing/user/userguide/cli_reference.rst | 3 ++ dovetail/container.py | 38 ++++++++++++++- dovetail/report.py | 69 ++++++++++++++++++++++++++- dovetail/run.py | 7 +++ dovetail/test_runner.py | 8 ++++ dovetail/testcase.py | 10 ++++ etc/compliance/onap.1.0.0.yml | 5 ++ etc/conf/cmd_config.yml | 7 +++ etc/conf/dovetail_config.yml | 4 ++ etc/conf/vnftest_config.yml | 31 ++++++++++++ etc/testcase/lifecycle.tc001.yml | 9 ++++ etc/userconfig/vnf_descriptor.yaml.sample | 20 ++++++++ etc/userconfig/vnftest_conf.yaml | 36 ++++++++++++++ 13 files changed, 244 insertions(+), 3 deletions(-) create mode 100644 etc/compliance/onap.1.0.0.yml create mode 100644 etc/conf/vnftest_config.yml create mode 100644 etc/testcase/lifecycle.tc001.yml create mode 100644 etc/userconfig/vnf_descriptor.yaml.sample create mode 100644 etc/userconfig/vnftest_conf.yaml diff --git a/docs/testing/user/userguide/cli_reference.rst b/docs/testing/user/userguide/cli_reference.rst index 39e72c93..7fca7137 100644 --- a/docs/testing/user/userguide/cli_reference.rst +++ b/docs/testing/user/userguide/cli_reference.rst @@ -80,6 +80,9 @@ Commands List | dovetail run --bottlenecks_tag | -b | Specify bottlenecks' docker image tag | | | | +------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+ +| dovetail run --vnf_tag | -v | Specify vnftest's docker image tag, default is beijing.0 | +| | | ++------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+ Commands Examples ================= diff --git a/dovetail/container.py b/dovetail/container.py index 66923e6a..5c16d802 100644 --- a/dovetail/container.py +++ b/dovetail/container.py @@ -18,7 +18,7 @@ class Container(object): container_list = {} has_pull_latest_image = {'yardstick': False, 'functest': False, - 'bottlenecks': False} + 'bottlenecks': False, 'vnftest': False} logger = None @@ -139,6 +139,23 @@ class Container(object): .format(dovetail_config['report_dest'])) return "{} {} {}".format(docker_vol, env, report) + @classmethod + def set_vnftest_config(cls): + dovetail_config = dt_cfg.dovetail_config + + log_vol = '-v %s:%s ' % (dovetail_config['result_dir'], + dovetail_config["vnftest"]['result']['log']) + + key_file = os.path.join(dovetail_config['config_dir'], + dovetail_config['pri_key']) + key_container_path = dovetail_config["vnftest"]['result']['key_path'] + if not os.path.isfile(key_file): + cls.logger.debug("Key file {} is not found".format(key_file)) + key_vol = '' + else: + key_vol = '-v %s:%s ' % (key_file, key_container_path) + return "%s %s" % (log_vol, key_vol) + @classmethod def create(cls, type, testcase_name): dovetail_config = dt_cfg.dovetail_config @@ -170,6 +187,8 @@ class Container(object): config = cls.set_yardstick_config() if type.lower() == "bottlenecks": config = cls.set_bottlenecks_config(testcase_name) + if type.lower() == "vnftest": + config = cls.set_vnftest_config() if not config: return None @@ -214,6 +233,8 @@ class Container(object): if type.lower() == 'yardstick': cls.set_yardstick_conf_file(container_id) + elif type.lower() == 'vnftest': + cls.set_vnftest_conf_file(container_id) return container_id @@ -322,6 +343,13 @@ class Container(object): cmd = 'cp %s %s' % (src_path, dest_path) return cls.exec_cmd(container_id, cmd, exit_on_error) + @classmethod + def docker_copy(cls, container_id, src_path, dest_path): + if not src_path or not dest_path: + return (1, 'src_path or dest_path is empty') + cmd = 'docker cp %s %s:%s' % (src_path, container_id, dest_path) + return dt_utils.exec_cmd(cmd, cls.logger) + @classmethod def set_yardstick_conf_file(cls, container_id): valid_type = 'yardstick' @@ -336,3 +364,11 @@ class Container(object): if url.lower() == 'file': cmd = ("sed -i '13s/http/file/g' {}".format(dest)) cls.exec_cmd(container_id, cmd) + + @classmethod + def set_vnftest_conf_file(cls, container_id): + valid_type = 'vnftest' + for conf_file in dt_cfg.dovetail_config[valid_type]['vnftest_conf']: + src = conf_file['src_file'] + dest = conf_file['dest_file'] + cls.docker_copy(container_id, src, dest) diff --git a/dovetail/report.py b/dovetail/report.py index 9d0517b4..dea9e426 100644 --- a/dovetail/report.py +++ b/dovetail/report.py @@ -27,7 +27,8 @@ from testcase import Testcase class Report(object): - results = {'functest': {}, 'yardstick': {}, 'bottlenecks': {}, 'shell': {}} + results = {'functest': {}, 'yardstick': {}, + 'bottlenecks': {}, 'shell': {}, 'vnftest': {}} logger = None @@ -427,11 +428,56 @@ class ShellCrawler(object): return None +class VnftestCrawler(object): + + logger = None + + def __init__(self): + self.type = 'vnftest' + self.logger.debug('Create crawler: {}'.format(self.type)) + + @classmethod + def create_log(cls): + cls.logger = \ + dt_logger.Logger(__name__ + '.VnftestCrawler').getLogger() + + def crawl(self, testcase): + report_dest = dt_cfg.dovetail_config['report_dest'] + if report_dest.lower() == 'file': + return self.crawl_from_file(testcase) + + if report_dest.lower().startswith('http'): + return self.crawl_from_url(testcase) + + def crawl_from_file(self, testcase): + + file_path = os.path.join(dt_cfg.dovetail_config['result_dir'], + testcase.name() + '.out') + if not os.path.exists(file_path): + self.logger.error('Result file not found: {}'.format(file_path)) + return None + criteria = 'FAIL' + with open(file_path, 'r') as f: + for jsonfile in f: + data = json.loads(jsonfile) + try: + criteria = data['result']['criteria'] + except KeyError as e: + self.logger.exception('Pass flag not found {}'.format(e)) + json_results = {'criteria': criteria} + self.logger.debug('Results: {}'.format(str(json_results))) + return json_results + + def crawl_from_url(self, testcase=None): + return None + + class CrawlerFactory(object): CRAWLER_MAP = {'functest': FunctestCrawler, 'yardstick': YardstickCrawler, 'bottlenecks': BottlenecksCrawler, + 'vnftest': VnftestCrawler, 'shell': ShellCrawler} @classmethod @@ -558,12 +604,31 @@ class ShellChecker(object): testcase.passed(False) +class VnftestChecker(object): + + logger = None + + @classmethod + def create_log(cls): + cls.logger = \ + dt_logger.Logger(__name__ + '.VnftestCheckers').getLogger() + + @staticmethod + def check(testcase, result): + if not result: + testcase.passed('FAIL') + else: + testcase.passed(result['criteria']) + return + + class CheckerFactory(object): CHECKER_MAP = {'functest': FunctestChecker, 'yardstick': YardstickChecker, 'bottlenecks': BottlenecksChecker, - 'shell': ShellChecker} + 'shell': ShellChecker, + 'vnftest': VnftestChecker} @classmethod def create(cls, type): diff --git a/dovetail/run.py b/dovetail/run.py index 1537fb6b..13e365c9 100755 --- a/dovetail/run.py +++ b/dovetail/run.py @@ -21,7 +21,9 @@ from container import Container from dovetail import constants from parser import Parser from report import BottlenecksChecker, FunctestChecker, YardstickChecker +from report import VnftestChecker from report import BottlenecksCrawler, FunctestCrawler, YardstickCrawler +from report import VnftestCrawler from report import Report from test_runner import DockerRunner, ShellRunner from testcase import Testcase @@ -97,6 +99,8 @@ def check_tc_result(testcase, logger): result_file = os.path.join(result_dir, functest_result) elif validate_type.lower() == 'bottlenecks': result_file = os.path.join(result_dir, testcase.name() + '.out') + elif validate_type.lower() == 'vnftest': + result_file = os.path.join(result_dir, testcase.name() + '.out') else: logger.error("Don't support {} now.".format(validate_type)) return @@ -180,9 +184,11 @@ def create_logs(): Report.create_log() FunctestCrawler.create_log() YardstickCrawler.create_log() + VnftestCrawler.create_log() BottlenecksCrawler.create_log() FunctestChecker.create_log() YardstickChecker.create_log() + VnftestChecker.create_log() BottlenecksChecker.create_log() Testcase.create_log() Testsuite.create_log() @@ -265,6 +271,7 @@ def main(*args, **kwargs): os.environ['DEBUG'] = 'true' create_logs() logger = dt_logger.Logger('run').getLogger() + logger.info('================================================') logger.info('Dovetail compliance: {}!'.format(kwargs['testsuite'])) logger.info('================================================') diff --git a/dovetail/test_runner.py b/dovetail/test_runner.py index c9260418..26b85a1e 100644 --- a/dovetail/test_runner.py +++ b/dovetail/test_runner.py @@ -260,6 +260,13 @@ class ShellRunner(object): 'exception: {}'.format(result_filename, e)) +class VnftestRunner(DockerRunner): + + def __init__(self, testcase): + self.type = 'vnftest' + super(VnftestRunner, self).__init__(testcase) + + class TestRunnerFactory(object): TEST_RUNNER_MAP = { @@ -267,6 +274,7 @@ class TestRunnerFactory(object): "yardstick": YardstickRunner, "bottlenecks": BottlenecksRunner, "shell": ShellRunner, + "vnftest": VnftestRunner } @classmethod diff --git a/dovetail/testcase.py b/dovetail/testcase.py index c9aef0e7..86f8061d 100644 --- a/dovetail/testcase.py +++ b/dovetail/testcase.py @@ -325,12 +325,22 @@ class ShellTestcase(Testcase): self.type = 'shell' +class VnftestTestcase(Testcase): + + validate_testcase_list = {} + + def __init__(self, testcase_yaml): + super(VnftestTestcase, self).__init__(testcase_yaml) + self.type = 'vnftest' + + class TestcaseFactory(object): TESTCASE_TYPE_MAP = { 'functest': FunctestTestcase, 'yardstick': YardstickTestcase, 'bottlenecks': BottlenecksTestcase, 'shell': ShellTestcase, + 'vnftest': VnftestTestcase } @classmethod diff --git a/etc/compliance/onap.1.0.0.yml b/etc/compliance/onap.1.0.0.yml new file mode 100644 index 00000000..9bb4d2f9 --- /dev/null +++ b/etc/compliance/onap.1.0.0.yml @@ -0,0 +1,5 @@ +--- +onap.1.0.0: + name: onap.1.0.0 + testcases_list: + - dovetail.lifecycle.tc001 \ No newline at end of file diff --git a/etc/conf/cmd_config.yml b/etc/conf/cmd_config.yml index 4dbfbbc8..cd8bfe93 100644 --- a/etc/conf/cmd_config.yml +++ b/etc/conf/cmd_config.yml @@ -36,6 +36,13 @@ cli: path: - 'bottlenecks/docker_tag' help: 'Overwrite tag for bottlenecks docker container (e.g. stable)' + vnf_tag: + flags: + - '--vnf_tag' + - '-v' + path: + - 'vnftest/docker_tag' + help: 'Overwrite tag for vnftest docker container (e.g. beijing.0)' control: testsuite: flags: diff --git a/etc/conf/dovetail_config.yml b/etc/conf/dovetail_config.yml index 464d046c..a77ac2af 100644 --- a/etc/conf/dovetail_config.yml +++ b/etc/conf/dovetail_config.yml @@ -35,6 +35,7 @@ testsuite_supported: - proposed_tests - debug - ovp.1.0.0 + - onap.1.0.0 # testarea supported, should adjust accordingly testarea_supported: - osinterop @@ -50,6 +51,7 @@ testarea_supported: - full - smoke - vnf + - lifecycle functest_testsuite: - refstack_defcore @@ -86,11 +88,13 @@ include_config: - functest_config.yml - yardstick_config.yml - bottlenecks_config.yml + - vnftest_config.yml test_project: - 'yardstick' - 'functest' - 'bottlenecks' + - 'vnftest' validate_input: valid_functest_tags: diff --git a/etc/conf/vnftest_config.yml b/etc/conf/vnftest_config.yml new file mode 100644 index 00000000..25a84c7b --- /dev/null +++ b/etc/conf/vnftest_config.yml @@ -0,0 +1,31 @@ +--- +vnftest: + image_name: onap/vnfsdk/vnftest + docker_tag: latest + opts: '-id --privileged=true' + config: + dir: '/home/onap/userconfig' + pre_condition: + - 'echo this is pre_condition' + cmds: + - 'mkdir -p /home/onap/vnftest/results/' + - "cd /home/onap/repos/vnftest && source /etc/vnftest/openstack.creds && + export CONF_FILE=/etc/vnftest/vnftest.yaml && + vnftest task start --output-file /home/onap/vnftest/results/{{testcase}}.out + /etc/vnftest/vnf_descriptor.yaml + tests/onap/test_cases/{{validate_testcase}}.yaml" + post_condition: + - 'echo this is post_condition' + result: + dir: '/home/onap/vnftest/results' + log: '/tmp/vnftest' + file_path: 'vnftest.log' + key_path: '/root/.ssh/id_rsa' + openrc: '/etc/vnftest/openstack.creds' + vnftest_conf: + - + src_file: '/home/opnfv/dovetail/pre_config/vnftest_conf.yaml' + dest_file: '/etc/vnftest/vnftest.yaml' + - + src_file: '/home/opnfv/dovetail/pre_config/vnf_descriptor.yaml' + dest_file: '/etc/vnftest/vnf_descriptor.yaml' diff --git a/etc/testcase/lifecycle.tc001.yml b/etc/testcase/lifecycle.tc001.yml new file mode 100644 index 00000000..f9c27985 --- /dev/null +++ b/etc/testcase/lifecycle.tc001.yml @@ -0,0 +1,9 @@ +--- +dovetail.lifecycle.tc001: + name: dovetail.lifecycle.tc001 + objective: vnf lifecycle tests + validate: + type: vnftest + testcase: onap_vnftest_tc001 + report: + sub_testcase_list: \ No newline at end of file diff --git a/etc/userconfig/vnf_descriptor.yaml.sample b/etc/userconfig/vnf_descriptor.yaml.sample new file mode 100644 index 00000000..98741768 --- /dev/null +++ b/etc/userconfig/vnf_descriptor.yaml.sample @@ -0,0 +1,20 @@ +############################################################################## +# 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 +############################################################################## + +--- + +vnf_name: sample_firewall +type: CSAR +vnf_id: 123456 +csar_package_location: /home/opnfv/userconfig/pre_config/vFW_sample.csar \ No newline at end of file diff --git a/etc/userconfig/vnftest_conf.yaml b/etc/userconfig/vnftest_conf.yaml new file mode 100644 index 00000000..781540bd --- /dev/null +++ b/etc/userconfig/vnftest_conf.yaml @@ -0,0 +1,36 @@ +############################################################################## +# 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 +############################################################################## + +dir: + conf: /etc/nvftest + repos: /home/vnftest/repos/vnftest + log: /tmp/vnftest + +file: + output_file: /tmp/vnftest.out + html_file: /tmp/vnftest.htm + reporting_file: /tmp/report.html + +component: + aai_ip: 10.247.43.140 + aai_port: 30202 + aai_ssl_port: 30233 + mso_ip: 10.247.43.140 + sdc_ip: 10.247.43.140 + sdc_port: 30205 + sdc_catalog_port: 30206 + sdc_designer_user: cs0008 + sdc_tester_user: jm0007 + sdc_governance_user: gv0001 + sdc_operations_user: op0001 \ No newline at end of file -- cgit 1.2.3-korg