]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
SONAR: Specify an exception class to catch or reraise the exception
authorJulien Fortin <jfortin@nvidia.com>
Wed, 3 May 2023 14:13:45 +0000 (16:13 +0200)
committerJulien Fortin <jfortin@nvidia.com>
Thu, 4 May 2023 11:21:55 +0000 (13:21 +0200)
Signed-off-by: Julien Fortin <jfortin@nvidia.com>
Makefile
ifupdown2/addons/address.py
ifupdown2/addons/bond.py
ifupdown2/addons/bridge.py
ifupdown2/addons/vlan.py
ifupdown2/addons/vxlan.py
ifupdown2/lib/gvgen.py
ifupdown2/lib/log.py
ifupdown2/nlmanager/ipnetwork.py
ifupdown2/sbin/ifaddon

index 37b51d1cc5e9b0967f12ad44afc214885cb7a2c8..e7e2bf4d729c1593bef6c1831ef5042e80c30e9f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ import os, webbrowser, sys
 
 try:
        from urllib import pathname2url
-except:
+except Exception:
        from urllib.request import pathname2url
 
 webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
index 1ea4df6032bcb8c2224ba7250e427b824709eb98..756b1ec67231d68bb6cf1ed9f807f4eff4a5b4ab 100644 (file)
@@ -238,9 +238,9 @@ class address(AddonWithIpBlackList, moduleBase):
             )
             try:
                 self.l3_intf_arp_accept = int(l3_intf_arp_accept_str)
-            except:
+            except ValueError:
                 self.l3_intf_arp_accept = int(strtobool(l3_intf_arp_accept_str))
-        except:
+        except Exception:
             self.l3_intf_arp_accept = 0
 
         self.l3_intf_default_gateway_set_onlink = utils.get_boolean_from_string(
@@ -469,7 +469,7 @@ class address(AddonWithIpBlackList, moduleBase):
                 try:
                     if utils.mac_str_to_int(old_mac_addr) != utils.mac_str_to_int(hwaddress):
                         self.iproute2.bridge_fdb_del(bridgename, old_mac_addr, vlan)
-                except:
+                except Exception:
                     pass
             if up:
                 # check statemanager to delete the old entry if necessary
index e4e46d6508e64475de49c7587641a017cfea860c..f6681f869082412baff2892203b673d17fbf531a 100644 (file)
@@ -452,7 +452,7 @@ class bond(Addon, moduleBase):
             for s in removed_slave:
                 try:
                     runningslaves.remove(s)
-                except:
+                except Exception:
                     pass
 
         return  runningslaves
@@ -960,7 +960,7 @@ class bond(Addon, moduleBase):
             try:
                 iface_attrs.remove("es-sys-mac")
                 self.logger.info("%s: non-root user can't check attribute \"es-sys-mac\" value" % ifaceobj.name)
-            except:
+            except Exception:
                 pass
 
         for attr in iface_attrs:
index 94f08eaa3ff6a68307dc5a41baaee1b9d78aec72..753638edd829b1d9e75dc3eeef19062cf7776517 100644 (file)
@@ -815,7 +815,7 @@ class bridge(Bridge, moduleBase):
                 module_name=self.__class__.__name__,
                 attr="bridge_vni_per_svi_limit"
             ))
-        except:
+        except Exception:
             self.bridge_vni_per_svi_limit = -1
 
     @staticmethod
@@ -947,7 +947,7 @@ class bridge(Bridge, moduleBase):
                 for obj in ifaceobj_getfunc(intf):
                     if obj.link_kind & ifaceLinkKind.BRIDGE:
                         return obj.name
-        except:
+        except Exception:
             pass
         return None
 
@@ -2609,7 +2609,7 @@ class bridge(Bridge, moduleBase):
                 for vlan_vni_map_entry in bridge_vlan_vni_map_entry.split():
                     try:
                         vlans_str, vni_str = utils.get_vlan_vni_in_map_entry(vlan_vni_map_entry)
-                    except:
+                    except Exception:
                         return self.__warn_bridge_vlan_vni_map_syntax_error(vxlan_name, vlan_vni_map_entry)
 
                     # we need to convert vlan_str and vni_str back to a map {vlan: vni}
@@ -3874,7 +3874,7 @@ class bridge(Bridge, moduleBase):
             for vlan_vni in bridge_vlan_vni_map_entry.split():
                 try:
                     vlans_str, vni_str = utils.get_vlan_vni_in_map_entry(vlan_vni)
