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