Check power supplies watts and voltages readings

Signed-off-by: Marissa Garza <garzam@us.ibm.com>
Change-Id: I4d42c2facc12247d2138162793004b4b2c97373e
diff --git a/data/variables.py b/data/variables.py
index 245c3dd..22bba32 100755
--- a/data/variables.py
+++ b/data/variables.py
@@ -163,6 +163,10 @@
 REDFISH_CHASSIS_THERMAL_URI = REDFISH_CHASSIS_URI + REDFISH_CHASSIS_THERMAL
 REDFISH_CHASSIS_POWER = 'chassis/Power/'
 REDFISH_CHASSIS_POWER_URI = REDFISH_CHASSIS_URI + REDFISH_CHASSIS_POWER
+REDFISH_CHASSIS_PSUPPLY0 = 'powersupply0/Power/'
+REDFISH_CHASSIS_PSUPPLY1 = 'powersupply1/Power/'
+REDFISH_CHASSIS_PSUPPLY0_URI = REDFISH_CHASSIS_URI + REDFISH_CHASSIS_PSUPPLY0
+REDFISH_CHASSIS_PSUPPLY1_URI = REDFISH_CHASSIS_URI + REDFISH_CHASSIS_PSUPPLY1
 
 # Boot options and URI variables.
 POWER_ON = 'On'
diff --git a/redfish/systems/test_powersupply_readings.robot b/redfish/systems/test_powersupply_readings.robot
new file mode 100755
index 0000000..835a288
--- /dev/null
+++ b/redfish/systems/test_powersupply_readings.robot
@@ -0,0 +1,116 @@
+*** Settings ***
+Documentation       Get the systems' power supply voltage readings.
+
+Resource            ../../lib/bmc_redfish_resource.robot
+Resource            ../../lib/bmc_redfish_utils.robot
+Resource            ../../lib/openbmc_ffdc.robot
+Library             ../../lib/gen_robot_valid.py
+
+Suite Setup         Suite Setup Execution
+Suite Teardown      Suite Teardown Execution
+Test Setup          Printn
+Test Teardown       Test Teardown Execution
+
+
+*** Test Cases ***
+
+Verify Power Supplies Input Watts
+    [Documentation]  Verify there are no invalid power supply input watt records.
+    [Tags]  Verify_Power_Supplies_Input_Watts
+    [Template]  Verify Watts Record
+
+    # record_type   redfish_uri                       reading_type
+    PowerSupplies   ${REDFISH_CHASSIS_PSUPPLY0_URI}   PowerInputWatts
+    PowerSupplies   ${REDFISH_CHASSIS_PSUPPLY1_URI}   PowerInputWatts
+
+
+Verify Power Supplies Input Output Voltages
+    [Documentation]  Verify there are no invalid power supply voltage records.
+    [Tags]  Verify_Power_Supplies_Input_Output_Voltages
+    [Template]  Verify Voltage Records
+
+    # record_type   redfish_uri                        reading_type
+    Voltages        ${REDFISH_CHASSIS_PSUPPLY0_URI}    ReadingVolts
+    Voltages        ${REDFISH_CHASSIS_PSUPPLY1_URI}    ReadingVolts
+
+
+*** Keywords ***
+
+Verify Watts Record
+    [Documentation]  Verify the power watt records.
+    [Arguments]  ${record_type}  ${redfish_uri}  ${reading_type}
+
+    # Description of Arguments(s):
+    # record_type    The sensor record type (e.g. "PowerSupplies")
+    # redfish_uri    The power supply URI (e.g. /redfish/v1/Chassis/powersupply0/Power)
+    # reading_type   The power watt readings (e.g. "PowerInputWatts")
+
+    Verify Valid Records  ${record_type}  ${redfish_uri}  ${reading_type}
+
+
+Verify Voltage Records
+    [Documentation]  Verify the power voltage records.
+    [Arguments]  ${record_type}  ${redfish_uri}  ${reading_type}
+
+    # Description of Arguments(s):
+    # record_type    The sensor record type (e.g. "Voltages")
+    # redfish_uri    The power supply URI (e.g. /redfish/v1/Chassis/powersupply0/Power)
+    # reading_type   The power voltage readings (e.g. "ReadingVolts")
+
+    Verify Valid Records  ${record_type}  ${redfish_uri}  ${reading_type}
+
+    ${records}=  Redfish.Get Attribute
+    ...  ${redfish_uri}  ${record_type}
+
+    ${invalid_records}=  Evaluate
+    ...  [x for x in ${records} if not x['LowerThresholdNonCritical'] <= x['${reading_type}'] <= x['UpperThresholdNonCritical']]
+
+    ${num_invalid_records}=  Get Length  ${invalid_records}
+    Run Keyword If  ${num_invalid_records} > ${0}
+    ...  Rprint Vars  num_invalid_records  invalid_records
+    Rvalid Value  num_invalid_records  valid_values=[0]
+
+
+Verify Valid Records
+    [Documentation]  Verify all the valid records.
+    [Arguments]  ${record_type}  ${redfish_uri}  ${reading_type}
+
+    # Description of Arguments(s):
+    # record_type    The sensor record type (e.g. "PowerSupplies")
+    # redfish_uri    The power supply URI (e.g. /redfish/v1/Chassis/powersupply0/Power)
+    # reading_type   The power watt readings (e.g. "PowerInputWatts")
+
+    # A valid record will have "State" key "Enabled" and "Health" key "OK".
+    ${records}=  Redfish.Get Attribute
+    ...  ${redfish_uri}  ${record_type}
+
+    ${num_records}=  Get Length  ${records}
+    Rprint Vars  num_records  records
+
+    ${invalid_records}=  Filter Struct  ${records}
+    ...  [('Health', '^OK$'), ('State', '^Enabled$'), ('${reading_type}', '')]  regex=1  invert=1
+    ${num_invalid_records}=  Get Length  ${invalid_records}
+
+    Run Keyword If  ${num_invalid_records} > ${0}
+    ...  Rprint Vars  num_invalid_records  invalid_records
+    Rvalid Value  num_invalid_records  valid_values=[0]
+
+
+Suite Teardown Execution
+    [Documentation]  Do the post suite teardown.
+
+    Redfish.Logout
+
+
+Suite Setup Execution
+    [Documentation]  Do test case setup tasks.
+
+    Printn
+    Redfish Power On
+    Redfish.Login
+
+
+Test Teardown Execution
+    [Documentation]  Do the post test teardown.
+
+    FFDC On Test Case Fail