Skip to content

Commit 475d8cb

Browse files
authored
fix obdiag workflow (#220)
* fix obdiag workflow * add obproxy port * optimize output content * fix out context * fix diag plugin * add auto install diag tool * replace get_server_conf with get_server_conf_with_default
1 parent 2e94a33 commit 475d8cb

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

_cmd.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ def _process_long_opt(self, rargs, values):
125125
value = rargs[0]
126126
OptionParser._process_long_opt(self, rargs, values)
127127
except BadOptionError as e:
128+
if self.prog.split()[-1] == "obdiag":
129+
return
128130
if self.allow_undefine:
129131
key = e.opt_str
130132
value = value[len(key)+1:]
@@ -138,6 +140,8 @@ def _process_short_opts(self, rargs, values):
138140
value = rargs[0]
139141
OptionParser._process_short_opts(self, rargs, values)
140142
except BadOptionError as e:
143+
if self.prog.split()[-1] == "obdiag":
144+
return
141145
if self.allow_undefine:
142146
key = e.opt_str
143147
value = value[len(key)+1:]

core.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4775,7 +4775,7 @@ def obdiag_func(self, args, deploy_name):
47754775
self._call_stdio('error', err.EC_OBDIAG_NOT_CONTAIN_DEPEND_COMPONENT.format(components=allow_components))
47764776
return False
47774777
cluster_config = deploy_config.components[component_name]
4778-
deploy_config.components = {tool_name: cluster_config}
4778+
deploy_config.components[tool_name] = cluster_config
47794779

47804780
workflow_name='diag'
47814781
pkg = self.mirror_manager.get_best_pkg(name=tool_name)
@@ -4790,7 +4790,9 @@ def obdiag_func(self, args, deploy_name):
47904790
workflows = self.get_workflows(workflow_name, [repository])
47914791
return self.run_workflow(workflows, deploy_config.components, [repository], **{const.COMP_OCEANBASE_DIAGNOSTIC_TOOL: {"full_cmd": args, "deploy_config": deploy_config}})
47924792
else:
4793-
self._call_stdio('error', err.EC_OBDIAG_FUNCTION_FAILED.format(function=workflow_name))
4793+
self._call_stdio('error', err.EC_OBDIAG_NOT_FOUND.format())
4794+
self._call_stdio('warn', '%s tool installation begins' % tool_name)
4795+
self.install_tool(tool_name)
47944796
return False
47954797

47964798
def obdiag_deploy(self, fuction_type):

plugins/oceanbase-diagnostic-tool/1.0/diag.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from __future__ import absolute_import, division, print_function
1717
from ssh import LocalClient
1818
import _errno as err
19+
import re
1920

2021

2122
def diag(plugin_context, *args, **kwargs):
@@ -27,8 +28,32 @@ def local_execute_command(command, env=None, timeout=None):
2728
exec_command = r"{install_dir}/{cmd}".format(install_dir=obdiag_install_dir, cmd=command)
2829
return LocalClient.execute_command(exec_command, env, timeout, stdio)
2930

31+
stdio.start_loading('obdiag working')
3032
ret = local_execute_command(f'{obdiag_bin} {" ".join(kwargs["full_cmd"])}')
33+
stdio.stop_loading('obdiag working')
3134
if not ret:
3235
stdio.error(err.EC_OBDIAG_NOT_FOUND.format())
3336
return plugin_context.return_false()
34-
stdio.print(ret.stdout)
37+
38+
fixed_output = ret.stdout
39+
if kwargs["full_cmd"][-1] == "list":
40+
command_to_replace = kwargs["full_cmd"][0]
41+
pattern = rf'(\s*)obdiag\s+{re.escape(command_to_replace)}(\s|$)'
42+
replacement = rf'\1obd obdiag {command_to_replace}\2'
43+
fixed_output = re.sub(
44+
pattern,
45+
replacement,
46+
ret.stdout,
47+
flags=re.MULTILINE | re.IGNORECASE
48+
)
49+
fixed_output = re.sub(
50+
r'Usage: /.*?/obdiag',
51+
'Usage: obd obdiag',
52+
fixed_output
53+
)
54+
fixed_output = re.sub(
55+
r'(<command>)(\s+\[options\])',
56+
r'\1 <deploy name>\2',
57+
fixed_output
58+
)
59+
stdio.print(fixed_output)

plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def get_obdiag_config():
6565
nodeItem["ssh_username"] = parse_empty(user_config.username)
6666
nodeItem["ssh_password"] = parse_empty(user_config.password)
6767
nodeItem["private_key"] = parse_empty(user_config.key_file)
68-
server_config = obproxy.get_server_conf(server)
68+
server_config = obproxy.get_server_conf_with_default(server)
69+
obproxy_config["obproxy_port"] = server_config.get("listen_port", 2883)
6970
nodeItem["home_path"] = server_config.get("home_path")
7071
obproxy_nodes.append(nodeItem)
7172
obproxy_config["servers"] = {"nodes": obproxy_nodes, "global": {}}
@@ -98,6 +99,8 @@ def get_obdiag_config():
9899
obcluster_config["servers"] = {"nodes": observer_nodes, "global": {}}
99100
if len(obproxy_nodes) > 0:
100101
config={"obcluster": obcluster_config, "obproxy": obproxy_config}
102+
obcluster_config["db_port"] = obproxy_config["obproxy_port"]
103+
obcluster_config["db_host"] = obproxy_config["servers"]["nodes"][0]["ip"]
101104
else:
102105
config={"obcluster": obcluster_config}
103106
return config

0 commit comments

Comments
 (0)