Added testcases to verify IPMI, DCMI sensor readings with Redfish

Signed-off-by: Anusha Dathatri <adathatr@in.ibm.com>
Change-Id: I03ee36cdc656a5e4a405cf0a06d2daec901fe670
diff --git a/ipmi/test_ipmi_sensor.robot b/ipmi/test_ipmi_sensor.robot
new file mode 100644
index 0000000..aa16e37
--- /dev/null
+++ b/ipmi/test_ipmi_sensor.robot
@@ -0,0 +1,98 @@
+*** Settings ***
+Documentation  Validate IPMI sensor IDs using Redfish.
+
+Resource          ../lib/ipmi_client.robot
+Resource          ../lib/openbmc_ffdc.robot
+
+Suite Setup       Redfish.Login
+Suite Teardown    Redfish.Logout
+Test Setup        Printn
+Test Teardown     FFDC On Test Case Fail
+
+*** Test Cases ***
+
+Verify IPMI Temperature Readings using Redfish
+    [Documentation]  Verify temperatures from IPMI sensor reading command using Redfish.
+    [Tags]  Verify_IPMI_Temperature_Readings_using_Redfish
+    [Template]  Get Temperature Reading And Verify In Redfish
+
+    # command_type  sensor_id  member_id
+    IPMI            pcie       pcie
+    IPMI            ambient    ambient
+
+
+Verify DCMI Temperature Readings using Redfish
+    [Documentation]  Verify temperatures from DCMI sensor reading command using Redfish.
+    [Tags]  Verify_DCMI_Temperature_Readings_using_Redfish
+    [Template]  Get Temperature Reading And Verify In Redfish
+
+    # command_type  sensor_id  member_id
+    DCMI            pcie       pcie
+    DCMI            ambient    ambient
+
+*** Keywords ***
+
+Get Temperature Reading And Verify In Redfish
+    [Documentation]  Get IPMI or DCMI sensor reading and verify in Redfish.
+    [Arguments]  ${command_type}  ${sensor_id}  ${member_id}
+
+    # Description of argument(s):
+    # command_type  Type of command used to get sensor data (eg. IPMI, DCMI).
+    # sensor_id     Sensor id used to get reading in IPMI or DCMI.
+    # member_id     Member id of sensor data in Redfish.
+
+    ${ipmi_value}=  Run Keyword If  '${command_type}' == 'IPMI'  Get IPMI Sensor Reading  ${sensor_id}
+    ...  ELSE  Get DCMI Sensor Reading  ${sensor_id}
+
+    ${redfish_value}=  Get Temperature Reading From Redfish  ${member_id}
+
+    Valid Range  ${ipmi_value}  ${redfish_value-1.000}  ${redfish_value+1.000}
+
+
+Get IPMI Sensor Reading
+    [Documentation]  Get reading from IPMI sensor reading command.
+    [Arguments]  ${sensor_id}
+
+    # Description of argument(s):
+    # sensor_id     Sensor id used to get reading in IPMI.
+
+    ${data}=  Run IPMI Standard Command  sensor reading ${sensor_id}
+
+    # Example reading:
+    # pcie             | 28.500
+
+    ${sensor_value}=  Set Variable  ${data.split('| ')[1].strip()}
+    [Return]  ${sensor_value}
+
+
+Get DCMI Sensor Reading
+    [Documentation]  Get reading from DCMI sensors command.
+    [Arguments]  ${sensor_id}
+
+    # Description of argument(s):
+    # sensor_id     Sensor id used to get reading in DCMI.
+
+    ${data}=  Run IPMI Standard Command  dcmi sensors
+    ${sensor_data}=  Get Lines Containing String  ${data}  ${sensor_id}
+
+    # Example reading:
+    # Record ID 0x00fd: pcie             | 28.50 degrees C   | ok
+
+    ${sensor_value}=  Set Variable  ${sensor_data.split(' | ')[1].strip('degrees C').strip()}
+    [Return]  ${sensor_value}
+
+
+Get Temperature Reading From Redfish
+    [Documentation]  Get temperature reading from Redfish.
+    [Arguments]  ${member_id}
+
+    # Description of argument(s):
+    # member_id    Member id of temperature.
+
+    @{redfish_readings}=  Redfish.Get Attribute  /redfish/v1/Chassis/chassis/Thermal  Temperatures
+    FOR  ${data}  IN  @{redfish_readings}
+        ${redfish_value}=  Set Variable If  '&{data}[MemberId]' == '${member_id}'
+        ...  &{data}[ReadingCelsius]
+        Exit For Loop If  '&{data}[MemberId]' == '${member_id}'
+    END
+    [Return]  ${redfish_value}
\ No newline at end of file