Remote logging test suite updates

Changes:
    - Added "Test Setup Execution" keyword.
    - Added "Remote Logging Server Not Configured" keywords.
    - Move "Get Service Attribute" keywords to lib/utils.robot.
    - Minor changes TODO.

Change-Id: I457bb8bca694913294ad277467dd92af783928e2
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/lib/utils.robot b/lib/utils.robot
index 2586e6b..53072d5 100755
--- a/lib/utils.robot
+++ b/lib/utils.robot
@@ -1547,3 +1547,14 @@
     ...    Should Be Empty  ${journal_log}
     ...  ELSE
     ...    Should Not Be Empty  ${journal_log}
+
+
+Get Service Attribute
+    [Documentation]  Get service attribute policy output.
+    [Arguments]  ${option}  ${servicename}
+    # option  systemctl supported options
+    # servicename  Qualified service name
+    ${cmd}=  Set Variable
+    ...  systemctl -p ${option} show ${servicename} | cut -d = -f2
+    ${attr}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
+    [Return]  ${attr}
diff --git a/remote_logging/test_remote_logging.robot b/remote_logging/test_remote_logging.robot
index 10fb992..d82dc39 100644
--- a/remote_logging/test_remote_logging.robot
+++ b/remote_logging/test_remote_logging.robot
@@ -15,6 +15,7 @@
 Resource         ../lib/boot_utils.robot
 
 Suite Setup      Suite Setup Execution
+Test Setup       Test Setup Execution
 Test Teardown    FFDC On Test Case Fail
 
 *** Variables ***
@@ -32,7 +33,6 @@
     [Documentation]  Test remote logging interface and configuration.
     [Tags]  Test_Remote_Logging_REST_Interface_And_Verify_Config
 
-    Configure Remote Logging Server
     Verify Rsyslog Config On BMC
 
     Configure Remote Logging Server  remote_host=${EMPTY}  remote_port=0
@@ -59,27 +59,25 @@
     [Documentation]  Check that BMC journald is sync to remote rsyslog.
     [Tags]  Verfiy_BMC_Journald_Synced_To_Remote_Logging_Server
 
-    ${hostname}  ${stderr}  ${rc}=  BMC Execute Command  /bin/hostname
-    Remove Journald Logs
-
-    Configure Remote Logging Server
-    # Take a couple second to restart rsyslog service.
-    Sleep  3s
-
     # Restart BMC dump service and get the last entry of the journald.
     # Example:
-    # Aug 31 15:16:54 wsbmc123 systemd[1]: Started Phosphor Dump Manager
+    # Sep 03 10:09:28 wsbmc123 systemd[1]: Started Phosphor Dump Manager.
     BMC Execute Command
     ...  systemctl restart xyz.openbmc_project.Dump.Manager.service
 
     ${bmc_journald}  ${stderr}  ${rc}=  BMC Execute Command
     ...  journalctl --no-pager | tail -1
 
-    ${cmd}=  Catenate  cat /var/log/syslog|grep ${hostname} | tail -1
+    # Sep 3 10:09:28 wsbmc123 systemd[1]: Started Phosphor Dump Manager.
+    ${cmd}=  Catenate  cat /var/log/syslog|grep ${bmc_hostname} | tail -1
     ${remote_journald}=  Remote Logging Server Execute Command  command=${cmd}
 
-    Should Be Equal As Strings   ${bmc_journald}  ${remote_journald}
-    ...  msg=${bmc_journald} and ${remote_journald} don't match.
+    # TODO: rsyslog configuration and time date template to match BMC journald.
+    # Compare the BMC journlad log. Example:
+    # systemd[1]: Started Phosphor Dump Manager.
+    Should Be Equal As Strings   ${bmc_journald.split('${bmc_hostname}')[1]}
+    ...  ${remote_journald.split('${bmc_hostname}')[1]}
+    ...  msg= ${bmc_journald} doesn't match remote rsyslog:${remote_journald}.
 
 
 Verify Journald Post BMC Reset
@@ -137,6 +135,23 @@
     Remote Logging Server Execute Command  true
     Remote Logging Interface Should Exist
 
