From 7af574e792b1433191b5e470782fd09d4fd5a274 Mon Sep 17 00:00:00 2001 From: Romanos Skiadas Date: Thu, 8 Dec 2016 12:00:36 +0200 Subject: Remove needless returns, convert comments to docstrings Change-Id: I2ad10d68d71b2d29b68e8fb8b90ba633d67d75bc Signed-off-by: Romanos Skiadas --- tests/functest/odl-sfc/sfc-test2.py | 47 ++++++++++--------------------------- tests/functest/odl-sfc/utils.py | 6 +---- 2 files changed, 14 insertions(+), 39 deletions(-) (limited to 'tests') diff --git a/tests/functest/odl-sfc/sfc-test2.py b/tests/functest/odl-sfc/sfc-test2.py index b954d0d4..2c64a3d6 100755 --- a/tests/functest/odl-sfc/sfc-test2.py +++ b/tests/functest/odl-sfc/sfc-test2.py @@ -56,10 +56,9 @@ PROXY = { 'password': 'r00tme' } -# run given command locally and return commands output if success - def run_cmd(cmd, wdir=None, ignore_stderr=False, ignore_no_output=True): + """run given command locally and return command's output if success""" pipe = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, @@ -84,10 +83,9 @@ def run_cmd(cmd, wdir=None, ignore_stderr=False, ignore_no_output=True): return output -# run given command on OpenStack controller - def run_cmd_on_cntlr(cmd): + """run given command on first OpenStack controller""" ip_cntlrs = get_openstack_node_ips("controller") if not ip_cntlrs: return None @@ -95,10 +93,9 @@ def run_cmd_on_cntlr(cmd): ssh_cmd = "ssh %s %s %s" % (ssh_options, ip_cntlrs[0], cmd) return run_cmd_on_fm(ssh_cmd) -# run given command on OpenStack Compute node - def run_cmd_on_compute(cmd): + """run given command on first OpenStack Compute node""" ip_computes = get_openstack_node_ips("compute") if not ip_computes: return None @@ -106,28 +103,25 @@ def run_cmd_on_compute(cmd): ssh_cmd = "ssh %s %s %s" % (ssh_options, ip_computes[0], cmd) return run_cmd_on_fm(ssh_cmd) -# run given command on Fuel Master - def run_cmd_on_fm(cmd, username="root", passwd="r00tme"): + """run given command on Fuel Master""" ip = os.environ.get("INSTALLER_IP") ssh_cmd = "sshpass -p %s ssh %s %s@%s %s" % ( passwd, ssh_options, username, ip, cmd) return run_cmd(ssh_cmd) -# run given command on Remote Machine, Can be VM - def run_cmd_remote(ip, cmd, username="root", passwd="opnfv"): + """run given command on Remote Machine""" ssh_opt_append = "%s -o ConnectTimeout=50 " % ssh_options ssh_cmd = "sshpass -p %s ssh %s %s@%s %s" % ( passwd, ssh_opt_append, username, ip, cmd) return run_cmd(ssh_cmd) -# Get OpenStack Nodes IP Address - def get_openstack_node_ips(role): + """Get OpenStack Nodes IP Address""" fuel_env = os.environ.get("FUEL_ENV") if fuel_env is not None: cmd = "fuel2 node list -f json -e %s" % fuel_env @@ -143,10 +137,9 @@ def get_openstack_node_ips(role): return ips -# Configures IPTABLES on OpenStack Controller - def configure_iptables(): + """Configure IPTABLES on OpenStack Controller""" iptable_cmds = ["iptables -P INPUT ACCEPT", "iptables -t nat -P INPUT ACCEPT", "iptables -A INPUT -m state \ @@ -156,8 +149,6 @@ def configure_iptables(): logger.info("Configuring %s on contoller" % cmd) run_cmd_on_cntlr(cmd) - return - def download_image(): if not os.path.isfile(IMAGE_PATH): @@ -165,7 +156,6 @@ def download_image(): ft_utils.download_url(IMAGE_URL, IMAGE_DIR) logger.info("Using old image") - return def setup_glance(glance_client): @@ -205,7 +195,6 @@ def setup_ingress_egress_secgroup(neutron_client, protocol, 'egress', protocol, port_range_min=min_port, port_range_max=max_port) - return def setup_security_groups(neutron_client): @@ -330,18 +319,16 @@ def get_floating_ips(nova_client, neutron_client): return server_ip, client_ip, ips[1], ips[0] -# Start http server on a give machine, Can be VM - def start_http_server(ip): + """Start http server on a given machine""" cmd = "\'python -m SimpleHTTPServer 80" cmd = cmd + " > /dev/null 2>&1 &\'" return run_cmd_remote(ip, cmd) -# Set firewall using vxlan_tool.py on a give machine, Can be VM - def vxlan_firewall(sf, iface="eth0", port="22", block=True): + """Set firewall using vxlan_tool.py on a give machine""" cmd = "python vxlan_tool.py" cmd = cmd + " -i " + iface + " -d forward -v off" if block: @@ -350,18 +337,16 @@ def vxlan_firewall(sf, iface="eth0", port="22", block=True): cmd = "sh -c 'cd /root;nohup " + cmd + " > /dev/null 2>&1 &'" run_cmd_remote(sf, cmd) -# Stop the vxlan_tool process if it was working - # JIRA: SFC-52 added function def vxlan_tool_stop(sf): + """Stop the vxlan_tool process""" cmd = "pkill -f vxlan_tool.py" run_cmd_remote(sf, cmd) -# Run netcat on a give machine, Can be VM - def netcat(s_ip, c_ip, port="80", timeout=5): + """Run netcat on a give machine, Can be VM""" cmd = "nc -zv " cmd = cmd + " -w %s %s %s" % (timeout, s_ip, port) cmd = cmd + " 2>&1" @@ -398,7 +383,6 @@ def capture_err_logs(controller_clients, compute_clients, error): compute_clients, related_error=error, timestamp=timestamp) - return def update_json_results(name, result): @@ -406,8 +390,6 @@ def update_json_results(name, result): if result is not "Passed": json_results["failures"] += 1 - return - def get_ssh_clients(role): clients = [] @@ -419,10 +401,9 @@ def get_ssh_clients(role): return clients -# Check SSH connectivity to VNFs - def check_ssh(ips, retries=100): + """Check SSH connectivity to VNFs""" check = [False, False] logger.info("Checking SSH connectivity to the SFs with ips %s" % str(ips)) while retries and not all(check): @@ -438,10 +419,9 @@ def check_ssh(ips, retries=100): return False -# Measure the time it takes to update the classification rules - def capture_time_log(compute_clients): + """Measure the time it takes to update the classification rules""" ovs_logger = ovs_utils.OVSLogger( os.path.join(os.getcwd(), 'ovs-logs'), "test") @@ -466,7 +446,6 @@ def capture_time_log(compute_clients): logger.info("It took %s seconds" % difference) break time.sleep(1) - return def main(): diff --git a/tests/functest/odl-sfc/utils.py b/tests/functest/odl-sfc/utils.py index 9cbc9ddb..cf72bd3a 100644 --- a/tests/functest/odl-sfc/utils.py +++ b/tests/functest/odl-sfc/utils.py @@ -104,8 +104,6 @@ def configure_iptables(): logger.info("Configuring %s on contoller" % cmd) run_cmd_on_controller(cmd) - return - def download_image(url, image_path): image_filename = os.path.basename(image_path) @@ -143,7 +141,6 @@ def setup_ingress_egress_secgroup(neutron_client, protocol, 'egress', protocol, port_range_min=min_port, port_range_max=max_port) - return def create_security_groups(neutron_client, secgroup_name, secgroup_descr): @@ -310,7 +307,6 @@ def capture_err_logs(ovs_logger, controller_clients, compute_clients, error): compute_clients, related_error=error, timestamp=timestamp) - return def get_ssh_clients(role, proxy): @@ -340,8 +336,8 @@ def check_ssh(ips, retries=100): return False -# Measure the time it takes to update the classification rules def timethis(func): + """Measure the time it takes to update the classification rules""" @functools.wraps(func) def timed(*args, **kwargs): ts = time.time() -- cgit 1.2.3-korg