xref: /openbmc/openbmc-test-automation/ipmi/test_ipmi_sensor.robot (revision 94041a34a992d9b5f6418a43e1cd5273a6d9f9b2)
1*** Settings ***
2Documentation     Validate IPMI sensor IDs using Redfish.
3
4Resource          ../lib/ipmi_client.robot
5Resource          ../lib/openbmc_ffdc.robot
6Resource          ../lib/boot_utils.robot
7Library           ../lib/ipmi_utils.py
8Variables         ../data/ipmi_raw_cmd_table.py
9
10Test Setup        Redfish.Login
11Test Teardown     Run Keywords  FFDC On Test Case Fail  AND
12...  Redfish.Logout
13
14Test Tags        IPMI_Sensor
15
16*** Variables ***
17
18${allowed_temp_diff}    ${2}
19${allowed_power_diff}   ${10}
20
21
22*** Test Cases ***
23Verify IPMI Temperature Readings using Redfish
24    [Documentation]  Verify temperatures from IPMI sensor reading command using Redfish.
25    [Tags]  Verify_IPMI_Temperature_Readings_using_Redfish
26    [Template]  Get Temperature Reading And Verify In Redfish
27
28    # command_type  sensor_id  member_id
29    IPMI            PCIE       PCIE
30    IPMI            Ambient    Ambient
31
32
33Verify DCMI Temperature Readings using Redfish
34    [Documentation]  Verify temperatures from DCMI sensor reading command using Redfish.
35    [Tags]  Verify_DCMI_Temperature_Readings_using_Redfish
36    [Template]  Get Temperature Reading And Verify In Redfish
37
38    # command_type  sensor_id  member_id
39    DCMI            PCIE       PCIE
40    DCMI            Ambient    Ambient
41
42
43Test Ambient Temperature Via IPMI
44    [Documentation]  Test ambient temperature via IPMI and verify using Redfish.
45    [Tags]  Test_Ambient_Temperature_Via_IPMI
46
47    # Example of IPMI dcmi get_temp_reading output:
48    #        Entity ID                       Entity Instance    Temp. Readings
49    # Inlet air temperature(40h)                      1               +22 C
50    # Inlet air temperature(40h)                      2               +23 C
51    # Inlet air temperature(40h)                      3               +22 C
52    # CPU temperature sensors(41h)                    0               +0 C
53    # Baseboard temperature sensors(42h)              1               +26 C
54    # Baseboard temperature sensors(42h)              2               +27 C
55
56    ${temp_reading}=  Run IPMI Standard Command  dcmi get_temp_reading -N 10
57    Should Contain  ${temp_reading}  Inlet air temperature
58    ...  msg="Unable to get inlet temperature via DCMI".
59
60    ${ambient_temp_line}=
61    ...  Get Lines Containing String  ${temp_reading}
62    ...  Inlet air temperature  case-insensitive
63
64    ${ambient_temp_line}=  Split To Lines  ${ambient_temp_line}
65    ${ipmi_temp_list}=  Create List
66    FOR  ${line}  IN  @{ambient_temp_line}
67        ${ambient_temp_ipmi}=  Set Variable  ${line.split('+')[1].strip(' C')}
68        Append To List  ${ipmi_temp_list}  ${ambient_temp_ipmi}
69    END
70    ${list_length}=  Get Length  ${ipmi_temp_list}
71
72    # Getting temperature readings from Redfish.
73    ${ambient_temp_redfish}=  Get Temperature Reading From Redfish  Ambient
74    ${ambient_temp_redfish}=  Get Dictionary Values  ${ambient_temp_redfish}  sort_keys=True
75    FOR  ${index}  IN RANGE  ${list_length}
76        ${ipmi_redfish_temp_diff}=
77        ...  Evaluate  abs(${ambient_temp_redfish[${index}]} - ${ipmi_temp_list[${index}]})
78
79        Should Be True  ${ipmi_redfish_temp_diff} <= ${allowed_temp_diff}
80        ...  msg=Ambient temperature above allowed threshold ${allowed_temp_diff}.
81    END
82
83
84Test Power Reading Via IPMI With Host Off
85    [Documentation]  Verify power reading via IPMI with host in off state
86    [Tags]  Test_Power_Reading_Via_IPMI_With_Host_Off
87
88    Redfish Power Off  stack_mode=skip
89
90    ${ipmi_reading}=  Get IPMI Power Reading
91
92    Should Be Equal  ${ipmi_reading['instantaneous_power_reading']}  0
93    ...  msg=Power reading not zero when power is off.
94
95
96Test Power Reading Via IPMI With Host Booted
97    [Documentation]  Test power reading via IPMI with host in booted state and
98    ...  verify using Redfish.
99    [Tags]  Test_Power_Reading_Via_IPMI_With_Host_Booted
100
101    IPMI Power On  stack_mode=skip
102
103    Wait Until Keyword Succeeds  2 min  30 sec  Verify Power Reading Using IPMI And Redfish
104
105
106Test Baseboard Temperature Via IPMI
107    [Documentation]  Test baseboard temperature via IPMI and verify using Redfish.
108    [Tags]  Test_Baseboard_Temperature_Via_IPMI
109
110    # Example of IPMI dcmi get_temp_reading output:
111    #        Entity ID                       Entity Instance    Temp. Readings
112    # Inlet air temperature(40h)                      1               +22 C
113    # Inlet air temperature(40h)                      2               +23 C
114    # Inlet air temperature(40h)                      3               +22 C
115    # CPU temperature sensors(41h)                    0               +0 C
116    # Baseboard temperature sensors(42h)              1               +26 C
117    # Baseboard temperature sensors(42h)              2               +27 C
118
119    ${temp_reading}=  Run IPMI Standard Command  dcmi get_temp_reading -N 10
120    Should Contain  ${temp_reading}  Baseboard temperature sensors
121    ...  msg="Unable to get baseboard temperature via DCMI".
122    ${baseboard_temp_lines}=
123    ...  Get Lines Containing String  ${temp_reading}
124    ...  Baseboard temperature  case-insensitive=True
125    ${lines}=  Split To Lines  ${baseboard_temp_lines}
126
127    ${ipmi_temp_list}=  Create List
128    FOR  ${line}  IN  @{lines}
129        ${baseboard_temp_ipmi}=  Set Variable  ${line.split('+')[1].strip(' C')}
130        Append To List  ${ipmi_temp_list}  ${baseboard_temp_ipmi}
131    END
132    ${list_length}=  Get Length  ${ipmi_temp_list}
133
134    # Getting temperature readings from Redfish.
135    ${baseboard_temp_redfish}=  Get Temperature Reading From Redfish  PCIE
136    ${baseboard_temp_redfish}=  Get Dictionary Values  ${baseboard_temp_redfish}  sort_keys=True
137
138    FOR  ${index}  IN RANGE  ${list_length}
139        ${baseboard_temp_diff}=  Evaluate  abs(${baseboard_temp_redfish[${index}]} - ${ipmi_temp_list[${index}]})
140        Should Be True
141        ...  ${baseboard_temp_diff} <= ${allowed_temp_diff}
142        ...  msg=Baseboard temperature above allowed threshold ${allowed_temp_diff}.
143    END
144
145Test Power Reading Via IPMI Raw Command
146    [Documentation]  Test power reading via IPMI raw command and verify
147    ...  using Redfish.
148    [Tags]  Test_Power_Reading_Via_IPMI_Raw_Command
149
150    IPMI Power On  stack_mode=skip
151
152    Wait Until Keyword Succeeds  2 min  30 sec  Verify Power Reading Via Raw Command
153
154
155Verify CPU Present
156    [Documentation]  Verify the IPMI sensor for CPU present using Redfish.
157    [Tags]  Verify_CPU_Present
158    [Template]  Set Present Bit Via IPMI and Verify Using Redfish
159
160    # component  state
161    cpu          Enabled
162
163
164Verify CPU Not Present
165    [Documentation]  Verify the IPMI sensor for CPU not present using Redfish.
166    [Tags]  Verify_CPU_Not_Present
167    [Template]  Set Present Bit Via IPMI and Verify Using Redfish
168
169    # component  state
170    cpu          Absent
171
172
173Verify GPU Present
174    [Documentation]  Verify the IPMI sensor for GPU present using Redfish.
175    [Tags]  Verify_GPU_Present
176    [Template]  Set Present Bit Via IPMI and Verify Using Redfish
177
178    # sensor_id  component
179    0xC5         gv100card0
180
181
182Verify GPU Not Present
183    [Documentation]  Verify the IPMI sensor for GPU not present using Redfish.
184    [Tags]  Verify_GPU_Not_Present
185    [Template]  Set Present Bit Via IPMI and Verify Using Redfish
186
187    # sensor_id  component
188    0xC5         gv100card0
189
190
191Test Sensor Threshold Via IPMI
192    [Documentation]  Test sensor threshold via IPMI and verify using Redfish.
193    [Tags]  Test_Sensor_Threshold_Via_IPMI
194    [Template]  Verify Power Supply Sensor Threshold
195
196    # threshold_id             component
197    Upper Non-Critical         UpperThresholdNonCritical
198    Upper Critical             UpperThresholdCritical
199    Lower Non-Critical         LowerThresholdNonCritical
200    Lower Critical             LowerThresholdCritical
201
202
203*** Keywords ***
204
205Get Temperature Reading And Verify In Redfish
206    [Documentation]  Get IPMI or DCMI sensor reading and verify in Redfish.
207    [Arguments]  ${command_type}  ${sensor_id}  ${member_id}
208
209    # Description of argument(s):
210    # command_type  Type of command used to get sensor data (eg. IPMI, DCMI).
211    # sensor_id     Sensor id used to get reading in IPMI or DCMI.
212    # member_id     Member id of sensor data in Redfish.
213
214    ${ipmi_value}=  Set Variable If  '${command_type}' == 'IPMI'  Get IPMI Sensor Reading  ${sensor_id}
215    ...  ELSE  Get DCMI Sensor Reading  ${sensor_id}
216
217    ${redfish_value}=  Get Temperature Reading From Redfish  ${member_id}
218
219    ${keys}=  Get Dictionary Keys  ${ipmi_value}
220    FOR  ${index}  IN  @{keys}
221        ${value_diff}=  Evaluate  abs(${redfish_value["${index}"]} - ${ipmi_value["${index}"]})
222        Should Be True  ${value_diff} <= ${allowed_temp_diff}
223    END
224
225
226
227Get IPMI Sensor Reading
228    [Documentation]  Get IPMI sensor readings as a dictionary.
229    [Arguments]  ${sensor_id}
230
231    # Description of argument(s):
232    # sensor_id     Sensor id used to get reading in IPMI.
233
234    ${sensor_list}=  Get Available Sensors  ${sensor_id}
235    ${sensor_value_dict}=  Create Dictionary
236
237    FOR  ${ids}  IN  @{sensor_list}
238        ${data}=  Run IPMI Standard Command  sensor reading ${ids}
239
240        # Example reading:
241        # PCIE_0_Temp      | 5Ch | ok  | 41.1 | 27 degrees C
242
243        ${sensor_key}=  Set Variable  ${data.split('| ')[0].strip()}
244        ${sensor_value}=  Set Variable  ${data.split('| ')[1].strip()}
245        Set To Dictionary  ${sensor_value_dict}  ${sensor_key}  ${sensor_value}
246    END
247
248    RETURN  ${sensor_value_dict}
249
250
251Get DCMI Sensor Reading
252    [Documentation]  Get DCMI sensor readings as a dictionary.
253    [Arguments]  ${sensor_id}
254
255    # Description of argument(s):
256    # sensor_id     Sensor id used to get reading in DCMI.
257
258    ${data}=  Run IPMI Standard Command  dcmi sensors
259    ${sensor_data}=  Get Lines Containing String  ${data}  ${sensor_id}  case_insensitive
260    ${sensor_lines}=  Split To Lines  ${sensor_data}
261
262    # Example reading:
263    # Record ID 0x005c: PCIE_0_Temp      | 27 degrees C      | ok
264
265    ${sensor_value_dict}=  Create Dictionary
266
267    FOR  ${line}  IN  @{sensor_lines}
268        ${sensor}=  Set Variable  ${line.split(' | ')}
269        ${sensor_key}=  Set Variable  ${sensor[0].split(':')[1].strip()}
270        ${sensor_value}=  Set Variable  ${sensor[1].split()[0].strip()}
271        ${contains}=  Evaluate  """disabled""" in "${sensor_value}"
272
273        IF  "${contains}" != """True"""
274            Set To Dictionary  ${sensor_value_dict}  ${sensor_key}  ${sensor_value}
275        END
276    END
277
278    RETURN  ${sensor_value_dict}
279
280
281Get Temperature Reading From Redfish
282    [Documentation]  Get temperature reading from Redfish.
283    [Arguments]  ${member_id}
284
285    # Description of argument(s):
286    # member_id    Member id of temperature.
287
288    @{thermal_uri}=  redfish_utils.Get Member List  /redfish/v1/Chassis/
289    @{redfish_readings}=  redfish_utils.Get Attribute
290    ...  ${thermal_uri[0]}/${THERMAL_METRICS}  TemperatureReadingsCelsius
291
292
293    # Example of Baseboard temperature via Redfish
294
295    # "@odata.id": "/redfish/v1/Chassis/chassis/ThermalSubsystem/ThermalMetrics",
296    # "@odata.type": "#ThermalMetrics.v1_0_0.ThermalMetrics",
297    # "Id": "ThermalMetrics",
298    # "Name": "Chassis Thermal Metrics",
299    # "TemperatureReadingsCelsius": [
300    # {
301    # "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/PCIE_0_Temp",
302    # "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/PCIE_0_Temp",
303    # "DeviceName": "PCIE_0_Temp",
304    # "Reading": 23.75
305    # },
306
307    ${redfish_value_dict}=  Create Dictionary
308    FOR  ${data}  IN  @{redfish_readings}
309        ${keys}=  Get Dictionary Keys  ${data}
310        ${reading}=  Set Variable  ${data}[Reading]
311        ${is_device_name_present}=  Evaluate  "DeviceName" in @{keys}
312        IF  ${is_device_name_present}
313            ${contains}=  Evaluate  "${member_id}" in """${data}[DeviceName]"""
314            IF  "${contains}" == "True"
315                Set To Dictionary  ${redfish_value_dict}  ${data}[DeviceName]  ${reading}
316            END
317        ELSE
318            ${data_source_id}=  Evaluate  ("${data}[DataSourceUri]").split('temperature_')
319            # Example format:
320            #
321            # {
322            #  "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/temperature_dimm17_dram_temp",
323            #  "Reading": 32.0
324            # }
325            ${contains}=  Evaluate  "${member_id}" in "${data_source_id[1]}"
326            IF  ${contains}
327               Set To Dictionary  ${redfish_value_dict}  ${data_source_id[1]}  ${reading}
328            END
329        END
330    END
331
332    RETURN  ${redfish_value_dict}
333
334
335Verify Power Reading Using IPMI And Redfish
336    [Documentation]  Verify power reading using IPMI and Redfish.
337
338    # Example of power reading command output via IPMI.
339    # Instantaneous power reading:                   235 Watts
340    # Minimum during sampling period:                235 Watts
341    # Maximum during sampling period:                235 Watts
342    # Average power reading over sample period:      235 Watts
343    # IPMI timestamp:                                Thu Jan  1 00:00:00 1970
344    # Sampling period:                               00000000 Seconds.
345    # Power reading state is:                        deactivated
346
347    ${ipmi_reading}=  Get IPMI Power Reading
348    ${redfish_power_reading}=  redfish_utils.Get Attribute
349    ...  /redfish/v1/Chassis/${CHASSIS_ID}/Sensors/power_total_power  Reading
350
351    ${ipmi_redfish_power_diff}=
352    ...  Evaluate  abs(${redfish_power_reading} - ${ipmi_reading['instantaneous_power_reading']})
353    Should Be True  ${ipmi_redfish_power_diff} <= ${allowed_power_diff}
354    ...  msg=Power reading above allowed threshold ${allowed_power_diff}.
355
356
357Verify Power Reading Via Raw Command
358    [Documentation]  Get dcmi power reading via IPMI raw command.
359
360    ${ipmi_raw_output}=  Run IPMI Standard Command
361    ...  raw ${IPMI_RAW_CMD['power_reading']['Get'][0]}
362
363    ${power_reading_ipmi}=  Set Variable  ${ipmi_raw_output.split()[1]}
364    ${power_reading_ipmi}=
365    ...  Convert To Integer  0x${power_reading_ipmi}
366
367    #  Example of power reading via Redfish
368    #  "@odata.id": "/redfish/v1/Chassis/chassis/Power#/PowerControl/0",
369    #  "@odata.type": "#Power.v1_0_0.PowerControl",
370    #  "MemberId": "0",
371    #  "Name": "Chassis Power Control",
372    #  "PowerConsumedWatts": 145.0,
373
374    ${power}=  Redfish.Get Properties  /redfish/v1/Chassis/${CHASSIS_ID}/Power
375    ${redfish_reading}=  Set Variable  ${power['PowerControl'][0]['PowerConsumedWatts']}
376
377    ${ipmi_redfish_power_diff}=
378    ...  Evaluate  abs(${redfish_reading} - ${power_reading_ipmi})
379
380    Should Be True  ${ipmi_redfish_power_diff} <= ${allowed_power_diff}
381    ...  msg=Power reading above allowed threshold ${allowed_power_diff}.
382
383
384Set Present Bit Via IPMI and Verify Using Redfish
385    [Documentation]  Set present bit of sensor via IPMI and verify using Redfish.
386    [Arguments]  ${component}  ${status}
387
388    # Description of argument(s):
389    # component    The Redfish component of IPMI sensor.
390    # status  Status of the bit to be set(e.g. Absent, Present).
391
392    ${sensor_list}=  Get Available Sensors  ${component}
393    ${sensor_name}=  Set Variable  ${sensor_list[0]}
394    ${sensor_id}=  Get Sensor Id For Sensor  ${sensor_name}
395
396     IF  '${status}' == 'Absent'
397         Run IPMI Command
398         ...  0x04 0x30 ${sensor_id} 0xa9 0x00 0x00 0x00 0x80 0x00 0x00 0x20 0x00
399     ELSE IF  '${status}' == 'Enabled'
400         Run IPMI Command
401         ...  0x04 0x30 ${sensor_id} 0xa9 0x00 0x80 0x00 0x00 0x00 0x00 0x20 0x00
402     END
403
404     # Redfish cpu components have "-" instead of "_" (e.g.: dcm0-cpu0).
405     ${cpu_name}=  Replace String  ${sensor_name}  _  -
406     ${sensor_properties}=  Redfish.Get Properties  /redfish/v1/Systems/${SYSTEM_ID}/Processors/${cpu_name}
407
408     #  Example of CPU state via Redfish
409
410     # "ProcessorType": "CPU",
411     # "SerialNumber": "YA1936422499",
412     # "Socket": "",
413     # "SparePartNumber": "F210110",
414     # "Status": {
415     # "Health": "OK",
416     # "State": "Absent"
417     # }
418
419     Should Be True  '${sensor_properties['Status']['State']}' == '${status}'
420
421
422Verify Power Supply Sensor Threshold
423    [Documentation]  Get power supply sensor threshold value via IPMI and verify using Redfish.
424    [Arguments]  ${ipmi_threshold_id}  ${redfish_threshold_id}
425
426    # Description of argument(s):
427    # ipmi_threshold_id       The sensor threshold component of IPMI sensor.
428    # redfish_threshold_id    The sensor threshold component of Redfish sensor.
429
430
431    #  Example of ipmi sensor output
432    # Locating sensor record...
433    # Sensor ID              : ps0_input_voltag (0xf7)
434    # Entity ID             : 10.19
435    # Sensor Type (Threshold)  : Voltage
436    # Sensor Reading        : 208 (+/- 0) Volts
437    # Status                : ok
438    # Lower Non-Recoverable : na
439    # Lower Critical        : 180.000
440    # Lower Non-Critical    : 200.000
441    # Upper Non-Critical    : 290.000
442    # Upper Critical        : 300.000
443    # Upper Non-Recoverable : na
444    # Positive Hysteresis   : Unspecified
445    # Negative Hysteresis   : Unspecified
446
447
448    ${ipmi_sensor_output}=  Run External IPMI Standard Command  sensor get ps0_input_voltag
449    ${ipmi_threshold_output}=  Get Lines Containing String  ${ipmi_sensor_output}  ${ipmi_threshold_id}
450    ${ipmi_threshold_reading}=  Fetch From Right  ${ipmi_threshold_output}  :${SPACE}
451
452    ${ipmi_threshold_reading}=  Set Variable If  '${ipmi_threshold_reading}' == 'na'
453    ...  ${0}  ${ipmi_threshold_reading}
454
455    #  Example of redfish sensor output
456    # "@odata.id": "/redfish/v1/Chassis/chassis/Power#/Voltages/0",
457    # "@odata.type": "#Power.v1_0_0.Voltage",
458    # "LowerThresholdCritical": 180.0,
459    # "LowerThresholdNonCritical": 200.0,
460    # "MaxReadingRange": 0.0,
461    # "MemberId": "ps0_input_voltage",
462    # "MinReadingRange": 0.0,
463    # "Name": "ps0 input voltage",
464    # "ReadingVolts": 209.5,
465    # "Status": {
466    # "Health": "OK",
467    # "State": "Enabled"
468    # },
469    # "UpperThresholdCritical": 300.0,
470    # "UpperThresholdNonCritical": 290.0
471
472    @{redfish_readings}=  Redfish.Get Attribute  /redfish/v1/Chassis/${CHASSIS_ID}/Power  Voltages
473    FOR  ${data}  IN  @{redfish_readings}
474        IF  '${data}[MemberId]' == 'ps0_input_voltage'
475            Should Be Equal As Numbers  ${data['${redfish_threshold_id}']}  ${ipmi_threshold_reading}
476        END
477    END
478
479
480Get Available Sensors
481    [Documentation]  Get all the available sensors for the required component.
482    ...  Returns a list of available sensors.
483    [Arguments]  ${sensor_component}
484
485    # Description of argument(s):
486    # sensor_component     sensor component name.(e.g.:cpu)
487
488    ${resp}=  Run IPMI Standard Command  sdr elist
489    ${sensor_list}=  Create List
490    ${sensors}=  Get Lines Containing String  ${resp}  ${sensor_component}  case-insensitive
491    ${sensors}=  Split To Lines  ${sensors}
492
493    # Example of IPMI sdr elist command.
494
495    # dcm0_cpu0        | 41h | ok  |  3.1 | Presence detected
496    # dcm0_cpu1        | 42h | ok  |  3.2 | Presence detected, Disabled
497    # dcm1_cpu0        | 43h | ok  |  3.3 | Presence detected
498    # dcm1_cpu1        | 44h | ok  |  3.4 | Presence detected, Disabled
499    # dcm2_cpu0        | 45h | ns  |  3.5 | Disabled
500    # dcm2_cpu1        | 46h | ns  |  3.6 | Disabled
501    # dcm3_cpu0        | 47h | ns  |  3.7 | Disabled
502    # dcm3_cpu1        | 48h | ns  |  3.8 | Disabled
503
504    FOR  ${line}  IN  @{sensors}
505        ${sensor_name}=  Set Variable  ${line.split('|')[0].strip()}
506
507        # Adding sensors to the list whose presence is detected.
508        ${contains}=  Evaluate  "Presence detected" in "${line}" or "ok" in "${line}"
509        IF  "${contains}" == "True"
510            Append To List  ${sensor_list}  ${sensor_name}
511        END
512    END
513
514    # Example of output for ${sensor_list}
515    # ['dcm0_cpu0', 'dcm0_cpu1', 'dcm1_cpu0', 'dcm1_cpu1']
516
517    RETURN  ${sensor_list}
518
519
520Get Sensor Id For Sensor
521    [Documentation]  Returns the sensor ID value for the given sensor.
522    [Arguments]  ${sensor_name}
523
524    # Description of argument(s):
525    # sensor_name     Name of sensor whose ID is required(e.g.: dcm0_cpu0, dcm0_cpu1 etc).
526
527    ${get_resp}=  Run IPMI Standard Command  sensor get ${sensor_name}
528
529    # Example of sensor get command.
530
531    # Locating sensor record...
532    # Sensor ID              : dcm0_cpu0 (0x41)
533    # Entity ID             : 3.1
534    # Sensor Type (Discrete): Processor
535    # States Asserted       : Processor
536    #                  [Presence detected]
537
538    ${line}=  Get Lines Containing String  ${get_resp}  Sensor ID
539    ${sensor_id}=  Set Variable  ${line[-5:-1]}
540
541    # Example of output for ${sensor_id} is 0x41.
542
543    RETURN  ${sensor_id}
544
545