xref: /openbmc/openbmc-test-automation/lib/openbmc_ffdc_list.py (revision de7d408d5fdb55924bfecdeb67253208eb7088eb)
1#!/usr/bin/python
2r"""
3#############################################################
4#    @file     openbmc_ffdc_list.py
5#
6#    @brief    List for FFDC ( First failure data capture )
7#              commands and files to be collected as a part
8#              of the test case failure.
9#############################################################
10"""
11
12# -------------------
13# FFDC default list
14# -------------------
15
16# -----------------------------------------------------------------
17# Dict Name {  Index string : { Key String :  Comand string} }
18# -----------------------------------------------------------------
19# Add cmd's needed to be part of the ffdc report manifest file
20FFDC_BMC_CMD = {
21    'DRIVER INFO':
22    {
23        # String Name         Command
24        'FW Level': 'cat /etc/os-release',
25        'FW Timestamp': 'cat /etc/timestamp',
26    },
27    'BMC DATA':
28    {
29        'BMC OS': 'uname -a',
30        'BMC Uptime': 'uptime',
31        'BMC File System Disk Space Usage': 'df -hT',
32    },
33    'APPLICATION DATA':
34    {
35        'BMC state': '/usr/sbin/obmcutil state',
36    },
37}
38
39# Add file name and correcponding command needed for BMC
40FFDC_BMC_FILE = {
41    'BMC FILES':
42    {
43        # File Name         Command
44        'BMC_proc_list': 'top -n 1 -b',
45        'BMC_proc_fd_active_list': 'ls -Al /proc/*/fd/',
46        'BMC_journalctl': 'journalctl --no-pager',
47        'BMC_dmesg': 'dmesg',
48        'BMC_procinfo': 'cat /proc/cpuinfo',
49        'BMC_meminfo': 'cat /proc/meminfo',
50    },
51}
52
53# Add file name and correcponding command needed for all Linux distributions
54FFDC_OS_ALL_DISTROS_FILE = {
55    'OS FILES':
56    {
57        # File Name         Command
58        'OS_msglog': 'cat /sys/firmware/opal/msglog',
59        'OS_cpufrequency': 'ppc64_cpu --frequency',
60        'OS_dmesg': 'dmesg',
61        'OS_boot': 'cat /var/log/boot.log',
62        'OS_procinfo': 'cat /proc/cpuinfo',
63        'OS_meminfo': 'cat /proc/meminfo',
64        'OS_netstat': 'netstat -a',
65        'OS_lspci': 'lspci',
66        'OS_lscpu': 'lscpu',
67        'OS_lscfg': 'lscfg',
68    },
69}
70
71# Add file name and correcponding command needed for Ubuntu Linux
72FFDC_OS_UBUNTU_FILE = {
73    'OS FILES':
74    {
75        # File Name         Command
76        'OS_isusb': 'lsusb -t ; lsusb -v',
77        'OS_kern': 'tail -n 50000 /var/log/kern.log',
78        'OS_authlog': 'cat /var/log/auth.log; cat /var/log/auth.log.1',
79        'OS_syslog': 'tail -n 200000 /var/log/syslog',
80        'OS_info': 'uname -a; dpkg -s opal-prd; dpkg -s ipmitool',
81    },
82}
83
84# Add file name and correcponding command needed for RHEL Linux
85FFDC_OS_RHEL_FILE = {
86    'OS FILES':
87    {
88        # File Name         Command
89        'OS_rsct': '/usr/bin/ctversion -bv',
90        'OS_secure': 'cat /var/log/secure',
91        'OS_syslog': 'tail -n 200000 /var/log/messages',
92        'OS_info': 'lsb_release -a; cat /etc/redhat-release; uname -a; rpm -qa',
93    },
94}
95
96# Add file name and correcponding command needed for RHEL Linux
97FFDC_OS_IBM_POWERKVM_FILE = {
98    'OS FILES':
99    {
100        # File Name         Command
101        'OS_secure': 'cat /var/log/secure',
102        'OS_syslog': 'tail -n 200000 /var/log/messages',
103        'OS_info': 'lsb_release -a; uname -a; rpm -qa',
104    },
105}
106
107# Enable when ready with openbmc/openbmc-test-automation#203
108# replace with new path /xyz/openbmc_project
109OPENBMC_BASE = '/org/openbmc/'
110ENUMERATE_SENSORS = OPENBMC_BASE + 'sensors/enumerate'
111# TODO: Use the xyz enums once moved to xyz completely
112# ENUMERATE_SYSTEMS = OPENBMC_BASE + 'inventory/enumerate'
113ENUMERATE_SYSTEMS = '/xyz/openbmc_project/inventory/enumerate'
114ENUMERATE_ELOG = '/xyz/openbmc_project/logging/entry/enumerate'
115ENUMERATE_EVENTS = OPENBMC_BASE + 'records/events/enumerate'
116ENUMERATE_LED = OPENBMC_BASE + 'control/led/enumerate'
117
118# Sensors/control data.
119ENUMERATE_SENSOR = '/xyz/openbmc_project/sensors/enumerate'
120ENUMERATE_CONTROL = '/xyz/openbmc_project/control/enumerate'
121
122# Add file name and correcponding Get Request
123FFDC_GET_REQUEST = {
124    'GET REQUESTS':
125    {
126        # File Name         Command
127        'BMC_sensor_list': ENUMERATE_SENSORS,
128        'BMC_sensor_xyz_list': ENUMERATE_SENSOR,
129        'BMC_control_list': ENUMERATE_CONTROL,
130        'BMC_inventory': ENUMERATE_SYSTEMS,
131        'BMC_elog': ENUMERATE_ELOG,
132        'BMC_led': ENUMERATE_EVENTS,
133        'BMC_record_log': ENUMERATE_LED,
134    },
135}
136
137
138# Define your keywords in method/utils and call here
139FFDC_METHOD_CALL = {
140    'BMC LOGS':
141    {
142        # Description             Keyword name
143        'FFDC Generic Report': 'BMC FFDC Manifest',
144        'BMC Specific Files': 'BMC FFDC Files',
145        'Get Request FFDC': 'BMC FFDC Get Requests',
146        'OS FFDC': 'OS FFDC Files',
147        'Core Files': 'SCP Coredump Files',
148        'SEL Log': 'Collect eSEL Log',
149    },
150}
151
152# -----------------------------------------------------------------
153
154
155# base class for FFDC default list
156class openbmc_ffdc_list():
157
158    def get_ffdc_bmc_cmd(self, i_type):
159        r"""
160        ########################################################################
161        #   @brief    This method returns the list from the dictionary for cmds
162        #   @param    i_type: @type string: string index lookup
163        #   @return   List of key pair from the dictionary
164        ########################################################################
165        """
166        return FFDC_BMC_CMD[i_type].items()
167
168    def get_ffdc_bmc_file(self, i_type):
169        r"""
170        ########################################################################
171        #   @brief    This method returns the list from the dictionary for scp
172        #   @param    i_type: @type string: string index lookup
173        #   @return   List of key pair from the dictionary
174        ########################################################################
175        """
176        return FFDC_BMC_FILE[i_type].items()
177
178    def get_ffdc_get_request(self, i_type):
179        r"""
180        ########################################################################
181        #   @brief    This method returns the list from the dictionary for scp
182        #   @param    i_type: @type string: string index lookup
183        #   @return   List of key pair from the dictionary
184        ########################################################################
185        """
186        return FFDC_GET_REQUEST[i_type].items()
187
188    def get_ffdc_cmd_index(self):
189        r"""
190        ########################################################################
191        #   @brief    This method returns the list index from dictionary
192        #   @return   List of index to the dictionary
193        ########################################################################
194        """
195        return FFDC_BMC_CMD.keys()
196
197    def get_ffdc_get_request_index(self):
198        r"""
199        ########################################################################
200        #   @brief    This method returns the list index from dictionary
201        #   @return   List of index to the dictionary
202        ########################################################################
203        """
204        return FFDC_GET_REQUEST.keys()
205
206    def get_ffdc_file_index(self):
207        r"""
208        ########################################################################
209        #   @brief    This method returns the list index from dictionary
210        #   @return   List of index to the dictionary
211        ########################################################################
212        """
213        return FFDC_BMC_FILE.keys()
214
215    def get_ffdc_method_index(self):
216        r"""
217        ########################################################################
218        #   @brief    This method returns the key pair from the dictionary
219        #   @return   Index of the method dictionary
220        ########################################################################
221        """
222        return FFDC_METHOD_CALL.keys()
223
224    def get_ffdc_method_desc(self,
225                             index):
226        r"""
227        ########################################################################
228        #   @brief   This method returns the just the keys from the dictionary.
229        #   @return  List of ffdc descriptions.
230        ########################################################################
231        """
232        return FFDC_METHOD_CALL[index].keys()
233
234    def get_ffdc_method_call(self, i_type):
235        r"""
236        ########################################################################
237        #   @brief    This method returns the key pair from the dictionary
238        #   @return   List of key pair keywords
239        ########################################################################
240        """
241        return FFDC_METHOD_CALL[i_type].items()
242
243    def get_ffdc_os_all_distros_index(self):
244        r"""
245        ########################################################################
246        #   @brief    This method returns the key pair from the dictionary
247        #   @return   Index of the method dictionary
248        ########################################################################
249        """
250        return FFDC_OS_ALL_DISTROS_FILE.keys()
251
252    def get_ffdc_os_all_distros_call(self, i_type):
253        r"""
254        ########################################################################
255        #   @brief    This method returns the key pair from the dictionary
256        #   @return   List of key pair keywords
257        ########################################################################
258        """
259        return FFDC_OS_ALL_DISTROS_FILE[i_type].items()
260
261    def get_ffdc_os_distro_index(self, distro):
262        r"""
263        ########################################################################
264        #   @brief    This method returns the key pair from the dictionary
265        #   @return   Index of the method dictionary
266        ########################################################################
267        """
268        distro_file = "FFDC_OS_" + str(distro).upper() + "_FILE"
269        return eval(distro_file).keys()
270
271    def get_ffdc_os_distro_call(self, i_type, distro):
272        r"""
273        ########################################################################
274        #   @brief    This method returns the key pair from the dictionary
275        #   @return   List of key pair keywords
276        ########################################################################
277        """
278        distro_file = "FFDC_OS_" + str(distro).upper() + "_FILE"
279        return eval(distro_file)[i_type].items()
280
281    def get_strip_string(self, i_str):
282        r"""
283        ########################################################################
284        #   @brief    Returns the stripped strings
285        #   @param    i_str: @type string: string name
286        #   @return   Remove all special chars and return the string
287        ########################################################################
288        """
289        return ''.join(e for e in i_str if e.isalnum())
290
291    def get_esel_index(self, esel_list):
292        r"""
293        #######################################################################
294        #   @brief    Returns the eSEL binary index.
295        #   @param    esel_ist: @type list: eSEL list.
296        #   @return   Index of "ESEL=" in the list.
297        #######################################################################
298        """
299        index = [i for i, str in enumerate(esel_list) if 'ESEL=' in str]
300        return index[0]
301