SEL Script Changes

ipmi/test_ipmi_sel_time.robot script changes
- In test_ipmi_sel_time.robot script created an time difference list and from time difference list
date and time will be either incremented or decremented.

- Removed Identify SEL Time Future DateTime and Identify SEL Time DateTime Delay and added Identify SEL Time keyword
for incrementing or decrementing date and time.

- Modified Verify Last SEL Added keyword previously sel elist last 1 command was used to get last sel entry but sometimes
while adding sel time at the same time there may be an chance other sel also can be generated. so handled the code to get
complete sel elist via ipmi sel elist command and fetch the sel entry based on sensor name and event type. keyword also
renamed to Verify SEL Added.

ipmi/test_ipmi_sel.robot
- As Get Data And Byte From SDR sensor keyword was modified based on the modification
remodified the variable for this keyword.
- Like ipmi_sel_time.robot script verify sel entry command was modified.

lib/ipmi_client.robot
- Get Data And Byte From SDR Sensor keyword return variable ${field_data} was removed.

Tested:
	- Tested ipmi/test_ipmi_sel_time.robot script.
	- Tested ipmi/test_ipmi_sel.robot script.

Signed-off-by: ganesanb <ganesanb@ami.com>
Change-Id: If0342c07c16ecc83a0cc092e6f3476eea42d63f5
diff --git a/ipmi/test_ipmi_sel.robot b/ipmi/test_ipmi_sel.robot
index b4b743d..13540ec 100644
--- a/ipmi/test_ipmi_sel.robot
+++ b/ipmi/test_ipmi_sel.robot
@@ -9,6 +9,14 @@
 Test Setup       Test Setup Execution
 Test Teardown    FFDC On Test Case Fail
 
+*** Variables ***
+
+# Based on 13th byte of add SEL entry command as per IPMI spec
+# event_dir and event_type variable value needs to be given.
+${sel_no_entry_msg}  SEL has no entries
+${event_type}        Lower Non-critical going low
+${event_dir}         Asserted
+
 *** Test Cases ***
 
 Verify IPMI SEL Version
@@ -70,11 +78,11 @@
 
     # Get Sensor ID from SDR get "sensor".
     ${sensor_data1}=  Fetch Sensor Details From SDR  ${sensor_name}  Sensor ID
-    ${name_sensor}  ${sensor_number}=  Get Data And Byte From SDR Sensor  ${sensor_data1}
+    ${sensor_number}=  Get Bytes From SDR Sensor  ${sensor_data1}
 
     # Get Sensor Type from SDR get "sensor".
     ${sensor_data2}=  Fetch Sensor Details From SDR  ${sensor_name}  Sensor Type (Threshold)
-    ${sensor_type}  ${sensor_type_id}=  Get Data And Byte From SDR Sensor  ${sensor_data2}
+    ${sensor_type_id}=  Get Bytes From SDR Sensor  ${sensor_data2}
 
     # Add SEL Entry.
     # ${sel_entry_id} is the Record ID for added record (LSB First).
@@ -82,15 +90,17 @@
     ${sel_entry_id}=  Split String  ${sel_create_resp}
 
     # Get last SEL entry.
-    ${resp}=  Run IPMI Standard Command  sel elist last 1
+    ${resp}=  Run IPMI Standard Command  sel elist
+    Should Not Contain  ${resp}  ${sel_no_entry_msg}
 
-    # Output of the Sel elist last 1.
+    # Output of the Sel elist.
     # Below example is a continuous line statement.
     #    N | MM/DD/YYYY | HH:MM:SS | Sensor_Type Sensor_Name |
     #    Lower Non-critical going low  | Asserted | Reading 0.
 
-    Run Keywords  Should Contain  ${resp}  ${sensor_type} ${sensor_name}  AND
-    ...  Should Contain  ${resp}  Asserted  msg=Add SEL Entry failed.
+    ${get_sel_entry}=  Get Lines Containing String  ${resp}  ${sensor_name}
+    ${sel_entry}=  Get Lines Containing String  ${get_sel_entry}  ${event_type}
+    Should Contain  ${sel_entry}  ${event_dir}  msg=Add SEL Entry failed.
 
     # Get SEL Entry IPMI Raw Command.
     ${entry}=  Get SEL Entry Via IPMI  ${sel_entry_id[0]}  ${sel_entry_id[1]}
