Inventory: Cores, Power Supplies, motherboard serial.

Add count of CPU cores and power supply count.
Verify motherboard serial number field is populated.

Resolves openbmc/openbmc-test-automation#1590

Signed-off-by: Steven Sombar <ssombar@us.ibm.com>
Change-Id: I5cbf6ec2e4f6bc31b0dcb08b3636a6f95b10c734
diff --git a/redfish/systems/test_systems_inventory.robot b/redfish/systems/test_systems_inventory.robot
index cce5699..8988d34 100755
--- a/redfish/systems/test_systems_inventory.robot
+++ b/redfish/systems/test_systems_inventory.robot
@@ -15,6 +15,8 @@
 # The passing criteria.  Must have at least this many.
 ${min_num_dimms}   2
 ${min_num_cpus}    1
+${min_num_cores}   18
+${min_num_powersupplies}  1
 
 
 *** Test Cases ***
@@ -26,6 +28,37 @@
     Verify FRU Inventory Minimums  Processors  ${min_num_cpus}
 
 
+Get Available CPU Cores And Verify
+    [Documentation]  Get the total number of cores in the system and
+    ...              verify that it is at or above the minimum.
+    [Tags]  Get_Available_CPU_Cores_And_Verify
+
+    ${total_num_cores}=  Set Variable  ${0}
+
+    ${processor_uris}=
+    ...  Redfish_Utils.Get Member List  ${SYSTEM_BASE_URI}Processors
+    # Example of processor_uris:
+    # /redfish/v1/Systems/system/Processors/cpu0
+    # /redfish/v1/Systems/system/Processors/cpu1
+
+    :FOR  ${processor}  IN  @{processor_uris}
+        # If the status of the processor is "OK" and "Enabled", get its number
+        # of cores.
+        ${status}=  Redfish.Get Attribute  ${processor}  Status
+        ${processor_cores}=  Run Keyword If
+        ...  "${status['Health']}" == "OK" and "${status['State']}" == "Enabled"
+        ...     Redfish.Get Attribute  ${processor}  TotalCores
+        ...  ELSE
+        ...     Set Variable  ${0}
+        # Add the number of processor_cores to the total.
+        ${total_num_cores}=  Evaluate  $total_num_cores + $processor_cores
+    END
+
+    Rprint Vars  total_num_cores
+    Run Keyword If  ${total_num_cores} < ${min_num_cores}
+    ...  Fail  Too few CPU cores found.
+
+
 Get Memory Inventory Via Redfish And Verify
     [Documentation]  Get the number of DIMMs that are functional and enabled.
     [Tags]  Get_Memory_Inventory_Via_Redfish_And_Verify
@@ -33,9 +66,9 @@
     Verify FRU Inventory Minimums  Memory  ${min_num_dimms}
 
 
-Get Serial And Verify Populated
-    [Documentation]  Check that the SerialNumber is non-blank.
-    [Tags]  Get_Serial_And_Verify_Populated
+Get System Serial And Verify Populated
+    [Documentation]  Check that the System SerialNumber is non-blank.
+    [Tags]  Get_System_Serial_And_Verify_Populated
 
     ${serial_number}=  Redfish.Get Attribute  ${SYSTEM_BASE_URI}  SerialNumber
     Rvalid Value  serial_number
@@ -51,6 +84,44 @@
     Rprint Vars  model
 
 
+Get Available Power Supplies And Verify
+    [Documentation]  Get the number of functional power supplies and
+    ...              verify that it is at or above the minimum.
+    [Tags]  Get_Available_Power_Supplies_And_Verify
+
+    ${total_num_supplies}=  Set Variable  ${0}
+
+    ${chassis_uris}=  Redfish_Utils.Get Member List  ${REDFISH_CHASSIS_URI}
+    # Example of chassis_uris:
+    # /redfish/v1/Chassis/chasis
+    # /redfish/v1/Chassis/motherboard
+    # /redfish/v1/Chassis/powersupply0
+
+    :FOR  ${chassis_uri}  IN  @{chassis_uris}
+        ${is_supply}=  Evaluate  "powersupply" in $chassis_uri
+        ${is_functional}=  Run Keyword If  ${is_supply}
+        ...    Check If Power Supply Is Functional  ${chassis_uri}
+        ...  ELSE
+        ...    Set Variable  ${0}
+        ${total_num_supplies}=  Evaluate  $total_num_supplies + $is_functional
+    END
+
+    Rprint Vars  total_num_supplies
+
+    Run Keyword If  ${total_num_supplies} < ${min_num_powersupplies}
+    ...  Fail  Too few power supplies found.
+
+
+Get Motherboard Serial And Verify Populated
+    [Documentation]  Check that the Motherboard SerialNumber is non-blank.
+    [Tags]  Get_Motherboard_Serial_And_Verify_Populated
+
+    ${serial_number}=  Redfish.Get Attribute
+    ...  ${REDFISH_CHASSIS_URI}motherboard  SerialNumber
+    Rvalid Value  serial_number
+    Rprint Vars  serial_number
+
+
 *** Keywords ***
 
 
@@ -71,6 +142,29 @@
     Fail  Too few "${fru_type}" FRUs found, found only ${num_valid_frus}.
 
 
+Check If Power Supply Is Functional
+    [Documentation]  Return 1 if a power supply is OK and either
+    ...   Enabled or StandbyOffline.  Return 0 otherwise.
+    [Arguments]  ${chassis_uri}
+
+    # Description of Argument(s):
+    # chassis_uri    The Redfish uri of a power supply
+    #                (e.g. "/redfish/v1/Chassis/powersupply0").
+
+    ${status}=  Redfish.Get Attribute  ${chassis_uri}  Status
+
+    ${state_check}=  Set Variable  "${status['Health']}" == "OK" and
+    ${state_check}=  Catenate  ${state_check}  ("${status['State']}" == "StandbyOffline" or
+    ${state_check}=  Catenate  ${state_check}  "${status['State']}" == "Enabled")
+
+    ${is_functional}=  Run Keyword If  ${state_check}
+    ...     Set Variable  ${1}
+    ...  ELSE
+    ...     Set Variable  ${0}
+
+    [Return]  ${is_functional}
+
+
 Suite Teardown Execution
     [Documentation]  Do the post suite teardown.