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 controll module"""
21 from functest.opnfv_tests.vnf.router.utilvnf import Utilvnf
22 from functest.opnfv_tests.vnf.router.vnf_controller.checker import Checker
23 from functest.opnfv_tests.vnf.router.vnf_controller.ssh_client import (
25 from functest.opnfv_tests.vnf.router.vnf_controller.vm_controller import (
29 class VnfController(object):
30 """vrouter controll class"""
32 logger = logging.getLogger(__name__)
34 def __init__(self, util_info):
35 self.logger.debug("init vnf controller")
37 self.vm_controller = VmController(util_info)
39 with open(self.util.test_env_config_yaml) as file_fd:
40 test_env_config_yaml = yaml.safe_load(file_fd)
43 self.cmd_wait = test_env_config_yaml.get("general").get("command_wait")
44 self.ssh_connect_timeout = test_env_config_yaml.get("general").get(
45 "ssh_connect_timeout")
46 self.ssh_connect_retry_count = test_env_config_yaml.get("general").get(
47 "ssh_connect_retry_count")
49 def config_vnf(self, source_vnf, destination_vnf, test_cmd_file_path,
50 parameter_file_path, prompt_file_path):
51 # pylint: disable=too-many-arguments
52 parameter_file = open(parameter_file_path,
54 cmd_input_param = yaml.safe_load(parameter_file)
55 parameter_file.close()
57 cmd_input_param["macaddress"] = source_vnf["data_plane_network_mac"]
58 cmd_input_param["source_ip"] = source_vnf["data_plane_network_ip"]
59 cmd_input_param["destination_ip"] = destination_vnf[
60 "data_plane_network_ip"]
62 return self.vm_controller.config_vm(source_vnf,
67 def result_check(self, target_vnf, reference_vnf,
68 check_rule_file_path_list, parameter_file_path,
70 # pylint: disable=too-many-arguments,too-many-locals
72 res_dict_data_list = []
74 parameter_file = open(parameter_file_path,
76 cmd_input_param = yaml.safe_load(parameter_file)
77 parameter_file.close()
79 cmd_input_param["source_ip"] = target_vnf["data_plane_network_ip"]
80 cmd_input_param["destination_ip"] = reference_vnf[
81 "data_plane_network_ip"]
83 prompt_file = open(prompt_file_path,
85 prompt = yaml.safe_load(prompt_file)
87 terminal_mode_prompt = prompt["terminal_mode"]
89 ssh = SshClient(target_vnf["floating_ip"],
93 result = ssh.connect(self.ssh_connect_timeout,
94 self.ssh_connect_retry_count)
96 return False, res_dict_data_list
100 res_table = prettytable.PrettyTable(
101 header_style='upper', padding_width=5,
102 field_names=['test item', 'result'])
106 for check_rule_file_path in check_rule_file_path_list:
107 (check_rule_dir, check_rule_file) = os.path.split(
108 check_rule_file_path)
109 check_rules = checker.load_check_rule(check_rule_dir,
112 (res, res_data) = self.vm_controller.command_execute(
114 check_rules["command"],
115 terminal_mode_prompt)
116 res_data_list.append(res_data)
121 (res, res_dict_data) = checker.regexp_information(res_data,
123 res_dict_data_list.append(res_dict_data)
124 res_table.add_row([res_dict_data["test_name"],
125 res_dict_data["result"]])
129 time.sleep(self.cmd_wait)
133 self.logger.info("Test result:\n\n%s\n", res_table.get_string())
135 self.output_check_result_detail_data(res_data_list)
137 return status, res_dict_data_list
139 def output_check_result_detail_data(self, res_data_list):
140 for res_data in res_data_list:
141 self.logger.debug(res_data)