@@ -148,11 +158,11 @@
 
         # Get Sensor ID from SDR Get "sensor" and Identify Sensor ID.
         ${sensor_data1}=  Fetch Sensor Details From SDR  ${sensor_name}  Sensor ID
-        ${name_sensor}  ${sensor_number}=  Get Data And Byte From SDR Sensor  ${sensor_data1}
+        ${sensor_number}=  Get Bytes From SDR Sensor  ${sensor_data1}
 
         # Get Sensor Type from SDR Get "sensor" and Identify Sensor Type.
         ${sensor_data2}=  Fetch Sensor Details From SDR  ${sensor_name}  Sensor Type (Threshold)
-        ${sensor_type}  ${sensor_type_id}=  Get Data And Byte From SDR Sensor  ${sensor_data2}
+        ${sensor_type_id}=  Get Bytes From SDR Sensor  ${sensor_data2}
 
         # Add SEL Entry.
         ${sel_create_resp}=  Create SEL  ${sensor_type_id}  ${sensor_number}
diff --git a/ipmi/test_ipmi_sel_time.robot b/ipmi/test_ipmi_sel_time.robot
index 367b968..7263c01 100644
--- a/ipmi/test_ipmi_sel_time.robot
+++ b/ipmi/test_ipmi_sel_time.robot
@@ -6,8 +6,6 @@
 ...
 ...              IPMI Raw command variables are defined under
 ...              ../data/ipmi_raw_command_table.py
-...              Python basic functionalities are defined under
-...              ../lib/functions.py imported under ../lib/resource.robot
 ...
 ...              Test the Set/Get SEL Time functionality and compare the result against
 ...              BMC Native command (date).
@@ -42,7 +40,16 @@
 *** Variables ***
 
 ${NETWORK_RESTART_TIME}   5s
+@{time_difference_list}  +8760:153:25  -87600:453:120  +175200:40:15  -43800:10:05  +20:35:12  -8760:00:00
 
+# Based on 13th byte of add SEL entry command as per IPMI spec 
+# event_dir and event_type variable value needs to be given.
+${sel_no_entry_msg}  SEL has no entries
+${event_type}        Lower Non-critical going low
+${event_dir}         Asserted
+# number_of_times_sel_entry_added this variable is used in Verify Multiple Set SEL Time With Multiple Add SEL Entry
+# test case. Need to give how many sel should be added with multiple date and time.
+${number_of_times_sel_entry_added}    6
 
 *** Test Cases ***
 
@@ -108,7 +115,7 @@
     [Tags]  Verify_Set_SEL_Time_With_Future_Date_And_Time
 
     # Gets BMC Current Time and Adds 15 minutes and sets the SEL Time.
-    ${sel_time}  ${set_sel_time}=  Identify SEL Time Future DateTime   06:15:00
+    ${sel_time}  ${set_sel_time}=  Identify SEL Time  +06:15:00
 
     # Set SEL Time via IPMI command.
     Set SEL Time Via IPMI  ${sel_time}
@@ -131,7 +138,7 @@
     [Tags]  Verify_Set_SEL_Time_With_Past_Date_And_Time
 
     # Gets BMC current time and subtracts 1 day and sets the SEL Time.
-    ${sel_time}  ${set_sel_time}=  Identify SEL Time DateTime Delay  1d
+    ${sel_time}  ${set_sel_time}=  Identify SEL Time  -24:00:00
 
     ${status}=  Run Keyword And Return Status  Should Not Contain  ${sel_time}  1969
     ...  msg=Date cannot be less than 1970.
@@ -230,17 +237,17 @@
 
     # Get Sensor ID from SDR Get "sensor".
     ${sensor_data1}=  Fetch Sensor Details From SDR  ${sensor_name}  Sensor ID
