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