Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions _cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand All @@ -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:]
Expand Down
6 changes: 4 additions & 2 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down
27 changes: 26 additions & 1 deletion plugins/oceanbase-diagnostic-tool/1.0/diag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'(<command>)(\s+\[options\])',
r'\1 <deploy name>\2',
fixed_output
)
stdio.print(fixed_output)
5 changes: 4 additions & 1 deletion plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}}
Expand Down Expand Up @@ -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
Expand Down