blob: 3568dc62a615d51db75f6827ca4f82ef37601a01 [file] [log] [blame]
Michael Walsh769c2a12016-12-13 15:45:17 -06001#!/usr/bin/env python
2
3r"""
4This module is the python counterpart to openbmc_ffdc.robot..
5"""
6
7import os
8
9import gen_robot_print as grp
10import gen_valid as gv
11
12from robot.libraries.BuiltIn import BuiltIn
13
14
15###############################################################################
16def ffdc(ffdc_dir_path=None,
17 ffdc_prefix=None):
18
19 r"""
20 Gather First Failure Data Capture (FFDC).
21
22 This includes:
23 - Set global FFDC_TIME.
24 - Create FFDC work space directory.
25 - Write test info details.
26 - Call BMC methods to write/collect FFDC data.
27
28 Description of arguments:
29 ffdc_dir_path The dir path where FFDC data should be put.
30 ffdc_prefix The prefix to be given to each FFDC file name generated.
31 """
32
33 grp.rprint_timen("Collecting FFDC.")
34
35 # Note: Several subordinate functions like 'Get Test Dir and Name' and
36 # 'Header Message' expect global variable FFDC_TIME to be set.
37 cmd_buf = ["Get Current Time Stamp"]
Michael Walsha0364ae2017-01-10 11:24:42 -060038 grp.rdpissuing_keyword(cmd_buf)
Michael Walsh769c2a12016-12-13 15:45:17 -060039 FFDC_TIME = BuiltIn().run_keyword(*cmd_buf)
40 BuiltIn().set_global_variable("${FFDC_TIME}", FFDC_TIME)
41
42 # Get default values for arguments.
43 ffdc_dir_path, ffdc_prefix = set_ffdc_defaults(ffdc_dir_path, ffdc_prefix)
44 grp.rprint_var(ffdc_dir_path)
45 grp.rprint_var(ffdc_prefix)
46
47 # LOG_PREFIX is used by subordinate functions.
48 LOG_PREFIX = ffdc_dir_path + ffdc_prefix
49 BuiltIn().set_global_variable("${LOG_PREFIX}", LOG_PREFIX)
50
51 cmd_buf = ["Create Directory", ffdc_dir_path]
52 grp.rpissuing_keyword(cmd_buf)
53 status, output = BuiltIn().run_keyword_and_ignore_error(*cmd_buf)
54 if status != "PASS":
Michael Walsha0364ae2017-01-10 11:24:42 -060055 error_message = grp.sprint_error_report("Create Directory failed" +
56 " with the following" +
57 " error:\n" + output)
Michael Walsh769c2a12016-12-13 15:45:17 -060058 BuiltIn().fail(error_message)
59
60 # FFDC_FILE_PATH is used by Header Message.
61 FFDC_FILE_PATH = ffdc_dir_path + ffdc_prefix + "BMC_general.txt"
62 BuiltIn().set_global_variable("${FFDC_FILE_PATH}", FFDC_FILE_PATH)
63
64 cmd_buf = ["Header Message"]
65 grp.rpissuing_keyword(cmd_buf)
66 BuiltIn().run_keyword(*cmd_buf)
67
68 cmd_buf = ["Call FFDC Methods"]
69 grp.rpissuing_keyword(cmd_buf)
70 BuiltIn().run_keyword(*cmd_buf)
71
72 grp.rprint_timen("Finished collecting FFDC.")
73
74###############################################################################
75
76
77###############################################################################
78def set_ffdc_defaults(ffdc_dir_path=None,
79 ffdc_prefix=None):
80
81 r"""
82 Set a default value for ffdc_dir_path and ffdc_prefix if they don't
83 already have values. Return both values.
84
85 Description of arguments:
86 ffdc_dir_path The dir path where FFDC data should be put.
87 ffdc_prefix The prefix to be given to each FFDC file name generated.
88
89 NOTE: If global variable ffdc_dir_path_style is set to ${1}, this function
90 will create default values in a newer way. Otherwise, its behavior
91 will remain unchanged.
92 """
93
Michael Walsha0364ae2017-01-10 11:24:42 -060094 ffdc_dir_path_style = BuiltIn().get_variable_value(
95 "${ffdc_dir_path_style}")
Michael Walsh769c2a12016-12-13 15:45:17 -060096
97 if ffdc_dir_path is None:
98 if ffdc_dir_path_style:
99 try:
100 ffdc_dir_path = os.environ['FFDC_DIR_PATH']
101 except KeyError:
102 ffdc_dir_path = os.path.dirname(
103 BuiltIn().get_variable_value("${LOG_FILE}")) + "/"
104 else:
105 FFDC_LOG_PATH = BuiltIn().get_variable_value("${FFDC_LOG_PATH}")
106 if FFDC_LOG_PATH is None:
107 FFDC_LOG_PATH = ""
108 if FFDC_LOG_PATH == "":
109 FFDC_LOG_PATH = os.path.dirname(
110 BuiltIn().get_variable_value("${LOG_FILE}")) + "/"
111 error_message = gv.svalid_value(FFDC_LOG_PATH,
112 var_name="FFDC_LOG_PATH")
113 if error_message != "":
114 error_message = grp.sprint_error_report(error_message)
115 BuiltIn().fail(error_message)
116 FFDC_LOG_PATH = os.path.normpath(FFDC_LOG_PATH) + os.sep
117
118 cmd_buf = ["Get Test Dir and Name"]
119 grp.rpissuing_keyword(cmd_buf)
120 suitename, testname = BuiltIn().run_keyword(*cmd_buf)
121
122 ffdc_dir_path = FFDC_LOG_PATH + suitename + "/" + testname + "/"
123
124 # Add trailing slash.
125 ffdc_dir_path = os.path.normpath(ffdc_dir_path) + os.sep
126
127 if ffdc_prefix is None:
128 FFDC_TIME = BuiltIn().get_variable_value("${FFDC_TIME}")
129 if ffdc_prefix is None:
130 if ffdc_dir_path_style:
131 OPENBMC_HOST = BuiltIn().get_variable_value("${OPENBMC_HOST}")
Michael Walsha0364ae2017-01-10 11:24:42 -0600132 OPENBMC_NICKNAME = BuiltIn().get_variable_value(
133 "${OPENBMC_NICKNAME}", default=OPENBMC_HOST)
134 ffdc_prefix = OPENBMC_NICKNAME + "." + FFDC_TIME[2:8] + "." +\
Michael Walsh769c2a12016-12-13 15:45:17 -0600135 FFDC_TIME[8:14] + "."
136 else:
137 ffdc_prefix = FFDC_TIME + "_"
138
139 return ffdc_dir_path, ffdc_prefix
140
141###############################################################################