NFVBENCH-175 pylint w0707 correction 78/70878/1
authorfmenguy <francoisregis.menguy@orange.com>
Mon, 24 Aug 2020 14:00:01 +0000 (16:00 +0200)
committerfmenguy <francoisregis.menguy@orange.com>
Mon, 24 Aug 2020 14:04:06 +0000 (16:04 +0200)
Change-Id: I16927f051f80c540ffc1989f5311e47e68b14a73
Signed-off-by: fmenguy <francoisregis.menguy@orange.com>
nfvbench/chaining.py
nfvbench/config.py
nfvbench/nfvbench.py
nfvbench/traffic_client.py
nfvbench/traffic_gen/trex_gen.py
nfvbench/utils.py

index a52c7e9..ed2f309 100644 (file)
@@ -279,7 +279,7 @@ class ChainNetwork(object):
                 return item_field[index]
             except IndexError:
                 raise ChainException("List %s is too short for chain index %d" %
-                                     (str(item_field), index))
+                                     (str(item_field), index)) from IndexError
         # single value is configured
         if auto_index:
             return item_field + index
@@ -1195,7 +1195,8 @@ class ChainManager(object):
             self.vlans = [self._check_list('vlans[0]', self.config.vlans[0], re_vlan),
                           self._check_list('vlans[1]', self.config.vlans[1], re_vlan)]
         except IndexError:
-            raise ChainException('vlans parameter is mandatory. Set valid value in config file')
+            raise ChainException(
+                'vlans parameter is mandatory. Set valid value in config file') from IndexError
 
     def _get_dest_macs_from_config(self):
         re_mac = "[0-9a-fA-F]{2}([-:])[0-9a-fA-F]{2}(\\1[0-9a-fA-F]{2}){4}$"
index 4cc9c86..c107958 100644 (file)
@@ -28,7 +28,7 @@ def config_load(file_name, from_cfg=None, whitelist_keys=None):
     except IOError:
         raise Exception("Configuration file at '{}' was not found. Please use correct path "
                         "and verify it is visible to container if you run nfvbench in container."
-                        .format(file_name))
+                        .format(file_name)) from IOError
 
     if from_cfg:
         if not whitelist_keys:
@@ -52,7 +52,7 @@ def config_loads(cfg_text, from_cfg=None, whitelist_keys=None):
         LOG.error("String %s is not well formatted. Please verify your yaml/json string. "
                   "If string is a file path, file was not found. Please use correct path and "
                   "verify it is visible to container if you run nfvbench in container.", cfg_text)
-        raise Exception(e)
+        raise Exception(e) from e
     if from_cfg:
         if not whitelist_keys:
             whitelist_keys = []
index 06ca19d..651d06b 100644 (file)
@@ -571,7 +571,8 @@ def main():
             factory = getattr(factory_module, config['factory_class'])()
         except AttributeError:
             raise Exception("Requested factory module '{m}' or class '{c}' was not found."
-                            .format(m=config['factory_module'], c=config['factory_class']))
+                            .format(m=config['factory_module'],
+                                    c=config['factory_class'])) from AttributeError
         # create config plugin for this platform
         config_plugin = factory.get_config_plugin_class()(config)
         config = config_plugin.get_config()
index 89653a8..460e7c2 100755 (executable)
@@ -288,7 +288,7 @@ class Device(object):
                 value = int((ip_size / step)) + 1
             return value
         except ZeroDivisionError:
-            raise ZeroDivisionError("step can't be zero !")
+            raise ZeroDivisionError("step can't be zero !") from ZeroDivisionError
 
     def set_mac(self, mac):
         """Set the local MAC for this port device."""
index b35d13f..0bf6d93 100644 (file)
@@ -640,7 +640,7 @@ class TRex(AbstractTrafficGenerator):
             if server_ip == '127.0.0.1':
                 self.__start_local_server()
             else:
-                raise TrafficGeneratorException(e.message)
+                raise TrafficGeneratorException(e.message) from e
 
         ports = list(self.generator_config.ports)
         self.port_handle = ports
@@ -696,7 +696,7 @@ class TRex(AbstractTrafficGenerator):
                     message = f.read()
             else:
                 message = e.message
-            raise TrafficGeneratorException(message)
+            raise TrafficGeneratorException(message) from e
 
     def __start_server(self):
         server = TRexTrafficServer()
index b92c75e..06f643c 100644 (file)
@@ -166,7 +166,7 @@ def parse_flow_count(flow_count):
     try:
         flow_count = int(flow_count)
     except ValueError:
-        raise Exception("Unknown flow count format '{}'".format(input_fc))
+        raise Exception("Unknown flow count format '{}'".format(input_fc)) from ValueError
 
     return flow_count * multiplier
 
@@ -190,8 +190,8 @@ class RunLock(object):
         try:
             self._fd = os.open(self._path, os.O_CREAT)
             fcntl.flock(self._fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
-        except (OSError, IOError):
-            raise Exception('Other NFVbench process is running. Please wait')
+        except (OSError, IOError) as e:
+            raise Exception('Other NFVbench process is running. Please wait') from e
 
     def __exit__(self, *args):
         fcntl.flock(self._fd, fcntl.LOCK_UN)