1*** Settings ***
2Documentation       Inventory of hardware FRUs under redfish/systems.
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 Teardown       Test Teardown Execution
12
13*** Variables ***
14
15# The passing criteria.  Must have at least this many.
16${min_num_dimms}   2
17${min_num_cpus}    1
18${min_num_cores}   18
19${min_num_powersupplies}  1
20
21
22*** Test Cases ***
23
24Get Processor Inventory Via Redfish And Verify
25    [Documentation]  Get the number of CPUs that are functional and enabled.
26    [Tags]  Get_Processor_Inventory_Via_Redfish_And_Verify
27
28    Verify FRU Inventory Minimums  Processors  ${min_num_cpus}
29
30
31Get Available CPU Cores And Verify
32    [Documentation]  Get the total number of cores in the system and
33    ...              verify that it is at or above the minimum.
34    [Tags]  Get_Available_CPU_Cores_And_Verify
35
36    ${total_num_cores}=  Set Variable  ${0}
37
38    ${processor_uris}=
39    ...  Redfish_Utils.Get Member List  ${SYSTEM_BASE_URI}Processors
40    # Example of processor_uris:
41    # /redfish/v1/Systems/system/Processors/cpu0
42    # /redfish/v1/Systems/system/Processors/cpu1
43
44    :FOR  ${processor}  IN  @{processor_uris}
45        # If the status of the processor is "OK" and "Enabled", get its number
46        # of cores.
47        ${status}=  Redfish.Get Attribute  ${processor}  Status
48        ${processor_cores}=  Run Keyword If
49        ...  "${status['Health']}" == "OK" and "${status['State']}" == "Enabled"
50        ...     Redfish.Get Attribute  ${processor}  TotalCores
51        ...  ELSE
52        ...     Set Variable  ${0}
53        # Add the number of processor_cores to the total.
54        ${total_num_cores}=  Evaluate  $total_num_cores + $processor_cores
55    END
56
57    Rprint Vars  total_num_cores
58    Run Keyword If  ${total_num_cores} < ${min_num_cores}
59    ...  Fail  Too few CPU cores found.
60
61
62Get Memory Inventory Via Redfish And Verify
63    [Documentation]  Get the number of DIMMs that are functional and enabled.
64    [Tags]  Get_Memory_Inventory_Via_Redfish_And_Verify
65
66    Verify FRU Inventory Minimums  Memory  ${min_num_dimms}
67
68
69Get System Serial And Verify Populated
70    [Documentation]  Check that the System SerialNumber is non-blank.
71    [Tags]  Get_System_Serial_And_Verify_Populated
72
73    ${serial_number}=  Redfish.Get Attribute  ${SYSTEM_BASE_URI}  SerialNumber
74    Rvalid Value  serial_number
75    Rprint Vars  serial_number
76
77
78Get Model And Verify Populated
79    [Documentation]  Check that the Model is non-blank.
80    [Tags]  Get_Model_And_Verify_Populated
81
82    ${model}=  Redfish.Get Attribute  ${SYSTEM_BASE_URI}  Model
83    Rvalid Value  model
84    Rprint Vars  model
85
86
87Get Available Power Supplies And Verify
88    [Documentation]  Get the number of functional power supplies and
89    ...              verify that it is at or above the minimum.
90    [Tags]  Get_Available_Power_Supplies_And_Verify
91
92    ${total_num_supplies}=  Set Variable  ${0}
93
94    ${chassis_uris}=  Redfish_Utils.Get Member List  ${REDFISH_CHASSIS_URI}
95    # Example of chassis_uris:
96    # /redfish/v1/Chassis/chasis
97    # /redfish/v1/Chassis/motherboard
98    # /redfish/v1/Chassis/powersupply0
99
100    :FOR  ${chassis_uri}  IN  @{chassis_uris}
101        ${is_supply}=  Evaluate  "powersupply" in $chassis_uri
102        ${is_functional}=  Run Keyword If  ${is_supply}
103        ...    Check If Power Supply Is Functional  ${chassis_uri}
104        ...  ELSE
105        ...    Set Variable  ${0}
106        ${total_num_supplies}=  Evaluate  $total_num_supplies + $is_functional
107    END
108
109    Rprint Vars  total_num_supplies
110
111    Run Keyword If  ${total_num_supplies} < ${min_num_powersupplies}
112    ...  Fail  Too few power supplies found.
113
114
115Get Motherboard Serial And Verify Populated
116    [Documentation]  Check that the Motherboard SerialNumber is non-blank.
117    [Tags]  Get_Motherboard_Serial_And_Verify_Populated
118
119    ${serial_number}=  Redfish.Get Attribute
120    ...  ${REDFISH_CHASSIS_URI}motherboard  SerialNumber
121    Rvalid Value  serial_number
122    Rprint Vars  serial_number
123
124
125*** Keywords ***
126
127
128Verify FRU Inventory Minimums
129    [Documentation]  Verify a minimum number of FRUs.
130    [Arguments]  ${fru_type}  ${min_num_frus}
131
132    # Description of Argument(s):
133    # fru_type      The type of FRU (e.g. "Processors", "Memory", etc.).
134    # min_num_frus  The minimum acceptable number of FRUs found.
135
136    # A valid FRU  will have a "State" key of "Enabled" and a "Health" key
137    # of "OK".
138
139    ${status}  ${num_valid_frus}=  Run Key U  Get Num Valid FRUs \ ${fru_type}
140
141    Return From Keyword If  ${num_valid_frus} >= ${min_num_frus}
142    Fail  Too few "${fru_type}" FRUs found, found only ${num_valid_frus}.
143
144
145Check If Power Supply Is Functional
146    [Documentation]  Return 1 if a power supply is OK and either
147    ...   Enabled or StandbyOffline.  Return 0 otherwise.
148    [Arguments]  ${chassis_uri}
149
150    # Description of Argument(s):
151    # chassis_uri    The Redfish uri of a power supply
152    #                (e.g. "/redfish/v1/Chassis/powersupply0").
153
154    ${status}=  Redfish.Get Attribute  ${chassis_uri}  Status
155
156    ${state_check}=  Set Variable  "${status['Health']}" == "OK" and
157    ${state_check}=  Catenate  ${state_check}  ("${status['State']}" == "StandbyOffline" or
158    ${state_check}=  Catenate  ${state_check}  "${status['State']}" == "Enabled")
159
160    ${is_functional}=  Run Keyword If  ${state_check}
161    ...     Set Variable  ${1}
162    ...  ELSE
163    ...     Set Variable  ${0}
164
165    [Return]  ${is_functional}
166
167
168Suite Teardown Execution
169    [Documentation]  Do the post suite teardown.
170
171    Redfish.Logout
172
173
174Suite Setup Execution
175    [Documentation]  Do test case setup tasks.
176
177    Redfish.Login
178    Printn
179
180
181Test Teardown Execution
182    [Documentation]  Do the post test teardown.
183
184    FFDC On Test Case Fail
185