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/logging_utils.robot
12
13
14Test Teardown     FFDC On Test Case Fail
15Suite Setup       Suite Setup Execution
16Suite Teardown    Suite Teardown Execution
17
18Test Tags        BMC_SNMP_Trap
19
20*** Test Cases ***
21
22Configure SNMP Manager On BMC And Verify
23    [Documentation]  Configure SNMP manager on BMC via Redfish and verify.
24    [Tags]  Configure_SNMP_Manager_On_BMC_And_Verify
25    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
26
27    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}  ${HTTP_CREATED}
28
29    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
30
31
32Configure SNMP Manager On BMC With Non Default Port And Verify
33    [Documentation]  Configure SNMP Manager On BMC And Verify.
34    [Tags]  Configure_SNMP_Manager_On_BMC_With_Non_Default_Port_And_Verify
35    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
36
37    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}  ${HTTP_CREATED}
38
39    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
40
41
42Configure SNMP Manager On BMC With Out Of Range Port And Verify
43    [Documentation]  Configure SNMP Manager On BMC with out-of range port and verify.
44    [Tags]  Configure_SNMP_Manager_On_BMC_With_Out_Of_Range_Port_And_Verify
45    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${out_of_range_port}
46
47    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${out_of_range_port}  ${HTTP_BAD_REQUEST}
48
49    ${status}=  Run Keyword And Return Status
50    ...  Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${out_of_range_port}
51
52    Should Be Equal As Strings  ${status}  False
53    ...  msg=BMC is allowing to configure out of range port.
54
55
56Generate Error On BMC And Verify SNMP Trap
57    [Documentation]  Generate error on BMC and verify trap and its fields.
58    [Tags]  Generate_Error_On_BMC_And_Verify_SNMP_Trap
59    [Template]  Create Error On BMC And Verify Trap
60
61    # event_log                 expected_error
62
63    # Generate internal failure error.
64    ${CMD_INTERNAL_FAILURE}     ${SNMP_TRAP_BMC_INTERNAL_FAILURE}
65
66    # Generate timeout error.
67    ${CMD_FRU_CALLOUT}          ${SNMP_TRAP_BMC_CALLOUT_ERROR}
68
69    # Generate informational error.
70    ${CMD_INFORMATIONAL_ERROR}  ${SNMP_TRAP_BMC_INFORMATIONAL_ERROR}
71
72
73Configure SNMP Manager On BMC With Alpha Port And Verify
74    [Documentation]  Configure SNMP Manager On BMC with alpha port and verify.
75    [Tags]  Configure_SNMP_Manager_On_BMC_With_Alpha_Port_And_Verify
76    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${alpha_port}
77
78    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${alpha_port}  ${HTTP_BAD_REQUEST}
79
80    ${status}=  Run Keyword And Return Status
81    ...  Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${alpha_port}
82
83    Should Be Equal As Strings  ${status}  False
84    ...  msg=BMC is allowing to configure invalid port.
85
86
87Configure SNMP Manager On BMC With Empty Port And Verify
88    [Documentation]  Configure SNMP Manager On BMC with empty port and verify
89    ...  SNMP manager gets configured with default port.
90    [Tags]  Configure_SNMP_Manager_On_BMC_With_Empty_Port_And_Verify
91    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
92
93    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${empty_port}
94
95    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
96
97
98Configure Multiple SNMP Managers And Verify
99    [Documentation]  Configure multiple SNMP managers and verify.
100    [Tags]  Configure_Multiple_SNMP_Managers_And_Verify
101    [Teardown]  Run Keywords
102    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
103    ...  AND
104    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
105
106    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
107    Configure SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
108    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
109    Verify SNMP Manager Configured On BMC  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
110
111
112Generate Error On BMC And Verify SNMP Trap Is Sent To Non Default Port
113    [Documentation]  Generate error on BMC and verify trap and its fields.
114    [Tags]  Generate_Error_On_BMC_And_Verify_SNMP_Trap_Is_Sent_To_Non_Default_Port
115    [Template]  Create Error On BMC And Verify Trap On Non Default Port
116
117    # event_log                 expected_error
118
119    # Generate internal failure error.
120    ${CMD_INTERNAL_FAILURE}     ${SNMP_TRAP_BMC_INTERNAL_FAILURE}
121
122    # Generate timeout error.
123    ${CMD_FRU_CALLOUT}          ${SNMP_TRAP_BMC_CALLOUT_ERROR}
124
125    # Generate informational error.
126    ${CMD_INFORMATIONAL_ERROR}  ${SNMP_TRAP_BMC_INFORMATIONAL_ERROR}
127
128
129Verify SNMP SysUpTime
130    [Documentation]  Verify SNMP SysUpTime.
131    [Tags]  Verify_SNMP_SysUpTime
132
133    Generate Error And Verify System Up Time
134
135
136Verify SNMP SysUpTime On BMC Reboot
137    [Documentation]  Verify SNMP SysUpTime on BMC reboot.
138    [Tags]  Verify_SNMP_SysUpTime_On_BMC_Reboot
139
140    # Reboot BMC to reset system uptime.
141    OBMC Reboot (off)
142
143    ${uptime}=  Generate Error And Verify System Up Time
144
145    # Check if uptime is reset after reboot.
146    Should Be True  ${uptime} <= 1  msg=SNMP SysUpTime is not reset on reboot
147
148
149Configure Multiple SNMP Managers With Non Default Port And Verify
150    [Documentation]  Configure multiple SNMP Managers with non-default port And Verify.
151    [Tags]  Configure_Multiple_SNMP_Managers_With_Non_Default_Port_And_Verify
152    [Teardown]  Run Keywords
153    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
154    ...  AND
155    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
156
157    # Configure multiple SNMP managers with non-default port.
158    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
159    Configure SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
160
161    # Verify if SNMP managers are configured.
162    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
163    Verify SNMP Manager Configured On BMC  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
164
165
166Configure Multiple SNMP Managers With Different Ports And Verify
167    [Documentation]  Configure multiple SNMP Managers with different ports And Verify.
168    [Tags]  Configure_Multiple_SNMP_Managers_With_Different_Ports_And_Verify
169    [Teardown]  Run Keywords
170    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
171    ...  AND
172    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
173    ...  AND
174    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR3_IP}  ${NON_DEFAULT_PORT2}
175
176    # Configure multiple SNMP managers with different ports.
177    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
178    Configure SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
179    Configure SNMP Manager Via Redfish  ${SNMP_MGR3_IP}  ${NON_DEFAULT_PORT2}
180
181    # Verify if SNMP managers are configured.
182    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
183    Verify SNMP Manager Configured On BMC  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
184    Verify SNMP Manager Configured On BMC  ${SNMP_MGR3_IP}  ${NON_DEFAULT_PORT2}
185
186
187Configure SNMP Manager With Out Of Range IP On BMC And Verify
188    [Documentation]  Configure SNMP Manager On BMC with out-of range IP and expect an error.
189    [Tags]  Configure_SNMP_Manager_With_Out_Of_Range_IP_On_BMC_And_Verify
190    [Teardown]  Delete SNMP Manager Via Redfish  ${out_of_range_ip}  ${SNMP_DEFAULT_PORT}
191
192    Configure SNMP Manager Via Redfish  ${out_of_range_ip}  ${SNMP_DEFAULT_PORT}  ${HTTP_BAD_REQUEST}
193
194    ${status}=  Run Keyword And Return Status
195    ...  Verify SNMP Manager Configured On BMC  ${out_of_range_ip}  ${SNMP_DEFAULT_PORT}
196
197    Should Be Equal As Strings  ${status}  False
198    ...  msg=BMC is allowing to configure out of range IP.
199
200
201Verify Persistency Of SNMP Manager And Trap On BMC Reboot
202    [Documentation]  Verify persistency of SNMP manager configuration on BMC
203    ...  and BMC is able to send trap after reboot.
204    [Tags]  Verify_Persistency_Of_SNMP_Manager_And_Trap_On_BMC_Reboot
205    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
206
207    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}  ${HTTP_CREATED}
208
209    # Reboot BMC and check persistency SNMP manager.
210    OBMC Reboot (off)
211
212    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
213
214    # Check if trap is generated and sent to SNMP manager after reboot.
215    Generate Error On BMC And Verify Trap
216    ...  ${CMD_INTERNAL_FAILURE}  ${SNMP_TRAP_BMC_INTERNAL_FAILURE}
217
218
219Configure SNMP Manager With Less Octet IP And Verify
220    [Documentation]  Configure SNMP manager on BMC with less octet IP and expect an error.
221    [Tags]  Configure_SNMP_Manager_With_Less_Octet_IP_And_Verify
222    [Teardown]  Delete SNMP Manager Via Redfish  ${less_octet_ip}  ${SNMP_DEFAULT_PORT}
223
224    Configure SNMP Manager Via Redfish  ${less_octet_ip}  ${SNMP_DEFAULT_PORT}  ${HTTP_BAD_REQUEST}
225
226    ${status}=  Run Keyword And Return Status
227    ...  Verify SNMP Manager Configured On BMC  ${less_octet_ip}  ${SNMP_DEFAULT_PORT}
228
229    Should Be Equal As Strings  ${status}  False
230    ...  msg=BMC is allowing to configure less octet IP.
231
232
233Configure SNMP Manager On BMC With Negative Port And Verify
234    [Documentation]  Configure SNMP Manager On BMC with negative port and verify.
235    [Tags]  Configure_SNMP_Manager_On_BMC_With_Negative_Port_And_Verify
236
237    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${negative_port}
238
239    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${negative_port}  ${HTTP_BAD_REQUEST}
240
241    ${status}=  Run Keyword And Return Status
242    ...  Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${negative_port}
243
244    Should Be Equal As Strings  ${status}  False
245    ...  msg=BMC is allowing to configure negative port.
246
247
248Configure Multiple SNMP Managers On BMC And Verify Persistency On BMC Reboot
249    [Documentation]  Configure multiple SNMP Managers on BMC and verify persistency on BMC reboot.
250    [Tags]  Configure_Multiple_SNMP_Managers_On_BMC_And_Verify_Persistency_On_BMC_Reboot
251    [Teardown]  Run Keywords
252    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
253    ...  AND
254    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
255
256    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
257    Configure SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
258
259    # Reboot BMC and check persistency SNMP manager.
260    OBMC Reboot (off)
261
262    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
263    Verify SNMP Manager Configured On BMC  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
264
265
266Configure Multiple SNMP Managers On BMC And Check Trap On BMC Reboot
267    [Documentation]  Configure multiple SNMP Managers on BMC and check trap on BMC reboot.
268    [Tags]  Configure_Multiple_SNMP_Managers_On_BMC_And_Check_Trap_On_BMC_Reboot
269    [Teardown]  Run Keywords
270    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
271    ...  AND
272    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
273
274    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
275    Configure SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
276
277    # Reboot BMC and check persistency SNMP manager.
278    OBMC Reboot (off)
279
280    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
281    Verify SNMP Manager Configured On BMC  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
282
283    # Check if trap is generated and sent to SNMP managers after reboot.
284    Generate Error On BMC And Verify Trap
285    ...  ${CMD_INTERNAL_FAILURE}  ${SNMP_TRAP_BMC_INTERNAL_FAILURE}
286
287
288*** Keywords ***
289
290Suite Setup Execution
291    [Documentation]  Do suite setup execution.
292
293    Redfish.Login
294
295    # Check for SNMP configurations.
296    Valid Value  SNMP_MGR1_IP
297    Valid Value  SNMP_DEFAULT_PORT
298
299
300Suite Teardown Execution
301    [Documentation]  Do suite Teardown execution.
302
303    Run Keyword And Ignore Error  Redfish Purge Event Log
304    Run Keyword And Ignore Error  Redfish Delete All BMC Dumps
305
306
307Generate Error And Verify System Up Time
308    [Documentation]  Generate error and verify system up time.
309
310    # Get system uptime on BMC.
311    # Example output of uptime:
312    # (8055.79 15032.86)
313
314    ${cmd_output}   ${stderr}  ${rc}=  BMC Execute Command  cat /proc/uptime
315    @{times}=  Split String  ${cmd_output}
316
317    ${bmc_uptime_in_minutes}=  Evaluate  int(${times}[0])/60
318
319    ${trap}=  Create Error On BMC And Verify Trap
320
321    # Extract System up time from SNMP trap.
322    # Example - SNMP trap:
323    # DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (252367) 0:42:03.67
324    # SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-SMI::enterprises.49871.1.0.0.1
325    # SNMPv2-SMI::enterprises.49871.1.0.1.1 = Gauge32: 54
326    # SNMPv2-SMI::enterprises.49871.1.0.1.2 = Opaque: UInt64: 4622921648578756984
327    # SNMPv2-SMI::enterprises.49871.1.0.1.3 = INTEGER: 3
328    # SNMPv2-SMI::enterprises.49871.1.0.1.4 = STRING:
329
330    @{words}=  Split String  ${trap}[0]  =
331
332    ${timeticks}=  Fetch From Right  ${words}[1]  (
333    ${snmp_sysuptime}=  Fetch From Left  ${timeticks}  )
334
335    # SNMP SysUptime will be in milli seconds.
336    # Convert into minutes.
337    ${sysuptime_in_minutes}=  Evaluate  int(${snmp_sysuptime})/6000
338
339    Should Be Equal As Integers  ${bmc_uptime_in_minutes}  ${sysuptime_in_minutes}
340
341    RETURN  ${sysuptime_in_minutes}
342