def compose_plug_in_save_dir_path(plug_in_package_name=None): r""" Create and return a directory path name that is suitable for saving plug-in data. The name will be comprised of things such as plug_in package name, pid, etc. in order to guarantee that it is unique for a given test run. Description of argument(s): plug_in_package_name The plug-in package name. This defaults to the name of the caller's plug-in package. However, the caller can specify another value in order to retrieve data saved by another plug-in package. """ plug_in_package_name = gm.dft(plug_in_package_name, get_plug_in_package_name()) BASE_TOOL_DIR_PATH = \ gm.add_trailing_slash(os.environ.get(PLUG_VAR_PREFIX + "_BASE_TOOL_DIR_PATH", "/tmp/")) NICKNAME = os.environ.get("AUTOBOOT_OPENBMC_NICKNAME", "") if NICKNAME == "": NICKNAME = os.environ["AUTOIPL_FSP1_NICKNAME"] MASTER_PID = os.environ[PLUG_VAR_PREFIX + "_MASTER_PID"] gp.dprint_vars(BASE_TOOL_DIR_PATH, NICKNAME, plug_in_package_name, MASTER_PID) return BASE_TOOL_DIR_PATH + gm.username() + "/" + NICKNAME + "/" +\ plug_in_package_name + "/" + str(MASTER_PID) + "/"
def init_robot_file_path(robot_file_path): r""" Determine full path name for the file path passed in robot_file_path and return it. If robot_file_path contains a fully qualified path name, this function will verify that the file exists. If robot_file_path contains a relative path, this function will search for the file and set robot_file_path so that it contains the absolute path to the robot file. This function will search for the robot file using the raw_robot_file_search_path (defined above). Note that if ROBOT_TEST_BASE_DIR_PATH is not set, this function will call init_robot_test_base_dir_path to set it. Description of arguments: robot_file_path The absolute or relative path to a robot file. """ if not gv.valid_value(robot_file_path): raise ValueError('Programmer error.') try: if ROBOT_TEST_BASE_DIR_PATH is NONE: init_robot_test_base_dir_path() except NameError: init_robot_test_base_dir_path() if not re.match(r".*\.(robot|py)$", robot_file_path): # No suffix so we'll assign one of "\.robot". robot_file_path = robot_file_path + ".robot" abs_path = 0 if robot_file_path[0:1] == "/": abs_path = 1 gp.dprint_vars(abs_path, robot_file_path) if not abs_path: cmd_buf = "echo -n \"" + raw_robot_file_search_path + "\"" shell_rc, out_buf = gc.shell_cmd(cmd_buf, quiet=(not debug), print_output=0) robot_file_search_paths = out_buf gp.dprint_var(robot_file_search_paths) robot_file_search_paths_list = robot_file_search_paths.split(':') for search_path in robot_file_search_paths_list: search_path = gm.add_trailing_slash(search_path) candidate_file_path = search_path + robot_file_path gp.dprint_var(candidate_file_path) if os.path.isfile(candidate_file_path): gp.dprint_timen("Found full path to " + robot_file_path + ".") robot_file_path = candidate_file_path break gp.dprint_var(robot_file_path) if not gv.valid_file_path(robot_file_path): raise ValueError('Programmer error.') return robot_file_path
def get_os_state(os_host="", os_username="", os_password="", req_states=default_os_req_states, os_up=True, quiet=None): r""" Get component states for the operating system such as ping, login, etc, put them into a dictionary and return them to the caller. Note that all substate values are strings. Description of argument(s): os_host The DNS name or IP address of the operating system. This defaults to global ${OS_HOST}. os_username The username to be used to login to the OS. This defaults to global ${OS_USERNAME}. os_password The password to be used to login to the OS. This defaults to global ${OS_PASSWORD}. req_states This is a list of states whose values are being requested by the caller. os_up If the caller knows that the os can't possibly be up, it can improve performance by passing os_up=False. This function will then simply return default values for all requested os sub states. quiet Indicates whether status details (e.g. curl commands) should be written to the console. Defaults to either global value of ${QUIET} or to 1. """ quiet = int(gp.get_var_value(quiet, 0)) # Set parm defaults where necessary and validate all parms. if os_host == "": os_host = BuiltIn().get_variable_value("${OS_HOST}") error_message = gv.valid_value(os_host, invalid_values=[None, ""]) if error_message != "": BuiltIn().fail(gp.sprint_error(error_message)) if os_username == "": os_username = BuiltIn().get_variable_value("${OS_USERNAME}") error_message = gv.valid_value(os_username, invalid_values=[None, ""]) if error_message != "": BuiltIn().fail(gp.sprint_error(error_message)) if os_password == "": os_password = BuiltIn().get_variable_value("${OS_PASSWORD}") error_message = gv.valid_value(os_password, invalid_values=[None, ""]) if error_message != "": BuiltIn().fail(gp.sprint_error(error_message)) invalid_req_states = [sub_state for sub_state in req_states if sub_state not in valid_os_req_states] if len(invalid_req_states) > 0: error_message = "The following req_states are not supported:\n" +\ gp.sprint_var(invalid_req_states) BuiltIn().fail(gp.sprint_error(error_message)) # Initialize all substate values supported by this function. os_ping = 0 os_login = 0 os_run_cmd = 0 if os_up: if 'os_ping' in req_states: # See if the OS pings. rc, out_buf = gc.shell_cmd("ping -c 1 -w 2 " + os_host, print_output=0, show_err=0, ignore_err=1) if rc == 0: os_ping = 1 # Programming note: All attributes which do not require an ssh login # should have been processed by this point. master_req_login = ['os_login', 'os_run_cmd'] req_login = [sub_state for sub_state in req_states if sub_state in master_req_login] must_login = (len(req_login) > 0) if must_login: output, stderr, rc = bsu.os_execute_command("uptime", quiet=quiet, ignore_err=1, time_out=20) if rc == 0: os_login = 1 os_run_cmd = 1 else: gp.dprint_vars(output, stderr) gp.dprint_vars(rc, 1) os_state = DotDict() for sub_state in req_states: cmd_buf = "os_state['" + sub_state + "'] = str(" + sub_state + ")" exec(cmd_buf) return os_state
def init_robot_test_base_dir_path(): r""" Initialize and validate the environment variable, ROBOT_TEST_BASE_DIR_PATH and set corresponding global variable ROBOT_TEST_RUNNING_FROM_SB. If ROBOT_TEST_BASE_DIR_PATH is already set, this function will merely validate it. This function will also set environment variable ROBOT_TEST_RUNNING_FROM_SB when ROBOT_TEST_BASE_DIR_PATH is not pre-set. """ # ROBOT_TEST_BASE_DIR_PATH will be set as follows: # This function will determine whether we are running in a user sandbox # or from a standard apolloxxx environment. # - User sandbox: # If there is a <developer's home dir>/git/openbmc-test-automation/, # ROBOT_TEST_BASE_DIR_PATH will be set to that path. Otherwise, we set it # to <program dir path>/git/openbmc-test-automation/ # - Not in user sandbox: # ROBOT_TEST_BASE_DIR_PATH will be set to <program dir # path>/git/openbmc-test-automation/ ROBOT_TEST_BASE_DIR_PATH = os.environ.get('ROBOT_TEST_BASE_DIR_PATH', "") ROBOT_TEST_RUNNING_FROM_SB = \ int(os.environ.get('ROBOT_TEST_RUNNING_FROM_SB', "0")) if ROBOT_TEST_BASE_DIR_PATH == "": # ROBOT_TEST_BASE_DIR_PATH was not set by user/caller. AUTOIPL_VERSION = os.environ.get('AUTOIPL_VERSION', '') if AUTOIPL_VERSION == "": ROBOT_TEST_BASE_DIR_PATH = base_path else: suffix = "git/openbmc-test-automation/" # Determine whether we're running out of a developer sandbox or # simply out of an apolloxxx/bin path. shell_rc, out_buf = gc.shell_cmd('dirname $(which gen_print.py)', quiet=(not debug), print_output=0) executable_base_dir_path = os.path.realpath(out_buf.rstrip()) + "/" apollo_dir_path = os.environ['AUTO_BASE_PATH'] + AUTOIPL_VERSION +\ "/bin/" developer_home_dir_path = re.sub('/sandbox.*', '', executable_base_dir_path) developer_home_dir_path = \ gm.add_trailing_slash(developer_home_dir_path) gp.dprint_vars(executable_base_dir_path, developer_home_dir_path, apollo_dir_path) ROBOT_TEST_RUNNING_FROM_SB = 0 if executable_base_dir_path != apollo_dir_path: ROBOT_TEST_RUNNING_FROM_SB = 1 gp.dprint_vars(ROBOT_TEST_RUNNING_FROM_SB) ROBOT_TEST_BASE_DIR_PATH = developer_home_dir_path + suffix if not os.path.isdir(ROBOT_TEST_BASE_DIR_PATH): gp.dprint_timen("NOTE: Sandbox directory " + ROBOT_TEST_BASE_DIR_PATH + " does not" + " exist.") # Fall back to the apollo dir path. ROBOT_TEST_BASE_DIR_PATH = apollo_dir_path + suffix else: # Use to the apollo dir path. ROBOT_TEST_BASE_DIR_PATH = apollo_dir_path + suffix if not gv.valid_value(ROBOT_TEST_BASE_DIR_PATH): return False gp.dprint_vars(ROBOT_TEST_RUNNING_FROM_SB, ROBOT_TEST_BASE_DIR_PATH) if not gv.valid_dir_path(ROBOT_TEST_BASE_DIR_PATH): return False ROBOT_TEST_BASE_DIR_PATH = gm.add_trailing_slash(ROBOT_TEST_BASE_DIR_PATH) gm.set_mod_global(ROBOT_TEST_BASE_DIR_PATH) os.environ['ROBOT_TEST_BASE_DIR_PATH'] = ROBOT_TEST_BASE_DIR_PATH gm.set_mod_global(ROBOT_TEST_RUNNING_FROM_SB) os.environ['ROBOT_TEST_RUNNING_FROM_SB'] = str(ROBOT_TEST_RUNNING_FROM_SB)
def robot_cmd_fnc(robot_cmd_buf, robot_jail=os.environ.get('ROBOT_JAIL', ''), gzip=1): r""" Run the robot command string. This function will set the various PATH variables correctly so that you are running the proper version of all imported files, etc. Description of argument(s): robot_cmd_buf The complete robot command string. robot_jail Indicates that this is to run in "robot jail" meaning without visibility to any apolloxxx import files, programs, etc. gqip This indicates that the log, report and output files produced by robot should be gzipped to save space. """ if not gv.valid_value(robot_cmd_buf): return False # Set global variables to aid in cleanup with process_robot_output_files. global gcr_last_robot_cmd_buf global gcr_last_robot_rc gcr_last_robot_cmd_buf = robot_cmd_buf # Get globals set by init_robot_test_base_dir_path(). module = sys.modules["__main__"] try: ROBOT_TEST_BASE_DIR_PATH = getattr(module, "ROBOT_TEST_BASE_DIR_PATH") except NameError: init_robot_test_base_dir_path() ROBOT_TEST_BASE_DIR_PATH = getattr(module, "ROBOT_TEST_BASE_DIR_PATH") ROBOT_TEST_RUNNING_FROM_SB = \ gm.get_mod_global("ROBOT_TEST_RUNNING_FROM_SB") if robot_jail == "": if ROBOT_TEST_RUNNING_FROM_SB: robot_jail = 0 else: robot_jail = 1 robot_jail = int(robot_jail) ROBOT_JAIL = os.environ.get('ROBOT_JAIL', '') gp.dprint_vars(ROBOT_TEST_BASE_DIR_PATH, ROBOT_TEST_RUNNING_FROM_SB, ROBOT_JAIL, robot_jail) # Save PATH and PYTHONPATH to be restored later. os.environ["SAVED_PYTHONPATH"] = os.environ.get("PYTHONPATH", "") os.environ["SAVED_PATH"] = os.environ.get("PATH", "") if robot_jail: PYTHONPATH = ROBOT_TEST_BASE_DIR_PATH + "lib" NEW_PATH_LIST = [ROBOT_TEST_BASE_DIR_PATH + "bin"] # Coding special case to preserve python27_path. python27_path = "/opt/rh/python27/root/usr/bin" PATH_LIST = os.environ.get("PATH", "").split(":") if python27_path in PATH_LIST: NEW_PATH_LIST.append(python27_path) NEW_PATH_LIST.extend(["/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin"]) PATH = ":".join(NEW_PATH_LIST) else: PYTHONPATH = os.environ.get('PYTHONPATH', '') + ":" +\ ROBOT_TEST_BASE_DIR_PATH + "lib/" PATH = os.environ.get('PATH', '') + ":" + ROBOT_TEST_BASE_DIR_PATH +\ "bin/" os.environ['PYTHONPATH'] = PYTHONPATH os.environ['PATH'] = PATH gp.dprint_vars(PATH, PYTHONPATH) os.environ['FFDC_DIR_PATH_STYLE'] = os.environ.get('FFDC_DIR_PATH_STYLE', '1') test_mode = getattr(module, "test_mode") gp.qpissuing(robot_cmd_buf, test_mode) if test_mode: os.environ["PATH"] = os.environ.get("SAVED_PATH", "") os.environ["PYTHONPATH"] = os.environ.get("SAVED_PYTHONPATH", "") return True if quiet: DEVNULL = open(os.devnull, 'wb') stdout = DEVNULL else: stdout = None sub_proc = subprocess.Popen(robot_cmd_buf, stdout=stdout, shell=True) sub_proc.communicate() shell_rc = sub_proc.returncode os.environ["PATH"] = os.environ.get("SAVED_PATH", "") os.environ["PYTHONPATH"] = os.environ.get("SAVED_PYTHONPATH", "") gcr_last_robot_rc = shell_rc process_robot_output_files() if shell_rc != 0: hex = 1 gp.print_var(shell_rc, hex) return False return True
def robot_cmd_fnc(robot_cmd_buf, robot_jail=os.environ.get('ROBOT_JAIL', ''), quiet=None, test_mode=0): r""" Run the robot command string. This function will set the various PATH variables correctly so that you are running the proper version of all imported files, etc. Description of argument(s): robot_cmd_buf The complete robot command string. robot_jail Indicates that this is to run in "robot jail" meaning without visibility to any apolloxxx import files, programs, etc. test_mode If test_mode is set, this function will not actually run the command. """ quiet = int(gm.dft(quiet, gp.get_stack_var('quiet', 0))) gv.valid_value(robot_cmd_buf) # Set global variables to aid in cleanup with process_robot_output_files. global gcr_last_robot_cmd_buf global gcr_last_robot_rc gcr_last_robot_cmd_buf = robot_cmd_buf # Get globals set by init_robot_test_base_dir_path(). module = sys.modules["__main__"] try: ROBOT_TEST_BASE_DIR_PATH = getattr(module, "ROBOT_TEST_BASE_DIR_PATH") except NameError: init_robot_test_base_dir_path() ROBOT_TEST_BASE_DIR_PATH = getattr(module, "ROBOT_TEST_BASE_DIR_PATH") ROBOT_TEST_RUNNING_FROM_SB = gm.get_mod_global( "ROBOT_TEST_RUNNING_FROM_SB") OPENBMCTOOL_DIR_PATH = gm.get_mod_global("OPENBMCTOOL_DIR_PATH") if robot_jail == "": if ROBOT_TEST_RUNNING_FROM_SB: robot_jail = 0 else: robot_jail = 1 robot_jail = int(robot_jail) ROBOT_JAIL = os.environ.get('ROBOT_JAIL', '') gp.dprint_vars(ROBOT_TEST_BASE_DIR_PATH, ROBOT_TEST_RUNNING_FROM_SB, ROBOT_JAIL, robot_jail) # Save PATH and PYTHONPATH to be restored later. os.environ["SAVED_PYTHONPATH"] = os.environ.get("PYTHONPATH", "") os.environ["SAVED_PATH"] = os.environ.get("PATH", "") if robot_jail: # Make sure required programs like python and robot can be found in the new restricted PATH. required_programs = "python robot" # It is expected that there will be a "python" program in the tool base bin path which is really a # link to select_version. Ditto for "robot". Call each with the --print_only option to get the # paths to the "real" programs. cmd_buf = "for program in " + required_programs \ + " ; do dirname $(${program} --print_only) ; done 2>/dev/null" rc, out_buf = gc.shell_cmd(cmd_buf, quiet=1, print_output=0) PYTHONPATH = ROBOT_TEST_BASE_DIR_PATH + "lib" NEW_PATH_LIST = [ROBOT_TEST_BASE_DIR_PATH + "bin"] NEW_PATH_LIST.extend(list(set(out_buf.rstrip("\n").split("\n")))) NEW_PATH_LIST.extend([ "/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin", OPENBMCTOOL_DIR_PATH.rstrip('/') ]) PATH = ":".join(NEW_PATH_LIST) else: PYTHONPATH = os.environ.get('PYTHONPATH', '') + ":" +\ ROBOT_TEST_BASE_DIR_PATH + "lib" PATH = os.environ.get('PATH', '') + ":" + ROBOT_TEST_BASE_DIR_PATH +\ "bin" + ":" + OPENBMCTOOL_DIR_PATH.rstrip('/') os.environ['PYTHONPATH'] = PYTHONPATH os.environ['PATH'] = PATH gp.dprint_vars(PATH, PYTHONPATH) os.environ['FFDC_DIR_PATH_STYLE'] = os.environ.get('FFDC_DIR_PATH_STYLE', '1') gp.qpissuing(robot_cmd_buf, test_mode) if test_mode: os.environ["PATH"] = os.environ.get("SAVED_PATH", "") os.environ["PYTHONPATH"] = os.environ.get("SAVED_PYTHONPATH", "") return True if quiet: DEVNULL = open(os.devnull, 'wb') stdout = DEVNULL else: stdout = None sub_proc = subprocess.Popen(robot_cmd_buf, stdout=stdout, shell=True) sub_proc.communicate() shell_rc = sub_proc.returncode os.environ["PATH"] = os.environ.get("SAVED_PATH", "") os.environ["PYTHONPATH"] = os.environ.get("SAVED_PYTHONPATH", "") gcr_last_robot_rc = shell_rc process_robot_output_files() if shell_rc != 0: gp.print_var(shell_rc, gp.hexa()) return False return True
def get_state(openbmc_host="", openbmc_username="", openbmc_password="", os_host="", os_username="", os_password="", req_states=default_req_states, quiet=None): r""" Get component states such as chassis state, bmc state, etc, put them into a dictionary and return them to the caller. Note that all substate values are strings. Note: If elapsed_boot_time is included in req_states, it is the caller's duty to call set_start_boot_seconds() in order to set global start_boot_seconds. elapsed_boot_time is the current time minus start_boot_seconds. Description of argument(s): openbmc_host The DNS name or IP address of the BMC. This defaults to global ${OPENBMC_HOST}. openbmc_username The username to be used to login to the BMC. This defaults to global ${OPENBMC_USERNAME}. openbmc_password The password to be used to login to the BMC. This defaults to global ${OPENBMC_PASSWORD}. os_host The DNS name or IP address of the operating system. This defaults to global ${OS_HOST}. os_username The username to be used to login to the OS. This defaults to global ${OS_USERNAME}. os_password The password to be used to login to the OS. This defaults to global ${OS_PASSWORD}. req_states This is a list of states whose values are being requested by the caller. quiet Indicates whether status details (e.g. curl commands) should be written to the console. Defaults to either global value of ${QUIET} or to 1. """ quiet = int(gp.get_var_value(quiet, 0)) # Set parm defaults where necessary and validate all parms. if openbmc_host == "": openbmc_host = BuiltIn().get_variable_value("${OPENBMC_HOST}") error_message = gv.valid_value(openbmc_host, invalid_values=[None, ""]) if error_message != "": BuiltIn().fail(gp.sprint_error(error_message)) if openbmc_username == "": openbmc_username = BuiltIn().get_variable_value("${OPENBMC_USERNAME}") error_message = gv.valid_value(openbmc_username, invalid_values=[None, ""]) if error_message != "": BuiltIn().fail(gp.sprint_error(error_message)) if openbmc_password == "": openbmc_password = BuiltIn().get_variable_value("${OPENBMC_PASSWORD}") error_message = gv.valid_value(openbmc_password, invalid_values=[None, ""]) if error_message != "": BuiltIn().fail(gp.sprint_error(error_message)) # NOTE: OS parms are optional. if os_host == "": os_host = BuiltIn().get_variable_value("${OS_HOST}") if os_host is None: os_host = "" if os_username is "": os_username = BuiltIn().get_variable_value("${OS_USERNAME}") if os_username is None: os_username = "" if os_password is "": os_password = BuiltIn().get_variable_value("${OS_PASSWORD}") if os_password is None: os_password = "" invalid_req_states = [ sub_state for sub_state in req_states if sub_state not in valid_req_states ] if len(invalid_req_states) > 0: error_message = "The following req_states are not supported:\n" +\ gp.sprint_var(invalid_req_states) BuiltIn().fail(gp.sprint_error(error_message)) # Initialize all substate values supported by this function. ping = 0 packet_loss = '' uptime = '' epoch_seconds = '' elapsed_boot_time = '' rest = '' redfish = '' chassis = '' requested_chassis = '' bmc = '' requested_bmc = '' # BootProgress state will get populated when state logic enumerates the # state URI. This is to prevent state dictionary boot_progress value # getting empty when the BootProgress is NOT found, making it optional. boot_progress = 'NA' operating_system = '' host = '' requested_host = '' attempts_left = '' # Get the component states. if 'ping' in req_states: # See if the OS pings. rc, out_buf = gc.shell_cmd("ping -c 1 -w 2 " + openbmc_host, print_output=0, show_err=0, ignore_err=1) if rc == 0: ping = 1 if 'packet_loss' in req_states: # See if the OS pings. cmd_buf = "ping -c 5 -w 5 " + openbmc_host +\ " | egrep 'packet loss' | sed -re 's/.* ([0-9]+)%.*/\\1/g'" rc, out_buf = gc.shell_cmd(cmd_buf, print_output=0, show_err=0, ignore_err=1) if rc == 0: packet_loss = out_buf.rstrip("\n") if 'uptime' in req_states: # Sometimes reading uptime results in a blank value. Call with # wait_until_keyword_succeeds to ensure a non-blank value is obtained. remote_cmd_buf = "read uptime filler 2>/dev/null < /proc/uptime" +\ " && [ ! -z \"${uptime}\" ] && echo ${uptime}" cmd_buf = [ "BMC Execute Command", re.sub('\\$', '\\$', remote_cmd_buf), 'quiet=1', 'test_mode=0', 'time_out=5' ] gp.qprint_issuing(cmd_buf, 0) gp.qprint_issuing(remote_cmd_buf, 0) try: stdout, stderr, rc =\ BuiltIn().wait_until_keyword_succeeds("10 sec", "5 sec", *cmd_buf) if rc == 0 and stderr == "": uptime = stdout except AssertionError as my_assertion_error: pass if 'epoch_seconds' in req_states or 'elapsed_boot_time' in req_states: date_cmd_buf = "date -u +%s" if USE_BMC_EPOCH_TIME: cmd_buf = ["BMC Execute Command", date_cmd_buf, 'quiet=${1}'] if not quiet: gp.print_issuing(cmd_buf) status, ret_values = \ BuiltIn().run_keyword_and_ignore_error(*cmd_buf) if status == "PASS": stdout, stderr, rc = ret_values if rc == 0 and stderr == "": epoch_seconds = stdout.rstrip("\n") else: shell_rc, out_buf = gc.cmd_fnc_u(date_cmd_buf, quiet=quiet, print_output=0) if shell_rc == 0: epoch_seconds = out_buf.rstrip("\n") if 'elapsed_boot_time' in req_states: global start_boot_seconds elapsed_boot_time = int(epoch_seconds) - start_boot_seconds if not redfish_support_trans_state: master_req_rest = [ 'rest', 'host', 'requested_host', 'operating_system', 'attempts_left', 'boot_progress', 'chassis', 'requested_chassis' 'bmc' 'requested_bmc' ] req_rest = [ sub_state for sub_state in req_states if sub_state in master_req_rest ] need_rest = (len(req_rest) > 0) state = DotDict() if need_rest: cmd_buf = [ "Read Properties", SYSTEM_STATE_URI + "enumerate", "quiet=${" + str(quiet) + "}", "timeout=30" ] gp.dprint_issuing(cmd_buf) status, ret_values = \ BuiltIn().run_keyword_and_ignore_error(*cmd_buf) if status == "PASS": state['rest'] = '1' else: state['rest'] = '0' if int(state['rest']): for url_path in ret_values: # Skip conflicting "CurrentHostState" URL from the enum # /xyz/openbmc_project/state/hypervisor0 if "hypervisor0" in url_path: continue if platform_arch_type == "x86": # Skip conflicting "CurrentPowerState" URL from the enum # /xyz/openbmc_project/state/chassis_system0 if "chassis_system0" in url_path: continue for attr_name in ret_values[url_path]: # Create a state key value based on the attr_name. try: ret_values[url_path][attr_name] = \ re.sub(r'.*\.', "", ret_values[url_path][attr_name]) except TypeError: pass # Do some key name manipulations. new_attr_name = re.sub(r'^Current|(State|Transition)$', "", attr_name) new_attr_name = re.sub(r'BMC', r'Bmc', new_attr_name) new_attr_name = re.sub(r'([A-Z][a-z])', r'_\1', new_attr_name) new_attr_name = new_attr_name.lower().lstrip("_") new_attr_name = re.sub(r'power', r'chassis', new_attr_name) if new_attr_name in req_states: state[new_attr_name] = ret_values[url_path][ attr_name] else: master_req_rf = [ 'redfish', 'host', 'requested_host', 'attempts_left', 'boot_progress', 'chassis', 'requested_chassis' 'bmc' 'requested_bmc' ] req_rf = [ sub_state for sub_state in req_states if sub_state in master_req_rf ] need_rf = (len(req_rf) > 0) state = DotDict() if need_rf: cmd_buf = ["Redfish Get States"] gp.dprint_issuing(cmd_buf) status, ret_values = \ BuiltIn().run_keyword_and_ignore_error(*cmd_buf) gp.dprint_vars(status, ret_values) if status == "PASS": state['redfish'] = '1' else: state['redfish'] = '0' if int(state['redfish']): state['chassis'] = ret_values['chassis'] state['boot_progress'] = ret_values['boot_progress'] state['host'] = ret_values['host'] state['bmc'] = ret_values['bmc'] for sub_state in req_states: if sub_state in state: continue if sub_state.startswith("os_"): # We pass "os_" requests on to get_os_state. continue cmd_buf = "state['" + sub_state + "'] = str(" + sub_state + ")" exec(cmd_buf) if os_host == "": # The caller has not specified an os_host so as far as we're concerned, # it doesn't exist. return state os_req_states = [ sub_state for sub_state in req_states if sub_state.startswith('os_') ] if len(os_req_states) > 0: # The caller has specified an os_host and they have requested # information on os substates. # Based on the information gathered on bmc, we'll try to make a # determination of whether the os is even up. We'll pass the result # of that assessment to get_os_state to enhance performance. os_up_match = DotDict() for sub_state in master_os_up_match: if sub_state in req_states: os_up_match[sub_state] = master_os_up_match[sub_state] os_up = compare_states(state, os_up_match) os_state = get_os_state(os_host=os_host, os_username=os_username, os_password=os_password, req_states=os_req_states, os_up=os_up, quiet=quiet) # Append os_state dictionary to ours. state.update(os_state) return state