def get_image_path(image_version): r""" Query the upload image dir for the presence of image matching the version that was read from the MANIFEST before uploading the image. Based on the purpose verify the activation object exists and is either READY or INVALID. Description of argument(s): image_version The version of the image that should match one of the images in the upload dir. """ keyword.run_key_u("Open Connection And Log In") status, image_list =\ keyword.run_key("Execute Command On BMC ls -d " + var.IMAGE_UPLOAD_DIR_PATH + "*/") image_list = image_list.split("\n") retry = 0 while (retry < 10): for i in range(0, len(image_list)): version = get_image_version(image_list[i] + "MANIFEST") if (version == image_version): return image_list[i] time.sleep(10) retry += 1
def verify_image_upload(): r""" Verify the image was uploaded correctly and that it created a valid d-bus object """ image_version = BuiltIn().get_variable_value("${image_version}") image_path = get_image_path(image_version) image_version_id = image_path.split("/")[-2] BuiltIn().set_global_variable("${version_id}", image_version_id) grk.run_key_u("Open Connection And Log In") image_purpose = get_image_purpose(image_path + "MANIFEST") if (image_purpose == var.VERSION_PURPOSE_BMC or image_purpose == var.VERSION_PURPOSE_HOST): uri = var.SOFTWARE_VERSION + image_version_id status, ret_values =\ grk.run_key("Read Attribute " + uri + " Activation") if ((ret_values == var.READY) or (ret_values == var.INVALID) or (ret_values == var.ACTIVE)): return True else: gp.print_var(ret_values) return False else: gp.print_var(image_purpose) return False
def get_image_purpose(file_path): r""" Read the file for a purpose object. Description of argument(s): file_path The path to a file that holds the image purpose. """ keyword.run_key_u("Open Connection And Log In") status, ret_values =\ keyword.run_key("Execute Command On BMC cat " + file_path + " | grep \"purpose=\"", ignore=1) return ret_values.split("=")[-1]
def get_image_version(file_path): r""" Read the file for a version object. Description of argument(s): file_path The path to a file that holds the image version. """ grk.run_key_u("Open Connection And Log In") status, ret_values =\ grk.run_key("Execute Command On BMC cat " + file_path + " | grep \"version=\"", ignore=1) return (ret_values.split("\n")[0]).split("=")[-1]
def get_latest_file(dir_path): r""" Get the path to the latest uploaded file. Description of argument(s): dir_path Path to the dir from which the name of the last updated file or folder will be returned to the calling function. """ keyword.run_key_u("Open Connection And Log In") status, ret_values =\ keyword.run_key("Execute Command On BMC cd " + dir_path + "; stat -c '%Y %n' * | sort -k1,1nr | head -n 1", ignore=1) return ret_values.split(" ")[-1]
def translate_power_policy_value(policy): r""" Translate the policy value and return the result. Using old style functions, callers might call like this with a hard- code value for policy: Set BMC Power Policy RESTORE_LAST_STATE This function will get the value of the corresponding global variable (if it exists) and return it. This will allow the old style call to still work on systems using the new method of storing the policy value. """ valid_power_policy_vars = \ BuiltIn().get_variable_value("${valid_power_policy_vars}") if policy not in valid_power_policy_vars: return policy status, ret_values = grk.run_key_u("Get Variable Value ${" + policy + "}", quiet=1) return ret_values
def my_ffdc(): r""" Collect FFDC data. """ global state plug_in_setup() rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( call_point='ffdc', stop_on_plug_in_failure=0) AUTOBOOT_FFDC_PREFIX = os.environ['AUTOBOOT_FFDC_PREFIX'] status, ffdc_file_list = grk.run_key_u( "FFDC ffdc_prefix=" + AUTOBOOT_FFDC_PREFIX + " ffdc_function_list=" + ffdc_function_list, ignore=1) if status != 'PASS': gp.qprint_error("Call to ffdc failed.\n") if type(ffdc_file_list) is not list: ffdc_file_list = [] # Leave a record for caller that "soft" errors occurred. soft_errors = 1 gpu.save_plug_in_value(soft_errors, pgm_name) my_get_state() print_defect_report(ffdc_file_list)
def translate_power_policy_value(policy): r""" Translate the policy value and return the result. Using old style functions, callers might call like this with a hard- code value for policy: Set BMC Power Policy ALWAYS_POWER_OFF This function will get the value of the corresponding global variable (if it exists) and return it. This will allow the old style call to still work on systems using the new method of storing the policy value. """ valid_power_policy_vars = \ BuiltIn().get_variable_value("${valid_power_policy_vars}") if policy not in valid_power_policy_vars: return policy status, ret_values = grk.run_key_u("Get Variable Value ${" + policy + "}", quiet=1) return ret_values
def get_channel_info(channel_number=1): r""" Get the channel info and return as a dictionary. Example: channel_info: [channel_0x2_info]: [channel_medium_type]: 802.3 LAN [channel_protocol_type]: IPMB-1.0 [session_support]: multi-session [active_session_count]: 0 [protocol_vendor_id]: 7154 [volatile(active)_settings]: [alerting]: enabled [per-message_auth]: enabled [user_level_auth]: enabled [access_mode]: always available [non-volatile_settings]: [alerting]: enabled [per-message_auth]: enabled [user_level_auth]: enabled [access_mode]: always available """ status, ret_values = \ grk.run_key_u("Run IPMI Standard Command channel info " + str(channel_number)) key_var_list = list(filter(None, ret_values.split("\n"))) # To match the dict format, add a colon after 'Volatile(active) Settings' and 'Non-Volatile Settings' # respectively. key_var_list[6] = 'Volatile(active) Settings:' key_var_list[11] = 'Non-Volatile Settings:' result = vf.key_value_list_to_dict(key_var_list, process_indent=1) return result
def validate_parms(): r""" Validate all program parameters. """ process_pgm_parms() gp.qprintn() global openbmc_model grv.rvalid_value("openbmc_host") grv.rvalid_value("openbmc_username") grv.rvalid_value("openbmc_password") if os_host != "": grv.rvalid_value("os_username") grv.rvalid_value("os_password") if pdu_host != "": grv.rvalid_value("pdu_username") grv.rvalid_value("pdu_password") grv.rvalid_integer("pdu_slot_no") if openbmc_serial_host != "": grv.rvalid_integer("openbmc_serial_port") if openbmc_model == "": status, ret_values =\ grk.run_key_u("Get BMC System Model") openbmc_model = ret_values BuiltIn().set_global_variable("${openbmc_model}", openbmc_model) grv.rvalid_value("openbmc_model") grv.rvalid_integer("max_num_tests") grv.rvalid_integer("boot_pass") grv.rvalid_integer("boot_fail") plug_in_packages_list = grpi.rvalidate_plug_ins(plug_in_dir_paths) BuiltIn().set_global_variable("${plug_in_packages_list}", plug_in_packages_list) grv.rvalid_value("stack_mode", valid_values=['normal', 'skip']) if len(boot_list) == 0 and len(boot_stack) == 0 and not ffdc_only: error_message = "You must provide either a value for either the" +\ " boot_list or the boot_stack parm.\n" BuiltIn().fail(gp.sprint_error(error_message)) valid_boot_list(boot_list, valid_boot_types) valid_boot_list(boot_stack, valid_boot_types) selected_PDU_boots = list(set(boot_list + boot_stack) & set(boot_lists['PDU_reboot'])) if len(selected_PDU_boots) > 0 and pdu_host == "": error_message = "You have selected the following boots which" +\ " require a PDU host but no value for pdu_host:\n" error_message += gp.sprint_var(selected_PDU_boots) error_message += gp.sprint_var(pdu_host, 2) BuiltIn().fail(gp.sprint_error(error_message)) return
def validate_parms(): r""" Validate all program parameters. """ process_pgm_parms() gp.qprintn() global openbmc_model grv.rvalid_value("openbmc_host") grv.rvalid_value("openbmc_username") grv.rvalid_value("openbmc_password") if os_host != "": grv.rvalid_value("os_username") grv.rvalid_value("os_password") if pdu_host != "": grv.rvalid_value("pdu_username") grv.rvalid_value("pdu_password") grv.rvalid_integer("pdu_slot_no") if openbmc_serial_host != "": grv.rvalid_integer("openbmc_serial_port") if openbmc_model == "": status, ret_values =\ grk.run_key_u("Get BMC System Model") openbmc_model = ret_values BuiltIn().set_global_variable("${openbmc_model}", openbmc_model) grv.rvalid_value("openbmc_model") grv.rvalid_integer("max_num_tests") grv.rvalid_integer("boot_pass") grv.rvalid_integer("boot_fail") plug_in_packages_list = grpi.rvalidate_plug_ins(plug_in_dir_paths) BuiltIn().set_global_variable("${plug_in_packages_list}", plug_in_packages_list) grv.rvalid_value("stack_mode", valid_values=['normal', 'skip']) if len(boot_list) == 0 and len(boot_stack) == 0 and not ffdc_only: error_message = "You must provide either a value for either the" +\ " boot_list or the boot_stack parm.\n" BuiltIn().fail(gp.sprint_error(error_message)) valid_boot_list(boot_list, valid_boot_types) valid_boot_list(boot_stack, valid_boot_types) selected_PDU_boots = list( set(boot_list + boot_stack) & set(boot_lists['PDU_reboot'])) if len(selected_PDU_boots) > 0 and pdu_host == "": error_message = "You have selected the following boots which" +\ " require a PDU host but no value for pdu_host:\n" error_message += gp.sprint_var(selected_PDU_boots) error_message += gp.sprint_var(pdu_host, 2) BuiltIn().fail(gp.sprint_error(error_message)) return
def get_fru_info(): r""" Get fru info and return it as a list of dictionaries. The data is obtained by issuing the IPMI "fru print -N 50" command. An example is shown below: FRU Device Description : Builtin FRU Device (ID 0) Device not present (Unspecified error) FRU Device Description : cpu0 (ID 1) Board Mfg Date : Sun Dec 31 18:00:00 1995 Board Mfg : <Manufacturer Name> Board Product : PROCESSOR MODULE Board Serial : YA1934315964 Board Part Number : 02CY209 FRU Device Description : cpu1 (ID 2) Board Mfg Date : Sun Dec 31 18:00:00 1995 Board Mfg : <Manufacturer Name> Board Product : PROCESSOR MODULE Board Serial : YA1934315965 Board Part Number : 02CY209 For the data shown above, the following list of dictionaries will be returned. fru_obj: fru_obj[0]: [fru_device_description]: Builtin FRU Device (ID 0) [state]: Device not present (Unspecified error) fru_obj[1]: [fru_device_description]: cpu0 (ID 1) [board_mfg_date]: Sun Dec 31 18:00:00 1995 [board_mfg]: <Manufacturer Name> [board_product]: PROCESSOR MODULE [board_serial]: YA1934315964 [board_part_number]: 02CY209 fru_obj[2]: [fru_device_description]: cpu1 (ID 2) [board_mfg_date]: Sun Dec 31 18:00:00 1995 [board_mfg]: <Manufacturer Name> [board_product]: PROCESSOR MODULE [board_serial]: YA1934315965 [board_part_number]: 02CY209 """ status, ret_values = \ grk.run_key_u("Run IPMI Standard Command fru print -N 50") # Manipulate the "Device not present" line to create a "state" key. ret_values = re.sub("Device not present", "state : Device not present", ret_values) return [ vf.key_value_outbuf_to_dict(x) for x in re.split("\n\n", ret_values) ]
def get_mc_info(): r""" Get IPMI mc info data and return it as a dictionary. The data is obtained by issuing the IPMI "mc info" command. An example is shown below: Device ID : 0 Device Revision : 0 Firmware Revision : 2.01 IPMI Version : 2.0 Manufacturer ID : 42817 Manufacturer Name : Unknown (0xA741) Product ID : 16975 (0x424f) Product Name : Unknown (0x424F) Device Available : yes Provides Device SDRs : yes Additional Device Support : Sensor Device SEL Device FRU Inventory Device Chassis Device Aux Firmware Rev Info : 0x00 0x00 0x00 0x00 For the data shown above, the following dictionary will be returned. mc_info: [device_id]: 0 [device_revision]: 0 [firmware_revision]: 2.01 [ipmi_version]: 2.0 [manufacturer_id]: 42817 [manufacturer_name]: Unknown (0xA741) [product_id]: 16975 (0x424f) [product_name]: Unknown (0x424F) [device_available]: yes [provides_device_sdrs]: yes [additional_device_support]: [additional_device_support][0]: Sensor Device [additional_device_support][1]: SEL Device [additional_device_support][2]: FRU Inventory Device [additional_device_support][3]: Chassis Device [aux_firmware_rev_info]: [aux_firmware_rev_info][0]: 0x00 [aux_firmware_rev_info][1]: 0x00 [aux_firmware_rev_info][2]: 0x00 [aux_firmware_rev_info][3]: 0x00 """ status, ret_values = \ grk.run_key_u("Run IPMI Standard Command mc info") result = vf.key_value_outbuf_to_dict(ret_values, process_indent=1) return result
def get_chassis_status(): r""" Get IPMI chassis status data and return it as a dictionary. The data is obtained by issuing the IPMI "chassis status" command. An example is shown below: System Power : off Power Overload : false Power Interlock : inactive Main Power Fault : false Power Control Fault : false Power Restore Policy : previous Last Power Event : Chassis Intrusion : inactive Front-Panel Lockout : inactive Drive Fault : false Cooling/Fan Fault : false Sleep Button Disable : not allowed Diag Button Disable : not allowed Reset Button Disable : not allowed Power Button Disable : allowed Sleep Button Disabled : false Diag Button Disabled : false Reset Button Disabled : false Power Button Disabled : false For the data shown above, the following dictionary will be returned. chassis_status: [system_power]: off [power_overload]: false [power_interlock]: inactive [main_power_fault]: false [power_control_fault]: false [power_restore_policy]: previous [last_power_event]: [chassis_intrusion]: inactive [front-panel_lockout]: inactive [drive_fault]: false [cooling/fan_fault]: false [sleep_button_disable]: not allowed [diag_button_disable]: not allowed [reset_button_disable]: not allowed [power_button_disable]: allowed [sleep_button_disabled]: false [diag_button_disabled]: false [reset_button_disabled]: false [power_button_disabled]: false """ status, ret_values = \ grk.run_key_u("Run IPMI Standard Command chassis status") result = vf.key_value_outbuf_to_dict(ret_values, process_indent=1) return result
def set_power_policy_method(): r""" Set the global bmc_power_policy_method to either 'Old' or 'New'. The power policy data has moved from an 'org' location to an 'xyz' location. This keyword will determine whether the new method of getting the power policy is valid and will set the global bmc_power_policy_method variable accordingly. If power_policy_setup is already set (by a prior call to this function), this keyword will simply return. If bmc_power_policy_method is "Old", this function will adjust the global policy variables from data/variables.py: RESTORE_LAST_STATE, ALWAYS_POWER_ON, ALWAYS_POWER_OFF. """ # Retrieve global variables. power_policy_setup = \ int(BuiltIn().get_variable_value("${power_policy_setup}", default=0)) bmc_power_policy_method = \ BuiltIn().get_variable_value("${bmc_power_policy_method}", default=0) gp.dpvar(power_policy_setup) # If this function has already been run once, we need not continue. if power_policy_setup: return gp.dpvar(bmc_power_policy_method, 1) # The user has not set bmc_power_policy_method via a -v parm so we will # determine what it should be. if bmc_power_policy_method == "": status, ret_values = grk.run_key_u("New Get Power Policy", ignore=1) if status == 'PASS': bmc_power_policy_method = 'New' else: bmc_power_policy_method = 'Old' gp.qpvar(bmc_power_policy_method) # For old style, we will rewrite these global variable settings to old # values. if bmc_power_policy_method == "Old": BuiltIn().set_global_variable("${RESTORE_LAST_STATE}", "RESTORE_LAST_STATE") BuiltIn().set_global_variable("${ALWAYS_POWER_ON}", "ALWAYS_POWER_ON") BuiltIn().set_global_variable("${ALWAYS_POWER_OFF}", "ALWAYS_POWER_OFF") # Set global variables to control subsequent calls to this function. BuiltIn().set_global_variable("${bmc_power_policy_method}", bmc_power_policy_method) BuiltIn().set_global_variable("${power_policy_setup}", 1)
def verify_image_upload(image_version, timeout=3): r""" Verify the image was uploaded correctly and that it created a valid d-bus object. If the first check for the image fails, try again until we reach the timeout. Description of argument(s): image_version The version from the image's manifest file (e.g. "IBM-witherspoon-redbud-ibm-OP9_v1.17_1.68"). timeout How long, in minutes, to keep trying to find the image on the BMC. Default is 3 minutes. """ image_path = get_image_path(image_version) image_version_id = image_path.split("/")[-2] keyword.run_key_u("Open Connection And Log In") image_purpose = get_image_purpose(image_path + "MANIFEST") if (image_purpose == var.VERSION_PURPOSE_BMC or image_purpose == var.VERSION_PURPOSE_HOST): uri = var.SOFTWARE_VERSION_URI + image_version_id ret_values = "" for itr in range(timeout * 2): status, ret_values = \ keyword.run_key("Read Attribute " + uri + " Activation") if ((ret_values == var.READY) or (ret_values == var.INVALID) or (ret_values == var.ACTIVE)): return True, image_version_id else: time.sleep(30) # If we exit the for loop, the timeout has been reached gp.print_var(ret_values) return False, None else: gp.print_var(image_purpose) return False, None
def verify_image_upload(image_version, timeout=3): r""" Verify the image was uploaded correctly and that it created a valid d-bus object. If the first check for the image fails, try again until we reach the timeout. Description of argument(s): image_version The version from the image's manifest file (e.g. "v2.2-253-g00050f1"). timeout How long, in minutes, to keep trying to find the image on the BMC. Default is 3 minutes. """ image_path = get_image_path(image_version) image_version_id = image_path.split("/")[-2] keyword.run_key_u("Open Connection And Log In") image_purpose = get_image_purpose(image_path + "MANIFEST") if (image_purpose == var.VERSION_PURPOSE_BMC or image_purpose == var.VERSION_PURPOSE_HOST): uri = var.SOFTWARE_VERSION_URI + image_version_id ret_values = "" for itr in range(timeout * 2): status, ret_values = \ keyword.run_key("Read Attribute " + uri + " Activation") if ((ret_values == var.READY) or (ret_values == var.INVALID) or (ret_values == var.ACTIVE)): return True, image_version_id else: time.sleep(30) # If we exit the for loop, the timeout has been reached gp.print_var(ret_values) return False, None else: gp.print_var(image_purpose) return False, None
def set_sol_setting(setting_name, setting_value): r""" Set SOL setting with given value. # Description of argument(s): # setting_name SOL setting which needs to be set (e.g. "retry-count"). # setting_value Value which needs to be set (e.g. "7"). """ status, ret_values = grk.run_key_u("Run IPMI Standard Command sol set " + setting_name + " " + setting_value) return status
def wait_for_activation_state_change(version_id, initial_state): r""" Wait for the current activation state of ${version_id} to change from the state provided by the calling function. Description of argument(s): version_id The version ID whose state change we are waiting for. initial_state The activation state we want to wait for. """ keyword.run_key_u("Open Connection And Log In") retry = 0 num_read_errors = 0 read_fail_threshold = 1 while (retry < 30): # TODO: Use retry option in run_key when available. status, software_state = keyword.run_key("Read Properties " + var.SOFTWARE_VERSION_URI + str(version_id), ignore=1) if status == 'FAIL': num_read_errors += 1 if num_read_errors > read_fail_threshold: message = "Read errors exceeds threshold:\n " \ + gp.sprint_vars(num_read_errors, read_fail_threshold) BuiltIn().fail(message) time.sleep(10) continue current_state = (software_state)["Activation"] if (initial_state == current_state): time.sleep(10) retry += 1 num_read_errors = 0 else: return return
def wait_for_activation_state_change(version_id, initial_state): r""" Wait for the current activation state of ${version_id} to change from the state provided by the calling function. Description of argument(s): version_id The version ID whose state change we are waiting for. initial_state The activation state we want to wait for. """ keyword.run_key_u("Open Connection And Log In") retry = 0 num_read_errors = 0 read_fail_threshold = 1 while (retry < 60): # TODO: Use retry option in run_key when available. status, software_state = keyword.run_key("Read Properties " + var.SOFTWARE_VERSION_URI + str(version_id), ignore=1) if status == 'FAIL': num_read_errors += 1 if num_read_errors > read_fail_threshold: message = "Read errors exceeds threshold:\n " \ + gp.sprint_vars(num_read_errors, read_fail_threshold) BuiltIn().fail(message) time.sleep(10) continue current_state = (software_state)["Activation"] if (initial_state == current_state): time.sleep(10) retry += 1 num_read_errors = 0 else: return return
def wait_for_activation_state_change(version_id, initial_state): r""" Wait for the current activation state of ${version_id} to change from the state provided by the calling function. Description of argument(s): version_id The version ID whose state change we are waiting for. initial_state The activation state we want to wait for. """ keyword.run_key_u("Open Connection And Log In") retry = 0 while (retry < 20): status, software_state = keyword.run_key("Read Properties " + var.SOFTWARE_VERSION_URI + str(version_id)) current_state = (software_state)["Activation"] if (initial_state == current_state): time.sleep(60) retry += 1 else: return return
def obmc_boot_test_py(alt_boot_stack=None): r""" Do main program processing. """ if alt_boot_stack is not None: BuiltIn().set_global_variable("${boot_stack}", alt_boot_stack) setup() if ffdc_only: gp.qprint_timen("Caller requested ffdc_only.") pre_boot_plug_in_setup() grk.run_key_u("my_ffdc") return # Process caller's boot_stack. while (len(boot_stack) > 0): test_loop_body() gp.qprint_timen("Finished processing stack.") # Process caller's boot_list. if len(boot_list) > 0: for ix in range(1, max_num_tests + 1): test_loop_body() gp.qprint_timen("Completed all requested boot tests.") boot_pass, boot_fail = boot_results.return_total_pass_fail() if boot_fail > boot_fail_threshold: error_message = "Boot failures exceed the boot failure" +\ " threshold:\n" +\ gp.sprint_var(boot_fail) +\ gp.sprint_var(boot_fail_threshold) BuiltIn().fail(gp.sprint_error(error_message))
def post_stack(): r""" Process post_stack plug-in programs. """ if not call_post_stack_plug: # The caller does not wish to have post_stack plug-in processing done. return global boot_success # NOTE: A post_stack call-point failure is NOT counted as a boot failure. pre_boot_plug_in_setup() # For the purposes of the following plug-ins, mark the "boot" as a success. boot_success = 1 plug_in_setup() rc, shell_rc, failed_plug_in_name, history =\ grpi.rprocess_plug_in_packages(call_point='post_stack', stop_on_plug_in_failure=0, return_history=True) last_ten.extend(history) # Trim list to max number of entries. del last_ten[:max(0, len(last_ten) - max_boot_history)] if rc != 0: boot_success = 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 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) 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.print_time(message) BuiltIn().fail(message)
def get_user_info(userid, channel_number=1): r""" Get user info using channel command and return it as a dictionary. Description of argument(s): userid The userid (e.g. "1", "2", etc.). channel_number The user's channel number (e.g. "1"). Note: If userid is blank, this function will return a list of dictionaries. Each list entry represents one userid record. The data is obtained by issuing the IPMI "channel getaccess" command. An example is shown below for user id 1 and channel number 1. Maximum User IDs : 15 Enabled User IDs : 1 User ID : 1 User Name : root Fixed Name : No Access Available : callback Link Authentication : enabled IPMI Messaging : enabled Privilege Level : ADMINISTRATOR Enable Status : enabled For the data shown above, the following dictionary will be returned. user_info: [maximum_userids]: 15 [enabled_userids: 1 [userid] 1 [user_name] root [fixed_name] No [access_available] callback [link_authentication] enabled [ipmi_messaging] enabled [privilege_level] ADMINISTRATOR [enable_status] enabled """ status, ret_values = grk.run_key_u( "Run IPMI Standard Command channel getaccess " + str(channel_number) + " " + str(userid)) if userid == "": return vf.key_value_outbuf_to_dicts(ret_values, process_indent=1) else: return vf.key_value_outbuf_to_dict(ret_values, process_indent=1)
def get_sol_info(): r""" Get all SOL info and return it as a dictionary. Example use: Robot code: ${sol_info}= get_sol_info Rpvars sol_info Output: sol_info: sol_info[Info]: SOL parameter 'Payload Channel (7)' not supported - defaulting to 0x0e sol_info[Character Send Threshold]: 1 sol_info[Force Authentication]: true sol_info[Privilege Level]: USER sol_info[Set in progress]: set-complete sol_info[Retry Interval (ms)]: 100 sol_info[Non-Volatile Bit Rate (kbps)]: IPMI-Over-Serial-Setting sol_info[Character Accumulate Level (ms)]: 100 sol_info[Enabled]: true sol_info[Volatile Bit Rate (kbps)]: IPMI-Over-Serial-Setting sol_info[Payload Channel]: 14 (0x0e) sol_info[Payload Port]: 623 sol_info[Force Encryption]: true sol_info[Retry Count]: 7 """ status, ret_values = grk.run_key_u("Run IPMI Standard Command sol info") # Create temp file path. temp = tempfile.NamedTemporaryFile() temp_file_path = temp.name # Write sol info to temp file path. text_file = open(temp_file_path, "w") text_file.write(ret_values) text_file.close() # Use my_parm_file to interpret data. sol_info = gm.my_parm_file(temp_file_path) return sol_info
def get_sdr_info(): r""" Get IPMI sdr info data and return it as a dictionary. The data is obtained by issuing the IPMI "sdr info" command. An example is shown below: SDR Version : 0x51 Record Count : 216 Free Space : unspecified Most recent Addition : Most recent Erase : SDR overflow : no SDR Repository Update Support : unspecified Delete SDR supported : no Partial Add SDR supported : no Reserve SDR repository supported : no SDR Repository Alloc info supported : no For the data shown above, the following dictionary will be returned. mc_info: [sdr_version]: 0x51 [record_Count]: 216 [free_space]: unspecified [most_recent_addition]: [most_recent_erase]: [sdr_overflow]: no [sdr_repository_update_support]: unspecified [delete_sdr_supported]: no [partial_add_sdr_supported]: no [reserve_sdr_repository_supported]: no [sdr_repository_alloc_info_supported]: no """ status, ret_values = \ grk.run_key_u("Run IPMI Standard Command sdr info") result = vf.key_value_outbuf_to_dict(ret_values, process_indent=1) return result
def my_ffdc(): r""" Collect FFDC data. """ global state plug_in_setup() rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( call_point='ffdc', stop_on_plug_in_failure=0) AUTOBOOT_FFDC_PREFIX = os.environ['AUTOBOOT_FFDC_PREFIX'] status, ret_values = grk.run_key_u( "FFDC ffdc_prefix=" + AUTOBOOT_FFDC_PREFIX + " ffdc_function_list=" + ffdc_function_list, ignore=1) if status != 'PASS': gp.qprint_error("Call to ffdc failed.\n") my_get_state() print_defect_report()
def get_ipmi_power_reading(strip_watts=1): r""" Get IPMI power reading data and return it as a dictionary. The data is obtained by issuing the IPMI "power reading" command. An example is shown below: Instantaneous power reading: 234 Watts Minimum during sampling period: 234 Watts Maximum during sampling period: 234 Watts Average power reading over sample period: 234 Watts IPMI timestamp: Thu Jan 1 00:00:00 1970 Sampling period: 00000000 Seconds. Power reading state is: deactivated For the data shown above, the following dictionary will be returned. result: [instantaneous_power_reading]: 238 Watts [minimum_during_sampling_period]: 238 Watts [maximum_during_sampling_period]: 238 Watts [average_power_reading_over_sample_period]: 238 Watts [ipmi_timestamp]: Thu Jan 1 00:00:00 1970 [sampling_period]: 00000000 Seconds. [power_reading_state_is]: deactivated Description of argument(s): strip_watts Strip all dictionary values of the trailing " Watts" substring. """ status, ret_values = \ grk.run_key_u("Run IPMI Standard Command dcmi power reading") result = vf.key_value_outbuf_to_dict(ret_values) if strip_watts: result.update((k, re.sub(' Watts$', '', v)) for k, v in result.items()) return result
def my_ffdc(): r""" Collect FFDC data. """ global state plug_in_setup() rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( call_point='ffdc', stop_on_plug_in_failure=0) AUTOBOOT_FFDC_PREFIX = os.environ['AUTOBOOT_FFDC_PREFIX'] status, ffdc_file_list = grk.run_key_u("FFDC ffdc_prefix=" + AUTOBOOT_FFDC_PREFIX + " ffdc_function_list=" + ffdc_function_list, ignore=1) if status != 'PASS': gp.qprint_error("Call to ffdc failed.\n") my_get_state() print_defect_report(ffdc_file_list)
def get_channel_auth_capabilities(channel_number=1): r""" Get the channel authentication capabilities and return as a dictionary. Example: channel_auth_cap: [channel_number]: 2 [ipmi_v1.5__auth_types]: [kg_status]: default (all zeroes) [per_message_authentication]: enabled [user_level_authentication]: enabled [non-null_user_names_exist]: yes [null_user_names_exist]: no [anonymous_login_enabled]: no [channel_supports_ipmi_v1.5]: no [channel_supports_ipmi_v2.0]: yes """ status, ret_values = \ grk.run_key_u("Run IPMI Standard Command channel authcap " + str(channel_number) + " 4") result = vf.key_value_outbuf_to_dict(ret_values, process_indent=1) return result
def ffdc(ffdc_dir_path=None, ffdc_prefix=None, ffdc_function_list=""): r""" Gather First Failure Data Capture (FFDC). This includes: - Set global FFDC_TIME. - Create FFDC work space directory. - Write test info details. - Call BMC methods to write/collect FFDC data. Description of arguments: ffdc_dir_path The dir path where FFDC data should be put. ffdc_prefix The prefix to be given to each FFDC file name generated. ffdc_function_list A colon-delimited list of all the types of FFDC data you wish to have collected. A blank value means that all possible kinds of FFDC are to be collected. See FFDC_METHOD_CALL object in lib/openbmc_ffdc_list.py for possible choices. """ ffdc_file_list = [] # Check if Ping and SSH connection is alive OPENBMC_HOST = BuiltIn().get_variable_value("${OPENBMC_HOST}") state = st.get_state(req_states=['ping', 'uptime', 'rest']) gp.qprint_var(state) if not int(state['ping']): gp.print_error("BMC is not ping-able. Terminating FFDC collection.\n") return ffdc_file_list if not int(state['rest']): gp.print_error("REST commands to the BMC are failing." + " Terminating FFDC collection.\n") return ffdc_file_list if state['uptime'] == "": gp.print_error("BMC is not communicating via ssh. Terminating FFDC" + " collection.\n") return ffdc_file_list gp.qprint_timen("Collecting FFDC.") # Get default values for arguments. ffdc_dir_path, ffdc_prefix = set_ffdc_defaults(ffdc_dir_path, ffdc_prefix) gp.qprint_var(ffdc_dir_path) gp.qprint_var(ffdc_prefix) # LOG_PREFIX is used by subordinate functions. LOG_PREFIX = ffdc_dir_path + ffdc_prefix BuiltIn().set_global_variable("${LOG_PREFIX}", LOG_PREFIX) cmd_buf = ["Create Directory", ffdc_dir_path] gp.qprint_issuing(cmd_buf) status, output = BuiltIn().run_keyword_and_ignore_error(*cmd_buf) if status != "PASS": error_message = gp.sprint_error_report("Create Directory failed" + " with the following" + " error:\n" + output) BuiltIn().fail(error_message) # FFDC_FILE_PATH is used by Header Message. FFDC_FILE_PATH = ffdc_dir_path + ffdc_prefix + "BMC_general.txt" BuiltIn().set_global_variable("${FFDC_FILE_PATH}", FFDC_FILE_PATH) status, ffdc_file_list = grk.run_key_u("Header Message") status, ffdc_file_sub_list = \ grk.run_key_u("Call FFDC Methods ffdc_function_list=" + ffdc_function_list) # Combine lists, remove duplicates and sort. ffdc_file_list = sorted(set(ffdc_file_list + ffdc_file_sub_list)) gp.qprint_timen("Finished collecting FFDC.") return ffdc_file_list
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 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 gp.qprint_timen("BOOT_SUCCESS: \"" + next_boot + "\" succeeded.") else: boot_success = 0 gp.qprint_timen("BOOT_FAILED: \"" + next_boot + "\" failed.") 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.print_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 ffdc(ffdc_dir_path=None, ffdc_prefix=None, ffdc_function_list=""): r""" Gather First Failure Data Capture (FFDC). This includes: - Set global FFDC_TIME. - Create FFDC work space directory. - Write test info details. - Call BMC methods to write/collect FFDC data. Description of arguments: ffdc_dir_path The dir path where FFDC data should be put. ffdc_prefix The prefix to be given to each FFDC file name generated. ffdc_function_list A colon-delimited list of all the types of FFDC data you wish to have collected. A blank value means that all possible kinds of FFDC are to be collected. See FFDC_METHOD_CALL object in lib/openbmc_ffdc_list.py for possible choices. """ ffdc_file_list = [] # Check if Ping and SSH connection is alive OPENBMC_HOST = BuiltIn().get_variable_value("${OPENBMC_HOST}") state = st.get_state(req_states=['ping', 'uptime']) gp.qprint_var(state) if not int(state['ping']): gp.print_error("BMC is not ping-able. Terminating FFDC collection.\n") return ffdc_file_list if state['uptime'] == "": gp.print_error("BMC is not communicating. Terminating FFDC" + " collection.\n") return ffdc_file_list gp.qprint_timen("Collecting FFDC.") # Get default values for arguments. ffdc_dir_path, ffdc_prefix = set_ffdc_defaults(ffdc_dir_path, ffdc_prefix) gp.qprint_var(ffdc_dir_path) gp.qprint_var(ffdc_prefix) # LOG_PREFIX is used by subordinate functions. LOG_PREFIX = ffdc_dir_path + ffdc_prefix BuiltIn().set_global_variable("${LOG_PREFIX}", LOG_PREFIX) cmd_buf = ["Create Directory", ffdc_dir_path] grp.rqpissuing_keyword(cmd_buf) status, output = BuiltIn().run_keyword_and_ignore_error(*cmd_buf) if status != "PASS": error_message = grp.sprint_error_report("Create Directory failed" + " with the following" + " error:\n" + output) BuiltIn().fail(error_message) # FFDC_FILE_PATH is used by Header Message. FFDC_FILE_PATH = ffdc_dir_path + ffdc_prefix + "BMC_general.txt" BuiltIn().set_global_variable("${FFDC_FILE_PATH}", FFDC_FILE_PATH) status, ffdc_file_list = grk.run_key("Header Message") status, ffdc_file_sub_list = \ grk.run_key_u("Call FFDC Methods ffdc_function_list=" + ffdc_function_list) # Combine lists, remove duplicates and sort. ffdc_file_list = sorted(set(ffdc_file_list + ffdc_file_sub_list)) gp.qprint_timen("Finished collecting FFDC.") return ffdc_file_list
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 setup(): r""" Do general program setup tasks. """ global cp_setup_called global transitional_boot_selected gp.qprintn() if redfish_supported: redfish.login() set_default_siguser1() transitional_boot_selected = False robot_pgm_dir_path = os.path.dirname(__file__) + os.sep repo_bin_path = robot_pgm_dir_path.replace("/lib/", "/bin/") # If we can't find process_plug_in_packages.py, ssh_pw or # validate_plug_ins.py, then we don't have our repo bin in PATH. shell_rc, out_buf = gc.cmd_fnc_u("which process_plug_in_packages.py" + " ssh_pw validate_plug_ins.py", quiet=1, print_output=0, show_err=0) if shell_rc != 0: os.environ['PATH'] = repo_bin_path + ":" + os.environ.get('PATH', "") # Likewise, our repo lib subdir needs to be in sys.path and PYTHONPATH. if robot_pgm_dir_path not in sys.path: sys.path.append(robot_pgm_dir_path) PYTHONPATH = os.environ.get("PYTHONPATH", "") if PYTHONPATH == "": os.environ['PYTHONPATH'] = robot_pgm_dir_path else: os.environ['PYTHONPATH'] = robot_pgm_dir_path + ":" + PYTHONPATH validate_parms() gp.qprint_pgm_header() grk.run_key_u(default_set_power_policy) initial_plug_in_setup() plug_in_setup() rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages( call_point='setup') if rc != 0: error_message = "Plug-in setup failed.\n" gp.print_error_report(error_message) BuiltIn().fail(error_message) # Setting cp_setup_called lets our Teardown know that it needs to call # the cleanup plug-in call point. cp_setup_called = 1 # Keyword "FFDC" will fail if TEST_MESSAGE is not set. BuiltIn().set_global_variable("${TEST_MESSAGE}", "${EMPTY}") # FFDC_LOG_PATH is used by "FFDC" keyword. BuiltIn().set_global_variable("${FFDC_LOG_PATH}", ffdc_dir_path) # Also printed by FFDC. global host_name global host_ip host = socket.gethostname() host_name, host_ip = gm.get_host_name_ip(host) gp.dprint_var(boot_table) gp.dprint_var(boot_lists)
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 obmc_boot_test_py(loc_boot_stack=None, loc_stack_mode=None, loc_quiet=None): r""" Do main program processing. """ global save_stack # Process function parms. for parm_name in main_func_parm_list: # Get parm's value. cmd_buf = "parm_value = loc_" + parm_name exec(cmd_buf) gp.dpvar(parm_name) gp.dpvar(parm_value) if parm_value is None: # Parm was not specified by the calling function so set it to its # corresponding global value. cmd_buf = "loc_" + parm_name + " = BuiltIn().get_variable_value" +\ "(\"${" + parm_name + "}\")" gp.dpissuing(cmd_buf) exec(cmd_buf) else: # Save the global value on a stack. cmd_buf = "save_stack.push(BuiltIn().get_variable_value(\"${" +\ parm_name + "}\"), \"" + parm_name + "\")" gp.dpissuing(cmd_buf) exec(cmd_buf) # Set the global value to the passed value. cmd_buf = "BuiltIn().set_global_variable(\"${" + parm_name +\ "}\", loc_" + parm_name + ")" gp.dpissuing(cmd_buf) exec(cmd_buf) gp.dprintn(save_stack.sprint_obj()) setup() if ffdc_only: gp.qprint_timen("Caller requested ffdc_only.") pre_boot_plug_in_setup() grk.run_key_u("my_ffdc") return # Process caller's boot_stack. while (len(boot_stack) > 0): test_loop_body() gp.qprint_timen("Finished processing stack.") # Process caller's boot_list. if len(boot_list) > 0: for ix in range(1, max_num_tests + 1): test_loop_body() gp.qprint_timen("Completed all requested boot tests.") boot_pass, boot_fail = boot_results.return_total_pass_fail() if boot_fail > boot_fail_threshold: error_message = "Boot failures exceed the boot failure" +\ " threshold:\n" +\ gp.sprint_var(boot_fail) +\ gp.sprint_var(boot_fail_threshold) BuiltIn().fail(gp.sprint_error(error_message))
def obmc_boot_test_py(loc_boot_stack=None, loc_stack_mode=None, loc_quiet=None): r""" Do main program processing. """ global save_stack # Process function parms. for parm_name in main_func_parm_list: # Get parm's value. cmd_buf = "parm_value = loc_" + parm_name exec(cmd_buf) gp.dpvar(parm_name) gp.dpvar(parm_value) if parm_value is None: # Parm was not specified by the calling function so set it to its # corresponding global value. cmd_buf = "loc_" + parm_name + " = BuiltIn().get_variable_value" +\ "(\"${" + parm_name + "}\")" gp.dpissuing(cmd_buf) exec(cmd_buf) else: # Save the global value on a stack. cmd_buf = "save_stack.push(BuiltIn().get_variable_value(\"${" +\ parm_name + "}\"), \"" + parm_name + "\")" gp.dpissuing(cmd_buf) exec(cmd_buf) # Set the global value to the passed value. cmd_buf = "BuiltIn().set_global_variable(\"${" + parm_name +\ "}\", loc_" + parm_name + ")" gp.dpissuing(cmd_buf) exec(cmd_buf) gp.dprintn(save_stack.sprint_obj()) setup() init_boot_pass, init_boot_fail = boot_results.return_total_pass_fail() if ffdc_only: gp.qprint_timen("Caller requested ffdc_only.") pre_boot_plug_in_setup() grk.run_key_u("my_ffdc") return # Process caller's boot_stack. while (len(boot_stack) > 0): test_loop_body() gp.qprint_timen("Finished processing stack.") # Process caller's boot_list. if len(boot_list) > 0: for ix in range(1, max_num_tests + 1): test_loop_body() gp.qprint_timen("Completed all requested boot tests.") boot_pass, boot_fail = boot_results.return_total_pass_fail() new_fail = boot_fail - init_boot_fail if new_fail > boot_fail_threshold: error_message = "Boot failures exceed the boot failure" +\ " threshold:\n" +\ gp.sprint_var(new_fail) +\ gp.sprint_var(boot_fail_threshold) BuiltIn().fail(gp.sprint_error(error_message))