Update Test Errorlog use cases testing logic

Existing test assumes that clearing the logs works, creates one
and index 0 of the list is the one created for the test.

The new changes address the following:
  - Clear eventlog should not be 'the' factor to fail the test
    because event can be created and still validated
  - Clear eventlog failure would reported by new test case
  - bustcl returns event out as in format 'q event_number'
    example  'q 154'. Test will fails
     1. If this event number generated is not listed
     2. If there is an error during command execution

Resolves openbmc/openbmc-test-automation#146

Change-Id: I4ea87c04bd35279727d6966f8372cdcc4e8a9fd6
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/tests/test_association.robot b/tests/test_association.robot
index fdc7b0e..f4f8595 100755
--- a/tests/test_association.robot
+++ b/tests/test_association.robot
@@ -8,7 +8,7 @@
 
 Library           Collections
 
-Suite Setup       Open Connection And Log In
+Suite Setup       Suite Initialization Setup
 Suite Teardown    Close All Connections
 
 Test Teardown     Log FFDC
@@ -35,6 +35,8 @@
 
 &{NIL}                            data=@{EMPTY}
 
+${EVENT_RECORD}                   /org/openbmc/records/events
+
 *** Test Cases ***
 
 Create error log on single FRU
@@ -43,14 +45,21 @@
     ...                 its association.\n
     [Tags]  Create_error_log_on_single_FRU
 
-    Clear all logs
+    Run Keyword And Continue On Failure   Clear all logs
 
-    ${output}=      Execute Command    ${CREATE_ERROR_SINGLE_FRU}
+    ${elog}  ${stderr}=
+    ...   Execute Command    ${CREATE_ERROR_SINGLE_FRU}
+    ...   return_stderr=True
+    Should Be Empty    ${stderr}
 
     ${log_list} =     Get EventList
-    ${association_uri} =    catenate    SEPARATOR=   ${log_list[0]}   /fru
+    Should Contain   '${log_list}'   ${elog.strip('q ')}
 
-    ${association_content} =     Read Attribute    ${association_uri}    endpoints
+    ${association_uri} =
+    ...   catenate  SEPARATOR=   ${EVENT_RECORD}/${elog.strip('q ')}  /fru
+
+    ${association_content} =
+    ...     Read Attribute    ${association_uri}    endpoints
     Should Contain     ${association_content}    ${DIMM1_URI}
 
     ${dimm1_event} =     Read Attribute     ${DIMM1_URI}/event   endpoints
@@ -78,7 +87,7 @@
 
 Create multiple error logs
     [Documentation]     ***GOOD PATH***
-    ...                 Create multiple error logs and verify 
+    ...                 Create multiple error logs and verify
     ...                 their association.\n
 
     : FOR    ${INDEX}    IN RANGE    1    4
@@ -99,7 +108,7 @@
 
 Delete error log
     [Documentation]     ***BAD PATH***
-    ...                 Delete an error log and verify that its 
+    ...                 Delete an error log and verify that its
     ...                 association is also removed.\n
     [Tags]  Delete_error_log
 
@@ -128,11 +137,18 @@
     ...                 Create an error log on invalid FRU and verify
     ...                 that its does not have any association.\n
 
-    Clear all logs
+    Run Keyword And Continue On Failure   Clear all logs
 
-    ${output}=      Execute Command    ${CREATE_ERROR_INVALID_FRU}
+    ${elog}  ${stderr}=
+    ...   Execute Command    ${CREATE_ERROR_INVALID_FRU}
+    ...   return_stderr=True
+    Should Be Empty    ${stderr}
+
     ${log_list} =     Get EventList
-    ${association_uri} =    catenate    SEPARATOR=   ${log_list[0]}   /fru
+    Should Contain   '${log_list}'   ${elog.strip('q ')}
+
+    ${association_uri} =
+    ...   catenate  SEPARATOR=  ${EVENT_RECORD}/${elog.strip('q ')}  /fru
 
     ${resp} =     openbmc get request     ${association_uri}
     ${jsondata} =    to json    ${resp.content}
@@ -144,11 +160,18 @@
     ...                 Create an error log on no FRU and verify
     ...                 that its does not have any association.\n
 
-    Clear all logs
+    Run Keyword And Continue On Failure   Clear all logs
 
-    ${output}=      Execute Command    ${CREATE_ERROR_NO_FRU}
+    ${elog}  ${stderr}=
+    ...   Execute Command    ${CREATE_ERROR_NO_FRU}
+    ...   return_stderr=True
+    Should Be Empty    ${stderr}
+
     ${log_list} =     Get EventList
-    ${association_uri} =    catenate    SEPARATOR=   ${log_list[0]}   /fru
+    Should Contain   '${log_list}'   ${elog.strip('q ')}
+
+    ${association_uri} =
+    ...   catenate    SEPARATOR=   ${EVENT_RECORD}/${elog.strip('q ')}  /fru
 
     ${resp} =     openbmc get request     ${association_uri}
     ${jsondata} =    to json    ${resp.content}
@@ -161,14 +184,23 @@
     ...                 verify its association.\n
     [Tags]              Association_with_virtual_sensor
 
-    Clear all logs
+    Run Keyword And Continue On Failure   Clear all logs
 
-    ${output}=      Execute Command    ${CREATE_ERROR_VIRTUAL_SENSOR}
+    ${elog}  ${stderr}=
+    ...   Execute Command    ${CREATE_ERROR_VIRTUAL_SENSOR}
+    ...   return_stderr=True
+    Should Be Empty    ${stderr}
+
     ${log_list} =     Get EventList
-    ${association_uri} =    catenate    SEPARATOR=   ${log_list[0]}   /fru
+    Should Contain   '${log_list}'   ${elog.strip('q ')}
 
-    ${association_content} =     Read Attribute    ${association_uri}    endpoints
-    Should Contain     ${association_content}    /org/openbmc/inventory/system/systemevent
+    ${association_uri} =
+    ...   catenate    SEPARATOR=   ${EVENT_RECORD}/${elog.strip('q ')}  /fru
+
+    ${association_content} =
+    ...     Read Attribute    ${association_uri}    endpoints
+    Should Contain
+    ...     ${association_content}    /org/openbmc/inventory/system/systemevent
 
 Association unchanged after reboot
     [Documentation]     ***GOOD PATH***
@@ -215,3 +247,7 @@
     ${resp} =   openbmc get request     /org/openbmc/records/events/
     ${json} =   to json         ${resp.content}
     Should Be Empty     ${json['data']}
+
+Suite Initialization Setup
+    Open Connection And Log In
+    Run Keyword And Continue On Failure   Clear all logs