George Keishing | e7e9171 | 2021-09-03 11:28:44 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 2 | |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 3 | r""" |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 4 | Use robot framework API to extract test result data from output.xml generated |
| 5 | by robot tests. For more information on the Robot Framework API, see |
| 6 | http://robot-framework.readthedocs.io/en/3.0/autodoc/robot.result.html |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 7 | """ |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 8 | |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 9 | import csv |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 10 | import datetime |
| 11 | import getopt |
| 12 | import os |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 13 | import re |
Steven Sombar | 3e82e3b | 2019-03-21 10:33:52 -0500 | [diff] [blame] | 14 | import stat |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 15 | import sys |
| 16 | from xml.etree import ElementTree |
| 17 | |
| 18 | import robot.errors |
| 19 | from robot.api import ExecutionResult |
| 20 | from robot.result.visitor import ResultVisitor |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 21 | |
| 22 | # Remove the python library path to restore with local project path later. |
| 23 | save_path_0 = sys.path[0] |
| 24 | del sys.path[0] |
George Keishing | c2a6f09 | 2019-02-20 12:26:54 -0600 | [diff] [blame] | 25 | sys.path.append(os.path.join(os.path.dirname(__file__), "../../lib")) |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 26 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 27 | from gen_arg import * # NOQA |
George Keishing | 0967989 | 2022-12-08 08:21:52 -0600 | [diff] [blame] | 28 | from gen_print import * # NOQA |
| 29 | from gen_valid import * # NOQA |
George Keishing | 37c58c8 | 2022-12-08 07:42:54 -0600 | [diff] [blame] | 30 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 31 | # Restore sys.path[0]. |
| 32 | sys.path.insert(0, save_path_0) |
| 33 | |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 34 | |
| 35 | this_program = sys.argv[0] |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 36 | info = " For more information: " + this_program + " -h" |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 37 | if len(sys.argv) == 1: |
George Keishing | bfa859a | 2020-04-02 00:38:24 -0500 | [diff] [blame] | 38 | print(info) |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 39 | sys.exit(1) |
| 40 | |
| 41 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 42 | parser = argparse.ArgumentParser( |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 43 | usage=info, |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 44 | description=( |
| 45 | "%(prog)s uses a robot framework API to extract test result data" |
| 46 | " from output.xml generated by robot tests. For more information on" |
| 47 | " the Robot Framework API, see " |
| 48 | " http://robot-framework.readthedocs.io/en/3.0/autodoc/robot.result.html" |
| 49 | ), |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 50 | formatter_class=argparse.ArgumentDefaultsHelpFormatter, |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 51 | prefix_chars="-+", |
| 52 | ) |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 53 | |
| 54 | parser.add_argument( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 55 | "--source", |
| 56 | "-s", |
| 57 | help=( |
| 58 | "The output.xml robot test result file path. This parameter is " |
| 59 | " required." |
| 60 | ), |
| 61 | ) |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 62 | |
| 63 | parser.add_argument( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 64 | "--dest", |
| 65 | "-d", |
| 66 | help=( |
| 67 | "The directory path where the generated .csv files will go. This " |
| 68 | " parameter is required." |
| 69 | ), |
| 70 | ) |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 71 | |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 72 | parser.add_argument( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 73 | "--version_id", |
| 74 | help=( |
| 75 | "Driver version of openbmc firmware which was used during test, " |
| 76 | ' e.g. "v2.1-215-g6e7eacb". This parameter is required.' |
| 77 | ), |
| 78 | ) |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 79 | |
| 80 | parser.add_argument( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 81 | "--platform", |
| 82 | help=( |
| 83 | "OpenBMC platform which was used during test, e.g." |
| 84 | ' "Witherspoon". This parameter is required.' |
| 85 | ), |
| 86 | ) |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 87 | |
George Keishing | 19533d5 | 2018-04-09 03:08:03 -0500 | [diff] [blame] | 88 | parser.add_argument( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 89 | "--level", |
| 90 | help=( |
| 91 | "OpenBMC release level which was used during test, e.g." |
| 92 | ' "Master", "OBMC920". This parameter is required.' |
| 93 | ), |
| 94 | ) |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 95 | |
| 96 | parser.add_argument( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 97 | "--test_phase", |
| 98 | help=( |
| 99 | 'Name of testing phase, e.g. "DVT", "SVT", etc. This' |
| 100 | " parameter is optional." |
| 101 | ), |
| 102 | default="FVT", |
| 103 | ) |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 104 | |
| 105 | parser.add_argument( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 106 | "--subsystem", |
| 107 | help=( |
| 108 | 'Name of the subsystem, e.g. "OPENBMC" etc. This parameter is' |
| 109 | " optional." |
| 110 | ), |
| 111 | default="OPENBMC", |
| 112 | ) |
Vijay | e3a9837 | 2019-10-30 02:04:22 -0500 | [diff] [blame] | 113 | |
| 114 | parser.add_argument( |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 115 | "--processor", |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 116 | help='Name of processor, e.g. "P9". This parameter is optional.', |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 117 | default="OPENPOWER", |
| 118 | ) |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 119 | |
George Keishing | 19533d5 | 2018-04-09 03:08:03 -0500 | [diff] [blame] | 120 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 121 | # Populate stock_list with options we want. |
| 122 | stock_list = [("test_mode", 0), ("quiet", 0), ("debug", 0)] |
| 123 | |
| 124 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 125 | def exit_function(signal_number=0, frame=None): |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 126 | r""" |
| 127 | Execute whenever the program ends normally or with the signals that we |
| 128 | catch (i.e. TERM, INT). |
| 129 | """ |
| 130 | |
| 131 | dprint_executing() |
| 132 | |
| 133 | dprint_var(signal_number) |
| 134 | |
| 135 | qprint_pgm_footer() |
| 136 | |
| 137 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 138 | def signal_handler(signal_number, frame): |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 139 | r""" |
| 140 | Handle signals. Without a function to catch a SIGTERM or SIGINT, the |
| 141 | program would terminate immediately with return code 143 and without |
| 142 | calling the exit_function. |
| 143 | """ |
| 144 | |
| 145 | # Our convention is to set up exit_function with atexit.register() so |
| 146 | # there is no need to explicitly call exit_function from here. |
| 147 | |
| 148 | dprint_executing() |
| 149 | |
| 150 | # Calling exit prevents us from returning to the code that was running |
| 151 | # when the signal was received. |
| 152 | exit(0) |
| 153 | |
| 154 | |
| 155 | def validate_parms(): |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 156 | r""" |
| 157 | Validate program parameters, etc. Return True or False (i.e. pass/fail) |
| 158 | accordingly. |
| 159 | """ |
| 160 | |
| 161 | if not valid_file_path(source): |
| 162 | return False |
| 163 | |
| 164 | if not valid_dir_path(dest): |
| 165 | return False |
| 166 | |
| 167 | gen_post_validation(exit_function, signal_handler) |
| 168 | |
| 169 | return True |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 170 | |
| 171 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 172 | def parse_output_xml( |
| 173 | xml_file_path, |
| 174 | csv_dir_path, |
| 175 | version_id, |
| 176 | platform, |
| 177 | level, |
| 178 | test_phase, |
| 179 | processor, |
| 180 | ): |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 181 | r""" |
| 182 | Parse the robot-generated output.xml file and extract various test |
| 183 | output data. Put the extracted information into a csv file in the "dest" |
| 184 | folder. |
| 185 | |
| 186 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 187 | xml_file_path The path to a Robot-generated output.xml |
| 188 | file. |
| 189 | csv_dir_path The path to the directory that is to |
| 190 | contain the .csv files generated by |
| 191 | this function. |
| 192 | version_id Version of the openbmc firmware |
| 193 | (e.g. "v2.1-215-g6e7eacb"). |
| 194 | platform Platform of the openbmc system. |
| 195 | level Release level of the OpenBMC system |
George Keishing | 360db63 | 2018-09-06 12:01:28 -0500 | [diff] [blame] | 196 | (e.g. "Master"). |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 197 | """ |
| 198 | |
Peter D Phan | 8e13ade | 2021-09-16 06:15:55 -0500 | [diff] [blame] | 199 | # Initialize tallies |
| 200 | total_critical_tc = 0 |
| 201 | total_critical_passed = 0 |
| 202 | total_critical_failed = 0 |
| 203 | total_non_critical_tc = 0 |
| 204 | total_non_critical_passed = 0 |
| 205 | total_non_critical_failed = 0 |
| 206 | |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 207 | result = ExecutionResult(xml_file_path) |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 208 | result.configure( |
| 209 | stat_config={ |
| 210 | "suite_stat_level": 2, |
| 211 | "tag_stat_combine": "tagANDanother", |
| 212 | } |
| 213 | ) |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 214 | |
| 215 | stats = result.statistics |
George Keishing | f8a9ebe | 2018-08-06 12:49:11 -0500 | [diff] [blame] | 216 | print("--------------------------------------") |
Peter D Phan | 8e13ade | 2021-09-16 06:15:55 -0500 | [diff] [blame] | 217 | try: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 218 | total_critical_tc = ( |
| 219 | stats.total.critical.passed + stats.total.critical.failed |
| 220 | ) |
Peter D Phan | 8e13ade | 2021-09-16 06:15:55 -0500 | [diff] [blame] | 221 | total_critical_passed = stats.total.critical.passed |
| 222 | total_critical_failed = stats.total.critical.failed |
| 223 | except AttributeError: |
| 224 | pass |
| 225 | |
| 226 | try: |
| 227 | total_non_critical_tc = stats.total.passed + stats.total.failed |
| 228 | total_non_critical_passed = stats.total.passed |
| 229 | total_non_critical_failed = stats.total.failed |
| 230 | except AttributeError: |
| 231 | pass |
| 232 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 233 | print( |
| 234 | "Total Test Count:\t %d" % (total_non_critical_tc + total_critical_tc) |
| 235 | ) |
Peter D Phan | 8e13ade | 2021-09-16 06:15:55 -0500 | [diff] [blame] | 236 | |
| 237 | print("Total Critical Test Failed:\t %d" % total_critical_failed) |
| 238 | print("Total Critical Test Passed:\t %d" % total_critical_passed) |
| 239 | print("Total Non-Critical Test Failed:\t %d" % total_non_critical_failed) |
| 240 | print("Total Non-Critical Test Passed:\t %d" % total_non_critical_passed) |
George Keishing | f8a9ebe | 2018-08-06 12:49:11 -0500 | [diff] [blame] | 241 | print("Test Start Time:\t %s" % result.suite.starttime) |
| 242 | print("Test End Time:\t\t %s" % result.suite.endtime) |
| 243 | print("--------------------------------------") |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 244 | |
| 245 | # Use ResultVisitor object and save off the test data info |
| 246 | class TestResult(ResultVisitor): |
| 247 | def __init__(self): |
| 248 | self.testData = [] |
| 249 | |
| 250 | def visit_test(self, test): |
| 251 | self.testData += [test] |
| 252 | |
| 253 | collectDataObj = TestResult() |
| 254 | result.visit(collectDataObj) |
| 255 | |
| 256 | # Write the result statistics attributes to CSV file |
| 257 | l_csvlist = [] |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 258 | |
| 259 | # Default Test data |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 260 | l_test_type = test_phase |
George Keishing | 19533d5 | 2018-04-09 03:08:03 -0500 | [diff] [blame] | 261 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 262 | l_pse_rel = "Master" |
George Keishing | 19533d5 | 2018-04-09 03:08:03 -0500 | [diff] [blame] | 263 | if level: |
| 264 | l_pse_rel = level |
| 265 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 266 | l_env = "HW" |
Steven Sombar | a5e32f2 | 2019-03-01 13:33:15 -0600 | [diff] [blame] | 267 | l_proc = processor |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 268 | l_platform_type = "" |
| 269 | l_func_area = "" |
| 270 | |
Gunnar Mills | 096cd56 | 2018-03-26 10:19:12 -0500 | [diff] [blame] | 271 | # System data from XML meta data |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 272 | # l_system_info = get_system_details(xml_file_path) |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 273 | |
| 274 | # First let us try to collect information from keyboard input |
| 275 | # If keyboard input cannot give both information, then find from xml file. |
| 276 | if version_id and platform: |
| 277 | l_driver = version_id |
| 278 | l_platform_type = platform |
George Keishing | f8a9ebe | 2018-08-06 12:49:11 -0500 | [diff] [blame] | 279 | print("BMC Version_id:%s" % version_id) |
| 280 | print("BMC Platform:%s" % platform) |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 281 | else: |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 282 | # System data from XML meta data |
| 283 | l_system_info = get_system_details(xml_file_path) |
| 284 | l_driver = l_system_info[0] |
| 285 | l_platform_type = l_system_info[1] |
| 286 | |
| 287 | # Driver version id and platform are mandatorily required for CSV file |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 288 | # generation. If any one is not avaulable, exit CSV file generation |
| 289 | # process. |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 290 | if l_driver and l_platform_type: |
George Keishing | f8a9ebe | 2018-08-06 12:49:11 -0500 | [diff] [blame] | 291 | print("Driver and system info set.") |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 292 | else: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 293 | print( |
| 294 | "Both driver and system info need to be set. CSV" |
| 295 | " file is not generated." |
| 296 | ) |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 297 | sys.exit() |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 298 | |
| 299 | # Default header |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 300 | l_header = [ |
| 301 | "test_start", |
| 302 | "test_end", |
| 303 | "subsys", |
| 304 | "test_type", |
| 305 | "test_result", |
| 306 | "test_name", |
| 307 | "pse_rel", |
| 308 | "driver", |
| 309 | "env", |
| 310 | "proc", |
| 311 | "platform_type", |
| 312 | "test_func_area", |
| 313 | ] |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 314 | |
| 315 | l_csvlist.append(l_header) |
| 316 | |
| 317 | # Generate CSV file onto the path with current time stamp |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 318 | l_base_dir = csv_dir_path |
George Keishing | 937fe3c | 2019-10-29 11:20:34 -0500 | [diff] [blame] | 319 | l_timestamp = datetime.datetime.utcnow().strftime("%Y-%m-%d-%H-%M-%S") |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 320 | # Example: 2017-02-20-08-47-22_Witherspoon.csv |
| 321 | l_csvfile = l_base_dir + l_timestamp + "_" + l_platform_type + ".csv" |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 322 | |
George Keishing | f8a9ebe | 2018-08-06 12:49:11 -0500 | [diff] [blame] | 323 | print("Writing data into csv file:%s" % l_csvfile) |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 324 | |
| 325 | for testcase in collectDataObj.testData: |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 326 | # Functional Area: Suite Name |
| 327 | # Test Name: Test Case Name |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 328 | l_func_area = str(testcase.parent).split(" ", 1)[1] |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 329 | l_test_name = str(testcase) |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 330 | |
| 331 | # Test Result pass=0 fail=1 |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 332 | if testcase.status == "PASS": |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 333 | l_test_result = 0 |
| 334 | else: |
| 335 | l_test_result = 1 |
| 336 | |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 337 | # Format datetime from robot output.xml to "%Y-%m-%d-%H-%M-%S" |
| 338 | l_stime = xml_to_csv_time(testcase.starttime) |
| 339 | l_etime = xml_to_csv_time(testcase.endtime) |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 340 | # Data Sequence: test_start,test_end,subsys,test_type, |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 341 | # test_result,test_name,pse_rel,driver, |
George Keishing | 360db63 | 2018-09-06 12:01:28 -0500 | [diff] [blame] | 342 | # env,proc,platform_type,test_func_area, |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 343 | l_data = [ |
| 344 | l_stime, |
| 345 | l_etime, |
| 346 | subsystem, |
| 347 | l_test_type, |
| 348 | l_test_result, |
| 349 | l_test_name, |
| 350 | l_pse_rel, |
| 351 | l_driver, |
| 352 | l_env, |
| 353 | l_proc, |
| 354 | l_platform_type, |
| 355 | l_func_area, |
| 356 | ] |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 357 | l_csvlist.append(l_data) |
| 358 | |
George Keishing | a96e27c | 2016-12-04 23:05:04 -0600 | [diff] [blame] | 359 | # Open the file and write to the CSV file |
| 360 | l_file = open(l_csvfile, "w") |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 361 | l_writer = csv.writer(l_file, lineterminator="\n") |
George Keishing | a96e27c | 2016-12-04 23:05:04 -0600 | [diff] [blame] | 362 | l_writer.writerows(l_csvlist) |
| 363 | l_file.close() |
Steven Sombar | 3e82e3b | 2019-03-21 10:33:52 -0500 | [diff] [blame] | 364 | # Set file permissions 666. |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 365 | perm = ( |
| 366 | stat.S_IRUSR |
| 367 | + stat.S_IWUSR |
| 368 | + stat.S_IRGRP |
| 369 | + stat.S_IWGRP |
| 370 | + stat.S_IROTH |
| 371 | + stat.S_IWOTH |
| 372 | ) |
Steven Sombar | 3e82e3b | 2019-03-21 10:33:52 -0500 | [diff] [blame] | 373 | os.chmod(l_csvfile, perm) |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 374 | |
| 375 | |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 376 | def xml_to_csv_time(xml_datetime): |
| 377 | r""" |
| 378 | Convert the time from %Y%m%d %H:%M:%S.%f format to %Y-%m-%d-%H-%M-%S format |
| 379 | and return it. |
| 380 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 381 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 382 | datetime The date in the following format: %Y%m%d |
| 383 | %H:%M:%S.%f (This is the format |
| 384 | typically found in an XML file.) |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 385 | |
| 386 | The date returned will be in the following format: %Y-%m-%d-%H-%M-%S |
| 387 | """ |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 388 | |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 389 | # 20170206 05:05:19.342 |
George Keishing | 937fe3c | 2019-10-29 11:20:34 -0500 | [diff] [blame] | 390 | l_str = datetime.datetime.strptime(xml_datetime, "%Y%m%d %H:%M:%S.%f") |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 391 | # 2017-02-06-05-05-19 |
| 392 | l_str = l_str.strftime("%Y-%m-%d-%H-%M-%S") |
| 393 | return str(l_str) |
| 394 | |
| 395 | |
| 396 | def get_system_details(xml_file_path): |
| 397 | r""" |
| 398 | Get the system data from output.xml generated by robot and return it. |
Gunnar Mills | 28e403b | 2017-10-25 16:16:38 -0500 | [diff] [blame] | 399 | The list returned will be in the following order: [driver,platform] |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 400 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 401 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 402 | xml_file_path The relative or absolute path to the |
| 403 | output.xml file. |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 404 | """ |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 405 | |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 406 | bmc_version_id = "" |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 407 | bmc_platform = "" |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 408 | with open(xml_file_path, "rt") as output: |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 409 | tree = ElementTree.parse(output) |
| 410 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 411 | for node in tree.iter("msg"): |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 412 | # /etc/os-release output is logged in the XML as msg |
George Keishing | 360db63 | 2018-09-06 12:01:28 -0500 | [diff] [blame] | 413 | # Example: ${output} = VERSION_ID="v1.99.2-71-gbc49f79" |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 414 | if "${output} = VERSION_ID=" in node.text: |
George Keishing | 360db63 | 2018-09-06 12:01:28 -0500 | [diff] [blame] | 415 | # Get BMC version (e.g. v1.99.1-96-g2a46570) |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 416 | bmc_version_id = str(node.text.split("VERSION_ID=")[1])[1:-1] |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 417 | |
| 418 | # Platform is logged in the XML as msg. |
| 419 | # Example: ${bmc_model} = Witherspoon BMC |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 420 | if "${bmc_model} = " in node.text: |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 421 | bmc_platform = node.text.split(" = ")[1] |
| 422 | |
manasarm | e4f79c9 | 2018-02-22 13:02:46 +0530 | [diff] [blame] | 423 | print_vars(bmc_version_id, bmc_platform) |
| 424 | return [str(bmc_version_id), str(bmc_platform)] |
George Keishing | 74777bd | 2017-02-07 01:43:38 -0600 | [diff] [blame] | 425 | |
| 426 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 427 | def main(): |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 428 | if not gen_get_options(parser, stock_list): |
| 429 | return False |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 430 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 431 | if not validate_parms(): |
| 432 | return False |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 433 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 434 | qprint_pgm_header() |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 435 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 436 | parse_output_xml( |
| 437 | source, dest, version_id, platform, level, test_phase, processor |
| 438 | ) |
George Keishing | 9fbdf79 | 2016-10-18 06:16:09 -0500 | [diff] [blame] | 439 | |
manasarm | 5dedfaf | 2018-02-07 14:54:54 +0530 | [diff] [blame] | 440 | return True |
| 441 | |
| 442 | |
| 443 | # Main |
| 444 | |
| 445 | if not main(): |
| 446 | exit(1) |