xref: /openbmc/openbmc-test-automation/lib/openbmc_ffdc_list.py (revision c42f5bf583c2bb5a5862f9b2d36bf1b68b0d16a4)
1#!/usr/bin/env python3
2r"""
3#    @file     openbmc_ffdc_list.py
4#    @brief    List for FFDC ( First failure data capture )
5#              commands and files to be collected as a part
6#              of the test case failure.
7"""
8import os
9
10from robot.libraries.BuiltIn import BuiltIn
11
12# -------------------
13# FFDC default list
14# -------------------
15# -----------------------------------------------------------------
16# Dict Name {  Index string : { Key String :  Command string} }
17# -----------------------------------------------------------------
18# Add cmd's needed to be part of the ffdc report manifest file
19FFDC_BMC_CMD = {
20    "DRIVER INFO": {
21        # String Name         Command
22        "FW Level": "cat /etc/os-release",
23        "FW Timestamp": "cat /etc/timestamp",
24    },
25    "BMC DATA": {
26        "BMC OS": "uname -a",
27        "BMC Uptime": "uptime;cat /proc/uptime",
28        "BMC File System Disk Space Usage": "df -hT",
29        "BMC Date Time": "date;/sbin/hwclock --show;/usr/bin/timedatectl",
30    },
31    "APPLICATION DATA": {
32        "BMC state": "/usr/bin/obmcutil state",
33    },
34}
35# Add file name and corresponding command needed for BMC
36FFDC_BMC_FILE = {
37    "BMC FILES": {
38        # File Name         Command
39        "BMC_flash_side.txt": (
40            "cat /sys/class/watchdog/watchdog1/bootstatus"
41            " >/tmp/BMC_flash_side.txt 2>&1"
42        ),
43        "BMC_hwmon.txt": (
44            "grep -r . /sys/class/hwmon/* >/tmp/BMC_hwmon.txt 2>&1"
45        ),
46        "BMC_proc_list.txt": "top -n 1 -b >/tmp/BMC_proc_list.txt 2>&1",
47        "BMC_proc_fd_active_list.txt": (
48            "ls -Al /proc/*/fd/ >/tmp/BMC_proc_fd_active_list.txt 2>&1"
49        ),
50        "BMC_journalctl.txt": (
51            "journalctl -o short-precise >/tmp/BMC_journalctl.txt 2>&1"
52        ),
53        "BMC_journalctl_pretty.json": (
54            "journalctl -o json-pretty >/tmp/BMC_journalctl_pretty.json 2>&1"
55        ),
56        "BMC_dmesg.txt": "dmesg >/tmp/BMC_dmesg.txt 2>&1",
57        "BMC_procinfo.txt": "cat /proc/cpuinfo >/tmp/BMC_procinfo.txt 2>&1",
58        "BMC_meminfo.txt": "cat /proc/meminfo >/tmp/BMC_meminfo.txt 2>&1",
59        "BMC_systemd.txt": "systemctl status --all >/tmp/BMC_systemd.txt 2>&1",
60        "BMC_failed_service.txt": (
61            "systemctl list-units --failed >/tmp/BMC_failed_service.txt 2>&1"
62        ),
63        "BMC_list_service.txt": (
64            "systemctl list-jobs >/tmp/BMC_list_service.txt 2>&1"
65        ),
66        "BMC_obmc_console.txt": (
67            "cat /var/log/obmc-console.log >/tmp/BMC_obmc_console.txt 2>&1"
68        ),
69        "BMC_obmc_console1.txt": (
70            "cat /var/log/obmc-console1.log >/tmp/BMC_obmc_console1.txt 2>&1"
71        ),
72        "vpd-inventory.txt": "vpd-tool -i >/tmp/vpd-inventory.txt 2>&1",
73        "PEL_logs_list.json": "peltool -l >/tmp/PEL_logs_list.json 2>&1",
74        "PEL_logs_complete_list.json": (
75            "peltool -l -a -f >/tmp/PEL_logs_complete_list.json 2>&1"
76        ),
77        "PEL_logs_display.json": "peltool -a >/tmp/PEL_logs_display.json 2>&1",
78        "PEL_logs_complete_display.json": (
79            "peltool -a -f -h>/tmp/PEL_logs_complete_display.json 2>&1"
80        ),
81        "PEL_logs_badPEL.txt": (
82            "hexdump -C"
83            + " /var/lib/phosphor-logging/extensions/pels/badPEL>/tmp/PEL_logs_badPEL.txt"
84            " 2>&1"
85        ),
86        "PLDM_fru_record.txt": (
87            "pldmtool fru getfrurecordtable>/tmp/PLDM_fru_record.txt 2>&1"
88        ),
89        "BMC_pldm_flight_recorder.txt": (
90            "rm -rf /tmp/pldm_flight_recorder; killall -s SIGUSR1 pldmd;"
91            + " sleep 5; cat /tmp/pldm_flight_recorder >"
92            " /tmp/BMC_pldm_flight_recorder.txt 2>&1;"
93        ),
94        "OCC_state.txt": (
95            'echo "OCC state check";for i in {0..3};'
96            + " do (echo /org/open_power/control/occ$i;"
97            + " busctl get-property org.open_power.OCC.Control"
98            " /org/open_power/control/occ$i"
99            + " org.open_power.OCC.Status OccActive) done > /tmp/OCC_state.txt"
100            " 2>&1"
101        ),
102        "GUARD_list.txt": "guard -l > /tmp/GUARD_list.txt 2>&1",
103        "fan_control_dump.json": "fanctl dump; sleep 5",
104        "fan_monitor_dump.json": "killall -s SIGUSR1 phosphor-fan-monitor; sleep 5",
105        "DEVTREE": (
106            "cat /var/lib/phosphor-software-manager/pnor/rw/DEVTREE >"
107            " /tmp/DEVTREE 2>&1"
108        ),
109        "kernel_sys_trace.txt": (
110            "cat /sys/kernel/tracing/trace >/tmp/kernel_sys_trace.txt 2>&1"
111        ),
112    },
113}
114# Add file name and corresponding command needed for all Linux distributions
115FFDC_OS_ALL_DISTROS_FILE = {
116    "OS FILES": {
117        # File Name         Command
118        "OS_msglog.txt": (
119            "cat /sys/firmware/opal/msglog >/tmp/OS_msglog.txt 2>&1"
120        ),
121        "OS_cpufrequency.txt": (
122            "ppc64_cpu --frequency >/tmp/OS_cpufrequency.txt 2>&1"
123        ),
124        "OS_dmesg.txt": "dmesg >/tmp/OS_dmesg.txt 2>&1",
125        "OS_opal_prd.txt": "cat /var/log/opal-prd* >/tmp/OS_opal_prd.txt 2>&1",
126        "OS_boot.txt": "cat /var/log/boot.log >/tmp/OS_boot.txt 2>&1",
127        "OS_procinfo.txt": "cat /proc/cpuinfo >/tmp/OS_procinfo.txt 2>&1",
128        "OS_meminfo.txt": "cat /proc/meminfo >/tmp/OS_meminfo.txt 2>&1",
129        "OS_netstat.txt": "netstat -a >/tmp/OS_netstat.txt 2>&1",
130        "OS_lspci.txt": "lspci >/tmp/OS_lspci.txt 2>&1",
131        "OS_lscpu.txt": "lscpu >/tmp/OS_lscpu.txt 2>&1",
132        "OS_lscfg.txt": "lscfg >/tmp/OS_lscfg.txt 2>&1",
133        "OS_journalctl_nopager.txt": (
134            "journalctl --no-pager -b "
135            + "> /tmp/OS_journalctl_nopager.txt  2>&1"
136        ),
137    },
138}
139# Add file name and corresponding command needed for Ubuntu Linux
140FFDC_OS_UBUNTU_FILE = {
141    "OS FILES": {
142        # File Name         Command
143        "OS_isusb.txt": "{ lsusb -t ; lsusb -v ; } >/tmp/OS_isusb.txt 2>&1",
144        "OS_kern.txt": (
145            "tail -n 50000 /var/log/kern.log >/tmp/OS_kern.txt 2>&1"
146        ),
147        "OS_authlog.txt": (
148            "{ cat /var/log/auth.log; cat /var/log/auth.log.1 ; } "
149            + ">/tmp/OS_authlog.txt 2>&1"
150        ),
151        "OS_syslog.txt": (
152            "tail -n 200000 /var/log/syslog >/tmp/OS_syslog.txt 2>&1"
153        ),
154        "OS_info.txt": (
155            "{ uname -a; dpkg -s opal-prd; dpkg -s ipmitool ; } "
156            + ">/tmp/OS_info.txt 2>&1"
157        ),
158        "OS_sosreport.txt": (
159            "{ rm -rf /tmp/sosreport*FFDC* ; sosreport --batch --tmp-dir "
160            + "/tmp --ticket-number FFDC ; } >/tmp/OS_sosreport.txt 2>&1"
161        ),
162    },
163}
164# Add file name and corresponding command needed for RHEL Linux
165FFDC_OS_RHEL_FILE = {
166    "OS FILES": {
167        # File Name         Command
168        "OS_rsct.txt": "/usr/bin/ctversion -bv >/tmp/OS_rsct.txt 2>&1",
169        "OS_secure.txt": "cat /var/log/secure >/tmp/OS_secure.txt 2>&1",
170        "OS_syslog.txt": (
171            "tail -n 200000 /var/log/messages >/tmp/OS_syslog.txt 2>&1"
172        ),
173        "OS_info.txt": (
174            "{ lsb_release -a; cat /etc/redhat-release; "
175            + "uname -a; rpm -qa ; } >/tmp/OS_info.txt 2>&1"
176        ),
177        "OS_sosreport.txt": (
178            "{ rm -rf /tmp/sosreport*FFDC* ; sosreport --batch --tmp-dir "
179            + "/tmp --label FFDC ; } >/tmp/OS_sosreport.txt 2>&1"
180        ),
181    },
182}
183# Add file name and corresponding command needed for AIX.
184FFDC_OS_AIX_FILE = {
185    "OS FILES": {
186        # File Name         Command
187        "OS_errpt.txt": "errpt >/tmp/OS_errpt.txt 2>&1 ; errclear 0;",
188        "OS_processors.txt": "bindprocessor -q >/tmp/OS_processors.txt 2>&1",
189    },
190}
191
192try:
193    redfish_support_trans_state = os.environ.get(
194        "REDFISH_SUPPORT_TRANS_STATE", 0
195    ) or int(
196        BuiltIn().get_variable_value(
197            "${REDFISH_SUPPORT_TRANS_STATE}", default=0
198        )
199    )
200except RobotNotRunningError:
201    pass
202
203OPENBMC_BASE = "/xyz/openbmc_project/"
204OPENPOWER_BASE = "/org/open_power/"
205ENUMERATE_SENSORS = OPENBMC_BASE + "sensors/enumerate"
206ENUMERATE_INVENTORY = OPENBMC_BASE + "inventory/enumerate"
207ENUMERATE_ELOG = OPENBMC_BASE + "logging/entry/enumerate"
208ENUMERATE_LED = OPENBMC_BASE + "led/enumerate"
209ENUMERATE_SW = OPENBMC_BASE + "software/enumerate"
210ENUMERATE_CONTROL = OPENBMC_BASE + "control/enumerate"
211ENUMERATE_STATE = OPENBMC_BASE + "state/enumerate"
212ENUMERATE_OCC = OPENPOWER_BASE + "/enumerate"
213ENUMERATE_DUMPS = OPENBMC_BASE + "dumps/enumerate"
214ENUMERATE_USER = OPENBMC_BASE + "user/enumerate"
215
216# Add file name and corresponding Get Request
217FFDC_GET_REQUEST = {
218    "GET REQUESTS": {
219        # File Name         Command
220        "FIRMWARE_list.txt": ENUMERATE_SW,
221        "BMC_sensor_list.txt": ENUMERATE_SENSORS,
222        "BMC_control_list.txt": ENUMERATE_CONTROL,
223        "BMC_inventory.txt": ENUMERATE_INVENTORY,
224        "BMC_elog.txt": ENUMERATE_ELOG,
225        "BMC_led.txt": ENUMERATE_LED,
226        "BMC_state.txt": ENUMERATE_STATE,
227        "OCC_state.txt": ENUMERATE_OCC,
228        "BMC_dumps.txt": ENUMERATE_DUMPS,
229        "BMC_USER.txt": ENUMERATE_USER,
230    },
231}
232
233# Remove the REST dictionary elements.
234if redfish_support_trans_state == 1:
235    for key in list(FFDC_GET_REQUEST):
236        del FFDC_GET_REQUEST[key]
237
238REDFISH_BASE = "/redfish/v1/"
239REDFISH_FIRMWARE = REDFISH_BASE + "UpdateService/FirmwareInventory"
240
241try:
242    REDFISH_SYSTEM_ID = REDFISH_SYSTEM_ID = os.environ.get(
243        "SYSTEM_ID", ""
244    ) or BuiltIn().get_variable_value("${SYSTEM_ID}", default="system")
245
246    REDFISH_ELOG = (
247        REDFISH_BASE
248        + "Systems/"
249        + REDFISH_SYSTEM_ID
250        + "/LogServices/EventLog/Entries"
251    )
252except RobotNotRunningError:
253    REDFISH_ELOG = REDFISH_BASE + "Systems/system/LogServices/EventLog/Entries"
254    pass
255
256# Add file name and corresponding Get Request
257FFDC_GET_REDFISH_REQUEST = {
258    "GET REQUESTS": {
259        # File Name         Command
260        "BMC_redfish_elog.txt": REDFISH_ELOG,
261    },
262}
263
264# Define your keywords in method/utils and call here
265FFDC_METHOD_CALL = {
266    "BMC LOGS": {
267        # Description               Keyword name
268        "Start ffdc cleanup": "BMC FFDC Cleanup",
269        "FFDC Generic Report": "BMC FFDC Manifest",
270        "BMC Specific Files": "BMC FFDC Files",
271        "Get Request FFDC": "BMC FFDC Get Requests",
272        "Get Redfish Request FFDC": "BMC FFDC Get Redfish Requests",
273        "OS FFDC": "OS FFDC Files",
274        "Core Files": "SCP Coredump Files",
275        "SEL Log": "Collect eSEL Log",
276        "Sys Inventory Files": "System Inventory Files",
277        "Dump Files": "SCP Dump Files",
278        "PEL Files": "Collect PEL Log",
279        "Redfish Log": "Enumerate Redfish Resources",
280        "Firmware Log": (
281            "Enumerate Redfish Resources  "
282            + " enum_uri=/redfish/v1/UpdateService/FirmwareInventory  "
283            + " file_enum_name=redfish_FIRMWARE_list.txt"
284        ),
285        "Redfish OEM Log": "Enumerate Redfish OEM Resources",
286        "End ffdc cleanup": "BMC FFDC Cleanup",
287    },
288}
289
290try:
291    platform_arch_type = os.environ.get(
292        "PLATFORM_ARCH_TYPE", ""
293    ) or BuiltIn().get_variable_value("${PLATFORM_ARCH_TYPE}", default="power")
294except RobotNotRunningError:
295    pass
296
297# Filter the logs based on platform type.
298if platform_arch_type == "x86":
299    del FFDC_BMC_FILE["BMC FILES"]["PEL_logs_list.json"]
300    del FFDC_BMC_FILE["BMC FILES"]["PEL_logs_display.json"]
301    del FFDC_METHOD_CALL["BMC LOGS"]["PEL Files"]
302
303# -----------------------------------------------------------------
304# base class for FFDC default list
305
306
307class openbmc_ffdc_list:
308    def get_ffdc_bmc_cmd(self, i_type):
309        r"""
310        #######################################################################
311        #   @brief    This method returns the list from the dictionary for cmds
312        #   @param    i_type: @type string: string index lookup
313        #   @return   List of key pair from the dictionary
314        #######################################################################
315        """
316        return FFDC_BMC_CMD[i_type].items()
317
318    def get_ffdc_bmc_file(self, i_type):
319        r"""
320        #######################################################################
321        #   @brief    This method returns the list from the dictionary for scp
322        #   @param    i_type: @type string: string index lookup
323        #   @return   List of key pair from the dictionary
324        #######################################################################
325        """
326        return FFDC_BMC_FILE[i_type].items()
327
328    def get_ffdc_get_request(self, i_type):
329        r"""
330        #######################################################################
331        #   @brief    This method returns the list from the dictionary for scp
332        #   @param    i_type: @type string: string index lookup
333        #   @return   List of key pair from the dictionary
334        #######################################################################
335        """
336        return FFDC_GET_REQUEST[i_type].items()
337
338    def get_ffdc_get_redfish_request(self, i_type):
339        r"""
340        #######################################################################
341        #   @brief    This method returns the list from the dictionary for scp
342        #   @param    i_type: @type string: string index lookup
343        #   @return   List of key pair from the dictionary
344        #######################################################################
345        """
346        return FFDC_GET_REDFISH_REQUEST[i_type].items()
347
348    def get_ffdc_cmd_index(self):
349        r"""
350        #######################################################################
351        #   @brief    This method returns the list index from dictionary
352        #   @return   List of index to the dictionary
353        #######################################################################
354        """
355        return FFDC_BMC_CMD.keys()
356
357    def get_ffdc_get_request_index(self):
358        r"""
359        #######################################################################
360        #   @brief    This method returns the list index from dictionary
361        #   @return   List of index to the dictionary
362        #######################################################################
363        """
364        return FFDC_GET_REQUEST.keys()
365
366    def get_ffdc_get_redfish_request_index(self):
367        r"""
368        #######################################################################
369        #   @brief    This method returns the list index from dictionary
370        #   @return   List of index to the dictionary
371        #######################################################################
372        """
373        return FFDC_GET_REDFISH_REQUEST.keys()
374
375    def get_ffdc_file_index(self):
376        r"""
377        #######################################################################
378        #   @brief    This method returns the list index from dictionary
379        #   @return   List of index to the dictionary
380        #######################################################################
381        """
382        return FFDC_BMC_FILE.keys()
383
384    def get_ffdc_method_index(self):
385        r"""
386        #######################################################################
387        #   @brief    This method returns the key pair from the dictionary
388        #   @return   Index of the method dictionary
389        #######################################################################
390        """
391        return FFDC_METHOD_CALL.keys()
392
393    def get_ffdc_method_desc(self, index):
394        r"""
395        #######################################################################
396        #   @brief   This method returns the just the keys from the dictionary.
397        #   @return  List of ffdc descriptions.
398        #######################################################################
399        """
400        return FFDC_METHOD_CALL[index].keys()
401
402    def get_ffdc_method_call(self, i_type):
403        r"""
404        #######################################################################
405        #   @brief    This method returns the key pair from the dictionary
406        #   @return   List of key pair keywords
407        #######################################################################
408        """
409        return FFDC_METHOD_CALL[i_type].items()
410
411    def get_ffdc_os_all_distros_index(self):
412        r"""
413        #######################################################################
414        #   @brief    This method returns the key pair from the dictionary
415        #   @return   Index of the method dictionary
416        #######################################################################
417        """
418        return FFDC_OS_ALL_DISTROS_FILE.keys()
419
420    def get_ffdc_os_all_distros_call(self, i_type):
421        r"""
422        #######################################################################
423        #   @brief    This method returns the key pair from the dictionary
424        #   @return   List of key pair keywords
425        #######################################################################
426        """
427        return FFDC_OS_ALL_DISTROS_FILE[i_type].items()
428
429    def get_ffdc_os_distro_index(self, distro):
430        r"""
431        #######################################################################
432        #   @brief    This method returns the key pair from the dictionary
433        #   @return   Index of the method dictionary
434        #######################################################################
435        """
436        distro_file = "FFDC_OS_" + str(distro).upper() + "_FILE"
437        return eval(distro_file).keys()
438
439    def get_ffdc_os_distro_call(self, i_type, distro):
440        r"""
441        #######################################################################
442        #   @brief    This method returns the key pair from the dictionary
443        #   @return   List of key pair keywords
444        #######################################################################
445        """
446        distro_file = "FFDC_OS_" + str(distro).upper() + "_FILE"
447        return eval(distro_file)[i_type].items()
448
449    def get_strip_string(self, i_str):
450        r"""
451        #######################################################################
452        #   @brief    Returns the stripped strings
453        #   @param    i_str: @type string: string name
454        #   @return   Remove all special chars and return the string
455        #######################################################################
456        """
457        return "".join(e for e in i_str if e.isalnum())
458
459    def get_esel_index(self, esel_list):
460        r"""
461        #######################################################################
462        #   @brief    Returns the eSEL binary index.
463        #   @param    esel_ist: @type list: eSEL list.
464        #   @return   Index of "ESEL=" in the list.
465        #######################################################################
466        """
467        index = [i for i, str in enumerate(esel_list) if "ESEL=" in str]
468        return index[0]
469
470    def get_dump_index(self, dump_list):
471        r"""
472        #######################################################################
473        #   @brief    Returns the eSEL binary index.
474        #   @param    esel_ist: @type list: eSEL list.
475        #   @return   Index of "ESEL=" in the list.
476        #######################################################################
477        """
478        index = [i for i, str in enumerate(dump_list) if "DUMP=" in str]
479        return index[0]
480