Test power reading via IPMI with Host booted.

Resolves openbmc/openbmc-test-automation#1195

Change-Id: I255338c7d8d487c0387ab82c16d5c000e46f5087
Signed-off-by: Rahul Maheshwari <rahulmaheshwari@in.ibm.com>
diff --git a/tests/ipmi/test_general_ipmi.robot b/tests/ipmi/test_general_ipmi.robot
index 56e5ff4..6c40b76 100644
--- a/tests/ipmi/test_general_ipmi.robot
+++ b/tests/ipmi/test_general_ipmi.robot
@@ -3,6 +3,8 @@
 
 Resource            ../../lib/ipmi_client.robot
 Resource            ../../lib/openbmc_ffdc.robot
+Resource            ../lib/boot_utils.robot
+Library             ../../lib/ipmi_utils.py
 
 Test Teardown       FFDC On Test Case Fail
 
@@ -10,6 +12,7 @@
 
 ${new_mc_id}=  HOST
 ${allowed_temp_diff}=  ${1}
+${allowed_power_diff}=  ${10}
 
 *** Test Cases ***
 
@@ -235,6 +238,54 @@
     ...  msg=Supported DCMI capabilities not present.
 
 
+Test Power Reading Via IPMI With Host Booted
+    [Documentation]  Test power reading via IPMI with host booted state and
+    ...  verify using REST.
+    [Tags]  Test_Power_Reading_Via_IPMI_With_Host_Booted
+
+    REST Power On  stack_mode=skip  quiet=1
+
+    # Example of power reading command output via IPMI.
+    # Instantaneous power reading:                   235 Watts
+    # Minimum during sampling period:                235 Watts
+    # Maximum during sampling period:                235 Watts
+    # Average power reading over sample period:      235 Watts
+    # IPMI timestamp:                           Thu Jan  1 00:00:00 1970
+    # Sampling period:                          00000000 Seconds.
+    # Power reading state is:                   deactivated
+
+    ${power_reading}=  Get IPMI Power Reading
+    ${power_reading_ipmi}=  Set Variable
+    ...  ${power_reading['instantaneous_power_reading']}
+    ${power_reading_ipmi}=  Remove String  ${power_reading_ipmi}  ${SPACE}Watts
+
+    ${power_reading_rest}=  Read Attribute
+    ...  ${SENSORS_URI}power/total_power  Value
+
+    # Example of power reading via REST
+    #  "CriticalAlarmHigh": 0,
+    #  "CriticalAlarmLow": 0,
+    #  "CriticalHigh": 3100000000,
+    #  "CriticalLow": 0,
+    #  "Scale": -6,
+    #  "Unit": "xyz.openbmc_project.Sensor.Value.Unit.Watts",
+    #  "Value": 228000000,
+    #  "WarningAlarmHigh": 0,
+    #  "WarningAlarmLow": 0,
+    #  "WarningHigh": 3050000000,
+    #  "WarningLow": 0
+
+    # Get power value based on scale i.e. Value * (10 power Scale Value)
+    # e.g. from above case 228000000 * (10 power -6) = 228000000/1000000
+
+    ${power_reading_rest}=  Evaluate  ${power_reading_rest}/1000000
+    ${ipmi_rest_power_diff}=
+    ...  Evaluate  abs(${power_reading_rest} - ${power_reading_ipmi})
+
+    Should Be True  ${ipmi_rest_power_diff} <= ${allowed_power_diff}
+    ...  msg=Power reading above allowed threshold ${allowed_power_diff}.
+
+
 *** Keywords ***
 
 Set Management Controller ID String