From ca9c9275ed6d5d852987c69a378e88a3502cb2ab Mon Sep 17 00:00:00 2001 From: goldammx Date: Thu, 9 Feb 2017 08:03:00 -0500 Subject: pylint: Fixing pylint errors and warnings All python files must reach pylint score 10/10. This will be regularly verified by Jenkins jobs to keep constant code quality. VSPERF specific pylintrc file was updated according to the vsperf coding standards. Distro version included in reports will be slightly different, due to migration to new python package distro. Previously used platform.distro() will be deprecated since python 3.7. JIRA: VSPERF-487 Change-Id: I934120208b9624787a3567ccaa49e14d77d7a5bf Signed-off-by: Martin Goldammer Reviewed-by: Martin Klozik Reviewed-by: Al Morton Reviewed-by: Christian Trautman Reviewed-by: Bill Michalowski Reviewed-by: Antonio Fischetti Reviewed-by: Sridhar Rao --- tools/pkt_gen/dummy/dummy.py | 28 ++++++- tools/pkt_gen/ixia/ixia.py | 34 ++++++-- tools/pkt_gen/ixnet/ixnet.py | 12 ++- .../pkt_gen/testcenter/testcenter-rfc2544-rest.py | 90 +++++++++++----------- .../pkt_gen/testcenter/testcenter-rfc2889-rest.py | 7 +- tools/pkt_gen/testcenter/testcenter.py | 21 +++++ tools/pkt_gen/xena/XenaDriver.py | 21 ++--- tools/pkt_gen/xena/xena_json.py | 8 +- 8 files changed, 143 insertions(+), 78 deletions(-) (limited to 'tools/pkt_gen') diff --git a/tools/pkt_gen/dummy/dummy.py b/tools/pkt_gen/dummy/dummy.py index 7a4daab6..3dc5448e 100755 --- a/tools/pkt_gen/dummy/dummy.py +++ b/tools/pkt_gen/dummy/dummy.py @@ -1,4 +1,4 @@ -# Copyright 2015-2016 Intel Corporation. +# Copyright 2015-2017 Intel Corporation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -59,7 +59,6 @@ def _get_user_traffic_stat(stat_type): else: print('Please respond with \'yes\' or \'no\' ', end='') - def get_user_traffic(traffic_type, traffic_conf, flow_conf, traffic_stats): """ Request user input for traffic. @@ -229,15 +228,36 @@ class Dummy(trafficgen.ITrafficGenerator): traffic_, ('b2b frames', 'b2b frame loss %')) - framesize = traffic_['l2']['framesize'] - # builds results by using user-supplied values # and guessing remainder using available info result[ResultsConstants.B2B_FRAMES] = float(results[0]) result[ResultsConstants.B2B_FRAME_LOSS_PERCENT] = float(results[1]) return result + def start_cont_traffic(self, traffic=None, duration=20): + return NotImplementedError('Dummy does not implement start_cont_traffic') + + def stop_cont_traffic(self): + return NotImplementedError( + 'Dummy does not implement stop_cont_traffic') + + def start_rfc2544_back2back(self, traffic=None, tests=1, duration=20, + lossrate=0.0): + return NotImplementedError( + 'Dummy does not implement start_rfc2544_back2back') + + def wait_rfc2544_back2back(self): + return NotImplementedError( + 'Dummy does not implement stop_cont_traffic') + + def start_rfc2544_throughput(self, traffic=None, tests=1, duration=20, + lossrate=0.0): + return NotImplementedError( + 'Dummy does not implement start_rfc2544_throughput') + def wait_rfc2544_throughput(self): + return NotImplementedError( + 'Dummy does not implement wait_rfc2544_throughput') if __name__ == '__main__': TRAFFIC = { diff --git a/tools/pkt_gen/ixia/ixia.py b/tools/pkt_gen/ixia/ixia.py index ed947e70..13c1a9a7 100755 --- a/tools/pkt_gen/ixia/ixia.py +++ b/tools/pkt_gen/ixia/ixia.py @@ -1,4 +1,4 @@ -# Copyright 2015-2016 Intel Corporation. +# Copyright 2015-2017 Intel Corporation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -33,7 +33,6 @@ This requires the following settings in your config file: If any of these don't exist, the application will raise an exception (EAFP). """ - import tkinter import logging import os @@ -106,9 +105,7 @@ def _build_set_cmds(values, prefix='dict set'): for key in values: value = values[key] - # Not allowing derived dictionary types for now - # pylint: disable=unidiomatic-typecheck - if type(value) == dict: + if isinstance(value, dict): _prefix = ' '.join([prefix, key]).strip() for subkey in _build_set_cmds(value, _prefix): yield subkey @@ -116,7 +113,7 @@ def _build_set_cmds(values, prefix='dict set'): # tcl doesn't recognise the strings "True" or "False", only "1" # or "0". Special case to convert them - if type(value) == bool: + if isinstance(value, bool): value = str(int(value)) else: value = str(value) @@ -138,6 +135,29 @@ class Ixia(trafficgen.ITrafficGenerator): _tclsh = tkinter.Tcl() _logger = logging.getLogger(__name__) + def start_rfc2544_throughput(self, traffic=None, tests=1, duration=20, + lossrate=0.0): + return NotImplementedError( + 'Ixia start throughput traffic not implemented') + + def wait_rfc2544_throughput(self): + return NotImplementedError( + 'Ixia wait throughput traffic not implemented') + + def start_rfc2544_back2back(self, traffic=None, tests=1, duration=20, + lossrate=0.0): + return NotImplementedError( + 'Ixia start back2back traffic not implemented') + + def send_rfc2544_back2back(self, traffic=None, duration=60, + lossrate=0.0, tests=1): + return NotImplementedError( + 'Ixia send back2back traffic not implemented') + + def wait_rfc2544_back2back(self): + return NotImplementedError( + 'Ixia wait back2back traffic not implemented') + def run_tcl(self, cmd): """Run a TCL script using the TCL interpreter found in ``tkinter``. @@ -228,7 +248,7 @@ class Ixia(trafficgen.ITrafficGenerator): assert len(result) == 6 # fail-fast if underlying Tcl code changes - #TODO - implement Burst results setting via TrafficgenResults. + #NOTE - implement Burst results setting via TrafficgenResults. def send_cont_traffic(self, traffic=None, duration=30): """See ITrafficGenerator for description diff --git a/tools/pkt_gen/ixnet/ixnet.py b/tools/pkt_gen/ixnet/ixnet.py index f84ab668..9a763104 100755 --- a/tools/pkt_gen/ixnet/ixnet.py +++ b/tools/pkt_gen/ixnet/ixnet.py @@ -1,4 +1,4 @@ -# Copyright 2015-2016 Intel Corporation. +# Copyright 2015-2017 Intel Corporation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -78,7 +78,6 @@ does not give any feedback as to the status of tests. As such, it can be expected that the user have access to the IxNetwork machine should this trafficgen need to be debugged. """ - import tkinter import logging import os @@ -122,18 +121,15 @@ def _build_set_cmds(values, prefix='dict set'): for key in values: value = values[key] - # Not allowing derived dictionary types for now - # pylint: disable=unidiomatic-typecheck - if type(value) == dict: + if isinstance(value, dict): _prefix = ' '.join([prefix, key]).strip() for subkey in _build_set_cmds(value, _prefix): yield subkey continue - # pylint: disable=unidiomatic-typecheck # tcl doesn't recognise the strings "True" or "False", only "1" # or "0". Special case to convert them - if type(value) == bool: + if isinstance(value, bool): value = str(int(value)) else: value = str(value) @@ -511,6 +507,8 @@ class IxNet(trafficgen.ITrafficGenerator): return parse_ixnet_rfc_results(parse_result_string(output[0])) + def send_burst_traffic(self, traffic=None, numpkts=100, duration=20): + return NotImplementedError('IxNet does not implement send_burst_traffic') if __name__ == '__main__': TRAFFIC = { diff --git a/tools/pkt_gen/testcenter/testcenter-rfc2544-rest.py b/tools/pkt_gen/testcenter/testcenter-rfc2544-rest.py index 8da8ed17..476e4e69 100644 --- a/tools/pkt_gen/testcenter/testcenter-rfc2544-rest.py +++ b/tools/pkt_gen/testcenter/testcenter-rfc2544-rest.py @@ -1,4 +1,4 @@ -# Copyright 2016 Spirent Communications. +# Copyright 2016-2017 Spirent Communications. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,7 +11,9 @@ # 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. - +# +# Invalid name of file, must be used '_' instead '-' +# pylint: disable=invalid-name ''' @author Spirent Communications @@ -25,7 +27,7 @@ import os from conf import settings -logger = logging.getLogger(__name__) +_LOGGER = logging.getLogger(__name__) def create_dir(path): @@ -33,8 +35,8 @@ def create_dir(path): if not os.path.exists(path): try: os.makedirs(path) - except OSError as e: - logger.error("Failed to create directory %s: %s", path, str(e)) + except OSError as ex: + _LOGGER.error("Failed to create directory %s: %s", path, str(ex)) raise @@ -43,11 +45,11 @@ def write_query_results_to_csv(results_path, csv_results_file_prefix, """ Write the results of the query to the CSV """ create_dir(results_path) filec = os.path.join(results_path, csv_results_file_prefix + ".csv") - with open(filec, "wb") as f: - f.write(query_results["Columns"].replace(" ", ",") + "\n") + with open(filec, "wb") as result_file: + result_file.write(query_results["Columns"].replace(" ", ",") + "\n") for row in (query_results["Output"].replace("} {", ","). replace("{", "").replace("}", "").split(",")): - f.write(row.replace(" ", ",") + "\n") + result_file.write(row.replace(" ", ",") + "\n") def positive_int(value): @@ -67,7 +69,7 @@ def percent_float(value): "%s not in range [0.0, 100.0]" % pvalue) return pvalue - +# pylint: disable=too-many-branches, too-many-statements def main(): """ Read the arguments, Invoke Test and Return the results""" parser = argparse.ArgumentParser() @@ -278,12 +280,12 @@ def main(): args = parser.parse_args() if args.verbose: - logger.debug("Creating results directory") + _LOGGER.debug("Creating results directory") create_dir(args.results_dir) session_name = args.test_session_name user_name = args.test_user_name - + # pylint: disable=import-error try: # Load Spirent REST Library from stcrestclient import stchttp @@ -291,8 +293,8 @@ def main(): stc = stchttp.StcHttp(args.lab_server_addr) session_id = stc.new_session(user_name, session_name) stc.join_session(session_id) - except RuntimeError as e: - logger.error(e) + except RuntimeError as err: + _LOGGER.error(err) raise # Get STC system info. @@ -305,43 +307,43 @@ def main(): # Retrieve and display the server information if args.verbose: - logger.debug("SpirentTestCenter system version: %s", - stc.get("system1", "version")) + _LOGGER.debug("SpirentTestCenter system version: %s", + stc.get("system1", "version")) try: device_list = [] port_list = [] if args.verbose: - logger.debug("Bring up license server") + _LOGGER.debug("Bring up license server") license_mgr = stc.get("system1", "children-licenseservermanager") if args.verbose: - logger.debug("license_mgr = %s", license_mgr) + _LOGGER.debug("license_mgr = %s", license_mgr) stc.create("LicenseServer", under=license_mgr, attributes={ - "server": args.license_server_addr}) + "server": args.license_server_addr}) # Create the root project object if args.verbose: - logger.debug("Creating project ...") + _LOGGER.debug("Creating project ...") project = stc.get("System1", "children-Project") # Configure any custom traffic parameters if args.traffic_custom == "cont": if args.verbose: - logger.debug("Configure Continuous Traffic") + _LOGGER.debug("Configure Continuous Traffic") stc.create("ContinuousTestConfig", under=project) # Create ports if args.verbose: - logger.debug("Creating ports ...") + _LOGGER.debug("Creating ports ...") east_chassis_port = stc.create('port', project) if args.verbose: - logger.debug("Configuring TX port ...") + _LOGGER.debug("Configuring TX port ...") stc.config(east_chassis_port, {'location': tx_port_loc}) port_list.append(east_chassis_port) west_chassis_port = stc.create('port', project) if args.verbose: - logger.debug("Configuring RX port ...") + _LOGGER.debug("Configuring RX port ...") stc.config(west_chassis_port, {'location': rx_port_loc}) port_list.append(west_chassis_port) @@ -387,12 +389,12 @@ def main(): # Append to the device list device_list.append(device_gen_config['ReturnList']) if args.verbose: - logger.debug(device_list) + _LOGGER.debug(device_list) # Create the RFC 2544 'metric test if args.metric == "throughput": if args.verbose: - logger.debug("Set up the RFC2544 throughput test...") + _LOGGER.debug("Set up the RFC2544 throughput test...") stc.perform("Rfc2544SetupThroughputTestCommand", params={"AcceptableFrameLoss": args.acceptable_frame_loss_pct, @@ -463,26 +465,26 @@ def main(): "system1.project", "children-port"), "autoConnect": "TRUE"}) # Apply configuration. if args.verbose: - logger.debug("Apply configuration...") + _LOGGER.debug("Apply configuration...") stc.apply() if args.verbose: - logger.debug("Starting the sequencer...") + _LOGGER.debug("Starting the sequencer...") stc.perform("SequencerStart") # Wait for sequencer to finish - logger.info( + _LOGGER.info( "Starting test... Please wait for the test to complete...") stc.wait_until_complete() - logger.info("The test has completed... Saving results...") + _LOGGER.info("The test has completed... Saving results...") # Determine what the results database filename is... lab_server_resultsdb = stc.get( "system1.project.TestResultSetting", "CurrentResultFileName") if args.verbose: - logger.debug("The lab server results database is %s", - lab_server_resultsdb) + _LOGGER.debug("The lab server results database is %s", + lab_server_resultsdb) stc.perform("CSSynchronizeFiles", params={"DefaultDownloadDir": args.results_dir}) @@ -492,10 +494,10 @@ def main(): if not os.path.exists(resultsdb): resultsdb = lab_server_resultsdb - logger.info("Failed to create the local summary DB File, using" - " the remote DB file instead.") + _LOGGER.info("Failed to create the local summary DB File, using" + " the remote DB file instead.") else: - logger.info( + _LOGGER.info( "The local summary DB file has been saved to %s", resultsdb) # The returns the "RFC2544ThroughputTestResultDetailedSummaryView" @@ -551,26 +553,26 @@ def main(): ("RFC2544FrameLossTestResultDetailed" "SummaryView")})) if args.verbose: - logger.debug("resultsdict[\"Columns\"]: %s", - resultsdict["Columns"]) - logger.debug("resultsdict[\"Output\"]: %s", resultsdict["Output"]) - logger.debug("Result paths: %s", - stc.perform("GetTestResultSettingPaths")) + _LOGGER.debug("resultsdict[\"Columns\"]: %s", + resultsdict["Columns"]) + _LOGGER.debug("resultsdict[\"Output\"]: %s", resultsdict["Output"]) + _LOGGER.debug("Result paths: %s", + stc.perform("GetTestResultSettingPaths")) # Write results to csv - logger.debug("Writing CSV file to results directory %s", - args.results_dir) + _LOGGER.debug("Writing CSV file to results directory %s", + args.results_dir) write_query_results_to_csv( args.results_dir, args.csv_results_file_prefix, resultsdict) except RuntimeError as e: - logger.error(e) + _LOGGER.error(e) if args.verbose: - logger.debug("Destroy session on lab server") + _LOGGER.debug("Destroy session on lab server") stc.end_session() - logger.info("Test complete!") + _LOGGER.info("Test complete!") if __name__ == "__main__": main() diff --git a/tools/pkt_gen/testcenter/testcenter-rfc2889-rest.py b/tools/pkt_gen/testcenter/testcenter-rfc2889-rest.py index 523d9d31..044fb67d 100644 --- a/tools/pkt_gen/testcenter/testcenter-rfc2889-rest.py +++ b/tools/pkt_gen/testcenter/testcenter-rfc2889-rest.py @@ -1,4 +1,4 @@ -# Copyright 2016 Spirent Communications. +# Copyright 2016-2017 Spirent Communications. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,7 +11,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. - +# pylint: disable=invalid-name ''' @author Spirent Communications @@ -66,7 +66,7 @@ def percent_float(value): "%s not in range [0.0, 100.0]" % pvalue) return pvalue - +# pylint: disable=too-many-statements def main(): """ Read the arguments, Invoke Test and Return the results""" parser = argparse.ArgumentParser() @@ -199,6 +199,7 @@ def main(): session_name = args.test_session_name user_name = args.test_user_name + # pylint: disable=import-error try: # Load Spirent REST Library from stcrestclient import stchttp diff --git a/tools/pkt_gen/testcenter/testcenter.py b/tools/pkt_gen/testcenter/testcenter.py index 4412b13a..deb14e7e 100644 --- a/tools/pkt_gen/testcenter/testcenter.py +++ b/tools/pkt_gen/testcenter/testcenter.py @@ -246,6 +246,7 @@ class TestCenter(trafficgen.ITrafficGenerator): row["ForwardingRate(fps)"]) return result + # pylint: disable=unused-argument def send_rfc2889_forwarding(self, traffic=None, tests=1, duration=20): """ Send traffic per RFC2889 Forwarding test specifications. @@ -467,6 +468,26 @@ class TestCenter(trafficgen.ITrafficGenerator): return self.get_rfc2544_results(filecs) + def start_cont_traffic(self, traffic=None, duration=30): + raise NotImplementedError('TestCenter start_cont_traffic not implement.') + + def stop_cont_traffic(self): + raise NotImplementedError('TestCenter stop_cont_traffic not implement.') + + def start_rfc2544_back2back(self, traffic=None, tests=1, duration=20, + lossrate=0.0): + raise NotImplementedError('TestCenter start_rfc2544_back2back not implement.') + + def wait_rfc2544_back2back(self): + raise NotImplementedError('TestCenter wait_rfc2544_back2back not implement.') + + def start_rfc2544_throughput(self, traffic=None, tests=1, duration=20, + lossrate=0.0): + raise NotImplementedError('TestCenter start_rfc2544_throughput not implement.') + + def wait_rfc2544_throughput(self): + raise NotImplementedError('TestCenter wait_rfc2544_throughput not implement.') + if __name__ == '__main__': TRAFFIC = { 'l3': { diff --git a/tools/pkt_gen/xena/XenaDriver.py b/tools/pkt_gen/xena/XenaDriver.py index e144514f..6e39e47a 100644 --- a/tools/pkt_gen/xena/XenaDriver.py +++ b/tools/pkt_gen/xena/XenaDriver.py @@ -1,4 +1,4 @@ -# Copyright 2016 Red Hat Inc & Xena Networks. +# Copyright 2016-2017 Red Hat Inc & Xena Networks. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ import struct import sys import threading import time - +# pylint: disable=too-many-lines # Xena Socket Commands CMD_CLEAR_RX_STATS = 'pr_clear' CMD_CLEAR_TX_STATS = 'pt_clear' @@ -371,7 +371,7 @@ class XenaManager(object): """ return self.driver.ask_verify(make_manager_command(CMD_OWNER, username)) - +# pylint: disable=too-many-public-methods class XenaPort(object): """ Xena Port emulator class @@ -537,7 +537,7 @@ class XenaPort(object): command = make_port_command(CMD_RESET, self) return self._manager.driver.ask_verify(command) - def set_port_arp_reply(self, on=True, v6=False): + def set_port_arp_reply(self, is_on=True, ipv6=False): """ Set the port arpreply value :param on: Enable or disable the arp reply on the port @@ -545,11 +545,11 @@ class XenaPort(object): :return: Boolean True if response OK, False if error """ command = make_port_command('{} {}'.format( - CMD_SET_PORT_ARP_V6_REPLY if v6 else CMD_SET_PORT_ARP_REPLY, - "on" if on else "off"), self) + CMD_SET_PORT_ARP_V6_REPLY if ipv6 else CMD_SET_PORT_ARP_REPLY, + "on" if is_on else "off"), self) return self._manager.driver.ask_verify(command) - def set_port_ping_reply(self, on=True, v6=False): + def set_port_ping_reply(self, is_on=True, ipv6=False): """ Set the port ping reply value :param on: Enable or disable the ping reply on the port @@ -557,8 +557,8 @@ class XenaPort(object): :return: Boolean True if response OK, False if error """ command = make_port_command('{} {}'.format( - CMD_SET_PORT_PING_V6_REPLY if v6 else CMD_SET_PORT_PING_REPLY, - "on" if on else "off"), self) + CMD_SET_PORT_PING_V6_REPLY if ipv6 else CMD_SET_PORT_PING_REPLY, + "on" if is_on else "off"), self) return self._manager.driver.ask_verify(command) def set_port_learning(self, interval): @@ -885,6 +885,7 @@ class XenaRXStats(object): """ return self._time + # pylint: disable=too-many-branches def parse_stats(self): """ Parse the stats from pr all command :return: Dictionary of all stats @@ -1040,7 +1041,7 @@ class XenaTXStats(object): def aggregate_stats(stat1, stat2): """ - Judge whether stat1 and stat2 both have same key, if both have same key, + Judge whether stat1 and stat2 both have same key, if both have same key, call the aggregate fuction, else use the stat1's value """ newstat = dict() diff --git a/tools/pkt_gen/xena/xena_json.py b/tools/pkt_gen/xena/xena_json.py index 1ce7b46f..50d0e2fe 100644 --- a/tools/pkt_gen/xena/xena_json.py +++ b/tools/pkt_gen/xena/xena_json.py @@ -1,4 +1,4 @@ -# Copyright 2016 Red Hat Inc & Xena Networks. +# Copyright 2016-2017 Red Hat Inc & Xena Networks. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -232,10 +232,13 @@ class XenaJSON(object): """ self.json_data['TestOptions']['TestTypeOptionMap']['Throughput'][ 'Enabled'] = 'true' - + # pylint: disable=too-many-arguments def modify_2544_tput_options(self, initial_value, minimum_value, maximum_value, value_resolution, use_pass_threshhold, pass_threshhold): + """ + modify_2544_tput_options + """ self.json_data['TestOptions']['TestTypeOptionMap']['Throughput'][ 'RateIterationOptions']['InitialValue'] = initial_value self.json_data['TestOptions']['TestTypeOptionMap']['Throughput'][ @@ -638,4 +641,3 @@ if __name__ == "__main__": write_json_file(JSON.json_data, './testthis.x2544') JSON = XenaJSON('./testthis.x2544') print_json_report(JSON.json_data) - -- cgit 1.2.3-korg