From 8bac97fb07e863573f5a2914058e1d23229d279b Mon Sep 17 00:00:00 2001 From: Tibor Frank Date: Wed, 23 Jan 2019 10:59:29 +0100 Subject: Fix PyLint errors Change-Id: I5a369f4b9f9b478375fda4a634bf57cc9623e972 Signed-off-by: Tibor Frank --- resources/libraries/python/ContainerUtils.py | 18 ++-- resources/libraries/python/DPDK/L3fwdTest.py | 25 ++--- resources/libraries/python/DropRateSearch.py | 36 +------ .../libraries/python/MLRsearch/NdrPdrResult.py | 5 +- .../python/MLRsearch/ReceiveRateInterval.py | 5 +- resources/libraries/python/Routing.py | 104 +++++++++------------ resources/libraries/python/VPPUtil.py | 4 +- resources/libraries/python/honeycomb/HcAPIKwACL.py | 15 ++- resources/libraries/python/honeycomb/Netconf.py | 6 +- .../libraries/python/honeycomb/Notifications.py | 6 +- resources/libraries/python/ssh.py | 12 ++- .../robot/honeycomb/access_control_lists.robot | 21 +++-- 12 files changed, 101 insertions(+), 156 deletions(-) (limited to 'resources') diff --git a/resources/libraries/python/ContainerUtils.py b/resources/libraries/python/ContainerUtils.py index 5fa0a575e9..11bb964665 100644 --- a/resources/libraries/python/ContainerUtils.py +++ b/resources/libraries/python/ContainerUtils.py @@ -183,9 +183,9 @@ class ContainerManager(object): container_vat_template, mid1=mid1, mid2=mid2, sid1=sid1, sid2=sid2, socket1='{dir}/memif-{c_name}-{sid}'. - format(c_name=c_name, sid=sid1, dir=guest_dir), + format(c_name=c_name, sid=sid1, dir=guest_dir), socket2='{dir}/memif-{c_name}-{sid}'. - format(c_name=c_name, sid=sid2, dir=guest_dir)) + format(c_name=c_name, sid=sid2, dir=guest_dir)) elif chain_topology == 'cross_horiz': if mod > 1: raise RuntimeError('Container chain topology {topology} ' @@ -206,21 +206,21 @@ class ContainerManager(object): c_name = self.engine.container.name guest_dir = self.engine.container.mnt[0].split(':')[1] if 'DUT1' in self.engine.container.name: - if_pci = Topology.get_interface_pci_addr( \ + if_pci = Topology.get_interface_pci_addr( self.engine.container.node, dut1_if) - if_name = Topology.get_interface_name( \ + if_name = Topology.get_interface_name( self.engine.container.node, dut1_if) if 'DUT2' in self.engine.container.name: - if_pci = Topology.get_interface_pci_addr( \ + if_pci = Topology.get_interface_pci_addr( self.engine.container.node, dut2_if) - if_name = Topology.get_interface_name( \ + if_name = Topology.get_interface_name( self.engine.container.node, dut2_if) self.engine.create_vpp_startup_config_dpdk_dev(if_pci) self.engine.create_vpp_exec_config( container_vat_template, mid1=mid1, sid1=sid1, if_name=if_name, socket1='{dir}/memif-{c_name}-{sid}'. - format(c_name=c_name, sid=sid1, dir=guest_dir)) + format(c_name=c_name, sid=sid1, dir=guest_dir)) elif chain_topology == 'chain_functional': for i, container in enumerate(self.containers): mid1 = i % mod + 1 @@ -236,9 +236,9 @@ class ContainerManager(object): container_vat_template, mid1=mid1, mid2=mid2, sid1=sid1, sid2=sid2, socket1='{dir}/memif-{c_name}-{sid}'. - format(c_name=c_name, sid=sid1, dir=guest_dir), + format(c_name=c_name, sid=sid1, dir=guest_dir), socket2='{dir}/memif-{c_name}-{sid}'. - format(c_name=c_name, sid=sid2, dir=guest_dir), + format(c_name=c_name, sid=sid2, dir=guest_dir), rx_mode=memif_rx_mode) else: raise RuntimeError('Container topology {topology} not implemented'. diff --git a/resources/libraries/python/DPDK/L3fwdTest.py b/resources/libraries/python/DPDK/L3fwdTest.py index 84c623e716..d4b9f16197 100644 --- a/resources/libraries/python/DPDK/L3fwdTest.py +++ b/resources/libraries/python/DPDK/L3fwdTest.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -19,6 +19,7 @@ from resources.libraries.python.ssh import SSH from resources.libraries.python.constants import Constants from resources.libraries.python.topology import NodeType, Topology + class L3fwdTest(object): """Test the DPDK l3fwd performance.""" @@ -50,35 +51,27 @@ class L3fwdTest(object): adj_mac0, adj_mac1 = L3fwdTest.get_adj_mac(nodes_info, dut_node, dut_if1, dut_if2) - list_cores = lcores_list.split(',') + list_cores = [int(item) for item in lcores_list.split(',')] # prepare the port config param + nb_cores = int(nb_cores) index = 0 port_config = '' for port in range(0, 2): for queue in range(0, int(queue_nums)): - if int(nb_cores) == 1: - index = 0 - temp_str = '({port}, {queue}, {core}),'.\ - format(port=port, queue=queue, - core=int(list_cores[index])) - else: - temp_str = '({port}, {queue}, {core}),'.\ - format(port=port, queue=queue, - core=int(list_cores[index])) - - port_config += temp_str - index = index + 1 + index = 0 if nb_cores == 1 else index + port_config += '({port}, {queue}, {core}),'.\ + format(port=port, queue=queue, core=list_cores[index]) + index += 1 ssh = SSH() ssh.connect(dut_node) - jumbo = 'yes' if jumbo_frames else 'no' cmd = '{fwdir}/tests/dpdk/dpdk_scripts/run_l3fwd.sh ' \ '"{lcores}" "{ports}" {mac1} {mac2} {jumbo}'.\ format(fwdir=Constants.REMOTE_FW_DIR, lcores=lcores_list, ports=port_config.rstrip(','), mac1=adj_mac0, - mac2=adj_mac1, jumbo=jumbo) + mac2=adj_mac1, jumbo='yes' if jumbo_frames else 'no') ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=600) if ret_code != 0: diff --git a/resources/libraries/python/DropRateSearch.py b/resources/libraries/python/DropRateSearch.py index 9b7c46668d..d090306cc5 100644 --- a/resources/libraries/python/DropRateSearch.py +++ b/resources/libraries/python/DropRateSearch.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -409,37 +409,7 @@ class DropRateSearch(object): res = self._get_res_based_on_search_type(res) - if self._search_linear_direction == SearchDirection.BOTTOM_UP: - # loss occurred and it was above acceptance criteria - if not res: - # if this is first run then we didn't find drop rate - if prev_rate is None: - self._search_result = SearchResults.FAILURE - self._search_result_rate = None - # else we found the rate, which is value from previous run - else: - self._search_result = SearchResults.SUCCESS - self._search_result_rate = prev_rate - return - # there was no loss / loss below acceptance criteria - elif res: - prev_rate = rate - rate += self._rate_linear_step - if rate > self._rate_max: - if prev_rate != self._rate_max: - # one last step with rate set to _rate_max - rate = self._rate_max - continue - else: - self._search_result = SearchResults.SUCCESS - self._search_result_rate = prev_rate - return - else: - continue - else: - raise RuntimeError("Unknown search result") - - elif self._search_linear_direction == SearchDirection.TOP_DOWN: + if self._search_linear_direction == SearchDirection.TOP_DOWN: # loss occurred, decrease rate if not res: prev_rate = rate @@ -465,8 +435,6 @@ class DropRateSearch(object): else: raise Exception("Unknown search direction") - raise Exception("Wrong codepath") - def verify_search_result(self): """Fail if search was not successful. diff --git a/resources/libraries/python/MLRsearch/NdrPdrResult.py b/resources/libraries/python/MLRsearch/NdrPdrResult.py index 80df0ef333..7b8cfd6449 100644 --- a/resources/libraries/python/MLRsearch/NdrPdrResult.py +++ b/resources/libraries/python/MLRsearch/NdrPdrResult.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -13,7 +13,8 @@ """Module defining NdrPdrResult class.""" -from ReceiveRateInterval import ReceiveRateInterval +from resources.libraries.python.MLRsearch.ReceiveRateInterval \ + import ReceiveRateInterval class NdrPdrResult(object): diff --git a/resources/libraries/python/MLRsearch/ReceiveRateInterval.py b/resources/libraries/python/MLRsearch/ReceiveRateInterval.py index 6dff1b8a7a..ec3cbb7462 100644 --- a/resources/libraries/python/MLRsearch/ReceiveRateInterval.py +++ b/resources/libraries/python/MLRsearch/ReceiveRateInterval.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -15,7 +15,8 @@ import math -from ReceiveRateMeasurement import ReceiveRateMeasurement +from resources.libraries.python.MLRsearch.ReceiveRateMeasurement \ + import ReceiveRateMeasurement class ReceiveRateInterval(object): diff --git a/resources/libraries/python/Routing.py b/resources/libraries/python/Routing.py index e6485ba3bc..a682c90102 100644 --- a/resources/libraries/python/Routing.py +++ b/resources/libraries/python/Routing.py @@ -22,81 +22,67 @@ class Routing(object): """Routing utilities.""" @staticmethod - def vpp_route_add(node, network, prefix_len, gateway=None, - interface=None, use_sw_index=True, resolve_attempts=10, - count=1, vrf=None, lookup_vrf=None, multipath=False, - weight=None, local=False): + def vpp_route_add(node, network, prefix_len, **kwargs): """Add route to the VPP node. :param node: Node to add route on. :param network: Route destination network address. :param prefix_len: Route destination network prefix length. - :param gateway: Route gateway address. - :param interface: Route interface. - :param vrf: VRF table ID (Optional). - :param use_sw_index: Use sw_if_index in VAT command. - :param resolve_attempts: Resolve attempts IP route add parameter. - :param count: number of IP addresses to add starting from network IP - :param local: The route is local - with same prefix (increment is 1). If None, then is not used. - :param lookup_vrf: VRF table ID for lookup. - :param multipath: Enable multipath routing. - :param weight: Weight value for unequal cost multipath routing. + :param kwargs: Optional key-value arguments: + + gateway: Route gateway address. (str) + interface: Route interface. (str) + vrf: VRF table ID. (int) + use_sw_index: Use sw_if_index in VAT command. (bool) + resolve_attempts: Resolve attempts IP route add parameter. (int) + count: number of IP addresses to add starting from network IP (int) + local: The route is local with same prefix (increment is 1). + If None, then is not used. (bool) + lookup_vrf: VRF table ID for lookup. (int) + multipath: Enable multipath routing. (bool) + weight: Weight value for unequal cost multipath routing. (int) + :type node: dict :type network: str :type prefix_len: int - :type gateway: str - :type interface: str - :type use_sw_index: bool - :type resolve_attempts: int - :type count: int - :type vrf: int - :type lookup_vrf: int - :type multipath: bool - :type weight: int - :type local: bool + :type kwargs: dict """ - if interface: + + gateway = kwargs.get("gateway", '') + intf = kwargs.get("interface", '') + use_sw_index = kwargs.get("use_sw_index", True) + resolve_attempts = kwargs.get("resolve_attempts", 10) + count = kwargs.get("count", 1) + vrf = kwargs.get("vrf", None) + l_vrf = kwargs.get("lookup_vrf", None) + multipath = kwargs.get("multipath", False) + weight = kwargs.get("weight", None) + local = kwargs.get("local", False) + + if intf: if use_sw_index: int_cmd = ('sw_if_index {}'. - format(Topology.get_interface_sw_index(node, - interface))) + format(Topology.get_interface_sw_index(node, intf))) else: - int_cmd = interface + int_cmd = intf else: int_cmd = '' - rap = 'resolve-attempts {}'.format(resolve_attempts) \ - if resolve_attempts else '' - - via = 'via {}'.format(gateway) if gateway else '' - - cnt = 'count {}'.format(count) \ - if count else '' - - vrf = 'vrf {}'.format(vrf) if vrf else '' - - lookup_vrf = 'lookup-in-vrf {}'.format(lookup_vrf) if lookup_vrf else '' - - multipath = 'multipath' if multipath else '' - - weight = 'weight {}'.format(weight) if weight else '' - - local = 'local' if local else '' - with VatTerminal(node, json_param=False) as vat: - vat.vat_terminal_exec_cmd_from_template('add_route.vat', - network=network, - prefix_length=prefix_len, - via=via, - vrf=vrf, - interface=int_cmd, - resolve_attempts=rap, - count=cnt, - lookup_vrf=lookup_vrf, - multipath=multipath, - weight=weight, - local=local) + vat.vat_terminal_exec_cmd_from_template( + 'add_route.vat', + network=network, + prefix_length=prefix_len, + via='via {}'.format(gateway) if gateway else '', + vrf='vrf {}'.format(vrf) if vrf else '', + interface=int_cmd, + resolve_attempts='resolve-attempts {}'. + format(resolve_attempts) if resolve_attempts else '', + count='count {}'.format(count) if count else '', + lookup_vrf='lookup-in-vrf {}'.format(l_vrf) if l_vrf else '', + multipath='multipath' if multipath else '', + weight='weight {}'.format(weight) if weight else '', + local='local' if local else '') @staticmethod def add_fib_table(node, table_id, ipv6=False): diff --git a/resources/libraries/python/VPPUtil.py b/resources/libraries/python/VPPUtil.py index d6c02a3e8a..63d9aaca86 100644 --- a/resources/libraries/python/VPPUtil.py +++ b/resources/libraries/python/VPPUtil.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -79,7 +79,7 @@ class VPPUtil(object): break else: raise RuntimeError('VPP failed to start on host {name}'. - format(name=node['host'])) + format(name=node['host'])) DUTSetup.get_service_logs(node, Constants.VPP_UNIT) @staticmethod diff --git a/resources/libraries/python/honeycomb/HcAPIKwACL.py b/resources/libraries/python/honeycomb/HcAPIKwACL.py index 19cdb37c47..b2848411a1 100644 --- a/resources/libraries/python/honeycomb/HcAPIKwACL.py +++ b/resources/libraries/python/honeycomb/HcAPIKwACL.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -13,6 +13,8 @@ """This module implements keywords to manipulate ACL data structures using Honeycomb REST API.""" + + from robot.api import logger from resources.libraries.python.topology import Topology @@ -255,17 +257,15 @@ class ACLKeywords(object): " under ACL table {1}.".format(session_match, table_name)) @staticmethod - def create_acl_plugin_classify_chain(node, list_name, data, macip=False): + def create_acl_plugin_classify_chain(node, list_name, data): """Create classify chain using the ietf-acl node. :param node: Honeycomb node. :param list_name: Name for the classify list. :param data: Dictionary of settings to send to Honeycomb. - :param macip: Use simple MAC+IP classifier. Optional. :type node: dict :type list_name: str :type data: dict - :type macip: bool :returns: Content of response. :rtype: bytearray :raises HoneycombError: If the operation fails. @@ -284,21 +284,18 @@ class ACLKeywords(object): return resp @staticmethod - def set_acl_plugin_interface(node, interface, acl_name, - direction, macip=False): + def set_acl_plugin_interface(node, interface, acl_name, direction): """Assign an interface to an ietf-acl classify chain. :param node: Honeycomb node. :param interface: Name of an interface on the node. :param acl_name: Name of an ACL chain configured through ACL-plugin. - :param direction: Classify incoming or outgiong packets. + :param direction: Classify incoming or outgoing packets. Valid options are: ingress, egress - :param macip: Use simple MAC+IP classifier. Optional. :type node: dict :type interface: str or int :type acl_name: str :type direction: str - :type macip: bool :returns: Content of response. :rtype: bytearray :raises ValueError: If the direction argument is incorrect. diff --git a/resources/libraries/python/honeycomb/Netconf.py b/resources/libraries/python/honeycomb/Netconf.py index 303361034e..caca14ed1a 100644 --- a/resources/libraries/python/honeycomb/Netconf.py +++ b/resources/libraries/python/honeycomb/Netconf.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -126,14 +126,12 @@ class Netconf(object): logger.trace(reply) return reply.replace(self.delimiter, "") - def get_all_responses(self, size=4096, time_out=3): + def get_all_responses(self, size=4096): """Read responses from the receive buffer and catenate together until a read operation times out. :param size: Maximum number of bytes to read in one iteration. - :param time_out: Timeout value for getting the complete response. :type size: int - :type time_out: int :returns: Content of response. :rtype: str """ diff --git a/resources/libraries/python/honeycomb/Notifications.py b/resources/libraries/python/honeycomb/Notifications.py index 7bba00a2d2..38f1fd3093 100644 --- a/resources/libraries/python/honeycomb/Notifications.py +++ b/resources/libraries/python/honeycomb/Notifications.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -27,14 +27,12 @@ class Notifications(Netconf): - read received notifications """ - def add_notification_listener(self, subscription, time_out=10): + def add_notification_listener(self, subscription): """Open a new channel on the SSH session, connect to Netconf subsystem and subscribe to receive Honeycomb notifications. :param subscription: RPC for subscription to notifications. - :param time_out: Timeout value for each read operation in seconds. :type subscription: str - :type time_out: int :raises HoneycombError: If subscription to notifications fails. """ diff --git a/resources/libraries/python/ssh.py b/resources/libraries/python/ssh.py index 4beec5aa83..a23d163768 100644 --- a/resources/libraries/python/ssh.py +++ b/resources/libraries/python/ssh.py @@ -13,15 +13,17 @@ """Library for SSH connection management.""" -import paramiko + import socket import StringIO -from paramiko import RSAKey +from time import time, sleep + +from paramiko import RSAKey, SSHClient, AutoAddPolicy from paramiko.ssh_exception import SSHException, NoValidConnectionsError from robot.api import logger from scp import SCPClient -from time import time, sleep + __all__ = ["exec_cmd", "exec_cmd_no_error"] @@ -86,8 +88,8 @@ class SSH(object): pkey = RSAKey.from_private_key( StringIO.StringIO(node['priv_key'])) - self._ssh = paramiko.SSHClient() - self._ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + self._ssh = SSHClient() + self._ssh.set_missing_host_key_policy(AutoAddPolicy()) self._ssh.connect(node['host'], username=node['username'], password=node.get('password'), pkey=pkey, diff --git a/resources/libraries/robot/honeycomb/access_control_lists.robot b/resources/libraries/robot/honeycomb/access_control_lists.robot index 4a68878144..37cd03c6be 100644 --- a/resources/libraries/robot/honeycomb/access_control_lists.robot +++ b/resources/libraries/robot/honeycomb/access_control_lists.robot @@ -1,4 +1,4 @@ -# Copyright (c) 2017 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -10,6 +10,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + *** Variables *** #TODO: update based on resolution of bug https://jira.fd.io/browse/HONEYCOMB-119 @@ -356,7 +357,7 @@ | | [Arguments] | ${node} | ${acl_list_name} | ${acl_list_settings} | | ... | ${macip}=${False} | | Create ACL plugin classify chain -| | ... | ${node} | ${acl_list_name} | ${acl_list_settings} | ${macip} +| | ... | ${node} | ${acl_list_name} | ${acl_list_settings} | Honeycomb assigns plugin-ACL chain to interface | | [Documentation] | Applies classification through the high-level\ @@ -377,7 +378,7 @@ | | ... | ${node} | ${interface} | ${acl_list_name} | ${direction} | | ... | ${macip}=${False} | | Set ACL plugin interface -| | ... | ${node} | ${interface} | ${acl_list_name} | ${direction} | ${macip} +| | ... | ${node} | ${interface} | ${acl_list_name} | ${direction} | Clear plugin-ACL configuration | | [Documentation] | Removes ACl assignment from interface, then deletes\ @@ -438,12 +439,12 @@ | | ${tx_port_name}= | Get interface name | ${tg_node} | ${tx_port} | | ${rx_port_name}= | Get interface name | ${tg_node} | ${rx_port} | | ${args}= | Catenate | --src_mac | ${tx_mac} -| | ... | --dst_mac | ${rx_mac} -| | ... | --src_ip | ${src_ip} -| | ... | --dst_ip | ${dst_ip} -| | ... | --tx_if | ${tx_port_name} -| | ... | --rx_if | ${rx_port_name} -| | ... | --icmp_type | ${icmp_type} -| | ... | --icmp_code | ${icmp_code} +| | ... | --dst_mac | ${rx_mac} +| | ... | --src_ip | ${src_ip} +| | ... | --dst_ip | ${dst_ip} +| | ... | --tx_if | ${tx_port_name} +| | ... | --rx_if | ${rx_port_name} +| | ... | --icmp_type | ${icmp_type} +| | ... | --icmp_code | ${icmp_code} | | Run Traffic Script On Node | send_icmp_type_code.py | | ... | ${tg_node} | ${args} -- cgit 1.2.3-korg