예제 #1
0
import gen_valid as gv
import gen_robot_utils as gru
import gen_cmd as gc
import bmc_ssh_utils as bsu

import commands
from robot.libraries.BuiltIn import BuiltIn
from robot.utils import DotDict

import re
import os
import sys
import imp

# We need utils.robot to get keywords like "Get Chassis Power State".
gru.my_import_resource("utils.robot")
gru.my_import_resource("state_manager.robot")

base_path = os.path.dirname(
    os.path.dirname(imp.find_module("gen_robot_print")[1])) + os.sep
sys.path.append(base_path + "data/")

# Previously, I had this coded:
# import variables as var
# However, we ran into a problem where a robot program did this...
# Variables           ../../lib/ras/variables.py
# Prior to doing this...
# Library            ../lib/state.py

# This caused the wrong variables.py file to be selected.  Attempts to fix this
# have failed so far.  For the moment, we will hard-code the value we need from
예제 #2
0
import gen_robot_utils as gru
import gen_cmd as gc
import bmc_ssh_utils as bsu

from robot.libraries.BuiltIn import BuiltIn
from robot.utils import DotDict

import re
import os
import sys
import imp


# NOTE: Avoid importing utils.robot because utils.robot imports state.py
# (indirectly) which will cause failures.
gru.my_import_resource("rest_client.robot")

base_path = os.path.dirname(os.path.dirname(
                            imp.find_module("gen_robot_print")[1])) + os.sep
sys.path.append(base_path + "data/")

# Previously, I had this coded:
# import variables as var
# However, we ran into a problem where a robot program did this...
# Variables           ../../lib/ras/variables.py
# Prior to doing this...
# Library            ../lib/state.py

# This caused the wrong variables.py file to be selected.  Attempts to fix this
# have failed so far.  For the moment, we will hard-code the value we need from
# the file.
def my_run_keywords(lib_file_path,
                    keyword_string,
                    quiet=0,
                    test_mode=0):

    r"""
    Run the keywords in the keyword string.

    Description of arguments:
    lib_file_path   The path to a library or resource needed to run the
                    keywords.  This may contain a colon-delimited list of
                    library/resource paths.
    keyword_string  The keyword string to be run by this function.  If this
                    keyword string contains " ; " anywhere, it will be taken to
                    be multiple keyword strings.  Each keyword may also include
                    a variable assignment.  Example:
                    ${my_var}=  My Keyword
    quiet           If this parameter is set to "1", this program will print
                    only essential information, i.e. it will not echo
                    parameters, echo commands, print the total run time, etc.
    test_mode       This means that this program should go through all the
                    motions but not actually do anything substantial.
    """

    # NOTE: During code review the following question was raised: Why support
    # 1) variable assignments 2) multiple keywords?  Couldn't a user simply
    # call this program twice to get what they need.  If necessary, the user
    # could take the output of the first call and specify it as a literal on
    # the second call.
    #
    # However, this approach would not work in all cases.  The following case
    # would be such an example:
    # Let's say the first keyword string is as follows:
    # Create Dictionary  foo=bar
    # You wish to take the output of that call and specify it as a literal
    # value when running the following:
    # Want Dictionary  parm=<literal dictionary specification>
    # The problem is that there is no way to specify a dictionary as a
    # literal in Robot Framework.
    # By having this program support variable assignments and multiple
    # keywords, the user can invoke it with the following keyword string.
    # ${my_dict}=  Create Dictionary  foo=bar ; Want Dictionary  ${my_dict}


    # The user can pass multiple lib/resource paths by separating them with a
    # colon.
    lib_file_path_list = lib_file_path.split(":")
    # Get rid of empty entry if it exists.
    if lib_file_path_list[0] == "":
        del lib_file_path_list[0]
    for lib_file_path in lib_file_path_list:
        if lib_file_path.endswith(".py"):
            grp.rdprint_issuing("import_library(\"" + lib_file_path + "\")")
            BuiltIn().import_library(lib_file_path)
        else:
            grp.rdprint_issuing("my_import_resource(\"" + lib_file_path +
                                "\")")
            gru.my_import_resource(lib_file_path)

    # The user can pass multiple keyword strings by separating them with " ; ".
    keyword_list = keyword_string.split(" ; ")
    for keyword_string in keyword_list:
        cmd_buf = keyword_string.split("  ")
        if re.match(r"\$\{", cmd_buf[0]):
            # This looks like an assignment (e.g. ${var}=  <keyword>).
            # We'll extract the variable name, remove element 0 from
            # cmd_buf and set the global variable with the results
            # after running the keyword.
            var_name = cmd_buf[0].strip("${}=")
            del cmd_buf[0]
        else:
            var_name = ""

        if not quiet:
            grp.rprint_issuing_keyword(cmd_buf, test_mode)
        if test_mode:
            continue

        output = BuiltIn().run_keyword(*cmd_buf)

        if var_name != "":
            BuiltIn().set_global_variable("${" + var_name + "}", output)
        else:
            if output is not None:
                grp.rprint(output)
예제 #4
0
r"""
Provide useful ipmi functions.
"""

import re
import gen_print as gp
import gen_misc as gm
import gen_cmd as gc
import gen_robot_keyword as grk
import gen_robot_utils as gru
import bmc_ssh_utils as bsu
import var_funcs as vf
import ipmi_client as ic
import tempfile

