Integrate dovetail with ONAP 51/54551/3
authorMoshe <moshehoa@amdocs.com>
Sun, 4 Mar 2018 13:42:23 +0000 (15:42 +0200)
committerMoshe <moshehoa@amdocs.com>
Thu, 29 Mar 2018 11:04:48 +0000 (14:04 +0300)
Change-Id: I6a1fa5f27df2f5127eb00156b3135dc79caf5e77
Issue-ID: DOVETAIL-629
Signed-off-by: Moshe <moshehoa@amdocs.com>
13 files changed:
docs/testing/user/userguide/cli_reference.rst
dovetail/container.py
dovetail/report.py
dovetail/run.py
dovetail/test_runner.py
dovetail/testcase.py
etc/compliance/onap.1.0.0.yml [new file with mode: 0644]
etc/conf/cmd_config.yml
etc/conf/dovetail_config.yml
etc/conf/vnftest_config.yml [new file with mode: 0644]
etc/testcase/lifecycle.tc001.yml [new file with mode: 0644]
etc/userconfig/vnf_descriptor.yaml.sample [new file with mode: 0644]
etc/userconfig/vnftest_conf.yaml [new file with mode: 0644]

index 39e72c9..7fca713 100644 (file)
@@ -80,6 +80,9 @@ Commands List
 | dovetail run --bottlenecks_tag | -b <bottlenecks_docker_image_tag>     | Specify bottlenecks' docker image tag                                                             |
 |                                                                        |                                                                                                   |
 +------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
+| dovetail run --vnf_tag | -v <vnftest_docker_image_tag>                 | Specify vnftest's docker image tag, default is beijing.0                                          |
+|                                                                        |                                                                                                   |
++------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+
 
 Commands Examples
 =================
index 66923e6..5c16d80 100644 (file)
@@ -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)
index 9d0517b..dea9e42 100644 (file)
@@ -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):
index 1537fb6..13e365c 100755 (executable)
@@ -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('================================================')
index c926041..26b85a1 100644 (file)
@@ -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
index c9aef0e..86f8061 100644 (file)
@@ -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 (file)
index 0000000..9bb4d2f
--- /dev/null
@@ -0,0 +1,5 @@
+---
+onap.1.0.0:
+  name: onap.1.0.0
+  testcases_list:
+    - dovetail.lifecycle.tc001
\ No newline at end of file
index 4dbfbbc..cd8bfe9 100644 (file)
@@ -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:
index 464d046..a77ac2a 100644 (file)
@@ -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 (file)
index 0000000..25a84c7
--- /dev/null
@@ -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 (file)
index 0000000..f9c2798
--- /dev/null
@@ -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 (file)
index 0000000..9874176
--- /dev/null
@@ -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 (file)
index 0000000..781540b
--- /dev/null
@@ -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