diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index 6b89a819b..3d72bb57a 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -1898,9 +1898,6 @@ diagnosis: --force: help: Ignore the cached report even if it is still 'fresh' action: store_true - -a: - help: Serialized arguments for diagnosis scripts (e.g. "domain=domain.tld") - full: --args ignore: action_help: Configure some diagnosis results to be ignored diff --git a/data/hooks/diagnosis/10-ip.py b/data/hooks/diagnosis/10-ip.py index 1f6c31f50..4a6ee75ce 100644 --- a/data/hooks/diagnosis/10-ip.py +++ b/data/hooks/diagnosis/10-ip.py @@ -15,70 +15,65 @@ class IPDiagnoser(Diagnoser): id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1] cache_duration = 60 - def validate_args(self, args): - if "version" not in args.keys(): - return {"versions": [4, 6]} - else: - assert str(args["version"]) in ["4", "6"], "Invalid version, should be 4 or 6." - return {"versions": [int(args["version"])]} - def run(self): - versions = self.args["versions"] + # + # IPv4 Diagnosis + # - if 4 in versions: + # If we can't ping, there's not much else we can do + if not self.can_ping_outside(4): + ipv4 = None + # If we do ping, check that we can resolv domain name + else: + can_resolve_dns = self.can_resolve_dns() + # And if we do, then we can fetch the public ip + if can_resolve_dns: + ipv4 = self.get_public_ip(4) - # If we can't ping, there's not much else we can do - if not self.can_ping_outside(4): - ipv4 = None - # If we do ping, check that we can resolv domain name - else: - can_resolve_dns = self.can_resolve_dns() - # And if we do, then we can fetch the public ip - if can_resolve_dns: - ipv4 = self.get_public_ip(4) + # In every case, we can check that resolvconf seems to be okay + # (symlink managed by resolvconf service + pointing to dnsmasq) + good_resolvconf = self.resolvconf_is_symlink() and self.resolvconf_points_to_localhost() - # In every case, we can check that resolvconf seems to be okay - # (symlink managed by resolvconf service + pointing to dnsmasq) - good_resolvconf = self.resolvconf_is_symlink() and self.resolvconf_points_to_localhost() + # If we can't resolve domain names at all, that's a pretty big issue ... + # If it turns out that at the same time, resolvconf is bad, that's probably + # the cause of this, so we use a different message in that case + if not can_resolve_dns: + yield dict(meta={"name": "dnsresolution"}, + status="ERROR", + summary=("diagnosis_ip_broken_dnsresolution", {}) if good_resolvconf + else ("diagnosis_ip_broken_resolvconf", {})) + # Otherwise, if the resolv conf is bad but we were able to resolve domain name, + # still warn that we're using a weird resolv conf ... + elif not good_resolvconf: + yield dict(meta={"name": "dnsresolution"}, + status="WARNING", + summary=("diagnosis_ip_weird_resolvconf", {})) + else: + # Well, maybe we could report a "success", "dns resolution is working", idk if it's worth it + pass - # If we can't resolve domain names at all, that's a pretty big issue ... - # If it turns out that at the same time, resolvconf is bad, that's probably - # the cause of this, so we use a different message in that case - if not can_resolve_dns: - yield dict(meta={"name": "dnsresolution"}, - status="ERROR", - summary=("diagnosis_ip_broken_dnsresolution", {}) if good_resolvconf - else ("diagnosis_ip_broken_resolvconf", {})) - # Otherwise, if the resolv conf is bad but we were able to resolve domain name, - # still warn that we're using a weird resolv conf ... - elif not good_resolvconf: - yield dict(meta={"name": "dnsresolution"}, - status="WARNING", - summary=("diagnosis_ip_weird_resolvconf", {})) - else: - # Well, maybe we could report a "success", "dns resolution is working", idk if it's worth it - pass + # And finally, we actually report the ipv4 connectivity stuff + yield dict(meta={"version": 4}, + data=ipv4, + status="SUCCESS" if ipv4 else "ERROR", + summary=("diagnosis_ip_connected_ipv4", {}) if ipv4 + else ("diagnosis_ip_no_ipv4", {})) - # And finally, we actually report the ipv4 connectivity stuff - yield dict(meta={"version": 4}, - data=ipv4, - status="SUCCESS" if ipv4 else "ERROR", - summary=("diagnosis_ip_connected_ipv4", {}) if ipv4 - else ("diagnosis_ip_no_ipv4", {})) + # + # IPv6 Diagnosis + # - if 6 in versions: + if not self.can_ping_outside(4): + ipv6 = None + else: + ipv6 = self.get_public_ip(6) - if not self.can_ping_outside(4): - ipv6 = None - else: - ipv6 = self.get_public_ip(6) - - yield dict(meta={"version": 6}, - data=ipv6, - status="SUCCESS" if ipv6 else "WARNING", - summary=("diagnosis_ip_connected_ipv6", {}) if ipv6 - else ("diagnosis_ip_no_ipv6", {})) + yield dict(meta={"version": 6}, + data=ipv6, + status="SUCCESS" if ipv6 else "WARNING", + summary=("diagnosis_ip_connected_ipv6", {}) if ipv6 + else ("diagnosis_ip_no_ipv6", {})) def can_ping_outside(self, protocol=4): diff --git a/data/hooks/diagnosis/12-dnsrecords.py b/data/hooks/diagnosis/12-dnsrecords.py index 493010c59..0f47ff136 100644 --- a/data/hooks/diagnosis/12-dnsrecords.py +++ b/data/hooks/diagnosis/12-dnsrecords.py @@ -14,14 +14,6 @@ class DNSRecordsDiagnoser(Diagnoser): id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1] cache_duration = 3600 * 24 - def validate_args(self, args): - all_domains = domain_list()["domains"] - if "domain" not in args.keys(): - return {"domains": all_domains} - else: - assert args["domain"] in all_domains, "Unknown domain" - return {"domains": [args["domain"]]} - def run(self): resolvers = read_file("/etc/resolv.dnsmasq.conf").split("\n") @@ -32,7 +24,8 @@ class DNSRecordsDiagnoser(Diagnoser): self.resolver = ipv4_resolvers[0] main_domain = _get_maindomain() - for domain in self.args["domains"]: + all_domains = domain_list()["domains"] + for domain in all_domains: self.logger_debug("Diagnosing DNS conf for %s" % domain) for report in self.check_domain(domain, domain == main_domain): yield report diff --git a/data/hooks/diagnosis/30-services.py b/data/hooks/diagnosis/30-services.py index 4f08247f1..5029e0a5d 100644 --- a/data/hooks/diagnosis/30-services.py +++ b/data/hooks/diagnosis/30-services.py @@ -21,10 +21,6 @@ class ServicesDiagnoser(Diagnoser): id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1] cache_duration = 300 - def validate_args(self, args): - # TODO / FIXME Ugh do we really need this arg system - return {} - def run(self): all_result = service_status() diff --git a/data/hooks/diagnosis/50-diskusage.py b/data/hooks/diagnosis/50-diskusage.py index 84ce3845c..2c6fe387b 100644 --- a/data/hooks/diagnosis/50-diskusage.py +++ b/data/hooks/diagnosis/50-diskusage.py @@ -9,10 +9,6 @@ class DiskUsageDiagnoser(Diagnoser): id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1] cache_duration = 3600 * 24 - def validate_args(self, args): - # TODO / FIXME Ugh do we really need this arg system - return {} - def run(self): disk_partitions = psutil.disk_partitions() diff --git a/src/yunohost/diagnosis.py b/src/yunohost/diagnosis.py index 9b17a7457..e7aca585f 100644 --- a/src/yunohost/diagnosis.py +++ b/src/yunohost/diagnosis.py @@ -84,7 +84,7 @@ def diagnosis_show(categories=[], issues=False, full=False): return {"reports": all_reports} -def diagnosis_run(categories=[], force=False, args=None): +def diagnosis_run(categories=[], force=False): # Get all the categories all_categories = _list_diagnosis_categories() @@ -98,13 +98,6 @@ def diagnosis_run(categories=[], force=False, args=None): if unknown_categories: raise YunohostError('unknown_categories', categories=", ".join(unknown_categories)) - # Transform "arg1=val1&arg2=val2" to { "arg1": "val1", "arg2": "val2" } - if args is not None: - args = {arg.split("=")[0]: arg.split("=")[1] for arg in args.split("&")} - else: - args = {} - args["force"] = force - issues = [] # Call the hook ... diagnosed_categories = [] @@ -113,7 +106,7 @@ def diagnosis_run(categories=[], force=False, args=None): path = [p for n, p in all_categories if n == category][0] try: - code, report = hook_exec(path, args=args, env=None) + code, report = hook_exec(path, args={"force": force}, env=None) except Exception as e: logger.error("Diagnosis failed for category '%s' : %s" % (category, str(e)), exc_info=True) # FIXME : i18n else: @@ -143,7 +136,6 @@ class Diagnoser(): self.logger_debug, self.logger_warning, self.logger_info = loggers self.env = env self.args = args or {} - self.args.update(self.validate_args(self.args)) self.cache_file = Diagnoser.cache_file(self.id_) descr_key = "diagnosis_description_" + self.id_