13468df56SSteven Sombar*** Settings ***
23468df56SSteven Sombar
33468df56SSteven SombarDocumentation  Websocket functionality test.
43468df56SSteven Sombar
53468df56SSteven Sombar# Test Parameters:
63468df56SSteven Sombar# OPENBMC_HOST       The BMC host name or IP address.
73468df56SSteven Sombar# OPENBMC_USERNAME   The username for the BMC login.
83468df56SSteven Sombar# OPENBMC_PASSWORD   The password for OPENBMC_USERNAME.
93468df56SSteven Sombar# OS_HOST            The OS host name or IP address.
103468df56SSteven Sombar# OS_USERNAME        The username for the OS login.
113468df56SSteven Sombar# OS_PASSWORD        The password for OS_USERNAME.
123468df56SSteven Sombar
133468df56SSteven SombarResource             ../../lib/esel_utils.robot
143468df56SSteven SombarResource             ../../lib/bmc_redfish_resource.robot
153468df56SSteven SombarResource             ../../lib/logging_utils.robot
1669b87c13SSteven SombarResource             ../../lib/dump_utils.robot
17*a28061a0SGeorge KeishingResource             ../../lib/os_utilities.robot
183468df56SSteven SombarLibrary              ../../lib/gen_cmd.py
193468df56SSteven SombarLibrary              OperatingSystem
203468df56SSteven Sombar
213468df56SSteven Sombar
223468df56SSteven SombarSuite Setup          Suite Setup Execution
233468df56SSteven SombarSuite Teardown       Suite Teardown Execution
243468df56SSteven SombarTest Teardown        Test Teardown Execution
253468df56SSteven Sombar
263468df56SSteven Sombar
273468df56SSteven Sombar*** Variables ***
283468df56SSteven Sombar
299686b769SSteven Sombar${monitor_pgm}          websocket_monitor.py
303468df56SSteven Sombar${monitor_file}         websocket_monitor_out.txt
3169b87c13SSteven Sombar${esel_received}        eSEL received over websocket interface
3269b87c13SSteven Sombar${dump_received}        Dump notification received over websocket interface
333468df56SSteven Sombar${min_number_chars}     22
343468df56SSteven Sombar${monitor_cmd}          ${monitor_pgm} ${OPENBMC_HOST} --openbmc_username ${OPENBMC_USERNAME}
353468df56SSteven Sombar
363468df56SSteven Sombar
373468df56SSteven Sombar*** Test Cases ***
383468df56SSteven Sombar
393468df56SSteven Sombar
4069b87c13SSteven SombarTest BMC Websocket ESEL Interface
4169b87c13SSteven Sombar    [Documentation]  Verify eSELs are reported over the websocket interface.
4269b87c13SSteven Sombar    [Tags]  Test_BMC_Websocket_ESEL_Interface
4369b87c13SSteven Sombar
4469b87c13SSteven Sombar    # Check that the ipmitool is available. That tool is used to create an eSEL.
4569b87c13SSteven Sombar    Tool Exist  ipmitool
463468df56SSteven Sombar
473468df56SSteven Sombar    # Spawn the websocket monitor program and then generate an eSEL.
483468df56SSteven Sombar    # The monitor should asynchronously receive the eSEL through the
493468df56SSteven Sombar    # websocket interface and report this fact to standard output.
503468df56SSteven Sombar
5169b87c13SSteven Sombar    Start Websocket Monitor  logging
523468df56SSteven Sombar
533468df56SSteven Sombar    ${initial_esel_count}=  Get Number Of Event Logs
543468df56SSteven Sombar
553468df56SSteven Sombar    # Generate eSEL (e.g.  typically "CPU 1 core 3 has failed").
563468df56SSteven Sombar    Create eSEL
573468df56SSteven Sombar
583468df56SSteven Sombar    ${current_esel_count}=   Get Number Of Event Logs
593468df56SSteven Sombar
603468df56SSteven Sombar    Run Keyword If  ${initial_esel_count} == ${current_esel_count}
613468df56SSteven Sombar    ...  Fail  msg=System failed to generate eSEL upon request.
623468df56SSteven Sombar
6369b87c13SSteven Sombar    ${line}=  Grep File  ${monitor_file}  ${esel_received}
643468df56SSteven Sombar    # Typical monitor_file contents:
653468df56SSteven Sombar    # --------------- ON_MESSAGE:begin --------------------
663468df56SSteven Sombar    # {"event":"PropertiesChanged","interface":"xyz.openbmc_project.Logging.
673468df56SSteven Sombar    # Entry","path":"/xyz/openbmc_project/logging/entry/5","properties":{"Id":5}}
683468df56SSteven Sombar    # eSEL received over websocket interface.
693468df56SSteven Sombar
703468df56SSteven Sombar    ${num_chars}=  Get Length  ${line}
713468df56SSteven Sombar    Run Keyword If  ${num_chars} < ${min_number_chars}  Fail
723468df56SSteven Sombar    ...  msg=No eSEL notification from websocket_monitor.py.
733468df56SSteven Sombar
743468df56SSteven Sombar
7569b87c13SSteven SombarTest BMC Websocket Dump Interface
7669b87c13SSteven Sombar    [Documentation]  Verify dumps are reported over the websocket interface.
7769b87c13SSteven Sombar    [Tags]  Test_BMC_Websocket_Dump_Interface
7869b87c13SSteven Sombar
794aff2d02STim Lee    Redfish Delete All BMC Dumps
8069b87c13SSteven Sombar    Start Websocket Monitor  dump
81792e31eeSTim Lee    ${dump_id}=  Create User Initiated BMC Dump Via Redfish
8269b87c13SSteven Sombar    Check Existence Of BMC Dump File  ${dump_id}
8369b87c13SSteven Sombar
8469b87c13SSteven Sombar    # Check that the monitor received notification of the dump.
8569b87c13SSteven Sombar    ${line}=  Grep File  ${monitor_file}  ${dump_received}
8669b87c13SSteven Sombar    # Typical monitor_file contents:
8769b87c13SSteven Sombar    # --------------- ON_MESSAGE:begin --------------------
8869b87c13SSteven Sombar    # {"event":"PropertiesChanged","interface":"xyz.openbmc_project.Dump.
8969b87c13SSteven Sombar    # Entry","path":"/xyz/openbmc_project/dump/entry/1","properties":{"Size":157888}}
9069b87c13SSteven Sombar    # Dump notification received over websocket interface.
9169b87c13SSteven Sombar
9269b87c13SSteven Sombar    ${num_chars}=  Get Length  ${line}
9369b87c13SSteven Sombar    Run Keyword If  ${num_chars} < ${min_number_chars}  Fail
9469b87c13SSteven Sombar    ...  msg=No dump notification from websocket_monitor.py.
9569b87c13SSteven Sombar
9669b87c13SSteven Sombar
973468df56SSteven Sombar*** Keywords ***
983468df56SSteven Sombar
993468df56SSteven Sombar
1003468df56SSteven SombarStart Websocket Monitor
1013468df56SSteven Sombar    [Documentation]  Fork the monitor to run in the background.
10269b87c13SSteven Sombar    [Arguments]  ${monitor_type}
10369b87c13SSteven Sombar
10469b87c13SSteven Sombar    # Description of Argument(s):
10569b87c13SSteven Sombar    # monitor_type  The type of websocket notifications to monitor,
10669b87c13SSteven Sombar    #               either "logging" or "dump".
1073468df56SSteven Sombar
1083468df56SSteven Sombar    # Delete the previous output file, if any.
1093468df56SSteven Sombar    Remove File  ${monitor_file}
1103468df56SSteven Sombar
11169b87c13SSteven Sombar    ${command}=  Catenate  ${monitor_cmd} --openbmc_password ${OPENBMC_PASSWORD}
11269b87c13SSteven Sombar    ...   --monitor_type ${monitor_type} 1>${monitor_file} 2>&1
11369b87c13SSteven Sombar
1143468df56SSteven Sombar    # Start the monitor. Fork so its a parallel task.
11569b87c13SSteven Sombar    Shell Cmd  ${command}  fork=${1}
1163468df56SSteven Sombar
1173468df56SSteven Sombar    # Allow time for the monitor to initialize.
1183468df56SSteven Sombar    Sleep  5s
1193468df56SSteven Sombar
1203468df56SSteven Sombar
1213468df56SSteven SombarFind Websocket Monitor
1223468df56SSteven Sombar    [Documentation]  Return the process Id(s) of running websocket monitors.
1233468df56SSteven Sombar
1243468df56SSteven Sombar    ${cmd}=  Catenate  ps -ef | grep '${monitor_cmd}'
1253468df56SSteven Sombar    ...  | grep -v grep | grep -v bash | cut -c10-14
1263468df56SSteven Sombar    ${shell_rc}  ${pid}=  Shell Cmd  ${cmd}
1273468df56SSteven Sombar    # There may be more than one pid returned if there is an instance
1283468df56SSteven Sombar    # of a monitory_pgm running from a previous run.
1293468df56SSteven Sombar    @{pid_list}=  Split String  ${pid}
1303468df56SSteven Sombar    [Return]  ${pid_list}
1313468df56SSteven Sombar
1323468df56SSteven Sombar
1333468df56SSteven SombarKill Websocket Monitor
1343468df56SSteven Sombar    [Documentation]  Terminate running websocket monitor.
1353468df56SSteven Sombar
1363468df56SSteven Sombar    ${pid_list}=  Find Websocket Monitor
1373468df56SSteven Sombar    FOR  ${pid}  IN  @{pid_list}
1383468df56SSteven Sombar        Shell Cmd  kill -s SIGTERM ${pid}
1393468df56SSteven Sombar    END
1403468df56SSteven Sombar
1413468df56SSteven Sombar
1423468df56SSteven SombarPrint Websocket Monitor Log
1433468df56SSteven Sombar    [Documentation]  Show the contents of the monitor output file.
1443468df56SSteven Sombar
1453468df56SSteven Sombar    ${websocket_monitor_log}=  OperatingSystem.Get File  ${monitor_file}
1463468df56SSteven Sombar    Log to Console  websocket_monitor_log:
1473468df56SSteven Sombar    Log to Console  ${websocket_monitor_log}
1483468df56SSteven Sombar
1493468df56SSteven Sombar
1503468df56SSteven SombarSuite Setup Execution
1513468df56SSteven Sombar    [Documentation]  Do the suite setup tasks.
1523468df56SSteven Sombar
1533468df56SSteven Sombar    Run Keyword  Redfish Power On  stack_mode=skip
1543468df56SSteven Sombar
1553468df56SSteven Sombar    Redfish.Login
1563468df56SSteven Sombar
1573468df56SSteven Sombar    Delete All Error Logs
1583468df56SSteven Sombar    Kill Websocket Monitor
1593468df56SSteven Sombar
1603468df56SSteven Sombar    # Allow time for Error Logs to be deleted.
1613468df56SSteven Sombar    Sleep  5s
1623468df56SSteven Sombar
1633468df56SSteven Sombar
1643468df56SSteven SombarTest Teardown Execution
1653468df56SSteven Sombar    [Documentation]  Do teardown tasks after a test.
1663468df56SSteven Sombar
1673468df56SSteven Sombar    FFDC On Test Case Fail
1683468df56SSteven Sombar    Run Keyword If  '${TEST_STATUS}' == 'FAIL'  Print Websocket Monitor Log
1693468df56SSteven Sombar    Kill Websocket Monitor
1703468df56SSteven Sombar
1714aff2d02STim Lee    Redfish Delete All BMC Dumps
17269b87c13SSteven Sombar
1733468df56SSteven Sombar
1743468df56SSteven SombarSuite Teardown Execution
1753468df56SSteven Sombar    [Documentation]  Do the post-suite teardown.
1763468df56SSteven Sombar
1773468df56SSteven Sombar    Delete All Error Logs
1783468df56SSteven Sombar    Run Keyword and Return Status  Redfish.Logout
179