xref: /openbmc/openbmc-test-automation/redfish/systems/test_sensor_monitoring.robot (revision 409df05d4b10b9a8c81e282da8fef0199db5bdea)
13a537b60STony Lee*** Settings ***
23a537b60STony LeeDocumentation    Test Redfish sensor monitoring.
33a537b60STony Lee
43a537b60STony LeeResource         ../../lib/resource.robot
53a537b60STony LeeResource         ../../lib/bmc_redfish_resource.robot
63a537b60STony LeeResource         ../../lib/bmc_redfish_utils.robot
73a537b60STony LeeLibrary          ../../lib/gen_robot_print.py
83a537b60STony Lee
93a537b60STony LeeTest Setup       Test Setup Execution
103a537b60STony LeeTest Teardown    Test Teardown Execution
113a537b60STony Lee
123a537b60STony Lee*** Variables ***
133a537b60STony Lee
143a537b60STony Lee@{INVALID_SENSORS}
153a537b60STony Lee${OPENBMC_CONN_METHOD}  ssh
163a537b60STony Lee${IPMI_COMMAND}         Inband
173a537b60STony Lee
183a537b60STony Lee** Test Cases **
193a537b60STony Lee
203a537b60STony LeeVerify Sensor Monitoring
213a537b60STony Lee    [Documentation]  Verify the redfish sensor monitoring according to the BMC
223a537b60STony Lee    ...              expected SDR table.
233a537b60STony Lee    [Tags]  Verify_Sensor_Monitoring
243a537b60STony Lee
253a537b60STony Lee    # Check whether the expected sensors are present in the Redfish request.
263a537b60STony Lee    # Check whether the sensors's 'Health' is 'OK' and the 'State' is 'Enabled'.
273a537b60STony Lee    # Check sensor reading is not equal to null.
283a537b60STony Lee
293a537b60STony Lee    ${resp}=  Redfish.Get  /redfish/v1/Chassis/${CHASSIS_ID}
303a537b60STony Lee    ...  valid_status_codes=[${HTTP_OK}]
313a537b60STony Lee
323a537b60STony Lee   Should Be Equal As Strings  ${resp.dict['Sensors']['@odata.id']}
333a537b60STony Lee   ...  /redfish/v1/Chassis/${CHASSIS_ID}/Sensors
343a537b60STony Lee   Should Be Equal As Strings  ${resp.dict['Thermal']['@odata.id']}
353a537b60STony Lee   ...  /redfish/v1/Chassis/${CHASSIS_ID}/Thermal
363a537b60STony Lee   Should Be Equal As Strings  ${resp.dict['Power']['@odata.id']}
373a537b60STony Lee   ...  /redfish/v1/Chassis/${CHASSIS_ID}/Power
383a537b60STony Lee
393a537b60STony Lee    # Check sensors in /redfish/v1/Chassis/{ChassisId}/Power
403a537b60STony Lee    ${resp}=  Redfish.Get  /redfish/v1/Chassis/${CHASSIS_ID}/Power
413a537b60STony Lee    ...  valid_status_codes=[${HTTP_OK}]
423a537b60STony Lee
433a537b60STony Lee    Check Sensors Present  ${resp.dict['Voltages']}  Voltage
443a537b60STony Lee    Check Sensor Status And Reading Via Sensor Info
453a537b60STony Lee    ...  ${resp.dict['Voltages']}  ReadingVolts
463a537b60STony Lee
473a537b60STony Lee    # Check sensors in /redfish/v1/Chassis/{ChassisId}/Thermal
483a537b60STony Lee    ${resp}=  Redfish.Get  /redfish/v1/Chassis/${CHASSIS_ID}/Thermal
493a537b60STony Lee    ...  valid_status_codes=[${HTTP_OK}]
503a537b60STony Lee
513a537b60STony Lee    Check Sensors Present  ${resp.dict['Temperatures']}  Temperature
523a537b60STony Lee    Check Sensors Present  ${resp.dict['Fans']}  Fans
533a537b60STony Lee
543a537b60STony Lee    Check Sensor Status And Reading Via Sensor Info
553a537b60STony Lee    ...  ${resp.dict['Temperatures']}  ReadingCelsius
563a537b60STony Lee    Check Sensor Status And Reading Via Sensor Info
573a537b60STony Lee    ...  ${resp.dict['Fans']}  Reading
583a537b60STony Lee
593a537b60STony Lee    # Check sensors in
603a537b60STony Lee    # /redfish/v1/Chassis/{ChassisId}/Sensors/{Sensor Name}
613a537b60STony Lee    ${expected_current_power_sensor_name_list}=  Set Variable
623a537b60STony Lee    ...  ${redfish_sensor_info_map['${OPENBMC_MODEL}']['Current_Power']}
633a537b60STony Lee
643a537b60STony Lee    FOR  ${sensor_name}  IN  @{expected_current_power_sensor_name_list}
653a537b60STony Lee        Check Sensor Status And Reading Via Sensor Name  ${sensor_name}
663a537b60STony Lee    END
673a537b60STony Lee
683a537b60STony Lee    Rprint Vars  INVALID_SENSORS
693a537b60STony Lee
703a537b60STony Lee    ${error_msg}=   Evaluate  ", ".join(${INVALID_SENSORS})
713a537b60STony Lee    Should Be Empty  ${INVALID_SENSORS}
723a537b60STony Lee    ...  msg=Test fail, invalid sensors are ${error_msg}.
733a537b60STony Lee
743a537b60STony Lee
753a537b60STony Lee*** Keywords ***
763a537b60STony Lee
773a537b60STony LeeTest Teardown Execution
783a537b60STony Lee    [Documentation]  Do the post test teardown.
793a537b60STony Lee
803a537b60STony Lee    Run Keyword And Ignore Error  Redfish.Logout
813a537b60STony Lee
823a537b60STony Lee
833a537b60STony LeeTest Setup Execution
843a537b60STony Lee    [Documentation]  Do the test setup.
853a537b60STony Lee
863a537b60STony Lee    Required Parameters For Sensor Monitoring
873a537b60STony Lee    Redfish.Login
883a537b60STony Lee
893a537b60STony Lee
903a537b60STony LeeRequired Parameters For Sensor Monitoring
913a537b60STony Lee    [Documentation]  Check if required parameters are provided via command line.
923a537b60STony Lee
933a537b60STony Lee    Should Not Be Empty   ${OS_HOST}
943a537b60STony Lee    Should Not Be Empty   ${OS_USERNAME}
953a537b60STony Lee    Should Not Be Empty   ${OS_PASSWORD}
963a537b60STony Lee    Run Keyword If  '${OPENBMC_CONN_METHOD}' == 'ssh'
973a537b60STony Lee    ...    Should Not Be Empty   ${OPENBMC_HOST}
983a537b60STony Lee    ...  ELSE IF  '${OPENBMC_CONN_METHOD}' == 'telnet'
993a537b60STony Lee    ...    Should Not Be Empty   ${OPENBMC_SERIAL_HOST}
1003a537b60STony Lee    Should Not Be Empty   ${OPENBMC_MODEL}
1013a537b60STony Lee
1023a537b60STony Lee
1033a537b60STony LeeGet Sensors Name List From Redfish
1043a537b60STony Lee    [Documentation]  Get sensors name list from redfish.
1053a537b60STony Lee    [Arguments]  ${sensor_info_list}
1063a537b60STony Lee    # Description of arguments:
1073a537b60STony Lee    # sensor_info_list    A list of a specified sensor info return by a redfish
1083a537b60STony Lee    #                     request.
1093a537b60STony Lee
1103a537b60STony Lee    # An example of a sensor redfish request:
1113a537b60STony Lee    # /redfish/v1/Chassis/${CHASSIS_ID}/Power
1123a537b60STony Lee    # {
1133a537b60STony Lee    #     ...
1143a537b60STony Lee    #     "Voltages": [
1153a537b60STony Lee    #     {
1163a537b60STony Lee    #     "@odata.id": "/redfish/v1/Chassis/${CHASSIS_ID}/Power#/Voltages/0",
1173a537b60STony Lee    #     "@odata.type": "#Power.v1_0_0.Voltage",
1183a537b60STony Lee    #     "LowerThresholdCritical": 1.14,
1193a537b60STony Lee    #     "LowerThresholdNonCritical": 1.14,
1203a537b60STony Lee    #     "MaxReadingRange": 2.0,
1213a537b60STony Lee    #     "MemberId": "Output_Voltage",
1223a537b60STony Lee    #     "MinReadingRange": 0.0,
1233a537b60STony Lee    #     "Name": "Output Voltage",
1243a537b60STony Lee    #     "ReadingVolts": 1.176,
1253a537b60STony Lee    #     "Status": {
1263a537b60STony Lee    #         "Health": "OK",
1273a537b60STony Lee    #         "State": "Enabled"
1283a537b60STony Lee    #     },
1293a537b60STony Lee    #     "UpperThresholdCritical": 1.21,
1303a537b60STony Lee    #     "UpperThresholdNonCritical": 1.21
1313a537b60STony Lee    #     }
1323a537b60STony Lee    #     ...
1333a537b60STony Lee    # }
1343a537b60STony Lee
1353a537b60STony Lee    @{sensor_name_list}=  Create List
1363a537b60STony Lee    FOR  ${sensor_info}  IN  @{sensor_info_list}
1373a537b60STony Lee        Append To List  ${sensor_name_list}  ${sensor_info['MemberId']}
1383a537b60STony Lee    END
1393a537b60STony Lee
140*409df05dSGeorge Keishing    RETURN  ${sensor_name_list}
1413a537b60STony Lee
1423a537b60STony Lee
1433a537b60STony LeeCheck Sensor Status And Reading Via Sensor Name
1443a537b60STony Lee    [Documentation]  Check Sensor Status And Reading Via Sensor Name.
1453a537b60STony Lee    [Arguments]  ${sensor_name}
1463a537b60STony Lee    # Description of arguments:
1473a537b60STony Lee    # sensor_name    Sensor that should be present.
1483a537b60STony Lee
1493a537b60STony Lee    ${resp}=  Redfish.Get
1503a537b60STony Lee    ...  /redfish/v1/Chassis/${CHASSIS_ID}/Sensors/${sensor_name}
1513a537b60STony Lee    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}]
1523a537b60STony Lee
1533a537b60STony Lee    Run Keyword And Return If  '${resp.status}' == '${HTTP_NOT_FOUND}'
1543a537b60STony Lee    ...  Append To List  ${INVALID_SENSORS}  ${sensor_name}
1553a537b60STony Lee
1563a537b60STony Lee    ${condition_str}=  Catenate
1573a537b60STony Lee        ...  '${resp.dict['Status']['Health']}' != 'OK'
1583a537b60STony Lee        ...  or '${resp.dict['Status']['State']}' != 'Enabled'
1593a537b60STony Lee        ...  or ${resp.dict['Reading']} == ${null}
1603a537b60STony Lee
1613a537b60STony Lee    Run Keyword If  ${condition_str}
1623a537b60STony Lee    ...  Append To List  ${INVALID_SENSORS}  ${sensor_name}
1633a537b60STony Lee
1643a537b60STony Lee
1653a537b60STony LeeCheck Sensor Status And Reading Via Sensor Info
1663a537b60STony Lee    [Documentation]  Check Sensor Status And Reading Via Sensor Info.
1673a537b60STony Lee    [Arguments]  ${sensor_info_list}  ${reading_unit}
1683a537b60STony Lee    # Description of arguments:
1693a537b60STony Lee    # sensor_info_list  A list of a specified sensor info return by a redfish
1703a537b60STony Lee    #                   request.
1713a537b60STony Lee    # reading_unit      A string represents the reading value in sensor info
1723a537b60STony Lee    #                   return by a redfish request. It different between
1733a537b60STony Lee    #                   different sensor unit of sensor info.
1743a537b60STony Lee
1753a537b60STony Lee    FOR  ${sensor_info}  IN  @{sensor_info_list}
1763a537b60STony Lee        ${sensor}=  Set Variable  ${sensor_info['MemberId']}
1773a537b60STony Lee        ${condition_str}=  Catenate
1783a537b60STony Lee        ...  '${sensor_info['Status']['Health']}' != 'OK'
1793a537b60STony Lee        ...  or '${sensor_info['Status']['State']}' != 'Enabled'
1803a537b60STony Lee        ...  or ${sensor_info['${reading_unit}']} == ${null}
1813a537b60STony Lee
1823a537b60STony Lee        Run Keyword If  ${condition_str}
1833a537b60STony Lee        ...  Append To List  ${INVALID_SENSORS}  ${sensor_info['MemberId']}
1843a537b60STony Lee    END
1853a537b60STony Lee
1863a537b60STony Lee
1873a537b60STony LeeCheck Sensors Present
1883a537b60STony Lee    [Documentation]  Check that sensors are present as expected.
1893a537b60STony Lee    [Arguments]  ${sensor_info_list}  ${sensor_type}
1903a537b60STony Lee    # Description of arguments:
1913a537b60STony Lee    # sensor_info_list  A list of a specified sensor info return by a redfish
1923a537b60STony Lee    #                   request.
1933a537b60STony Lee    # sensor_type       A string represents the sensor category to be verified.
1943a537b60STony Lee
1953a537b60STony Lee    # An example table of expected sensors:
1963a537b60STony Lee    # redfish_sensor_info_map = {
1973a537b60STony Lee    #   ${OPENBMC_MODEL}:{
1983a537b60STony Lee    #       "Voltage":{
1993a537b60STony Lee    #           "Voltage0",
2003a537b60STony Lee    #           ...
2013a537b60STony Lee    #       },
2023a537b60STony Lee    #       "Temperature":{
2033a537b60STony Lee    #           "DIMM0",
2043a537b60STony Lee    #           ...
2053a537b60STony Lee    #       }
2063a537b60STony Lee    #       "Fans":{
2073a537b60STony Lee    #           "Fan0",
2083a537b60STony Lee    #           ...
2093a537b60STony Lee    #       }...
2103a537b60STony Lee    #   }
2113a537b60STony Lee    #}
2123a537b60STony Lee
2133a537b60STony Lee    ${curr_sensor_name_list}=  Get Sensors Name List From Redfish
2143a537b60STony Lee    ...  ${sensor_info_list}
2153a537b60STony Lee
2163a537b60STony Lee    ${expected_sensor_name_list}=  Set Variable
2173a537b60STony Lee    ...  ${redfish_sensor_info_map['${OPENBMC_MODEL}']['${sensor_type}']}
2183a537b60STony Lee
2193a537b60STony Lee    FOR  ${sensor_name}  IN  @{expected_sensor_name_list}
2203a537b60STony Lee        ${exist}=  Evaluate  '${sensor_name}' in ${curr_sensor_name_list}
2213a537b60STony Lee        Run Keyword If  '${exist}' == '${False}'
2223a537b60STony Lee        ...  Append To List  ${INVALID_SENSORS}  ${sensor_name}
2233a537b60STony Lee    END
224