IPMI: Added the logic to extract oem record count from sdr elist

Changes:
    - In test_ipmi_sdr.robot under "Verify SDR Info" added new keyword
      Fetch Sdr Type to extract the oem record count from sdr elist.
      New keyword logic has been added in lib/ipmi_util.py
Tested:
    - Ran ipmi/test_ipmi_sdr.robot script Successfully

Change-Id: I466e353c1224590fddc6175fa3c7dfe9ebbe5a2b
Signed-off-by: manimozhik <manimozhik@ami.com>
diff --git a/ipmi/test_ipmi_sdr.robot b/ipmi/test_ipmi_sdr.robot
index 4577dda..7ec5685 100755
--- a/ipmi/test_ipmi_sdr.robot
+++ b/ipmi/test_ipmi_sdr.robot
@@ -47,10 +47,15 @@
     ${sdr_info}=  Get SDR Info
     Should Be Equal  ${sdr_info['sdr_version']}  0x51
 
+    # Get SDR OEM record count from "sdr elist -vvv" command output.
+    ${sdr_data}=  Run IPMI Standard Command  sdr elist -vvv
+    ${sdr_oem}=  Fetch Sdr Count  ${sdr_data}
+    ${sdr_info_record_count}=  Evaluate  ${sdr_info['record_count']} - ${sdr_oem}
+
     # Get sensor count from "sdr elist all" command output.
     ${sensor_count}=  Get Sensor Count
     Should Be Equal As Strings
-    ...  ${sdr_info['record_count']}  ${sensor_count}
+    ...  ${sdr_info_record_count}  ${sensor_count}
 
     Should Be Equal  ${sdr_info['free_space']}  unspecified
     Should Not Be Equal  ${sdr_info['most_recent_addition']}  ${EMPTY}
diff --git a/lib/ipmi_utils.py b/lib/ipmi_utils.py
index 5d1598c..34fd701 100644
--- a/lib/ipmi_utils.py
+++ b/lib/ipmi_utils.py
@@ -353,6 +353,32 @@
     return result
 
 
+def fetch_sdr_count(sdr_data):
+    r"""
+    Get IPMI SDR list and return the SDR OEM count.
+
+    The data is obtained by issuing the IPMI "sdr elist -vvv" command.  An
+    example is shown below:
+
+    SDR record ID   : 0x00cb
+    SDR record ID   : 0x00cc
+    SDR record type : 0xc0
+    SDR record next : 0xffff
+    SDR record bytes: 11
+    Getting 11 bytes from SDR at offset 5
+
+    For the data shown above, the SDR record type with 0xc0 count will be returned.
+    """
+
+    data = sdr_data.split("\n")
+    sdr_list = []
+    for i, j in enumerate(data):
+        a = j.split(":")
+        if a[0].strip() == "SDR record type":
+            sdr_list.append(a[1].strip())
+    return sdr_list.count("0xc0")
+
+
 def get_aux_version(version_id):
     r"""
     Get IPMI Aux version info data and return it.