diff options
Diffstat (limited to 'functest/opnfv_tests/vnf/router/vnf_controller/vm_controller.py')
-rw-r--r-- | functest/opnfv_tests/vnf/router/vnf_controller/vm_controller.py | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/functest/opnfv_tests/vnf/router/vnf_controller/vm_controller.py b/functest/opnfv_tests/vnf/router/vnf_controller/vm_controller.py index d1c2e3242..2210b3909 100644 --- a/functest/opnfv_tests/vnf/router/vnf_controller/vm_controller.py +++ b/functest/opnfv_tests/vnf/router/vnf_controller/vm_controller.py @@ -7,6 +7,8 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 +# pylint: disable=missing-docstring + """vm controll module""" import logging @@ -21,7 +23,7 @@ from functest.opnfv_tests.vnf.router.vnf_controller.ssh_client import ( SshClient) -class VmController(object): +class VmController(): """vm controll class""" logger = logging.getLogger(__name__) @@ -32,14 +34,12 @@ class VmController(object): credentials = util_info["credentials"] self.util = Utilvnf() - self.util.set_credentials(credentials["snaps_creds"]) + self.util.set_credentials(credentials["cloud"]) - with open(self.util.test_env_config_yaml) as file_fd: + with open(self.util.test_env_config_yaml, encoding='utf-8') as file_fd: test_env_config_yaml = yaml.safe_load(file_fd) file_fd.close() - self.reboot_wait = test_env_config_yaml.get("general").get( - "reboot_wait") self.command_wait = test_env_config_yaml.get("general").get( "command_wait") self.ssh_connect_timeout = test_env_config_yaml.get("general").get( @@ -83,13 +83,10 @@ class VmController(object): result = ssh.connect(self.ssh_connect_timeout, self.ssh_connect_retry_count) if not result: - self.logger.debug("try to vm reboot.") - self.util.reboot_vm(vm_info["vnf_name"]) - time.sleep(self.reboot_wait) - result = ssh.connect(self.ssh_connect_timeout, - self.ssh_connect_retry_count) - if not result: - return None + self.logger.error( + "Cannot establish connection to IP '%s'. Aborting!", + ssh.ip_address) + return None (result, _) = self.command_create_and_execute( ssh, @@ -104,10 +101,8 @@ class VmController(object): def command_create_and_execute(self, ssh, test_cmd_file_path, cmd_input_param, prompt_file_path): - prompt_file = open(prompt_file_path, - 'r') - prompt = yaml.safe_load(prompt_file) - prompt_file.close() + with open(prompt_file_path, 'r', encoding='utf-8') as prompt_file: + prompt = yaml.safe_load(prompt_file) config_mode_prompt = prompt["config_mode"] commands = self.command_gen_from_template(test_cmd_file_path, @@ -119,11 +114,11 @@ class VmController(object): def command_list_execute(self, ssh, command_list, prompt): res_data_list = [] for command in command_list: - self.logger.debug("Command : " + command) + self.logger.debug("Command : %s", command) (res, res_data) = self.command_execute(ssh, command, prompt) - self.logger.debug("Response : " + res_data) + self.logger.debug("Response : %s", res_data) res_data_list.append(res_data) if not res: return res, res_data_list @@ -135,7 +130,7 @@ class VmController(object): def command_execute(self, ssh, command, prompt): res_data = ssh.send(command, prompt) if res_data is None: - self.logger.info("retry send command : " + command) + self.logger.info("retry send command : %s", command) res_data = ssh.send(command, prompt) if not ssh.error_check(res_data): |