gru.my_import_resource("ipmi_client.robot")
from robot.libraries.BuiltIn import BuiltIn


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:
예제 #5
0
def my_run_keywords(lib_file_path, keyword_string, quiet=0, test_mode=0):
    r"""
    Run the keywords in the keyword string.

    Description of arguments:
    lib_file_path   The path to a library or resource needed to run the
                    keywords.  This may contain a colon-delimited list of
                    library/resource paths.
    keyword_string  The keyword string to be run by this function.  If this
                    keyword string contains " ; " anywhere, it will be taken to
                    be multiple keyword strings.  Each keyword may also include
                    a variable assignment.  Example:
                    ${my_var}=  My Keyword
    quiet           If this parameter is set to "1", this program will print
                    only essential information, i.e. it will not echo
                    parameters, echo commands, print the total run time, etc.
    test_mode       This means that this program should go through all the
                    motions but not actually do anything substantial.
    """

    # NOTE: During code review the following question was raised: Why support
    # 1) variable assignments 2) multiple keywords?  Couldn't a user simply
    # call this program twice to get what they need.  If necessary, the user
    # could take the output of the first call and specify it as a literal on
    # the second call.
    #
    # However, this approach would not work in all cases.  The following case
    # would be such an example:
    # Let's say the first keyword string is as follows:
    # Create Dictionary  foo=bar
    # You wish to take the output of that call and specify it as a literal
    # value when running the following:
    # Want Dictionary  parm=<literal dictionary specification>
    # The problem is that there is no way to specify a dictionary as a
    # literal in Robot Framework.
    # By having this program support variable assignments and multiple
    # keywords, the user can invoke it with the following keyword string.
    # ${my_dict}=  Create Dictionary  foo=bar ; Want Dictionary  ${my_dict}

    # The user can pass multiple lib/resource paths by separating them with a
    # colon.
    lib_file_path_list = lib_file_path.split(":")
    # Get rid of empty entry if it exists.
    if lib_file_path_list[0] == "":
        del lib_file_path_list[0]
    for lib_file_path in lib_file_path_list:
        if lib_file_path.endswith(".py"):
            gp.dprint_issuing("import_library(\"" + lib_file_path + "\")")
            BuiltIn().import_library(lib_file_path)
        else:
            gp.dprint_issuing("my_import_resource(\"" + lib_file_path + "\")")
            gru.my_import_resource(lib_file_path)

    # The user can pass multiple keyword strings by separating them with " ; ".
    keyword_list = keyword_string.split(" ; ")
    for keyword_string in keyword_list:
        cmd_buf = keyword_string.split("  ")
        if re.match(r"\$\{", cmd_buf[0]):
            # This looks like an assignment (e.g. ${var}=  <keyword>).
            # We'll extract the variable name, remove element 0 from
            # cmd_buf and set the global variable with the results
            # after running the keyword.
            var_name = cmd_buf[0].strip("${}=")
            del cmd_buf[0]
        else:
            var_name = ""

        if not quiet:
            gp.print_issuing(cmd_buf, test_mode)
        if test_mode:
            continue

        output = BuiltIn().run_keyword(*cmd_buf)

        if var_name != "":
            BuiltIn().set_global_variable("${" + var_name + "}", output)
        else:
            if output is not None:
                gp.gp_print(output)
#!/usr/bin/env python
r"""
Provide useful error log utility keywords.
"""

import gen_print as gp
import sys
import os
import imp
base_path = os.path.dirname(
    os.path.dirname(imp.find_module("gen_robot_print")[1])) + os.sep
sys.path.append(base_path + "data/")
import variables as var
from robot.libraries.BuiltIn import BuiltIn
import gen_robot_utils as gru
gru.my_import_resource("logging_utils.robot")


def print_error_logs(error_logs, key_list=None):
    r"""
    Print the error logs to the console screen.

    This function provides the following benefits:
    - It will specify print_var parms for the caller (e.g. hex=1).
    - It is much easier to call this function than to generate the desired code
      directly from a robot script.

    Description of argument(s):
    error_logs                      An error log dictionary such as the one
                                    returned by the 'Get Error Logs' keyword.
    key_list                        The list of keys to be printed.  This may
예제 #7
0
#!/usr/bin/env python

r"""
This module is the python counterpart to poweroffs.robot.  It provides
functions for powering off an open bmc machine.
"""

import gen_robot_print as grp
import state as state_mod
import gen_robot_utils as gru

from robot.libraries.BuiltIn import BuiltIn

# We need utils.robot to get keyword "Initiate Power Off".
gru.my_import_resource("utils.robot")


###############################################################################
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()
예제 #8
0
#!/usr/bin/env python
r"""
This module is the python counterpart to utils.robot.  It provides many
functions for communicating with the Open BMC machine.
"""

import gen_robot_print as grp
import state as state_mod
import gen_robot_utils as gru

from robot.libraries.BuiltIn import BuiltIn

# We need utils.robot to get keyword "Initiate Power On".
gru.my_import_resource("utils.robot")


###############################################################################
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)
#!/usr/bin/env python

r"""
Provide useful ipmi functions.
"""

import gen_misc as gm
import gen_robot_keyword as grk
import gen_robot_utils as gru
import tempfile
gru.my_import_resource("ipmi_client.robot")


###############################################################################
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