xref: /openbmc/openbmc-test-automation/lib/snmp/redfish_snmp_utils.robot (revision 409df05d4b10b9a8c81e282da8fef0199db5bdea)
1391000c1SPrashanth KattiDocumentation  Utility for SNMP configurations via Redfish.
2391000c1SPrashanth Katti
3391000c1SPrashanth Katti*** Settings ***
4391000c1SPrashanth Katti
5391000c1SPrashanth KattiResource                ../../lib/utils.robot
6391000c1SPrashanth KattiResource                ../../lib/connection_client.robot
7391000c1SPrashanth KattiLibrary                 ../../lib/gen_misc.py
8391000c1SPrashanth KattiLibrary                 ../../lib/utils.py
9391000c1SPrashanth Katti
102f9632faSAnves Kumar rayankula*** Variables ***
112f9632faSAnves Kumar rayankula
122f9632faSAnves Kumar rayankula${snmp_function}     SNMPTrap
132f9632faSAnves Kumar rayankula${snmp_version}      SNMPv2c
142f9632faSAnves Kumar rayankula${subscription_uri}  /redfish/v1/EventService/Subscriptions
152f9632faSAnves Kumar rayankula
162f9632faSAnves Kumar rayankula${CMD_INTERNAL_FAILURE}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
172f9632faSAnves Kumar rayankula...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.InternalFailure
182f9632faSAnves Kumar rayankula...  xyz.openbmc_project.Logging.Entry.Level.Error 0
192f9632faSAnves Kumar rayankula
202f9632faSAnves Kumar rayankula${CMD_FRU_CALLOUT}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
212f9632faSAnves Kumar rayankula...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.Timeout
222f9632faSAnves Kumar rayankula...  xyz.openbmc_project.Logging.Entry.Level.Error 2 "TIMEOUT_IN_MSEC" "5"
232f9632faSAnves Kumar rayankula...  "CALLOUT_INVENTORY_PATH" "/xyz/openbmc_project/inventory/system/chassis/motherboard"
242f9632faSAnves Kumar rayankula
252f9632faSAnves Kumar rayankula${CMD_INFORMATIONAL_ERROR}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
262f9632faSAnves Kumar rayankula...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.TestError2
272f9632faSAnves Kumar rayankula...  xyz.openbmc_project.Logging.Entry.Level.Informational 0
282f9632faSAnves Kumar rayankula
292f9632faSAnves Kumar rayankula${SNMP_TRAP_BMC_INTERNAL_FAILURE}  xyz.openbmc_project.Common.Error.InternalFailure
302f9632faSAnves Kumar rayankula${SNMP_TRAP_BMC_CALLOUT_ERROR}  xyz.openbmc_project.Common.Error.Timeout
312476c5c1SMegha G N...  CALLOUT_INVENTORY_PATH=/xyz/openbmc_project/inventory/system/chassis/motherboard TIMEOUT_IN_MSEC=5
322f9632faSAnves Kumar rayankula${SNMP_TRAP_BMC_INFORMATIONAL_ERROR}  xyz.openbmc_project.Common.Error.TestError2
332f9632faSAnves Kumar rayankula
34391000c1SPrashanth Katti
35391000c1SPrashanth Katti*** Keywords ***
36391000c1SPrashanth Katti
37391000c1SPrashanth KattiGet SNMP Manager List
38391000c1SPrashanth Katti    [Documentation]  Get the list of SNMP managers and return IP addresses and ports.
39391000c1SPrashanth Katti
40391000c1SPrashanth Katti    # Get the list of SNMP manager URIs.
41391000c1SPrashanth Katti    @{snmp_mgr_uris}=  Get SNMP Child URIs
42391000c1SPrashanth Katti
43391000c1SPrashanth Katti    ${snmp_mgr_list}=  Create List
44391000c1SPrashanth Katti
45391000c1SPrashanth Katti    FOR  ${snmp_mgr_uri}  IN  @{snmp_mgr_uris}
46391000c1SPrashanth Katti      # Sample output:
47391000c1SPrashanth Katti      # {
48391000c1SPrashanth Katti      #  "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp1",
49391000c1SPrashanth Katti      #  "@odata.type": "#EventDestination.v1_7_0.EventDestination",
50391000c1SPrashanth Katti      #  "Context": "",
51391000c1SPrashanth Katti      #  "Destination": "snmp://xx.xx.xx.xx:162",
52391000c1SPrashanth Katti      #  "EventFormatType": "Event",
53391000c1SPrashanth Katti      #  "Id": "snmp1",
54391000c1SPrashanth Katti      #  "Name": "Event Destination snmp1",
55391000c1SPrashanth Katti      #  "Protocol": "SNMPv2c",
56391000c1SPrashanth Katti      #  "SubscriptionType": "SNMPTrap"
57391000c1SPrashanth Katti
58391000c1SPrashanth Katti      ${resp}=  Redfish.Get  ${snmp_mgr_uri}
59391000c1SPrashanth Katti      ${snmp_mgr}=  Get From Dictionary  ${resp.dict}  Destination
60391000c1SPrashanth Katti      Append To List  ${snmp_mgr_list}  ${snmp_mgr}
61391000c1SPrashanth Katti    END
62391000c1SPrashanth Katti
63*409df05dSGeorge Keishing    RETURN  ${snmp_mgr_list}
64391000c1SPrashanth Katti
65391000c1SPrashanth Katti
66391000c1SPrashanth KattiConfigure SNMP Manager Via Redfish
67391000c1SPrashanth Katti    [Documentation]  Configure SNMP manager on BMC via Redfish.
68391000c1SPrashanth Katti    [Arguments]  ${snmp_mgr_ip}  ${snmp_port}  ${valid_status_codes}=${HTTP_CREATED}
69391000c1SPrashanth Katti
70391000c1SPrashanth Katti    # Description of argument(s):
71391000c1SPrashanth Katti    # snmp_mgr_ip  SNMP manager IP address
72391000c1SPrashanth Katti    # snmp_port  SNMP manager port
73391000c1SPrashanth Katti    # valid_status_code  expected code
74391000c1SPrashanth Katti
7502d32765SYi Hu    ${colon}=  Set Variable If  '${snmp_port}' == '${EMPTY}'  ${EMPTY}  :
7602d32765SYi Hu    ${snmp_mgr_data}=  Create Dictionary  Destination=snmp://${snmp_mgr_ip}${colon}${snmp_port}
77391000c1SPrashanth Katti    ...  SubscriptionType=${snmp_function}  Protocol=${snmp_version}
78391000c1SPrashanth Katti
79391000c1SPrashanth Katti    Redfish.Post  ${subscription_uri}  body=&{snmp_mgr_data}
80391000c1SPrashanth Katti    ...  valid_status_codes=[${valid_status_codes}]
81391000c1SPrashanth Katti
82391000c1SPrashanth Katti
83391000c1SPrashanth KattiVerify SNMP Manager Configured On BMC
84391000c1SPrashanth Katti    [Documentation]  Verify SNMP manager configured on BMC.
85391000c1SPrashanth Katti    [Arguments]  ${snmp_mgr_ip}  ${snmp_port}
86391000c1SPrashanth Katti
87391000c1SPrashanth Katti    # Description of argument(s):
88391000c1SPrashanth Katti    # snmp_mgr_ip  SNMP manager IP address
89391000c1SPrashanth Katti    # snmp_port  SNMP manager port
90391000c1SPrashanth Katti
91391000c1SPrashanth Katti    # Get the list of SNMP managers that are configured on BMC.
92391000c1SPrashanth Katti    @{snmp_mgr_list}=  Get SNMP Manager List
93391000c1SPrashanth Katti
94391000c1SPrashanth Katti    ${snmp_ip_port}=  Catenate  ${snmp_mgr_ip}:${snmp_port}
95391000c1SPrashanth Katti
96391000c1SPrashanth Katti    List Should Contain Value  ${snmp_mgr_list}  snmp://${snmp_ip_port}
97391000c1SPrashanth Katti    ...  msg=SNMP manager is not configured.
98391000c1SPrashanth Katti
99391000c1SPrashanth Katti
100391000c1SPrashanth KattiGet SNMP Child URIs
101391000c1SPrashanth Katti    [Documentation]  Get the list of all SNMP manager URIs.
102391000c1SPrashanth Katti
103391000c1SPrashanth Katti    # Sample output of SNMP URI:
104391000c1SPrashanth Katti    # {
105391000c1SPrashanth Katti    #  "@odata.id": "/redfish/v1/EventService/Subscriptions",
106391000c1SPrashanth Katti    #  "@odata.type": "#EventDestinationCollection.EventDestinationCollection",
107391000c1SPrashanth Katti    #  "Members": [
108391000c1SPrashanth Katti    #    {
109391000c1SPrashanth Katti    #      "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp6"
110391000c1SPrashanth Katti    #    },
111391000c1SPrashanth Katti    #    {
112391000c1SPrashanth Katti    #      "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp2"
113391000c1SPrashanth Katti    #    },
114391000c1SPrashanth Katti    #    {
115391000c1SPrashanth Katti    #      "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp9"
116391000c1SPrashanth Katti    #    },
117391000c1SPrashanth Katti    #    {
118391000c1SPrashanth Katti    #      "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp1"
119391000c1SPrashanth Katti    #    },
120391000c1SPrashanth Katti    #    {
121391000c1SPrashanth Katti    #      "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp8"
122391000c1SPrashanth Katti    #    },
123391000c1SPrashanth Katti    #    {
124391000c1SPrashanth Katti    #      "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp4"
125391000c1SPrashanth Katti    #    },
126391000c1SPrashanth Katti    #    {
127391000c1SPrashanth Katti    #      "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp7"
128391000c1SPrashanth Katti    #    },
129391000c1SPrashanth Katti    #    {
130391000c1SPrashanth Katti    #      "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp5"
131391000c1SPrashanth Katti    #    },
132391000c1SPrashanth Katti    #    {
133391000c1SPrashanth Katti    #      "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp3"
134391000c1SPrashanth Katti    #    }
135391000c1SPrashanth Katti    #  ],
136391000c1SPrashanth Katti    #  "Members@odata.count": 9,
137391000c1SPrashanth Katti    #  "Name": "Event Destination Collections"
138391000c1SPrashanth Katti
139391000c1SPrashanth Katti    # Get the list of child URIs.
140391000c1SPrashanth Katti    @{snmp_mgr_uris}=  Redfish.Get Members List  ${subscription_uri}  filter=snmp
141391000c1SPrashanth Katti
142*409df05dSGeorge Keishing    RETURN  ${snmp_mgr_uris}
143dd99a919SPrashanth Katti
144dd99a919SPrashanth Katti
145dd99a919SPrashanth KattiDelete SNMP Manager Via Redfish
146dd99a919SPrashanth Katti    [Documentation]  Delete SNMP manager.
147dd99a919SPrashanth Katti    [Arguments]  ${snmp_mgr_ip}  ${snmp_port}
148dd99a919SPrashanth Katti
149dd99a919SPrashanth Katti    # Description of argument(s):
150dd99a919SPrashanth Katti    # snmp_mgr_ip  SNMP manager IP.
151dd99a919SPrashanth Katti    # snmp_port    Network port where SNMP manager is listening.
152dd99a919SPrashanth Katti
153dd99a919SPrashanth Katti    ${is_snmp_found}=  Set Variable  ${False}
154dd99a919SPrashanth Katti    ${snmp_ip_port}=  Catenate  ${snmp_mgr_ip}:${snmp_port}
155dd99a919SPrashanth Katti
156dd99a919SPrashanth Katti    # Get the list of SNMP manager URIs.
157dd99a919SPrashanth Katti    @{snmp_mgr_uris}=  Get SNMP Child URIs
158dd99a919SPrashanth Katti
159dd99a919SPrashanth Katti    # Find the SNMP manager URI that has IP and port configured.
160dd99a919SPrashanth Katti    FOR  ${snmp_mgr_uri}  IN  @{snmp_mgr_uris}
161dd99a919SPrashanth Katti      # Sample output:
162dd99a919SPrashanth Katti      # {
163dd99a919SPrashanth Katti      #  "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp1",
164dd99a919SPrashanth Katti      #  "@odata.type": "#EventDestination.v1_7_0.EventDestination",
165dd99a919SPrashanth Katti      #  "Context": "",
166dd99a919SPrashanth Katti      #  "Destination": "snmp://xx.xx.xx.xx:162",
167dd99a919SPrashanth Katti      #  "EventFormatType": "Event",
168dd99a919SPrashanth Katti      #  "Id": "snmp1",
169dd99a919SPrashanth Katti      #  "Name": "Event Destination snmp1",
170dd99a919SPrashanth Katti      #  "Protocol": "SNMPv2c",
171dd99a919SPrashanth Katti      #  "SubscriptionType": "SNMPTrap"
172dd99a919SPrashanth Katti
173dd99a919SPrashanth Katti      # Find the SNMP manager that has matching destination details.
174dd99a919SPrashanth Katti      ${snmp_mgr}=  Redfish.Get Attribute  ${snmp_mgr_uri}  Destination
175dd99a919SPrashanth Katti
176dd99a919SPrashanth Katti      # Delete the SNMP manager if the requested IP & ports are found
177dd99a919SPrashanth Katti      # and mark is_snmp_found to true.
178dd99a919SPrashanth Katti      Run Keyword If  'snmp://${snmp_ip_port}' == '${snmp_mgr}'
179dd99a919SPrashanth Katti      ...  Run Keywords  Set Local Variable  ${is_snmp_found}  ${True}
180dd99a919SPrashanth Katti      ...  AND  Redfish.Delete  ${snmp_mgr_uri}
181dd99a919SPrashanth Katti      ...  AND  Exit For Loop
182dd99a919SPrashanth Katti    END
183dd99a919SPrashanth Katti
184dd99a919SPrashanth Katti    Pass Execution If  ${is_snmp_found} == ${False}
185dd99a919SPrashanth Katti    ...  SNMP Manager: ${snmp_mgr_ip}:${snmp_port} is not configured on BMC
186dd99a919SPrashanth Katti
187dd99a919SPrashanth Katti    # Check if the SNMP manager is really deleted from BMC.
188dd99a919SPrashanth Katti    ${status}=  Run Keyword And Return Status
189dd99a919SPrashanth Katti    ...  Verify SNMP Manager Configured On BMC  ${snmp_mgr_ip}  ${snmp_port}
190dd99a919SPrashanth Katti
191dd99a919SPrashanth Katti    Should Be Equal  ${status}  ${False}  msg=SNMP manager is not deleted in the backend.
192c744f04eSPrashanth Katti
193c744f04eSPrashanth Katti
194c744f04eSPrashanth KattiCreate Error On BMC And Verify Trap
195c744f04eSPrashanth Katti    [Documentation]  Generate error on BMC and verify if trap is sent.
196c744f04eSPrashanth Katti    [Arguments]  ${event_log}=${CMD_INTERNAL_FAILURE}  ${expected_error}=${SNMP_TRAP_BMC_INTERNAL_FAILURE}
197c744f04eSPrashanth Katti
198c744f04eSPrashanth Katti    # Description of argument(s):
199c744f04eSPrashanth Katti    # event_log       Event logs to be created.
200c744f04eSPrashanth Katti    # expected_error  Expected error on SNMP.
201c744f04eSPrashanth Katti
202c744f04eSPrashanth Katti    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}  ${HTTP_CREATED}
203c744f04eSPrashanth Katti
204c744f04eSPrashanth Katti    Start SNMP Manager
205c744f04eSPrashanth Katti
206c744f04eSPrashanth Katti    # Generate error log.
207c744f04eSPrashanth Katti    BMC Execute Command  ${event_log}
208c744f04eSPrashanth Katti
209c744f04eSPrashanth Katti    SSHLibrary.Switch Connection  snmp_server
210c744f04eSPrashanth Katti    ${SNMP_LISTEN_OUT}=  Read  delay=1s
211c744f04eSPrashanth Katti
212c744f04eSPrashanth Katti    Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
213c744f04eSPrashanth Katti
214c744f04eSPrashanth Katti    # Stop SNMP manager process.
215c744f04eSPrashanth Katti    SSHLibrary.Execute Command  sudo killall snmptrapd
216c744f04eSPrashanth Katti
217c744f04eSPrashanth Katti    # Sample SNMP trap:
218c744f04eSPrashanth Katti    # 2021-06-16 07:05:29 xx.xx.xx.xx [UDP: [xx.xx.xx.xx]:58154->[xx.xx.xx.xx]:xxx]:
219c744f04eSPrashanth Katti    # DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (2100473) 5:50:04.73
220c744f04eSPrashanth Katti    #   SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-SMI::enterprises.49871.1.0.0.1
221c744f04eSPrashanth Katti    #  SNMPv2-SMI::enterprises.49871.1.0.1.1 = Gauge32: 369    SNMPv2-SMI::enterprises.49871.1.0.1.2 = Opaque:
222c744f04eSPrashanth Katti    # UInt64: 1397718405502468474     SNMPv2-SMI::enterprises.49871.1.0.1.3 = INTEGER: 3
223c744f04eSPrashanth Katti    #      SNMPv2-SMI::enterprises.49871.1.0.1.4 = STRING: "xxx.xx.xx Failure"
224c744f04eSPrashanth Katti
225c744f04eSPrashanth Katti    ${lines}=  Split To Lines  ${SNMP_LISTEN_OUT}
226c744f04eSPrashanth Katti    ${trap_info}=  Get From List  ${lines}  -1
227c744f04eSPrashanth Katti    ${snmp_trap}=  Split String  ${trap_info}  \t
228c744f04eSPrashanth Katti
229c744f04eSPrashanth Katti    Verify SNMP Trap  ${snmp_trap}  ${expected_error}
230c744f04eSPrashanth Katti
231*409df05dSGeorge Keishing    RETURN  ${snmp_trap}
232c744f04eSPrashanth Katti
233c744f04eSPrashanth Katti
234c744f04eSPrashanth KattiVerify SNMP Trap
235c744f04eSPrashanth Katti    [Documentation]  Verify SNMP trap.
236c744f04eSPrashanth Katti    [Arguments]  ${snmp_trap}  ${expected_error}=${SNMP_TRAP_BMC_INTERNAL_FAILURE}
237c744f04eSPrashanth Katti
238c744f04eSPrashanth Katti    # Description of argument(s):
239c744f04eSPrashanth Katti    # snmp_trap       SNMP trap collected on SNMP manager.
240c744f04eSPrashanth Katti    # expected_error  Expected error on SNMP.
241c744f04eSPrashanth Katti
242c744f04eSPrashanth Katti    # Verify all the mandatory fields of trap.
243c744f04eSPrashanth Katti    Should Contain  ${snmp_trap}[0]  DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks:
244c744f04eSPrashanth Katti    Should Be Equal  ${snmp_trap}[1]  SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-SMI::enterprises.49871.1.0.0.1
245c744f04eSPrashanth Katti    Should Match Regexp  ${snmp_trap}[2]  SNMPv2-SMI::enterprises.49871.1.0.1.1 = Gauge32: \[0-9]*
246c744f04eSPrashanth Katti    Should Match Regexp  ${snmp_trap}[3]  SNMPv2-SMI::enterprises.49871.1.0.1.2 = Opaque: UInt64: \[0-9]*
247c744f04eSPrashanth Katti    Should Match Regexp  ${snmp_trap}[4]  SNMPv2-SMI::enterprises.49871.1.0.1.3 = INTEGER: \[0-9]
248c744f04eSPrashanth Katti    Should Be Equal  ${snmp_trap}[5]  SNMPv2-SMI::enterprises.49871.1.0.1.4 = STRING: "${expected_error}"
249c744f04eSPrashanth Katti
250c744f04eSPrashanth Katti
251c744f04eSPrashanth KattiStart SNMP Manager
252c744f04eSPrashanth Katti    [Documentation]  Start SNMP listener on the remote SNMP manager.
253c744f04eSPrashanth Katti
254c744f04eSPrashanth Katti    Open Connection And Log In  ${SNMP_MGR1_USERNAME}  ${SNMP_MGR1_PASSWORD}
255c744f04eSPrashanth Katti    ...  alias=snmp_server  host=${SNMP_MGR1_IP}
256c744f04eSPrashanth Katti
25798825c0bSPrashanth Katti    # Clean SNMP managers running in the background.
25898825c0bSPrashanth Katti    SSHLibrary.Execute Command  killall snmptrapd
25998825c0bSPrashanth Katti
260c744f04eSPrashanth Katti    # The execution of the SNMP_TRAPD_CMD is necessary to cause SNMP to begin
261c744f04eSPrashanth Katti    # listening to SNMP messages.
262c744f04eSPrashanth Katti    SSHLibrary.write  ${SNMP_TRAPD_CMD} &
263b1a9c6b7SPrashanth Katti
264b1a9c6b7SPrashanth Katti
265a2e8b0d6SGeorge KeishingCreate Error On BMC And Verify Trap On Non Default Port
266b1a9c6b7SPrashanth Katti    [Documentation]  Generate error on BMC and verify if trap is sent to non default port.
267b1a9c6b7SPrashanth Katti    [Arguments]  ${event_log}=${CMD_INTERNAL_FAILURE}  ${expected_error}=${SNMP_TRAP_BMC_INTERNAL_FAILURE}
268b1a9c6b7SPrashanth Katti
269b1a9c6b7SPrashanth Katti    # Description of argument(s):
270b1a9c6b7SPrashanth Katti    # event_log       Event logs to be created.
271b1a9c6b7SPrashanth Katti    # expected_error  Expected error on SNMP.
272b1a9c6b7SPrashanth Katti
273b1a9c6b7SPrashanth Katti    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
274b1a9c6b7SPrashanth Katti
275b1a9c6b7SPrashanth Katti    Start SNMP Manager On Specific Port  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
276b1a9c6b7SPrashanth Katti
277b1a9c6b7SPrashanth Katti    # Generate error log.
278b1a9c6b7SPrashanth Katti    BMC Execute Command  ${event_log}
279b1a9c6b7SPrashanth Katti
280b1a9c6b7SPrashanth Katti    SSHLibrary.Switch Connection  snmp_server
281b1a9c6b7SPrashanth Katti    ${SNMP_LISTEN_OUT}=  Read  delay=1s
282b1a9c6b7SPrashanth Katti
283b1a9c6b7SPrashanth Katti    Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
284b1a9c6b7SPrashanth Katti
285b1a9c6b7SPrashanth Katti    # Stop SNMP manager process.
286b1a9c6b7SPrashanth Katti    SSHLibrary.Execute Command  sudo killall snmptrapd
287b1a9c6b7SPrashanth Katti
288b1a9c6b7SPrashanth Katti    # Sample SNMP trap:
289b1a9c6b7SPrashanth Katti    # 2021-06-16 07:05:29 xx.xx.xx.xx [UDP: [xx.xx.xx.xx]:58154->[xx.xx.xx.xx]:xxx]:
290b1a9c6b7SPrashanth Katti    # DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (2100473) 5:50:04.73
291b1a9c6b7SPrashanth Katti    #   SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-SMI::enterprises.49871.1.0.0.1
292b1a9c6b7SPrashanth Katti    #  SNMPv2-SMI::enterprises.49871.1.0.1.1 = Gauge32: 369    SNMPv2-SMI::enterprises.49871.1.0.1.2 = Opaque:
293b1a9c6b7SPrashanth Katti    # UInt64: 1397718405502468474     SNMPv2-SMI::enterprises.49871.1.0.1.3 = INTEGER: 3
294b1a9c6b7SPrashanth Katti    #      SNMPv2-SMI::enterprises.49871.1.0.1.4 = STRING: "xxx.xx.xx Failure"
295b1a9c6b7SPrashanth Katti
296b1a9c6b7SPrashanth Katti    ${lines}=  Split To Lines  ${SNMP_LISTEN_OUT}
297b1a9c6b7SPrashanth Katti    ${trap_info}=  Get From List  ${lines}  -1
298b1a9c6b7SPrashanth Katti    ${snmp_trap}=  Split String  ${trap_info}  \t
299b1a9c6b7SPrashanth Katti
300b1a9c6b7SPrashanth Katti    Verify SNMP Trap  ${snmp_trap}  ${expected_error}
301b1a9c6b7SPrashanth Katti
302*409df05dSGeorge Keishing    RETURN  ${snmp_trap}
303b1a9c6b7SPrashanth Katti
304b1a9c6b7SPrashanth Katti
305b1a9c6b7SPrashanth KattiStart SNMP Manager On Specific Port
306b1a9c6b7SPrashanth Katti    [Documentation]  Start SNMP listener on specific port on the remote SNMP manager.
307b1a9c6b7SPrashanth Katti    [Arguments]  ${snmp_mgr_ip}  ${snmp_port}
308b1a9c6b7SPrashanth Katti
309b1a9c6b7SPrashanth Katti    # Description of argument(s):
310b1a9c6b7SPrashanth Katti    # snmp_mgr_ip  SNMP manager IP.
311b1a9c6b7SPrashanth Katti    # snmp_port    Network port on which SNMP manager need to run.
312b1a9c6b7SPrashanth Katti
313b1a9c6b7SPrashanth Katti    ${ip_and_port}=  Catenate  ${snmp_mgr_ip}:${snmp_port}
314b1a9c6b7SPrashanth Katti
315b1a9c6b7SPrashanth Katti    Open Connection And Log In  ${SNMP_MGR1_USERNAME}  ${SNMP_MGR1_PASSWORD}
316b1a9c6b7SPrashanth Katti    ...  alias=snmp_server  host=${SNMP_MGR1_IP}
317b1a9c6b7SPrashanth Katti
318b1a9c6b7SPrashanth Katti    # The execution of the SNMP_TRAPD_CMD is necessary to cause SNMP to begin
319b1a9c6b7SPrashanth Katti    # listening to SNMP messages.
320b1a9c6b7SPrashanth Katti    SSHLibrary.write  ${SNMP_TRAPD_CMD} ${ip_and_port} &
3216ea399beSPrashanth Katti
3226ea399beSPrashanth Katti
3236ea399beSPrashanth KattiGenerate Error On BMC And Verify Trap
3246ea399beSPrashanth Katti    [Documentation]  Generate error on BMC and verify if trap is sent.
3256ea399beSPrashanth Katti    [Arguments]  ${event_log}=${CMD_INTERNAL_FAILURE}  ${expected_error}=${SNMP_TRAP_BMC_INTERNAL_FAILURE}
3266ea399beSPrashanth Katti
3276ea399beSPrashanth Katti    # Description of argument(s):
3286ea399beSPrashanth Katti    # event_log       Event logs to be created.
3296ea399beSPrashanth Katti    # expected_error  Expected error on SNMP.
3306ea399beSPrashanth Katti
3316ea399beSPrashanth Katti    Start SNMP Manager
3326ea399beSPrashanth Katti
3336ea399beSPrashanth Katti    # Generate error log.
3346ea399beSPrashanth Katti    BMC Execute Command  ${event_log}
3356ea399beSPrashanth Katti
3366ea399beSPrashanth Katti    SSHLibrary.Switch Connection  snmp_server
3376ea399beSPrashanth Katti    ${SNMP_LISTEN_OUT}=  Read  delay=1s
3386ea399beSPrashanth Katti
3396ea399beSPrashanth Katti    Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
3406ea399beSPrashanth Katti
3416ea399beSPrashanth Katti    # Stop SNMP manager process.
3426ea399beSPrashanth Katti    SSHLibrary.Execute Command  sudo killall snmptrapd
3436ea399beSPrashanth Katti
3446ea399beSPrashanth Katti    # Sample SNMP trap:
3456ea399beSPrashanth Katti    # 2021-06-16 07:05:29 xx.xx.xx.xx [UDP: [xx.xx.xx.xx]:58154->[xx.xx.xx.xx]:xxx]:
3466ea399beSPrashanth Katti    # DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (2100473) 5:50:04.73
3476ea399beSPrashanth Katti    #   SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-SMI::enterprises.49871.1.0.0.1
3486ea399beSPrashanth Katti    #  SNMPv2-SMI::enterprises.49871.1.0.1.1 = Gauge32: 369    SNMPv2-SMI::enterprises.49871.1.0.1.2 = Opaque:
3496ea399beSPrashanth Katti    # UInt64: 1397718405502468474     SNMPv2-SMI::enterprises.49871.1.0.1.3 = INTEGER: 3
3506ea399beSPrashanth Katti    #      SNMPv2-SMI::enterprises.49871.1.0.1.4 = STRING: "xxx.xx.xx Failure"
3516ea399beSPrashanth Katti
3526ea399beSPrashanth Katti    ${lines}=  Split To Lines  ${SNMP_LISTEN_OUT}
3536ea399beSPrashanth Katti    ${trap_info}=  Get From List  ${lines}  -1
3546ea399beSPrashanth Katti    ${snmp_trap}=  Split String  ${trap_info}  \t
3556ea399beSPrashanth Katti
3566ea399beSPrashanth Katti    Verify SNMP Trap  ${snmp_trap}  ${expected_error}
3576ea399beSPrashanth Katti
358*409df05dSGeorge Keishing    RETURN  ${snmp_trap}
3596ea399beSPrashanth Katti
360