Goddamit Aleks, check your damn code before release yo

This commit is contained in:
Alexandre Aubin 2020-04-30 18:03:44 +02:00
parent c33e61ab2e
commit 86810fb68a

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python
import re
import os
import random
@ -10,6 +11,7 @@ from moulinette.utils.filesystem import read_file
from yunohost.diagnosis import Diagnoser
from yunohost.utils.network import get_network_interfaces
class IPDiagnoser(Diagnoser):
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
@ -72,6 +74,7 @@ class IPDiagnoser(Diagnoser):
ipv6 = self.get_public_ip(6) if can_ping_ipv6 else None
network_interfaces = get_network_interfaces()
def get_local_ip(version):
local_ip = {iface: addr[version].split("/")[0]
for iface, addr in network_interfaces.items() if version in addr}
@ -106,6 +109,7 @@ class IPDiagnoser(Diagnoser):
# If we are indeed connected in ipv4 or ipv6, we should find a default route
routes = check_output("ip -%s route" % protocol).split("\n")
def is_default_route(r):
# Typically the default route starts with "default"
# But of course IPv6 is more complex ... e.g. on internet cube there's
@ -113,7 +117,7 @@ class IPDiagnoser(Diagnoser):
# e.g. 2000:/3 dev tun0 ...
return r.startswith("default") or (":" in r and re.match(r".*/[0-3]$", r.split()[0]))
if not any(is_default_route(r) for r in routes):
logger.debug("No default route for IPv%s, so assuming there's no IP address for that version" % protocol)
self.logger_debug("No default route for IPv%s, so assuming there's no IP address for that version" % protocol)
return None
# We use the resolver file as a list of well-known, trustable (ie not google ;)) IPs that we can ping