3 # Copyright (c) 2017 Okinawa Open Laboratory and others.
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
10 # pylint: disable=missing-docstring
12 """vrouter function test execution module"""
19 from functest.opnfv_tests.vnf.router.utilvnf import Utilvnf
20 from functest.opnfv_tests.vnf.router.vnf_controller.vnf_controller import (
24 class FunctionTestExec():
25 """vrouter function test execution class"""
27 logger = logging.getLogger(__name__)
29 def __init__(self, util_info):
30 self.logger.debug("init test exec")
32 credentials = util_info["credentials"]
33 self.vnf_ctrl = VnfController(util_info)
35 test_cmd_map_file = open(
37 self.util.vnf_data_dir, self.util.command_template_dir,
38 self.util.test_cmd_map_yaml_file),
40 self.test_cmd_map_yaml = yaml.safe_load(test_cmd_map_file)
41 test_cmd_map_file.close()
43 self.util.set_credentials(credentials["cloud"])
45 with open(self.util.test_env_config_yaml) as file_fd:
46 test_env_config_yaml = yaml.safe_load(file_fd)
49 self.protocol_stable_wait = test_env_config_yaml.get("general").get(
50 "protocol_stable_wait")
52 def config_target_vnf(self, target_vnf, reference_vnf, test_kind):
53 self.logger.debug("Configuration to target vnf")
54 test_info = self.test_cmd_map_yaml[target_vnf["os_type"]]
55 test_cmd_file_path = test_info[test_kind]["pre_command_target"]
56 target_parameter_file_path = test_info[test_kind]["parameter_target"]
57 prompt_file_path = test_info["prompt"]
59 return self.vnf_ctrl.config_vnf(target_vnf,
62 target_parameter_file_path,
65 def config_reference_vnf(self, target_vnf, reference_vnf, test_kind):
66 self.logger.debug("Configuration to reference vnf")
67 test_info = self.test_cmd_map_yaml[reference_vnf["os_type"]]
68 test_cmd_file_path = test_info[test_kind]["pre_command_reference"]
69 reference_parameter_file_path = test_info[test_kind][
70 "parameter_reference"]
71 prompt_file_path = test_info["prompt"]
73 return self.vnf_ctrl.config_vnf(reference_vnf,
76 reference_parameter_file_path,
79 def result_check(self, target_vnf, reference_vnf, test_kind, test_list):
80 test_info = self.test_cmd_map_yaml[target_vnf["os_type"]]
81 target_parameter_file_path = test_info[test_kind]["parameter_target"]
82 prompt_file_path = test_info["prompt"]
83 check_rule_file_path_list = []
85 for test in test_list:
86 check_rule_file_path_list.append(test_info[test_kind][test])
88 return self.vnf_ctrl.result_check(target_vnf,
90 check_rule_file_path_list,
91 target_parameter_file_path,
94 def run(self, target_vnf, reference_vnf_list, test_info, test_list):
96 test_kind = test_info["protocol"]
97 for reference_vnf in reference_vnf_list:
98 self.logger.debug("Start config command " +
99 target_vnf["vnf_name"] + " and " +
100 reference_vnf["vnf_name"])
102 result = self.config_target_vnf(target_vnf,
106 return False, test_result_data
108 result = self.config_reference_vnf(target_vnf,
112 return False, test_result_data
114 self.logger.debug("Finish config command.")
116 self.logger.debug("Waiting for protocol stable.")
117 time.sleep(self.protocol_stable_wait)
119 self.logger.debug("Start check method")
121 (result, res_dict_data_list) = self.result_check(target_vnf,
126 test_result_data = {"test_kind": test_info["test_kind"],
127 "protocol": test_info["protocol"],
128 "result": res_dict_data_list}
131 self.logger.debug("Error check method.")
132 return False, test_result_data
134 self.logger.debug("Finish check method.")
136 return True, test_result_data