xref: /openbmc/openbmc-test-automation/redfish/systems/test_sensor_monitoring.robot (revision b2a2d948d555cb6e5169b9f21d489a3b089b4387)
1*** Settings ***
2Documentation    Test Redfish sensor monitoring.
3
4Resource         ../../lib/resource.robot
5Resource         ../../lib/bmc_redfish_resource.robot
6Resource         ../../lib/bmc_redfish_utils.robot
7Library          ../../lib/gen_robot_print.py
8
9Test Setup       Test Setup Execution
10Test Teardown    Test Teardown Execution
11
12Test Tags        Sensor_Monitoring
13
14*** Variables ***
15
16@{INVALID_SENSORS}
17${OPENBMC_CONN_METHOD}  ssh
18${IPMI_COMMAND}         Inband
19
20** Test Cases **
21
22Verify Sensor Monitoring
23    [Documentation]  Verify the redfish sensor monitoring according to the BMC
24    ...              expected SDR table.
25    [Tags]  Verify_Sensor_Monitoring
26
27    # Check whether the expected sensors are present in the Redfish request.
28    # Check whether the sensors's 'Health' is 'OK' and the 'State' is 'Enabled'.
29    # Check sensor reading is not equal to null.
30
31    ${resp}=  Redfish.Get  /redfish/v1/Chassis/${CHASSIS_ID}
32    ...  valid_status_codes=[${HTTP_OK}]
33
34   Should Be Equal As Strings  ${resp.dict['Sensors']['@odata.id']}
35   ...  /redfish/v1/Chassis/${CHASSIS_ID}/Sensors
36   Should Be Equal As Strings  ${resp.dict['Thermal']['@odata.id']}
37   ...  /redfish/v1/Chassis/${CHASSIS_ID}/Thermal
38   Should Be Equal As Strings  ${resp.dict['Power']['@odata.id']}
39   ...  /redfish/v1/Chassis/${CHASSIS_ID}/Power
40
41    # Check sensors in /redfish/v1/Chassis/{ChassisId}/Power
42    ${resp}=  Redfish.Get  /redfish/v1/Chassis/${CHASSIS_ID}/Power
43    ...  valid_status_codes=[${HTTP_OK}]
44
45    Check Sensors Present  ${resp.dict['Voltages']}  Voltage
46    Check Sensor Status And Reading Via Sensor Info
47    ...  ${resp.dict['Voltages']}  ReadingVolts
48
49    # Check sensors in /redfish/v1/Chassis/{ChassisId}/Thermal
50    ${resp}=  Redfish.Get  /redfish/v1/Chassis/${CHASSIS_ID}/Thermal
51    ...  valid_status_codes=[${HTTP_OK}]
52
53    Check Sensors Present  ${resp.dict['Temperatures']}  Temperature
54    Check Sensors Present  ${resp.dict['Fans']}  Fans
55
56    Check Sensor Status And Reading Via Sensor Info
57    ...  ${resp.dict['Temperatures']}  ReadingCelsius
58    Check Sensor Status And Reading Via Sensor Info
59    ...  ${resp.dict['Fans']}  Reading
60
61    # Check sensors in
62    # /redfish/v1/Chassis/{ChassisId}/Sensors/{Sensor Name}
63    ${expected_current_power_sensor_name_list}=  Set Variable
64    ...  ${redfish_sensor_info_map['${OPENBMC_MODEL}']['Current_Power']}
65
66    FOR  ${sensor_name}  IN  @{expected_current_power_sensor_name_list}
67        Check Sensor Status And Reading Via Sensor Name  ${sensor_name}
68    END
69
70    Rprint Vars  INVALID_SENSORS
71
72    ${error_msg}=   Evaluate  ", ".join(${INVALID_SENSORS})
73    Should Be Empty  ${INVALID_SENSORS}
74    ...  msg=Test fail, invalid sensors are ${error_msg}.
75
76
77*** Keywords ***
78
79Test Teardown Execution
80    [Documentation]  Do the post test teardown.
81
82    Run Keyword And Ignore Error  Redfish.Logout
83
84
85Test Setup Execution
86    [Documentation]  Do the test setup.
87
88    Required Parameters For Sensor Monitoring
89    Redfish.Login
90
91
92Required Parameters For Sensor Monitoring
93    [Documentation]  Check if required parameters are provided via command line.
94
95    Should Not Be Empty   ${OS_HOST}
96    Should Not Be Empty   ${OS_USERNAME}
97    Should Not Be Empty   ${OS_PASSWORD}
98
99    IF  '${OPENBMC_CONN_METHOD}' == 'ssh'
100        Should Not Be Empty   ${OPENBMC_HOST}
101    ELSE IF  '${OPENBMC_CONN_METHOD}' == 'telnet'
102        Should Not Be Empty   ${OPENBMC_SERIAL_HOST}
103    END
104
105    Should Not Be Empty   ${OPENBMC_MODEL}
106
107
108Get Sensors Name List From Redfish
109    [Documentation]  Get sensors name list from redfish.
110    [Arguments]  ${sensor_info_list}
111    # Description of arguments:
112    # sensor_info_list    A list of a specified sensor info return by a redfish
113    #                     request.
114
115    # An example of a sensor redfish request:
116    # /redfish/v1/Chassis/${CHASSIS_ID}/Power
117    # {
118    #     ...
119    #     "Voltages": [
120    #     {
121    #     "@odata.id": "/redfish/v1/Chassis/${CHASSIS_ID}/Power#/Voltages/0",
122    #     "@odata.type": "#Power.v1_0_0.Voltage",
123    #     "LowerThresholdCritical": 1.14,
124    #     "LowerThresholdNonCritical": 1.14,
125    #     "MaxReadingRange": 2.0,
126    #     "MemberId": "Output_Voltage",
127    #     "MinReadingRange": 0.0,
128    #     "Name": "Output Voltage",
129    #     "ReadingVolts": 1.176,
130    #     "Status": {
131    #         "Health": "OK",
132    #         "State": "Enabled"
133    #     },
134    #     "UpperThresholdCritical": 1.21,
135    #     "UpperThresholdNonCritical": 1.21
136    #     }
137    #     ...
138    # }
139
140    @{sensor_name_list}=  Create List
141    FOR  ${sensor_info}  IN  @{sensor_info_list}
142        Append To List  ${sensor_name_list}  ${sensor_info['MemberId']}
143    END
144
145    RETURN  ${sensor_name_list}
146
147
148Check Sensor Status And Reading Via Sensor Name
149    [Documentation]  Check Sensor Status And Reading Via Sensor Name.
150    [Arguments]  ${sensor_name}
151    # Description of arguments:
152    # sensor_name    Sensor that should be present.
153
154    ${resp}=  Redfish.Get
155    ...  /redfish/v1/Chassis/${CHASSIS_ID}/Sensors/${sensor_name}
156    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}]
157
158    Run Keyword And Return If  '${resp.status}' == '${HTTP_NOT_FOUND}'
159    ...  Append To List  ${INVALID_SENSORS}  ${sensor_name}
160
161    ${condition_str}=  Catenate
162        ...  '${resp.dict['Status']['Health']}' != 'OK'
163        ...  or '${resp.dict['Status']['State']}' != 'Enabled'
164        ...  or ${resp.dict['Reading']} == ${null}
165
166    IF  ${condition_str}
167        Append To List  ${INVALID_SENSORS}  ${sensor_name}
168    END
169
170
171Check Sensor Status And Reading Via Sensor Info
172    [Documentation]  Check Sensor Status And Reading Via Sensor Info.
173    [Arguments]  ${sensor_info_list}  ${reading_unit}
174    # Description of arguments:
175    # sensor_info_list  A list of a specified sensor info return by a redfish
176    #                   request.
177    # reading_unit      A string represents the reading value in sensor info
178    #                   return by a redfish request. It different between
179    #                   different sensor unit of sensor info.
180
181    FOR  ${sensor_info}  IN  @{sensor_info_list}
182        ${sensor}=  Set Variable  ${sensor_info['MemberId']}
183        ${condition_str}=  Catenate
184        ...  '${sensor_info['Status']['Health']}' != 'OK'
185        ...  or '${sensor_info['Status']['State']}' != 'Enabled'
186        ...  or ${sensor_info['${reading_unit}']} == ${null}
187
188        IF  ${condition_str}
189            Append To List  ${INVALID_SENSORS}  ${sensor_info['MemberId']}
190        END
191    END
192
193
194Check Sensors Present
195    [Documentation]  Check that sensors are present as expected.
196    [Arguments]  ${sensor_info_list}  ${sensor_type}
197    # Description of arguments:
198    # sensor_info_list  A list of a specified sensor info return by a redfish
199    #                   request.
200    # sensor_type       A string represents the sensor category to be verified.
201
202    # An example table of expected sensors:
203    # redfish_sensor_info_map = {
204    #   ${OPENBMC_MODEL}:{
205    #       "Voltage":{
206    #           "Voltage0",
207    #           ...
208    #       },
209    #       "Temperature":{
210    #           "DIMM0",
211    #           ...
212    #       }
213    #       "Fans":{
214    #           "Fan0",
215    #           ...
216    #       }...
217    #   }
218    #}
219
220    ${curr_sensor_name_list}=  Get Sensors Name List From Redfish
221    ...  ${sensor_info_list}
222
223    ${expected_sensor_name_list}=  Set Variable
224    ...  ${redfish_sensor_info_map['${OPENBMC_MODEL}']['${sensor_type}']}
225
226    FOR  ${sensor_name}  IN  @{expected_sensor_name_list}
227        ${exist}=  Evaluate  '${sensor_name}' in ${curr_sensor_name_list}
228        IF  '${exist}' == '${False}'
229           Append To List  ${INVALID_SENSORS}  ${sensor_name}
230        END
231    END
232