コード例 #1
0
    def rest_request(self, func, *args, **kwargs):
        r"""
        Perform redfish rest request and return response.

        This function provides the following additional functionality.
        - The calling function's call line is logged to standard out (provided that global variable "quiet"
          is not set).
        - The caller may include a valid_status_codes argument.
        - Callers may include inline python code strings to define arguments.  This predominantly benefits
          robot callers.

          For example, instead of calling like this:
            ${data}=  Create Dictionary  HostName=${hostname}
            Redfish.patch  ${REDFISH_NW_PROTOCOL_URI}  body=&{data}

          Callers may do this:

            Redfish.patch  ${REDFISH_NW_PROTOCOL_URI}
            ...  body=[('HostName', '${hostname}')]

        Description of argument(s):
        func                        A reference to the parent class function which is to be called (e.g. get,
                                    put, etc.).
        args                        This is passed directly to the function referenced by the func argument
                                    (see the documentation for the corresponding redfish HttpClient method
                                    for details).
        kwargs                      This is passed directly to the function referenced by the func argument
                                    (see the documentation for the corresponding redfish HttpClient method
                                    for details) with the following exception:  If kwargs contains a
                                    valid_status_codes key, it will be removed from kwargs and processed by
                                    this function.  This allows the caller to indicate what rest status codes
                                    are acceptable.  The default value is [200].  See the
                                    valid_http_status_code function above for details.

        Example uses:

        From a python program:

        response = bmc_redfish.get("/redfish/v1/Managers/bmc/EthernetInterfaces", [200, 201])

        If this call to the get method generates a response.status equal to anything other than 200 or 201,
        an exception will be raised.

        From a robot program:

        BMC_Redfish.logout
        ${response}=  BMC_Redfish.Get  /redfish/v1/Managers/bmc/EthernetInterfaces  valid_status_codes=[401]

        As part of a robot test, the programmer has logged out to verify that the get request will generate a
        status code of 401 (i.e. "Unauthorized").
        """
        gp.qprint_executing(stack_frame_ix=3, style=gp.func_line_style_short)
        # Convert python string object definitions to objects (mostly useful for robot callers).
        args = fa.args_to_objects(args)
        kwargs = fa.args_to_objects(kwargs)
        valid_status_codes = kwargs.pop('valid_status_codes', [200])
        response = func(*args, **kwargs)
        valid_http_status_code(response.status, valid_status_codes)
        return response
コード例 #2
0
def sprint_vars(*args, **kwargs):
    r"""
    Sprint the values of one or more variables to the console.

    This is a robot re-definition of the sprint_vars function in gen_print.py.  Given a list of variable
    names, this keyword will string print each variable name and value such that each value lines up in the
    same column as messages printed with sprint_time().

    Description of argument(s):
    args                            The names of the variables to be printed (e.g. var1 rather than ${var1}).
    kwargs                          See sprint_varx in gen_print.py for descriptions of all other arguments.
    """

    if 'fmt' in kwargs:
        # Find format option names in kwargs['fmt'] and wrap them with "gp." and "()" to make them into
        # function calls.  For example, verbose would be converted to "gp.verbose()".  This allows the user
        # to simply specify "fmt=verbose" (vs. fmt=gp.verbose()).
        # Note "terse" has been explicitly added for backward compatibility.  Once the repo has been purged
        # of its use, this code can return to its original form.
        regex = "(" + "|".join(gp.valid_fmts()) + "|terse)"
        kwargs['fmt'] = \
            re.sub(regex, "gp.\\1()", kwargs['fmt'])
    kwargs = fa.args_to_objects(kwargs)
    buffer = ""
    for var_name in args:
        var_value = BuiltIn().get_variable_value("${" + str(var_name) + "}")
        buffer += gp.sprint_varx(var_name, var_value, **kwargs)

    return buffer
コード例 #3
0
def pldmtool(option_string, **bsu_options):
    r"""
    Run pldmtool on the BMC with the caller's option string and return the result.

    Example:

    ${pldm_results}=  Pldmtool  base GetPLDMTypes
    Rprint Vars  pldm_results

    pldm_results:
      pldmtool base GetPLDMVersion -t 0
      {
          "Response": "1.0.0"
      }

     pldmtool base GetTID
     {
         "Response": 1
     }

    Description of argument(s):
    option_string                   A string of options which are to be processed by the pldmtool command.
    parse_results                   Parse the pldmtool results and return a dictionary rather than the raw
                                    pldmtool output.
    bsu_options                     Options to be passed directly to bmc_execute_command.  See its prolog for
                                    details.
    """

    # This allows callers to specify arguments in python style (e.g. print_out=1 vs. print_out=${1}).
    bsu_options = fa.args_to_objects(bsu_options)

    stdout, stderr, rc = bsu.bmc_execute_command('pldmtool ' + option_string,
                                                 **bsu_options)
    return json.loads(stdout)
