Fix semantic, way too many things called 'report' ...

This commit is contained in:
Alexandre Aubin 2019-07-13 22:07:07 +02:00
parent 1d8ba7fa95
commit 41c3b054ba
3 changed files with 39 additions and 39 deletions

View file

@ -26,16 +26,18 @@ class IPDiagnoser(Diagnoser):
if 4 in versions: if 4 in versions:
ipv4 = self.get_public_ip(4) ipv4 = self.get_public_ip(4)
yield dict(meta = {"version": 4}, yield dict(meta = {"version": 4},
result = ipv4, data = ipv4,
report = ("SUCCESS", "diagnosis_network_connected_ipv4", {}) if ipv4 \ status = "SUCCESS" if ipv4 else "ERROR",
else ("ERROR", "diagnosis_network_no_ipv4", {})) summary = ("diagnosis_network_connected_ipv4", {}) if ipv4 \
else ("diagnosis_network_no_ipv4", {}))
if 6 in versions: if 6 in versions:
ipv6 = self.get_public_ip(6) ipv6 = self.get_public_ip(6)
yield dict(meta = {"version": 6}, yield dict(meta = {"version": 6},
result = ipv6, data = ipv6,
report = ("SUCCESS", "diagnosis_network_connected_ipv6", {}) if ipv6 \ status = "SUCCESS" if ipv6 else "WARNING",
else ("WARNING", "diagnosis_network_no_ipv6", {})) summary = ("diagnosis_network_connected_ipv6", {}) if ipv6 \
else ("diagnosis_network_no_ipv6", {}))
def get_public_ip(self, protocol=4): def get_public_ip(self, protocol=4):

View file

@ -58,19 +58,15 @@ class DNSRecordsDiagnoser(Diagnoser):
discrepancies.append(("diagnosis_dns_discrepancy", (r["type"], r["name"], expected_value, current_value))) discrepancies.append(("diagnosis_dns_discrepancy", (r["type"], r["name"], expected_value, current_value)))
if discrepancies: if discrepancies:
if category == "basic" or is_main_domain: status = "ERROR" if (category == "basic" or is_main_domain) else "WARNING"
level = "ERROR" summary = ("diagnosis_dns_bad_conf", {"domain": domain, "category": category})
else: else:
level = "WARNING" status = "SUCCESS"
report = (level, "diagnosis_dns_bad_conf", {"domain": domain, "category": category}) summary = ("diagnosis_dns_good_conf", {"domain": domain, "category": category})
else:
level = "SUCCESS"
report = ("SUCCESS", "diagnosis_dns_good_conf", {"domain": domain, "category": category})
details = None
output = dict(meta = {"domain": domain, "category": category}, output = dict(meta = {"domain": domain, "category": category},
result = level, status = status,
report = report ) summary = summary)
if discrepancies: if discrepancies:
output["details"] = discrepancies output["details"] = discrepancies

View file

@ -60,22 +60,24 @@ def diagnosis_show(categories=[], issues=False, full=False):
all_reports = [] all_reports = []
for category in categories: for category in categories:
try: try:
cat_report = Diagnoser.get_cached_report(category) report = Diagnoser.get_cached_report(category)
except Exception as e: except Exception as e:
logger.error("Failed to fetch diagnosis result for category '%s' : %s" % (category, str(e))) # FIXME : i18n logger.error("Failed to fetch diagnosis result for category '%s' : %s" % (category, str(e))) # FIXME : i18n
else: else:
if not full: if not full:
del cat_report["timestamp"] del report["timestamp"]
del cat_report["cached_for"] del report["cached_for"]
for report in cat_report["reports"]: for item in report["items"]:
del report["meta"] del item["meta"]
del report["result"] if "data" in item:
del item["data"]
if issues: if issues:
cat_report["reports"] = [ r for r in cat_report["reports"] if r["report"][0] != "SUCCESS" ] report["items"] = [ item for item in report["items"] if item["status"] != "SUCCESS" ]
if not cat_report["reports"]: # Ignore this category if no issue was found
if not report["items"]:
continue continue
all_reports.append(cat_report) all_reports.append(report)
return {"reports": all_reports} return {"reports": all_reports}
@ -101,7 +103,7 @@ def diagnosis_run(categories=[], force=False, args=None):
args = {} args = {}
args["force"] = force args["force"] = force
found_issues = False issues = []
# Call the hook ... # Call the hook ...
diagnosed_categories = [] diagnosed_categories = []
for category in categories: for category in categories:
@ -115,11 +117,9 @@ def diagnosis_run(categories=[], force=False, args=None):
else: else:
diagnosed_categories.append(category) diagnosed_categories.append(category)
if report != {}: if report != {}:
issues = [r for r in report["reports"] if r["report"][0] in ["ERROR", "WARNING"]] issues.extend([item for item in report["items"] if item["status"] != "SUCCESS"])
if issues:
found_issues = True
if found_issues: if issues:
if msettings.get("interface") == "api": if msettings.get("interface") == "api":
logger.info("You can go to the Diagnosis section (in the home screen) to see the issues found.") logger.info("You can go to the Diagnosis section (in the home screen) to see the issues found.")
else: else:
@ -147,7 +147,7 @@ class Diagnoser():
self.description = m18n.n(descr_key) self.description = m18n.n(descr_key)
# If no description available, fallback to id # If no description available, fallback to id
if self.description == descr_key: if self.description == descr_key:
self.description = report["id"] self.description = self.id_
def cached_time_ago(self): def cached_time_ago(self):
@ -170,9 +170,11 @@ class Diagnoser():
self.logger_debug("Running diagnostic for %s" % self.id_) self.logger_debug("Running diagnostic for %s" % self.id_)
items = list(self.run())
new_report = { "id": self.id_, new_report = { "id": self.id_,
"cached_for": self.cache_duration, "cached_for": self.cache_duration,
"reports": list(self.run()) "items": items
} }
# TODO / FIXME : should handle the case where we only did a partial diagnosis # TODO / FIXME : should handle the case where we only did a partial diagnosis
@ -180,8 +182,8 @@ class Diagnoser():
self.write_cache(new_report) self.write_cache(new_report)
Diagnoser.i18n(new_report) Diagnoser.i18n(new_report)
errors = [r for r in new_report["reports"] if r["report"][0] == "ERROR"] errors = [item for item in new_report["items"] if item["status"] == "ERROR"]
warnings = [r for r in new_report["reports"] if r["report"][0] == "WARNING"] warnings = [item for item in new_report["items"] if item["status"] == "WARNING"]
# FIXME : i18n # FIXME : i18n
if errors: if errors:
@ -220,12 +222,12 @@ class Diagnoser():
if report["description"] == descr_key: if report["description"] == descr_key:
report["description"] = report["id"] report["description"] = report["id"]
for r in report["reports"]: for item in report["items"]:
type_, message_key, message_args = r["report"] summary_key, summary_args = item["summary"]
r["report"] = (type_, m18n.n(message_key, **message_args)) item["summary"] = m18n.n(summary_key, **summary_args)
if "details" in r: if "details" in item:
r["details"] = [ m18n.n(key, *values) for key, values in r["details"] ] item["details"] = [ m18n.n(key, *values) for key, values in item["details"] ]
def _list_diagnosis_categories(): def _list_diagnosis_categories():