mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Implement basic dependency system between diagnoser
This commit is contained in:
parent
f050b3c5b8
commit
91ec775ebb
7 changed files with 24 additions and 13 deletions
|
@ -14,6 +14,7 @@ class IPDiagnoser(Diagnoser):
|
|||
|
||||
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
||||
cache_duration = 60
|
||||
dependencies = []
|
||||
|
||||
def run(self):
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ class DNSRecordsDiagnoser(Diagnoser):
|
|||
|
||||
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
||||
cache_duration = 3600 * 24
|
||||
dependencies = ["ip"]
|
||||
|
||||
def run(self):
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ class PortsDiagnoser(Diagnoser):
|
|||
|
||||
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
||||
cache_duration = 3600
|
||||
dependencies = ["ip"]
|
||||
|
||||
def run(self):
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ class HttpDiagnoser(Diagnoser):
|
|||
|
||||
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
||||
cache_duration = 3600
|
||||
dependencies = ["ip"]
|
||||
|
||||
def run(self):
|
||||
|
||||
|
@ -28,7 +29,6 @@ class HttpDiagnoser(Diagnoser):
|
|||
|
||||
try:
|
||||
r = requests.post('https://ynhdiagnoser.netlib.re/check-http', json={'domain': domain, "nonce": nonce}, timeout=30).json()
|
||||
print(r)
|
||||
if "status" not in r.keys():
|
||||
raise Exception("Bad syntax for response ? Raw json: %s" % str(r))
|
||||
elif r["status"] == "error" and ("code" not in r.keys() or r["code"] not in ["error_http_check_connection_error", "error_http_check_unknown_error"]):
|
||||
|
@ -37,7 +37,6 @@ class HttpDiagnoser(Diagnoser):
|
|||
else:
|
||||
raise Exception("Bad syntax for response ? Raw json: %s" % str(r))
|
||||
except Exception as e:
|
||||
print(e)
|
||||
raise YunohostError("diagnosis_http_could_not_diagnose", error=e)
|
||||
|
||||
if r["status"] == "ok":
|
||||
|
|
|
@ -20,6 +20,7 @@ class ServicesDiagnoser(Diagnoser):
|
|||
|
||||
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
||||
cache_duration = 300
|
||||
dependencies = []
|
||||
|
||||
def run(self):
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ class DiskUsageDiagnoser(Diagnoser):
|
|||
|
||||
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
||||
cache_duration = 3600 * 24
|
||||
dependencies = []
|
||||
|
||||
def run(self):
|
||||
|
||||
|
|
|
@ -137,12 +137,7 @@ class Diagnoser():
|
|||
self.env = env
|
||||
self.args = args or {}
|
||||
self.cache_file = Diagnoser.cache_file(self.id_)
|
||||
|
||||
descr_key = "diagnosis_description_" + self.id_
|
||||
self.description = m18n.n(descr_key)
|
||||
# If no description available, fallback to id
|
||||
if self.description == descr_key:
|
||||
self.description = self.id_
|
||||
self.description = Diagnoser.get_description(self.id_)
|
||||
|
||||
def cached_time_ago(self):
|
||||
|
||||
|
@ -159,9 +154,18 @@ class Diagnoser():
|
|||
|
||||
if not self.args.get("force", False) and self.cached_time_ago() < self.cache_duration:
|
||||
self.logger_debug("Cache still valid : %s" % self.cache_file)
|
||||
# FIXME : i18n
|
||||
logger.info("(Cache still valid for %s diagnosis. Not re-diagnosing yet!)" % self.description)
|
||||
return 0, {}
|
||||
|
||||
for dependency in self.dependencies:
|
||||
dep_report = Diagnoser.get_cached_report(dependency)
|
||||
dep_errors = [item for item in dep_report["items"] if item["status"] == "ERROR"]
|
||||
if dep_errors:
|
||||
# FIXME : i18n
|
||||
logger.error("Can't run diagnosis for %s while there are important issues related to %s." % (self.description, Diagnoser.get_description(dependency)))
|
||||
return 1, {}
|
||||
|
||||
self.logger_debug("Running diagnostic for %s" % self.id_)
|
||||
|
||||
items = list(self.run())
|
||||
|
@ -200,6 +204,13 @@ class Diagnoser():
|
|||
Diagnoser.i18n(report)
|
||||
return report
|
||||
|
||||
@staticmethod
|
||||
def get_description(id_):
|
||||
key = "diagnosis_description_" + id_
|
||||
descr = m18n.n(key)
|
||||
# If no description available, fallback to id
|
||||
return descr if descr != key else id_
|
||||
|
||||
@staticmethod
|
||||
def i18n(report):
|
||||
|
||||
|
@ -209,11 +220,7 @@ class Diagnoser():
|
|||
# was generated ... e.g. if the diagnosing happened inside a cron job with locale EN
|
||||
# instead of FR used by the actual admin...
|
||||
|
||||
descr_key = "diagnosis_description_" + report["id"]
|
||||
report["description"] = m18n.n(descr_key)
|
||||
# If no description available, fallback to id
|
||||
if report["description"] == descr_key:
|
||||
report["description"] = report["id"]
|
||||
report["description"] = Diagnoser.get_description(report["id"])
|
||||
|
||||
for item in report["items"]:
|
||||
summary_key, summary_args = item["summary"]
|
||||
|
|
Loading…
Add table
Reference in a new issue