Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wayyoungboy committed Aug 15, 2024
1 parent 9b7f1eb commit 40d6cd2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
9 changes: 6 additions & 3 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,17 @@ def check(self, opts):
self.set_context('check', 'check', config)
obproxy_check_handler = None
observer_check_handler = None
result_data = {}
if self.context.obproxy_config.get("servers") is not None and len(self.context.obproxy_config.get("servers")) > 0:
obproxy_check_handler = CheckHandler(self.context, check_target_type="obproxy")
obproxy_check_handler.handle()
obproxy_check_handler.execute()
obproxy_result = obproxy_check_handler.execute()
result_data['obproxy'] = obproxy_result
if self.context.cluster_config.get("servers") is not None and len(self.context.cluster_config.get("servers")) > 0:
observer_check_handler = CheckHandler(self.context, check_target_type="observer")
observer_check_handler.handle()
observer_check_handler.execute()
observer_result = observer_check_handler.execute()
result_data['observer'] = observer_result
if obproxy_check_handler is not None:
obproxy_report_path = os.path.expanduser(obproxy_check_handler.report.get_report_path())
if os.path.exists(obproxy_report_path):
Expand All @@ -349,7 +352,7 @@ def check(self, opts):
observer_report_path = os.path.expanduser(observer_check_handler.report.get_report_path())
if os.path.exists(observer_report_path):
self.stdio.print("Check observer finished. For more details, please run cmd'" + Fore.YELLOW + " cat {0} ".format(observer_check_handler.report.get_report_path()) + Style.RESET_ALL + "'")
return ObdiagResult(ObdiagResult.SUCCESS_CODE, data={})
return ObdiagResult(ObdiagResult.SUCCESS_CODE, data=result_data)

def check_list(self, opts):
config = self.config_manager
Expand Down
3 changes: 3 additions & 0 deletions diag_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def do_command(self):
obdiag.set_options(self.opts)
obdiag.set_cmds(self.cmds)
ret = self._do_command(obdiag)
exit_code = 0
# if silent is true ,print ret
if ROOT_IO.silent:
if isinstance(ret, ObdiagResult) is False:
Expand All @@ -286,6 +287,8 @@ def do_command(self):
ROOT_IO.print('Trace ID: %s' % self.trace_id)
ROOT_IO.print('If you want to view detailed obdiag logs, please run: {0} display-trace {1}'.format(obdiag_bin, self.trace_id))
telemetry.put_data()
if ret.get_code() == ObdiagResult.SUCCESS_CODE:
return True
except NotImplementedError:
ROOT_IO.exception('command \'%s\' is not implemented' % self.prev_cmd)
except SystemExit:
Expand Down
2 changes: 1 addition & 1 deletion handler/checker/check_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def execute(self):
t_report = self.execute_one(task)
self.report.add_task_report(t_report)
self.report.export_report()
return self.report
return self.report.report_tobeMap()
except CheckrReportException as e:
self.stdio.error("Report error :{0}".format(e))
self.stdio.verbose(traceback.format_exc())
Expand Down
18 changes: 11 additions & 7 deletions handler/checker/check_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def handle(self):
self.stdio.verbose("list check cases")
entries = os.listdir(self.work_path)
files = [f for f in entries if os.path.isfile(os.path.join(self.work_path, f))]
result_map = {"data": {}}
result_map = {}
for file in files:
if "check_package" in file:
cases_map = {"all": {"name": "all", "command": "obdiag check", "info_en": "default check all task without filter", "info_cn": "默认执行除filter组里的所有巡检项"}}
Expand All @@ -50,6 +50,8 @@ def handle(self):
# read yaml file
with open(file, 'r') as f:
package_file_data = yaml.safe_load(f)
result_map[target] = {}
result_map[target]["commands"] = []
if not package_file_data or len(package_file_data) == 0:
self.stdio.warn("No data check package data :{0} ".format(file))
continue
Expand All @@ -68,12 +70,14 @@ def handle(self):
"info_en": package_file_data[package_data].get("info_en") or "",
"info_cn": package_file_data[package_data].get("info_cn") or "",
}
result_map["data"]["commands"] = {
"name": package_data,
"command": "obdiag check --{0}={1}".format(package_target, package_data),
"info_en": package_file_data[package_data].get("info_en") or "",
"info_cn": package_file_data[package_data].get("info_cn") or "",
}
result_map[target]["commands"].append(
{
"name": package_data,
"command": "obdiag check --{0}={1}".format(package_target, package_data),
"info_en": package_file_data[package_data].get("info_en") or "",
"info_cn": package_file_data[package_data].get("info_cn") or "",
}
)
Util.print_title("check cases about {0}".format(target), stdio=self.stdio)
Util.print_scene(cases_map, stdio=self.stdio)
return ObdiagResult(ObdiagResult.SUCCESS_CODE, data=result_map)
Expand Down
14 changes: 7 additions & 7 deletions result_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ def __init__(self, code, data=None, error_data=None):
self.error_data = error_data
if code is None:
raise TypeError("ObdiagResult code is None. Please contact the Oceanbase community. ")
if isinstance(code, int):
self.code = str(code)
else:
raise TypeError("ObdiagResult code is not int. Please contact the Oceanbase community. ")
self.code = code
if data is not None:
if isinstance(data, dict):
self.result = data
self.data = data
else:
raise TypeError("ObdiagResult data is not dict. Please contact the Oceanbase community. ")
if error_data is not None:
Expand All @@ -41,5 +38,8 @@ def set_command(self, command):
self.command = command

def get_result(self):
result = {"code": self.code, "data": self.result, "error_data": self.error_data, "trace_id": self.trace_id, "command": self.command}
return json.dumps(result)
result = {"code": self.code, "data": self.data, "error_data": self.error_data, "trace_id": self.trace_id, "command": self.command}
return json.dumps(result, ensure_ascii=False)

def get_code(self):
return self.code

0 comments on commit 40d6cd2

Please sign in to comment.