From 7c8627f87681ba78e4b9c22b5317b2219366874f Mon Sep 17 00:00:00 2001 From: Julien Fortin Date: Wed, 3 May 2023 16:13:45 +0200 Subject: [PATCH] SONAR: Specify an exception class to catch or reraise the exception Signed-off-by: Julien Fortin --- Makefile | 2 +- ifupdown2/addons/address.py | 6 +++--- ifupdown2/addons/bond.py | 4 ++-- ifupdown2/addons/bridge.py | 10 +++++----- ifupdown2/addons/vlan.py | 2 +- ifupdown2/addons/vxlan.py | 4 ++-- ifupdown2/lib/gvgen.py | 2 +- ifupdown2/lib/log.py | 4 ++-- ifupdown2/nlmanager/ipnetwork.py | 2 +- ifupdown2/sbin/ifaddon | 8 ++++---- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 37b51d1c..e7e2bf4d 100644 --- 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]))) diff --git a/ifupdown2/addons/address.py b/ifupdown2/addons/address.py index 1ea4df60..756b1ec6 100644 --- a/ifupdown2/addons/address.py +++ b/ifupdown2/addons/address.py @@ -238,9 +238,9 @@ def __init__(self, *args, **kargs): ) 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 @@ def _process_bridge(self, ifaceobj, up, hwaddress, old_mac_addr=None): 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 diff --git a/ifupdown2/addons/bond.py b/ifupdown2/addons/bond.py index e4e46d65..f6681f86 100644 --- a/ifupdown2/addons/bond.py +++ b/ifupdown2/addons/bond.py @@ -452,7 +452,7 @@ def _add_slaves(self, ifaceobj, runningslaves, ifaceobj_getfunc=None): for s in removed_slave: try: runningslaves.remove(s) - except: + except Exception: pass return runningslaves @@ -960,7 +960,7 @@ def _query_check(self, ifaceobj, ifaceobjcurr, ifaceobj_getfunc=None): 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: diff --git a/ifupdown2/addons/bridge.py b/ifupdown2/addons/bridge.py index 94f08eaa..753638ed 100644 --- a/ifupdown2/addons/bridge.py +++ b/ifupdown2/addons/bridge.py @@ -815,7 +815,7 @@ def __init__(self, *args, **kargs): 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 @@ def __get_vxlan_bridge_name(self, ifaceobj, ifaceobj_getfunc): 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 @@ def apply_bridge_port_vlan_vni_map(self, ifaceobj): 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 @@ def _query_check_bridge_port(self, ifaceobj, ifaceobjcurr, 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 @@ def _query_check_bridge_port(self, ifaceobj, ifaceobjcurr, 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) diff --git a/ifupdown2/addons/vlan.py b/ifupdown2/addons/vlan.py index 3b045dca..72291fdc 100644 --- a/ifupdown2/addons/vlan.py +++ b/ifupdown2/addons/vlan.py @@ -72,7 +72,7 @@ def _is_vlan_device(self, ifaceobj): try: if self._get_vlan_id(ifaceobj) != -1: return True - except: + except Exception: pass return False diff --git a/ifupdown2/addons/vxlan.py b/ifupdown2/addons/vxlan.py index 36c25f1b..012aba4d 100644 --- a/ifupdown2/addons/vxlan.py +++ b/ifupdown2/addons/vxlan.py @@ -1320,14 +1320,14 @@ def vxlan_remote_ip_map(self, ifaceobj, vxlan_mcast_grp_map): 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 diff --git a/ifupdown2/lib/gvgen.py b/ifupdown2/lib/gvgen.py index 14dc5f70..bb1b00d2 100644 --- a/ifupdown2/lib/gvgen.py +++ b/ifupdown2/lib/gvgen.py @@ -345,7 +345,7 @@ def propertyGet(self, node_or_link, key): try: props = node_or_link['properties'] return props[key] - except: + except Exception: return None def propertyRemove(self, node_or_link, key): diff --git a/ifupdown2/lib/log.py b/ifupdown2/lib/log.py index 7bcfd0f9..5d83afe2 100644 --- a/ifupdown2/lib/log.py +++ b/ifupdown2/lib/log.py @@ -32,7 +32,7 @@ try: from ifupdown2.ifupdown.utils import utils -except: +except ImportError: from ifupdown.utils import utils @@ -204,7 +204,7 @@ def __init_debug_logging(self): 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 diff --git a/ifupdown2/nlmanager/ipnetwork.py b/ifupdown2/nlmanager/ipnetwork.py index 37a1f6d8..90f93d14 100644 --- a/ifupdown2/nlmanager/ipnetwork.py +++ b/ifupdown2/nlmanager/ipnetwork.py @@ -185,5 +185,5 @@ def __str__(self): def ip_address(ip): try: return IPv4Address(ip) - except: + except Exception: return IPv6Address(ip) diff --git a/ifupdown2/sbin/ifaddon b/ifupdown2/sbin/ifaddon index 4a2f748d..1fe0a692 100755 --- a/ifupdown2/sbin/ifaddon +++ b/ifupdown2/sbin/ifaddon @@ -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: