def bmc_power_on():
    r"""
    Power the Open BMC machine on and monitor status to verify.
    """

    grp.rprint_timen("Refreshing state data.")
    state = state_mod.get_state()
    grp.rprint_var(state)

    match_state = state_mod.anchor_state(state)

    grp.rprintn()
    cmd_buf = ["Initiate Power On", "wait=${0}"]
    grp.rpissuing_keyword(cmd_buf)
    power = BuiltIn().run_keyword(*cmd_buf)

    state_change_timeout = BuiltIn().get_variable_value(
        "${STATE_CHANGE_TIMEOUT}", default="1 min")

    # Wait for the state to change in any way.
    state_mod.wait_state(match_state,
                         wait_time=state_change_timeout,
                         interval="3 seconds",
                         invert=1)

    if state_mod.OBMC_STATES_VERSION == 0:
        cmd_buf = [
            "Create Dictionary", "power=${1}", "bmc=HOST_BOOTED",
            "boot_progress=FW Progress, Starting OS"
        ]
    else:
        # TODO: Add back boot_progress when ipmi is enabled on Witherspoon.
        cmd_buf = [
            "Create Dictionary",
            "chassis=On",
            "bmc=Ready",
            #  "boot_progress=FW Progress, Starting OS",
            "host=Running"
        ]
    grp.rdpissuing_keyword(cmd_buf)
    final_state = BuiltIn().run_keyword(*cmd_buf)

    os_host = BuiltIn().get_variable_value("${OS_HOST}", default="")

    if os_host != "":
        final_state['os_ping'] = 1
        final_state['os_login'] = 1
        final_state['os_run_cmd'] = 1

    final_state = state_mod.anchor_state(final_state)

    grp.rprintn()
    power_on_timeout = BuiltIn().get_variable_value("${POWER_ON_TIMEOUT}",
                                                    default="14 mins")
    state_mod.wait_state(final_state,
                         wait_time=power_on_timeout,
                         interval="3 seconds")
def bmc_power_on():

    r"""
    Power the Open BMC machine on and monitor status to verify.
    """

    grp.rprint_timen("Refreshing state data.")
    state = state_mod.get_state()
    grp.rprint_var(state)

    match_state = state_mod.anchor_state(state)

    grp.rprintn()
    cmd_buf = ["Initiate Power On", "wait=${0}"]
    grp.rpissuing_keyword(cmd_buf)
    power = BuiltIn().run_keyword(*cmd_buf)

    state_change_timeout = BuiltIn().get_variable_value(
        "${STATE_CHANGE_TIMEOUT}", default="1 min")

    # Wait for the state to change in any way.
    state_mod.wait_state(match_state, wait_time=state_change_timeout,
                         interval="3 seconds", invert=1)

    if state_mod.OBMC_STATES_VERSION == 0:
        cmd_buf = ["Create Dictionary", "power=${1}",
                   "bmc=HOST_BOOTED",
                   "boot_progress=FW Progress, Starting OS"]
    else:
        # TODO: Add back boot_progress when ipmi is enabled on Witherspoon.
        cmd_buf = ["Create Dictionary", "chassis=On",
                   "bmc=Ready",
                   #  "boot_progress=FW Progress, Starting OS",
                   "host=Running"]
    grp.rdpissuing_keyword(cmd_buf)
    final_state = BuiltIn().run_keyword(*cmd_buf)

    os_host = BuiltIn().get_variable_value("${OS_HOST}", default="")

    if os_host != "":
        final_state['os_ping'] = 1
        final_state['os_login'] = 1
        final_state['os_run_cmd'] = 1

    final_state = state_mod.anchor_state(final_state)

    grp.rprintn()
    power_on_timeout = BuiltIn().get_variable_value(
        "${POWER_ON_TIMEOUT}", default="14 mins")
    state_mod.wait_state(final_state, wait_time=power_on_timeout,
                         interval="3 seconds")
def bmc_power_off():
    r"""
    Power the Open BMC machine off and monitor status to verify.
    """

    grp.rprint_timen("Refreshing state data.")
    state = state_mod.get_state()
    grp.rprint_var(state)

    match_state = state_mod.anchor_state(state)

    grp.rprintn()
    cmd_buf = ["Initiate Power Off"]
    grp.rpissuing_keyword(cmd_buf)
    power = BuiltIn().run_keyword(*cmd_buf)

    state_change_timeout = BuiltIn().get_variable_value(
        "${STATE_CHANGE_TIMEOUT}", default="1 min")

    # Wait for the state to change in any way.
    state_mod.wait_state(match_state,
                         wait_time=state_change_timeout,
                         interval="3 seconds",
                         invert=1)

    if state_mod.OBMC_STATES_VERSION == 0:
        cmd_buf = [
            "Create Dictionary", "power=${0}", "bmc=HOST_POWERED_OFF",
            "boot_progress=Off"
        ]
    else:
        # TODO: Add back boot_progress when ipmi is enabled on Witherspoon.
        cmd_buf = [
            "Create Dictionary",
            "chassis=Off",
            "bmc=Ready",
            #  "boot_progress=Off",
            "host=Off"
        ]
    grp.rdpissuing_keyword(cmd_buf)
    final_state = BuiltIn().run_keyword(*cmd_buf)

    final_state = state_mod.anchor_state(final_state)

    grp.rprintn()
    power_off_timeout = BuiltIn().get_variable_value("${POWER_OFF_TIMEOUT}",
                                                     default="2 mins")
    state_mod.wait_state(final_state,
                         wait_time=power_off_timeout,
                         interval="3 seconds")
def bmc_power_off():

    r"""
    Power the Open BMC machine off and monitor status to verify.
    """

    grp.rprint_timen("Refreshing state data.")
    state = state_mod.get_state()
    grp.rprint_var(state)

    match_state = state_mod.anchor_state(state)

    grp.rprintn()
    cmd_buf = ["Initiate Power Off"]
    grp.rpissuing_keyword(cmd_buf)
    power = BuiltIn().run_keyword(*cmd_buf)

    state_change_timeout = BuiltIn().get_variable_value(
        "${STATE_CHANGE_TIMEOUT}", default="1 min")

    # Wait for the state to change in any way.
    state_mod.wait_state(match_state, wait_time=state_change_timeout,
                         interval="3 seconds", invert=1)

    if state_mod.OBMC_STATES_VERSION == 0:
        cmd_buf = ["Create Dictionary", "power=${0}",
                   "bmc=HOST_POWERED_OFF", "boot_progress=Off"]
    else:
        # TODO: Add back boot_progress when ipmi is enabled on Witherspoon.
        cmd_buf = ["Create Dictionary", "chassis=Off",
                   "bmc=Ready",
                   #  "boot_progress=Off",
                   "host=Off"]
    grp.rdpissuing_keyword(cmd_buf)
    final_state = BuiltIn().run_keyword(*cmd_buf)

    final_state = state_mod.anchor_state(final_state)

    grp.rprintn()
    power_off_timeout = BuiltIn().get_variable_value(
        "${POWER_OFF_TIMEOUT}", default="2 mins")
    state_mod.wait_state(final_state, wait_time=power_off_timeout,
                         interval="3 seconds")
def wait_for_reboot(start_boot_seconds):
    r"""
    Wait for the BMC to complete a previously initiated reboot.

    Description of argument(s):
    start_boot_seconds  The time that the boot test started.  The format is the
                        epoch time in seconds, i.e. the number of seconds since
                        1970-01-01 00:00:00 UTC.  This value should be obtained
                        from the BMC so that it is not dependent on any kind of
                        synchronization between this machine and the target BMC
                        This will allow this program to work correctly even in
                        a simulated environment.  This value should be obtained
                        by the caller prior to initiating a reboot.  It can be
                        obtained as follows:
                        state = st.get_state(req_states=['epoch_seconds'])

    """

    st.wait_for_comm_cycle(int(start_boot_seconds))

    gp.qprintn()
    st.wait_state(st.standby_match_state,
                  wait_time="10 mins",
                  interval="10 seconds")
