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