1*369b75c1SMichael Walsh#!/usr/bin/env python 2*369b75c1SMichael Walsh 3*369b75c1SMichael Walshfrom gen_print import * 4*369b75c1SMichael Walshfrom gen_valid import * 5*369b75c1SMichael Walshfrom gen_arg import * 6*369b75c1SMichael Walshfrom gen_misc import * 7*369b75c1SMichael Walshfrom gen_cmd import * 8*369b75c1SMichael Walshfrom var_funcs import * 9*369b75c1SMichael Walshfrom gen_plug_in_utils import * 10*369b75c1SMichael Walshfrom gen_call_robot import * 11*369b75c1SMichael Walsh 12*369b75c1SMichael Walsh# Set exit_on_error for gen_valid functions. 13*369b75c1SMichael Walshset_exit_on_error(True) 14*369b75c1SMichael Walshignore_err = 0 15*369b75c1SMichael Walsh 16*369b75c1SMichael Walsh 17*369b75c1SMichael Walshparser = argparse.ArgumentParser( 18*369b75c1SMichael Walsh usage='%(prog)s [OPTIONS]', 19*369b75c1SMichael Walsh description="%(prog)s will calculate the value of num_err_logs and" 20*369b75c1SMichael Walsh + " save it as a plug-in value for the benefit of the FFDC plug-in." 21*369b75c1SMichael Walsh + " The FFDC plug-in can use that data to decide whether to collect" 22*369b75c1SMichael Walsh + " FFDC data.", 23*369b75c1SMichael Walsh formatter_class=argparse.ArgumentDefaultsHelpFormatter, 24*369b75c1SMichael Walsh prefix_chars='-+') 25*369b75c1SMichael Walsh 26*369b75c1SMichael Walsh# The stock_list will be passed to gen_get_options. We populate it with the names of stock parm options we 27*369b75c1SMichael Walsh# want. These stock parms are pre-defined by gen_get_options. 28*369b75c1SMichael Walshstock_list = [("test_mode", 0), 29*369b75c1SMichael Walsh ("quiet", get_plug_default("quiet", 0)), 30*369b75c1SMichael Walsh ("debug", get_plug_default("debug", 0))] 31*369b75c1SMichael Walsh 32*369b75c1SMichael Walsh 33*369b75c1SMichael Walshdef exit_function(signal_number=0, 34*369b75c1SMichael Walsh frame=None): 35*369b75c1SMichael Walsh r""" 36*369b75c1SMichael Walsh Execute whenever the program ends normally or with the signals that we catch (i.e. TERM, INT). 37*369b75c1SMichael Walsh 38*369b75c1SMichael Walsh This function will be called by gen_exit_function(). 39*369b75c1SMichael Walsh """ 40*369b75c1SMichael Walsh 41*369b75c1SMichael Walsh process_robot_output_files() 42*369b75c1SMichael Walsh 43*369b75c1SMichael Walsh 44*369b75c1SMichael Walshdef validate_parms(): 45*369b75c1SMichael Walsh r""" 46*369b75c1SMichael Walsh Validate program parameters, etc. 47*369b75c1SMichael Walsh 48*369b75c1SMichael Walsh This function will be called by gen_setup(). 49*369b75c1SMichael Walsh """ 50*369b75c1SMichael Walsh 51*369b75c1SMichael Walsh get_plug_vars() 52*369b75c1SMichael Walsh 53*369b75c1SMichael Walsh global AUTOSCRIPT_STATUS_FILE_PATH 54*369b75c1SMichael Walsh # AUTOSCRIPT_STATUS_FILE_PATH is set when we're called by autoscript. For this program to work 55*369b75c1SMichael Walsh # correctly, it must be called with autoscript. 56*369b75c1SMichael Walsh AUTOSCRIPT_STATUS_FILE_PATH = os.environ.get("AUTOSCRIPT_STATUS_FILE_PATH", "") 57*369b75c1SMichael Walsh valid_value(AUTOSCRIPT_STATUS_FILE_PATH) 58*369b75c1SMichael Walsh valid_value(AUTOBOOT_OPENBMC_HOST) 59*369b75c1SMichael Walsh 60*369b75c1SMichael Walsh 61*369b75c1SMichael Walshdef main(): 62*369b75c1SMichael Walsh 63*369b75c1SMichael Walsh gen_setup() 64*369b75c1SMichael Walsh 65*369b75c1SMichael Walsh print_plug_in_header() 66*369b75c1SMichael Walsh 67*369b75c1SMichael Walsh # Get the number of error logs from the BMC. 68*369b75c1SMichael Walsh init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".") 69*369b75c1SMichael Walsh 70*369b75c1SMichael Walsh lib_file_path = init_robot_file_path("lib/logging_utils.robot") 71*369b75c1SMichael Walsh lib_file_path += ":" + init_robot_file_path("lib/gen_robot_print.py") 72*369b75c1SMichael Walsh set_mod_global(lib_file_path) 73*369b75c1SMichael Walsh 74*369b75c1SMichael Walsh keyword_string = "${error_logs}= Get Error Logs &{filter_low_severity_errlogs}" 75*369b75c1SMichael Walsh keyword_string += " ; ${num_error_logs}= Get Length ${error_logs}" 76*369b75c1SMichael Walsh keyword_string += " ; Rprint Vars num_error_logs" 77*369b75c1SMichael Walsh set_mod_global(keyword_string) 78*369b75c1SMichael Walsh 79*369b75c1SMichael Walsh cmd_buf = create_robot_cmd_string("extended/run_keyword.robot", OPENBMC_HOST, SSH_PORT, HTTPS_PORT, 80*369b75c1SMichael Walsh REST_USERNAME, REST_PASSWORD, keyword_string, lib_file_path, quiet, 81*369b75c1SMichael Walsh test_mode, debug, outputdir, output, log, report) 82*369b75c1SMichael Walsh if not robot_cmd_fnc(cmd_buf): 83*369b75c1SMichael Walsh exit(1) 84*369b75c1SMichael Walsh # The output contains the num_error_logs value which we will isolate with egrep. 85*369b75c1SMichael Walsh rc, out_buf = shell_cmd("egrep '^num_error_logs:[ ]' " + AUTOSCRIPT_STATUS_FILE_PATH, quiet=1, 86*369b75c1SMichael Walsh print_output=0) 87*369b75c1SMichael Walsh result = key_value_outbuf_to_dict(out_buf) 88*369b75c1SMichael Walsh num_error_logs = int(result['num_error_logs']) 89*369b75c1SMichael Walsh save_plug_in_value(num_error_logs) 90*369b75c1SMichael Walsh 91*369b75c1SMichael Walsh 92*369b75c1SMichael Walshmain() 93