DO_NOT_MERGE CSIT-1194 - Framework easy pylint improvements 14/21314/1
authorMiroslav Los <miroslav.los@pantheon.tech>
Wed, 14 Aug 2019 15:29:33 +0000 (17:29 +0200)
committerMiroslav Los <miroslav.los@pantheon.tech>
Wed, 14 Aug 2019 15:29:33 +0000 (17:29 +0200)
- force a python2 environment in tox for pylint
- let pylint load some compiled modules for member checking
- allow locally enabled pylint rules
- ignore bad enum names
- ignore complexity for code to be refactored by other tickets
- broad excepts are acceptable sometimes

Signed-off-by: Miroslav Los <miroslav.los@pantheon.tech>
Change-Id: If4c3a1b85e8609f074e1de8ce91fc9c4fedbeb38

pylint.cfg
resources/libraries/python/DropRateSearch.py
resources/libraries/python/GBP.py
resources/libraries/python/IPUtil.py
resources/libraries/python/InterfaceUtil.py
resources/libraries/python/PapiExecutor.py
resources/libraries/python/TrafficGenerator.py
resources/libraries/python/VatExecutor.py
tox.ini

index 82c19ae..69668ed 100644 (file)
@@ -21,6 +21,10 @@ persistent=yes
 # usually to register additional checkers.
 load-plugins=
 
+# A comma-separated list of package or module names from where C extensions may
+# be loaded. Extensions are loading into the active Python interpreter and may
+# run arbitrary code
+extension-pkg-whitelist=numpy, scipy
 
 [MESSAGES CONTROL]
 
@@ -38,7 +42,7 @@ load-plugins=
 # --enable=similarities". If you want to run only the classes checker, but have
 # no Warning level messages displayed, use"--disable=all --enable=classes
 # --disable=W"
-disable=redefined-variable-type, locally-disabled
+disable=redefined-variable-type, locally-disabled, locally-enabled
 
 
 [REPORTS]
index e87ef95..0c4f2c6 100644 (file)
@@ -61,6 +61,8 @@ class SearchResultType(Enum):
 
 class DropRateSearch(object):
     """Abstract class with search algorithm implementation."""
+    #TODO DropRateSearch should be refactored as part of CSIT-1378
+    #pylint: disable=too-many-instance-attributes
 
     __metaclass__ = ABCMeta
 
index ff0c133..e0fa07e 100644 (file)
@@ -42,8 +42,8 @@ class GBPBridgeDomainFlags(IntEnum):
 class GBPSubnetType(IntEnum):
     """GBP Subnet Type."""
     GBP_API_SUBNET_TRANSPORT = 1
-    GBP_API_SUBNET_STITCHED_INTERNAL = 2
-    GBP_API_SUBNET_STITCHED_EXTERNAL = 3
+    GBP_API_SUBNET_STITCHED_INTERNAL = 2  # pylint: disable=invalid-name
+    GBP_API_SUBNET_STITCHED_EXTERNAL = 3  # pylint: disable=invalid-name
     GBP_API_SUBNET_L3_OUT = 4
     GBP_API_SUBNET_ANON_L3_OUT = 5
 
index 901d2ed..2109997 100644 (file)
@@ -55,7 +55,7 @@ class FibPathType(IntEnum):
 class FibPathFlags(IntEnum):
     """FIB path flags."""
     FIB_PATH_FLAG_NONE = 0
-    FIB_PATH_FLAG_RESOLVE_VIA_ATTACHED = 1
+    FIB_PATH_FLAG_RESOLVE_VIA_ATTACHED = 1  #pylint: disable=invalid-name
     FIB_PATH_FLAG_RESOLVE_VIA_HOST = 2
 
 
index 1f79d7e..1a97130 100644 (file)
@@ -32,7 +32,7 @@ from resources.libraries.python.VPPUtil import VPPUtil
 
 class LinkBondLoadBalance(IntEnum):
     """Link bonding load balance."""
-    L2 = 0
+    L2 = 0  # pylint: disable=invalid-name
     L34 = 1
     L23 = 2
 
index 4e4e082..bfa538f 100644 (file)
@@ -193,6 +193,7 @@ class PapiSocketExecutor(object):
             # Package path has to be one level above the vpp_papi directory.
             package_path = package_path.rsplit('/', 1)[0]
             sys.path.append(package_path)
+            # pylint: disable=import-error
             from vpp_papi.vpp_papi import VPPApiClient as vpp_class
             vpp_class.apidir = api_json_directory
             # We need to create instance before removing from sys.path.
@@ -705,7 +706,7 @@ class PapiExecutor(object):
                          "\n{apis}".format(host=self._node["host"],
                                            apis=api_data))
             raise
-        except Exception as exc:
+        except Exception as exc:  # pylint: disable=broad-except
             raise_from(RuntimeError(
                 "PAPI command(s) execution on host {host} "
                 "failed: {apis}".format(
index 334e299..cc968f8 100644 (file)
@@ -443,10 +443,10 @@ class TrafficGenerator(AbstractMeasurer):
         # we need to encode them, so that repr() does not lead with 'u'.
         if isinstance(rate, unicode):
             rate = rate.encode("utf-8")
-        if isinstance(duration, unicode):
-            duration = duration.encode("utf-8")
-        if isinstance(warmup_time, unicode):
-            warmup_time = warmup_time.encode("utf-8")
+        if not isinstance(duration, (float, int)):
+            duration = float(duration)
+        if not isinstance(warmup_time, (float, int)):
+            warmup_time = float(warmup_time)
         command = (
             "sh -c '{tool}/resources/tools/trex/trex_stateless_profile.py"
             " --profile {prof}/resources/traffic_profiles/trex/{traffic}.py"
index 8197b5e..1d0a213 100644 (file)
@@ -252,7 +252,7 @@ class VatTerminal(object):
                     self._tty,
                     'sudo -S {0}{1}'.format(Constants.VAT_BIN_NAME, json_text),
                     self.__VAT_PROMPT)
-            except Exception:
+            except Exception:  #pylint: disable=broad-except
                 continue
             else:
                 break
@@ -306,10 +306,9 @@ class VatTerminal(object):
                     raise RuntimeError("More instances of VPP running on node "
                                        "{0}. VAT command {1} execution failed.".
                                        format(self._node['host'], cmd))
-            else:
-                raise RuntimeError("VPP not running on node {0}. VAT command "
-                                   "{1} execution failed.".
-                                   format(self._node['host'], cmd))
+            raise RuntimeError("VPP not running on node {0}. VAT command "
+                               "{1} execution failed.".
+                               format(self._node['host'], cmd))
 
         logger.debug("VAT output: {0}".format(out))
         if self.json:
diff --git a/tox.ini b/tox.ini
index fd0a6cf..2aa1877 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -34,6 +34,7 @@ checker_dir = ./resources/libraries/bash/entry/check
 # TODO: Tox prints various warnings. Figure them out and fix them.
 
 [testenv:pylint]
+basepython = python2
 deps =
     pylint==1.5.4
     -r ./requirements.txt

©2016 FD.io a Linux Foundation Collaborative Project. All Rights Reserved.
Linux Foundation is a registered trademark of The Linux Foundation. Linux is a registered trademark of Linus Torvalds.
Please see our privacy policy and terms of use.