コード例 #4
0
def peltool(option_string, **bsu_options):
    r"""
    Run peltool on the BMC with the caller's option string and return the result.

    Example:

    ${pel_results}=  Peltool  -l
    Rprint Vars  pel_results

    pel_results:
      [0x50000031]:
        [CompID]:                       0x1000
        [PLID]:                         0x50000031
        [Subsystem]:                    BMC Firmware
        [Message]:                      An application had an internal failure
        [SRC]:                          BD8D1002
        [Commit Time]:                  02/25/2020  04:51:31
        [Sev]:                          Unrecoverable Error
        [CreatorID]:                    BMC

    Description of argument(s):
    option_string           A string of options which are to be processed by the peltool command.
    bsu_options             Options to be passed directly to bmc_execute_command. See its prolog for
                            details.
    """

    bsu_options = fa.args_to_objects(bsu_options)
    out_buf, stderr, rc = bsu.bmc_execute_command('peltool ' + option_string,
                                                  **bsu_options)
    out_buf = json.loads(out_buf)
    return out_buf
コード例 #5
0
def valid_init(var_name, *args, **kwargs):
    r"""
    Do initialization for variable validation and return var_name, args and kwargs.

    This function is to be called by all of the various validation functions in this module.

    This function is designed solely for use by other functions in this file.

    Description of argument(s):
    var_name                        The name of the variable to be validated.
    args                            The positional arguments to be passed to a validation function.
    kwargs                          The keyword arguments to be passed to a validation function.
    """

    var_value = valid_var_name(var_name)
    # Convert python string object definitions to objects (useful for robot callers).
    args = fa.args_to_objects(args)
    kwargs = fa.args_to_objects(kwargs)
    return var_value, args, kwargs
コード例 #6
0
def vpdtool(option_string, **bsu_options):
    r"""
    Run vpdtool on the BMC with the caller's option string and return the result.

    Example:

    ${vpd_results}=  vpd-tool -i
    Rprint Vars  vpd_results

    vpd_results:
      [/system/chassis/motherboard]:
        [PN]:                                         PN12345
        [SN]:                                         YL2E2D010000
        [LocationCode]:                               U78DA.ND1.       -P0
        [CC]:                                         2E2D
        [DR]:                                         SYSTEM BACKPLANE
        [FN]:                                         F191014
        [type]:                                       xyz.openbmc_project.Inventory.Item.Board.Motherboard
      [/system/chassis/motherboard/ebmc_card_bmc]:
        [PN]:                                         PN12345
        [SN]:                                         YL6B58010000
        [LocationCode]:                               U78DA.ND1.       -P0-C5
        [CC]:                                         6B58
        [DR]:                                         EBMC
        [FN]:                                         F191014
        [type]:                                       xyz.openbmc_project.Inventory.Item.Bmc

    Description of argument(s):
    option_string                   A string of options which are to be processed by the vpd-tool command.
    bsu_options                     Options to be passed directly to bmc_execute_command. See its prolog for
                                    details.
    """

    bsu_options = fa.args_to_objects(bsu_options)
    out_buf, stderr, rc = bsu.bmc_execute_command('vpd-tool ' + option_string,
                                                  **bsu_options)

    # Only return output if its not a VPD write command.
    if '-w' not in option_string:
        out_buf = json.loads(out_buf)
        if '-r' in option_string:
            return out_buf
        else:
            return out_buf[0]
