Fix fail of vRouter on Orange POD
[functest.git] / functest / opnfv_tests / vnf / router / vrouter_base.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2017 Okinawa Open Laboratory and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 """vrouter testing base class module"""
11
12 import datetime
13 import json
14 import logging
15 import os
16 import pkg_resources
17 import time
18
19 import functest.core.vnf as vnf
20 from functest.utils.constants import CONST
21 from functest.opnfv_tests.vnf.router.test_controller import function_test_exec
22 from functest.opnfv_tests.vnf.router.utilvnf import Utilvnf
23
24 __author__ = "Shuya Nakama <shuya.nakama@okinawaopenlabs.org>"
25
26 REBOOT_WAIT = 30
27
28
29 class VrouterOnBoardingBase(vnf.VnfOnBoarding):
30     """vrouter testing base class"""
31
32     def __init__(self, **kwargs):
33         self.logger = logging.getLogger(__name__)
34         super(VrouterOnBoardingBase, self).__init__(**kwargs)
35         self.case_dir = pkg_resources.resource_filename(
36             'functest', 'opnfv_tests/vnf/router')
37         self.data_dir = CONST.__getattribute__('dir_router_data')
38         self.result_dir = os.path.join(CONST.__getattribute__('dir_results'),
39                                        self.case_name)
40         self.util = Utilvnf()
41         self.util_info = {}
42
43         self.vnf_list = []
44
45         if not os.path.exists(self.data_dir):
46             os.makedirs(self.data_dir)
47         if not os.path.exists(self.result_dir):
48             os.makedirs(self.result_dir)
49
50     def test_vnf(self):
51         """vrouter test execution"""
52         result = False
53         test_result_data_list = []
54         test_scenario_file_path = os.path.join(self.case_dir,
55                                                self.util.test_scenario_yaml)
56         test_scenario_list = self.util.get_test_scenario(
57             test_scenario_file_path)
58         for test_scenario in test_scenario_list:
59             if test_scenario["test_type"] == "function_test":
60                 function_test_list = test_scenario["function_test_list"]
61                 for function_test in function_test_list:
62                     test_list = function_test["test_list"]
63                     target_vnf_name = function_test["target_vnf_name"]
64                     for test_info in test_list:
65                         self.logger.info(test_info["protocol"] + " " +
66                                          test_info["test_kind"] +
67                                          " test.")
68                         (result, result_data) = self.function_test_vrouter(
69                                                     target_vnf_name,
70                                                     test_info)
71                         test_result_data_list.append(result_data)
72                         if not result:
73                             break
74
75         self.util.request_vm_delete(self.vnf_list)
76
77         test_result_data = json.dumps(test_result_data_list, indent=4)
78
79         return result, test_result_data
80
81     def function_test_vrouter(self, target_vnf_name, test_info):
82         """function test execution"""
83
84         test_protocol = test_info["protocol"]
85         test_list = test_info[test_protocol]
86
87         vnf_info_list = self.get_vnf_info_list(target_vnf_name)
88         self.vnf_list = vnf_info_list
89
90         self.logger.debug("request vnf's reboot.")
91         self.util.request_vnf_reboot(vnf_info_list)
92         time.sleep(REBOOT_WAIT)
93
94         target_vnf = self.util.get_target_vnf(vnf_info_list)
95
96         reference_vnf_list = self.util.get_reference_vnf_list(vnf_info_list)
97
98         test_exec = function_test_exec.FunctionTestExec(self.util_info)
99
100         # start test
101         start_time_ts = time.time()
102         self.logger.info("vRouter test Start Time:'%s'", (
103             datetime.datetime.fromtimestamp(start_time_ts).strftime(
104                 '%Y-%m-%d %H:%M:%S')))
105
106         (result, test_result_data) = test_exec.run(target_vnf,
107                                                    reference_vnf_list,
108                                                    test_info,
109                                                    test_list)
110
111         end_time_ts = time.time()
112         duration = round(end_time_ts - start_time_ts, 1)
113         self.logger.info("vRouter test duration :'%s'", duration)
114
115         return result, test_result_data
116
117     def get_vnf_info_list(self, target_vnf_name):
118         vnf_info_list = []
119         return vnf_info_list