Library keywords for remote logging
Changes:
- Move common utilities to lib/remote_logging_utils.robot
Change-Id: I37db22776c3bde060b075a6bda40de0831858679
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/lib/remote_logging_utils.robot b/lib/remote_logging_utils.robot
new file mode 100644
index 0000000..05f2151
--- /dev/null
+++ b/lib/remote_logging_utils.robot
@@ -0,0 +1,126 @@
+*** Settings ***
+Documentation Remote syslog utilities keywords.
+
+Resource ../lib/resource.txt
+Resource ../lib/rest_client.robot
+Resource ../lib/utils.robot
+
+*** Keywords ***
+
+Configure Remote Log Server With Parameters
+ [Documentation] Configure the remote logging server on BMC.
+ [Arguments] ${remote_host}=${REMOTE_LOG_SERVER_HOST}
+ ... ${remote_port}=${REMOTE_LOG_SERVER_PORT}
+
+ # Description of argument(s):
+ # remote_host The host name or IP address of the remote logging server
+ # (e.g. "xx.xx.xx.xx").
+ # remote_port Remote ryslog server port number (e.g. "514").
+
+ # Example:
+ # https://xx.xx.xx.xx/xyz/openbmc_project/logging/config/remote
+ # Response code:200, Content:{
+ # "data": {
+ # "Address": "xx.xx.xx.xx",
+ # "Port": 514
+ # },
+ # "message": "200 OK",
+ # "status": "ok"
+ # }
+
+ ${host_dict}= Create Dictionary data=${remote_host}
+ 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
+
+
+Configure Remote Log Server
+ [Documentation] Configure the remote logging server on BMC.
+ [Arguments] ${remote_host}=${REMOTE_LOG_SERVER_HOST}
+ ... ${remote_port}=${REMOTE_LOG_SERVER_PORT}
+
+ # Description of argument(s):
+ # remote_host The host name or IP address of the remote logging server
+ # (e.g. "xx.xx.xx.xx").
+ # remote_port Remote ryslog server port number (e.g. "514").
+
+ @{remote_parm_list}= Create List ${remote_host} ${remote_port}
+
+ ${data}= Create Dictionary data=@{remote_parm_list}
+
+ ${resp}= OpenBMC Post Request
+ ... ${REMOTE_LOGGING_CONFIG_URI}/action/remote data=${data}
+
+ Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
+
+
+Verify Rsyslog Config On BMC
+ [Documentation] Check if the rsyslog configuration on BMC is correct.
+ [Arguments] ${remote_host}=${REMOTE_LOG_SERVER_HOST}
+ ... ${remote_port}=${REMOTE_LOG_SERVER_PORT}
+
+ # Description of argument(s):
+ # remote_host The host name or IP address of the remote logging server
+ # (e.g. "xx.xx.xx.xx").
+ # remote_port Remote ryslog server port number (e.g. "514").
+
+ # Example:
+ # Configured:
+ # *.* @@xx.xx.xx.xx:514root@wsbmc123
+ # By default:
+ # #*.* @@remote-host:port
+
+ ${ryslog_conf} ${stderr} ${rc}= BMC Execute Command
+ ... cat /etc/rsyslog.d/server.conf
+
+ ${config}= Catenate @@${remote_host}:${remote_port}
+
+ Should Contain ${ryslog_conf} ${config}
+ ... msg=${remote_host} and ${remote_port} are not configured.
+
+
+Remote Logging Server Execute Command
+ [Documentation] Login to remote logging server.
+ [Arguments] ${command}
+ ... ${remote_host}=${REMOTE_LOG_SERVER_HOST}
+ ... ${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 ${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/remote_logging/test_remote_logging.robot b/remote_logging/test_remote_logging.robot
index 706f591..b04f07a 100644
--- a/remote_logging/test_remote_logging.robot
+++ b/remote_logging/test_remote_logging.robot
@@ -9,11 +9,9 @@
# REMOTE_PASSWORD The password for the remote logging server.
Library String
-Resource ../lib/resource.txt
-Resource ../lib/rest_client.robot
-Resource ../lib/utils.robot
Resource ../lib/openbmc_ffdc.robot
Resource ../lib/boot_utils.robot
+Resource ../lib/remote_logging_utils.robot
Library ../lib/gen_misc.py
Suite Setup Suite Setup Execution
@@ -100,7 +98,7 @@
Verify Rsyslog Config On BMC
- Configure Remote Logging Server remote_host=${EMPTY} remote_port=0
+ Configure Remote Log Server With Parameters remote_host=${EMPTY} remote_port=0
Verify Rsyslog Config On BMC remote_host=remote-host remote_port=port
@@ -110,7 +108,7 @@
# Invalid port derived by (REMOTE_LOG_SERVER_PORT + 1) port config setting.
${INVALID_PORT}= Evaluate ${REMOTE_LOG_SERVER_PORT} + ${1}
- Configure Remote Logging Server
+ Configure Remote Log Server With Parameters
... remote_host=${REMOTE_LOG_SERVER_HOST} remote_port=${INVALID_PORT}
Sleep 3s
@@ -270,7 +268,7 @@
${hostname} ${stderr} ${rc}= BMC Execute Command /bin/hostname
Set Suite Variable ${bmc_hostname} ${hostname}
- Configure Remote Logging Server
+ Configure Remote Log Server With Parameters
Test Setup Execution
@@ -282,7 +280,8 @@
${config_status}= Run Keyword And Return Status
... Get Remote Log Server Configured
- Run Keyword If ${config_status}==${FALSE} Configure Remote Logging Server
+ Run Keyword If ${config_status}==${FALSE}
+ ... Configure Remote Log Server With Parameters
${ActiveState}= Get Service Attribute ActiveState rsyslog.service
Should Be Equal active ${ActiveState}
@@ -294,122 +293,3 @@
${resp}= OpenBMC Get Request ${REMOTE_LOGGING_URI}
Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
-
-
-Configure Remote Logging Server
- [Documentation] Configure the remote logging server on BMC.
- [Arguments] ${remote_host}=${REMOTE_LOG_SERVER_HOST}
- ... ${remote_port}=${REMOTE_LOG_SERVER_PORT}
-
- # Description of argument(s):
- # remote_host The host name or IP address of the remote logging server
- # (e.g. "xx.xx.xx.xx").
- # remote_port Remote ryslog server port number (e.g. "514").
-
- # Example:
- # https://xx.xx.xx.xx/xyz/openbmc_project/logging/config/remote
- # Response code:200, Content:{
- # "data": {
- # "Address": "xx.xx.xx.xx",
- # "Port": 514
- # },
- # "message": "200 OK",
- # "status": "ok"
- # }
-
- ${host_dict}= Create Dictionary data=${remote_host}
- 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
-
-
-Configure Group Remote Logging Server
- [Documentation] Configure the remote logging server on BMC.
- [Arguments] ${remote_host}=${REMOTE_LOG_SERVER_HOST}
- ... ${remote_port}=${REMOTE_LOG_SERVER_PORT}
-
- # Description of argument(s):
- # remote_host The host name or IP address of the remote logging server
- # (e.g. "xx.xx.xx.xx").
- # remote_port Remote ryslog server port number (e.g. "514").
-
- @{remote_parm_list}= Create List ${remote_host} ${remote_port}
-
- ${data}= Create Dictionary data=@{snmp_parm_list}
-
- ${resp}= OpenBMC Post Request
- ... ${REMOTE_LOGGING_CONFIG_URI}/action/remote data=${data}
-
- Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
-
-
-Verify Rsyslog Config On BMC
- [Documentation] Check if the rsyslog configuration on BMC is correct.
- [Arguments] ${remote_host}=${REMOTE_LOG_SERVER_HOST}
- ... ${remote_port}=${REMOTE_LOG_SERVER_PORT}
-
- # Description of argument(s):
- # remote_host The host name or IP address of the remote logging server
- # (e.g. "xx.xx.xx.xx").
- # remote_port Remote ryslog server port number (e.g. "514").
-
- # Example:
- # Configured:
- # *.* @@xx.xx.xx.xx:514root@wsbmc123
- # By default:
- # #*.* @@remote-host:port
-
- ${ryslog_conf} ${stderr} ${rc}= BMC Execute Command
- ... cat /etc/rsyslog.d/server.conf
-
- ${config}= Catenate @@${remote_host}:${remote_port}
-
- Should Contain ${ryslog_conf} ${config}
- ... msg=${remote_host} and ${remote_port} are not configured.
-
-
-Remote Logging Server Execute Command
- [Documentation] Login to remote logging server.
- [Arguments] ${command}
- ... ${remote_host}=${REMOTE_LOG_SERVER_HOST}
- ... ${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 ${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}