コード例 #7
0
def pldmtool(option_string, parse_results=1, **bsu_options):
    r"""
    Run pldmtool on the BMC with the caller's option string and return the result.

    Example:

    ${pldm_results}=  Pldmtool  base GetPLDMTypes
    Rprint Vars  pldm_results

    pldm_results:
      [supported_types]:
        [raw]:
          [0]:                                        0
          [1]:                                        2
          [2]:                                        3
        [text]:
          [0]:                                        base
          [1]:                                        platform
          [2]:                                        bios

    Description of argument(s):
    option_string                   A string of options which are to be processed by the pldmtool command.
    parse_results                   Parse the pldmtool results and return a dictionary rather than the raw
                                    pldmtool output.
    bsu_options                     Options to be passed directly to bmc_execute_command.  See its prolog for
                                    details.
    """

    # This allows callers to specify arguments in python style (e.g. print_out=1 vs. print_out=${1}).
    bsu_options = fa.args_to_objects(bsu_options)

    stdout, stderr, rc = bsu.bmc_execute_command('pldmtool ' + option_string,
                                                 **bsu_options)

    if parse_results:
        result = vf.key_value_outbuf_to_dict(stdout)
        if 'supported_types' in result:
            # 'supported types' begins like this:
            # 0(base) 2(platform) 3(bios)
            # Parsing it to look like it does in the example above.
            supported_types = {'raw': [], 'text': []}
            for entry in result['supported_types'].split(" "):
                record = entry.split("(")
                supported_types['raw'].append(record[0])
                supported_types['text'].append(record[1].rstrip(")"))
            result['supported_types'] = supported_types

        elif 'supported_commands' in result:
            commands = result['supported_commands'].split(":")[0].split(" ")
            return commands

        elif 'yyyy-mm-dd_hh' in result:
            # Date & Time :
            # YYYY-MM-DD HH:MM:SS - 2020-02-24 06:44:16
            return result['yyyy-mm-dd_hh'].split(' - ')[1]

        # Simplfying dict output for GetPDR with type PDREntityAssociation.
        # Example :

        # pldmtool platform GetPDR -d 10
        # Entity Association
        # nextRecordHandle: 0
        # responseCount: 56
        # recordHandle: 10
        # PDRHeaderVersion: 1
        # PDRType: 15
        # recordChangeNumber: 0
        # dataLength: 46
        # containerID: 1
        # associationType: Physical
        # containerEntityType: System Board
        # containerEntityInstanceNumber: 1
        # containerEntityContainerID: 0
        # containedEntityCount: 6
        # containedEntityType[1]: Chassis front panel board (control panel)
        # containedEntityInstanceNumber[1]: 1
        # containedEntityContainerID[1]: 1
        # containedEntityType[2]: Chassis front panel board (control panel)
        # containedEntityInstanceNumber[2]: 2
        # containedEntityContainerID[2]: 1
        elif 'containerentitycontainerid' in result:
            dict_data1, dict_data2 = vf.split_dict_on_key(
                'containerentitycontainerid', result)
            return dict_data1

        elif 'entitytype' in result:
            # Example :
            # entityType: 24576(OEM)
            # Note: OEM type number is dynamic
            if 'OEM' in result['entitytype']:
                result['entitytype'] = 'OEM'

        # Collect bios strings from bios string table in to list.
        # Example output for pldmtool GetBIOSTable --type stringTable
        # PLDM StringTable:
        # BIOSStringHandle : BIOSString
        # 0 : Allowed
        # 1 : Disabled
        # 2 : Enabled
        elif 'pldm_stringtable' in result:
            result.pop('pldm_stringtable')
            result.pop('biosstringhandle')
            bios_string_list = []
            for data in result:
                bios_string_list.append(result[data])
            # Example for bios_string_list:
            # bios_string_list = ['Allowed', 'Disabled', 'Enabled']
            return bios_string_list

        # Check if parameter pldm_attributetable/pldm_attributevaluetable present for
        # pldmtool GetBIOSTable --type AttributeTable/AttributeValueTable.
        # Note: Output for AttributeTable/AttributeValueTable is huge and verification of
        #       table content is not available.
        elif 'pldm_attributetable' in result:
            result['pldm_attributetable'] = True
            return result
        elif 'pldm_attributevaluetable' in result:
            result['pldm_attributevaluetable'] = True
            return result

        return result

    return stdout
コード例 #8
0
def pldmtool(option_string, parse_results=1, **bsu_options):
    r"""
    Run pldmtool on the BMC with the caller's option string and return the result.

    Example:

    ${pldm_results}=  Pldmtool  base GetPLDMTypes
    Rprint Vars  pldm_results

    pldm_results:
      [request_message]:                              08 01 80 00 04
      [success_in_creating_the_socket]:               RC = 3
      [success_in_connecting_to_socket]:              RC = 0
      [success_in_sending_message_type_as_pldm_to_mctp]:RC = 0
      [write_to_socket_successful]:                   RC = 5
      [total_length]:                                 14
      [loopback_response_message]:                    08 01 80 00 04
      [on_first_recv(),response_==_request]:          RC = 0
      [shutdown_socket_successful]:                   RC = 0
      [response_message]:                             08 01 00 00 04 00 0d 00 00 00 00 00 00 00
      [supported_types]:
        [raw]:
          [0]:                                        0
          [1]:                                        2
          [2]:                                        3
        [text]:
          [0]:                                        base
          [1]:                                        platform
          [2]:                                        bios

    Description of argument(s):
    option_string                   A string of options which are to be processed by the pldmtool command.
    parse_results                   Parse the pldmtool results and return a dictionary rather than the raw
                                    pldmtool output.
    bsu_options                     Options to be passed directly to bmc_execute_command.  See its prolog for
                                    details.
    """

    # This allows callers to specify arguments in python style (e.g. print_out=1 vs. print_out=${1}).
    bsu_options = fa.args_to_objects(bsu_options)

    stdout, stderr, rc = bsu.bmc_execute_command('pldmtool ' + option_string, **bsu_options)
    if parse_results:
        # Remove linefeeds following colons.
        stdout = re.sub(":\n", ":", stdout)
        # Remove first line (e.g. "Encode request successfully").
        stdout = re.sub("^.*\\n", "", stdout)
        result = vf.key_value_outbuf_to_dict(stdout)
        if 'supported_types' in result:
            # 'supported types' begins like this:
            # 0(base) 2(platform) 3(bios)
            # Parsing it to look like it does in the example above.
            supported_types = {'raw': [], 'text': []}
            for entry in result['supported_types'].split(" "):
                record = entry.split("(")
                supported_types['raw'].append(record[0])
                supported_types['text'].append(record[1].rstrip(")"))
            result['supported_types'] = supported_types

        if 'date_&_time' in result:
            return result['yyyy-mm-dd_hh'].split(' - ')[1]

        return result

    return stdout