diff --git a/vppcfg/config/acl.py b/vppcfg/config/acl.py index 976149d..cb7242e 100644 --- a/vppcfg/config/acl.py +++ b/vppcfg/config/acl.py @@ -76,7 +76,7 @@ def get_icmp_low_high(icmpstring): icmp = int(icmpstring) if icmp > 0: return icmp, icmp - except: + except ValueError: pass if icmpstring.startswith("-"): @@ -90,7 +90,7 @@ def get_icmp_low_high(icmpstring): try: icmps = icmpstring.split("-") return int(icmps[0]), int(icmps[1]) - except: + except ValueError: pass return None, None @@ -110,13 +110,13 @@ def get_port_low_high(portstring): port = int(portstring) if port > 0: return port, port - except: + except ValueError: pass try: port = socket.getservbyname(portstring) return port, port - except: + except OSError: pass if portstring.startswith("-"): @@ -130,7 +130,7 @@ def get_port_low_high(portstring): try: ports = portstring.split("-") return int(ports[0]), int(ports[1]) - except: + except ValueError: pass return None, None @@ -144,7 +144,7 @@ def is_ip(ip_string): try: _ = ipaddress.ip_network(ip_string, strict=False) return True - except: + except ValueError: pass return False @@ -190,13 +190,13 @@ def get_protocol(protostring): proto = int(protostring) if proto > 0: return proto - except: + except ValueError: pass try: proto = socket.getprotobyname(protostring) return proto - except: + except OSError: pass return None diff --git a/vppcfg/config/interface.py b/vppcfg/config/interface.py index 4b08c12..4edd0d0 100644 --- a/vppcfg/config/interface.py +++ b/vppcfg/config/interface.py @@ -790,10 +790,7 @@ def validate_interfaces(yaml): def is_mpls(yaml, ifname): """Returns True if the interface exists and has mpls enabled. Returns false otherwise.""" - ifname, iface = get_by_name(yaml, ifname) - try: - if iface["mpls"]: - return True - except: - pass + _, iface = get_by_name(yaml, ifname) + if iface and "mpls" in iface and iface["mpls"]: + return True return False diff --git a/vppcfg/config/loopback.py b/vppcfg/config/loopback.py index 71cab0d..343a592 100644 --- a/vppcfg/config/loopback.py +++ b/vppcfg/config/loopback.py @@ -152,10 +152,7 @@ def validate_loopbacks(yaml): def is_mpls(yaml, ifname): """Returns True if the loopback exists and has mpls enabled. Returns false otherwise.""" - ifname, iface = get_by_name(yaml, ifname) - try: - if iface["mpls"]: - return True - except: - pass + _, iface = get_by_name(yaml, ifname) + if iface and "mpls" in iface and iface["mpls"]: + return True return False