xref: /openbmc/openbmc-test-automation/redfish/events/test_bmc_snmp_trap.robot (revision c0df92e7b0347fa8da85fb5d4076ecf849b7b179)
1*** Settings ***
2Documentation  This testing requires special setup where SNMP trapd is
3...            configured and installed. For download, installation and
4...            configuration refer http://www.net-snmp.org/.
5
6
7Resource  ../../lib/snmp/resource.robot
8Resource  ../../lib/snmp/redfish_snmp_utils.robot
9Resource  ../../lib/bmc_redfish_resource.robot
10Resource  ../../lib/openbmc_ffdc.robot
11Resource  ../../lib/bmc_redfish_resource.robot
12Resource  ../../lib/openbmc_ffdc.robot
13Resource  ../../lib/logging_utils.robot
14
15
16Test Teardown  FFDC On Test Case Fail
17Suite Setup    Suite Setup Execution
18
19*** Variables ***
20
21${snmp_function}     SNMPTrap
22${snmp_version}      SNMPv2c
23${subscription_uri}  /redfish/v1/EventService/Subscriptions
24
25${CMD_INTERNAL_FAILURE}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
26...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.InternalFailure
27...  xyz.openbmc_project.Logging.Entry.Level.Error 0
28
29${CMD_FRU_CALLOUT}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
30...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.Timeout
31...  xyz.openbmc_project.Logging.Entry.Level.Error 2 "TIMEOUT_IN_MSEC" "5"
32...  "CALLOUT_INVENTORY_PATH" "/xyz/openbmc_project/inventory/system/chassis/motherboard"
33
34${CMD_INFORMATIONAL_ERROR}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
35...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.TestError2
36...  xyz.openbmc_project.Logging.Entry.Level.Informational 0
37
38${SNMP_TRAP_BMC_INTERNAL_FAILURE}  xyz.openbmc_project.Common.Error.InternalFailure
39${SNMP_TRAP_BMC_CALLOUT_ERROR}  xyz.openbmc_project.Common.Error.Timeout
40${SNMP_TRAP_BMC_INFORMATIONAL_ERROR}  xyz.openbmc_project.Common.Error.TestError2
41
42
43*** Test Cases ***
44
45Configure SNMP Manager On BMC And Verify
46    [Documentation]  Configure SNMP manager on BMC via Redfish and verify.
47    [Tags]  Configure_SNMP_Manager_On_BMC_And_Verify
48    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
49
50    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}  ${HTTP_CREATED}
51
52    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
53
54
55Configure SNMP Manager On BMC With Non-default Port And Verify
56    [Documentation]  Configure SNMP Manager On BMC And Verify.
57    [Tags]  Configure_SNMP_Manager_On_BMC_With_Non_Default_Port_And_Verify
58    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
59
60    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}  ${HTTP_CREATED}
61
62    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
63
64
65Configure SNMP Manager On BMC With Out Of Range Port And Verify
66    [Documentation]  Configure SNMP Manager On BMC with out-of range port and verify.
67    [Tags]  Configure_SNMP_Manager_On_BMC_With_Out_Of_Range_Port_And_Verify
68    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${out_of_range_port}
69
70    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${out_of_range_port}  ${HTTP_BAD_REQUEST}
71
72    ${status}=  Run Keyword And Return Status
73    ...  Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${out_of_range_port}
74
75    Should Be Equal As Strings  ${status}  False
76    ...  msg=BMC is allowing to configure out of range port.
77
78
79Generate Error On BMC And Verify SNMP Trap
80    [Documentation]  Generate error on BMC and verify trap and its fields.
81    [Tags]  Generate_Error_On_BMC_And_Verify_SNMP_Trap
82    [Template]  Create Error On BMC And Verify Trap
83
84    # event_log                 expected_error
85
86    # Generate internal failure error.
87    ${CMD_INTERNAL_FAILURE}     ${SNMP_TRAP_BMC_INTERNAL_FAILURE}
88
89    # Generate timeout error.
90    ${CMD_FRU_CALLOUT}          ${SNMP_TRAP_BMC_CALLOUT_ERROR}
91
92    # Generate informational error.
93    ${CMD_INFORMATIONAL_ERROR}  ${SNMP_TRAP_BMC_INFORMATIONAL_ERROR}
94
95
96Configure SNMP Manager On BMC With Alpha Port And Verify
97    [Documentation]  Configure SNMP Manager On BMC with alpha port and verify.
98    [Tags]  Configure_SNMP_Manager_On_BMC_With_Alpha_Port_And_Verify
99    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${alpha_port}
100
101    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${alpha_port}  ${HTTP_BAD_REQUEST}
102
103    ${status}=  Run Keyword And Return Status
104    ...  Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${alpha_port}
105
106    Should Be Equal As Strings  ${status}  False
107    ...  msg=BMC is allowing to configure invalid port.
108
109
110Configure SNMP Manager On BMC With Empty Port And Verify
111    [Documentation]  Configure SNMP Manager On BMC with empty port and verify
112    ...  SNMP manager gets configured with default port.
113    [Tags]  Configure_SNMP_Manager_On_BMC_With_Empty_Port_And_Verify
114    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
115
116    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${empty_port}
117
118    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
119
120
121Configure Multiple SNMP Managers And Verify
122    [Documentation]  Configure multiple SNMP managers and verify.
123    [Tags]  Configure_Multiple_SNMP_Managers_And_Verify
124    [Teardown]  Run Keywords
125    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
126    ...  AND
127    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
128
129    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
130    Configure SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
131    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
132    Verify SNMP Manager Configured On BMC  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
133
134
135Generate Error On BMC And Verify SNMP Trap Is Sent To Non-Default Port
136    [Documentation]  Generate error on BMC and verify trap and its fields.
137    [Tags]  Generate_Error_On_BMC_And_Verify_SNMP_Trap_Is_Sent_To_Non-Default_Port
138    [Template]  Create Error On BMC And Verify Trap On Non-Default Port
139
140    # event_log                 expected_error
141
142    # Generate internal failure error.
143    ${CMD_INTERNAL_FAILURE}     ${SNMP_TRAP_BMC_INTERNAL_FAILURE}
144
145    # Generate timeout error.
146    ${CMD_FRU_CALLOUT}          ${SNMP_TRAP_BMC_CALLOUT_ERROR}
147
148    # Generate informational error.
149    ${CMD_INFORMATIONAL_ERROR}  ${SNMP_TRAP_BMC_INFORMATIONAL_ERROR}
150
151
152Verify SNMP SysUpTime
153    [Documentation]  Verify SNMP SysUpTime.
154    [Tags]  Verify_SNMP_SysUpTime
155
156    Generate Error And Verify System Up Time
157
158
159Verify SNMP SysUpTime On BMC Reboot
160    [Documentation]  Verify SNMP SysUpTime on BMC reboot.
161    [Tags]  Verify_SNMP_SysUpTime_On_BMC_Reboot
162
163    # Reboot BMC to reset system uptime.
164    OBMC Reboot (off)
165
166    ${uptime}=  Generate Error And Verify System Up Time
167
168    # Check if uptime is reset after reboot.
169    Should Be True  ${uptime} <= 1  msg=SNMP SysUpTime is not reset on reboot
170
171
172Configure Multiple SNMP Managers With Non-default Port And Verify
173    [Documentation]  Configure multiple SNMP Managers with non-default port And Verify.
174    [Tags]  Configure_Multiple_SNMP_Managers_With_Non_Default_Port_And_Verify
175    [Teardown]  Run Keywords
176    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
177    ...  AND
178    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
179
180    # Configure multiple SNMP managers with non-default port.
181    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
182    Configure SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
183
184    # Verify if SNMP managers are configured.
185    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
186    Verify SNMP Manager Configured On BMC  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
187
188
189Configure Multiple SNMP Managers With Different Ports And Verify
190    [Documentation]  Configure multiple SNMP Managers with different ports And Verify.
191    [Tags]  Configure_Multiple_SNMP_Managers_With_Different_Ports_And_Verify
192    [Teardown]  Run Keywords
193    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
194    ...  AND
195    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
196    ...  AND
197    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR3_IP}  ${NON_DEFAULT_PORT2}
198
199    # Configure multiple SNMP managers with diffrent ports.
200    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
201    Configure SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
202    Configure SNMP Manager Via Redfish  ${SNMP_MGR3_IP}  ${NON_DEFAULT_PORT2}
203
204    # Verify if SNMP managers are configured.
205    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
206    Verify SNMP Manager Configured On BMC  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
207    Verify SNMP Manager Configured On BMC  ${SNMP_MGR3_IP}  ${NON_DEFAULT_PORT2}
208
209
210*** Keywords ***
211
212Suite Setup Execution
213    [Documentation]  Do suite setup execution.
214
215    Redfish.Login
216
217    # Check for SNMP configurations.
218    Valid Value  SNMP_MGR1_IP
219    Valid Value  SNMP_DEFAULT_PORT
220
221
222Generate Error And Verify System Up Time
223    [Documentation]  Generate error and verify system up time.
224
225    # Get system uptime on BMC.
226    # Example output of uptime:
227    # (8055.79 15032.86)
228
229    ${cmd_output}   ${stderr}  ${rc}=  BMC Execute Command  cat /proc/uptime
230    @{times}=  Split String  ${cmd_output}
231
232    ${bmc_uptime_in_minutes}=  Evaluate  int(${times}[0])/60
233
234    ${trap}=  Create Error On BMC And Verify Trap
235
236    # Extract System up time from SNMP trap.
237    # Example - SNMP trap:
238    # DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (252367) 0:42:03.67
239    # SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-SMI::enterprises.49871.1.0.0.1
240    # SNMPv2-SMI::enterprises.49871.1.0.1.1 = Gauge32: 54
241    # SNMPv2-SMI::enterprises.49871.1.0.1.2 = Opaque: UInt64: 4622921648578756984
242    # SNMPv2-SMI::enterprises.49871.1.0.1.3 = INTEGER: 3
243    # SNMPv2-SMI::enterprises.49871.1.0.1.4 = STRING:
244
245    @{words}=  Split String  ${trap}[0]  =
246
247    ${timeticks}=  Fetch From Right  ${words}[1]  (
248    ${snmp_sysuptime}=  Fetch From Left  ${timeticks}  )
249
250    # SNMP SysUptime will be in milli seconds.
251    # Convert into minutes.
252    ${sysuptime_in_minutes}=  Evaluate  int(${snmp_sysuptime})/6000
253
254    Should Be Equal As Integers  ${bmc_uptime_in_minutes}  ${sysuptime_in_minutes}
255
256    [Return]  ${sysuptime_in_minutes}
257