From 3200fef39c3fb5966031d62153b02baa82f38dfb Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 21 May 2019 20:08:09 +0200 Subject: [PATCH] Implement detail mechanism for DNS category --- data/hooks/diagnosis/12-dns.py | 17 ++++++++++++----- src/yunohost/diagnosis.py | 3 +++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/data/hooks/diagnosis/12-dns.py b/data/hooks/diagnosis/12-dns.py index 9bf6a13a3..e6370ba05 100644 --- a/data/hooks/diagnosis/12-dns.py +++ b/data/hooks/diagnosis/12-dns.py @@ -54,8 +54,10 @@ class DNSDiagnoser(Diagnoser): current_value = self.get_current_record(domain, r["name"], r["type"]) or "None" expected_value = r["value"] if r["value"] != "@" else domain+"." - if current_value != expected_value: - discrepancies.append((r, expected_value, current_value)) + if current_value == "None": + discrepancies.append(("diagnosis_dns_missing_record", (r["type"], r["name"], expected_value))) + elif current_value != expected_value: + discrepancies.append(("diagnosis_dns_discrepancy", (r["type"], r["name"], expected_value, current_value))) if discrepancies: if category == "basic" or is_main_domain: @@ -66,11 +68,16 @@ class DNSDiagnoser(Diagnoser): else: level = "SUCCESS" report = ("SUCCESS", "diagnosis_dns_good_conf", {"domain": domain, "category": category}) + details = None - # FIXME : add management of details of what's wrong if there are discrepancies - yield dict(meta = {"domain": domain, "category": category}, - result = level, report = report ) + output = dict(meta = {"domain": domain, "category": category}, + result = level, + report = report ) + if discrepancies: + output["details"] = discrepancies + + yield output def get_current_record(self, domain, name, type_): diff --git a/src/yunohost/diagnosis.py b/src/yunohost/diagnosis.py index 22770ce87..a8fae4124 100644 --- a/src/yunohost/diagnosis.py +++ b/src/yunohost/diagnosis.py @@ -73,6 +73,9 @@ def diagnosis_show(categories=[], full=False): type_, message_key, message_args = r["report"] r["report"] = (type_, m18n.n(message_key, **message_args)) + if "details" in r: + r["details"] = [ m18n.n(key, *values) for key, values in r["details"] ] + return {"reports": all_reports} def diagnosis_run(categories=[], force=False, args=None):