1*** Settings ***
2Documentation       Inventory of hardware FRUs under redfish.
3
4Resource            ../../lib/bmc_redfish_resource.robot
5Resource            ../../lib/bmc_redfish_utils.robot
6Resource            ../../lib/openbmc_ffdc.robot
7Library             ../../lib/gen_robot_valid.py
8
9Suite Setup         Suite Setup Execution
10Suite Teardown      Suite Teardown Execution
11Test Setup          Printn
12Test Teardown       Test Teardown Execution
13
14*** Variables ***
15
16# The passing criteria.  Must have at least this many.
17${min_num_dimms}   2
18${min_num_cpus}    1
19${min_num_cores}   18
20${min_num_power_supplies}  1
21
22
23*** Test Cases ***
24
25
26Verify CPU And Core Count
27    [Documentation]  Get the total number of CPUs and cores in the system.
28    ...              Verify counts are above minimums.
29    [Tags]  Verify_CPU_And_Core_Count
30
31    # Select only CPUs with Health = "OK".
32    ${cpus_ok}=  Filter Struct  ${cpu_info}  [('Health', 'OK')]
33    ${num_cpus}=   Get Length  ${cpus_ok}
34
35    Rprint Vars  num_cpus  min_num_cpus
36
37    # Assert that num_cpus is greater than or equal to min_num_cpus.
38    Valid Range  num_cpus  ${min_num_cpus}
39
40    # Get the number of cores.
41    ${total_num_cores}=  Set Variable  ${0}
42    :FOR  ${cpu}  IN  @{cpus_ok}
43        ${cores}=   Get CPU TotalCores  ${cpu}
44        ${total_num_cores}=  Evaluate  $total_num_cores + ${cores}
45    END
46
47    Rprint Vars  total_num_cores  min_num_cores
48
49    # Assert that total_num_cores is greater than or equal to
50    # min_num_cores.
51    Valid Range  total_num_cores  ${min_num_cores}
52
53
54Get Memory Inventory Via Redfish And Verify
55    [Documentation]  Get the number of DIMMs that are functional and enabled.
56    [Tags]  Get_Memory_Inventory_Via_Redfish_And_Verify
57
58    Verify FRU Inventory Minimums  Memory  ${min_num_dimms}
59
60
61Get Memory Summary State And Verify Enabled
62    [Documentation]  Check that the state of the MemorySummary attribute
63    ...              under /redfish/v1/Systems/system is 'Enabled'.
64    [Tags]  Get_Memory_Summary_State_And_Verify_Enabled
65
66    ${status}=  Redfish.Get Attribute  ${SYSTEM_BASE_URI}  MemorySummary
67    ${memory_summary_state}=  Set Variable  ${status['Status']['State']}
68    Rprint Vars  memory_summary_state
69
70    Should Be Equal As Strings  Enabled  ${memory_summary_state}
71    ...  msg=MemorySummary State is not 'Enabled'.
72
73
74Get System Serial And Verify Populated
75    [Documentation]  Check that the System SerialNumber is non-blank.
76    [Tags]  Get_System_Serial_And_Verify_Populated
77
78    ${serial_number}=  Redfish.Get Attribute  ${SYSTEM_BASE_URI}  SerialNumber
79    Valid Value  serial_number
80    Rprint Vars  serial_number
81
82
83Get Model And Verify Populated
84    [Documentation]  Check that the Model is non-blank.
85    [Tags]  Get_Model_And_Verify_Populated
86
87    ${model}=  Redfish.Get Attribute  ${SYSTEM_BASE_URI}  Model
88    Valid Value  model
89    Rprint Vars  model
90
91
92Get Available Power Supplies And Verify
93    [Documentation]  Get the number of functional power supplies and
94    ...              verify that it is at or above the minimum.
95    [Tags]  Get_Available_Power_Supplies_And_Verify
96
97    # Select only power supplies with Health = "OK".
98    ${power_supplies_ok}=  Filter Struct  ${power_supplies}  [('Health', 'OK')]
99
100    # Count the power supplies that are Enabled or StandbyOffline.
101    ${total_num_supplies}=  Set Variable  ${0}
102    :FOR  ${power_supply}  IN  @{power_supplies_ok}
103        # Example of power_supply:
104        # power_supply = {'@odata.id': '/redfish/v1/Chassis/chassis/Power#/PowerSupplies/0',
105        # 'Manufacturer': '', 'MemberId': 'powersupply0', 'Model': '2100', 'Name':
106        # 'powersupply0', 'PartNumber': 'PNPWR123', 'PowerInputWatts': 394.0,
107        # 'SerialNumber': '75B12W', 'Status': {'Health': 'OK', 'State': 'Enabled'}}
108        ${state}=  Set Variable  ${power_supply['Status']['State']}
109        ${good_state}=  Evaluate
110        ...  any(x in '${state}' for x in ('Enabled', 'StandbyOffline'))
111        Run Keyword If  not ${good_state}  Continue For Loop
112        ${total_num_supplies}=  Evaluate  $total_num_supplies + ${1}
113    END
114
115    Rprint Vars  total_num_supplies  min_num_power_supplies
116
117    Valid Range  total_num_supplies  ${min_num_power_supplies}
118
119
120Get Motherboard Serial And Verify Populated
121    [Documentation]  Check that the Motherboard SerialNumber is non-blank.
122    [Tags]  Get_Motherboard_Serial_And_Verify_Populated
123
124    ${serial_number}=  Redfish.Get Attribute
125    ...  ${REDFISH_CHASSIS_URI}motherboard  SerialNumber
126    Valid Value  serial_number
127    Rprint Vars  serial_number
128
129
130Verify Motherboard Manufacturer Field Value Populated
131    [Documentation]  Check that the Motherboard manufacturer is non-blank.
132    [Tags]  Verify_Motherboard_Manufacturer_Field_Value_Populated
133
134    ${motherboard_manufacturer}=  Redfish.Get Attribute
135    ...  ${REDFISH_CHASSIS_URI}motherboard  Manufacturer
136    Valid Value  motherboard_manufacturer
137
138
139Verify Motherboard Partnumber Field Value Populated
140    [Documentation]  Check that the Motherboard partnumber is non-blank.
141    [Tags]  Verify_Motherboard_Partnumber_Field_Value_Populated
142
143    ${motherboard_part_number}=  Redfish.Get Attribute
144    ...  ${REDFISH_CHASSIS_URI}motherboard  PartNumber
145    Valid Value  motherboard_part_number
146
147
148Check GPU States When Power On
149    [Documentation]  Check the State of each of the GPUs
150    ...              in the system.  A system may have 0-6 GPUs.
151    [Tags]  Check_GPU_States_When_Power_On
152
153    # System was powered-on in Suite Setup.
154    GPU State Check
155
156
157Check GPU States When Power Off
158    [Documentation]  Check the State of the GPUs when power is Off.
159    [Tags]  Check_GPU_States_When_Power_Off
160
161    Redfish Power Off
162    Redfish.Login
163    GPU State Check
164
165
166*** Keywords ***
167
168
169Get CPU TotalCores
170    [Documentation]  Return the TotalCores of a CPU.
171    ...              Return 0 if this attribute is missing or NONE.
172    [Arguments]      ${processor}
173
174    # Description of Argument(s):
175    # processor     The Redfish URI of a CPU (e.g.
176    #               "/redfish/v1/Systems/system/Processors/cpu0").
177
178    ${total_cores}=  Redfish.Get Attribute  ${processor}  TotalCores
179    Return From Keyword If  ${total_cores} is ${NONE}  ${0}
180    [Return]  ${total_cores}
181
182
183GPU State Check
184    [Documentation]  The state of every "OK" GPU should be
185    ...              "Absent", "Enabled", or "UnavailableOffline".
186
187    # Select only GPUs with Health = "OK".
188    ${gpus_ok}=  Filter Struct  ${gpu_info}  [('Health', 'OK')]
189
190    :FOR  ${gpu}  IN  @{gpus_ok}
191        ${status}=  Redfish.Get Attribute  ${gpu}  Status
192        ${state}=  Set Variable  ${status['State']}
193        ${good_state}=  Evaluate
194        ...  any(x in '${state}' for x in ('Absent', 'Enabled', 'UnavailableOffline'))
195        Rprint Vars  gpu  state
196        Run Keyword If  not ${good_state}  Fail
197        ...  msg=GPU State is not Absent, Enabled, or UnavailableOffline.
198    END
199
200
201Get Inventory URIs
202    [Documentation]  Get and return a tuple of lists of URIs for CPU,
203    ...              GPU and PowerSupplies.
204
205    ${processor_info}=  Redfish_Utils.Enumerate Request
206    ...  ${SYSTEM_BASE_URI}Processors  return_json=0
207
208    ${cpu_info}=  Filter Struct  ${processor_info}
209    ...  [('ProcessorType', 'CPU')]  regex=1
210
211    ${gpu_info}=  Filter Struct  ${processor_info}
212    ...  [('ProcessorType', 'Accelerator')]  regex=1
213
214    ${power_supplies}=  Redfish.Get Attribute
215    ...  ${REDFISH_CHASSIS_POWER_URI}  PowerSupplies
216
217    [Return]  ${cpu_info}  ${gpu_info}  ${power_supplies}
218
219
220Verify FRU Inventory Minimums
221    [Documentation]  Verify a minimum number of FRUs.
222    [Arguments]  ${fru_type}  ${min_num_frus}
223
224    # Description of Argument(s):
225    # fru_type      The type of FRU (e.g. "Processors", "Memory", etc.).
226    # min_num_frus  The minimum acceptable number of FRUs found.
227
228    # A valid FRU  will have a "State" key of "Enabled" and a "Health" key
229    # of "OK".
230
231    ${status}  ${num_valid_frus}=  Run Key U  Get Num Valid FRUs \ ${fru_type}
232
233    Rprint Vars  fru_type  num_valid_frus  min_num_frus
234
235    Return From Keyword If  ${num_valid_frus} >= ${min_num_frus}
236    Fail  Too few "${fru_type}" FRUs found, found only ${num_valid_frus}.
237
238
239Suite Teardown Execution
240    [Documentation]  Do the post suite teardown.
241
242    Redfish.Logout
243
244
245Suite Setup Execution
246    [Documentation]  Do test case setup tasks.
247
248    Redfish Power On  stack_mode=skip
249    Redfish.Login
250
251    ${cpu_info}  ${gpu_info}  ${power_supplies}=  Get Inventory URIs
252
253    Set Suite Variable  ${cpu_info}
254    Set Suite Variable  ${gpu_info}
255    Set Suite Variable  ${power_supplies}
256
257
258Test Teardown Execution
259    [Documentation]  Do the post test teardown.
260
261    FFDC On Test Case Fail
262