Skip to content

Commit

Permalink
Fix ldmsd_controller completion without ldmsd connection
Browse files Browse the repository at this point in the history
When there is no `ldmsd` connection, `ldmsd_controller` command
parameter completion does not work. This patch fixes the issue.
  • Loading branch information
narategithub authored and tom95858 committed Aug 26, 2024
1 parent c221572 commit 408f168
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
29 changes: 20 additions & 9 deletions ldms/python/ldmsd/ldmsd_communicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@
'auth_add': {'req_attr': ['name', 'plugin'], 'opt_attr': []},
}

def get_cmd_attr_list(cmd_verb):
"""Return the dictionary of command attributes
If there are no required/optional attributes, the value of the
'req'/'opt' key is None. Otherwise, the value is a list of attribute
names.
@return: {'req': [], 'opt': []}
"""
attr_dict = {'req': [], 'opt': []}
if 'req_attr' in LDMSD_CTRL_CMD_MAP[cmd_verb]:
if len(LDMSD_CTRL_CMD_MAP[cmd_verb]['req_attr']) > 0:
attr_dict['req'] = LDMSD_CTRL_CMD_MAP[cmd_verb]['req_attr']
if 'opt_attr' in LDMSD_CTRL_CMD_MAP[cmd_verb]:
if len(LDMSD_CTRL_CMD_MAP[cmd_verb]['opt_attr']) > 0:
attr_dict['opt'] = LDMSD_CTRL_CMD_MAP[cmd_verb]['opt_attr']
return attr_dict

def fmt_status(msg):
"""
Format communicator status response string into json object
Expand Down Expand Up @@ -901,19 +919,12 @@ def get_cmd_attr_list(self, cmd_verb):
"""Return the dictionary of command attributes
If there are no required/optional attributes, the value of the
'req'/'opt' key is None. Otherweise, the value is a list of attribute
'req'/'opt' key is None. Otherwise, the value is a list of attribute
names.
@return: {'req': [], 'opt': []}
"""
attr_dict = {'req': [], 'opt': []}
if 'req_attr' in LDMSD_CTRL_CMD_MAP[cmd_verb]:
if len(LDMSD_CTRL_CMD_MAP[cmd_verb]['req_attr']) > 0:
attr_dict['req'] = LDMSD_CTRL_CMD_MAP[cmd_verb]['req_attr']
if 'opt_attr' in LDMSD_CTRL_CMD_MAP[cmd_verb]:
if len(LDMSD_CTRL_CMD_MAP[cmd_verb]['opt_attr']) > 0:
attr_dict['opt'] = LDMSD_CTRL_CMD_MAP[cmd_verb]['opt_attr']
return attr_dict
return get_cmd_attr_list(cmd_verb)

def reconnect(self, timeout=0):
if self.ldms:
Expand Down
11 changes: 6 additions & 5 deletions ldms/python/ldmsd/ldmsd_controller
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ from datetime import datetime

from ldmsd import ldmsd_util
from ldmsd.ldmsd_communicator import LDMSD_Request, LDMSD_Req_Attr
from ldmsd.ldmsd_communicator import Communicator, fmt_status
from ldmsd.ldmsd_communicator import Communicator, fmt_status, get_cmd_attr_list
import errno

LDMSD_REQ_SOM_F=1
Expand Down Expand Up @@ -115,13 +115,14 @@ class LdmsdCmdParser(cmd.Cmd):
cmd.Cmd.__init__(self)

def __complete_attr_list(self, verb, text):
req_opt_attr = self.comm.get_cmd_attr_list(verb)
req_opt_attr = get_cmd_attr_list(verb)
attr_list = []
if req_opt_attr['req'] is not None:
attr_list = req_opt_attr['req']
if req_opt_attr['opt'] is not None:
attr_list += req_opt_attr['opt']
return ["{0}=".format(attr) for attr in attr_list if attr.startswith(text)]
ret = ["{0}=".format(attr) for attr in attr_list if attr.startswith(text)]
return ret

def emptyline(self):
pass
Expand All @@ -134,7 +135,7 @@ class LdmsdCmdParser(cmd.Cmd):
return True

def __check_command_args(self, verb, args):
req_opt_attr = self.comm.get_cmd_attr_list(verb)
req_opt_attr = get_cmd_attr_list(verb)
if set(req_opt_attr['req']) <= set(args):
return 0
else:
Expand Down Expand Up @@ -209,7 +210,7 @@ class LdmsdCmdParser(cmd.Cmd):
def handle_args(self, verb, _args):
if _args and not self.__check_command_syntax(_args):
print("Syntax error, there are attributes for which no value is given.")
req_opt_attr = self.comm.get_cmd_attr_list(verb)
req_opt_attr = get_cmd_attr_list(verb)

if not self.comm:
print("Error: no LDMS connection")
Expand Down

0 comments on commit 408f168

Please sign in to comment.