Generate Error On BMC And Verify If Trap Is Sent

Resolve openbmc/openbmc-test-automation#1763

Change-Id: I9ff7500e0497780d1fbf1a3aac05174f527a945f
Signed-off-by: Naman Navin Hegde <nhegde89@in.ibm.com>
diff --git a/lib/snmp/resource.robot b/lib/snmp/resource.robot
index 9ddb262..7ff3ed7 100644
--- a/lib/snmp/resource.robot
+++ b/lib/snmp/resource.robot
@@ -21,3 +21,12 @@
 ${alpha_port}         ab
 ${negative_port}      ${-12}
 ${empty_port}         ${EMPTY}
+
+# User Name Password
+${SNMP_MGR1_USERNAME}    ${EMPTY}
+${SNMP_MGR1_PASSWORD}    ${EMPTY}
+
+# SNMP Command
+${SNMP_TRAPD_CMD}       snmptrapd -f -c
+...                     /usr/local/etc/snmp/snmptrapd.conf -Lo
+${SNMP_TRAP_BMC_ERROR}  example.xyz.openbmc_project.Example.Elog.AutoTestSimple
diff --git a/lib/snmp/snmp_utils.robot b/lib/snmp/snmp_utils.robot
index 27594b5..2bdf401 100644
--- a/lib/snmp/snmp_utils.robot
+++ b/lib/snmp/snmp_utils.robot
@@ -123,3 +123,14 @@
     ${status}=  Run Keyword And Return Status  Verify SNMP Manager
     ...  ${snmp_ip}  ${port}
     Should Be Equal  ${status}  ${False}  msg=SNMP manager is not deleted.
+
+
+Start SNMP Manager
+    [Documentation]  Start SNMP listener on the remote SNMP manager.
+
+    Open Connection And Log In  ${SNMP_MGR1_USERNAME}  ${SNMP_MGR1_PASSWORD}
+    ...  alias=snmp_server  host=${SNMP_MGR1_IP}
+
+    # The execution of the SNMP_TRAPD_CMD is necessary to cause SNMP to begin
+    # listening to SNMP messages.
+    SSHLibrary.write  ${SNMP_TRAPD_CMD} &
diff --git a/snmp/test_bmc_snmp_config.robot b/snmp/test_bmc_snmp_config.robot
index f70eddf..6a81337 100644
--- a/snmp/test_bmc_snmp_config.robot
+++ b/snmp/test_bmc_snmp_config.robot
@@ -1,11 +1,12 @@
 *** Settings ***
-Documentation  This testing require special setup where SNMP trapd is
+Documentation  This testing requires special setup where SNMP trapd is
 ...            configured and installed. For download, installation and
 ...            configuration refer http://www.net-snmp.org/.
 
 Resource  ../lib/snmp/resource.robot
 Resource  ../lib/snmp/snmp_utils.robot
 Resource  ../lib/openbmc_ffdc.robot
+Resource  ../lib/logging_utils.robot
 
 Library  String
 Library  SSHLibrary
@@ -111,3 +112,18 @@
     Delete SNMP Manager And Object  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
     Delete SNMP Manager And Object  ${SNMP_MGR3_IP}  ${NON_DEFAULT_PORT2}
 
+Generate Error On BMC And Verify If Trap Is Sent
+    [Documentation]  Generate Error On BMC And Verify If Trap Is Sent.
+    [Tags]  Generate_Error_On_BMC_And_Verify_If_Trap_Is_Sent
+    [Setup]  Install Tarball
+
+    Configure SNMP Manager On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}  Valid
+
+    Start SNMP Manager
+    BMC Execute Command  /tmp/tarball/bin/logging-test -c AutoTestSimple
+    SSHLibrary.Switch Connection  snmp_server
+    ${SNMP_LISTEN_OUT}=  Read  delay=1s
+    SSHLibrary.Execute Command  sudo killall snmptrapd
+
+    Should Contain  ${SNMP_LISTEN_OUT}  ${SNMP_TRAP_BMC_ERROR}
+    ...  msg=Failed to receive trap message.