Support to run SNMP server on specific port and verify trap
Changes:
Added to keyword to start SNMP server on specific port other than default port.
Added test case to configure multiple SNMP managers.
Added test cases to configure SNMP manager with different ports
Signed-off-by: Prashanth Katti <prkatti1@in.ibm.com>
Change-Id: I091925d6f4232270fbaf189f5682453535559a8c
diff --git a/lib/snmp/redfish_snmp_utils.robot b/lib/snmp/redfish_snmp_utils.robot
index 8f43918..79656a1 100644
--- a/lib/snmp/redfish_snmp_utils.robot
+++ b/lib/snmp/redfish_snmp_utils.robot
@@ -232,3 +232,61 @@
# The execution of the SNMP_TRAPD_CMD is necessary to cause SNMP to begin
# listening to SNMP messages.
SSHLibrary.write ${SNMP_TRAPD_CMD} &
+
+
+Create Error On BMC And Verify Trap On Non-Default Port
+ [Documentation] Generate error on BMC and verify if trap is sent to non default port.
+ [Arguments] ${event_log}=${CMD_INTERNAL_FAILURE} ${expected_error}=${SNMP_TRAP_BMC_INTERNAL_FAILURE}
+
+ # Description of argument(s):
+ # event_log Event logs to be created.
+ # expected_error Expected error on SNMP.
+
+ Configure SNMP Manager Via Redfish ${SNMP_MGR1_IP} ${NON_DEFAULT_PORT1}
+
+ Start SNMP Manager On Specific Port ${SNMP_MGR1_IP} ${NON_DEFAULT_PORT1}
+
+ # Generate error log.
+ BMC Execute Command ${event_log}
+
+ SSHLibrary.Switch Connection snmp_server
+ ${SNMP_LISTEN_OUT}= Read delay=1s
+
+ Delete SNMP Manager Via Redfish ${SNMP_MGR1_IP} ${NON_DEFAULT_PORT1}
+
+ # Stop SNMP manager process.
+ SSHLibrary.Execute Command sudo killall snmptrapd
+
+ # Sample SNMP trap:
+ # 2021-06-16 07:05:29 xx.xx.xx.xx [UDP: [xx.xx.xx.xx]:58154->[xx.xx.xx.xx]:xxx]:
+ # DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (2100473) 5:50:04.73
+ # SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-SMI::enterprises.49871.1.0.0.1
+ # SNMPv2-SMI::enterprises.49871.1.0.1.1 = Gauge32: 369 SNMPv2-SMI::enterprises.49871.1.0.1.2 = Opaque:
+ # UInt64: 1397718405502468474 SNMPv2-SMI::enterprises.49871.1.0.1.3 = INTEGER: 3
+ # SNMPv2-SMI::enterprises.49871.1.0.1.4 = STRING: "xxx.xx.xx Failure"
+
+ ${lines}= Split To Lines ${SNMP_LISTEN_OUT}
+ ${trap_info}= Get From List ${lines} -1
+ ${snmp_trap}= Split String ${trap_info} \t
+
+ Verify SNMP Trap ${snmp_trap} ${expected_error}
+
+ [Return] ${snmp_trap}
+
+
+Start SNMP Manager On Specific Port
+ [Documentation] Start SNMP listener on specific port on the remote SNMP manager.
+ [Arguments] ${snmp_mgr_ip} ${snmp_port}
+
+ # Description of argument(s):
+ # snmp_mgr_ip SNMP manager IP.
+ # snmp_port Network port on which SNMP manager need to run.
+
+ ${ip_and_port}= Catenate ${snmp_mgr_ip}:${snmp_port}
+
+ 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} ${ip_and_port} &
diff --git a/redfish/events/test_bmc_snmp_trap.robot b/redfish/events/test_bmc_snmp_trap.robot
index 7587371..76f6914 100644
--- a/redfish/events/test_bmc_snmp_trap.robot
+++ b/redfish/events/test_bmc_snmp_trap.robot
@@ -93,6 +93,62 @@
${CMD_INFORMATIONAL_ERROR} ${SNMP_TRAP_BMC_INFORMATIONAL_ERROR}
+Configure SNMP Manager On BMC With Alpha Port And Verify
+ [Documentation] Configure SNMP Manager On BMC with alpha port and verify.
+ [Tags] Configure_SNMP_Manager_On_BMC_With_Alpha_Port_And_Verify
+ [Teardown] Delete SNMP Manager Via Redfish ${SNMP_MGR1_IP} ${alpha_port}
+
+ Configure SNMP Manager Via Redfish ${SNMP_MGR1_IP} ${alpha_port} ${HTTP_BAD_REQUEST}
+
+ ${status}= Run Keyword And Return Status
+ ... Verify SNMP Manager Configured On BMC ${SNMP_MGR1_IP} ${alpha_port}
+
+ Should Be Equal As Strings ${status} False
+ ... msg=BMC is allowing to configure invalid port.
+
+
+Configure SNMP Manager On BMC With Empty Port And Verify
+ [Documentation] Configure SNMP Manager On BMC with empty port and verify
+ ... SNMP manager gets configured with default port.
+ [Tags] Configure_SNMP_Manager_On_BMC_With_Empty_Port_And_Verify
+ [Teardown] Delete SNMP Manager Via Redfish ${SNMP_MGR1_IP} ${SNMP_DEFAULT_PORT}
+
+ Configure SNMP Manager Via Redfish ${SNMP_MGR1_IP} ${empty_port}
+
+ Verify SNMP Manager Configured On BMC ${SNMP_MGR1_IP} ${SNMP_DEFAULT_PORT}
+
+
+Configure Multiple SNMP Managers And Verify
+ [Documentation] Configure multiple SNMP managers and verify.
+ [Tags] Configure_Multiple_SNMP_Managers_And_Verify
+ [Teardown] Run Keywords
+ ... Delete SNMP Manager Via Redfish ${SNMP_MGR1_IP} ${SNMP_DEFAULT_PORT}
+ ... AND
+ ... Delete SNMP Manager Via Redfish ${SNMP_MGR2_IP} ${SNMP_DEFAULT_PORT}
+
+ Configure SNMP Manager Via Redfish ${SNMP_MGR1_IP} ${SNMP_DEFAULT_PORT}
+ Configure SNMP Manager Via Redfish ${SNMP_MGR2_IP} ${SNMP_DEFAULT_PORT}
+ Verify SNMP Manager Configured On BMC ${SNMP_MGR1_IP} ${SNMP_DEFAULT_PORT}
+ Verify SNMP Manager Configured On BMC ${SNMP_MGR2_IP} ${SNMP_DEFAULT_PORT}
+
+
+Generate Error On BMC And Verify SNMP Trap Is Sent To Non-Default Port
+ [Documentation] Generate error on BMC and verify trap and its fields.
+ [Tags] Generate_Error_On_BMC_And_Verify_SNMP_Trap_Is_Sent_To_Non-Default_Port
+ [Template] Create Error On BMC And Verify Trap On Non-Default Port
+
+ # event_log expected_error
+
+ # Generate internal failure error.
+ ${CMD_INTERNAL_FAILURE} ${SNMP_TRAP_BMC_INTERNAL_FAILURE}
+
+ # Generate timeout error.
+ ${CMD_FRU_CALLOUT} ${SNMP_TRAP_BMC_CALLOUT_ERROR}
+
+ # Generate informational error.
+ ${CMD_INFORMATIONAL_ERROR} ${SNMP_TRAP_BMC_INFORMATIONAL_ERROR}
+
+
*** Keywords ***
Suite Setup Execution