-    ${name_sensor}  ${sensor_number}=  Get Data And Byte From SDR Sensor  ${sensor_data1}
+    ${sensor_number}=  Get Bytes From SDR Sensor  ${sensor_data1}
 
     # Get Sensor Type from SDR Get "sensor".
     ${sensor_data2}=  Fetch Sensor Details From SDR  ${sensor_name}  Sensor Type (Threshold)
-    ${sensor_type}  ${sensor_type_id}=  Get Data And Byte From SDR Sensor  ${sensor_data2}
+    ${sensor_type_id}=  Get Bytes From SDR Sensor  ${sensor_data2}
 
     # Add SEL Entry.
     ${sel_create_resp}=  Create SEL  ${sensor_type_id}  ${sensor_number}
 
     # Finds the last added sel entry.
-    ${resp}=  Verify Last SEL Added  ${sensor_type}  ${sensor_name}
+    ${resp}=  Verify SEL Added  ${sensor_name}
 
     # Fetches the date of the last added SEL Entry.
     ${sel_entry_date}=  Fetch Added SEL Date  ${resp}
@@ -259,7 +266,7 @@
     Clear The SEL
 
     # Gets BMC Current Time and Adds 15 minutes and sets the SEL Time.
-    ${sel_time}  ${set_sel_time}=  Identify SEL Time Future DateTime   06:15:00
+    ${sel_time}  ${set_sel_time}=  Identify SEL Time  +06:15:00
 
     # Set SEL Time via IPMI command.
     Set SEL Time Via IPMI  ${sel_time}
@@ -281,17 +288,17 @@
 
     # Get Sensor ID from SDR Get "sensor".
     ${sensor_data1}=  Fetch Sensor Details From SDR  ${sensor_name}  Sensor ID
-    ${name_sensor}  ${sensor_number}=  Get Data And Byte From SDR Sensor  ${sensor_data1}
+    ${sensor_number}=  Get Bytes From SDR Sensor  ${sensor_data1}
 
     # Get Sensor Type from SDR Get "sensor".
     ${sensor_data2}=  Fetch Sensor Details From SDR  ${sensor_name}  Sensor Type (Threshold)
-    ${sensor_type}  ${sensor_type_id}=  Get Data And Byte From SDR Sensor  ${sensor_data2}
+    ${sensor_type_id}=  Get Bytes From SDR Sensor  ${sensor_data2}
 
     # Add SEL Entry.
     ${sel_create_resp}=  Create SEL  ${sensor_type_id}  ${sensor_number}
 
     # Finds the last added sel entry.
-    ${resp}=  Verify Last SEL Added  ${sensor_type}  ${sensor_name}
+    ${resp}=  Verify SEL Added  ${sensor_name}
 
     # Fetches the date of the last added SEL Entry.
     ${sel_entry_date}=  Fetch Added SEL Date  ${resp}
@@ -310,7 +317,7 @@
     Clear The SEL
 
     # Gets BMC Current Time and subtracts 1 day and sets the SEL Time.
-    ${sel_time}  ${set_sel_time}=  Identify SEL Time DateTime Delay  1d
+    ${sel_time}  ${set_sel_time}=  Identify SEL Time  -24:00:00
 
     ${status}=  Run Keyword And Return Status  Should Not Contain  ${sel_time}  1969
     ...  msg=Date cannot be less than 1970
@@ -332,17 +339,17 @@
         ${sensor_name}=  Fetch One Threshold Sensor From Sensor List
         # Get Sensor ID from SDR Get "sensor".
         ${sensor_data1}=  Fetch Sensor Details From SDR  ${sensor_name}  Sensor ID
-        ${name_sensor}  ${sensor_number}=  Get Data And Byte From SDR Sensor  ${sensor_data1}
+        ${sensor_number}=  Get Bytes From SDR Sensor  ${sensor_data1}
 
         # Get Sensor Type from SDR Get "sensor".
         ${sensor_data2}=  Fetch Sensor Details From SDR  ${sensor_name}  Sensor Type (Threshold)
