Skip to content

Commit

Permalink
use "except Exception:" instead of "except:"
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Fortin <[email protected]>
  • Loading branch information
julienfortin committed Jun 23, 2020
1 parent efa80e3 commit 3218f49
Show file tree
Hide file tree
Showing 36 changed files with 178 additions and 178 deletions.
6 changes: 3 additions & 3 deletions docs/examples/generate_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions ifupdown2/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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

Expand All @@ -47,7 +47,7 @@

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__
Expand All @@ -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


Expand All @@ -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())
Expand Down
10 changes: 5 additions & 5 deletions ifupdown2/addons/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def _process_bridge(self, ifaceobj, up):
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:
Expand Down Expand Up @@ -973,7 +973,7 @@ def _pre_up(self, ifaceobj, ifaceobj_getfunc=None):
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)
Expand Down Expand Up @@ -1224,7 +1224,7 @@ def _query_check_address(self, ifaceobj, ifaceobjcurr, ifaceobj_getfunc):

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
Expand All @@ -1240,7 +1240,7 @@ def _query_check_address(self, ifaceobj, ifaceobjcurr, ifaceobj_getfunc):
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
Expand Down Expand Up @@ -1283,7 +1283,7 @@ def _query_running(self, ifaceobjrunning, ifaceobj_getfunc=None):
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'
Expand Down
4 changes: 2 additions & 2 deletions ifupdown2/addons/addressvirtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def create_macvlan_and_apply_config(self, ifaceobj, intf_config_list, vrrp=False
# 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

Expand Down Expand Up @@ -708,7 +708,7 @@ def translate_vrr_user_config_to_list(self, ifaceobj, vrr_config_list, ifquery=F
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:
Expand Down
10 changes: 5 additions & 5 deletions ifupdown2/addons/bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,13 @@ def syntax_check_updown_delay(self, ifaceobj):

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:
Expand Down Expand Up @@ -618,7 +618,7 @@ def should_update_bond_mode(self, ifaceobj, ifname, is_link_up, ifla_info_data,

try:
bond_slaves.remove(lower_dev)
except:
except Exception:
pass

else:
Expand Down Expand Up @@ -746,7 +746,7 @@ def _query_check(self, ifaceobj, ifaceobjcurr, ifaceobj_getfunc=None):
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')]
Expand All @@ -757,7 +757,7 @@ def _query_check(self, ifaceobj, ifaceobjcurr, ifaceobj_getfunc=None):
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:
Expand Down
46 changes: 23 additions & 23 deletions ifupdown2/addons/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def __init__(self, *args, **kargs):
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
Expand Down Expand Up @@ -1027,7 +1027,7 @@ def _process_bridge_waitport(self, ifaceobj, portlist):
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
Expand Down Expand Up @@ -1172,7 +1172,7 @@ def _add_ports(self, ifaceobj, ifaceobj_getfunc):
# 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
Expand Down Expand Up @@ -1201,7 +1201,7 @@ def _process_bridge_maxwait(self, ifaceobj, portlist):
if not maxwait: return
try:
maxwait = int(maxwait)
except:
except Exception:
self.log_warn('%s: invalid maxwait value \'%s\'' %(ifaceobj.name,
maxwait))
return
Expand Down Expand Up @@ -1240,7 +1240,7 @@ def _ranges_to_ints(self, rangelist):
else:
a = int(part)
result.append(a)
except:
except Exception:
self.logger.warning('unable to parse vids \'%s\''
%''.join(rangelist))
pass
Expand Down Expand Up @@ -1365,7 +1365,7 @@ def _is_running_stp_state_on(self, bridgename):
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):
Expand Down Expand Up @@ -1461,7 +1461,7 @@ def up_apply_bridge_settings(self, ifaceobj, link_just_created, bridge_vlan_awar
# 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():
Expand Down Expand Up @@ -1704,7 +1704,7 @@ def remove_bridge_vlans_mapped_to_vnis_from_vids_list(self, bridge_ifaceobj, vxl
for vlan in user_config_vids:
try:
vids_list.remove(vlan)
except:
except Exception:
pass

return vids_list
Expand Down Expand Up @@ -1929,7 +1929,7 @@ def sync_bridge_learning_to_vxlan_brport(self, bridge_name, brport_ifaceobj, brp
# part of ifla_info_slave_data.
try:
del brport_ifla_info_slave_data[Link.IFLA_BRPORT_LEARNING]
except:
except Exception:
pass

#
Expand Down Expand Up @@ -2061,7 +2061,7 @@ def up_apply_brports_attributes(self, ifaceobj, ifaceobj_getfunc, bridge_vlan_aw
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

Expand Down Expand Up @@ -2113,7 +2113,7 @@ def up_apply_brports_attributes(self, ifaceobj, ifaceobj_getfunc, bridge_vlan_aw
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
Expand Down Expand Up @@ -2265,7 +2265,7 @@ def up_apply_brports_attributes(self, ifaceobj, ifaceobj_getfunc, bridge_vlan_aw
# 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

#
Expand Down Expand Up @@ -2318,7 +2318,7 @@ def apply_bridge_port_vlan_vni_map(self, ifaceobj):

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])
Expand Down Expand Up @@ -2623,7 +2623,7 @@ def _down(self, ifaceobj, ifaceobj_getfunc=None):

try:
self.netlink.link_del(self.get_dummy_brport_name_for_bridge(ifname))
except:
except Exception:
pass

try:
Expand Down Expand Up @@ -2794,7 +2794,7 @@ def _query_running_attrs(self, ifaceobjrunning, ifaceobj_getfunc,
bridge_attributes_map = dict(self._ifla_br_attributes_map)
try:
del bridge_attributes_map[Link.IFLA_BR_STP_STATE]
except:
except Exception:
pass

#
Expand All @@ -2809,7 +2809,7 @@ def _query_running_attrs(self, ifaceobjrunning, ifaceobj_getfunc,

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)
Expand Down Expand Up @@ -3078,7 +3078,7 @@ def _query_check_bridge_always_up(self, ifname, ifaceobj, ifaceobjcurr, bridge_c
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(
Expand Down Expand Up @@ -3219,7 +3219,7 @@ def query_check_bridge_ports(self, ifaceobj, ifaceobjcurr, running_port_list, if
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 = []
Expand All @@ -3242,7 +3242,7 @@ def query_check_bridge_ports(self, ifaceobj, ifaceobjcurr, running_port_list, if
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)
Expand Down Expand Up @@ -3524,7 +3524,7 @@ def _query_check_bridge_port(self, ifaceobj, ifaceobjcurr,

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)

Expand All @@ -3541,15 +3541,15 @@ def _query_check_bridge_port(self, ifaceobj, ifaceobjcurr,
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

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
Expand Down Expand Up @@ -3616,7 +3616,7 @@ def _query_check_l2protocol_tunnel_on_bridge(self, ifname, ifaceobj, ifaceobjcur
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:
Expand Down
4 changes: 2 additions & 2 deletions ifupdown2/addons/bridgevlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _up(self, ifaceobj):
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
Expand Down Expand Up @@ -105,7 +105,7 @@ def _down(self, ifaceobj):
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
Expand Down
Loading

0 comments on commit 3218f49

Please sign in to comment.