diff --git a/docs/examples/generate_interfaces.py b/docs/examples/generate_interfaces.py index 76aac64..7be8e9f 100755 --- a/docs/examples/generate_interfaces.py +++ b/docs/examples/generate_interfaces.py @@ -42,9 +42,9 @@ def get_pci_interfaces(): try: subprocess.check_call(cmd, shell=True, stdout=FNULL) ports.append(interface) - except: + except Exception: pass - except: + except Exception: pass finally: FNULL.close() @@ -63,7 +63,7 @@ def get_swp_interfaces(): ports.append(line.split()[0]) except ValueError: continue - except: + except Exception: try: ports = get_pci_interfaces() except Exception as e: diff --git a/ifupdown2/__main__.py b/ifupdown2/__main__.py index 5e65c3d..d720529 100755 --- a/ifupdown2/__main__.py +++ b/ifupdown2/__main__.py @@ -29,7 +29,7 @@ import sys try: from ifupdown2.lib.log import LogManager, root_logger from ifupdown2.lib.status import Status -except: +except Exception: from lib.log import LogManager, root_logger from lib.status import Status @@ -47,7 +47,7 @@ try: from ifupdown2.ifupdown.client import Client from ifupdown2.ifupdown.exceptions import ArgvParseHelp, ArgvParseError -except: +except Exception: import ifupdown.config as config config.__version__ = __import__("__init__").__version__ @@ -63,7 +63,7 @@ def daemon_mode(): try: with open(config.IFUPDOWN2_CONF_PATH) as f: return "use_daemon=yes" in f.read() - except: + except Exception: return False @@ -85,7 +85,7 @@ def stand_alone(): try: from ifupdown2.ifupdown.main import Ifupdown2 from ifupdown2.lib.nlcache import NetlinkListenerWithCache, NetlinkListenerWithCacheErrorNotInitialized - except: + except Exception: from ifupdown.main import Ifupdown2 from lib.nlcache import NetlinkListenerWithCache, NetlinkListenerWithCacheErrorNotInitialized ifupdown2 = Ifupdown2(daemon=False, uid=os.geteuid()) diff --git a/ifupdown2/addons/address.py b/ifupdown2/addons/address.py index a29414c..8b99b25 100644 --- a/ifupdown2/addons/address.py +++ b/ifupdown2/addons/address.py @@ -406,7 +406,7 @@ class address(Addon, moduleBase): if old_hwaddress and utils.mac_str_to_int(old_hwaddress) != utils.mac_str_to_int(hwaddress): self.iproute2.bridge_fdb_del(bridgename, old_hwaddress, vlan) break - except: + except Exception: pass self.iproute2.bridge_fdb_add(bridgename, hwaddress, vlan) else: @@ -973,7 +973,7 @@ class address(Addon, moduleBase): dhclientcmd.release6(ifaceobj.name) self.cache.force_address_flush_family(ifaceobj.name, socket.AF_INET6) force_reapply = True - except: + except Exception: pass self.process_mtu(ifaceobj, ifaceobj_getfunc) @@ -1224,7 +1224,7 @@ class address(Addon, moduleBase): if clagd_vxlan_anycast_ip in intf_running_addrs: user_config_addrs.append(clagd_vxlan_anycast_ip) - except: + except Exception: pass # Set ifaceobjcurr method and family @@ -1240,7 +1240,7 @@ class address(Addon, moduleBase): ifaceobjcurr.update_config_with_status('address', str(address), address not in intf_running_addrs) try: intf_running_addrs.remove(address) - except: + except Exception: pass # if any ip address is left in 'intf_running_addrs' it means that they @@ -1283,7 +1283,7 @@ class address(Addon, moduleBase): for default_addr in self.default_loopback_addresses: try: intf_running_addrs.remove(default_addr) - except: + except Exception: pass ifaceobjrunning.addr_family.append('inet') ifaceobjrunning.addr_method = 'loopback' diff --git a/ifupdown2/addons/addressvirtual.py b/ifupdown2/addons/addressvirtual.py index 9947175..f2b37f6 100644 --- a/ifupdown2/addons/addressvirtual.py +++ b/ifupdown2/addons/addressvirtual.py @@ -434,7 +434,7 @@ class addressvirtual(Addon, moduleBase): # so for now we should only use the iproute2 API. # try: # self.netlink.link_add_macvlan(ifname, macvlan_ifname) - # except: + # except Exception: self.iproute2.link_add_macvlan(ifname, macvlan_ifname, macvlan_mode) link_created = True @@ -708,7 +708,7 @@ class addressvirtual(Addon, moduleBase): for vrr_config in old_ifaceobj.get_attr_value("vrrp") or []: try: old_vrr_ids.add(vrr_config.split()[0]) - except: + except Exception: continue if old_vrr_ids: diff --git a/ifupdown2/addons/bond.py b/ifupdown2/addons/bond.py index cb73f50..8d9c647 100644 --- a/ifupdown2/addons/bond.py +++ b/ifupdown2/addons/bond.py @@ -413,13 +413,13 @@ class bond(Addon, moduleBase): try: miimon = int(ifaceobj.get_attr_value_first('bond-miimon')) - except: + except Exception: try: miimon = int(policymanager.policymanager_api.get_iface_default( module_name=self.__class__.__name__, ifname=ifaceobj.name, attr='bond-miimon')) - except: + except Exception: miimon = 0 if not miimon: @@ -618,7 +618,7 @@ class bond(Addon, moduleBase): try: bond_slaves.remove(lower_dev) - except: + except Exception: pass else: @@ -746,7 +746,7 @@ class bond(Addon, moduleBase): running_bond_slaves = self.cache.get_slaves(ifaceobj.name) self._query_check_bond_slaves(ifaceobjcurr, 'bond-slaves', user_bond_slaves, running_bond_slaves) - except: + except Exception: pass try: del iface_attrs[iface_attrs.index('bond-ports')] @@ -757,7 +757,7 @@ class bond(Addon, moduleBase): running_bond_slaves = self.cache.get_slaves(ifaceobj.name) self._query_check_bond_slaves(ifaceobjcurr, 'bond-ports', user_bond_slaves, running_bond_slaves) - except: + except Exception: pass for attr in iface_attrs: diff --git a/ifupdown2/addons/bridge.py b/ifupdown2/addons/bridge.py index d990b66..c719657 100644 --- a/ifupdown2/addons/bridge.py +++ b/ifupdown2/addons/bridge.py @@ -678,7 +678,7 @@ class bridge(Addon, moduleBase): self.bridge_allow_multiple_vlans = utils.get_boolean_from_string( self.sysctl_get('net.bridge.bridge-allow-multiple-vlans') ) - except: + except Exception: # Cumulus Linux specific variable. Failure probably means that # ifupdown2 is running a a different system. self.bridge_allow_multiple_vlans = True @@ -1027,7 +1027,7 @@ class bridge(Addon, moduleBase): if not waitportvals: return try: waitporttime = int(waitportvals[0]) - except: + except Exception: self.log_warn('%s: invalid waitport value \'%s\'' %(ifaceobj.name, waitportvals[0])) return @@ -1172,7 +1172,7 @@ class bridge(Addon, moduleBase): # to avoid any side effect we remove the dummy brport from the # list of supposedly newly configured ports. newly_enslaved_ports.remove(dummy_brport) - except: + except Exception: pass return newly_enslaved_ports @@ -1201,7 +1201,7 @@ class bridge(Addon, moduleBase): if not maxwait: return try: maxwait = int(maxwait) - except: + except Exception: self.log_warn('%s: invalid maxwait value \'%s\'' %(ifaceobj.name, maxwait)) return @@ -1240,7 +1240,7 @@ class bridge(Addon, moduleBase): else: a = int(part) result.append(a) - except: + except Exception: self.logger.warning('unable to parse vids \'%s\'' %''.join(rangelist)) pass @@ -1365,7 +1365,7 @@ class bridge(Addon, moduleBase): try: running_stp_state = self.read_file_oneline(stp_state_file) return running_stp_state and running_stp_state != '0' - except: + except Exception: return False def _is_config_stp_state_on(self, ifaceobj): @@ -1461,7 +1461,7 @@ class bridge(Addon, moduleBase): # i.e. our default value is 31 but the kernel default seems to be 3125 cached_ifla_info_data[Link.IFLA_BR_MCAST_STARTUP_QUERY_INTVL] //= 100 cached_ifla_info_data[Link.IFLA_BR_MCAST_STARTUP_QUERY_INTVL] *= 100 - except: + except Exception: pass for attr_name, nl_attr in self._ifla_br_attributes_map.items(): @@ -1704,7 +1704,7 @@ class bridge(Addon, moduleBase): for vlan in user_config_vids: try: vids_list.remove(vlan) - except: + except Exception: pass return vids_list @@ -1929,7 +1929,7 @@ class bridge(Addon, moduleBase): # part of ifla_info_slave_data. try: del brport_ifla_info_slave_data[Link.IFLA_BRPORT_LEARNING] - except: + except Exception: pass # @@ -2061,7 +2061,7 @@ class bridge(Addon, moduleBase): if '=' in br_config: try: br_config = self.parse_interface_list_value(br_config) - except: + except Exception: self.log_error('error while parsing \'%s %s\'' % (attr_name, br_config)) continue @@ -2113,7 +2113,7 @@ class bridge(Addon, moduleBase): elif self.arp_nd_suppress_only_on_vxlan and brport_ifaceobj.link_kind & ifaceLinkKind.VXLAN: # ignore the case of VXLAN brport - handled later in the code continue - except: + except Exception: continue elif nl_attr == Link.IFLA_BRPORT_GROUP_FWD_MASK: # special handking for group_fwd_mask because Cisco proprietary @@ -2265,7 +2265,7 @@ class bridge(Addon, moduleBase): # we need to remove this attribute from the request dictionary try: del brport_ifla_info_slave_data[Link.IFLA_BRPORT_NEIGH_SUPPRESS] - except: + except Exception: pass # @@ -2318,7 +2318,7 @@ class bridge(Addon, moduleBase): try: vlans_str, vni_str = vlan_vni_map.split("=") - except: + except Exception: return self.__warn_bridge_vlan_vni_map_syntax_error(vlan_vni_map) vlans = self._ranges_to_ints([vlans_str]) @@ -2623,7 +2623,7 @@ class bridge(Addon, moduleBase): try: self.netlink.link_del(self.get_dummy_brport_name_for_bridge(ifname)) - except: + except Exception: pass try: @@ -2794,7 +2794,7 @@ class bridge(Addon, moduleBase): bridge_attributes_map = dict(self._ifla_br_attributes_map) try: del bridge_attributes_map[Link.IFLA_BR_STP_STATE] - except: + except Exception: pass # @@ -2809,7 +2809,7 @@ class bridge(Addon, moduleBase): try: del bridge_attributes_map[Link.IFLA_BR_VLAN_STATS_ENABLED] - except: + except Exception: pass lambda_nl_value_int_divide100 = lambda x: str(x // 100) @@ -3078,7 +3078,7 @@ class bridge(Addon, moduleBase): if utils.get_boolean_from_string(bridge_always_up): try: link_exists = self.cache.link_exists(self.get_dummy_brport_name_for_bridge(ifname)) - except: + except Exception: link_exists = False ifaceobjcurr.update_config_with_status( @@ -3219,7 +3219,7 @@ class bridge(Addon, moduleBase): if utils.get_boolean_from_string(ifaceobj.get_attr_value_first("bridge-always-up")): try: running_port_list.remove(self.get_dummy_brport_name_for_bridge(ifaceobj.name)) - except: + except Exception: pass bridge_all_ports = [] @@ -3242,7 +3242,7 @@ class bridge(Addon, moduleBase): if port_list[i] in running_port_list: ordered.append(port_list[i]) port_list = ordered - except: + except Exception: port_list = running_port_list difference = set(running_port_list).symmetric_difference(bridge_all_ports) @@ -3524,7 +3524,7 @@ class bridge(Addon, moduleBase): try: vlans_str, vni_str = bridge_vlan_vni_map.split("=") - except: + except Exception: ifaceobjcurr.update_config_with_status("bridge-vlan-vni-map", bridge_vlan_vni_map, 1) return self.__warn_bridge_vlan_vni_map_syntax_error(bridge_vlan_vni_map) @@ -3541,7 +3541,7 @@ class bridge(Addon, moduleBase): try: for vlan in vlans_list: cached_vlans.remove(vlan) - except: + except Exception: ifaceobjcurr.update_config_with_status("bridge-vlan-vni-map", bridge_vlan_vni_map, 1) fail = True continue @@ -3549,7 +3549,7 @@ class bridge(Addon, moduleBase): try: for vni in vnis_list: cached_vnis.remove(vni) - except: + except Exception: ifaceobjcurr.update_config_with_status("bridge-vlan-vni-map", bridge_vlan_vni_map, 1) fail = True continue @@ -3616,7 +3616,7 @@ class bridge(Addon, moduleBase): try: config_per_port_dict = self.parse_interface_list_value(user_config_l2protocol_tunnel) brport_list = list(config_per_port_dict.keys()) - except: + except Exception: ifaceobjcurr.update_config_with_status('bridge-l2protocol-tunnel', user_config_l2protocol_tunnel, 1) return else: diff --git a/ifupdown2/addons/bridgevlan.py b/ifupdown2/addons/bridgevlan.py index e6f536f..a8b8255 100644 --- a/ifupdown2/addons/bridgevlan.py +++ b/ifupdown2/addons/bridgevlan.py @@ -72,7 +72,7 @@ class bridgevlan(Addon, moduleBase): try: (bridgename, vlan) = self._get_bridge_n_vlan(ifaceobj) vlanid = int(vlan, 10) - except: + except Exception: self.log_error("%s: bridge vlan interface name does not correspond " "to format (eg. br0.100)" % ifaceobj.name, ifaceobj) raise @@ -105,7 +105,7 @@ class bridgevlan(Addon, moduleBase): try: (bridgename, vlan) = self._get_bridge_n_vlan(ifaceobj) vlanid = int(vlan, 10) - except: + except Exception: self.logger.warning("%s: bridge vlan interface name does not " "correspond to format (eg. br0.100)" % ifaceobj.name) raise diff --git a/ifupdown2/addons/dhcp.py b/ifupdown2/addons/dhcp.py index b27dfce..71a8bdf 100644 --- a/ifupdown2/addons/dhcp.py +++ b/ifupdown2/addons/dhcp.py @@ -61,7 +61,7 @@ class dhcp(Addon, moduleBase): attr="dhclient_retry_on_failure" ) ) - except: + except Exception: self.dhclient_retry_on_failure = self.DHCLIENT_RETRY_ON_FAILURE if self.dhclient_retry_on_failure < 0: @@ -93,7 +93,7 @@ class dhcp(Addon, moduleBase): if ip: ips.add(ip) - except: + except Exception: pass return ips @@ -149,7 +149,7 @@ class dhcp(Addon, moduleBase): ifname=ifaceobj.name, attr='dhcp6-ll-wait') try: timeout = int(dhcp6_ll_wait)+1 - except: + except Exception: timeout = 10 pass dhcp6_duid = policymanager.policymanager_api.get_iface_default(module_name=self.__class__.__name__, \ @@ -171,7 +171,7 @@ class dhcp(Addon, moduleBase): try: if not ifupdownflags.flags.PERFMODE: self.dhclientcmd.stop(ifaceobj.name) - except: + except Exception: pass self.dhclient_start_and_check( @@ -199,7 +199,7 @@ class dhcp(Addon, moduleBase): '.autoconf', autoconf) try: self.dhclientcmd.stop6(ifaceobj.name, duid=dhcp6_duid) - except: + except Exception: pass #add delay before starting IPv6 dhclient to #make sure the configured interface/link is up. @@ -227,7 +227,7 @@ class dhcp(Addon, moduleBase): if not family in ifaceobj.addr_family and dhclientX_running: ifaceobj.addr_family = [family] self._dhcp_down(ifaceobj) - except: + except Exception: pass finally: ifaceobj.addr_family = addr_family @@ -319,7 +319,7 @@ class dhcp(Addon, moduleBase): (ifaceobj.addr_method != 'dhcp' and ifaceobj.addr_method != 'dhcp6')): return - except: + except Exception: return if not self.is_dhcp_allowed_on(ifaceobj, syntax_check=False): return diff --git a/ifupdown2/addons/mstpctl.py b/ifupdown2/addons/mstpctl.py index 4096590..b2632b0 100644 --- a/ifupdown2/addons/mstpctl.py +++ b/ifupdown2/addons/mstpctl.py @@ -424,7 +424,7 @@ class mstpctl(Addon, moduleBase): try: running_val = self.mstpctlcmd.get_bridge_attr( ifaceobj.name, jsonAttr) - except: + except Exception: self.logger.info('%s: could not get running %s value' %(ifaceobj.name, attrname)) running_val = None @@ -612,7 +612,7 @@ class mstpctl(Addon, moduleBase): try: running_val = self.mstpctlcmd.get_bridge_port_attr(bridgename, ifaceobj.name, jsonAttr) - except: + except Exception: self.logger.info('%s %s: could not get running %s value' %(bridgename, ifaceobj.name, attrname)) running_val = None @@ -892,7 +892,7 @@ class mstpctl(Addon, moduleBase): jsonAttr = self.get_mod_subattr(k, 'jsonAttr') try: running_val = self.mstpctlcmd.get_bridge_port_attr(ifaceobj.name, bport, jsonAttr) - except: + except Exception: self.logger.info('%s %s: could not get running %s value' %(ifaceobj.name, bport, attr)) running_val = None @@ -1015,7 +1015,7 @@ class mstpctl(Addon, moduleBase): try: running_val = self.mstpctlcmd.get_bridge_port_attr(bifaceobj.name, ifaceobj.name, jsonAttr) - except: + except Exception: self.logger.info('%s %s: could not get running %s value' %(bifaceobj.name, ifaceobj.name, attr)) running_val = None diff --git a/ifupdown2/addons/openvswitch.py b/ifupdown2/addons/openvswitch.py index 43aca48..8ba2806 100644 --- a/ifupdown2/addons/openvswitch.py +++ b/ifupdown2/addons/openvswitch.py @@ -13,7 +13,7 @@ try: from ifupdown2.ifupdown.exceptions import moduleNotSupported import ifupdown2.ifupdown.ifupdownflags as ifupdownflags -except: +except Exception: from lib.addon import Addon from ifupdown.iface import * diff --git a/ifupdown2/addons/openvswitch_port.py b/ifupdown2/addons/openvswitch_port.py index 72bd4bf..856a023 100644 --- a/ifupdown2/addons/openvswitch_port.py +++ b/ifupdown2/addons/openvswitch_port.py @@ -13,7 +13,7 @@ try: from ifupdown2.ifupdown.exceptions import moduleNotSupported import ifupdown2.ifupdown.ifupdownflags as ifupdownflags -except: +except Exception: from lib.addon import Addon from ifupdown.iface import * diff --git a/ifupdown2/addons/tunnel.py b/ifupdown2/addons/tunnel.py index 5c8a69a..66d6178 100644 --- a/ifupdown2/addons/tunnel.py +++ b/ifupdown2/addons/tunnel.py @@ -205,7 +205,7 @@ class tunnel(Addon, moduleBase): """ try: user_config[attr_name] = ipnetwork.IPNetwork(user_config[attr_name]) - except: + except Exception: pass def _query_check(self, ifaceobj, ifaceobjcurr): diff --git a/ifupdown2/addons/vrf.py b/ifupdown2/addons/vrf.py index 5c37968..91e9b4c 100644 --- a/ifupdown2/addons/vrf.py +++ b/ifupdown2/addons/vrf.py @@ -465,7 +465,7 @@ class vrf(Addon, moduleBase): dhclient_cmd_prefix = '%s %s' %(self.vrf_exec_cmd_prefix, vrfname) self.dhclientcmd.release(ifaceobj.name, dhclient_cmd_prefix) - except: + except Exception: # ignore any dhclient release errors pass diff --git a/ifupdown2/addons/vrrpd.py b/ifupdown2/addons/vrrpd.py index e09d154..c343eaf 100644 --- a/ifupdown2/addons/vrrpd.py +++ b/ifupdown2/addons/vrrpd.py @@ -52,7 +52,7 @@ class vrrpd(moduleBase): try: cmdl = [utils.pidof_cmd, cmdname] pidstr = utils.exec_commandl(cmdl, stderr=None).strip('\n') - except: + except Exception: pass if not pidstr: return [] @@ -70,7 +70,7 @@ class vrrpd(moduleBase): self.logger.info('(%d) (%d)' %(len(pcmdline), len(tmpcmdline))) if pcmdline and pcmdline == tmpcmdline: targetpids.append(pid) - except: + except Exception: pass return targetpids diff --git a/ifupdown2/addons/vxlan.py b/ifupdown2/addons/vxlan.py index 9b080d6..f498b16 100644 --- a/ifupdown2/addons/vxlan.py +++ b/ifupdown2/addons/vxlan.py @@ -151,7 +151,7 @@ class vxlan(Addon, moduleBase): self.logger.warning('%s: vxlan-local-tunnelip and clagd-vxlan-anycast-ip are identical (%s)' % (ifname, local_ip)) return False - except: + except Exception: pass return True @@ -266,7 +266,7 @@ class vxlan(Addon, moduleBase): if vxlan_ageing_str: return int(vxlan_ageing_str) - except: + except Exception: self.log_error("%s: invalid vxlan-ageing '%s'" % (ifname, vxlan_ageing_str), ifaceobj) def __config_vxlan_ageing(self, ifname, ifaceobj, link_exists, user_request_vxlan_info_data, cached_vxlan_ifla_info_data): @@ -324,7 +324,7 @@ class vxlan(Addon, moduleBase): self.logger.info("%s: set vxlan-port %s" % (ifname, vxlan_port)) user_request_vxlan_info_data[Link.IFLA_VXLAN_PORT] = vxlan_port - except: + except Exception: self.log_error("%s: invalid vxlan-port '%s'" % (ifname, vxlan_port_str), ifaceobj) def __config_vxlan_ttl(self, ifname, ifaceobj, user_request_vxlan_info_data, cached_vxlan_ifla_info_data): @@ -357,7 +357,7 @@ class vxlan(Addon, moduleBase): self.logger.info("%s: set vxlan-ttl %s" % (ifname, vxlan_ttl_str if vxlan_ttl_str else vxlan_ttl)) user_request_vxlan_info_data[Link.IFLA_VXLAN_TTL] = vxlan_ttl - except: + except Exception: self.log_error("%s: invalid vxlan-ttl '%s'" % (ifname, vxlan_ttl_str), ifaceobj) def __config_vxlan_local_tunnelip(self, ifname, ifaceobj, link_exists, user_request_vxlan_info_data, cached_vxlan_ifla_info_data): @@ -596,7 +596,7 @@ class vxlan(Addon, moduleBase): except NetlinkCacheIfnameNotFoundError: try: vxlan_physdev_ifindex = int(self.sysfs.read_file_oneline("/sys/class/net/%s/ifindex" % vxlan_physdev)) - except: + except Exception: self.logger.error("%s: physdev %s doesn't exists" % (ifaceobj.name, vxlan_physdev)) return @@ -746,7 +746,7 @@ class vxlan(Addon, moduleBase): "00:00:00:00:00:00", None, True, addr ) - except: + except Exception: pass for addr in add_list: @@ -756,7 +756,7 @@ class vxlan(Addon, moduleBase): "00:00:00:00:00:00", None, True, addr ) - except: + except Exception: pass def _down(self, ifaceobj): diff --git a/ifupdown2/ifupdown/argv.py b/ifupdown2/ifupdown/argv.py index cb32e05..47c0d63 100644 --- a/ifupdown2/ifupdown/argv.py +++ b/ifupdown2/ifupdown/argv.py @@ -112,7 +112,7 @@ class Parse: if self.executable_name.endswith(key): return value raise ArgvParseError("Unexpected executable. Should be '%s'" % "' or '".join(list(self.valid_ops.keys()))) - except: + except Exception: raise ArgvParseError("Unexpected executable. Should be '%s'" % "' or '".join(list(self.valid_ops.keys()))) def get_args(self): diff --git a/ifupdown2/ifupdown/client.py b/ifupdown2/ifupdown/client.py index 692d10b..f63bdcb 100644 --- a/ifupdown2/ifupdown/client.py +++ b/ifupdown2/ifupdown/client.py @@ -180,12 +180,12 @@ class Client(SocketIO): try: self.uds.close() self.uds = None - except: + except Exception: pass try: self.socket_receiver.server_close() self.socket_receiver = None - except: + except Exception: pass def __signal_handler(self, sig, frame): diff --git a/ifupdown2/ifupdown/graph.py b/ifupdown2/ifupdown/graph.py index 6352e44..2e58143 100644 --- a/ifupdown2/ifupdown/graph.py +++ b/ifupdown2/ifupdown/graph.py @@ -54,7 +54,7 @@ class graph(): for y in dlist: try: indegrees[y] = indegrees.get(y) - 1 - except: + except Exception: cls.logger.debug('topological_sort_graphs_all: did not find %s' %y) indegrees[y] = 0 pass diff --git a/ifupdown2/ifupdown/iface.py b/ifupdown2/ifupdown/iface.py index d834512..15afe08 100644 --- a/ifupdown2/ifupdown/iface.py +++ b/ifupdown2/ifupdown/iface.py @@ -542,7 +542,7 @@ class iface(): if attr_value_list: try: return attr_value_list[attr_index] - except: + except Exception: return None return None @@ -576,7 +576,7 @@ class iface(): """ add attribute name and value to the interface config """ try: del self.config[attr_name] - except: + except Exception: pass def update_config_dict(self, attrdict): diff --git a/ifupdown2/ifupdown/ifupdownmain.py b/ifupdown2/ifupdown/ifupdownmain.py index 549923e..437eea5 100644 --- a/ifupdown2/ifupdown/ifupdownmain.py +++ b/ifupdown2/ifupdown/ifupdownmain.py @@ -118,7 +118,7 @@ class ifupdownMain: return try: self.netlink.link_up(ifaceobj.name) - except: + except Exception: if ifaceobj.addr_method == 'manual': pass else: @@ -158,7 +158,7 @@ class ifupdownMain: self.netlink.link_down(ifaceobj.name) else: self.logger.info("%s: ifupdown2 cannot bring loopback interface down" % ifaceobj.name) - except: + except Exception: if ifaceobj.addr_method == 'manual': pass else: @@ -189,14 +189,14 @@ class ifupdownMain: ifupdown2.ifupdown.ifupdownflags.reset() ifupdownConfig.reset() ifupdown2.ifupdownaddons.mstpctlutil.mstpctlutil.reset() - except: + except Exception: try: ifupdown.statemanager.reset() ifupdown.policymanager.reset() ifupdown.ifupdownflags.reset() ifupdownConfig.reset() ifupdownaddons.mstpctlutil.mstpctlutil.reset() - except: + except Exception: pass def ignore_error(self, errmsg): @@ -421,12 +421,12 @@ class ifupdownMain: mgmt_iface_default_prefix = ifupdown2.ifupdown.policymanager.policymanager_api.get_module_globals( module_name='main', attr='mgmt_intf_prefix' ) - except: + except Exception: try: mgmt_iface_default_prefix = ifupdown.policymanager.policymanager_api.get_module_globals( module_name='main', attr='mgmt_intf_prefix' ) - except: + except Exception: pass if not mgmt_iface_default_prefix: mgmt_iface_default_prefix = "eth" @@ -846,7 +846,7 @@ class ifupdownMain: for d in difaceobjs: d.dec_refcnt() d.upperifaces.remove(i) - except: + except Exception: self.logger.debug('error removing %s from %s upperifaces' %(i, d)) pass self.logger.debug("populate_dependency_info: deleting blacklisted interface %s" %i) @@ -1082,7 +1082,7 @@ class ifupdownMain: for arg in value.replace(",", " ").split(): if arg not in ['all', 'stp', 'lldp', 'lacp', 'cdp', 'pvst']: return False - except: + except Exception: return False return True @@ -1215,7 +1215,7 @@ class ifupdownMain: if prev: return False prev = True - except: + except Exception: prev = False return not prev except Exception as e: @@ -1440,14 +1440,14 @@ class ifupdownMain: self.logger.info('module %s not loaded (%s)' %(mname, str(e))) continue - except: + except Exception: raise self.modules[mname] = minstance try: self.module_attrs[mname] = minstance.get_modinfo() - except: + except Exception: pass - except: + except Exception: raise # Assign all modules to query operations @@ -1512,7 +1512,7 @@ class ifupdownMain: print('%sexample:' %(indent + ' ')) for e in examples: print('%s%s' %(indent + ' ', e)) - except: + except Exception: pass print('') @@ -1534,7 +1534,7 @@ class ifupdownMain: if self.modules.get(module) or module in self.overridden_ifupdown_scripts: continue self.script_ops[op].append(msubdir + '/' + module) - except: + except Exception: # continue reading pass @@ -1731,7 +1731,7 @@ class ifupdownMain: return ifupdown2.ifupdown.policymanager.policymanager_api.get_iface_default( module_name='main', ifname=ifacename, attr='exclude-companion') - except: + except Exception: return ifupdown.policymanager.policymanager_api.get_iface_default( module_name='main', ifname=ifacename, attr='exclude-companion') @@ -2070,7 +2070,7 @@ class ifupdownMain: try: iface_read_ret = self.read_iface_config() - except: + except Exception: raise if not self.ifaceobjdict: self.logger.warning("nothing to reload ..exiting.") @@ -2164,7 +2164,7 @@ class ifupdownMain: try: iface_read_ret = self.read_iface_config() - except: + except Exception: raise if not self.ifaceobjdict: diff --git a/ifupdown2/ifupdown/main.py b/ifupdown2/ifupdown/main.py index 77d9480..5ab07fa 100644 --- a/ifupdown2/ifupdown/main.py +++ b/ifupdown2/ifupdown/main.py @@ -196,7 +196,7 @@ class Ifupdown2: printdependency=args.printdependency, syntaxcheck=args.syntaxcheck, type=args.type, skipupperifaces=args.skipupperifaces) - except: + except Exception: raise def run_down(self, args): @@ -222,7 +222,7 @@ class Ifupdown2: printdependency=args.printdependency, usecurrentconfig=args.usecurrentconfig, type=args.type) - except: + except Exception: raise def run_query(self, args): @@ -267,7 +267,7 @@ class Ifupdown2: excludepats=args.excludepats, printdependency=args.printdependency, format=args.format, type=args.type) - except: + except Exception: raise def run_reload(self, args): @@ -288,5 +288,5 @@ class Ifupdown2: usecurrentconfig=args.usecurrentconfig, syntaxcheck=args.syntaxcheck, currentlyup=args.currentlyup) - except: + except Exception: raise diff --git a/ifupdown2/ifupdown/networkinterfaces.py b/ifupdown2/ifupdown/networkinterfaces.py index 97ebfc4..3dd43bb 100644 --- a/ifupdown2/ifupdown/networkinterfaces.py +++ b/ifupdown2/ifupdown/networkinterfaces.py @@ -82,7 +82,7 @@ class networkInterfaces(): def _currentfile(self): try: return self._filestack[-1] - except: + except Exception: return self.interfacesfile def _parse_error(self, filename, lineno, msg): @@ -209,7 +209,7 @@ class networkInterfaces(): 'iface %s: unsupported keyword (%s)' %(ifacename, attrname)) return - except: + except Exception: pass attrvallist = iface_config.get(newattrname, []) if newattrname in ['scope', 'netmask', 'broadcast', 'preferred-lifetime']: diff --git a/ifupdown2/ifupdown/statemanager.py b/ifupdown2/ifupdown/statemanager.py index 62b0148..cc4da99 100644 --- a/ifupdown2/ifupdown/statemanager.py +++ b/ifupdown2/ifupdown/statemanager.py @@ -33,7 +33,7 @@ class pickling(): with open(filename, 'wb') as f: for obj in list_of_objects: pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL) - except: + except Exception: raise @classmethod @@ -41,7 +41,7 @@ class pickling(): """ pickle iface object """ try: pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL) - except: + except Exception: raise @classmethod @@ -51,7 +51,7 @@ class pickling(): while True: try: yield pickle.load(f) except EOFError: break - except: raise + except Exception: raise class stateManager(): """ state manager for managing ifupdown iface obj state @@ -200,7 +200,7 @@ class stateManager(): for ifaceobjs in list(self.ifaceobjdict.values()): [pickling.save_obj(f, i) for i in ifaceobjs] open('%s/%s' %(self.state_rundir, self.state_runlockfile), 'w').close() - except: + except Exception: raise def dump_pretty(self, ifacenames, format='native'): diff --git a/ifupdown2/ifupdown/utils.py b/ifupdown2/ifupdown/utils.py index d34f559..d638fe9 100644 --- a/ifupdown2/ifupdown/utils.py +++ b/ifupdown2/ifupdown/utils.py @@ -194,7 +194,7 @@ class utils(): def get_int_from_boolean_and_string(value): try: return int(value) - except: + except Exception: return int(utils.get_boolean_from_string(value)) @staticmethod diff --git a/ifupdown2/ifupdownaddons/dhclient.py b/ifupdown2/ifupdownaddons/dhclient.py index c6c51a0..cf03f9a 100644 --- a/ifupdown2/ifupdownaddons/dhclient.py +++ b/ifupdown2/ifupdownaddons/dhclient.py @@ -29,9 +29,9 @@ class dhclient(utilsBase): try: if e.errno == errno.EACCES: return os.path.exists("/proc/%s" % self.read_file_oneline(pidfilename)) - except: + except Exception: return False - except: + except Exception: return False return False diff --git a/ifupdown2/ifupdownaddons/modulebase.py b/ifupdown2/ifupdownaddons/modulebase.py index f77bbff..589513d 100644 --- a/ifupdown2/ifupdownaddons/modulebase.py +++ b/ifupdown2/ifupdownaddons/modulebase.py @@ -120,7 +120,7 @@ class moduleBase(object): try: utils.exec_command('%s -x %s' % (utils.pidof_cmd, procName)) - except: + except Exception: return False else: return True @@ -132,14 +132,14 @@ class moduleBase(object): lines = f.readlines() for line in lines[2:]: ifacenames.append(line.split()[0].strip(': ')) - except: + except Exception: raise return ifacenames def parse_regex(self, ifacename, expr, ifacenames=None): try: proc_ifacenames = self.get_ifaces_from_proc() - except: + except Exception: self.logger.warning('%s: error reading ifaces from proc' %ifacename) for proc_ifacename in proc_ifacenames: @@ -292,7 +292,7 @@ class moduleBase(object): self.logger.info('reading \'%s\'' %filename) with open(filename, 'r') as f: return f.readlines() - except: + except Exception: return None return None @@ -302,7 +302,7 @@ class moduleBase(object): self.logger.info('reading \'%s\'' %filename) with open(filename, 'r') as f: return f.readline().strip('\n') - except: + except Exception: return None return None @@ -325,7 +325,7 @@ class moduleBase(object): return self._bridge_stp_user_space try: self._bridge_stp_user_space = self.sysctl_get('net.bridge.bridge-stp-user-space') - except: + except Exception: self._bridge_stp_user_space = 0 return self._bridge_stp_user_space @@ -379,14 +379,14 @@ class moduleBase(object): if 'aliases' in attrvals: retattrs.extend(attrvals['aliases']) return retattrs - except: + except Exception: return None def get_mod_attr(self, attrname): """ returns module attr info """ try: return self._modinfo.get('attrs', {}).get(attrname) - except: + except Exception: return None def get_mod_subattr(self, attrname, subattrname): @@ -394,14 +394,14 @@ class moduleBase(object): try: return reduce(lambda d, k: d[k], ['attrs', attrname, subattrname], self._modinfo) - except: + except Exception: return None def get_modinfo(self): """ return module info """ try: return self._modinfo - except: + except Exception: return {} def get_attr_default_value(self, attrname): @@ -411,7 +411,7 @@ class moduleBase(object): """ return the ifupdown scripts replaced by the current module """ try: return self.overrides_ifupdown_scripts - except: + except Exception: return [] def _get_reserved_vlan_range(self): @@ -482,7 +482,7 @@ class moduleBase(object): return -1 try: vid = int(vid_str) - except: + except Exception: return -1 return vid @@ -499,7 +499,7 @@ class moduleBase(object): vid_str = ifaceobj.get_attr_value_first('vlan-id') try: if vid_str: return int(vid_str) - except: + except Exception: return -1 return self._get_vlan_id_from_ifacename(ifaceobj.name) diff --git a/ifupdown2/ifupdownaddons/mstpctlutil.py b/ifupdown2/ifupdownaddons/mstpctlutil.py index 9424fc1..0e0026b 100644 --- a/ifupdown2/ifupdownaddons/mstpctlutil.py +++ b/ifupdown2/ifupdownaddons/mstpctlutil.py @@ -96,7 +96,7 @@ class mstpctlutil(utilsBase): "%s batch -" % utils.mstpctl_cmd, stdin="\n".join(self.__batch) ) - except: + except Exception: raise finally: self.__batch_mode = False @@ -114,7 +114,7 @@ class mstpctlutil(utilsBase): def is_mstpd_running(self): try: utils.exec_command('%s mstpd'%utils.pidof_cmd) - except: + except Exception: return False else: return True @@ -122,7 +122,7 @@ class mstpctlutil(utilsBase): def _extract_bridge_port_prio(self, portid): try: return str(int(portid[0], 16) * 16) - except: + except Exception: return mstpctlutil._DEFAULT_PORT_PRIO def _get_bridge_and_port_attrs_from_cache(self, bridgename): @@ -288,5 +288,5 @@ class mstpctlutil(utilsBase): utils.exec_command('%s showbridge %s' % (utils.mstpctl_cmd, bridgename)) return True - except: + except Exception: return False diff --git a/ifupdown2/ifupdownaddons/systemutils.py b/ifupdown2/ifupdownaddons/systemutils.py index 505efdd..13369ed 100644 --- a/ifupdown2/ifupdownaddons/systemutils.py +++ b/ifupdown2/ifupdownaddons/systemutils.py @@ -31,7 +31,7 @@ class systemUtils(): try: utils.exec_command('%s %s' % (utils.pidof_cmd, procname)) - except: + except Exception: return False else: return True @@ -57,7 +57,7 @@ class systemUtils(): try: utils.exec_command('%s %s' % (utils.pidof_cmd, processname)) - except: + except Exception: return False else: return True diff --git a/ifupdown2/ifupdownaddons/utilsbase.py b/ifupdown2/ifupdownaddons/utilsbase.py index 9480aec..2467b89 100644 --- a/ifupdown2/ifupdownaddons/utilsbase.py +++ b/ifupdown2/ifupdownaddons/utilsbase.py @@ -56,7 +56,7 @@ class utilsBase(object): self.logger.debug('reading \'%s\'' %filename) with open(filename, 'r') as f: return f.readlines() - except: + except Exception: return None return None @@ -65,7 +65,7 @@ class utilsBase(object): self.logger.debug('reading \'%s\'' %filename) with open(filename, 'r') as f: return f.readline().strip('\n') - except: + except Exception: return None return None diff --git a/ifupdown2/lib/dry_run.py b/ifupdown2/lib/dry_run.py index 3f883f9..832c3c8 100644 --- a/ifupdown2/lib/dry_run.py +++ b/ifupdown2/lib/dry_run.py @@ -77,7 +77,7 @@ def WeakMethod(f): def _weakref_call_back_delete(reference): try: DryRunManager.get_instance().unregister_dry_run_handler_weakref_callback(reference) - except: + except Exception: pass @@ -119,7 +119,7 @@ class DryRun(object): handler_code_weakref=WeakMethod(base_attr_value), dry_run_code_weakref=WeakMethod(attr_value) ) - except: + except Exception: pass def log_info_ifname_dry_run(self, ifname, string): @@ -215,7 +215,7 @@ class DryRunManager(object): """ try: del self.__entries[reference] - except: + except Exception: pass def dry_run_mode_on(self): diff --git a/ifupdown2/lib/io.py b/ifupdown2/lib/io.py index c6ca443..7c1823f 100644 --- a/ifupdown2/lib/io.py +++ b/ifupdown2/lib/io.py @@ -56,7 +56,7 @@ class IO(BaseObject): self.logger.info("reading '%s'" % path) with open(path, "r") as f: return f.readline().strip("\n") - except: + except Exception: return None def read_file_oneline_dry_run(self, path): @@ -69,7 +69,7 @@ class IO(BaseObject): self.logger.info("reading '%s'" % path) with open(path, "r") as f: return f.readlines() - except: + except Exception: return None diff --git a/ifupdown2/lib/iproute2.py b/ifupdown2/lib/iproute2.py index 5025de0..8c9d98b 100644 --- a/ifupdown2/lib/iproute2.py +++ b/ifupdown2/lib/iproute2.py @@ -54,7 +54,7 @@ import socket # # try: # import ifupdown2.nlmanager.nlpacket as nlpacket # -except: # +except Exception: # import nlmanager.nlpacket as nlpacket # ################################################################################ @@ -119,7 +119,7 @@ class IPRoute2(Cache, Requirements): # i.e.: packet.flags shouldn't contain NLM_F_* values but IFF_* (in case of Link object) # otherwise call to cache.link_is_up() will probably return True packet.decode_service_header() - except: + except Exception: # we can ignore all errors pass @@ -168,7 +168,7 @@ class IPRoute2(Cache, Requirements): "%s -force -batch -" % prefix, stdin="\n".join(commands) ) - except: + except Exception: raise finally: self.__batch_mode = False @@ -352,7 +352,7 @@ class IPRoute2(Cache, Requirements): m = self.VXLAN_PEER_REGEX_PATTERN.search(l) if m and m.group(1) != svcnodeip: cur_peers.append(m.group(1)) - except: + except Exception: self.logger.warning('error parsing ip link output') except subprocess.CalledProcessError as e: if e.returncode != 1: @@ -545,7 +545,7 @@ class IPRoute2(Cache, Requirements): try: entries = fdb_entry.split() fdbs.setdefault(entries[2], []).append(entries[0]) - except: + except Exception: pass return fdbs except Exception: @@ -745,7 +745,7 @@ class IPRoute2(Cache, Requirements): vrf_table = self.cache.get_vrf_table(upper_iface) if vrf_table: break - except: + except Exception: pass ip_route_del = [] diff --git a/ifupdown2/lib/nlcache.py b/ifupdown2/lib/nlcache.py index df425b4..106c3e3 100644 --- a/ifupdown2/lib/nlcache.py +++ b/ifupdown2/lib/nlcache.py @@ -283,7 +283,7 @@ class _NetlinkCache: """ try: del self._link_cache[slave].attributes[Link.IFLA_MASTER] - except: + except Exception: pass try: @@ -389,7 +389,7 @@ class _NetlinkCache: try: with self._cache_lock: self._link_cache[ifname].flags = flags - except: + except Exception: pass def override_link_mtu(self, ifname, mtu): @@ -402,7 +402,7 @@ class _NetlinkCache: try: with self._cache_lock: self._link_cache[ifname].attributes[Link.IFLA_MTU].value = mtu - except: + except Exception: pass def override_cache_unslave_link(self, slave, master): @@ -456,7 +456,7 @@ class _NetlinkCache: # log.error('-----------') # log.error('-----------') # log.error('-----------') - except: + except Exception: traceback.print_exc() # TODO: save log_level at entry and re-apply it after the dump nllistener.log.setLevel(WARNING) @@ -485,7 +485,7 @@ class _NetlinkCache: msg.debug = True msg.dump() msg.debug = save_debug - except: + except Exception: traceback.print_exc() # TODO: save log_level at entry and re-apply it after the dump nllistener.log.setLevel(WARNING) @@ -1081,7 +1081,7 @@ class _NetlinkCache: else: vlans.append(vlan_id) - except: + except Exception: log.exception("get_bridge_vids") return pvid, vlans @@ -1103,7 +1103,7 @@ class _NetlinkCache: if vlan_flag & Link.BRIDGE_VLAN_INFO_PVID: return vlan_id - except: + except Exception: log.exception("get_pvid") return pvid @@ -1209,7 +1209,7 @@ class _NetlinkCache: if ifname in self._rtm_newlink_nomasterq: try: del link.attributes[Link.IFLA_MASTER] - except: + except Exception: self._rtm_newlink_nomasterq.remove(ifname) # we need to check if the device was previously enslaved @@ -1347,7 +1347,7 @@ class _NetlinkCache: try: with self._cache_lock: self._link_cache[ifname].attributes[Link.IFLA_LINKINFO].value[Link.IFLA_INFO_DATA].update(ifla_info_data) - except: + except Exception: pass def add_bridge_vlan(self, msg): @@ -1378,7 +1378,7 @@ class _NetlinkCache: if not ifla_master or not ifla_master in self._ifname_by_ifindex: return - except: + except Exception: pass # Example IFLA_AF_SPEC @@ -1427,11 +1427,11 @@ class _NetlinkCache: if old_master and old_master != master: try: self._masters_and_slaves.get(old_master, []).remove(slave) - except: + except Exception: pass self._slaves_master[slave] = master - except: + except Exception: # since this is an optimization function we can ignore all error pass @@ -1455,7 +1455,7 @@ class _NetlinkCache: for slave in slave_list: self._slaves_master[slave] = master - except: + except Exception: # since this is an optimization function we can ignore all error pass @@ -1522,17 +1522,17 @@ class _NetlinkCache: # have their bridge-vlans and _slaves_master entries cleared. for slave in list(self._masters_and_slaves[ifname]): self.__unslave_nolock(slave, master=ifname) - except: + except Exception: pass try: del self._bridge_vlan_cache[ifname] - except: + except Exception: pass try: del self._bridge_vlan_vni_cache[ifname] - except: + except Exception: pass try: @@ -1628,7 +1628,7 @@ class _NetlinkCache: try: with self._cache_lock: self._addr_cache[ifname][family] = [] - except: + except Exception: pass def address_flush_link(self, ifname): @@ -1640,7 +1640,7 @@ class _NetlinkCache: try: with self._cache_lock: self._addr_cache[ifname] = {4: [], 6: []} - except: + except Exception: pass def force_remove_addr(self, ifname, addr): @@ -1661,15 +1661,15 @@ class _NetlinkCache: try: if cache_addr.attributes[Address.IFA_ADDRESS].value == addr: obj_to_remove = cache_addr - except: + except Exception: try: if cache_addr.attributes[Address.IFA_LOCAL].value == addr: obj_to_remove = cache_addr - except: + except Exception: return if obj_to_remove: self._addr_cache[ifname][addr.version].remove(obj_to_remove) - except: + except Exception: pass def remove_address(self, addr_to_remove): @@ -1680,10 +1680,10 @@ class _NetlinkCache: # to find which one to remove from the cache try: ip_version = addr_to_remove.get_attribute_value(Address.IFA_ADDRESS).version - except: + except Exception: try: ip_version = addr_to_remove.get_attribute_value(Address.IFA_LOCAL).version - except: + except Exception: # print debug error return @@ -1735,7 +1735,7 @@ class _NetlinkCache: with self._cache_lock: intf_addresses = self._addr_cache[ifname] return bool(intf_addresses.get(4, None) or intf_addresses.get(6, None)) - except: + except Exception: return False ############################################################################ @@ -1755,7 +1755,7 @@ class _NetlinkCache: try: with self._netconf_cache_lock: self._netconf_cache[msg.family][msg.get_attribute_value(msg.NETCONFA_IFINDEX)] = msg - except: + except Exception: pass def remove_netconf(self, msg): @@ -1765,7 +1765,7 @@ class _NetlinkCache: try: with self._netconf_cache_lock: del self._netconf_cache[msg.family][msg.get_attribute_value(msg.NETCONFA_IFINDEX)] - except: + except Exception: pass def get_netconf_forwarding(self, family, ifname): @@ -1775,7 +1775,7 @@ class _NetlinkCache: try: with self._netconf_cache_lock: return self._netconf_cache[family][self.get_ifindex(ifname)].get_attribute_value(Netconf.NETCONFA_FORWARDING) - except: + except Exception: # if KeyError and family == AF_INET6: ipv6 is probably disabled on this device return None @@ -1786,7 +1786,7 @@ class _NetlinkCache: try: with self._netconf_cache_lock: return self._netconf_cache[AF_MPLS][self.get_ifindex(ifname)].get_attribute_value(Netconf.NETCONFA_INPUT) - except: + except Exception: return None ############################################################################ @@ -1834,7 +1834,7 @@ class _NetlinkCache: ip6.append(ip_network_obj) else: ip4.append(ip_network_obj) - except: + except Exception: continue # always return ip4 first, followed by ip6 @@ -1902,11 +1902,11 @@ class _NetlinkCache: ifa_address = cache_addr.attributes[Address.IFA_ADDRESS].value if ifa_address.ip == addr.ip and ifa_address.prefixlen == addr.prefixlen: return True - except: + except Exception: try: ifa_local = cache_addr.attributes[Address.IFA_LOCAL].value return ifa_local.ip == addr.ip and ifa_local.prefixlen == addr.prefixlen - except: + except Exception: pass except (KeyError, AttributeError): pass @@ -2157,7 +2157,7 @@ class NetlinkListenerWithCache(nllistener.NetlinkManagerWithListener, BaseObject self.logger.error('NetlinkListenerWithCache: WORKQ_SERVICE_ERROR') else: raise Exception("Unsupported workq event %s" % event) - except: + except Exception: raise finally: # il faut surement mettre un try/except autour de la boucle au dessus @@ -2283,7 +2283,7 @@ class NetlinkListenerWithCache(nllistener.NetlinkManagerWithListener, BaseObject # i.e.: packet.flags shouldn't contain NLM_F_* values but IFF_* (in case of Link object) # otherwise call to cache.link_is_up() will probably return True packet.decode_service_header() - except: + except Exception: # we can ignore all errors pass @@ -2306,7 +2306,7 @@ class NetlinkListenerWithCache(nllistener.NetlinkManagerWithListener, BaseObject try: result = self.tx_nlpacket_get_response_with_error(nl_packet) - except: + except Exception: # an error was caught, we need to unregister the event and raise again self.cache.unregister_wait_event() raise @@ -2575,7 +2575,7 @@ class NetlinkListenerWithCache(nllistener.NetlinkManagerWithListener, BaseObject # any stale value in our cache self.cache.force_remove_link(ifname) return result - except: + except Exception: # Something went wrong while sending the RTM_DELLINK request # we need to clear ifname from the ignore_rtm_newlinkq list self.cache.remove_from_ignore_rtm_newlinkq(ifname) @@ -3182,7 +3182,7 @@ class NetlinkListenerWithCache(nllistener.NetlinkManagerWithListener, BaseObject for addr in self.cache.get_ip_addresses(ifname): try: self.addr_del(ifname, addr) - except: + except Exception: pass ######################## diff --git a/ifupdown2/lib/sysfs.py b/ifupdown2/lib/sysfs.py index d56a26f..ad6e4c0 100644 --- a/ifupdown2/lib/sysfs.py +++ b/ifupdown2/lib/sysfs.py @@ -79,7 +79,7 @@ class __Sysfs(IO, Requirements): if not uppers: return [] return [os.path.basename(u)[6:] for u in uppers] - except: + except Exception: return [] @staticmethod @@ -89,7 +89,7 @@ class __Sysfs(IO, Requirements): if not lowers: return [] return [os.path.basename(l)[6:] for l in lowers] - except: + except Exception: return [] def link_is_up(self, ifname): @@ -163,7 +163,7 @@ class __Sysfs(IO, Requirements): try: stp_state_int = int(stp_state) return "yes" if stp_state_int > 0 else "no" - except: + except Exception: return "unknown" def bridge_get_mcqv4src(self, bridge): diff --git a/ifupdown2/nlmanager/nllistener.py b/ifupdown2/nlmanager/nllistener.py index e319dc4..71d47a9 100644 --- a/ifupdown2/nlmanager/nllistener.py +++ b/ifupdown2/nlmanager/nllistener.py @@ -113,7 +113,7 @@ class NetlinkListener(Thread): self.rx_socket.bind((pid | (pid_offset << 22), self.groups)) self.pid_offset = pid_offset return - except: + except Exception: pass # if we reach this line it means we've reach NLMANAGER_BIND_RETRY limit # and couldn't successfully bind the rx_socket... We will try one more diff --git a/ifupdown2/nlmanager/nlmanager.py b/ifupdown2/nlmanager/nlmanager.py index e9d3d2e..c720f9f 100644 --- a/ifupdown2/nlmanager/nlmanager.py +++ b/ifupdown2/nlmanager/nlmanager.py @@ -166,13 +166,13 @@ class NetlinkManager(object): ) self.pid = self.pid + i return - except: + except Exception: pass # if we reach this code it means all our bind calls failed. We are trying to # bind the socket one last time on the original parameters if not we will not # be catching the exception self.tx_socket.bind((self.pid, 0)) - except: + except Exception: if self.tx_socket: self.tx_socket.close() self.tx_socket = None