diff --git a/_cmd.py b/_cmd.py index 7e1f3590..df255f51 100644 --- a/_cmd.py +++ b/_cmd.py @@ -125,6 +125,8 @@ def _process_long_opt(self, rargs, values): value = rargs[0] OptionParser._process_long_opt(self, rargs, values) except BadOptionError as e: + if self.prog.split()[-1] == "obdiag": + return if self.allow_undefine: key = e.opt_str value = value[len(key)+1:] @@ -138,6 +140,8 @@ def _process_short_opts(self, rargs, values): value = rargs[0] OptionParser._process_short_opts(self, rargs, values) except BadOptionError as e: + if self.prog.split()[-1] == "obdiag": + return if self.allow_undefine: key = e.opt_str value = value[len(key)+1:] diff --git a/core.py b/core.py index e52d4750..32358283 100644 --- a/core.py +++ b/core.py @@ -4775,7 +4775,7 @@ def obdiag_func(self, args, deploy_name): self._call_stdio('error', err.EC_OBDIAG_NOT_CONTAIN_DEPEND_COMPONENT.format(components=allow_components)) return False cluster_config = deploy_config.components[component_name] - deploy_config.components = {tool_name: cluster_config} + deploy_config.components[tool_name] = cluster_config workflow_name='diag' pkg = self.mirror_manager.get_best_pkg(name=tool_name) @@ -4790,7 +4790,9 @@ def obdiag_func(self, args, deploy_name): workflows = self.get_workflows(workflow_name, [repository]) return self.run_workflow(workflows, deploy_config.components, [repository], **{const.COMP_OCEANBASE_DIAGNOSTIC_TOOL: {"full_cmd": args, "deploy_config": deploy_config}}) else: - self._call_stdio('error', err.EC_OBDIAG_FUNCTION_FAILED.format(function=workflow_name)) + self._call_stdio('error', err.EC_OBDIAG_NOT_FOUND.format()) + self._call_stdio('warn', '%s tool installation begins' % tool_name) + self.install_tool(tool_name) return False def obdiag_deploy(self, fuction_type): diff --git a/plugins/oceanbase-diagnostic-tool/1.0/diag.py b/plugins/oceanbase-diagnostic-tool/1.0/diag.py index 91264e6b..40f55e2e 100644 --- a/plugins/oceanbase-diagnostic-tool/1.0/diag.py +++ b/plugins/oceanbase-diagnostic-tool/1.0/diag.py @@ -16,6 +16,7 @@ from __future__ import absolute_import, division, print_function from ssh import LocalClient import _errno as err +import re def diag(plugin_context, *args, **kwargs): @@ -27,8 +28,32 @@ def local_execute_command(command, env=None, timeout=None): exec_command = r"{install_dir}/{cmd}".format(install_dir=obdiag_install_dir, cmd=command) return LocalClient.execute_command(exec_command, env, timeout, stdio) + stdio.start_loading('obdiag working') ret = local_execute_command(f'{obdiag_bin} {" ".join(kwargs["full_cmd"])}') + stdio.stop_loading('obdiag working') if not ret: stdio.error(err.EC_OBDIAG_NOT_FOUND.format()) return plugin_context.return_false() - stdio.print(ret.stdout) + + fixed_output = ret.stdout + if kwargs["full_cmd"][-1] == "list": + command_to_replace = kwargs["full_cmd"][0] + pattern = rf'(\s*)obdiag\s+{re.escape(command_to_replace)}(\s|$)' + replacement = rf'\1obd obdiag {command_to_replace}\2' + fixed_output = re.sub( + pattern, + replacement, + ret.stdout, + flags=re.MULTILINE | re.IGNORECASE + ) + fixed_output = re.sub( + r'Usage: /.*?/obdiag', + 'Usage: obd obdiag', + fixed_output + ) + fixed_output = re.sub( + r'()(\s+\[options\])', + r'\1 \2', + fixed_output + ) + stdio.print(fixed_output) diff --git a/plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py b/plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py index b59d2917..560b6cb4 100644 --- a/plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py +++ b/plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py @@ -65,7 +65,8 @@ def get_obdiag_config(): nodeItem["ssh_username"] = parse_empty(user_config.username) nodeItem["ssh_password"] = parse_empty(user_config.password) nodeItem["private_key"] = parse_empty(user_config.key_file) - server_config = obproxy.get_server_conf(server) + server_config = obproxy.get_server_conf_with_default(server) + obproxy_config["obproxy_port"] = server_config.get("listen_port", 2883) nodeItem["home_path"] = server_config.get("home_path") obproxy_nodes.append(nodeItem) obproxy_config["servers"] = {"nodes": obproxy_nodes, "global": {}} @@ -98,6 +99,8 @@ def get_obdiag_config(): obcluster_config["servers"] = {"nodes": observer_nodes, "global": {}} if len(obproxy_nodes) > 0: config={"obcluster": obcluster_config, "obproxy": obproxy_config} + obcluster_config["db_port"] = obproxy_config["obproxy_port"] + obcluster_config["db_host"] = obproxy_config["servers"]["nodes"][0]["ip"] else: config={"obcluster": obcluster_config} return config