+    ${hostname}  ${stderr}  ${rc}=  BMC Execute Command  /bin/hostname
+    Set Suite Variable  ${bmc_hostname}  ${hostname}
+
+
+Test Setup Execution
+    [Documentation]  Do the test setup.
+
+    Remove Journald Logs
+    ${cofig_status}=  Run Keyword And Return Status
+    ...  Get Remote Log Server Configured
+
+    Run Keyword If  ${config_status}==${FALSE}  Configure Remote Logging Server
+
+    ${ActiveState}=  Get Service Attribute  ActiveState  rsyslog.service
+    Should Be Equal  active  ${ActiveState}
+    ...  msg=rsyslog logging service not in active state.
+
 
 Remote Logging Interface Should Exist
     [Documentation]  Check that the remote logging URI exist.
@@ -170,11 +185,21 @@
     Write Attribute  ${REMOTE_LOGGING_URI}  Address  data=${host_dict}
     ...  verify=${TRUE}  expected_value=${remote_host}
 
+    # TODO: From Dev to do bump up restart service time and bulk address and
+    # port update API.
+    # Reference: https://github.com/ibm-openbmc/dev/issues/59
+    Sleep  10s
+
     ${remote_port}=  Convert To Integer  ${remote_port}
     ${port_dict}=  Create Dictionary  data=${remote_port}
     Write Attribute  ${REMOTE_LOGGING_URI}  Port  data=${port_dict}
     ...  verify=${TRUE}  expected_value=${remote_port}
 
+    # TODO: From Dev to do bump up restart service time and bulk address and
+    # port update API.
+    # Reference: https://github.com/ibm-openbmc/dev/issues/59
+    Sleep  10s
+
 
 Verify Rsyslog Config On BMC
     [Documentation]  Check if the rsyslog configuration on BMC is correct.
@@ -205,13 +230,30 @@
     [Documentation]  Login to remote logging server.
     [Arguments]  ${command}
     ...          ${remote_host}=${REMOTE_LOG_SERVER_HOST}
-    ...          ${user_name}=${REMOTE_USERNAME}
-    ...          ${user_password}=${REMOTE_PASSWORD}
+    ...          ${username}=${REMOTE_USERNAME}
+    ...          ${password}=${REMOTE_PASSWORD}
+
+    # Description of argument(s):
+    # command          Command line string.
+    # remote_host    The host name or IP address of the remote logging server
+    #                (e.g. "xx.xx.xx.xx").
+    # username       Remote rsyslog server user name.
+    # password       Remote rsyslog server password.
 
     ${remote_dict}=  Create Dictionary  host=${remote_host}
-    Open Connection And Log In  ${user_name}  ${user_password}
+    Open Connection And Log In  ${username}  ${password}
     ...  &{remote_dict}
     ${stdout}  ${stderr}=  Execute Command  ${command}  return_stderr=True
     Should Be Empty   ${stderr}
     [Return]  ${stdout}
 
+
+Get Remote Log Server Configured
+    [Documentation]  Check that remote logging server is not configured.
+
+    ${address}=  Read Attribute  ${REMOTE_LOGGING_URI}  Address
+    Should Not Be Equal  ${address}  ${REMOTE_LOG_SERVER_HOST}
+
+    ${port_number}=  Convert To Integer  ${REMOTE_LOG_SERVER_PORT}
+    ${port}=  Read Attribute  ${REMOTE_LOGGING_URI}  Port
+    Should Not Be Equal  ${port}  ${port_number}
diff --git a/tests/test_service_restart_policy.robot b/tests/test_service_restart_policy.robot
index 48d4623..a094c39 100644
--- a/tests/test_service_restart_policy.robot
+++ b/tests/test_service_restart_policy.robot
@@ -67,14 +67,3 @@
     ${restart_policy}=  Get Service Attribute  Restart  ${servicename}
     Should Be Equal  always  ${restart_policy}
     ...  msg=Incorrect policy for ${servicename}
-
-
-Get Service Attribute
-    [Documentation]  Get service attribute policy output.
-    [Arguments]  ${option}  ${servicename}
-    # option  systemctl supported options
-    # servicename  Qualified service name
-    ${cmd}=  Set Variable
-    ...  systemctl -p ${option} show ${servicename} | cut -d = -f2
-    ${attr}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
-    [Return]  ${attr}