-        ${sensor_type}  ${sensor_type_id}=  Get Data And Byte From SDR Sensor  ${sensor_data2}
+        ${sensor_type_id}=  Get Bytes From SDR Sensor  ${sensor_data2}
 
         # Add SEL Entry.
         ${sel_create_resp}=  Create SEL  ${sensor_type_id}  ${sensor_number}
 
         # Finds the last added sel entry.
-        ${resp}=  Verify Last SEL Added  ${sensor_type}  ${sensor_name}
+        ${resp}=  Verify SEL Added  ${sensor_name}
 
         # Fetches the date of the last added SEL Entry.
         ${sel_entry_date}=  Fetch Added SEL Date  ${resp}
@@ -361,10 +368,9 @@
     [Documentation]  Verify SEL time in multiple addition Of SEL entry.
     [Tags]  Verify_Multiple_Set_SEL_Time_With_Multiple_Add_SEL_Entry
 
-    # Gets BMC Current Time and Adds 15 minutes and sets the SEL Time.
-    ${sel_time}  ${set_sel_time}=  Identify SEL Time Future DateTime   06:15:00
+    FOR  ${i}  IN RANGE  ${number_of_times_sel_entry_added}
 
-    FOR  ${i}  IN RANGE  1  6
+      ${sel_time}  ${set_sel_time}=  Identify SEL Time  ${time_difference_list[${i}]}
 
       # Set SEL Time via IPMI command.
       Set SEL Time Via IPMI  ${sel_time}
@@ -377,17 +383,17 @@
 
       # Get Sensor ID from SDR Get "sensor" and Identify Sensor ID.
       ${sensor_data1}=  Fetch Sensor Details From SDR  ${sensor_name}  Sensor ID
-      ${name_sensor}  ${sensor_number}=  Get Data And Byte From SDR Sensor  ${sensor_data1}
+      ${sensor_number}=  Get Bytes From SDR Sensor  ${sensor_data1}
 
       # Get Sensor Type from SDR Get "sensor" and identify Sensor Type.
       ${sensor_data2}=  Fetch Sensor Details From SDR  ${sensor_name}  Sensor Type (Threshold)
-      ${sensor_type}  ${sensor_type_id}=  Get Data And Byte From SDR Sensor  ${sensor_data2}
+      ${sensor_type_id}=  Get Bytes From SDR Sensor  ${sensor_data2}
 
       # Add SEL Entry.
       ${sel_create_resp}=  Create SEL  ${sensor_type_id}  ${sensor_number}
 
       # Finds the last added sel entry.
-      ${resp}=  Verify Last SEL Added  ${sensor_type}  ${sensor_name}
+      ${resp}=  Verify SEL Added  ${sensor_name}
 
       # Fetches the date of the last added SEL Entry.
       ${sel_entry_date}=  Fetch Added SEL Date  ${resp}
@@ -471,20 +477,20 @@
     Sleep  2s
 
 
-Verify Last SEL Added
-    [Documentation]  Verify last SEL added.
-    [Arguments]  ${sensor_type}  ${sensor_name}
+Verify SEL Added
+    [Documentation]  Verify Added SEL.
+    [Arguments]  ${sensor_name}
 
     # Description of argument(s):
-    # ${sensor_type}         Type of the sensor (say Fan, Temp, etc.,).
-    # ${sensor_name}         Name of the sensor.
+    # sensor_name         Name of the sensor.
 
-    ${resp}=  Run IPMI Standard Command  sel elist last 1
-    Run Keywords  Should Contain  ${resp}  ${sensor_type} ${sensor_name}  AND
-    ...  Should Contain  ${resp}  Asserted  msg=Add SEL Entry failed.
-    Should Not Contain  ${resp}  reset/cleared
+    ${resp}=  Run IPMI Standard Command  sel elist
+    Should Not Contain  ${resp}  ${sel_no_entry_msg}
+    ${get_sel_entry}=  Get Lines Containing String  ${resp}  ${sensor_name}
+    ${sel_entry}=  Get Lines Containing String  ${get_sel_entry}  ${event_type}
+    Should Contain  ${sel_entry}  ${event_dir}  msg=Add SEL Entry failed.
 
