1*** Settings ***
2Documentation  Utilities for fan tests.
3
4Library        ../lib/bmc_ssh_utils.py
5Resource       ../lib/openbmc_ffdc_utils.robot
6Variables      ../data/variables.py
7
8*** Keywords ***
9
10Is Water Cooled
11    [Documentation]  Return 1 if system is water cooled, 0 othersise.
12
13    ${water_cooled}=  Read Attribute
14    ...  ${HOST_INVENTORY_URI}/system/chassis  WaterCooled
15    [Return]  ${water_cooled}
16
17
18Get Fan Names
19    [Documentation]  Get the names of the fans marked present in inventory.
20    [Arguments]  ${fan_names}
21    # This keyword populates the fan_names list with the names of
22    # fans present in inventory e.g. fan0, fan2, fan3.
23
24    # Description of Argument(s):
25    # fan_names   The list of fan names to which new fan names are to be
26    #             added to.  This list is returned to the caller.
27
28    ${fan_uris}=  Get Endpoint Paths  ${HOST_INVENTORY_URI}/system  fan
29    : FOR  ${fan_uri}  IN  @{fan_uris}
30
31    \  ${fan_properties}=  Read Properties  ${fan_uri}
32    \  ${fan_present}=  Get Variable Value  ${fan_properties['Present']}  0
33    \  Continue For Loop If  ${fan_present} != 1
34    \  ${remaining_uri}  ${fan_name}=  Split Path  ${fan_uri}
35    \  Append To List  ${fan_names}  ${fan_name}
36
37    [Return]  ${fan_names}
38
39
40Verify System Error Indication Due To Fans
41    [Documentation]  Verify enclosure LEDs are on and there's an error log.
42
43    # Both enclosure LEDs should now be On.
44    Verify Front And Rear LED State  On
45
46    # An error log should now exist.
47    Error Logs Should Exist
48
49
50Verify Front And Rear LED State
51    [Documentation]  Check state of the front and rear enclsure fault LEDs.
52    [Arguments]  ${state}
53    # Both LEDs should be in the specified state.  If not fail the test case.
54
55    # Description of Argument(s):
56    # state    The state to check for, either 'Off' or 'On'.
57
58    ${front_fault}=  Get System LED State  front_fault
59    ${rear_fault}=  Get System LED State  rear_fault
60
61    Run Keyword If
62    ...  '${front_fault}' != '${state}' or '${rear_fault}' != '${state}'
63    ...  Fail  msg=Expecting both enclosure LEDs to be ${state}.
64
65
66Set Fan State
67    [Documentation]  Set the fan state, either functional or non-functional.
68    [Arguments]  ${fan_name}  ${fan_state}
69
70    # Description of Argument(s):
71    # fan_name     The name of the fan, e.g. "fan2".
72    # fan_state    The state to set, 1 for functional, 2 for non-functional.
73
74    ${valueDict}=  Create Dictionary  data=${fan_state}
75    Write Attribute
76    ...  ${HOST_INVENTORY_URI}system/chassis/motherboard/${fan_name}
77    ...  Functional  data=${valueDict}
78
79
80Set Fan Target Speed
81    [Documentation]  Set the target speed of a fan.
82    [Arguments]  ${fan_name}  ${fan_speed}
83
84    # Description of argument(s):
85    # fan_name    The name of the fan (e.g. "fan0").
86    # fan_speed   The target speed to set (e.g. "9000").
87
88    ${valueDict}=  Create Dictionary  data=${fan_speed}
89    Write Attribute  ${SENSORS_URI}fan_tach/${fan_name}_0
90    ...  Target  data=${valueDict}
91
92
93Get Target Speed Of Fans
94    [Documentation]  Return the maximum target speed of the system fans.
95
96    ${max_target}=  Set Variable  0
97    ${paths}=  Get Endpoint Paths  ${SENSORS_URI}fan_tach/  0
98    :FOR  ${path}  IN  @{paths}
99    \  ${response}=  OpenBMC Get Request  ${path}
100    \  ${json}=  To JSON  ${response.content}
101    \  ${target_speed}=  Set Variable  ${json["data"]["Target"]}
102    \  ${max_target}=  Run Keyword If  ${target_speed} > ${max_target}
103    ...  Set Variable  ${target_speed}  ELSE  Set Variable  ${max_target}
104    [Return]  ${max_target}
105
106
107Get Target And Blade Speeds
108    [Documentation]  Return the fan target speed setting, the speed of the
109    ...  fan's clockwise blade, and the speed of the counter-clockwise blade.
110    # Each fan unit has two counter-rotating fan blades
111    # One blade is expected to be moving but the other blade may not be
112    # moving whenever the fan unit is transitioning to a new target speed.
113    [Arguments]  ${fan_name}
114
115    # Description of argument(s):
116    # fan_name       The name of a fan (e.g. "fan0")
117
118    # Get the fan target speed and the clockwise blade speed.
119    ${path}=  Catenate  ${SENSORS_URI}fan_tach/${fan_name}_0
120    ${response}=  OpenBMC Get Request  ${path}
121    ${json}=  To JSON  ${response.content}
122    ${fan_clockwise_speed}=  Set Variable  ${json["data"]["Value"]}
123    ${target_speed}=  Set Variable  ${json["data"]["Target"]}
124
125    # Get the counter-clockwise blade speed.
126    ${path}=  Catenate  ${SENSORS_URI}fan_tach/${fan_name}_1
127    ${response}=  OpenBMC Get Request  ${path}
128    ${json}=  To JSON  ${response.content}
129    ${fan_counterclockwise_speed}=  Set Variable  ${json["data"]["Value"]}
130
131    [Return]  ${target_speed}  ${fan_clockwise_speed}
132    ...  ${fan_counterclockwise_speed}
133
134
135Get Fan Target And Speed
136    [Documentation]  Return the fan target speed setting and the
137    ...  speed of the fastest blade.
138    [Arguments]  ${fan_name}
139
140    # Description of argument(s):
141    # fan_name       The name of a fan (e.g. "fan0")
142
143    ${target_speed}  ${clockwise_speed}  ${counterclockwise_speed}=
144    ...  Get Target And Blade Speeds  ${fan_name}
145    ${blade_speed}=  Run Keyword If
146    ...  ${clockwise_speed} > ${counterclockwise_speed}
147    ...  Set Variable  ${clockwise_speed}  ELSE
148    ...  Set Variable  ${counterclockwise_speed}
149    [Return]  ${target_speed}  ${blade_speed}
150
151
152Set Fan Daemon State
153    [Documentation]  Set the state of the fan control service.
154    [Arguments]  ${state}
155
156    # Description of argument(s):
157    # state     The desired state of the service, usually
158    #           "start", "stop", or "restart".
159
160    ${cmd}=  Catenate  systemctl  ${state}  phosphor-fan-control@0.service
161    ${stdout}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
162
163
164Verify Minimum Number Of Fans With Cooling Type
165    [Documentation]  Verify minimum number of fans.
166    [Arguments]  ${num_fans}  ${water_cooled}
167
168    # Description of argument(s):
169    # num_fans       The number of fans present in the system.
170    # water_cooled   The value 1 if the system is water cooled,
171    #                0 if air cooled.
172
173    # For a water cooled system.
174    ${min_fans_water}=  Set Variable  2
175
176    # For an air cooled system.
177    ${min_fans_air}=  Set Variable  3
178
179    Rprintn
180    Rpvars  num_fans  water_cooled
181
182    # If water cooled must have at least min_fans_water fans, otherwise
183    # issue Fatal Error and terminate testing.
184    Run Keyword If  ${water_cooled} == 1 and ${num_fans} < ${min_fans_water}
185    ...  Fatal Error
186    ...  msg=Water cooled but less than ${min_fans_water} fans present.
187
188    # If air cooled must have at least min_fans_air fans.
189    Run Keyword If  ${water_cooled} == 0 and ${num_fans} < ${min_fans_air}
190    ...  Fatal Error
191    ...  msg=Air cooled but less than ${min_fans_air} fans present.
192
193
194Verify Fan Monitors With State
195    [Documentation]  Verify fan monitor daemons in the system state.
196    [Arguments]  ${power_state}
197    # The number of monitoring daemons is dependent upon the system
198    # power state.  If power is off there should be 0, if power
199    # is on there should be several.
200
201    # Description of argument(s):
202    # power_state   Power staet of the system, either "On" or "Off"
203
204    ${cmd}=  Catenate  systemctl list-units | grep phosphor-fan | wc -l
205    ${num_fan_daemons}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
206
207    Rpvars  power_state  num_fan_daemons
208
209    # Fail if system is On and there are no fan monitors.
210    Run Keyword If  '${power_state}' == 'On' and ${num_fan_daemons} == 0
211    ...  Fail  msg=No phosphor-fan monitors found at power on.
212
213    # Fail if system is Off and the fan monitors are present.
214    Run Keyword If  '${power_state}' == 'Off' and ${num_fan_daemons} != 0
215    ...  Fail  msg=Phosphor-fan monitors found at power off.
216