diff options
author | Shuya Nakama <shuya.nakama@okinawaopenlabs.org> | 2017-08-25 14:26:30 +0000 |
---|---|---|
committer | Shuya Nakama <shuya.nakama@okinawaopenlabs.org> | 2017-08-29 07:19:48 +0000 |
commit | 0a56dfd7f42d6a6d849e5cf3f82b0863c8a62ffe (patch) | |
tree | 2361c11c016f4101487787c9ea7676c4d696902d /functest/opnfv_tests/vnf/router/vrouter_base.py | |
parent | cb239a2a5ec46086ce8c046e2db4cb7eb7b18181 (diff) |
Refactor the vyos_vrouter to adopt VNF abstraction
JIRA: FUNCTEST-788
1.Modifying code of vyos_vrouter to inherit vnf abstraction class.
2.Adding vyos_vrouter code from our repo to functest.
3.Adding unit test of vyos_vrouter.
4.Doing test of modified vyos_vrouter codes on our labs.
Change-Id: I77e4be8b2a140ea0176c607f2be736599f893ace
Signed-off-by: Shuya Nakama <shuya.nakama@okinawaopenlabs.org>
Diffstat (limited to 'functest/opnfv_tests/vnf/router/vrouter_base.py')
-rw-r--r-- | functest/opnfv_tests/vnf/router/vrouter_base.py | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/functest/opnfv_tests/vnf/router/vrouter_base.py b/functest/opnfv_tests/vnf/router/vrouter_base.py new file mode 100644 index 00000000..a534f1f2 --- /dev/null +++ b/functest/opnfv_tests/vnf/router/vrouter_base.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python + +# Copyright (c) 2017 Okinawa Open Laboratory 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 + +"""vrouter testing base class module""" + +import datetime +import json +import logging +import os +import pkg_resources +import time + +import functest.core.vnf as vnf +from functest.utils.constants import CONST +from functest.opnfv_tests.vnf.router.test_controller import function_test_exec +from functest.opnfv_tests.vnf.router.utilvnf import Utilvnf + +__author__ = "Shuya Nakama <shuya.nakama@okinawaopenlabs.org>" + +REBOOT_WAIT = 30 + + +class VrouterOnBoardingBase(vnf.VnfOnBoarding): + """vrouter testing base class""" + + def __init__(self, **kwargs): + self.logger = logging.getLogger(__name__) + super(VrouterOnBoardingBase, self).__init__(**kwargs) + self.case_dir = pkg_resources.resource_filename( + 'functest', 'opnfv_tests/vnf/router') + self.data_dir = CONST.__getattribute__('dir_router_data') + self.result_dir = os.path.join(CONST.__getattribute__('dir_results'), + self.case_name) + self.util = Utilvnf() + self.util_info = {} + + self.vnf_list = [] + + if not os.path.exists(self.data_dir): + os.makedirs(self.data_dir) + if not os.path.exists(self.result_dir): + os.makedirs(self.result_dir) + + def test_vnf(self): + """vrouter test execution""" + result = False + test_result_data_list = [] + test_scenario_file_path = os.path.join(self.case_dir, + self.util.test_scenario_yaml) + test_scenario_list = self.util.get_test_scenario( + test_scenario_file_path) + for test_scenario in test_scenario_list: + if test_scenario["test_type"] == "function_test": + function_test_list = test_scenario["function_test_list"] + for function_test in function_test_list: + test_list = function_test["test_list"] + target_vnf_name = function_test["target_vnf_name"] + for test_info in test_list: + self.logger.info(test_info["protocol"] + " " + + test_info["test_kind"] + + " test.") + (result, result_data) = self.function_test_vrouter( + target_vnf_name, + test_info) + test_result_data_list.append(result_data) + if not result: + break + + self.util.request_vm_delete(self.vnf_list) + + test_result_data = json.dumps(test_result_data_list, indent=4) + + return result, test_result_data + + def function_test_vrouter(self, target_vnf_name, test_info): + """function test execution""" + + test_protocol = test_info["protocol"] + test_list = test_info[test_protocol] + + vnf_info_list = self.get_vnf_info_list(target_vnf_name) + self.vnf_list = vnf_info_list + + self.logger.debug("request vnf's reboot.") + self.util.request_vnf_reboot(vnf_info_list) + time.sleep(REBOOT_WAIT) + + target_vnf = self.util.get_target_vnf(vnf_info_list) + + reference_vnf_list = self.util.get_reference_vnf_list(vnf_info_list) + + test_exec = function_test_exec.FunctionTestExec(self.util_info) + + # start test + start_time_ts = time.time() + self.logger.info("vRouter test Start Time:'%s'", ( + datetime.datetime.fromtimestamp(start_time_ts).strftime( + '%Y-%m-%d %H:%M:%S'))) + + (result, test_result_data) = test_exec.run(target_vnf, + reference_vnf_list, + test_info, + test_list) + + end_time_ts = time.time() + duration = round(end_time_ts - start_time_ts, 1) + self.logger.info("vRouter test duration :'%s'", duration) + + return result, test_result_data + + def get_vnf_info_list(self, target_vnf_name): + vnf_info_list = [] + return vnf_info_list |