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        'Build Info': 'cat /etc/version',
25        'FW Level': 'cat /etc/os-release',
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_journalctl': 'journalctl --no-pager',
46        'BMC_dmesg': 'dmesg',
47        'BMC_procinfo': 'cat /proc/cpuinfo',
48        'BMC_meminfo': 'cat /proc/meminfo',
49    },
50}
51
52# Add file name and correcponding command needed for all Linux distributions
53FFDC_OS_ALL_DISTROS_FILE = {
54    'OS FILES':
55    {
56        # File Name         Command
57        'OS_msglog': 'cat /sys/firmware/opal/msglog',
58        'OS_cpufrequency': 'ppc64_cpu --frequency',
59        'OS_dmesg': 'dmesg',
60        'OS_boot': 'cat /var/log/boot.log',
61        'OS_procinfo': 'cat /proc/cpuinfo',
62        'OS_meminfo': 'cat /proc/meminfo',
63        'OS_netstat': 'netstat -a',
64    },
65}
66
67# Add file name and correcponding command needed for Ubuntu Linux
68FFDC_OS_UBUNTU_FILE = {
69    'OS FILES':
70    {
71        # File Name         Command
72        'OS_isusb': 'lsusb -t ; lsusb -v',
73        'OS_kern': 'tail -n 50000 /var/log/kern.log',
74        'OS_authlog': 'cat /var/log/auth.log; cat /var/log/auth.log.1',
75        'OS_syslog': 'tail -n 200000 /var/log/syslog',
76        'OS_info': 'uname -a; dpkg -s opal-prd; dpkg -s ipmitool',
77    },
78}
79
80# Add file name and correcponding command needed for RHEL Linux
81FFDC_OS_RHEL_FILE = {
82    'OS FILES':
83    {
84        # File Name         Command
85        'OS_rsct': '/usr/bin/ctversion -bv',
86        'OS_secure': 'cat /var/log/secure',
87        'OS_syslog': 'tail -n 200000 /var/log/messages',
88        'OS_info': 'lsb_release -a; cat /etc/redhat-release; uname -a; rpm -qa',
89    },
90}
91
92# Add file name and correcponding command needed for RHEL Linux
93FFDC_OS_IBM_POWERKVM_FILE = {
94    'OS FILES':
95    {
96        # File Name         Command
97        'OS_secure': 'cat /var/log/secure',
98        'OS_syslog': 'tail -n 200000 /var/log/messages',
99        'OS_info': 'lsb_release -a; uname -a; rpm -qa',
100    },
101}
102
103# Enable when ready with openbmc/openbmc-test-automation#203
104# replace with new path /xyz/openbmc_project
105OPENBMC_BASE = '/org/openbmc/'
106ENUMERATE_SENSORS = OPENBMC_BASE + 'sensors/enumerate'
107# TODO: Use the xyz enums once moved to xyz completely
108# ENUMERATE_SYSTEMS = OPENBMC_BASE + 'inventory/enumerate'
109ENUMERATE_SYSTEMS = '/xyz/openbmc_project/inventory/enumerate'
110ENUMERATE_ELOG = '/xyz/openbmc_project/logging/entry/enumerate'
111ENUMERATE_EVENTS = OPENBMC_BASE + 'records/events/enumerate'
112ENUMERATE_LED = OPENBMC_BASE + 'control/led/enumerate'
113
114# Add file name and correcponding Get Request
115FFDC_GET_REQUEST = {
116    'GET REQUESTS':
117    {
118        # File Name         Command
119        'BMC_sensor_list': ENUMERATE_SENSORS,
120        'BMC_inventory': ENUMERATE_SYSTEMS,
121        'BMC_elog': ENUMERATE_ELOG,
122        'BMC_led': ENUMERATE_EVENTS,
123        'BMC_record_log': ENUMERATE_LED,
124    },
125}
126
127
128# Define your keywords in method/utils and call here
129FFDC_METHOD_CALL = {
130    'BMC LOGS':
131    {
132        # Description             Keyword name
133        'FFDC Generic Report': 'BMC FFDC Manifest',
134        'BMC Specific Files': 'BMC FFDC Files',
135        'Get Request FFDC': 'BMC FFDC Get Requests',
136        'OS FFDC': 'OS FFDC Files',
137        'Core Files': 'SCP Coredump Files',
138    },
139}
140
141# -----------------------------------------------------------------
142
143
144# base class for FFDC default list
145class openbmc_ffdc_list():
146
147    def get_ffdc_bmc_cmd(self, i_type):
148        r"""
149        ########################################################################
150        #   @brief    This method returns the list from the dictionary for cmds
151        #   @param    i_type: @type string: string index lookup
152        #   @return   List of key pair from the dictionary
153        ########################################################################
154        """
155        return FFDC_BMC_CMD[i_type].items()
156
157    def get_ffdc_bmc_file(self, i_type):
158        r"""
159        ########################################################################
160        #   @brief    This method returns the list from the dictionary for scp
161        #   @param    i_type: @type string: string index lookup
162        #   @return   List of key pair from the dictionary
163        ########################################################################
164        """
165        return FFDC_BMC_FILE[i_type].items()
166
167    def get_ffdc_get_request(self, i_type):
168        r"""
169        ########################################################################
170        #   @brief    This method returns the list from the dictionary for scp
171        #   @param    i_type: @type string: string index lookup
172        #   @return   List of key pair from the dictionary
173        ########################################################################
174        """
175        return FFDC_GET_REQUEST[i_type].items()
176
177    def get_ffdc_cmd_index(self):
178        r"""
179        ########################################################################
180        #   @brief    This method returns the list index from dictionary
181        #   @return   List of index to the dictionary
182        ########################################################################
183        """
184        return FFDC_BMC_CMD.keys()
185
186    def get_ffdc_get_request_index(self):
187        r"""
188        ########################################################################
189        #   @brief    This method returns the list index from dictionary
190        #   @return   List of index to the dictionary
191        ########################################################################
192        """
193        return FFDC_GET_REQUEST.keys()
194
195    def get_ffdc_file_index(self):
196        r"""
197        ########################################################################
198        #   @brief    This method returns the list index from dictionary
199        #   @return   List of index to the dictionary
200        ########################################################################
201        """
202        return FFDC_BMC_FILE.keys()
203
204    def get_ffdc_method_index(self):
205        r"""
206        ########################################################################
207        #   @brief    This method returns the key pair from the dictionary
208        #   @return   Index of the method dictionary
209        ########################################################################
210        """
211        return FFDC_METHOD_CALL.keys()
212
213    def get_ffdc_method_call(self, i_type):
214        r"""
215        ########################################################################
216        #   @brief    This method returns the key pair from the dictionary
217        #   @return   List of key pair keywords
218        ########################################################################
219        """
220        return FFDC_METHOD_CALL[i_type].items()
221
222    def get_ffdc_os_all_distros_index(self):
223        r"""
224        ########################################################################
225        #   @brief    This method returns the key pair from the dictionary
226        #   @return   Index of the method dictionary
227        ########################################################################
228        """
229        return FFDC_OS_ALL_DISTROS_FILE.keys()
230
231    def get_ffdc_os_all_distros_call(self, i_type):
232        r"""
233        ########################################################################
234        #   @brief    This method returns the key pair from the dictionary
235        #   @return   List of key pair keywords
236        ########################################################################
237        """
238        return FFDC_OS_ALL_DISTROS_FILE[i_type].items()
239
240    def get_ffdc_os_distro_index(self, distro):
241        r"""
242        ########################################################################
243        #   @brief    This method returns the key pair from the dictionary
244        #   @return   Index of the method dictionary
245        ########################################################################
246        """
247        distro_file = "FFDC_OS_" + str(distro).upper() + "_FILE"
248        return eval(distro_file).keys()
249
250    def get_ffdc_os_distro_call(self, i_type, distro):
251        r"""
252        ########################################################################
253        #   @brief    This method returns the key pair from the dictionary
254        #   @return   List of key pair keywords
255        ########################################################################
256        """
257        distro_file = "FFDC_OS_" + str(distro).upper() + "_FILE"
258        return eval(distro_file)[i_type].items()
259
260    def get_strip_string(self, i_str):
261        r"""
262        ########################################################################
263        #   @brief    Returns the stripped strings
264        #   @param    i_str: @type string: string name
265        #   @return   Remove all special chars and return the string
266        ########################################################################
267        """
268        return ''.join(e for e in i_str if e.isalnum())
269