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 """vrouter function test execution module"""
16 from functest.opnfv_tests.vnf.router.utilvnf import Utilvnf
17 from functest.opnfv_tests.vnf.router.vnf_controller.vnf_controller import (
21 class FunctionTestExec(object):
22 """vrouter function test execution class"""
24 logger = logging.getLogger(__name__)
26 def __init__(self, util_info):
27 self.logger.debug("init test exec")
29 credentials = util_info["credentials"]
30 self.vnf_ctrl = VnfController(util_info)
32 test_cmd_map_file = open(self.util.vnf_data_dir +
33 self.util.opnfv_vnf_data_dir +
34 self.util.command_template_dir +
35 self.util.test_cmd_map_yaml_file,
37 self.test_cmd_map_yaml = yaml.safe_load(test_cmd_map_file)
38 test_cmd_map_file.close()
40 self.util.set_credentials(credentials["username"],
41 credentials["password"],
42 credentials["auth_url"],
43 credentials["tenant_name"],
44 credentials["region_name"])
46 with open(self.util.test_env_config_yaml) as file_fd:
47 test_env_config_yaml = yaml.safe_load(file_fd)
50 self.protocol_stable_wait = test_env_config_yaml.get("general").get(
51 "protocol_stable_wait")
53 def config_target_vnf(self, target_vnf, reference_vnf, test_kind):
54 self.logger.debug("Configuration to target vnf")
55 test_info = self.test_cmd_map_yaml[target_vnf["os_type"]]
56 test_cmd_file_path = test_info[test_kind]["pre_command_target"]
57 target_parameter_file_path = test_info[test_kind]["parameter_target"]
58 prompt_file_path = test_info["prompt"]
60 return self.vnf_ctrl.config_vnf(target_vnf,
63 target_parameter_file_path,
66 def config_reference_vnf(self, target_vnf, reference_vnf, test_kind):
67 self.logger.debug("Configuration to reference vnf")
68 test_info = self.test_cmd_map_yaml[reference_vnf["os_type"]]
69 test_cmd_file_path = test_info[test_kind]["pre_command_reference"]
70 reference_parameter_file_path = test_info[test_kind][
71 "parameter_reference"]
72 prompt_file_path = test_info["prompt"]
74 return self.vnf_ctrl.config_vnf(reference_vnf,
77 reference_parameter_file_path,
80 def result_check(self, target_vnf, reference_vnf, test_kind, test_list):
81 test_info = self.test_cmd_map_yaml[target_vnf["os_type"]]
82 target_parameter_file_path = test_info[test_kind]["parameter_target"]
83 prompt_file_path = test_info["prompt"]
84 check_rule_file_path_list = []
86 for test in test_list:
87 check_rule_file_path_list.append(test_info[test_kind][test])
89 return self.vnf_ctrl.result_check(target_vnf,
91 check_rule_file_path_list,
92 target_parameter_file_path,
95 def run(self, target_vnf, reference_vnf_list, test_info, test_list):
97 test_kind = test_info["protocol"]
98 for reference_vnf in reference_vnf_list:
99 self.logger.debug("Start config command " +
100 target_vnf["vnf_name"] + " and " +
101 reference_vnf["vnf_name"])
103 result = self.config_target_vnf(target_vnf,
107 return False, test_result_data
109 result = self.config_reference_vnf(target_vnf,
113 return False, test_result_data
115 self.logger.debug("Finish config command.")
117 self.logger.debug("Waiting for protocol stable.")
118 time.sleep(self.protocol_stable_wait)
120 self.logger.debug("Start check method")
122 (result, res_dict_data_list) = self.result_check(target_vnf,
127 test_result_data = {"test_kind": test_info["test_kind"],
128 "protocol": test_info["protocol"],
129 "result": res_dict_data_list}
132 self.logger.debug("Error check method.")
133 return False, test_result_data
135 self.logger.debug("Finish check method.")
137 return True, test_result_data