-                except:
+                except Exception:
                     fail = True
                     self.__warn_bridge_vlan_vni_map_syntax_error(ifname, vlan_vni)
                     continue
@@ -3893,7 +3893,7 @@ class bridge(Bridge, moduleBase):
 
                         if vlan != cached_vnis[index] or vnis_list[i] != cached_vlans[index]:
                             fail = True
-                except:
+                except Exception:
                     fail = True
 
             ifaceobjcurr.update_config_with_status("bridge-vlan-vni-map", bridge_vlan_vni_map_entry, fail)
index 3b045dca75d2a669f0959402a9b48529e6b2f007..72291fdc547c4f20899df72f5bae7d92e6e85932 100644 (file)
@@ -72,7 +72,7 @@ class vlan(Addon, moduleBase):
             try:
                 if self._get_vlan_id(ifaceobj) != -1:
                     return True
-            except:
+            except Exception:
                 pass
         return False
 
index 36c25f1bfed495ec235a4bc95d5c97fa4843adbb..012aba4dc7b2950afc6134d877f434b22f780941 100644 (file)
@@ -1320,14 +1320,14 @@ class vxlan(Vxlan, moduleBase):
             for vni, ip in (vxlan_mcast_grp_map or {}).items():
                 try:
                     old_vxlan_remote_ip_map[vni].remove(ip)
-                except:
+                except Exception:
                     pass
 
             for vni, ips in old_vxlan_remote_ip_map.items():
                 for ip in ips:
                     try:
                         self.iproute2.bridge_fdb_del_raw(ifaceobj.name, "00:00:00:00:00:00 dst %s src_vni %s" % (ip, vni))
-                    except:
+                    except Exception:
                         pass
 
     @staticmethod
index 14dc5f701ce0684b053ddd2b1dcfafdca7b72650..bb1b00d23e05455b6b2cf02cecdc649b6d1d6cd7 100644 (file)
@@ -345,7 +345,7 @@ class GvGen:
         try:
             props = node_or_link['properties']
             return props[key]
-        except:
+        except Exception:
             return None
 
     def propertyRemove(self, node_or_link, key):
index 7bcfd0f98eb0774d2dab0cbeb388bd836c00b18c..5d83afe2a801874c15da316180fba00318c422fb 100644 (file)
@@ -32,7 +32,7 @@ from datetime import date, datetime
 
 try:
     from ifupdown2.ifupdown.utils import utils
-except:
+except ImportError:
     from ifupdown.utils import utils
 
 
@@ -204,7 +204,7 @@ class LogManager:
                 try:
                     directory_to_remove = "%s/%s%s_%s" % (self.LOGGING_DIRECTORY, self.LOGGING_DIRECTORY_PREFIX, ifupdown2_log_dirs[index][0], ifupdown2_log_dirs[index][1])
                     shutil.rmtree(directory_to_remove, ignore_errors=True)
-                except:
+                except Exception:
                     pass
 
     @staticmethod
index 37a1f6d8ef12f56f63c224a7f6a00624d6f59037..90f93d144524734f01af5cbbd2a0f4dc9c4af96e 100644 (file)
@@ -185,5 +185,5 @@ class IPv6Address(IPv6Network):
 def ip_address(ip):
     try:
         return IPv4Address(ip)
-    except:
+    except Exception:
         return IPv6Address(ip)
index 4a2f748d6bdabf7fa5cf96c113ed140fcfd2ce33..1fe0a69214b9a9c155f3814ca5ceb460bfe281b7 100755 (executable)
@@ -53,7 +53,7 @@ def man_rst_body():
 
     print ('''    ifupdown2 addon modules add incremental functionality to
     core ifupdown2 tool.
-           
+
     All installed addon modules are executed on every interface
     listed in the interfaces file. Addon modules are installed under
     /usr/share/ifupdownaddons. To see the list of active addon
@@ -85,13 +85,13 @@ def get_addon_modinfo(modules_dir):
                     try:
                         m = __import__(mname)
                         mclass = getattr(m, mname)
-                    except:
+                    except Exception:
                         pass
                         continue
                     minstance = mclass()
                     if hasattr(minstance, 'get_modinfo'):
                        modinfo[mname] = minstance.get_modinfo()
-    except
+    except Exception:
         raise
 
     return modinfo
@@ -233,7 +233,7 @@ def process_move_cmd(args):
         pos = int(args.position)
         if pos < 0 or pos > len(addon_config.get(op)):
             raise Exception('invalid value for position')
-    except:
+    except Exception:
         raise
 
     if addon_config[op].index(module) == pos: