def print_test_start_message(boot_keyword): r""" Print a message indicating what boot test is about to run. Description of arguments: boot_keyword The name of the boot which is to be run (e.g. "BMC Power On"). """ global last_ten doing_msg = gp.sprint_timen("Doing \"" + boot_keyword + "\".") gp.qprint(doing_msg) last_ten.append(doing_msg) if len(last_ten) > 10: del last_ten[0]
def print_test_start_message(boot_keyword): r""" Print a message indicating what boot test is about to run. Description of arguments: boot_keyword The name of the boot which is to be run (e.g. "BMC Power On"). """ global boot_history global boot_start_time doing_msg = gp.sprint_timen("Doing \"" + boot_keyword + "\".") # Set boot_start_time for use by plug-ins. boot_start_time = doing_msg[1:33] gp.qprint_var(boot_start_time) gp.qprint(doing_msg) update_boot_history(boot_history, doing_msg, max_boot_history)
def print_test_start_message(boot_keyword): r""" Print a message indicating what boot test is about to run. Description of arguments: boot_keyword The name of the boot which is to be run (e.g. "BMC Power On"). """ global last_ten global boot_start_time doing_msg = gp.sprint_timen("Doing \"" + boot_keyword + "\".") # Set boot_start_time for use by plug-ins. boot_start_time = doing_msg[1:33] gp.qprint_var(boot_start_time) gp.qprint(doing_msg) last_ten.append(doing_msg) # Trim list to max number of entries. del last_ten[:max(0, len(last_ten) - max_boot_history)]
def test_loop_body(): r""" The main loop body for the loop in main_py. Description of arguments: boot_count The iteration number (starts at 1). """ global boot_count global state global next_boot global boot_success global boot_end_time gp.qprintn() next_boot = select_boot() if next_boot == "": return True boot_count += 1 gp.qprint_timen("Starting boot " + str(boot_count) + ".") pre_boot_plug_in_setup() cmd_buf = ["run_boot", next_boot] boot_status, msg = BuiltIn().run_keyword_and_ignore_error(*cmd_buf) if boot_status == "FAIL": gp.qprint(msg) gp.qprintn() if boot_status == "PASS": boot_success = 1 completion_msg = gp.sprint_timen("BOOT_SUCCESS: \"" + next_boot + "\" succeeded.") else: boot_success = 0 completion_msg = gp.sprint_timen("BOOT_FAILED: \"" + next_boot + "\" failed.") # Set boot_end_time for use by plug-ins. boot_end_time = completion_msg[1:33] gp.qprint_var(boot_end_time) gp.qprint(completion_msg) boot_results.update(next_boot, boot_status) plug_in_setup() # NOTE: A post_test_case call point failure is NOT counted as a boot # failure. rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( call_point='post_test_case', stop_on_plug_in_failure=0) plug_in_setup() rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( call_point='ffdc_check', shell_rc=0x00000200, stop_on_plug_in_failure=1, stop_on_non_zero_rc=1) if boot_status != "PASS" or ffdc_check == "All" or shell_rc == 0x00000200: status, ret_values = grk.run_key_u("my_ffdc", ignore=1) if status != 'PASS': gp.qprint_error("Call to my_ffdc failed.\n") # We need to purge error logs between boots or they build up. grk.run_key("Delete Error logs", ignore=1) boot_results.print_report() gp.qprint_timen("Finished boot " + str(boot_count) + ".") plug_in_setup() rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( call_point='stop_check') if rc != 0: error_message = "Stopping as requested by user.\n" grp.rprint_error_report(error_message) BuiltIn().fail(error_message) # This should help prevent ConnectionErrors. grk.run_key_u("Close All Connections") return True
def terminate_descendants(): r""" Terminate descendants of the current process according to the requirements layed out in global term_options variable. Note: If term_options is not null, gen_exit_function() will automatically call this function. When this function gets called, descendant processes may be running and may be printing to the same stdout stream being used by this process. If this function writes directly to stdout, its output can be interspersed with any output generated by descendant processes. This makes it very difficult to interpret the output. In order solve this problem, the activity of this process will be logged to a temporary file. After descendant processes have been terminated successfully, the temporary file will be printed to stdout and then deleted. However, if this function should fail to complete (i.e. get hung waiting for descendants to terminate gracefully), the temporary file will not be deleted and can be used by the developer for debugging. If no descendant processes are found, this function will return before creating the temporary file. Note that a general principal being observed here is that each process is responsible for the children it produces. """ message = "\n" + gp.sprint_dashes(width=120) \ + gp.sprint_executing() + "\n" current_process = psutil.Process() descendants, descendant_pids, process_report = get_descendant_info( current_process) if not descendants: # If there are no descendants, then we have nothing to do. return terminate_descendants_temp_file_path = gm.create_temp_file_path() gp.print_vars(terminate_descendants_temp_file_path) message += gp.sprint_varx("pgm_name", gp.pgm_name) \ + gp.sprint_vars(term_options) \ + process_report # Process the termination requests: if term_options['term_requests'] == 'children': term_processes = current_process.children(recursive=False) term_pids = [str(process.pid) for process in term_processes] elif term_options['term_requests'] == 'descendants': term_processes = descendants term_pids = descendant_pids else: # Process term requests by pgm_names. term_processes = [] for pgm_name in term_options['term_requests']['pgm_names']: term_processes.extend( select_processes_by_pgm_name(descendants, pgm_name)) term_pids = [str(process.pid) for process in term_processes] message += gp.sprint_timen("Processes to be terminated:") \ + gp.sprint_var(term_pids) for process in term_processes: process.terminate() message += gp.sprint_timen("Waiting on the following pids: " + ' '.join(descendant_pids)) gm.append_file(terminate_descendants_temp_file_path, message) psutil.wait_procs(descendants) # Checking after the fact to see whether any descendant processes are still alive. If so, a process # report showing this will be included in the output. descendants, descendant_pids, process_report = get_descendant_info( current_process) if descendants: message = "\n" + gp.sprint_timen("Not all of the processes terminated:") \ + process_report gm.append_file(terminate_descendants_temp_file_path, message) message = gp.sprint_dashes(width=120) gm.append_file(terminate_descendants_temp_file_path, message) gp.print_file(terminate_descendants_temp_file_path) os.remove(terminate_descendants_temp_file_path)
def test_loop_body(): r""" The main loop body for the loop in main_py. Description of arguments: boot_count The iteration number (starts at 1). """ global boot_count global state global next_boot global boot_success global boot_end_time gp.qprintn() next_boot = select_boot() if next_boot == "": return True boot_count += 1 gp.qprint_timen("Starting boot " + str(boot_count) + ".") pre_boot_plug_in_setup() cmd_buf = ["run_boot", next_boot] boot_status, msg = BuiltIn().run_keyword_and_ignore_error(*cmd_buf) if boot_status == "FAIL": gp.qprint(msg) gp.qprintn() if boot_status == "PASS": boot_success = 1 completion_msg = gp.sprint_timen("BOOT_SUCCESS: \"" + next_boot + "\" succeeded.") else: boot_success = 0 completion_msg = gp.sprint_timen("BOOT_FAILED: \"" + next_boot + "\" failed.") # Set boot_end_time for use by plug-ins. boot_end_time = completion_msg[1:33] gp.qprint_var(boot_end_time) gp.qprint(completion_msg) boot_results.update(next_boot, boot_status) plug_in_setup() # NOTE: A post_test_case call point failure is NOT counted as a boot # failure. rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( call_point='post_test_case', stop_on_plug_in_failure=0) plug_in_setup() rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( call_point='ffdc_check', shell_rc=dump_ffdc_rc(), stop_on_plug_in_failure=1, stop_on_non_zero_rc=1) if ffdc_check == "All" or\ shell_rc == dump_ffdc_rc(): status, ret_values = grk.run_key_u("my_ffdc", ignore=1) if status != 'PASS': gp.qprint_error("Call to my_ffdc failed.\n") # Leave a record for caller that "soft" errors occurred. soft_errors = 1 gpu.save_plug_in_value(soft_errors, pgm_name) if delete_errlogs: # print error logs before delete status, error_logs = grk.run_key_u("Get Error Logs") pels = pel.peltool("-l", ignore_err=1) log.print_error_logs(error_logs, "AdditionalData Message Severity") gp.qprint_var(pels) # We need to purge error logs between boots or they build up. grk.run_key(delete_errlogs_cmd, ignore=1) grk.run_key(delete_bmcdump_cmd, ignore=1) boot_results.print_report() gp.qprint_timen("Finished boot " + str(boot_count) + ".") plug_in_setup() rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( call_point='stop_check', shell_rc=stop_test_rc(), stop_on_non_zero_rc=1) if shell_rc == stop_test_rc(): message = "Stopping as requested by user.\n" gp.qprint_time(message) BuiltIn().fail(message) # This should help prevent ConnectionErrors. # Purge all redfish and REST connection sessions. if redfish_delete_sessions: grk.run_key_u("Close All Connections", ignore=1) grk.run_key_u("Delete All Redfish Sessions", ignore=1) return True
def test_loop_body(): r""" The main loop body for the loop in main_py. Description of arguments: boot_count The iteration number (starts at 1). """ global boot_count global state global next_boot global boot_success global boot_end_time gp.qprintn() next_boot = select_boot() if next_boot == "": return True boot_count += 1 gp.qprint_timen("Starting boot " + str(boot_count) + ".") pre_boot_plug_in_setup() cmd_buf = ["run_boot", next_boot] boot_status, msg = BuiltIn().run_keyword_and_ignore_error(*cmd_buf) if boot_status == "FAIL": gp.qprint(msg) gp.qprintn() if boot_status == "PASS": boot_success = 1 completion_msg = gp.sprint_timen("BOOT_SUCCESS: \"" + next_boot + "\" succeeded.") else: boot_success = 0 completion_msg = gp.sprint_timen("BOOT_FAILED: \"" + next_boot + "\" failed.") # Set boot_end_time for use by plug-ins. boot_end_time = completion_msg[1:33] gp.qprint_var(boot_end_time) gp.qprint(completion_msg) boot_results.update(next_boot, boot_status) plug_in_setup() # NOTE: A post_test_case call point failure is NOT counted as a boot # failure. rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( call_point='post_test_case', stop_on_plug_in_failure=0) plug_in_setup() rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( call_point='ffdc_check', shell_rc=0x00000200, stop_on_plug_in_failure=1, stop_on_non_zero_rc=1) if boot_status != "PASS" or ffdc_check == "All" or shell_rc == 0x00000200: status, ret_values = grk.run_key_u("my_ffdc", ignore=1) if status != 'PASS': gp.qprint_error("Call to my_ffdc failed.\n") if delete_errlogs: # We need to purge error logs between boots or they build up. grk.run_key("Delete Error logs", ignore=1) boot_results.print_report() gp.qprint_timen("Finished boot " + str(boot_count) + ".") plug_in_setup() rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( call_point='stop_check', shell_rc=0x00000200, stop_on_non_zero_rc=1) if shell_rc == 0x00000200: message = "Stopping as requested by user.\n" gp.print_time(message) BuiltIn().fail(message) # This should help prevent ConnectionErrors. grk.run_key_u("Close All Connections") return True