1*** Settings ***
2Documentation       BMC server health, collect sensors.
3
4# Test Parameters:
5# OPENBMC_HOST      The BMC host name or IP address.
6
7Resource            ../../lib/bmc_redfish_resource.robot
8Resource            ../../lib/openbmc_ffdc.robot
9Library             Collections
10Library             ../syslib/utils_keywords.py
11
12Suite Setup         Suite Setup Execution
13Suite Teardown      Suite Teardown Execution
14Test Setup          Printn
15
16*** Variables ***
17${QUIET}                     ${1}
18${sensors_values_rest}       Rest sensors collection excluded
19${sensors_values_redfish}    Redfish sensors collection excluded
20${sensors_flagged_rest}      Rest sensors collection excluded
21${sensors_flagged_redfish}   Redfish sensors collection excluded
22
23
24*** Test Cases ***
25
26Rest Collect Sensors
27    [Documentation]  Collect the sensors values using the OpenBMC Rest API.
28    [Tags]  Rest_Collect_Sensors  rest
29    [Teardown]  FFDC On Test Case Fail
30
31    ${sensors}=  OpenBMC Get Request  ${SENSORS_URI}enumerate
32    ${sensors}=  Evaluate  $sensors.json()['data']
33    ${sensors_collected_via_rest}=  gen_robot_print.Sprint Vars  sensors
34    Log To Console  ${sensors_collected_via_rest}
35    ${fans}=  Filter Struct  ${sensors}  [('Unit', '\.RPMS$')]  regex=1
36    ${no_fans}=  Filter Struct  ${sensors}  [('WarningAlarmHigh', None),('WarningAlarmLow', None)]
37    ...  invert=${True}
38    Log  sensor values raw:${\n}${sensors}${\n}sensors no fans:${\n}${no_fans}${\n}fans:${\n}${fans}
39    ...  level=DEBUG
40
41    ${fans_flagged}=  Filter Struct  ${fans}
42    ...  [('CriticalAlarmHigh', False),('CriticalAlarmLow', False)]  invert=${True}
43    ${filter_str}=  Catenate  [('CriticalAlarmHigh', False),('CriticalAlarmLow', False),
44    ...  ('WarningAlarmHigh', False),('WarningAlarmLow', False)]
45    ${other_sensors_flagged}=  Filter Struct  ${no_fans}  ${filter_str}  invert=${True}
46    ${sensors_flagged_rest}=  gen_robot_print.Sprint Vars  fans_flagged  other_sensors_flagged
47    Set Suite Variable  ${sensors_flagged_rest}
48
49
50Redfish Collect Sensors
51    [Documentation]  Collect the sensor values using Redfish.
52    [Tags]  Redfish_Collect_Sensors  redfish
53    [Setup]  Redfish.Login
54    [Teardown]  Redfish Test Teardown Execution
55
56    ${redfish_chassis_power}=  Redfish_Utils.Enumerate Request  ${REDFISH_CHASSIS_POWER_URI}  ${0}
57    ${redfish_chassis_thermal}=  Redfish_Utils.Enumerate Request  ${REDFISH_CHASSIS_THERMAL_URI}  ${0}
58    ${redfish_chassis_sensors}=  Redfish_Utils.Enumerate Request  ${REDFISH_CHASSIS_SENSORS_URI}  ${0}
59    ${sensors_values_redfish}=  gen_robot_print.Sprint Vars
60    ...  redfish_chassis_power  redfish_chassis_thermal  redfish_chassis_sensors
61    Set Suite Variable  ${sensors_values_redfish}
62    Log To Console  ${sensors_values_redfish}
63
64    ${health_check_filter_dict}=  Create Dictionary  Health=OK
65    ${merged_dicts}=  Evaluate  {**$redfish_chassis_power, **$redfish_chassis_thermal}
66    Log  ${merged_dicts}  level=DEBUG
67    ${sensors_flagged_redfish}=  Filter Struct  ${merged_dicts}  ${health_check_filter_dict}  invert=${TRUE}
68    ${sensors_flagged_redfish}=  gen_robot_print.Sprint Vars  sensors_flagged_redfish
69    Set Suite Variable  ${sensors_flagged_redfish}
70
71
72*** Keywords ***
73
74Suite Setup Execution
75    [Documentation]  Do suite setup tasks.
76
77    Set Log Level  DEBUG
78    REST Power On  stack_mode=skip
79
80
81Suite Teardown Execution
82    [Documentation]  Do suite teardown tasks. Log sensor values collected.
83
84    Log Many  ${sensors_values_rest}  ${sensors_values_redfish}
85    Log  Sensors detected out of bounds via Rest:${\n}${sensors_flagged_rest}  console=true
86    Log  Sensors detected out of bounds via Redfish:${\n}${sensors_flagged_redfish}  console=true
87
88
89Redfish Test Teardown Execution
90    [Documentation]  Do the post test teardown for redfish.
91
92    Redfish.Logout
93    FFDC On Test Case Fail
94