def run_boot(boot):
    r"""
    Run the specified boot.

    Description of arguments:
    boot  The name of the boot test to be performed.
    """

    global state

    print_test_start_message(boot)

    plug_in_setup()
    rc, shell_rc, failed_plug_in_name = \
        grpi.rprocess_plug_in_packages(call_point="pre_boot")
    if rc != 0:
        error_message = "Plug-in failed with non-zero return code.\n" +\
            gp.sprint_var(rc, 1)
        BuiltIn().fail(gp.sprint_error(error_message))

    if test_mode:
        # In test mode, we'll pretend the boot worked by assigning its
        # required end state to the default state value.
        state = st.strip_anchor_state(boot_table[boot]['end'])
    else:
        # Assertion:  We trust that the state data was made fresh by the
        # caller.

        gp.qprintn()

        if boot_table[boot]['method_type'] == "keyword":
            rk.my_run_keywords(boot_table[boot].get('lib_file_path', ''),
                               boot_table[boot]['method'],
                               quiet=quiet)

        if boot_table[boot]['bmc_reboot']:
            st.wait_for_comm_cycle(int(state['epoch_seconds']))
            plug_in_setup()
            rc, shell_rc, failed_plug_in_name = \
                grpi.rprocess_plug_in_packages(call_point="post_reboot")
            if rc != 0:
                error_message = "Plug-in failed with non-zero return code.\n"
                error_message += gp.sprint_var(rc, 1)
                BuiltIn().fail(gp.sprint_error(error_message))
        else:
            match_state = st.anchor_state(state)
            del match_state['epoch_seconds']
            # Wait for the state to change in any way.
            st.wait_state(match_state,
                          wait_time=state_change_timeout,
                          interval="10 seconds",
                          invert=1)

        gp.qprintn()
        if boot_table[boot]['end']['chassis'] == "Off":
            boot_timeout = power_off_timeout
        else:
            boot_timeout = power_on_timeout
        st.wait_state(boot_table[boot]['end'],
                      wait_time=boot_timeout,
                      interval="10 seconds")

    plug_in_setup()
    rc, shell_rc, failed_plug_in_name = \
        grpi.rprocess_plug_in_packages(call_point="post_boot")
    if rc != 0:
        error_message = "Plug-in failed with non-zero return code.\n" +\
            gp.sprint_var(rc, 1)
        BuiltIn().fail(gp.sprint_error(error_message))
def run_boot(boot):

    r"""
    Run the specified boot.

    Description of arguments:
    boot  The name of the boot test to be performed.
    """

    global state

    print_test_start_message(boot)

    plug_in_setup()
    rc, shell_rc, failed_plug_in_name = \
        grpi.rprocess_plug_in_packages(call_point="pre_boot")
    if rc != 0:
        error_message = "Plug-in failed with non-zero return code.\n" +\
            gp.sprint_var(rc, 1)
        BuiltIn().fail(gp.sprint_error(error_message))

    if test_mode:
        # In test mode, we'll pretend the boot worked by assigning its
        # required end state to the default state value.
        state = st.strip_anchor_state(boot_table[boot]['end'])
    else:
        # Assertion:  We trust that the state data was made fresh by the
        # caller.

        gp.qprintn()

        if boot_table[boot]['method_type'] == "keyword":
            rk.my_run_keywords(boot_table[boot].get('lib_file_path', ''),
                               boot_table[boot]['method'],
                               quiet=quiet)

        if boot_table[boot]['bmc_reboot']:
            st.wait_for_comm_cycle(int(state['epoch_seconds']))
            plug_in_setup()
            rc, shell_rc, failed_plug_in_name = \
                grpi.rprocess_plug_in_packages(call_point="post_reboot")
            if rc != 0:
                error_message = "Plug-in failed with non-zero return code.\n"
                error_message += gp.sprint_var(rc, 1)
                BuiltIn().fail(gp.sprint_error(error_message))
        else:
            match_state = st.anchor_state(state)
            del match_state['epoch_seconds']
            # Wait for the state to change in any way.
            st.wait_state(match_state, wait_time=state_change_timeout,
                          interval="10 seconds", invert=1)

        gp.qprintn()
        if boot_table[boot]['end']['chassis'] == "Off":
            boot_timeout = power_off_timeout
        else:
            boot_timeout = power_on_timeout
        st.wait_state(boot_table[boot]['end'], wait_time=boot_timeout,
                      interval="10 seconds")

    plug_in_setup()
    rc, shell_rc, failed_plug_in_name = \
        grpi.rprocess_plug_in_packages(call_point="post_boot")
    if rc != 0:
        error_message = "Plug-in failed with non-zero return code.\n" +\
            gp.sprint_var(rc, 1)
        BuiltIn().fail(gp.sprint_error(error_message))