-    [Return]  ${resp}
+    [Return]  ${sel_entry}
 
 
 Check Current Date Time Via IPMI
@@ -552,18 +558,28 @@
     [Return]  ${diff}
 
 
-Identify SEL Time Future DateTime
-    [Documentation]  Identify SEL Time Future DateTime.
+Identify SEL Time
+    [Documentation]  Modify SEL Time From BMC For Set Sel Time Command.
     [Arguments]  ${time}
 
     # Description of argument(s):
-    # ${time}             Can be any number of hours or minutes in format %H:%M:%S.
+    # time             Can be any number of hours or minutes in format %H:%M:%S.
 
     # Gets BMC current date via date command.
     ${current_date}=  Get Current Date from BMC
 
-    ${datetime} =  Add Time To Date
-    ...  ${current_date}  ${time}  result_format=%m/%d/%Y %H:%M:%S  date_format=%m/%d/%Y %H:%M:%S
+    ${modifying_date_status}=  Run Keyword And Return Status  Should Contain  ${time}  +
+
+    ${date_time}=  Set Variable IF
+    ...  ${modifying_date_status} == True  ${time.split("+")[-1]}
+    ...  ${modifying_date_status} == False  ${time.split("-")[-1]}
+
+    ${datetime} =  Run Keyword IF  ${modifying_date_status} == True
+    ...    Add Time To Date
+    ...    ${current_date}  ${date_time}  result_format=%m/%d/%Y %H:%M:%S  date_format=%m/%d/%Y %H:%M:%S
+    ...  ELSE IF  ${modifying_date_status} == False
+    ...    Subtract Time From Date
+    ...    ${current_date}  ${date_time}  result_format=%m/%d/%Y %H:%M:%S  date_format=%m/%d/%Y %H:%M:%S
 
     #Set SEL Time.
     ${quoted_date}=  Fetch Date  ${datetime}
@@ -571,26 +587,6 @@
     [Return]  ${quoted_date}  ${datetime}
 
 
-Identify SEL Time DateTime Delay
-    [Documentation]  Identify SEL Time DateTime Delay by subtracting given date.
-    [Arguments]  ${days}
-
-    # Description of argument(s):
-    # ${days}             Can be any days (say 3d).
-
-    # Gets BMC current date via date command.
-    ${current_date}=  Get Current Date from BMC
-
-    ${datetime}=  Subtract Time From Date
-    ...  ${current_date}  ${days}  result_format=%m/%d/%Y %H:%M:%S  date_format=%m/%d/%Y %H:%M:%S
-
-    # Format the sel time.
-    # function call from lib/utils.py.
-    ${quoted_date}=  Fetch Date  ${datetime}
-
-    [Return]  ${quoted_date}  ${datetime}
-
-
 Set SEL Time Via IPMI
     [Documentation]  Set SEL Time for given date using IPMI.
     [Arguments]  ${date_time}
diff --git a/lib/ipmi_client.robot b/lib/ipmi_client.robot
index 87dd411..136aa3d 100755
--- a/lib/ipmi_client.robot
+++ b/lib/ipmi_client.robot
@@ -545,7 +545,7 @@
     [Return]  ${setting_status}
 
 
-Get Data And Byte From SDR Sensor
+Get Bytes From SDR Sensor
     [Documentation]  Fetch the Field Data and hexadecimal values from given details.
     [Arguments]  ${sensor_detail}
 
@@ -555,12 +555,10 @@
     #                          ${sensor_detail} will be "Sensor ID : SENSOR_1 (0xHH)"
 
     ${sensor_detail}=  Split String  ${sensor_detail}  (0x
-    ${field_data}=  Set Variable  ${sensor_detail[0]}
-    ${field_data}=  Remove Whitespace  ${field_data}
     ${sensor_hex}=  Replace String  ${sensor_detail[1]}  )  ${EMPTY}
     ${sensor_hex}=  Zfill Data  ${sensor_hex}  2
 
-    [Return]  ${field_data}  ${sensor_hex}
+    [Return]  ${sensor_hex}
 
 
 Get Current Date from BMC