eSEL test verification

Added use cases are:
   1. Verify eSEL Entries Using REST
   2. Verify Multiple eSEL Using REST
   3. Restructuring changes

Resolves openbmc/openbmc-test-automation#365

Change-Id: I244ef735a75b45bdf728fe07801f3b2fceba59c6
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/tests/test_esel.robot b/tests/test_esel.robot
index ed0fdc4..c9db34e 100644
--- a/tests/test_esel.robot
+++ b/tests/test_esel.robot
@@ -7,7 +7,7 @@
 Variables           ../data/variables.py
 
 Suite Setup         Open Connection And Log In
-Suite Teardown      Close All Connections
+Suite Teardown      Test Cleanup On Exit
 Test Teardown       FFDC On Test Case Fail
 
 Force Tags  eSEL_Logging
@@ -25,29 +25,42 @@
 
 ${LOGGING_SERVICE}  xyz.openbmc_project.Logging.service
 
+${ESEL_DATA}        ESEL=00 00 df 00 00 00 00 20 00 04 12 35 6f aa 00 00
+
 *** Test Cases ***
 
 Verify eSEL Using REST
-    [Documentation]  Generate eSEL log and Verify using REST.
+    [Documentation]  Generate eSEL log and verify using REST.
     [setup]  Restart Logging Service
     [Tags]  Verify_eSEL_Using_REST
 
-    # Prior eSEL log shouldn't exist
+    # Prior eSEL log shouldn't exist.
     ${resp}=   OpenBMC Get Request  ${BMC_LOGGING_ENTRY}${1}
     Should Be Equal As Strings  ${resp.status_code}  ${HTTP_NOT_FOUND}
-
-    Open Connection And Log In
-    ${Resv_id}=  Run Dbus IPMI Standard Command  ${RESERVE_ID}
-    ${cmd}=  Catenate
-    ...  ${RAW_PREFIX}${Resv_id.strip().rsplit(' ', 1)[0]}  ${RAW_SUFFIX}
-    Run Dbus IPMI Standard Command  ${cmd}
-    Run Dbus IPMI Standard Command  ${RAW_SEL_COMMIT}
-
+    Create eSEL
     # New eSEL log should exist
     ${resp}=   OpenBMC Get Request  ${BMC_LOGGING_ENTRY}${1}
     Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
 
 
+Verify eSEL Entries Using REST
+    [Documentation]  Verify that eSEL entries have data.
+    [setup]  Restart Logging Service
+    [Tags]  Verify_eSEL_Entries_Using_REST
+    Create eSEL
+    Verify eSEL Entries
+
+
+Verify Multiple eSEL Using REST
+    [Documentation]  Generate multiple eSEL log and Verify using REST.
+    [setup]  Restart Logging Service
+    [Tags]  Verify_Multiple_eSEL_Using_REST
+    Create eSEL
+    Create eSEL
+    ${entries}=  Count eSEL Entries
+    Should Be Equal As Integers  ${entries}  ${2}
+
+
 Test Wrong Reservation_ID
     [Documentation]   This testcase is to test BMC can handle multi-requestor's
     ...               oem partial add command with incorrect reservation id.
@@ -85,6 +98,51 @@
 
 *** Keywords ***
 
+Create eSEL
+    [Documentation]  Create an eSEL.
+    Open Connection And Log In
+    ${Resv_id}=  Run Dbus IPMI Standard Command  ${RESERVE_ID}
+    ${cmd}=  Catenate
+    ...  ${RAW_PREFIX}${Resv_id.strip().rsplit(' ', 1)[0]}  ${RAW_SUFFIX}
+    Run Dbus IPMI Standard Command  ${cmd}
+    Run Dbus IPMI Standard Command  ${RAW_SEL_COMMIT}
+
+
+Count eSEL Entries
+    [Documentation]  Count eSEL entries logged.
+    ${resp}=  OpenBMC Get Request  ${BMC_LOGGING_ENTRY}
+    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
+    ${jsondata}=  To JSON  ${resp.content}
+    ${count}=  Get Length  ${jsondata["data"]}
+    [Return]  ${count}
+
+
+Verify eSEL Entries
+    [Documentation]  Verify eSEL entries logged.
+    ${resp}=  OpenBMC Get Request  ${BMC_LOGGING_ENTRY}${1}
+    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
+    ${jsondata}=  To JSON  ${resp.content}
+    #  "data": {
+    #       "AdditionalData": [
+    #           "ESEL=00 00 df 00 00 00 00 20 00 04 12 35 6f aa 00 00 "
+    #          ],
+    #       "Id": 1,
+    #       "Message": "org.open_power.Error.Host.Event.Event",
+    #       "Severity": "xyz.openbmc_project.Logging.Entry.Level.Emergency",
+    #       "Timestamp": 1485904869061
+    # }
+
+    Should Be Equal As Integers  ${jsondata["data"]["Id"]}  ${1}
+    Should Be Equal As Strings
+    ...  ${jsondata["data"]["AdditionalData"][0].rstrip()}  ${ESEL_DATA}
+
+
+Test Cleanup On Exit
+    [Documentation]  Cleanup test logs and connection.
+    Restart Logging Service
+    Close All Connections
+
+
 Restart Logging Service
     [Documentation]  Restart Logging to clear eSEL log.
     ${MainPID}  ${stderr}=  Execute Command