aboutsummaryrefslogtreecommitdiffstats
path: root/functest/opnfv_tests/vnf/router/vnf_controller
diff options
context:
space:
mode:
Diffstat (limited to 'functest/opnfv_tests/vnf/router/vnf_controller')
-rw-r--r--functest/opnfv_tests/vnf/router/vnf_controller/checker.py10
-rw-r--r--functest/opnfv_tests/vnf/router/vnf_controller/command_generator.py12
-rw-r--r--functest/opnfv_tests/vnf/router/vnf_controller/ssh_client.py37
-rw-r--r--functest/opnfv_tests/vnf/router/vnf_controller/vm_controller.py33
-rw-r--r--functest/opnfv_tests/vnf/router/vnf_controller/vnf_controller.py35
5 files changed, 68 insertions, 59 deletions
diff --git a/functest/opnfv_tests/vnf/router/vnf_controller/checker.py b/functest/opnfv_tests/vnf/router/vnf_controller/checker.py
index 198a5ffc9..d3a216ed0 100644
--- a/functest/opnfv_tests/vnf/router/vnf_controller/checker.py
+++ b/functest/opnfv_tests/vnf/router/vnf_controller/checker.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
+
"""vrouter test result check module"""
import json
@@ -16,7 +18,7 @@ import re
from jinja2 import Environment, FileSystemLoader
-class Checker(object):
+class Checker():
"""vrouter test result check class"""
logger = logging.getLogger(__name__)
@@ -24,7 +26,8 @@ class Checker(object):
def __init__(self):
self.logger.debug("init checker")
- def load_check_rule(self, rule_file_dir, rule_file_name, parameter):
+ @staticmethod
+ def load_check_rule(rule_file_dir, rule_file_name, parameter):
loader = FileSystemLoader(rule_file_dir,
encoding='utf8')
env = Environment(loader=loader)
@@ -33,7 +36,8 @@ class Checker(object):
check_rule_data = json.loads(check_rule)
return check_rule_data
- def regexp_information(self, response, rules):
+ @staticmethod
+ def regexp_information(response, rules):
status = False
result_data = {}
diff --git a/functest/opnfv_tests/vnf/router/vnf_controller/command_generator.py b/functest/opnfv_tests/vnf/router/vnf_controller/command_generator.py
index 98cb14cc0..a86a16485 100644
--- a/functest/opnfv_tests/vnf/router/vnf_controller/command_generator.py
+++ b/functest/opnfv_tests/vnf/router/vnf_controller/command_generator.py
@@ -7,13 +7,15 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
"""command generator module for vrouter testing"""
import logging
from jinja2 import Environment, FileSystemLoader
-class CommandGenerator(object):
+class CommandGenerator():
"""command generator class for vrouter testing"""
logger = logging.getLogger(__name__)
@@ -21,12 +23,16 @@ class CommandGenerator(object):
def __init__(self):
self.logger.debug("init command generator")
- def load_template(self, template_dir, template):
+ @staticmethod
+ def load_template(template_dir, template):
+ # pylint disable=missing-docstring
loader = FileSystemLoader(template_dir,
encoding='utf8')
env = Environment(loader=loader)
return env.get_template(template)
- def command_create(self, template, parameter):
+ @staticmethod
+ def command_create(template, parameter):
+ # pylint disable=missing-docstring
commands = template.render(parameter)
return commands.split('\n')
diff --git a/functest/opnfv_tests/vnf/router/vnf_controller/ssh_client.py b/functest/opnfv_tests/vnf/router/vnf_controller/ssh_client.py
index c85a57351..269f6526b 100644
--- a/functest/opnfv_tests/vnf/router/vnf_controller/ssh_client.py
+++ b/functest/opnfv_tests/vnf/router/vnf_controller/ssh_client.py
@@ -10,10 +10,11 @@
"""ssh client module for vrouter testing"""
import logging
-import paramiko
import time
import yaml
+import paramiko
+
from functest.opnfv_tests.vnf.router.utilvnf import Utilvnf
RECEIVE_ROOP_WAIT = 1
@@ -23,7 +24,7 @@ DEFAULT_CONNECT_RETRY_COUNT = 10
DEFAULT_SEND_TIMEOUT = 10
-class SshClient(object):
+class SshClient(): # pylint: disable=too-many-instance-attributes
"""ssh client class for vrouter testing"""
logger = logging.getLogger(__name__)
@@ -42,7 +43,7 @@ class SshClient(object):
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.util = Utilvnf()
- 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()
@@ -51,6 +52,7 @@ class SshClient(object):
def connect(self, time_out=DEFAULT_CONNECT_TIMEOUT,
retrycount=DEFAULT_CONNECT_RETRY_COUNT):
+ # pylint: disable=missing-docstring
while retrycount > 0:
try:
self.logger.info("SSH connect to %s.", self.ip_address)
@@ -72,15 +74,14 @@ class SshClient(object):
self.shell.recv(self.ssh_revieve_buff)
break
- except: # pylint: disable=broad-except
+ except Exception: # pylint: disable=broad-except
self.logger.info("SSH timeout for %s...", self.ip_address)
time.sleep(time_out)
retrycount -= 1
if retrycount == 0:
- self.logger.error("Cannot establish connection to IP '%s'. " +
- "Aborting",
- self.ip_address)
+ self.logger.warning(
+ "Cannot establish connection to IP '%s'", self.ip_address)
self.connected = False
return self.connected
@@ -88,13 +89,14 @@ class SshClient(object):
return self.connected
def send(self, cmd, prompt, timeout=DEFAULT_SEND_TIMEOUT):
+ # pylint: disable=missing-docstring
if self.connected is True:
self.shell.settimeout(timeout)
self.logger.debug("Commandset : '%s'", cmd)
try:
self.shell.send(cmd + '\n')
- except: # pylint: disable=broad-except
+ except Exception: # pylint: disable=broad-except
self.logger.error("ssh send timeout : Command : '%s'", cmd)
return None
@@ -103,27 +105,28 @@ class SshClient(object):
time.sleep(RECEIVE_ROOP_WAIT)
try:
res = self.shell.recv(self.ssh_revieve_buff)
- except: # pylint: disable=broad-except
+ except Exception: # pylint: disable=broad-except
self.logger.error("ssh receive timeout : Command : '%s'",
cmd)
break
- res_buff += res
+ res_buff += res.decode("utf-8")
self.logger.debug("Response : '%s'", res_buff)
return res_buff
- else:
- self.logger.error("Cannot connected to IP '%s'.", self.ip_address)
- return None
+ self.logger.error("Cannot connected to IP '%s'.", self.ip_address)
+ return None
def close(self):
+ # pylint: disable=missing-docstring
if self.connected is True:
self.ssh.close()
- def error_check(response, err_strs=["error",
- "warn",
- "unknown command",
- "already exist"]):
+ @staticmethod
+ def error_check(response, err_strs=None):
+ # pylint: disable=missing-docstring
+ if err_strs is None:
+ err_strs = ["error", "warn", "unknown command", "already exist"]
for err in err_strs:
if err in response:
return False
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):
diff --git a/functest/opnfv_tests/vnf/router/vnf_controller/vnf_controller.py b/functest/opnfv_tests/vnf/router/vnf_controller/vnf_controller.py
index 814e9e333..46584456f 100644
--- a/functest/opnfv_tests/vnf/router/vnf_controller/vnf_controller.py
+++ b/functest/opnfv_tests/vnf/router/vnf_controller/vnf_controller.py
@@ -7,14 +7,17 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
"""vrouter controll module"""
import logging
import os
-import prettytable
import time
import yaml
+import prettytable
+
from functest.opnfv_tests.vnf.router.utilvnf import Utilvnf
from functest.opnfv_tests.vnf.router.vnf_controller.checker import Checker
from functest.opnfv_tests.vnf.router.vnf_controller.ssh_client import (
@@ -23,7 +26,7 @@ from functest.opnfv_tests.vnf.router.vnf_controller.vm_controller import (
VmController)
-class VnfController(object):
+class VnfController():
"""vrouter controll class"""
logger = logging.getLogger(__name__)
@@ -33,7 +36,7 @@ class VnfController(object):
self.util = Utilvnf()
self.vm_controller = VmController(util_info)
- 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()
@@ -45,10 +48,10 @@ class VnfController(object):
def config_vnf(self, source_vnf, destination_vnf, test_cmd_file_path,
parameter_file_path, prompt_file_path):
- parameter_file = open(parameter_file_path,
- 'r')
- cmd_input_param = yaml.safe_load(parameter_file)
- parameter_file.close()
+ # pylint: disable=too-many-arguments
+ with open(
+ parameter_file_path, 'r', encoding='utf-8') as parameter_file:
+ cmd_input_param = yaml.safe_load(parameter_file)
cmd_input_param["macaddress"] = source_vnf["data_plane_network_mac"]
cmd_input_param["source_ip"] = source_vnf["data_plane_network_ip"]
@@ -63,22 +66,20 @@ class VnfController(object):
def result_check(self, target_vnf, reference_vnf,
check_rule_file_path_list, parameter_file_path,
prompt_file_path):
+ # pylint: disable=too-many-arguments,too-many-locals
res_dict_data_list = []
- parameter_file = open(parameter_file_path,
- 'r')
- cmd_input_param = yaml.safe_load(parameter_file)
- parameter_file.close()
+ with open(
+ parameter_file_path, 'r', encoding='utf-8') as parameter_file:
+ cmd_input_param = yaml.safe_load(parameter_file)
cmd_input_param["source_ip"] = target_vnf["data_plane_network_ip"]
cmd_input_param["destination_ip"] = reference_vnf[
"data_plane_network_ip"]
- 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)
terminal_mode_prompt = prompt["terminal_mode"]
ssh = SshClient(target_vnf["floating_ip"],
@@ -93,8 +94,8 @@ class VnfController(object):
checker = Checker()
res_table = prettytable.PrettyTable(
- header_style='upper', padding_width=5,
- field_names=['test item', 'result'])
+ header_style='upper', padding_width=5,
+ field_names=['test item', 'result'])
status = True
res_data_list = []