From b56da57f77b284ba7c38ecc6c443dfbbbdfe0a7c Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Tue, 27 Feb 2018 10:40:52 -0500 Subject: [PATCH] Changes for review comments --- .../lib/python/agent/hwctl/eventlog.py | 23 +++++++++++++--- .../agent/hwctl/executor/openbmc_eventlog.py | 12 +++++++-- .../lib/python/agent/hwctl/openbmc_client.py | 11 +++++--- .../lib/python/agent/xcatagent/openbmc.py | 26 +++++++++++++------ xCAT-server/lib/xcat/plugins/openbmc2.pm | 21 ++++++++++++++- 5 files changed, 76 insertions(+), 17 deletions(-) diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/eventlog.py b/xCAT-openbmc-py/lib/python/agent/hwctl/eventlog.py index e5e644f17..0c8f6378d 100644 --- a/xCAT-openbmc-py/lib/python/agent/hwctl/eventlog.py +++ b/xCAT-openbmc-py/lib/python/agent/hwctl/eventlog.py @@ -10,14 +10,31 @@ class EventlogInterface(object): interface_type = 'eventlog' version = '1.0' - def get_eventlog_info(self, task, eventlog_type=None): + def get_eventlog_info(self, task, number_of_records="all"): """Return the eventlog info of the task's nodes. - :param eventlog_type: type of eventlog info want to get. + :param number_of_records: number of records to display. :param task: a Task instance containing the nodes to act on. :return eventlog list """ - return task.run('get_ev_info', eventlog_type) + return task.run('get_ev_info', number_of_records) + + def clear_all_eventlog_records(self, task): + """Clear all eventlog records. + + :param task: a Task instance containing the nodes to act on. + :return + """ + return task.run('clear_all_ev_records') + + def resolve_eventlog_records(self, task, resolve_list="LED"): + """Return the eventlog info of the task's nodes. + + :param resolve: list of eventlog ids to resolve or LED label. + :param task: a Task instance containing the nodes to act on. + :return eventlog list of resolved entries + """ + return task.run('resolve_ev_records', resolve_list) class DefaultEventlogManager(EventlogInterface): """Interface for eventlog-related actions.""" diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_eventlog.py b/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_eventlog.py index f0d417a31..243b469f7 100644 --- a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_eventlog.py +++ b/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_eventlog.py @@ -20,13 +20,13 @@ logger = logging.getLogger('xcatagent') class OpenBMCEventlogTask(ParallelNodesCommand): """Executor for eventlog-related actions.""" - def get_ev_info(self, args, **kw): + def get_ev_info(self, num_to_display, **kw): node = kw['node'] number_to_display = 0 try: # Number of records to display from the end - number_to_display = 0-int(args[0]) + number_to_display = 0-int(num_to_display[0]) except Exception: # All records to display number_to_display = 0 @@ -52,3 +52,11 @@ class OpenBMCEventlogTask(ParallelNodesCommand): self.callback.info('%s: %s' % (node, e.message)) return eventlog_info + + def clear_all_ev_records(self, **kw): + + node = kw['node'] + + def resolve_ev_records(self, resolve_list, **kw): + + node = kw['node'] diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py index ca456abab..7911e5a77 100644 --- a/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py +++ b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py @@ -492,11 +492,16 @@ class OpenBMCRest(object): return bool(func_list), fw_dict - # Extract all eventlog info and build a dictionary with eventid as a key + # Extract all eventlog info and parse it def get_eventlog_info(self): eventlog_data = self.request('GET', EVENTLOG_URL, cmd='get_eventlog_info') + return self.parse_eventlog_data(eventlog_data) + + # Parse eventlog data and build a dictionary with eventid as a key + def parse_eventlog_data(self, eventlog_data): + # Check if policy table file is there ras_event_mapping = {} if os.path.isfile(RAS_POLICY_TABLE): @@ -512,7 +517,7 @@ class OpenBMCRest(object): try: eventlog_dict = {} for key, value in sorted(eventlog_data.items()): - id, event_log_line = self.parse_event_data(value, ras_event_mapping) + id, event_log_line = self.parse_eventlog_data_record(value, ras_event_mapping) if int(id) != 0: eventlog_dict[str(id)] = event_log_line return eventlog_dict @@ -521,7 +526,7 @@ class OpenBMCRest(object): raise SelfServerException(error) # Parse a single eventlog entry and return data in formatted string - def parse_event_data(self, event_log_entry, ras_event_mapping): + def parse_eventlog_data_record(self, event_log_entry, ras_event_mapping): formatted_line = "" callout_data = "" LED_tag = " [LED]" diff --git a/xCAT-openbmc-py/lib/python/agent/xcatagent/openbmc.py b/xCAT-openbmc-py/lib/python/agent/xcatagent/openbmc.py index 16d20823a..65c52a701 100644 --- a/xCAT-openbmc-py/lib/python/agent/xcatagent/openbmc.py +++ b/xCAT-openbmc-py/lib/python/agent/xcatagent/openbmc.py @@ -145,7 +145,7 @@ VITALS_OPTIONS = ('all', 'altitude', 'fanspeed', 'leds', 'power', 'temp', 'voltage', 'wattage') # global variables of reventlog -EVENTLOG_OPTIONS = ('all', 'clear', 'resolved') +EVENTLOG_OPTIONS = ('list', 'clear', 'resolved') class OpenBMC(base.BaseDriver): @@ -841,9 +841,9 @@ class OpenBMCManager(base.BaseManager): reventlog_usage = """ Usage: - reventlog [-V|--verbose] [resolved=LED|resolved=] - reventlog [-V|--verbose] [clear|all] - reventlog [-V|--verbose] [] + reventlog [-V|--verbose] resolved + reventlog [-V|--verbose] clear + reventlog [-V|--verbose] list Options: -V --verbose eventlog verbose mode. @@ -859,13 +859,23 @@ class OpenBMCManager(base.BaseManager): return # 2, validate the args - #if action not in EVENTLOG_OPTIONS: - # self.messager.error("Not supported subcommand for reventlog: %s" % action) - # return + if action not in EVENTLOG_OPTIONS: + self.messager.error("Not supported subcommand for reventlog: %s" % action) + return # 3, run the subcommands runner = OpenBMCEventlogTask(nodesinfo, callback=self.messager, debugmode=self.debugmode, verbose=self.verbose) - DefaultEventlogManager().get_eventlog_info(runner, args) + self.messager.info('revetlog.py processing action=%s args=%s' % (action, args)) + if action == 'clear': + DefaultEventlogManager().clear_all_eventlog_records(runner) + elif action == 'resolved': + eventlog_id_list = opts.pop('') + DefaultEventlogManager().resolve_eventlog_records(runner, eventlog_id_list) + elif action == 'list': + eventlog_number_of_records = opts.pop('') + DefaultEventlogManager().get_eventlog_info(runner, eventlog_number_of_records) + else: + DefaultEventlogManager().get_eventlog_info(runner, "all") def _get_full_path(self,file_path): if type(self.cwd) == 'unicode': diff --git a/xCAT-server/lib/xcat/plugins/openbmc2.pm b/xCAT-server/lib/xcat/plugins/openbmc2.pm index 84cc74df2..8375793d1 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc2.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc2.pm @@ -364,8 +364,9 @@ sub refactor_args { my $request = shift; my $command = $request->{command}->[0]; my $extrargs = $request->{arg}; + my $subcommand; if ($command eq "rspconfig") { - my $subcommand = $extrargs->[0]; + $subcommand = $extrargs->[0]; if ($subcommand !~ /^dump$|^sshcfg$|^ip=dhcp$/) { if (grep /=/, @$extrargs) { unshift @$extrargs, "set"; @@ -374,6 +375,24 @@ sub refactor_args { } } } + if ($command eq "reventlog") { + if (!defined($extrargs->[0])) { + # If no parameters are passed, default to list all records + $request->{arg} = ["list","all"]; + } + else { + $subcommand = $extrargs->[0]; + } + if ($subcommand =~ /^\d+$/) { + unshift @$extrargs, "list"; + } + elsif ($subcommand =~/^resolved=(.*)/) { + unshift @$extrargs, "resolved"; + } + elsif ($subcommand =~/^all$/) { + unshift @$extrargs, "list"; + } + } return 0; }